Commit remaining work
This commit is contained in:
		| @@ -3,6 +3,9 @@ package me.libraryaddict.disguise; | |||||||
| import java.io.File; | import java.io.File; | ||||||
| import java.io.IOException; | import java.io.IOException; | ||||||
| import java.lang.reflect.Field; | import java.lang.reflect.Field; | ||||||
|  | import java.util.ArrayList; | ||||||
|  | import java.util.Arrays; | ||||||
|  | import java.util.Iterator; | ||||||
|  |  | ||||||
| import me.libraryaddict.disguise.disguisetypes.watchers.*; | import me.libraryaddict.disguise.disguisetypes.watchers.*; | ||||||
| import org.bukkit.Bukkit; | import org.bukkit.Bukkit; | ||||||
| @@ -322,6 +325,7 @@ public class LibsDisguises extends JavaPlugin { | |||||||
|                         bukkitEntity instanceof Damageable ? ((Damageable) bukkitEntity).getMaxHealth() : 0); |                         bukkitEntity instanceof Damageable ? ((Damageable) bukkitEntity).getMaxHealth() : 0); | ||||||
|  |  | ||||||
|                 WrappedDataWatcher watcher = WrappedDataWatcher.getEntityWatcher(bukkitEntity); |                 WrappedDataWatcher watcher = WrappedDataWatcher.getEntityWatcher(bukkitEntity); | ||||||
|  |                 ArrayList<MetaIndex> indexes = MetaIndex.getFlags(disguiseType.getWatcherClass()); | ||||||
|  |  | ||||||
|                 for (WrappedWatchableObject watch : watcher.getWatchableObjects()) { |                 for (WrappedWatchableObject watch : watcher.getWatchableObjects()) { | ||||||
|                     MetaIndex flagType = MetaIndex.getFlag(watcherClass, watch.getIndex()); |                     MetaIndex flagType = MetaIndex.getFlag(watcherClass, watch.getIndex()); | ||||||
| @@ -335,6 +339,8 @@ public class LibsDisguises extends JavaPlugin { | |||||||
|                         continue; |                         continue; | ||||||
|                     } |                     } | ||||||
|  |  | ||||||
|  |                     indexes.remove(flagType); | ||||||
|  |  | ||||||
|                     if (ReflectionManager.convertInvalidItem( |                     if (ReflectionManager.convertInvalidItem( | ||||||
|                             flagType.getDefault()).getClass() != ReflectionManager.convertInvalidItem( |                             flagType.getDefault()).getClass() != ReflectionManager.convertInvalidItem( | ||||||
|                             watch.getValue()).getClass()) { |                             watch.getValue()).getClass()) { | ||||||
| @@ -346,6 +352,11 @@ public class LibsDisguises extends JavaPlugin { | |||||||
|                     } |                     } | ||||||
|                 } |                 } | ||||||
|  |  | ||||||
|  |                 for (MetaIndex index : indexes) { | ||||||
|  |                     System.out.println( | ||||||
|  |                             disguiseType + " has MetaIndex remaining! " + index.getFlagWatcher().getSimpleName() + " at index " + index.getIndex()); | ||||||
|  |                 } | ||||||
|  |  | ||||||
|                 DisguiseSound sound = DisguiseSound.getType(disguiseType.name()); |                 DisguiseSound sound = DisguiseSound.getType(disguiseType.name()); | ||||||
|  |  | ||||||
|                 if (sound != null) { |                 if (sound != null) { | ||||||
|   | |||||||
| @@ -220,14 +220,8 @@ public class MetaIndex<Y> { | |||||||
|  |  | ||||||
|     public static MetaIndex<Byte> SPIDER_CLIMB = new MetaIndex<>(SpiderWatcher.class, 0, (byte) 0); |     public static MetaIndex<Byte> SPIDER_CLIMB = new MetaIndex<>(SpiderWatcher.class, 0, (byte) 0); | ||||||
|  |  | ||||||
|     public static MetaIndex<ItemStack> SPLASH_POTION_ITEM = new MetaIndex<>(SplashPotionWatcher.class, 1, |     public static MetaIndex<ItemStack> SPLASH_POTION_ITEM = new MetaIndex<>(SplashPotionWatcher.class, 0, | ||||||
|             new ItemStack(Material.SPLASH_POTION)); // Yeah, the '1' isn't a bug. No idea why but MC thinks |             new ItemStack(Material.SPLASH_POTION)); | ||||||
|     // there's a '0' already. |  | ||||||
|  |  | ||||||
|     public static MetaIndex<ItemStack> SPLASH_POTION_ITEM_BAD = new MetaIndex<>(SplashPotionWatcher.class, 0, |  | ||||||
|             new ItemStack(Material.SPLASH_POTION)); // Yeah, the '1' isn't a bug. No |  | ||||||
|     // idea why but MC thinks there's a |  | ||||||
|     // '0' already. |  | ||||||
|  |  | ||||||
|     public static MetaIndex<Byte> TAMEABLE_META = new MetaIndex<>(TameableWatcher.class, 0, (byte) 0); |     public static MetaIndex<Byte> TAMEABLE_META = new MetaIndex<>(TameableWatcher.class, 0, (byte) 0); | ||||||
|  |  | ||||||
| @@ -438,6 +432,25 @@ public class MetaIndex<Y> { | |||||||
|         return _values; |         return _values; | ||||||
|     } |     } | ||||||
|  |  | ||||||
|  |     public static void addMetaIndexes(MetaIndex... metaIndexes) { | ||||||
|  |         _values = Arrays.copyOf(values(), values().length + metaIndexes.length); | ||||||
|  |  | ||||||
|  |         for (int i = values().length - metaIndexes.length, a = 0; i < values().length; i++, a++) { | ||||||
|  |             MetaIndex index = metaIndexes[a]; | ||||||
|  |  | ||||||
|  |             for (MetaIndex metaIndex : values()) { | ||||||
|  |                 if (metaIndex.getFlagWatcher() != index.getFlagWatcher() || metaIndex.getIndex() != index.getIndex()) { | ||||||
|  |                     continue; | ||||||
|  |                 } | ||||||
|  |  | ||||||
|  |                 System.err.println( | ||||||
|  |                         "[LibsDisguises] MetaIndex " + metaIndex.getFlagWatcher().getSimpleName() + " at index " + metaIndex.getIndex() + " has already registered this! (" + metaIndex.getDefault() + "," + index.getDefault() + ")"); | ||||||
|  |             } | ||||||
|  |  | ||||||
|  |             values()[i] = metaIndexes[a]; | ||||||
|  |         } | ||||||
|  |     } | ||||||
|  |  | ||||||
|     public static void setValues() { |     public static void setValues() { | ||||||
|         try { |         try { | ||||||
|             _values = new MetaIndex[0]; |             _values = new MetaIndex[0]; | ||||||
| @@ -460,7 +473,10 @@ public class MetaIndex<Y> { | |||||||
|         } |         } | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     public static void setMetaIndex(String name, MetaIndex metaIndex) { |     /** | ||||||
|  |      * Returns true if success, false if the field doesn't exist | ||||||
|  |      */ | ||||||
|  |     public static boolean setMetaIndex(String name, MetaIndex metaIndex) { | ||||||
|         try { |         try { | ||||||
|             Field field = MetaIndex.class.getField(name); |             Field field = MetaIndex.class.getField(name); | ||||||
|             MetaIndex index = (MetaIndex) field.get(null); |             MetaIndex index = (MetaIndex) field.get(null); | ||||||
| @@ -468,12 +484,13 @@ public class MetaIndex<Y> { | |||||||
|             field.set(null, metaIndex); |             field.set(null, metaIndex); | ||||||
|         } |         } | ||||||
|         catch (NoSuchFieldException ex) { |         catch (NoSuchFieldException ex) { | ||||||
|             System.out.println("The field '" + name + "' doesn't exist in MetaIndex!"); |             return false; | ||||||
|             Thread.dumpStack(); |  | ||||||
|         } |         } | ||||||
|         catch (Exception ex) { |         catch (Exception ex) { | ||||||
|             ex.printStackTrace(); |             ex.printStackTrace(); | ||||||
|         } |         } | ||||||
|  |  | ||||||
|  |         return true; | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     private Y _defaultValue; |     private Y _defaultValue; | ||||||
|   | |||||||
| @@ -3,9 +3,10 @@ package me.libraryaddict.disguise.utilities.backwards; | |||||||
| import me.libraryaddict.disguise.disguisetypes.MetaIndex; | import me.libraryaddict.disguise.disguisetypes.MetaIndex; | ||||||
| import me.libraryaddict.disguise.utilities.LibsPremium; | import me.libraryaddict.disguise.utilities.LibsPremium; | ||||||
| import me.libraryaddict.disguise.utilities.ReflectionManager; | import me.libraryaddict.disguise.utilities.ReflectionManager; | ||||||
| import me.libraryaddict.disguise.utilities.backwards.metadata.Version_1_1; | import me.libraryaddict.disguise.utilities.backwards.metadata.Version_1_11; | ||||||
|  |  | ||||||
| import java.lang.reflect.Field; | import java.lang.reflect.Field; | ||||||
|  | import java.util.ArrayList; | ||||||
|  |  | ||||||
| /** | /** | ||||||
|  * Created by libraryaddict on 8/06/2017. |  * Created by libraryaddict on 8/06/2017. | ||||||
| @@ -17,7 +18,7 @@ public class BackwardsSupport { | |||||||
|  |  | ||||||
|             if (LibsPremium.isPremium()) { |             if (LibsPremium.isPremium()) { | ||||||
|                 if (version.equals("v1_11_R1")) { |                 if (version.equals("v1_11_R1")) { | ||||||
|                     return setupMetadata(Version_1_1.class); |                     return setupMetadata(Version_1_11.class); | ||||||
|                 } |                 } | ||||||
|             } |             } | ||||||
|  |  | ||||||
| @@ -33,16 +34,23 @@ public class BackwardsSupport { | |||||||
|     private static BackwardMethods setupMetadata(Class<? extends BackwardMethods> backwardsClass) { |     private static BackwardMethods setupMetadata(Class<? extends BackwardMethods> backwardsClass) { | ||||||
|         try { |         try { | ||||||
|             BackwardMethods backwards = backwardsClass.newInstance(); |             BackwardMethods backwards = backwardsClass.newInstance(); | ||||||
|  |             ArrayList<MetaIndex> newIndexes = new ArrayList<>(); | ||||||
|  |  | ||||||
|             for (Field field : backwards.getClass().getFields()) { |             for (Field field : backwards.getClass().getFields()) { | ||||||
|                 if (field.getType() != MetaIndex.class) |                 if (field.getType() != MetaIndex.class) | ||||||
|                     continue; |                     continue; | ||||||
|  |  | ||||||
|                 MetaIndex.setMetaIndex(field.getName(), (MetaIndex) field.get(backwards)); |                 if (MetaIndex.setMetaIndex(field.getName(), (MetaIndex) field.get(backwards))) { | ||||||
|  |                     continue; | ||||||
|  |                 } | ||||||
|  |  | ||||||
|  |                 newIndexes.add((MetaIndex) field.get(backwards)); | ||||||
|             } |             } | ||||||
|  |  | ||||||
|             MetaIndex.setValues(); |             MetaIndex.setValues(); | ||||||
|  |  | ||||||
|  |             MetaIndex.addMetaIndexes(newIndexes.toArray(new MetaIndex[0])); | ||||||
|  |  | ||||||
|             if (backwards.isOrderedIndexes()) { |             if (backwards.isOrderedIndexes()) { | ||||||
|                 MetaIndex.fillInBlankIndexes(); |                 MetaIndex.fillInBlankIndexes(); | ||||||
|                 MetaIndex.orderMetaIndexes(); |                 MetaIndex.orderMetaIndexes(); | ||||||
|   | |||||||
| @@ -0,0 +1,7 @@ | |||||||
|  | package me.libraryaddict.disguise.utilities.backwards.metadata; | ||||||
|  |  | ||||||
|  | /** | ||||||
|  |  * Created by libraryaddict on 9/06/2017. | ||||||
|  |  */ | ||||||
|  | public class Version_1_10 { | ||||||
|  | } | ||||||
| @@ -10,7 +10,7 @@ import me.libraryaddict.disguise.utilities.backwards.BackwardMethods; | |||||||
|  * Created by libraryaddict on 8/06/2017. |  * Created by libraryaddict on 8/06/2017. | ||||||
|  * Supports 1.11.0 1.11.1 and 1.11.2 |  * Supports 1.11.0 1.11.1 and 1.11.2 | ||||||
|  */ |  */ | ||||||
| public class Version_1_1 extends BackwardMethods { | public class Version_1_11 extends BackwardMethods { | ||||||
|     private MetaIndex ILLAGER_META; |     private MetaIndex ILLAGER_META; | ||||||
|     private MetaIndex PARROT_VARIANT; |     private MetaIndex PARROT_VARIANT; | ||||||
|     private MetaIndex PLAYER_LEFT_SHOULDER_ENTITY; |     private MetaIndex PLAYER_LEFT_SHOULDER_ENTITY; | ||||||
		Reference in New Issue
	
	Block a user