diff options
author | Minenash <minenash@protonmail.com> | 2018-12-13 18:51:59 -0500 |
---|---|---|
committer | Minenash <minenash@protonmail.com> | 2018-12-13 18:51:59 -0500 |
commit | b2d82f8a143a0ce61b495a65c38dd7446e7712d1 (patch) | |
tree | 95bb4ae530e6a163e65524016d2a75c4e511e755 /src/main/java/com/redstoner/modules/mentio | |
parent | ee4c8dd48fe8372020a84d0ec8153927dfea3639 (diff) |
Fixed duplicate entry if username and display name is the same.
Diffstat (limited to 'src/main/java/com/redstoner/modules/mentio')
-rw-r--r-- | src/main/java/com/redstoner/modules/mentio/Mentio.java | 42 |
1 files changed, 17 insertions, 25 deletions
diff --git a/src/main/java/com/redstoner/modules/mentio/Mentio.java b/src/main/java/com/redstoner/modules/mentio/Mentio.java index 3db8edf..0e282cd 100644 --- a/src/main/java/com/redstoner/modules/mentio/Mentio.java +++ b/src/main/java/com/redstoner/modules/mentio/Mentio.java @@ -56,12 +56,7 @@ public class Mentio implements Module, Listener Player player = (Player) sender; UUID uuid = player.getUniqueId(); JSONArray playerMentios = (JSONArray) mentios.get(uuid.toString()); - if (playerMentios == null) - { - playerMentios = new JSONArray(); - playerMentios.add(player.getName()); - playerMentios.add(player.getDisplayName().split(" ")[0].replaceAll("§[0-9a-fk-o]", "")); - } + playerMentios = defaultMentio(playerMentios, player); if (playerMentios.contains(trigger)) getLogger().message(sender, true, "You already had that as a mentio!"); else @@ -81,12 +76,7 @@ public class Mentio implements Module, Listener Player player = (Player) sender; UUID uuid = player.getUniqueId(); JSONArray playerMentios = (JSONArray) mentios.get(uuid.toString()); - if (playerMentios == null) - { - playerMentios = new JSONArray(); - playerMentios.add(player.getName()); - playerMentios.add(player.getDisplayName().split(" ")[0].replaceAll("§[0-9a-fk-o]", "")); - } + playerMentios = defaultMentio(playerMentios, player); if (!playerMentios.remove(trigger)) getLogger().message(sender, true, "You didn't have that as a mentio!"); else @@ -98,7 +88,6 @@ public class Mentio implements Module, Listener return true; } - @SuppressWarnings("unchecked") @Command(hook = "listmentios") public boolean listMentios(CommandSender sender) { @@ -106,12 +95,7 @@ public class Mentio implements Module, Listener Player player = (Player) sender; UUID uuid = player.getUniqueId(); JSONArray playerMentios = (JSONArray) mentios.get(uuid.toString()); - if (playerMentios == null) - { - playerMentios = new JSONArray(); - playerMentios.add(player.getName()); - playerMentios.add(player.getDisplayName().split(" ")[0].replaceAll("§[0-9a-fk-or]", "")); - } + playerMentios = defaultMentio(playerMentios, player); for (Object raw : playerMentios) { String mentio = (String) raw; @@ -122,6 +106,19 @@ public class Mentio implements Module, Listener } @SuppressWarnings("unchecked") + private JSONArray defaultMentio(JSONArray mentios, Player player) { + if (mentios == null) + { + mentios = new JSONArray(); + mentios.add(player.getName()); + + String displayName = player.getDisplayName().split(" ")[0].replaceAll("§[0-9a-fk-or]", ""); + if (!player.getName().equals(displayName)) + mentios.add(displayName); + } + return mentios; + } + @EventHandler(priority = EventPriority.HIGHEST) public void onPlayerChat(AsyncPlayerChatEvent event) { @@ -133,12 +130,7 @@ public class Mentio implements Module, Listener return; UUID uuid = player.getUniqueId(); JSONArray playerMentios = (JSONArray) mentios.get(uuid.toString()); - if (playerMentios == null) - { - playerMentios = new JSONArray(); - playerMentios.add(player.getName()); - playerMentios.add(player.getDisplayName().split(" ")[0].replaceAll("§[0-9a-fk-o]", "")); - } + playerMentios = defaultMentio(playerMentios, player); for (Object raw : playerMentios) { String mentio = (String) raw; |