New API method, more 1.13 entity support, and cleanup.

Signed-off-by: matt <4009945+MattBDev@users.noreply.github.com>
This commit is contained in:
matt 2019-02-15 12:50:43 -05:00
parent 4f27abb4a0
commit a64d764cc1
12 changed files with 319 additions and 313 deletions

View File

@ -30,6 +30,7 @@ import com.sk89q.worldedit.bukkit.WorldEditPlugin;
import com.sk89q.worldedit.extension.platform.Capability; import com.sk89q.worldedit.extension.platform.Capability;
import lombok.Getter; import lombok.Getter;
import lombok.NonNull; import lombok.NonNull;
import org.bstats.bukkit.Metrics;
import org.bukkit.*; import org.bukkit.*;
import org.bukkit.Location; import org.bukkit.Location;
import org.bukkit.command.PluginCommand; import org.bukkit.command.PluginCommand;
@ -287,244 +288,248 @@ public final class BukkitMain extends JavaPlugin implements Listener, IPlotMain
@Override @SuppressWarnings("deprecation") public void runEntityTask() { @Override @SuppressWarnings("deprecation") public void runEntityTask() {
PlotSquared.log(C.PREFIX + "KillAllEntities started."); PlotSquared.log(C.PREFIX + "KillAllEntities started.");
TaskManager TaskManager.runTaskRepeat(() -> PlotSquared.get().forEachPlotArea(plotArea -> {
.runTaskRepeat(() -> PlotSquared.get().foreachPlotArea(new RunnableVal<PlotArea>() { final World world = Bukkit.getWorld(plotArea.worldname);
@Override public void run(PlotArea plotArea) { try {
final World world = Bukkit.getWorld(plotArea.worldname); if (world == null) {
try { return;
if (world == null) { }
return; List<Entity> entities = world.getEntities();
} Iterator<Entity> iterator = entities.iterator();
List<Entity> entities = world.getEntities(); while (iterator.hasNext()) {
Iterator<Entity> iterator = entities.iterator(); Entity entity = iterator.next();
while (iterator.hasNext()) { switch (entity.getType()) {
Entity entity = iterator.next(); case EGG:
switch (entity.getType()) { case COMPLEX_PART:
case EGG: case FISHING_HOOK:
case COMPLEX_PART: case ENDER_SIGNAL:
case FISHING_HOOK: case LINGERING_POTION:
case ENDER_SIGNAL: case AREA_EFFECT_CLOUD:
case LINGERING_POTION: case EXPERIENCE_ORB:
case AREA_EFFECT_CLOUD: case LEASH_HITCH:
case EXPERIENCE_ORB: case FIREWORK:
case LEASH_HITCH: case WEATHER:
case FIREWORK: case LIGHTNING:
case WEATHER: case WITHER_SKULL:
case LIGHTNING: case UNKNOWN:
case WITHER_SKULL: case PLAYER:
case UNKNOWN: // non moving / unmovable
case PLAYER: continue;
// non moving / unmovable 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; continue;
case THROWN_EXP_BOTTLE: }
case SPLASH_POTION: List<MetadataValue> meta = entity.getMetadata("plot");
case SNOWBALL: if (meta.isEmpty()) {
case SHULKER_BULLET:
case SPECTRAL_ARROW:
case TIPPED_ARROW:
case ENDER_PEARL:
case ARROW:
case LLAMA_SPIT:
case TRIDENT:
// managed elsewhere | projectile
continue; continue;
case ITEM_FRAME: }
case PAINTING: Plot origin = (Plot) meta.get(0).value();
// Not vehicles if (!plot.equals(origin.getBasePlot(false))) {
continue; if (entity.hasMetadata("ps-tmp-teleport")) {
case ARMOR_STAND: continue;
// Temporarily classify as vehicle }
case MINECART: iterator.remove();
case MINECART_CHEST: entity.remove();
case MINECART_COMMAND: }
case MINECART_FURNACE: }
case MINECART_HOPPER: continue;
case MINECART_MOB_SPAWNER: case SMALL_FIREBALL:
case ENDER_CRYSTAL: case FIREBALL:
case MINECART_TNT: case DRAGON_FIREBALL:
case BOAT: case DROPPED_ITEM:
if (Settings.Enabled_Components.KILL_ROAD_VEHICLES) { 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<MetadataValue> meta = entity.getMetadata("plot");
if (meta != null && !meta.isEmpty()) {
if (livingEntity.isLeashed()) {
continue;
}
List<MetadataValue> 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 com.github.intellectualsites.plotsquared.plot.object.Location
location = BukkitUtil.getLocation(entity.getLocation()); pLoc = BukkitUtil.getLocation(entity.getLocation());
Plot plot = location.getPlot(); PlotArea area = pLoc.getPlotArea();
if (plot == null) { if (area != null) {
if (location.isPlotArea()) { 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")) { if (entity.hasMetadata("ps-tmp-teleport")) {
continue; continue;
} }
iterator.remove(); iterator.remove();
entity.remove(); entity.remove();
} }
continue;
} }
List<MetadataValue> meta = entity.getMetadata("plot"); }
if (meta.isEmpty()) { } else {
continue; //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")) { if (entity.hasMetadata("ps-tmp-teleport")) {
continue; continue;
} }
iterator.remove(); iterator.remove();
entity.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<MetadataValue> meta = entity.getMetadata("plot");
if (meta != null && !meta.isEmpty()) {
if (livingEntity.isLeashed())
continue;
List<MetadataValue> 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 @Override @Nullable
@ -701,7 +706,7 @@ public final class BukkitMain extends JavaPlugin implements Listener, IPlotMain
} }
System.setProperty("bstats.relocatecheck", System.setProperty("bstats.relocatecheck",
"false"); // We do not want to relocate the package... "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."); PlotSquared.log(C.PREFIX + "&6Metrics enabled.");
this.metricsStarted = true; this.metricsStarted = true;
} }

View File

@ -128,7 +128,7 @@ public class BukkitPlotGenerator extends ChunkGenerator
result.setBiome(x, z, biome.name()); 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; return Biome.FOREST;
} }
}; };
@ -142,7 +142,7 @@ public class BukkitPlotGenerator extends ChunkGenerator
} }
/* TODO: Redo this /* TODO: Redo this
// Populator spillage // Populator spillage
short[][] tmp = cg.generateExtBlockSections(w, r, cx, cz, grid); short[][] tmp = cg.generateExtBlockSections(w, r, cx, cz, biomeGrid);
if (tmp != null) { if (tmp != null) {
for (int i = 0; i < tmp.length; i++) { for (int i = 0; i < tmp.length; i++) {
short[] section = tmp[i]; short[] section = tmp[i];
@ -235,30 +235,30 @@ public class BukkitPlotGenerator extends ChunkGenerator
} }
@Override @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; GenChunk result = this.chunkSetter;
if (this.getPlotGenerator() instanceof SingleWorldGenerator) { if (this.getPlotGenerator() instanceof SingleWorldGenerator) {
if (result.getCd() != null) { if (result.getCd() != null) {
for (int x = 0; x < 16; x++) { for (int cx = 0; cx < 16; cx++) {
for (int z = 0; z < 16; z++) { for (int cz = 0; cz < 16; cz++) {
grid.setBiome(x, z, Biome.PLAINS); biome.setBiome(cx, cz, Biome.PLAINS);
} }
} }
return result.getCd(); return result.getCd();
} }
} }
// Set the chunk location // Set the chunk location
result.setChunk(new ChunkWrapper(world.getName(), cx, cz)); result.setChunk(new ChunkWrapper(world.getName(), x, z));
// Set the result data // Set the result data
result.setCd(createChunkData(world)); result.setCd(createChunkData(world));
result.grid = grid; result.biomeGrid = biome;
result.result = null; result.result = null;
// Catch any exceptions (as exceptions usually thrown) // Catch any exceptions (as exceptions usually thrown)
try { try {
// Fill the result data if necessary // Fill the result data if necessary
if (this.platformGenerator != this) { if (this.platformGenerator != this) {
return this.platformGenerator.generateChunkData(world, random, cx, cz, grid); return this.platformGenerator.generateChunkData(world, random, x, z, biome);
} else { } else {
generate(world, result); generate(world, result);
} }

View File

@ -16,7 +16,7 @@ public final class ReplicatingEntityWrapper extends EntityWrapper {
private final int hash; private final int hash;
private final EntityBaseStats base = new EntityBaseStats(); private final EntityBaseStats base = new EntityBaseStats();
public ItemStack[] inventory; private ItemStack[] inventory;
// Extended // Extended
private ItemStack stack; private ItemStack stack;
private byte dataByte; private byte dataByte;
@ -94,6 +94,8 @@ public final class ReplicatingEntityWrapper extends EntityWrapper {
case DRAGON_FIREBALL: case DRAGON_FIREBALL:
case LINGERING_POTION: case LINGERING_POTION:
case AREA_EFFECT_CLOUD: case AREA_EFFECT_CLOUD:
case TRIDENT:
case LLAMA_SPIT:
// Do this stuff later // Do this stuff later
return; return;
// MISC // // MISC //
@ -132,13 +134,21 @@ public final class ReplicatingEntityWrapper extends EntityWrapper {
// START AGEABLE // // START AGEABLE //
// START TAMEABLE // // START TAMEABLE //
case HORSE: 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 = new HorseStats();
this.horse.jump = horse.getJumpStrength(); this.horse.jump = horse.getJumpStrength();
this.horse.chest = horse.isCarryingChest(); if (horse instanceof ChestedHorse) {
this.horse.variant = horse.getVariant(); ChestedHorse horse1 = (ChestedHorse) horse;
this.horse.style = horse.getStyle(); this.horse.chest = horse1.isCarryingChest();
this.horse.color = horse.getColor(); }
//todo these horse feeatures need fixing
//this.horse.variant = horse.getVariant();
//this.horse.style = horse.getStyle();
//this.horse.color = horse.getColor();
storeTameable(horse); storeTameable(horse);
storeAgeable(horse); storeAgeable(horse);
storeLiving(horse); storeLiving(horse);
@ -164,6 +174,7 @@ public final class ReplicatingEntityWrapper extends EntityWrapper {
case COW: case COW:
case MUSHROOM_COW: case MUSHROOM_COW:
case PIG: case PIG:
case TURTLE:
case POLAR_BEAR: case POLAR_BEAR:
storeAgeable((Ageable) entity); storeAgeable((Ageable) entity);
storeLiving((LivingEntity) entity); storeLiving((LivingEntity) entity);
@ -174,16 +185,6 @@ public final class ReplicatingEntityWrapper extends EntityWrapper {
storeLiving((LivingEntity) entity); storeLiving((LivingEntity) entity);
return; return;
// END AGEABLE // // 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: case ARMOR_STAND:
ArmorStand stand = (ArmorStand) entity; ArmorStand stand = (ArmorStand) entity;
this.inventory = this.inventory =
@ -249,6 +250,10 @@ public final class ReplicatingEntityWrapper extends EntityWrapper {
EnderDragon entity1 = (EnderDragon) entity; EnderDragon entity1 = (EnderDragon) entity;
this.dataByte = (byte) entity1.getPhase().ordinal(); this.dataByte = (byte) entity1.getPhase().ordinal();
return; return;
case SKELETON:
case WITHER_SKELETON:
case GUARDIAN:
case ELDER_GUARDIAN:
case GHAST: case GHAST:
case MAGMA_CUBE: case MAGMA_CUBE:
case SQUID: case SQUID:
@ -487,6 +492,8 @@ public final class ReplicatingEntityWrapper extends EntityWrapper {
case DRAGON_FIREBALL: case DRAGON_FIREBALL:
case WITHER_SKULL: case WITHER_SKULL:
case MINECART_FURNACE: case MINECART_FURNACE:
case LLAMA_SPIT:
case TRIDENT:
case UNKNOWN: case UNKNOWN:
// Do this stuff later // Do this stuff later
return entity; return entity;
@ -510,14 +517,20 @@ public final class ReplicatingEntityWrapper extends EntityWrapper {
// START LIVING ENTITY // // START LIVING ENTITY //
// START AGEABLE // // START AGEABLE //
// START TAMEABLE // // START TAMEABLE //
//todo this needs to be fixed
case HORSE: 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.setJumpStrength(this.horse.jump);
horse.setCarryingChest(this.horse.chest); if (horse instanceof ChestedHorse) {
horse.setVariant(this.horse.variant); ((ChestedHorse) horse).setCarryingChest(this.horse.chest);
horse.setStyle(this.horse.style); }
horse.setColor(this.horse.color); //todo broken as of 1.13
//horse.setVariant(this.horse.variant);
//horse.setStyle(this.horse.style);
//horse.setColor(this.horse.color);
restoreTameable(horse); restoreTameable(horse);
restoreAgeable(horse); restoreAgeable(horse);
restoreLiving(horse); restoreLiving(horse);
@ -545,6 +558,7 @@ public final class ReplicatingEntityWrapper extends EntityWrapper {
case VILLAGER: case VILLAGER:
case CHICKEN: case CHICKEN:
case COW: case COW:
case TURTLE:
case POLAR_BEAR: case POLAR_BEAR:
case MUSHROOM_COW: case MUSHROOM_COW:
case PIG: case PIG:

View File

@ -154,7 +154,7 @@ public class NbtFactory {
* @return The decoded NBT compound. * @return The decoded NBT compound.
* @throws IOException If anything went wrong. * @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 { throws IOException {
DataInputStream data = null; DataInputStream data = null;
boolean suppress = true; boolean suppress = true;
@ -189,24 +189,11 @@ public class NbtFactory {
*/ */
public static void saveStream(NbtCompound source, ByteSink stream, StreamOptions option) public static void saveStream(NbtCompound source, ByteSink stream, StreamOptions option)
throws IOException { 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); 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 * @author Kristian
*/ */
public enum StreamOptions { public enum StreamOptions {NO_COMPRESSION, GZIP_COMPRESSION,}
NO_COMPRESSION, GZIP_COMPRESSION,
}
private enum NbtType { private enum NbtType {

View File

@ -23,7 +23,7 @@ public class GenChunk extends ScopedLocalBlockQueue {
public final Biome[] biomes; public final Biome[] biomes;
public PlotBlock[][] result; public PlotBlock[][] result;
public BiomeGrid grid; public BiomeGrid biomeGrid;
public Chunk chunk; public Chunk chunk;
public String world; public String world;
public int cx; public int cx;
@ -57,13 +57,13 @@ public class GenChunk extends ScopedLocalBlockQueue {
} }
@Override public void fillBiome(String biomeName) { @Override public void fillBiome(String biomeName) {
if (grid == null) { if (biomeGrid == null) {
return; return;
} }
Biome biome = Biome.valueOf(biomeName.toUpperCase()); Biome biome = Biome.valueOf(biomeName.toUpperCase());
for (int x = 0; x < 16; x++) { for (int x = 0; x < 16; x++) {
for (int z = 0; z < 16; z++) { 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) { public boolean setBiome(int x, int z, Biome biome) {
if (this.grid != null) { if (this.biomeGrid != null) {
this.grid.setBiome(x, z, biome); this.biomeGrid.setBiome(x, z, biome);
return true; return true;
} }
return false; return false;

View File

@ -15,13 +15,13 @@ import java.util.stream.Collectors;
public abstract class FileConfiguration extends MemoryConfiguration { public abstract class FileConfiguration extends MemoryConfiguration {
/** /**
* Creates an empty {@link FileConfiguration} with no default values. * Creates an empty FileConfiguration with no default values.
*/ */
FileConfiguration() { 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. * Configuration} as a source for all default values.
* *
* @param defaults Default value provider * @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.
* *
* <p>If the file does not exist, it will be created. If already exists, it * <p>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 * 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. * @return String containing this configuration.
*/ */
public abstract String saveToString(); public abstract String saveToString();
/** /**
* Loads this {@link FileConfiguration} from the specified location. * Loads this FileConfiguration from the specified location.
* *
* <p>All the values contained within this configuration will be removed, * <p>All the values contained within this configuration will be removed,
* leaving only settings and defaults, and the new values will be loaded * 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 { public void load(File file) throws IOException, InvalidConfigurationException {
FileInputStream stream = new FileInputStream(file); try (FileInputStream stream = new FileInputStream(file)) {
load(new InputStreamReader(stream, StandardCharsets.UTF_8));
load(new InputStreamReader(stream, StandardCharsets.UTF_8)); }
} }
/** /**
* Loads this {@link FileConfiguration} from the specified reader. * Loads this FileConfiguration from the specified reader.
* *
* <p>All the values contained within this configuration will be removed, * <p>All the values contained within this configuration will be removed,
* leaving only settings and defaults, and the new values will be loaded * 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. * opposed to from file.
* *
* <p>All the values contained within this configuration will be removed, * <p>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; 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. * result.
* *
* <p>This will use the header from {@link #options()} -> {@link * <p>This will use the header from {@link #options()} -> {@link

View File

@ -41,6 +41,7 @@ import java.nio.file.Files;
import java.sql.SQLException; import java.sql.SQLException;
import java.util.*; import java.util.*;
import java.util.Map.Entry; import java.util.Map.Entry;
import java.util.function.Consumer;
import java.util.regex.Pattern; import java.util.regex.Pattern;
import java.util.zip.ZipEntry; import java.util.zip.ZipEntry;
import java.util.zip.ZipInputStream; import java.util.zip.ZipInputStream;
@ -1817,6 +1818,12 @@ import java.util.zip.ZipInputStream;
return Double.parseDouble(System.getProperty("java.specification.version")); return Double.parseDouble(System.getProperty("java.specification.version"));
} }
public void forEachPlotArea(Consumer<? super PlotArea> action) {
for (final PlotArea area : this.plotAreaManager.getAllPlotAreas()) {
action.accept(area);
}
}
public void foreachPlotArea(@Nonnull final RunnableVal<PlotArea> runnable) { public void foreachPlotArea(@Nonnull final RunnableVal<PlotArea> runnable) {
for (final PlotArea area : this.plotAreaManager.getAllPlotAreas()) { for (final PlotArea area : this.plotAreaManager.getAllPlotAreas()) {
runnable.run(area); runnable.run(area);

View File

@ -1513,6 +1513,7 @@ public class Plot {
return WorldUtil.IMP.getBiome(loc.getWorld(), loc.getX(), loc.getZ()); return WorldUtil.IMP.getBiome(loc.getWorld(), loc.getX(), loc.getZ());
} }
//TODO Better documentation needed.
/** /**
* Return the top location for the plot. * Return the top location for the plot.
* *
@ -1525,7 +1526,6 @@ public class Plot {
} }
//TODO Better documentation needed. //TODO Better documentation needed.
/** /**
* Return the bottom location for the plot. * 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 plot the plot to move
* @param whenDone * @param whenDone
@ -1710,7 +1710,7 @@ public class Plot {
} }
/** /**
* Move the plot to an empty location<br> * Moves the plot to an empty location<br>
* - The location must be empty * - The location must be empty
* *
* @param destination Where to move the plot * @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<br> * Do the plot entry tasks for each player in the plot<br>
* - Usually called when the plot state changes (unclaimed/claimed/flag change etc) * - 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() { public void updateWorldBorder() {
if (this.owner == null) {
return;
}
int border = this.area.getBorder(); int border = this.area.getBorder();
if (border == Integer.MAX_VALUE) { if (border == Integer.MAX_VALUE) {
return; 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 destination Plot moved to
* @param whenDone task when done * @param whenDone task when done

View File

@ -655,7 +655,7 @@ public abstract class PlotPlayer implements CommandCaller, OfflinePlotPlayer {
} }
} }
public interface PlotPlayerConverter<BaseObject> { @FunctionalInterface public interface PlotPlayerConverter<BaseObject> {
PlotPlayer convert(BaseObject object); PlotPlayer convert(BaseObject object);
} }
} }

View File

@ -39,9 +39,9 @@ public class Schematic {
} }
public void save(File file) throws IOException { public void save(File file) throws IOException {
SpongeSchematicWriter ssw = try (SpongeSchematicWriter ssw = new SpongeSchematicWriter(
new SpongeSchematicWriter(new NBTOutputStream(new FileOutputStream(file))); new NBTOutputStream(new FileOutputStream(file)))) {
ssw.write(clipboard); ssw.write(clipboard);
ssw.close(); }
} }
} }

View File

@ -87,7 +87,7 @@ public abstract class SchematicHandler {
} else { } else {
MainUtil.sendMessage(null, "&7 - &a success: " + plot.getId()); 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 plot plot to paste in
* @param xOffset offset x to paste it from plot origin * @param xOffset offset x to paste it from plot origin
* @param zOffset offset z 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, public void paste(final Schematic schematic, final Plot plot, final int xOffset,
final int yOffset, final int zOffset, final boolean autoHeight, final int yOffset, final int zOffset, final boolean autoHeight,
@ -126,7 +125,7 @@ public abstract class SchematicHandler {
if (!flags.isEmpty()) { if (!flags.isEmpty()) {
for (Map.Entry<String, Tag> entry : flags.entrySet()) { for (Map.Entry<String, Tag> entry : flags.entrySet()) {
plot.setFlag(Flags.getFlag(entry.getKey()), 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<String> getSaves(UUID uuid) { public List<String> getSaves(UUID uuid) {
StringBuilder rawJSON = new StringBuilder(); String rawJSON = "";
try { try {
String website = Settings.Web.URL + "list.php?" + uuid.toString(); String website = Settings.Web.URL + "list.php?" + uuid.toString();
URL url = new URL(website); URL url = new URL(website);
URLConnection connection = new URL(url.toString()).openConnection(); URLConnection connection = new URL(url.toString()).openConnection();
connection.setRequestProperty("User-Agent", "Mozilla/5.0"); connection.setRequestProperty("User-Agent", "Mozilla/5.0");
BufferedReader reader = try (BufferedReader reader = new BufferedReader(
new BufferedReader(new InputStreamReader(connection.getInputStream())); new InputStreamReader(connection.getInputStream()))) {
String line; rawJSON = reader.lines().collect(Collectors.joining());
while ((line = reader.readLine()) != null) {
rawJSON.append(line);
} }
reader.close(); JSONArray array = new JSONArray(rawJSON);
JSONArray array = new JSONArray(rawJSON.toString());
List<String> schematics = new ArrayList<>(); List<String> schematics = new ArrayList<>();
for (int i = 0; i < array.length(); i++) { for (int i = 0; i < array.length(); i++) {
String schematic = array.getString(i); String schematic = array.getString(i);

View File

@ -78,13 +78,14 @@ public abstract class WorldUtil {
map.put("SpawnX", new IntTag(home.getX())); map.put("SpawnX", new IntTag(home.getX()));
map.put("SpawnY", new IntTag(home.getY())); map.put("SpawnY", new IntTag(home.getY()));
map.put("SpawnZ", new IntTag(home.getZ())); map.put("SpawnZ", new IntTag(home.getZ()));
ByteArrayOutputStream baos = new ByteArrayOutputStream(); try (ByteArrayOutputStream baos = new ByteArrayOutputStream()) {
try (NBTOutputStream out = new NBTOutputStream( try (NBTOutputStream out = new NBTOutputStream(
new GZIPOutputStream(baos, true))) { new GZIPOutputStream(baos, true))) {
//TODO Find what this should be called //TODO Find what this should be called
out.writeNamedTag("Schematic????", tag); out.writeNamedTag("Schematic????", tag);
}
zos.write(baos.toByteArray());
} }
zos.write(baos.toByteArray());
} }
} }
setSpawn(spawn); setSpawn(spawn);