Added new ChatMessageEvent for Mark Hughes.

This commit is contained in:
Aust1n46 2017-03-14 18:25:59 -04:00
parent f6460f36bd
commit 221e523c79
11 changed files with 114 additions and 51 deletions

View File

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

View File

@ -1,5 +1,5 @@
#===============================================================
# MineverseChat Config =
# VentureChat Config =
# Author: Aust1n46 =
#===============================================================
@ -171,8 +171,8 @@ jsonformatting:
# The icon is the block shown in the GUI
# The text is the display name of the block icon
# Include a slash (/) before the command
# Permissions automatically include "mineversechat."
# Example: permissions: alert equals mineversechat.alert
# Permissions are the name of the button and automatically include "venturechat."
# Example: mute equals venturechat.mute
venturegui:
mute:
icon: 'REDSTONE_BLOCK'
@ -206,7 +206,7 @@ underlineurls: true
# broadcast information
broadcast:
color: red
permissions: mineversechat.adminchannel
permissions: venturechat.adminchannel
displaytag: '[Broadcast]'
# Use $ to include arguments into the message
@ -214,8 +214,8 @@ broadcast:
# Command: Sends a message or command in chat
# Message: Sends a message to the player
# Broadcast: Sends a broadcast to all players on the server
# Permissions automatically include "mineversechat."
# Example: permissions: alert equals mineversechat.alert
# Permissions automatically include "venturechat."
# Example: permissions: alert equals venturechat.alert
# Use None for no permissions
# The number of arguments is the minimum number of required arguments, use 0 for no required arguments
alias:
@ -281,11 +281,11 @@ alias:
# Arguments are accepted
irc:
enabled: false
nick: 'MineverseChatBot'
login: 'MineverseChatbot'
nick: 'VentureChatBot'
login: 'VentureChatbot'
server: 'irc.freenode.net'
port: 6667
channel: '#mineversechat'
channel: '#venturechat'
trustallcertificates: true
# the delay before the bot logs into the channel in seconds
# increase the time if the bot fails to login
@ -310,8 +310,8 @@ irc:
# bungeecord overrides distance
# channel permissions are configurable
# channels can be changed, and new channels can be created
# Permissions automatically include "mineversechat."
# Example: permissions: staff equals mineversechat.staff
# Permissions automatically include "venturechat."
# Example: permissions: staff equals venturechat.staff
# Use None for no permissions
# Legacy Placeholders:

View File

@ -1,5 +1,5 @@
#===============================================================
# MineverseChat Config =
# VentureChat Config =
# Author: Aust1n46 =
#===============================================================
@ -138,7 +138,7 @@ messageremoverpermissions: '&cYou need additional permissions to view this messa
# A lower priority overrides a higher priority if a player has more than 1 group
# Possible options for click_name and click_prefix are suggest_command, run_command, and open_url
jsonformatting:
Default:
Default: # This default format is required! Do not delete or rename it!
priority: 2147483647 # Integer.MAX_VALUE
hover_name:
- '&6I have no rank!'
@ -171,8 +171,8 @@ jsonformatting:
# The icon is the block shown in the GUI
# The text is the display name of the block icon
# Include a slash (/) before the command
# Permissions automatically include "mineversechat."
# Example: permissions: alert equals mineversechat.alert
# Permissions are the name of the button and automatically include "venturechat."
# Example: mute equals venturechat.mute
venturegui:
mute:
icon: 'REDSTONE_BLOCK'
@ -206,7 +206,7 @@ underlineurls: true
# broadcast information
broadcast:
color: red
permissions: mineversechat.adminchannel
permissions: venturechat.adminchannel
displaytag: '[Broadcast]'
# Use $ to include arguments into the message
@ -214,8 +214,8 @@ broadcast:
# Command: Sends a message or command in chat
# Message: Sends a message to the player
# Broadcast: Sends a broadcast to all players on the server
# Permissions automatically include "mineversechat."
# Example: permissions: alert equals mineversechat.alert
# Permissions automatically include "venturechat."
# Example: permissions: alert equals venturechat.alert
# Use None for no permissions
# The number of arguments is the minimum number of required arguments, use 0 for no required arguments
alias:
@ -245,11 +245,6 @@ alias:
permissions: None
components:
- 'Message: &aThis is our website: www.site.net'
mail:
arguments: 0
permissions: None
components:
- 'Command: /email$'
tell:
arguments: 0
permissions: None
@ -286,11 +281,11 @@ alias:
# Arguments are accepted
irc:
enabled: false
nick: 'MineverseChatBot'
login: 'MineverseChatbot'
nick: 'VentureChatBot'
login: 'VentureChatbot'
server: 'irc.freenode.net'
port: 6667
channel: '#mineversechat'
channel: '#venturechat'
trustallcertificates: true
# the delay before the bot logs into the channel in seconds
# increase the time if the bot fails to login
@ -315,8 +310,8 @@ irc:
# bungeecord overrides distance
# channel permissions are configurable
# channels can be changed, and new channels can be created
# Permissions automatically include "mineversechat."
# Example: permissions: staff equals mineversechat.staff
# Permissions automatically include "venturechat."
# Example: permissions: staff equals venturechat.staff
# Use None for no permissions
# Legacy Placeholders:

