81 Zeilen
3.7 KiB
Diff
81 Zeilen
3.7 KiB
Diff
|
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 528c860fc0c04431e0ebb2ae6bc96bf9c2d04789..6fad9329213e4e8a3ef9ce7fb568ad22484a11f3 100644
|
||
|
--- a/src/main/java/com/destroystokyo/paper/PaperCommand.java
|
||
|
+++ b/src/main/java/com/destroystokyo/paper/PaperCommand.java
|
||
|
@@ -12,6 +12,7 @@ import com.google.gson.JsonObject;
|
||
|
import com.google.gson.internal.Streams;
|
||
|
import com.google.gson.stream.JsonWriter;
|
||
|
import net.minecraft.core.BlockPos;
|
||
|
+import net.minecraft.nbt.CompoundTag;
|
||
|
import net.minecraft.network.protocol.game.ClientboundLightUpdatePacket;
|
||
|
import net.minecraft.resources.ResourceLocation;
|
||
|
import net.minecraft.server.MCUtil;
|
||
|
@@ -36,7 +37,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;
|
||
|
@@ -59,7 +62,7 @@ import java.util.stream.Collectors;
|
||
|
|
||
|
public class PaperCommand extends Command {
|
||
|
private static final String BASE_PERM = "bukkit.command.paper.";
|
||
|
- private static final ImmutableSet<String> SUBCOMMANDS = ImmutableSet.<String>builder().add("heap", "entity", "reload", "version", "debug", "chunkinfo", "dumpwaiting", "syncloadinfo", "fixlight").build();
|
||
|
+ private static final ImmutableSet<String> SUBCOMMANDS = ImmutableSet.<String>builder().add("heap", "entity", "reload", "version", "debug", "chunkinfo", "dumpwaiting", "syncloadinfo", "fixlight", "dumpitem").build();
|
||
|
|
||
|
public PaperCommand(String name) {
|
||
|
super(name);
|
||
|
@@ -168,6 +171,9 @@ public class PaperCommand extends Command {
|
||
|
case "reload":
|
||
|
doReload(sender);
|
||
|
break;
|
||
|
+ case "dumpitem":
|
||
|
+ doDumpItem(sender);
|
||
|
+ break;
|
||
|
case "debug":
|
||
|
doDebug(sender, args);
|
||
|
break;
|
||
|
@@ -200,6 +206,19 @@ public class PaperCommand extends Command {
|
||
|
return true;
|
||
|
}
|
||
|
|
||
|
+ private void doDumpItem(CommandSender sender) {
|
||
|
+ ItemStack itemInHand = ((CraftPlayer) sender).getItemInHand();
|
||
|
+ net.minecraft.world.item.ItemStack itemStack = CraftItemStack.asNMSCopy(itemInHand);
|
||
|
+ CompoundTag tag = itemStack.getTag();
|
||
|
+ if (tag != null) {
|
||
|
+ 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");
|
||
|
diff --git a/src/main/java/net/minecraft/nbt/Tag.java b/src/main/java/net/minecraft/nbt/Tag.java
|
||
|
index 85e9c5f4620fcf48cb3655fbb2db58b3fb31aa74..ba204cf135be333d4ac1c06ee6c2e961faadf8cb 100644
|
||
|
--- a/src/main/java/net/minecraft/nbt/Tag.java
|
||
|
+++ b/src/main/java/net/minecraft/nbt/Tag.java
|
||
|
@@ -26,6 +26,7 @@ public interface Tag {
|
||
|
return this.toString();
|
||
|
}
|
||
|
|
||
|
+ default Component getNbtPrettyComponent() { return this.getPrettyDisplay(); } // Paper - OBFHELPER
|
||
|
default Component getPrettyDisplay() {
|
||
|
return this.getPrettyDisplay("", 0);
|
||
|
}
|