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

Add delete changer to ExprMessage #6828

Merged
merged 12 commits into from
Jul 1, 2024
32 changes: 18 additions & 14 deletions src/main/java/ch/njol/skript/expressions/ExprMessage.java
Original file line number Diff line number Diff line change
Expand Up @@ -48,23 +48,27 @@
@SuppressWarnings("deprecation")
@Name("Message")
@Description("The (chat) message of a chat event, the join message of a join event, the quit message of a quit event, or the death message on a death event. This expression is mostly useful for being changed.")
@Examples({"on chat:",
" player has permission \"admin\"",
" set message to \"&c%message%\"",
@Examples({
"on chat:",
"\tplayer has permission \"admin\"",
"\tset message to \"&c%message%\"",
"",
"on first join:",
" set join message to \"Welcome %player% to our awesome server!\"",
"\tset join message to \"Welcome %player% to our awesome server!\"",
"",
"on join:",
" player has played before",
" set join message to \"Welcome back, %player%!\"",
"\tplayer has played before",
"\tset join message to \"Welcome back, %player%!\"",
"",
"on quit:",
" set quit message to \"%player% left this awesome server!\"",
"\tif {vanish::%player's uuid%} is set:",
"\t\tclear quit message",
"\telse:",
"\t\tset quit message to \"%player% left this awesome server!\"",
"",
"on death:",
" set the death message to \"%player% died!\""})
@Since("1.4.6 (chat message), 1.4.9 (join & quit messages), 2.0 (death message)")
"\tset the death message to \"%player% died!\""})
@Since("1.4.6 (chat message), 1.4.9 (join & quit messages), 2.0 (death message), INSERT VERSION (clear message)")
@Events({"chat", "join", "quit", "death"})
public class ExprMessage extends SimpleExpression<String> {

Expand Down Expand Up @@ -181,18 +185,18 @@ protected String[] get(final Event e) {
@Override
@Nullable
public Class<?>[] acceptChange(final ChangeMode mode) {
if (mode == ChangeMode.SET)
if (mode == ChangeMode.SET || mode == ChangeMode.DELETE)
return CollectionUtils.array(String.class);
return null;
}

@Override
public void change(final Event e, final @Nullable Object[] delta, final ChangeMode mode) {
assert mode == ChangeMode.SET;
assert delta != null;
assert mode == ChangeMode.SET || mode == ChangeMode.DELETE;
for (final Class<? extends Event> c : type.events) {
if (c.isInstance(e))
type.set(e, "" + delta[0]);
if (c.isInstance(e)) {
type.set(e, (mode == ChangeMode.DELETE) ? "" : "" + delta[0]);
Phill310 marked this conversation as resolved.
Show resolved Hide resolved
}
}
}

Expand Down