Skip to content

Commit

Permalink
Revert changes
Browse files Browse the repository at this point in the history
  • Loading branch information
Straikerinos committed Aug 8, 2024
1 parent cf4f1f3 commit a96c95c
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 20 deletions.
2 changes: 1 addition & 1 deletion Loader - Bukkit/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
<dependency>
<groupId>org.spigotmc</groupId>
<artifactId>spigot-api</artifactId>
<version>1.16.5-R0.1-SNAPSHOT</version>
<version>1.21-R0.1-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
<dependency>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,9 @@ public class ItemMaker implements Cloneable {
protected static final Field PROFILE_FIELD = Ref.field(Ref.craft("inventory.CraftMetaSkull"), "profile");
protected static Method getBaseColor = Ref.method(BannerMeta.class, "getBaseColor");
protected static Method getPlayerProfile = Ref.method(SkullMeta.class,"getPlayerProfile");
protected static Method getOwnerProfile = Ref.method(SkullMeta.class,"getOwnerProfile");
protected static Method getProperties = Ref.method(Ref.getClass("com.destroystokyo.paper.profile.PlayerProfile"),"getProperties");
protected static Method getName = Ref.method(Ref.getClass("com.destroystokyo.paper.profile.ProfileProperty"),"getName");
protected static Method getValue = Ref.method(Ref.getClass("com.destroystokyo.paper.profile.ProfileProperty"),"getValue");
protected static Method getItems = Ref.method(Ref.getClass("org.bukkit.inventory.meta.BundleMeta"),"getItems");
protected static Method setEnchantmentGlintOverride = Ref.method(ItemMeta.class,"setEnchantmentGlintOverride",boolean.class);

protected Material material;
protected int amount = 1;
Expand Down Expand Up @@ -125,7 +122,7 @@ protected ItemMeta apply(ItemMeta meta) {
meta.setLore(lore);
if (enchantedGlow)
if (Ref.isNewerThan(20) || Ref.serverVersionInt() == 20 && Ref.serverVersionRelease() >= 4)
Ref.invoke(meta,setEnchantmentGlintOverride,true);
meta.setEnchantmentGlintOverride(true);
else {
if (itemFlags != null) {
itemFlags.add("HIDE_ENCHANTS");
Expand Down Expand Up @@ -368,7 +365,7 @@ public ItemMaker itemMeta(ItemMeta meta) {
break;
}
} else if (Ref.isNewerThan(17)) {
Object profile = Ref.invoke(skull,getOwnerProfile);
Object profile = skull.getOwnerProfile();
@SuppressWarnings("unchecked")
Multimap<String, Object> props = (Multimap<String, Object>) Ref.get(profile, SKIN_PROPERTIES);
Collection<Object> coll = props.get("textures");
Expand Down Expand Up @@ -657,7 +654,7 @@ public static void saveToConfig(Config config, String path, ItemStack stack) {
}
if (type == XMaterial.BUNDLE) {
List<String> contents = new ArrayList<>();
for (ItemStack itemStack : (List<ItemStack>) Ref.invoke(meta,getItems))
for (ItemStack itemStack : ((BundleMeta)meta).getItems())
if (itemStack != null && itemStack.getType() != Material.AIR)
contents.add(Json.writer().simpleWrite(ItemMaker.of(itemStack).serializeToMap()));
if (!contents.isEmpty())
Expand Down Expand Up @@ -695,7 +692,7 @@ public static void saveToConfig(Config config, String path, ItemStack stack) {
break;
}
} else if (Ref.isNewerThan(17)) {
Object profile = Ref.invoke(skull,getOwnerProfile);
Object profile = skull.getOwnerProfile();
@SuppressWarnings("unchecked")
Multimap<String, Object> props = (Multimap<String, Object>) Ref.get(profile, SKIN_PROPERTIES);
Collection<Object> coll = props.get("textures");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import me.devtec.theapi.bukkit.game.ItemMaker;
import org.bukkit.Material;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.BundleMeta;
import org.bukkit.inventory.meta.ItemMeta;

import java.lang.reflect.Method;
Expand Down Expand Up @@ -56,14 +57,12 @@ public ItemMaker clone() {
BundleItemMaker maker = (BundleItemMaker) super.clone();
return maker.contents(contents);
}
private static final Class<?> bundleMeta = Ref.getClass("org.bukkit.inventory.meta.BundleMeta");
private static final Method setItems = Ref.method(bundleMeta, "setItems",List.class);

@Override
protected ItemMeta apply(ItemMeta meta) {
if (!meta.getClass().isAssignableFrom(bundleMeta))
if (!(meta instanceof BundleMeta))
return super.apply(meta);
Ref.invoke(meta, setItems, contents);
((BundleMeta)meta).setItems(contents);
return super.apply(meta);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ protected ItemMeta apply(ItemMeta meta) {
if (super.lore != null)
iMeta.setLore(super.lore);
if (Ref.isNewerThan(20) || Ref.serverVersionInt() == 20 && Ref.serverVersionRelease() >= 4)
Ref.invoke(meta,setEnchantmentGlintOverride,true);
meta.setEnchantmentGlintOverride(true);
else {
if (itemFlags != null) {
itemFlags.add("HIDE_ENCHANTS");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import org.bukkit.Material;
import org.bukkit.inventory.meta.ItemMeta;
import org.bukkit.inventory.meta.SkullMeta;
import org.bukkit.profile.PlayerProfile;

import java.lang.reflect.Constructor;
import java.lang.reflect.Method;
Expand All @@ -39,11 +40,10 @@ public class HeadItemMaker extends ItemMaker {
private static final Material skull = XMaterial.PLAYER_HEAD.parseMaterial();
private static final String URL_FORMAT = "https://api.mineskin.org/generate/url?url=%s&%s";
private static final Method createProfile = Ref.method(Bukkit.class,"createProfile",UUID.class);
private static Constructor<?> constructor = Ref.constructor(Ref.getClass("com.mojang.authlib.properties.Property"), String.class, String.class, String.class);
private static final Method setProperty = Ref.method(Ref.getClass("com.destroystokyo.paper.profile.PlayerProfile"),"setProperty",Ref.getClass("com.destroystokyo.paper.profile.ProfileProperty"));
private static final Method setPlayerProfile = Ref.method(SkullMeta.class,"setPlayerProfile",Ref.getClass("com.destroystokyo.paper.profile.PlayerProfile"));
private static final Constructor<?> profileProperty= Ref.constructor(Ref.getClass("com.destroystokyo.paper.profile.ProfileProperty"),String.class,String.class);
private static final Method setOwnerProfile = Ref.method(SkullMeta.class,"setOwnerProfile",Ref.getClass("org.bukkit.profile.PlayerProfile"));
private static final Method createPlayerProfile = Ref.method(Bukkit.class,"createPlayerProfile",UUID.class, String.class);

private String owner;
/**
Expand Down Expand Up @@ -155,13 +155,13 @@ protected ItemMeta apply(ItemMeta meta) {
Ref.invoke(profile,setProperty,Ref.newInstance(profileProperty,"textures", finalValue));
Ref.invoke(iMeta,setPlayerProfile,profile);
} else if (Ref.isNewerThan(17)) {
Object profile = Ref.invokeStatic(createPlayerProfile,uuid, "");
PlayerProfile profile = Bukkit.createPlayerProfile(uuid,"");
@SuppressWarnings("unchecked")
Multimap<String, Object> props = (Multimap<String, Object>) Ref.get(profile, SKIN_PROPERTIES);
props.removeAll("textures");
Object property = Ref.newInstance(Ref.constructor(Ref.getClass("com.mojang.authlib.properties.Property"), String.class, String.class, String.class), "textures", finalValue, null);
Object property = Ref.newInstance(constructor, "textures", finalValue, null);
props.put("textures", property);
Ref.invoke(iMeta, setOwnerProfile,profile);
iMeta.setOwnerProfile(profile);
} else
Ref.set(iMeta, PROFILE_FIELD, BukkitLoader.getNmsProvider().toGameProfile(GameProfileHandler.of("", uuid, PropertyHandler.of("textures", finalValue))));
break;
Expand Down
4 changes: 2 additions & 2 deletions Loader - Velocity/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>1.17</maven.compiler.source>
<maven.compiler.target>1.17</maven.compiler.target>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
</properties>

<dependencies>
Expand Down

0 comments on commit a96c95c

Please sign in to comment.