Commit remaining work

This commit is contained in:
libraryaddict 2017-06-09 09:14:36 +12:00
parent 083c459057
commit 87e810c608
5 changed files with 58 additions and 15 deletions

View File

@ -3,6 +3,9 @@ package me.libraryaddict.disguise;
import java.io.File;
import java.io.IOException;
import java.lang.reflect.Field;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Iterator;
import me.libraryaddict.disguise.disguisetypes.watchers.*;
import org.bukkit.Bukkit;
@ -322,6 +325,7 @@ public class LibsDisguises extends JavaPlugin {
bukkitEntity instanceof Damageable ? ((Damageable) bukkitEntity).getMaxHealth() : 0);
WrappedDataWatcher watcher = WrappedDataWatcher.getEntityWatcher(bukkitEntity);
ArrayList<MetaIndex> indexes = MetaIndex.getFlags(disguiseType.getWatcherClass());
for (WrappedWatchableObject watch : watcher.getWatchableObjects()) {
MetaIndex flagType = MetaIndex.getFlag(watcherClass, watch.getIndex());
@ -335,6 +339,8 @@ public class LibsDisguises extends JavaPlugin {
continue;
}
indexes.remove(flagType);
if (ReflectionManager.convertInvalidItem(
flagType.getDefault()).getClass() != ReflectionManager.convertInvalidItem(
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());
if (sound != null) {

View File

@ -220,14 +220,8 @@ public class MetaIndex<Y> {
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,
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<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<ItemStack> SPLASH_POTION_ITEM = new MetaIndex<>(SplashPotionWatcher.class, 0,
new ItemStack(Material.SPLASH_POTION));
public static MetaIndex<Byte> TAMEABLE_META = new MetaIndex<>(TameableWatcher.class, 0, (byte) 0);
@ -438,6 +432,25 @@ public class MetaIndex<Y> {
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() {
try {
_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 {
Field field = MetaIndex.class.getField(name);
MetaIndex index = (MetaIndex) field.get(null);
@ -468,12 +484,13 @@ public class MetaIndex<Y> {
field.set(null, metaIndex);
}
catch (NoSuchFieldException ex) {
System.out.println("The field '" + name + "' doesn't exist in MetaIndex!");
Thread.dumpStack();
return false;
}
catch (Exception ex) {
ex.printStackTrace();
}
return true;
}
private Y _defaultValue;

View File

@ -3,9 +3,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_1;
import me.libraryaddict.disguise.utilities.backwards.metadata.Version_1_11;
import java.lang.reflect.Field;
import java.util.ArrayList;
/**
* Created by libraryaddict on 8/06/2017.
@ -17,7 +18,7 @@ public class BackwardsSupport {
if (LibsPremium.isPremium()) {
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) {
try {
BackwardMethods backwards = backwardsClass.newInstance();
ArrayList<MetaIndex> newIndexes = new ArrayList<>();
for (Field field : backwards.getClass().getFields()) {
if (field.getType() != MetaIndex.class)
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.addMetaIndexes(newIndexes.toArray(new MetaIndex[0]));
if (backwards.isOrderedIndexes()) {
MetaIndex.fillInBlankIndexes();
MetaIndex.orderMetaIndexes();

View File

@ -0,0 +1,7 @@
package me.libraryaddict.disguise.utilities.backwards.metadata;
/**
* Created by libraryaddict on 9/06/2017.
*/
public class Version_1_10 {
}

View File

@ -10,7 +10,7 @@ import me.libraryaddict.disguise.utilities.backwards.BackwardMethods;
* Created by libraryaddict on 8/06/2017.
* 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 PARROT_VARIANT;
private MetaIndex PLAYER_LEFT_SHOULDER_ENTITY;