Added support for the chat event

This commit is contained in:
Norbi Peti 2016-11-25 19:46:23 +01:00
parent 9857bc5bd5
commit 39d932bf77
3 changed files with 26 additions and 6 deletions

View file

@ -46,7 +46,7 @@ public class ChatProcessing {
private static boolean pingedconsole = false;
// Returns e.setCancelled
public static boolean ProcessChat(CommandSender sender, String message) {
public static boolean ProcessChat(Channel channel, CommandSender sender, String message) {
long processstart = System.nanoTime();
if (PluginMain.essentials == null)
PluginMain.essentials = (Essentials) (Bukkit.getPluginManager().getPlugin("Essentials"));
@ -81,7 +81,7 @@ public class ChatProcessing {
}
}
}
Channel currentchannel = (mp == null ? PlayerListener.ConsoleChannel : mp.CurrentChannel);
Channel currentchannel = channel;
ArrayList<ChatFormatter> formatters = new ArrayList<ChatFormatter>();

View file

@ -1,8 +1,13 @@
package buttondevteam.chat.commands.appendtext;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import buttondevteam.chat.ChatProcessing;
import buttondevteam.chat.ChatPlayer;
import buttondevteam.chat.listener.PlayerListener;
import buttondevteam.lib.TBMCPlayer;
import buttondevteam.lib.chat.Channel;
import buttondevteam.lib.chat.TBMCChatAPI;
import buttondevteam.lib.chat.TBMCCommandBase;
public abstract class AppendTextCommandBase extends TBMCCommandBase {
@ -16,7 +21,13 @@ public abstract class AppendTextCommandBase extends TBMCCommandBase {
String msg = GetAppendedText();
for (int i = args.length - 1; i >= 0; i--)
msg = args[i] + " " + msg;
ChatProcessing.ProcessChat(sender, msg);
if (sender instanceof Player)
TBMCChatAPI.SendChatMessage(
TBMCPlayer.getPlayer((Player) sender).asPluginPlayer(ChatPlayer.class).CurrentChannel, sender, msg);
else if (sender.isOp())
TBMCChatAPI.SendChatMessage(PlayerListener.ConsoleChannel, sender, msg);
else
TBMCChatAPI.SendChatMessage(Channel.GlobalChat, sender, msg);
return true;
}

View file

@ -27,9 +27,11 @@ import org.bukkit.potion.PotionEffectType;
import buttondevteam.chat.ChatPlayer;
import buttondevteam.chat.ChatProcessing;
import buttondevteam.chat.PluginMain;
import buttondevteam.lib.TBMCChatEvent;
import buttondevteam.lib.TBMCPlayer;
import buttondevteam.lib.TBMCPlayer.InfoTarget;
import buttondevteam.lib.chat.Channel;
import buttondevteam.lib.chat.TBMCChatAPI;
import buttondevteam.lib.TBMCPlayerGetInfoEvent;
import com.google.common.collect.BiMap;
import com.google.common.collect.HashBiMap;
@ -64,7 +66,9 @@ public class PlayerListener implements Listener {
public void onPlayerChat(AsyncPlayerChatEvent event) {
if (event.isCancelled())
return;
event.setCancelled(ChatProcessing.ProcessChat(event.getPlayer(), event.getMessage()));
TBMCChatAPI.SendChatMessage(
TBMCPlayer.getPlayer(event.getPlayer()).asPluginPlayer(ChatPlayer.class).CurrentChannel,
event.getPlayer(), event.getMessage());
}
@EventHandler(priority = EventPriority.HIGHEST)
@ -288,7 +292,7 @@ public class PlayerListener implements Listener {
if (cmd.equalsIgnoreCase(channel.Command)) {
Channel c = ConsoleChannel;
ConsoleChannel = channel;
ChatProcessing.ProcessChat(Bukkit.getServer().getConsoleSender(),
TBMCChatAPI.SendChatMessage(PlayerListener.ConsoleChannel, Bukkit.getConsoleSender(),
event.getCommand().substring(index + 1));
ConsoleChannel = c;
event.setCommand("dontrunthiscmd");
@ -329,4 +333,9 @@ public class PlayerListener implements Listener {
e.addInfo("/r/TheButton flair: " + flair);
e.addInfo("Respect: " + (double) cp.getFCount() / (double) cp.getFDeaths());
}
@EventHandler
public void onPlayerTBMCChat(TBMCChatEvent e) {
ChatProcessing.ProcessChat(e.getChannel(), e.getSender(), e.getMessage());
}
}