diff --git a/src/main/java/pk/ajneb97/database/MySQLConnection.java b/src/main/java/pk/ajneb97/database/MySQLConnection.java index b32e2d3..78d3054 100644 --- a/src/main/java/pk/ajneb97/database/MySQLConnection.java +++ b/src/main/java/pk/ajneb97/database/MySQLConnection.java @@ -12,9 +12,7 @@ import java.sql.Connection; import java.sql.PreparedStatement; import java.sql.ResultSet; import java.sql.SQLException; -import java.util.ArrayList; -import java.util.HashSet; -import java.util.Set; +import java.util.*; public class MySQLConnection { @@ -76,7 +74,7 @@ public class MySQLConnection { ResultSet result = statement.executeQuery(); - Set existingUUIDs = new HashSet<>(); + Map playerMap = new HashMap<>(); while(result.next()){ String uuid = result.getString("UUID"); String playerName = result.getString("PLAYER_NAME"); @@ -85,17 +83,13 @@ public class MySQLConnection { boolean oneTime = result.getBoolean("ONE_TIME"); boolean bought = result.getBoolean("BOUGHT"); - PlayerData currentPlayer; - if(!existingUUIDs.contains(uuid)){ + PlayerData player = playerMap.get(uuid); + + if(player == null){ //Create and add it - currentPlayer = new PlayerData(playerName,uuid); - players.add(currentPlayer); - existingUUIDs.add(uuid); - }else{ - currentPlayer = players.stream() - .filter(p -> p.getUuid().equals(uuid)) - .findFirst() - .orElse(null); + player = new PlayerData(playerName,uuid); + players.add(player); + playerMap.put(uuid, player); } if(kitName != null){ @@ -103,7 +97,7 @@ public class MySQLConnection { playerDataKit.setCooldown(cooldown); playerDataKit.setOneTime(oneTime); playerDataKit.setBought(bought); - currentPlayer.addKit(playerDataKit); + player.addKit(playerDataKit); } } } catch (SQLException e) { diff --git a/src/main/java/pk/ajneb97/model/verify/PKInventoryInvalidSlotError.java b/src/main/java/pk/ajneb97/model/verify/PKInventoryInvalidSlotError.java index 64808b1..93aa24c 100644 --- a/src/main/java/pk/ajneb97/model/verify/PKInventoryInvalidSlotError.java +++ b/src/main/java/pk/ajneb97/model/verify/PKInventoryInvalidSlotError.java @@ -27,7 +27,7 @@ public class PKInventoryInvalidSlotError extends PKBaseError{ hover.add("&eTHIS IS AN ERROR!"); hover.add("&fSlot &c"+slot+" &fon inventory &c"+inventoryName); hover.add("&fis out of range. Use a range"); - hover.add("&fbetween 0 and "+maxSlots+"."); + hover.add("&fbetween 0 and "+(maxSlots-1)+"."); jsonMessage.hover(hover).send(); } diff --git a/src/main/java/pk/ajneb97/utils/ItemUtils.java b/src/main/java/pk/ajneb97/utils/ItemUtils.java index 77d6981..c1379bb 100644 --- a/src/main/java/pk/ajneb97/utils/ItemUtils.java +++ b/src/main/java/pk/ajneb97/utils/ItemUtils.java @@ -6,6 +6,8 @@ import java.net.MalformedURLException; import java.net.URL; import java.util.*; +import com.google.gson.Gson; +import com.google.gson.JsonObject; import org.bukkit.*; import org.bukkit.FireworkEffect.Type; import org.bukkit.attribute.Attribute; @@ -129,8 +131,7 @@ public class ItemUtils { return kitItemSkullData; } - - @SuppressWarnings("deprecation") + public static void setSkullData(ItemStack item, KitItemSkullData skullData, Player player){ String typeName = item.getType().name(); if(!typeName.equals("PLAYER_HEAD") && !typeName.equals("SKULL_ITEM")) { @@ -148,46 +149,48 @@ public class ItemUtils { } String id = skullData.getId(); SkullMeta skullMeta = (SkullMeta) item.getItemMeta(); - if(texture == null && owner != null) { + if(owner != null) { skullMeta.setOwner(owner); - item.setItemMeta(skullMeta); - return; } - ServerVersion serverVersion = PlayerKits2.serverVersion; - if(serverVersion.serverVersionGreaterEqualThan(serverVersion,ServerVersion.v1_20_R2)){ - UUID uuid = id != null ? UUID.fromString(id) : UUID.randomUUID(); - PlayerProfile profile = Bukkit.createPlayerProfile(uuid); - PlayerTextures textures = profile.getTextures(); - URL url; - try { - String decoded = new String(Base64.getDecoder().decode(texture)); - String decodedFormatted = decoded.replaceAll("\\s", ""); - int firstIndex = decodedFormatted.indexOf("\"SKIN\":{\"url\":")+15; - int lastIndex = decodedFormatted.indexOf("\"",firstIndex+1); - url = new URL(decodedFormatted.substring(firstIndex,lastIndex)); - } catch (MalformedURLException error) { - error.printStackTrace(); - return; - } - textures.setSkin(url); - profile.setTextures(textures); - skullMeta.setOwnerProfile(profile); - }else{ - GameProfile profile = null; - if(id == null) { - profile = new GameProfile(UUID.randomUUID(), owner != null ? owner : ""); - }else { - profile = new GameProfile(UUID.fromString(id), owner != null ? owner : ""); - } - profile.getProperties().put("textures", new Property("textures", texture)); + if(texture != null){ + ServerVersion serverVersion = PlayerKits2.serverVersion; + if(serverVersion.serverVersionGreaterEqualThan(serverVersion,ServerVersion.v1_20_R2)){ + UUID uuid = id != null ? UUID.fromString(id) : UUID.randomUUID(); + PlayerProfile profile = Bukkit.createPlayerProfile(uuid); + PlayerTextures textures = profile.getTextures(); + URL url; + try { + String decoded = new String(Base64.getDecoder().decode(texture)); + String decodedFormatted = decoded.replaceAll("\\s", ""); + JsonObject jsonObject = new Gson().fromJson(decodedFormatted, JsonObject.class); + String urlText = jsonObject.get("textures").getAsJsonObject().get("SKIN") + .getAsJsonObject().get("url").getAsString(); - try { - Field profileField = skullMeta.getClass().getDeclaredField("profile"); - profileField.setAccessible(true); - profileField.set(skullMeta, profile); - } catch (IllegalArgumentException | NoSuchFieldException | SecurityException | IllegalAccessException error) { - error.printStackTrace(); + url = new URL(urlText); + } catch (Exception error) { + error.printStackTrace(); + return; + } + textures.setSkin(url); + profile.setTextures(textures); + skullMeta.setOwnerProfile(profile); + }else{ + GameProfile profile = null; + if(id == null) { + profile = new GameProfile(UUID.randomUUID(), owner != null ? owner : ""); + }else { + profile = new GameProfile(UUID.fromString(id), owner != null ? owner : ""); + } + profile.getProperties().put("textures", new Property("textures", texture)); + + try { + Field profileField = skullMeta.getClass().getDeclaredField("profile"); + profileField.setAccessible(true); + profileField.set(skullMeta, profile); + } catch (IllegalArgumentException | NoSuchFieldException | SecurityException | IllegalAccessException error) { + error.printStackTrace(); + } } } diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml index 877894f..1a47a15 100644 --- a/src/main/resources/plugin.yml +++ b/src/main/resources/plugin.yml @@ -1,5 +1,5 @@ main: pk.ajneb97.PlayerKits2 -version: 1.9.2 +version: 1.9.3 name: PlayerKits2 api-version: 1.13 softdepend: [Vault,PlaceholderAPI]