Exclude plugins from syschat event

This commit is contained in:
Norbi Peti 2019-01-09 18:52:24 +01:00
parent 7f385df3b1
commit bb31f4e378
No known key found for this signature in database
GPG key ID: DBA4C4549A927E56
4 changed files with 364 additions and 343 deletions

15
.editorconfig Normal file
View file

@ -0,0 +1,15 @@
[*]
charset=utf-8
end_of_line=lf
insert_final_newline=false
indent_style=space
indent_size=4
[*.java]
indent_style=tab
tab_width=4
[{*.yml,*.yaml}]
indent_style=space
indent_size=2

View file

@ -14,6 +14,7 @@ import org.bukkit.event.player.PlayerQuitEvent;
import java.time.Instant; import java.time.Instant;
import java.time.temporal.ChronoUnit; import java.time.temporal.ChronoUnit;
import java.util.Arrays;
import java.util.Date; import java.util.Date;
import static buttondevteam.core.MainPlugin.permission; import static buttondevteam.core.MainPlugin.permission;
@ -55,6 +56,8 @@ public class PlayerListener implements Listener {
public void onSystemChat(TBMCSystemChatEvent event) { public void onSystemChat(TBMCSystemChatEvent event) {
if (event.isHandled()) if (event.isHandled())
return; // Only handle here if ButtonChat couldn't return; // Only handle here if ButtonChat couldn't
if (Arrays.stream(event.getExceptions()).anyMatch("Minecraft"::equalsIgnoreCase))
return;
Bukkit.getOnlinePlayers().stream().filter(event::shouldSendTo) Bukkit.getOnlinePlayers().stream().filter(event::shouldSendTo)
.forEach(p -> p.sendMessage(event.getChannel().DisplayName.substring(0, 2) + event.getMessage())); .forEach(p -> p.sendMessage(event.getChannel().DisplayName.substring(0, 2) + event.getMessage()));
} }

View file

@ -13,14 +13,16 @@ import org.bukkit.event.HandlerList;
*/ */
@Getter @Getter
public class TBMCSystemChatEvent extends TBMCChatEventBase { public class TBMCSystemChatEvent extends TBMCChatEventBase {
private final String[] exceptions;
private boolean handled; private boolean handled;
public void setHandled() { public void setHandled() {
handled = true; handled = true;
} }
public TBMCSystemChatEvent(Channel channel, String message, int score, String groupid) { // TODO: Rich message public TBMCSystemChatEvent(Channel channel, String message, int score, String groupid, String[] exceptions) { // TODO: Rich message
super(channel, message, score, groupid); super(channel, message, score, groupid);
this.exceptions = exceptions;
} }
private static final HandlerList handlers = new HandlerList(); private static final HandlerList handlers = new HandlerList();

View file

@ -253,12 +253,13 @@ public class TBMCChatAPI {
* The score&group to use to find the group - use {@link RecipientTestResult#ALL} if the channel doesn't have scores * The score&group to use to find the group - use {@link RecipientTestResult#ALL} if the channel doesn't have scores
* @param message * @param message
* The message to send * The message to send
* @param exceptions Platforms where this message shouldn't be sent (same as {@link ChatMessage#getOrigin()}
* @return The event cancelled state * @return The event cancelled state
*/ */
public static boolean SendSystemMessage(Channel channel, RecipientTestResult rtr, String message) { public static boolean SendSystemMessage(Channel channel, RecipientTestResult rtr, String message, String... exceptions) {
if (!Channel.getChannels().contains(channel)) if (!Channel.getChannels().contains(channel))
throw new RuntimeException("Channel " + channel.DisplayName + " not registered!"); throw new RuntimeException("Channel " + channel.DisplayName + " not registered!");
TBMCSystemChatEvent event = new TBMCSystemChatEvent(channel, message, rtr.score, rtr.groupID); TBMCSystemChatEvent event = new TBMCSystemChatEvent(channel, message, rtr.score, rtr.groupID, exceptions);
Bukkit.getPluginManager().callEvent(event); Bukkit.getPluginManager().callEvent(event);
return event.isCancelled(); return event.isCancelled();
} }