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
1 parent
07af9ba
commit cbd0ca5
Showing
2 changed files
with
74 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
71 changes: 71 additions & 0 deletions
71
src/main/java/net/aufdemrand/denizen/scripts/commands/core/RepeatCommand.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,71 @@ | ||
package net.aufdemrand.denizen.scripts.commands.core; | ||
|
||
import net.aufdemrand.denizen.exceptions.CommandExecutionException; | ||
import net.aufdemrand.denizen.exceptions.InvalidArgumentsException; | ||
import net.aufdemrand.denizen.objects.Element; | ||
import net.aufdemrand.denizen.objects.aH; | ||
import net.aufdemrand.denizen.objects.dList; | ||
import net.aufdemrand.denizen.scripts.ScriptEntry; | ||
import net.aufdemrand.denizen.scripts.commands.BracedCommand; | ||
import net.aufdemrand.denizen.scripts.queues.ScriptQueue; | ||
import net.aufdemrand.denizen.scripts.queues.core.InstantQueue; | ||
import net.aufdemrand.denizen.utilities.debugging.dB; | ||
import net.aufdemrand.denizen.utilities.debugging.dB.Messages; | ||
|
||
import java.util.ArrayList; | ||
import java.util.UUID; | ||
|
||
public class RepeatCommand extends BracedCommand { | ||
|
||
|
||
@Override | ||
public void parseArgs(ScriptEntry scriptEntry) throws InvalidArgumentsException { | ||
|
||
for (aH.Argument arg : aH.interpret(scriptEntry.getArguments())) { | ||
|
||
if (!scriptEntry.hasObject("qty") | ||
&& arg.matchesPrimitive(aH.PrimitiveType.Integer)) | ||
scriptEntry.addObject("qty", arg.asElement()); | ||
|
||
} | ||
|
||
if (!scriptEntry.hasObject("qty")) | ||
throw new InvalidArgumentsException(Messages.ERROR_MISSING_OTHER, "QUANTITY"); | ||
|
||
scriptEntry.addObject("entries", getBracedCommands(scriptEntry)); | ||
|
||
} | ||
|
||
@SuppressWarnings("unchecked") | ||
@Override | ||
public void execute(ScriptEntry scriptEntry) throws CommandExecutionException { | ||
|
||
// Get objects | ||
int qty = ((Element)scriptEntry.getObject("qty")).asInt(); | ||
ArrayList<ScriptEntry> entries = (ArrayList<ScriptEntry>) scriptEntry.getObject("entries"); | ||
|
||
// Report to dB | ||
dB.report(getName(), aH.debugObj("qty", qty) ); | ||
|
||
for (int incr = 0;incr < qty;incr++) { | ||
ArrayList<ScriptEntry> newEntries = (ArrayList<ScriptEntry>) new ArrayList<ScriptEntry>(); | ||
for (ScriptEntry entr: entries) { | ||
try { | ||
ScriptEntry toadd = entr.clone(); | ||
toadd.getObjects().clear(); | ||
newEntries.add(toadd); | ||
} | ||
catch (Throwable e) { | ||
e.printStackTrace(); | ||
} | ||
} | ||
ScriptQueue queue = new InstantQueue(UUID.randomUUID().toString()); | ||
scriptEntry.getResidingQueue().addContext("value", String.valueOf(incr + 1)); | ||
queue.addContext("value", String.valueOf(incr + 1)); | ||
queue.addEntries(newEntries); | ||
queue.start(); | ||
} | ||
|
||
} | ||
|
||
} | ||
This comment has been minimized.
Sorry, something went wrong. |
Mwahaha no new line xD