From c997a2583ce43782198e243014fbc3fbcd549899 Mon Sep 17 00:00:00 2001 From: matt <4009945+MattBDev@users.noreply.github.com> Date: Mon, 1 Apr 2019 21:28:49 -0400 Subject: [PATCH] I like change --- .../bukkit/listener/BukkitImageListener.java | 44 ++++++++----------- .../bukkit/listener/CFIPacketListener.java | 22 ++++------ .../boydti/fawe/bukkit/util/VaultUtil.java | 3 +- .../fawe/bukkit/v0/BukkitChunk_All.java | 2 +- .../boydti/fawe/bukkit/v0/BukkitQueue_0.java | 19 ++++---- .../fawe/bukkit/v0/BukkitQueue_All.java | 21 ++++----- .../boydti/fawe/bukkit/v0/ChunkListener.java | 35 +++++++-------- .../fawe/bukkit/wrapper/AsyncBlock.java | 16 +++---- .../fawe/bukkit/wrapper/AsyncChunk.java | 10 ++--- .../fawe/bukkit/wrapper/AsyncWorld.java | 29 +++--------- 10 files changed, 81 insertions(+), 120 deletions(-) diff --git a/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/listener/BukkitImageListener.java b/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/listener/BukkitImageListener.java index efd8dbb3d..e175ff1d5 100644 --- a/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/listener/BukkitImageListener.java +++ b/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/listener/BukkitImageListener.java @@ -103,7 +103,7 @@ public class BukkitImageListener implements Listener { if (event.getHand() == EquipmentSlot.OFF_HAND) return; } catch (NoSuchFieldError | NoSuchMethodError ignored) {} - List target = player.getLastTwoTargetBlocks((Set) null, 100); + List target = player.getLastTwoTargetBlocks(null, 100); if (target.isEmpty()) return; Block targetBlock = target.get(0); @@ -151,7 +151,7 @@ public class BukkitImageListener implements Listener { if (generator == null) return null; ImageViewer viewer = generator.getImageViewer(); - if (viewer == null || !(viewer instanceof BukkitImageViewer)) return null; + if (!(viewer instanceof BukkitImageViewer)) return null; BukkitImageViewer biv = (BukkitImageViewer) viewer; return biv; @@ -185,12 +185,7 @@ public class BukkitImageListener implements Listener { if (frames == null || tool == null) { viewer.selectFrame(itemFrame); player.updateInventory(); - TaskManager.IMP.laterAsync(new Runnable() { - @Override - public void run() { - viewer.view(generator); - } - }, 1); + TaskManager.IMP.laterAsync(() -> viewer.view(generator), 1); return; } @@ -250,26 +245,23 @@ public class BukkitImageListener implements Listener { if (worldX < 0 || worldX > width || worldZ < 0 || worldZ > length) return; - fp.runAction(new Runnable() { - @Override - public void run() { - BlockVector3 wPos = BlockVector3.at(worldX, 0, worldZ); - viewer.refresh(); - int topY = generator.getNearestSurfaceTerrainBlock(wPos.getBlockX(), wPos.getBlockZ(), 255, 0, 255); - wPos = wPos.withY(topY); + fp.runAction(() -> { + BlockVector3 wPos = BlockVector3.at(worldX, 0, worldZ); + viewer.refresh(); + int topY = generator.getNearestSurfaceTerrainBlock(wPos.getBlockX(), wPos.getBlockZ(), 255, 0, 255); + wPos = wPos.withY(topY); - EditSession es = new EditSessionBuilder(fp.getWorld()).player(fp).combineStages(false).autoQueue(false).blockBag(null).limitUnlimited().build(); - ExtentTraverser last = new ExtentTraverser(es.getExtent()).last(); - if (last.get() instanceof FastWorldEditExtent) last = last.previous(); - last.setNext(generator); - try { - brush.build(es, wPos, context.getMaterial(), context.getSize()); - } catch (WorldEditException e) { - e.printStackTrace(); - } - es.flushQueue(); - viewer.view(generator); + EditSession es = new EditSessionBuilder(fp.getWorld()).player(fp).combineStages(false).autoQueue(false).blockBag(null).limitUnlimited().build(); + ExtentTraverser last = new ExtentTraverser(es.getExtent()).last(); + if (last.get() instanceof FastWorldEditExtent) last = last.previous(); + last.setNext(generator); + try { + brush.build(es, wPos, context.getMaterial(), context.getSize()); + } catch (WorldEditException e) { + e.printStackTrace(); } + es.flushQueue(); + viewer.view(generator); }, true, true); diff --git a/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/listener/CFIPacketListener.java b/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/listener/CFIPacketListener.java index ea188f757..2053d8f9c 100644 --- a/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/listener/CFIPacketListener.java +++ b/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/listener/CFIPacketListener.java @@ -90,17 +90,13 @@ public class CFIPacketListener implements Listener { PlayerInventory inv = plr.getInventory(); ItemStack hand = enumHand == EnumWrappers.Hand.MAIN_HAND ? inv.getItemInMainHand() : inv.getItemInOffHand(); if (hand != null && hand.getType().isBlock()) { - switch (hand.getType()) { - case AIR: - case CAVE_AIR: - case VOID_AIR: - break; - default: - BlockStateHolder block = BukkitAdapter.asBlockState(hand); - if (block != null) { - gen.setBlock(pt, block); - return; - } + Material type = hand.getType(); + if (!type.isEmpty()) { + BlockStateHolder block = BukkitAdapter.asBlockState(hand); + if (block != null) { + gen.setBlock(pt, block); + return; + } } } pt = getRelPos(event, gen); @@ -201,9 +197,7 @@ public class CFIPacketListener implements Listener { reply.getIntegers().write(0, id); try { protocolmanager.recieveClientPacket(player, reply); - } catch (IllegalAccessException e) { - e.printStackTrace(); - } catch (InvocationTargetException e) { + } catch (IllegalAccessException | InvocationTargetException e) { e.printStackTrace(); } event.setCancelled(true); diff --git a/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/util/VaultUtil.java b/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/util/VaultUtil.java index dfc2cde83..4d0751c94 100644 --- a/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/util/VaultUtil.java +++ b/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/util/VaultUtil.java @@ -8,7 +8,8 @@ public class VaultUtil { public final Permission permission; public VaultUtil() { - final RegisteredServiceProvider permissionProvider = Bukkit.getServer().getServicesManager().getRegistration(net.milkbowl.vault.permission.Permission.class); + final RegisteredServiceProvider permissionProvider = + Bukkit.getServer().getServicesManager().getRegistration(Permission.class); if (permissionProvider != null) { this.permission = permissionProvider.getProvider(); } else { diff --git a/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/v0/BukkitChunk_All.java b/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/v0/BukkitChunk_All.java index cb727178e..96483b7c5 100644 --- a/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/v0/BukkitChunk_All.java +++ b/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/v0/BukkitChunk_All.java @@ -104,7 +104,7 @@ public class BukkitChunk_All extends IntFaweChunk { int[][] sections = getCombinedIdArrays(); final int bx = getX() << 4; final int bz = getZ() << 4; - boolean update = adapter != null ? adapter.isChunkInUse(chunk) : true; + boolean update = adapter == null || adapter.isChunkInUse(chunk); if (layer == -1) { if (adapter != null) { diff --git a/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/v0/BukkitQueue_0.java b/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/v0/BukkitQueue_0.java index ac294817f..65ae8e00d 100644 --- a/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/v0/BukkitQueue_0.java +++ b/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/v0/BukkitQueue_0.java @@ -113,14 +113,15 @@ public abstract class BukkitQueue_0 extends NMSMa WirePacket packet = null; int viewDistance = Bukkit.getViewDistance(); try { - for (int i = 0; i < players.length; i++) { + for (FawePlayer fawePlayer : players) { int cx = chunk.getX(); int cz = chunk.getZ(); - Player player = ((BukkitPlayer) players[i]).parent; + Player player = ((BukkitPlayer) fawePlayer).parent; Location loc = player.getLocation(); - if (Math.abs((loc.getBlockX() >> 4) - cx) <= viewDistance && Math.abs((loc.getBlockZ() >> 4) - cz) <= viewDistance) { + if (Math.abs((loc.getBlockX() >> 4) - cx) <= viewDistance + && Math.abs((loc.getBlockZ() >> 4) - cz) <= viewDistance) { if (packet == null) { byte[] data; byte[] buffer = new byte[8192]; @@ -128,12 +129,12 @@ public abstract class BukkitQueue_0 extends NMSMa chunk = (FaweChunk) chunk.getChunk(); } // TODO FIXME -// if (chunk instanceof MCAChunk) { -// data = new MCAChunkPacket((MCAChunk) chunk, true, true, hasSky()).apply(buffer); -// } else { -// data = new FaweChunkPacket(chunk, true, true, hasSky()).apply(buffer); -// } -// packet = new WirePacket(PacketType.Play.Server.MAP_CHUNK, data); + // if (chunk instanceof MCAChunk) { + // data = new MCAChunkPacket((MCAChunk) chunk, true, true, hasSky()).apply(buffer); + // } else { + // data = new FaweChunkPacket(chunk, true, true, hasSky()).apply(buffer); + // } + // packet = new WirePacket(PacketType.Play.Server.MAP_CHUNK, data); } manager.sendWirePacket(player, packet); } diff --git a/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/v0/BukkitQueue_All.java b/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/v0/BukkitQueue_All.java index 77ea732fc..8960efd76 100644 --- a/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/v0/BukkitQueue_All.java +++ b/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/v0/BukkitQueue_All.java @@ -181,19 +181,16 @@ public class BukkitQueue_All extends BukkitQueue_0 finalUnloaded = unloaded; - TaskManager.IMP.async(new Runnable() { - @Override - public void run() { - for (Chunk chunk : finalUnloaded) { - int cx = chunk.getX(); - int cz = chunk.getZ(); - if (world.isChunkLoaded(cx, cz)) continue; - SetQueue.IMP.addTask(() -> { - world.loadChunk(chunk.getX(), chunk.getZ(), false); - world.refreshChunk(chunk.getX(), chunk.getZ()); - }); + TaskManager.IMP.async(() -> { + for (Chunk chunk : finalUnloaded) { + int cx = chunk.getX(); + int cz = chunk.getZ(); + if (world.isChunkLoaded(cx, cz)) continue; + SetQueue.IMP.addTask(() -> { + world.loadChunk(chunk.getX(), chunk.getZ(), false); + world.refreshChunk(chunk.getX(), chunk.getZ()); + }); - } } }); // load chunks diff --git a/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/v0/ChunkListener.java b/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/v0/ChunkListener.java index e373c9f25..72c9ac673 100644 --- a/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/v0/ChunkListener.java +++ b/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/v0/ChunkListener.java @@ -58,26 +58,23 @@ public abstract class ChunkListener implements Listener { Plugin plugin = Fawe.imp().getPlugin(); plm.registerEvents(this, plugin); try { plm.registerEvents(new ChunkListener_8Plus(this), plugin); } catch (Throwable ignore) {} - TaskManager.IMP.repeat(new Runnable() { - @Override - public void run() { - rateLimit--; - physicsFreeze = false; - itemFreeze = false; - lastZ = Integer.MIN_VALUE; - physSkip = 0; - physCancelPair = Long.MIN_VALUE; - physCancel = false; + TaskManager.IMP.repeat(() -> { + rateLimit--; + physicsFreeze = false; + itemFreeze = false; + lastZ = Integer.MIN_VALUE; + physSkip = 0; + physCancelPair = Long.MIN_VALUE; + physCancel = false; - counter.clear(); - for (Long2ObjectMap.Entry entry : badChunks.long2ObjectEntrySet()) { - long key = entry.getLongKey(); - int x = MathMan.unpairIntX(key); - int z = MathMan.unpairIntY(key); - counter.put(key, badLimit); - } - badChunks.clear(); + counter.clear(); + for (Long2ObjectMap.Entry entry : badChunks.long2ObjectEntrySet()) { + long key = entry.getLongKey(); + int x = MathMan.unpairIntX(key); + int z = MathMan.unpairIntY(key); + counter.put(key, badLimit); } + badChunks.clear(); }, Settings.IMP.TICK_LIMITER.INTERVAL); } } @@ -381,4 +378,4 @@ public abstract class ChunkListener implements Listener { return; } } -} \ No newline at end of file +} diff --git a/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/wrapper/AsyncBlock.java b/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/wrapper/AsyncBlock.java index f9e588f1f..a41583620 100644 --- a/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/wrapper/AsyncBlock.java +++ b/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/wrapper/AsyncBlock.java @@ -204,9 +204,10 @@ public class AsyncBlock implements Block { @Override public BlockFace getFace(Block block) { BlockFace[] directions = BlockFace.values(); - for(int i = 0; i < directions.length; ++i) { - BlockFace face = directions[i]; - if(this.getX() + face.getModX() == block.getX() && this.getY() + face.getModY() == block.getY() && this.getZ() + face.getModZ() == block.getZ()) { + for (BlockFace face : directions) { + if (this.getX() + face.getModX() == block.getX() + && this.getY() + face.getModY() == block.getY() + && this.getZ() + face.getModZ() == block.getZ()) { return face; } } @@ -272,14 +273,7 @@ public class AsyncBlock implements Block { @Override public boolean isEmpty() { - switch (getType()) { - case AIR: - case CAVE_AIR: - case VOID_AIR: - return true; - default: - return false; - } + return getType().isEmpty(); } @Override diff --git a/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/wrapper/AsyncChunk.java b/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/wrapper/AsyncChunk.java index 4c5711ebd..c536f9f8a 100644 --- a/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/wrapper/AsyncChunk.java +++ b/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/wrapper/AsyncChunk.java @@ -29,7 +29,7 @@ public class AsyncChunk implements Chunk { @Override public boolean equals(Object obj) { - if (obj == null || !(obj instanceof Chunk)) { + if (!(obj instanceof Chunk)) { return false; } Chunk other = (Chunk) obj; @@ -88,14 +88,14 @@ public class AsyncChunk implements Chunk { BukkitQueue_0 bq = (BukkitQueue_0) queue; if (world.isChunkLoaded(x, z)) { long pair = MathMan.pairInt(x, z); - Long originalKeep = bq.keepLoaded.get(pair); - bq.keepLoaded.put(pair, Long.MAX_VALUE); + Long originalKeep = BukkitQueue_0.keepLoaded.get(pair); + BukkitQueue_0.keepLoaded.put(pair, Long.MAX_VALUE); if (world.isChunkLoaded(x, z)) { task.run(); if (originalKeep != null) { - bq.keepLoaded.put(pair, originalKeep); + BukkitQueue_0.keepLoaded.put(pair, originalKeep); } else { - bq.keepLoaded.remove(pair); + BukkitQueue_0.keepLoaded.remove(pair); } return task.value; } diff --git a/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/wrapper/AsyncWorld.java b/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/wrapper/AsyncWorld.java index d332f4ddc..2c2bda098 100644 --- a/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/wrapper/AsyncWorld.java +++ b/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/wrapper/AsyncWorld.java @@ -114,7 +114,7 @@ public class AsyncWorld extends DelegateFaweQueue implements World, HasFaweQueue this.parent = parent; this.queue = queue; if (queue instanceof BukkitQueue_0) { - this.adapter = (BukkitImplAdapter) ((BukkitQueue_0) queue).getAdapter(); + this.adapter = BukkitQueue_0.getAdapter(); } else { try { this.adapter = WorldEditPlugin.getInstance().getBukkitImplAdapter(); @@ -141,12 +141,7 @@ public class AsyncWorld extends DelegateFaweQueue implements World, HasFaweQueue if (queue != this.queue) { if (this.queue != null) { final FaweQueue oldQueue = this.queue; - TaskManager.IMP.async(new Runnable() { - @Override - public void run() { - oldQueue.flush(); - } - }); + TaskManager.IMP.async(oldQueue::flush); } this.queue = queue; } @@ -354,7 +349,7 @@ public class AsyncWorld extends DelegateFaweQueue implements World, HasFaweQueue @Override public boolean equals(Object obj) { - if (obj == null || !(obj instanceof World)) { + if (!(obj instanceof World)) { return false; } World other = (World) obj; @@ -571,7 +566,7 @@ public class AsyncWorld extends DelegateFaweQueue implements World, HasFaweQueue return TaskManager.IMP.sync(new RunnableVal>() { @Override public void run(Collection value) { - this.value = (Collection) parent.getEntitiesByClass(classes); + this.value = parent.getEntitiesByClass(classes); } }); } @@ -581,7 +576,7 @@ public class AsyncWorld extends DelegateFaweQueue implements World, HasFaweQueue return TaskManager.IMP.sync(new RunnableVal>() { @Override public void run(Collection value) { - this.value = (Collection) parent.getEntitiesByClass(cls); + this.value = parent.getEntitiesByClass(cls); } }); } @@ -799,22 +794,12 @@ public class AsyncWorld extends DelegateFaweQueue implements World, HasFaweQueue @Override @Deprecated public FallingBlock spawnFallingBlock(Location location, Material material, byte data) throws IllegalArgumentException { - return TaskManager.IMP.sync(new Supplier() { - @Override - public FallingBlock get() { - return parent.spawnFallingBlock(location, material, data); - } - }); + return TaskManager.IMP.sync(() -> parent.spawnFallingBlock(location, material, data)); } @Override public FallingBlock spawnFallingBlock(Location location, BlockData blockData) throws IllegalArgumentException { - return TaskManager.IMP.sync(new Supplier() { - @Override - public FallingBlock get() { - return parent.spawnFallingBlock(location, blockData); - } - }); + return TaskManager.IMP.sync(() -> parent.spawnFallingBlock(location, blockData)); } @Override