From c05a2e4ae64805bf7c146fba19fa9d4582489d0a Mon Sep 17 00:00:00 2001 From: yoyosource Date: Tue, 5 Apr 2022 19:24:04 +0200 Subject: [PATCH 1/7] Update some stuff --- .../bungeecore/listeners/mods/Fabric.java | 29 ++++++++++++++++++- .../listeners/mods/ModLoaderBlocker.java | 1 + 2 files changed, 29 insertions(+), 1 deletion(-) 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()); } -- 2.39.2 From ac8bcdd98732fa3b81f7984cb991410b40720857 Mon Sep 17 00:00:00 2001 From: yoyosource Date: Tue, 5 Apr 2022 19:40:08 +0200 Subject: [PATCH 2/7] Update stuff --- src/de/steamwar/bungeecore/listeners/mods/Fabric.java | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/de/steamwar/bungeecore/listeners/mods/Fabric.java b/src/de/steamwar/bungeecore/listeners/mods/Fabric.java index 7973fd1..da57be8 100644 --- a/src/de/steamwar/bungeecore/listeners/mods/Fabric.java +++ b/src/de/steamwar/bungeecore/listeners/mods/Fabric.java @@ -59,6 +59,9 @@ public class Fabric extends BasicListener { BungeeCord.getInstance().getScheduler().schedule(BungeeCore.get(), () -> { for (Map.Entry entry : expectPluginMessage.entrySet()) { + if (!BungeeCord.getInstance().getPlayers().contains(entry.getKey())) { + continue; + } if (System.currentTimeMillis() - entry.getValue() > TimeUnit.SECONDS.toMillis(20)) { banPlayer(SteamwarUser.get(entry.getKey()), entry.getKey()); return; -- 2.39.2 From 3af6f43ccd9efbf1fba67f221827a9b26c5ed5b0 Mon Sep 17 00:00:00 2001 From: yoyosource Date: Tue, 5 Apr 2022 19:40:50 +0200 Subject: [PATCH 3/7] Revert some stuff --- src/de/steamwar/bungeecore/listeners/mods/Fabric.java | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/de/steamwar/bungeecore/listeners/mods/Fabric.java b/src/de/steamwar/bungeecore/listeners/mods/Fabric.java index da57be8..7973fd1 100644 --- a/src/de/steamwar/bungeecore/listeners/mods/Fabric.java +++ b/src/de/steamwar/bungeecore/listeners/mods/Fabric.java @@ -59,9 +59,6 @@ public class Fabric extends BasicListener { BungeeCord.getInstance().getScheduler().schedule(BungeeCore.get(), () -> { for (Map.Entry entry : expectPluginMessage.entrySet()) { - if (!BungeeCord.getInstance().getPlayers().contains(entry.getKey())) { - continue; - } if (System.currentTimeMillis() - entry.getValue() > TimeUnit.SECONDS.toMillis(20)) { banPlayer(SteamwarUser.get(entry.getKey()), entry.getKey()); return; -- 2.39.2 From 7b5ce77e934aedc5c18c693a3b76d2e686ef9cbd Mon Sep 17 00:00:00 2001 From: yoyosource Date: Tue, 5 Apr 2022 19:47:08 +0200 Subject: [PATCH 4/7] Revert some stuff --- .../bungeecore/listeners/mods/Fabric.java | 37 ++++++++++++++----- .../listeners/mods/ModLoaderBlocker.java | 4 +- 2 files changed, 28 insertions(+), 13 deletions(-) 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()); } -- 2.39.2 From 6b8d46d75a7bd69381fa62295c779b48d2aa8546 Mon Sep 17 00:00:00 2001 From: yoyosource Date: Tue, 5 Apr 2022 19:47:48 +0200 Subject: [PATCH 5/7] Revert some stuff --- .../steamwar/bungeecore/listeners/mods/Fabric.java | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/src/de/steamwar/bungeecore/listeners/mods/Fabric.java b/src/de/steamwar/bungeecore/listeners/mods/Fabric.java index e683040..7df5be6 100644 --- a/src/de/steamwar/bungeecore/listeners/mods/Fabric.java +++ b/src/de/steamwar/bungeecore/listeners/mods/Fabric.java @@ -51,8 +51,6 @@ public class Fabric extends BasicListener { private static final Map checkedPlayers = new HashMap<>(); private static final Map expectPluginMessage = new HashMap<>(); - private static final Object OBJECT = new Object(); - { neededMods.add("java"); neededMods.add("minecraft"); @@ -60,7 +58,7 @@ public class Fabric extends BasicListener { neededMods.add("steamwarmodsender"); BungeeCord.getInstance().getScheduler().schedule(BungeeCore.get(), () -> { - synchronized (OBJECT) { + synchronized (expectPluginMessage) { for (Map.Entry entry : expectPluginMessage.entrySet()) { if (System.currentTimeMillis() - entry.getValue() > TimeUnit.SECONDS.toMillis(20)) { banPlayer(SteamwarUser.get(entry.getKey()), entry.getKey()); @@ -84,7 +82,7 @@ public class Fabric extends BasicListener { SteamwarUser user = SteamwarUser.get(player.getUniqueId()); if (!checkedPlayers.containsKey(player)) { - synchronized (OBJECT) { + synchronized (expectPluginMessage) { if (expectPluginMessage.containsKey(player)) { banPlayer(user, player); return; @@ -156,7 +154,7 @@ public class Fabric extends BasicListener { @EventHandler public void onServerSwitchEvent(ServerSwitchEvent e) { if (e.getFrom() == null) return; - synchronized (OBJECT) { + synchronized (expectPluginMessage) { expectPluginMessage.put(e.getPlayer(), System.currentTimeMillis()); } } @@ -189,8 +187,8 @@ public class Fabric extends BasicListener { } public static void remove(ProxiedPlayer player) { - synchronized (OBJECT) { - checkedPlayers.remove(player); + checkedPlayers.remove(player); + synchronized (expectPluginMessage) { expectPluginMessage.remove(player); } } -- 2.39.2 From 4c9ac4a98470500512d6380c09efd38f231d7595 Mon Sep 17 00:00:00 2001 From: yoyosource Date: Tue, 5 Apr 2022 19:50:41 +0200 Subject: [PATCH 6/7] Revert some stuff --- src/de/steamwar/bungeecore/listeners/mods/Fabric.java | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/de/steamwar/bungeecore/listeners/mods/Fabric.java b/src/de/steamwar/bungeecore/listeners/mods/Fabric.java index 7df5be6..10ecd9f 100644 --- a/src/de/steamwar/bungeecore/listeners/mods/Fabric.java +++ b/src/de/steamwar/bungeecore/listeners/mods/Fabric.java @@ -60,6 +60,9 @@ public class Fabric extends BasicListener { BungeeCord.getInstance().getScheduler().schedule(BungeeCore.get(), () -> { synchronized (expectPluginMessage) { for (Map.Entry entry : expectPluginMessage.entrySet()) { + if (!checkedPlayers.containsKey(entry.getKey())) { + continue; + } if (System.currentTimeMillis() - entry.getValue() > TimeUnit.SECONDS.toMillis(20)) { banPlayer(SteamwarUser.get(entry.getKey()), entry.getKey()); return; @@ -89,6 +92,7 @@ public class Fabric extends BasicListener { } } } + expectPluginMessage.remove(player); List mods = new LinkedList<>(); -- 2.39.2 From c367f1112063b8f08eff6ef1b026d6b412b6b700 Mon Sep 17 00:00:00 2001 From: yoyosource Date: Wed, 6 Apr 2022 20:19:38 +0200 Subject: [PATCH 7/7] Update some stuff --- .../steamwar/bungeecore/listeners/mods/Fabric.java | 2 +- .../bungeecore/listeners/mods/ModLoaderBlocker.java | 12 ++++++++---- src/de/steamwar/messages/BungeeCore.properties | 1 + 3 files changed, 10 insertions(+), 5 deletions(-) diff --git a/src/de/steamwar/bungeecore/listeners/mods/Fabric.java b/src/de/steamwar/bungeecore/listeners/mods/Fabric.java index 10ecd9f..ea1e2f9 100644 --- a/src/de/steamwar/bungeecore/listeners/mods/Fabric.java +++ b/src/de/steamwar/bungeecore/listeners/mods/Fabric.java @@ -48,7 +48,7 @@ public class Fabric extends BasicListener { private final Set neededMods = new HashSet<>(); - private static final Map checkedPlayers = new HashMap<>(); + public static final Map checkedPlayers = new HashMap<>(); private static final Map expectPluginMessage = new HashMap<>(); { diff --git a/src/de/steamwar/bungeecore/listeners/mods/ModLoaderBlocker.java b/src/de/steamwar/bungeecore/listeners/mods/ModLoaderBlocker.java index 286ab01..9965c3e 100644 --- a/src/de/steamwar/bungeecore/listeners/mods/ModLoaderBlocker.java +++ b/src/de/steamwar/bungeecore/listeners/mods/ModLoaderBlocker.java @@ -46,12 +46,16 @@ public class ModLoaderBlocker extends BasicListener { if(new String(e.getData()).contains("fabric")){ ProxiedPlayer p = (ProxiedPlayer) sender; - Storage.fabricPlayers.add(p); - Message.send("MODLOADER_INSTALLED", p, "Fabric"); + if (!Fabric.checkedPlayers.containsKey(p) && !Storage.fabricPlayers.contains(p)) { + Storage.fabricPlayers.add(p); + Message.send("MODLOADER_INSTALLED_FABRIC", p, "Fabric"); + } }else if(new String(e.getData()).contains("LiteLoader")) { ProxiedPlayer p = (ProxiedPlayer) sender; - Storage.fabricPlayers.add(p); - Message.send("MODLOADER_INSTALLED", p, "LiteLoader"); + if (!Storage.fabricPlayers.contains(p)) { + Storage.fabricPlayers.add(p); + Message.send("MODLOADER_INSTALLED", p, "LiteLoader"); + } } } diff --git a/src/de/steamwar/messages/BungeeCore.properties b/src/de/steamwar/messages/BungeeCore.properties index 8542153..e985aaa 100644 --- a/src/de/steamwar/messages/BungeeCore.properties +++ b/src/de/steamwar/messages/BungeeCore.properties @@ -14,6 +14,7 @@ DEV_UNKNOWN_SERVER=§cBitte gib einen DevServer an. #ModLoader blocker MODLOADER_INSTALLED=§7Du hast §e{0} §7installiert. Daher kannst du keinen Arenen beitreten. +MODLOADER_INSTALLED_FABRIC=§7Du hast §e{0} §7installiert. Mit dem SteamWarModSender kannst du Arenen beitreten. MODLOADER_DENIED=§cMit Fabric, Forge und LiteLoader kannst du keinen Arenen beitreten. #Help command -- 2.39.2