From c3546c777c1ef852f14af85bc83409daaa278481 Mon Sep 17 00:00:00 2001 From: Pim van der Loos Date: Thu, 2 Aug 2018 03:53:56 +0200 Subject: [PATCH] 1.13 support - Added initial support for version 1.13 of Minecraft. --- pom.xml | 60 +++------ .../armoredElytra/ArmoredElytra.java | 14 ++- .../armoredElytra/handlers/EventHandlers.java | 9 +- .../armoredElytra/nms/NBTEditor_V1_13_R1.java | 116 ++++++++++++++++++ .../pim16aap2/armoredElytra/util/Update.java | 6 +- src/main/resources/plugin.yml | 2 +- 6 files changed, 149 insertions(+), 58 deletions(-) create mode 100644 src/main/java/nl/pim16aap2/armoredElytra/nms/NBTEditor_V1_13_R1.java diff --git a/pom.xml b/pom.xml index b780367..7f33834 100644 --- a/pom.xml +++ b/pom.xml @@ -1,10 +1,8 @@ - + 4.0.0 nl.pim16aap2 ArmoredElytra - 2.4-SNAPSHOT - + 2.4.2-SNAPSHOT @@ -17,57 +15,29 @@ - - - - - org.spigotmc - spigot - 1.10.2-R0.1-SNAPSHOT - provided - - - + org.spigotmc - spigot-api + spigot-1.10 1.10.2-R0.1-SNAPSHOT provided - - + org.spigotmc - spigot-api + spigot-1.11 1.11.2-R0.1-SNAPSHOT provided - + + org.spigotmc + spigot-1.12 + 1.12.2-R0.1-SNAPSHOT + provided + org.spigotmc - spigot-api - 1.12.1-R0.1-SNAPSHOT - provided - - - - - org.bukkit - craftbukkit - 1.10.2-R0.1-SNAPSHOT - provided - - - - org.bukkit - craftbukkit - 1.11.2-R0.1-SNAPSHOT - provided - - - - org.bukkit - craftbukkit - 1.12-R0.1-SNAPSHOT + spigot-1.13 + 1.13-R0.1-SNAPSHOT provided @@ -79,8 +49,6 @@ - - diff --git a/src/main/java/nl/pim16aap2/armoredElytra/ArmoredElytra.java b/src/main/java/nl/pim16aap2/armoredElytra/ArmoredElytra.java index 46f7ece..556f6ff 100644 --- a/src/main/java/nl/pim16aap2/armoredElytra/ArmoredElytra.java +++ b/src/main/java/nl/pim16aap2/armoredElytra/ArmoredElytra.java @@ -19,6 +19,7 @@ import nl.pim16aap2.armoredElytra.nms.NBTEditor; import nl.pim16aap2.armoredElytra.nms.NBTEditor_V1_10_R1; import nl.pim16aap2.armoredElytra.nms.NBTEditor_V1_11_R1; import nl.pim16aap2.armoredElytra.nms.NBTEditor_V1_12_R1; +import nl.pim16aap2.armoredElytra.nms.NBTEditor_V1_13_R1; import nl.pim16aap2.armoredElytra.util.ArmorTier; import nl.pim16aap2.armoredElytra.util.ConfigLoader; import nl.pim16aap2.armoredElytra.util.Metrics; @@ -41,10 +42,10 @@ public class ArmoredElytra extends JavaPlugin implements Listener { readConfigValues(); - // Check if the user allows checking for updates. if (config.getBool("checkForUpdates")) { + // Check for updates in a new thread, so the server won't hang when it cannot contact the update servers. Thread thread = new Thread(new Runnable() { @Override @@ -99,7 +100,7 @@ public class ArmoredElytra extends JavaPlugin implements Listener } else // Y u do dis? :( - myLogger(Level.INFO, "Stats disabled, not laoding stats ::(... Please consider enabling it! I am a simple man, seeing higher user numbers helps me stay motivated!"); + myLogger(Level.INFO, "Stats disabled, not laoding stats :(... Please consider enabling it! I am a simple man, seeing higher user numbers helps me stay motivated!"); @@ -111,7 +112,10 @@ public class ArmoredElytra extends JavaPlugin implements Listener getCommand("ArmoredElytra").setExecutor(new CommandHandler(this, nbtEditor)); } else - myLogger(Level.WARNING, "Trying to load the plugin on an incompatible version of Minecraft!"); + { + myLogger(Level.WARNING, "Trying to load the plugin on an incompatible version of Minecraft! This plugin will NOT be enabled!"); + return; + } @@ -260,7 +264,9 @@ public class ArmoredElytra extends JavaPlugin implements Listener else if (version.equals("v1_11_R1")) nbtEditor = new NBTEditor_V1_11_R1(this); else if (version.equals("v1_12_R1")) - nbtEditor = new NBTEditor_V1_12_R1(this); + nbtEditor = new NBTEditor_V1_12_R1(this); + else if (version.equals("v1_13_R1")) + nbtEditor = new NBTEditor_V1_13_R1(this); // Return true if compatible. return nbtEditor != null; } diff --git a/src/main/java/nl/pim16aap2/armoredElytra/handlers/EventHandlers.java b/src/main/java/nl/pim16aap2/armoredElytra/handlers/EventHandlers.java index c3037f7..065449c 100644 --- a/src/main/java/nl/pim16aap2/armoredElytra/handlers/EventHandlers.java +++ b/src/main/java/nl/pim16aap2/armoredElytra/handlers/EventHandlers.java @@ -470,7 +470,7 @@ public class EventHandlers implements Listener if (player.getInventory().getChestplate() != null) { // If that chestplate is an (armored) elytra. - if (chestplate.getType() == Material.ELYTRA && (nbtEditor.getArmorTier(chestplate) != ArmorTier.NONE)) + if (nbtEditor.getArmorTier(chestplate) != ArmorTier.NONE) { ArmorTier armorTier = nbtEditor.getArmorTier(chestplate); if ((chestplate.getDurability() >= chestplate.getType().getMaxDurability())) @@ -493,7 +493,7 @@ public class EventHandlers implements Listener } // Because the armored elytra doesn't actually give any armor, the damage received by players wearing an armored elytra is calculated here. - @EventHandler + @EventHandler(ignoreCancelled = true) public void onPlayerDamage(EntityDamageEvent e) { if(e.getEntity() instanceof Player) @@ -502,10 +502,9 @@ public class EventHandlers implements Listener // If the player didn't die from the damage. if ((p.getHealth() - e.getFinalDamage()) > 0) { - if (p.getInventory().getChestplate()!=null) + if (p.getInventory().getChestplate() != null) { - if (p.getInventory().getChestplate().getType() == Material.ELYTRA && - nbtEditor.getArmorTier(p.getInventory().getChestplate()) != ArmorTier.NONE) + if (nbtEditor.getArmorTier(p.getInventory().getChestplate()) != ArmorTier.NONE) { ItemStack elytra = p.getInventory().getChestplate(); DamageCause cause = e.getCause(); diff --git a/src/main/java/nl/pim16aap2/armoredElytra/nms/NBTEditor_V1_13_R1.java b/src/main/java/nl/pim16aap2/armoredElytra/nms/NBTEditor_V1_13_R1.java new file mode 100644 index 0000000..e052e49 --- /dev/null +++ b/src/main/java/nl/pim16aap2/armoredElytra/nms/NBTEditor_V1_13_R1.java @@ -0,0 +1,116 @@ +package nl.pim16aap2.armoredElytra.nms; + +import java.util.Arrays; + +import org.bukkit.Material; +import org.bukkit.craftbukkit.v1_13_R1.inventory.CraftItemStack; +import org.bukkit.inventory.ItemStack; +import org.bukkit.inventory.meta.ItemMeta; + +import net.minecraft.server.v1_13_R1.NBTTagByte; +import net.minecraft.server.v1_13_R1.NBTTagCompound; +import net.minecraft.server.v1_13_R1.NBTTagInt; +import net.minecraft.server.v1_13_R1.NBTTagList; +import net.minecraft.server.v1_13_R1.NBTTagString; +import nl.pim16aap2.armoredElytra.ArmoredElytra; +import nl.pim16aap2.armoredElytra.util.ArmorTier; + +public class NBTEditor_V1_13_R1 implements NBTEditor +{ + private ArmoredElytra plugin; + + // Get the names and lores for every tier of armor. + public NBTEditor_V1_13_R1(ArmoredElytra plugin) + { + this.plugin = plugin; + } + + // Add armor to the supplied item, based on the armorTier. + @Override + public ItemStack addArmorNBTTags(ItemStack item, ArmorTier armorTier, boolean unbreakable) + { + ItemMeta itemmeta = item.getItemMeta(); + int armorProtection = ArmorTier.getArmor (armorTier); + int armorToughness = ArmorTier.getToughness(armorTier); + + itemmeta.setDisplayName(plugin.getArmoredElytrName(armorTier)); + if (plugin.getElytraLore() != null) + itemmeta.setLore(Arrays.asList(plugin.fillInArmorTierInStringNoColor(plugin.getElytraLore(), armorTier))); + item.setItemMeta(itemmeta); + + net.minecraft.server.v1_13_R1.ItemStack nmsStack = CraftItemStack.asNMSCopy(item); + NBTTagCompound compound = (nmsStack.hasTag()) ? nmsStack.getTag() : new NBTTagCompound(); + NBTTagList modifiers = new NBTTagList(); + NBTTagCompound armor = new NBTTagCompound(); + armor.set("AttributeName", new NBTTagString("generic.armor")); + armor.set("Name", new NBTTagString("generic.armor")); + armor.set("Amount", new NBTTagInt(armorProtection)); + armor.set("Operation", new NBTTagInt(0)); + armor.set("UUIDLeast", new NBTTagInt(894654)); + armor.set("UUIDMost", new NBTTagInt(2872)); + armor.set("Slot", new NBTTagString("chest")); + modifiers.add(armor); + + NBTTagCompound armorTough = new NBTTagCompound(); + armorTough.set("AttributeName", new NBTTagString("generic.armorToughness")); + armorTough.set("Name", new NBTTagString("generic.armorToughness")); + armorTough.set("Amount", new NBTTagInt(armorToughness)); + armorTough.set("Operation", new NBTTagInt(0)); + armorTough.set("UUIDLeast", new NBTTagInt(894654)); + armorTough.set("UUIDMost", new NBTTagInt(2872)); + armorTough.set("Slot", new NBTTagString("chest")); + modifiers.add(armorTough); + + if (unbreakable) + compound.set("Unbreakable", new NBTTagByte((byte) 1)); + + compound.set("AttributeModifiers", modifiers); + item = CraftItemStack.asBukkitCopy(nmsStack); + return item; + } + + // Get the armor tier of the supplied item. + @Override + public ArmorTier getArmorTier(ItemStack item) + { + if (item == null) + return ArmorTier.NONE; + if (item.getType() != Material.ELYTRA) + return ArmorTier.NONE; + + // Get the NBT tags from the item. + NBTTagCompound compound = CraftItemStack.asNMSCopy(item).getTag(); + if (compound == null) + return ArmorTier.NONE; + String nbtTags = compound.toString(); + + // Check if the item has the generic.armor attribute. + // Format = ,Slot:"chest",AttributeName:"generic.armor so get pos of char before + // The start of the string, as that's the value of the generic.armor attribute. + int pos = nbtTags.indexOf(",Slot:\"chest\",AttributeName:\"generic.armor\""); + int armorValue = 0; + if (pos > 0) + { + // If so, get the value of the generic.armor attribute. + pos--; + String stringAtPos = nbtTags.substring(pos, pos+1); + armorValue = Integer.parseInt(stringAtPos); + } else + // Otherwise, the item has no armor, so return 0; + return ArmorTier.NONE; + + switch (armorValue) + { + case 3: + return ArmorTier.LEATHER; + case 5: + return ArmorTier.GOLD; + case 6: + return ArmorTier.IRON; + case 8: + return ArmorTier.DIAMOND; + default: + return ArmorTier.NONE; + } + } +} \ No newline at end of file diff --git a/src/main/java/nl/pim16aap2/armoredElytra/util/Update.java b/src/main/java/nl/pim16aap2/armoredElytra/util/Update.java index 5a55897..4eadc73 100644 --- a/src/main/java/nl/pim16aap2/armoredElytra/util/Update.java +++ b/src/main/java/nl/pim16aap2/armoredElytra/util/Update.java @@ -139,9 +139,11 @@ public class Update } catch (IOException e) { - // There was an error reading the query + // There was an error reading the query. + // Does not print stacktrace, so people won't see any errors from this plugin when Bukkit Dev's servers are down, + // So people won't think the plugin is broken, while the actualy problem is much, much smaller. latestVersion will be null, though, which will prompt a warning in the log instead. - e.printStackTrace(); +// e.printStackTrace(); return; } } diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml index 4e26965..669d919 100644 --- a/src/main/resources/plugin.yml +++ b/src/main/resources/plugin.yml @@ -1,6 +1,6 @@ name: ArmoredElytra main: nl.pim16aap2.armoredElytra.ArmoredElytra -version: 2.4 +version: 2.4.2 author: Pim commands: ArmoredElytra: