From 2f83a9055301fbaccdfcc3656007f84b012623f9 Mon Sep 17 00:00:00 2001 From: NorbiPeti Date: Fri, 18 Aug 2017 03:04:13 +0200 Subject: [PATCH] Added /lenny to plugin.yml and fixed an NPE Fixed NPE for non-players trying to chat --- .../buttondevteam/chat/ChatProcessing.java | 5 ++- .../chat/listener/PlayerListener.java | 37 ++++++++++--------- src/main/resources/plugin.yml | 2 + 3 files changed, 25 insertions(+), 19 deletions(-) diff --git a/src/main/java/buttondevteam/chat/ChatProcessing.java b/src/main/java/buttondevteam/chat/ChatProcessing.java index b45db0a..ef8bdae 100644 --- a/src/main/java/buttondevteam/chat/ChatProcessing.java +++ b/src/main/java/buttondevteam/chat/ChatProcessing.java @@ -134,8 +134,11 @@ public class ChatProcessing { for (Player p : Bukkit.getOnlinePlayers()) { final int mcScore = VanillaUtils.getMCScoreIfChatOn(p, e); obj.getScore(p.getName()) - .setScore(p.getUniqueId().equals(player.getUniqueId()) ? score = mcScore : mcScore); + .setScore(p.getUniqueId().equals(player == null ? null : player.getUniqueId()) // p.UniqueID==player?.UniqueID + ? score = mcScore : mcScore); } + if (player == null) + score = e.getMCScore(sender); PluginMain.Instance.getServer().dispatchCommand(PluginMain.Console, String.format( "tellraw @a[score_%s=%d,score_%s_min=%d] %s", channel.ID, score, channel.ID, score, jsonstr)); } else diff --git a/src/main/java/buttondevteam/chat/listener/PlayerListener.java b/src/main/java/buttondevteam/chat/listener/PlayerListener.java index ea96c79..521eb54 100644 --- a/src/main/java/buttondevteam/chat/listener/PlayerListener.java +++ b/src/main/java/buttondevteam/chat/listener/PlayerListener.java @@ -62,7 +62,7 @@ public class PlayerListener implements Listener { int index = event.getMessage().indexOf(" "); ChatPlayer mp = TBMCPlayer.getPlayer(event.getPlayer().getUniqueId(), ChatPlayer.class); String cmd = ""; - if (index == -1) { + if (index == -1) { // Only the command is run cmd = event.getMessage().substring(1); for (Channel channel : Channel.getChannels()) { if (cmd.equalsIgnoreCase(channel.ID)) { @@ -75,29 +75,30 @@ public class PlayerListener implements Listener { break; } } - } else { + } else { // We have arguments cmd = event.getMessage().substring(1, index); - for (Channel channel : Channel.getChannels()) { - if (cmd.equalsIgnoreCase(channel.ID)) { + if (cmd.equalsIgnoreCase("tpahere")) { + Player player = Bukkit.getPlayer(event.getMessage().substring(index + 1)); + if (player != null) + player.sendMessage("§b" + event.getPlayer().getDisplayName() + " §bis in this world: " + + event.getPlayer().getWorld().getName()); + } else if (cmd.equalsIgnoreCase("minecraft:me")) { + if (!PluginMain.essentials.getUser(event.getPlayer()).isMuted()) { event.setCancelled(true); - Channel c = mp.CurrentChannel; - mp.CurrentChannel = channel; - event.getPlayer().chat(event.getMessage().substring(index + 1)); - mp.CurrentChannel = c; - } else if (cmd.equalsIgnoreCase("tpahere")) { - Player player = Bukkit.getPlayer(event.getMessage().substring(index + 1)); - if (player != null) - player.sendMessage("§b" + event.getPlayer().getDisplayName() + " §bis in this world: " - + event.getPlayer().getWorld().getName()); - } else if (cmd.equalsIgnoreCase("minecraft:me")) { - if (!PluginMain.essentials.getUser(event.getPlayer()).isMuted()) { + String message = event.getMessage().substring(index + 1); + Bukkit.broadcastMessage(String.format("* %s %s", event.getPlayer().getDisplayName(), message)); + } + } else + for (Channel channel : Channel.getChannels()) { + if (cmd.equalsIgnoreCase(channel.ID)) { event.setCancelled(true); - String message = event.getMessage().substring(index + 1); - Bukkit.broadcastMessage(String.format("* %s %s", event.getPlayer().getDisplayName(), message)); + TBMCChatAPI.SendChatMessage(channel, event.getPlayer(), + event.getMessage().substring(index + 1)); } } - } + // TODO: Target selectors } + // We don't care if we have arguments if (cmd.toLowerCase().startsWith("un")) { for (HelpTopic ht : PluginMain.Instance.getServer().getHelpMap().getHelpTopics()) { if (ht.getName().equalsIgnoreCase("/" + cmd)) diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml index 49ccb02..de34be8 100644 --- a/src/main/resources/plugin.yml +++ b/src/main/resources/plugin.yml @@ -26,6 +26,8 @@ commands: waitwhat: description: Wait what aliases: ww + lenny: + description: Lenny face. author: NorbiPeti depend: - Essentials