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 PlayerPlotChatEvent #3735

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<Player> recipients = event.getRecipients();
recipients.clear();
Set<PlotPlayer<?>> spies = new HashSet<>();
Expand All @@ -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
Copy link
Member

Choose a reason for hiding this comment

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

I think this should be !force, as the plot chat should happen if the result is FORCE

.hasPermission(plotPlayer, Permission.PERMISSION_ADMIN_CHAT_BYPASS))) {
return;
}

event.setCancelled(true);

String sender = event.getPlayer().getDisplayName();
PlotId id = plot.getId();
String worldName = plot.getWorldName();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
/*
* PlotSquared, a land and world management plugin for Minecraft.
* Copyright (C) IntellectualSites <https://intellectualsites.com>
* 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 <https://www.gnu.org/licenses/>.
*/
package com.plotsquared.core.events;

import com.plotsquared.core.player.PlotPlayer;
import com.plotsquared.core.plot.Plot;

import java.util.Set;

/**
* @since TODO
Copy link
Member

Choose a reason for hiding this comment

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

Please add since todo to the added methods too.

*/
public class PlayerPlotChatEvent extends PlotEvent implements CancellablePlotEvent {

private final PlotPlayer<?> player;
private final String message;
Copy link
Member

Choose a reason for hiding this comment

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

Maybe rather use an adventure component for the message?
The passed message as a string is before the translation of color codes etc happened. Would be more suitable to use the component which is used as the "msg" placeholder.

private final Set<PlotPlayer<?>> recipients;
private final Set<PlotPlayer<?>> spies;
private Result eventResult;

public PlayerPlotChatEvent(
PlotPlayer<?> player,
Plot plot,
String message,
Set<PlotPlayer<?>> recipients,
Set<PlotPlayer<?>> 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<PlotPlayer<?>> getRecipients() {
Copy link
Member

Choose a reason for hiding this comment

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

It should be documented that

  • the returned set can be modified
  • the changes apply to who receives the message

Also, the PlotPlayer should be at least marked as non-null here, as putting a null value into the set will throw an exception later.
Same applies for getSpies(), and it's probably also worth to think about what should happen if a player is in both sets.

return this.recipients;
}

/**
* The message spies.
*
* @return Set of PlotPlayer
*/
public Set<PlotPlayer<?>> getSpies() {
return this.spies;
}

@Override
public Result getEventResult() {
return this.eventResult;
}

@Override
public void setEventResult(final Result eventResult) {
this.eventResult = eventResult;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -80,6 +81,7 @@

import java.util.ArrayList;
import java.util.List;
import java.util.Set;
import java.util.UUID;

@DoNotUse
Expand Down Expand Up @@ -241,6 +243,22 @@ public PlayerLeavePlotEvent callLeave(PlotPlayer<?> player, Plot plot) {
return event;
}

/**
* @since TODO
*/
Comment on lines +246 to +248
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
/**
* @since TODO
*/

This is an internal class.

public PlayerPlotChatEvent callChat(
PlotPlayer<?> player,
Plot plot,
String message,
Set<PlotPlayer<?>> recipients,
Set<PlotPlayer<?>> 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
Expand Down