From bc44380c32071e8b9a1c227b0543b37799c7beaa Mon Sep 17 00:00:00 2001 From: yoyosource Date: Fri, 17 Feb 2023 17:13:46 +0100 Subject: [PATCH] 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 b0c69b61..ea959b73 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 00000000..3dab7f15 --- /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 fb44d5a8..5725c9b9 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 f9b11af6..61110187 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}