diff --git a/src/main/java/com/wimbli/WorldBorder/BlockPlaceListener.java b/src/main/java/com/wimbli/WorldBorder/BlockPlaceListener.java index b1e5f82..921a208 100644 --- a/src/main/java/com/wimbli/WorldBorder/BlockPlaceListener.java +++ b/src/main/java/com/wimbli/WorldBorder/BlockPlaceListener.java @@ -8,7 +8,9 @@ import org.bukkit.event.HandlerList; import org.bukkit.event.Listener; import org.bukkit.event.block.BlockPlaceEvent; -public class BlockPlaceListener implements Listener { + +public class BlockPlaceListener implements Listener +{ @EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true) public void onBlockPlace(BlockPlaceEvent event) { @@ -20,12 +22,14 @@ public class BlockPlaceListener implements Listener { BorderData border = Config.Border(world.getName()); if (border == null) return; - if (!border.insideBorder(loc.getX(), loc.getZ(), Config.ShapeRound())) { + if (!border.insideBorder(loc.getX(), loc.getZ(), Config.ShapeRound())) + { event.setCancelled(true); } } - public void unregister() { + public void unregister() + { HandlerList.unregisterAll(this); } } diff --git a/src/main/java/com/wimbli/WorldBorder/UUID/NameFetcher.java b/src/main/java/com/wimbli/WorldBorder/UUID/NameFetcher.java index e1372c7..deb5517 100644 --- a/src/main/java/com/wimbli/WorldBorder/UUID/NameFetcher.java +++ b/src/main/java/com/wimbli/WorldBorder/UUID/NameFetcher.java @@ -19,31 +19,37 @@ import java.util.concurrent.Callable; * from http://forums.bukkit.org/threads/player-name-uuid-fetcher.250926/ */ -public class NameFetcher implements Callable> { +public class NameFetcher implements Callable> +{ private static final String PROFILE_URL = "https://sessionserver.mojang.com/session/minecraft/profile/"; private final JSONParser jsonParser = new JSONParser(); private final List uuids; - public NameFetcher(List uuids) { + public NameFetcher(List uuids) + { this.uuids = ImmutableList.copyOf(uuids); } @Override - public Map call() throws Exception { + public Map call() throws Exception + { Map uuidStringMap = new HashMap(); - for (UUID uuid: uuids) { + for (UUID uuid: uuids) + { HttpURLConnection connection = (HttpURLConnection) new URL(PROFILE_URL+uuid.toString().replace("-", "")).openConnection(); JSONObject response = (JSONObject) jsonParser.parse(new InputStreamReader(connection.getInputStream())); String name = (String) response.get("name"); - if (name == null) { + if (name == null) + { continue; } String cause = (String) response.get("cause"); String errorMessage = (String) response.get("errorMessage"); - if (cause != null && cause.length() > 0) { + if (cause != null && cause.length() > 0) + { throw new IllegalStateException(errorMessage); } uuidStringMap.put(uuid, name); } return uuidStringMap; } -} \ No newline at end of file +} diff --git a/src/main/java/com/wimbli/WorldBorder/UUID/UUIDFetcher.java b/src/main/java/com/wimbli/WorldBorder/UUID/UUIDFetcher.java index d7455ca..e77e1a5 100644 --- a/src/main/java/com/wimbli/WorldBorder/UUID/UUIDFetcher.java +++ b/src/main/java/com/wimbli/WorldBorder/UUID/UUIDFetcher.java @@ -20,52 +20,61 @@ import java.util.concurrent.Callable; * slightly modified to fix name case mismatches for single name lookup */ -public class UUIDFetcher implements Callable> { +public class UUIDFetcher implements Callable> +{ private static final double PROFILES_PER_REQUEST = 100; private static final String PROFILE_URL = "https://api.mojang.com/profiles/minecraft"; private final JSONParser jsonParser = new JSONParser(); private final List names; private final boolean rateLimiting; - public UUIDFetcher(List names, boolean rateLimiting) { + public UUIDFetcher(List names, boolean rateLimiting) + { this.names = ImmutableList.copyOf(names); this.rateLimiting = rateLimiting; } - public UUIDFetcher(List names) { + public UUIDFetcher(List names) + { this(names, true); } - public Map call() throws Exception { + public Map call() throws Exception + { Map uuidMap = new HashMap(); int requests = (int) Math.ceil(names.size() / PROFILES_PER_REQUEST); - for (int i = 0; i < requests; i++) { + for (int i = 0; i < requests; i++) + { HttpURLConnection connection = createConnection(); String body = JSONArray.toJSONString(names.subList(i * 100, Math.min((i + 1) * 100, names.size()))); writeBody(connection, body); JSONArray array = (JSONArray) jsonParser.parse(new InputStreamReader(connection.getInputStream())); - for (Object profile : array) { + for (Object profile : array) + { JSONObject jsonProfile = (JSONObject) profile; String id = (String) jsonProfile.get("id"); String name = (String) jsonProfile.get("name"); UUID uuid = UUIDFetcher.getUUID(id); uuidMap.put(name.toLowerCase(), uuid); } - if (rateLimiting && i != requests - 1) { + if (rateLimiting && i != requests - 1) + { Thread.sleep(100L); } } return uuidMap; } - private static void writeBody(HttpURLConnection connection, String body) throws Exception { + private static void writeBody(HttpURLConnection connection, String body) throws Exception + { OutputStream stream = connection.getOutputStream(); stream.write(body.getBytes()); stream.flush(); stream.close(); } - private static HttpURLConnection createConnection() throws Exception { + private static HttpURLConnection createConnection() throws Exception + { URL url = new URL(PROFILE_URL); HttpURLConnection connection = (HttpURLConnection) url.openConnection(); connection.setRequestMethod("POST"); @@ -76,18 +85,21 @@ public class UUIDFetcher implements Callable> { return connection; } - private static UUID getUUID(String id) { + private static UUID getUUID(String id) + { return UUID.fromString(id.substring(0, 8) + "-" + id.substring(8, 12) + "-" + id.substring(12, 16) + "-" + id.substring(16, 20) + "-" +id.substring(20, 32)); } - public static byte[] toBytes(UUID uuid) { + public static byte[] toBytes(UUID uuid) + { ByteBuffer byteBuffer = ByteBuffer.wrap(new byte[16]); byteBuffer.putLong(uuid.getMostSignificantBits()); byteBuffer.putLong(uuid.getLeastSignificantBits()); return byteBuffer.array(); } - public static UUID fromBytes(byte[] array) { + public static UUID fromBytes(byte[] array) + { if (array.length != 16) { throw new IllegalArgumentException("Illegal byte array length: " + array.length); } @@ -97,7 +109,8 @@ public class UUIDFetcher implements Callable> { return new UUID(mostSignificant, leastSignificant); } - public static UUID getUUIDOf(String name) throws Exception { + public static UUID getUUIDOf(String name) throws Exception + { return new UUIDFetcher(Arrays.asList(name)).call().get(name.toLowerCase()); } } diff --git a/src/main/java/com/wimbli/WorldBorder/WBCommand.java b/src/main/java/com/wimbli/WorldBorder/WBCommand.java index 432933e..57ad7e1 100644 --- a/src/main/java/com/wimbli/WorldBorder/WBCommand.java +++ b/src/main/java/com/wimbli/WorldBorder/WBCommand.java @@ -209,5 +209,4 @@ public class WBCommand implements CommandExecutor commands.remove("commands"); return commands; } - -} \ No newline at end of file +} diff --git a/src/main/java/com/wimbli/WorldBorder/WorldBorder.java b/src/main/java/com/wimbli/WorldBorder/WorldBorder.java index 8379f44..3e63da4 100644 --- a/src/main/java/com/wimbli/WorldBorder/WorldBorder.java +++ b/src/main/java/com/wimbli/WorldBorder/WorldBorder.java @@ -27,7 +27,8 @@ public class WorldBorder extends JavaPlugin // keep an eye on teleports, to redirect them to a spot inside the border if necessary getServer().getPluginManager().registerEvents(new WBListener(), this); - if (Config.preventBlockPlace()) { + if (Config.preventBlockPlace()) + { enableBlockPlaceListener(true); } @@ -64,11 +65,13 @@ public class WorldBorder extends JavaPlugin } public void enableBlockPlaceListener(boolean enable) { - if (enable) { + if (enable) + { getServer().getPluginManager().registerEvents(this.blockPlaceListener = new BlockPlaceListener(), this); - } else { + } + else + { blockPlaceListener.unregister(); } - } } diff --git a/src/main/java/com/wimbli/WorldBorder/WorldFileData.java b/src/main/java/com/wimbli/WorldBorder/WorldFileData.java index 9a4095b..73e46a8 100644 --- a/src/main/java/com/wimbli/WorldBorder/WorldFileData.java +++ b/src/main/java/com/wimbli/WorldBorder/WorldFileData.java @@ -259,7 +259,7 @@ public class WorldFileData } -// crude chunk map PNG image output, for debugging + // crude chunk map PNG image output, for debugging private void testImage(CoordXZ region, List data) { int width = 32; int height = 32;