Always respawn edit players in edit world if they die

This commit is contained in:
Daniel Saukel 2020-08-31 22:39:07 +02:00
parent 7a2ec54945
commit 13c0068add

View File

@ -29,8 +29,8 @@ import de.erethon.dungeonsxl.api.player.GlobalPlayer;
import de.erethon.dungeonsxl.api.player.InstancePlayer; import de.erethon.dungeonsxl.api.player.InstancePlayer;
import de.erethon.dungeonsxl.api.player.PlayerCache; import de.erethon.dungeonsxl.api.player.PlayerCache;
import de.erethon.dungeonsxl.api.player.PlayerGroup; import de.erethon.dungeonsxl.api.player.PlayerGroup;
import de.erethon.dungeonsxl.api.world.EditWorld;
import de.erethon.dungeonsxl.api.world.GameWorld; import de.erethon.dungeonsxl.api.world.GameWorld;
import de.erethon.dungeonsxl.api.world.InstanceWorld;
import de.erethon.dungeonsxl.config.DMessage; import de.erethon.dungeonsxl.config.DMessage;
import de.erethon.dungeonsxl.config.MainConfig; import de.erethon.dungeonsxl.config.MainConfig;
import de.erethon.dungeonsxl.dungeon.DGame; import de.erethon.dungeonsxl.dungeon.DGame;
@ -468,51 +468,41 @@ public class DPlayerListener implements Listener {
return; return;
} }
GlobalPlayer dPlayer = dPlayers.get(player); InstancePlayer instancePlayer = dPlayers.getInstancePlayer(player);
if (dPlayer == null) { if (instancePlayer == null) {
return;
}
InstanceWorld instance = instancePlayer.getInstanceWorld();
if (instance == null) {
return; return;
} }
if (dPlayer instanceof EditPlayer) { GamePlayer gamePlayer = null;
EditWorld editWorld = ((EditPlayer) dPlayer).getEditWorld(); PlayerGroup group = instancePlayer.getGroup();
if (editWorld == null) { Location respawn = null;
return; boolean shouldResetInventory = false;
} if (instancePlayer instanceof GamePlayer) {
gamePlayer = ((GamePlayer) instancePlayer);
if (editWorld.getLobbyLocation() == null) { respawn = gamePlayer.getLastCheckpoint();
event.setRespawnLocation(editWorld.getWorld().getSpawnLocation());
} else {
event.setRespawnLocation(editWorld.getLobbyLocation());
}
} else if (dPlayer instanceof GamePlayer) {
GamePlayer gamePlayer = (GamePlayer) dPlayer;
GameWorld gameWorld = gamePlayer.getGameWorld();
if (gameWorld == null) {
return;
}
PlayerGroup group = dPlayer.getGroup();
Location respawn = gamePlayer.getLastCheckpoint();
if (respawn == null) { if (respawn == null) {
respawn = group.getGameWorld().getStartLocation(group); respawn = group.getGameWorld().getStartLocation(group);
} }
shouldResetInventory = gamePlayer.getGameWorld().getDungeon().getRules().getState(GameRule.RESET_CLASS_INVENTORY_ON_RESPAWN);
boolean shouldResetInventory = gamePlayer.getGameWorld().getDungeon().getRules().getState(GameRule.RESET_CLASS_INVENTORY_ON_RESPAWN);
// Because some plugins set another respawn point, DXL teleports a few ticks later.
event.setRespawnLocation(respawn);
new RespawnTask(player, gamePlayer, respawn, shouldResetInventory).runTaskLater(plugin, 10L);
// Don't forget Doge! // Don't forget Doge!
if (gamePlayer.getWolf() != null) { if (gamePlayer.getWolf() != null) {
gamePlayer.getWolf().teleport(respawn); gamePlayer.getWolf().teleport(respawn);
} }
} }
if (respawn == null) {
respawn = instancePlayer.getInstanceWorld().getLobbyLocation();
}
if (respawn == null) {
respawn = instancePlayer.getInstanceWorld().getWorld().getSpawnLocation();
}
// Because some plugins set another respawn point, DXL teleports a few ticks later.
event.setRespawnLocation(respawn);
new RespawnTask(player, gamePlayer, respawn, shouldResetInventory).runTaskLater(plugin, 10L);
} }
@EventHandler(priority = EventPriority.HIGHEST) @EventHandler(priority = EventPriority.HIGHEST)