From a64d764cc14d465c9bbd5affe9e20d1d99c8e6eb Mon Sep 17 00:00:00 2001 From: matt <4009945+MattBDev@users.noreply.github.com> Date: Fri, 15 Feb 2019 12:50:43 -0500 Subject: [PATCH] New API method, more 1.13 entity support, and cleanup. Signed-off-by: matt <4009945+MattBDev@users.noreply.github.com> --- .../plotsquared/bukkit/BukkitMain.java | 437 +++++++++--------- .../bukkit/generator/BukkitPlotGenerator.java | 18 +- .../entity/ReplicatingEntityWrapper.java | 58 ++- .../plotsquared/bukkit/util/NbtFactory.java | 25 +- .../bukkit/util/block/GenChunk.java | 10 +- .../configuration/file/FileConfiguration.java | 22 +- .../plotsquared/plot/PlotSquared.java | 7 + .../plotsquared/plot/object/Plot.java | 14 +- .../plotsquared/plot/object/PlotPlayer.java | 2 +- .../plot/object/schematic/Schematic.java | 8 +- .../plot/util/SchematicHandler.java | 18 +- .../plotsquared/plot/util/WorldUtil.java | 13 +- 12 files changed, 319 insertions(+), 313 deletions(-) diff --git a/Bukkit/src/main/java/com/github/intellectualsites/plotsquared/bukkit/BukkitMain.java b/Bukkit/src/main/java/com/github/intellectualsites/plotsquared/bukkit/BukkitMain.java index 9c2bc49db..5060e4f4a 100644 --- a/Bukkit/src/main/java/com/github/intellectualsites/plotsquared/bukkit/BukkitMain.java +++ b/Bukkit/src/main/java/com/github/intellectualsites/plotsquared/bukkit/BukkitMain.java @@ -30,6 +30,7 @@ import com.sk89q.worldedit.bukkit.WorldEditPlugin; import com.sk89q.worldedit.extension.platform.Capability; import lombok.Getter; import lombok.NonNull; +import org.bstats.bukkit.Metrics; import org.bukkit.*; import org.bukkit.Location; import org.bukkit.command.PluginCommand; @@ -287,244 +288,248 @@ public final class BukkitMain extends JavaPlugin implements Listener, IPlotMain @Override @SuppressWarnings("deprecation") public void runEntityTask() { PlotSquared.log(C.PREFIX + "KillAllEntities started."); - TaskManager - .runTaskRepeat(() -> PlotSquared.get().foreachPlotArea(new RunnableVal() { - @Override public void run(PlotArea plotArea) { - final World world = Bukkit.getWorld(plotArea.worldname); - try { - if (world == null) { - return; - } - List entities = world.getEntities(); - Iterator iterator = entities.iterator(); - while (iterator.hasNext()) { - Entity entity = iterator.next(); - switch (entity.getType()) { - case EGG: - case COMPLEX_PART: - case FISHING_HOOK: - case ENDER_SIGNAL: - case LINGERING_POTION: - case AREA_EFFECT_CLOUD: - case EXPERIENCE_ORB: - case LEASH_HITCH: - case FIREWORK: - case WEATHER: - case LIGHTNING: - case WITHER_SKULL: - case UNKNOWN: - case PLAYER: - // non moving / unmovable + TaskManager.runTaskRepeat(() -> PlotSquared.get().forEachPlotArea(plotArea -> { + final World world = Bukkit.getWorld(plotArea.worldname); + try { + if (world == null) { + return; + } + List entities = world.getEntities(); + Iterator iterator = entities.iterator(); + while (iterator.hasNext()) { + Entity entity = iterator.next(); + switch (entity.getType()) { + case EGG: + case COMPLEX_PART: + case FISHING_HOOK: + case ENDER_SIGNAL: + case LINGERING_POTION: + case AREA_EFFECT_CLOUD: + case EXPERIENCE_ORB: + case LEASH_HITCH: + case FIREWORK: + case WEATHER: + case LIGHTNING: + case WITHER_SKULL: + case UNKNOWN: + case PLAYER: + // non moving / unmovable + continue; + case THROWN_EXP_BOTTLE: + case SPLASH_POTION: + case SNOWBALL: + case SHULKER_BULLET: + case SPECTRAL_ARROW: + case TIPPED_ARROW: + case ENDER_PEARL: + case ARROW: + case LLAMA_SPIT: + case TRIDENT: + // managed elsewhere | projectile + continue; + case ITEM_FRAME: + case PAINTING: + // Not vehicles + continue; + case ARMOR_STAND: + // Temporarily classify as vehicle + case MINECART: + case MINECART_CHEST: + case MINECART_COMMAND: + case MINECART_FURNACE: + case MINECART_HOPPER: + case MINECART_MOB_SPAWNER: + case ENDER_CRYSTAL: + case MINECART_TNT: + case BOAT: + if (Settings.Enabled_Components.KILL_ROAD_VEHICLES) { + com.github.intellectualsites.plotsquared.plot.object.Location + location = BukkitUtil.getLocation(entity.getLocation()); + Plot plot = location.getPlot(); + if (plot == null) { + if (location.isPlotArea()) { + if (entity.hasMetadata("ps-tmp-teleport")) { + continue; + } + iterator.remove(); + entity.remove(); + } continue; - case THROWN_EXP_BOTTLE: - case SPLASH_POTION: - case SNOWBALL: - case SHULKER_BULLET: - case SPECTRAL_ARROW: - case TIPPED_ARROW: - case ENDER_PEARL: - case ARROW: - case LLAMA_SPIT: - case TRIDENT: - // managed elsewhere | projectile + } + List meta = entity.getMetadata("plot"); + if (meta.isEmpty()) { continue; - case ITEM_FRAME: - case PAINTING: - // Not vehicles - continue; - case ARMOR_STAND: - // Temporarily classify as vehicle - case MINECART: - case MINECART_CHEST: - case MINECART_COMMAND: - case MINECART_FURNACE: - case MINECART_HOPPER: - case MINECART_MOB_SPAWNER: - case ENDER_CRYSTAL: - case MINECART_TNT: - case BOAT: - if (Settings.Enabled_Components.KILL_ROAD_VEHICLES) { + } + Plot origin = (Plot) meta.get(0).value(); + if (!plot.equals(origin.getBasePlot(false))) { + if (entity.hasMetadata("ps-tmp-teleport")) { + continue; + } + iterator.remove(); + entity.remove(); + } + } + continue; + case SMALL_FIREBALL: + case FIREBALL: + case DRAGON_FIREBALL: + case DROPPED_ITEM: + if (Settings.Enabled_Components.KILL_ROAD_ITEMS && plotArea + .getOwnedPlotAbs(BukkitUtil.getLocation(entity.getLocation())) + == null) { + entity.remove(); + } + // dropped item + continue; + case PRIMED_TNT: + case FALLING_BLOCK: + // managed elsewhere + continue; + case SHULKER: + if (Settings.Enabled_Components.KILL_ROAD_MOBS) { + LivingEntity livingEntity = (LivingEntity) entity; + List meta = entity.getMetadata("plot"); + if (meta != null && !meta.isEmpty()) { + if (livingEntity.isLeashed()) { + continue; + } + List keep = entity.getMetadata("keep"); + if (keep != null && !keep.isEmpty()) { + continue; + } + + PlotId originalPlotId = (PlotId) meta.get(0).value(); + if (originalPlotId != null) { com.github.intellectualsites.plotsquared.plot.object.Location - location = BukkitUtil.getLocation(entity.getLocation()); - Plot plot = location.getPlot(); - if (plot == null) { - if (location.isPlotArea()) { + pLoc = BukkitUtil.getLocation(entity.getLocation()); + PlotArea area = pLoc.getPlotArea(); + if (area != null) { + PlotId currentPlotId = PlotId.of(area.getPlotAbs(pLoc)); + if (!originalPlotId.equals(currentPlotId) && ( + currentPlotId == null || !area + .getPlot(originalPlotId) + .equals(area.getPlot(currentPlotId)))) { if (entity.hasMetadata("ps-tmp-teleport")) { continue; } iterator.remove(); entity.remove(); } - continue; } - List meta = entity.getMetadata("plot"); - if (meta.isEmpty()) { - continue; + } + } else { + //This is to apply the metadata to already spawned shulkers (see EntitySpawnListener.java) + com.github.intellectualsites.plotsquared.plot.object.Location + pLoc = BukkitUtil.getLocation(entity.getLocation()); + PlotArea area = pLoc.getPlotArea(); + if (area != null) { + PlotId currentPlotId = PlotId.of(area.getPlotAbs(pLoc)); + if (currentPlotId != null) { + entity.setMetadata("plot", new FixedMetadataValue( + (Plugin) PlotSquared.get().IMP, currentPlotId)); } - Plot origin = (Plot) meta.get(0).value(); - if (!plot.equals(origin.getBasePlot(false))) { + } + } + } + continue; + case LLAMA: + case DONKEY: + case MULE: + case ZOMBIE_HORSE: + case SKELETON_HORSE: + case HUSK: + case ELDER_GUARDIAN: + case WITHER_SKELETON: + case STRAY: + case ZOMBIE_VILLAGER: + case EVOKER: + case EVOKER_FANGS: + case VEX: + case VINDICATOR: + case POLAR_BEAR: + case BAT: + case BLAZE: + case CAVE_SPIDER: + case CHICKEN: + case COW: + case CREEPER: + case ENDERMAN: + case ENDERMITE: + case ENDER_DRAGON: + case GHAST: + case GIANT: + case GUARDIAN: + case HORSE: + case IRON_GOLEM: + case MAGMA_CUBE: + case MUSHROOM_COW: + case OCELOT: + case PIG: + case PIG_ZOMBIE: + case RABBIT: + case SHEEP: + case SILVERFISH: + case SKELETON: + case SLIME: + case SNOWMAN: + case SPIDER: + case SQUID: + case VILLAGER: + case WITCH: + case WITHER: + case WOLF: + case ZOMBIE: + case PARROT: + case SALMON: + case DOLPHIN: + case TROPICAL_FISH: + case DROWNED: + case COD: + case TURTLE: + case PUFFERFISH: + case PHANTOM: + case ILLUSIONER: + default: { + if (Settings.Enabled_Components.KILL_ROAD_MOBS) { + Location location = entity.getLocation(); + if (BukkitUtil.getLocation(location).isPlotRoad()) { + if (entity instanceof LivingEntity) { + LivingEntity livingEntity = (LivingEntity) entity; + if (!livingEntity.isLeashed() || !entity + .hasMetadata("keep")) { + Entity passenger = entity.getPassenger(); + if (!(passenger instanceof Player) && entity + .getMetadata("keep").isEmpty()) { + if (entity.hasMetadata("ps-tmp-teleport")) { + continue; + } + iterator.remove(); + entity.remove(); + continue; + } + } + } else { + Entity passenger = entity.getPassenger(); + if (!(passenger instanceof Player) && entity + .getMetadata("keep").isEmpty()) { if (entity.hasMetadata("ps-tmp-teleport")) { continue; } iterator.remove(); entity.remove(); + continue; } } - continue; - case SMALL_FIREBALL: - case FIREBALL: - case DRAGON_FIREBALL: - case DROPPED_ITEM: - if (Settings.Enabled_Components.KILL_ROAD_ITEMS && plotArea - .getOwnedPlotAbs( - BukkitUtil.getLocation(entity.getLocation())) == null) { - entity.remove(); - } - // dropped item - continue; - case PRIMED_TNT: - case FALLING_BLOCK: - // managed elsewhere - continue; - case SHULKER: - if (Settings.Enabled_Components.KILL_ROAD_MOBS) { - LivingEntity livingEntity = (LivingEntity) entity; - List meta = entity.getMetadata("plot"); - if (meta != null && !meta.isEmpty()) { - if (livingEntity.isLeashed()) - continue; - List keep = entity.getMetadata("keep"); - if (keep != null && !keep.isEmpty()) - continue; - - PlotId originalPlotId = (PlotId) meta.get(0).value(); - if (originalPlotId != null) { - com.github.intellectualsites.plotsquared.plot.object.Location - pLoc = - BukkitUtil.getLocation(entity.getLocation()); - PlotArea area = pLoc.getPlotArea(); - if (area != null) { - PlotId currentPlotId = - PlotId.of(area.getPlotAbs(pLoc)); - if (!originalPlotId.equals(currentPlotId) && ( - currentPlotId == null || !area - .getPlot(originalPlotId) - .equals(area.getPlot(currentPlotId)))) { - if (entity.hasMetadata("ps-tmp-teleport")) { - continue; - } - iterator.remove(); - entity.remove(); - } - } - } - } else { - //This is to apply the metadata to already spawned shulkers (see EntitySpawnListener.java) - com.github.intellectualsites.plotsquared.plot.object.Location - pLoc = BukkitUtil.getLocation(entity.getLocation()); - PlotArea area = pLoc.getPlotArea(); - if (area != null) { - PlotId currentPlotId = - PlotId.of(area.getPlotAbs(pLoc)); - if (currentPlotId != null) { - entity.setMetadata("plot", - new FixedMetadataValue( - (Plugin) PlotSquared.get().IMP, - currentPlotId)); - } - } - } - } - continue; - case LLAMA: - case DONKEY: - case MULE: - case ZOMBIE_HORSE: - case SKELETON_HORSE: - case HUSK: - case ELDER_GUARDIAN: - case WITHER_SKELETON: - case STRAY: - case ZOMBIE_VILLAGER: - case EVOKER: - case EVOKER_FANGS: - case VEX: - case VINDICATOR: - case POLAR_BEAR: - case BAT: - case BLAZE: - case CAVE_SPIDER: - case CHICKEN: - case COW: - case CREEPER: - case ENDERMAN: - case ENDERMITE: - case ENDER_DRAGON: - case GHAST: - case GIANT: - case GUARDIAN: - case HORSE: - case IRON_GOLEM: - case MAGMA_CUBE: - case MUSHROOM_COW: - case OCELOT: - case PIG: - case PIG_ZOMBIE: - case RABBIT: - case SHEEP: - case SILVERFISH: - case SKELETON: - case SLIME: - case SNOWMAN: - case SPIDER: - case SQUID: - case VILLAGER: - case WITCH: - case WITHER: - case WOLF: - case ZOMBIE: - default: { - if (Settings.Enabled_Components.KILL_ROAD_MOBS) { - Location location = entity.getLocation(); - if (BukkitUtil.getLocation(location).isPlotRoad()) { - if (entity instanceof LivingEntity) { - LivingEntity livingEntity = (LivingEntity) entity; - if (!livingEntity.isLeashed() || !entity - .hasMetadata("keep")) { - Entity passenger = entity.getPassenger(); - if (!(passenger instanceof Player) && entity - .getMetadata("keep").isEmpty()) { - if (entity.hasMetadata("ps-tmp-teleport")) { - continue; - } - iterator.remove(); - entity.remove(); - continue; - } - } - } else { - Entity passenger = entity.getPassenger(); - if (!(passenger instanceof Player) && entity - .getMetadata("keep").isEmpty()) { - if (entity.hasMetadata("ps-tmp-teleport")) { - continue; - } - iterator.remove(); - entity.remove(); - continue; - } - } - } - } - continue; } } + continue; } - } catch (Throwable e) { - e.printStackTrace(); } } - }), 20); + } catch (Throwable e) { + e.printStackTrace(); + } + }), 20); } @Override @Nullable @@ -701,7 +706,7 @@ public final class BukkitMain extends JavaPlugin implements Listener, IPlotMain } System.setProperty("bstats.relocatecheck", "false"); // We do not want to relocate the package... - new org.bstats.bukkit.Metrics(this); // bstats + Metrics metrics = new Metrics(this);// bstats PlotSquared.log(C.PREFIX + "&6Metrics enabled."); this.metricsStarted = true; } diff --git a/Bukkit/src/main/java/com/github/intellectualsites/plotsquared/bukkit/generator/BukkitPlotGenerator.java b/Bukkit/src/main/java/com/github/intellectualsites/plotsquared/bukkit/generator/BukkitPlotGenerator.java index 6be860b32..affb0461e 100644 --- a/Bukkit/src/main/java/com/github/intellectualsites/plotsquared/bukkit/generator/BukkitPlotGenerator.java +++ b/Bukkit/src/main/java/com/github/intellectualsites/plotsquared/bukkit/generator/BukkitPlotGenerator.java @@ -128,7 +128,7 @@ public class BukkitPlotGenerator extends ChunkGenerator result.setBiome(x, z, biome.name()); } - @Override public Biome getBiome(int arg0, int arg1) { + @Override public Biome getBiome(int x, int z) { return Biome.FOREST; } }; @@ -142,7 +142,7 @@ public class BukkitPlotGenerator extends ChunkGenerator } /* TODO: Redo this // Populator spillage - short[][] tmp = cg.generateExtBlockSections(w, r, cx, cz, grid); + short[][] tmp = cg.generateExtBlockSections(w, r, cx, cz, biomeGrid); if (tmp != null) { for (int i = 0; i < tmp.length; i++) { short[] section = tmp[i]; @@ -235,30 +235,30 @@ public class BukkitPlotGenerator extends ChunkGenerator } @Override - public ChunkData generateChunkData(World world, Random random, int cx, int cz, BiomeGrid grid) { + public ChunkData generateChunkData(World world, Random random, int x, int z, BiomeGrid biome) { GenChunk result = this.chunkSetter; if (this.getPlotGenerator() instanceof SingleWorldGenerator) { if (result.getCd() != null) { - for (int x = 0; x < 16; x++) { - for (int z = 0; z < 16; z++) { - grid.setBiome(x, z, Biome.PLAINS); + for (int cx = 0; cx < 16; cx++) { + for (int cz = 0; cz < 16; cz++) { + biome.setBiome(cx, cz, Biome.PLAINS); } } return result.getCd(); } } // Set the chunk location - result.setChunk(new ChunkWrapper(world.getName(), cx, cz)); + result.setChunk(new ChunkWrapper(world.getName(), x, z)); // Set the result data result.setCd(createChunkData(world)); - result.grid = grid; + result.biomeGrid = biome; result.result = null; // Catch any exceptions (as exceptions usually thrown) try { // Fill the result data if necessary if (this.platformGenerator != this) { - return this.platformGenerator.generateChunkData(world, random, cx, cz, grid); + return this.platformGenerator.generateChunkData(world, random, x, z, biome); } else { generate(world, result); } diff --git a/Bukkit/src/main/java/com/github/intellectualsites/plotsquared/bukkit/object/entity/ReplicatingEntityWrapper.java b/Bukkit/src/main/java/com/github/intellectualsites/plotsquared/bukkit/object/entity/ReplicatingEntityWrapper.java index 6c1eab0c7..dfcf03a9a 100644 --- a/Bukkit/src/main/java/com/github/intellectualsites/plotsquared/bukkit/object/entity/ReplicatingEntityWrapper.java +++ b/Bukkit/src/main/java/com/github/intellectualsites/plotsquared/bukkit/object/entity/ReplicatingEntityWrapper.java @@ -16,7 +16,7 @@ public final class ReplicatingEntityWrapper extends EntityWrapper { private final int hash; private final EntityBaseStats base = new EntityBaseStats(); - public ItemStack[] inventory; + private ItemStack[] inventory; // Extended private ItemStack stack; private byte dataByte; @@ -94,6 +94,8 @@ public final class ReplicatingEntityWrapper extends EntityWrapper { case DRAGON_FIREBALL: case LINGERING_POTION: case AREA_EFFECT_CLOUD: + case TRIDENT: + case LLAMA_SPIT: // Do this stuff later return; // MISC // @@ -132,13 +134,21 @@ public final class ReplicatingEntityWrapper extends EntityWrapper { // START AGEABLE // // START TAMEABLE // case HORSE: - Horse horse = (Horse) entity; + case DONKEY: + case LLAMA: + case MULE: + case SKELETON_HORSE: + AbstractHorse horse = (AbstractHorse) entity; this.horse = new HorseStats(); this.horse.jump = horse.getJumpStrength(); - this.horse.chest = horse.isCarryingChest(); - this.horse.variant = horse.getVariant(); - this.horse.style = horse.getStyle(); - this.horse.color = horse.getColor(); + if (horse instanceof ChestedHorse) { + ChestedHorse horse1 = (ChestedHorse) horse; + this.horse.chest = horse1.isCarryingChest(); + } + //todo these horse feeatures need fixing + //this.horse.variant = horse.getVariant(); + //this.horse.style = horse.getStyle(); + //this.horse.color = horse.getColor(); storeTameable(horse); storeAgeable(horse); storeLiving(horse); @@ -164,6 +174,7 @@ public final class ReplicatingEntityWrapper extends EntityWrapper { case COW: case MUSHROOM_COW: case PIG: + case TURTLE: case POLAR_BEAR: storeAgeable((Ageable) entity); storeLiving((LivingEntity) entity); @@ -174,16 +185,6 @@ public final class ReplicatingEntityWrapper extends EntityWrapper { storeLiving((LivingEntity) entity); return; // END AGEABLE // - //todo this needs to be fixed - case GUARDIAN: - case ELDER_GUARDIAN: - storeLiving((LivingEntity) entity); - return; - //todo this needs to be fixed - case SKELETON: - case WITHER_SKELETON: - storeLiving((LivingEntity) entity); - return; case ARMOR_STAND: ArmorStand stand = (ArmorStand) entity; this.inventory = @@ -249,6 +250,10 @@ public final class ReplicatingEntityWrapper extends EntityWrapper { EnderDragon entity1 = (EnderDragon) entity; this.dataByte = (byte) entity1.getPhase().ordinal(); return; + case SKELETON: + case WITHER_SKELETON: + case GUARDIAN: + case ELDER_GUARDIAN: case GHAST: case MAGMA_CUBE: case SQUID: @@ -487,6 +492,8 @@ public final class ReplicatingEntityWrapper extends EntityWrapper { case DRAGON_FIREBALL: case WITHER_SKULL: case MINECART_FURNACE: + case LLAMA_SPIT: + case TRIDENT: case UNKNOWN: // Do this stuff later return entity; @@ -510,14 +517,20 @@ public final class ReplicatingEntityWrapper extends EntityWrapper { // START LIVING ENTITY // // START AGEABLE // // START TAMEABLE // - //todo this needs to be fixed case HORSE: - Horse horse = (Horse) entity; + case LLAMA: + case SKELETON_HORSE: + case DONKEY: + case MULE: + AbstractHorse horse = (AbstractHorse) entity; horse.setJumpStrength(this.horse.jump); - horse.setCarryingChest(this.horse.chest); - horse.setVariant(this.horse.variant); - horse.setStyle(this.horse.style); - horse.setColor(this.horse.color); + if (horse instanceof ChestedHorse) { + ((ChestedHorse) horse).setCarryingChest(this.horse.chest); + } + //todo broken as of 1.13 + //horse.setVariant(this.horse.variant); + //horse.setStyle(this.horse.style); + //horse.setColor(this.horse.color); restoreTameable(horse); restoreAgeable(horse); restoreLiving(horse); @@ -545,6 +558,7 @@ public final class ReplicatingEntityWrapper extends EntityWrapper { case VILLAGER: case CHICKEN: case COW: + case TURTLE: case POLAR_BEAR: case MUSHROOM_COW: case PIG: diff --git a/Bukkit/src/main/java/com/github/intellectualsites/plotsquared/bukkit/util/NbtFactory.java b/Bukkit/src/main/java/com/github/intellectualsites/plotsquared/bukkit/util/NbtFactory.java index ffc69edfc..6a9017cf8 100644 --- a/Bukkit/src/main/java/com/github/intellectualsites/plotsquared/bukkit/util/NbtFactory.java +++ b/Bukkit/src/main/java/com/github/intellectualsites/plotsquared/bukkit/util/NbtFactory.java @@ -154,7 +154,7 @@ public class NbtFactory { * @return The decoded NBT compound. * @throws IOException If anything went wrong. */ - public static NbtCompound fromStream(InputStream input, StreamOptions option) + @SuppressWarnings({"IOResourceOpenedButNotSafelyClosed", "resource"}) public static NbtCompound fromStream(InputStream input, StreamOptions option) throws IOException { DataInputStream data = null; boolean suppress = true; @@ -189,24 +189,11 @@ public class NbtFactory { */ public static void saveStream(NbtCompound source, ByteSink stream, StreamOptions option) throws IOException { - OutputStream output = null; - DataOutputStream data = null; - boolean suppress = true; - - try { - output = stream.openStream(); - data = new DataOutputStream( - option == StreamOptions.GZIP_COMPRESSION ? new GZIPOutputStream(output) : output); + try (OutputStream output = stream.openStream(); + DataOutputStream data = new DataOutputStream( + option == StreamOptions.GZIP_COMPRESSION ? new GZIPOutputStream(output) : output)) { invokeMethod(get().SAVE_COMPOUND, null, source.getHandle(), data); - suppress = false; - - } finally { - if (data != null) { - Closeables.close(data, suppress); - } else if (output != null) { - Closeables.close(output, suppress); - } } } @@ -540,9 +527,7 @@ public class NbtFactory { * * @author Kristian */ - public enum StreamOptions { - NO_COMPRESSION, GZIP_COMPRESSION, - } + public enum StreamOptions {NO_COMPRESSION, GZIP_COMPRESSION,} private enum NbtType { diff --git a/Bukkit/src/main/java/com/github/intellectualsites/plotsquared/bukkit/util/block/GenChunk.java b/Bukkit/src/main/java/com/github/intellectualsites/plotsquared/bukkit/util/block/GenChunk.java index b905c2d5b..90a42db9b 100644 --- a/Bukkit/src/main/java/com/github/intellectualsites/plotsquared/bukkit/util/block/GenChunk.java +++ b/Bukkit/src/main/java/com/github/intellectualsites/plotsquared/bukkit/util/block/GenChunk.java @@ -23,7 +23,7 @@ public class GenChunk extends ScopedLocalBlockQueue { public final Biome[] biomes; public PlotBlock[][] result; - public BiomeGrid grid; + public BiomeGrid biomeGrid; public Chunk chunk; public String world; public int cx; @@ -57,13 +57,13 @@ public class GenChunk extends ScopedLocalBlockQueue { } @Override public void fillBiome(String biomeName) { - if (grid == null) { + if (biomeGrid == null) { return; } Biome biome = Biome.valueOf(biomeName.toUpperCase()); for (int x = 0; x < 16; x++) { for (int z = 0; z < 16; z++) { - this.grid.setBiome(x, z, biome); + this.biomeGrid.setBiome(x, z, biome); } } } @@ -96,8 +96,8 @@ public class GenChunk extends ScopedLocalBlockQueue { } public boolean setBiome(int x, int z, Biome biome) { - if (this.grid != null) { - this.grid.setBiome(x, z, biome); + if (this.biomeGrid != null) { + this.biomeGrid.setBiome(x, z, biome); return true; } return false; diff --git a/Core/src/main/java/com/github/intellectualsites/plotsquared/configuration/file/FileConfiguration.java b/Core/src/main/java/com/github/intellectualsites/plotsquared/configuration/file/FileConfiguration.java index 442668ee1..a56c65901 100644 --- a/Core/src/main/java/com/github/intellectualsites/plotsquared/configuration/file/FileConfiguration.java +++ b/Core/src/main/java/com/github/intellectualsites/plotsquared/configuration/file/FileConfiguration.java @@ -15,13 +15,13 @@ import java.util.stream.Collectors; public abstract class FileConfiguration extends MemoryConfiguration { /** - * Creates an empty {@link FileConfiguration} with no default values. + * Creates an empty FileConfiguration with no default values. */ FileConfiguration() { } /** - * Creates an empty {@link FileConfiguration} using the specified {@link + * Creates an empty FileConfiguration using the specified {@link * Configuration} as a source for all default values. * * @param defaults Default value provider @@ -31,7 +31,7 @@ public abstract class FileConfiguration extends MemoryConfiguration { } /** - * Saves this {@link FileConfiguration} to the specified location. + * Saves this FileConfiguration to the specified location. * *

If the file does not exist, it will be created. If already exists, it * will be overwritten. If it cannot be overwritten or created, an @@ -59,14 +59,14 @@ public abstract class FileConfiguration extends MemoryConfiguration { } /** - * Saves this {@link FileConfiguration} to a string, and returns it. + * Saves this FileConfiguration to a string, and returns it. * * @return String containing this configuration. */ public abstract String saveToString(); /** - * Loads this {@link FileConfiguration} from the specified location. + * Loads this FileConfiguration from the specified location. * *

All the values contained within this configuration will be removed, * leaving only settings and defaults, and the new values will be loaded @@ -85,13 +85,13 @@ public abstract class FileConfiguration extends MemoryConfiguration { */ public void load(File file) throws IOException, InvalidConfigurationException { - FileInputStream stream = new FileInputStream(file); - - load(new InputStreamReader(stream, StandardCharsets.UTF_8)); + try (FileInputStream stream = new FileInputStream(file)) { + load(new InputStreamReader(stream, StandardCharsets.UTF_8)); + } } /** - * Loads this {@link FileConfiguration} from the specified reader. + * Loads this FileConfiguration from the specified reader. * *

All the values contained within this configuration will be removed, * leaving only settings and defaults, and the new values will be loaded @@ -117,7 +117,7 @@ public abstract class FileConfiguration extends MemoryConfiguration { } /** - * Loads this {@link FileConfiguration} from the specified string, as + * Loads this FileConfiguration from the specified string, as * opposed to from file. * *

All the values contained within this configuration will be removed, @@ -133,7 +133,7 @@ public abstract class FileConfiguration extends MemoryConfiguration { public abstract void loadFromString(String contents) throws InvalidConfigurationException; /** - * Compiles the header for this {@link FileConfiguration} and returns the + * Compiles the header for this FileConfiguration and returns the * result. * *

This will use the header from {@link #options()} -> {@link diff --git a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/PlotSquared.java b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/PlotSquared.java index 44ba326c8..87f8f209d 100644 --- a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/PlotSquared.java +++ b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/PlotSquared.java @@ -41,6 +41,7 @@ import java.nio.file.Files; import java.sql.SQLException; import java.util.*; import java.util.Map.Entry; +import java.util.function.Consumer; import java.util.regex.Pattern; import java.util.zip.ZipEntry; import java.util.zip.ZipInputStream; @@ -1817,6 +1818,12 @@ import java.util.zip.ZipInputStream; return Double.parseDouble(System.getProperty("java.specification.version")); } + public void forEachPlotArea(Consumer action) { + for (final PlotArea area : this.plotAreaManager.getAllPlotAreas()) { + action.accept(area); + } + } + public void foreachPlotArea(@Nonnull final RunnableVal runnable) { for (final PlotArea area : this.plotAreaManager.getAllPlotAreas()) { runnable.run(area); diff --git a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/object/Plot.java b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/object/Plot.java index b3e4c88af..53b74d402 100644 --- a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/object/Plot.java +++ b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/object/Plot.java @@ -1513,6 +1513,7 @@ public class Plot { return WorldUtil.IMP.getBiome(loc.getWorld(), loc.getX(), loc.getZ()); } + //TODO Better documentation needed. /** * Return the top location for the plot. * @@ -1525,7 +1526,6 @@ public class Plot { } //TODO Better documentation needed. - /** * Return the bottom location for the plot. */ @@ -1573,7 +1573,7 @@ public class Plot { } /** - * Move the settings for a plot. + * Moves the settings for a plot. * * @param plot the plot to move * @param whenDone @@ -1710,7 +1710,7 @@ public class Plot { } /** - * Move the plot to an empty location
+ * Moves the plot to an empty location
* - The location must be empty * * @param destination Where to move the plot @@ -2616,6 +2616,7 @@ public class Plot { } /** + * * Do the plot entry tasks for each player in the plot
* - Usually called when the plot state changes (unclaimed/claimed/flag change etc) */ @@ -2735,12 +2736,9 @@ public class Plot { } /** - * Expand the world border to include the provided plot (if applicable). + * Expands the world border to include this plot if it is beyond the current border. */ public void updateWorldBorder() { - if (this.owner == null) { - return; - } int border = this.area.getBorder(); if (border == Integer.MAX_VALUE) { return; @@ -2811,7 +2809,7 @@ public class Plot { } /** - * Move a plot physically, as well as the corresponding settings. + * Moves a plot physically, as well as the corresponding settings. * * @param destination Plot moved to * @param whenDone task when done diff --git a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/object/PlotPlayer.java b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/object/PlotPlayer.java index d2767e90d..3e41d1cb5 100644 --- a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/object/PlotPlayer.java +++ b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/object/PlotPlayer.java @@ -655,7 +655,7 @@ public abstract class PlotPlayer implements CommandCaller, OfflinePlotPlayer { } } - public interface PlotPlayerConverter { + @FunctionalInterface public interface PlotPlayerConverter { PlotPlayer convert(BaseObject object); } } diff --git a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/object/schematic/Schematic.java b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/object/schematic/Schematic.java index df20b3300..b67b16b58 100644 --- a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/object/schematic/Schematic.java +++ b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/object/schematic/Schematic.java @@ -39,9 +39,9 @@ public class Schematic { } public void save(File file) throws IOException { - SpongeSchematicWriter ssw = - new SpongeSchematicWriter(new NBTOutputStream(new FileOutputStream(file))); - ssw.write(clipboard); - ssw.close(); + try (SpongeSchematicWriter ssw = new SpongeSchematicWriter( + new NBTOutputStream(new FileOutputStream(file)))) { + ssw.write(clipboard); + } } } diff --git a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/util/SchematicHandler.java b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/util/SchematicHandler.java index 6957e858a..38869c2ee 100644 --- a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/util/SchematicHandler.java +++ b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/util/SchematicHandler.java @@ -87,7 +87,7 @@ public abstract class SchematicHandler { } else { MainUtil.sendMessage(null, "&7 - &a success: " + plot.getId()); } - TaskManager.runTask(THIS::run); + TaskManager.runTask(THIS); }); } } @@ -104,7 +104,6 @@ public abstract class SchematicHandler { * @param plot plot to paste in * @param xOffset offset x to paste it from plot origin * @param zOffset offset z to paste it from plot origin - * @return boolean true if succeeded */ public void paste(final Schematic schematic, final Plot plot, final int xOffset, final int yOffset, final int zOffset, final boolean autoHeight, @@ -126,7 +125,7 @@ public abstract class SchematicHandler { if (!flags.isEmpty()) { for (Map.Entry entry : flags.entrySet()) { plot.setFlag(Flags.getFlag(entry.getKey()), - StringTag.class.cast(entry.getValue()).getValue()); + ((StringTag) entry.getValue()).getValue()); } } @@ -341,20 +340,17 @@ public abstract class SchematicHandler { } public List getSaves(UUID uuid) { - StringBuilder rawJSON = new StringBuilder(); + String rawJSON = ""; try { String website = Settings.Web.URL + "list.php?" + uuid.toString(); URL url = new URL(website); URLConnection connection = new URL(url.toString()).openConnection(); connection.setRequestProperty("User-Agent", "Mozilla/5.0"); - BufferedReader reader = - new BufferedReader(new InputStreamReader(connection.getInputStream())); - String line; - while ((line = reader.readLine()) != null) { - rawJSON.append(line); + try (BufferedReader reader = new BufferedReader( + new InputStreamReader(connection.getInputStream()))) { + rawJSON = reader.lines().collect(Collectors.joining()); } - reader.close(); - JSONArray array = new JSONArray(rawJSON.toString()); + JSONArray array = new JSONArray(rawJSON); List schematics = new ArrayList<>(); for (int i = 0; i < array.length(); i++) { String schematic = array.getString(i); diff --git a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/util/WorldUtil.java b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/util/WorldUtil.java index bb376f431..2e05542aa 100644 --- a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/util/WorldUtil.java +++ b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/util/WorldUtil.java @@ -78,13 +78,14 @@ public abstract class WorldUtil { map.put("SpawnX", new IntTag(home.getX())); map.put("SpawnY", new IntTag(home.getY())); map.put("SpawnZ", new IntTag(home.getZ())); - ByteArrayOutputStream baos = new ByteArrayOutputStream(); - try (NBTOutputStream out = new NBTOutputStream( - new GZIPOutputStream(baos, true))) { - //TODO Find what this should be called - out.writeNamedTag("Schematic????", tag); + try (ByteArrayOutputStream baos = new ByteArrayOutputStream()) { + try (NBTOutputStream out = new NBTOutputStream( + new GZIPOutputStream(baos, true))) { + //TODO Find what this should be called + out.writeNamedTag("Schematic????", tag); + } + zos.write(baos.toByteArray()); } - zos.write(baos.toByteArray()); } } setSpawn(spawn);