-
-
Notifications
You must be signed in to change notification settings - Fork 386
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
[WIP] Add kick message expr #7658
Open
nopeless
wants to merge
18
commits into
SkriptLang:dev/feature
Choose a base branch
from
nopeless:master
base: dev/feature
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
28004b4
Add kick message expr
nopeless a2dae9b
Add proper placeholder for version
nopeless 6e83db1
Code clean up
nopeless 892b09b
Update src/main/java/ch/njol/skript/expressions/ExprKickMessage.java
nopeless d73e203
We only support 1.19.4+
nopeless 6dcda26
Merge branch 'master' of https://github.com/nopeless/Skript
nopeless f37986e
use deprecated api
nopeless 1affe07
resolve suggestions
nopeless bdc5d3e
mark method as nullable
nopeless da82cd6
remove minimessage entirely
nopeless 6659594
Update src/main/java/ch/njol/skript/expressions/ExprKickMessage.java
nopeless d4c88a1
Update src/main/java/ch/njol/skript/expressions/ExprKickMessage.java
nopeless bf8f9f3
Update src/main/java/ch/njol/skript/expressions/ExprKickMessage.java
nopeless b2552ee
Update src/main/java/ch/njol/skript/expressions/ExprKickMessage.java
nopeless 7d2f9c6
shorter import
nopeless 8066fc8
implement EventRestrictedSyntax
nopeless b8b2574
Merge branch 'dev/feature' into master
nopeless bc2e1ad
Update src/main/java/ch/njol/skript/expressions/ExprKickMessage.java
nopeless File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
78 changes: 78 additions & 0 deletions
78
src/main/java/ch/njol/skript/expressions/ExprKickMessage.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,78 @@ | ||||||||||||
package ch.njol.skript.expressions; | ||||||||||||
|
||||||||||||
import ch.njol.skript.classes.Changer.ChangeMode; | ||||||||||||
import ch.njol.skript.lang.EventRestrictedSyntax; | ||||||||||||
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 ch.njol.util.coll.CollectionUtils; | ||||||||||||
import org.bukkit.event.Event; | ||||||||||||
import org.bukkit.event.player.PlayerKickEvent; | ||||||||||||
import ch.njol.skript.Skript; | ||||||||||||
import ch.njol.skript.doc.*; | ||||||||||||
import org.jetbrains.annotations.Nullable; | ||||||||||||
|
||||||||||||
@Name("Kick Message") | ||||||||||||
@Description("The kick message that is displayed on-screen when a player is kicked.") | ||||||||||||
@Examples({ | ||||||||||||
"on kick:", | ||||||||||||
"\tkick message is 'Invalid hotbar selection (Hacking?)'", | ||||||||||||
"\tcancel event" | ||||||||||||
}) | ||||||||||||
@Since("INSERT VERSION") | ||||||||||||
@Events("Kick") | ||||||||||||
public class ExprKickMessage extends SimpleExpression<String> implements EventRestrictedSyntax { | ||||||||||||
|
||||||||||||
static { | ||||||||||||
Skript.registerExpression(ExprKickMessage.class, String.class, ExpressionType.SIMPLE, "kick (message|reason)"); | ||||||||||||
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
there should be a way to differentiate the chat kick message from this one |
||||||||||||
} | ||||||||||||
|
||||||||||||
@Override | ||||||||||||
public boolean init(Expression<?>[] expressions, int matchedPattern, Kleenean isDelayed, ParseResult parseResult) { | ||||||||||||
return true; | ||||||||||||
} | ||||||||||||
|
||||||||||||
@Override | ||||||||||||
protected String @Nullable [] get(Event event) { | ||||||||||||
if (event instanceof PlayerKickEvent playerKickEvent) { | ||||||||||||
return new String[] { playerKickEvent.getReason() }; | ||||||||||||
} | ||||||||||||
return null; | ||||||||||||
} | ||||||||||||
|
||||||||||||
@Override | ||||||||||||
public Class<?> @Nullable [] acceptChange(ChangeMode mode) { | ||||||||||||
return mode == ChangeMode.SET ? CollectionUtils.array(String.class) : null; | ||||||||||||
} | ||||||||||||
|
||||||||||||
@Override | ||||||||||||
public void change(Event event, Object @Nullable [] delta, ChangeMode mode) { | ||||||||||||
assert delta != null; | ||||||||||||
assert delta.length == 1; | ||||||||||||
if (event instanceof PlayerKickEvent kickEvent && delta[0] instanceof String text) { | ||||||||||||
kickEvent.setReason(text); | ||||||||||||
} | ||||||||||||
} | ||||||||||||
|
||||||||||||
@Override | ||||||||||||
public boolean isSingle() { | ||||||||||||
return true; | ||||||||||||
} | ||||||||||||
|
||||||||||||
@Override | ||||||||||||
public Class<? extends String> getReturnType() { | ||||||||||||
return String.class; | ||||||||||||
} | ||||||||||||
|
||||||||||||
@Override | ||||||||||||
public String toString(@Nullable Event event, boolean debug) { | ||||||||||||
return "the kick reason"; | ||||||||||||
} | ||||||||||||
|
||||||||||||
@Override | ||||||||||||
public Class<? extends Event>[] supportedEvents() { | ||||||||||||
return CollectionUtils.array(PlayerKickEvent.class); | ||||||||||||
} | ||||||||||||
} | ||||||||||||
Comment on lines
+77
to
+78
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
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.