From 804b7ab72fdf4daa94adc1278212afff4ac25709 Mon Sep 17 00:00:00 2001 From: TheLimeGlass Date: Tue, 18 Apr 2023 21:23:49 -0600 Subject: [PATCH 01/16] Add server broadcast event --- .../ch/njol/skript/events/SimpleEvents.java | 12 +- .../expressions/ExprChatRecipients.java | 99 ++++++++------ .../njol/skript/expressions/ExprMessage.java | 129 ++++++++++-------- 3 files changed, 138 insertions(+), 102 deletions(-) diff --git a/src/main/java/ch/njol/skript/events/SimpleEvents.java b/src/main/java/ch/njol/skript/events/SimpleEvents.java index 6e1aa2b7004..ec7d3a8264f 100644 --- a/src/main/java/ch/njol/skript/events/SimpleEvents.java +++ b/src/main/java/ch/njol/skript/events/SimpleEvents.java @@ -88,6 +88,7 @@ import org.bukkit.event.player.PlayerToggleFlightEvent; import org.bukkit.event.player.PlayerToggleSneakEvent; import org.bukkit.event.player.PlayerToggleSprintEvent; +import org.bukkit.event.server.BroadcastMessageEvent; import org.bukkit.event.server.ServerListPingEvent; import org.bukkit.event.vehicle.VehicleCreateEvent; import org.bukkit.event.vehicle.VehicleDamageEvent; @@ -118,9 +119,6 @@ import ch.njol.skript.SkriptEventHandler; import ch.njol.skript.lang.util.SimpleEvent; -/** - * @author Peter Güttinger - */ public class SimpleEvents { static { Skript.registerEvent("Can Build Check", SimpleEvent.class, BlockCanBuildEvent.class, "[block] can build check") @@ -709,6 +707,14 @@ public class SimpleEvents { .requiredPlugins("Paper 1.16+"); } + Skript.registerEvent("Server Broadcast", SimpleEvent.class, BroadcastMessageEvent.class, "[server] broadcast") + .description("Called when the server broadcasts messages such as from the broadcast effect.") + .examples("on item mend:", + "on server broadcast", + "\tbroadcast-message contains \"example\"", + "\tcancel event") + .since("INSERT VERSION"); + } } diff --git a/src/main/java/ch/njol/skript/expressions/ExprChatRecipients.java b/src/main/java/ch/njol/skript/expressions/ExprChatRecipients.java index bda0a00f294..b47ec8a4f9a 100644 --- a/src/main/java/ch/njol/skript/expressions/ExprChatRecipients.java +++ b/src/main/java/ch/njol/skript/expressions/ExprChatRecipients.java @@ -18,11 +18,11 @@ */ package ch.njol.skript.expressions; -import java.util.Set; - +import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; import org.bukkit.event.Event; import org.bukkit.event.player.AsyncPlayerChatEvent; +import org.bukkit.event.server.BroadcastMessageEvent; import org.eclipse.jdt.annotation.Nullable; import ch.njol.skript.Skript; @@ -40,71 +40,70 @@ import ch.njol.util.coll.CollectionUtils; @Name("Chat Recipients") -@Description("Recipients of chat events where this is called.") +@Description("Recipients of chat/broadcast events where this is called.") @Examples("chat recipients") -@Since("2.2-Fixes-v7, 2.2-dev35 (clearing recipients)") -public class ExprChatRecipients extends SimpleExpression { +@Since("2.2-Fixes-v7, 2.2-dev35 (clearing recipients), INSERT VERSION (broadcast event)") +public class ExprChatRecipients extends SimpleExpression { static { - Skript.registerExpression(ExprChatRecipients.class, Player.class, ExpressionType.SIMPLE, "[chat][( |-)]recipients"); - } - - @Override - public boolean isSingle() { - return false; - } - - @Override - public Class getReturnType() { - return Player.class; - } - - @Override - public Class[] acceptChange(final ChangeMode mode) { - return CollectionUtils.array(Player[].class); + Skript.registerExpression(ExprChatRecipients.class, CommandSender.class, ExpressionType.SIMPLE, "[chat][( |-)]recipients"); } @Override public boolean init(Expression[] exprs, int matchedPattern, Kleenean isDelayed, ParseResult parseResult) { - if (!(getParser().isCurrentEvent(AsyncPlayerChatEvent.class))) { - Skript.error("Cannot use chat recipients expression outside of a chat event", ErrorQuality.SEMANTIC_ERROR); + if (!(getParser().isCurrentEvent(AsyncPlayerChatEvent.class, BroadcastMessageEvent.class))) { + Skript.error("Cannot use chat recipients expression outside of a chat or server broadcast event", ErrorQuality.SEMANTIC_ERROR); return false; } return true; } @Override - public String toString(@Nullable Event event, boolean debug) { - return "chat recipients"; + @Nullable + protected CommandSender[] get(Event event) { + if (event instanceof AsyncPlayerChatEvent) { + AsyncPlayerChatEvent chatEvent = (AsyncPlayerChatEvent) event; + return chatEvent.getRecipients().toArray(new Player[0]); + } else if (event instanceof BroadcastMessageEvent) { + BroadcastMessageEvent broadcastEvent = (BroadcastMessageEvent) event; + return broadcastEvent.getRecipients().toArray(new CommandSender[0]); + } + return null; } @Override - @Nullable - protected Player[] get(Event event) { - if (!(event instanceof AsyncPlayerChatEvent)) - return null; - - AsyncPlayerChatEvent ae = (AsyncPlayerChatEvent) event; - Set playerSet = ae.getRecipients(); - return playerSet.toArray(new Player[playerSet.size()]); + public Class[] acceptChange(ChangeMode mode) { + return CollectionUtils.array(CommandSender[].class); } @Override public void change(Event event, @Nullable Object[] delta, ChangeMode mode) { - if (!(event instanceof AsyncPlayerChatEvent)) + if (!(event instanceof AsyncPlayerChatEvent) || !(event instanceof BroadcastMessageEvent)) return; - final Player[] recipients = (Player[]) delta; + CommandSender[] recipients = (CommandSender[]) delta; switch (mode) { case REMOVE: assert recipients != null; - for (Player player : recipients) - ((AsyncPlayerChatEvent) event).getRecipients().remove(player); + if (event instanceof AsyncPlayerChatEvent) { + for (CommandSender sender : recipients) + ((AsyncPlayerChatEvent) event).getRecipients().remove(sender); + } else { + for (CommandSender sender : recipients) + ((BroadcastMessageEvent) event).getRecipients().remove(sender); + } break; case ADD: assert recipients != null; - for (Player player : recipients) - ((AsyncPlayerChatEvent) event).getRecipients().add(player); + if (event instanceof AsyncPlayerChatEvent) { + for (CommandSender sender : recipients) { + if (sender instanceof Player) + ((AsyncPlayerChatEvent) event).getRecipients().add((Player) sender); + } + } else { + for (CommandSender sender : recipients) + ((BroadcastMessageEvent) event).getRecipients().add((Player) sender); + } break; case SET: change(event, delta, ChangeMode.DELETE); @@ -113,8 +112,28 @@ public void change(Event event, @Nullable Object[] delta, ChangeMode mode) { case REMOVE_ALL: case RESET: case DELETE: - ((AsyncPlayerChatEvent) event).getRecipients().clear(); + if (event instanceof AsyncPlayerChatEvent) { + ((AsyncPlayerChatEvent) event).getRecipients().clear(); + } else { + ((BroadcastMessageEvent) event).getRecipients().clear(); + } break; } } + + @Override + public boolean isSingle() { + return false; + } + + @Override + public Class getReturnType() { + return CommandSender.class; + } + + @Override + public String toString(@Nullable Event event, boolean debug) { + return "chat recipients"; + } + } diff --git a/src/main/java/ch/njol/skript/expressions/ExprMessage.java b/src/main/java/ch/njol/skript/expressions/ExprMessage.java index a3b54f43c4c..845e35f13bc 100644 --- a/src/main/java/ch/njol/skript/expressions/ExprMessage.java +++ b/src/main/java/ch/njol/skript/expressions/ExprMessage.java @@ -25,6 +25,7 @@ import org.bukkit.event.player.PlayerJoinEvent; import org.bukkit.event.player.PlayerKickEvent; import org.bukkit.event.player.PlayerQuitEvent; +import org.bukkit.event.server.BroadcastMessageEvent; import org.eclipse.jdt.annotation.Nullable; import ch.njol.skript.Skript; @@ -42,9 +43,6 @@ import ch.njol.util.Kleenean; import ch.njol.util.coll.CollectionUtils; -/** - * @author Peter Güttinger - */ @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.") @@ -63,11 +61,14 @@ " set 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)") + " set the death message to \"%player% died!\"", + "", + "on server broadcast:", + " set the broadcast message to \"something else!\""}) +@Since("1.4.6 (chat message), 1.4.9 (join & quit messages), 2.0 (death message), INSERT VERSION (broadcast message)") @Events({"chat", "join", "quit", "death"}) public class ExprMessage extends SimpleExpression { - + @SuppressWarnings("unchecked") private static enum MessageType { CHAT("chat", "[chat( |-)]message", AsyncPlayerChatEvent.class) { @@ -75,7 +76,7 @@ private static enum MessageType { String get(Event event) { return ((AsyncPlayerChatEvent) event).getMessage(); } - + @Override void set(Event event, String message) { ((AsyncPlayerChatEvent) event).setMessage(message); @@ -84,83 +85,93 @@ void set(Event event, String message) { JOIN("join", "(join|log[ ]in)( |-)message", PlayerJoinEvent.class) { @Override @Nullable - String get(final Event e) { - return ((PlayerJoinEvent) e).getJoinMessage(); + String get(Event event) { + return ((PlayerJoinEvent) event).getJoinMessage(); } - + @Override - void set(final Event e, final String message) { - ((PlayerJoinEvent) e).setJoinMessage(message); + void set(Event event, String message) { + ((PlayerJoinEvent) event).setJoinMessage(message); } }, QUIT("quit", "(quit|leave|log[ ]out|kick)( |-)message", PlayerQuitEvent.class, PlayerKickEvent.class) { @Override @Nullable - String get(final Event e) { - if (e instanceof PlayerKickEvent) - return ((PlayerKickEvent) e).getLeaveMessage(); + String get(Event event) { + if (event instanceof PlayerKickEvent) + return ((PlayerKickEvent) event).getLeaveMessage(); else - return ((PlayerQuitEvent) e).getQuitMessage(); + return ((PlayerQuitEvent) event).getQuitMessage(); } @Override - void set(final Event e, final String message) { - if (e instanceof PlayerKickEvent) - ((PlayerKickEvent) e).setLeaveMessage(message); + void set(Event event, String message) { + if (event instanceof PlayerKickEvent) + ((PlayerKickEvent) event).setLeaveMessage(message); else - ((PlayerQuitEvent) e).setQuitMessage(message); + ((PlayerQuitEvent) event).setQuitMessage(message); } }, DEATH("death", "death( |-)message", EntityDeathEvent.class) { @Override @Nullable - String get(final Event e) { - if (e instanceof PlayerDeathEvent) - return ((PlayerDeathEvent) e).getDeathMessage(); + String get(Event event) { + if (event instanceof PlayerDeathEvent) + return ((PlayerDeathEvent) event).getDeathMessage(); return null; } @Override - void set(final Event e, final String message) { - if (e instanceof PlayerDeathEvent) - ((PlayerDeathEvent) e).setDeathMessage(message); + void set(Event event, String message) { + if (event instanceof PlayerDeathEvent) + ((PlayerDeathEvent) event).setDeathMessage(message); + } + }, + BROADCAST("broadcast", "broadcast( |-)message", BroadcastMessageEvent.class) { + @Override + @Nullable + String get(Event event) { + return ((PlayerJoinEvent) event).getJoinMessage(); + } + + @Override + void set(Event event, String message) { + ((PlayerJoinEvent) event).setJoinMessage(message); } }; - + final String name; private final String pattern; final Class[] events; - - MessageType(final String name, final String pattern, final Class... events) { + + MessageType(String name, String pattern, Class... events) { this.name = name; this.pattern = "[the] " + pattern; this.events = events; } - + static String[] patterns; static { patterns = new String[values().length]; for (int i = 0; i < patterns.length; i++) patterns[i] = values()[i].pattern; } - + @Nullable - abstract String get(Event e); - - abstract void set(Event e, String message); - + abstract String get(Event event); + + abstract void set(Event event, String message); + } - + static { Skript.registerExpression(ExprMessage.class, String.class, ExpressionType.SIMPLE, MessageType.patterns); } - - @SuppressWarnings("null") + private MessageType type; - - @SuppressWarnings("null") + @Override - public boolean init(final Expression[] exprs, final int matchedPattern, final Kleenean isDelayed, final ParseResult parseResult) { + public boolean init(Expression[] exprs, int matchedPattern, Kleenean isDelayed, ParseResult parseResult) { type = MessageType.values()[matchedPattern]; if (!getParser().isCurrentEvent(type.events)) { Skript.error("The " + type.name + " message can only be used in a " + type.name + " event", ErrorQuality.SEMANTIC_ERROR); @@ -168,47 +179,47 @@ public boolean init(final Expression[] exprs, final int matchedPattern, final } return true; } - + @Override - protected String[] get(final Event e) { - for (final Class c : type.events) { - if (c.isInstance(e)) - return new String[] {type.get(e)}; + protected String[] get(Event event) { + for (Class c : type.events) { + if (c.isInstance(event)) + return new String[] {type.get(event)}; } return new String[0]; } - + @Override @Nullable - public Class[] acceptChange(final ChangeMode mode) { + public Class[] acceptChange(ChangeMode mode) { if (mode == ChangeMode.SET) return CollectionUtils.array(String.class); return null; } - + @Override - public void change(final Event e, final @Nullable Object[] delta, final ChangeMode mode) { + public void change(Event event, @Nullable Object[] delta, ChangeMode mode) { assert mode == ChangeMode.SET; assert delta != null; - for (final Class c : type.events) { - if (c.isInstance(e)) - type.set(e, "" + delta[0]); + for (Class c : type.events) { + if (c.isInstance(event)) + type.set(event, "" + delta[0]); } } - + @Override public boolean isSingle() { return true; } - + @Override public Class getReturnType() { return String.class; } - + @Override - public String toString(final @Nullable Event e, final boolean debug) { - return "the " + type.name + " message"; + public String toString(@Nullable Event event, final boolean debug) { + return type.name + " message"; } - + } From 0506270f806e3a504925c16bb26f019bb9cb62ea Mon Sep 17 00:00:00 2001 From: TheLimeGlass Date: Tue, 18 Apr 2023 22:16:58 -0600 Subject: [PATCH 02/16] Update description --- src/main/java/ch/njol/skript/events/SimpleEvents.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/ch/njol/skript/events/SimpleEvents.java b/src/main/java/ch/njol/skript/events/SimpleEvents.java index ec7d3a8264f..311bd489c42 100644 --- a/src/main/java/ch/njol/skript/events/SimpleEvents.java +++ b/src/main/java/ch/njol/skript/events/SimpleEvents.java @@ -708,7 +708,7 @@ public class SimpleEvents { } Skript.registerEvent("Server Broadcast", SimpleEvent.class, BroadcastMessageEvent.class, "[server] broadcast") - .description("Called when the server broadcasts messages such as from the broadcast effect.") + .description("Called when the server broadcasts messages.") .examples("on item mend:", "on server broadcast", "\tbroadcast-message contains \"example\"", From 5d1258d4256d4273fd693e93f853607b210d3ca1 Mon Sep 17 00:00:00 2001 From: LimeGlass <16087552+TheLimeGlass@users.noreply.github.com> Date: Sun, 30 Jul 2023 02:54:43 -0600 Subject: [PATCH 03/16] Update src/main/java/ch/njol/skript/expressions/ExprChatRecipients.java Co-authored-by: Ayham Al Ali <20037329+AyhamAl-Ali@users.noreply.github.com> --- .../java/ch/njol/skript/expressions/ExprChatRecipients.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/ch/njol/skript/expressions/ExprChatRecipients.java b/src/main/java/ch/njol/skript/expressions/ExprChatRecipients.java index b47ec8a4f9a..a65125c1ca1 100644 --- a/src/main/java/ch/njol/skript/expressions/ExprChatRecipients.java +++ b/src/main/java/ch/njol/skript/expressions/ExprChatRecipients.java @@ -52,7 +52,7 @@ public class ExprChatRecipients extends SimpleExpression { @Override public boolean init(Expression[] exprs, int matchedPattern, Kleenean isDelayed, ParseResult parseResult) { if (!(getParser().isCurrentEvent(AsyncPlayerChatEvent.class, BroadcastMessageEvent.class))) { - Skript.error("Cannot use chat recipients expression outside of a chat or server broadcast event", ErrorQuality.SEMANTIC_ERROR); + Skript.error("Cannot use chat recipients expression outside of a chat or server broadcast event"); return false; } return true; From 10b7621eab022c74aacc87945fd3d4ba8e9209f6 Mon Sep 17 00:00:00 2001 From: LimeGlass <16087552+TheLimeGlass@users.noreply.github.com> Date: Sun, 30 Jul 2023 03:03:58 -0600 Subject: [PATCH 04/16] Update src/main/java/ch/njol/skript/expressions/ExprChatRecipients.java Co-authored-by: Ayham Al Ali <20037329+AyhamAl-Ali@users.noreply.github.com> --- .../java/ch/njol/skript/expressions/ExprChatRecipients.java | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/main/java/ch/njol/skript/expressions/ExprChatRecipients.java b/src/main/java/ch/njol/skript/expressions/ExprChatRecipients.java index a65125c1ca1..8e69918e4a3 100644 --- a/src/main/java/ch/njol/skript/expressions/ExprChatRecipients.java +++ b/src/main/java/ch/njol/skript/expressions/ExprChatRecipients.java @@ -62,11 +62,9 @@ public boolean init(Expression[] exprs, int matchedPattern, Kleenean isDelaye @Nullable protected CommandSender[] get(Event event) { if (event instanceof AsyncPlayerChatEvent) { - AsyncPlayerChatEvent chatEvent = (AsyncPlayerChatEvent) event; - return chatEvent.getRecipients().toArray(new Player[0]); + return ((AsyncPlayerChatEvent) event).getRecipients().toArray(new Player[0]); } else if (event instanceof BroadcastMessageEvent) { - BroadcastMessageEvent broadcastEvent = (BroadcastMessageEvent) event; - return broadcastEvent.getRecipients().toArray(new CommandSender[0]); + return ((BroadcastMessageEvent) event).getRecipients().toArray(new CommandSender[0]); } return null; } From 91407982ecb0e6fe0984dcb2f79562cb8fc95d91 Mon Sep 17 00:00:00 2001 From: TheLimeGlass Date: Sun, 30 Jul 2023 03:04:40 -0600 Subject: [PATCH 05/16] Address reviews --- .../ch/njol/skript/events/SimpleEvents.java | 12 +++--- .../njol/skript/expressions/ExprMessage.java | 42 ++++++++++--------- 2 files changed, 29 insertions(+), 25 deletions(-) diff --git a/src/main/java/ch/njol/skript/events/SimpleEvents.java b/src/main/java/ch/njol/skript/events/SimpleEvents.java index b2a80d227d9..64b41269c95 100644 --- a/src/main/java/ch/njol/skript/events/SimpleEvents.java +++ b/src/main/java/ch/njol/skript/events/SimpleEvents.java @@ -723,17 +723,19 @@ public class SimpleEvents { .description("Called when a player drags an item in their cursor across the inventory.") .examples( "on inventory drag:", - "\tif player's current inventory is {_gui}:", - "\t\tsend \"You can't drag your items here!\" to player", - "\t\tcancel event" + "\tif player's current inventory is {_gui}:", + "\t\tsend \"You can't drag your items here!\" to player", + "\t\tcancel event" ) + .since("INSERT VERSION"); Skript.registerEvent("Server Broadcast", SimpleEvent.class, BroadcastMessageEvent.class, "[server] broadcast") .description("Called when the server broadcasts messages.") - .examples("on item mend:", + .examples( "on server broadcast", "\tbroadcast-message contains \"example\"", - "\tcancel event") + "\tcancel event" + ) .since("INSERT VERSION"); } diff --git a/src/main/java/ch/njol/skript/expressions/ExprMessage.java b/src/main/java/ch/njol/skript/expressions/ExprMessage.java index 845e35f13bc..211a643015d 100644 --- a/src/main/java/ch/njol/skript/expressions/ExprMessage.java +++ b/src/main/java/ch/njol/skript/expressions/ExprMessage.java @@ -46,25 +46,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%\"", - "", - "on first join:", - " set join message to \"Welcome %player% to our awesome server!\"", - "", - "on join:", - " player has played before", - " set join message to \"Welcome back, %player%!\"", - "", - "on quit:", - " set quit message to \"%player% left this awesome server!\"", - "", - "on death:", - " set the death message to \"%player% died!\"", - "", - "on server broadcast:", - " set the broadcast message to \"something else!\""}) +@Examples({ + "on chat:", + "\tplayer has permission \"admin\"", + "\tset message to \"&c%message%\"", + "", + "on first join:", + "\tset join message to \"Welcome %player% to our awesome server!\"", + "", + "on join:", + "\tplayer has played before", + "\tset join message to \"Welcome back, %player%!\"", + "", + "on quit:", + "\tset quit message to \"%player% left this awesome server!\"", + "", + "on death:", + "\tset the death message to \"%player% died!\"", + "", + "on server broadcast:", + "\tset the broadcast message to \"something else!\"" +}) @Since("1.4.6 (chat message), 1.4.9 (join & quit messages), 2.0 (death message), INSERT VERSION (broadcast message)") @Events({"chat", "join", "quit", "death"}) public class ExprMessage extends SimpleExpression { @@ -136,7 +138,7 @@ String get(Event event) { @Override void set(Event event, String message) { - ((PlayerJoinEvent) event).setJoinMessage(message); + ((BroadcastMessageEvent) event).setMessage(message); } }; From 99c4a1069a6cf35ab14ed3cc91b7d7eab713cee4 Mon Sep 17 00:00:00 2001 From: LimeGlass <16087552+TheLimeGlass@users.noreply.github.com> Date: Sun, 30 Jul 2023 15:07:24 -0600 Subject: [PATCH 06/16] Update src/main/java/ch/njol/skript/events/SimpleEvents.java Co-authored-by: Ayham Al Ali <20037329+AyhamAl-Ali@users.noreply.github.com> --- src/main/java/ch/njol/skript/events/SimpleEvents.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/ch/njol/skript/events/SimpleEvents.java b/src/main/java/ch/njol/skript/events/SimpleEvents.java index 64b41269c95..850c8476a2f 100644 --- a/src/main/java/ch/njol/skript/events/SimpleEvents.java +++ b/src/main/java/ch/njol/skript/events/SimpleEvents.java @@ -732,7 +732,7 @@ public class SimpleEvents { Skript.registerEvent("Server Broadcast", SimpleEvent.class, BroadcastMessageEvent.class, "[server] broadcast") .description("Called when the server broadcasts messages.") .examples( - "on server broadcast", + "on server broadcast:", "\tbroadcast-message contains \"example\"", "\tcancel event" ) From 087ad0df4d493eee98dc2df1cc1fb182123c2518 Mon Sep 17 00:00:00 2001 From: LimeGlass <16087552+TheLimeGlass@users.noreply.github.com> Date: Sun, 30 Jul 2023 15:09:24 -0600 Subject: [PATCH 07/16] Apply suggestions from code review Co-authored-by: Ayham Al Ali <20037329+AyhamAl-Ali@users.noreply.github.com> --- .../java/ch/njol/skript/expressions/ExprChatRecipients.java | 2 +- src/main/java/ch/njol/skript/expressions/ExprMessage.java | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/main/java/ch/njol/skript/expressions/ExprChatRecipients.java b/src/main/java/ch/njol/skript/expressions/ExprChatRecipients.java index 8e69918e4a3..8016e1ddef7 100644 --- a/src/main/java/ch/njol/skript/expressions/ExprChatRecipients.java +++ b/src/main/java/ch/njol/skript/expressions/ExprChatRecipients.java @@ -100,7 +100,7 @@ public void change(Event event, @Nullable Object[] delta, ChangeMode mode) { } } else { for (CommandSender sender : recipients) - ((BroadcastMessageEvent) event).getRecipients().add((Player) sender); + ((BroadcastMessageEvent) event).getRecipients().add(sender); } break; case SET: diff --git a/src/main/java/ch/njol/skript/expressions/ExprMessage.java b/src/main/java/ch/njol/skript/expressions/ExprMessage.java index 211a643015d..c7e644a9544 100644 --- a/src/main/java/ch/njol/skript/expressions/ExprMessage.java +++ b/src/main/java/ch/njol/skript/expressions/ExprMessage.java @@ -68,7 +68,7 @@ "\tset the broadcast message to \"something else!\"" }) @Since("1.4.6 (chat message), 1.4.9 (join & quit messages), 2.0 (death message), INSERT VERSION (broadcast message)") -@Events({"chat", "join", "quit", "death"}) +@Events({"chat", "join", "quit", "death", "server_broadcast"}) public class ExprMessage extends SimpleExpression { @SuppressWarnings("unchecked") @@ -133,7 +133,7 @@ void set(Event event, String message) { @Override @Nullable String get(Event event) { - return ((PlayerJoinEvent) event).getJoinMessage(); + return ((BroadcastMessageEvent) event).getMessage(); } @Override From 560f2260b1d544a040b90e1029cdb1b230ee754b Mon Sep 17 00:00:00 2001 From: LimeGlass <16087552+TheLimeGlass@users.noreply.github.com> Date: Sun, 30 Jul 2023 15:10:40 -0600 Subject: [PATCH 08/16] Update src/main/java/ch/njol/skript/events/SimpleEvents.java Co-authored-by: Ayham Al Ali <20037329+AyhamAl-Ali@users.noreply.github.com> --- src/main/java/ch/njol/skript/events/SimpleEvents.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/ch/njol/skript/events/SimpleEvents.java b/src/main/java/ch/njol/skript/events/SimpleEvents.java index 850c8476a2f..3ab30df4d70 100644 --- a/src/main/java/ch/njol/skript/events/SimpleEvents.java +++ b/src/main/java/ch/njol/skript/events/SimpleEvents.java @@ -723,7 +723,7 @@ public class SimpleEvents { .description("Called when a player drags an item in their cursor across the inventory.") .examples( "on inventory drag:", - "\tif player's current inventory is {_gui}:", + "\tif player's current inventory is {inventories::custom-gui}:", "\t\tsend \"You can't drag your items here!\" to player", "\t\tcancel event" ) From bb5b5cf6e7fdda1015d10c1414df35c4d8cb0d29 Mon Sep 17 00:00:00 2001 From: LimeGlass <16087552+TheLimeGlass@users.noreply.github.com> Date: Sat, 28 Oct 2023 03:43:31 -0600 Subject: [PATCH 09/16] Update ExprChatRecipients.java --- .../java/ch/njol/skript/expressions/ExprChatRecipients.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/ch/njol/skript/expressions/ExprChatRecipients.java b/src/main/java/ch/njol/skript/expressions/ExprChatRecipients.java index 8016e1ddef7..95622705fba 100644 --- a/src/main/java/ch/njol/skript/expressions/ExprChatRecipients.java +++ b/src/main/java/ch/njol/skript/expressions/ExprChatRecipients.java @@ -76,7 +76,7 @@ public Class[] acceptChange(ChangeMode mode) { @Override public void change(Event event, @Nullable Object[] delta, ChangeMode mode) { - if (!(event instanceof AsyncPlayerChatEvent) || !(event instanceof BroadcastMessageEvent)) + if (!(event instanceof AsyncPlayerChatEvent) && !(event instanceof BroadcastMessageEvent)) return; CommandSender[] recipients = (CommandSender[]) delta; From 97156409983e44e9ec034f936b100a2d89a69a6b Mon Sep 17 00:00:00 2001 From: LimeGlass <16087552+TheLimeGlass@users.noreply.github.com> Date: Sat, 28 Oct 2023 03:43:57 -0600 Subject: [PATCH 10/16] Update src/main/java/ch/njol/skript/expressions/ExprMessage.java Co-authored-by: _tud --- src/main/java/ch/njol/skript/expressions/ExprMessage.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/ch/njol/skript/expressions/ExprMessage.java b/src/main/java/ch/njol/skript/expressions/ExprMessage.java index c7e644a9544..4493bb0dbb7 100644 --- a/src/main/java/ch/njol/skript/expressions/ExprMessage.java +++ b/src/main/java/ch/njol/skript/expressions/ExprMessage.java @@ -176,7 +176,7 @@ void set(Event event, String message) { public boolean init(Expression[] exprs, int matchedPattern, Kleenean isDelayed, ParseResult parseResult) { type = MessageType.values()[matchedPattern]; if (!getParser().isCurrentEvent(type.events)) { - Skript.error("The " + type.name + " message can only be used in a " + type.name + " event", ErrorQuality.SEMANTIC_ERROR); + Skript.error("The " + type.name + " message can only be used in a " + type.name + " event"); return false; } return true; From a6e8e61a9fab9235e1173ecb4d5462c324152320 Mon Sep 17 00:00:00 2001 From: LimeGlass <16087552+TheLimeGlass@users.noreply.github.com> Date: Sun, 31 Dec 2023 18:35:44 -0700 Subject: [PATCH 11/16] Update src/main/java/ch/njol/skript/events/SimpleEvents.java Co-authored-by: sovdee <10354869+sovdeeth@users.noreply.github.com> --- src/main/java/ch/njol/skript/events/SimpleEvents.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/ch/njol/skript/events/SimpleEvents.java b/src/main/java/ch/njol/skript/events/SimpleEvents.java index 590f8e76f1e..36ce08fe1a9 100644 --- a/src/main/java/ch/njol/skript/events/SimpleEvents.java +++ b/src/main/java/ch/njol/skript/events/SimpleEvents.java @@ -762,7 +762,7 @@ public class SimpleEvents { .since("INSERT VERSION"); Skript.registerEvent("Server Broadcast", SimpleEvent.class, BroadcastMessageEvent.class, "[server] broadcast") - .description("Called when the server broadcasts messages.") + .description("Called when the server broadcasts messages. Does not get called when using Skript's broadcast effect.") .examples( "on server broadcast:", "\tbroadcast-message contains \"example\"", From 56643517875ecd106471b5bb7cd6b4093c846273 Mon Sep 17 00:00:00 2001 From: LimeGlass <16087552+TheLimeGlass@users.noreply.github.com> Date: Sat, 7 Sep 2024 03:35:58 -0600 Subject: [PATCH 12/16] Update src/main/java/ch/njol/skript/expressions/ExprChatRecipients.java Co-authored-by: Moderocky --- .../java/ch/njol/skript/expressions/ExprChatRecipients.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/ch/njol/skript/expressions/ExprChatRecipients.java b/src/main/java/ch/njol/skript/expressions/ExprChatRecipients.java index 95622705fba..b5a7e5a893f 100644 --- a/src/main/java/ch/njol/skript/expressions/ExprChatRecipients.java +++ b/src/main/java/ch/njol/skript/expressions/ExprChatRecipients.java @@ -46,7 +46,7 @@ public class ExprChatRecipients extends SimpleExpression { static { - Skript.registerExpression(ExprChatRecipients.class, CommandSender.class, ExpressionType.SIMPLE, "[chat][( |-)]recipients"); + Skript.registerExpression(ExprChatRecipients.class, CommandSender.class, ExpressionType.SIMPLE, "[chat( |-)]recipients"); } @Override From 283b2d57939b5d28f057491d0b0991fa0f026114 Mon Sep 17 00:00:00 2001 From: LimeGlass <16087552+TheLimeGlass@users.noreply.github.com> Date: Sat, 7 Sep 2024 03:36:54 -0600 Subject: [PATCH 13/16] Update src/main/java/ch/njol/skript/expressions/ExprChatRecipients.java Co-authored-by: _tud <98935832+UnderscoreTud@users.noreply.github.com> --- .../java/ch/njol/skript/expressions/ExprChatRecipients.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/ch/njol/skript/expressions/ExprChatRecipients.java b/src/main/java/ch/njol/skript/expressions/ExprChatRecipients.java index b5a7e5a893f..86a72501eb7 100644 --- a/src/main/java/ch/njol/skript/expressions/ExprChatRecipients.java +++ b/src/main/java/ch/njol/skript/expressions/ExprChatRecipients.java @@ -52,7 +52,7 @@ public class ExprChatRecipients extends SimpleExpression { @Override public boolean init(Expression[] exprs, int matchedPattern, Kleenean isDelayed, ParseResult parseResult) { if (!(getParser().isCurrentEvent(AsyncPlayerChatEvent.class, BroadcastMessageEvent.class))) { - Skript.error("Cannot use chat recipients expression outside of a chat or server broadcast event"); + Skript.error("Cannot use chat recipients expression outside of a chat or a server broadcast event"); return false; } return true; From 81141eb75f0902f4333175a9832fc98b6c9c68d5 Mon Sep 17 00:00:00 2001 From: LimeGlass <16087552+TheLimeGlass@users.noreply.github.com> Date: Sat, 7 Sep 2024 03:38:49 -0600 Subject: [PATCH 14/16] Update src/main/java/ch/njol/skript/expressions/ExprChatRecipients.java Co-authored-by: Moderocky --- .../ch/njol/skript/expressions/ExprChatRecipients.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/main/java/ch/njol/skript/expressions/ExprChatRecipients.java b/src/main/java/ch/njol/skript/expressions/ExprChatRecipients.java index 86a72501eb7..b807a3c520f 100644 --- a/src/main/java/ch/njol/skript/expressions/ExprChatRecipients.java +++ b/src/main/java/ch/njol/skript/expressions/ExprChatRecipients.java @@ -61,10 +61,10 @@ public boolean init(Expression[] exprs, int matchedPattern, Kleenean isDelaye @Override @Nullable protected CommandSender[] get(Event event) { - if (event instanceof AsyncPlayerChatEvent) { - return ((AsyncPlayerChatEvent) event).getRecipients().toArray(new Player[0]); - } else if (event instanceof BroadcastMessageEvent) { - return ((BroadcastMessageEvent) event).getRecipients().toArray(new CommandSender[0]); + if (event instanceof AsyncPlayerChatEvent async) { + return async.getRecipients().toArray(new Player[0]); + } else if (event instanceof BroadcastMessageEvent broadcast) { + return broadcast.getRecipients().toArray(new CommandSender[0]); } return null; } From 11fc732fbc91829dc24beb5969394cba315e1f97 Mon Sep 17 00:00:00 2001 From: LimeGlass <16087552+TheLimeGlass@users.noreply.github.com> Date: Sat, 7 Sep 2024 03:39:09 -0600 Subject: [PATCH 15/16] Update src/main/java/ch/njol/skript/events/SimpleEvents.java Co-authored-by: _tud <98935832+UnderscoreTud@users.noreply.github.com> --- src/main/java/ch/njol/skript/events/SimpleEvents.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/ch/njol/skript/events/SimpleEvents.java b/src/main/java/ch/njol/skript/events/SimpleEvents.java index 9c68625f031..adefeea856f 100644 --- a/src/main/java/ch/njol/skript/events/SimpleEvents.java +++ b/src/main/java/ch/njol/skript/events/SimpleEvents.java @@ -754,7 +754,7 @@ public class SimpleEvents { "\t\tsend \"You can't drag your items here!\" to player", "\t\tcancel event" ) - .since("INSERT VERSION"); + .since("2.7"); Skript.registerEvent("Server Broadcast", SimpleEvent.class, BroadcastMessageEvent.class, "[server] broadcast") .description("Called when the server broadcasts messages. Does not get called when using Skript's broadcast effect.") @@ -763,7 +763,7 @@ public class SimpleEvents { "\tbroadcast-message contains \"example\"", "\tcancel event" ) - .since("2.7"); + .since("INSERT VERSION"); { final Class eventClass; From 6fb4b2bc334bb4fff8917c684b30a2bf43e6bee8 Mon Sep 17 00:00:00 2001 From: Moderocky Date: Sun, 8 Sep 2024 10:46:14 +0100 Subject: [PATCH 16/16] Update src/main/java/ch/njol/skript/expressions/ExprMessage.java --- src/main/java/ch/njol/skript/expressions/ExprMessage.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/ch/njol/skript/expressions/ExprMessage.java b/src/main/java/ch/njol/skript/expressions/ExprMessage.java index 6cfd2e7eb6e..bd9d4d7d441 100644 --- a/src/main/java/ch/njol/skript/expressions/ExprMessage.java +++ b/src/main/java/ch/njol/skript/expressions/ExprMessage.java @@ -65,7 +65,7 @@ "\t\tset quit message to \"%player% left this awesome server!\"", "", "on server broadcast:", - "\tset the broadcast message to \"something else!\"" + "\tset the broadcast message to \"something else!\"", "", "on death:", "\tset the death message to \"%player% died!\""})