mirror of
https://github.com/DRE2N/DungeonsXL.git
synced 2024-11-02 17:00:19 +01:00
Add resetClassInventoryOnRespawn game rule
This commit is contained in:
parent
1cd7758956
commit
342dffb23e
@ -61,6 +61,10 @@ public class GameRule<V> {
|
||||
* Shall players lose their items when they die (do not mix up this with "onEscape"!)?
|
||||
*/
|
||||
public static final GameRule<Boolean> KEEP_INVENTORY_ON_DEATH = new GameRule<>(Boolean.class, "keepInventoryOnDeath", true);
|
||||
/**
|
||||
* Shall players reset their inventory to their chosen class when respawning?
|
||||
*/
|
||||
public static final GameRule<Boolean> RESET_CLASS_INVENTORY_ON_RESPAWN = new GameRule<>(Boolean.class, "resetClassInventoryOnRespawn", true);
|
||||
/**
|
||||
* The location where the players spawn when they leave the dungeon without succeeding.
|
||||
*/
|
||||
|
@ -72,6 +72,7 @@ public class DGamePlayer extends DInstancePlayer implements GamePlayer {
|
||||
private Wolf wolf;
|
||||
private int wolfRespawnTime = 30;
|
||||
private long offlineTime;
|
||||
private boolean resetClassInventoryOnRespawn;
|
||||
|
||||
private int initialLives = -1;
|
||||
private int lives;
|
||||
@ -105,6 +106,8 @@ public class DGamePlayer extends DInstancePlayer implements GamePlayer {
|
||||
initialLives = rules.getState(GameRule.INITIAL_LIVES);
|
||||
lives = initialLives;
|
||||
|
||||
resetClassInventoryOnRespawn = rules.getState(GameRule.RESET_CLASS_INVENTORY_ON_RESPAWN);
|
||||
|
||||
Location teleport = world.getLobbyLocation();
|
||||
if (teleport == null) {
|
||||
PlayerUtil.secureTeleport(player, world.getWorld().getSpawnLocation());
|
||||
@ -532,9 +535,13 @@ public class DGamePlayer extends DInstancePlayer implements GamePlayer {
|
||||
|
||||
PlayerUtil.secureTeleport(getPlayer(), respawn);
|
||||
|
||||
// Don't forget Doge!
|
||||
if (wolf != null) {
|
||||
wolf.teleport(getPlayer());
|
||||
if (resetClassInventoryOnRespawn) {
|
||||
setPlayerClass(dClass);
|
||||
} else {
|
||||
// Don't forget Doge!
|
||||
if (wolf != null) {
|
||||
wolf.teleport(getPlayer());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -659,6 +666,10 @@ public class DGamePlayer extends DInstancePlayer implements GamePlayer {
|
||||
getWolf().teleport(respawn);
|
||||
}
|
||||
|
||||
if (rules.getState(GameRule.RESET_CLASS_INVENTORY_ON_RESPAWN)) {
|
||||
setPlayerClass(dClass);
|
||||
}
|
||||
|
||||
} else if (config.areGlobalDeathMessagesDisabled()) {
|
||||
event.setDeathMessage(null);
|
||||
}
|
||||
|
@ -499,8 +499,11 @@ public class DPlayerListener implements Listener {
|
||||
respawn = group.getGameWorld().getStartLocation(group);
|
||||
}
|
||||
|
||||
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.
|
||||
new RespawnTask(player, respawn).runTaskLater(plugin, 10L);
|
||||
event.setRespawnLocation(respawn);
|
||||
new RespawnTask(player, gamePlayer, respawn, shouldResetInventory).runTaskLater(plugin, 10L);
|
||||
|
||||
// Don't forget Doge!
|
||||
if (gamePlayer.getWolf() != null) {
|
||||
|
@ -17,6 +17,7 @@
|
||||
package de.erethon.dungeonsxl.player;
|
||||
|
||||
import de.erethon.commons.player.PlayerUtil;
|
||||
import de.erethon.dungeonsxl.api.player.GamePlayer;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.scheduler.BukkitRunnable;
|
||||
@ -27,11 +28,15 @@ import org.bukkit.scheduler.BukkitRunnable;
|
||||
public class RespawnTask extends BukkitRunnable {
|
||||
|
||||
private Player player;
|
||||
private GamePlayer dPlayer;
|
||||
private Location location;
|
||||
private boolean resetClassInventory;
|
||||
|
||||
public RespawnTask(Player player, Location location) {
|
||||
public RespawnTask(Player player, GamePlayer dPlayer, Location location, boolean resetClassInventory) {
|
||||
this.location = location;
|
||||
this.player = player;
|
||||
this.dPlayer = dPlayer;
|
||||
this.resetClassInventory = resetClassInventory;
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -42,6 +47,9 @@ public class RespawnTask extends BukkitRunnable {
|
||||
if (player.getWorld() != location.getWorld() || player.getLocation().distance(location) > 2) {
|
||||
PlayerUtil.secureTeleport(player, location);
|
||||
}
|
||||
if (resetClassInventory) {
|
||||
dPlayer.setPlayerClass(dPlayer.getPlayerClass());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user