diff --git a/src/com/dre/dungeonsxl/DPlayer.java b/src/com/dre/dungeonsxl/DPlayer.java index 5983894a..2ad6717b 100644 --- a/src/com/dre/dungeonsxl/DPlayer.java +++ b/src/com/dre/dungeonsxl/DPlayer.java @@ -102,6 +102,11 @@ public class DPlayer { } } + public void escape() { + remove(this); + this.savePlayer.reset(); + } + public void leave() { remove(this); diff --git a/src/com/dre/dungeonsxl/EditWorld.java b/src/com/dre/dungeonsxl/EditWorld.java index e7575f25..726c929c 100644 --- a/src/com/dre/dungeonsxl/EditWorld.java +++ b/src/com/dre/dungeonsxl/EditWorld.java @@ -105,6 +105,20 @@ public class EditWorld { p.removeDirectory(dir); } + public void deleteNoSave() { + eworlds.remove(this); + for (Player player : this.world.getPlayers()) { + DPlayer dplayer = DPlayer.get(player); + dplayer.leave(); + } + + File dir = new File("DXL_Edit_" + this.id); + p.copyDirectory(dir, new File(p.getDataFolder(), "/dungeons/" + this.dungeonname)); + p.deletenotusingfiles(new File(p.getDataFolder(), "/dungeons/" + this.dungeonname)); + p.getServer().unloadWorld(this.world, true); + p.removeDirectory(dir); + } + // Static public static EditWorld get(World world) { for (EditWorld eworld : eworlds) { diff --git a/src/com/dre/dungeonsxl/LanguageReader.java b/src/com/dre/dungeonsxl/LanguageReader.java index fcde3302..b492579e 100644 --- a/src/com/dre/dungeonsxl/LanguageReader.java +++ b/src/com/dre/dungeonsxl/LanguageReader.java @@ -115,6 +115,7 @@ public class LanguageReader { defaults.put("Help_Cmd_Help", "/dxl help - Zeigt die Hilfeseite an"); defaults.put("Help_Cmd_Invite", "/dxl invite - Ladet einen Spieler dazu ein den Dungeon zu editieren"); defaults.put("Help_Cmd_Leave", "/dxl leave - Verlässt den aktuellen Dungeon"); + defaults.put("Help_Cmd_Escape", "/dxl escape - Verlässt den Dungeon, ohne ihn zu speichern"); defaults.put("Help_Cmd_List", "/dxl list - Zeigt alle Dungeons an"); defaults.put("Help_Cmd_Msg", "/dxl msg '[msg]' - Zeigt oder editiert eine Nachricht"); defaults.put("Help_Cmd_Portal", "/dxl portal - Erstellt ein Portal welches in Dungeons führt"); diff --git a/src/com/dre/dungeonsxl/commands/CMDEscape.java b/src/com/dre/dungeonsxl/commands/CMDEscape.java new file mode 100644 index 00000000..55e57c3b --- /dev/null +++ b/src/com/dre/dungeonsxl/commands/CMDEscape.java @@ -0,0 +1,49 @@ +package com.dre.dungeonsxl.commands; + +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; + +import com.dre.dungeonsxl.DGroup; +import com.dre.dungeonsxl.DPlayer; +import com.dre.dungeonsxl.EditWorld; + +public class CMDEscape extends DCommand { + + public CMDEscape() { + this.command = "escape"; + this.args = 0; + this.help = p.language.get("Help_Cmd_Escape"); + this.isPlayerCommand = true; + } + + @Override + public void onExecute(String[] args, CommandSender sender) { + Player player = (Player) sender; + DPlayer dplayer = DPlayer.get(player); + if (dplayer != null) { + + if (dplayer.isEditing) { + dplayer.escape(); + + EditWorld eworld = EditWorld.get(dplayer.world); + if (eworld != null) { + if (eworld.world.getPlayers().isEmpty()) { + eworld.deleteNoSave(); + } + } + } else { + p.msg(player, p.language.get("Error_LeaveDungeon")); + } + + return; + } else { + DGroup dgroup = DGroup.get(player); + if (dgroup != null) { + dgroup.removePlayer(player); + p.msg(player, p.language.get("Cmd_Leave_Success")); + return; + } + p.msg(player, p.language.get("Error_NotInDungeon")); + } + } +} diff --git a/src/com/dre/dungeonsxl/commands/DCommandRoot.java b/src/com/dre/dungeonsxl/commands/DCommandRoot.java index faa7163c..1f094022 100644 --- a/src/com/dre/dungeonsxl/commands/DCommandRoot.java +++ b/src/com/dre/dungeonsxl/commands/DCommandRoot.java @@ -12,6 +12,7 @@ public class DCommandRoot { public CMDCreate cmdCreate = new CMDCreate(); public CMDSave cmdSave = new CMDSave(); public CMDLeave cmdLeave = new CMDLeave(); + public CMDEscape cmdEscape = new CMDEscape(); public CMDEdit cmdEdit = new CMDEdit(); public CMDPortal cmdPortal = new CMDPortal(); public CMDDeletePortal cmdDeletePortal = new CMDDeletePortal(); @@ -33,6 +34,7 @@ public class DCommandRoot { this.commands.add(cmdCreate); this.commands.add(cmdSave); this.commands.add(cmdLeave); + this.commands.add(cmdEscape); this.commands.add(cmdEdit); this.commands.add(cmdPortal); this.commands.add(cmdDeletePortal);