mirror of
https://github.com/mcMMO-Dev/mcMMO.git
synced 2024-11-24 22:26:46 +01:00
Add showtags subcommand to nbttools
This commit is contained in:
parent
f45c70b694
commit
3c382a11ed
@ -1,22 +1,44 @@
|
||||
package com.gmail.nossr50.commands.admin;
|
||||
|
||||
import co.aikar.commands.BaseCommand;
|
||||
import co.aikar.commands.annotation.CommandAlias;
|
||||
import co.aikar.commands.annotation.Default;
|
||||
import co.aikar.commands.annotation.Dependency;
|
||||
import co.aikar.commands.annotation.Description;
|
||||
import co.aikar.commands.annotation.*;
|
||||
import com.gmail.nossr50.mcMMO;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
@CommandAlias("nbttools")
|
||||
@Description("Read or Modify values of NBT on an item in-hand")
|
||||
public class NBTToolsCommand extends BaseCommand {
|
||||
|
||||
public static final String STYLE_TEXT_1 = "//////////";
|
||||
@Dependency
|
||||
private mcMMO pluginRef;
|
||||
private mcMMO plugin;
|
||||
|
||||
@Default
|
||||
public void onCommand(Player player) {
|
||||
player.sendMessage("hi");
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the NBT tags of an item in hand
|
||||
*/
|
||||
@Subcommand("showtags")
|
||||
public void onShowTags(Player player) {
|
||||
//Show NBT tags to player
|
||||
player.sendMessage(STYLE_TEXT_1 + " NBT TOOLS " + STYLE_TEXT_1);
|
||||
player.sendMessage("NBT Analysis: " + player.getInventory().getItemInMainHand().getType().getKey().toString());
|
||||
player.sendMessage(STYLE_TEXT_1 + STYLE_TEXT_1);
|
||||
plugin.getNbtManager().printNBT(player.getInventory().getItemInMainHand(), player);
|
||||
player.sendMessage(ChatColor.GRAY + "NBT Analysis completed!");
|
||||
}
|
||||
|
||||
@Subcommand("add")
|
||||
public void onAddTags(Player player) {
|
||||
|
||||
}
|
||||
|
||||
@Subcommand("remove")
|
||||
public void onRemoveTags(Player player) {
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -4,6 +4,7 @@ package com.gmail.nossr50.util.nbt;
|
||||
import com.gmail.nossr50.core.nbt.NBTBase;
|
||||
import net.minecraft.server.v1_14_R1.NBTList;
|
||||
import net.minecraft.server.v1_14_R1.NBTTagCompound;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.craftbukkit.v1_14_R1.inventory.CraftItemStack;
|
||||
import org.bukkit.craftbukkit.v1_14_R1.util.CraftNBTTagConfigSerializer;
|
||||
import org.bukkit.entity.Player;
|
||||
@ -166,11 +167,36 @@ public class NBTManager {
|
||||
*/
|
||||
public void printNBT(ItemStack itemStack, Player player) {
|
||||
NBTTagCompound tagCompoundCopy = getNBTCopy(itemStack);
|
||||
for(String key : tagCompoundCopy.getKeys()) {
|
||||
player.sendMessage("");
|
||||
player.sendMessage("NBT Key: "+key);
|
||||
player.sendMessage("NBT Value: " + tagCompoundCopy.get(key).asString());
|
||||
printNBT(tagCompoundCopy, player);
|
||||
}
|
||||
|
||||
private void printNBT(NBTTagCompound nbtTagCompound, Player player) {
|
||||
for(String key : nbtTagCompound.getKeys()) {
|
||||
player.sendMessage("");
|
||||
|
||||
net.minecraft.server.v1_14_R1.NBTBase targetTag = nbtTagCompound.get(key);
|
||||
|
||||
//Recursively print contents
|
||||
if(targetTag instanceof NBTTagCompound) {
|
||||
NBTTagCompound childTagCompound = nbtTagCompound.getCompound(key);
|
||||
if(childTagCompound != null) {
|
||||
player.sendMessage(ChatColor.BLUE + "NBT named " + ChatColor.GOLD + key + ChatColor.BLUE + " is a tag compound, printing contents...");
|
||||
printNBT(childTagCompound, player);
|
||||
player.sendMessage(ChatColor.BLUE + "Exiting "+ key);
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
player.sendMessage(ChatColor.GOLD + "Tag Key: " + ChatColor.RESET + key);
|
||||
|
||||
if(targetTag == null) {
|
||||
player.sendMessage(ChatColor.RED + "Tag is null!");
|
||||
continue;
|
||||
}
|
||||
|
||||
player.sendMessage(ChatColor.GREEN + "Tag Value: " + ChatColor.RESET + targetTag.asString());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public boolean hasNBT(NBTBase nbt, NBTTagCompound otherNbt) {
|
||||
|
Loading…
Reference in New Issue
Block a user