Merge pull request #2896 from owlnull/v3.0
Add skins support via SkinsRestorer plugin
This commit is contained in:
commit
f151cdc84f
8 changed files with 121 additions and 15 deletions
|
|
@ -105,6 +105,7 @@ import org.dynmap.renderer.DynmapBlockState;
|
|||
import org.dynmap.utils.MapChunkCache;
|
||||
import org.dynmap.utils.Polygon;
|
||||
import org.dynmap.utils.VisibilityLimit;
|
||||
import skinsrestorer.bukkit.SkinsRestorer;
|
||||
|
||||
public class DynmapPlugin extends JavaPlugin implements DynmapAPI {
|
||||
private DynmapCore core;
|
||||
|
|
@ -896,6 +897,23 @@ public class DynmapPlugin extends JavaPlugin implements DynmapAPI {
|
|||
this.setEnabled(false);
|
||||
return;
|
||||
}
|
||||
|
||||
/* Skins support via SkinsRestorer */
|
||||
SkinsRestorerSkinUrlProvider skinUrlProvider = null;
|
||||
|
||||
if (core.configuration.getBoolean("skinsrestorer-integration", false)) {
|
||||
SkinsRestorer skinsRestorer = (SkinsRestorer) getServer().getPluginManager().getPlugin("SkinsRestorer");
|
||||
|
||||
if (skinsRestorer == null) {
|
||||
Log.warning("SkinsRestorer integration can't be enabled because SkinsRestorer not installed");
|
||||
} else {
|
||||
skinUrlProvider = new SkinsRestorerSkinUrlProvider(skinsRestorer);
|
||||
Log.info("SkinsRestorer integration enabled");
|
||||
}
|
||||
}
|
||||
|
||||
core.setSkinUrlProvider(skinUrlProvider);
|
||||
|
||||
/* See if we need to wait before enabling core */
|
||||
if(!readyToEnable()) {
|
||||
Listener pl = new Listener() {
|
||||
|
|
|
|||
|
|
@ -0,0 +1,62 @@
|
|||
package org.dynmap.bukkit;
|
||||
|
||||
import org.dynmap.SkinUrlProvider;
|
||||
import org.json.simple.parser.JSONParser;
|
||||
import org.json.simple.parser.ParseException;
|
||||
import org.json.simple.JSONObject;
|
||||
import skinsrestorer.bukkit.SkinsRestorer;
|
||||
import skinsrestorer.bukkit.SkinsRestorerBukkitAPI;
|
||||
import skinsrestorer.shared.utils.ReflectionUtil;
|
||||
|
||||
import java.net.MalformedURLException;
|
||||
import java.net.URL;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.Base64;
|
||||
|
||||
public class SkinsRestorerSkinUrlProvider implements SkinUrlProvider {
|
||||
private JSONParser mJsonParser;
|
||||
private SkinsRestorerBukkitAPI mSkinsRestorerApi;
|
||||
|
||||
SkinsRestorerSkinUrlProvider(SkinsRestorer skinsRestorer) {
|
||||
mJsonParser = new JSONParser();
|
||||
mSkinsRestorerApi = skinsRestorer.getSkinsRestorerBukkitAPI();
|
||||
}
|
||||
|
||||
@Override
|
||||
public URL getSkinUrl(String playerName) {
|
||||
String skinName = mSkinsRestorerApi.getSkinName(playerName);
|
||||
|
||||
Object skinDataProperty = mSkinsRestorerApi.getSkinData(skinName == null ? playerName : skinName);
|
||||
|
||||
if (skinDataProperty == null)
|
||||
return null;
|
||||
|
||||
String skinDataPropertyValue;
|
||||
|
||||
try {
|
||||
skinDataPropertyValue = (String) ReflectionUtil.invokeMethod(skinDataProperty, "getValue");
|
||||
} catch (Exception ex) {
|
||||
ex.printStackTrace();
|
||||
return null;
|
||||
}
|
||||
|
||||
byte[] skinDataBytes = Base64.getDecoder().decode(skinDataPropertyValue);
|
||||
|
||||
JSONObject skinData;
|
||||
|
||||
try {
|
||||
skinData = (JSONObject) mJsonParser.parse(new String(skinDataBytes, StandardCharsets.UTF_8));
|
||||
} catch (ParseException ex) {
|
||||
ex.printStackTrace();
|
||||
return null;
|
||||
}
|
||||
|
||||
try {
|
||||
return new URL((String) ((JSONObject) ((JSONObject) skinData.get("textures")).get("SKIN")).get("url"));
|
||||
} catch (MalformedURLException ex) {
|
||||
ex.printStackTrace();
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue