Skip to content

Commit 13a52d5

Browse files
authored
Merge pull request #108 from caucow/master
Fix NMS skin lookup lag (by ripkilling the Future so they don't happen)
2 parents 9761c67 + 54633ac commit 13a52d5

1 file changed

Lines changed: 24 additions & 3 deletions

File tree

src/main/java/vg/civcraft/mc/civmodcore/util/SkinCache.java

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ public SkinData load(UUID uuid) throws Exception {
6767
if (profile.hasTextures()) {
6868
return new SkinData(profile);
6969
}
70-
throw new Exception("Could not complete() PlayerProfile for " + uuid + " (rate limited or profile doesn't exist)");
70+
throw new SkinLoadException("Could not complete() PlayerProfile for " + uuid + " (rate limited or profile doesn't exist)");
7171
}
7272
});
7373
this.futureCache = CacheBuilder.newBuilder()
@@ -78,8 +78,23 @@ public CompletableFuture<SkinData> load(UUID uuid) throws Exception {
7878
return CompletableFuture.supplyAsync(() -> {
7979
try {
8080
return skinCache.get(uuid);
81-
} catch (Exception e) {
82-
return new SkinData(Bukkit.createProfile(uuid));
81+
} catch (Exception ex) {
82+
// This was causing "issues" with nms querying
83+
// the skin server. Just going to log the
84+
// exception now I guess
85+
// return new SkinData(Bukkit.createProfile(uuid));
86+
if (ex instanceof SkinLoadException) {
87+
plugin.getLogger().log(Level.WARNING, "Exception loading skin: " + ex.getMessage());
88+
} else {
89+
plugin.getLogger().log(Level.WARNING, "Exception loading skin", ex);
90+
}
91+
// also complete exceptionally to cancel later
92+
// CompletionStages
93+
if (ex instanceof RuntimeException) {
94+
throw (RuntimeException) ex;
95+
} else {
96+
throw new RuntimeException("Skin could not be loaded", ex);
97+
}
8398
}
8499
}, executor);
85100
}
@@ -170,4 +185,10 @@ public SkinData(PlayerProfile profile) {
170185
}
171186

172187
}
188+
189+
public static class SkinLoadException extends RuntimeException {
190+
public SkinLoadException(String message) {
191+
super(message);
192+
}
193+
}
173194
}

0 commit comments

Comments
 (0)