Skip to content
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
wants to merge 18 commits into
base: dev/feature
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
78 changes: 78 additions & 0 deletions src/main/java/ch/njol/skript/expressions/ExprKickMessage.java
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")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
@Name("Kick Message")
@Name("On-screen 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)");
Copy link
Member

@Efnilite Efnilite Mar 3, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Skript.registerExpression(ExprKickMessage.class, String.class, ExpressionType.SIMPLE, "kick (message|reason)");
Skript.registerExpression(ExprKickMessage.class, String.class, ExpressionType.SIMPLE, "(display[ed]|on-screen) kick (message|reason)");

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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
}
}
}
}