From f1f8607dd413a3c0770eba1766d13a5b2fa320cc Mon Sep 17 00:00:00 2001 From: Pim van der Loos Date: Mon, 22 Jan 2018 10:35:00 +0100 Subject: [PATCH] - Fixed not being able to rename non-AE items. - Using correct version number again... - Removed unused methods in Metrics class, reducing jar size by 12.5%. --- pom.xml | 2 +- .../armoredElytra/ArmoredElytra.java | 37 +- .../armoredElytra/handlers/EventHandlers.java | 11 +- .../armoredElytra/nms/NBTEditor_V1_10_R1.java | 8 +- .../armoredElytra/nms/NBTEditor_V1_11_R1.java | 4 +- .../armoredElytra/nms/NBTEditor_V1_12_R1.java | 8 +- .../pim16aap2/armoredElytra/util/Metrics.java | 339 +----------------- src/main/resources/plugin.yml | 2 +- 8 files changed, 53 insertions(+), 358 deletions(-) diff --git a/pom.xml b/pom.xml index 5238cb9..fcc66ec 100644 --- a/pom.xml +++ b/pom.xml @@ -3,7 +3,7 @@ 4.0.0 nl.pim16aap2 ArmoredElytra - 2.1.9-SNAPSHOT + 2.2.1-SNAPSHOT diff --git a/src/main/java/nl/pim16aap2/armoredElytra/ArmoredElytra.java b/src/main/java/nl/pim16aap2/armoredElytra/ArmoredElytra.java index e3e38ea..5be0285 100644 --- a/src/main/java/nl/pim16aap2/armoredElytra/ArmoredElytra.java +++ b/src/main/java/nl/pim16aap2/armoredElytra/ArmoredElytra.java @@ -26,32 +26,32 @@ import nl.pim16aap2.armoredElytra.util.Update; public class ArmoredElytra extends JavaPlugin implements Listener { - private NBTEditor nbtEditor; - private ConfigLoader config; + private NBTEditor nbtEditor; + private ConfigLoader config; - private String usageDeniedMessage; - private String elytraReceivedMessage; - private String elytraName; - private String elytraLore; - private boolean upToDate; - private boolean uninstallMode; + private String usageDeniedMessage; + private String elytraReceivedMessage; + private String elytraName; + private String elytraLore; + private boolean upToDate; + private boolean uninstallMode; @Override public void onEnable() { // Load the settings from the config file. - config = new ConfigLoader(this); + config = new ConfigLoader(this); // Replace color codes by the corresponding colors. - usageDeniedMessage = config.getString("usageDeniedMessage" ).replaceAll("&((?i)[0-9a-fk-or])", "\u00A7$1"); - elytraReceivedMessage = config.getString("elytraReceivedMessage").replaceAll("&((?i)[0-9a-fk-or])", "\u00A7$1"); - elytraName = config.getString("elytraName" ).replaceAll("&((?i)[0-9a-fk-or])", "\u00A7$1"); - elytraLore = config.getString("elytraLore" ).replaceAll("&((?i)[0-9a-fk-or])", "\u00A7$1"); + usageDeniedMessage = config.getString("usageDeniedMessage" ).replaceAll("&((?i)[0-9a-fk-or])", "\u00A7$1"); + elytraReceivedMessage = config.getString("elytraReceivedMessage" ).replaceAll("&((?i)[0-9a-fk-or])", "\u00A7$1"); + elytraName = config.getString("elytraName" ).replaceAll("&((?i)[0-9a-fk-or])", "\u00A7$1"); + elytraLore = config.getString("elytraLore" ).replaceAll("&((?i)[0-9a-fk-or])", "\u00A7$1"); // Change the string to null if it says "NONE". - usageDeniedMessage = (Objects.equals(usageDeniedMessage, new String("NONE")) ? null : usageDeniedMessage ); - elytraReceivedMessage = (Objects.equals(elytraReceivedMessage, new String("NONE")) ? null : elytraReceivedMessage); - elytraLore = (Objects.equals(elytraLore, new String("NONE")) ? null : elytraLore ); + usageDeniedMessage = (Objects.equals(usageDeniedMessage, new String("NONE")) ? null : usageDeniedMessage ); + elytraReceivedMessage = (Objects.equals(elytraReceivedMessage, new String("NONE")) ? null : elytraReceivedMessage); + elytraLore = (Objects.equals(elytraLore, new String("NONE")) ? null : elytraLore ); // Check if the plugin should go into uninstall mode. uninstallMode = config.getBool("uninstallMode"); @@ -69,6 +69,7 @@ public class ArmoredElytra extends JavaPlugin implements Listener if (updateStatus > 0) { // TODO: Insert download link to latest version. + // TODO: Use Spiget instead of the unreliable BukkitDev's update stuff? // TODO: Add auto update option? // Load the loginHandler to show messages to the user when they join. @@ -91,13 +92,13 @@ public class ArmoredElytra extends JavaPlugin implements Listener // Are stats allowed? if (config.getBool("allowStats")) { - myLogger(Level.INFO, "Enabling stats!"); + myLogger(Level.INFO, "Enabling stats! Thanks, it really helps!"); @SuppressWarnings("unused") Metrics metrics = new Metrics(this); } else // Y u do dis? :( - myLogger(Level.INFO, "Stats disabled, not laoding stats :("); + 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!"); diff --git a/src/main/java/nl/pim16aap2/armoredElytra/handlers/EventHandlers.java b/src/main/java/nl/pim16aap2/armoredElytra/handlers/EventHandlers.java index 38c4856..8d1729e 100644 --- a/src/main/java/nl/pim16aap2/armoredElytra/handlers/EventHandlers.java +++ b/src/main/java/nl/pim16aap2/armoredElytra/handlers/EventHandlers.java @@ -1,17 +1,13 @@ package nl.pim16aap2.armoredElytra.handlers; -import java.lang.reflect.Field; import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.Random; import java.util.logging.Level; -import org.bukkit.Bukkit; import org.bukkit.ChatColor; import org.bukkit.Material; -import org.bukkit.craftbukkit.v1_10_R1.inventory.CraftItemStack; -import org.bukkit.craftbukkit.v1_12_R1.inventory.CraftInventoryAnvil; import org.bukkit.enchantments.Enchantment; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; @@ -28,9 +24,6 @@ import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.meta.EnchantmentStorageMeta; import org.bukkit.scheduler.BukkitRunnable; -import net.minecraft.server.v1_12_R1.ContainerAnvil; -import net.minecraft.server.v1_12_R1.Container; -import net.minecraft.server.v1_12_R1.ContainerDispenser; import nl.pim16aap2.armoredElytra.ArmoredElytra; import nl.pim16aap2.armoredElytra.nms.NBTEditor; import nl.pim16aap2.armoredElytra.util.Action; @@ -390,8 +383,8 @@ public class EventHandlers implements Listener } // Check if either itemA or itemB is unoccupied. - if (itemA == null || itemB == null) - // If Item2 is occupied despite itemA or itemB not being occupied. + if ((itemA == null || itemB == null) && nbtEditor.getArmorTier(event.getInventory().getItem(2)) != ArmorTier.NONE) + // If Item2 is occupied despite itemA or itemB not being occupied. (only for armored elytra)/ event.setResult(null); p.updateInventory(); } diff --git a/src/main/java/nl/pim16aap2/armoredElytra/nms/NBTEditor_V1_10_R1.java b/src/main/java/nl/pim16aap2/armoredElytra/nms/NBTEditor_V1_10_R1.java index 5d61ed8..bb4a1c8 100644 --- a/src/main/java/nl/pim16aap2/armoredElytra/nms/NBTEditor_V1_10_R1.java +++ b/src/main/java/nl/pim16aap2/armoredElytra/nms/NBTEditor_V1_10_R1.java @@ -3,6 +3,7 @@ package nl.pim16aap2.armoredElytra.nms; import java.util.Arrays; import org.bukkit.ChatColor; +import org.bukkit.Material; import org.bukkit.craftbukkit.v1_10_R1.inventory.CraftItemStack; import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.meta.ItemMeta; @@ -77,7 +78,12 @@ public class NBTEditor_V1_10_R1 implements NBTEditor // 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) diff --git a/src/main/java/nl/pim16aap2/armoredElytra/nms/NBTEditor_V1_11_R1.java b/src/main/java/nl/pim16aap2/armoredElytra/nms/NBTEditor_V1_11_R1.java index 4e367ef..a171e34 100644 --- a/src/main/java/nl/pim16aap2/armoredElytra/nms/NBTEditor_V1_11_R1.java +++ b/src/main/java/nl/pim16aap2/armoredElytra/nms/NBTEditor_V1_11_R1.java @@ -78,7 +78,9 @@ public class NBTEditor_V1_11_R1 implements NBTEditor // 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; diff --git a/src/main/java/nl/pim16aap2/armoredElytra/nms/NBTEditor_V1_12_R1.java b/src/main/java/nl/pim16aap2/armoredElytra/nms/NBTEditor_V1_12_R1.java index d99e43c..664e1c2 100644 --- a/src/main/java/nl/pim16aap2/armoredElytra/nms/NBTEditor_V1_12_R1.java +++ b/src/main/java/nl/pim16aap2/armoredElytra/nms/NBTEditor_V1_12_R1.java @@ -3,6 +3,7 @@ package nl.pim16aap2.armoredElytra.nms; import java.util.Arrays; import org.bukkit.ChatColor; +import org.bukkit.Material; import org.bukkit.craftbukkit.v1_12_R1.inventory.CraftItemStack; import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.meta.ItemMeta; @@ -77,7 +78,12 @@ public class NBTEditor_V1_12_R1 implements NBTEditor // 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) diff --git a/src/main/java/nl/pim16aap2/armoredElytra/util/Metrics.java b/src/main/java/nl/pim16aap2/armoredElytra/util/Metrics.java index 2ba64bc..a515abe 100644 --- a/src/main/java/nl/pim16aap2/armoredElytra/util/Metrics.java +++ b/src/main/java/nl/pim16aap2/armoredElytra/util/Metrics.java @@ -20,11 +20,9 @@ import java.net.URL; import java.util.ArrayList; import java.util.Collection; import java.util.List; -import java.util.Map; import java.util.Timer; import java.util.TimerTask; import java.util.UUID; -import java.util.concurrent.Callable; import java.util.logging.Level; import java.util.zip.GZIPOutputStream; @@ -108,35 +106,21 @@ public class Metrics { // Load the data serverUUID = config.getString("serverUuid"); logFailedRequests = config.getBoolean("logFailedRequests", false); - if (config.getBoolean("enabled", true)) { - boolean found = false; - // Search for all other bStats Metrics classes to see if we are the first one - for (Class service : Bukkit.getServicesManager().getKnownServices()) { - try { - service.getField("B_STATS_VERSION"); // Our identifier :) - found = true; // We aren't the first - break; - } catch (NoSuchFieldException ignored) { } - } - // Register our service - Bukkit.getServicesManager().register(Metrics.class, this, plugin, ServicePriority.Normal); - if (!found) { - // We are the first! - startSubmitting(); - } + boolean found = false; + // Search for all other bStats Metrics classes to see if we are the first one + for (Class service : Bukkit.getServicesManager().getKnownServices()) { + try { + service.getField("B_STATS_VERSION"); // Our identifier :) + found = true; // We aren't the first + break; + } catch (NoSuchFieldException ignored) { } } - } - - /** - * Adds a custom chart. - * - * @param chart The chart to add. - */ - public void addCustomChart(CustomChart chart) { - if (chart == null) { - throw new IllegalArgumentException("Chart cannot be null!"); + // Register our service + Bukkit.getServicesManager().register(Metrics.class, this, plugin, ServicePriority.Normal); + if (!found) { + // We are the first! + startSubmitting(); } - charts.add(chart); } /** @@ -376,303 +360,6 @@ public class Metrics { } return chart; } - protected abstract JSONObject getChartData() throws Exception; - - } - - /** - * Represents a custom simple pie. - */ - public static class SimplePie extends CustomChart { - - private final Callable callable; - - /** - * Class constructor. - * - * @param chartId The id of the chart. - * @param callable The callable which is used to request the chart data. - */ - public SimplePie(String chartId, Callable callable) { - super(chartId); - this.callable = callable; - } - - @SuppressWarnings("unchecked") - @Override - protected JSONObject getChartData() throws Exception { - JSONObject data = new JSONObject(); - String value = callable.call(); - if (value == null || value.isEmpty()) { - // Null = skip the chart - return null; - } - data.put("value", value); - return data; - } - } - - /** - * Represents a custom advanced pie. - */ - public static class AdvancedPie extends CustomChart { - - private final Callable> callable; - - /** - * Class constructor. - * - * @param chartId The id of the chart. - * @param callable The callable which is used to request the chart data. - */ - public AdvancedPie(String chartId, Callable> callable) { - super(chartId); - this.callable = callable; - } - - @SuppressWarnings("unchecked") - @Override - protected JSONObject getChartData() throws Exception { - JSONObject data = new JSONObject(); - JSONObject values = new JSONObject(); - Map map = callable.call(); - if (map == null || map.isEmpty()) { - // Null = skip the chart - return null; - } - boolean allSkipped = true; - for (Map.Entry entry : map.entrySet()) { - if (entry.getValue() == 0) { - continue; // Skip this invalid - } - allSkipped = false; - values.put(entry.getKey(), entry.getValue()); - } - if (allSkipped) { - // Null = skip the chart - return null; - } - data.put("values", values); - return data; - } - } - - /** - * Represents a custom drilldown pie. - */ - public static class DrilldownPie extends CustomChart { - - private final Callable>> callable; - - /** - * Class constructor. - * - * @param chartId The id of the chart. - * @param callable The callable which is used to request the chart data. - */ - public DrilldownPie(String chartId, Callable>> callable) { - super(chartId); - this.callable = callable; - } - - @SuppressWarnings("unchecked") - @Override - public JSONObject getChartData() throws Exception { - JSONObject data = new JSONObject(); - JSONObject values = new JSONObject(); - Map> map = callable.call(); - if (map == null || map.isEmpty()) { - // Null = skip the chart - return null; - } - boolean reallyAllSkipped = true; - for (Map.Entry> entryValues : map.entrySet()) { - JSONObject value = new JSONObject(); - boolean allSkipped = true; - for (Map.Entry valueEntry : map.get(entryValues.getKey()).entrySet()) { - value.put(valueEntry.getKey(), valueEntry.getValue()); - allSkipped = false; - } - if (!allSkipped) { - reallyAllSkipped = false; - values.put(entryValues.getKey(), value); - } - } - if (reallyAllSkipped) { - // Null = skip the chart - return null; - } - data.put("values", values); - return data; - } - } - - /** - * Represents a custom single line chart. - */ - public static class SingleLineChart extends CustomChart { - - private final Callable callable; - - /** - * Class constructor. - * - * @param chartId The id of the chart. - * @param callable The callable which is used to request the chart data. - */ - public SingleLineChart(String chartId, Callable callable) { - super(chartId); - this.callable = callable; - } - - @SuppressWarnings("unchecked") - @Override - protected JSONObject getChartData() throws Exception { - JSONObject data = new JSONObject(); - int value = callable.call(); - if (value == 0) { - // Null = skip the chart - return null; - } - data.put("value", value); - return data; - } - - } - - /** - * Represents a custom multi line chart. - */ - public static class MultiLineChart extends CustomChart { - - private final Callable> callable; - - /** - * Class constructor. - * - * @param chartId The id of the chart. - * @param callable The callable which is used to request the chart data. - */ - public MultiLineChart(String chartId, Callable> callable) { - super(chartId); - this.callable = callable; - } - - @SuppressWarnings("unchecked") - @Override - protected JSONObject getChartData() throws Exception { - JSONObject data = new JSONObject(); - JSONObject values = new JSONObject(); - Map map = callable.call(); - if (map == null || map.isEmpty()) { - // Null = skip the chart - return null; - } - boolean allSkipped = true; - for (Map.Entry entry : map.entrySet()) { - if (entry.getValue() == 0) { - continue; // Skip this invalid - } - allSkipped = false; - values.put(entry.getKey(), entry.getValue()); - } - if (allSkipped) { - // Null = skip the chart - return null; - } - data.put("values", values); - return data; - } - - } - - /** - * Represents a custom simple bar chart. - */ - public static class SimpleBarChart extends CustomChart { - - private final Callable> callable; - - /** - * Class constructor. - * - * @param chartId The id of the chart. - * @param callable The callable which is used to request the chart data. - */ - public SimpleBarChart(String chartId, Callable> callable) { - super(chartId); - this.callable = callable; - } - - @SuppressWarnings("unchecked") - @Override - protected JSONObject getChartData() throws Exception { - JSONObject data = new JSONObject(); - JSONObject values = new JSONObject(); - Map map = callable.call(); - if (map == null || map.isEmpty()) { - // Null = skip the chart - return null; - } - for (Map.Entry entry : map.entrySet()) { - JSONArray categoryValues = new JSONArray(); - categoryValues.add(entry.getValue()); - values.put(entry.getKey(), categoryValues); - } - data.put("values", values); - return data; - } - - } - - /** - * Represents a custom advanced bar chart. - */ - public static class AdvancedBarChart extends CustomChart { - - private final Callable> callable; - - /** - * Class constructor. - * - * @param chartId The id of the chart. - * @param callable The callable which is used to request the chart data. - */ - public AdvancedBarChart(String chartId, Callable> callable) { - super(chartId); - this.callable = callable; - } - - @SuppressWarnings("unchecked") - @Override - protected JSONObject getChartData() throws Exception { - JSONObject data = new JSONObject(); - JSONObject values = new JSONObject(); - Map map = callable.call(); - if (map == null || map.isEmpty()) { - // Null = skip the chart - return null; - } - boolean allSkipped = true; - for (Map.Entry entry : map.entrySet()) { - if (entry.getValue().length == 0) { - continue; // Skip this invalid - } - allSkipped = false; - JSONArray categoryValues = new JSONArray(); - for (int categoryValue : entry.getValue()) { - categoryValues.add(categoryValue); - } - values.put(entry.getKey(), categoryValues); - } - if (allSkipped) { - // Null = skip the chart - return null; - } - data.put("values", values); - return data; - } - } } diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml index 8f42fdf..657a01e 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.1.9 +version: 2.2.1 author: Pim commands: ArmoredElytra: