diff --git a/src/main/java/me/lokka30/phantomworlds/listeners/player/PlayerChangeWorldListener.java b/src/main/java/me/lokka30/phantomworlds/listeners/player/PlayerChangeWorldListener.java index 9ae302a..97bbdb1 100644 --- a/src/main/java/me/lokka30/phantomworlds/listeners/player/PlayerChangeWorldListener.java +++ b/src/main/java/me/lokka30/phantomworlds/listeners/player/PlayerChangeWorldListener.java @@ -45,7 +45,7 @@ public void onChangeWorld(PlayerChangedWorldEvent event) { //Check if this world has a PhantomWorlds managed spawn. If so, teleport the player there. final String spawnPath = "worlds-to-load." + event.getPlayer().getWorld().getName() + ".spawn"; - if(PhantomWorlds.instance().data.getConfig().contains(spawnPath)) { + if(PhantomWorlds.instance().settings.getConfig().getBoolean("spawning.change", false) && PhantomWorlds.instance().data.getConfig().contains(spawnPath)) { final double x = PhantomWorlds.instance().data.getConfig().getDouble(spawnPath + ".x", event.getPlayer().getWorld().getSpawnLocation().getX()); final double y = PhantomWorlds.instance().data.getConfig().getDouble(spawnPath + ".y", event.getPlayer().getWorld().getSpawnLocation().getY()); final double z = PhantomWorlds.instance().data.getConfig().getDouble(spawnPath + ".z", event.getPlayer().getWorld().getSpawnLocation().getZ()); diff --git a/src/main/java/me/lokka30/phantomworlds/listeners/player/PlayerDeathListener.java b/src/main/java/me/lokka30/phantomworlds/listeners/player/PlayerDeathListener.java index ba2c97d..fdfba9e 100644 --- a/src/main/java/me/lokka30/phantomworlds/listeners/player/PlayerDeathListener.java +++ b/src/main/java/me/lokka30/phantomworlds/listeners/player/PlayerDeathListener.java @@ -18,6 +18,8 @@ */ import me.lokka30.phantomworlds.PhantomWorlds; +import me.lokka30.phantomworlds.misc.Utils; +import org.bukkit.Location; import org.bukkit.event.EventHandler; import org.bukkit.event.Listener; import org.bukkit.event.entity.PlayerDeathEvent; @@ -38,12 +40,13 @@ public PlayerDeathListener(PhantomWorlds plugin) { @EventHandler public void onDeath(PlayerDeathEvent event) { - if(!PhantomWorlds.instance().settings.getConfig().getBoolean("respawn-world", false)) { + if(!PhantomWorlds.instance().settings.getConfig().getBoolean("spawning.respawn-world", false)) { return; } if(event.getEntity().getBedSpawnLocation() == null) { - event.getEntity().teleport(event.getEntity().getWorld().getSpawnLocation()); + + event.getEntity().teleport(Utils.spawn(event.getEntity().getWorld())); } } } \ No newline at end of file diff --git a/src/main/java/me/lokka30/phantomworlds/listeners/player/PlayerJoinListener.java b/src/main/java/me/lokka30/phantomworlds/listeners/player/PlayerJoinListener.java index 809e5bf..4fc5a98 100644 --- a/src/main/java/me/lokka30/phantomworlds/listeners/player/PlayerJoinListener.java +++ b/src/main/java/me/lokka30/phantomworlds/listeners/player/PlayerJoinListener.java @@ -18,6 +18,7 @@ */ import me.lokka30.phantomworlds.PhantomWorlds; +import me.lokka30.phantomworlds.misc.Utils; import org.bukkit.Bukkit; import org.bukkit.Location; import org.bukkit.World; @@ -41,31 +42,16 @@ public PlayerJoinListener(PhantomWorlds plugin) { @EventHandler public void onJoin(PlayerJoinEvent event) { - final String spawnWorld = PhantomWorlds.instance().settings.getConfig().getString("spawn-world", "world"); + final String spawnWorld = PhantomWorlds.instance().settings.getConfig().getString("spawning.default-world", "world"); final World sWorld = Bukkit.getWorld(spawnWorld); if(sWorld == null) { plugin.getLogger().warning("Configured spawn world doesn't exist! Not changing player spawn location."); return; } - final World world = (event.getPlayer().hasPlayedBefore())? event.getPlayer().getWorld() : sWorld; - - //Check if we manage the spawn for the world the player needs to join in. - final String cfgPath = "worlds-to-load." + world.getName() + ".spawn"; - if(PhantomWorlds.instance().data.getConfig().contains(cfgPath)) { - final double x = PhantomWorlds.instance().data.getConfig().getDouble(cfgPath + ".x", world.getSpawnLocation().getX()); - final double y = PhantomWorlds.instance().data.getConfig().getDouble(cfgPath + ".y", world.getSpawnLocation().getY()); - final double z = PhantomWorlds.instance().data.getConfig().getDouble(cfgPath + ".z", world.getSpawnLocation().getZ()); - final float yaw = (float)PhantomWorlds.instance().data.getConfig().getDouble(cfgPath + ".yaw", world.getSpawnLocation().getYaw()); - final float pitch = (float)PhantomWorlds.instance().data.getConfig().getDouble(cfgPath + ".pitch", world.getSpawnLocation().getPitch()); - - event.getPlayer().teleport(new Location(world, x, y, z, yaw, pitch)); - } else { - - //We don't manage so send the player to the spawn world - if(!event.getPlayer().hasPlayedBefore()) { - event.getPlayer().teleport(sWorld.getSpawnLocation()); - } + //We don't manage so send the player to the spawn world + if(!event.getPlayer().hasPlayedBefore()) { + event.getPlayer().teleport(Utils.spawn(sWorld)); } } } \ No newline at end of file diff --git a/src/main/java/me/lokka30/phantomworlds/misc/Utils.java b/src/main/java/me/lokka30/phantomworlds/misc/Utils.java index 79f633a..e27f4ec 100644 --- a/src/main/java/me/lokka30/phantomworlds/misc/Utils.java +++ b/src/main/java/me/lokka30/phantomworlds/misc/Utils.java @@ -4,6 +4,7 @@ import me.lokka30.microlib.messaging.MultiMessage; import me.lokka30.phantomworlds.PhantomWorlds; import org.bukkit.Bukkit; +import org.bukkit.Location; import org.bukkit.World; import org.bukkit.command.CommandExecutor; import org.bukkit.command.CommandSender; @@ -294,7 +295,8 @@ public static void teleportToWorld(@NotNull CommandSender sender, @NotNull Strin worldName = targetPlayer.getWorld().getName(); } - if(Bukkit.getWorld(worldName) == null) { + final World world = Bukkit.getWorld(worldName); + if(world == null) { (new MultiMessage( PhantomWorlds.instance().messages.getConfig() .getStringList("command.phantomworlds.subcommands.common.invalid-world"), @@ -305,9 +307,7 @@ public static void teleportToWorld(@NotNull CommandSender sender, @NotNull Strin ))).send(sender); return; } - - //noinspection ConstantConditions - targetPlayer.teleport(Bukkit.getWorld(worldName).getSpawnLocation()); + targetPlayer.teleport(spawn(world)); (new MultiMessage( PhantomWorlds.instance().messages.getConfig() @@ -320,4 +320,18 @@ public static void teleportToWorld(@NotNull CommandSender sender, @NotNull Strin new MultiMessage.Placeholder("world", worldName, false) ))).send(sender); } + + public static Location spawn(final World world) { + final String cfgPath = "worlds-to-load." + world.getName() + ".spawn"; + if(PhantomWorlds.instance().data.getConfig().contains(cfgPath)) { + final double x = PhantomWorlds.instance().data.getConfig().getDouble(cfgPath + ".x", world.getSpawnLocation().getX()); + final double y = PhantomWorlds.instance().data.getConfig().getDouble(cfgPath + ".y", world.getSpawnLocation().getY()); + final double z = PhantomWorlds.instance().data.getConfig().getDouble(cfgPath + ".z", world.getSpawnLocation().getZ()); + final float yaw = (float)PhantomWorlds.instance().data.getConfig().getDouble(cfgPath + ".yaw", world.getSpawnLocation().getYaw()); + final float pitch = (float)PhantomWorlds.instance().data.getConfig().getDouble(cfgPath + ".pitch", world.getSpawnLocation().getPitch()); + + return new Location(world, x, y, z, yaw, pitch); + } + return world.getSpawnLocation(); + } } \ No newline at end of file diff --git a/src/main/resources/settings.yml b/src/main/resources/settings.yml index 7e42418..0b59b2f 100644 --- a/src/main/resources/settings.yml +++ b/src/main/resources/settings.yml @@ -7,12 +7,18 @@ # Should PW run an update check from the Spigot page on startup? run-update-checker: true -#What is the spawn world for the server? If the player hasn't played before this is the world that -#they will go to. -spawn-world: world +#Configurations relating to spawn controls. +spawning: -#Should players respawn at the world spawn if they don't have a bed? -respawn-world: true + #What is the spawn world for the server? If the player hasn't played before this is the world that + #they will go to. + default-world: world + + #Should players respawn at the world spawn if they don't have a bed? + respawn-world: true + + #Should players be sent to the world spawn each time they change worlds? + change: false #Should worlds deleted be moved to an archive folder in deletedworlds? delete-archive: true