Skip to content

Commit be7fe8e

Browse files
committed
add version fallback
1 parent 1e59218 commit be7fe8e

File tree

1 file changed

+16
-7
lines changed
  • plugin/src/main/java/com/craftmend/openaudiomc/spigot/modules/speakers/utils

1 file changed

+16
-7
lines changed

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

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import com.craftmend.openaudiomc.spigot.services.server.enums.ServerVersion;
99
import de.tr7zw.changeme.nbtapi.NBT;
1010
import de.tr7zw.changeme.nbtapi.NBTItem;
11+
import de.tr7zw.changeme.nbtapi.NbtApiException;
1112
import de.tr7zw.changeme.nbtapi.iface.ReadWriteNBT;
1213
import org.bukkit.Bukkit;
1314
import org.bukkit.ChatColor;
@@ -83,13 +84,21 @@ public static ItemStack getSkull(String source, int radius) {
8384
.setString("Value", textureValue);
8485
});
8586

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-
});
87+
try {
88+
NBT.modifyComponents(skull, nbt -> {
89+
ReadWriteNBT profileNbt = nbt.getOrCreateCompound("minecraft:profile");
90+
profileNbt.setUUID("id", speakerUUID);
91+
ReadWriteNBT propertiesNbt = profileNbt.getCompoundList("properties").addCompound();
92+
propertiesNbt.setString("name", "textures");
93+
propertiesNbt.setString("value", textureValue);
94+
});
95+
} catch (NbtApiException e) {
96+
if (e.getMessage().contains("only works for")) {
97+
OpenAudioLogger.info("Failed to use modern speaker NBT, this server version does not support it.");
98+
} else {
99+
e.printStackTrace();
100+
}
101+
}
93102

94103
SkullMeta sm = (SkullMeta) skull.getItemMeta();
95104
if (sm != null) {

0 commit comments

Comments
 (0)