From 59712f98001751e0840d9240e19a52caf749a4b9 Mon Sep 17 00:00:00 2001 From: TheDutchMC Date: Thu, 13 Aug 2020 02:29:44 +0200 Subject: [PATCH] Everything update - Split the NMS classes into seperate Gradle submodules - Refactored the NMS classes to not depend on the 'core' - On join, players now get checked for if they're premium, if so, their normal skin will be set - package files renamed to fileHandlers - Think that's all? Anyway it works now --- Spigot_1_16_R1/build.gradle | 5 + .../ChangeGameProfile_1_16_r1.java | 37 ++----- Spigot_1_16_R2/build.gradle | 5 + .../ChangeGameProfile_1_16_r2.java | 50 ++++++++++ build.gradle | 21 ++-- settings.gradle | 11 +-- .../nl/thedutchmc/SkinFixer/JdaHandler.java | 2 +- .../nl/thedutchmc/SkinFixer/SkinFixer.java | 4 +- .../changeSkin/CheckUserAgainstMojang.java | 74 ++++++++++++++ .../SkinFixer/changeSkin/GetSkin.java | 30 ++++++ .../changeSkin/SkinChangeOrchestrator.java | 96 ++++++++++++------- .../changeGameProfile/ChangeGameProfile.java | 12 --- .../SetSkinCommandExecutor.java | 8 +- .../commonEventMethods/AddNewSkin.java | 2 +- .../ConfigurationHandler.java | 2 +- .../StorageHandler.java | 2 +- .../PlayerJoinEventListener.java | 37 ++++--- 17 files changed, 285 insertions(+), 113 deletions(-) create mode 100644 Spigot_1_16_R1/build.gradle rename {src => Spigot_1_16_R1/src}/main/java/nl/thedutchmc/SkinFixer/changeSkin/changeGameProfile/ChangeGameProfile_1_16_r1.java (59%) create mode 100644 Spigot_1_16_R2/build.gradle create mode 100644 Spigot_1_16_R2/src/main/java/nl/thedutchmc/SkinFixer/changeSkin/changeGameProfile/ChangeGameProfile_1_16_r2.java create mode 100644 src/main/java/nl/thedutchmc/SkinFixer/changeSkin/CheckUserAgainstMojang.java delete mode 100644 src/main/java/nl/thedutchmc/SkinFixer/changeSkin/changeGameProfile/ChangeGameProfile.java rename src/main/java/nl/thedutchmc/SkinFixer/{files => fileHandlers}/ConfigurationHandler.java (92%) rename src/main/java/nl/thedutchmc/SkinFixer/{files => fileHandlers}/StorageHandler.java (98%) diff --git a/Spigot_1_16_R1/build.gradle b/Spigot_1_16_R1/build.gradle new file mode 100644 index 0000000..09d3d84 --- /dev/null +++ b/Spigot_1_16_R1/build.gradle @@ -0,0 +1,5 @@ +apply plugin: 'java' +dependencies { + compileOnly 'org.spigotmc:spigot:1.16.1-R0.1-SNAPSHOT' +} + diff --git a/src/main/java/nl/thedutchmc/SkinFixer/changeSkin/changeGameProfile/ChangeGameProfile_1_16_r1.java b/Spigot_1_16_R1/src/main/java/nl/thedutchmc/SkinFixer/changeSkin/changeGameProfile/ChangeGameProfile_1_16_r1.java similarity index 59% rename from src/main/java/nl/thedutchmc/SkinFixer/changeSkin/changeGameProfile/ChangeGameProfile_1_16_r1.java rename to Spigot_1_16_R1/src/main/java/nl/thedutchmc/SkinFixer/changeSkin/changeGameProfile/ChangeGameProfile_1_16_r1.java index b887fe0..c6a326e 100644 --- a/src/main/java/nl/thedutchmc/SkinFixer/changeSkin/changeGameProfile/ChangeGameProfile_1_16_r1.java +++ b/Spigot_1_16_R1/src/main/java/nl/thedutchmc/SkinFixer/changeSkin/changeGameProfile/ChangeGameProfile_1_16_r1.java @@ -3,11 +3,8 @@ import java.util.UUID; import org.bukkit.Bukkit; -import org.bukkit.Location; -import org.bukkit.World; import org.bukkit.craftbukkit.v1_16_R1.entity.CraftPlayer; import org.bukkit.entity.Player; -import org.bukkit.scheduler.BukkitRunnable; import com.mojang.authlib.GameProfile; import com.mojang.authlib.properties.Property; @@ -16,12 +13,14 @@ import net.minecraft.server.v1_16_R1.EntityPlayer; import net.minecraft.server.v1_16_R1.PacketPlayOutPlayerInfo; import net.minecraft.server.v1_16_R1.PacketPlayOutPlayerInfo.EnumPlayerInfoAction; -import nl.thedutchmc.SkinFixer.SkinFixer; -public class ChangeGameProfile_1_16_r1 implements ChangeGameProfile { +/* It is normal for all net.minecraft.server and org.bukkit.craftbukkit imports + * to error when you are not working on that version. + * Gradle cannot handle multiple versions + */ +public class ChangeGameProfile_1_16_r1 { - @Override - public void changeProfile(UUID uuid, String skinValue, String skinSignature) { + public static void changeProfile(UUID uuid, String skinValue, String skinSignature) { Player player = Bukkit.getPlayer(uuid); //Fetch the EntityPlayer and their GameProfile @@ -40,38 +39,16 @@ public void changeProfile(UUID uuid, String skinValue, String skinSignature) { //Remove the old texture, and set the new one. pm.put("textures", new Property("textures", skinValue, skinSignature)); - //Reload the player for all online players - for(Player p : Bukkit.getOnlinePlayers()) { - p.hidePlayer(SkinFixer.INSTANCE, player); - p.showPlayer(SkinFixer.INSTANCE, player); - } - //Reload the skin for the player itself reloadSkinForSelf(player); } - @Override - public void reloadSkinForSelf(Player player) { + public static void reloadSkinForSelf(Player player) { final EntityPlayer ep = ((CraftPlayer) player).getHandle(); final PacketPlayOutPlayerInfo removeInfo = new PacketPlayOutPlayerInfo(EnumPlayerInfoAction.REMOVE_PLAYER, ep); final PacketPlayOutPlayerInfo addInfo = new PacketPlayOutPlayerInfo(EnumPlayerInfoAction.ADD_PLAYER, ep); - final Location loc = player.getLocation().clone(); ep.playerConnection.sendPacket(removeInfo); ep.playerConnection.sendPacket(addInfo); - - World teleportToWorld = null; - for(World w : Bukkit.getWorlds()) { - if(!w.equals(loc.getWorld())) teleportToWorld = w; - } - - player.teleport(new Location(teleportToWorld, 0, 255, 0)); - new BukkitRunnable() { - @Override - public void run() { - player.teleport(loc); - player.updateInventory(); - } - }.runTaskLater(SkinFixer.INSTANCE, 5L); } } diff --git a/Spigot_1_16_R2/build.gradle b/Spigot_1_16_R2/build.gradle new file mode 100644 index 0000000..3613e21 --- /dev/null +++ b/Spigot_1_16_R2/build.gradle @@ -0,0 +1,5 @@ +apply plugin: 'java' +dependencies { + compileOnly 'org.spigotmc:spigot:1.16.2-R0.1-SNAPSHOT' +} + diff --git a/Spigot_1_16_R2/src/main/java/nl/thedutchmc/SkinFixer/changeSkin/changeGameProfile/ChangeGameProfile_1_16_r2.java b/Spigot_1_16_R2/src/main/java/nl/thedutchmc/SkinFixer/changeSkin/changeGameProfile/ChangeGameProfile_1_16_r2.java new file mode 100644 index 0000000..dc8c77f --- /dev/null +++ b/Spigot_1_16_R2/src/main/java/nl/thedutchmc/SkinFixer/changeSkin/changeGameProfile/ChangeGameProfile_1_16_r2.java @@ -0,0 +1,50 @@ +package nl.thedutchmc.SkinFixer.changeSkin.changeGameProfile; + +import java.util.UUID; + +import org.bukkit.Bukkit; +import org.bukkit.craftbukkit.v1_16_R2.entity.CraftPlayer; +import org.bukkit.entity.Player; + +import com.mojang.authlib.GameProfile; +import com.mojang.authlib.properties.Property; +import com.mojang.authlib.properties.PropertyMap; + +import net.minecraft.server.v1_16_R2.EntityPlayer; +import net.minecraft.server.v1_16_R2.PacketPlayOutPlayerInfo; +import net.minecraft.server.v1_16_R2.PacketPlayOutPlayerInfo.EnumPlayerInfoAction; + +public class ChangeGameProfile_1_16_r2 { + + public static void changeProfile(UUID uuid, String skinValue, String skinSignature) { + Player player = Bukkit.getPlayer(uuid); + + //Fetch the EntityPlayer and their GameProfile + EntityPlayer ep = ((CraftPlayer)player).getHandle(); + GameProfile gp = ep.getProfile(); + + //Get the skin texture property + PropertyMap pm = gp.getProperties(); + + //Check if the propertyMap contains a texture value, if so, remove it. + if(pm.containsKey("textures")) { + Property property = pm.get("textures").iterator().next(); + pm.remove("textures", property); + } + + //Remove the old texture, and set the new one. + pm.put("textures", new Property("textures", skinValue, skinSignature)); + + //Reload the skin for the player itself + reloadSkinForSelf(player); + } + + public static void reloadSkinForSelf(Player player) { + final EntityPlayer ep = ((CraftPlayer) player).getHandle(); + final PacketPlayOutPlayerInfo removeInfo = new PacketPlayOutPlayerInfo(EnumPlayerInfoAction.REMOVE_PLAYER, ep); + final PacketPlayOutPlayerInfo addInfo = new PacketPlayOutPlayerInfo(EnumPlayerInfoAction.ADD_PLAYER, ep); + + ep.playerConnection.sendPacket(removeInfo); + ep.playerConnection.sendPacket(addInfo); + } +} diff --git a/build.gradle b/build.gradle index 18777da..7269830 100644 --- a/build.gradle +++ b/build.gradle @@ -4,7 +4,7 @@ import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar plugins { id 'java' id 'eclipse' - id 'com.github.johnrengelman.shadow' version '5.0.0' + id 'com.github.johnrengelman.shadow' version '5.0.0' } @@ -36,19 +36,26 @@ allprojects { } dependencies { - - compileOnly 'org.spigotmc:spigot:1.16.1-R0.1-SNAPSHOT' + //Apache HTTP Client compile 'org.apache.httpcomponents:httpclient:4.5.12' - compile 'org.json:json:20200518' + //JSON + compile 'org.json:json:20200518' - //JDA, for hooking into Discord + //JDA implementation ('net.dv8tion:JDA:4.2.0_168') { exclude module: 'opus-java' } + + //Spigot 1.16.1 + compileOnly 'org.spigotmc:spigot-api:1.16.1-R0.1-SNAPSHOT' + + //NMS classes + compile project('Spigot_1_16_R1') + compile project('Spigot_1_16_R2') } shadowJar() { - + classifier = '' relocate 'net.dv8tion.jda', 'nl.thedutchmc.libs.jda' -} \ No newline at end of file +} diff --git a/settings.gradle b/settings.gradle index 5d2776d..c886ec3 100644 --- a/settings.gradle +++ b/settings.gradle @@ -1,10 +1,3 @@ -/* - * This file was generated by the Gradle 'init' task. - * - * The settings file is used to specify which projects to include in your build. - * - * Detailed information about configuring a multi-project build in Gradle can be found - * in the user guide at https://docs.gradle.org/5.1.1/userguide/multi_project_builds.html - */ - rootProject.name = pluginName +include ':Spigot_1_16_R1' +include ':Spigot_1_16_R2' diff --git a/src/main/java/nl/thedutchmc/SkinFixer/JdaHandler.java b/src/main/java/nl/thedutchmc/SkinFixer/JdaHandler.java index 2fc8525..f5524d6 100644 --- a/src/main/java/nl/thedutchmc/SkinFixer/JdaHandler.java +++ b/src/main/java/nl/thedutchmc/SkinFixer/JdaHandler.java @@ -6,7 +6,7 @@ import net.dv8tion.jda.api.JDABuilder; import net.dv8tion.jda.api.entities.MessageChannel; import nl.thedutchmc.SkinFixer.discordEvents.MessageReceivedEventListener; -import nl.thedutchmc.SkinFixer.files.ConfigurationHandler; +import nl.thedutchmc.SkinFixer.fileHandlers.ConfigurationHandler; public class JdaHandler { diff --git a/src/main/java/nl/thedutchmc/SkinFixer/SkinFixer.java b/src/main/java/nl/thedutchmc/SkinFixer/SkinFixer.java index a07b49e..b92b351 100644 --- a/src/main/java/nl/thedutchmc/SkinFixer/SkinFixer.java +++ b/src/main/java/nl/thedutchmc/SkinFixer/SkinFixer.java @@ -6,8 +6,8 @@ import nl.thedutchmc.SkinFixer.commandHandlers.GetCodeCommandExecutor; import nl.thedutchmc.SkinFixer.commandHandlers.SetSkinCommandExecutor; import nl.thedutchmc.SkinFixer.commandHandlers.SkinFixerCommandExecutor; -import nl.thedutchmc.SkinFixer.files.ConfigurationHandler; -import nl.thedutchmc.SkinFixer.files.StorageHandler; +import nl.thedutchmc.SkinFixer.fileHandlers.ConfigurationHandler; +import nl.thedutchmc.SkinFixer.fileHandlers.StorageHandler; import nl.thedutchmc.SkinFixer.minecraftEvents.PlayerJoinEventListener; public class SkinFixer extends JavaPlugin { diff --git a/src/main/java/nl/thedutchmc/SkinFixer/changeSkin/CheckUserAgainstMojang.java b/src/main/java/nl/thedutchmc/SkinFixer/changeSkin/CheckUserAgainstMojang.java new file mode 100644 index 0000000..20a9177 --- /dev/null +++ b/src/main/java/nl/thedutchmc/SkinFixer/changeSkin/CheckUserAgainstMojang.java @@ -0,0 +1,74 @@ +package nl.thedutchmc.SkinFixer.changeSkin; + +import java.io.IOException; +import java.nio.charset.StandardCharsets; + +import org.apache.http.HttpEntity; +import org.apache.http.HttpResponse; +import org.apache.http.ParseException; +import org.apache.http.client.HttpClient; +import org.apache.http.client.methods.HttpPost; +import org.apache.http.entity.ContentType; +import org.apache.http.entity.StringEntity; +import org.apache.http.impl.client.HttpClients; +import org.apache.http.util.EntityUtils; +import org.json.JSONArray; +import org.json.JSONObject; +import org.json.JSONTokener; + +public class CheckUserAgainstMojang { + + public static String premiumUser(String playername) { + HttpClient httpClient = HttpClients.createDefault(); + HttpPost httpPost = new HttpPost("https://api.mojang.com/profiles/minecraft"); + + String jsonOut = "[\"" + playername + "\"]"; + + StringEntity requestEntity = new StringEntity( + jsonOut, + ContentType.APPLICATION_JSON); + + httpPost.setEntity(requestEntity); + + HttpResponse response = null; + try { + response = httpClient.execute(httpPost); + } catch (IOException e) { + e.printStackTrace(); + } + + HttpEntity entity = response.getEntity(); + + String json = ""; + try { + json = EntityUtils.toString(entity, StandardCharsets.UTF_8); + } catch (ParseException e) { + e.printStackTrace(); + } catch (IOException e) { + e.printStackTrace(); + } + + JSONTokener tokener = new JSONTokener(json); + JSONArray array = (JSONArray) tokener.nextValue(); + for(Object o : array) { + JSONObject jsonObj = (JSONObject) o; + String uuid = (String) jsonObj.getString("id"); + return insertDashUUID(uuid); + } + + return null; + } + + private static String insertDashUUID(String uuid) { + StringBuilder sb = new StringBuilder(uuid); + sb.insert(8, "-"); + sb = new StringBuilder(sb.toString()); + sb.insert(13, "-"); + sb = new StringBuilder(sb.toString()); + sb.insert(18, "-"); + sb = new StringBuilder(sb.toString()); + sb.insert(23, "-"); + + return sb.toString(); + } +} diff --git a/src/main/java/nl/thedutchmc/SkinFixer/changeSkin/GetSkin.java b/src/main/java/nl/thedutchmc/SkinFixer/changeSkin/GetSkin.java index d0ac0a8..91255b7 100644 --- a/src/main/java/nl/thedutchmc/SkinFixer/changeSkin/GetSkin.java +++ b/src/main/java/nl/thedutchmc/SkinFixer/changeSkin/GetSkin.java @@ -11,6 +11,7 @@ import org.apache.http.client.ClientProtocolException; import org.apache.http.client.HttpClient; import org.apache.http.client.entity.UrlEncodedFormEntity; +import org.apache.http.client.methods.HttpGet; import org.apache.http.client.methods.HttpPost; import org.apache.http.impl.client.HttpClients; import org.apache.http.message.BasicNameValuePair; @@ -58,4 +59,33 @@ public static String getSkin(String skinUrl, boolean slim) { return null; } + + public static String getSkinOfValidPlayer(String uuid) { + HttpClient httpclient = HttpClients.createDefault(); + HttpGet httpGet = new HttpGet("https://api.mineskin.org/generate/user/" + uuid); + + try { + //Execute and get the response. + HttpResponse response = httpclient.execute(httpGet); + Scanner sc = new Scanner(response.getEntity().getContent()); + + StringBuilder responseBuilder = new StringBuilder(); + + while(sc.hasNext()) { + responseBuilder.append(sc.next()); + } + + sc.close(); + return responseBuilder.toString(); + + } catch (UnsupportedEncodingException e) { + e.printStackTrace(); + } catch (ClientProtocolException e) { + e.printStackTrace(); + } catch (IOException e) { + e.printStackTrace(); + } + + return null; + } } diff --git a/src/main/java/nl/thedutchmc/SkinFixer/changeSkin/SkinChangeOrchestrator.java b/src/main/java/nl/thedutchmc/SkinFixer/changeSkin/SkinChangeOrchestrator.java index 7c8e6ef..2a8053d 100644 --- a/src/main/java/nl/thedutchmc/SkinFixer/changeSkin/SkinChangeOrchestrator.java +++ b/src/main/java/nl/thedutchmc/SkinFixer/changeSkin/SkinChangeOrchestrator.java @@ -3,6 +3,8 @@ import java.util.UUID; import org.bukkit.Bukkit; +import org.bukkit.Location; +import org.bukkit.World; import org.bukkit.entity.Player; import org.bukkit.scheduler.BukkitRunnable; import org.json.JSONObject; @@ -11,28 +13,33 @@ import net.md_5.bungee.api.ChatColor; import nl.thedutchmc.SkinFixer.SkinFixer; import nl.thedutchmc.SkinFixer.SkinObject; -import nl.thedutchmc.SkinFixer.changeSkin.changeGameProfile.ChangeGameProfile; import nl.thedutchmc.SkinFixer.changeSkin.changeGameProfile.ChangeGameProfile_1_16_r1; -import nl.thedutchmc.SkinFixer.files.StorageHandler; +import nl.thedutchmc.SkinFixer.changeSkin.changeGameProfile.ChangeGameProfile_1_16_r2; +import nl.thedutchmc.SkinFixer.fileHandlers.StorageHandler; public class SkinChangeOrchestrator { - - static ChangeGameProfile changeGameProfile; - public static void changeSkinJson(String skinUrl, UUID caller, boolean slim) { + public static void changeSkinJson(String skinUrl, UUID internalUuid, UUID externalUuid, boolean slim, boolean isPremium) { //Everything needs to be async, because the watchdog will kill the server because it takes too long new BukkitRunnable() { - - Player p = Bukkit.getPlayer(caller); - String value, signature; - - public void run() { - p.sendMessage(ChatColor.GOLD + "Fetching skin value and signature..."); + @Override + public void run() { + + Player player = Bukkit.getPlayer(internalUuid); + + String value, signature; + + player.sendMessage(ChatColor.GOLD + "Fetching skin value and signature..."); //Fetch the skin from Mineskin.org's API - String skinJson = GetSkin.getSkin(skinUrl, slim); + String skinJson = null; + if(isPremium ) { + skinJson = GetSkin.getSkinOfValidPlayer(externalUuid.toString()); + } else { + skinJson = GetSkin.getSkin(skinUrl, slim); + } //Get the skin texture value, and the skin texture signature JSONTokener tokener = new JSONTokener(skinJson); @@ -46,7 +53,7 @@ public void run() { value = (String) texture.get("value"); signature = (String) texture.get("signature"); - changeSkin(value, signature, caller, slim); + changeSkin(value, signature, internalUuid, slim); } }.runTaskAsynchronously(SkinFixer.INSTANCE); } @@ -61,7 +68,7 @@ public void run() { } private static void changeSkin(String skinValue, String skinSignature, UUID caller, boolean slim ) { - Player p = Bukkit.getPlayer(caller); + Player player = Bukkit.getPlayer(caller); //Store the skin to the storage file, so it can be reapplied when they join. if(StorageHandler.skins.containsKey(caller)) { @@ -74,36 +81,57 @@ private static void changeSkin(String skinValue, String skinSignature, UUID call StorageHandler.skins.put(caller, skin); } - p.sendMessage(ChatColor.GOLD + "Applying skin..."); + player.sendMessage(ChatColor.GOLD + "Applying skin..."); - //NMS is version dependant. So we need to set the correct class to use. - switch(SkinFixer.NMS_VERSION) { - case "v1_16_R1": changeGameProfile = new ChangeGameProfile_1_16_r1(); break; - - default: - //We dont support the version that the user is running, so we inform them of this. - //Calls to the Bukkit API may only be sync, so it's inside a BukkitRunnable - new BukkitRunnable() { - @Override - public void run() { + new BukkitRunnable() { + @Override + public void run() { + //NMS is version dependant. So we need to set the correct class to use. + switch(SkinFixer.NMS_VERSION) { + case "v1_16_R1": ChangeGameProfile_1_16_r1.changeProfile(player.getUniqueId(), skinValue, skinSignature); break; + case "v1_16_R2": ChangeGameProfile_1_16_r2.changeProfile(player.getUniqueId(), skinValue, skinSignature); break; + default: + //We dont support the version that the user is running, so we inform them of this. + //Calls to the Bukkit API may only be sync, so it's inside a BukkitRunnable Player p = Bukkit.getPlayer(caller); p.sendMessage(ChatColor.RED + "This server is using a Minecraft version that is not supported by SkinFixer!"); p.sendMessage(ChatColor.RED + "You are running NMS version " + SkinFixer.NMS_VERSION); } - }.runTask(SkinFixer.INSTANCE); - } + } + }.runTask(SkinFixer.INSTANCE); - //Change the skins on the GameProfile. Needs to be sync + reloadPlayer(player); + + //Inform the player that we're done + player.sendMessage(ChatColor.GOLD + "Done."); + } + + private static void reloadPlayer(Player player) { new BukkitRunnable() { - @Override public void run() { - Player p = Bukkit.getPlayer(caller); - changeGameProfile.changeProfile(p.getUniqueId(), skinValue, skinSignature); + Location loc = player.getLocation().clone(); + + //Reload the player for all online players + for(Player p : Bukkit.getOnlinePlayers()) { + p.hidePlayer(SkinFixer.INSTANCE, player); + p.showPlayer(SkinFixer.INSTANCE, player); + } + + World teleportToWorld = null; + for(World w : Bukkit.getWorlds()) { + if(!w.equals(loc.getWorld())) teleportToWorld = w; + } + + player.teleport(new Location(teleportToWorld, 0, 255, 0)); + new BukkitRunnable() { + @Override + public void run() { + player.teleport(loc); + player.updateInventory(); + } + }.runTaskLater(SkinFixer.INSTANCE, 5L); } }.runTask(SkinFixer.INSTANCE); - - //Inform the player that we're done - p.sendMessage(ChatColor.GOLD + "Done."); } } diff --git a/src/main/java/nl/thedutchmc/SkinFixer/changeSkin/changeGameProfile/ChangeGameProfile.java b/src/main/java/nl/thedutchmc/SkinFixer/changeSkin/changeGameProfile/ChangeGameProfile.java deleted file mode 100644 index 1cbae3f..0000000 --- a/src/main/java/nl/thedutchmc/SkinFixer/changeSkin/changeGameProfile/ChangeGameProfile.java +++ /dev/null @@ -1,12 +0,0 @@ -package nl.thedutchmc.SkinFixer.changeSkin.changeGameProfile; - -import java.util.UUID; - -import org.bukkit.entity.Player; - -public interface ChangeGameProfile { - - public void changeProfile(UUID uuid, String skinValue, String skinSignature); - - public void reloadSkinForSelf(Player p); -} diff --git a/src/main/java/nl/thedutchmc/SkinFixer/commandHandlers/SetSkinCommandExecutor.java b/src/main/java/nl/thedutchmc/SkinFixer/commandHandlers/SetSkinCommandExecutor.java index 3e27107..a3b8773 100644 --- a/src/main/java/nl/thedutchmc/SkinFixer/commandHandlers/SetSkinCommandExecutor.java +++ b/src/main/java/nl/thedutchmc/SkinFixer/commandHandlers/SetSkinCommandExecutor.java @@ -8,7 +8,7 @@ import net.md_5.bungee.api.ChatColor; import nl.thedutchmc.SkinFixer.SkinFixer; import nl.thedutchmc.SkinFixer.changeSkin.SkinChangeOrchestrator; -import nl.thedutchmc.SkinFixer.files.StorageHandler; +import nl.thedutchmc.SkinFixer.fileHandlers.StorageHandler; public class SetSkinCommandExecutor implements CommandExecutor { @@ -51,14 +51,14 @@ public boolean onCommand(CommandSender sender, Command command, String label, St if(args.length == 2) { if(args[1].equals("true")) { //Slim model - SkinChangeOrchestrator.changeSkinJson(url, p.getUniqueId(), true); + SkinChangeOrchestrator.changeSkinJson(url, p.getUniqueId(), null, true, false); } else { //Regular model - SkinChangeOrchestrator.changeSkinJson(url, p.getUniqueId(), false); + SkinChangeOrchestrator.changeSkinJson(url, p.getUniqueId(), null, false, false); } } else { //Regular model - SkinChangeOrchestrator.changeSkinJson(url, p.getUniqueId(), false); + SkinChangeOrchestrator.changeSkinJson(url, p.getUniqueId(), null, false, false); } SkinFixer.STORAGE.updateConfig(); diff --git a/src/main/java/nl/thedutchmc/SkinFixer/commonEventMethods/AddNewSkin.java b/src/main/java/nl/thedutchmc/SkinFixer/commonEventMethods/AddNewSkin.java index 17a889b..27162eb 100644 --- a/src/main/java/nl/thedutchmc/SkinFixer/commonEventMethods/AddNewSkin.java +++ b/src/main/java/nl/thedutchmc/SkinFixer/commonEventMethods/AddNewSkin.java @@ -2,7 +2,7 @@ import java.util.Random; -import nl.thedutchmc.SkinFixer.files.StorageHandler; +import nl.thedutchmc.SkinFixer.fileHandlers.StorageHandler; public class AddNewSkin { diff --git a/src/main/java/nl/thedutchmc/SkinFixer/files/ConfigurationHandler.java b/src/main/java/nl/thedutchmc/SkinFixer/fileHandlers/ConfigurationHandler.java similarity index 92% rename from src/main/java/nl/thedutchmc/SkinFixer/files/ConfigurationHandler.java rename to src/main/java/nl/thedutchmc/SkinFixer/fileHandlers/ConfigurationHandler.java index 5afab13..e0f9210 100644 --- a/src/main/java/nl/thedutchmc/SkinFixer/files/ConfigurationHandler.java +++ b/src/main/java/nl/thedutchmc/SkinFixer/fileHandlers/ConfigurationHandler.java @@ -1,4 +1,4 @@ -package nl.thedutchmc.SkinFixer.files; +package nl.thedutchmc.SkinFixer.fileHandlers; import java.io.File; import java.io.IOException; diff --git a/src/main/java/nl/thedutchmc/SkinFixer/files/StorageHandler.java b/src/main/java/nl/thedutchmc/SkinFixer/fileHandlers/StorageHandler.java similarity index 98% rename from src/main/java/nl/thedutchmc/SkinFixer/files/StorageHandler.java rename to src/main/java/nl/thedutchmc/SkinFixer/fileHandlers/StorageHandler.java index 1f7ea9b..857ed08 100644 --- a/src/main/java/nl/thedutchmc/SkinFixer/files/StorageHandler.java +++ b/src/main/java/nl/thedutchmc/SkinFixer/fileHandlers/StorageHandler.java @@ -1,4 +1,4 @@ -package nl.thedutchmc.SkinFixer.files; +package nl.thedutchmc.SkinFixer.fileHandlers; import java.io.File; import java.io.IOException; diff --git a/src/main/java/nl/thedutchmc/SkinFixer/minecraftEvents/PlayerJoinEventListener.java b/src/main/java/nl/thedutchmc/SkinFixer/minecraftEvents/PlayerJoinEventListener.java index 62c9fcc..916c203 100644 --- a/src/main/java/nl/thedutchmc/SkinFixer/minecraftEvents/PlayerJoinEventListener.java +++ b/src/main/java/nl/thedutchmc/SkinFixer/minecraftEvents/PlayerJoinEventListener.java @@ -1,5 +1,7 @@ package nl.thedutchmc.SkinFixer.minecraftEvents; +import java.util.UUID; + import org.bukkit.event.EventHandler; import org.bukkit.event.Listener; import org.bukkit.event.player.PlayerJoinEvent; @@ -7,26 +9,39 @@ import nl.thedutchmc.SkinFixer.SkinFixer; import nl.thedutchmc.SkinFixer.SkinObject; +import nl.thedutchmc.SkinFixer.changeSkin.CheckUserAgainstMojang; import nl.thedutchmc.SkinFixer.changeSkin.SkinChangeOrchestrator; -import nl.thedutchmc.SkinFixer.files.StorageHandler; +import nl.thedutchmc.SkinFixer.fileHandlers.StorageHandler; public class PlayerJoinEventListener implements Listener { @EventHandler - public void onPlayerJoinEvent(PlayerJoinEvent event) { - - if(!StorageHandler.skins.containsKey(event.getPlayer().getUniqueId())) { - return; - } - - SkinObject skin = StorageHandler.skins.get(event.getPlayer().getUniqueId()); - + public void onPlayerJoinEvent(PlayerJoinEvent event) { new BukkitRunnable() { @Override public void run() { - SkinChangeOrchestrator.changeSkinFromObject(skin); + String uuidAsString = CheckUserAgainstMojang.premiumUser(event.getPlayer().getName()); + if(uuidAsString != null) { + + SkinChangeOrchestrator.changeSkinJson(null, event.getPlayer().getUniqueId(), UUID.fromString(uuidAsString), false, true); + return; + } + + if(!StorageHandler.skins.containsKey(event.getPlayer().getUniqueId())) { + return; + } + + SkinObject skin = StorageHandler.skins.get(event.getPlayer().getUniqueId()); + + new BukkitRunnable() { + + @Override + public void run() { + SkinChangeOrchestrator.changeSkinFromObject(skin); + } + }.runTaskLater(SkinFixer.INSTANCE, 5L); } - }.runTaskLater(SkinFixer.INSTANCE, 5L); + }.runTaskAsynchronously(SkinFixer.INSTANCE); } } \ No newline at end of file