Skip to content

Commit

Permalink
Merge pull request #102 from BentoBoxWorld/develop
Browse files Browse the repository at this point in the history
Fixes for 1.21.3
  • Loading branch information
tastybento authored Nov 23, 2024
2 parents 091c767 + 14dee15 commit a0e9fa9
Show file tree
Hide file tree
Showing 7 changed files with 58 additions and 110 deletions.
49 changes: 18 additions & 31 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@
<powermock.version>2.0.9</powermock.version>
<!-- More visible way how to change dependency versions -->
<spigot.version>1.21.3-R0.1-SNAPSHOT</spigot.version>
<paper.version>1.21.3-R0.1-SNAPSHOT</paper.version>
<bentobox.version>2.7.1-SNAPSHOT</bentobox.version>
<!-- Revision variable removes warning about dynamic version -->
<revision>${build.version}-SNAPSHOT</revision>
Expand Down Expand Up @@ -111,10 +112,14 @@
</profiles>

<repositories>
<repository>
<repository>
<id>spigot-repo</id>
<url>https://hub.spigotmc.org/nexus/content/repositories/snapshots</url>
</repository>
<repository>
<id>papermc</id>
<url>https://repo.papermc.io/repository/maven-public/</url>
</repository>
<repository>
<id>bentoboxworld</id>
<url>https://repo.codemc.org/repository/bentoboxworld/</url>
Expand Down Expand Up @@ -172,14 +177,7 @@
<scope>provided</scope>
</dependency>
<!-- Spigot NMS. Used for chunk deletion and pasting. -->

<dependency>
<groupId>org.spigotmc....</groupId>
<artifactId>spigot</artifactId>
<version>1.20.6-R0.1-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
<dependency>
<dependency>
<groupId>org.spigotmc</groupId>
<artifactId>spigot</artifactId>
<version>${spigot.version}</version>
Expand All @@ -191,24 +189,6 @@
<version>1.21.1-R0.1-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.spigotmc.</groupId>
<artifactId>spigot</artifactId>
<version>1.20.4-R0.1-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.spigotmc..</groupId>
<artifactId>spigot</artifactId>
<version>1.20.2-R0.1-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.spigotmc...</groupId>
<artifactId>spigot</artifactId>
<version>1.20.1-R0.1-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
</dependencies>

<build>
Expand Down Expand Up @@ -318,10 +298,17 @@
</argLine>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>3.1.0</version>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>3.4.1</version>
<configuration>
<archive>
<manifestEntries>
<paperweight-mappings-namespace>spigot</paperweight-mappings-namespace>
</manifestEntries>
</archive>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
Expand Down
48 changes: 17 additions & 31 deletions src/main/java/world/bentobox/boxed/listeners/NewAreaListener.java
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -231,14 +226,13 @@ public void onChunkLoad(ChunkLoadEvent e) {
if (!(addon.inWorld(chunk.getWorld()))) {
return;
}
//BentoBox.getInstance().logDebug(e.getEventName());
Pair<Integer, Integer> chunkCoords = new Pair<Integer, Integer>(chunk.getX(), chunk.getZ());
if (pending.containsKey(chunkCoords)) {
Iterator<StructureRecord> 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();
}
Expand All @@ -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");
}
}

Expand Down Expand Up @@ -394,10 +386,9 @@ 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));
.add(new StructureRecord(name, "minecraft:" + name, location, rotation, mirror, noMobs));
this.itemsToBuild
.add(new StructureRecord(name, "minecraft:" + name, location, rotation, mirror, noMobs));
} else {
Expand All @@ -412,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);
Expand Down Expand Up @@ -508,16 +497,20 @@ 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) {
e.printStackTrace();
}
}

Expand Down Expand Up @@ -549,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());
}
}

Expand Down Expand Up @@ -646,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()) {
Expand Down
6 changes: 2 additions & 4 deletions src/main/java/world/bentobox/boxed/nms/AbstractMetaData.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,8 @@
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);
Expand All @@ -30,7 +28,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(
Expand Down

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -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");
}

}
3 changes: 2 additions & 1 deletion src/test/java/world/bentobox/boxed/mocks/ServerMocks.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@

public final class ServerMocks {

@SuppressWarnings({ "deprecation", "unchecked" })
public static @NonNull Server newServer() {
Server mock = mock(Server.class);

Expand Down Expand Up @@ -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());

Expand Down

0 comments on commit a0e9fa9

Please sign in to comment.