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;
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,27 @@ public class Fabric extends BasicListener {
private final Set<String> neededMods = new HashSet<>();
public static final Map<ProxiedPlayer, Integer> checkedPlayers = new HashMap<>();
private static final Map<ProxiedPlayer, Long> expectPluginMessage = new HashMap<>();
{
neededMods.add("java");
neededMods.add("minecraft");
neededMods.add("fabricloader");
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
@ -63,6 +84,16 @@ public class Fabric extends BasicListener {
ProxiedPlayer player = (ProxiedPlayer) e.getSender();
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<>();
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) {
boolean isSorted = true;
for(int i = 0; i < mods.size() - 1; i++) {
@ -150,4 +189,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) {
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.event.EventHandler;
import java.nio.charset.StandardCharsets;
import java.util.HashSet;
import java.util.Set;
@ -47,18 +46,22 @@ 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");
}
}
}
@EventHandler
public void onDisconnect(PlayerDisconnectEvent e){
Fabric.checkedPlayers.remove(e.getPlayer());
Fabric.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_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