From 8fea7f47011b7085ff57e28c179493cb338163cb Mon Sep 17 00:00:00 2001 From: "Ansgar [Hiajen]" Date: Sun, 20 Jun 2021 22:29:57 +0200 Subject: [PATCH] some performance shit --- .../net/saltymc/eaa/commands/TagCommand.java | 45 +++++++++++++------ .../net/saltymc/eaa/util/database/DB_Tag.java | 14 +++--- 2 files changed, 39 insertions(+), 20 deletions(-) diff --git a/src/main/java/net/saltymc/eaa/commands/TagCommand.java b/src/main/java/net/saltymc/eaa/commands/TagCommand.java index de6c7ed..d9d9df2 100644 --- a/src/main/java/net/saltymc/eaa/commands/TagCommand.java +++ b/src/main/java/net/saltymc/eaa/commands/TagCommand.java @@ -23,6 +23,7 @@ import static net.fabricmc.fabric.api.client.command.v1.ClientCommandManager.lit public class TagCommand extends EaaModCommand{ private static final Map player_tags = new HashMap<>(); + private static volatile boolean free = true; @Override public int run(CommandContext context) { @@ -68,16 +69,8 @@ public class TagCommand extends EaaModCommand{ } public static void loadPlayer(String uuid, boolean reload){ - if (!player_tags.containsKey(uuid) || reload){ - DB_Player db_player = DB_Player.getPlayer(uuid); - if (db_player == null) { - player_tags.put(uuid, new DB_Tag(null, DB_Tag.Type.NOTTAGGED, 0)); - return; - } - - List tag = DB_Tag.getTagsFromPlayer(db_player); - if (tag.size() > 0) - player_tags.put(uuid, tag.get(tag.size()-1)); + if ( (!player_tags.containsKey(uuid) || reload)) { + new Thread(new LoadTag(uuid)).start(); } } @@ -86,11 +79,15 @@ public class TagCommand extends EaaModCommand{ } public static DB_Tag.Type getScoreboardTag(String uuid){ - loadPlayer(uuid, false); if (player_tags.containsKey(uuid)) return player_tags.get(uuid).getType(); - else - return DB_Tag.Type.NOTTAGGED; + else { + if (free) { + free = false; + loadPlayer(uuid, false); + } + } + return DB_Tag.Type.NOTLOADED; } public static class CustomText { @@ -111,4 +108,26 @@ public class TagCommand extends EaaModCommand{ } } + private static class LoadTag implements Runnable{ + + String uuid; + + public LoadTag(String uuid){ + this.uuid = uuid; + } + + @Override + public void run() { + DB_Player db_player = DB_Player.getPlayer(uuid); + if (db_player == null) { + player_tags.put(uuid, new DB_Tag(null, DB_Tag.Type.NOTTAGGED, 0)); + } else { + List tag = DB_Tag.getTagsFromPlayer(db_player); + if (tag.size() > 0) + player_tags.put(uuid, tag.get(tag.size() - 1)); + } + + free = true; + } + } } diff --git a/src/main/java/net/saltymc/eaa/util/database/DB_Tag.java b/src/main/java/net/saltymc/eaa/util/database/DB_Tag.java index ce8556b..8270b97 100644 --- a/src/main/java/net/saltymc/eaa/util/database/DB_Tag.java +++ b/src/main/java/net/saltymc/eaa/util/database/DB_Tag.java @@ -1,7 +1,5 @@ package net.saltymc.eaa.util.database; -import net.saltymc.eaa.custom.ping.PingColors; - import java.sql.PreparedStatement; import java.sql.ResultSet; import java.sql.SQLException; @@ -96,15 +94,17 @@ public class DB_Tag { public enum Type { HACKER( - "HAX", "PLayer who hacks", PingColors.COLOR_END + "HAX", "PLayer who hacks", 0xaa0000 ), FRIENDLY( - "FND", "Player you like", PingColors.COLOR_START + "FND", "Player you like", 0x55ff55 ), GOODPLAYER( - "PRO", "Fair player with good skill", 0x3aaa80 + "PRO", "Fair player with good skill", 0xffaa00 ), IDIOT( - "BAD", "Person who is annoying and bad", PingColors.COLOR_MID + "BAD", "Person who is annoying and bad", 0x55ffff ), NOTTAGGED( - "NaN", "Player is not tagged", 0xbababa + "NaN", "Player is not tagged", 0x555555 + ), NOTLOADED( + "---", "PLayer not loaded", 0xffffff ); String tag, description;