Multiple start locations; resolves #16

This commit is contained in:
Daniel Saukel 2016-06-19 23:26:24 +02:00
parent 973297b2cc
commit cea08e440d
5 changed files with 53 additions and 36 deletions

View File

@ -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)));
}
}

View File

@ -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.

View File

@ -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!

View File

@ -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);
}

View File

@ -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);
// Try the matching location
for (DSign dSign : dSigns) {
if (dSign.getType() == DSignTypeDefault.START) {
if (((StartSign) dSign).getId() == index) {
return dSign.getSign().getLocation();
}
}
}
/**
* @param location
* the location to start to set
*/
public void setStartLocation(Location location) {
this.locStart = location;
// 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();
}
/**