-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add player values for relational placeholder structure
- Loading branch information
1 parent
1801dcb
commit cc4c882
Showing
2 changed files
with
80 additions
and
0 deletions.
There are no files selected for viewing
74 changes: 74 additions & 0 deletions
74
...va/io/github/apickledwalrus/skriptplaceholders/skript/elements/ExprRelationalPlayers.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,74 @@ | ||
package io.github.apickledwalrus.skriptplaceholders.skript.elements; | ||
|
||
import ch.njol.skript.Skript; | ||
import ch.njol.skript.doc.Description; | ||
import ch.njol.skript.doc.Examples; | ||
import ch.njol.skript.doc.Name; | ||
import ch.njol.skript.doc.Since; | ||
import ch.njol.skript.lang.Expression; | ||
import ch.njol.skript.lang.ExpressionType; | ||
import ch.njol.skript.lang.SkriptParser.ParseResult; | ||
import ch.njol.skript.lang.util.SimpleExpression; | ||
import ch.njol.util.Kleenean; | ||
import io.github.apickledwalrus.skriptplaceholders.skript.RelationalPlaceholderEvent; | ||
import org.bukkit.entity.Player; | ||
import org.bukkit.event.Event; | ||
import org.jetbrains.annotations.NotNull; | ||
import org.jetbrains.annotations.Nullable; | ||
|
||
@Name("Relational Placeholder Players") | ||
@Description("The two players involved in a relational placeholder request.") | ||
@Examples({ | ||
"on placeholderapi placeholder request for the relational prefix \"skriptplaceholders\":", | ||
"\tif the identifier is \"rel_longer_name\": # Placeholder is \"%skriptplaceholders_author%\"", | ||
"\t\tif the length of the name of the first player > the length of the name of the second player:", | ||
"\t\t\tset the result to the name of the first player", | ||
"\t\telse:", | ||
"\t\t\tset the result to the name of the second player" | ||
}) | ||
@Since("1.7.0") | ||
public class ExprRelationalPlayers extends SimpleExpression<Player> { | ||
|
||
static { | ||
Skript.registerExpression(ExprRelationalPlayers.class, Player.class, ExpressionType.SIMPLE, | ||
"[the] first player", | ||
"[the] second player" | ||
); | ||
} | ||
|
||
private boolean first; | ||
|
||
@Override | ||
public boolean init(Expression<?> @NotNull [] expressions, int matchedPattern, @NotNull Kleenean kleenean, @NotNull ParseResult parseResult) { | ||
if (!getParser().isCurrentEvent(RelationalPlaceholderEvent.class)) { | ||
Skript.error("'the " + (first ? "first" : "second") + " player' can only be used in custom relational placeholders."); | ||
} | ||
first = matchedPattern == 0; | ||
return true; | ||
} | ||
|
||
@Override | ||
protected Player @NotNull [] get(@NotNull Event e) { | ||
if (!(e instanceof RelationalPlaceholderEvent)) { | ||
return new Player[0]; | ||
} | ||
RelationalPlaceholderEvent event = (RelationalPlaceholderEvent) e; | ||
return new Player[]{first ? event.getPlayer() : event.getOther()}; | ||
} | ||
|
||
@Override | ||
public boolean isSingle() { | ||
return true; | ||
} | ||
|
||
@Override | ||
public @NotNull Class<? extends Player> getReturnType() { | ||
return Player.class; | ||
} | ||
|
||
@Override | ||
public @NotNull String toString(@Nullable Event event, boolean debug) { | ||
return "the " + (first ? "first" : "second") + " player"; | ||
} | ||
|
||
} |
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