diff --git a/PlayerHeads-compatibility/PlayerHeads-compatibility-lib/dependency-reduced-pom.xml b/PlayerHeads-compatibility/PlayerHeads-compatibility-lib/dependency-reduced-pom.xml index 57cfaffc..abd1d4e0 100644 --- a/PlayerHeads-compatibility/PlayerHeads-compatibility-lib/dependency-reduced-pom.xml +++ b/PlayerHeads-compatibility/PlayerHeads-compatibility-lib/dependency-reduced-pom.xml @@ -3,7 +3,7 @@ PlayerHeads-compatibility org.shininet.bukkit - 5.2.14-SNAPSHOT + 5.2.15-SNAPSHOT 4.0.0 PlayerHeads-compatibility-lib diff --git a/PlayerHeads-compatibility/PlayerHeads-compatibility-lib/pom.xml b/PlayerHeads-compatibility/PlayerHeads-compatibility-lib/pom.xml index 0ce19a65..6e6bca55 100644 --- a/PlayerHeads-compatibility/PlayerHeads-compatibility-lib/pom.xml +++ b/PlayerHeads-compatibility/PlayerHeads-compatibility-lib/pom.xml @@ -4,7 +4,7 @@ org.shininet.bukkit PlayerHeads-compatibility - 5.2.14-SNAPSHOT + 5.2.15-SNAPSHOT PlayerHeads-compatibility-lib jar @@ -31,7 +31,7 @@ ${project.groupId} PlayerHeads-craftbukkit-support - 5.2.14-SNAPSHOT + 5.2.15-SNAPSHOT org.bukkit @@ -67,7 +67,7 @@ ${project.groupId} PlayerHeads-craftbukkit-1.8-support - 5.2.14-SNAPSHOT + 5.2.15-SNAPSHOT org.bukkit @@ -79,14 +79,14 @@ ${project.groupId} PlayerHeads-craftbukkit-1.13-support - 5.2.14-SNAPSHOT + 5.2.15-SNAPSHOT ${project.groupId} PlayerHeads-paperapi-support - 5.2.14-SNAPSHOT + 5.2.15-SNAPSHOT org.bukkit @@ -107,7 +107,7 @@ ${project.groupId} PlayerHeads-glowstone-1.12-support - 5.2.14-SNAPSHOT + 5.2.15-SNAPSHOT org.bukkit diff --git a/PlayerHeads-compatibility/PlayerHeads-craftbukkit-1.13-support/pom.xml b/PlayerHeads-compatibility/PlayerHeads-craftbukkit-1.13-support/pom.xml index 69411454..a39e9aae 100644 --- a/PlayerHeads-compatibility/PlayerHeads-craftbukkit-1.13-support/pom.xml +++ b/PlayerHeads-compatibility/PlayerHeads-craftbukkit-1.13-support/pom.xml @@ -9,7 +9,7 @@ PlayerHeads-compatibility org.shininet.bukkit - 5.2.14-SNAPSHOT + 5.2.15-SNAPSHOT @@ -62,7 +62,7 @@ ${project.groupId} PlayerHeads-craftbukkit-support - 5.2.14-SNAPSHOT + 5.2.15-SNAPSHOT org.bukkit diff --git a/PlayerHeads-compatibility/PlayerHeads-craftbukkit-1.8-support/pom.xml b/PlayerHeads-compatibility/PlayerHeads-craftbukkit-1.8-support/pom.xml index d9282cb0..89c0736c 100644 --- a/PlayerHeads-compatibility/PlayerHeads-craftbukkit-1.8-support/pom.xml +++ b/PlayerHeads-compatibility/PlayerHeads-craftbukkit-1.8-support/pom.xml @@ -9,7 +9,7 @@ PlayerHeads-compatibility org.shininet.bukkit - 5.2.14-SNAPSHOT + 5.2.15-SNAPSHOT @@ -46,7 +46,7 @@ ${project.groupId} PlayerHeads-craftbukkit-support - 5.2.14-SNAPSHOT + 5.2.15-SNAPSHOT org.bukkit diff --git a/PlayerHeads-compatibility/PlayerHeads-craftbukkit-support/pom.xml b/PlayerHeads-compatibility/PlayerHeads-craftbukkit-support/pom.xml index a31a8ed1..0508feeb 100644 --- a/PlayerHeads-compatibility/PlayerHeads-craftbukkit-support/pom.xml +++ b/PlayerHeads-compatibility/PlayerHeads-craftbukkit-support/pom.xml @@ -9,7 +9,7 @@ PlayerHeads-compatibility org.shininet.bukkit - 5.2.14-SNAPSHOT + 5.2.15-SNAPSHOT diff --git a/PlayerHeads-compatibility/PlayerHeads-craftbukkit-support/src/main/java/com/github/crashdemons/playerheads/compatibility/craftbukkit/ProfileUtils.java b/PlayerHeads-compatibility/PlayerHeads-craftbukkit-support/src/main/java/com/github/crashdemons/playerheads/compatibility/craftbukkit/ProfileUtils.java index 717cedc2..ebbf6e5d 100644 --- a/PlayerHeads-compatibility/PlayerHeads-craftbukkit-support/src/main/java/com/github/crashdemons/playerheads/compatibility/craftbukkit/ProfileUtils.java +++ b/PlayerHeads-compatibility/PlayerHeads-craftbukkit-support/src/main/java/com/github/crashdemons/playerheads/compatibility/craftbukkit/ProfileUtils.java @@ -8,11 +8,10 @@ import com.github.crashdemons.playerheads.compatibility.CompatibleProfile; import com.mojang.authlib.GameProfile; import java.lang.reflect.Field; +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; import java.util.UUID; -import org.bukkit.Bukkit; -import org.bukkit.OfflinePlayer; import org.bukkit.block.Skull; -import org.bukkit.inventory.meta.ItemMeta; import org.bukkit.inventory.meta.SkullMeta; /** @@ -32,6 +31,12 @@ private static Field getProfileField(Object skull) throws IllegalArgumentExcepti profileField.setAccessible(true); return profileField; } + private static Method getCBProfileMethod(Object skull) throws IllegalArgumentException,NoSuchMethodException,SecurityException,IllegalAccessException{ + if(!(skull instanceof SkullMeta || skull instanceof Skull)) throw new IllegalArgumentException("Object is not a supported type: SkullMeta or Skull (blockstate)"); + Method profileMethod = skull.getClass().getDeclaredMethod("setProfile", GameProfile.class); + profileMethod.setAccessible(true); + return profileMethod; + } //------------------------------------------------------------------------- @@ -47,8 +52,23 @@ public static CompatibleProfile getProfile(Object skull) throws IllegalStateExce if(profile==null) return new CompatibleProfileCB(); return new CompatibleProfileCB(profile); } + + + private static boolean setInternalProfileCB(Object skull, GameProfile profile) throws IllegalStateException{ + try { + getCBProfileMethod(skull).invoke(skull, profile); + return true; + } catch (NoSuchMethodException | InvocationTargetException | SecurityException | IllegalAccessException error) { + return false; + } + } + public static boolean setInternalProfile(Object skull, GameProfile profile) throws IllegalStateException{ try { + /* in some version of Spigot after 1.8, a method was added to set the profile, which also sets serialization data + we shouuld prefer using the craftbukkit method over directly accessing the profile field in order to serialize correctly. + */ + if(setInternalProfileCB(skull,profile)) return true; getProfileField(skull).set(skull, profile); return true; } catch (IllegalArgumentException | NoSuchFieldException | SecurityException | IllegalAccessException error) { diff --git a/PlayerHeads-compatibility/PlayerHeads-glowstone-1.12-support/pom.xml b/PlayerHeads-compatibility/PlayerHeads-glowstone-1.12-support/pom.xml index db1a4317..85f213b4 100644 --- a/PlayerHeads-compatibility/PlayerHeads-glowstone-1.12-support/pom.xml +++ b/PlayerHeads-compatibility/PlayerHeads-glowstone-1.12-support/pom.xml @@ -9,7 +9,7 @@ PlayerHeads-compatibility org.shininet.bukkit - 5.2.14-SNAPSHOT + 5.2.15-SNAPSHOT @@ -83,7 +83,7 @@ ${project.groupId} PlayerHeads-paperapi-support - 5.2.14-SNAPSHOT + 5.2.15-SNAPSHOT * diff --git a/PlayerHeads-compatibility/PlayerHeads-paperapi-support/pom.xml b/PlayerHeads-compatibility/PlayerHeads-paperapi-support/pom.xml index e60fd25f..041e93f8 100644 --- a/PlayerHeads-compatibility/PlayerHeads-paperapi-support/pom.xml +++ b/PlayerHeads-compatibility/PlayerHeads-paperapi-support/pom.xml @@ -9,7 +9,7 @@ PlayerHeads-compatibility org.shininet.bukkit - 5.2.14-SNAPSHOT + 5.2.15-SNAPSHOT diff --git a/PlayerHeads-compatibility/PlayerHeads-paperapi-support/src/main/java/com/github/crashdemons/playerheads/compatibility/paperapi/ProfileUtils.java b/PlayerHeads-compatibility/PlayerHeads-paperapi-support/src/main/java/com/github/crashdemons/playerheads/compatibility/paperapi/ProfileUtils.java index 6f1f9672..f7b6a992 100644 --- a/PlayerHeads-compatibility/PlayerHeads-paperapi-support/src/main/java/com/github/crashdemons/playerheads/compatibility/paperapi/ProfileUtils.java +++ b/PlayerHeads-compatibility/PlayerHeads-paperapi-support/src/main/java/com/github/crashdemons/playerheads/compatibility/paperapi/ProfileUtils.java @@ -8,6 +8,8 @@ import com.destroystokyo.paper.profile.PlayerProfile; import com.github.crashdemons.playerheads.compatibility.CompatibleProfile; import java.lang.reflect.Field; +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; import java.util.UUID; import org.bukkit.block.Skull; import org.bukkit.inventory.meta.SkullMeta; @@ -29,6 +31,12 @@ private static Field getProfileField(Object skull) throws IllegalArgumentExcepti profileField.setAccessible(true); return profileField; } + private static Method getPAProfileMethod(Object skull) throws IllegalArgumentException,NoSuchMethodException,SecurityException,IllegalAccessException{ + if(!(skull instanceof SkullMeta || skull instanceof Skull)) throw new IllegalArgumentException("Object is not a supported type: SkullMeta or Skull (blockstate)"); + Method profileMethod = skull.getClass().getDeclaredMethod("setProfile", PlayerProfile.class); + profileMethod.setAccessible(true); + return profileMethod; + } //------------------------------------------------------------------------- @@ -44,8 +52,22 @@ public static CompatibleProfile getProfile(Object skull) throws IllegalStateExce if(profile==null) return new CompatibleProfilePA(); return new CompatibleProfilePA(profile); } + + private static boolean setInternalProfilePA(Object skull, PlayerProfile profile) throws IllegalStateException{ + try { + getPAProfileMethod(skull).invoke(skull, profile); + return true; + } catch (NoSuchMethodException | InvocationTargetException | SecurityException | IllegalAccessException error) { + return false; + } + } + public static boolean setInternalProfile(Object skull, PlayerProfile profile) throws IllegalStateException{ try { + /* in some version of Spigot after 1.8, a method was added to set the profile, which also sets serialization data + we shouuld prefer using the craftbukkit method over directly accessing the profile field in order to serialize correctly. + */ + if(setInternalProfilePA(skull,profile)) return true; getProfileField(skull).set(skull, profile); return true; } catch (IllegalArgumentException | NoSuchFieldException | SecurityException | IllegalAccessException error) { diff --git a/PlayerHeads-compatibility/pom.xml b/PlayerHeads-compatibility/pom.xml index a6cdde58..556b1837 100644 --- a/PlayerHeads-compatibility/pom.xml +++ b/PlayerHeads-compatibility/pom.xml @@ -4,7 +4,7 @@ org.shininet.bukkit PlayerHeads - 5.2.14-SNAPSHOT + 5.2.15-SNAPSHOT PlayerHeads-compatibility pom diff --git a/PlayerHeads-crossversion-plugin/dependency-reduced-pom.xml b/PlayerHeads-crossversion-plugin/dependency-reduced-pom.xml index 0d41b297..d7d88804 100644 --- a/PlayerHeads-crossversion-plugin/dependency-reduced-pom.xml +++ b/PlayerHeads-crossversion-plugin/dependency-reduced-pom.xml @@ -3,7 +3,7 @@ PlayerHeads org.shininet.bukkit - 5.2.14-SNAPSHOT + 5.2.15-SNAPSHOT 4.0.0 org.shininet.bukkit @@ -190,6 +190,14 @@ commons-lang commons-lang + + guava + com.google.guava + + + gson + com.google.code.gson + bungeecord-chat net.md-5 diff --git a/PlayerHeads-crossversion-plugin/pom.xml b/PlayerHeads-crossversion-plugin/pom.xml index 7e39a634..ffdab5a6 100644 --- a/PlayerHeads-crossversion-plugin/pom.xml +++ b/PlayerHeads-crossversion-plugin/pom.xml @@ -47,7 +47,7 @@ ${project.groupId} PlayerHeads-core - 5.2.14-SNAPSHOT + 5.2.15-SNAPSHOT org.bukkit @@ -59,7 +59,7 @@ ${project.groupId} PlayerHeads-compatibility-lib - 5.2.14-SNAPSHOT + 5.2.15-SNAPSHOT compile