-
-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathAbstractMetaData.java
More file actions
45 lines (37 loc) · 1.88 KB
/
AbstractMetaData.java
File metadata and controls
45 lines (37 loc) · 1.88 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
package world.bentobox.boxed.nms;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
import org.bukkit.block.Block;
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) {
try {
// Check if the method 'j' exists
Method updatePacketMethod = te.getClass().getDeclaredMethod(method);
if (updatePacketMethod != null) {
// Invoke the method to get the PacketPlayOutTileEntityData object
updatePacketMethod.setAccessible(true);
Object object = updatePacketMethod.invoke(te);
PacketPlayOutTileEntityData packet = (PacketPlayOutTileEntityData) object;
//if (object instanceof PacketPlayOutTileEntityData packet) {
// Access the private field for the NBTTagCompound getter in PacketPlayOutTileEntityData
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(
// object.getClass().getCanonicalName() + " is not a PacketPlayOutTileEntityData");
//}
}
} catch (Exception e) {
System.out.println("The method '" + method + "' does not exist in the TileEntity class.");
e.printStackTrace();
}
return "";
}
}