Skip to content

Commit

Permalink
Completely remove UUID for player heads
Browse files Browse the repository at this point in the history
  • Loading branch information
JNNGL committed Jul 13, 2023
1 parent f04c344 commit cb4d47c
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 34 deletions.
6 changes: 3 additions & 3 deletions src/main/java/net/elytrium/limbohub/Settings.java
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ public static class COMMAND {
Settings.createNodeSequence(MENU.ITEM_DATA.class, ".", "minecraft:black_stained_glass_pane", List.of("minecraft:white_stained_glass_pane"), 1, 15, false, 0, false, "", "", List.of()),
Settings.createNodeSequence(MENU.ITEM_DATA.class, "1", "minecraft:leather_helmet", List.of(), 1, 0, true, 12544467, false, "", "&fOpen another menu", List.of()),
Settings.createNodeSequence(MENU.ITEM_DATA.class, "2", "minecraft:stone", List.of(), 2, 0, false, 0, true, "", "&fServer1", List.of("&r&7This is a server.")),
Settings.createNodeSequence(MENU.ITEM_DATA.class, "3", "minecraft:player_head", List.of("minecraft:experience_bottle"), 1, 0, false, 0, false, "f051234a-8c3d-45d5-8e78-df729dd0da8c;eyJ0ZXh0dXJlcyI6eyJTS0lOIjp7InVybCI6Imh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUvMjcwNWZkOTRhMGM0MzE5MjdmYjRlNjM5YjBmY2ZiNDk3MTdlNDEyMjg1YTAyYjQzOWUwMTEyZGEyMmIyZTJlYyJ9fX0=", "&fWhat is this?", List.of())
Settings.createNodeSequence(MENU.ITEM_DATA.class, "3", "minecraft:player_head", List.of("minecraft:experience_bottle"), 1, 0, false, 0, false, "eyJ0ZXh0dXJlcyI6eyJTS0lOIjp7InVybCI6Imh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUvMjcwNWZkOTRhMGM0MzE5MjdmYjRlNjM5YjBmY2ZiNDk3MTdlNDEyMjg1YTAyYjQzOWUwMTEyZGEyMmIyZTJlYyJ9fX0=", "&fWhat is this?", List.of())
),
List.of(
".........",
Expand Down Expand Up @@ -238,8 +238,8 @@ public static class ITEM_DATA {
public int COLOR = 0;
public boolean ENCHANTED = false;
@Comment({
"Player skin in \"uuid;value\" or \"value\" format",
"You can get these values at https://mineskin.org/ or https://minecraft-heads.com/."
"Player skin value.",
"You can get this value at https://mineskin.org/ or https://minecraft-heads.com/."
})
public String SKULL_OWNER = "";
public String CUSTOM_NAME = "";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,8 @@ private void handleAction(Settings.MAIN.ACTION action) {
break;

case CONNECT_TO_SERVER:
RegisteredServer server = this.plugin.getServer().getServer(action.DATA).orElseThrow();
RegisteredServer server = this.plugin.getServer().getServer(action.DATA).orElseThrow(
() -> new IllegalArgumentException("No such server with name " + action.DATA));
this.player.disconnect(server);
break;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,8 @@

import com.velocitypowered.api.network.ProtocolVersion;
import com.velocitypowered.proxy.protocol.ProtocolUtils;
import java.nio.ByteBuffer;
import java.util.List;
import java.util.UUID;
import java.util.concurrent.ThreadLocalRandom;
import java.util.stream.Stream;
import net.kyori.adventure.nbt.BinaryTagTypes;
import net.kyori.adventure.nbt.CompoundBinaryTag;
import net.kyori.adventure.nbt.ListBinaryTag;
Expand All @@ -40,48 +37,28 @@ public abstract class AbstractItemMeta implements ItemMeta {
private final boolean enchanted;

private final String skinName = "npc" + ThreadLocalRandom.current().nextInt();
private final int[] skinId;
private final String skinValue;


public AbstractItemMeta(boolean hasColor, int color, boolean enchanted, String skullOwner) {
this.hasColor = hasColor;
this.color = color;

if (skullOwner == null || skullOwner.isBlank()) {
this.enchanted = enchanted;
this.skinId = null;
this.hasColor = hasColor;
this.skinValue = null;
return;
} else {
this.enchanted = false;
this.hasColor = false;
}

String uuidString;
if (skullOwner.contains(";")) {
String[] data = skullOwner.split(";", 2);
uuidString = data[0];
this.skinValue = data[1];
} else {
uuidString = "00000000-0000-0000-0000-000000000000";
this.skinValue = skullOwner;
}

if (uuidString.contains(",")) {
this.skinId = Stream.of(uuidString.split(",")).mapToInt(Integer::parseInt).toArray();
if (this.skinId.length != 4) {
throw new IllegalArgumentException("Invalid id array length");
}
} else {
this.skinId = new int[4];

UUID uuid = UUID.fromString(uuidString);
ByteBuffer buffer = ByteBuffer.allocateDirect(16);
buffer.putLong(uuid.getMostSignificantBits());
buffer.putLong(uuid.getLeastSignificantBits());
buffer.flip();
buffer.asIntBuffer().get(this.skinId);
}
}

@Override
Expand Down Expand Up @@ -146,7 +123,6 @@ public CompoundBinaryTag buildNbt(ProtocolVersion protocolVersion) {
if (this.skinValue != null) {
builder.put("SkullOwner",
CompoundBinaryTag.builder()
.putIntArray("Id", this.skinId)
.putString("Name", this.skinName)
.put("Properties",
CompoundBinaryTag.builder()
Expand Down Expand Up @@ -184,10 +160,6 @@ public String getSkinName() {
return this.skinName;
}

public int[] getSkinId() {
return this.skinId;
}

public String getSkinValue() {
return this.skinValue;
}
Expand Down

0 comments on commit cb4d47c

Please sign in to comment.