/dxl escape: leave without saving

This commit is contained in:
Sn0wStorm 2013-06-27 17:48:56 +02:00
parent 800e97adc1
commit f97db1ed19
5 changed files with 71 additions and 0 deletions

View File

@ -102,6 +102,11 @@ public class DPlayer {
} }
} }
public void escape() {
remove(this);
this.savePlayer.reset();
}
public void leave() { public void leave() {
remove(this); remove(this);

View File

@ -105,6 +105,20 @@ public class EditWorld {
p.removeDirectory(dir); 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 // Static
public static EditWorld get(World world) { public static EditWorld get(World world) {
for (EditWorld eworld : eworlds) { for (EditWorld eworld : eworlds) {

View File

@ -115,6 +115,7 @@ public class LanguageReader {
defaults.put("Help_Cmd_Help", "/dxl help - Zeigt die Hilfeseite an"); defaults.put("Help_Cmd_Help", "/dxl help - Zeigt die Hilfeseite an");
defaults.put("Help_Cmd_Invite", "/dxl invite <player> <dungeon> - Ladet einen Spieler dazu ein den Dungeon zu editieren"); defaults.put("Help_Cmd_Invite", "/dxl invite <player> <dungeon> - 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_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_List", "/dxl list - Zeigt alle Dungeons an");
defaults.put("Help_Cmd_Msg", "/dxl msg <id> '[msg]' - Zeigt oder editiert eine Nachricht"); defaults.put("Help_Cmd_Msg", "/dxl msg <id> '[msg]' - Zeigt oder editiert eine Nachricht");
defaults.put("Help_Cmd_Portal", "/dxl portal - Erstellt ein Portal welches in Dungeons führt"); defaults.put("Help_Cmd_Portal", "/dxl portal - Erstellt ein Portal welches in Dungeons führt");

View File

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

View File

@ -12,6 +12,7 @@ public class DCommandRoot {
public CMDCreate cmdCreate = new CMDCreate(); public CMDCreate cmdCreate = new CMDCreate();
public CMDSave cmdSave = new CMDSave(); public CMDSave cmdSave = new CMDSave();
public CMDLeave cmdLeave = new CMDLeave(); public CMDLeave cmdLeave = new CMDLeave();
public CMDEscape cmdEscape = new CMDEscape();
public CMDEdit cmdEdit = new CMDEdit(); public CMDEdit cmdEdit = new CMDEdit();
public CMDPortal cmdPortal = new CMDPortal(); public CMDPortal cmdPortal = new CMDPortal();
public CMDDeletePortal cmdDeletePortal = new CMDDeletePortal(); public CMDDeletePortal cmdDeletePortal = new CMDDeletePortal();
@ -33,6 +34,7 @@ public class DCommandRoot {
this.commands.add(cmdCreate); this.commands.add(cmdCreate);
this.commands.add(cmdSave); this.commands.add(cmdSave);
this.commands.add(cmdLeave); this.commands.add(cmdLeave);
this.commands.add(cmdEscape);
this.commands.add(cmdEdit); this.commands.add(cmdEdit);
this.commands.add(cmdPortal); this.commands.add(cmdPortal);
this.commands.add(cmdDeletePortal); this.commands.add(cmdDeletePortal);