Skip to content

Commit

Permalink
Update to WorldEdit/WorldGuard 7
Browse files Browse the repository at this point in the history
  • Loading branch information
Jikoo committed Oct 21, 2018
1 parent 32a74ec commit 2972569
Show file tree
Hide file tree
Showing 7 changed files with 49 additions and 26 deletions.
24 changes: 19 additions & 5 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<groupId>com.github.jikoo</groupId>
<artifactId>regionerator</artifactId>
<name>Regionerator</name>
<version>1.5.3</version>
<version>1.5.4</version>

<dependencies>
<dependency>
Expand All @@ -28,14 +28,24 @@
<dependency>
<groupId>com.sk89q.worldedit</groupId>
<artifactId>worldedit-bukkit</artifactId>
<version>6.1.5</version>
<version>7.0.0-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.sk89q.worldguard</groupId>
<artifactId>worldguard-legacy</artifactId>
<version>6.2</version>
<version>7.0.0-SNAPSHOT</version>
<scope>provided</scope>
<exclusions>
<exclusion>
<groupId>org.bukkit</groupId>
<artifactId>bukkit</artifactId>
</exclusion>
<exclusion>
<groupId>com.sk89q</groupId>
<artifactId>commandbook</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>com.github.TechFortress</groupId>
Expand All @@ -50,9 +60,9 @@
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.github.FabioZumbi12.RedProtect</groupId>
<groupId>br.net.fabiozumbi12.RedProtect</groupId>
<artifactId>RedProtect-Spigot</artifactId>
<version>master-SNAPSHOT</version>
<version>7.5.3</version>
<scope>provided</scope>
</dependency>
<dependency>
Expand Down Expand Up @@ -134,6 +144,10 @@
<id>jitpack.io</id>
<url>https://jitpack.io</url>
</repository>
<repository>
<id>redprotect-repo</id>
<url>https://raw.github.com/FabioZumbi12/RedProtect/mvn-repo/</url>
</repository>
</repositories>

<build>
Expand Down
10 changes: 5 additions & 5 deletions src/main/java/com/github/jikoo/regionerator/ChunkFlagger.java
Original file line number Diff line number Diff line change
Expand Up @@ -199,14 +199,14 @@ private File getFlagFile(Pair<String, String> data) {
}

private Pair<String, String> getFlagFileIdentifier(String world, int chunkX, int chunkZ) {
return new ImmutablePair<String, String>(world,
new StringBuilder().append(CoordinateConversions.chunkToRegion(chunkX) >> 9)
.append('_').append(CoordinateConversions.chunkToRegion(chunkZ) >> 9)
.append(".yml").toString());
return new ImmutablePair<>(world,
String.valueOf(CoordinateConversions.chunkToRegion(chunkX) >> 9) +
'_' + (CoordinateConversions.chunkToRegion(chunkZ) >> 9) +
".yml");
}

private String getChunkPath(int chunkX, int chunkZ) {
return new StringBuilder().append(chunkX).append('_').append(chunkZ).toString();
return String.valueOf(chunkX) + '_' + chunkZ;
}

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@ public enum DebugLevel {
OFF,
LOW,
MEDIUM,
HIGH;
HIGH

}
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
import java.util.Map.Entry;
import java.util.Set;

import com.bekvon.bukkit.residence.commands.message;
import com.github.jikoo.regionerator.commands.CommandFlag;
import com.github.jikoo.regionerator.listeners.FlaggingListener;
import com.github.jikoo.regionerator.listeners.HookListener;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
package com.github.jikoo.regionerator.commands;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;

import com.github.jikoo.regionerator.CoordinateConversions;
import com.github.jikoo.regionerator.Regionerator;

import com.sk89q.worldedit.IncompleteRegionException;
import com.sk89q.worldedit.LocalSession;
import com.sk89q.worldedit.bukkit.WorldEditPlugin;
import com.sk89q.worldedit.bukkit.selections.Selection;

import com.sk89q.worldedit.regions.Region;
import org.apache.commons.lang3.tuple.ImmutableTriple;
import org.apache.commons.lang3.tuple.Triple;

Expand Down Expand Up @@ -100,7 +102,7 @@ private List<Triple<String, Integer, Integer>> getSelectedArea(CommandSender sen
return null;
}
// This looks silly, but it's necessary to make the compiler happy
return Arrays.asList((Triple<String, Integer, Integer>) new ImmutableTriple<>(worldName, chunkX, chunkZ));
return Collections.singletonList((Triple<String, Integer, Integer>) new ImmutableTriple<>(worldName, chunkX, chunkZ));
}

// Safe cast: prior 2 blocks remove all non-players.
Expand All @@ -109,7 +111,7 @@ private List<Triple<String, Integer, Integer>> getSelectedArea(CommandSender sen
// Flag current chunk
if (args.length < 2) {
Location location = player.getLocation();
return Arrays.asList((Triple<String, Integer, Integer>) new ImmutableTriple<>(
return Collections.singletonList((Triple<String, Integer, Integer>) new ImmutableTriple<>(
location.getWorld().getName(),
CoordinateConversions.blockToChunk(location.getBlockX()),
CoordinateConversions.blockToChunk(location.getBlockZ())));
Expand Down Expand Up @@ -138,7 +140,19 @@ private List<Triple<String, Integer, Integer>> getSelectedArea(CommandSender sen
return null;
}

Selection selection = worldedit.getSelection(player);
LocalSession session = worldedit.getSession(player);

if (session == null || session.getSelectionWorld() == null) {
sender.sendMessage("You must select an area with WorldEdit to (un)flag!");
return null;
}

Region selection = null;
try {
selection = session.getSelection(session.getSelectionWorld());
} catch (IncompleteRegionException e) {
// Ignored - we return anyway.
}

if (selection == null) {
sender.sendMessage("You must select an area with WorldEdit to (un)flag!");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,8 @@ public boolean isChunkProtected(World chunkWorld, int chunkX, int chunkZ) {
}

int spawnChunkZ = CoordinateConversions.blockToChunk(spawn.getBlockZ());
if (chunkZ > spawnChunkZ + protectionRadius || chunkZ < spawnChunkZ - protectionRadius) {
// Chunk z is outside of protection radius
return false;
}

// X and z both within radius, huzzah
return true;
return chunkZ <= spawnChunkZ + protectionRadius && chunkZ >= spawnChunkZ - protectionRadius;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import com.github.jikoo.regionerator.PluginHook;

import com.sk89q.worldedit.BlockVector;
import com.sk89q.worldguard.bukkit.WorldGuardPlugin;
import com.sk89q.worldguard.bukkit.WGBukkit;
import com.sk89q.worldguard.protection.regions.ProtectedCuboidRegion;

import org.bukkit.World;
Expand All @@ -26,7 +26,8 @@ public boolean isChunkProtected(World chunkWorld, int chunkX, int chunkZ) {
int chunkBlockZ = CoordinateConversions.chunkToBlock(chunkZ);
BlockVector bottom = new BlockVector(chunkBlockX, 0, chunkBlockZ);
BlockVector top = new BlockVector(chunkBlockX + 15, 255, chunkBlockZ + 15);
return WorldGuardPlugin.inst().getRegionManager(chunkWorld)
.getApplicableRegions(new ProtectedCuboidRegion("REGIONERATOR_TMP", bottom, top)).size() > 0;
return WGBukkit.getRegionManager(chunkWorld)
.getApplicableRegions(new ProtectedCuboidRegion("REGIONERATOR_TMP", bottom, top))
.size() > 0;
}
}

0 comments on commit 2972569

Please sign in to comment.