diff --git a/src/de/steamwar/bungeecore/listeners/mods/Fabric.java b/src/de/steamwar/bungeecore/listeners/mods/Fabric.java index 825d80e..7973fd1 100644 --- a/src/de/steamwar/bungeecore/listeners/mods/Fabric.java +++ b/src/de/steamwar/bungeecore/listeners/mods/Fabric.java @@ -19,7 +19,10 @@ package de.steamwar.bungeecore.listeners.mods; -import com.google.gson.*; +import com.google.gson.JsonArray; +import com.google.gson.JsonElement; +import com.google.gson.JsonParser; +import com.google.gson.JsonSyntaxException; import de.steamwar.bungeecore.BungeeCore; import de.steamwar.bungeecore.Message; import de.steamwar.bungeecore.Storage; @@ -27,8 +30,10 @@ import de.steamwar.bungeecore.listeners.BasicListener; import de.steamwar.bungeecore.sql.Mod; import de.steamwar.bungeecore.sql.Punishment; import de.steamwar.bungeecore.sql.SteamwarUser; +import net.md_5.bungee.BungeeCord; import net.md_5.bungee.api.connection.ProxiedPlayer; import net.md_5.bungee.api.event.PluginMessageEvent; +import net.md_5.bungee.api.event.ServerSwitchEvent; import net.md_5.bungee.event.EventHandler; import java.nio.charset.StandardCharsets; @@ -36,6 +41,7 @@ import java.nio.charset.UnsupportedCharsetException; import java.sql.Timestamp; import java.time.Instant; import java.util.*; +import java.util.concurrent.TimeUnit; import java.util.logging.Level; public class Fabric extends BasicListener { @@ -43,12 +49,22 @@ public class Fabric extends BasicListener { private final Set neededMods = new HashSet<>(); public static final Map checkedPlayers = new HashMap<>(); + public static final Map expectPluginMessage = new HashMap<>(); { neededMods.add("java"); neededMods.add("minecraft"); neededMods.add("fabricloader"); neededMods.add("steamwarmodsender"); + + BungeeCord.getInstance().getScheduler().schedule(BungeeCore.get(), () -> { + for (Map.Entry entry : expectPluginMessage.entrySet()) { + if (System.currentTimeMillis() - entry.getValue() > TimeUnit.SECONDS.toMillis(20)) { + banPlayer(SteamwarUser.get(entry.getKey()), entry.getKey()); + return; + } + } + }, 0, 1, TimeUnit.SECONDS); } @EventHandler @@ -63,6 +79,11 @@ public class Fabric extends BasicListener { ProxiedPlayer player = (ProxiedPlayer) e.getSender(); SteamwarUser user = SteamwarUser.get(player.getUniqueId()); + if (expectPluginMessage.containsKey(player) && !checkedPlayers.containsKey(player)) { + banPlayer(user, player); + return; + } + List mods = new LinkedList<>(); byte[] data = e.getData(); @@ -124,6 +145,12 @@ public class Fabric extends BasicListener { } } + @EventHandler + public void onServerSwitchEvent(ServerSwitchEvent e) { + if (e.getFrom() == null) return; + expectPluginMessage.put(e.getPlayer(), System.currentTimeMillis()); + } + private boolean isSortedAlphabetically(List mods) { boolean isSorted = true; for(int i = 0; i < mods.size() - 1; i++) { diff --git a/src/de/steamwar/bungeecore/listeners/mods/ModLoaderBlocker.java b/src/de/steamwar/bungeecore/listeners/mods/ModLoaderBlocker.java index 134c7f8..00e076e 100644 --- a/src/de/steamwar/bungeecore/listeners/mods/ModLoaderBlocker.java +++ b/src/de/steamwar/bungeecore/listeners/mods/ModLoaderBlocker.java @@ -59,6 +59,7 @@ public class ModLoaderBlocker extends BasicListener { @EventHandler public void onDisconnect(PlayerDisconnectEvent e){ Fabric.checkedPlayers.remove(e.getPlayer()); + Fabric.expectPluginMessage.remove(e.getPlayer()); Storage.fabricPlayers.remove(e.getPlayer()); }