Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
125 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
95 changes: 95 additions & 0 deletions
95
src/main/java/net/aufdemrand/denizen/scripts/commands/npc/PushableCommand.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
package net.aufdemrand.denizen.scripts.commands.npc; | ||
|
||
import net.aufdemrand.denizen.BukkitScriptEntryData; | ||
import net.aufdemrand.denizen.npc.traits.PushableTrait; | ||
import net.aufdemrand.denizen.objects.dNPC; | ||
import net.aufdemrand.denizen.utilities.debugging.dB; | ||
import net.aufdemrand.denizencore.exceptions.CommandExecutionException; | ||
import net.aufdemrand.denizencore.exceptions.InvalidArgumentsException; | ||
import net.aufdemrand.denizencore.objects.Duration; | ||
import net.aufdemrand.denizencore.objects.Element; | ||
import net.aufdemrand.denizencore.objects.aH; | ||
import net.aufdemrand.denizencore.scripts.ScriptEntry; | ||
import net.aufdemrand.denizencore.scripts.commands.AbstractCommand; | ||
|
||
public class PushableCommand extends AbstractCommand { | ||
|
||
private enum Toggle {TOGGLE, TRUE, FALSE, ON, OFF} | ||
|
||
@Override | ||
public void parseArgs(ScriptEntry scriptEntry) throws InvalidArgumentsException { | ||
|
||
for (aH.Argument arg : aH.interpret(scriptEntry.getArguments())) { | ||
|
||
if (!scriptEntry.hasObject("state") | ||
&& arg.matchesPrefix("state", "s") | ||
&& arg.matchesEnum(Toggle.values())) { | ||
scriptEntry.addObject("state", arg.asElement()); | ||
} | ||
|
||
else if (!scriptEntry.hasObject("delay") | ||
&& arg.matchesPrefix("delay", "d") | ||
&& arg.matchesArgumentType(Duration.class)) { | ||
scriptEntry.addObject("delay", arg.asType(Duration.class)); | ||
} | ||
|
||
else if (!scriptEntry.hasObject("return") | ||
&& arg.matchesPrefix("return", "r") | ||
&& arg.matchesPrimitive(aH.PrimitiveType.Boolean)) { | ||
scriptEntry.addObject("return", arg.asElement()); | ||
} | ||
|
||
} | ||
} | ||
|
||
@Override | ||
public void execute(ScriptEntry scriptEntry) throws CommandExecutionException { | ||
|
||
dNPC denizenNPC = ((BukkitScriptEntryData) scriptEntry.entryData).getNPC(); | ||
if (denizenNPC == null) { | ||
throw new CommandExecutionException("No valid NPC attached to this queue!"); | ||
} | ||
PushableTrait trait = denizenNPC.getPushableTrait(); | ||
|
||
Element state = scriptEntry.getElement("state"); | ||
Duration delay = scriptEntry.getdObject("delay"); | ||
Element returnable = scriptEntry.getElement("return"); | ||
|
||
if (state == null && delay == null && returnable == null) { | ||
state = new Element("TOGGLE"); | ||
} | ||
|
||
dB.report(scriptEntry, getName(), | ||
(state != null ? state.debug() : "") + | ||
(delay != null ? delay.debug() : "") + | ||
(returnable != null ? returnable.debug() : "")); | ||
|
||
if (delay != null) { | ||
trait.setDelay(delay.getSecondsAsInt()); | ||
} | ||
|
||
if (returnable != null) { | ||
trait.setReturnable(returnable.asBoolean()); | ||
} | ||
|
||
if (state != null) { | ||
switch (Toggle.valueOf(state.asString().toUpperCase())) {\ | ||
|
||
case TRUE: | ||
case ON: | ||
trait.setPushable(true); | ||
break; | ||
|
||
case FALSE: | ||
case OFF: | ||
trait.setPushable(false); | ||
break; | ||
|
||
case TOGGLE: | ||
trait.setPushable(!trait.isPushable()); | ||
break; | ||
|
||
} | ||
} | ||
} | ||
} |