Skip to content

Commit 10292cc

Browse files
committed
Implement custom skin textures, and fix it not showing up
1 parent f17350a commit 10292cc

File tree

8 files changed

+66
-30
lines changed

8 files changed

+66
-30
lines changed

.tool-versions

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
java adoptopenjdk-8.0.332+9
1+
java openjdk-21

plugin/src/main/bash/data.bin

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
BUILD_NUM="1491"
1+
BUILD_NUM="1497"

plugin/src/main/java/com/craftmend/openaudiomc/generic/migrations/MigrationWorker.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ public void handleMigrations() {
6464
new AddConfigKeyMigration(SETTINGS_AUTO_RECONNECT, "Add a migration setting for auto reconnect"),
6565
new AddConfigKeyMigration(SETTINGS_SPEAKER_MAX_RANGE, "Add max range config value"),
6666
new AddConfigKeyMigration(SETTINGS_STATIC_CHANNELS_SHOW_IN_WEB_UI, "Add a setting to show the channels web UI"),
67+
new AddConfigKeyMigration(SETTINGS_SPEAKER_SKIN_UUID, "Add a setting for the speaker skin textures"),
6768
};
6869

6970
for (SimpleMigration migration : migrations) {

plugin/src/main/java/com/craftmend/openaudiomc/generic/storage/enums/StorageKey.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,11 @@ public enum StorageKey {
128128
SETTINGS_PAPI_VC_CONNECTED(false, "papi.voicechat-connected", StorageLocation.CONFIG_FILE),
129129
SETTINGS_PAPI_VC_DISCONNECTED(false, "papi.voicechat-disconnected", StorageLocation.CONFIG_FILE),
130130

131+
SETTINGS_SPEAKER_SKIN_NAME(false, "speaker-skin.profile-name", StorageLocation.CONFIG_FILE),
132+
SETTINGS_SPEAKER_SKIN_UUID(false, "speaker-skin.profile-uuid", StorageLocation.CONFIG_FILE),
133+
SETTINGS_SPEAKER_SKIN_TEXTURE(false, "speaker-skin.texture-url", StorageLocation.CONFIG_FILE),
134+
135+
131136
DEBUG_LOG_STATE_CHANGES(false, "debug.log-state-changes", StorageLocation.DATA_FILE),
132137

133138
AUTH_HOST(true, "keyset.server-ip", StorageLocation.DATA_FILE),

plugin/src/main/java/com/craftmend/openaudiomc/spigot/modules/speakers/utils/SpeakerUtils.java

Lines changed: 41 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -6,38 +6,41 @@
66
import com.craftmend.openaudiomc.spigot.OpenAudioMcSpigot;
77
import com.craftmend.openaudiomc.spigot.modules.speakers.SpeakerService;
88
import com.craftmend.openaudiomc.spigot.services.server.enums.ServerVersion;
9+
import de.tr7zw.changeme.nbtapi.NBT;
910
import de.tr7zw.changeme.nbtapi.NBTItem;
11+
import de.tr7zw.changeme.nbtapi.iface.ReadWriteNBT;
1012
import org.bukkit.Bukkit;
1113
import org.bukkit.ChatColor;
12-
import org.bukkit.OfflinePlayer;
1314
import org.bukkit.block.Block;
1415
import org.bukkit.block.Skull;
1516
import org.bukkit.inventory.ItemStack;
1617
import org.bukkit.inventory.meta.SkullMeta;
1718

1819
import java.util.Arrays;
20+
import java.util.Base64;
1921
import java.util.UUID;
2022

21-
public class SpeakerUtils {
23+
import static com.craftmend.openaudiomc.generic.storage.enums.StorageKey.*;
2224

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 {
2626

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;
2830

2931
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());
3940
}
4041

42+
private static final SpeakerService SPEAKER_SERVICE = OpenAudioMc.getService(SpeakerService.class);
43+
4144
public static boolean isSpeakerSkull(Block block) {
4245
if (block.getState() instanceof Skull) {
4346
Skull skull = (Skull) block.getState();
@@ -65,18 +68,31 @@ public static boolean isSpeakerSkull(Block block) {
6568
public static ItemStack getSkull(String source, int radius) {
6669
ItemStack skull = new ItemStack(SPEAKER_SERVICE.getPlayerSkullItem());
6770
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+
6894
SkullMeta sm = (SkullMeta) skull.getItemMeta();
6995
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);
8096
sm.setDisplayName(ChatColor.AQUA + "OpenAudioMc Speaker");
8197
sm.setLore(Arrays.asList(
8298
ChatColor.AQUA + "I'm a super cool speaker!",

plugin/src/main/resources/config.yml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -363,6 +363,20 @@ cdn:
363363
enabled: false
364364
skip-validation: false
365365

366+
# The speaker skin defines the look and feel of your speakers.
367+
speaker-skin:
368+
# The texture of the speaker's skull. This can't be any online value, it has to be from the mojang texture service.
369+
# You can find a texture url from a name, using a site like https://mcprofile.io/
370+
texture-url: https://textures.minecraft.net/texture/6a5fed371c2231879a5b4c413c94d81e139dc3c21449128333469a439d7b9561
371+
372+
# The default is a Minecraft account called "OpenAudioMc"
373+
# This has to match the profile-uuid, and is case sensitive.
374+
#
375+
# IMPORTANT: Changing the profile n ame or UUID will break all existing speakers in your world.
376+
# IMPORTANT: Only 'new' speakers with the configured profile name and UUID be detected
377+
profile-name: OpenAudioMc
378+
# The game profile UUID of the spaeker's skull owner. Has to be a valid/premium minecraft account.
379+
profile-uuid: c0db149e-d498-4a16-8e35-93d57577589f
366380

367381
# REDIS
368382
# This is only used for syncing shows with other servers and the vistas modules.

plugin/src/main/resources/data.bin

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
BUILD_NUM="1491"
1+
BUILD_NUM="1497"
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
BUILD_VERSION="1491"
2-
BUILD_COMMIT="3c3773db2653a2e98dce48cd5d479d01c7ad7134"
1+
BUILD_VERSION="1497"
2+
BUILD_COMMIT="f17350ae1d8dd428fe6ce03024e30a18ca83b508"
33
BUILD_AUTHOR="Mats"

0 commit comments

Comments
 (0)