From d0a92fc7622438be20569fa46ffd9b38b6bdf269 Mon Sep 17 00:00:00 2001 From: Jaap Elst Date: Fri, 22 Jul 2022 09:39:30 +0200 Subject: [PATCH 1/3] Add PlayerPlotChatEvent --- .../bukkit/listener/PlayerEventListener.java | 2 + .../core/events/PlayerPlotChatEvent.java | 67 +++++++++++++++++++ .../core/util/EventDispatcher.java | 18 +++++ 3 files changed, 87 insertions(+) create mode 100644 Core/src/main/java/com/plotsquared/core/events/PlayerPlotChatEvent.java diff --git a/Bukkit/src/main/java/com/plotsquared/bukkit/listener/PlayerEventListener.java b/Bukkit/src/main/java/com/plotsquared/bukkit/listener/PlayerEventListener.java index 6eddc83e1c..ea246482e3 100644 --- a/Bukkit/src/main/java/com/plotsquared/bukkit/listener/PlayerEventListener.java +++ b/Bukkit/src/main/java/com/plotsquared/bukkit/listener/PlayerEventListener.java @@ -778,6 +778,8 @@ public void onChat(AsyncPlayerChatEvent event) { spymessageTemplate ); } + + this.eventDispatcher.callChat(plotPlayer, plot, message, plotRecipients, spies); } @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) diff --git a/Core/src/main/java/com/plotsquared/core/events/PlayerPlotChatEvent.java b/Core/src/main/java/com/plotsquared/core/events/PlayerPlotChatEvent.java new file mode 100644 index 0000000000..4d52c53564 --- /dev/null +++ b/Core/src/main/java/com/plotsquared/core/events/PlayerPlotChatEvent.java @@ -0,0 +1,67 @@ +package com.plotsquared.core.events; + +import com.plotsquared.core.player.PlotPlayer; +import com.plotsquared.core.plot.Plot; + +import java.util.Set; + +/** + * @since TODO + */ +public class PlayerPlotChatEvent extends PlotEvent { + + private final PlotPlayer player; + private final String message; + private final Set> recipients; + private final Set> spies; + + public PlayerPlotChatEvent( + PlotPlayer player, + Plot plot, + String message, + Set> recipients, + Set> spies + ) { + super(plot); + this.player = player; + this.message = message; + this.recipients = recipients; + this.spies = spies; + } + + /** + * The player that sent the message. + * + * @return PlotPlayer + */ + public PlotPlayer getPlayer() { + return this.player; + } + + /** + * The message that was sent. + * + * @return String + */ + public String getMessage() { + return this.message; + } + + /** + * The message recipients. + * + * @return Set of PlotPlayer + */ + public Set> getRecipients() { + return this.recipients; + } + + /** + * The message spies. + * + * @return Set of PlotPlayer + */ + public Set> getSpies() { + return this.spies; + } +} diff --git a/Core/src/main/java/com/plotsquared/core/util/EventDispatcher.java b/Core/src/main/java/com/plotsquared/core/util/EventDispatcher.java index e91c7b35b2..aa40ebb34c 100644 --- a/Core/src/main/java/com/plotsquared/core/util/EventDispatcher.java +++ b/Core/src/main/java/com/plotsquared/core/util/EventDispatcher.java @@ -27,6 +27,7 @@ import com.plotsquared.core.events.PlayerClaimPlotEvent; import com.plotsquared.core.events.PlayerEnterPlotEvent; import com.plotsquared.core.events.PlayerLeavePlotEvent; +import com.plotsquared.core.events.PlayerPlotChatEvent; import com.plotsquared.core.events.PlayerPlotDeniedEvent; import com.plotsquared.core.events.PlayerPlotHelperEvent; import com.plotsquared.core.events.PlayerPlotTrustedEvent; @@ -80,6 +81,7 @@ import java.util.ArrayList; import java.util.List; +import java.util.Set; import java.util.UUID; @DoNotUse @@ -241,6 +243,22 @@ public PlayerLeavePlotEvent callLeave(PlotPlayer player, Plot plot) { return event; } + /** + * @since TODO + */ + public PlayerPlotChatEvent callChat( + PlotPlayer player, + Plot plot, + String message, + Set> recipients, + Set> spies + ) { + PlayerPlotChatEvent event = new PlayerPlotChatEvent(player, plot, message, recipients, spies); + callEvent(event); + return event; + } + + public PlayerPlotDeniedEvent callDenied( PlotPlayer initiator, Plot plot, UUID player, boolean added From a4ce2472cdac40d85e4df8da9e7b0bceee93f4f1 Mon Sep 17 00:00:00 2001 From: Jaap Elst Date: Fri, 22 Jul 2022 10:09:28 +0200 Subject: [PATCH 2/3] Add license --- .../core/events/PlayerPlotChatEvent.java | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/Core/src/main/java/com/plotsquared/core/events/PlayerPlotChatEvent.java b/Core/src/main/java/com/plotsquared/core/events/PlayerPlotChatEvent.java index 4d52c53564..4f5ab1aef3 100644 --- a/Core/src/main/java/com/plotsquared/core/events/PlayerPlotChatEvent.java +++ b/Core/src/main/java/com/plotsquared/core/events/PlayerPlotChatEvent.java @@ -1,3 +1,21 @@ +/* + * PlotSquared, a land and world management plugin for Minecraft. + * Copyright (C) IntellectualSites + * Copyright (C) IntellectualSites team and contributors + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ package com.plotsquared.core.events; import com.plotsquared.core.player.PlotPlayer; From a2be04dd7848d38e38738548a28ba2f037600db0 Mon Sep 17 00:00:00 2001 From: Jaap Elst Date: Fri, 22 Jul 2022 11:32:17 +0200 Subject: [PATCH 3/3] Make PlayerPlotChatEvent cancellable --- .../bukkit/listener/PlayerEventListener.java | 26 ++++++++++++++----- .../core/events/PlayerPlotChatEvent.java | 14 +++++++++- 2 files changed, 32 insertions(+), 8 deletions(-) diff --git a/Bukkit/src/main/java/com/plotsquared/bukkit/listener/PlayerEventListener.java b/Bukkit/src/main/java/com/plotsquared/bukkit/listener/PlayerEventListener.java index ea246482e3..436f1fef2d 100644 --- a/Bukkit/src/main/java/com/plotsquared/bukkit/listener/PlayerEventListener.java +++ b/Bukkit/src/main/java/com/plotsquared/bukkit/listener/PlayerEventListener.java @@ -29,6 +29,8 @@ import com.plotsquared.core.configuration.Settings; import com.plotsquared.core.configuration.caption.Caption; import com.plotsquared.core.configuration.caption.TranslatableCaption; +import com.plotsquared.core.events.PlayerPlotChatEvent; +import com.plotsquared.core.events.Result; import com.plotsquared.core.listener.PlayerBlockEventType; import com.plotsquared.core.listener.PlotListener; import com.plotsquared.core.location.Location; @@ -712,11 +714,7 @@ public void onChat(AsyncPlayerChatEvent event) { || area.isForcingPlotChat())) { return; } - if (plot.isDenied(plotPlayer.getUUID()) && !Permissions - .hasPermission(plotPlayer, Permission.PERMISSION_ADMIN_CHAT_BYPASS)) { - return; - } - event.setCancelled(true); + Set recipients = event.getRecipients(); recipients.clear(); Set> spies = new HashSet<>(); @@ -732,6 +730,22 @@ public void onChat(AsyncPlayerChatEvent event) { } } String message = event.getMessage(); + + PlayerPlotChatEvent plotChatEvent = this.eventDispatcher.callChat(plotPlayer, plot, message, plotRecipients, spies); + + if (plotChatEvent.getEventResult() == Result.DENY) { + return; + } + + boolean force = plotChatEvent.getEventResult() == Result.FORCE; + + if (force || (plot.isDenied(plotPlayer.getUUID()) && !Permissions + .hasPermission(plotPlayer, Permission.PERMISSION_ADMIN_CHAT_BYPASS))) { + return; + } + + event.setCancelled(true); + String sender = event.getPlayer().getDisplayName(); PlotId id = plot.getId(); String worldName = plot.getWorldName(); @@ -778,8 +792,6 @@ public void onChat(AsyncPlayerChatEvent event) { spymessageTemplate ); } - - this.eventDispatcher.callChat(plotPlayer, plot, message, plotRecipients, spies); } @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) diff --git a/Core/src/main/java/com/plotsquared/core/events/PlayerPlotChatEvent.java b/Core/src/main/java/com/plotsquared/core/events/PlayerPlotChatEvent.java index 4f5ab1aef3..5d59be3a10 100644 --- a/Core/src/main/java/com/plotsquared/core/events/PlayerPlotChatEvent.java +++ b/Core/src/main/java/com/plotsquared/core/events/PlayerPlotChatEvent.java @@ -26,12 +26,13 @@ /** * @since TODO */ -public class PlayerPlotChatEvent extends PlotEvent { +public class PlayerPlotChatEvent extends PlotEvent implements CancellablePlotEvent { private final PlotPlayer player; private final String message; private final Set> recipients; private final Set> spies; + private Result eventResult; public PlayerPlotChatEvent( PlotPlayer player, @@ -82,4 +83,15 @@ public Set> getRecipients() { public Set> getSpies() { return this.spies; } + + @Override + public Result getEventResult() { + return this.eventResult; + } + + @Override + public void setEventResult(final Result eventResult) { + this.eventResult = eventResult; + } + }