API additions to ChatMessageEvent

Made "<message removed>" text configurable

Added new config option 'messageremovertext:'
This commit is contained in:
Aust1n46 2019-02-07 16:06:07 -05:00
parent 5aa13908bd
commit 622b2f113d
7 changed files with 30 additions and 6 deletions

View File

@ -1,4 +1,4 @@
name: VentureChat name: VentureChat
main: mineverse.Aust1n46.chat.bungee.MineverseChatBungee main: mineverse.Aust1n46.chat.bungee.MineverseChatBungee
version: 2.14.0 version: 2.14.2
author: Aust1n46 author: Aust1n46

View File

@ -132,6 +132,7 @@ ignorechat: false
emptychannelalert: "&6No one is listening to you." emptychannelalert: "&6No one is listening to you."
messageremoverpermissions: '&cYou need additional permissions to view this message!' messageremoverpermissions: '&cYou need additional permissions to view this message!'
messageremovertext: '&c&o<message removed>'
# The name of the group is the permissions node for the format # The name of the group is the permissions node for the format
# Example: venturechat.json.Owner is the node for the group Owner # Example: venturechat.json.Owner is the node for the group Owner

View File

@ -132,6 +132,7 @@ ignorechat: false
emptychannelalert: "&6No one is listening to you." emptychannelalert: "&6No one is listening to you."
messageremoverpermissions: '&cYou need additional permissions to view this message!' messageremoverpermissions: '&cYou need additional permissions to view this message!'
messageremovertext: '&c&o<message removed>'
# The name of the group is the permissions node for the format # The name of the group is the permissions node for the format
# Example: mineversechat.json.Owner is the node for the group Owner # Example: mineversechat.json.Owner is the node for the group Owner

View File

@ -4,6 +4,8 @@ import org.bukkit.event.Event;
import org.bukkit.event.HandlerList; import org.bukkit.event.HandlerList;
import mineverse.Aust1n46.chat.ChatMessage; import mineverse.Aust1n46.chat.ChatMessage;
import mineverse.Aust1n46.chat.api.MineverseChatPlayer;
import mineverse.Aust1n46.chat.channel.ChatChannel;
/** /**
* Event called when a message has been sent to a channel. * Event called when a message has been sent to a channel.
@ -12,14 +14,32 @@ import mineverse.Aust1n46.chat.ChatMessage;
*/ */
public class ChatMessageEvent extends Event { public class ChatMessageEvent extends Event {
private static final HandlerList handlers = new HandlerList(); private static final HandlerList handlers = new HandlerList();
private final MineverseChatPlayer mcp;
private final ChatChannel channel;
private final boolean bungee;
private final ChatMessage chatMessage; private final ChatMessage chatMessage;
private final String json; private final String json;
public ChatMessageEvent(ChatMessage chatMessage, String json) { public ChatMessageEvent(MineverseChatPlayer mcp, ChatChannel channel, boolean bungee, ChatMessage chatMessage, String json) {
this.mcp = mcp;
this.channel = channel;
this.bungee = bungee;
this.chatMessage = chatMessage; this.chatMessage = chatMessage;
this.json = json; this.json = json;
} }
public MineverseChatPlayer getMineverseChatPlayer() {
return mcp;
}
public ChatChannel getChannel() {
return channel;
}
public boolean isBungee() {
return bungee;
}
public ChatMessage getChatMessage() { public ChatMessage getChatMessage() {
return this.chatMessage; return this.chatMessage;
} }

View File

@ -181,7 +181,8 @@ public class Removemessage extends MineverseCommand {
public WrappedChatComponent getMessageDeletedChatComponentPlayer() { public WrappedChatComponent getMessageDeletedChatComponentPlayer() {
if(this.messageDeletedComponentPlayer == null) { if(this.messageDeletedComponentPlayer == null) {
this.messageDeletedComponentPlayer = WrappedChatComponent.fromJson("{\"text\":\"\",\"extra\":[{\"text\":\"<message removed>\",\"color\":\"red\",\"italic\":\"true\",\"hoverEvent\":{\"action\":\"show_text\",\"value\":{\"text\":\"\",\"extra\":[{\"text\":\"" + Format.FormatStringAll(plugin.getConfig().getString("messageremoverpermissions")) + "\"}]}}}]}"); //this.messageDeletedComponentPlayer = WrappedChatComponent.fromJson("{\"text\":\"\",\"extra\":[{\"text\":\"<message removed>\",\"color\":\"red\",\"italic\":\"true\",\"hoverEvent\":{\"action\":\"show_text\",\"value\":{\"text\":\"\",\"extra\":[{\"text\":\"" + Format.FormatStringAll(plugin.getConfig().getString("messageremoverpermissions")) + "\"}]}}}]}");
this.messageDeletedComponentPlayer = WrappedChatComponent.fromJson("{\"text\":\"\",\"extra\":[{\"text\":\"" + Format.FormatStringAll(plugin.getConfig().getString("messageremovertext")) + "\",\"hoverEvent\":{\"action\":\"show_text\",\"value\":{\"text\":\"\",\"extra\":[{\"text\":\"" + Format.FormatStringAll(plugin.getConfig().getString("messageremoverpermissions")) + "\"}]}}}]}");
} }
return this.messageDeletedComponentPlayer; return this.messageDeletedComponentPlayer;
} }
@ -191,6 +192,6 @@ public class Removemessage extends MineverseCommand {
if(message.getMessage().contains(ChatColor.stripColor(Format.FormatStringAll(plugin.getConfig().getString("guiicon"))))) { if(message.getMessage().contains(ChatColor.stripColor(Format.FormatStringAll(plugin.getConfig().getString("guiicon"))))) {
oMessage = oMessage.substring(0, oMessage.length() - ChatColor.stripColor(Format.FormatStringAll(plugin.getConfig().getString("guiicon"))).length() - 3) + "\"}]"; oMessage = oMessage.substring(0, oMessage.length() - ChatColor.stripColor(Format.FormatStringAll(plugin.getConfig().getString("guiicon"))).length() - 3) + "\"}]";
} }
return WrappedChatComponent.fromJson(Format.FormatStringAll("{\"text\":\"\",\"extra\":[{\"text\":\"&c&o<message removed>\",\"hoverEvent\":{\"action\":\"show_text\",\"value\":{\"text\":\"&7Message: \"," + oMessage + "}}}]}")); return WrappedChatComponent.fromJson(Format.FormatStringAll("{\"text\":\"\",\"extra\":[{\"text\":\"" + Format.FormatStringAll(plugin.getConfig().getString("messageremovertext")) + "\",\"hoverEvent\":{\"action\":\"show_text\",\"value\":{\"text\":\"&7Message: \"," + oMessage + "}}}]}"));
} }
} }

