Skip to content

Commit 8eb29af

Browse files
committed
fix: proper null checks while recovering world in admin state
1 parent 2968016 commit 8eb29af

2 files changed

Lines changed: 12 additions & 1 deletion

File tree

src/main/java/org/modernbeta/admintoolbox/managers/admin/AdminManager.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,11 @@ public void restore(Player player) {
126126
Location originalLocation = adminState.getTeleportHistory().getOriginalLocation();
127127
ItemStack[] originalInventory = adminState.getSavedInventory();
128128

129+
if (originalLocation == null) {
130+
plugin.getLogger().warning("Restore location was null for " + player.getName() + ". Falling back to server spawn.");
131+
originalLocation = Bukkit.getWorlds().getFirst().getSpawnLocation();
132+
}
133+
129134
player.teleportAsync(originalLocation).thenAccept((didTeleport) -> {
130135
if (!didTeleport) {
131136
player.sendRichMessage("<red>Error: Could not teleport you back to your original location.");

src/main/java/org/modernbeta/admintoolbox/managers/admin/AdminState.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,14 +107,20 @@ static AdminState fromConfig(Player player, ConfigurationSection playerSection)
107107
if (playerSection.isConfigurationSection("original_location")) {
108108
ConfigurationSection locSection = playerSection.getConfigurationSection("original_location");
109109
if (locSection != null) {
110-
World world = Bukkit.getWorld(locSection.getString("world"));
110+
String worldName = locSection.getString("world");
111+
World world = Bukkit.getWorld(worldName);
111112
if (world != null) {
112113
double x = locSection.getDouble("x");
113114
double y = locSection.getDouble("y");
114115
double z = locSection.getDouble("z");
115116
float yaw = (float) locSection.getDouble("yaw");
116117
float pitch = (float) locSection.getDouble("pitch");
117118
history = new TeleportHistory<>(new Location(world, x, y, z, yaw, pitch));
119+
} else {
120+
AdminToolboxPlugin.getInstance().getLogger().warning(
121+
String.format("Could not restore original location for %s — world '%s' not found. Falling back to server spawn.", playerId, worldName)
122+
);
123+
history = new TeleportHistory<>(Bukkit.getWorlds().get(0).getSpawnLocation());
118124
}
119125
}
120126
}

0 commit comments

Comments
 (0)