From 48356275af1eae87a4c03621fbe505382aca82dd Mon Sep 17 00:00:00 2001 From: Jesse Boyd Date: Wed, 17 Jul 2019 06:36:48 +1000 Subject: [PATCH 1/5] fix loading legacy biomes --- .../boydti/fawe/jnbt/SchematicStreamer.java | 7 +- .../registry/NamespacedRegistry.java | 8 +- .../worldedit/world/biome/BiomeType.java | 10 ++- .../worldedit/world/biome/BiomeTypes.java | 87 +++++++++++++++++++ 4 files changed, 108 insertions(+), 4 deletions(-) diff --git a/worldedit-core/src/main/java/com/boydti/fawe/jnbt/SchematicStreamer.java b/worldedit-core/src/main/java/com/boydti/fawe/jnbt/SchematicStreamer.java index d20c2405b..180d9a1b7 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/jnbt/SchematicStreamer.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/jnbt/SchematicStreamer.java @@ -22,6 +22,7 @@ import com.sk89q.worldedit.math.BlockVector3; import com.sk89q.worldedit.regions.CuboidRegion; import com.sk89q.worldedit.registry.state.PropertyKey; import com.sk89q.worldedit.util.Direction; +import com.sk89q.worldedit.world.biome.BiomeType; import com.sk89q.worldedit.world.biome.BiomeTypes; import com.sk89q.worldedit.world.block.BlockID; import com.sk89q.worldedit.world.block.BlockStateHolder; @@ -109,7 +110,6 @@ public class SchematicStreamer extends NBTStreamer { if (value != 0) { int first = value & 0x0F; int second = (value & 0xF0) >> 4; - int gIndex = index << 1; try { if (first != 0) adds.write(first); if (second != 0) adds.write(second); @@ -122,7 +122,10 @@ public class SchematicStreamer extends NBTStreamer { ByteReader biomeReader = new ByteReader() { @Override public void run(int index, int value) { - fc.setBiome(index, BiomeTypes.get(value)); + BiomeType biome = BiomeTypes.getLegacy(value); + if (biome != null) { + fc.setBiome(index, biome); + } } }; NBTStreamReader initializer23 = new NBTStreamReader() { diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/registry/NamespacedRegistry.java b/worldedit-core/src/main/java/com/sk89q/worldedit/registry/NamespacedRegistry.java index 4d362bde8..17fb15a97 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/registry/NamespacedRegistry.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/registry/NamespacedRegistry.java @@ -23,6 +23,8 @@ import static com.google.common.base.Preconditions.checkState; import static java.util.Objects.requireNonNull; import java.util.ArrayList; +import java.util.Collection; +import java.util.Collections; import java.util.List; public final class NamespacedRegistry extends Registry { @@ -59,7 +61,11 @@ public final class NamespacedRegistry extends Registry REGISTRY = new NamespacedRegistry<>("biome type"); private final String id; + private int legacyId = -1; + private int internalId; public BiomeType(String id) { this.id = id; } - private int internalId; + public int getLegacyId() { + return legacyId; + } + + public void setLegacyId(int legacyId) { + this.legacyId = legacyId; + } @Override public void setInternalId(int internalId) { diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/world/biome/BiomeTypes.java b/worldedit-core/src/main/java/com/sk89q/worldedit/world/biome/BiomeTypes.java index d8eec08be..20280eb99 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/world/biome/BiomeTypes.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/world/biome/BiomeTypes.java @@ -108,6 +108,15 @@ public class BiomeTypes { return BiomeType.REGISTRY.get(id); } + public static BiomeType getLegacy(int legacyId) { + for (BiomeType type : values()) { + if (type.getLegacyId() == legacyId) { + return type; + } + } + return null; + } + public static BiomeType get(int internalId) { return BiomeType.REGISTRY.getByInternalId(internalId); } @@ -115,4 +124,82 @@ public class BiomeTypes { public static Collection values() { return BiomeType.REGISTRY.values(); } + + static { + OCEAN.setLegacyId(0); + PLAINS.setLegacyId(1); + DESERT.setLegacyId(2); + MOUNTAINS.setLegacyId(3); + FOREST.setLegacyId(4); + TAIGA.setLegacyId(5); + SWAMP.setLegacyId(6); + RIVER.setLegacyId(7); + NETHER.setLegacyId(8); + THE_END.setLegacyId(9); + FROZEN_OCEAN.setLegacyId(10); + FROZEN_RIVER.setLegacyId(11); + SNOWY_TUNDRA.setLegacyId(12); + SNOWY_MOUNTAINS.setLegacyId(13); + MUSHROOM_FIELDS.setLegacyId(14); + MUSHROOM_FIELD_SHORE.setLegacyId(15); + BEACH.setLegacyId(16); + DESERT_HILLS.setLegacyId(17); + WOODED_HILLS.setLegacyId(18); + TAIGA_HILLS.setLegacyId(19); + MOUNTAIN_EDGE.setLegacyId(20); + JUNGLE.setLegacyId(21); + JUNGLE_HILLS.setLegacyId(22); + JUNGLE_EDGE.setLegacyId(23); + DEEP_OCEAN.setLegacyId(24); + STONE_SHORE.setLegacyId(25); + SNOWY_BEACH.setLegacyId(26); + BIRCH_FOREST.setLegacyId(27); + BIRCH_FOREST_HILLS.setLegacyId(28); + DARK_FOREST.setLegacyId(29); + SNOWY_TAIGA.setLegacyId(30); + SNOWY_TAIGA_HILLS.setLegacyId(31); + GIANT_TREE_TAIGA.setLegacyId(32); + GIANT_TREE_TAIGA_HILLS.setLegacyId(33); + WOODED_MOUNTAINS.setLegacyId(34); + SAVANNA.setLegacyId(35); + SAVANNA_PLATEAU.setLegacyId(36); + BADLANDS.setLegacyId(37); + WOODED_BADLANDS_PLATEAU.setLegacyId(38); + BADLANDS_PLATEAU.setLegacyId(39); + SMALL_END_ISLANDS.setLegacyId(40); + END_MIDLANDS.setLegacyId(41); + END_HIGHLANDS.setLegacyId(42); + END_BARRENS.setLegacyId(43); + WARM_OCEAN.setLegacyId(44); + LUKEWARM_OCEAN.setLegacyId(45); + COLD_OCEAN.setLegacyId(46); + DEEP_WARM_OCEAN.setLegacyId(47); + DEEP_LUKEWARM_OCEAN.setLegacyId(48); + DEEP_COLD_OCEAN.setLegacyId(49); + DEEP_FROZEN_OCEAN.setLegacyId(50); + THE_VOID.setLegacyId(127); + SUNFLOWER_PLAINS.setLegacyId(129); + DESERT_LAKES.setLegacyId(130); + GRAVELLY_MOUNTAINS.setLegacyId(131); + FLOWER_FOREST.setLegacyId(132); + TAIGA_MOUNTAINS.setLegacyId(133); + SWAMP_HILLS.setLegacyId(134); + ICE_SPIKES.setLegacyId(140); + MODIFIED_JUNGLE.setLegacyId(149); + MODIFIED_JUNGLE_EDGE.setLegacyId(151); + TALL_BIRCH_FOREST.setLegacyId(155); + TALL_BIRCH_HILLS.setLegacyId(156); + DARK_FOREST_HILLS.setLegacyId(157); + SNOWY_TAIGA_MOUNTAINS.setLegacyId(158); + GIANT_SPRUCE_TAIGA.setLegacyId(160); + GIANT_SPRUCE_TAIGA_HILLS.setLegacyId(161); + MODIFIED_GRAVELLY_MOUNTAINS.setLegacyId(162); + SHATTERED_SAVANNA.setLegacyId(163); + SHATTERED_SAVANNA_PLATEAU.setLegacyId(164); + ERODED_BADLANDS.setLegacyId(165); + MODIFIED_WOODED_BADLANDS_PLATEAU.setLegacyId(166); + MODIFIED_BADLANDS_PLATEAU.setLegacyId(167); +// BAMBOO_JUNGLE.setLegacyId(168); +// BAMBOO_JUNGLE_HILLS.setLegacyId(169); + } } From 8f902c797de33f5481159a5f7664e329dde57c66 Mon Sep 17 00:00:00 2001 From: Jesse Boyd Date: Wed, 17 Jul 2019 21:28:46 +1000 Subject: [PATCH 2/5] Don't print within high stack depth conditions FAWE is trying to detect prevent a stackoverflow from block/item lag. Calling print adds to the stack depth. --- .../java/com/boydti/fawe/bukkit/v0/ChunkListener.java | 10 ++++++++-- .../com/boydti/fawe/bukkit/v0/ChunkListener_9.java | 2 +- 2 files changed, 9 insertions(+), 3 deletions(-) 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 a2ca171cc..e7bef8045 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 @@ -50,6 +50,7 @@ import java.util.List; public abstract class ChunkListener implements Listener { protected int rateLimit = 0; + protected Location lastCancelPos; private int[] badLimit = new int[]{Settings.IMP.TICK_LIMITER.PHYSICS_MS, Settings.IMP.TICK_LIMITER.FALLING, Settings.IMP.TICK_LIMITER.ITEMS}; public ChunkListener() { @@ -59,6 +60,10 @@ public abstract class ChunkListener implements Listener { plm.registerEvents(this, plugin); try { plm.registerEvents(new ChunkListener_8Plus(this), plugin); } catch (Throwable ignore) {} TaskManager.IMP.repeat(() -> { + Location tmpLoc = lastCancelPos; + if (tmpLoc != null) { + Fawe.debug("[FAWE `tick-limiter`] Detected and cancelled physics lag source at " + tmpLoc); + } rateLimit--; physicsFreeze = false; itemFreeze = false; @@ -66,6 +71,7 @@ public abstract class ChunkListener implements Listener { physSkip = 0; physCancelPair = Long.MIN_VALUE; physCancel = false; + lastCancelPos = null; counter.clear(); for (Long2ObjectMap.Entry entry : badChunks.long2ObjectEntrySet()) { @@ -231,7 +237,7 @@ public abstract class ChunkListener implements Listener { physCancelPair = MathMan.pairInt(cx, cz); if (rateLimit <= 0) { rateLimit = 20; - Fawe.debug("[FAWE `tick-limiter`] Detected and cancelled physics lag source at " + block.getLocation()); + lastCancelPos = block.getLocation(); } cancelNearby(cx, cz); event.setCancelled(true); @@ -305,7 +311,7 @@ public abstract class ChunkListener implements Listener { cancelNearby(cx, cz); if (rateLimit <= 0) { rateLimit = 20; - Fawe.debug("[FAWE `tick-limiter`] Detected and cancelled falling block lag source at " + block.getLocation()); + lastCancelPos = block.getLocation(); } event.setCancelled(true); return; diff --git a/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/v0/ChunkListener_9.java b/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/v0/ChunkListener_9.java index 7c84f1924..53ccbe1ca 100644 --- a/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/v0/ChunkListener_9.java +++ b/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/v0/ChunkListener_9.java @@ -60,7 +60,7 @@ public class ChunkListener_9 extends ChunkListener { physCancelPair = MathMan.pairInt(cx, cz); if (rateLimit <= 0) { rateLimit = 20; - Fawe.debug("[FAWE `tick-limiter`] Detected and cancelled physics lag source at " + block.getLocation()); + lastCancelPos = block.getLocation(); } cancelNearby(cx, cz); event.setCancelled(true); From 505af853bd30e275f2e65c19c5789bf7bf045172 Mon Sep 17 00:00:00 2001 From: Jesse Boyd Date: Wed, 17 Jul 2019 22:00:00 +1000 Subject: [PATCH 3/5] setLocation should be synchronized --- .../java/com/boydti/fawe/bukkit/v1_14/BukkitChunk_1_14.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/v1_14/BukkitChunk_1_14.java b/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/v1_14/BukkitChunk_1_14.java index 0309eec7e..eae0fcd29 100644 --- a/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/v1_14/BukkitChunk_1_14.java +++ b/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/v1_14/BukkitChunk_1_14.java @@ -436,8 +436,8 @@ public class BukkitChunk_1_14 extends IntFaweChunk { } entity.f(tag); } - entity.setLocation(x, y, z, yaw, pitch); synchronized (BukkitQueue_0.class) { + entity.setLocation(x, y, z, yaw, pitch); nmsWorld.addEntity(entity, CreatureSpawnEvent.SpawnReason.CUSTOM); } } From 7a42bd208f7c4a22b28cfef250815bcac2457fc5 Mon Sep 17 00:00:00 2001 From: Jesse Boyd Date: Wed, 17 Jul 2019 22:04:05 +1000 Subject: [PATCH 4/5] Update AsyncWorld.java --- .../fawe/bukkit/wrapper/AsyncWorld.java | 26 +++++++++++++++++++ 1 file changed, 26 insertions(+) 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 679484c9b..3211cd3bf 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 @@ -17,6 +17,7 @@ import com.sk89q.worldedit.world.biome.BiomeType; import java.io.File; import java.util.Collection; import java.util.List; +import java.util.Map; import java.util.Set; import java.util.UUID; import java.util.concurrent.CompletableFuture; @@ -1177,6 +1178,31 @@ public class AsyncWorld extends DelegateFaweQueue implements World, HasFaweQueue return parent.getForceLoadedChunks(); } + @Override + public boolean addPluginChunkTicket(int x, int z, @NotNull Plugin plugin) { + return getBukkitWorld().addPluginChunkTicket(x, z, plugin); + } + + @Override + public boolean removePluginChunkTicket(int x, int z, @NotNull Plugin plugin) { + return getBukkitWorld().removePluginChunkTicket(x, z, plugin); + } + + @Override + public void removePluginChunkTickets(@NotNull Plugin plugin) { + getBukkitWorld().removePluginChunkTickets(plugin); + } + + @Override + public @NotNull Collection getPluginChunkTickets(int x, int z) { + return getBukkitWorld().getPluginChunkTickets(x, z); + } + + @Override + public @NotNull Map> getPluginChunkTickets() { + return getBukkitWorld().getPluginChunkTickets(); + } + @Override public int getHighestBlockYAt(int x, int z, com.destroystokyo.paper.HeightmapType heightmap) throws UnsupportedOperationException { return TaskManager.IMP.sync(new Supplier() { From 8d60c0197b0ed80469283474bbc3777026a50082 Mon Sep 17 00:00:00 2001 From: Jesse Boyd Date: Wed, 17 Jul 2019 22:09:48 +1000 Subject: [PATCH 5/5] Update AsyncChunk.java --- .../boydti/fawe/bukkit/wrapper/AsyncChunk.java | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) 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 69da4e4b5..f92a0db3c 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 @@ -11,8 +11,11 @@ import org.bukkit.ChunkSnapshot; import org.bukkit.World; import org.bukkit.block.BlockState; import org.bukkit.entity.Entity; +import org.bukkit.plugin.Plugin; import org.jetbrains.annotations.NotNull; +import java.util.Collection; + public class AsyncChunk implements Chunk { private final AsyncWorld world; @@ -178,4 +181,19 @@ public class AsyncChunk implements Chunk { public void setForceLoaded(boolean arg0) { world.getChunkAt(x, z).setForceLoaded(arg0); } + + @Override + public boolean addPluginChunkTicket(final Plugin plugin) { + return world.addPluginChunkTicket(this.getX(), this.getZ(), plugin); + } + + @Override + public boolean removePluginChunkTicket(final Plugin plugin) { + return world.removePluginChunkTicket(this.getX(), this.getZ(), plugin); + } + + @Override + public Collection getPluginChunkTickets() { + return world.getPluginChunkTickets(this.getX(), this.getZ()); + } }