-
-
Notifications
You must be signed in to change notification settings - Fork 413
A Complete Whitelist Module #8205
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: dev/feature
Are you sure you want to change the base?
Changes from all commits
18d347d
b0df785
1cfa46c
9ac835d
65b81dc
a10b4b0
4d451d9
2a9694b
7fa0de4
df62f37
92410d5
20904d1
93a67b7
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| package org.skriptlang.skript.bukkit.whitelist; | ||
|
|
||
| import java.io.IOException; | ||
|
|
||
| import ch.njol.skript.Skript; | ||
| import org.skriptlang.skript.addon.AddonModule; | ||
| import org.skriptlang.skript.addon.SkriptAddon; | ||
|
|
||
| public class WhitelistModule implements AddonModule { | ||
|
|
||
| @Override | ||
| public void load(SkriptAddon addon) { | ||
| try { | ||
| Skript.getAddonInstance().loadClasses("org.skriptlang.skript.bukkit.whitelist", "elements"); | ||
| } catch (IOException e) { | ||
| throw new RuntimeException(e); | ||
| } | ||
| } | ||
|
|
||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,74 @@ | ||
| package org.skriptlang.skript.bukkit.whitelist.elements; | ||
|
|
||
| import com.destroystokyo.paper.event.server.WhitelistToggleEvent; | ||
| import io.papermc.paper.event.server.WhitelistStateUpdateEvent; | ||
| import org.bukkit.event.Event; | ||
| import org.jetbrains.annotations.Nullable; | ||
|
|
||
| import ch.njol.skript.Skript; | ||
| import ch.njol.skript.doc.*; | ||
| import ch.njol.skript.lang.Condition; | ||
| import ch.njol.skript.lang.Expression; | ||
| import ch.njol.skript.lang.SkriptParser.ParseResult; | ||
| import ch.njol.skript.lang.SyntaxStringBuilder; | ||
| import ch.njol.util.Kleenean; | ||
|
|
||
| @Name("Will Be Whitelisted") | ||
| @Description("Checks whether the server or a player will be whitelisted in a <a href='events.html#whitelist'>whitelist</a> event.") | ||
| @Keywords("server, player") | ||
| @Example(""" | ||
| on server whitelist: | ||
| send "Server whitelist has been set to %whether server will be whitelisted%" to all ops | ||
| """) | ||
| @Example(""" | ||
| on player whitelist: | ||
| send "Whitelist of player %event-player% has been set to %whether server will be whitelisted%" to all ops | ||
| """) | ||
| @Since("INSERT VERSION") | ||
| public class CondWillBeWhitelisted extends Condition { | ||
|
|
||
| static { | ||
| Skript.registerCondition(CondWillBeWhitelisted.class, | ||
| "[the] (:player|server) will be whitelisted", | ||
| "[the] (:player|server) (will not|won't) be whitelisted" | ||
| ); | ||
NotSoDelayed marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| } | ||
|
|
||
| private boolean isServer; | ||
|
|
||
| @Override | ||
| public boolean init(Expression<?>[] expressions, int matchedPattern, Kleenean isDelayed, ParseResult parseResult) { | ||
| isServer = !parseResult.hasTag("player"); | ||
| if (isServer) { | ||
| if (!getParser().isCurrentEvent(WhitelistToggleEvent.class)) { | ||
| Skript.error("The 'server will be whitelisted' condition can only be used in an 'server whitelist' event"); | ||
| return false; | ||
| } | ||
| } else { | ||
| if (!getParser().isCurrentEvent(WhitelistStateUpdateEvent.class)) { | ||
| Skript.error("The 'player will be whitelisted' condition can only be used in an 'player whitelist' event"); | ||
| return false; | ||
| } | ||
| } | ||
| setNegated(matchedPattern == 1); | ||
| return true; | ||
| } | ||
|
|
||
| @Override | ||
| public boolean check(Event event) { | ||
| if (isServer) | ||
| return ((WhitelistToggleEvent) event).isEnabled() ^ isNegated(); | ||
| return (((WhitelistStateUpdateEvent) event).getStatus() == WhitelistStateUpdateEvent.WhitelistStatus.ADDED) ^ isNegated(); | ||
| } | ||
|
|
||
| @Override | ||
| public String toString(@Nullable Event event, boolean debug) { | ||
| return new SyntaxStringBuilder(event, debug) | ||
| .append("the") | ||
| .append(isServer ? "server" : "player") | ||
| .append(isNegated() ? "will not" : "will") | ||
| .append("be whitelisted") | ||
| .toString(); | ||
|
Comment on lines
+66
to
+71
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this should use if statements instead of ternary to improve readability
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. was this resolved? |
||
| } | ||
|
|
||
| } | ||
| Original file line number | Diff line number | Diff line change | ||
|---|---|---|---|---|
| @@ -0,0 +1,88 @@ | ||||
| package org.skriptlang.skript.bukkit.whitelist.elements; | ||||
|
|
||||
| import io.papermc.paper.event.server.WhitelistStateUpdateEvent; | ||||
| import io.papermc.paper.event.server.WhitelistStateUpdateEvent.WhitelistStatus; | ||||
| import org.bukkit.OfflinePlayer; | ||||
| import org.bukkit.event.Event; | ||||
| import org.jetbrains.annotations.Nullable; | ||||
|
|
||||
| import ch.njol.skript.Skript; | ||||
| import ch.njol.skript.lang.Literal; | ||||
| import ch.njol.skript.lang.SkriptEvent; | ||||
| import ch.njol.skript.lang.SkriptParser.ParseResult; | ||||
| import ch.njol.skript.lang.SyntaxStringBuilder; | ||||
| import ch.njol.skript.registrations.EventValues; | ||||
|
|
||||
| public class EvtPlayerWhitelist extends SkriptEvent { | ||||
|
|
||||
| private enum EventState { | ||||
|
|
||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||
| WHITELISTED("whitelisted"), | ||||
| UNWHITELISTED("unwhitelisted"); | ||||
|
|
||||
| final String toString; | ||||
|
|
||||
| EventState(String toString) { | ||||
| this.toString = toString; | ||||
| } | ||||
|
|
||||
| @Override | ||||
| public String toString() { | ||||
| return toString; | ||||
| } | ||||
|
|
||||
| } | ||||
|
|
||||
| static { | ||||
| Skript.registerEvent("Player Whitelist", EvtPlayerWhitelist.class, WhitelistStateUpdateEvent.class, | ||||
| "player whitelist [state] (change[d]|update[d])", | ||||
| "player (added to whitelist|whitelist[ed])", | ||||
| "player (removed from whitelist|unwhitelist[ed])") | ||||
| .description( | ||||
| "Called whenever a player has been added to or removed from the server's whitelist.", | ||||
| "Use <a href='conditions.html#CondWillBeWhitelisted'>will be whitelisted</a> condition to check with its state.") | ||||
| .examples( | ||||
| "on player whitelisted:", | ||||
| "on player unwhitelisted:", | ||||
| "", | ||||
| "on player whitelist state changed:", | ||||
| "\tsend \"Whitelist of player %event-offlineplayer% has been set to %whether server will be whitelisted%\" to all ops") | ||||
| .since("INSERT VERSION"); | ||||
|
|
||||
| EventValues.registerEventValue(WhitelistStateUpdateEvent.class, OfflinePlayer.class, WhitelistStateUpdateEvent::getPlayer); | ||||
| } | ||||
|
|
||||
| private @Nullable EventState state = null; | ||||
|
|
||||
| @Override | ||||
| public boolean init(Literal<?>[] args, int matchedPattern, ParseResult parseResult) { | ||||
| if (matchedPattern == 1) | ||||
| state = EventState.WHITELISTED; | ||||
| else if (matchedPattern == 2) | ||||
| state = EventState.UNWHITELISTED; | ||||
| return true; | ||||
| } | ||||
|
|
||||
| @Override | ||||
| public boolean check(Event event) { | ||||
| if (state != null) | ||||
| return (state == EventState.WHITELISTED) == (((WhitelistStateUpdateEvent) event).getStatus() == WhitelistStatus.ADDED); | ||||
| return true; | ||||
| } | ||||
|
|
||||
| @Override | ||||
| public String toString(@Nullable Event event, boolean debug) { | ||||
| SyntaxStringBuilder builder = new SyntaxStringBuilder(event, debug) | ||||
| .append("player"); | ||||
| if (state != null) { | ||||
| if (state == EventState.WHITELISTED) | ||||
| builder.append("added to whitelist"); | ||||
| else | ||||
| builder.append("removed from whitelist"); | ||||
| } else { | ||||
| builder.append("whitelist state changed"); | ||||
| } | ||||
| return builder.toString(); | ||||
| } | ||||
|
|
||||
| } | ||||
| Original file line number | Diff line number | Diff line change | ||
|---|---|---|---|---|
| @@ -0,0 +1,74 @@ | ||||
| package org.skriptlang.skript.bukkit.whitelist.elements; | ||||
|
|
||||
| import com.destroystokyo.paper.event.server.WhitelistToggleEvent; | ||||
| import org.bukkit.event.Event; | ||||
| import org.jetbrains.annotations.Nullable; | ||||
|
|
||||
| import ch.njol.skript.Skript; | ||||
| import ch.njol.skript.lang.Literal; | ||||
| import ch.njol.skript.lang.SkriptEvent; | ||||
| import ch.njol.skript.lang.SkriptParser.ParseResult; | ||||
| import ch.njol.skript.lang.SyntaxStringBuilder; | ||||
|
|
||||
| public class EvtServerWhitelist extends SkriptEvent { | ||||
|
|
||||
| private enum EventState { | ||||
|
|
||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||
| ON("on"), | ||||
| OFF("off"); | ||||
|
|
||||
| final String toString; | ||||
|
|
||||
| EventState(String toString) { | ||||
| this.toString = toString; | ||||
| } | ||||
|
|
||||
| @Override | ||||
| public String toString() { | ||||
| return toString; | ||||
| } | ||||
|
|
||||
| } | ||||
|
|
||||
| static { | ||||
| Skript.registerEvent("Whitelist Toggled", EvtServerWhitelist.class, WhitelistToggleEvent.class, "whitelist toggle[d] [:on|:off]") | ||||
| .description( | ||||
| "Called whenever the server's whitelist has been toggled on or off.", | ||||
| "Use <a href='conditions.html#CondWillBeWhitelisted'>will be whitelisted</a> condition to check with its state.") | ||||
| .examples( | ||||
| "on whitelist toggled on:", | ||||
| "on whitelist toggled off:", | ||||
| "", | ||||
| "on whitelist toggled:", | ||||
| "\tsend \"Server whitelist has been set to %whether server will be whitelisted%\" to all ops") | ||||
| .since("INSERT VERSION"); | ||||
| } | ||||
|
|
||||
| private @Nullable EventState state = null; | ||||
|
|
||||
| @Override | ||||
| public boolean init(Literal<?>[] args, int matchedPattern, ParseResult parseResult) { | ||||
| if (parseResult.hasTag("on")) | ||||
| state = EventState.ON; | ||||
| else if (parseResult.hasTag("off")) | ||||
| state = EventState.OFF; | ||||
| return true; | ||||
| } | ||||
|
|
||||
| @Override | ||||
| public boolean check(Event event) { | ||||
| if (state != null) | ||||
| return (state == EventState.ON) == ((WhitelistToggleEvent) event).isEnabled(); | ||||
| return true; | ||||
| } | ||||
|
|
||||
| @Override | ||||
| public String toString(@Nullable Event event, boolean debug) { | ||||
| SyntaxStringBuilder builder = new SyntaxStringBuilder(event, debug) | ||||
| .append("server whitelist toggled"); | ||||
| if (state != null) | ||||
| builder.append(state); | ||||
| return builder.toString(); | ||||
| } | ||||
|
|
||||
| } | ||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.