From 0050a73be837fe6659f6d8bcb6740cb39dae0c52 Mon Sep 17 00:00:00 2001 From: nossr50 Date: Fri, 21 Jun 2019 10:46:27 -0700 Subject: [PATCH] NBT WIP --- .../commands/player/McrankCommand.java | 1 - .../nossr50/commands/player/MctopCommand.java | 1 - .../gmail/nossr50/config/ConfigManager.java | 6 +-- .../com/gmail/nossr50/config/MainConfig.java | 1 - .../serializers/ItemStackSerializer.java | 2 - .../serializers/RepairableSerializer.java | 6 --- .../hocon/skills/repair/ConfigRepair.java | 5 +- .../gmail/nossr50/datatypes/party/Party.java | 1 - .../nossr50/datatypes/player/McMMOPlayer.java | 1 - .../nossr50/listeners/EntityListener.java | 7 +-- .../com/gmail/nossr50/party/PartyManager.java | 1 - .../nossr50/skills/repair/RepairManager.java | 6 --- .../skills/repair/repairables/Repairable.java | 1 - .../gmail/nossr50/util/nbt/NBTManager.java | 50 +++++++++++++++++++ .../com/gmail/nossr50/util/nbt/NBTUtils.java | 26 ---------- .../com/gmail/nossr50/util/nbt/RawNBT.java | 2 +- .../util/skills/ParticleEffectUtils.java | 1 - 17 files changed, 62 insertions(+), 56 deletions(-) create mode 100644 src/main/java/com/gmail/nossr50/util/nbt/NBTManager.java delete mode 100644 src/main/java/com/gmail/nossr50/util/nbt/NBTUtils.java diff --git a/src/main/java/com/gmail/nossr50/commands/player/McrankCommand.java b/src/main/java/com/gmail/nossr50/commands/player/McrankCommand.java index b6b65cc57..b1cad04b7 100644 --- a/src/main/java/com/gmail/nossr50/commands/player/McrankCommand.java +++ b/src/main/java/com/gmail/nossr50/commands/player/McrankCommand.java @@ -1,6 +1,5 @@ package com.gmail.nossr50.commands.player; -import com.gmail.nossr50.config.MainConfig; import com.gmail.nossr50.core.MetadataConstants; import com.gmail.nossr50.datatypes.player.McMMOPlayer; import com.gmail.nossr50.locale.LocaleLoader; diff --git a/src/main/java/com/gmail/nossr50/commands/player/MctopCommand.java b/src/main/java/com/gmail/nossr50/commands/player/MctopCommand.java index 38df376fc..18f43f377 100644 --- a/src/main/java/com/gmail/nossr50/commands/player/MctopCommand.java +++ b/src/main/java/com/gmail/nossr50/commands/player/MctopCommand.java @@ -1,6 +1,5 @@ package com.gmail.nossr50.commands.player; -import com.gmail.nossr50.config.MainConfig; import com.gmail.nossr50.core.MetadataConstants; import com.gmail.nossr50.datatypes.player.McMMOPlayer; import com.gmail.nossr50.datatypes.skills.PrimarySkillType; diff --git a/src/main/java/com/gmail/nossr50/config/ConfigManager.java b/src/main/java/com/gmail/nossr50/config/ConfigManager.java index 14f682fcb..df1f4ec35 100644 --- a/src/main/java/com/gmail/nossr50/config/ConfigManager.java +++ b/src/main/java/com/gmail/nossr50/config/ConfigManager.java @@ -37,9 +37,6 @@ import com.gmail.nossr50.config.hocon.skills.mining.ConfigMining; import com.gmail.nossr50.config.hocon.skills.ranks.ConfigRanks; import com.gmail.nossr50.config.hocon.skills.ranks.SkillRankProperty; import com.gmail.nossr50.config.hocon.skills.repair.ConfigRepair; -import com.gmail.nossr50.skills.repair.RepairCost; -import com.gmail.nossr50.skills.repair.RepairTransaction; -import com.gmail.nossr50.datatypes.items.ItemWildcards; import com.gmail.nossr50.config.hocon.skills.salvage.ConfigSalvage; import com.gmail.nossr50.config.hocon.skills.smelting.ConfigSmelting; import com.gmail.nossr50.config.hocon.skills.swords.ConfigSwords; @@ -55,11 +52,14 @@ import com.gmail.nossr50.config.treasure.FishingTreasureConfig; import com.gmail.nossr50.config.treasure.HerbalismTreasureConfig; import com.gmail.nossr50.datatypes.experience.CustomXPPerk; import com.gmail.nossr50.datatypes.experience.FormulaType; +import com.gmail.nossr50.datatypes.items.ItemWildcards; import com.gmail.nossr50.datatypes.party.PartyFeature; import com.gmail.nossr50.datatypes.skills.PrimarySkillType; import com.gmail.nossr50.datatypes.skills.properties.DamageProperty; import com.gmail.nossr50.datatypes.skills.properties.MaxBonusLevel; import com.gmail.nossr50.mcMMO; +import com.gmail.nossr50.skills.repair.RepairCost; +import com.gmail.nossr50.skills.repair.RepairTransaction; import com.gmail.nossr50.skills.repair.repairables.Repairable; import com.gmail.nossr50.skills.salvage.salvageables.Salvageable; import com.google.common.reflect.TypeToken; diff --git a/src/main/java/com/gmail/nossr50/config/MainConfig.java b/src/main/java/com/gmail/nossr50/config/MainConfig.java index 5cb5ae203..276aa09a2 100644 --- a/src/main/java/com/gmail/nossr50/config/MainConfig.java +++ b/src/main/java/com/gmail/nossr50/config/MainConfig.java @@ -1,6 +1,5 @@ package com.gmail.nossr50.config; -import com.gmail.nossr50.datatypes.skills.PrimarySkillType; import com.gmail.nossr50.mcMMO; import com.gmail.nossr50.util.StringUtils; import ninja.leaping.configurate.objectmapping.serialize.ConfigSerializable; diff --git a/src/main/java/com/gmail/nossr50/config/hocon/serializers/ItemStackSerializer.java b/src/main/java/com/gmail/nossr50/config/hocon/serializers/ItemStackSerializer.java index 10519b4b2..4da79d156 100644 --- a/src/main/java/com/gmail/nossr50/config/hocon/serializers/ItemStackSerializer.java +++ b/src/main/java/com/gmail/nossr50/config/hocon/serializers/ItemStackSerializer.java @@ -12,8 +12,6 @@ import org.bukkit.inventory.ItemStack; import org.checkerframework.checker.nullness.qual.NonNull; import org.checkerframework.checker.nullness.qual.Nullable; -import java.util.List; - public class ItemStackSerializer implements TypeSerializer { private static final String ITEM_MINECRAFT_NAME = "Item-Name"; diff --git a/src/main/java/com/gmail/nossr50/config/hocon/serializers/RepairableSerializer.java b/src/main/java/com/gmail/nossr50/config/hocon/serializers/RepairableSerializer.java index 948d5fbb4..bf61273d1 100644 --- a/src/main/java/com/gmail/nossr50/config/hocon/serializers/RepairableSerializer.java +++ b/src/main/java/com/gmail/nossr50/config/hocon/serializers/RepairableSerializer.java @@ -4,19 +4,13 @@ import com.gmail.nossr50.datatypes.permissions.PermissionWrapper; import com.gmail.nossr50.skills.repair.RepairTransaction; import com.gmail.nossr50.skills.repair.repairables.Repairable; import com.gmail.nossr50.skills.repair.repairables.RepairableBuilder; -import com.gmail.nossr50.util.nbt.RawNBT; import com.google.common.reflect.TypeToken; import ninja.leaping.configurate.ConfigurationNode; import ninja.leaping.configurate.ValueType; import ninja.leaping.configurate.objectmapping.ObjectMappingException; import ninja.leaping.configurate.objectmapping.serialize.TypeSerializer; -import ninja.leaping.configurate.util.EnumLookup; import org.bukkit.inventory.ItemStack; -import java.util.HashSet; -import java.util.Optional; -import java.util.Set; - public class RepairableSerializer implements TypeSerializer { private static final String ITEM = "Item"; private static final String BASE_XP = "XP-Per-Repair"; diff --git a/src/main/java/com/gmail/nossr50/config/hocon/skills/repair/ConfigRepair.java b/src/main/java/com/gmail/nossr50/config/hocon/skills/repair/ConfigRepair.java index 04a7b1940..ee5d968a0 100644 --- a/src/main/java/com/gmail/nossr50/config/hocon/skills/repair/ConfigRepair.java +++ b/src/main/java/com/gmail/nossr50/config/hocon/skills/repair/ConfigRepair.java @@ -10,7 +10,10 @@ import ninja.leaping.configurate.objectmapping.Setting; import ninja.leaping.configurate.objectmapping.serialize.ConfigSerializable; import org.bukkit.inventory.ItemStack; -import java.util.*; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.HashSet; +import java.util.List; import static org.bukkit.Material.*; diff --git a/src/main/java/com/gmail/nossr50/datatypes/party/Party.java b/src/main/java/com/gmail/nossr50/datatypes/party/Party.java index b2a4ab4f6..4a82fc736 100644 --- a/src/main/java/com/gmail/nossr50/datatypes/party/Party.java +++ b/src/main/java/com/gmail/nossr50/datatypes/party/Party.java @@ -1,6 +1,5 @@ package com.gmail.nossr50.datatypes.party; -import com.gmail.nossr50.config.MainConfig; import com.gmail.nossr50.datatypes.player.McMMOPlayer; import com.gmail.nossr50.locale.LocaleLoader; import com.gmail.nossr50.mcMMO; diff --git a/src/main/java/com/gmail/nossr50/datatypes/player/McMMOPlayer.java b/src/main/java/com/gmail/nossr50/datatypes/player/McMMOPlayer.java index 4be224a17..a85e1b033 100644 --- a/src/main/java/com/gmail/nossr50/datatypes/player/McMMOPlayer.java +++ b/src/main/java/com/gmail/nossr50/datatypes/player/McMMOPlayer.java @@ -1,6 +1,5 @@ package com.gmail.nossr50.datatypes.player; -import com.gmail.nossr50.config.MainConfig; import com.gmail.nossr50.config.WorldBlacklist; import com.gmail.nossr50.datatypes.chat.ChatMode; import com.gmail.nossr50.datatypes.experience.XPGainReason; diff --git a/src/main/java/com/gmail/nossr50/listeners/EntityListener.java b/src/main/java/com/gmail/nossr50/listeners/EntityListener.java index a91bef3ef..2454f24ad 100644 --- a/src/main/java/com/gmail/nossr50/listeners/EntityListener.java +++ b/src/main/java/com/gmail/nossr50/listeners/EntityListener.java @@ -30,17 +30,18 @@ import org.bukkit.OfflinePlayer; import org.bukkit.block.Block; import org.bukkit.enchantments.Enchantment; import org.bukkit.entity.*; -import org.bukkit.event.*; +import org.bukkit.event.Cancellable; +import org.bukkit.event.EventHandler; +import org.bukkit.event.EventPriority; +import org.bukkit.event.Listener; import org.bukkit.event.entity.*; import org.bukkit.event.entity.EntityDamageEvent.DamageCause; -import org.bukkit.event.entity.EntityDamageEvent.DamageModifier; import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.meta.PotionMeta; import org.bukkit.metadata.FixedMetadataValue; import org.bukkit.potion.PotionEffect; import org.bukkit.potion.PotionEffectType; import org.bukkit.projectiles.ProjectileSource; -import sun.security.krb5.Config; public class EntityListener implements Listener { private final mcMMO plugin; diff --git a/src/main/java/com/gmail/nossr50/party/PartyManager.java b/src/main/java/com/gmail/nossr50/party/PartyManager.java index 4519e3995..5ac45e2a6 100644 --- a/src/main/java/com/gmail/nossr50/party/PartyManager.java +++ b/src/main/java/com/gmail/nossr50/party/PartyManager.java @@ -1,6 +1,5 @@ package com.gmail.nossr50.party; -import com.gmail.nossr50.config.MainConfig; import com.gmail.nossr50.datatypes.chat.ChatMode; import com.gmail.nossr50.datatypes.interactions.NotificationType; import com.gmail.nossr50.datatypes.party.*; diff --git a/src/main/java/com/gmail/nossr50/skills/repair/RepairManager.java b/src/main/java/com/gmail/nossr50/skills/repair/RepairManager.java index 703454559..8588f66ac 100644 --- a/src/main/java/com/gmail/nossr50/skills/repair/RepairManager.java +++ b/src/main/java/com/gmail/nossr50/skills/repair/RepairManager.java @@ -1,6 +1,5 @@ package com.gmail.nossr50.skills.repair; -import com.gmail.nossr50.datatypes.experience.XPGainReason; import com.gmail.nossr50.datatypes.interactions.NotificationType; import com.gmail.nossr50.datatypes.player.McMMOPlayer; import com.gmail.nossr50.datatypes.skills.PrimarySkillType; @@ -8,11 +7,8 @@ import com.gmail.nossr50.datatypes.skills.SubSkillType; import com.gmail.nossr50.locale.LocaleLoader; import com.gmail.nossr50.mcMMO; import com.gmail.nossr50.skills.SkillManager; -import com.gmail.nossr50.skills.repair.repairables.Repairable; -import com.gmail.nossr50.util.EventUtils; import com.gmail.nossr50.util.Misc; import com.gmail.nossr50.util.Permissions; -import com.gmail.nossr50.util.StringUtils; import com.gmail.nossr50.util.random.RandomChanceSkillStatic; import com.gmail.nossr50.util.random.RandomChanceUtil; import com.gmail.nossr50.util.skills.RankUtils; @@ -20,11 +16,9 @@ import com.gmail.nossr50.util.skills.SkillActivationType; import com.gmail.nossr50.util.skills.SkillUtils; import com.gmail.nossr50.util.sounds.SoundManager; import com.gmail.nossr50.util.sounds.SoundType; -import org.bukkit.Material; import org.bukkit.enchantments.Enchantment; import org.bukkit.entity.Player; import org.bukkit.inventory.ItemStack; -import org.bukkit.inventory.PlayerInventory; import java.util.Map; import java.util.Map.Entry; diff --git a/src/main/java/com/gmail/nossr50/skills/repair/repairables/Repairable.java b/src/main/java/com/gmail/nossr50/skills/repair/repairables/Repairable.java index acf4dff93..b1543e6a3 100644 --- a/src/main/java/com/gmail/nossr50/skills/repair/repairables/Repairable.java +++ b/src/main/java/com/gmail/nossr50/skills/repair/repairables/Repairable.java @@ -3,7 +3,6 @@ package com.gmail.nossr50.skills.repair.repairables; import com.gmail.nossr50.datatypes.permissions.PermissionWrapper; import com.gmail.nossr50.skills.repair.RepairTransaction; import com.gmail.nossr50.util.nbt.RawNBT; -import org.bukkit.Material; import org.bukkit.inventory.ItemStack; public class Repairable { diff --git a/src/main/java/com/gmail/nossr50/util/nbt/NBTManager.java b/src/main/java/com/gmail/nossr50/util/nbt/NBTManager.java new file mode 100644 index 000000000..9a1b12137 --- /dev/null +++ b/src/main/java/com/gmail/nossr50/util/nbt/NBTManager.java @@ -0,0 +1,50 @@ +package com.gmail.nossr50.util.nbt; + + +import com.gmail.nossr50.mcMMO; +import net.minecraft.server.v1_13_R2.NBTBase; +import net.minecraft.server.v1_13_R2.NBTTagCompound; +import org.bukkit.Bukkit; +import org.bukkit.craftbukkit.v1_13_R2.inventory.CraftItemStack; +import org.bukkit.craftbukkit.v1_13_R2.util.CraftNBTTagConfigSerializer; +import org.bukkit.inventory.ItemStack; + + + +public class NBTManager { + + private static final String CRAFT_META_ITEM_CLASS_PATH = "org.bukkit.craftbukkit.inventory.CraftMetaItem"; + private Class craftMetaItemClass; + + public NBTManager() { + init(); //Setup method references etc + } + + private void init() { + try { + Class craftMetaItemClass = Class.forName(CRAFT_META_ITEM_CLASS_PATH); //for type comparisons + } catch (ClassNotFoundException e) { + e.printStackTrace(); + } + } + + public RawNBT constructNBT(String nbtString) { + try { + return new RawNBT(nbtString, CraftNBTTagConfigSerializer.deserialize(nbtString)); + } catch (Exception e) { + e.printStackTrace(); + mcMMO.p.getLogger().severe("mcMMO was unable parse the NBT string from your config! Double check that it is proper NBT!"); + return null; + } + } + + public void printNBT(ItemStack itemStack) { + Bukkit.broadcastMessage("Checking NBT for "+itemStack.toString()); + net.minecraft.server.v1_13_R2.ItemStack nmsItemStack = CraftItemStack.asNMSCopy(itemStack); + NBTTagCompound rootTag = nmsItemStack.getTag(); + for(String key : rootTag.getKeys()) { + Bukkit.broadcastMessage("NBT Key found: "+key); + } + } + +} diff --git a/src/main/java/com/gmail/nossr50/util/nbt/NBTUtils.java b/src/main/java/com/gmail/nossr50/util/nbt/NBTUtils.java deleted file mode 100644 index 29d2e7c23..000000000 --- a/src/main/java/com/gmail/nossr50/util/nbt/NBTUtils.java +++ /dev/null @@ -1,26 +0,0 @@ -package com.gmail.nossr50.util.nbt; - - -import com.gmail.nossr50.mcMMO; -import net.minecraft.server.v1_13_R2.NBTBase; -import org.bukkit.craftbukkit.v1_13_R2.entity.CraftItem; -import org.bukkit.craftbukkit.v1_13_R2.util.CraftNBTTagConfigSerializer; -import org.bukkit.inventory.ItemStack; - -public class NBTUtils { - - public RawNBT constructNBT(String nbtString) { - try { - return new RawNBT(nbtString, CraftNBTTagConfigSerializer.deserialize(nbtString)); - } catch (Exception e) { - e.printStackTrace(); - mcMMO.p.getLogger().severe("mcMMO was unable parse the NBT string from your config! Double check that it is proper NBT!"); - return null; - } - } - - public boolean hasNBT(ItemStack itemStack) { - if(CraftItem) - } - -} diff --git a/src/main/java/com/gmail/nossr50/util/nbt/RawNBT.java b/src/main/java/com/gmail/nossr50/util/nbt/RawNBT.java index 2f5754e5a..53c64b469 100644 --- a/src/main/java/com/gmail/nossr50/util/nbt/RawNBT.java +++ b/src/main/java/com/gmail/nossr50/util/nbt/RawNBT.java @@ -16,7 +16,7 @@ public class RawNBT { public RawNBT(String nbtContents, T nbtTree) { this.nbtContents = nbtContents; - NBTUtils + NBTManager } public String getNbtContents() { diff --git a/src/main/java/com/gmail/nossr50/util/skills/ParticleEffectUtils.java b/src/main/java/com/gmail/nossr50/util/skills/ParticleEffectUtils.java index a10dd9337..3199f45b2 100644 --- a/src/main/java/com/gmail/nossr50/util/skills/ParticleEffectUtils.java +++ b/src/main/java/com/gmail/nossr50/util/skills/ParticleEffectUtils.java @@ -1,6 +1,5 @@ package com.gmail.nossr50.util.skills; -import com.gmail.nossr50.config.MainConfig; import org.bukkit.Effect; import org.bukkit.Location; import org.bukkit.Material;