fix: load spawn from players.json as fallback

This commit is contained in:
Simon Giesel 2020-05-26 10:30:22 +02:00
parent 5513aac4b5
commit e3ddc6f779
2 changed files with 25 additions and 4 deletions

View file

@ -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<String, Object> getDefaults() {
final HashMap<String, Object> defaults = new HashMap<String, Object>();

View file

@ -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) {
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())),