diff --git a/src/main/java/io/github/dre2n/dungeonsxl/game/Game.java b/src/main/java/io/github/dre2n/dungeonsxl/game/Game.java index 912b40ab..f92abacb 100644 --- a/src/main/java/io/github/dre2n/dungeonsxl/game/Game.java +++ b/src/main/java/io/github/dre2n/dungeonsxl/game/Game.java @@ -381,7 +381,7 @@ public class Game { public void run() { if (teleport) { for (Player player : getPlayers()) { - PlayerUtil.secureTeleport(player, world.getStartLocation()); + PlayerUtil.secureTeleport(player, world.getStartLocation(DGroup.getByPlayer(player))); } } diff --git a/src/main/java/io/github/dre2n/dungeonsxl/listener/PlayerListener.java b/src/main/java/io/github/dre2n/dungeonsxl/listener/PlayerListener.java index f3e2685d..dd443e1b 100644 --- a/src/main/java/io/github/dre2n/dungeonsxl/listener/PlayerListener.java +++ b/src/main/java/io/github/dre2n/dungeonsxl/listener/PlayerListener.java @@ -398,15 +398,7 @@ public class PlayerListener implements Listener { Location respawn = gamePlayer.getCheckpoint(); if (respawn == null) { - respawn = dGroup.getGameWorld().getStartLocation(); - } - - if (respawn == null) { - respawn = dGroup.getGameWorld().getLobbyLocation(); - } - - if (respawn == null) { - respawn = dGroup.getGameWorld().getWorld().getSpawnLocation(); + respawn = dGroup.getGameWorld().getStartLocation(dGroup); } // Because some plugins set another respawn point, DXL teleports a few ticks later. diff --git a/src/main/java/io/github/dre2n/dungeonsxl/player/DGamePlayer.java b/src/main/java/io/github/dre2n/dungeonsxl/player/DGamePlayer.java index 65b18931..30d8a84e 100644 --- a/src/main/java/io/github/dre2n/dungeonsxl/player/DGamePlayer.java +++ b/src/main/java/io/github/dre2n/dungeonsxl/player/DGamePlayer.java @@ -596,11 +596,7 @@ public class DGamePlayer extends DInstancePlayer { Location respawn = checkpoint; if (respawn == null) { - respawn = dGroup.getGameWorld().getStartLocation(); - } - - if (respawn == null) { - respawn = dGroup.getGameWorld().getLobbyLocation(); + respawn = dGroup.getGameWorld().getStartLocation(dGroup); } if (respawn == null) { @@ -693,7 +689,7 @@ public class DGamePlayer extends DInstancePlayer { for (Player player : dGroup.getPlayers()) { DGamePlayer dPlayer = getByPlayer(player); dPlayer.setWorld(gameWorld.getWorld()); - dPlayer.setCheckpoint(dGroup.getGameWorld().getStartLocation()); + dPlayer.setCheckpoint(dGroup.getGameWorld().getStartLocation(dGroup)); if (dPlayer.getWolf() != null) { dPlayer.getWolf().teleport(dPlayer.getCheckpoint()); } @@ -816,15 +812,7 @@ public class DGamePlayer extends DInstancePlayer { teleportLocation = getCheckpoint(); if (teleportLocation == null) { - teleportLocation = dGroup.getGameWorld().getStartLocation(); - } - - if (teleportLocation == null) { - teleportLocation = dGroup.getGameWorld().getLobbyLocation(); - } - - if (teleportLocation == null) { - teleportLocation = getWorld().getSpawnLocation(); + teleportLocation = dGroup.getGameWorld().getStartLocation(dGroup); } // Don't forget Doge! diff --git a/src/main/java/io/github/dre2n/dungeonsxl/sign/StartSign.java b/src/main/java/io/github/dre2n/dungeonsxl/sign/StartSign.java index 8d3935ea..1f435b10 100644 --- a/src/main/java/io/github/dre2n/dungeonsxl/sign/StartSign.java +++ b/src/main/java/io/github/dre2n/dungeonsxl/sign/StartSign.java @@ -16,6 +16,7 @@ */ package io.github.dre2n.dungeonsxl.sign; +import io.github.dre2n.commons.util.NumberUtil; import io.github.dre2n.dungeonsxl.world.GameWorld; import org.bukkit.Material; import org.bukkit.block.Sign; @@ -27,10 +28,29 @@ public class StartSign extends DSign { private DSignType type = DSignTypeDefault.START; + private int id; + public StartSign(Sign sign, String[] lines, GameWorld gameWorld) { super(sign, lines, gameWorld); } + /* Getters and setters */ + /** + * @return the ID + */ + public int getId() { + return id; + } + + /** + * @param id + * the ID to set + */ + public void setId(int id) { + this.id = id; + } + + /* Actions */ @Override public boolean check() { return true; @@ -38,7 +58,7 @@ public class StartSign extends DSign { @Override public void onInit() { - getGameWorld().setStartLocation(getSign().getLocation()); + id = NumberUtil.parseInt(lines[1]); getSign().getBlock().setType(Material.AIR); } diff --git a/src/main/java/io/github/dre2n/dungeonsxl/world/GameWorld.java b/src/main/java/io/github/dre2n/dungeonsxl/world/GameWorld.java index 2d3bf546..c54cb92d 100644 --- a/src/main/java/io/github/dre2n/dungeonsxl/world/GameWorld.java +++ b/src/main/java/io/github/dre2n/dungeonsxl/world/GameWorld.java @@ -29,10 +29,12 @@ import io.github.dre2n.dungeonsxl.game.Game; import io.github.dre2n.dungeonsxl.game.GamePlaceableBlock; import io.github.dre2n.dungeonsxl.mob.DMob; import io.github.dre2n.dungeonsxl.player.DGamePlayer; +import io.github.dre2n.dungeonsxl.player.DGroup; import io.github.dre2n.dungeonsxl.reward.RewardChest; import io.github.dre2n.dungeonsxl.sign.DSign; +import io.github.dre2n.dungeonsxl.sign.DSignTypeDefault; import io.github.dre2n.dungeonsxl.sign.MobSign; -import io.github.dre2n.dungeonsxl.trigger.MobTrigger; +import io.github.dre2n.dungeonsxl.sign.StartSign; import io.github.dre2n.dungeonsxl.trigger.ProgressTrigger; import io.github.dre2n.dungeonsxl.trigger.RedstoneTrigger; import io.github.dre2n.dungeonsxl.trigger.Trigger; @@ -203,16 +205,31 @@ public class GameWorld { /** * @return the start location */ - public Location getStartLocation() { - return locStart; - } + public Location getStartLocation(DGroup dGroup) { + int index = getGame().getDGroups().indexOf(dGroup); - /** - * @param location - * the location to start to set - */ - public void setStartLocation(Location location) { - this.locStart = location; + // Try the matching location + for (DSign dSign : dSigns) { + if (dSign.getType() == DSignTypeDefault.START) { + if (((StartSign) dSign).getId() == index) { + return dSign.getSign().getLocation(); + } + } + } + + // Try any location + for (DSign dSign : dSigns) { + if (dSign.getType() == DSignTypeDefault.START) { + return dSign.getSign().getLocation(); + } + } + + // Lobby location as fallback + if (locLobby != null) { + return locLobby; + } + + return world.getSpawnLocation(); } /**