From 916881e62822f333911ed490d99d63eba7ee3f94 Mon Sep 17 00:00:00 2001 From: DaTTV <104141141+DrFreezyYT@users.noreply.github.com> Date: Sun, 23 Feb 2025 16:10:58 +0100 Subject: [PATCH] fixed homes --- .../blazesmp/command/RestartCommand.java | 1 - .../papermc/blazesmp/command/VanishCommand.java | 4 +--- .../papermc/blazesmp/module/manager/Homes.java | 17 +++++++++++------ src/main/resources/storage/homes.json | 3 ++- 4 files changed, 14 insertions(+), 11 deletions(-) diff --git a/src/main/java/me/freezy/plugins/papermc/blazesmp/command/RestartCommand.java b/src/main/java/me/freezy/plugins/papermc/blazesmp/command/RestartCommand.java index 4fdeeb2..b0c52e1 100644 --- a/src/main/java/me/freezy/plugins/papermc/blazesmp/command/RestartCommand.java +++ b/src/main/java/me/freezy/plugins/papermc/blazesmp/command/RestartCommand.java @@ -8,7 +8,6 @@ import net.kyori.adventure.text.minimessage.MiniMessage; import org.bukkit.Bukkit; import org.bukkit.command.Command; import org.bukkit.command.CommandSender; -import org.bukkit.entity.Player; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; diff --git a/src/main/java/me/freezy/plugins/papermc/blazesmp/command/VanishCommand.java b/src/main/java/me/freezy/plugins/papermc/blazesmp/command/VanishCommand.java index 0774c5d..d36ef93 100644 --- a/src/main/java/me/freezy/plugins/papermc/blazesmp/command/VanishCommand.java +++ b/src/main/java/me/freezy/plugins/papermc/blazesmp/command/VanishCommand.java @@ -17,9 +17,7 @@ import java.util.Map; import java.util.UUID; public class VanishCommand extends SimpleCommand { - private final Map vanishedPlayers = new HashMap(); - - + private final Map vanishedPlayers = new HashMap<>(); public VanishCommand() { diff --git a/src/main/java/me/freezy/plugins/papermc/blazesmp/module/manager/Homes.java b/src/main/java/me/freezy/plugins/papermc/blazesmp/module/manager/Homes.java index 90bfee9..39df583 100644 --- a/src/main/java/me/freezy/plugins/papermc/blazesmp/module/manager/Homes.java +++ b/src/main/java/me/freezy/plugins/papermc/blazesmp/module/manager/Homes.java @@ -43,7 +43,8 @@ public class Homes { } try (FileReader reader = new FileReader(file)) { // Use a TypeToken to handle the Map structure - Type type = new TypeToken>() {}.getType(); + Type type = new TypeToken>() { + }.getType(); Map jsonMap = GSON.fromJson(reader, type); if (jsonMap == null) { return; @@ -58,17 +59,19 @@ public class Homes { } LocationJson locJson = entry.getValue(); // Assume the default world "world" for homes - World world = Bukkit.getWorld("world"); - if (world == null) { - LOGGER.warning("Default world 'world' not found. Skipping home for " + uuid); - continue; - } + try { double x = Double.parseDouble(locJson.x); double y = Double.parseDouble(locJson.y); double z = Double.parseDouble(locJson.z); float yaw = Float.parseFloat(locJson.yaw); float pitch = Float.parseFloat(locJson.pitch); + String worldName = locJson.world; + World world = Bukkit.getWorld(worldName); + if (world == null) { + LOGGER.warning("World '%s' not found. Skipping home for %s".formatted(worldName, uuid)); + continue; + } Location location = new Location(world, x, y, z, yaw, pitch); homes.put(uuid, location); } catch (NumberFormatException ex) { @@ -94,6 +97,7 @@ public class Homes { locJson.z = String.valueOf(location.getZ()); locJson.yaw = String.valueOf(location.getYaw()); locJson.pitch = String.valueOf(location.getPitch()); + locJson.world = location.getWorld().getName(); jsonMap.put(entry.getKey().toString(), locJson); } File file = new File(FILE_PATH); @@ -138,5 +142,6 @@ public class Homes { String z; String yaw; String pitch; + String world; } } diff --git a/src/main/resources/storage/homes.json b/src/main/resources/storage/homes.json index 67d7d5a..8dba881 100644 --- a/src/main/resources/storage/homes.json +++ b/src/main/resources/storage/homes.json @@ -4,6 +4,7 @@ "y": "", "z": "", "yaw": "", - "pitch": "" + "pitch": "", + "world": "" } } \ No newline at end of file