Skip to content

Commit

Permalink
Fix NPE when reading skull-owner uuidInts
Browse files Browse the repository at this point in the history
  • Loading branch information
TBlueF committed Jun 4, 2024
1 parent cca1fbc commit 7895222
Showing 1 changed file with 12 additions and 34 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,15 @@
*/
package de.bluecolored.bluemap.core.world.block.entity;

import lombok.Getter;
import org.jetbrains.annotations.Nullable;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.UUID;

@Getter
public class SkullBlockEntity extends BlockEntity {
private final @Nullable String noteBlockSound;
private final @Nullable String extraType;
Expand All @@ -47,18 +49,6 @@ protected SkullBlockEntity(Map<String, Object> data) {
this.skullOwner = ownerData != null ? new SkullOwner(ownerData) : null;
}

public @Nullable String getNoteBlockSound() {
return noteBlockSound;
}

public @Nullable String getExtraType() {
return extraType;
}

public SkullOwner getSkullOwner() {
return skullOwner;
}

@Override
public String toString() {
return "SkullBlockEntity{" +
Expand All @@ -68,15 +58,22 @@ public String toString() {
"} " + super.toString();
}

@Getter
public static class SkullOwner {
private final @Nullable UUID id;
private final @Nullable String name;
private final List<Texture> textures = new ArrayList<>();

@SuppressWarnings("unchecked")
private SkullOwner(Map<String, Object> data) {
int[] uuidInts = (int[]) data.get("Id");
this.id = new UUID((long) uuidInts[0] << 32 | uuidInts[1], (long) uuidInts[2] << 32 | uuidInts[3]);
int @Nullable [] uuidInts = (int[]) data.get("Id");

if (uuidInts == null || uuidInts.length != 4) {
this.id = null;
} else {
this.id = new UUID((long) uuidInts[0] << 32 | uuidInts[1], (long) uuidInts[2] << 32 | uuidInts[3]);
}

this.name = (String) data.get("Name");

Map<String, Object> properties = (Map<String, Object>) data.getOrDefault("Properties", Map.of());
Expand All @@ -87,18 +84,6 @@ private SkullOwner(Map<String, Object> data) {
}
}

public UUID getId() {
return id;
}

public String getName() {
return name;
}

public List<Texture> getTextures() {
return textures;
}

@Override
public String toString() {
return "SkullOwner{" +
Expand All @@ -109,6 +94,7 @@ public String toString() {
}
}

@Getter
public static class Texture {
private final @Nullable String signature;
private final String value;
Expand All @@ -118,14 +104,6 @@ private Texture(Map<String, Object> data) {
this.value = (String) data.getOrDefault("value", "");
}

public String getSignature() {
return signature;
}

public String getValue() {
return value;
}

@Override
public String toString() {
return "Texture{" +
Expand Down

0 comments on commit 7895222

Please sign in to comment.