Skip to content

Commit

Permalink
Small cleanup.
Browse files Browse the repository at this point in the history
  • Loading branch information
RezzedUp committed Mar 6, 2022
1 parent 92d814b commit d6a838b
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -59,25 +59,22 @@ public void onPrefixedChatEarly(AsyncPlayerChatEvent event)

String message = event.getMessage();
if (!message.startsWith(identifier)) { return; }

String unprefixed = message.substring(identifier.length()).trim();
String submission = (Strings.isEmptyOrNull(unprefixed)) ? message : unprefixed;

plugin.debug(getClass()).log(event, () ->
"Early Listener: Identified prefixed chat from player(" + player.getName() + ") identified " +
"by prefix(\"" + identifier + "\"): message(\"" + submission + "\")"
"by prefix(\"" + identifier + "\"): full-message(\"" + message + "\")"
);

event.setCancelled(true); // Cancel this message from getting sent to global chat.

//Handle message in a later listener order allowing other plugins to modify the message
// Handle message in a later listener order, allowing other plugins to modify the message.
}

@EventListener(ListenerOrder.MONITOR)
public void onPrefixedChatMonitor(AsyncPlayerChatEvent event)
{
if (!event.isCancelled()) { return; } //Event should already be cancelled in the early listener

// Event should already be cancelled in the early listener.
if (!event.isCancelled()) { return; }

if (!plugin.config().getOrDefault(StaffChatConfig.PREFIXED_CHAT_ENABLED)) { return; }

Player player = event.getPlayer();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,21 +49,22 @@ public PlayerStaffChatToggleListener(StaffChatPlugin plugin)
@EventListener(ListenerOrder.FIRST)
public void onAutomaticChatFirst(AsyncPlayerChatEvent event)
{
Player player = event.getPlayer();
if (!plugin.data().isAutomaticStaffChatEnabled(player)) { return; }

event.setCancelled(true); // Cancel this message from getting sent to global chat.
//Handle message in a later listener order allowing other plugins to modify the message
if (plugin.data().isAutomaticStaffChatEnabled(event.getPlayer()))
{
event.setCancelled(true); // Cancel this message from getting sent to global chat.
// Handle message in a later listener order, allowing other plugins to modify the message.
}
}

@EventListener(ListenerOrder.MONITOR)
public void onAutomaticChatMonitor(AsyncPlayerChatEvent event)
{
Player player = event.getPlayer();
if (!plugin.data().isAutomaticStaffChatEnabled(player)) { return; }

event.setCancelled(true); // Cancel this message from getting sent to global chat.

// The event could've been uncancelled since cancelling it the first time.

if (Permissions.ACCESS.allows(player))
{
plugin.debug(getClass()).log(event, () ->
Expand Down

0 comments on commit d6a838b

Please sign in to comment.