Skip to content

Commit 7fb9a36

Browse files
committed
Ensure BlockUtil has NPE checks on player profiles
1 parent c792874 commit 7fb9a36

1 file changed

Lines changed: 12 additions & 10 deletions

File tree

src/main/java/dev/espi/protectionstones/utils/BlockUtil.java

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -69,12 +69,15 @@ public static String getProtectBlockType(ItemStack i) {
6969

7070
// PLAYER_HEAD:base64
7171
PlayerProfile offlineProfile = sm.getOwnerProfile();
72-
if (ProtectionStones.getBlockOptions("PLAYER_HEAD:" +offlineProfile.getUniqueId()) != null) {
73-
return Material.PLAYER_HEAD + ":" +offlineProfile.getUniqueId();
72+
if (offlineProfile == null) {
73+
return Material.PLAYER_HEAD.toString();
74+
}
75+
if (ProtectionStones.getBlockOptions("PLAYER_HEAD:" + offlineProfile.getUniqueId()) != null) {
76+
return Material.PLAYER_HEAD + ":" + offlineProfile.getUniqueId();
7477
}
7578

7679
// PLAYER_HEAD:name
77-
return Material.PLAYER_HEAD + ":" + offlineProfile.getName(); // return name if it doesn't exist
80+
return Material.PLAYER_HEAD + ":" + offlineProfile.getName();
7881
}
7982
return i.getType().toString();
8083
}
@@ -85,16 +88,15 @@ public static String getProtectBlockType(Block block) {
8588
Skull s = (Skull) block.getState();
8689
if (s.hasOwner() && isOwnedSkullTypeConfigured()) {
8790
PlayerProfile offlineProfile = s.getOwnerProfile();
91+
if (offlineProfile == null) {
92+
return Material.PLAYER_HEAD.toString();
93+
}
8894
if (ProtectionStones.getBlockOptions("PLAYER_HEAD:" + offlineProfile.getUniqueId()) != null) {
89-
// PLAYER_HEAD:base64
9095
return Material.PLAYER_HEAD + ":" + offlineProfile.getUniqueId();
91-
} else {
92-
// PLAYER_HEAD:name
93-
return Material.PLAYER_HEAD + ":" + offlineProfile.getName(); // return name if doesn't exist
9496
}
95-
} else { // PLAYER_HEAD
96-
return Material.PLAYER_HEAD.toString();
97+
return Material.PLAYER_HEAD + ":" + offlineProfile.getName();
9798
}
99+
return Material.PLAYER_HEAD.toString();
98100
} else if (block.getType() == Material.CREEPER_WALL_HEAD) {
99101
return Material.CREEPER_HEAD.toString();
100102
} else if (block.getType() == Material.DRAGON_WALL_HEAD) {
@@ -201,4 +203,4 @@ public static String getUUIDFromBase64PS(PSProtectBlock b) {
201203
// see github issue #126
202204
return new UUID(base64.hashCode(), base64.hashCode()).toString();
203205
}
204-
}
206+
}

0 commit comments

Comments
 (0)