mirror of
https://github.com/darksaid98/TownyChat.git
synced 2026-12-04 14:38:58 +00:00
Cancel our own event after all other plugins have had a bash at the
formatting.
This commit is contained in:
1 parent
c495337f1b
commit
e373612cdf
5 files changed
+67
-22
No files matched your search
+3
-1
@@ -113,4 +113,6 @@ v0.24:
|
|||||||
v0.25:
|
v0.25:
|
||||||
- Update to account for the refactoring in Towny.
|
- Update to account for the refactoring in Towny.
|
||||||
v0.26:
|
v0.26:
|
||||||
- Throw a "fake" PlayerChatEvent which will allow TownyChat to have much increased compatibility with other plugins (dumptruckman).
|
- Throw a "fake" PlayerChatEvent which will allow TownyChat to have much increased compatibility with other plugins (dumptruckman).
|
||||||
|
v0.27:
|
||||||
|
- Cancel our own event after all other plugins have had a bash at the formatting.
|
||||||
@@ -70,14 +70,17 @@ public class StandardChannel extends Channel {
|
|||||||
|
|
||||||
LocalTownyChatEvent chatEvent = new LocalTownyChatEvent(event, resident);
|
LocalTownyChatEvent chatEvent = new LocalTownyChatEvent(event, resident);
|
||||||
event.setFormat(TownyChatFormatter.getChatFormat(chatEvent));
|
event.setFormat(TownyChatFormatter.getChatFormat(chatEvent));
|
||||||
String msg = chatEvent.getFormat().replace("%1$s", event.getPlayer().getDisplayName()).replace("%2$s", event.getMessage());
|
|
||||||
|
|
||||||
// Throw a "fake" chat event for other plugins to handle the chat after TownyChat has formatted it.
|
// Throw a "fake" chat event for other plugins to handle the chat after TownyChat has formatted it.
|
||||||
event = new TownyChatEvent(player, msg);
|
event = new TownyChatEvent(player, event.getMessage(), event.getFormat());
|
||||||
plugin.getServer().getPluginManager().callEvent(event);
|
plugin.getServer().getPluginManager().callEvent(event);
|
||||||
if (event.isCancelled())
|
|
||||||
|
// If the event was canceled by anything other then TownyChat
|
||||||
|
if (event.isCancelled() && !((TownyChatEvent)event).isCanceledByTownyChat())
|
||||||
return;
|
return;
|
||||||
msg = event.getMessage();
|
|
||||||
|
// Read the format after it's been updated by all other plugins.
|
||||||
|
String msg = event.getFormat().replace("%1$s", event.getPlayer().getDisplayName()).replace("%2$s", event.getMessage());
|
||||||
|
|
||||||
plugin.getLogger().info(ChatTools.stripColour("[Town Msg] " + town.getName() + ": " + msg));
|
plugin.getLogger().info(ChatTools.stripColour("[Town Msg] " + town.getName() + ": " + msg));
|
||||||
|
|
||||||
@@ -116,14 +119,17 @@ public class StandardChannel extends Channel {
|
|||||||
|
|
||||||
LocalTownyChatEvent chatEvent = new LocalTownyChatEvent(event, resident);
|
LocalTownyChatEvent chatEvent = new LocalTownyChatEvent(event, resident);
|
||||||
event.setFormat(TownyChatFormatter.getChatFormat(chatEvent));
|
event.setFormat(TownyChatFormatter.getChatFormat(chatEvent));
|
||||||
String msg = chatEvent.getFormat().replace("%1$s", event.getPlayer().getDisplayName()).replace("%2$s", event.getMessage());
|
|
||||||
|
|
||||||
// Throw a "fake" chat event for other plugins to handle the chat after TownyChat has formatted it.
|
// Throw a "fake" chat event for other plugins to handle the chat after TownyChat has formatted it.
|
||||||
event = new TownyChatEvent(player, msg);
|
event = new TownyChatEvent(player, event.getMessage(), event.getFormat());
|
||||||
plugin.getServer().getPluginManager().callEvent(event);
|
plugin.getServer().getPluginManager().callEvent(event);
|
||||||
if (event.isCancelled())
|
|
||||||
|
// If the event was canceled by anything other then TownyChat
|
||||||
|
if (event.isCancelled() && !((TownyChatEvent)event).isCanceledByTownyChat())
|
||||||
return;
|
return;
|
||||||
msg = event.getMessage();
|
|
||||||
|
// Read the format after it's been updated by all other plugins.
|
||||||
|
String msg = event.getFormat().replace("%1$s", event.getPlayer().getDisplayName()).replace("%2$s", event.getMessage());
|
||||||
|
|
||||||
plugin.getLogger().info(ChatTools.stripColour("[Nation Msg] " + nation.getName() + ": " + msg));
|
plugin.getLogger().info(ChatTools.stripColour("[Nation Msg] " + nation.getName() + ": " + msg));
|
||||||
|
|
||||||
@@ -161,14 +167,17 @@ public class StandardChannel extends Channel {
|
|||||||
|
|
||||||
LocalTownyChatEvent chatEvent = new LocalTownyChatEvent(event, resident);
|
LocalTownyChatEvent chatEvent = new LocalTownyChatEvent(event, resident);
|
||||||
event.setFormat(TownyChatFormatter.getChatFormat(chatEvent));
|
event.setFormat(TownyChatFormatter.getChatFormat(chatEvent));
|
||||||
String msg = chatEvent.getFormat().replace("%1$s", event.getPlayer().getDisplayName()).replace("%2$s", event.getMessage());
|
|
||||||
|
|
||||||
// Throw a "fake" chat event for other plugins to handle the chat after TownyChat has formatted it.
|
// Throw a "fake" chat event for other plugins to handle the chat after TownyChat has formatted it.
|
||||||
event = new TownyChatEvent(player, msg);
|
event = new TownyChatEvent(player, event.getMessage(), event.getFormat());
|
||||||
plugin.getServer().getPluginManager().callEvent(event);
|
plugin.getServer().getPluginManager().callEvent(event);
|
||||||
if (event.isCancelled())
|
|
||||||
|
// If the event was canceled by anything other then TownyChat
|
||||||
|
if (event.isCancelled() && !((TownyChatEvent)event).isCanceledByTownyChat())
|
||||||
return;
|
return;
|
||||||
msg = event.getMessage();
|
|
||||||
|
// Read the format after it's been updated by all other plugins.
|
||||||
|
String msg = event.getFormat().replace("%1$s", event.getPlayer().getDisplayName()).replace("%2$s", event.getMessage());
|
||||||
|
|
||||||
plugin.getLogger().info(ChatTools.stripColour(msg));
|
plugin.getLogger().info(ChatTools.stripColour(msg));
|
||||||
|
|
||||||
@@ -219,14 +228,17 @@ public class StandardChannel extends Channel {
|
|||||||
|
|
||||||
LocalTownyChatEvent chatEvent = new LocalTownyChatEvent(event, resident);
|
LocalTownyChatEvent chatEvent = new LocalTownyChatEvent(event, resident);
|
||||||
event.setFormat(TownyChatFormatter.getChatFormat(chatEvent));
|
event.setFormat(TownyChatFormatter.getChatFormat(chatEvent));
|
||||||
String msg = chatEvent.getFormat().replace("%1$s", event.getPlayer().getDisplayName()).replace("%2$s", event.getMessage());
|
|
||||||
|
|
||||||
// Throw a "fake" chat event for other plugins to handle the chat after TownyChat has formatted it.
|
// Throw a "fake" chat event for other plugins to handle the chat after TownyChat has formatted it.
|
||||||
event = new TownyChatEvent(player, msg);
|
event = new TownyChatEvent(player, event.getMessage(), event.getFormat());
|
||||||
plugin.getServer().getPluginManager().callEvent(event);
|
plugin.getServer().getPluginManager().callEvent(event);
|
||||||
if (event.isCancelled())
|
|
||||||
|
// If the event was canceled by anything other then TownyChat
|
||||||
|
if (event.isCancelled() && !((TownyChatEvent)event).isCanceledByTownyChat())
|
||||||
return;
|
return;
|
||||||
msg = event.getMessage();
|
|
||||||
|
// Read the format after it's been updated by all other plugins.
|
||||||
|
String msg = event.getFormat().replace("%1$s", event.getPlayer().getDisplayName()).replace("%2$s", event.getMessage());
|
||||||
|
|
||||||
plugin.getLogger().info(ChatTools.stripColour(msg));
|
plugin.getLogger().info(ChatTools.stripColour(msg));
|
||||||
|
|
||||||
|
|||||||
@@ -4,8 +4,21 @@ import org.bukkit.entity.Player;
|
|||||||
import org.bukkit.event.player.PlayerChatEvent;
|
import org.bukkit.event.player.PlayerChatEvent;
|
||||||
|
|
||||||
public class TownyChatEvent extends PlayerChatEvent {
|
public class TownyChatEvent extends PlayerChatEvent {
|
||||||
|
|
||||||
public TownyChatEvent(Player player, String message) {
|
public TownyChatEvent(Player player, String message, String format) {
|
||||||
super(player, message);
|
super(player, message);
|
||||||
|
this.setFormat(format);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private boolean tcCanceled = false;
|
||||||
|
|
||||||
|
public void setCanceledByTownyChat(boolean canceled) {
|
||||||
|
this.tcCanceled = canceled;
|
||||||
|
this.setCancelled(canceled);
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isCanceledByTownyChat() {
|
||||||
|
return tcCanceled;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -60,9 +60,8 @@ public class TownyChatPlayerListener implements Listener {
|
|||||||
// if not muted and has permission
|
// if not muted and has permission
|
||||||
if (!isMuted(player)) {
|
if (!isMuted(player)) {
|
||||||
|
|
||||||
event.setCancelled(true);
|
|
||||||
|
|
||||||
if (isSpam(player)) {
|
if (isSpam(player)) {
|
||||||
|
event.setCancelled(true);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -78,6 +77,8 @@ public class TownyChatPlayerListener implements Listener {
|
|||||||
channel.chatProcess(event);
|
channel.chatProcess(event);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
event.setCancelled(true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -133,6 +134,22 @@ public class TownyChatPlayerListener implements Listener {
|
|||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Cancel our own events so they only get sent for formatting changes by others.
|
||||||
|
*
|
||||||
|
* @param event
|
||||||
|
*/
|
||||||
|
@EventHandler(priority = EventPriority.HIGHEST)
|
||||||
|
public void onPlayerChatHighest(PlayerChatEvent event) {
|
||||||
|
|
||||||
|
// We need to cancel events we spawned so only we deal with them.
|
||||||
|
if (event instanceof TownyChatEvent) {
|
||||||
|
((TownyChatEvent) event).setCanceledByTownyChat(true);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private boolean isMuted(Player player) {
|
private boolean isMuted(Player player) {
|
||||||
// Check if essentials has this player muted.
|
// Check if essentials has this player muted.
|
||||||
if (plugin.getTowny().isEssentials()) {
|
if (plugin.getTowny().isEssentials()) {
|
||||||
@@ -149,6 +166,7 @@ public class TownyChatPlayerListener implements Listener {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test if this player is spamming chat.
|
* Test if this player is spamming chat.
|
||||||
* One message every 2 seconds limit
|
* One message every 2 seconds limit
|
||||||
|
|||||||
+1
-1
@@ -1,6 +1,6 @@
|
|||||||
name: TownyChat
|
name: TownyChat
|
||||||
main: com.palmergames.bukkit.TownyChat.Chat
|
main: com.palmergames.bukkit.TownyChat.Chat
|
||||||
version: 0.26
|
version: 0.27
|
||||||
author: ElgarL, Shade, phrstbrn
|
author: ElgarL, Shade, phrstbrn
|
||||||
website: http://code.google.com/a/eclipselabs.org/p/towny/
|
website: http://code.google.com/a/eclipselabs.org/p/towny/
|
||||||
description: >
|
description: >
|
||||||
|
|||||||
Reference in new issue
Block a user