-
-
Notifications
You must be signed in to change notification settings - Fork 30
/
GotoCommand.java
72 lines (58 loc) · 2.56 KB
/
GotoCommand.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
package net.aufdemrand.denizencore.scripts.commands.core;
import net.aufdemrand.denizencore.exceptions.InvalidArgumentsException;
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;
import net.aufdemrand.denizencore.utilities.debugging.dB;
import java.util.List;
public class GotoCommand extends AbstractCommand {
@Override
public void parseArgs(ScriptEntry scriptEntry) throws InvalidArgumentsException {
// Interpret arguments
for (aH.Argument arg : aH.interpret(scriptEntry.getArguments())) {
if (!scriptEntry.hasObject("m_name")) {
scriptEntry.addObject("m_name", arg.asElement());
}
else {
arg.reportUnhandled();
}
}
// Check for required information
if (!scriptEntry.hasObject("m_name")) {
throw new InvalidArgumentsException("Must have a mark name!");
}
}
@Override
public void execute(ScriptEntry scriptEntry) {
// Fetch required objects
Element mName = scriptEntry.getElement("m_name");
// Debug the execution
if (scriptEntry.dbCallShouldDebug()) {
dB.report(scriptEntry, getName(), mName.debug());
}
// Jump forth
boolean hasmark = false;
for (int i = 0; i < scriptEntry.getResidingQueue().getQueueSize(); i++) {
ScriptEntry entry = scriptEntry.getResidingQueue().getEntry(i);
List<String> args = entry.getOriginalArguments();
if (entry.getCommandName().equalsIgnoreCase("mark") && args.size() > 0 && args.get(0).equalsIgnoreCase(mName.asString())) {
hasmark = true;
break;
}
}
if (hasmark) {
while (scriptEntry.getResidingQueue().getQueueSize() > 0) {
ScriptEntry entry = scriptEntry.getResidingQueue().getEntry(0);
List<String> args = entry.getOriginalArguments();
if (entry.getCommandName().equalsIgnoreCase("mark") && args.size() > 0 && args.get(0).equalsIgnoreCase(mName.asString())) {
break;
}
scriptEntry.getResidingQueue().removeEntry(0);
}
}
else {
dB.echoError(scriptEntry.getResidingQueue(), "Cannot go to that location - doesn't seem to exist!");
}
}
}