From 9677653c545d850bc96ca5cbb216d3bb93554ca1 Mon Sep 17 00:00:00 2001 From: JamieSinn Date: Fri, 11 Dec 2015 23:30:21 -0500 Subject: [PATCH 1/5] If sender is console, strip colours for mctop Ugly ugly colours. --- .../commands/MctopCommandDisplayTask.java | 30 ++++++++++++------- 1 file changed, 19 insertions(+), 11 deletions(-) diff --git a/src/main/java/com/gmail/nossr50/runnables/commands/MctopCommandDisplayTask.java b/src/main/java/com/gmail/nossr50/runnables/commands/MctopCommandDisplayTask.java index b7c63199b..3f8d1cc10 100644 --- a/src/main/java/com/gmail/nossr50/runnables/commands/MctopCommandDisplayTask.java +++ b/src/main/java/com/gmail/nossr50/runnables/commands/MctopCommandDisplayTask.java @@ -1,17 +1,16 @@ package com.gmail.nossr50.runnables.commands; -import java.util.List; - +import com.gmail.nossr50.datatypes.database.PlayerStat; +import com.gmail.nossr50.datatypes.skills.SkillType; +import com.gmail.nossr50.locale.LocaleLoader; +import com.gmail.nossr50.mcMMO; +import com.gmail.nossr50.util.scoreboards.ScoreboardManager; import org.bukkit.ChatColor; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; import org.bukkit.scheduler.BukkitRunnable; -import com.gmail.nossr50.mcMMO; -import com.gmail.nossr50.datatypes.database.PlayerStat; -import com.gmail.nossr50.datatypes.skills.SkillType; -import com.gmail.nossr50.locale.LocaleLoader; -import com.gmail.nossr50.util.scoreboards.ScoreboardManager; +import java.util.List; /** * Display the results of {@link MctopCommandAsyncTask} to the sender. @@ -45,15 +44,23 @@ public class MctopCommandDisplayTask extends BukkitRunnable { if (sender instanceof Player) { ((Player) sender).removeMetadata(mcMMO.databaseCommandKey, mcMMO.p); } - sender.sendMessage(LocaleLoader.getString("Commands.mctop.Tip")); + if(sender instanceof Player) + sender.sendMessage(LocaleLoader.getString("Commands.mctop.Tip")); } private void displayChat() { + if (skill == null) { - sender.sendMessage(LocaleLoader.getString("Commands.PowerLevel.Leaderboard")); + if(sender instanceof Player) + sender.sendMessage(LocaleLoader.getString("Commands.PowerLevel.Leaderboard")); + else + sender.sendMessage(ChatColor.stripColor(LocaleLoader.getString("Commands.PowerLevel.Leaderboard"))); } else { - sender.sendMessage(LocaleLoader.getString("Commands.Skill.Leaderboard", skill.getName())); + if(sender instanceof Player) + sender.sendMessage(LocaleLoader.getString("Commands.Skill.Leaderboard", skill.getName())); + else + sender.sendMessage(ChatColor.stripColor(LocaleLoader.getString("Commands.Skill.Leaderboard", skill.getName()))); } int place = (page * 10) - 9; @@ -62,7 +69,8 @@ public class MctopCommandDisplayTask extends BukkitRunnable { // Format: // 01. Playername - skill value // 12. Playername - skill value - sender.sendMessage(String.format("%2d. %s%s - %s%s", place, ChatColor.GREEN, stat.name, ChatColor.WHITE, stat.statVal)); + sender.sendMessage(String.format("%2d. %s%s - %s%s", place, sender instanceof Player ? ChatColor.GREEN : "", + stat.name, sender instanceof Player ? ChatColor.WHITE : "", stat.statVal)); place++; } } From a0635eeb08c1aa5c261f671e2074039a1b42b240 Mon Sep 17 00:00:00 2001 From: JamieSinn Date: Fri, 11 Dec 2015 23:45:17 -0500 Subject: [PATCH 2/5] Remove escape character at EOL --- .../nossr50/runnables/commands/MctopCommandDisplayTask.java | 6 +++--- .../com/gmail/nossr50/runnables/party/PartyChatTask.java | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/main/java/com/gmail/nossr50/runnables/commands/MctopCommandDisplayTask.java b/src/main/java/com/gmail/nossr50/runnables/commands/MctopCommandDisplayTask.java index 3f8d1cc10..5c2c571fe 100644 --- a/src/main/java/com/gmail/nossr50/runnables/commands/MctopCommandDisplayTask.java +++ b/src/main/java/com/gmail/nossr50/runnables/commands/MctopCommandDisplayTask.java @@ -54,13 +54,13 @@ public class MctopCommandDisplayTask extends BukkitRunnable { if(sender instanceof Player) sender.sendMessage(LocaleLoader.getString("Commands.PowerLevel.Leaderboard")); else - sender.sendMessage(ChatColor.stripColor(LocaleLoader.getString("Commands.PowerLevel.Leaderboard"))); + sender.sendMessage(ChatColor.stripColor(LocaleLoader.getString("Commands.PowerLevel.Leaderboard")).replaceAll("\\033\\[m", "")); } else { if(sender instanceof Player) sender.sendMessage(LocaleLoader.getString("Commands.Skill.Leaderboard", skill.getName())); else - sender.sendMessage(ChatColor.stripColor(LocaleLoader.getString("Commands.Skill.Leaderboard", skill.getName()))); + sender.sendMessage(ChatColor.stripColor(LocaleLoader.getString("Commands.Skill.Leaderboard", skill.getName())).replaceAll("\\033\\[m", "")); } int place = (page * 10) - 9; @@ -70,7 +70,7 @@ public class MctopCommandDisplayTask extends BukkitRunnable { // 01. Playername - skill value // 12. Playername - skill value sender.sendMessage(String.format("%2d. %s%s - %s%s", place, sender instanceof Player ? ChatColor.GREEN : "", - stat.name, sender instanceof Player ? ChatColor.WHITE : "", stat.statVal)); + stat.name, sender instanceof Player ? ChatColor.WHITE : "", stat.statVal).replaceAll("\\033\\[m", "")); place++; } } diff --git a/src/main/java/com/gmail/nossr50/runnables/party/PartyChatTask.java b/src/main/java/com/gmail/nossr50/runnables/party/PartyChatTask.java index ff4b4999f..6d2c3a7af 100644 --- a/src/main/java/com/gmail/nossr50/runnables/party/PartyChatTask.java +++ b/src/main/java/com/gmail/nossr50/runnables/party/PartyChatTask.java @@ -45,6 +45,6 @@ public class PartyChatTask extends BukkitRunnable { } } - plugin.getServer().getConsoleSender().sendMessage(ChatColor.stripColor("[mcMMO] [P]<" + party.getName() + ">" + message)); + plugin.getServer().getConsoleSender().sendMessage(ChatColor.stripColor("[mcMMO] [P]<" + party.getName() + ">" + message).replaceAll("\\033\\[m", "")); } } From 2dd1775d9af94adc466223161946e4e048edac79 Mon Sep 17 00:00:00 2001 From: JamieSinn Date: Fri, 11 Dec 2015 23:52:14 -0500 Subject: [PATCH 3/5] Remove regex replace, does nothing --- .../nossr50/runnables/commands/MctopCommandDisplayTask.java | 6 +++--- .../com/gmail/nossr50/runnables/party/PartyChatTask.java | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/main/java/com/gmail/nossr50/runnables/commands/MctopCommandDisplayTask.java b/src/main/java/com/gmail/nossr50/runnables/commands/MctopCommandDisplayTask.java index 5c2c571fe..3f8d1cc10 100644 --- a/src/main/java/com/gmail/nossr50/runnables/commands/MctopCommandDisplayTask.java +++ b/src/main/java/com/gmail/nossr50/runnables/commands/MctopCommandDisplayTask.java @@ -54,13 +54,13 @@ public class MctopCommandDisplayTask extends BukkitRunnable { if(sender instanceof Player) sender.sendMessage(LocaleLoader.getString("Commands.PowerLevel.Leaderboard")); else - sender.sendMessage(ChatColor.stripColor(LocaleLoader.getString("Commands.PowerLevel.Leaderboard")).replaceAll("\\033\\[m", "")); + sender.sendMessage(ChatColor.stripColor(LocaleLoader.getString("Commands.PowerLevel.Leaderboard"))); } else { if(sender instanceof Player) sender.sendMessage(LocaleLoader.getString("Commands.Skill.Leaderboard", skill.getName())); else - sender.sendMessage(ChatColor.stripColor(LocaleLoader.getString("Commands.Skill.Leaderboard", skill.getName())).replaceAll("\\033\\[m", "")); + sender.sendMessage(ChatColor.stripColor(LocaleLoader.getString("Commands.Skill.Leaderboard", skill.getName()))); } int place = (page * 10) - 9; @@ -70,7 +70,7 @@ public class MctopCommandDisplayTask extends BukkitRunnable { // 01. Playername - skill value // 12. Playername - skill value sender.sendMessage(String.format("%2d. %s%s - %s%s", place, sender instanceof Player ? ChatColor.GREEN : "", - stat.name, sender instanceof Player ? ChatColor.WHITE : "", stat.statVal).replaceAll("\\033\\[m", "")); + stat.name, sender instanceof Player ? ChatColor.WHITE : "", stat.statVal)); place++; } } diff --git a/src/main/java/com/gmail/nossr50/runnables/party/PartyChatTask.java b/src/main/java/com/gmail/nossr50/runnables/party/PartyChatTask.java index 6d2c3a7af..ff4b4999f 100644 --- a/src/main/java/com/gmail/nossr50/runnables/party/PartyChatTask.java +++ b/src/main/java/com/gmail/nossr50/runnables/party/PartyChatTask.java @@ -45,6 +45,6 @@ public class PartyChatTask extends BukkitRunnable { } } - plugin.getServer().getConsoleSender().sendMessage(ChatColor.stripColor("[mcMMO] [P]<" + party.getName() + ">" + message).replaceAll("\\033\\[m", "")); + plugin.getServer().getConsoleSender().sendMessage(ChatColor.stripColor("[mcMMO] [P]<" + party.getName() + ">" + message)); } } From 3a9c55a9eabb386813ac60d5d387095450f59e4e Mon Sep 17 00:00:00 2001 From: JamieSinn Date: Sat, 12 Dec 2015 00:04:23 -0500 Subject: [PATCH 4/5] Remove ternary operators and use if/else --- .../runnables/commands/MctopCommandDisplayTask.java | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/gmail/nossr50/runnables/commands/MctopCommandDisplayTask.java b/src/main/java/com/gmail/nossr50/runnables/commands/MctopCommandDisplayTask.java index 3f8d1cc10..cf3547cf2 100644 --- a/src/main/java/com/gmail/nossr50/runnables/commands/MctopCommandDisplayTask.java +++ b/src/main/java/com/gmail/nossr50/runnables/commands/MctopCommandDisplayTask.java @@ -69,8 +69,11 @@ public class MctopCommandDisplayTask extends BukkitRunnable { // Format: // 01. Playername - skill value // 12. Playername - skill value - sender.sendMessage(String.format("%2d. %s%s - %s%s", place, sender instanceof Player ? ChatColor.GREEN : "", - stat.name, sender instanceof Player ? ChatColor.WHITE : "", stat.statVal)); + if(sender instanceof Player) + sender.sendMessage(String.format("%2d. %s%s - %s%s", place, ChatColor.GREEN, stat.name, ChatColor.WHITE, stat.statVal)); + else + sender.sendMessage(String.format("%2d. %s - %s", place, stat.name, stat.statVal)); + place++; } } From 0e34202d4d9f417bca4e2a7fc786276c6a10d2eb Mon Sep 17 00:00:00 2001 From: Jamie Sinn Date: Sun, 20 Dec 2015 23:05:48 -0500 Subject: [PATCH 5/5] Curly braces as toothpick requested @andrewkm --- .../commands/MctopCommandDisplayTask.java | 20 ++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/src/main/java/com/gmail/nossr50/runnables/commands/MctopCommandDisplayTask.java b/src/main/java/com/gmail/nossr50/runnables/commands/MctopCommandDisplayTask.java index cf3547cf2..f1c9ffc7a 100644 --- a/src/main/java/com/gmail/nossr50/runnables/commands/MctopCommandDisplayTask.java +++ b/src/main/java/com/gmail/nossr50/runnables/commands/MctopCommandDisplayTask.java @@ -51,16 +51,20 @@ public class MctopCommandDisplayTask extends BukkitRunnable { private void displayChat() { if (skill == null) { - if(sender instanceof Player) + if(sender instanceof Player) { sender.sendMessage(LocaleLoader.getString("Commands.PowerLevel.Leaderboard")); - else + } + else { sender.sendMessage(ChatColor.stripColor(LocaleLoader.getString("Commands.PowerLevel.Leaderboard"))); + } } else { - if(sender instanceof Player) + if(sender instanceof Player) { sender.sendMessage(LocaleLoader.getString("Commands.Skill.Leaderboard", skill.getName())); - else + } + else { sender.sendMessage(ChatColor.stripColor(LocaleLoader.getString("Commands.Skill.Leaderboard", skill.getName()))); + } } int place = (page * 10) - 9; @@ -69,11 +73,13 @@ public class MctopCommandDisplayTask extends BukkitRunnable { // Format: // 01. Playername - skill value // 12. Playername - skill value - if(sender instanceof Player) + if(sender instanceof Player) { sender.sendMessage(String.format("%2d. %s%s - %s%s", place, ChatColor.GREEN, stat.name, ChatColor.WHITE, stat.statVal)); - else + } + else { sender.sendMessage(String.format("%2d. %s - %s", place, stat.name, stat.statVal)); - + } + place++; } }