Archived
0

Fixed duplicate entry if username and display name is the same.

This commit is contained in:
Minenash
2018-12-13 18:51:59 -05:00
parent ee4c8dd48f
commit b2d82f8a14

View File

@@ -56,12 +56,7 @@ public class Mentio implements Module, Listener
Player player = (Player) sender; Player player = (Player) sender;
UUID uuid = player.getUniqueId(); UUID uuid = player.getUniqueId();
JSONArray playerMentios = (JSONArray) mentios.get(uuid.toString()); JSONArray playerMentios = (JSONArray) mentios.get(uuid.toString());
if (playerMentios == null) playerMentios = defaultMentio(playerMentios, player);
{
playerMentios = new JSONArray();
playerMentios.add(player.getName());
playerMentios.add(player.getDisplayName().split(" ")[0].replaceAll("§[0-9a-fk-o]", ""));
}
if (playerMentios.contains(trigger)) if (playerMentios.contains(trigger))
getLogger().message(sender, true, "You already had that as a mentio!"); getLogger().message(sender, true, "You already had that as a mentio!");
else else
@@ -81,12 +76,7 @@ public class Mentio implements Module, Listener
Player player = (Player) sender; Player player = (Player) sender;
UUID uuid = player.getUniqueId(); UUID uuid = player.getUniqueId();
JSONArray playerMentios = (JSONArray) mentios.get(uuid.toString()); JSONArray playerMentios = (JSONArray) mentios.get(uuid.toString());
if (playerMentios == null) playerMentios = defaultMentio(playerMentios, player);
{
playerMentios = new JSONArray();
playerMentios.add(player.getName());
playerMentios.add(player.getDisplayName().split(" ")[0].replaceAll("§[0-9a-fk-o]", ""));
}
if (!playerMentios.remove(trigger)) if (!playerMentios.remove(trigger))
getLogger().message(sender, true, "You didn't have that as a mentio!"); getLogger().message(sender, true, "You didn't have that as a mentio!");
else else
@@ -98,7 +88,6 @@ public class Mentio implements Module, Listener
return true; return true;
} }
@SuppressWarnings("unchecked")
@Command(hook = "listmentios") @Command(hook = "listmentios")
public boolean listMentios(CommandSender sender) public boolean listMentios(CommandSender sender)
{ {
@@ -106,12 +95,7 @@ public class Mentio implements Module, Listener
Player player = (Player) sender; Player player = (Player) sender;
UUID uuid = player.getUniqueId(); UUID uuid = player.getUniqueId();
JSONArray playerMentios = (JSONArray) mentios.get(uuid.toString()); JSONArray playerMentios = (JSONArray) mentios.get(uuid.toString());
if (playerMentios == null) playerMentios = defaultMentio(playerMentios, player);
{
playerMentios = new JSONArray();
playerMentios.add(player.getName());
playerMentios.add(player.getDisplayName().split(" ")[0].replaceAll("§[0-9a-fk-or]", ""));
}
for (Object raw : playerMentios) for (Object raw : playerMentios)
{ {
String mentio = (String) raw; String mentio = (String) raw;
@@ -122,6 +106,19 @@ public class Mentio implements Module, Listener
} }
@SuppressWarnings("unchecked") @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) @EventHandler(priority = EventPriority.HIGHEST)
public void onPlayerChat(AsyncPlayerChatEvent event) public void onPlayerChat(AsyncPlayerChatEvent event)
{ {
@@ -133,12 +130,7 @@ public class Mentio implements Module, Listener
return; return;
UUID uuid = player.getUniqueId(); UUID uuid = player.getUniqueId();
JSONArray playerMentios = (JSONArray) mentios.get(uuid.toString()); JSONArray playerMentios = (JSONArray) mentios.get(uuid.toString());
if (playerMentios == null) playerMentios = defaultMentio(playerMentios, player);
{
playerMentios = new JSONArray();
playerMentios.add(player.getName());
playerMentios.add(player.getDisplayName().split(" ")[0].replaceAll("§[0-9a-fk-o]", ""));
}
for (Object raw : playerMentios) for (Object raw : playerMentios)
{ {
String mentio = (String) raw; String mentio = (String) raw;