mirror of
https://github.com/mcMMO-Dev/mcMMO.git
synced 2024-11-25 06:36:45 +01:00
Starting work on reading NBT
This commit is contained in:
parent
d2028321d4
commit
0509f4f63e
@ -15,6 +15,7 @@ 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;
|
||||||
@ -898,4 +899,18 @@ public class PlayerListener implements Listener {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@EventHandler(priority = EventPriority.LOWEST)
|
||||||
|
public void onDebugPlayerInteract(PlayerInteractEvent event) {
|
||||||
|
if(pluginRef.getUserManager().getPlayer(event.getPlayer()) != null) {
|
||||||
|
McMMOPlayer mcMMOPlayer = pluginRef.getUserManager().getPlayer(event.getPlayer());
|
||||||
|
if(mcMMOPlayer.isDebugMode()) {
|
||||||
|
switch(event.getAction()) {
|
||||||
|
case LEFT_CLICK_AIR:
|
||||||
|
case LEFT_CLICK_BLOCK:
|
||||||
|
NBTManager.debugNBTInMainHandItem(event.getPlayer());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -4,10 +4,11 @@ package com.gmail.nossr50.util.nbt;
|
|||||||
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.inventory.ItemStack;
|
import org.bukkit.inventory.ItemStack;
|
||||||
|
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||||
|
|
||||||
public class NBTManager {
|
public class NBTManager {
|
||||||
|
|
||||||
@ -26,11 +27,26 @@ public class NBTManager {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static 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;
|
||||||
|
}
|
||||||
|
|
||||||
|
player.sendMessage("Total NBT Entries: "+nbtTagCompound.getKeys().size());
|
||||||
|
printNBT(nbtTagCompound, player);
|
||||||
|
player.sendMessage("-- END OF NBT REPORT --");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Nullable
|
||||||
public static NBTTagCompound getNBT(ItemStack itemStack) {
|
public static NBTTagCompound getNBT(ItemStack itemStack) {
|
||||||
Bukkit.broadcastMessage("Checking NBT for "+itemStack.toString());
|
|
||||||
net.minecraft.server.v1_14_R1.ItemStack nmsItemStack = CraftItemStack.asNMSCopy(itemStack);
|
net.minecraft.server.v1_14_R1.ItemStack nmsItemStack = CraftItemStack.asNMSCopy(itemStack);
|
||||||
NBTTagCompound rootTag = nmsItemStack.getTag();
|
return nmsItemStack.getTag();
|
||||||
return rootTag;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static NBTBase constructNBT(String nbtString) {
|
public static NBTBase constructNBT(String nbtString) {
|
||||||
@ -43,9 +59,11 @@ public class NBTManager {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void printNBT(ItemStack itemStack) {
|
public static void printNBT(NBTTagCompound nbtTagCompound, Player player) {
|
||||||
for(String key : getNBT(itemStack).getKeys()) {
|
for(String key : nbtTagCompound.getKeys()) {
|
||||||
Bukkit.broadcastMessage("NBT Key found: "+key);
|
player.sendMessage("");
|
||||||
|
player.sendMessage("NBT Key: "+key);
|
||||||
|
player.sendMessage("NBT Value: " + nbtTagCompound.get(key).asString());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user