Skip to content

Commit

Permalink
Add MobArena Command.
Browse files Browse the repository at this point in the history
  • Loading branch information
Fortifier42 committed Feb 5, 2016
1 parent 0253238 commit ee9e465
Show file tree
Hide file tree
Showing 6 changed files with 132 additions and 4 deletions.
@@ -0,0 +1,126 @@
package net.gnomeffinway.depenizen.commands.MobArena;

import com.garbagemule.MobArena.framework.Arena;
import net.aufdemrand.denizen.objects.dPlayer;
import net.aufdemrand.denizencore.exceptions.CommandExecutionException;
import net.aufdemrand.denizencore.exceptions.InvalidArgumentsException;
import net.aufdemrand.denizencore.objects.aH;
import net.aufdemrand.denizencore.objects.dList;
import net.aufdemrand.denizencore.scripts.ScriptEntry;
import net.aufdemrand.denizencore.scripts.commands.AbstractCommand;
import net.aufdemrand.denizencore.utilities.debugging.dB;
import net.gnomeffinway.depenizen.objects.mobarena.MobArenaArena;

import java.util.List;

// <--[command]
// @Name MobArena
// @Syntax mobarena [<mobarena>] (add:<player>|...) (remove:<player>|...) (spectate:<player>|...)
// @Group Depenizen
// @Plugin Depenizen, MobArena
// @Required 1
// @Stable untested
// @Short Make a player join, remove a player from or make a player spectate a MobArena.
// @Author Morphan1

This comment has been minimized.

Copy link
@Morphan1

Morphan1 Feb 6, 2016

Contributor

I most certainly did not


// @Description
// This command allows you to make a player join an arena, make them leave an arena or make them spectate an arena.
// Follows normal MobArena functionality, so acts as if the player has typed '/mobarena join'.
// NOTE: You can use all 3: ("add", "remove", and "spectate") as once, however avoid conflicts.

// @Tags
// <player.mobarena.*>

// @Usage
// Use to force the player to join an arena.
// - mobarena mobarena@Default add:<player>

// @Usage
// Use to force the player to leave an arena.
// - mobarena mobarena@Default remove:<player>

// @Usage
// Use to force a player to join an arena and another to leave..
// - mobarena mobarena@Default add:<player> remove:p@mcmonkey4eva

// @Usage
// Use to cause all players who aren't in an arena to spectate.
// - mobarena mobarena@Default spectate:<server.list_online_players.filter[mobarena.in_arena.not]>

// -->

