|
6 | 6 | import com.craftmend.openaudiomc.spigot.OpenAudioMcSpigot;
|
7 | 7 | import com.craftmend.openaudiomc.spigot.modules.speakers.SpeakerService;
|
8 | 8 | import com.craftmend.openaudiomc.spigot.services.server.enums.ServerVersion;
|
| 9 | +import de.tr7zw.changeme.nbtapi.NBT; |
9 | 10 | import de.tr7zw.changeme.nbtapi.NBTItem;
|
| 11 | +import de.tr7zw.changeme.nbtapi.iface.ReadWriteNBT; |
10 | 12 | import org.bukkit.Bukkit;
|
11 | 13 | import org.bukkit.ChatColor;
|
12 |
| -import org.bukkit.OfflinePlayer; |
13 | 14 | import org.bukkit.block.Block;
|
14 | 15 | import org.bukkit.block.Skull;
|
15 | 16 | import org.bukkit.inventory.ItemStack;
|
16 | 17 | import org.bukkit.inventory.meta.SkullMeta;
|
17 | 18 |
|
18 | 19 | import java.util.Arrays;
|
| 20 | +import java.util.Base64; |
19 | 21 | import java.util.UUID;
|
20 | 22 |
|
21 |
| -public class SpeakerUtils { |
| 23 | +import static com.craftmend.openaudiomc.generic.storage.enums.StorageKey.*; |
22 | 24 |
|
23 |
| - public static final String speakerSkin = "OpenAudioMc"; |
24 |
| - public static final UUID speakerUUID = UUID.fromString("c0db149e-d498-4a16-8e35-93d57577589f"); |
25 |
| - private static final SpeakerService SPEAKER_SERVICE = OpenAudioMc.getService(SpeakerService.class); |
| 25 | +public class SpeakerUtils { |
26 | 26 |
|
27 |
| - private static OfflinePlayer proxiedPlayer; |
| 27 | + public static final String speakerSkin = SETTINGS_SPEAKER_SKIN_NAME.getString(); |
| 28 | + public static final UUID speakerUUID = UUID.fromString(SETTINGS_SPEAKER_SKIN_UUID.getString()); |
| 29 | + public static final String textureValue; |
28 | 30 |
|
29 | 31 | static {
|
30 |
| - // attempt to create a offline player instance |
31 |
| - try { |
32 |
| - proxiedPlayer = new ClassMocker<OfflinePlayer>(OfflinePlayer.class) |
33 |
| - .addReturnValue("getUniqueId", speakerUUID) |
34 |
| - .addReturnValue("getName", speakerSkin) |
35 |
| - .createProxy(); |
36 |
| - } catch (Exception e) { |
37 |
| - OpenAudioLogger.warn("Failed to create a OfflinePlayer proxy class. This will cause issues with speakers on servers running post 1.20.2"); |
38 |
| - } |
| 32 | + String rawUrl = SETTINGS_SPEAKER_SKIN_TEXTURE.getString(); |
| 33 | + // convert to http instead of https, don't know if its important, but lets stick with what our |
| 34 | + // mojang gods decided |
| 35 | + rawUrl = rawUrl.replace("https://", "http://"); |
| 36 | + |
| 37 | + // turn it into the json format, our gods have also decided this is the way to go |
| 38 | + String json = "{textures:{SKIN:{url:\"" + rawUrl + "\"}}}"; |
| 39 | + textureValue = Base64.getEncoder().encodeToString(json.getBytes()); |
39 | 40 | }
|
40 | 41 |
|
| 42 | + private static final SpeakerService SPEAKER_SERVICE = OpenAudioMc.getService(SpeakerService.class); |
| 43 | + |
41 | 44 | public static boolean isSpeakerSkull(Block block) {
|
42 | 45 | if (block.getState() instanceof Skull) {
|
43 | 46 | Skull skull = (Skull) block.getState();
|
@@ -65,18 +68,31 @@ public static boolean isSpeakerSkull(Block block) {
|
65 | 68 | public static ItemStack getSkull(String source, int radius) {
|
66 | 69 | ItemStack skull = new ItemStack(SPEAKER_SERVICE.getPlayerSkullItem());
|
67 | 70 | skull.setDurability((short) 3);
|
| 71 | + |
| 72 | + // For Minecraft 1.20.4 and below |
| 73 | + NBT.modify(skull, nbt -> { |
| 74 | + ReadWriteNBT skullOwnerCompound = nbt.getOrCreateCompound("SkullOwner"); |
| 75 | + |
| 76 | + // The owner UUID. Note that skulls with the same UUID but different textures will misbehave and only one texture will load. |
| 77 | + // They will share the texture. To avoid this limitation, it is recommended to use a random UUID. |
| 78 | + skullOwnerCompound.setUUID("Id", UUID.randomUUID()); |
| 79 | + |
| 80 | + skullOwnerCompound.getOrCreateCompound("Properties") |
| 81 | + .getCompoundList("textures") |
| 82 | + .addCompound() |
| 83 | + .setString("Value", textureValue); |
| 84 | + }); |
| 85 | + |
| 86 | + NBT.modifyComponents(skull, nbt -> { |
| 87 | + ReadWriteNBT profileNbt = nbt.getOrCreateCompound("minecraft:profile"); |
| 88 | + profileNbt.setUUID("id", speakerUUID); |
| 89 | + ReadWriteNBT propertiesNbt = profileNbt.getCompoundList("properties").addCompound(); |
| 90 | + propertiesNbt.setString("name", "textures"); |
| 91 | + propertiesNbt.setString("value", textureValue); |
| 92 | + }); |
| 93 | + |
68 | 94 | SkullMeta sm = (SkullMeta) skull.getItemMeta();
|
69 | 95 | if (sm != null) {
|
70 |
| - if (SPEAKER_SERVICE.getVersion() == ServerVersion.MODERN) { |
71 |
| - if (proxiedPlayer != null) { |
72 |
| - sm.setOwningPlayer(proxiedPlayer); |
73 |
| - } else { |
74 |
| - // fallback for servers that don't support the proxy class |
75 |
| - sm.setOwningPlayer(Bukkit.getOfflinePlayer(speakerUUID)); |
76 |
| - } |
77 |
| - } |
78 |
| - |
79 |
| - sm.setOwner(speakerSkin); |
80 | 96 | sm.setDisplayName(ChatColor.AQUA + "OpenAudioMc Speaker");
|
81 | 97 | sm.setLore(Arrays.asList(
|
82 | 98 | ChatColor.AQUA + "I'm a super cool speaker!",
|
|
0 commit comments