testserver/Spigot-Server-Patches/0511-Paper-dumpitem-command...

85 lines
3.9 KiB
Diff
Raw Normal View History

From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Aikar <aikar@aikar.co>
Date: Sun, 28 Jun 2020 19:27:20 -0400
Subject: [PATCH] Paper dumpitem command
Let's you quickly view the item in your hands NBT data
diff --git a/src/main/java/com/destroystokyo/paper/PaperCommand.java b/src/main/java/com/destroystokyo/paper/PaperCommand.java
index f60800c3bc06a38493e17b00b815f18cb87cc8bf..0abfe19e204d20af0f8dedbeedb0ef98dfe9d3c8 100644
--- a/src/main/java/com/destroystokyo/paper/PaperCommand.java
+++ b/src/main/java/com/destroystokyo/paper/PaperCommand.java
@@ -21,7 +21,9 @@ import org.bukkit.command.CommandSender;
import org.bukkit.craftbukkit.CraftServer;
import org.bukkit.craftbukkit.CraftWorld;
import org.bukkit.craftbukkit.entity.CraftPlayer;
+import org.bukkit.craftbukkit.inventory.CraftItemStack;
import org.bukkit.entity.Player;
+import org.bukkit.inventory.ItemStack;
import java.io.File;
import java.io.FileOutputStream;
@@ -37,14 +39,14 @@ public class PaperCommand extends Command {
public PaperCommand(String name) {
super(name);
this.description = "Paper related commands";
- this.usageMessage = "/paper [heap | entity | reload | version | debug | dumpwaiting | chunkinfo | syncloadinfo | fixlight]";
+ this.usageMessage = "/paper [heap | entity | reload | version | debug | dumpwaiting | chunkinfo | syncloadinfo | fixlight | dumpitem]";
this.setPermission("bukkit.command.paper");
}
@Override
public List<String> tabComplete(CommandSender sender, String alias, String[] args, Location location) throws IllegalArgumentException {
if (args.length <= 1)
- return getListMatchingLast(args, "heap", "entity", "reload", "version", "debug", "dumpwaiting", "chunkinfo", "syncloadinfo", "fixlight");
+ return getListMatchingLast(args, "heap", "entity", "reload", "version", "debug", "dumpwaiting", "chunkinfo", "syncloadinfo", "fixlight", "dumpitem");
switch (args[0].toLowerCase(Locale.ENGLISH))
{
@@ -133,6 +135,9 @@ public class PaperCommand extends Command {
case "reload":
doReload(sender);
break;
+ case "dumpitem":
+ doDumpItem(sender);
+ break;
case "debug":
doDebug(sender, args);
break;
@@ -164,6 +169,23 @@ public class PaperCommand extends Command {
return true;
}
+ private void doDumpItem(CommandSender sender) {
+ if (!(sender instanceof Player)) {
+ sender.sendMessage("Only players can use this command");
+ return;
+ }
+ ItemStack itemInHand = ((CraftPlayer) sender).getItemInHand();
+ net.minecraft.server.ItemStack itemStack = CraftItemStack.asNMSCopy(itemInHand);
+ NBTTagCompound tag = itemStack.getTag();
+ if (tag != null) {
2020-12-08 02:10:22 +00:00
+ String nbt = org.bukkit.craftbukkit.util.CraftChatMessage.fromComponent(tag.getNbtPrettyComponent());
+ Bukkit.getConsoleSender().sendMessage(nbt);
+ sender.sendMessage(nbt);
+ } else {
+ sender.sendMessage("Item does not have NBT");
+ }
+ }
+
private void doFixLight(CommandSender sender, String[] args) {
if (!(sender instanceof Player)) {
sender.sendMessage("Only players can use this command");
2020-12-08 02:10:22 +00:00
diff --git a/src/main/java/net/minecraft/server/NBTBase.java b/src/main/java/net/minecraft/server/NBTBase.java
index 8b9e47b4c7f5dc464fa617a59583df9e30a54045..104b820ee380083ec755c443a4a9c270e525ca45 100644
--- a/src/main/java/net/minecraft/server/NBTBase.java
+++ b/src/main/java/net/minecraft/server/NBTBase.java
@@ -24,6 +24,7 @@ public interface NBTBase {
return this.toString();
}
+ default IChatBaseComponent getNbtPrettyComponent() { return this.l(); } // Paper - OBFHELPER
default IChatBaseComponent l() {
return this.a("", 0);
}