View File

@ -563,22 +563,6 @@ public class MineverseChat extends JavaPlugin implements PluginMessageListener {
}
return;
}*/
if(VersionHandler.is1_9() || VersionHandler.is1_10()) {
try {
MineverseChat.posField = MinecraftReflection.getMinecraftClass("PacketPlayOutChat").getDeclaredField("b");
MineverseChat.posField.setAccessible(true);
}
catch(NoSuchFieldException | SecurityException localNoSuchFieldException) {
localNoSuchFieldException.printStackTrace();
}
try {
MineverseChat.messageMethod = MinecraftReflection.getMinecraftClass("ChatBaseComponent").getDeclaredMethod("toPlainText", new Class[0]);
MineverseChat.messageMethod.setAccessible(true);
}
catch(SecurityException | NoSuchMethodException e) {
e.printStackTrace();
}
}
if(VersionHandler.is1_8() || VersionHandler.is1_7_10()) {
try {
MineverseChat.posField = MinecraftReflection.getMinecraftClass("PacketPlayOutChat").getDeclaredField("b");
@ -595,6 +579,22 @@ public class MineverseChat extends JavaPlugin implements PluginMessageListener {
e.printStackTrace();
}
}
else {
try {
MineverseChat.posField = MinecraftReflection.getMinecraftClass("PacketPlayOutChat").getDeclaredField("b");
MineverseChat.posField.setAccessible(true);
}
catch(NoSuchFieldException | SecurityException localNoSuchFieldException) {
localNoSuchFieldException.printStackTrace();
}
try {
MineverseChat.messageMethod = MinecraftReflection.getMinecraftClass("ChatBaseComponent").getDeclaredMethod("toPlainText", new Class[0]);
MineverseChat.messageMethod.setAccessible(true);
}
catch(SecurityException | NoSuchMethodException e) {
e.printStackTrace();
}
}
}
private boolean setupPermissions() {

View File

@ -1,2 +1,3 @@
/ChannelJoinEvent.class
/MutePlayerEvent.class
/ChatMessageEvent.class

View File

@ -0,0 +1,39 @@
package mineverse.Aust1n46.chat.api.events;
import org.bukkit.event.Event;
import org.bukkit.event.HandlerList;
import mineverse.Aust1n46.chat.ChatMessage;
/**
* Event called when a message has been sent to a channel.
* This event can not be cancelled.
* @author Mark Hughes, Aust1n46
*/
public class ChatMessageEvent extends Event {
private static final HandlerList handlers = new HandlerList();
private final ChatMessage chatMessage;
private final String json;
public ChatMessageEvent(ChatMessage chatMessage, String json) {
this.chatMessage = chatMessage;
this.json = json;
}
public ChatMessage getChatMessage() {
return this.chatMessage;
}
public String getJson() {
return this.json;
}
@Override
public HandlerList getHandlers() {
return handlers;
}
public static HandlerList getHandlerList() {
return handlers;
}
}

View File

@ -22,10 +22,10 @@ public class Chatreload extends MineverseCommand {
plugin.reloadConfig();
Bukkit.getPluginManager().disablePlugin(plugin);
Bukkit.getPluginManager().enablePlugin(plugin);
plugin.getServer().getLogger().info("[" + plugin.getConfig().getString("pluginname", "MineverseChat") + "] Config reloaded");
plugin.getServer().getLogger().info("[VentureChat] Config reloaded");
for(MineverseChatPlayer player : MineverseChat.players) {
if(player.isOnline() && player.getPlayer().hasPermission("venturechat.reload")) {
player.getPlayer().sendMessage(ChatColor.GOLD + plugin.getConfig().getString("pluginname", "MineverseChat") + " config reloaded.");
player.getPlayer().sendMessage(ChatColor.GOLD + "VentureChat config reloaded.");
}
}
return;

View File

@ -2,9 +2,14 @@ package mineverse.Aust1n46.chat.command.chat;
import mineverse.Aust1n46.chat.MineverseChat;
import mineverse.Aust1n46.chat.command.MineverseCommand;
import net.md_5.bungee.api.chat.ClickEvent;
import net.md_5.bungee.api.chat.ComponentBuilder;
import net.md_5.bungee.api.chat.HoverEvent;
import net.md_5.bungee.api.chat.TextComponent;
import org.bukkit.ChatColor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
public class Venturechat extends MineverseCommand {
private MineverseChat plugin;
@ -18,5 +23,16 @@ public class Venturechat extends MineverseCommand {
public void execute(CommandSender sender, String command, String[] args) {
sender.sendMessage(ChatColor.GOLD + "VentureChat Version: " + plugin.getDescription().getVersion());
sender.sendMessage(ChatColor.GOLD + "Written by Aust1n46");
if (sender instanceof Player) {
Player player = (Player) sender;
String title = ChatColor.GOLD + " | " + ChatColor.BLUE.toString() + ChatColor.BOLD + "Click here to begin..." + ChatColor.RESET + ChatColor.GOLD + " | ";
String spaces = " ";
TextComponent tcSpaces = new TextComponent(spaces);
TextComponent message = new TextComponent(title);
message.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new ComponentBuilder("Click here to rank up!").create()));
message.setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/rules 1"));
tcSpaces.addExtra(message);
player.spigot().sendMessage(tcSpaces);
}
}
}

View File

@ -36,6 +36,7 @@ import mineverse.Aust1n46.chat.MineverseChat;
import mineverse.Aust1n46.chat.api.MineverseChatAPI;
import mineverse.Aust1n46.chat.api.MineverseChatPlayer;
import mineverse.Aust1n46.chat.api.events.ChannelJoinEvent;
import mineverse.Aust1n46.chat.api.events.ChatMessageEvent;
import mineverse.Aust1n46.chat.channel.ChatChannel;
import mineverse.Aust1n46.chat.channel.ChatChannelInfo;
import mineverse.Aust1n46.chat.database.DatabaseSender;
@ -677,6 +678,10 @@ public class ChatListener implements Listener {
}
MineverseChat.lastChatMessage = new ChatMessage(mcp.getPlayer().getName(), message, message.hashCode(), format, chat, eventChannel.getName());
MineverseChat.lastJson = Format.convertToJson(MineverseChat.lastChatMessage);
ChatMessageEvent chatMessageEvent = new ChatMessageEvent(MineverseChat.lastChatMessage, MineverseChat.lastJson);
Bukkit.getServer().getPluginManager().callEvent(chatMessageEvent);
if(irc && plugin.irc) {
if(bot.bot.isConnected()) {
bot.bot.getUserChannelDao().getChannel(bot.channel).send().message(mcp.getName() + ":" + evMessage);

View File

@ -12,13 +12,18 @@ import mineverse.Aust1n46.chat.api.MineverseChatAPI;
import mineverse.Aust1n46.chat.api.MineverseChatPlayer;
import mineverse.Aust1n46.chat.utilities.Format;
import mineverse.Aust1n46.chat.versions.VersionHandler;
import net.md_5.bungee.api.chat.BaseComponent;
import net.md_5.bungee.api.chat.TextComponent;
import net.md_5.bungee.chat.ComponentSerializer;
import com.comphenix.protocol.PacketType;
import com.comphenix.protocol.events.ListenerPriority;
import com.comphenix.protocol.events.PacketAdapter;
import com.comphenix.protocol.events.PacketEvent;
import com.comphenix.protocol.reflect.StructureModifier;
import com.comphenix.protocol.wrappers.WrappedChatComponent;
import me.clip.placeholderapi.PlaceholderAPI;
//This class listens for chat packets and intercepts them before they are sent to the Player.
//The packets are modified to include advanced json formating and the message remover button if the
@ -35,7 +40,7 @@ public class PacketListener extends PacketAdapter {
return;
}
/*StructureModifier<WrappedChatComponent> chatP = event.getPacket().getChatComponents();
StructureModifier<WrappedChatComponent> chatP = event.getPacket().getChatComponents();
WrappedChatComponent c = chatP.read(0);
if (c == null) {
StructureModifier<BaseComponent[]> modifier = event.getPacket().getSpecificModifier(BaseComponent[].class);
@ -62,7 +67,7 @@ public class PacketListener extends PacketAdapter {
return;
}
msg = PlaceholderAPI.setBracketPlaceholders(event.getPlayer(), msg);
chatP.write(0, WrappedChatComponent.fromJson(msg))*/
chatP.write(0, WrappedChatComponent.fromJson(msg));
try {
if(VersionHandler.is1_7_10() || VersionHandler.is1_7_9() || VersionHandler.is1_7_2()) {
@ -96,7 +101,9 @@ public class PacketListener extends PacketAdapter {
hash = message != null ? message.hashCode() : -1;
}
catch(Exception ex) {
ex.printStackTrace();
message = TextComponent.toPlainText(new TextComponent(chat.getJson()));
System.out.println(message);
//ex.printStackTrace();
}
ChatMessage lastChatMessage = MineverseChat.lastChatMessage;
MineverseChatPlayer mcp = MineverseChatAPI.getMineverseChatPlayer(event.getPlayer());

View File

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