From 1a9a9aea42ad1293f3a983474547809860124762 Mon Sep 17 00:00:00 2001 From: "Ansgar [Hiajen]" Date: Sun, 20 Jun 2021 17:10:47 +0200 Subject: [PATCH] implement lobby check --- src/main/java/net/saltymc/eaa/EaaMod.java | 1 + .../eaa/commands/CheckLobbyCommand.java | 72 +++++++++++++++++++ .../net/saltymc/eaa/commands/TagCommand.java | 10 ++- .../net/saltymc/eaa/util/database/DB_Tag.java | 4 +- 4 files changed, 83 insertions(+), 4 deletions(-) create mode 100644 src/main/java/net/saltymc/eaa/commands/CheckLobbyCommand.java diff --git a/src/main/java/net/saltymc/eaa/EaaMod.java b/src/main/java/net/saltymc/eaa/EaaMod.java index 2062d86..ac67067 100644 --- a/src/main/java/net/saltymc/eaa/EaaMod.java +++ b/src/main/java/net/saltymc/eaa/EaaMod.java @@ -25,6 +25,7 @@ public final class EaaMod implements ClientModInitializer { new EchoCommand(); new TagCommand(); new CheckPlayerCommand(); + new CheckLobbyCommand(); } } diff --git a/src/main/java/net/saltymc/eaa/commands/CheckLobbyCommand.java b/src/main/java/net/saltymc/eaa/commands/CheckLobbyCommand.java new file mode 100644 index 0000000..77eaefb --- /dev/null +++ b/src/main/java/net/saltymc/eaa/commands/CheckLobbyCommand.java @@ -0,0 +1,72 @@ +package net.saltymc.eaa.commands; + +import com.mojang.brigadier.arguments.StringArgumentType; +import com.mojang.brigadier.builder.LiteralArgumentBuilder; +import com.mojang.brigadier.context.CommandContext; +import net.fabricmc.fabric.api.client.command.v1.FabricClientCommandSource; +import net.minecraft.client.MinecraftClient; +import net.minecraft.client.toast.SystemToast; +import net.minecraft.command.argument.EntityArgumentType; +import net.minecraft.text.Text; +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.*; +import java.util.stream.Collectors; + +import static net.fabricmc.fabric.api.client.command.v1.ClientCommandManager.argument; +import static net.fabricmc.fabric.api.client.command.v1.ClientCommandManager.literal; + +public class CheckLobbyCommand extends EaaModCommand{ + + private static final Map player_tags = new HashMap<>(); + public static final SimpleDateFormat dateformat = new SimpleDateFormat("dd.MM.yyyy"); + + @Override + public int run(CommandContext context) { + FabricClientCommandSource source = context.getSource(); + + try { + List uuids = new ArrayList<>(); + MinecraftClient.getInstance().getNetworkHandler().getPlayerList().forEach(x -> uuids.add(x.getProfile().getId().toString())); + + int dangerLvl = 0; // 0 = nothing; 1 = idiot; 2 = hacker + + for (String uuid: uuids){ + TagCommand.loadPlayer(uuid, false); + if (TagCommand.getHashMap().containsKey(uuid)){ + DB_Tag.Type type = TagCommand.getHashMap().get(uuid).getType(); + if (type == DB_Tag.Type.HACKER){ + dangerLvl = 2; + break; + } else if (type == DB_Tag.Type.IDIOT){ + dangerLvl = 1; + } + } + } + + switch (dangerLvl){ + case 0: + SystemToast.add(source.getClient().getToastManager(), SystemToast.Type.WORLD_BACKUP, Text.of("OKAY!"), Text.of("No Hackers found")); + break; + case 1: + SystemToast.add(source.getClient().getToastManager(), SystemToast.Type.TUTORIAL_HINT, Text.of("MEH!"), Text.of("There is an Idiot!")); + break; + case 2: + SystemToast.add(source.getClient().getToastManager(), SystemToast.Type.WORLD_ACCESS_FAILURE, Text.of("ALARM!"), Text.of("There is a Hacker!")); + } + + } catch (Exception e) { + source.sendFeedback(Text.of(e.toString())); + } + + return 1; + } + + @Override + public LiteralArgumentBuilder getCommandSpecification() { + return literal("/lobby").executes(this); + } +} diff --git a/src/main/java/net/saltymc/eaa/commands/TagCommand.java b/src/main/java/net/saltymc/eaa/commands/TagCommand.java index 16a9297..de6c7ed 100644 --- a/src/main/java/net/saltymc/eaa/commands/TagCommand.java +++ b/src/main/java/net/saltymc/eaa/commands/TagCommand.java @@ -70,15 +70,21 @@ 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) + 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(0)); + player_tags.put(uuid, tag.get(tag.size()-1)); } } + public static Map getHashMap(){ + return player_tags; + } + public static DB_Tag.Type getScoreboardTag(String uuid){ loadPlayer(uuid, false); if (player_tags.containsKey(uuid)) 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 78ca175..ce8556b 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 @@ -100,11 +100,11 @@ public class DB_Tag { ), FRIENDLY( "FND", "Player you like", PingColors.COLOR_START ), GOODPLAYER( - "PRO", "Fair player with good skill", PingColors.COLOR_START + "PRO", "Fair player with good skill", 0x3aaa80 ), IDIOT( "BAD", "Person who is annoying and bad", PingColors.COLOR_MID ), NOTTAGGED( - "NaN", "Player is not tagged", PingColors.COLOR_GREY + "NaN", "Player is not tagged", 0xbababa ); String tag, description;