mirror of
https://github.com/libraryaddict/LibsDisguises.git
synced 2024-12-14 15:26:54 +01:00
Fix player disguises setSkin
This commit is contained in:
parent
11781fbb1f
commit
af886f3af9
@ -86,7 +86,6 @@ public class DisguisePlayerCommand extends DisguiseBaseCommand implements TabCom
|
||||
|
||||
if (DisguiseConfig.isNameOfPlayerShownAboveDisguise()) {
|
||||
if (disguise.getWatcher() instanceof LivingWatcher) {
|
||||
|
||||
disguise.getWatcher().setCustomName(player.getDisplayName());
|
||||
|
||||
if (DisguiseConfig.isNameAboveHeadAlwaysVisible()) {
|
||||
|
@ -8,11 +8,14 @@ import com.comphenix.protocol.wrappers.EnumWrappers.PlayerInfoAction;
|
||||
import com.comphenix.protocol.wrappers.PlayerInfoData;
|
||||
import com.comphenix.protocol.wrappers.WrappedChatComponent;
|
||||
import com.comphenix.protocol.wrappers.WrappedGameProfile;
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.GsonBuilder;
|
||||
import me.libraryaddict.disguise.LibsDisguises;
|
||||
import me.libraryaddict.disguise.disguisetypes.watchers.PlayerWatcher;
|
||||
import me.libraryaddict.disguise.utilities.DisguiseUtilities;
|
||||
import me.libraryaddict.disguise.utilities.LibsProfileLookup;
|
||||
import me.libraryaddict.disguise.utilities.ReflectionManager;
|
||||
import me.libraryaddict.disguise.utilities.json.SerializerGameProfile;
|
||||
import org.apache.commons.lang.Validate;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Entity;
|
||||
@ -99,8 +102,8 @@ public class PlayerDisguise extends TargetedDisguise {
|
||||
|
||||
if (currentLookup == null && gameProfile != null) {
|
||||
disguise.skinToUse = getSkin();
|
||||
disguise.gameProfile = ReflectionManager.getGameProfileWithThisSkin(disguise.uuid,
|
||||
getGameProfile().getName(), getGameProfile());
|
||||
disguise.gameProfile = ReflectionManager
|
||||
.getGameProfileWithThisSkin(disguise.uuid, getGameProfile().getName(), getGameProfile());
|
||||
} else {
|
||||
disguise.setSkin(getSkin());
|
||||
}
|
||||
@ -127,8 +130,8 @@ public class PlayerDisguise extends TargetedDisguise {
|
||||
if (getSkin() != null) {
|
||||
gameProfile = ReflectionManager.getGameProfile(uuid, getName());
|
||||
} else {
|
||||
gameProfile = ReflectionManager.getGameProfileWithThisSkin(uuid, getName(),
|
||||
DisguiseUtilities.getProfileFromMojang(this));
|
||||
gameProfile = ReflectionManager
|
||||
.getGameProfileWithThisSkin(uuid, getName(), DisguiseUtilities.getProfileFromMojang(this));
|
||||
}
|
||||
}
|
||||
|
||||
@ -252,11 +255,11 @@ public class PlayerDisguise extends TargetedDisguise {
|
||||
public PlayerDisguise setSkin(String newSkin) {
|
||||
if (newSkin != null && newSkin.length() > 50) {
|
||||
try {
|
||||
return setSkin(ReflectionManager.parseGameProfile(newSkin));
|
||||
return setSkin(DisguiseUtilities.getGson().fromJson(newSkin, WrappedGameProfile.class));
|
||||
}
|
||||
catch (Exception ex) {
|
||||
throw new IllegalArgumentException(
|
||||
"The skin is too long to be a playername, but cannot be parsed to a GameProfile!");
|
||||
catch (Exception ex) {ex.printStackTrace();
|
||||
throw new IllegalArgumentException(String.format(
|
||||
"The skin %s is too long to be a playername, but cannot be parsed to a GameProfile!", newSkin));
|
||||
}
|
||||
}
|
||||
|
||||
@ -293,6 +296,9 @@ public class PlayerDisguise extends TargetedDisguise {
|
||||
|
||||
this.skinToUse = gameProfile.getName();
|
||||
this.gameProfile = ReflectionManager.getGameProfileWithThisSkin(uuid, getName(), gameProfile);
|
||||
System.out.println(
|
||||
new GsonBuilder().registerTypeAdapter(WrappedGameProfile.class, new SerializerGameProfile()).create()
|
||||
.toJson(gameProfile));
|
||||
|
||||
if (DisguiseUtilities.isDisguiseInUse(this)) {
|
||||
if (isDisplayedInTab()) {
|
||||
|
@ -6,7 +6,9 @@ import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map.Entry;
|
||||
|
||||
import com.google.gson.GsonBuilder;
|
||||
import com.mojang.authlib.GameProfile;
|
||||
import me.libraryaddict.disguise.utilities.json.SerializerGameProfile;
|
||||
import org.bukkit.Art;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.Material;
|
||||
@ -701,7 +703,7 @@ public class DisguiseParser {
|
||||
}
|
||||
} else if (WrappedGameProfile.class == param && valueString.length() > 20) {
|
||||
try {
|
||||
value = ReflectionManager.parseGameProfile(valueString);
|
||||
value = DisguiseUtilities.getGson().fromJson(valueString, WrappedGameProfile.class);
|
||||
}
|
||||
catch (Exception ex) {
|
||||
throw parseToException(WrappedGameProfile.class, valueString, methodName);
|
||||
|
@ -815,6 +815,10 @@ public class DisguiseUtilities {
|
||||
return selfDisguised;
|
||||
}
|
||||
|
||||
public static Gson getGson() {
|
||||
return gson;
|
||||
}
|
||||
|
||||
public static void init(LibsDisguises disguises) {
|
||||
libsDisguises = disguises;
|
||||
methods = BackwardsSupport.getMethods();
|
||||
|
@ -77,33 +77,6 @@ public class ReflectionManager {
|
||||
entityCountField.setAccessible(true);
|
||||
}
|
||||
|
||||
public static WrappedGameProfile parseGameProfile(String toParse) {
|
||||
Map<String, Object> response = new Gson().fromJson(toParse, Map.class);
|
||||
|
||||
String id = (String) response.get("id");
|
||||
|
||||
if (!id.contains("-")) {
|
||||
id = Pattern.compile("([0-9a-fA-F]{8})([0-9a-fA-F]{4})([0-9a-fA-F]{4})([0-9a-fA-F]{4})([0-9a-fA-F]+)")
|
||||
.matcher(id).replaceFirst("$1-$2-$3-$4-$5");
|
||||
}
|
||||
|
||||
WrappedGameProfile gameProfile = new WrappedGameProfile(UUID.fromString(id), (String) response.get("name"));
|
||||
|
||||
if (response.containsKey("properties")) {
|
||||
ArrayList<Map<String, String>> properties = (ArrayList) response.get("properties");
|
||||
|
||||
for (Map<String, String> s : properties) {
|
||||
String gName = s.containsKey("name") ? s.get("name") : null;
|
||||
String gValue = s.containsKey("value") ? s.get("value") : null;
|
||||
String gSigned = s.containsKey("signature") ? s.get("signature") : null;
|
||||
|
||||
gameProfile.getProperties().put(gName, new WrappedSignedProperty(gName, gValue, gSigned));
|
||||
}
|
||||
}
|
||||
|
||||
return gameProfile;
|
||||
}
|
||||
|
||||
public static Object createEntityInstance(String entityName) {
|
||||
try {
|
||||
Class<?> entityClass = getNmsClass("Entity" + entityName);
|
||||
|
@ -5,6 +5,8 @@ import com.google.gson.*;
|
||||
import com.mojang.authlib.GameProfile;
|
||||
|
||||
import java.lang.reflect.Type;
|
||||
import java.util.HashMap;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
/**
|
||||
* Created by libraryaddict on 1/06/2017.
|
||||
@ -19,6 +21,14 @@ public class SerializerGameProfile implements JsonSerializer<WrappedGameProfile>
|
||||
@Override
|
||||
public WrappedGameProfile deserialize(JsonElement json, Type typeOfT,
|
||||
JsonDeserializationContext context) throws JsonParseException {
|
||||
JsonObject obj = json.getAsJsonObject();
|
||||
|
||||
if (obj.has("id") && !obj.get("id").getAsString().contains("-")) {
|
||||
obj.addProperty("id",
|
||||
Pattern.compile("([0-9a-fA-F]{8})([0-9a-fA-F]{4})([0-9a-fA-F]{4})([0-9a-fA-F]{4})([0-9a-fA-F]+)")
|
||||
.matcher(obj.get("id").getAsString()).replaceFirst("$1-$2-$3-$4-$5"));
|
||||
}
|
||||
|
||||
return WrappedGameProfile.fromHandle(context.deserialize(json, GameProfile.class));
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user