85 lines
3.1 KiB
Java
85 lines
3.1 KiB
Java
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.Style;
|
|
import net.minecraft.text.Text;
|
|
import net.minecraft.text.TextColor;
|
|
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()).setStyle(Style.EMPTY.withColor(TextColor.fromRgb(curr.getType().getColor()))))
|
|
.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()));
|
|
}
|
|
}
|
|
}
|
|
|
|
public static Formatting getScaleFormat(int grade){
|
|
if (grade <= 5)
|
|
return Formatting.WHITE;
|
|
else if (grade < 9)
|
|
return Formatting.DARK_AQUA;
|
|
else
|
|
return Formatting.BLUE;
|
|
}
|
|
}
|