-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Added execute module - Fixed a bug causing EITHER action to omit displaying message on the very first perform callback
- Loading branch information
Showing
4 changed files
with
52 additions
and
1 deletion.
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
49 changes: 49 additions & 0 deletions
49
src/main/java/net/programmer/igoodie/twitchspawn/command/module/ModuleExecute.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,49 @@ | ||
package net.programmer.igoodie.twitchspawn.command.module; | ||
|
||
import net.minecraft.command.CommandException; | ||
import net.minecraft.command.ICommandSender; | ||
import net.programmer.igoodie.twitchspawn.tslanguage.EventArguments; | ||
import net.programmer.igoodie.twitchspawn.tslanguage.action.TSLAction; | ||
import net.programmer.igoodie.twitchspawn.tslanguage.parser.TSLParser; | ||
import net.programmer.igoodie.twitchspawn.tslanguage.parser.TSLSyntaxError; | ||
import net.programmer.igoodie.twitchspawn.tslanguage.parser.TSLTokenizer; | ||
|
||
import java.util.Arrays; | ||
import java.util.LinkedList; | ||
import java.util.List; | ||
|
||
public class ModuleExecute extends CommandModule { | ||
|
||
@Override | ||
public String getName() { | ||
return "execute"; | ||
} | ||
|
||
@Override | ||
public String getUsage() { | ||
return super.getUsage() + " <tsl_action>"; | ||
} | ||
|
||
@Override | ||
public void execute(ICommandSender commandSender, String[] moduleArgs) throws CommandException { | ||
try { | ||
TSLAction tslAction = parseAction(moduleArgs); | ||
EventArguments eventArguments = EventArguments.createRandom(commandSender.getName()); | ||
tslAction.process(eventArguments); | ||
|
||
} catch (TSLSyntaxError e) { | ||
throw new CommandException(e.getMessage()); | ||
} | ||
} | ||
|
||
private TSLAction parseAction(String[] moduleArgs) throws CommandException, TSLSyntaxError { | ||
if (moduleArgs.length == 0) | ||
throw new CommandException("Expected at least 1 TSL word!"); | ||
|
||
List<String> words = TSLTokenizer.intoWords(String.join(" ", moduleArgs)); | ||
String actionName = words.remove(0); | ||
|
||
return TSLParser.parseAction(actionName, words); | ||
} | ||
|
||
} |
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