some performance shit

This commit is contained in:
Hiajen Hiajen 2021-06-20 22:29:57 +02:00
parent 00bfe748cc
commit 8fea7f4701
2 changed files with 39 additions and 20 deletions

View File

@ -23,6 +23,7 @@ import static net.fabricmc.fabric.api.client.command.v1.ClientCommandManager.lit
public class TagCommand extends EaaModCommand{
private static final Map<String, DB_Tag> player_tags = new HashMap<>();
private static volatile boolean free = true;
@Override
public int run(CommandContext<FabricClientCommandSource> 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<DB_Tag> 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<DB_Tag> tag = DB_Tag.getTagsFromPlayer(db_player);
if (tag.size() > 0)
player_tags.put(uuid, tag.get(tag.size() - 1));
}
free = true;
}
}
}

View File

@ -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;