View File

@ -689,7 +689,7 @@ public class ChatListener implements Listener {
MineverseChat.lastChatMessage = new ChatMessage(mcp.getPlayer().getName(), message, message.hashCode(), format, chat, eventChannel.getName()); MineverseChat.lastChatMessage = new ChatMessage(mcp.getPlayer().getName(), message, message.hashCode(), format, chat, eventChannel.getName());
MineverseChat.lastJson = Format.convertToJson(MineverseChat.lastChatMessage); MineverseChat.lastJson = Format.convertToJson(MineverseChat.lastChatMessage);
ChatMessageEvent chatMessageEvent = new ChatMessageEvent(MineverseChat.lastChatMessage, MineverseChat.lastJson); ChatMessageEvent chatMessageEvent = new ChatMessageEvent(mcp, eventChannel, bungee, MineverseChat.lastChatMessage, MineverseChat.lastJson);
Bukkit.getServer().getPluginManager().callEvent(chatMessageEvent); Bukkit.getServer().getPluginManager().callEvent(chatMessageEvent);
if(irc && plugin.irc) { if(irc && plugin.irc) {
@ -749,6 +749,7 @@ public class ChatListener implements Listener {
catch(Exception e) { catch(Exception e) {
e.printStackTrace(); e.printStackTrace();
} }
} }
} }
catch(IllegalFormatException ex) { catch(IllegalFormatException ex) {

View File

@ -1,5 +1,5 @@
name: VentureChat name: VentureChat
version: 2.14.0 version: 2.14.2
main: mineverse.Aust1n46.chat.MineverseChat main: mineverse.Aust1n46.chat.MineverseChat
depend: [Vault, ProtocolLib, PlaceholderAPI] depend: [Vault, ProtocolLib, PlaceholderAPI]
softdepend: [Towny, Factions, Heroes] softdepend: [Towny, Factions, Heroes]