diff --git a/src/de/steamwar/bungeecore/listeners/mods/Fabric.java b/src/de/steamwar/bungeecore/listeners/mods/Fabric.java index 7973fd1..e683040 100644 --- a/src/de/steamwar/bungeecore/listeners/mods/Fabric.java +++ b/src/de/steamwar/bungeecore/listeners/mods/Fabric.java @@ -48,8 +48,10 @@ 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<>(); + private static final Map checkedPlayers = new HashMap<>(); + private static final Map expectPluginMessage = new HashMap<>(); + + private static final Object OBJECT = new Object(); { neededMods.add("java"); @@ -58,10 +60,12 @@ public class Fabric extends BasicListener { 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; + synchronized (OBJECT) { + 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); @@ -79,9 +83,13 @@ 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; + if (!checkedPlayers.containsKey(player)) { + synchronized (OBJECT) { + if (expectPluginMessage.containsKey(player)) { + banPlayer(user, player); + return; + } + } } List mods = new LinkedList<>(); @@ -148,7 +156,9 @@ public class Fabric extends BasicListener { @EventHandler public void onServerSwitchEvent(ServerSwitchEvent e) { if (e.getFrom() == null) return; - expectPluginMessage.put(e.getPlayer(), System.currentTimeMillis()); + synchronized (OBJECT) { + expectPluginMessage.put(e.getPlayer(), System.currentTimeMillis()); + } } private boolean isSortedAlphabetically(List mods) { @@ -177,4 +187,11 @@ public class Fabric extends BasicListener { true); BungeeCore.log(Level.SEVERE,Message.parse("MODIFICATION_BAN_LOG", player, user.getUserName())); } + + public static void remove(ProxiedPlayer player) { + synchronized (OBJECT) { + checkedPlayers.remove(player); + expectPluginMessage.remove(player); + } + } } diff --git a/src/de/steamwar/bungeecore/listeners/mods/ModLoaderBlocker.java b/src/de/steamwar/bungeecore/listeners/mods/ModLoaderBlocker.java index 00e076e..286ab01 100644 --- a/src/de/steamwar/bungeecore/listeners/mods/ModLoaderBlocker.java +++ b/src/de/steamwar/bungeecore/listeners/mods/ModLoaderBlocker.java @@ -28,7 +28,6 @@ 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; import java.util.HashSet; import java.util.Set; @@ -58,8 +57,7 @@ public class ModLoaderBlocker extends BasicListener { @EventHandler public void onDisconnect(PlayerDisconnectEvent e){ - Fabric.checkedPlayers.remove(e.getPlayer()); - Fabric.expectPluginMessage.remove(e.getPlayer()); + Fabric.remove(e.getPlayer()); Storage.fabricPlayers.remove(e.getPlayer()); }