Permalink
Browse files

Added a configuration option to teleport players to the middle of the…

… spawn block when using /spawn

Implements CMDBOOK-2410
  • Loading branch information...
DarkArc committed Jul 20, 2014
1 parent 936973f commit beedb169c513e48fa4ff394cfa298f4628e2e799
Showing with 11 additions and 4 deletions.
  1. +11 −4 src/main/java/com/sk89q/commandbook/locations/SpawnLocationsComponent.java
@@ -71,14 +71,21 @@ public WrappedSpawnManager getSpawnManager() {
return spawns;
}
public Location getSpawnPoint(World world) {
Location target = spawns.getWorldSpawn(world);
if (config.centeredTeleport) target.add(.5, 0, .5);
return target;
}
private static class LocalConfiguration extends ConfigurationBase {
@Setting("exact-spawn") public boolean exactSpawn;
@Setting("centered-teleport") public boolean centeredTeleport;
}
@EventHandler
public void onRespawn(PlayerRespawnEvent event) {
if (config.exactSpawn && !event.isBedSpawn()) {
event.setRespawnLocation(spawns.getWorldSpawn(event.getPlayer().getWorld()));
event.setRespawnLocation(getSpawnPoint(event.getPlayer().getWorld()));
}
}
@@ -94,14 +101,14 @@ public void onTeleport(PlayerTeleportEvent event) {
return;
}
if (loc.equals(loc.getWorld().getSpawnLocation())) {
event.setTo(spawns.getWorldSpawn(loc.getWorld()));
event.setTo(getSpawnPoint(loc.getWorld()));
}
}
@EventHandler
public void onJoin(PlayerJoinEvent event) {
if (!event.getPlayer().hasPlayedBefore() && config.exactSpawn) {
event.getPlayer().teleport(spawns.getWorldSpawn(event.getPlayer().getWorld()));
event.getPlayer().teleport(getSpawnPoint(event.getPlayer().getWorld()));
}
}
@@ -130,7 +137,7 @@ public void spawn(CommandContext args, CommandSender sender) throws CommandExcep
@Override
public boolean perform(Player player) {
return PlayerUtil.teleportTo(sender, player, getSpawnManager().getWorldSpawn(player.getWorld()), true);
return PlayerUtil.teleportTo(sender, player, getSpawnPoint(player.getWorld()), true);
}
@Override

0 comments on commit beedb16

Please sign in to comment.