Skip to content

Commit

Permalink
removed message cancelling for chat but removed all recipients
Browse files Browse the repository at this point in the history
  • Loading branch information
bierdosenhalter committed Aug 31, 2022
1 parent 86d2e2a commit 43ee87c
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 18 deletions.
4 changes: 0 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -75,10 +75,6 @@ You can customize the appearance of whispers.
- Write [SPOILER]text[/SPOILER] to make a spoiler.
- Write /show spoiler [1-5] to view spoilers.

### Planned Features

- Fully Async Chat

### Tested Minecraft Versions

- 1.12.2
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

<groupId>org.zeroBzeroT.chatCo</groupId>
<artifactId>ChatCoPlus</artifactId>
<version>0.27.3</version>
<version>0.27.4</version>
<packaging>jar</packaging>
<name>${project.artifactId}</name>

Expand Down
16 changes: 8 additions & 8 deletions src/main/java/org/zeroBzeroT/chatCo/PublicChat.java
Original file line number Diff line number Diff line change
Expand Up @@ -59,18 +59,17 @@ public String replaceInlineColors(String message, final Player player) {
@EventHandler(ignoreCancelled = true)
public void onPlayerChat(final AsyncPlayerChatEvent event) {
// Set format to the plain message, since the player is not needed
String oldFormat = event.getFormat();
event.setFormat("%2$s");

// Cancel the event, because the chat is rewritten to system messages
event.setCancelled(true);

// Plain message
final Player player = event.getPlayer();
String legacyMessage = replacePrefixColors(event.getMessage(), player);
legacyMessage = replaceInlineColors(legacyMessage, player);

// Do not send empty messages
if (ChatColor.stripColor(legacyMessage).trim().length() == 0) {
event.setCancelled(true);
return;
}

Expand All @@ -91,10 +90,6 @@ public void onPlayerChat(final AsyncPlayerChatEvent event) {
message.addExtra(componentFromLegacyText("> "));
message.addExtra(messageText);

// Send to console
if (plugin.getConfig().getBoolean("ChatCo.chatToConsole", true))
plugin.getLogger().info(message.toLegacyText());

// Send to the players
for (Player recipient : event.getRecipients()) {
try {
Expand All @@ -104,11 +99,16 @@ public void onPlayerChat(final AsyncPlayerChatEvent event) {
(!chatPlayer.isIgnored(player.getName()) || !plugin.getConfig().getBoolean("ChatCo.ignoresEnabled", true))) {
recipient.spigot().sendMessage(message);
}

} catch (NullPointerException e) {
e.printStackTrace();
}
}

// Do not send it to the players again - no event cancelling, so that other plugins can process the chat
event.getRecipients().clear();

// Write back the old format
event.setFormat(oldFormat);
}

@EventHandler
Expand Down
6 changes: 1 addition & 5 deletions src/main/java/org/zeroBzeroT/chatCo/Whispers.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
import org.bukkit.ChatColor;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerCommandPreprocessEvent;

Expand All @@ -28,10 +27,7 @@ public Whispers(final Main plugin) {
this.plugin = plugin;
}

/**
* high event priority (lower rank) makes it easier for other plugins to block commands of this plugin
*/
@EventHandler(ignoreCancelled = true, priority = EventPriority.HIGH)
@EventHandler(ignoreCancelled = true)
public void onPlayerCommandPreprocess(final PlayerCommandPreprocessEvent event) {
final String[] args = event.getMessage().split(" ");
final Player sender = event.getPlayer();
Expand Down

0 comments on commit 43ee87c

Please sign in to comment.