mirror of
https://github.com/BentoBoxWorld/Boxed.git
synced 2024-12-03 13:23:32 +01:00
Merge pull request #78 from BentoBoxWorld/better_nms
Add nms support for multiple servers
This commit is contained in:
commit
36ca0af4ec
4
.github/workflows/build.yml
vendored
4
.github/workflows/build.yml
vendored
@ -14,11 +14,11 @@ jobs:
|
|||||||
- uses: actions/checkout@v3
|
- uses: actions/checkout@v3
|
||||||
with:
|
with:
|
||||||
fetch-depth: 0 # Shallow clones should be disabled for a better relevancy of analysis
|
fetch-depth: 0 # Shallow clones should be disabled for a better relevancy of analysis
|
||||||
- name: Set up JDK 17
|
- name: Set up JDK 21
|
||||||
uses: actions/setup-java@v3
|
uses: actions/setup-java@v3
|
||||||
with:
|
with:
|
||||||
distribution: 'adopt'
|
distribution: 'adopt'
|
||||||
java-version: 17
|
java-version: 21
|
||||||
- name: Cache SonarCloud packages
|
- name: Cache SonarCloud packages
|
||||||
uses: actions/cache@v3
|
uses: actions/cache@v3
|
||||||
with:
|
with:
|
||||||
|
31
pom.xml
31
pom.xml
@ -178,7 +178,36 @@
|
|||||||
<version>${spigot.version}</version>
|
<version>${spigot.version}</version>
|
||||||
<scope>provided</scope>
|
<scope>provided</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.spigotmc.....</groupId>
|
||||||
|
<artifactId>spigot</artifactId>
|
||||||
|
<version>1.21-R0.1-SNAPSHOT</version>
|
||||||
|
<scope>provided</scope>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.spigotmc....</groupId>
|
||||||
|
<artifactId>spigot</artifactId>
|
||||||
|
<version>1.20.6-R0.1-SNAPSHOT</version>
|
||||||
|
<scope>provided</scope>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.spigotmc.</groupId>
|
||||||
|
<artifactId>spigot</artifactId>
|
||||||
|
<version>1.20.3-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>
|
</dependencies>
|
||||||
|
|
||||||
<build>
|
<build>
|
||||||
|
@ -2,7 +2,6 @@ package world.bentobox.boxed.listeners;
|
|||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.lang.reflect.Field;
|
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.LinkedList;
|
import java.util.LinkedList;
|
||||||
@ -27,7 +26,6 @@ import org.bukkit.block.structure.Mirror;
|
|||||||
import org.bukkit.block.structure.StructureRotation;
|
import org.bukkit.block.structure.StructureRotation;
|
||||||
import org.bukkit.configuration.ConfigurationSection;
|
import org.bukkit.configuration.ConfigurationSection;
|
||||||
import org.bukkit.configuration.file.YamlConfiguration;
|
import org.bukkit.configuration.file.YamlConfiguration;
|
||||||
import org.bukkit.craftbukkit.v1_20_R3.CraftWorld;
|
|
||||||
import org.bukkit.entity.Entity;
|
import org.bukkit.entity.Entity;
|
||||||
import org.bukkit.entity.EntityType;
|
import org.bukkit.entity.EntityType;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
@ -43,10 +41,6 @@ import org.bukkit.util.Vector;
|
|||||||
import com.google.common.base.Enums;
|
import com.google.common.base.Enums;
|
||||||
import com.google.gson.Gson;
|
import com.google.gson.Gson;
|
||||||
|
|
||||||
import net.minecraft.core.BlockPosition;
|
|
||||||
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;
|
import world.bentobox.bentobox.BentoBox;
|
||||||
import world.bentobox.bentobox.api.events.BentoBoxReadyEvent;
|
import world.bentobox.bentobox.api.events.BentoBoxReadyEvent;
|
||||||
import world.bentobox.bentobox.api.events.island.IslandCreatedEvent;
|
import world.bentobox.bentobox.api.events.island.IslandCreatedEvent;
|
||||||
@ -56,6 +50,7 @@ import world.bentobox.bentobox.database.objects.Island;
|
|||||||
import world.bentobox.bentobox.util.Pair;
|
import world.bentobox.bentobox.util.Pair;
|
||||||
import world.bentobox.bentobox.util.Util;
|
import world.bentobox.bentobox.util.Util;
|
||||||
import world.bentobox.boxed.Boxed;
|
import world.bentobox.boxed.Boxed;
|
||||||
|
import world.bentobox.boxed.nms.AbstractMetaData;
|
||||||
import world.bentobox.boxed.objects.BoxedJigsawBlock;
|
import world.bentobox.boxed.objects.BoxedJigsawBlock;
|
||||||
import world.bentobox.boxed.objects.BoxedStructureBlock;
|
import world.bentobox.boxed.objects.BoxedStructureBlock;
|
||||||
import world.bentobox.boxed.objects.IslandStructures;
|
import world.bentobox.boxed.objects.IslandStructures;
|
||||||
@ -547,22 +542,23 @@ public class NewAreaListener implements Listener {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private static String nmsData(Block block) {
|
private static String nmsData(Block block) {
|
||||||
Location w = block.getLocation();
|
// Bukkit method that was added in 2011
|
||||||
CraftWorld cw = (CraftWorld) w.getWorld(); // CraftWorld is NMS one
|
// Example value: 1.20.4-R0.1-SNAPSHOT
|
||||||
// for 1.13+ (we have use WorldServer)
|
String bukkitVersion = "v" + Bukkit.getBukkitVersion().replace('.', '_').replace('-', '_');
|
||||||
TileEntity te = cw.getHandle().c_(new BlockPosition(w.getBlockX(), w.getBlockY(), w.getBlockZ()));
|
String pluginPackageName = BentoBox.getInstance().getClass().getPackage().getName();
|
||||||
|
AbstractMetaData handler;
|
||||||
try {
|
try {
|
||||||
PacketPlayOutTileEntityData packet = ((PacketPlayOutTileEntityData) te.j()); // get update packet from NMS
|
Class<?> clazz = Class.forName(pluginPackageName + ".nms." + bukkitVersion + ".GetMetaData");
|
||||||
// object
|
if (AbstractMetaData.class.isAssignableFrom(clazz)) {
|
||||||
// here we should use reflection because "c" field isn't accessible
|
handler = (AbstractMetaData) clazz.getConstructor().newInstance();
|
||||||
Field f = packet.getClass().getDeclaredField("c"); // get field
|
} else {
|
||||||
f.setAccessible(true); // make it available
|
throw new IllegalStateException("Class " + clazz.getName() + " does not implement AbstractGetMetaData");
|
||||||
NBTTagCompound nbtTag = (NBTTagCompound) f.get(packet);
|
|
||||||
return nbtTag.toString(); // this will show what you want
|
|
||||||
} catch (Exception exc) {
|
|
||||||
exc.printStackTrace();
|
|
||||||
}
|
}
|
||||||
return "Nothing";
|
} catch (Exception e) {
|
||||||
|
BentoBox.getInstance().logWarning("No metadata handler found for " + bukkitVersion + " in Boxed.");
|
||||||
|
handler = new world.bentobox.boxed.nms.fallback.GetMetaData();
|
||||||
|
}
|
||||||
|
return handler.nmsData(block);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
12
src/main/java/world/bentobox/boxed/nms/AbstractMetaData.java
Normal file
12
src/main/java/world/bentobox/boxed/nms/AbstractMetaData.java
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
package world.bentobox.boxed.nms;
|
||||||
|
|
||||||
|
import org.bukkit.block.Block;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public abstract class AbstractMetaData {
|
||||||
|
|
||||||
|
public abstract String nmsData(Block block);
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,17 @@
|
|||||||
|
package world.bentobox.boxed.nms.fallback;
|
||||||
|
|
||||||
|
import org.bukkit.block.Block;
|
||||||
|
|
||||||
|
import world.bentobox.boxed.nms.AbstractMetaData;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Fallback
|
||||||
|
*/
|
||||||
|
public class GetMetaData extends AbstractMetaData {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String nmsData(Block block) {
|
||||||
|
return "Nothing"; // We cannot read it if we have no NMS
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,37 @@
|
|||||||
|
package world.bentobox.boxed.nms.v1_20_4_R0_1_SNAPSHOT;
|
||||||
|
|
||||||
|
import java.lang.reflect.Field;
|
||||||
|
|
||||||
|
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.nbt.NBTTagCompound;
|
||||||
|
import net.minecraft.network.protocol.game.PacketPlayOutTileEntityData;
|
||||||
|
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()));
|
||||||
|
try {
|
||||||
|
PacketPlayOutTileEntityData packet = ((PacketPlayOutTileEntityData) te.j()); // get update packet from NMS
|
||||||
|
// object
|
||||||
|
// here we should use reflection because "c" field isn't accessible
|
||||||
|
Field f = packet.getClass().getDeclaredField("c"); // get field
|
||||||
|
f.setAccessible(true); // make it available
|
||||||
|
NBTTagCompound nbtTag = (NBTTagCompound) f.get(packet);
|
||||||
|
return nbtTag.toString(); // this will show what you want
|
||||||
|
} catch (Exception exc) {
|
||||||
|
exc.printStackTrace();
|
||||||
|
}
|
||||||
|
return "Nothing";
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,37 @@
|
|||||||
|
package world.bentobox.boxed.nms.v1_20_6_R0_1_SNAPSHOT;
|
||||||
|
|
||||||
|
import java.lang.reflect.Field;
|
||||||
|
|
||||||
|
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.nbt.NBTTagCompound;
|
||||||
|
import net.minecraft.network.protocol.game.PacketPlayOutTileEntityData;
|
||||||
|
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()));
|
||||||
|
try {
|
||||||
|
PacketPlayOutTileEntityData packet = ((PacketPlayOutTileEntityData) te.j()); // get update packet from NMS
|
||||||
|
// object
|
||||||
|
// here we should use reflection because "c" field isn't accessible
|
||||||
|
Field f = packet.getClass().getDeclaredField("c"); // get field
|
||||||
|
f.setAccessible(true); // make it available
|
||||||
|
NBTTagCompound nbtTag = (NBTTagCompound) f.get(packet);
|
||||||
|
return nbtTag.toString(); // this will show what you want
|
||||||
|
} catch (Exception exc) {
|
||||||
|
exc.printStackTrace();
|
||||||
|
}
|
||||||
|
return "Nothing";
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,37 @@
|
|||||||
|
package world.bentobox.boxed.nms.v1_21_R0_1_SNAPSHOT;
|
||||||
|
|
||||||
|
import java.lang.reflect.Field;
|
||||||
|
|
||||||
|
import org.bukkit.Location;
|
||||||
|
import org.bukkit.block.Block;
|
||||||
|
import org.bukkit.craftbukkit.v1_21_R1.CraftWorld;
|
||||||
|
|
||||||
|
import net.minecraft.core.BlockPosition;
|
||||||
|
import net.minecraft.nbt.NBTTagCompound;
|
||||||
|
import net.minecraft.network.protocol.game.PacketPlayOutTileEntityData;
|
||||||
|
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()));
|
||||||
|
try {
|
||||||
|
PacketPlayOutTileEntityData packet = ((PacketPlayOutTileEntityData) te.j()); // get update packet from NMS
|
||||||
|
// object
|
||||||
|
// here we should use reflection because "c" field isn't accessible
|
||||||
|
Field f = packet.getClass().getDeclaredField("c"); // get field
|
||||||
|
f.setAccessible(true); // make it available
|
||||||
|
NBTTagCompound nbtTag = (NBTTagCompound) f.get(packet);
|
||||||
|
return nbtTag.toString(); // this will show what you want
|
||||||
|
} catch (Exception exc) {
|
||||||
|
exc.printStackTrace();
|
||||||
|
}
|
||||||
|
return "Nothing";
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user