From bd93f1dbd7eabd25004f0f0c10891c263f1c0ddd Mon Sep 17 00:00:00 2001 From: libraryaddict Date: Tue, 11 Jul 2017 04:02:24 +1200 Subject: [PATCH] Change where Lib's premim does its check. Fix backwards compatibility a little --- .../libraryaddict/disguise/LibsDisguises.java | 42 ++++++++++++++++--- .../disguise/disguisetypes/MetaIndex.java | 20 +++++++-- .../utilities/backwards/BackwardsSupport.java | 22 +++++++--- .../backwards/metadata/Version_1_10.java | 9 ++++ 4 files changed, 79 insertions(+), 14 deletions(-) diff --git a/src/me/libraryaddict/disguise/LibsDisguises.java b/src/me/libraryaddict/disguise/LibsDisguises.java index 423a137d..9fcffb58 100644 --- a/src/me/libraryaddict/disguise/LibsDisguises.java +++ b/src/me/libraryaddict/disguise/LibsDisguises.java @@ -17,6 +17,7 @@ import org.bukkit.plugin.java.JavaPlugin; import java.io.File; import java.lang.reflect.Field; import java.util.ArrayList; +import java.util.Collection; import java.util.HashMap; import java.util.HashSet; @@ -27,6 +28,7 @@ public class LibsDisguises extends JavaPlugin { @Override public void onEnable() { instance = this; + saveDefaultConfig(); getLogger().info("Discovered nms version: " + ReflectionManager.getBukkitVersion()); @@ -35,6 +37,8 @@ public class LibsDisguises extends JavaPlugin { saveResource("disguises.yml", false); } + LibsPremium.check(instance); + PacketsManager.init(this); DisguiseUtilities.init(this); @@ -200,6 +204,27 @@ public class LibsDisguises extends JavaPlugin { return updates ? "Enabled" : "Disabled"; } }); + + metrics.addCustomChart(new Metrics.SimplePie("targeted_disguises") { + @Override + public String getValue() { + Collection> list = DisguiseUtilities.getDisguises().values(); + + if (list.isEmpty()) + return "Unknown"; + + for (HashSet dList : list) { + for (TargetedDisguise disg : dList) { + if (disg.getObservers().isEmpty()) + continue; + + return "Yes"; + } + } + + return "No"; + } + }); } @Override @@ -423,13 +448,18 @@ public class LibsDisguises extends JavaPlugin { indexes.remove(flagType); - if (ReflectionManager.convertInvalidItem(flagType.getDefault()).getClass() != ReflectionManager - .convertInvalidItem(watch.getValue()).getClass()) { - System.err.println("Mismatch of FlagType's for " + disguiseType.name() + "! Index " + watch + Object obj1 = ReflectionManager.convertInvalidItem(flagType.getDefault()); + Object obj2 = ReflectionManager.convertInvalidItem(watch.getValue()); + + if (obj1 != obj2 && ((obj1 == null || obj2 == null) || obj1.getClass() != obj2.getClass())) { + System.err.println("Mismatch of " + "FlagType's for " + disguiseType.name() + "! Index " + watch .getIndex() + " has the wrong classtype!"); - System.err.println("Value is " + watch.getRawValue() + " (" + watch.getRawValue() - .getClass() + ") (" + nmsEntity.getClass() + ") & " + watcherClass - .getSimpleName() + " which doesn't match up with " + flagType.getDefault().getClass()); + System.err.println( + "MetaIndex has the " + "default of " + flagType.getDefault() + " (" + flagType + .getDefault().getClass() + ") (" + nmsEntity.getClass() + ") & " + watcherClass + .getSimpleName()); + System.err.println("Where the internals is " + watch.getRawValue() + " (" + watch.getRawValue() + .getClass()); System.err.println("Lib's Disguises will continue to load, but this will not work properly!"); } } diff --git a/src/me/libraryaddict/disguise/disguisetypes/MetaIndex.java b/src/me/libraryaddict/disguise/disguisetypes/MetaIndex.java index a035f1a2..03897535 100644 --- a/src/me/libraryaddict/disguise/disguisetypes/MetaIndex.java +++ b/src/me/libraryaddict/disguise/disguisetypes/MetaIndex.java @@ -410,12 +410,19 @@ public class MetaIndex { ArrayList list = new ArrayList<>(); for (MetaIndex type : values()) { - if (!type.getFlagWatcher().isAssignableFrom(watcherClass)) + if (type == null || !type.getFlagWatcher().isAssignableFrom(watcherClass)) continue; list.add(type); } + Collections.sort(list, new Comparator() { + @Override + public int compare(MetaIndex o1, MetaIndex o2) { + return Integer.compare(o1.getIndex(), o2.getIndex()); + } + }); + return list; } @@ -446,8 +453,15 @@ public class MetaIndex { for (int i = values().length - metaIndexes.length, a = 0; i < values().length; i++, a++) { MetaIndex index = metaIndexes[a]; + ArrayList list = getFlags(index.getFlagWatcher()); + + for (int b = index.getIndex(); b < list.size(); b++) { + list.get(b)._index++; + } + for (MetaIndex metaIndex : values()) { - if (metaIndex.getFlagWatcher() != index.getFlagWatcher() || metaIndex.getIndex() != index.getIndex()) { + if (metaIndex == null || metaIndex.getFlagWatcher() != index.getFlagWatcher() || metaIndex + .getIndex() != index.getIndex()) { continue; } @@ -507,7 +521,7 @@ public class MetaIndex { private int _index; private Class _watcher; - private MetaIndex(Class watcher, int index, Y defaultValue) { + public MetaIndex(Class watcher, int index, Y defaultValue) { _index = index; _watcher = watcher; _defaultValue = defaultValue; diff --git a/src/me/libraryaddict/disguise/utilities/backwards/BackwardsSupport.java b/src/me/libraryaddict/disguise/utilities/backwards/BackwardsSupport.java index 2e48fdaa..8e9abb94 100644 --- a/src/me/libraryaddict/disguise/utilities/backwards/BackwardsSupport.java +++ b/src/me/libraryaddict/disguise/utilities/backwards/BackwardsSupport.java @@ -9,6 +9,8 @@ import me.libraryaddict.disguise.utilities.backwards.metadata.Version_1_9; import java.lang.reflect.Field; import java.util.ArrayList; +import java.util.HashMap; +import java.util.HashSet; /** * Created by libraryaddict on 8/06/2017. @@ -48,16 +50,22 @@ public class BackwardsSupport { } private static void getIndexes(Class backwardsClass, BackwardMethods backwards, - ArrayList newIndexes) throws IllegalAccessException { - for (Field field : backwardsClass.getFields()) { + HashMap newIndexes) throws IllegalAccessException { + for (Field field : backwardsClass.getDeclaredFields()) { if (field.getType() != MetaIndex.class) continue; + field.setAccessible(true); + + if (newIndexes.containsKey(field.getName())) + continue; + if (MetaIndex.setMetaIndex(field.getName(), (MetaIndex) field.get(backwards))) { + newIndexes.put(field.getName(), MetaIndex.ENTITY_META); continue; } - newIndexes.add((MetaIndex) field.get(backwards)); + newIndexes.put(field.getName(), (MetaIndex) field.get(backwards)); } backwardsClass = backwardsClass.getSuperclass(); @@ -70,13 +78,17 @@ public class BackwardsSupport { try { BackwardMethods backwards = backwardsClass.newInstance(); - ArrayList newIndexes = new ArrayList<>(); + HashMap newIndexes = new HashMap<>(); getIndexes(backwardsClass, backwards, newIndexes); MetaIndex.setValues(); - MetaIndex.addMetaIndexes(newIndexes.toArray(new MetaIndex[0])); + HashSet indexes = new HashSet<>(newIndexes.values()); + indexes.remove(MetaIndex.ENTITY_META); // We do the hashmap stuff to prevent multiple versions + // registering the same meta index + + MetaIndex.addMetaIndexes(indexes.toArray(new MetaIndex[0])); if (backwards.isOrderedIndexes()) { MetaIndex.eliminateBlankIndexes(); diff --git a/src/me/libraryaddict/disguise/utilities/backwards/metadata/Version_1_10.java b/src/me/libraryaddict/disguise/utilities/backwards/metadata/Version_1_10.java index a1ef645f..6af7929b 100644 --- a/src/me/libraryaddict/disguise/utilities/backwards/metadata/Version_1_10.java +++ b/src/me/libraryaddict/disguise/utilities/backwards/metadata/Version_1_10.java @@ -1,6 +1,11 @@ package me.libraryaddict.disguise.utilities.backwards.metadata; +import com.google.common.base.Optional; import me.libraryaddict.disguise.disguisetypes.MetaIndex; +import me.libraryaddict.disguise.disguisetypes.watchers.DroppedItemWatcher; +import me.libraryaddict.disguise.disguisetypes.watchers.HorseWatcher; +import org.bukkit.Material; +import org.bukkit.inventory.ItemStack; /** * Created by libraryaddict on 9/06/2017. @@ -10,4 +15,8 @@ import me.libraryaddict.disguise.disguisetypes.MetaIndex; public class Version_1_10 extends Version_1_11 { private MetaIndex ILLAGER_META; private MetaIndex ILLAGER_SPELL_TICKS; + private MetaIndex HORSE_VARIANT = new MetaIndex<>(HorseWatcher.class, 1, 0); + private MetaIndex SHULKER_COLOR; + private MetaIndex> DROPPED_ITEM = new MetaIndex<>(DroppedItemWatcher.class, 0, + Optional.of(new ItemStack(Material.STONE))); }