From e5053a04833ec59b9038f97cb7bca5e5f5dd8c3a Mon Sep 17 00:00:00 2001 From: NorbiPeti Date: Wed, 18 Apr 2018 22:44:31 +0200 Subject: [PATCH] Fixes and more helpful error messages --- pom.xml | 4 +-- .../chat/commands/ucmds/NColorCommand.java | 6 ++--- .../ucmds/admin/TownColorCommand.java | 1 + .../chat/formatting/ChatFormatter.java | 26 ++++++++----------- .../listener/PlayerJoinLeaveListener.java | 15 +++++++---- 5 files changed, 27 insertions(+), 25 deletions(-) diff --git a/pom.xml b/pom.xml index fe745f6..890ef83 100644 --- a/pom.xml +++ b/pom.xml @@ -106,7 +106,7 @@ https://hub.spigotmc.org/nexus/content/repositories/snapshots/ - jitpack.io + jitpack https://jitpack.io/ @@ -198,7 +198,7 @@ com.github.webbukkit Dynmap - master-SNAPSHOT + v2.5 diff --git a/src/main/java/buttondevteam/chat/commands/ucmds/NColorCommand.java b/src/main/java/buttondevteam/chat/commands/ucmds/NColorCommand.java index 71e2ec6..79432c6 100644 --- a/src/main/java/buttondevteam/chat/commands/ucmds/NColorCommand.java +++ b/src/main/java/buttondevteam/chat/commands/ucmds/NColorCommand.java @@ -58,15 +58,15 @@ public class NColorCommand extends UCommandBase { return true; } if (nameparts.length < towncolors.length) { - player.sendMessage("§cYou need more vertical lines (|) in your name."); + player.sendMessage("§cYou need more vertical lines (|) in your name. (Should have " + (towncolors.length - 1) + ")"); return true; } if (nameparts.length > towncolors.length * 2) { - player.sendMessage("§cYou have waay too many vertical lines (|) in your name."); + player.sendMessage("§cYou have waay too many vertical lines (|) in your name. (Should have " + (towncolors.length - 1) + ")"); return true; } if (nameparts.length > towncolors.length) { - player.sendMessage("§cYou have too many vertical lines (|) in your name."); + player.sendMessage("§cYou have too many vertical lines (|) in your name. (Should have " + (towncolors.length - 1) + ")"); return true; } ChatPlayer.getPlayer(player.getUniqueId(), ChatPlayer.class).NameColorLocations() diff --git a/src/main/java/buttondevteam/chat/commands/ucmds/admin/TownColorCommand.java b/src/main/java/buttondevteam/chat/commands/ucmds/admin/TownColorCommand.java index 8b4a44f..c45a95e 100644 --- a/src/main/java/buttondevteam/chat/commands/ucmds/admin/TownColorCommand.java +++ b/src/main/java/buttondevteam/chat/commands/ucmds/admin/TownColorCommand.java @@ -45,6 +45,7 @@ public class TownColorCommand extends AdminCommandBase { if (!c.isPresent()) { //^^ Skip black sender.sendMessage("§cThe color '" + args[i] + "' cannot be found."); //ˇˇ Skip black sender.sendMessage("§cAvailable colors: " + Arrays.stream(Color.values()).skip(1).map(col -> String.format("§%x%s§r", col.ordinal(), col.getName())).collect(Collectors.joining(", "))); + sender.sendMessage("§cMake sure to type them exactly as shown above."); return true; } clrs[i - 1] = c.get(); diff --git a/src/main/java/buttondevteam/chat/formatting/ChatFormatter.java b/src/main/java/buttondevteam/chat/formatting/ChatFormatter.java index 691e074..4eea954 100644 --- a/src/main/java/buttondevteam/chat/formatting/ChatFormatter.java +++ b/src/main/java/buttondevteam/chat/formatting/ChatFormatter.java @@ -1,24 +1,20 @@ package buttondevteam.chat.formatting; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.HashMap; -import java.util.List; -import java.util.Map; +import buttondevteam.chat.ChatProcessing; +import buttondevteam.chat.commands.ucmds.admin.DebugCommand; +import buttondevteam.lib.chat.Color; +import buttondevteam.lib.chat.Priority; +import lombok.Builder; +import lombok.Data; +import lombok.val; + +import java.util.*; import java.util.function.BiFunction; -import java.util.function.Function; import java.util.function.Predicate; import java.util.regex.Matcher; import java.util.regex.Pattern; import java.util.stream.Collectors; -import buttondevteam.chat.ChatProcessing; -import buttondevteam.chat.commands.ucmds.admin.DebugCommand; -import buttondevteam.lib.chat.*; -import lombok.Builder; -import lombok.Data; -import lombok.val; - /** * A {@link ChatFormatter} shows what formatting to use based on regular expressions. {@link ChatFormatter#Combine(List, String, TellrawPart)} is used to turn it into a {@link TellrawPart}, combining * intersecting parts found, for example when {@code _abc*def*ghi_} is said in chat, it'll turn it into an underlined part, then an underlined and italics part, finally an underlined part @@ -279,8 +275,8 @@ public final class ChatFormatter { if (rce.isPresent()) e = rce.get()[0]; DebugCommand.SendDebugMessage("After RC - Start: " + s + " - End: " + e); - if (e - s < 1) { - DebugCommand.SendDebugMessage("Skipping section because of remchars (length would be " + (e - s) + ")"); + if (e - s < 0) { //e-s==0 means the end char is the same as start char, so one char message + DebugCommand.SendDebugMessage("Skipping section because of remchars (length would be " + (e - s + 1) + ")"); continue; } originaltext = str.substring(s, e + 1); diff --git a/src/main/java/buttondevteam/chat/listener/PlayerJoinLeaveListener.java b/src/main/java/buttondevteam/chat/listener/PlayerJoinLeaveListener.java index 396a668..711670d 100644 --- a/src/main/java/buttondevteam/chat/listener/PlayerJoinLeaveListener.java +++ b/src/main/java/buttondevteam/chat/listener/PlayerJoinLeaveListener.java @@ -45,7 +45,7 @@ public class PlayerJoinLeaveListener implements Listener { PlayerJoinTimerTask tt = new PlayerJoinTimerTask() { @Override public void run() { - p.setPlayerListName(p.getName() + mp.GetFormattedFlair()); + mp.FlairUpdate(); } }; tt.mp = cp; @@ -78,8 +78,6 @@ public class PlayerJoinLeaveListener implements Listener { String nwithoutformatting = PluginMain.essentials.getUser(p).getNickname(); - updatePlayerColors(p); - int index; if (nwithoutformatting != null) { while ((index = nwithoutformatting.indexOf("§k")) != -1) @@ -90,7 +88,9 @@ public class PlayerJoinLeaveListener implements Listener { nwithoutformatting = p.getName(); PlayerListener.nicknames.put(nwithoutformatting, p.getUniqueId()); - cp.FlairUpdate(); + Bukkit.getScheduler().runTask(PluginMain.Instance, () -> { + updatePlayerColors(p, cp); //TODO: Doesn't have effect + }); if (cp.ChatOnly || p.getGameMode().equals(GameMode.SPECTATOR)) { cp.ChatOnly = false; @@ -141,7 +141,12 @@ public class PlayerJoinLeaveListener implements Listener { } } - public static void updatePlayerColors(Player player) { + public static void updatePlayerColors(Player player) { //Probably while ingame (/u ncolor) + updatePlayerColors(player, ChatPlayer.getPlayer(player.getUniqueId(), ChatPlayer.class)); + } + + public static void updatePlayerColors(Player player, ChatPlayer cp) { //Probably at join player.setDisplayName(getPlayerDisplayName(player)); + cp.FlairUpdate(); //Update in list } }