mirror of
https://github.com/mcMMO-Dev/mcMMO.git
synced 2024-11-25 06:36:45 +01:00
Progress??
This commit is contained in:
parent
6e0f8f99fa
commit
8febe2d0bd
@ -15,7 +15,6 @@ import com.gmail.nossr50.skills.herbalism.HerbalismManager;
|
||||
import com.gmail.nossr50.skills.mining.MiningManager;
|
||||
import com.gmail.nossr50.skills.taming.TamingManager;
|
||||
import com.gmail.nossr50.util.ChimaeraWing;
|
||||
import com.gmail.nossr50.util.nbt.NBTManager;
|
||||
import com.gmail.nossr50.util.sounds.SoundType;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
@ -908,7 +907,7 @@ public class PlayerListener implements Listener {
|
||||
switch(event.getAction()) {
|
||||
case LEFT_CLICK_AIR:
|
||||
case LEFT_CLICK_BLOCK:
|
||||
NBTManager.debugNBTInMainHandItem(event.getPlayer());
|
||||
pluginRef.getNbtManager().debugNBTInMainHandItem(event.getPlayer());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -33,6 +33,7 @@ import com.gmail.nossr50.util.blockmeta.chunkmeta.ChunkManagerFactory;
|
||||
import com.gmail.nossr50.util.commands.CommandRegistrationManager;
|
||||
import com.gmail.nossr50.util.commands.CommandTools;
|
||||
import com.gmail.nossr50.util.experience.FormulaManager;
|
||||
import com.gmail.nossr50.util.nbt.NBTManager;
|
||||
import com.gmail.nossr50.util.player.NotificationManager;
|
||||
import com.gmail.nossr50.util.player.PlayerLevelTools;
|
||||
import com.gmail.nossr50.util.player.UserManager;
|
||||
@ -75,7 +76,7 @@ public class mcMMO extends JavaPlugin {
|
||||
private FormulaManager formulaManager;
|
||||
private NotificationManager notificationManager;
|
||||
private CommandRegistrationManager commandRegistrationManager;
|
||||
// private NBTManager nbtManager;
|
||||
private NBTManager nbtManager;
|
||||
private PartyManager partyManager;
|
||||
private LocaleManager localeManager;
|
||||
private ChatManager chatManager;
|
||||
@ -212,7 +213,7 @@ public class mcMMO extends JavaPlugin {
|
||||
commandRegistrationManager = new CommandRegistrationManager(this);
|
||||
commandRegistrationManager.registerCommands();
|
||||
|
||||
// nbtManager = new NBTManager();
|
||||
nbtManager = new NBTManager();
|
||||
|
||||
//Init Chunk Manager Factory
|
||||
chunkManagerFactory = new ChunkManagerFactory(this);
|
||||
@ -857,4 +858,8 @@ public class mcMMO extends JavaPlugin {
|
||||
public PerkUtils getPerkUtils() {
|
||||
return perkUtils;
|
||||
}
|
||||
|
||||
public NBTManager getNbtManager() {
|
||||
return nbtManager;
|
||||
}
|
||||
}
|
||||
|
@ -1,23 +1,21 @@
|
||||
package com.gmail.nossr50.util.nbt;
|
||||
|
||||
|
||||
import net.minecraft.server.v1_14_R1.Item;
|
||||
import net.minecraft.server.v1_14_R1.NBTBase;
|
||||
import net.minecraft.server.v1_14_R1.NBTList;
|
||||
import net.minecraft.server.v1_14_R1.NBTTagCompound;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.craftbukkit.v1_14_R1.inventory.CraftItemStack;
|
||||
import org.bukkit.craftbukkit.v1_14_R1.util.CraftNBTTagConfigSerializer;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.lang.reflect.Method;
|
||||
|
||||
public class NBTManager {
|
||||
|
||||
private static final String CRAFT_META_ITEM_CLASS_PATH = "org.bukkit.craftbukkit.inventory.CraftMetaItem";
|
||||
private final String CRAFT_META_ITEM_CLASS_PATH = "org.bukkit.craftbukkit.inventory.CraftMetaItem";
|
||||
private Class<?> craftMetaItemClass;
|
||||
|
||||
public NBTManager() {
|
||||
@ -25,42 +23,68 @@ public class NBTManager {
|
||||
}
|
||||
|
||||
private void init() {
|
||||
try {
|
||||
Class<?> craftMetaItemClass = Class.forName(CRAFT_META_ITEM_CLASS_PATH); //for type comparisons
|
||||
} catch (ClassNotFoundException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
// try {
|
||||
// Class<?> craftMetaItemClass = Class.forName(CRAFT_META_ITEM_CLASS_PATH); //for type comparisons
|
||||
// } catch (ClassNotFoundException e) {
|
||||
// e.printStackTrace();
|
||||
// }
|
||||
}
|
||||
|
||||
public static void debugNBTInMainHandItem(Player player) {
|
||||
public void debugNBTInMainHandItem(Player player) {
|
||||
player.sendMessage("Starting NBT Debug Dump...");
|
||||
ItemStack itemStack = player.getInventory().getItemInMainHand();
|
||||
player.sendMessage("Checking NBT for "+itemStack.toString());
|
||||
NBTTagCompound nbtTagCompound = getNBT(itemStack);
|
||||
|
||||
if(nbtTagCompound == null) {
|
||||
player.sendMessage("No NBT data found for main hand item.");
|
||||
return;
|
||||
}
|
||||
NBTTagCompound nbtTagCompound = getNBTCopy(itemStack);
|
||||
|
||||
player.sendMessage("Total NBT Entries: "+nbtTagCompound.getKeys().size());
|
||||
printNBT(nbtTagCompound, player);
|
||||
player.sendMessage("-- END OF NBT REPORT --");
|
||||
|
||||
player.sendMessage("Attempting to add NBT key named - Herp");
|
||||
addFloatNBT(nbtTagCompound, "herp", 13.37F);
|
||||
addFloatNBT(itemStack, "herp", 13.37F);
|
||||
|
||||
player.sendMessage("(After HERP) Total NBT Entries: "+nbtTagCompound.getKeys().size());
|
||||
printNBT(nbtTagCompound, player);
|
||||
player.sendMessage("-- END OF NBT REPORT --");
|
||||
|
||||
player.sendMessage("Attempting to save NBT data...");
|
||||
player.getInventory().setItemInMainHand(saveNBT(itemStack, nbtTagCompound));
|
||||
player.updateInventory();
|
||||
}
|
||||
|
||||
public static ItemStack saveNBT(ItemStack itemStack, NBTTagCompound nbtTagCompound) {
|
||||
net.minecraft.server.v1_14_R1.ItemStack nmsItemStack = getNMSItemStack(itemStack);
|
||||
|
||||
|
||||
public void addNewNBT(ItemStack itemStack) {
|
||||
|
||||
}
|
||||
|
||||
public net.minecraft.server.v1_14_R1.ItemStack getNMSItemStack(ItemStack itemStack) {
|
||||
return CraftItemStack.asNMSCopy(itemStack);
|
||||
}
|
||||
|
||||
@NonNull
|
||||
public NBTTagCompound getNBTCopy(ItemStack itemStack) {
|
||||
net.minecraft.server.v1_14_R1.ItemStack nmsItemStack = CraftItemStack.asNMSCopy(itemStack);
|
||||
return nmsItemStack.save(new NBTTagCompound());
|
||||
}
|
||||
|
||||
public void addFloatNBT(ItemStack itemStack, String key, float value) {
|
||||
//NBT Copied off Item
|
||||
net.minecraft.server.v1_14_R1.ItemStack nmsIS = getNMSItemStack(itemStack);
|
||||
NBTTagCompound freshNBTCopy = nmsIS.save(new NBTTagCompound());
|
||||
|
||||
//New Float NBT Value
|
||||
NBTTagCompound updatedNBT = new NBTTagCompound();
|
||||
updatedNBT.setFloat(key, value);
|
||||
|
||||
//Merge
|
||||
freshNBTCopy.a(updatedNBT);
|
||||
|
||||
//Invoke load() time
|
||||
applyNBT(nmsIS, updatedNBT);
|
||||
}
|
||||
|
||||
|
||||
public net.minecraft.server.v1_14_R1.ItemStack applyNBT(net.minecraft.server.v1_14_R1.ItemStack nmsItemStack, NBTTagCompound nbtTagCompound) {
|
||||
|
||||
try {
|
||||
Class clazz = Class.forName("net.minecraft.server.v1_14_R1.ItemStack");
|
||||
@ -72,26 +96,10 @@ public class NBTManager {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
// nmsItemStack.save(nbtTagCompound);
|
||||
// itemStack.setItemMeta(nmsItemStack..getItemMeta());
|
||||
return itemStack;
|
||||
return nmsItemStack;
|
||||
}
|
||||
|
||||
public static net.minecraft.server.v1_14_R1.ItemStack getNMSItemStack(ItemStack itemStack) {
|
||||
return CraftItemStack.asNMSCopy(itemStack);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public static NBTTagCompound getNBT(ItemStack itemStack) {
|
||||
net.minecraft.server.v1_14_R1.ItemStack nmsItemStack = CraftItemStack.asNMSCopy(itemStack);
|
||||
return nmsItemStack.getTag();
|
||||
}
|
||||
|
||||
public static void addFloatNBT(NBTTagCompound nbtTagCompound, String key, float value) {
|
||||
nbtTagCompound.setFloat(key, value);
|
||||
}
|
||||
|
||||
public static NBTBase constructNBT(String nbtString) {
|
||||
public NBTBase constructNBT(String nbtString) {
|
||||
try {
|
||||
return CraftNBTTagConfigSerializer.deserialize(nbtString);
|
||||
} catch (Exception e) {
|
||||
@ -101,7 +109,7 @@ public class NBTManager {
|
||||
}
|
||||
}
|
||||
|
||||
public static void printNBT(NBTTagCompound nbtTagCompound, Player player) {
|
||||
public void printNBT(NBTTagCompound nbtTagCompound, Player player) {
|
||||
for(String key : nbtTagCompound.getKeys()) {
|
||||
player.sendMessage("");
|
||||
player.sendMessage("NBT Key: "+key);
|
||||
@ -109,7 +117,7 @@ public class NBTManager {
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean hasNBT(NBTBase nbt, NBTTagCompound otherNbt) {
|
||||
public boolean hasNBT(NBTBase nbt, NBTTagCompound otherNbt) {
|
||||
if(nbt instanceof NBTList<?>) {
|
||||
|
||||
} else {
|
||||
|
Loading…
Reference in New Issue
Block a user