From e3ddc6f779bd2ae8cfd725913bbf7464332cd26b Mon Sep 17 00:00:00 2001 From: Simon Date: Tue, 26 May 2020 10:30:22 +0200 Subject: [PATCH] fix: load spawn from players.json as fallback --- .../de/cliffbreak/varo/managers/TeamManager.java | 14 ++++++++++++++ .../de/cliffbreak/varo/uitls/PlayerCache.java | 15 +++++++++++---- 2 files changed, 25 insertions(+), 4 deletions(-) diff --git a/varo/src/main/java/de/cliffbreak/varo/managers/TeamManager.java b/varo/src/main/java/de/cliffbreak/varo/managers/TeamManager.java index 11a108c..4a4918c 100644 --- a/varo/src/main/java/de/cliffbreak/varo/managers/TeamManager.java +++ b/varo/src/main/java/de/cliffbreak/varo/managers/TeamManager.java @@ -183,6 +183,20 @@ public class TeamManager { return false; } + public JSONObject getPlayerSpawn(final String uuid) { + final JSONArray jsonTeams = config.getArray("teams"); + for (final Object jsonRawTeam : jsonTeams) { + final JSONObject jsonTeam = (JSONObject) jsonRawTeam; + for (final Object rawPlayer : ((JSONArray) jsonTeam.get("players"))) { + final JSONObject jsonPlayer = (JSONObject) rawPlayer; + if (jsonPlayer.get("uuid").equals(uuid)) { + return (JSONObject) jsonPlayer.get("spawn"); + } + } + } + return null; + } + @SuppressWarnings("unchecked") private HashMap getDefaults() { final HashMap defaults = new HashMap(); diff --git a/varo/src/main/java/de/cliffbreak/varo/uitls/PlayerCache.java b/varo/src/main/java/de/cliffbreak/varo/uitls/PlayerCache.java index bec116b..20f59fd 100644 --- a/varo/src/main/java/de/cliffbreak/varo/uitls/PlayerCache.java +++ b/varo/src/main/java/de/cliffbreak/varo/uitls/PlayerCache.java @@ -5,6 +5,7 @@ import org.bukkit.Location; import org.bukkit.World; import org.bukkit.World.Environment; import org.bukkit.inventory.MainHand; +import org.json.simple.JSONObject; import de.cliffbreak.varo.Varo; @@ -32,13 +33,19 @@ public class PlayerCache { public Location getPlayerLocationCache(final String uuid) { if ((String) this.plugin.getDatabase().getPlayerCache(uuid, PlayerCacheType.WORLD.toString().toLowerCase()) == null) { - for (final World world : Bukkit.getWorlds()) { - if (world.getEnvironment().equals(Environment.NORMAL)) - return world.getSpawnLocation(); + JSONObject jsonSpawn = this.plugin.getTeamManager().getPlayerSpawn(uuid); + if (jsonSpawn == null) { + for (final World world : Bukkit.getWorlds()) { + if (world.getEnvironment().equals(Environment.NORMAL)) + return world.getSpawnLocation(); + } + } else { + return new Location(Bukkit.getWorld((String) jsonSpawn.get("world")), (double) jsonSpawn.get("x"), + (double) jsonSpawn.get("y"), (double) jsonSpawn.get("z"), + ((Double) jsonSpawn.get("yaw")).floatValue(), ((Double) jsonSpawn.get("pitch")).floatValue()); } return null; } else { - return new Location( Bukkit.getWorld((String) this.plugin.getDatabase().getPlayerCache(uuid, PlayerCacheType.WORLD.toString().toLowerCase())),