some performance shit #2 and loading non present players, Refactoring project
This commit is contained in:
parent
8fea7f4701
commit
9af6f4c073
12 changed files with 339 additions and 200 deletions
82
src/main/java/net/saltymc/eaa/function/CheckFunction.java
Normal file
82
src/main/java/net/saltymc/eaa/function/CheckFunction.java
Normal file
|
@ -0,0 +1,82 @@
|
|||
package net.saltymc.eaa.function;
|
||||
|
||||
import net.fabricmc.fabric.api.client.command.v1.FabricClientCommandSource;
|
||||
import net.minecraft.client.MinecraftClient;
|
||||
import net.minecraft.client.toast.SystemToast;
|
||||
import net.minecraft.text.LiteralText;
|
||||
import net.minecraft.text.Text;
|
||||
import net.minecraft.util.Formatting;
|
||||
import net.saltymc.eaa.util.database.DB_Player;
|
||||
import net.saltymc.eaa.util.database.DB_Tag;
|
||||
import net.saltymc.eaa.util.mojangApi.PlayerInfo;
|
||||
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.List;
|
||||
import java.util.ListIterator;
|
||||
|
||||
public class CheckFunction {
|
||||
|
||||
public static final SimpleDateFormat dateformat = new SimpleDateFormat("dd.MM.yyyy");
|
||||
|
||||
public static void checkPlayer(String player, FabricClientCommandSource source){
|
||||
new Thread(new Check(player, source)).start();
|
||||
}
|
||||
|
||||
private static class Check implements Runnable {
|
||||
|
||||
String player;
|
||||
FabricClientCommandSource source;
|
||||
|
||||
public Check(String player, FabricClientCommandSource source) {
|
||||
this.player = player;
|
||||
this.source = source;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
String playerUUID = PlayerInfo.playerNameToUUID(player);
|
||||
|
||||
if (playerUUID == null){
|
||||
SystemToast.add(MinecraftClient.getInstance().getToastManager(), SystemToast.Type.WORLD_ACCESS_FAILURE,
|
||||
Text.of("ERROR!"), Text.of("Player does not exist"));
|
||||
return;
|
||||
}
|
||||
|
||||
TagFunction.loadPlayer(playerUUID, true);
|
||||
|
||||
List<String> names = PlayerInfo.playerUUIDToNames(playerUUID);
|
||||
for (int i = 1; i <= names.size(); i++)
|
||||
source.sendFeedback(Text.of(i + ". " + names.get(i-1)));
|
||||
|
||||
List<DB_Tag> tags = DB_Tag.getTagsFromPlayer(DB_Player.getPlayer(playerUUID));
|
||||
if (tags.size() > 0) {
|
||||
ListIterator<DB_Tag> it = tags.listIterator(tags.size());
|
||||
while (it.hasPrevious()) {
|
||||
DB_Tag curr = it.previous();
|
||||
|
||||
source.sendFeedback(new LiteralText(dateformat.format(curr.getTagDate())).formatted(Formatting.GRAY)
|
||||
.append(new LiteralText(" | "))
|
||||
.append(new LiteralText(curr.getType().getTag()).formatted(curr.getType().getFormatting()))
|
||||
.append(new LiteralText(" (" + curr.getGrade() + ") ").formatted(getScaleFormat(curr.getGrade())))
|
||||
);
|
||||
}
|
||||
} else {
|
||||
source.sendFeedback(Text.of("No Tags Set!"));
|
||||
}
|
||||
|
||||
} catch (Exception e) {
|
||||
source.sendFeedback(Text.of(e.toString()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static Formatting getScaleFormat(int grade){
|
||||
if (grade <= 5)
|
||||
return Formatting.WHITE;
|
||||
else if (grade < 9)
|
||||
return Formatting.DARK_AQUA;
|
||||
else
|
||||
return Formatting.BLUE;
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue