mirror of
https://github.com/CitizensDev/Citizens2.git
synced 2025-02-28 10:12:14 +01:00
A bugfix and some debug output for skins
This commit is contained in:
parent
7a37058ff1
commit
4e00828a89
@ -2,6 +2,7 @@ package net.citizensnpcs.npc.entity;
|
|||||||
|
|
||||||
import java.lang.reflect.Method;
|
import java.lang.reflect.Method;
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
|
import java.util.Iterator;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
import java.util.concurrent.BlockingDeque;
|
import java.util.concurrent.BlockingDeque;
|
||||||
@ -13,6 +14,7 @@ import net.citizensnpcs.api.CitizensAPI;
|
|||||||
import net.citizensnpcs.api.event.DespawnReason;
|
import net.citizensnpcs.api.event.DespawnReason;
|
||||||
import net.citizensnpcs.api.npc.NPC;
|
import net.citizensnpcs.api.npc.NPC;
|
||||||
import net.citizensnpcs.api.util.Colorizer;
|
import net.citizensnpcs.api.util.Colorizer;
|
||||||
|
import net.citizensnpcs.api.util.Messaging;
|
||||||
import net.citizensnpcs.npc.AbstractEntityController;
|
import net.citizensnpcs.npc.AbstractEntityController;
|
||||||
import net.citizensnpcs.util.NMS;
|
import net.citizensnpcs.util.NMS;
|
||||||
import net.minecraft.server.v1_7_R4.PlayerInteractManager;
|
import net.minecraft.server.v1_7_R4.PlayerInteractManager;
|
||||||
@ -122,8 +124,8 @@ public class HumanController extends AbstractEntityController {
|
|||||||
private GameProfile fillProfileProperties(YggdrasilAuthenticationService auth, GameProfile profile,
|
private GameProfile fillProfileProperties(YggdrasilAuthenticationService auth, GameProfile profile,
|
||||||
boolean requireSecure) throws Exception {
|
boolean requireSecure) throws Exception {
|
||||||
URL url = HttpAuthenticationService.constantURL(new StringBuilder()
|
URL url = HttpAuthenticationService.constantURL(new StringBuilder()
|
||||||
.append("https://sessionserver.mojang.com/session/minecraft/profile/")
|
.append("https://sessionserver.mojang.com/session/minecraft/profile/")
|
||||||
.append(UUIDTypeAdapter.fromUUID(profile.getId())).toString());
|
.append(UUIDTypeAdapter.fromUUID(profile.getId())).toString());
|
||||||
url = HttpAuthenticationService.concatenateURL(url,
|
url = HttpAuthenticationService.concatenateURL(url,
|
||||||
new StringBuilder().append("unsigned=").append(!requireSecure).toString());
|
new StringBuilder().append("unsigned=").append(!requireSecure).toString());
|
||||||
MinecraftProfilePropertiesResponse response = (MinecraftProfilePropertiesResponse) MAKE_REQUEST.invoke(
|
MinecraftProfilePropertiesResponse response = (MinecraftProfilePropertiesResponse) MAKE_REQUEST.invoke(
|
||||||
@ -148,6 +150,10 @@ public class HumanController extends AbstractEntityController {
|
|||||||
GameProfile skinProfile = null;
|
GameProfile skinProfile = null;
|
||||||
Property cached = TEXTURE_CACHE.get(realUUID);
|
Property cached = TEXTURE_CACHE.get(realUUID);
|
||||||
if (cached != null) {
|
if (cached != null) {
|
||||||
|
if (Messaging.isDebugging()) {
|
||||||
|
Messaging
|
||||||
|
.debug("Using cached skin texture for NPC " + npc.getName() + " UUID " + npc.getUniqueId());
|
||||||
|
}
|
||||||
skinProfile = new GameProfile(UUID.fromString(realUUID), "");
|
skinProfile = new GameProfile(UUID.fromString(realUUID), "");
|
||||||
skinProfile.getProperties().put("textures", cached);
|
skinProfile.getProperties().put("textures", cached);
|
||||||
} else {
|
} else {
|
||||||
@ -168,6 +174,11 @@ public class HumanController extends AbstractEntityController {
|
|||||||
Property textures = Iterables.getFirst(skinProfile.getProperties().get("textures"), null);
|
Property textures = Iterables.getFirst(skinProfile.getProperties().get("textures"), null);
|
||||||
if (textures.getValue() == null || textures.getSignature() == null)
|
if (textures.getValue() == null || textures.getSignature() == null)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
if (Messaging.isDebugging()) {
|
||||||
|
Messaging.debug("Fetched skin texture for UUID " + realUUID + " for NPC " + npc.getName()
|
||||||
|
+ " UUID " + npc.getUniqueId());
|
||||||
|
}
|
||||||
TEXTURE_CACHE.put(realUUID, new Property("textures", textures.getValue(), textures.getSignature()));
|
TEXTURE_CACHE.put(realUUID, new Property("textures", textures.getValue(), textures.getSignature()));
|
||||||
}
|
}
|
||||||
Bukkit.getScheduler().callSyncMethod(CitizensAPI.getPlugin(), new Callable<Void>() {
|
Bukkit.getScheduler().callSyncMethod(CitizensAPI.getPlugin(), new Callable<Void>() {
|
||||||
@ -188,6 +199,12 @@ public class HumanController extends AbstractEntityController {
|
|||||||
private final BlockingDeque<Runnable> tasks = new LinkedBlockingDeque<Runnable>();
|
private final BlockingDeque<Runnable> tasks = new LinkedBlockingDeque<Runnable>();
|
||||||
|
|
||||||
public void addRunnable(Runnable r) {
|
public void addRunnable(Runnable r) {
|
||||||
|
Iterator<Runnable> itr = tasks.iterator();
|
||||||
|
while (itr.hasNext()) {
|
||||||
|
if (((SkinFetcher) itr.next()).npc.getUniqueId().equals(((SkinFetcher) r).npc.getUniqueId())) {
|
||||||
|
itr.remove();
|
||||||
|
}
|
||||||
|
}
|
||||||
tasks.offer(r);
|
tasks.offer(r);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -233,18 +250,22 @@ public class HumanController extends AbstractEntityController {
|
|||||||
.getGameProfileRepository();
|
.getGameProfileRepository();
|
||||||
repo.findProfilesByNames(new String[] { ChatColor.stripColor(reportedUUID) }, Agent.MINECRAFT,
|
repo.findProfilesByNames(new String[] { ChatColor.stripColor(reportedUUID) }, Agent.MINECRAFT,
|
||||||
new ProfileLookupCallback() {
|
new ProfileLookupCallback() {
|
||||||
@Override
|
@Override
|
||||||
public void onProfileLookupFailed(GameProfile arg0, Exception arg1) {
|
public void onProfileLookupFailed(GameProfile arg0, Exception arg1) {
|
||||||
throw new RuntimeException(arg1);
|
throw new RuntimeException(arg1);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onProfileLookupSucceeded(final GameProfile profile) {
|
public void onProfileLookupSucceeded(final GameProfile profile) {
|
||||||
UUID_CACHE.put(reportedUUID, profile.getId().toString());
|
UUID_CACHE.put(reportedUUID, profile.getId().toString());
|
||||||
npc.data().setPersistent(CACHED_SKIN_UUID_METADATA, profile.getId().toString());
|
if (Messaging.isDebugging()) {
|
||||||
npc.data().setPersistent(CACHED_SKIN_UUID_NAME_METADATA, profile.getName());
|
Messaging.debug("Fetched UUID " + profile.getId() + " for NPC " + npc.getName()
|
||||||
}
|
+ " UUID " + npc.getUniqueId());
|
||||||
});
|
}
|
||||||
|
npc.data().setPersistent(CACHED_SKIN_UUID_METADATA, profile.getId().toString());
|
||||||
|
npc.data().setPersistent(CACHED_SKIN_UUID_NAME_METADATA, profile.getName());
|
||||||
|
}
|
||||||
|
});
|
||||||
return npc.data().get(CACHED_SKIN_UUID_METADATA, reportedUUID);
|
return npc.data().get(CACHED_SKIN_UUID_METADATA, reportedUUID);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user