Made it compatible with old npc files
This commit is contained in:
parent
33e79e8543
commit
d9ed69eecd
4 changed files with 23 additions and 6 deletions
|
@ -7,6 +7,7 @@ import lol.pyr.znpcsplus.skin.descriptor.NameFetchingDescriptor;
|
||||||
import lol.pyr.znpcsplus.skin.descriptor.MirrorDescriptor;
|
import lol.pyr.znpcsplus.skin.descriptor.MirrorDescriptor;
|
||||||
import lol.pyr.znpcsplus.skin.descriptor.PrefetchedDescriptor;
|
import lol.pyr.znpcsplus.skin.descriptor.PrefetchedDescriptor;
|
||||||
import lol.pyr.znpcsplus.skin.descriptor.UUIDFetchingDescriptor;
|
import lol.pyr.znpcsplus.skin.descriptor.UUIDFetchingDescriptor;
|
||||||
|
import lol.pyr.znpcsplus.util.UUIDUtil;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
@ -24,10 +25,10 @@ public interface BaseSkinDescriptor extends SkinDescriptor {
|
||||||
static BaseSkinDescriptor deserialize(MojangSkinCache skinCache, String str) {
|
static BaseSkinDescriptor deserialize(MojangSkinCache skinCache, String str) {
|
||||||
String[] arr = str.split(";");
|
String[] arr = str.split(";");
|
||||||
if (arr[0].equalsIgnoreCase("mirror")) return new MirrorDescriptor(skinCache);
|
if (arr[0].equalsIgnoreCase("mirror")) return new MirrorDescriptor(skinCache);
|
||||||
else if (arr[0].equalsIgnoreCase("fetching-name"))
|
else if (arr[0].equalsIgnoreCase("fetching")) {
|
||||||
return new NameFetchingDescriptor(skinCache, String.join(";", Arrays.copyOfRange(arr, 1, arr.length)));
|
String value = String.join(";", Arrays.copyOfRange(arr, 1, arr.length));
|
||||||
else if(arr[0].equalsIgnoreCase("fetching-uuid"))
|
return UUIDUtil.isUUID(value) ? new UUIDFetchingDescriptor(skinCache, UUID.fromString(value)) : new NameFetchingDescriptor(skinCache, value);
|
||||||
return new UUIDFetchingDescriptor(skinCache, UUID.fromString(String.join(";", Arrays.copyOfRange(arr, 1, arr.length))));
|
}
|
||||||
else if (arr[0].equalsIgnoreCase("prefetched")) {
|
else if (arr[0].equalsIgnoreCase("prefetched")) {
|
||||||
List<TextureProperty> properties = new ArrayList<>();
|
List<TextureProperty> properties = new ArrayList<>();
|
||||||
for (int i = 0; i < (arr.length - 1) / 3; i++) {
|
for (int i = 0; i < (arr.length - 1) / 3; i++) {
|
||||||
|
|
|
@ -39,6 +39,6 @@ public class NameFetchingDescriptor implements BaseSkinDescriptor, SkinDescripto
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String serialize() {
|
public String serialize() {
|
||||||
return "fetching-name;" + name;
|
return "fetching;" + name;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -36,7 +36,7 @@ public class UUIDFetchingDescriptor implements BaseSkinDescriptor, SkinDescripto
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String serialize() {
|
public String serialize() {
|
||||||
return "fetching-uuid;" + uuid.toString();
|
return "fetching;" + uuid.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
16
plugin/src/main/java/lol/pyr/znpcsplus/util/UUIDUtil.java
Normal file
16
plugin/src/main/java/lol/pyr/znpcsplus/util/UUIDUtil.java
Normal file
|
@ -0,0 +1,16 @@
|
||||||
|
package lol.pyr.znpcsplus.util;
|
||||||
|
|
||||||
|
|
||||||
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
|
public final class UUIDUtil {
|
||||||
|
|
||||||
|
|
||||||
|
public final static Pattern UUID_REGEX =
|
||||||
|
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]{12}$");
|
||||||
|
|
||||||
|
public static boolean isUUID(String uuid) {
|
||||||
|
return UUID_REGEX.matcher(uuid).matches();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Loading…
Reference in a new issue