public class MobArenaCommand extends AbstractCommand {

@Override
public void parseArgs(ScriptEntry scriptEntry) throws InvalidArgumentsException {
for (aH.Argument arg : aH.interpret(scriptEntry.getArguments())) {
if (!scriptEntry.hasObject("arena") &&
(arg.matchesPrefix("arena") || MobArenaArena.matches(arg.getValue()))) {
scriptEntry.addObject("arena", MobArenaArena.valueOf(arg.getValue()));
}
else if (!scriptEntry.hasObject("add")
&& arg.matchesPrefix("add", "join")
&& arg.matchesArgumentList(dPlayer.class)) {
scriptEntry.addObject("add", arg.asType(dList.class).filter(dPlayer.class));
}
else if (!scriptEntry.hasObject("remove")
&& arg.matchesPrefix("remove", "leave")
&& arg.matchesArgumentList(dPlayer.class)) {
scriptEntry.addObject("remove", arg.asType(dList.class).filter(dPlayer.class));
}
else if (!scriptEntry.hasObject("spectate")
&& arg.matchesPrefix("spectate", "spec")
&& arg.matchesArgumentList(dPlayer.class)) {
scriptEntry.addObject("spectate", arg.asType(dList.class).filter(dPlayer.class));
}
else {
arg.reportUnhandled();
}
}

if (!scriptEntry.hasObject("arena")) {
throw new InvalidArgumentsException("Must specify a valid MobArena!");
}
else if (!scriptEntry.hasObject("add") && !scriptEntry.hasObject("remove") && !scriptEntry.hasObject("spectate")) {
throw new InvalidArgumentsException("Must specify players to add, remove or spectate!");
}
}

@SuppressWarnings("unchecked")
@Override
public void execute(ScriptEntry scriptEntry) throws CommandExecutionException {
MobArenaArena arena = scriptEntry.getdObject("arena");
List<dPlayer> add = (List<dPlayer>) scriptEntry.getObject("add");
List<dPlayer> remove = (List<dPlayer>) scriptEntry.getObject("remove");
List<dPlayer> spectate = (List<dPlayer>) scriptEntry.getObject("spectate");

dB.report(scriptEntry, getName(), arena.debug()
+ aH.debugList("Add Players", add)
+ aH.debugList("Remove Players", remove)
+ aH.debugList("Spectate Players", spectate));

Arena mobArena = arena.getArena();

if (add != null && !add.isEmpty()) {
for (dPlayer p : add) {
if (mobArena.canJoin(p.getPlayerEntity())) {
mobArena.playerJoin(p.getPlayerEntity(), p.getLocation());
}
}
}
if (remove != null && !remove.isEmpty()) {
for (dPlayer p : remove) {
if (mobArena.getAllPlayers().contains(p.getPlayerEntity())) {

This comment has been minimized.

Copy link
@Morphan1

Morphan1 Feb 6, 2016

Contributor

There's a possibility of Player objects not being equal. I'd switch to check for names or uuids

mobArena.playerLeave(p.getPlayerEntity());
}
}
}
if (spectate != null && !spectate.isEmpty()) {
for (dPlayer p : spectate) {
if (mobArena.canSpec(p.getPlayerEntity())) {
mobArena.playerSpec(p.getPlayerEntity(), p.getLocation());
}
}
}
}
}
Expand Up @@ -15,7 +15,7 @@ public class BattleNightSupport extends Support {
public BattleNightSupport() {
registerProperty(BNPlayerExtension.class, dPlayer.class);
registerAdditionalTags("battle");
new BattleNightCommands().activate().as("BN").withOptions("see documentation", 1);
new BattleNightCommands().activate().as("BN").withOptions("See Documentation.", 1);
}

@Override
Expand Down
Expand Up @@ -16,7 +16,7 @@ public JobsSupport() {
registerProperty(JobPlayer.class, JobsJob.class);
registerProperty(JobsPlayerExtension.class, dPlayer.class);
registerAdditionalTags("jobs");
new JobsCommands().activate().as("jobs").withOptions("see documentation", 2);
new JobsCommands().activate().as("jobs").withOptions("See Documentation.", 2);
}

@Override
Expand Down
Expand Up @@ -17,7 +17,7 @@ public McMMOSupport() {
registerObjects(dParty.class);
registerAdditionalTags("party");
registerProperty(McMMOPlayerExtension.class, dPlayer.class);
new McMMOCommands().activate().as("MCMMO").withOptions("see documentation", 1);
new McMMOCommands().activate().as("MCMMO").withOptions("See Documentation.", 1);
registerScriptEvents(new mcMMOPlayerLevelChangeScriptEvent());
registerScriptEvents(new mcMMOPlayerLevelUpScriptEvent());
registerScriptEvents(new mcMMOPlayerLevelDownScriptEvent());
Expand Down
Expand Up @@ -5,6 +5,7 @@
import net.aufdemrand.denizen.objects.dPlayer;
import net.aufdemrand.denizencore.objects.dList;
import net.aufdemrand.denizencore.tags.Attribute;
import net.gnomeffinway.depenizen.commands.MobArena.MobArenaCommand;
import net.gnomeffinway.depenizen.events.MobArena.MobArenaEndsScriptEvent;
import net.gnomeffinway.depenizen.events.MobArena.MobArenaStartsScriptEvent;
import net.gnomeffinway.depenizen.events.MobArena.MobArenaWaveChangesScriptEvent;
Expand All @@ -19,6 +20,7 @@ public class MobArenaSupport extends Support {
public MobArenaSupport() {
registerObjects(MobArenaArena.class);
registerAdditionalTags("mobarena");
new MobArenaCommand().activate().withOptions("See Documentation.", 1);
registerScriptEvents(new MobArenaStartsScriptEvent());
registerScriptEvents(new MobArenaEndsScriptEvent());
registerScriptEvents(new MobArenaWaveChangesScriptEvent());
Expand Down
Expand Up @@ -18,7 +18,7 @@ public WorldGuardSupport() {
registerProperty(WorldGuardLocationExtension.class, dLocation.class);
registerProperty(WorldGuardCuboidExtension.class, dCuboid.class);
registerProperty(WorldGuardWorldExtension.class, dWorld.class);
new RegionCommand().activate().as("REGION").withOptions("see documentation", 2);
new RegionCommand().activate().as("REGION").withOptions("See Documentation.", 2);
registerAdditionalTags("region");
}

Expand Down

0 comments on commit ee9e465

Please sign in to comment.