some performance shit
This commit is contained in:
parent
00bfe748cc
commit
8fea7f4701
2 changed files with 39 additions and 20 deletions
|
@ -23,6 +23,7 @@ import static net.fabricmc.fabric.api.client.command.v1.ClientCommandManager.lit
|
||||||
public class TagCommand extends EaaModCommand{
|
public class TagCommand extends EaaModCommand{
|
||||||
|
|
||||||
private static final Map<String, DB_Tag> player_tags = new HashMap<>();
|
private static final Map<String, DB_Tag> player_tags = new HashMap<>();
|
||||||
|
private static volatile boolean free = true;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int run(CommandContext<FabricClientCommandSource> context) {
|
public int run(CommandContext<FabricClientCommandSource> context) {
|
||||||
|
@ -68,16 +69,8 @@ public class TagCommand extends EaaModCommand{
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void loadPlayer(String uuid, boolean reload){
|
public static void loadPlayer(String uuid, boolean reload){
|
||||||
if (!player_tags.containsKey(uuid) || reload){
|
if ( (!player_tags.containsKey(uuid) || reload)) {
|
||||||
DB_Player db_player = DB_Player.getPlayer(uuid);
|
new Thread(new LoadTag(uuid)).start();
|
||||||
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));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -86,11 +79,15 @@ public class TagCommand extends EaaModCommand{
|
||||||
}
|
}
|
||||||
|
|
||||||
public static DB_Tag.Type getScoreboardTag(String uuid){
|
public static DB_Tag.Type getScoreboardTag(String uuid){
|
||||||
loadPlayer(uuid, false);
|
|
||||||
if (player_tags.containsKey(uuid))
|
if (player_tags.containsKey(uuid))
|
||||||
return player_tags.get(uuid).getType();
|
return player_tags.get(uuid).getType();
|
||||||
else
|
else {
|
||||||
return DB_Tag.Type.NOTTAGGED;
|
if (free) {
|
||||||
|
free = false;
|
||||||
|
loadPlayer(uuid, false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return DB_Tag.Type.NOTLOADED;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static class CustomText {
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,7 +1,5 @@
|
||||||
package net.saltymc.eaa.util.database;
|
package net.saltymc.eaa.util.database;
|
||||||
|
|
||||||
import net.saltymc.eaa.custom.ping.PingColors;
|
|
||||||
|
|
||||||
import java.sql.PreparedStatement;
|
import java.sql.PreparedStatement;
|
||||||
import java.sql.ResultSet;
|
import java.sql.ResultSet;
|
||||||
import java.sql.SQLException;
|
import java.sql.SQLException;
|
||||||
|
@ -96,15 +94,17 @@ public class DB_Tag {
|
||||||
|
|
||||||
public enum Type {
|
public enum Type {
|
||||||
HACKER(
|
HACKER(
|
||||||
"HAX", "PLayer who hacks", PingColors.COLOR_END
|
"HAX", "PLayer who hacks", 0xaa0000
|
||||||
), FRIENDLY(
|
), FRIENDLY(
|
||||||
"FND", "Player you like", PingColors.COLOR_START
|
"FND", "Player you like", 0x55ff55
|
||||||
), GOODPLAYER(
|
), GOODPLAYER(
|
||||||
"PRO", "Fair player with good skill", 0x3aaa80
|
"PRO", "Fair player with good skill", 0xffaa00
|
||||||
), IDIOT(
|
), IDIOT(
|
||||||
"BAD", "Person who is annoying and bad", PingColors.COLOR_MID
|
"BAD", "Person who is annoying and bad", 0x55ffff
|
||||||
), NOTTAGGED(
|
), NOTTAGGED(
|
||||||
"NaN", "Player is not tagged", 0xbababa
|
"NaN", "Player is not tagged", 0x555555
|
||||||
|
), NOTLOADED(
|
||||||
|
"---", "PLayer not loaded", 0xffffff
|
||||||
);
|
);
|
||||||
|
|
||||||
String tag, description;
|
String tag, description;
|
||||||
|
|
Loading…
Reference in a new issue