use of skinsrestorer.shared.utils.MojangAPI.SkinRequestException in project SkinsRestorerX by DoNotSpamPls.
the class SkinsRestorer method onEnable.
@Override
public void onEnable() {
@SuppressWarnings("unused") MetricsLite metrics = new MetricsLite(this);
instance = this;
Config.load(getResourceAsStream("config.yml"));
Locale.load();
if (Config.USE_MYSQL) {
SkinStorage.init(mysql = new MySQL(Config.MYSQL_HOST, Config.MYSQL_PORT, Config.MYSQL_DATABASE, Config.MYSQL_USERNAME, Config.MYSQL_PASSWORD));
} else {
SkinStorage.init(getDataFolder());
}
getProxy().getPluginManager().registerListener(this, new LoginListener());
getProxy().getPluginManager().registerCommand(this, new AdminCommands());
getProxy().getPluginManager().registerCommand(this, new PlayerCommands());
getProxy().registerChannel("SkinsRestorer");
SkinApplier.init();
multibungee = Config.MULTIBUNGEE_ENABLED || ProxyServer.getInstance().getPluginManager().getPlugin("RedisBungee") != null;
ProxyServer.getInstance().getScheduler().runAsync(SkinsRestorer.getInstance(), () -> {
CommandSender console = getProxy().getConsole();
if (Config.UPDATER_ENABLED)
if (checkVersion(console).equals(getVersion())) {
outdated = false;
console.sendMessage(new TextComponent("§e[§2SkinsRestorer§e] §a----------------------------------------------"));
console.sendMessage(new TextComponent("§e[§2SkinsRestorer§e] §a +===============+"));
console.sendMessage(new TextComponent("§e[§2SkinsRestorer§e] §a | SkinsRestorer |"));
console.sendMessage(new TextComponent("§e[§2SkinsRestorer§e] §a +===============+"));
console.sendMessage(new TextComponent("§e[§2SkinsRestorer§e] §a----------------------------------------------"));
console.sendMessage(new TextComponent("§e[§2SkinsRestorer§e] §b Current version: §a" + getVersion()));
console.sendMessage(new TextComponent("§e[§2SkinsRestorer§e] §a This is the latest version!"));
console.sendMessage(new TextComponent("§e[§2SkinsRestorer§e] §a----------------------------------------------"));
} else {
outdated = true;
console.sendMessage(new TextComponent("§e[§2SkinsRestorer§e] §a----------------------------------------------"));
console.sendMessage(new TextComponent("§e[§2SkinsRestorer§e] §a +===============+"));
console.sendMessage(new TextComponent("§e[§2SkinsRestorer§e] §a | SkinsRestorer |"));
console.sendMessage(new TextComponent("§e[§2SkinsRestorer§e] §a +===============+"));
console.sendMessage(new TextComponent("§e[§2SkinsRestorer§e] §a----------------------------------------------"));
console.sendMessage(new TextComponent("§e[§2SkinsRestorer§e] §b Current version: §c" + getVersion()));
console.sendMessage(new TextComponent("§e[§2SkinsRestorer§e] §e A new version is available! Download it at:"));
console.sendMessage(new TextComponent("§e[§2SkinsRestorer§e] §e https://www.spigotmc.org/resources/skinsrestorer.2124"));
console.sendMessage(new TextComponent("§e[§2SkinsRestorer§e] §a----------------------------------------------"));
}
if (Config.DEFAULT_SKINS_ENABLED)
for (String skin : Config.DEFAULT_SKINS) try {
SkinStorage.setSkinData(skin, MojangAPI.getSkinProperty(MojangAPI.getUUID(skin)));
} catch (SkinRequestException e) {
if (SkinStorage.getSkinData(skin) == null)
console.sendMessage(new TextComponent("§e[§2SkinsRestorer§e] §cDefault Skin '" + skin + "' request error:" + e.getReason()));
}
});
}
use of skinsrestorer.shared.utils.MojangAPI.SkinRequestException in project SkinsRestorerX by DoNotSpamPls.
the class PlayerCommands method execute.
public void execute(CommandSender sender, final String[] args) {
if (!(sender instanceof ProxiedPlayer)) {
sender.sendMessage(new TextComponent(Locale.NOT_PLAYER));
return;
}
final ProxiedPlayer p = (ProxiedPlayer) sender;
// Skin Help
if (args.length == 0 || args.length > 2) {
if (!Config.SKINWITHOUTPERM) {
if (p.hasPermission("skinsrestorer.playercmds")) {
help(p);
} else {
p.sendMessage(new TextComponent(Locale.PLAYER_HAS_NO_PERMISSION));
}
} else {
help(p);
}
}
// Skin Clear and Skin (name)
if (args.length == 1) {
if (args[0].equalsIgnoreCase("clear")) {
CooldownStorage.resetCooldown(p.getName());
CooldownStorage.setCooldown(p.getName(), Config.SKIN_CHANGE_COOLDOWN, TimeUnit.SECONDS);
ProxyServer.getInstance().getScheduler().runAsync(SkinsRestorer.getInstance(), () -> {
SkinStorage.removePlayerSkin(p.getName());
SkinStorage.setPlayerSkin(p.getName(), p.getName());
SkinApplier.applySkin(p);
p.sendMessage(new TextComponent(Locale.SKIN_CLEAR_SUCCESS));
});
} else {
// skin <skin>
final String skin = args[0];
if (Config.DISABLED_SKINS_ENABLED)
if (!p.hasPermission("skinsrestorer.bypassdisabled")) {
for (String dskin : Config.DISABLED_SKINS) if (skin.equalsIgnoreCase(dskin)) {
p.sendMessage(new TextComponent(Locale.SKIN_DISABLED));
return;
}
}
if (!p.hasPermission("skinsrestorer.bypasscooldown") && CooldownStorage.hasCooldown(p.getName())) {
p.sendMessage(new TextComponent(Locale.SKIN_COOLDOWN_NEW.replace("%s", "" + CooldownStorage.getCooldown(p.getName()))));
return;
}
CooldownStorage.resetCooldown(p.getName());
CooldownStorage.setCooldown(p.getName(), Config.SKIN_CHANGE_COOLDOWN, TimeUnit.SECONDS);
ProxyServer.getInstance().getScheduler().runAsync(SkinsRestorer.getInstance(), () -> {
try {
MojangAPI.getUUID(skin);
SkinStorage.setPlayerSkin(p.getName(), skin);
SkinApplier.applySkin(p);
p.sendMessage(new TextComponent(Locale.SKIN_CHANGE_SUCCESS));
} catch (SkinRequestException e) {
p.sendMessage(new TextComponent(e.getReason()));
}
});
return;
}
}
// skin set
if (args.length == 2) {
if (args[0].equalsIgnoreCase("set")) {
final String skin = args[1];
if (Config.DISABLED_SKINS_ENABLED)
if (!p.hasPermission("skinsrestorer.bypassdisabled")) {
for (String dskin : Config.DISABLED_SKINS) if (skin.equalsIgnoreCase(dskin)) {
p.sendMessage(new TextComponent(Locale.SKIN_DISABLED));
return;
}
}
if (!p.hasPermission("skinsrestorer.bypasscooldown") && CooldownStorage.hasCooldown(p.getName())) {
p.sendMessage(new TextComponent(Locale.SKIN_COOLDOWN_NEW.replace("%s", "" + CooldownStorage.getCooldown(p.getName()))));
return;
}
CooldownStorage.resetCooldown(p.getName());
CooldownStorage.setCooldown(p.getName(), Config.SKIN_CHANGE_COOLDOWN, TimeUnit.SECONDS);
ProxyServer.getInstance().getScheduler().runAsync(SkinsRestorer.getInstance(), () -> {
try {
MojangAPI.getUUID(skin);
SkinStorage.setPlayerSkin(p.getName(), skin);
SkinApplier.applySkin(p);
p.sendMessage(new TextComponent(Locale.SKIN_CHANGE_SUCCESS));
} catch (SkinRequestException e) {
p.sendMessage(new TextComponent(e.getReason()));
}
});
} else {
help(p);
}
}
}
use of skinsrestorer.shared.utils.MojangAPI.SkinRequestException in project SkinsRestorerX by DoNotSpamPls.
the class SkinStorage method getOrCreateSkinForPlayer.
/**
* This methods seeks out players actual skin (chosen or not) and returns
* either null (if no skin data found) or the property object conatining all
* the skin data.
* <p>
* Also, it schedules a skin update to stay up to date with skin changes.
*
* @return Property object
*/
public static Object getOrCreateSkinForPlayer(final String name) throws SkinRequestException {
String skin = getPlayerSkin(name);
if (skin == null)
skin = name.toLowerCase();
Object textures;
if (Config.DEFAULT_SKINS_ENABLED) {
getSkinData(Config.DEFAULT_SKINS.get(new Random().nextInt(Config.DEFAULT_SKINS.size())));
}
textures = getSkinData(skin);
if (textures != null) {
return textures;
}
// Schedule skin update for next login
final String sname = skin;
final Object oldprops = null;
try {
Object props;
props = MojangAPI.getSkinProperty(MojangAPI.getUUID(sname));
if (props == null)
return null;
boolean shouldUpdate;
String value = Base64Coder.decodeString((String) ReflectionUtil.invokeMethod(props, "getValue"));
String urlbeg = "url\":\"";
String urlend = "\"}}";
String newurl = MojangAPI.getStringBetween(value, urlbeg, urlend);
try {
assert false;
value = Base64Coder.decodeString((String) ReflectionUtil.invokeMethod(props, "getValue"));
String oldurl = MojangAPI.getStringBetween(value, urlbeg, urlend);
shouldUpdate = !oldurl.equals(newurl);
} catch (Exception e) {
shouldUpdate = true;
}
setSkinData(sname, props);
if (shouldUpdate)
if (isBungee)
skinsrestorer.bungee.SkinApplier.applySkin(name);
else {
SkinsRestorer.getInstance().getFactory().applySkin(org.bukkit.Bukkit.getPlayer(name), props);
}
} catch (Exception e) {
throw new SkinRequestException(Locale.WAIT_A_MINUTE);
}
return textures;
}
use of skinsrestorer.shared.utils.MojangAPI.SkinRequestException in project SkinsRestorerX by DoNotSpamPls.
the class SkinCommand method onCommand.
public boolean onCommand(CommandSender sender, Command arg1, String arg2, String[] args) {
if (!(sender instanceof Player)) {
sender.sendMessage(Locale.NOT_PLAYER);
return true;
}
final Player p = (Player) sender;
// Skin Help
if (args.length == 0 || args.length > 2) {
if (Config.SKINWITHOUTPERM) {
p.sendMessage(Locale.SR_LINE);
p.sendMessage(Locale.HELP_PLAYER.replace("%ver%", SkinsRestorer.getInstance().getVersion()));
if (p.hasPermission("skinsrestorer.cmds"))
p.sendMessage(Locale.HELP_SR);
p.sendMessage(Locale.SR_LINE);
} else {
if (p.hasPermission("skinsrestorer.playercmds")) {
p.sendMessage(Locale.SR_LINE);
p.sendMessage(Locale.HELP_PLAYER.replace("%ver%", SkinsRestorer.getInstance().getVersion()));
if (p.hasPermission("skinsrestorer.cmds"))
p.sendMessage(Locale.HELP_SR);
p.sendMessage(Locale.SR_LINE);
} else {
p.sendMessage(Locale.PLAYER_HAS_NO_PERMISSION);
}
}
}
// Skin Clear and Skin (name)
if (args.length == 1) {
if (args[0].equalsIgnoreCase("clear")) {
if (sender.hasPermission("skinsrestorer.playercmds")) {
Object props;
SkinStorage.removePlayerSkin(p.getName());
props = SkinStorage.createProperty("textures", "", "");
SkinsRestorer.getInstance().getFactory().applySkin(p, props);
SkinsRestorer.getInstance().getFactory().updateSkin(p);
p.sendMessage(Locale.SKIN_CLEAR_SUCCESS);
return true;
} else {
p.sendMessage(Locale.PLAYER_HAS_NO_PERMISSION);
return false;
}
} else {
if (sender.hasPermission("skinsrestorer.playercmds")) {
final String skin = args[0];
if (Config.DISABLED_SKINS_ENABLED)
if (!p.hasPermission("skinsrestorer.bypassdisabled")) {
for (String dskin : Config.DISABLED_SKINS) if (skin.equalsIgnoreCase(dskin)) {
p.sendMessage(Locale.SKIN_DISABLED);
return true;
}
}
if (p.hasPermission("skinsrestorer.bypasscooldown")) {
return false;
} else {
if (CooldownStorage.hasCooldown(p.getName())) {
p.sendMessage(Locale.SKIN_COOLDOWN_NEW.replace("%s", "" + CooldownStorage.getCooldown(p.getName())));
return true;
}
}
CooldownStorage.resetCooldown(p.getName());
CooldownStorage.setCooldown(p.getName(), Config.SKIN_CHANGE_COOLDOWN, TimeUnit.SECONDS);
Bukkit.getScheduler().runTaskAsynchronously(SkinsRestorer.getInstance(), () -> {
try {
MojangAPI.getUUID(skin);
SkinStorage.setPlayerSkin(p.getName(), skin);
SkinsRestorer.getInstance().getFactory().applySkin(p, SkinStorage.getOrCreateSkinForPlayer(p.getName()));
p.sendMessage(Locale.SKIN_CHANGE_SUCCESS);
} catch (SkinRequestException e) {
p.sendMessage(e.getReason());
}
});
return true;
} else {
p.sendMessage(Locale.PLAYER_HAS_NO_PERMISSION);
return false;
}
}
}
// Skin Set
if (args.length == 2) {
if (args[0].equalsIgnoreCase("set")) {
if (sender.hasPermission("skinsrestorer.playercmds")) {
final String skin = args[1];
if (Config.DISABLED_SKINS_ENABLED)
if (!p.hasPermission("skinsrestorer.bypassdisabled")) {
for (String dskin : Config.DISABLED_SKINS) if (skin.equalsIgnoreCase(dskin)) {
p.sendMessage(Locale.SKIN_DISABLED);
return true;
}
}
if (p.hasPermission("skinsrestorer.bypasscooldown")) {
return false;
} else {
if (CooldownStorage.hasCooldown(p.getName())) {
p.sendMessage(Locale.SKIN_COOLDOWN_NEW.replace("%s", "" + CooldownStorage.getCooldown(p.getName())));
return true;
}
}
CooldownStorage.resetCooldown(p.getName());
CooldownStorage.setCooldown(p.getName(), Config.SKIN_CHANGE_COOLDOWN, TimeUnit.SECONDS);
Bukkit.getScheduler().runTaskAsynchronously(SkinsRestorer.getInstance(), () -> {
try {
MojangAPI.getUUID(skin);
SkinStorage.setPlayerSkin(p.getName(), skin);
SkinsRestorer.getInstance().getFactory().applySkin(p, SkinStorage.getOrCreateSkinForPlayer(p.getName()));
p.sendMessage(Locale.SKIN_CHANGE_SUCCESS);
} catch (SkinRequestException e) {
p.sendMessage(e.getReason());
}
});
return true;
} else {
p.sendMessage(Locale.PLAYER_HAS_NO_PERMISSION);
return false;
}
} else {
if (Config.SKINWITHOUTPERM) {
p.sendMessage(Locale.SR_LINE);
p.sendMessage(Locale.HELP_PLAYER.replace("%ver%", SkinsRestorer.getInstance().getVersion()));
if (p.hasPermission("skinsrestorer.cmds"))
p.sendMessage(Locale.HELP_SR);
p.sendMessage(Locale.SR_LINE);
} else {
if (p.hasPermission("skinsrestorer.playercmds")) {
p.sendMessage(Locale.SR_LINE);
p.sendMessage(Locale.HELP_PLAYER.replace("%ver%", SkinsRestorer.getInstance().getVersion()));
if (p.hasPermission("skinsrestorer.cmds"))
p.sendMessage(Locale.HELP_SR);
p.sendMessage(Locale.SR_LINE);
} else {
p.sendMessage(Locale.PLAYER_HAS_NO_PERMISSION);
}
}
return true;
}
}
return true;
}
use of skinsrestorer.shared.utils.MojangAPI.SkinRequestException in project SkinsRestorerX by DoNotSpamPls.
the class SrCommand method onCommand.
@Override
public boolean onCommand(final CommandSender sender, Command arg1, String arg2, String[] args) {
if (sender.hasPermission("skinsrestorer.cmds")) {
if (args.length == 0) {
sender.sendMessage(Locale.SR_LINE);
sender.sendMessage(Locale.HELP_ADMIN.replace("%ver%", SkinsRestorer.getInstance().getVersion()));
sender.sendMessage(Locale.SR_LINE);
} else if (args.length > 2 && args[0].equalsIgnoreCase("set")) {
StringBuilder sb = new StringBuilder();
for (int i = 2; i < args.length; i++) if (args.length == 3)
sb.append(args[i]);
else if (i + 1 == args.length)
sb.append(args[i]);
else
sb.append(args[i]).append(" ");
final String skin = sb.toString();
Player player = Bukkit.getPlayer(args[1]);
if (player == null)
for (Player pl : Bukkit.getOnlinePlayers()) if (pl.getName().startsWith(args[1])) {
player = pl;
break;
}
if (player == null) {
sender.sendMessage(Locale.NOT_ONLINE);
return true;
}
final Player p = player;
Bukkit.getScheduler().runTaskAsynchronously(SkinsRestorer.getInstance(), () -> {
try {
MojangAPI.getUUID(skin);
SkinStorage.setPlayerSkin(p.getName(), skin);
SkinsRestorer.getInstance().getFactory().applySkin(p, SkinStorage.getOrCreateSkinForPlayer(p.getName()));
sender.sendMessage(Locale.SKIN_CHANGE_SUCCESS);
} catch (SkinRequestException e) {
sender.sendMessage(e.getReason());
}
});
} else if (args.length == 1 && args[0].equalsIgnoreCase("reload")) {
Locale.load();
Config.load(SkinsRestorer.getInstance().getResource("config.yml"));
sender.sendMessage(Locale.RELOAD);
} else if (args.length == 1 && args[0].equalsIgnoreCase("config")) {
sender.sendMessage("§e[§2SkinsRestorer§e] §2/sr config has been removed from SkinsRestorer. Farewell!");
} else if (args.length == 1 && args[0].equalsIgnoreCase("status")) {
try {
MojangAPI.getSkinProperty(MojangAPI.getUUID("Notch"));
sender.sendMessage(Locale.STATUS_OK);
} catch (SkinRequestException e) {
sender.sendMessage(e.getReason());
}
} else if (args.length > 1 && args[0].equalsIgnoreCase("drop")) {
StringBuilder sb = new StringBuilder();
for (int i = 1; i < args.length; i++) sb.append(args[i]);
SkinStorage.removeSkinData(sb.toString());
sender.sendMessage(Locale.SKIN_DATA_DROPPED.replace("%player", sb.toString()));
} else if (args[0].equalsIgnoreCase("props")) {
Player p;
if (args.length == 1) {
if (!(sender instanceof Player)) {
sender.sendMessage(Locale.NOT_PLAYER);
return true;
}
p = (Player) sender;
} else {
StringBuilder name = new StringBuilder();
for (int i = 1; i < args.length; i++) if (args.length == 2)
name.append(args[i]);
else if (i + 1 == args.length)
name.append(args[i]);
else
name.append(args[i]).append(" ");
p = Bukkit.getPlayer(name.toString());
if (p == null) {
sender.sendMessage(Locale.NOT_ONLINE);
return true;
}
}
try {
Object ep = ReflectionUtil.invokeMethod(p, "getHandle");
Object profile = ReflectionUtil.invokeMethod(ep, "getProfile");
Object propmap = ReflectionUtil.invokeMethod(profile, "getProperties");
Collection<?> props = (Collection<?>) ReflectionUtil.invokeMethod(propmap.getClass(), propmap, "get", new Class[] { Object.class }, "textures");
if (props == null || props.isEmpty()) {
sender.sendMessage(Locale.NO_SKIN_DATA);
return true;
}
for (Object prop : props) {
String name = (String) ReflectionUtil.invokeMethod(prop, "getName");
String value = (String) ReflectionUtil.invokeMethod(prop, "getValue");
String signature = (String) ReflectionUtil.invokeMethod(prop, "getSignature");
ConsoleCommandSender cons = Bukkit.getConsoleSender();
cons.sendMessage("\n§aName: §8" + name);
cons.sendMessage("\n§aValue : §8" + value);
cons.sendMessage("\n§aSignature : §8" + signature);
byte[] decoded = Base64.getDecoder().decode(value);
cons.sendMessage("\n§aValue Decoded: §e" + Arrays.toString(decoded));
sender.sendMessage("\n§e" + Arrays.toString(decoded));
sender.sendMessage("§cMore info in console!");
}
} catch (Exception e) {
e.printStackTrace();
sender.sendMessage(Locale.NO_SKIN_DATA);
return true;
}
sender.sendMessage("§cMore info in console!");
}
} else {
sender.sendMessage(Locale.PLAYER_HAS_NO_PERMISSION);
return true;
}
return true;
}
Aggregations