Fixed /dxl test command and made it compatible with edit mode

This commit is contained in:
Daniel Saukel 2016-12-27 00:56:23 +01:00
parent 7d254ec019
commit 329876e881
3 changed files with 47 additions and 27 deletions

View File

@ -20,12 +20,16 @@ import io.github.dre2n.commons.command.BRCommand;
import io.github.dre2n.commons.util.messageutil.MessageUtil;
import io.github.dre2n.dungeonsxl.DungeonsXL;
import io.github.dre2n.dungeonsxl.config.DMessages;
import io.github.dre2n.dungeonsxl.dungeon.Dungeon;
import io.github.dre2n.dungeonsxl.game.Game;
import io.github.dre2n.dungeonsxl.game.GameTypeDefault;
import io.github.dre2n.dungeonsxl.player.DEditPlayer;
import io.github.dre2n.dungeonsxl.player.DGamePlayer;
import io.github.dre2n.dungeonsxl.player.DGlobalPlayer;
import io.github.dre2n.dungeonsxl.player.DGroup;
import io.github.dre2n.dungeonsxl.player.DPermissions;
import io.github.dre2n.dungeonsxl.world.DGameWorld;
import io.github.dre2n.dungeonsxl.world.DResourceWorld;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
@ -43,19 +47,22 @@ public class TestCommand extends BRCommand {
setHelp(DMessages.HELP_CMD_TEST.getMessage());
setPermission(DPermissions.TEST.getNode());
setPlayerCommand(true);
setConsoleCommand(false);
}
@Override
public void onExecute(String[] args, CommandSender sender) {
Player player = (Player) sender;
DGlobalPlayer dPlayer = plugin.getDPlayers().getByPlayer(player);
if (!(dPlayer instanceof DEditPlayer)) {
DGroup dGroup = DGroup.getByPlayer(player);
if (dGroup == null) {
MessageUtil.sendMessage(sender, DMessages.ERROR_JOIN_GROUP.getMessage());
return;
}
if (!dGroup.getCaptain().equals(player)) {
if (!dGroup.getCaptain().equals(player) && !DPermissions.hasPermission(player, DPermissions.BYPASS)) {
MessageUtil.sendMessage(sender, DMessages.ERROR_NOT_CAPTAIN.getMessage());
return;
}
@ -67,7 +74,7 @@ public class TestCommand extends BRCommand {
}
Game game = gameWorld.getGame();
if (game != null) {
if (game != null && game.hasStarted()) {
MessageUtil.sendMessage(sender, DMessages.ERROR_LEAVE_DUNGEON.getMessage());
return;
}
@ -75,6 +82,16 @@ public class TestCommand extends BRCommand {
for (Player groupPlayer : dGroup.getPlayers()) {
DGamePlayer.getByPlayer(groupPlayer).ready(GameTypeDefault.TEST);
}
} else {
DEditPlayer editPlayer = (DEditPlayer) dPlayer;
editPlayer.leave();
DResourceWorld resource = editPlayer.getEditWorld().getResource();
Dungeon dungeon = new Dungeon(resource);
DGameWorld instance = resource.instantiateAsGameWorld();
Game game = new Game(new DGroup(player, dungeon), GameTypeDefault.TEST, instance);
DGamePlayer.create(player, game.getWorld(), GameTypeDefault.TEST);
}
}
}

View File

@ -31,6 +31,8 @@ import org.bukkit.scheduler.BukkitRunnable;
*/
public class AnnouncerStartGameTask extends BukkitRunnable {
DungeonsXL plugin = DungeonsXL.getInstance();
private Announcer announcer;
private ProgressBar bar;
@ -47,7 +49,7 @@ public class AnnouncerStartGameTask extends BukkitRunnable {
}
}
bar = new ProgressBar(players, 30);
bar.runTaskTimer(DungeonsXL.getInstance(), 0L, 20L);
bar.runTaskTimer(plugin, 0L, 20L);
}
/**
@ -72,7 +74,7 @@ public class AnnouncerStartGameTask extends BukkitRunnable {
}
if (game == null) {
game = new Game(dGroup, announcer.getMapName());
game = new Game(dGroup, plugin.getDWorlds().getResourceByName(announcer.getMapName()));
} else {
game.getDGroups().add(dGroup);
}

View File

@ -17,6 +17,7 @@
package io.github.dre2n.dungeonsxl.task;
import io.github.dre2n.commons.util.messageutil.MessageUtil;
import io.github.dre2n.dungeonsxl.game.GameType;
import io.github.dre2n.dungeonsxl.player.DEditPlayer;
import io.github.dre2n.dungeonsxl.player.DGamePlayer;
import io.github.dre2n.dungeonsxl.world.DEditWorld;
@ -37,7 +38,7 @@ public class CreateDInstancePlayerTask extends BukkitRunnable {
private UUID player;
private DInstanceWorld instance;
private boolean ready;
private GameType ready;
private int i = 12;
@ -46,7 +47,7 @@ public class CreateDInstancePlayerTask extends BukkitRunnable {
this.instance = instance;
}
public CreateDInstancePlayerTask(Player player, DInstanceWorld instance, boolean ready) {
public CreateDInstancePlayerTask(Player player, DInstanceWorld instance, GameType ready) {
this.player = player.getUniqueId();
this.instance = instance;
this.ready = ready;
@ -63,8 +64,8 @@ public class CreateDInstancePlayerTask extends BukkitRunnable {
if (instance.exists()) {
if (instance instanceof DGameWorld) {
DGamePlayer gamePlayer = new DGamePlayer(player, (DGameWorld) instance);
if (ready) {
gamePlayer.ready();
if (ready != null) {
gamePlayer.ready(ready);
}
} else if (instance instanceof DEditWorld) {