Skip to content

Commit 9a45227

Browse files
committed
Add null check back in to prevent NPE
1 parent ba2c4ca commit 9a45227

File tree

1 file changed

+29
-27
lines changed

1 file changed

+29
-27
lines changed

src/main/java/world/bentobox/stranger/StrangerRealms.java

Lines changed: 29 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ public class StrangerRealms extends GameModeAddon {
5555

5656
private static final String NETHER = "_nether";
5757
private static final String THE_END = "_the_end";
58-
58+
5959
// Define a static key for the custom item, primarily for referencing its material later if needed.
6060
public static final Material WARPED_COMPASS_MATERIAL = Material.COMPASS;
6161

@@ -75,7 +75,7 @@ public class StrangerRealms extends GameModeAddon {
7575
public boolean isFixIslandCenter() {
7676
return false;
7777
}
78-
78+
7979
@Override
8080
public boolean isEnforceEqualRanges() {
8181
return false;
@@ -89,7 +89,7 @@ public void onLoad() {
8989
loadSettings();
9090
// Create the nether chunk listener; set it up in onEnable
9191
netherChunkMaker = new NetherChunkMaker(this);
92-
92+
9393
// Register commands
9494
playerCommand = new DefaultPlayerCommand(this) {
9595
@Override
@@ -141,10 +141,10 @@ public void onEnable() {
141141
this.registerListener(netherChunkMaker);
142142
this.registerListener(new TeamListener(this));
143143
this.registerListener(new NetherRedstoneListener(this));
144-
144+
145145
// Register recipe for warped compass
146146
registerWarpedCompassRecipe();
147-
147+
148148
// Set the initial spawn
149149
if (getPlugin().getIslands().getSpawn(getOverWorld()).isEmpty()) {
150150
// Make a spawn claim
@@ -296,12 +296,12 @@ public BorderShower getBorderShower() {
296296
*/
297297
public double getBorderSize() {
298298
int newBorderSize = getSettings().isManualBorderSize() ? borderSize :
299-
Math.max(getSettings().getBarrierIncreaseBlocks(), (this.getSettings().getBarrierIncreaseBlocks() * Bukkit.getServer().getOnlinePlayers().size()));
300-
if (newBorderSize < borderSize) {
301-
// End any current task to replace it
302-
task.cancel();
303-
// Trigger gradual reduction of border
304-
task = Bukkit.getScheduler().runTaskTimer(getPlugin(), () -> {
299+
Math.max(getSettings().getBarrierIncreaseBlocks(), (this.getSettings().getBarrierIncreaseBlocks() * Bukkit.getServer().getOnlinePlayers().size()));
300+
if (newBorderSize < borderSize) {
301+
// End any current task to replace it
302+
task.cancel();
303+
// Trigger gradual reduction of border
304+
task = Bukkit.getScheduler().runTaskTimer(getPlugin(), () -> {
305305
if (borderSize > newBorderSize) {
306306
borderSize--;
307307
// Update the border for any online players
@@ -323,14 +323,16 @@ public double getBorderSize() {
323323
public void setBorderSize(int borderSize) {
324324
this.borderSize = borderSize;
325325
}
326-
326+
327327
/**
328328
* Cancels any active border reduction task
329329
*/
330330
public void cancelBorderTask() {
331-
this.task.cancel();
331+
if (task != null) {
332+
this.task.cancel();
333+
}
332334
}
333-
335+
334336
/**
335337
* Creates a new ItemStack representing the Warped Compass with all its custom metadata.
336338
* This method is used both for the recipe result and for checking items.
@@ -342,21 +344,21 @@ public static ItemStack createWarpedCompassItem() {
342344

343345
// Set the custom display name using the Adventure API
344346
Component displayName = Component.text("Warped Compass", NamedTextColor.AQUA)
345-
.decorate(TextDecoration.BOLD);
347+
.decorate(TextDecoration.BOLD);
346348
meta.displayName(displayName);
347349

348350
// Set the lore/tooltip using the Adventure API
349351
List<Component> lore = Arrays.asList(
350-
Component.text("Hold fast to the needle when the realm is stale.", NamedTextColor.GRAY),
351-
Component.text("A single spark is all it takes to refresh the flame.", NamedTextColor.GRAY),
352-
Component.empty(), // Represents an empty line
353-
Component.text("Consumed upon entry to re-thread the Nether.", NamedTextColor.RED)
354-
);
352+
Component.text("Hold fast to the needle when the realm is stale.", NamedTextColor.GRAY),
353+
Component.text("A single spark is all it takes to refresh the flame.", NamedTextColor.GRAY),
354+
Component.empty(), // Represents an empty line
355+
Component.text("Consumed upon entry to re-thread the Nether.", NamedTextColor.RED)
356+
);
355357
meta.lore(lore);
356358
warpedCompass.setItemMeta(meta);
357359
return warpedCompass;
358360
}
359-
361+
360362
/**
361363
* Checks if the given ItemStack is a Warped Compass based on its material and metadata.
362364
* @param item The ItemStack to check.
@@ -371,7 +373,7 @@ public static boolean isWarpedCompass(ItemStack item) {
371373
// We compare the item's meta against the meta of a freshly created reference item.
372374
ItemMeta referenceMeta = createWarpedCompassItem().getItemMeta();
373375
ItemMeta itemMeta = item.getItemMeta();
374-
376+
375377
return itemMeta.equals(referenceMeta);
376378
}
377379

@@ -387,11 +389,11 @@ private void registerWarpedCompassRecipe() {
387389

388390
// --- 3. Define the Recipe Shape ---
389391
recipe.shape(
390-
"COC",
391-
"FRF",
392-
"COC"
393-
);
394-
392+
"COC",
393+
"FRF",
394+
"COC"
395+
);
396+
395397
// --- 4. Define the Ingredients ---
396398
// O = Obsidian
397399
// C = Crying Obsidian

0 commit comments

Comments
 (0)