From bc44380c32071e8b9a1c227b0543b37799c7beaa Mon Sep 17 00:00:00 2001 From: yoyosource Date: Fri, 17 Feb 2023 17:13:46 +0100 Subject: [PATCH 1/6] Add NonFabricFabricCheck --- src/de/steamwar/bungeecore/BungeeCore.java | 7 +- .../listeners/NonFabricFabricCheck.java | 82 +++++++++++++++++++ .../steamwar/messages/BungeeCore.properties | 2 + .../messages/BungeeCore_de.properties | 2 + 4 files changed, 92 insertions(+), 1 deletion(-) create mode 100644 src/de/steamwar/bungeecore/listeners/NonFabricFabricCheck.java diff --git a/src/de/steamwar/bungeecore/BungeeCore.java b/src/de/steamwar/bungeecore/BungeeCore.java index b0c69b6..ea959b7 100644 --- a/src/de/steamwar/bungeecore/BungeeCore.java +++ b/src/de/steamwar/bungeecore/BungeeCore.java @@ -28,7 +28,10 @@ import de.steamwar.bungeecore.listeners.ping.PingListener; import de.steamwar.bungeecore.network.BungeeNetworkHandler; import de.steamwar.bungeecore.network.NetworkReceiver; import de.steamwar.bungeecore.network.SWScriptSyntaxForwarder; -import de.steamwar.bungeecore.sql.*; +import de.steamwar.bungeecore.sql.Punishment; +import de.steamwar.bungeecore.sql.SteamwarUser; +import de.steamwar.bungeecore.sql.Team; +import de.steamwar.bungeecore.sql.UserElo; import de.steamwar.bungeecore.tablist.TablistManager; import de.steamwar.command.SWCommandUtils; import de.steamwar.command.SWTypeMapperCreator; @@ -102,6 +105,8 @@ public class BungeeCore extends Plugin { }); BungeeCord.getInstance().getScheduler().schedule(this, TabCompletionCache::invalidateOldEntries, 1, 1, TimeUnit.SECONDS); + new NonFabricFabricCheck(); + new SWScriptSyntaxForwarder(); new ConnectionListener(); new Forge(); diff --git a/src/de/steamwar/bungeecore/listeners/NonFabricFabricCheck.java b/src/de/steamwar/bungeecore/listeners/NonFabricFabricCheck.java new file mode 100644 index 0000000..3dab7f1 --- /dev/null +++ b/src/de/steamwar/bungeecore/listeners/NonFabricFabricCheck.java @@ -0,0 +1,82 @@ +/* + * This file is a part of the SteamWar software. + * + * Copyright (C) 2022 SteamWar.de-Serverteam + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +package de.steamwar.bungeecore.listeners; + +import de.steamwar.bungeecore.BungeeCore; +import de.steamwar.bungeecore.Message; +import de.steamwar.bungeecore.Storage; +import net.md_5.bungee.BungeeCord; +import net.md_5.bungee.api.connection.Connection; +import net.md_5.bungee.api.connection.ProxiedPlayer; +import net.md_5.bungee.api.event.PlayerDisconnectEvent; +import net.md_5.bungee.api.event.PluginMessageEvent; +import net.md_5.bungee.api.event.PostLoginEvent; +import net.md_5.bungee.event.EventHandler; + +import java.util.HashSet; +import java.util.Set; +import java.util.concurrent.TimeUnit; + +public class NonFabricFabricCheck extends BasicListener { + + private Set usingFabric = new HashSet<>(); + + private Set checking = new HashSet<>(); + + @EventHandler + public void pluginMessageEvent(PluginMessageEvent e) { + Connection sender = e.getSender(); + if(!(sender instanceof ProxiedPlayer)) + return; + + if(!e.getTag().equals("minecraft:brand")) + return; + + if(!new String(e.getData()).contains("vanilla")){ + return; + } + + ProxiedPlayer p = (ProxiedPlayer) sender; + + BungeeCord.getInstance().getScheduler().schedule(BungeeCore.get(), () -> { + if (!p.isConnected()) return; + if (Storage.fabricCheckedPlayers.containsKey(p)) return; + checking.add(p); + p.sendData("fabric-screen-handler-api-v1:open_screen", new byte[] {0}); + BungeeCord.getInstance().getScheduler().schedule(BungeeCore.get(), () -> checking.remove(p), 1, TimeUnit.SECONDS); + }, 30, TimeUnit.SECONDS); + } + + @EventHandler + public void onPlayerPreLogin(PostLoginEvent e) { + if (usingFabric.contains(e.getPlayer())) { + e.getPlayer().disconnect(Message.parse("MOD_USE_MODSENDER", e.getPlayer())); + usingFabric.remove(e.getPlayer()); + } + } + + @EventHandler + public void onPlayerDisconnect(PlayerDisconnectEvent e) { + if (checking.contains(e.getPlayer())) { + usingFabric.add(e.getPlayer()); + } + checking.remove(e.getPlayer()); + } +} diff --git a/src/de/steamwar/messages/BungeeCore.properties b/src/de/steamwar/messages/BungeeCore.properties index fb44d5a..5725c9b 100644 --- a/src/de/steamwar/messages/BungeeCore.properties +++ b/src/de/steamwar/messages/BungeeCore.properties @@ -116,6 +116,8 @@ MOD_RED_PLUR=Attempted use of mods:\n{0} MOD_YELLOW_SING=§7Deactivate the mod §e{0}§7 to continue playing on §eSteam§8War§7. MOD_YELLOW_PLUR=§7Deactivate the mods\n§e{0}\n§7to continue playing on §eSteam§8War§7. +MOD_USE_MODSENDER=§cPlease use the §c§lSteamWarModSender§c. + #Various commands ALERT=§f{0} STAT_SERVER=§7Server §e{0}§8: §7Below limit §e{1} §7Server count §e{2} diff --git a/src/de/steamwar/messages/BungeeCore_de.properties b/src/de/steamwar/messages/BungeeCore_de.properties index f9b11af..6111018 100644 --- a/src/de/steamwar/messages/BungeeCore_de.properties +++ b/src/de/steamwar/messages/BungeeCore_de.properties @@ -102,6 +102,8 @@ MOD_RED_PLUR=Versuchte Benutzung der Mods:\n{0} MOD_YELLOW_SING=§7Deaktiviere den Mod §e{0}§7, um weiter auf §eSteam§8War §7spielen zu können. MOD_YELLOW_PLUR=§7Deaktiviere die Mods\n§e{0}\n§7um weiter auf §eSteam§8War §7spielen zu können. +MOD_USE_MODSENDER=§cBitte nutze den §c§lSteamWarModSender§c. + #Various commands STAT_SERVER=§7Server §e{0}§8: §7Startfähig §e{1} §7Serveranzahl §e{2} -- 2.39.2 From 277304b7f2d3b195fc4e4f2bf749a68e0868fb4f Mon Sep 17 00:00:00 2001 From: yoyosource Date: Fri, 17 Feb 2023 17:15:30 +0100 Subject: [PATCH 2/6] Fix vanilla brand check --- src/de/steamwar/bungeecore/listeners/NonFabricFabricCheck.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/de/steamwar/bungeecore/listeners/NonFabricFabricCheck.java b/src/de/steamwar/bungeecore/listeners/NonFabricFabricCheck.java index 3dab7f1..72cbb42 100644 --- a/src/de/steamwar/bungeecore/listeners/NonFabricFabricCheck.java +++ b/src/de/steamwar/bungeecore/listeners/NonFabricFabricCheck.java @@ -49,7 +49,7 @@ public class NonFabricFabricCheck extends BasicListener { if(!e.getTag().equals("minecraft:brand")) return; - if(!new String(e.getData()).contains("vanilla")){ + if(!new String(e.getData()).equals("vanilla")){ return; } -- 2.39.2 From e4ab48a386e79575ee8dee41925320d28a760bcb Mon Sep 17 00:00:00 2001 From: yoyosource Date: Fri, 17 Feb 2023 17:22:49 +0100 Subject: [PATCH 3/6] Fix vanilla brand check --- .../listeners/NonFabricFabricCheck.java | 22 +++++++++++-------- .../steamwar/messages/BungeeCore.properties | 2 +- .../messages/BungeeCore_de.properties | 2 +- 3 files changed, 15 insertions(+), 11 deletions(-) diff --git a/src/de/steamwar/bungeecore/listeners/NonFabricFabricCheck.java b/src/de/steamwar/bungeecore/listeners/NonFabricFabricCheck.java index 72cbb42..43da240 100644 --- a/src/de/steamwar/bungeecore/listeners/NonFabricFabricCheck.java +++ b/src/de/steamwar/bungeecore/listeners/NonFabricFabricCheck.java @@ -25,21 +25,27 @@ import de.steamwar.bungeecore.Storage; import net.md_5.bungee.BungeeCord; import net.md_5.bungee.api.connection.Connection; import net.md_5.bungee.api.connection.ProxiedPlayer; +import net.md_5.bungee.api.event.LoginEvent; import net.md_5.bungee.api.event.PlayerDisconnectEvent; import net.md_5.bungee.api.event.PluginMessageEvent; -import net.md_5.bungee.api.event.PostLoginEvent; import net.md_5.bungee.event.EventHandler; import java.util.HashSet; +import java.util.Locale; import java.util.Set; +import java.util.UUID; import java.util.concurrent.TimeUnit; public class NonFabricFabricCheck extends BasicListener { - private Set usingFabric = new HashSet<>(); + private Set usingFabric = new HashSet<>(); private Set checking = new HashSet<>(); + { + BungeeCord.getInstance().getScheduler().schedule(BungeeCore.get(), usingFabric::clear, 0, 15, TimeUnit.MINUTES); + } + @EventHandler public void pluginMessageEvent(PluginMessageEvent e) { Connection sender = e.getSender(); @@ -65,18 +71,16 @@ public class NonFabricFabricCheck extends BasicListener { } @EventHandler - public void onPlayerPreLogin(PostLoginEvent e) { - if (usingFabric.contains(e.getPlayer())) { - e.getPlayer().disconnect(Message.parse("MOD_USE_MODSENDER", e.getPlayer())); - usingFabric.remove(e.getPlayer()); + public void onPlayerPreLogin(LoginEvent e) { + if (usingFabric.remove(e.getConnection().getUniqueId())) { + e.getConnection().disconnect(Message.parse("MOD_USE_MODSENDER", Locale.getDefault())); } } @EventHandler public void onPlayerDisconnect(PlayerDisconnectEvent e) { - if (checking.contains(e.getPlayer())) { - usingFabric.add(e.getPlayer()); + if (checking.remove(e.getPlayer())) { + usingFabric.add(e.getPlayer().getUniqueId()); } - checking.remove(e.getPlayer()); } } diff --git a/src/de/steamwar/messages/BungeeCore.properties b/src/de/steamwar/messages/BungeeCore.properties index 5725c9b..926b255 100644 --- a/src/de/steamwar/messages/BungeeCore.properties +++ b/src/de/steamwar/messages/BungeeCore.properties @@ -116,7 +116,7 @@ MOD_RED_PLUR=Attempted use of mods:\n{0} MOD_YELLOW_SING=§7Deactivate the mod §e{0}§7 to continue playing on §eSteam§8War§7. MOD_YELLOW_PLUR=§7Deactivate the mods\n§e{0}\n§7to continue playing on §eSteam§8War§7. -MOD_USE_MODSENDER=§cPlease use the §c§lSteamWarModSender§c. +MOD_USE_MODSENDER=§cPlease use the §c§lSteamWarModSender§c or say that you are using fabric. #Various commands ALERT=§f{0} diff --git a/src/de/steamwar/messages/BungeeCore_de.properties b/src/de/steamwar/messages/BungeeCore_de.properties index 6111018..5a81745 100644 --- a/src/de/steamwar/messages/BungeeCore_de.properties +++ b/src/de/steamwar/messages/BungeeCore_de.properties @@ -102,7 +102,7 @@ MOD_RED_PLUR=Versuchte Benutzung der Mods:\n{0} MOD_YELLOW_SING=§7Deaktiviere den Mod §e{0}§7, um weiter auf §eSteam§8War §7spielen zu können. MOD_YELLOW_PLUR=§7Deaktiviere die Mods\n§e{0}\n§7um weiter auf §eSteam§8War §7spielen zu können. -MOD_USE_MODSENDER=§cBitte nutze den §c§lSteamWarModSender§c. +MOD_USE_MODSENDER=§cBitte nutze den §c§lSteamWarModSender§c oder sag uns das du Fabric nutzt. #Various commands STAT_SERVER=§7Server §e{0}§8: §7Startfähig §e{1} §7Serveranzahl §e{2} -- 2.39.2 From 91e73eab25b5abd65d0b136628a4a2ad14f891e0 Mon Sep 17 00:00:00 2001 From: yoyosource Date: Fri, 17 Feb 2023 17:24:49 +0100 Subject: [PATCH 4/6] Update messages --- src/de/steamwar/messages/BungeeCore.properties | 2 +- src/de/steamwar/messages/BungeeCore_de.properties | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/de/steamwar/messages/BungeeCore.properties b/src/de/steamwar/messages/BungeeCore.properties index 926b255..f5b03dd 100644 --- a/src/de/steamwar/messages/BungeeCore.properties +++ b/src/de/steamwar/messages/BungeeCore.properties @@ -116,7 +116,7 @@ MOD_RED_PLUR=Attempted use of mods:\n{0} MOD_YELLOW_SING=§7Deactivate the mod §e{0}§7 to continue playing on §eSteam§8War§7. MOD_YELLOW_PLUR=§7Deactivate the mods\n§e{0}\n§7to continue playing on §eSteam§8War§7. -MOD_USE_MODSENDER=§cPlease use the §c§lSteamWarModSender§c or say that you are using fabric. +MOD_USE_MODSENDER=§cPlease use the §c§lSteamWarModSender§c or remove the mod that is rebranding your installation. #Various commands ALERT=§f{0} diff --git a/src/de/steamwar/messages/BungeeCore_de.properties b/src/de/steamwar/messages/BungeeCore_de.properties index 5a81745..98b6a76 100644 --- a/src/de/steamwar/messages/BungeeCore_de.properties +++ b/src/de/steamwar/messages/BungeeCore_de.properties @@ -102,7 +102,7 @@ MOD_RED_PLUR=Versuchte Benutzung der Mods:\n{0} MOD_YELLOW_SING=§7Deaktiviere den Mod §e{0}§7, um weiter auf §eSteam§8War §7spielen zu können. MOD_YELLOW_PLUR=§7Deaktiviere die Mods\n§e{0}\n§7um weiter auf §eSteam§8War §7spielen zu können. -MOD_USE_MODSENDER=§cBitte nutze den §c§lSteamWarModSender§c oder sag uns das du Fabric nutzt. +MOD_USE_MODSENDER=§cBitte nutze den §c§lSteamWarModSender§c oder entfernen Sie den Mod, der Ihre Installation umbenennt. #Various commands STAT_SERVER=§7Server §e{0}§8: §7Startfähig §e{1} §7Serveranzahl §e{2} -- 2.39.2 From 5d70cc4185ed9c46d82c988a504300ef28718eb5 Mon Sep 17 00:00:00 2001 From: yoyosource Date: Fri, 17 Feb 2023 17:25:58 +0100 Subject: [PATCH 5/6] Update messages --- src/de/steamwar/messages/BungeeCore.properties | 2 +- src/de/steamwar/messages/BungeeCore_de.properties | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/de/steamwar/messages/BungeeCore.properties b/src/de/steamwar/messages/BungeeCore.properties index f5b03dd..b4256b2 100644 --- a/src/de/steamwar/messages/BungeeCore.properties +++ b/src/de/steamwar/messages/BungeeCore.properties @@ -116,7 +116,7 @@ MOD_RED_PLUR=Attempted use of mods:\n{0} MOD_YELLOW_SING=§7Deactivate the mod §e{0}§7 to continue playing on §eSteam§8War§7. MOD_YELLOW_PLUR=§7Deactivate the mods\n§e{0}\n§7to continue playing on §eSteam§8War§7. -MOD_USE_MODSENDER=§cPlease use the §c§lSteamWarModSender§c or remove the mod that is rebranding your installation. +MOD_USE_MODSENDER=§cPlease use the §c§lFabricModSender§c (https://steamwar.de/downloads/) or remove the mod that is rebranding your installation. #Various commands ALERT=§f{0} diff --git a/src/de/steamwar/messages/BungeeCore_de.properties b/src/de/steamwar/messages/BungeeCore_de.properties index 98b6a76..d5c5c54 100644 --- a/src/de/steamwar/messages/BungeeCore_de.properties +++ b/src/de/steamwar/messages/BungeeCore_de.properties @@ -102,7 +102,7 @@ MOD_RED_PLUR=Versuchte Benutzung der Mods:\n{0} MOD_YELLOW_SING=§7Deaktiviere den Mod §e{0}§7, um weiter auf §eSteam§8War §7spielen zu können. MOD_YELLOW_PLUR=§7Deaktiviere die Mods\n§e{0}\n§7um weiter auf §eSteam§8War §7spielen zu können. -MOD_USE_MODSENDER=§cBitte nutze den §c§lSteamWarModSender§c oder entfernen Sie den Mod, der Ihre Installation umbenennt. +MOD_USE_MODSENDER=§cBitte nutze den §c§lFabricModSender§c (https://steamwar.de/downloads/) oder entfernen Sie den Mod, der Ihre Installation umbenennt. #Various commands STAT_SERVER=§7Server §e{0}§8: §7Startfähig §e{1} §7Serveranzahl §e{2} -- 2.39.2 From 68a2f78e04b4b3c4efb56650f45b418619f73f41 Mon Sep 17 00:00:00 2001 From: yoyosource Date: Fri, 17 Feb 2023 17:33:56 +0100 Subject: [PATCH 6/6] Update messages --- .../steamwar/bungeecore/listeners/NonFabricFabricCheck.java | 4 ++-- src/de/steamwar/messages/BungeeCore_de.properties | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/de/steamwar/bungeecore/listeners/NonFabricFabricCheck.java b/src/de/steamwar/bungeecore/listeners/NonFabricFabricCheck.java index 43da240..b903b9c 100644 --- a/src/de/steamwar/bungeecore/listeners/NonFabricFabricCheck.java +++ b/src/de/steamwar/bungeecore/listeners/NonFabricFabricCheck.java @@ -38,9 +38,9 @@ import java.util.concurrent.TimeUnit; public class NonFabricFabricCheck extends BasicListener { - private Set usingFabric = new HashSet<>(); + private final Set usingFabric = new HashSet<>(); - private Set checking = new HashSet<>(); + private final Set checking = new HashSet<>(); { BungeeCord.getInstance().getScheduler().schedule(BungeeCore.get(), usingFabric::clear, 0, 15, TimeUnit.MINUTES); diff --git a/src/de/steamwar/messages/BungeeCore_de.properties b/src/de/steamwar/messages/BungeeCore_de.properties index d5c5c54..83de9f6 100644 --- a/src/de/steamwar/messages/BungeeCore_de.properties +++ b/src/de/steamwar/messages/BungeeCore_de.properties @@ -102,7 +102,7 @@ MOD_RED_PLUR=Versuchte Benutzung der Mods:\n{0} MOD_YELLOW_SING=§7Deaktiviere den Mod §e{0}§7, um weiter auf §eSteam§8War §7spielen zu können. MOD_YELLOW_PLUR=§7Deaktiviere die Mods\n§e{0}\n§7um weiter auf §eSteam§8War §7spielen zu können. -MOD_USE_MODSENDER=§cBitte nutze den §c§lFabricModSender§c (https://steamwar.de/downloads/) oder entfernen Sie den Mod, der Ihre Installation umbenennt. +MOD_USE_MODSENDER=§cBitte nutze den §c§lFabricModSender§c (https://steamwar.de/downloads/) oder entfernen den Mod, der die Installation umbenennt. #Various commands STAT_SERVER=§7Server §e{0}§8: §7Startfähig §e{1} §7Serveranzahl §e{2} -- 2.39.2