From c096c4a7812778a68508f8371f71bab191e1d77a Mon Sep 17 00:00:00 2001 From: Super_ Date: Wed, 11 Dec 2019 22:17:05 -0500 Subject: [PATCH] fixed offline player lookup should work now, but i still need to allow for nbt data lookup as well. --- ...tory.java => Command_inventorylookup.java} | 6 ++-- .../config/ConfigInventory.java | 32 +++++++++++++++++-- .../playerverification/VPlayer.java | 9 +++++- 3 files changed, 41 insertions(+), 6 deletions(-) rename src/main/java/me/totalfreedom/totalfreedommod/command/{Command_inventory.java => Command_inventorylookup.java} (85%) diff --git a/src/main/java/me/totalfreedom/totalfreedommod/command/Command_inventory.java b/src/main/java/me/totalfreedom/totalfreedommod/command/Command_inventorylookup.java similarity index 85% rename from src/main/java/me/totalfreedom/totalfreedommod/command/Command_inventory.java rename to src/main/java/me/totalfreedom/totalfreedommod/command/Command_inventorylookup.java index c5bfc5ff..33a036f9 100644 --- a/src/main/java/me/totalfreedom/totalfreedommod/command/Command_inventory.java +++ b/src/main/java/me/totalfreedom/totalfreedommod/command/Command_inventorylookup.java @@ -10,8 +10,8 @@ import org.bukkit.entity.Player; import org.bukkit.inventory.ItemStack; @CommandPermissions(level = Rank.SUPER_ADMIN, source = SourceType.BOTH) -@CommandParameters(description = "View player inventory information of players.", usage = "/ ", aliases = "inv") -public class Command_inventory extends FreedomCommand +@CommandParameters(description = "View inventory information of players.", usage = "/ ", aliases = "il,invlookup") +public class Command_inventorylookup extends FreedomCommand { @Override @@ -48,7 +48,7 @@ public class Command_inventory extends FreedomCommand msg(" - Amount: " + stack.getAmount()); if (inv.hasNBT(slot)) { - msg(" - NBT Data: " + inv.getNBT(slot)); + msg(" - NBT Data: " + inv.getNBT(slot).toString()); } return true; } diff --git a/src/main/java/me/totalfreedom/totalfreedommod/config/ConfigInventory.java b/src/main/java/me/totalfreedom/totalfreedommod/config/ConfigInventory.java index 6bba050c..8f894ba9 100644 --- a/src/main/java/me/totalfreedom/totalfreedommod/config/ConfigInventory.java +++ b/src/main/java/me/totalfreedom/totalfreedommod/config/ConfigInventory.java @@ -4,6 +4,7 @@ import java.util.HashMap; import java.util.Map; import lombok.Getter; import lombok.Setter; +import net.minecraft.server.v1_14_R1.NBTTagCompound; import org.bukkit.Material; import org.bukkit.configuration.ConfigurationSection; import org.bukkit.craftbukkit.v1_14_R1.inventory.CraftItemStack; @@ -21,6 +22,17 @@ public class ConfigInventory updateInventory(inv); } + public void set(int location, Material material, int amount, NBTTagCompound nbt) + { + ItemStack stack = new ItemStack(material, amount); + /* + net.minecraft.server.v1_14_R1.ItemStack nmsStack = CraftItemStack.asNMSCopy(stack); + nmsStack.setTag(nbt); + stack = CraftItemStack.asBukkitCopy(nmsStack); + */ + inventoryItems.put(location, stack); + } + public void set(int location, ItemStack stack) { inventoryItems.put(location, stack); @@ -36,14 +48,18 @@ public class ConfigInventory return CraftItemStack.asNMSCopy(inventoryItems.get(location)).hasTag(); } - public String getNBT(int location) + public NBTTagCompound getNBT(int location) { - return CraftItemStack.asNMSCopy(inventoryItems.get(location)).getTag().toString(); + return CraftItemStack.asNMSCopy(inventoryItems.get(location)).getTag(); } public void updateInventory(Inventory inv) { inventoryItems = new HashMap<>(); + if (inv == null) + { + return; + } for (int i = 0; i < inv.getSize(); i++) { inventoryItems.put(i, inv.getItem(i)); @@ -70,4 +86,16 @@ public class ConfigInventory } } } + + public static ConfigInventory createInventoryFromConfig(ConfigurationSection cs) + { + ConfigInventory configInventory = new ConfigInventory(null); + for (int i = 0; i < 40; i++) + { + configInventory.set(i, Material.valueOf(cs.getString("inventory." + i + ".type")), + cs.getInt("inventory." + i + ".amount"), null);//, + //(NBTTagCompound) cs.get("inventory." + i + ".nbt")); + } + return configInventory; + } } diff --git a/src/main/java/me/totalfreedom/totalfreedommod/playerverification/VPlayer.java b/src/main/java/me/totalfreedom/totalfreedommod/playerverification/VPlayer.java index 8c989961..a7894796 100644 --- a/src/main/java/me/totalfreedom/totalfreedommod/playerverification/VPlayer.java +++ b/src/main/java/me/totalfreedom/totalfreedommod/playerverification/VPlayer.java @@ -64,7 +64,14 @@ public class VPlayer implements ConfigLoadable, ConfigSavable, Validatable tag = cs.getString("tag", null); clearChatOptOut = cs.getBoolean("clearChatOptOut", false); rideToggle = cs.getBoolean("rideToggle", true); - inventory = new ConfigInventory(Bukkit.getPlayer(name).getInventory()); + if (!cs.contains("inventory") || Bukkit.getPlayer(name) != null) + { + inventory = new ConfigInventory(Bukkit.getPlayer(name).getInventory()); + } + else + { + inventory = ConfigInventory.createInventoryFromConfig(cs); + } } @Override