More changes for backwards support

This commit is contained in:
libraryaddict 2017-06-26 07:36:09 +12:00
parent d1a04e0f7d
commit a08e3aea9b
6 changed files with 67 additions and 16 deletions

View File

@ -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";
}
});

View File

@ -276,7 +276,7 @@ public class MetaIndex<Y> {
setValues();
}
public static void fillInBlankIndexes() {
public static void eliminateBlankIndexes() {
ArrayList<Entry<Class, ArrayList<MetaIndex>>> list = new ArrayList<>();
for (MetaIndex index : values()) {

View File

@ -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<Object, Object> 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;

View File

@ -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
*

View File

@ -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);
}
}

View File

@ -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<? extends BackwardMethods> methods = BackwardMethods.class;
@ -70,6 +69,7 @@ public class BackwardsSupport {
private static BackwardMethods setupMetadata(Class<? extends BackwardMethods> backwardsClass) {
try {
BackwardMethods backwards = backwardsClass.newInstance();
ArrayList<MetaIndex> 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) {