implement lobby check

This commit is contained in:
Hiajen Hiajen 2021-06-20 17:10:47 +02:00
parent 2577a71ca7
commit 1a9a9aea42
4 changed files with 83 additions and 4 deletions

View file

@ -25,6 +25,7 @@ public final class EaaMod implements ClientModInitializer {
new EchoCommand(); new EchoCommand();
new TagCommand(); new TagCommand();
new CheckPlayerCommand(); new CheckPlayerCommand();
new CheckLobbyCommand();
} }
} }

View file

@ -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<String, DB_Tag> player_tags = new HashMap<>();
public static final SimpleDateFormat dateformat = new SimpleDateFormat("dd.MM.yyyy");
@Override
public int run(CommandContext<FabricClientCommandSource> context) {
FabricClientCommandSource source = context.getSource();
try {
List<String> 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<FabricClientCommandSource> getCommandSpecification() {
return literal("/lobby").executes(this);
}
}

View file

@ -70,15 +70,21 @@ 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); 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; return;
}
List<DB_Tag> tag = DB_Tag.getTagsFromPlayer(db_player); List<DB_Tag> tag = DB_Tag.getTagsFromPlayer(db_player);
if (tag.size() > 0) if (tag.size() > 0)
player_tags.put(uuid, tag.get(0)); player_tags.put(uuid, tag.get(tag.size()-1));
} }
} }
public static Map<String, DB_Tag> getHashMap(){
return player_tags;
}
public static DB_Tag.Type getScoreboardTag(String uuid){ public static DB_Tag.Type getScoreboardTag(String uuid){
loadPlayer(uuid, false); loadPlayer(uuid, false);
if (player_tags.containsKey(uuid)) if (player_tags.containsKey(uuid))

View file

@ -100,11 +100,11 @@ public class DB_Tag {
), FRIENDLY( ), FRIENDLY(
"FND", "Player you like", PingColors.COLOR_START "FND", "Player you like", PingColors.COLOR_START
), GOODPLAYER( ), GOODPLAYER(
"PRO", "Fair player with good skill", PingColors.COLOR_START "PRO", "Fair player with good skill", 0x3aaa80
), IDIOT( ), IDIOT(
"BAD", "Person who is annoying and bad", PingColors.COLOR_MID "BAD", "Person who is annoying and bad", PingColors.COLOR_MID
), NOTTAGGED( ), NOTTAGGED(
"NaN", "Player is not tagged", PingColors.COLOR_GREY "NaN", "Player is not tagged", 0xbababa
); );
String tag, description; String tag, description;