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.mining.MiningManager;
|
||||||
import com.gmail.nossr50.skills.taming.TamingManager;
|
import com.gmail.nossr50.skills.taming.TamingManager;
|
||||||
import com.gmail.nossr50.util.ChimaeraWing;
|
import com.gmail.nossr50.util.ChimaeraWing;
|
||||||
import com.gmail.nossr50.util.nbt.NBTManager;
|
|
||||||
import com.gmail.nossr50.util.sounds.SoundType;
|
import com.gmail.nossr50.util.sounds.SoundType;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.ChatColor;
|
import org.bukkit.ChatColor;
|
||||||
@ -908,7 +907,7 @@ public class PlayerListener implements Listener {
|
|||||||
switch(event.getAction()) {
|
switch(event.getAction()) {
|
||||||
case LEFT_CLICK_AIR:
|
case LEFT_CLICK_AIR:
|
||||||
case LEFT_CLICK_BLOCK:
|
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.CommandRegistrationManager;
|
||||||
import com.gmail.nossr50.util.commands.CommandTools;
|
import com.gmail.nossr50.util.commands.CommandTools;
|
||||||
import com.gmail.nossr50.util.experience.FormulaManager;
|
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.NotificationManager;
|
||||||
import com.gmail.nossr50.util.player.PlayerLevelTools;
|
import com.gmail.nossr50.util.player.PlayerLevelTools;
|
||||||
import com.gmail.nossr50.util.player.UserManager;
|
import com.gmail.nossr50.util.player.UserManager;
|
||||||
@ -75,7 +76,7 @@ public class mcMMO extends JavaPlugin {
|
|||||||
private FormulaManager formulaManager;
|
private FormulaManager formulaManager;
|
||||||
private NotificationManager notificationManager;
|
private NotificationManager notificationManager;
|
||||||
private CommandRegistrationManager commandRegistrationManager;
|
private CommandRegistrationManager commandRegistrationManager;
|
||||||
// private NBTManager nbtManager;
|
private NBTManager nbtManager;
|
||||||
private PartyManager partyManager;
|
private PartyManager partyManager;
|
||||||
private LocaleManager localeManager;
|
private LocaleManager localeManager;
|
||||||
private ChatManager chatManager;
|
private ChatManager chatManager;
|
||||||
@ -212,7 +213,7 @@ public class mcMMO extends JavaPlugin {
|
|||||||
commandRegistrationManager = new CommandRegistrationManager(this);
|
commandRegistrationManager = new CommandRegistrationManager(this);
|
||||||
commandRegistrationManager.registerCommands();
|
commandRegistrationManager.registerCommands();
|
||||||
|
|
||||||
// nbtManager = new NBTManager();
|
nbtManager = new NBTManager();
|
||||||
|
|
||||||
//Init Chunk Manager Factory
|
//Init Chunk Manager Factory
|
||||||
chunkManagerFactory = new ChunkManagerFactory(this);
|
chunkManagerFactory = new ChunkManagerFactory(this);
|
||||||
@ -857,4 +858,8 @@ public class mcMMO extends JavaPlugin {
|
|||||||
public PerkUtils getPerkUtils() {
|
public PerkUtils getPerkUtils() {
|
||||||
return perkUtils;
|
return perkUtils;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public NBTManager getNbtManager() {
|
||||||
|
return nbtManager;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,23 +1,21 @@
|
|||||||
package com.gmail.nossr50.util.nbt;
|
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.NBTBase;
|
||||||
import net.minecraft.server.v1_14_R1.NBTList;
|
import net.minecraft.server.v1_14_R1.NBTList;
|
||||||
import net.minecraft.server.v1_14_R1.NBTTagCompound;
|
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.inventory.CraftItemStack;
|
||||||
import org.bukkit.craftbukkit.v1_14_R1.util.CraftNBTTagConfigSerializer;
|
import org.bukkit.craftbukkit.v1_14_R1.util.CraftNBTTagConfigSerializer;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.inventory.ItemStack;
|
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.InvocationTargetException;
|
||||||
import java.lang.reflect.Method;
|
import java.lang.reflect.Method;
|
||||||
|
|
||||||
public class NBTManager {
|
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;
|
private Class<?> craftMetaItemClass;
|
||||||
|
|
||||||
public NBTManager() {
|
public NBTManager() {
|
||||||
@ -25,42 +23,68 @@ public class NBTManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void init() {
|
private void init() {
|
||||||
try {
|
// try {
|
||||||
Class<?> craftMetaItemClass = Class.forName(CRAFT_META_ITEM_CLASS_PATH); //for type comparisons
|
// Class<?> craftMetaItemClass = Class.forName(CRAFT_META_ITEM_CLASS_PATH); //for type comparisons
|
||||||
} catch (ClassNotFoundException e) {
|
// } catch (ClassNotFoundException e) {
|
||||||
e.printStackTrace();
|
// e.printStackTrace();
|
||||||
}
|
// }
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void debugNBTInMainHandItem(Player player) {
|
public void debugNBTInMainHandItem(Player player) {
|
||||||
player.sendMessage("Starting NBT Debug Dump...");
|
player.sendMessage("Starting NBT Debug Dump...");
|
||||||
ItemStack itemStack = player.getInventory().getItemInMainHand();
|
ItemStack itemStack = player.getInventory().getItemInMainHand();
|
||||||
player.sendMessage("Checking NBT for "+itemStack.toString());
|
player.sendMessage("Checking NBT for "+itemStack.toString());
|
||||||
NBTTagCompound nbtTagCompound = getNBT(itemStack);
|
NBTTagCompound nbtTagCompound = getNBTCopy(itemStack);
|
||||||
|
|
||||||
if(nbtTagCompound == null) {
|
|
||||||
player.sendMessage("No NBT data found for main hand item.");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
player.sendMessage("Total NBT Entries: "+nbtTagCompound.getKeys().size());
|
player.sendMessage("Total NBT Entries: "+nbtTagCompound.getKeys().size());
|
||||||
printNBT(nbtTagCompound, player);
|
printNBT(nbtTagCompound, player);
|
||||||
player.sendMessage("-- END OF NBT REPORT --");
|
player.sendMessage("-- END OF NBT REPORT --");
|
||||||
|
|
||||||
player.sendMessage("Attempting to add NBT key named - Herp");
|
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());
|
player.sendMessage("(After HERP) Total NBT Entries: "+nbtTagCompound.getKeys().size());
|
||||||
printNBT(nbtTagCompound, player);
|
printNBT(nbtTagCompound, player);
|
||||||
player.sendMessage("-- END OF NBT REPORT --");
|
player.sendMessage("-- END OF NBT REPORT --");
|
||||||
|
|
||||||
player.sendMessage("Attempting to save NBT data...");
|
player.sendMessage("Attempting to save NBT data...");
|
||||||
player.getInventory().setItemInMainHand(saveNBT(itemStack, nbtTagCompound));
|
|
||||||
player.updateInventory();
|
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 {
|
try {
|
||||||
Class clazz = Class.forName("net.minecraft.server.v1_14_R1.ItemStack");
|
Class clazz = Class.forName("net.minecraft.server.v1_14_R1.ItemStack");
|
||||||
@ -72,26 +96,10 @@ public class NBTManager {
|
|||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
|
|
||||||
// nmsItemStack.save(nbtTagCompound);
|
return nmsItemStack;
|
||||||
// itemStack.setItemMeta(nmsItemStack..getItemMeta());
|
|
||||||
return itemStack;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static net.minecraft.server.v1_14_R1.ItemStack getNMSItemStack(ItemStack itemStack) {
|
public NBTBase constructNBT(String nbtString) {
|
||||||
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) {
|
|
||||||
try {
|
try {
|
||||||
return CraftNBTTagConfigSerializer.deserialize(nbtString);
|
return CraftNBTTagConfigSerializer.deserialize(nbtString);
|
||||||
} catch (Exception e) {
|
} 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()) {
|
for(String key : nbtTagCompound.getKeys()) {
|
||||||
player.sendMessage("");
|
player.sendMessage("");
|
||||||
player.sendMessage("NBT Key: "+key);
|
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<?>) {
|
if(nbt instanceof NBTList<?>) {
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
|
Loading…
Reference in New Issue
Block a user