Recoded play command

This commit is contained in:
Daniel Saukel 2016-12-27 00:55:43 +01:00
parent 23f6f4bfd6
commit 7d254ec019
8 changed files with 50 additions and 93 deletions

View File

@ -89,7 +89,7 @@ public class EnterCommand extends BRCommand {
joining.sendMessage(DMessages.CMD_ENTER_SUCCESS.getMessage(joining.getName(), target.getName()));
for (Player player : joining.getPlayers()) {
DGamePlayer.create(player, game.getWorld(), true);
DGamePlayer.create(player, game.getWorld(), game.getType());
}
}

View File

@ -28,11 +28,12 @@ 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;
import io.github.dre2n.dungeonsxl.world.DResourceWorld;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
/**
* @author Frank Baumann, Daniel Saukel
* @author Daniel Saukel
*/
public class PlayCommand extends BRCommand {
@ -41,108 +42,52 @@ public class PlayCommand extends BRCommand {
public PlayCommand() {
setCommand("play");
setMinArgs(1);
setMaxArgs(2);
setMaxArgs(1);
setHelp(DMessages.HELP_CMD_PLAY.getMessage());
setPermission(DPermissions.PLAY.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 DInstancePlayer) {
MessageUtil.sendMessage(player, DMessages.ERROR_LEAVE_DUNGEON.getMessage());
return;
}
if (!(args.length >= 2 && args.length <= 3)) {
displayHelp(player);
return;
}
String identifier = args[1];
String mapName = identifier;
boolean multiFloor = false;
if (args.length == 3) {
identifier = args[2];
mapName = identifier;
if (args[1].equalsIgnoreCase("dungeon") || args[1].equalsIgnoreCase("d")) {
Dungeon dungeon = plugin.getDungeons().getByName(args[2]);
if (dungeon != null && dungeon.isMultiFloor()) {
multiFloor = true;
mapName = dungeon.getConfig().getStartFloor().getName();
} else {
displayHelp(player);
return;
}
} else if (args[1].equalsIgnoreCase("map") || args[1].equalsIgnoreCase("m")) {
identifier = args[2];
Dungeon dungeon = plugin.getDungeons().getByName(args[1]);
if (dungeon == null) {
DResourceWorld resource = plugin.getDWorlds().getResourceByName(args[1]);
if (resource != null) {
dungeon = new Dungeon(resource);
} else {
MessageUtil.sendMessage(player, DMessages.ERROR_DUNGEON_NOT_EXIST.getMessage(args[1]));
return;
}
}
if (!multiFloor && !plugin.getDWorlds().exists(identifier)) {
MessageUtil.sendMessage(player, DMessages.ERROR_DUNGEON_NOT_EXIST.getMessage(identifier));
return;
}
DGroup dGroup = DGroup.getByPlayer(player);
if (dGroup != null) {
if (!dGroup.getCaptain().equals(player) && !DPermissions.hasPermission(player, DPermissions.BYPASS)) {
MessageUtil.sendMessage(player, DMessages.ERROR_NOT_CAPTAIN.getMessage());
if (dGroup == null || dGroup.isPlaying()) {
dGroup = new DGroup(player, dungeon);
DGroupCreateEvent event = new DGroupCreateEvent(dGroup, player, DGroupCreateEvent.Cause.COMMAND);
plugin.getServer().getPluginManager().callEvent(event);
if (event.isCancelled()) {
plugin.getDGroups().remove(dGroup);
dGroup = null;
}
if (dGroup.getMapName() == null) {
if (multiFloor) {
dGroup.setDungeon(plugin.getDungeons().getByName(identifier));
} else {
dGroup.setDungeon(mapName);
}
} else {
MessageUtil.sendMessage(player, DMessages.ERROR_LEAVE_GROUP.getMessage());
return;
}
} else {
dGroup = new DGroup(player, identifier, multiFloor);
}
DGroupCreateEvent event = new DGroupCreateEvent(dGroup, player, DGroupCreateEvent.Cause.COMMAND);
plugin.getServer().getPluginManager().callEvent(event);
if (event.isCancelled()) {
plugin.getDGroups().remove(dGroup);
dGroup = null;
}
if (dGroup == null) {
if (!dGroup.getCaptain().equals(player) && !DPermissions.hasPermission(player, DPermissions.BYPASS)) {
MessageUtil.sendMessage(player, DMessages.ERROR_NOT_CAPTAIN.getMessage());
return;
}
dGroup.setDungeon(dungeon);
if (dGroup.getGameWorld() == null) {
new Game(dGroup, mapName);
}
if (dGroup.getGameWorld() == null) {
MessageUtil.sendMessage(player, DMessages.ERROR_NOT_SAVED.getMessage(mapName));
dGroup.delete();
return;
}
if (dGroup.getGameWorld().getLobbyLocation() == null) {
for (Player groupPlayer : dGroup.getPlayers()) {
DGamePlayer.create(groupPlayer, dGroup.getGameWorld());
}
} else {
for (Player groupPlayer : dGroup.getPlayers()) {
DGamePlayer.create(groupPlayer, dGroup.getGameWorld());
}
new Game(dGroup, dungeon.getMap());
for (Player groupPlayer : dGroup.getPlayers()) {
DGamePlayer.create(groupPlayer, dGroup.getGameWorld());
}
}

View File

@ -132,7 +132,7 @@ public enum DMessages implements Messages {
HELP_CMD_LIVES("Help_Cmd_Lives", "/dxl lives [player] - Shows the lives a player has left"),
HELP_CMD_MAIN("Help_Cmd_Main", "/dxl - General status information"),
HELP_CMD_MSG("Help_Cmd_Msg", "/dxl msg [id] '[msg]' - Show or edit a message"),
HELP_CMD_PLAY("Help_Cmd_Play", "/dxl play ([dungeon|map]) [name] - Allows the player to play a dungeon without a portal"),
HELP_CMD_PLAY("Help_Cmd_Play", "/dxl play [name] - Allows the player to play a dungeon without a portal"),
HELP_CMD_PORTAL("Help_Cmd_Portal", "/dxl portal ([material=portal])- Creates a portal that leads into a dungeon"),
HELP_CMD_RELOAD("Help_Cmd_Reload", "/dxl reload - Reloads the plugin"),
HELP_CMD_RENAME("Help_Cmd_Rename", "/dxl rename [old name] [new name] - Changes the name of a map to the new one. This command does NOT break dungeons that include this map."),

View File

@ -89,15 +89,12 @@ public class Game {
dGroup.setScore(rules.getInitialScore());
}
public Game(DGroup dGroup, String worldName) {
public Game(DGroup dGroup, DResourceWorld resource) {
plugin.getGames().add(this);
tutorial = false;
started = false;
DResourceWorld resource = plugin.getDWorlds().getResourceByName(worldName);
if (resource != null) {
world = resource.instantiateAsGameWorld();
}
world = resource.instantiateAsGameWorld();
dGroups.add(dGroup);
dGroup.setGameWorld(world);

View File

@ -41,9 +41,11 @@ import org.bukkit.scheduler.BukkitRunnable;
public class DEditPlayer extends DInstancePlayer {
private String[] linesCopy;
private DEditWorld editWorld;
public DEditPlayer(final Player player, DEditWorld world) {
super(player, world.getWorld());
editWorld = world;
// Set gamemode a few ticks later to avoid incompatibilities with plugins that force a gamemode
new BukkitRunnable() {
@ -96,6 +98,13 @@ public class DEditPlayer extends DInstancePlayer {
this.linesCopy = linesCopy;
}
/**
* @return the DEditWorld
*/
public DEditWorld getEditWorld() {
return editWorld;
}
/* Actions */
@Override
public void delete() {

View File

@ -120,7 +120,7 @@ public class DGamePlayer extends DInstancePlayer {
* the player's GameWorld
*/
public static void create(Player player, DGameWorld gameWorld) {
create(player, gameWorld, false);
create(player, gameWorld, null);
}
/**
@ -129,9 +129,10 @@ public class DGamePlayer extends DInstancePlayer {
* @param gameWorld
* the player's GameWorld
* @param ready
* if the player will be ready from the beginning
* Any GameType if the player will be ready from the beginning
* null if the player will not be ready from the beginning
*/
public static void create(Player player, DGameWorld gameWorld, boolean ready) {
public static void create(Player player, DGameWorld gameWorld, GameType ready) {
new CreateDInstancePlayerTask(player, gameWorld, ready).runTaskTimer(plugin, 0L, 5L);
}

View File

@ -133,7 +133,6 @@ public class DGroup {
this("Group_" + plugin.getDGroups().size(), player, dungeon);
}
@Deprecated
public DGroup(String name, Player player, Dungeon dungeon) {
this(name, player, new ArrayList<Player>(), dungeon);
}
@ -421,14 +420,19 @@ public class DGroup {
* @param name
* the name of the dungeon
*/
public void setDungeon(String name) {
public boolean setDungeon(String name) {
dungeon = plugin.getDungeons().getByName(name);
if (dungeon != null) {
unplayedFloors = dungeon.getConfig().getFloors();
return true;
} else {
DResourceWorld resource = plugin.getDWorlds().getResourceByName(name);
dungeon = new Dungeon(resource);
if (resource != null) {
dungeon = new Dungeon(resource);
return true;
}
return false;
}
}

View File

@ -52,6 +52,7 @@ public enum DPermissions {
INVITE("invite", OP),
INSECURE("insecure", OP),
JOIN("join", TRUE),
KICK("kick", OP),
LEAVE("leave", TRUE),
LIST("list", OP),
LIVES("lives", TRUE),