1.20r2 Support

This commit is contained in:
JaTiTV 2023-12-07 18:29:51 +01:00
parent 65e0082322
commit 0f645300f4
2 changed files with 50 additions and 6 deletions

View File

@ -6,7 +6,7 @@
<groupId>net.t2code</groupId>
<artifactId>T2CodeLib</artifactId>
<version>16.1</version>
<version>16.2</version>
<!--version>VERSION_snapshot-0</version-->
<!--version>VERSION_beta-0</version-->
<!--version>VERSION_dev-0</version-->
@ -221,6 +221,12 @@
<version>4.5.14</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.json</groupId>
<artifactId>json</artifactId>
<version>20230227</version>
<scope>compile</scope>
</dependency>
</dependencies>
</project>

View File

@ -3,13 +3,23 @@ package net.t2code.t2codelib.SPIGOT.api.items;
import com.mojang.authlib.GameProfile;
import com.mojang.authlib.properties.Property;
import net.t2code.t2codelib.SPIGOT.api.minecraftVersion.T2CmcVersion;
import net.t2code.t2codelib.SPIGOT.system.bstats.Metrics;
import org.bukkit.Bukkit;
import org.bukkit.Material;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;
import org.bukkit.inventory.meta.SkullMeta;
import org.bukkit.profile.PlayerProfile;
import org.bukkit.profile.PlayerTextures;
import java.lang.reflect.Field;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.Base64;
import org.json.JSONObject;
import java.util.List;
import java.util.UUID;
@ -66,7 +76,13 @@ public class T2CitemBuilder {
inventory.setItem(slot, item);
}
public static ItemStack base64(String base64Value, Integer amount, String displayName, List<String> lore) {
public static ItemStack base64(String base64Value) {
if (!T2CmcVersion.minMc1_20() || T2CmcVersion.isNms1_20_R1()) {
return base64Old(base64Value);
} else return base64New(base64Value);
}
private static ItemStack base64Old(String base64Value) {
ItemStack itemStack = new ItemStack(T2CitemVersion.getHead());
SkullMeta itemMeta = (SkullMeta) itemStack.getItemMeta();
@ -81,11 +97,33 @@ public class T2CitemBuilder {
e.printStackTrace();
}
itemMeta.setDisplayName(displayName);
itemMeta.setLore(lore);
itemStack.setItemMeta(itemMeta);
itemStack.setAmount(amount);
return itemStack;
}
private static ItemStack base64New(String base64Value) {
ItemStack itemStack = new ItemStack(T2CitemVersion.getHead());
SkullMeta itemMeta = (SkullMeta) itemStack.getItemMeta();
PlayerProfile profile = Bukkit.createPlayerProfile(UUID.randomUUID());
PlayerTextures textures = profile.getTextures();
try {
textures.setSkin(new URL(base64Convert(base64Value)));
} catch (MalformedURLException e) {
throw new RuntimeException(e);
}
profile.setTextures(textures);
itemMeta.setOwnerProfile(profile);
itemStack.setItemMeta(itemMeta);
return itemStack;
}
private static String base64Convert(String base64Value) {
String jsonString = new String(Base64.getDecoder().decode(base64Value));
JSONObject obj = new JSONObject(jsonString);
String output = obj.getJSONObject("textures").getJSONObject("SKIN").getString("url");
if (output.startsWith("http://textures.minecraft.net/texture/")){
return output;
} else return "http://textures.minecraft.net/texture/d5d20330da59c207d78352838e91a48ea1e42b45a9893226144b251fe9b9d535";
}
}