Should be private
This commit is contained in:
		| @@ -13,6 +13,7 @@ import me.libraryaddict.disguise.utilities.reflection.NmsVersion; | |||||||
| import me.libraryaddict.disguise.utilities.reflection.ReflectionManager; | import me.libraryaddict.disguise.utilities.reflection.ReflectionManager; | ||||||
| import me.libraryaddict.disguise.utilities.translations.LibsMsg; | import me.libraryaddict.disguise.utilities.translations.LibsMsg; | ||||||
| import me.libraryaddict.disguise.utilities.translations.TranslateType; | import me.libraryaddict.disguise.utilities.translations.TranslateType; | ||||||
|  | import me.libraryaddict.disguise.utilities.watchers.DisguiseMethods; | ||||||
| import org.bukkit.Bukkit; | import org.bukkit.Bukkit; | ||||||
| import org.bukkit.Material; | import org.bukkit.Material; | ||||||
| import org.bukkit.block.data.BlockData; | import org.bukkit.block.data.BlockData; | ||||||
| @@ -149,10 +150,14 @@ public class DisguiseParser { | |||||||
|         return parseToString(disguise, true); |         return parseToString(disguise, true); | ||||||
|     } |     } | ||||||
|  |  | ||||||
|  |     public static String parseToString(Disguise disguise, boolean outputSkinData) { | ||||||
|  |         return parseToString(disguise, outputSkinData, false); | ||||||
|  |     } | ||||||
|  |  | ||||||
|     /** |     /** | ||||||
|      * Not outputting skin information is not garanteed to display the correct player name |      * Not outputting skin information is not garanteed to display the correct player name | ||||||
|      */ |      */ | ||||||
|     public static String parseToString(Disguise disguise, boolean outputSkinData) { |     public static String parseToString(Disguise disguise, boolean outputSkinData, boolean includeCustomData) { | ||||||
|         try { |         try { | ||||||
|             StringBuilder stringBuilder = new StringBuilder(); |             StringBuilder stringBuilder = new StringBuilder(); | ||||||
|  |  | ||||||
| @@ -244,6 +249,40 @@ public class DisguiseParser { | |||||||
|                 stringBuilder.append(" ").append(valueString); |                 stringBuilder.append(" ").append(valueString); | ||||||
|             } |             } | ||||||
|  |  | ||||||
|  |             if (includeCustomData) { | ||||||
|  |                 LinkedHashMap<String, Object> meta = disguise.getCustomData(); | ||||||
|  |                 LinkedHashMap<String, String> serializedMeta = new LinkedHashMap<>(); | ||||||
|  |  | ||||||
|  |                 for (Entry<String, Object> entry : meta.entrySet()) { | ||||||
|  |                     Object val = entry.getValue(); | ||||||
|  |  | ||||||
|  |                     try { | ||||||
|  |                         if (val == null) { | ||||||
|  |                             serializedMeta.put(entry.getKey(), "null"); | ||||||
|  |                             continue; | ||||||
|  |                         } | ||||||
|  |  | ||||||
|  |                         String serialized = DisguiseUtilities.getGson().toJson(val); | ||||||
|  |  | ||||||
|  |                         serializedMeta.put(entry.getKey(), val.getClass().getName() + ":" + serialized); | ||||||
|  |                     } catch (Throwable throwable) { | ||||||
|  |                         DisguiseUtilities.getLogger() | ||||||
|  |                                 .warning("Unable to properly serialize the metadata on a disguise, the metadata was saved under name '" + entry.getKey() + "'"); | ||||||
|  |  | ||||||
|  |                         if (!(throwable instanceof StackOverflowError)) { | ||||||
|  |                             throwable.printStackTrace(); | ||||||
|  |                         } | ||||||
|  |                         continue; | ||||||
|  |                     } | ||||||
|  |                 } | ||||||
|  |  | ||||||
|  |                 if (!serializedMeta.isEmpty()) { | ||||||
|  |                     String serialized = DisguiseUtilities.getGson().toJson(serializedMeta); | ||||||
|  |  | ||||||
|  |                     stringBuilder.append(" ").append("setCustomData").append(" ").append(DisguiseUtilities.quote(serialized)); | ||||||
|  |                 } | ||||||
|  |             } | ||||||
|  |  | ||||||
|             return stringBuilder.toString(); |             return stringBuilder.toString(); | ||||||
|         } catch (Throwable e) { |         } catch (Throwable e) { | ||||||
|             e.printStackTrace(); |             e.printStackTrace(); | ||||||
| @@ -914,6 +953,28 @@ public class DisguiseParser { | |||||||
|             Object valueToSet = null; |             Object valueToSet = null; | ||||||
|             DisguiseParseException parseException = null; |             DisguiseParseException parseException = null; | ||||||
|  |  | ||||||
|  |             if (!list.isEmpty() && methodNameProvided.equalsIgnoreCase("setCustomData") && (sender == null || sender.isOp())) { | ||||||
|  |                 argIndex++; | ||||||
|  |                 String data = list.remove(0); | ||||||
|  |                 Map<String, String> deserial = DisguiseUtilities.getGson().fromJson(data, LinkedHashMap.class); | ||||||
|  |  | ||||||
|  |                 for (Entry<String, String> entry : deserial.entrySet()) { | ||||||
|  |                     String val = entry.getValue(); | ||||||
|  |  | ||||||
|  |                     if (!val.contains(":")) { | ||||||
|  |                         disguise.addCustomData(entry.getKey(), null); | ||||||
|  |                         continue; | ||||||
|  |                     } | ||||||
|  |  | ||||||
|  |                     String className = val.substring(0, val.indexOf(":")); | ||||||
|  |                     val = val.substring(className.length() + 1); | ||||||
|  |  | ||||||
|  |                     disguise.addCustomData(entry.getKey(), DisguiseUtilities.getGson().fromJson(val, DisguiseMethods.parseType(className))); | ||||||
|  |                 } | ||||||
|  |  | ||||||
|  |                 continue; | ||||||
|  |             } | ||||||
|  |  | ||||||
|             for (WatcherMethod method : methods) { |             for (WatcherMethod method : methods) { | ||||||
|                 if (!method.getName().equalsIgnoreCase(methodNameJava)) { |                 if (!method.getName().equalsIgnoreCase(methodNameJava)) { | ||||||
|                     continue; |                     continue; | ||||||
|   | |||||||
| @@ -17,7 +17,7 @@ public class WatcherInfo { | |||||||
|     private String watcher; |     private String watcher; | ||||||
|     private String method; |     private String method; | ||||||
|     private String param; |     private String param; | ||||||
|     String descriptor; |     private String descriptor; | ||||||
|  |  | ||||||
|     public boolean isSupported() { |     public boolean isSupported() { | ||||||
|         if (getAdded() >= 0 && added > ReflectionManager.getVersion().ordinal()) { |         if (getAdded() >= 0 && added > ReflectionManager.getVersion().ordinal()) { | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user