From a08e3aea9b8ae00c243d17372208b13e7ef2d98a Mon Sep 17 00:00:00 2001 From: libraryaddict Date: Mon, 26 Jun 2017 07:36:09 +1200 Subject: [PATCH] More changes for backwards support --- .../libraryaddict/disguise/LibsDisguises.java | 39 +++++++++++++------ .../disguise/disguisetypes/MetaIndex.java | 2 +- .../disguise/utilities/DisguiseSound.java | 15 +++++++ .../disguise/utilities/ReflectionManager.java | 6 +++ .../utilities/backwards/BackwardMethods.java | 11 ++++++ .../utilities/backwards/BackwardsSupport.java | 10 +++-- 6 files changed, 67 insertions(+), 16 deletions(-) diff --git a/src/me/libraryaddict/disguise/LibsDisguises.java b/src/me/libraryaddict/disguise/LibsDisguises.java index a685f3a9..423a137d 100644 --- a/src/me/libraryaddict/disguise/LibsDisguises.java +++ b/src/me/libraryaddict/disguise/LibsDisguises.java @@ -29,7 +29,7 @@ public class LibsDisguises extends JavaPlugin { instance = this; saveDefaultConfig(); - getLogger().info("Discovered MC version: " + ReflectionManager.getBukkitVersion()); + getLogger().info("Discovered nms version: " + ReflectionManager.getBukkitVersion()); if (!new File(getDataFolder(), "disguises.yml").exists()) { saveResource("disguises.yml", false); @@ -134,24 +134,41 @@ public class LibsDisguises extends JavaPlugin { } }); - metrics.addCustomChart(new Metrics.SimplePie("disguised_with_commands") { + metrics.addCustomChart(new Metrics.SimplePie("disguised_using") { @Override public String getValue() { - return DisguiseUtilities.isCommandsUsed() ? "Yes" : "No"; + if (DisguiseUtilities.isPluginsUsed()) { + if (DisguiseUtilities.isCommandsUsed()) { + return "Plugins and Commands"; + } + + return "Plugins"; + } else if (DisguiseUtilities.isCommandsUsed()) { + return "Commands"; + } + + return "Unknown"; } }); - metrics.addCustomChart(new Metrics.SimplePie("disguised_with_plugins") { + metrics.addCustomChart(new Metrics.SimplePie("active_disguises") { @Override public String getValue() { - return DisguiseUtilities.isPluginsUsed() ? "Yes" : "No"; - } - }); + int disgs = 0; - metrics.addCustomChart(new Metrics.SimplePie("using_disguises") { - @Override - public String getValue() { - return !DisguiseUtilities.getDisguises().isEmpty() ? "Yes" : "No"; + for (HashSet set : DisguiseUtilities.getDisguises().values()) { + disgs += set.size(); + } + + if (disgs == 0) + return "0"; + if (disgs <= 5) + return "1 to 5"; + else if (disgs <= 15) + return "6 to 15"; + else if (disgs <= 30) + return "16 to 30"; + return "More than 30"; } }); diff --git a/src/me/libraryaddict/disguise/disguisetypes/MetaIndex.java b/src/me/libraryaddict/disguise/disguisetypes/MetaIndex.java index 8ff2b323..a035f1a2 100644 --- a/src/me/libraryaddict/disguise/disguisetypes/MetaIndex.java +++ b/src/me/libraryaddict/disguise/disguisetypes/MetaIndex.java @@ -276,7 +276,7 @@ public class MetaIndex { setValues(); } - public static void fillInBlankIndexes() { + public static void eliminateBlankIndexes() { ArrayList>> list = new ArrayList<>(); for (MetaIndex index : values()) { diff --git a/src/me/libraryaddict/disguise/utilities/DisguiseSound.java b/src/me/libraryaddict/disguise/utilities/DisguiseSound.java index 79ec679c..855d649d 100644 --- a/src/me/libraryaddict/disguise/utilities/DisguiseSound.java +++ b/src/me/libraryaddict/disguise/utilities/DisguiseSound.java @@ -202,6 +202,21 @@ public enum DisguiseSound { } } + public static void replace(String oldString, String newString) { + for (DisguiseSound sound : DisguiseSound.values()) { + if (sound.disguiseSounds.containsKey(oldString)) { + sound.disguiseSounds.put(newString, sound.disguiseSounds.get(oldString)); + } + + for (Entry entry : sound.disguiseSounds.entrySet()) { + if (entry.getValue() == null || !entry.getValue().equals(oldString)) + continue; + + entry.setValue(newString); + } + } + } + private void addSound(Object sound, SoundType type) { String s; diff --git a/src/me/libraryaddict/disguise/utilities/ReflectionManager.java b/src/me/libraryaddict/disguise/utilities/ReflectionManager.java index faf6fdd0..1fa2a5ca 100644 --- a/src/me/libraryaddict/disguise/utilities/ReflectionManager.java +++ b/src/me/libraryaddict/disguise/utilities/ReflectionManager.java @@ -850,6 +850,12 @@ public class ReflectionManager { return value; } + public static String getMinecraftVersion() { + String version = Bukkit.getVersion(); + version = version.substring(version.lastIndexOf(" ") + 1, version.length() - 1); + return version; + } + /** * This creates a DataWatcherItem usable with WrappedWatchableObject * diff --git a/src/me/libraryaddict/disguise/utilities/backwards/BackwardMethods.java b/src/me/libraryaddict/disguise/utilities/backwards/BackwardMethods.java index b6da500c..285b3db2 100644 --- a/src/me/libraryaddict/disguise/utilities/backwards/BackwardMethods.java +++ b/src/me/libraryaddict/disguise/utilities/backwards/BackwardMethods.java @@ -1,5 +1,9 @@ package me.libraryaddict.disguise.utilities.backwards; +import me.libraryaddict.disguise.utilities.DisguiseSound; + +import java.util.HashMap; + /** * Created by libraryaddict on 8/06/2017. */ @@ -8,4 +12,11 @@ public class BackwardMethods { public boolean isOrderedIndexes() { return true; } + + public void doReplaceSounds() { + } + + public void replace(String old, String newString) { + DisguiseSound.replace(old, newString); + } } diff --git a/src/me/libraryaddict/disguise/utilities/backwards/BackwardsSupport.java b/src/me/libraryaddict/disguise/utilities/backwards/BackwardsSupport.java index a0623799..2e48fdaa 100644 --- a/src/me/libraryaddict/disguise/utilities/backwards/BackwardsSupport.java +++ b/src/me/libraryaddict/disguise/utilities/backwards/BackwardsSupport.java @@ -2,10 +2,10 @@ package me.libraryaddict.disguise.utilities.backwards; import me.libraryaddict.disguise.disguisetypes.MetaIndex; import me.libraryaddict.disguise.utilities.LibsPremium; +import me.libraryaddict.disguise.utilities.ReflectionManager; import me.libraryaddict.disguise.utilities.backwards.metadata.Version_1_10; import me.libraryaddict.disguise.utilities.backwards.metadata.Version_1_11; import me.libraryaddict.disguise.utilities.backwards.metadata.Version_1_9; -import org.bukkit.Bukkit; import java.lang.reflect.Field; import java.util.ArrayList; @@ -16,8 +16,7 @@ import java.util.ArrayList; public class BackwardsSupport { public static BackwardMethods getMethods() { try { - String version = Bukkit.getVersion(); - version = version.substring(version.lastIndexOf(" ") + 1, version.length() - 1); + String version = ReflectionManager.getMinecraftVersion(); Class methods = BackwardMethods.class; @@ -70,6 +69,7 @@ public class BackwardsSupport { private static BackwardMethods setupMetadata(Class backwardsClass) { try { BackwardMethods backwards = backwardsClass.newInstance(); + ArrayList newIndexes = new ArrayList<>(); getIndexes(backwardsClass, backwards, newIndexes); @@ -79,10 +79,12 @@ public class BackwardsSupport { MetaIndex.addMetaIndexes(newIndexes.toArray(new MetaIndex[0])); if (backwards.isOrderedIndexes()) { - MetaIndex.fillInBlankIndexes(); + MetaIndex.eliminateBlankIndexes(); MetaIndex.orderMetaIndexes(); } + backwards.doReplaceSounds(); + return backwards; } catch (Exception ex) {