Fixed typos, added DisguiseParser.parsetoString(Disguise)
This commit is contained in:
@@ -1,15 +1,13 @@
|
||||
package me.libraryaddict.disguise.utilities;
|
||||
|
||||
import com.comphenix.protocol.PacketType;
|
||||
import com.comphenix.protocol.PacketType.Play.Server;
|
||||
import com.comphenix.protocol.ProtocolLibrary;
|
||||
import com.comphenix.protocol.ProtocolManager;
|
||||
import com.comphenix.protocol.events.PacketContainer;
|
||||
import com.comphenix.protocol.reflect.StructureModifier;
|
||||
import com.comphenix.protocol.wrappers.*;
|
||||
import com.google.common.collect.ConcurrentHashMultiset;
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.GsonBuilder;
|
||||
import com.google.gson.JsonSyntaxException;
|
||||
import com.mojang.authlib.properties.PropertyMap;
|
||||
import me.libraryaddict.disguise.DisguiseAPI;
|
||||
import me.libraryaddict.disguise.DisguiseConfig;
|
||||
@@ -18,7 +16,6 @@ import me.libraryaddict.disguise.LibsDisguises;
|
||||
import me.libraryaddict.disguise.disguisetypes.*;
|
||||
import me.libraryaddict.disguise.disguisetypes.TargetedDisguise.TargetType;
|
||||
import me.libraryaddict.disguise.disguisetypes.watchers.AgeableWatcher;
|
||||
import me.libraryaddict.disguise.disguisetypes.watchers.PlayerWatcher;
|
||||
import me.libraryaddict.disguise.disguisetypes.watchers.ZombieWatcher;
|
||||
import me.libraryaddict.disguise.utilities.json.*;
|
||||
import me.libraryaddict.disguise.utilities.packets.LibsPackets;
|
||||
@@ -29,8 +26,10 @@ import me.libraryaddict.disguise.utilities.reflection.LibsProfileLookup;
|
||||
import me.libraryaddict.disguise.utilities.reflection.ReflectionManager;
|
||||
import me.libraryaddict.disguise.utilities.translations.LibsMsg;
|
||||
import org.apache.logging.log4j.util.Strings;
|
||||
import org.bukkit.*;
|
||||
import org.bukkit.block.BlockFace;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.craftbukkit.libs.org.apache.commons.io.FileUtils;
|
||||
import org.bukkit.entity.*;
|
||||
import org.bukkit.inventory.EquipmentSlot;
|
||||
@@ -600,6 +599,12 @@ public class DisguiseUtilities {
|
||||
|
||||
return gson.fromJson(cached, WrappedGameProfile.class);
|
||||
}
|
||||
catch (JsonSyntaxException ex) {
|
||||
DisguiseUtilities.getLogger()
|
||||
.warning("Gameprofile " + file.getName() + " had invalid gson and has been deleted");
|
||||
cachedNames.remove(playerName.toLowerCase());
|
||||
file.delete();
|
||||
}
|
||||
catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
@@ -705,8 +710,14 @@ public class DisguiseUtilities {
|
||||
final String playerName = origName.toLowerCase();
|
||||
|
||||
if (DisguiseConfig.isSaveGameProfiles() && hasGameProfile(playerName)) {
|
||||
return getGameProfile(playerName);
|
||||
} else if (Pattern.matches("([A-Za-z0-9_]){1,16}", origName)) {
|
||||
WrappedGameProfile profile = getGameProfile(playerName);
|
||||
|
||||
if (profile != null) {
|
||||
return profile;
|
||||
}
|
||||
}
|
||||
|
||||
if (Pattern.matches("([A-Za-z0-9_]){1,16}", origName)) {
|
||||
final Player player = Bukkit.getPlayerExact(playerName);
|
||||
|
||||
if (player != null) {
|
||||
|
@@ -182,17 +182,19 @@ public class PacketListenerClientInteract extends PacketAdapter {
|
||||
if (disguise.getType() == DisguiseType.SHEEP) {
|
||||
SheepWatcher watcher = (SheepWatcher) disguise.getWatcher();
|
||||
|
||||
watcher.setColor(DisguiseConfig.isSheepDyeable() ? color : watcher.getColor());
|
||||
watcher.setColor(DisguiseConfig.isSheepDyeable() ? color.getDyeColor() : watcher.getColor());
|
||||
break;
|
||||
} else if (disguise.getType() == DisguiseType.WOLF) {
|
||||
WolfWatcher watcher = (WolfWatcher) disguise.getWatcher();
|
||||
|
||||
watcher.setCollarColor(DisguiseConfig.isWolfDyeable() ? color : watcher.getCollarColor());
|
||||
watcher.setCollarColor(
|
||||
DisguiseConfig.isWolfDyeable() ? color.getDyeColor() : watcher.getCollarColor());
|
||||
break;
|
||||
} else if (disguise.getType() == DisguiseType.CAT) {
|
||||
CatWatcher watcher = (CatWatcher) disguise.getWatcher();
|
||||
|
||||
watcher.setCollarColor(DisguiseConfig.isCatDyeable() ? color : watcher.getCollarColor());
|
||||
watcher.setCollarColor(
|
||||
DisguiseConfig.isCatDyeable() ? color.getDyeColor() : watcher.getCollarColor());
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@@ -1,6 +1,7 @@
|
||||
package me.libraryaddict.disguise.utilities.parser;
|
||||
|
||||
import com.comphenix.protocol.wrappers.WrappedGameProfile;
|
||||
import com.google.gson.Gson;
|
||||
import me.libraryaddict.disguise.DisguiseConfig;
|
||||
import me.libraryaddict.disguise.disguisetypes.*;
|
||||
import me.libraryaddict.disguise.utilities.DisguiseUtilities;
|
||||
@@ -17,6 +18,7 @@ import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.permissions.PermissionAttachmentInfo;
|
||||
import org.bukkit.potion.PotionEffectType;
|
||||
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.lang.reflect.Method;
|
||||
@@ -25,6 +27,185 @@ import java.util.Map.Entry;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
public class DisguiseParser {
|
||||
private static HashMap<Method, Map.Entry<Method, Object>> defaultWatcherValues = new HashMap<>();
|
||||
|
||||
public static void createDefaultMethods() {
|
||||
try {
|
||||
for (DisguiseType type : DisguiseType.values()) {
|
||||
Disguise disguise;
|
||||
|
||||
if (type.isMisc()) {
|
||||
disguise = new MiscDisguise(type);
|
||||
} else if (type.isMob()) {
|
||||
disguise = new MobDisguise(type);
|
||||
} else {
|
||||
disguise = new PlayerDisguise("Foobar");
|
||||
}
|
||||
|
||||
FlagWatcher watcher = type.getWatcherClass().getConstructor(Disguise.class).newInstance(disguise);
|
||||
|
||||
Method[] methods = ParamInfoManager.getDisguiseWatcherMethods(watcher.getClass());
|
||||
|
||||
for (Method setMethod : methods) {
|
||||
// Invalidate methods that can't be handled normally
|
||||
if (setMethod.getName().equals("addPotionEffect") || (setMethod.getName().equals("setSkin") &&
|
||||
setMethod.getParameterTypes()[0] == String.class) ||
|
||||
(setMethod.getName().equals("setTarget") &&
|
||||
setMethod.getParameterTypes()[0] != int.class) ||
|
||||
(setMethod.getName().equals("setItemInMainHand") &&
|
||||
setMethod.getParameterTypes()[0] == Material.class)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
String getName = setMethod.getName().substring(3); // Remove 'set'
|
||||
|
||||
if (getName.equals("HasNectar")) {
|
||||
getName = "hasNectar";
|
||||
} else if (getName.equals("HasStung")) {
|
||||
getName = "hasStung";
|
||||
} else if (setMethod.getParameterTypes()[0].isAssignableFrom(boolean.class)) {
|
||||
getName = "is" + getName;
|
||||
} else {
|
||||
getName = "get" + getName;
|
||||
}
|
||||
|
||||
Method getMethod = null;
|
||||
|
||||
for (Method m : setMethod.getDeclaringClass().getDeclaredMethods()) {
|
||||
if (!m.getName().equals(getName)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (m.getParameterTypes().length > 0 || m.getReturnType() != setMethod.getParameterTypes()[0]) {
|
||||
continue;
|
||||
}
|
||||
|
||||
getMethod = m;
|
||||
break;
|
||||
}
|
||||
|
||||
if (getMethod == null) {
|
||||
DisguiseUtilities.getLogger().severe(String
|
||||
.format("No such method '%s' when looking for the companion of '%s' in '%s'", getName,
|
||||
setMethod.getName(), setMethod.getDeclaringClass().getSimpleName()));
|
||||
continue;
|
||||
}
|
||||
|
||||
Object defaultValue = null;
|
||||
|
||||
// Value is randomish so shouldn't be checked, should always specify value when setting
|
||||
if (!setMethod.isAnnotationPresent(RandomDefaultValue.class)) {
|
||||
Object invokeWith = watcher;
|
||||
|
||||
if (!FlagWatcher.class.isAssignableFrom(getMethod.getDeclaringClass())) {
|
||||
invokeWith = disguise;
|
||||
}
|
||||
|
||||
defaultValue = getMethod.invoke(invokeWith);
|
||||
}
|
||||
|
||||
addWatcherDefault(setMethod, getMethod, defaultValue);
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (InstantiationException | IllegalAccessException | InvocationTargetException | NoSuchMethodException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public static String parseToString(Disguise disguise) {
|
||||
try {
|
||||
StringBuilder stringBuilder = new StringBuilder();
|
||||
|
||||
stringBuilder.append(disguise.getType().name());
|
||||
|
||||
if (disguise.isPlayerDisguise()) {
|
||||
stringBuilder.append(" ").append(((PlayerDisguise) disguise).getName());
|
||||
}
|
||||
|
||||
for (Method m : ParamInfoManager.getDisguiseWatcherMethods(disguise.getType().getWatcherClass())) {
|
||||
// Special handling for this method
|
||||
if (m.getName().equals("addPotionEffect")) {
|
||||
PotionEffectType[] types = (PotionEffectType[]) m.getDeclaringClass().getMethod("getPotionEffects")
|
||||
.invoke(disguise.getWatcher());
|
||||
|
||||
for (PotionEffectType type : types) {
|
||||
if (type == null) {
|
||||
continue;
|
||||
}
|
||||
|
||||
stringBuilder.append(" ").append(m.getName()).append(" ").append(type.getName());
|
||||
}
|
||||
} else {
|
||||
Entry<Method, Object> entry = defaultWatcherValues.get(m);
|
||||
|
||||
if (entry == null) {
|
||||
continue;
|
||||
}
|
||||
|
||||
Object invokeWith = m.getDeclaringClass().isInstance(disguise) ? disguise : disguise.getWatcher();
|
||||
|
||||
Object ourValue = entry.getKey().invoke(invokeWith);
|
||||
|
||||
// Escape a hacky fix for custom names, disguised players with custom names don't want to show it
|
||||
// so it was set to an empty string.
|
||||
if ("".equals(ourValue) && m.getName().equals("setCustomName")) {
|
||||
ourValue = null;
|
||||
}
|
||||
|
||||
// If its the same as default, continue
|
||||
if (!m.isAnnotationPresent(RandomDefaultValue.class) &&
|
||||
Objects.deepEquals(entry.getValue(), ourValue)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
stringBuilder.append(" ").append(m.getName());
|
||||
|
||||
if (ourValue instanceof Boolean && (Boolean) ourValue) {
|
||||
continue;
|
||||
}
|
||||
|
||||
String valueString;
|
||||
|
||||
if (ourValue != null) {
|
||||
valueString = ParamInfoManager.getParamInfo(ourValue.getClass()).toString(ourValue);
|
||||
|
||||
if (valueString.contains(" ") || valueString.contains("\"")) {
|
||||
valueString = "\"" + valueString.replace("\\", "\\\\").replace("\"", "\\\"") + "\"";
|
||||
}
|
||||
} else {
|
||||
valueString = "null";
|
||||
}
|
||||
|
||||
stringBuilder.append(" ").append(valueString);
|
||||
}
|
||||
}
|
||||
|
||||
return stringBuilder.toString();
|
||||
}
|
||||
catch (IllegalAccessException | InvocationTargetException | NoSuchMethodException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
private static void addWatcherDefault(Method setMethod, Method getMethod, Object object) {
|
||||
Map.Entry<Method, Object> entry = new HashMap.SimpleEntry<>(getMethod, object);
|
||||
|
||||
if (defaultWatcherValues.containsKey(setMethod)) {
|
||||
Object dObj = defaultWatcherValues.get(setMethod);
|
||||
|
||||
if (!Objects.deepEquals(defaultWatcherValues.get(setMethod).getValue(), object)) {
|
||||
throw new IllegalStateException(String.format("%s has conflicting values!", setMethod.getName()));
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
defaultWatcherValues.put(setMethod, entry);
|
||||
}
|
||||
|
||||
private static void doCheck(CommandSender sender, DisguisePermissions permissions, DisguisePerm disguisePerm,
|
||||
Collection<String> usedOptions) throws DisguiseParseException {
|
||||
|
||||
|
@@ -0,0 +1,14 @@
|
||||
package me.libraryaddict.disguise.utilities.parser;
|
||||
|
||||
import java.lang.annotation.ElementType;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
|
||||
/**
|
||||
* Created by libraryaddict on 31/12/2019.
|
||||
*/
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@Target(ElementType.METHOD)
|
||||
public @interface RandomDefaultValue {
|
||||
}
|
@@ -77,6 +77,8 @@ public abstract class ParamInfo {
|
||||
|
||||
protected abstract Object fromString(String string) throws DisguiseParseException;
|
||||
|
||||
public abstract String toString(Object object);
|
||||
|
||||
public Object fromString(List<String> arguments) throws DisguiseParseException {
|
||||
// Don't consume a string immediately, if it errors we need to check other param types
|
||||
String string = arguments.get(0);
|
||||
@@ -101,7 +103,7 @@ public abstract class ParamInfo {
|
||||
return getValues() != null;
|
||||
}
|
||||
|
||||
private Class getParamClass() {
|
||||
protected Class getParamClass() {
|
||||
return paramClass;
|
||||
}
|
||||
|
||||
|
@@ -105,8 +105,8 @@ public class ParamInfoManager {
|
||||
});
|
||||
|
||||
// Add these last as it's what we want to present to be called the least
|
||||
for (String methodName : new String[]{"setViewSelfDisguise", "setHideHeldItemFromSelf", "setHideArmorFromSelf",
|
||||
"setHearSelfDisguise", "setHidePlayer", "setExpires"}) {
|
||||
for (String methodName : new String[]{"setSelfDisguiseVisible", "setHideHeldItemFromSelf",
|
||||
"setHideArmorFromSelf", "setHearSelfDisguise", "setHidePlayer", "setExpires"}) {
|
||||
try {
|
||||
methods.add(Disguise.class
|
||||
.getMethod(methodName, methodName.equals("setExpires") ? long.class : boolean.class));
|
||||
|
@@ -107,9 +107,9 @@ public class ParamInfoTypes {
|
||||
return paramInfos;
|
||||
}
|
||||
|
||||
private Map<String, Object> getColors() {
|
||||
private Map<String, Color> getColors() {
|
||||
try {
|
||||
Map<String, Object> map = new HashMap<>();
|
||||
Map<String, Color> map = new HashMap<>();
|
||||
Class cl = Class.forName("org.bukkit.Color");
|
||||
|
||||
for (Field field : cl.getFields()) {
|
||||
@@ -117,7 +117,7 @@ public class ParamInfoTypes {
|
||||
continue;
|
||||
}
|
||||
|
||||
map.put(field.getName(), field.get(null));
|
||||
map.put(field.getName(), (Color) field.get(null));
|
||||
}
|
||||
|
||||
return map;
|
||||
|
@@ -21,7 +21,7 @@ public class ParamInfoEnum extends ParamInfo {
|
||||
super(paramClass, name, name, description, possibleValues);
|
||||
}
|
||||
|
||||
public ParamInfoEnum(Class paramClass, String name, String description, Map<String,Object> possibleValues) {
|
||||
public ParamInfoEnum(Class paramClass, String name, String description, Map<String, Object> possibleValues) {
|
||||
super(paramClass, name, name, description, possibleValues);
|
||||
}
|
||||
|
||||
@@ -39,4 +39,9 @@ public class ParamInfoEnum extends ParamInfo {
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString(Object object) {
|
||||
return object.toString();
|
||||
}
|
||||
}
|
||||
|
@@ -42,6 +42,11 @@ public class ParamInfoBoolean extends ParamInfo {
|
||||
throw new IllegalStateException("This shouldn't be called");
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString(Object object) {
|
||||
return object.toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMinArguments() {
|
||||
return 0;
|
||||
|
@@ -19,4 +19,9 @@ public class ParamInfoDouble extends ParamInfo {
|
||||
protected Object fromString(String string) {
|
||||
return Double.parseDouble(string);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString(Object object) {
|
||||
return object.toString();
|
||||
}
|
||||
}
|
||||
|
@@ -19,4 +19,9 @@ public class ParamInfoFloat extends ParamInfo {
|
||||
protected Object fromString(String string) {
|
||||
return Float.parseFloat(string);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString(Object object) {
|
||||
return object.toString();
|
||||
}
|
||||
}
|
||||
|
@@ -19,4 +19,9 @@ public class ParamInfoInteger extends ParamInfo {
|
||||
protected Object fromString(String string) {
|
||||
return Integer.parseInt(string);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString(Object object) {
|
||||
return object.toString();
|
||||
}
|
||||
}
|
||||
|
@@ -15,4 +15,9 @@ public class ParamInfoString extends ParamInfo {
|
||||
protected Object fromString(String string) {
|
||||
return ChatColor.translateAlternateColorCodes('&', string);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString(Object object) {
|
||||
return object.toString();
|
||||
}
|
||||
}
|
||||
|
@@ -21,4 +21,11 @@ public class ParamInfoBlockPosition extends ParamInfo {
|
||||
|
||||
return new BlockPosition(Integer.parseInt(split[0]), Integer.parseInt(split[1]), Integer.parseInt(split[2]));
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString(Object object) {
|
||||
BlockPosition position = (BlockPosition) object;
|
||||
|
||||
return String.format("%s,%s,%s", position.getX(), position.getY(), position.getZ());
|
||||
}
|
||||
}
|
||||
|
@@ -9,23 +9,23 @@ import java.util.Map;
|
||||
* Created by libraryaddict on 19/09/2018.
|
||||
*/
|
||||
public class ParamInfoColor extends ParamInfoEnum {
|
||||
private static Map<String, Object> staticColors;
|
||||
private static Map<String, Color> staticColors;
|
||||
|
||||
public ParamInfoColor(Class paramClass, String name, String description, Map<String, Object> possibleValues) {
|
||||
public ParamInfoColor(Class paramClass, String name, String description, Map possibleValues) {
|
||||
super(paramClass, name, description, possibleValues);
|
||||
|
||||
staticColors = possibleValues;
|
||||
staticColors = (Map<String, Color>) possibleValues;
|
||||
}
|
||||
|
||||
protected static Color parseToColor(String string) {
|
||||
protected Color parseToColor(String string) {
|
||||
string = string.replace("_", "");
|
||||
|
||||
for (Map.Entry<String, Object> entry : staticColors.entrySet()) {
|
||||
for (Map.Entry<String, Color> entry : staticColors.entrySet()) {
|
||||
if (!entry.getKey().replace("_", "").equalsIgnoreCase(string)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
return (Color) entry.getValue();
|
||||
return entry.getValue();
|
||||
}
|
||||
|
||||
String[] split = string.split(",");
|
||||
@@ -39,6 +39,23 @@ public class ParamInfoColor extends ParamInfoEnum {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString(Object object) {
|
||||
Color color = (Color) object;
|
||||
|
||||
if (staticColors.containsValue(color)) {
|
||||
for (String key : staticColors.keySet()) {
|
||||
if (staticColors.get(key) != color) {
|
||||
continue;
|
||||
}
|
||||
|
||||
return key;
|
||||
}
|
||||
}
|
||||
|
||||
return String.format("%s,%s,%s", color.getRed(), color.getGreen(), color.getBlue());
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Object fromString(String string) {
|
||||
return parseToColor(string);
|
||||
|
@@ -21,4 +21,11 @@ public class ParamInfoEulerAngle extends ParamInfo {
|
||||
|
||||
return new EulerAngle(Double.parseDouble(split[0]), Double.parseDouble(split[1]), Double.parseDouble(split[2]));
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString(Object object) {
|
||||
EulerAngle angle = (EulerAngle) object;
|
||||
|
||||
return String.format("%s,%s,%s", angle.getX(), angle.getY(), angle.getZ());
|
||||
}
|
||||
}
|
||||
|
@@ -1,11 +1,11 @@
|
||||
package me.libraryaddict.disguise.utilities.parser.params.types.custom;
|
||||
|
||||
import com.comphenix.protocol.wrappers.WrappedGameProfile;
|
||||
import com.google.gson.Gson;
|
||||
import com.mojang.authlib.GameProfile;
|
||||
import me.libraryaddict.disguise.utilities.DisguiseUtilities;
|
||||
import me.libraryaddict.disguise.utilities.parser.params.ParamInfo;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
|
||||
/**
|
||||
* Created by libraryaddict on 7/09/2018.
|
||||
*/
|
||||
@@ -15,7 +15,12 @@ public class ParamInfoGameProfile extends ParamInfo {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Object fromString( String string) {
|
||||
protected Object fromString(String string) {
|
||||
return DisguiseUtilities.getGson().fromJson(string, WrappedGameProfile.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString(Object object) {
|
||||
return DisguiseUtilities.getGson().toJson(((WrappedGameProfile) object).getHandle(), GameProfile.class);
|
||||
}
|
||||
}
|
||||
|
@@ -1,10 +1,12 @@
|
||||
package me.libraryaddict.disguise.utilities.parser.params.types.custom;
|
||||
|
||||
import me.libraryaddict.disguise.utilities.DisguiseUtilities;
|
||||
import me.libraryaddict.disguise.utilities.translations.TranslateType;
|
||||
import me.libraryaddict.disguise.utilities.parser.params.types.ParamInfoEnum;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.enchantments.Enchantment;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.ItemMeta;
|
||||
|
||||
/**
|
||||
* Created by libraryaddict on 7/09/2018.
|
||||
@@ -32,7 +34,20 @@ public class ParamInfoItemStack extends ParamInfoEnum {
|
||||
return parseToItemstack(string);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString(Object object) {
|
||||
return DisguiseUtilities.getGson().toJson(object);
|
||||
}
|
||||
|
||||
protected static ItemStack parseToItemstack(String string) {
|
||||
if (string.startsWith("{") && string.endsWith("}")) {
|
||||
try {
|
||||
return DisguiseUtilities.getGson().fromJson(string, ItemStack.class);
|
||||
}
|
||||
catch (Exception ex) {
|
||||
}
|
||||
}
|
||||
|
||||
return parseToItemstack(string.split("[:,]")); // Split on colon or comma
|
||||
}
|
||||
|
||||
@@ -70,4 +85,8 @@ public class ParamInfoItemStack extends ParamInfoEnum {
|
||||
|
||||
return itemStack;
|
||||
}
|
||||
|
||||
public boolean isParam(Class paramClass) {
|
||||
return getParamClass().isAssignableFrom(paramClass);
|
||||
}
|
||||
}
|
||||
|
@@ -1,5 +1,6 @@
|
||||
package me.libraryaddict.disguise.utilities.parser.params.types.custom;
|
||||
|
||||
import me.libraryaddict.disguise.utilities.DisguiseUtilities;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import java.util.LinkedHashSet;
|
||||
@@ -36,8 +37,21 @@ public class ParamInfoItemStackArray extends ParamInfoItemStack {
|
||||
return toReturn;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString(Object object) {
|
||||
return DisguiseUtilities.getGson().toJson(object);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object fromString(String string) {
|
||||
if (string.startsWith("{") && string.endsWith("}")) {
|
||||
try {
|
||||
return DisguiseUtilities.getGson().fromJson(string, ItemStack[].class);
|
||||
}
|
||||
catch (Exception ex) {
|
||||
}
|
||||
}
|
||||
|
||||
String[] split = string.split(",", -1);
|
||||
|
||||
if (split.length != 4) {
|
||||
|
@@ -2,13 +2,15 @@ package me.libraryaddict.disguise.utilities.parser.params.types.custom;
|
||||
|
||||
import com.comphenix.protocol.wrappers.WrappedBlockData;
|
||||
import com.comphenix.protocol.wrappers.WrappedParticle;
|
||||
import me.libraryaddict.disguise.utilities.translations.LibsMsg;
|
||||
import me.libraryaddict.disguise.utilities.parser.DisguiseParseException;
|
||||
import me.libraryaddict.disguise.utilities.parser.params.ParamInfoManager;
|
||||
import me.libraryaddict.disguise.utilities.parser.params.types.ParamInfoEnum;
|
||||
import me.libraryaddict.disguise.utilities.translations.LibsMsg;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.bukkit.Color;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.Particle;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.HashSet;
|
||||
@@ -57,6 +59,32 @@ public class ParamInfoParticle extends ParamInfoEnum {
|
||||
return enums;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString(Object object) {
|
||||
WrappedParticle particle = (WrappedParticle) object;
|
||||
|
||||
Object data = particle.getData();
|
||||
String returns = particle.getParticle().name();
|
||||
|
||||
if (data != null) {
|
||||
if (data instanceof ItemStack) {
|
||||
returns += "," + ((ItemStack) data).getType().name();
|
||||
} else if (data instanceof WrappedBlockData) {
|
||||
|
||||
returns += "," + ((WrappedBlockData) data).getType().name();
|
||||
} else if (data instanceof Particle.DustOptions) {
|
||||
returns += "," +
|
||||
ParamInfoManager.getParamInfo(Color.class).toString(((Particle.DustOptions) data).getColor());
|
||||
|
||||
if (((Particle.DustOptions) data).getSize() != 1f) {
|
||||
returns += "," + ((Particle.DustOptions) data).getSize();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return returns;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object fromString(String string) throws DisguiseParseException {
|
||||
String[] split = string.split("[:,]"); // Split on comma or colon
|
||||
@@ -99,7 +127,7 @@ public class ParamInfoParticle extends ParamInfoEnum {
|
||||
throw new DisguiseParseException(LibsMsg.PARSE_PARTICLE_REDSTONE, particle.name(), string);
|
||||
}
|
||||
|
||||
Color color = ParamInfoColor.parseToColor(
|
||||
Color color = ((ParamInfoColor) ParamInfoManager.getParamInfo(Color.class)).parseToColor(
|
||||
StringUtils.join(Arrays.copyOfRange(split, 1, split.length - (split.length % 2)), ","));
|
||||
|
||||
if (color == null) {
|
||||
|
@@ -15,6 +15,10 @@ public class ParamInfoTime extends ParamInfo {
|
||||
|
||||
@Override
|
||||
protected Object fromString(String string) throws DisguiseParseException {
|
||||
if (string.matches("[0-9]{13,}")) {
|
||||
return Long.parseLong(string);
|
||||
}
|
||||
|
||||
long time = DisguiseParser.parseStringToTime(string);
|
||||
|
||||
// If disguise expires X ticks afterwards
|
||||
@@ -27,4 +31,9 @@ public class ParamInfoTime extends ParamInfo {
|
||||
|
||||
return time;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString(Object object) {
|
||||
return object.toString();
|
||||
}
|
||||
}
|
||||
|
@@ -650,6 +650,9 @@ public class ReflectionManager {
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the UUID of the player, as well as properly capitalized playername
|
||||
*/
|
||||
public static WrappedGameProfile grabProfileAddUUID(String playername) {
|
||||
try {
|
||||
Object minecraftServer = getMinecraftServer();
|
||||
|
Reference in New Issue
Block a user