From 3d411d24ffffd12a6fa7d5ae21811d6e41833b46 Mon Sep 17 00:00:00 2001 From: tastybento Date: Sat, 23 Nov 2024 09:41:23 -0800 Subject: [PATCH 1/3] Limit to 1.21.x Fix for 1.21.3 --- pom.xml | 61 ++++++++++--------- .../bentobox/boxed/AdvancementsManager.java | 8 ++- .../boxed/listeners/NewAreaListener.java | 28 +++++---- .../bentobox/boxed/nms/AbstractMetaData.java | 13 ++-- .../v1_20_4_R0_1_SNAPSHOT/GetMetaData.java | 21 ------- .../v1_20_6_R0_1_SNAPSHOT/GetMetaData.java | 20 ------ .../v1_21_3_R0_1_SNAPSHOT/GetMetaData.java | 21 ++++++- 7 files changed, 80 insertions(+), 92 deletions(-) delete mode 100644 src/main/java/world/bentobox/boxed/nms/v1_20_4_R0_1_SNAPSHOT/GetMetaData.java delete mode 100644 src/main/java/world/bentobox/boxed/nms/v1_20_6_R0_1_SNAPSHOT/GetMetaData.java diff --git a/pom.xml b/pom.xml index 772fa0b..61338fd 100644 --- a/pom.xml +++ b/pom.xml @@ -55,6 +55,7 @@ 2.0.9 1.21.3-R0.1-SNAPSHOT + 1.21.3-R0.1-SNAPSHOT 2.7.1-SNAPSHOT ${build.version}-SNAPSHOT @@ -111,6 +112,10 @@ + + papermc + https://repo.papermc.io/repository/maven-public/ + spigot-repo https://hub.spigotmc.org/nexus/content/repositories/snapshots @@ -139,6 +144,20 @@ + + + io.papermc.paper + paper-api + ${paper.version} + provided + + + + io.papermc + paperlib + 1.0.6 + compile + org.spigotmc @@ -172,14 +191,7 @@ provided - - - org.spigotmc.... - spigot - 1.20.6-R0.1-SNAPSHOT - provided - - + org.spigotmc spigot ${spigot.version} @@ -191,24 +203,6 @@ 1.21.1-R0.1-SNAPSHOT provided - - org.spigotmc. - spigot - 1.20.4-R0.1-SNAPSHOT - provided - - - org.spigotmc.. - spigot - 1.20.2-R0.1-SNAPSHOT - provided - - - org.spigotmc... - spigot - 1.20.1-R0.1-SNAPSHOT - provided - @@ -318,10 +312,17 @@ - - org.apache.maven.plugins - maven-jar-plugin - 3.1.0 + + org.apache.maven.plugins + maven-jar-plugin + 3.4.1 + + + + spigot + + + org.apache.maven.plugins diff --git a/src/main/java/world/bentobox/boxed/AdvancementsManager.java b/src/main/java/world/bentobox/boxed/AdvancementsManager.java index d8adc0f..b9d2960 100644 --- a/src/main/java/world/bentobox/boxed/AdvancementsManager.java +++ b/src/main/java/world/bentobox/boxed/AdvancementsManager.java @@ -250,9 +250,11 @@ public int getScore(Advancement a) { } if (advConfig.getBoolean("settings.automatic-scoring")) { if (!a.getKey().getKey().contains("recipes") && a.getDisplay() != null) { - float x = a.getDisplay().getX(); - float y = a.getDisplay().getY(); - return (int) Math.round(Math.sqrt(x * x + y * y)); + int score = 1; + while (a.getParent() != null) { + score++; + } + return score; } else { return 0; } diff --git a/src/main/java/world/bentobox/boxed/listeners/NewAreaListener.java b/src/main/java/world/bentobox/boxed/listeners/NewAreaListener.java index 9a99a49..28f9675 100644 --- a/src/main/java/world/bentobox/boxed/listeners/NewAreaListener.java +++ b/src/main/java/world/bentobox/boxed/listeners/NewAreaListener.java @@ -396,8 +396,7 @@ private void place(ConfigurationSection section, Location center, Environment en Location location = new Location(world, x, y, z); //BentoBox.getInstance().logDebug("Structure " + name + " will be placed at " + location); readyToBuild.computeIfAbsent(new Pair<>(x >> 4, z >> 4), k -> new ArrayList<>()) - .add(new StructureRecord(name, "minecraft:" + name, location, - rotation, mirror, noMobs)); + .add(new StructureRecord(name, "minecraft:" + name, location, rotation, mirror, noMobs)); this.itemsToBuild .add(new StructureRecord(name, "minecraft:" + name, location, rotation, mirror, noMobs)); } else { @@ -508,16 +507,21 @@ private static void processStructureBlock(Block b) { } private static void processJigsaw(Block b, StructureRotation structureRotation, boolean pasteMobs) { - String data = nmsData(b); - if (data.isEmpty()) { - return; - } - BoxedJigsawBlock bjb = gson.fromJson(data, BoxedJigsawBlock.class); - String finalState = correctDirection(bjb.getFinal_state(), structureRotation); - BlockData bd = Bukkit.createBlockData(finalState); - b.setBlockData(bd); - if (!bjb.getPool().equalsIgnoreCase("minecraft:empty") && pasteMobs) { - spawnMob(b, bjb); + try { + String data = nmsData(b); + if (data.isEmpty()) { + return; + } + BoxedJigsawBlock bjb = gson.fromJson(data, BoxedJigsawBlock.class); + String finalState = correctDirection(bjb.getFinal_state(), structureRotation); + BlockData bd = Bukkit.createBlockData(finalState); + b.setBlockData(bd); + if (!bjb.getPool().equalsIgnoreCase("minecraft:empty") && pasteMobs) { + spawnMob(b, bjb); + } + } catch (Exception e) { + BentoBox.getInstance().logDebug("We have an error"); + e.printStackTrace(); } } diff --git a/src/main/java/world/bentobox/boxed/nms/AbstractMetaData.java b/src/main/java/world/bentobox/boxed/nms/AbstractMetaData.java index 94f7576..5657ff9 100644 --- a/src/main/java/world/bentobox/boxed/nms/AbstractMetaData.java +++ b/src/main/java/world/bentobox/boxed/nms/AbstractMetaData.java @@ -8,15 +8,20 @@ import net.minecraft.nbt.NBTTagCompound; import net.minecraft.network.protocol.game.PacketPlayOutTileEntityData; import net.minecraft.world.level.block.entity.TileEntity; +import world.bentobox.bentobox.BentoBox; -/** - * - */ public abstract class AbstractMetaData { public abstract String nmsData(Block block); protected String getData(TileEntity te, String method, String field) { + /* + for (Method m : te.getClass().getMethods()) { + BentoBox.getInstance().logDebug(m.getName() + " returns " + m.getReturnType() + " and has these parameters " + + m.getParameterTypes()); + } + te.getUpdateTag(); + */ try { // Check if the method 'j' exists Method updatePacketMethod = te.getClass().getDeclaredMethod(method); @@ -30,7 +35,7 @@ protected String getData(TileEntity te, String method, String field) { Field fieldC = packet.getClass().getDeclaredField(field); fieldC.setAccessible(true); NBTTagCompound nbtTag = (NBTTagCompound) fieldC.get(packet); - + return nbtTag.toString(); // This will show what you want //} else { // throw new ClassNotFoundException( diff --git a/src/main/java/world/bentobox/boxed/nms/v1_20_4_R0_1_SNAPSHOT/GetMetaData.java b/src/main/java/world/bentobox/boxed/nms/v1_20_4_R0_1_SNAPSHOT/GetMetaData.java deleted file mode 100644 index 639598a..0000000 --- a/src/main/java/world/bentobox/boxed/nms/v1_20_4_R0_1_SNAPSHOT/GetMetaData.java +++ /dev/null @@ -1,21 +0,0 @@ -package world.bentobox.boxed.nms.v1_20_4_R0_1_SNAPSHOT; - -import org.bukkit.Location; -import org.bukkit.block.Block; -import org.bukkit.craftbukkit.v1_20_R3.CraftWorld; - -import net.minecraft.core.BlockPosition; -import net.minecraft.world.level.block.entity.TileEntity; -import world.bentobox.boxed.nms.AbstractMetaData; - -public class GetMetaData extends AbstractMetaData { - - @Override - public String nmsData(Block block) { - Location w = block.getLocation(); - CraftWorld cw = (CraftWorld) w.getWorld(); // CraftWorld is NMS one - TileEntity te = cw.getHandle().c_(new BlockPosition(w.getBlockX(), w.getBlockY(), w.getBlockZ())); - - return getData(te, "j", "c"); - } -} \ No newline at end of file diff --git a/src/main/java/world/bentobox/boxed/nms/v1_20_6_R0_1_SNAPSHOT/GetMetaData.java b/src/main/java/world/bentobox/boxed/nms/v1_20_6_R0_1_SNAPSHOT/GetMetaData.java deleted file mode 100644 index 2855074..0000000 --- a/src/main/java/world/bentobox/boxed/nms/v1_20_6_R0_1_SNAPSHOT/GetMetaData.java +++ /dev/null @@ -1,20 +0,0 @@ -package world.bentobox.boxed.nms.v1_20_6_R0_1_SNAPSHOT; - -import org.bukkit.Location; -import org.bukkit.block.Block; -import org.bukkit.craftbukkit.v1_20_R4.CraftWorld; - -import net.minecraft.core.BlockPosition; -import net.minecraft.world.level.block.entity.TileEntity; -import world.bentobox.boxed.nms.AbstractMetaData; - -public class GetMetaData extends AbstractMetaData { - - @Override - public String nmsData(Block block) { - Location w = block.getLocation(); - CraftWorld cw = (CraftWorld) w.getWorld(); // CraftWorld is NMS one - TileEntity te = cw.getHandle().c_(new BlockPosition(w.getBlockX(), w.getBlockY(), w.getBlockZ())); - return getData(te, "au_", "tag"); - } -} \ No newline at end of file diff --git a/src/main/java/world/bentobox/boxed/nms/v1_21_3_R0_1_SNAPSHOT/GetMetaData.java b/src/main/java/world/bentobox/boxed/nms/v1_21_3_R0_1_SNAPSHOT/GetMetaData.java index 0cf1131..c0df15e 100644 --- a/src/main/java/world/bentobox/boxed/nms/v1_21_3_R0_1_SNAPSHOT/GetMetaData.java +++ b/src/main/java/world/bentobox/boxed/nms/v1_21_3_R0_1_SNAPSHOT/GetMetaData.java @@ -1,5 +1,22 @@ package world.bentobox.boxed.nms.v1_21_3_R0_1_SNAPSHOT; -public class GetMetaData extends world.bentobox.boxed.nms.v1_21_R0_1_SNAPSHOT.GetMetaData { - // Identical to 1.21 +import org.bukkit.Location; +import org.bukkit.block.Block; +import org.bukkit.craftbukkit.v1_21_R2.CraftWorld; + +import net.minecraft.core.BlockPosition; +import net.minecraft.world.level.block.entity.TileEntity; +import world.bentobox.boxed.nms.AbstractMetaData; + +public class GetMetaData extends AbstractMetaData { + + @Override + public String nmsData(Block block) { + Location w = block.getLocation(); + CraftWorld cw = (CraftWorld) w.getWorld(); // CraftWorld is NMS one + // for 1.13+ (we have use WorldServer) + TileEntity te = cw.getHandle().c_(new BlockPosition(w.getBlockX(), w.getBlockY(), w.getBlockZ())); + return getData(te, "getUpdatePacket", "tag"); + } + } \ No newline at end of file From 1fe87fedff18cfa89e08f08da86ef0533b678edf Mon Sep 17 00:00:00 2001 From: tastybento Date: Sat, 23 Nov 2024 09:46:10 -0800 Subject: [PATCH 2/3] Debug clean up --- .../boxed/listeners/NewAreaListener.java | 22 ++----------------- .../bentobox/boxed/nms/AbstractMetaData.java | 7 ------ 2 files changed, 2 insertions(+), 27 deletions(-) diff --git a/src/main/java/world/bentobox/boxed/listeners/NewAreaListener.java b/src/main/java/world/bentobox/boxed/listeners/NewAreaListener.java index 28f9675..2ac8399 100644 --- a/src/main/java/world/bentobox/boxed/listeners/NewAreaListener.java +++ b/src/main/java/world/bentobox/boxed/listeners/NewAreaListener.java @@ -153,21 +153,16 @@ private void runStructurePrinter() { * Build something in the queue. Structures are built one by one */ private void buildStructure() { - //BentoBox.getInstance().logDebug("buildStructure"); // Only kick off a build if there is something to build and something isn't // already being built if (!pasting && !itemsToBuild.isEmpty()) { // Build item - //BentoBox.getInstance().logDebug("Build item"); StructureRecord item = itemsToBuild.poll(); placeStructure(item); - } else { - //BentoBox.getInstance().logDebug("Nothing to do"); } } private void placeStructure(StructureRecord item) { - //BentoBox.getInstance().logDebug("Placing structure"); // Set the semaphore - only paste one at a time pasting = true; // Place the structure - this cannot be done async @@ -231,14 +226,13 @@ public void onChunkLoad(ChunkLoadEvent e) { if (!(addon.inWorld(chunk.getWorld()))) { return; } - //BentoBox.getInstance().logDebug(e.getEventName()); Pair chunkCoords = new Pair(chunk.getX(), chunk.getZ()); if (pending.containsKey(chunkCoords)) { Iterator it = pending.get(chunkCoords).iterator(); while (it.hasNext()) { StructureRecord item = it.next(); if (item.location().getWorld().equals(e.getWorld())) { - //BentoBox.getInstance().logDebug("Placing structure in itemsToBuild " + item); + // Placing structure in itemsToBuild this.itemsToBuild.add(item); it.remove(); } @@ -247,8 +241,6 @@ public void onChunkLoad(ChunkLoadEvent e) { ToBePlacedStructures tbd = new ToBePlacedStructures(); tbd.setReadyToBuild(pending); toPlace.saveObjectAsync(tbd); - } else { - //BentoBox.getInstance().logDebug("Nothing to build in this chunk"); } } @@ -394,7 +386,7 @@ private void place(ConfigurationSection section, Location center, Environment en int y = Integer.parseInt(coords[1].strip()); int z = Integer.parseInt(coords[2].strip()) + center.getBlockZ(); Location location = new Location(world, x, y, z); - //BentoBox.getInstance().logDebug("Structure " + name + " will be placed at " + location); + // Structure will be placed at location readyToBuild.computeIfAbsent(new Pair<>(x >> 4, z >> 4), k -> new ArrayList<>()) .add(new StructureRecord(name, "minecraft:" + name, location, rotation, mirror, noMobs)); this.itemsToBuild @@ -411,8 +403,6 @@ private void place(ConfigurationSection section, Location center, Environment en return list1; })); - //BentoBox.getInstance().logDebug("mergedMap size = " + mergedMap.size()); - //BentoBox.getInstance().logDebug("readyToBuild size = " + readyToBuild.size()); // Save the list tbd.setReadyToBuild(mergedMap); toPlace.saveObjectAsync(tbd); @@ -520,7 +510,6 @@ private static void processJigsaw(Block b, StructureRotation structureRotation, spawnMob(b, bjb); } } catch (Exception e) { - BentoBox.getInstance().logDebug("We have an error"); e.printStackTrace(); } } @@ -553,17 +542,12 @@ private static void spawnMob(Block b, BoxedJigsawBlock bjb) { } else if (bjb.getPool().contains("villagers")) { type = EntityType.VILLAGER; } - // if (type == null) { - // BentoBox.getInstance().logDebug(bjb.getPool()); - // } // Spawn it if (type != null) { Entity e = b.getWorld().spawnEntity(b.getRelative(BlockFace.UP).getLocation(), type); if (e != null) { e.setPersistent(true); } - // BentoBox.getInstance().logDebug("Spawned a " + type + " at " + - // b.getRelative(BlockFace.UP).getLocation()); } } @@ -650,12 +634,10 @@ private static String nmsData(Block block) { private ToBePlacedStructures loadToDos() { if (!toPlace.objectExists(TODO)) { - //BentoBox.getInstance().logDebug("No TODO list"); return new ToBePlacedStructures(); } ToBePlacedStructures list = toPlace.loadObject(TODO); if (list == null) { - //BentoBox.getInstance().logDebug("TODO list is null"); return new ToBePlacedStructures(); } if (!list.getReadyToBuild().isEmpty()) { diff --git a/src/main/java/world/bentobox/boxed/nms/AbstractMetaData.java b/src/main/java/world/bentobox/boxed/nms/AbstractMetaData.java index 5657ff9..81906cb 100644 --- a/src/main/java/world/bentobox/boxed/nms/AbstractMetaData.java +++ b/src/main/java/world/bentobox/boxed/nms/AbstractMetaData.java @@ -15,13 +15,6 @@ public abstract class AbstractMetaData { public abstract String nmsData(Block block); protected String getData(TileEntity te, String method, String field) { - /* - for (Method m : te.getClass().getMethods()) { - BentoBox.getInstance().logDebug(m.getName() + " returns " + m.getReturnType() + " and has these parameters " - + m.getParameterTypes()); - } - te.getUpdateTag(); - */ try { // Check if the method 'j' exists Method updatePacketMethod = te.getClass().getDeclaredMethod(method); From 14dee1525829a1aa28cbd7728828dd0f070d66c1 Mon Sep 17 00:00:00 2001 From: tastybento Date: Sat, 23 Nov 2024 10:09:04 -0800 Subject: [PATCH 3/3] Fix tests. Revert Paper-specific code. --- pom.xml | 24 ++++--------------- .../bentobox/boxed/AdvancementsManager.java | 8 +++---- .../bentobox/boxed/mocks/ServerMocks.java | 3 ++- 3 files changed, 10 insertions(+), 25 deletions(-) diff --git a/pom.xml b/pom.xml index 61338fd..062688b 100644 --- a/pom.xml +++ b/pom.xml @@ -112,14 +112,14 @@ - - papermc - https://repo.papermc.io/repository/maven-public/ - - + spigot-repo https://hub.spigotmc.org/nexus/content/repositories/snapshots + + papermc + https://repo.papermc.io/repository/maven-public/ + bentoboxworld https://repo.codemc.org/repository/bentoboxworld/ @@ -144,20 +144,6 @@ - - - io.papermc.paper - paper-api - ${paper.version} - provided - - - - io.papermc - paperlib - 1.0.6 - compile - org.spigotmc diff --git a/src/main/java/world/bentobox/boxed/AdvancementsManager.java b/src/main/java/world/bentobox/boxed/AdvancementsManager.java index b9d2960..d8adc0f 100644 --- a/src/main/java/world/bentobox/boxed/AdvancementsManager.java +++ b/src/main/java/world/bentobox/boxed/AdvancementsManager.java @@ -250,11 +250,9 @@ public int getScore(Advancement a) { } if (advConfig.getBoolean("settings.automatic-scoring")) { if (!a.getKey().getKey().contains("recipes") && a.getDisplay() != null) { - int score = 1; - while (a.getParent() != null) { - score++; - } - return score; + float x = a.getDisplay().getX(); + float y = a.getDisplay().getY(); + return (int) Math.round(Math.sqrt(x * x + y * y)); } else { return 0; } diff --git a/src/test/java/world/bentobox/boxed/mocks/ServerMocks.java b/src/test/java/world/bentobox/boxed/mocks/ServerMocks.java index a4f2f40..9533491 100644 --- a/src/test/java/world/bentobox/boxed/mocks/ServerMocks.java +++ b/src/test/java/world/bentobox/boxed/mocks/ServerMocks.java @@ -24,6 +24,7 @@ public final class ServerMocks { + @SuppressWarnings({ "deprecation", "unchecked" }) public static @NonNull Server newServer() { Server mock = mock(Server.class); @@ -66,7 +67,7 @@ public final class ServerMocks { doReturn(key).when(keyed).getKey(); return keyed; }); - }).when(registry).get(notNull()); + }).when(registry).get((NamespacedKey) notNull()); return registry; })).when(mock).getRegistry(notNull());