From 6e43b559b6e54c7ace8a20d92588422fbe05c27b Mon Sep 17 00:00:00 2001 From: Daniel Saukel Date: Sat, 21 May 2016 23:33:17 +0200 Subject: [PATCH] Fix /dxl leave outside a dungeon --- .../dungeonsxl/command/LeaveCommand.java | 50 +++++++++---------- 1 file changed, 24 insertions(+), 26 deletions(-) diff --git a/src/main/java/io/github/dre2n/dungeonsxl/command/LeaveCommand.java b/src/main/java/io/github/dre2n/dungeonsxl/command/LeaveCommand.java index 2797ed5b..7e873164 100644 --- a/src/main/java/io/github/dre2n/dungeonsxl/command/LeaveCommand.java +++ b/src/main/java/io/github/dre2n/dungeonsxl/command/LeaveCommand.java @@ -22,6 +22,7 @@ import io.github.dre2n.dungeonsxl.DungeonsXL; import io.github.dre2n.dungeonsxl.config.DMessages; import io.github.dre2n.dungeonsxl.event.dplayer.DPlayerEscapeEvent; import io.github.dre2n.dungeonsxl.event.dplayer.DPlayerLeaveDGroupEvent; +import io.github.dre2n.dungeonsxl.player.DGlobalPlayer; import io.github.dre2n.dungeonsxl.player.DGroup; import io.github.dre2n.dungeonsxl.player.DInstancePlayer; import io.github.dre2n.dungeonsxl.player.DPermissions; @@ -49,12 +50,7 @@ public class LeaveCommand extends BRCommand { public void onExecute(String[] args, CommandSender sender) { Player player = (Player) sender; - if (!(plugin.getDPlayers().getByPlayer(player) instanceof DInstancePlayer)) { - MessageUtil.sendMessage(player, DMessages.ERROR_NOT_IN_DUNGEON.getMessage()); - return; - } - - DInstancePlayer dPlayer = (DInstancePlayer) plugin.getDPlayers().getByPlayer(player); + DGlobalPlayer dPlayer = plugin.getDPlayers().getByPlayer(player); if (GameWorld.getByWorld(player.getWorld()) != null) { if (GameWorld.getByWorld(player.getWorld()).isTutorial()) { @@ -63,28 +59,30 @@ public class LeaveCommand extends BRCommand { } } - if (dPlayer != null) { - DGroup dGroup = DGroup.getByPlayer(player); + DGroup dGroup = DGroup.getByPlayer(player); - DPlayerEscapeEvent dPlayerEscapeEvent = new DPlayerEscapeEvent(dPlayer); - plugin.getServer().getPluginManager().callEvent(dPlayerEscapeEvent); - DPlayerLeaveDGroupEvent dPlayerLeaveDGroupEvent = new DPlayerLeaveDGroupEvent(dPlayer, dGroup); - plugin.getServer().getPluginManager().callEvent(dPlayerLeaveDGroupEvent); - - if (dPlayerEscapeEvent.isCancelled() || dPlayerLeaveDGroupEvent.isCancelled()) { - return; - } - - dPlayer.leave(); - MessageUtil.sendMessage(player, DMessages.CMD_LEAVE_SUCCESS.getMessage()); - - } else { - DGroup dGroup = DGroup.getByPlayer(player); - if (dGroup != null) { - dGroup.removePlayer(player); - MessageUtil.sendMessage(player, DMessages.CMD_LEAVE_SUCCESS.getMessage()); - } + if (dGroup == null) { + MessageUtil.sendMessage(player, DMessages.ERROR_JOIN_GROUP.getMessage()); + return; } + + DPlayerEscapeEvent dPlayerEscapeEvent = new DPlayerEscapeEvent(dPlayer); + plugin.getServer().getPluginManager().callEvent(dPlayerEscapeEvent); + DPlayerLeaveDGroupEvent dPlayerLeaveDGroupEvent = new DPlayerLeaveDGroupEvent(dPlayer, dGroup); + plugin.getServer().getPluginManager().callEvent(dPlayerLeaveDGroupEvent); + + if (dPlayerEscapeEvent.isCancelled() || dPlayerLeaveDGroupEvent.isCancelled()) { + return; + } + + if (dPlayer instanceof DInstancePlayer) { + ((DInstancePlayer) dPlayer).leave(); + } else { + dGroup.removePlayer(player); + } + + MessageUtil.sendMessage(player, DMessages.CMD_LEAVE_SUCCESS.getMessage()); + } }