mirror of
https://github.com/libraryaddict/LibsDisguises.git
synced 2024-09-11 01:38:07 +02:00
Change where Lib's premim does its check. Fix backwards compatibility a little
This commit is contained in:
parent
f239dcc1fe
commit
bd93f1dbd7
@ -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<HashSet<TargetedDisguise>> list = DisguiseUtilities.getDisguises().values();
|
||||
|
||||
if (list.isEmpty())
|
||||
return "Unknown";
|
||||
|
||||
for (HashSet<TargetedDisguise> 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!");
|
||||
}
|
||||
}
|
||||
|
@ -410,12 +410,19 @@ public class MetaIndex<Y> {
|
||||
ArrayList<MetaIndex> 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<MetaIndex>() {
|
||||
@Override
|
||||
public int compare(MetaIndex o1, MetaIndex o2) {
|
||||
return Integer.compare(o1.getIndex(), o2.getIndex());
|
||||
}
|
||||
});
|
||||
|
||||
return list;
|
||||
}
|
||||
|
||||
@ -446,8 +453,15 @@ public class MetaIndex<Y> {
|
||||
for (int i = values().length - metaIndexes.length, a = 0; i < values().length; i++, a++) {
|
||||
MetaIndex index = metaIndexes[a];
|
||||
|
||||
ArrayList<MetaIndex> 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<Y> {
|
||||
private int _index;
|
||||
private Class<? extends FlagWatcher> _watcher;
|
||||
|
||||
private MetaIndex(Class<? extends FlagWatcher> watcher, int index, Y defaultValue) {
|
||||
public MetaIndex(Class<? extends FlagWatcher> watcher, int index, Y defaultValue) {
|
||||
_index = index;
|
||||
_watcher = watcher;
|
||||
_defaultValue = defaultValue;
|
||||
|
@ -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<MetaIndex> newIndexes) throws IllegalAccessException {
|
||||
for (Field field : backwardsClass.getFields()) {
|
||||
HashMap<String, MetaIndex> 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<MetaIndex> newIndexes = new ArrayList<>();
|
||||
HashMap<String, MetaIndex> newIndexes = new HashMap<>();
|
||||
|
||||
getIndexes(backwardsClass, backwards, newIndexes);
|
||||
|
||||
MetaIndex.setValues();
|
||||
|
||||
MetaIndex.addMetaIndexes(newIndexes.toArray(new MetaIndex[0]));
|
||||
HashSet<MetaIndex> 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();
|
||||
|
@ -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<Integer> HORSE_VARIANT = new MetaIndex<>(HorseWatcher.class, 1, 0);
|
||||
private MetaIndex<Byte> SHULKER_COLOR;
|
||||
private MetaIndex<Optional<ItemStack>> DROPPED_ITEM = new MetaIndex<>(DroppedItemWatcher.class, 0,
|
||||
Optional.of(new ItemStack(Material.STONE)));
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user