Skip to content

Commit

Permalink
feat(tsl): add REFLECT ONLY syntax
Browse files Browse the repository at this point in the history
  • Loading branch information
iGoodie committed Sep 13, 2020
1 parent 2771b17 commit f0e6ee7
Showing 1 changed file with 20 additions and 4 deletions.
Expand Up @@ -3,6 +3,7 @@
import net.minecraft.entity.player.EntityPlayerMP;
import net.programmer.igoodie.twitchspawn.TwitchSpawn;
import net.programmer.igoodie.twitchspawn.configuration.ConfigManager;
import net.programmer.igoodie.twitchspawn.eventqueue.EventQueue;
import net.programmer.igoodie.twitchspawn.tslanguage.EventArguments;
import net.programmer.igoodie.twitchspawn.tslanguage.keyword.TSLActionKeyword;
import net.programmer.igoodie.twitchspawn.tslanguage.parser.TSLParser;
Expand All @@ -15,6 +16,7 @@

public class ReflectAction extends TSLAction {

private boolean onlyReflectedPlayers;
private boolean reflectEveryone;
private int reflectRandomN;
private List<String> reflectedUsers;
Expand All @@ -31,7 +33,14 @@ public ReflectAction(List<String> words) throws TSLSyntaxError {
if (words.stream().anyMatch(word -> word.equalsIgnoreCase(reflectActionName)))
throw new TSLSyntaxError("Cannot have a cyclic REFLECT rule.");

String usersRaw = words.get(0);
LinkedList<String> wordsCloned = new LinkedList<>(words);

if (wordsCloned.get(0).equalsIgnoreCase("ONLY")) {
this.onlyReflectedPlayers = true;
wordsCloned.remove(0);
}

String usersRaw = wordsCloned.get(0);

if (usersRaw.equals("*")) {
this.reflectEveryone = true;
Expand All @@ -49,15 +58,22 @@ public ReflectAction(List<String> words) throws TSLSyntaxError {
this.reflectedUsers = Arrays.asList(usersRaw.split(",\\s*"));
}

this.action = TSLParser.parseAction(words.get(1), words.size() > 2
? words.subList(2, words.size())
this.action = TSLParser.parseAction(wordsCloned.get(1), wordsCloned.size() > 2
? wordsCloned.subList(2, wordsCloned.size())
: Collections.emptyList());
}

@Override
protected void performAction(EntityPlayerMP player, EventArguments args) {
action.reflectedUser = null;
action.process(args);

if (onlyReflectedPlayers) {
EventQueue eventQueue = ConfigManager.RULESET_COLLECTION.getQueue(args.streamerNickname);
eventQueue.cancelUpcomingSleep();

} else {
action.process(args);
}

// Select where to reflect
List<String> reflectedUsers = getReflectedPlayers(player);
Expand Down

0 comments on commit f0e6ee7

Please sign in to comment.