Added /lenny to plugin.yml and fixed an NPE

Fixed NPE for non-players trying to chat
This commit is contained in:
Norbi Peti 2017-08-18 03:04:13 +02:00
parent 9ab875f73b
commit 2f83a90553
3 changed files with 25 additions and 19 deletions

View file

@ -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

View file

@ -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))

View file

@ -26,6 +26,8 @@ commands:
waitwhat:
description: Wait what
aliases: ww
lenny:
description: Lenny face.
author: NorbiPeti
depend:
- Essentials