Archiviert
1
0

Merge pull request 'Update some stuff' (#339) from FabricModStuff into master

Reviewed-on: SteamWar/BungeeCore#339
Reviewed-by: Lixfel <lixfel@steamwar.de>
Dieser Commit ist enthalten in:
Lixfel 2022-04-09 20:58:27 +02:00
Commit 89f525adb4
3 geänderte Dateien mit 57 neuen und 7 gelöschten Zeilen

Datei anzeigen

@ -19,7 +19,10 @@
package de.steamwar.bungeecore.listeners.mods; 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.BungeeCore;
import de.steamwar.bungeecore.Message; import de.steamwar.bungeecore.Message;
import de.steamwar.bungeecore.Storage; 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.Mod;
import de.steamwar.bungeecore.sql.Punishment; import de.steamwar.bungeecore.sql.Punishment;
import de.steamwar.bungeecore.sql.SteamwarUser; 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.connection.ProxiedPlayer;
import net.md_5.bungee.api.event.PluginMessageEvent; import net.md_5.bungee.api.event.PluginMessageEvent;
import net.md_5.bungee.api.event.ServerSwitchEvent;
import net.md_5.bungee.event.EventHandler; import net.md_5.bungee.event.EventHandler;
import java.nio.charset.StandardCharsets; import java.nio.charset.StandardCharsets;
@ -36,6 +41,7 @@ import java.nio.charset.UnsupportedCharsetException;
import java.sql.Timestamp; import java.sql.Timestamp;
import java.time.Instant; import java.time.Instant;
import java.util.*; import java.util.*;
import java.util.concurrent.TimeUnit;
import java.util.logging.Level; import java.util.logging.Level;
public class Fabric extends BasicListener { public class Fabric extends BasicListener {
@ -43,12 +49,27 @@ public class Fabric extends BasicListener {
private final Set<String> neededMods = new HashSet<>(); private final Set<String> neededMods = new HashSet<>();
public static final Map<ProxiedPlayer, Integer> checkedPlayers = new HashMap<>(); public static final Map<ProxiedPlayer, Integer> checkedPlayers = new HashMap<>();
private static final Map<ProxiedPlayer, Long> expectPluginMessage = new HashMap<>();
{ {
neededMods.add("java"); neededMods.add("java");
neededMods.add("minecraft"); neededMods.add("minecraft");
neededMods.add("fabricloader"); neededMods.add("fabricloader");
neededMods.add("steamwarmodsender"); neededMods.add("steamwarmodsender");
BungeeCord.getInstance().getScheduler().schedule(BungeeCore.get(), () -> {
synchronized (expectPluginMessage) {
for (Map.Entry<ProxiedPlayer, Long> 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;
}
}
}
}, 0, 1, TimeUnit.SECONDS);
} }
@EventHandler @EventHandler
@ -63,6 +84,16 @@ public class Fabric extends BasicListener {
ProxiedPlayer player = (ProxiedPlayer) e.getSender(); ProxiedPlayer player = (ProxiedPlayer) e.getSender();
SteamwarUser user = SteamwarUser.get(player.getUniqueId()); SteamwarUser user = SteamwarUser.get(player.getUniqueId());
if (!checkedPlayers.containsKey(player)) {
synchronized (expectPluginMessage) {
if (expectPluginMessage.containsKey(player)) {
banPlayer(user, player);
return;
}
}
}
expectPluginMessage.remove(player);
List<Mod> mods = new LinkedList<>(); List<Mod> mods = new LinkedList<>();
byte[] data = e.getData(); byte[] data = e.getData();
@ -124,6 +155,14 @@ public class Fabric extends BasicListener {
} }
} }
@EventHandler
public void onServerSwitchEvent(ServerSwitchEvent e) {
if (e.getFrom() == null) return;
synchronized (expectPluginMessage) {
expectPluginMessage.put(e.getPlayer(), System.currentTimeMillis());
}
}
private boolean isSortedAlphabetically(List<Mod> mods) { private boolean isSortedAlphabetically(List<Mod> mods) {
boolean isSorted = true; boolean isSorted = true;
for(int i = 0; i < mods.size() - 1; i++) { for(int i = 0; i < mods.size() - 1; i++) {
@ -150,4 +189,11 @@ public class Fabric extends BasicListener {
true); true);
BungeeCore.log(Level.SEVERE,Message.parse("MODIFICATION_BAN_LOG", player, user.getUserName())); BungeeCore.log(Level.SEVERE,Message.parse("MODIFICATION_BAN_LOG", player, user.getUserName()));
} }
public static void remove(ProxiedPlayer player) {
checkedPlayers.remove(player);
synchronized (expectPluginMessage) {
expectPluginMessage.remove(player);
}
}
} }

Datei anzeigen

@ -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.api.event.ServerSwitchEvent;
import net.md_5.bungee.event.EventHandler; import net.md_5.bungee.event.EventHandler;
import java.nio.charset.StandardCharsets;
import java.util.HashSet; import java.util.HashSet;
import java.util.Set; import java.util.Set;
@ -47,18 +46,22 @@ public class ModLoaderBlocker extends BasicListener {
if(new String(e.getData()).contains("fabric")){ if(new String(e.getData()).contains("fabric")){
ProxiedPlayer p = (ProxiedPlayer) sender; ProxiedPlayer p = (ProxiedPlayer) sender;
if (!Fabric.checkedPlayers.containsKey(p) && !Storage.fabricPlayers.contains(p)) {
Storage.fabricPlayers.add(p); Storage.fabricPlayers.add(p);
Message.send("MODLOADER_INSTALLED", p, "Fabric"); Message.send("MODLOADER_INSTALLED_FABRIC", p, "Fabric");
}
}else if(new String(e.getData()).contains("LiteLoader")) { }else if(new String(e.getData()).contains("LiteLoader")) {
ProxiedPlayer p = (ProxiedPlayer) sender; ProxiedPlayer p = (ProxiedPlayer) sender;
if (!Storage.fabricPlayers.contains(p)) {
Storage.fabricPlayers.add(p); Storage.fabricPlayers.add(p);
Message.send("MODLOADER_INSTALLED", p, "LiteLoader"); Message.send("MODLOADER_INSTALLED", p, "LiteLoader");
} }
} }
}
@EventHandler @EventHandler
public void onDisconnect(PlayerDisconnectEvent e){ public void onDisconnect(PlayerDisconnectEvent e){
Fabric.checkedPlayers.remove(e.getPlayer()); Fabric.remove(e.getPlayer());
Storage.fabricPlayers.remove(e.getPlayer()); Storage.fabricPlayers.remove(e.getPlayer());
} }

Datei anzeigen

@ -14,6 +14,7 @@ DEV_UNKNOWN_SERVER=§cBitte gib einen DevServer an.
#ModLoader blocker #ModLoader blocker
MODLOADER_INSTALLED=§7Du hast §e{0} §7installiert. Daher kannst du keinen Arenen beitreten. 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. MODLOADER_DENIED=§cMit Fabric, Forge und LiteLoader kannst du keinen Arenen beitreten.
#Help command #Help command