Re-added nickname map... Fixes

This commit is contained in:
Norbi Peti 2018-05-18 01:32:05 +02:00
parent 71242cc0ac
commit ef2328e126
No known key found for this signature in database
GPG key ID: DBA4C4549A927E56
4 changed files with 47 additions and 39 deletions

View file

@ -128,7 +128,7 @@ public class ChatPlayer extends TBMCPlayerBase {
return 0x6;
else if (flairTime <= 11 && flairTime >= 0)
return 0xc;
return 0xf;
return 0x00; //Return 0 if none or too high, so names will get aqua default color, not white
}
public double getF() {

View file

@ -276,11 +276,11 @@ public class ChatProcessing {
if (addNickFormatter)
formatters.add(ChatFormatter.builder().regex((Pattern.compile(nicksb.toString()))).color(Color.Aqua)
.onmatch((match, builder) -> {
if (PlayerListener.nicknames.containsKey(match)) {
Player p = Bukkit.getPlayer(PlayerListener.nicknames.get(match));
if (PlayerListener.nicknames.containsKey(match.toLowerCase())) { //Made a stream and all that but I can actually store it lowercased
Player p = Bukkit.getPlayer(PlayerListener.nicknames.get(match.toLowerCase()));
if (p == null) {
PluginMain.Instance.getLogger().warning("Error: Can't find player nicknamed "
+ match + " but was reported as online.");
+ match.toLowerCase() + " but was reported as online.");
return "§c" + match + "§r";
}
if (PlayerListener.NotificationSound == null)
@ -290,7 +290,7 @@ public class ChatProcessing {
(float) PlayerListener.NotificationPitch);
return PluginMain.essentials.getUser(p).getNickname();
}
Bukkit.getServer().getLogger().warning("Player nicknamed " + match
Bukkit.getServer().getLogger().warning("Player nicknamed " + match.toLowerCase()
+ " not found in nickname map but was reported as online.");
return "§c" + match + "§r";
}).priority(Priority.High).build());

View file

@ -87,7 +87,7 @@ public class PlayerJoinLeaveListener implements Listener {
nwithoutformatting = nwithoutformatting.replace("§" + nwithoutformatting.charAt(index + 1), "");
} else
nwithoutformatting = p.getName();
PlayerListener.nicknames.put(nwithoutformatting, p.getUniqueId());
PlayerListener.nicknames.forcePut(nwithoutformatting.toLowerCase(), p.getUniqueId());
Bukkit.getScheduler().runTaskLater(PluginMain.Instance, () -> {
updatePlayerColors(p, cp); //TODO: Doesn't have effect

View file

@ -12,6 +12,8 @@ import buttondevteam.lib.chat.TBMCChatAPI;
import buttondevteam.lib.player.ChromaGamerBase.InfoTarget;
import buttondevteam.lib.player.TBMCPlayer;
import buttondevteam.lib.player.TBMCPlayerGetInfoEvent;
import com.google.common.collect.BiMap;
import com.google.common.collect.HashBiMap;
import com.vexsoftware.votifier.model.Vote;
import com.vexsoftware.votifier.model.VotifierEvent;
import net.ess3.api.events.NickChangeEvent;
@ -31,11 +33,17 @@ import org.bukkit.potion.PotionEffect;
import org.bukkit.potion.PotionEffectType;
import java.util.*;
import java.util.Map.Entry;
import java.util.function.BiPredicate;
import java.util.function.Consumer;
import java.util.function.Supplier;
public class PlayerListener implements Listener {
/**
* Does not contain format codes, lowercased
*/
public static BiMap<String, UUID> nicknames = HashBiMap.create();
public static boolean Enable = false;
public static int LoginWarningCountTotal = 5;
@ -109,31 +117,31 @@ public class PlayerListener implements Listener {
if (player != null && sender instanceof Player)
player.sendMessage("§b" + ((Player) sender).getDisplayName() + " §bis in this world: "
+ ((Player) sender).getWorld().getName());
} else if (cmd.equalsIgnoreCase("minecraft:me")) {
if (!(sender instanceof Player) || !PluginMain.essentials.getUser((Player) sender).isMuted()) {
String msg = message.substring(index + 1);
Bukkit.broadcastMessage(String.format("* %s %s", sender instanceof Player ? ((Player) sender).getDisplayName() : sender.getName(), msg));
return true;
} else {
sender.sendMessage("§cCan't use /minecraft:me while muted.");
return true;
}
} else if (cmd.equalsIgnoreCase("me")) { //Take over for Discord broadcast
if (!(sender instanceof Player) || !PluginMain.essentials.getUser((Player) sender).isMuted()) {
String msg = message.substring(index + 1);
Bukkit.broadcastMessage(String.format("§5* %s %s", sender instanceof Player ? ((Player) sender).getDisplayName() : sender.getName(), msg));
return true;
} else {
sender.sendMessage("§cCan't use /me while muted.");
return true;
}
} else
for (Channel channel : Channel.getChannels()) {
} else if (cmd.equalsIgnoreCase("minecraft:me")) {
if (!(sender instanceof Player) || !PluginMain.essentials.getUser((Player) sender).isMuted()) {
String msg = message.substring(index + 1);
Bukkit.broadcastMessage(String.format("* %s %s", sender instanceof Player ? ((Player) sender).getDisplayName() : sender.getName(), msg));
return true;
} else {
sender.sendMessage("§cCan't use /minecraft:me while muted.");
return true;
}
} else if (cmd.equalsIgnoreCase("me")) { //Take over for Discord broadcast
if (!(sender instanceof Player) || !PluginMain.essentials.getUser((Player) sender).isMuted()) {
String msg = message.substring(index + 1);
Bukkit.broadcastMessage(String.format("§5* %s %s", sender instanceof Player ? ((Player) sender).getDisplayName() : sender.getName(), msg));
return true;
} else {
sender.sendMessage("§cCan't use /me while muted.");
return true;
}
} else
for (Channel channel : Channel.getChannels()) {
if (checkchid.test(channel, cmd)) { //Apparently method references don't require final variables
TBMCChatAPI.SendChatMessage(channel, sender, message.substring(index + 1));
return true;
}
}
TBMCChatAPI.SendChatMessage(channel, sender, message.substring(index + 1));
return true;
}
}
// TODO: Target selectors
}
// We don't care if we have arguments
@ -162,10 +170,9 @@ public class PlayerListener implements Listener {
@EventHandler
public void onTabComplete(PlayerChatTabCompleteEvent e) {
String name = e.getLastToken();
for (Player p : Bukkit.getOnlinePlayers()) {
String displayName = ChatColor.stripColor(p.getDisplayName());
if (displayName.startsWith(name))
e.getTabCompletions().add(displayName);
for (Entry<String, UUID> nicknamekv : nicknames.entrySet()) {
if (nicknamekv.getKey().startsWith(name.toLowerCase()))
e.getTabCompletions().add(Bukkit.getPlayer(nicknamekv.getValue()).getName()); //Tabcomplete with the correct case
}
}
@ -272,7 +279,7 @@ public class PlayerListener implements Listener {
if (e.shouldSendTo(p))
p.sendMessage("§c!§r["
+ e.getChannel().DisplayName + "] <" + (e.getSender() instanceof Player
? ((Player) e.getSender()).getDisplayName() : e.getSender().getName())
? ((Player) e.getSender()).getDisplayName() : e.getSender().getName())
+ "> " + e.getMessage());
TBMCCoreAPI.SendException("An error occured while processing a chat message!", ex);
}
@ -286,10 +293,11 @@ public class PlayerListener implements Listener {
@EventHandler
public void onNickChange(NickChangeEvent e) {
//PlayerJoinLeaveListener.updatePlayerColors(e.getAffected().getBase()); //Won't fire this event again
nicknames.inverse().forcePut(e.getAffected().getBase().getUniqueId(), ChatColor.stripColor(e.getValue()).toLowerCase());
//PlayerJoinLeaveListener.updatePlayerColors(e.getAffected().getBase()); //Won't fire this event again
Bukkit.getScheduler().runTaskLater(PluginMain.Instance, () -> {
PlayerJoinLeaveListener.updatePlayerColors(e.getAffected().getBase()); //TODO: Doesn't have effect
}, 1);
Bukkit.getScheduler().runTaskLater(PluginMain.Instance, () -> {
PlayerJoinLeaveListener.updatePlayerColors(e.getAffected().getBase()); //TODO: Doesn't have effect
}, 1);
}
}