diff --git a/README.md b/README.md index e60bfcc..1db474c 100644 --- a/README.md +++ b/README.md @@ -47,7 +47,7 @@ * `anti-vpn [on|off|token] [your_token]` Anti VPN service. * `filters ` Enabled/disabled filters. * `effect [id|name]` Enabled/disabled a particles effect. -* `switch [name] [ip] [onlyAdmin]` Configure the list of servers in the switch. +* `switch [name] [ip] [onlyAdmin]` Configure the list of servers in the switch. * `tag [ID|] [tagName...]` Configure the tag system. * `ban [type-id|ip] [ID|IP] [reason...]` List all banned IP/ID or ban/unban an ID/IP. * `alogs [on|off|reset] [y|n]` Configure admins logs. diff --git a/build.gradle b/build.gradle index 98b80de..9e8021d 100644 --- a/build.gradle +++ b/build.gradle @@ -7,16 +7,21 @@ sourceCompatibility = 1.8 repositories{ mavenCentral() maven{ url 'https://www.jitpack.io' } + maven{ url 'https://maven.xpdustry.fr/releases' } } ext{ //the build number that this plugin is made for - mindustryVersion = 'v126.2' + mindustry = 'v141.3' + nucleus = '2023.1.4' + distributor = '3.0.0-rc.2' } dependencies{ - compileOnly "com.github.Anuken.Arc:arc-core:$mindustryVersion" - compileOnly "com.github.Anuken.Mindustry:core:$mindustryVersion" + compileOnly "com.github.Anuken.Arc:arc-core:$mindustry" + compileOnly "com.github.Anuken.Mindustry:core:$mindustry" + compileOnly "fr.xpdustry:nucleus-mindustry:$nucleus" + compileOnly "fr.xpdustry:distributor-api:$distributor" } jar{ diff --git a/src/main/java/ContentRegister.java b/src/main/java/ContentRegister.java index 4559027..5e16973 100644 --- a/src/main/java/ContentRegister.java +++ b/src/main/java/ContentRegister.java @@ -27,7 +27,7 @@ public class ContentRegister { public static void initFilters() { // test if Nucleaus plugin is present to keep auto-translated chat - mindustry.mod.Mod nucleusPlugin = Vars.mods.getMod("xpdustry-nucleus") == null ? null : Vars.mods.getMod("xpdustry-nucleus").main; + final mindustry.mod.Mod nucleusPlugin = Vars.mods.getMod("xpdustry-nucleus") == null ? null : Vars.mods.getMod("xpdustry-nucleus").main; // filter for muted, rainbowed players, disabled chat, and tags // register this filter at second position after anti-spam of mindustry and @@ -44,28 +44,27 @@ public static void initFilters() { else if (nucleusPlugin != null) { final fr.xpdustry.nucleus.core.translation.Translator translator = ((fr.xpdustry.nucleus.mindustry.NucleusPlugin) nucleusPlugin).getTranslator(); final String stripedMessage = Strings.stripColors(m); - + TempData.localeOrdonedPlayer.each((k, v) -> { String newMessage = m; - try { - newMessage += " [lightgray](" - + translator.translate(stripedMessage, data.locale, v.first().locale) - .orTimeout(3l, java.util.concurrent.TimeUnit.SECONDS).join() - + ")"; - } catch (Exception e) { - Log.debug("Failed to translate message '" + stripedMessage + "' in language " + v.first().player.locale); - Log.debug("Error: " + e.getLocalizedMessage()); + if (!(k.contains("_") ? k.subSequence(0, k.indexOf("_")) : k).equals(data.locale.getLanguage())) { + try { + newMessage += " [lightgray](" + + translator.translate(stripedMessage, data.locale, v.first().locale) + .orTimeout(3l, java.util.concurrent.TimeUnit.SECONDS).join() + + ")"; + } catch (Exception e) { + Log.debug("Failed to translate message '" + stripedMessage + "' in language " + v.first().player.locale); + Log.debug("Error: " + e.getLocalizedMessage()); + } } for (int i = 0; i < v.size; i++) { Call.sendMessage(v.items[i].player.con, (PVars.tags ? data.tag : "") - + "[coral][[" + data.getName() + "[coral]]:[white] " - + (v.items[i].player == p ? m : newMessage), v.items[i].player == p ? m : newMessage, p); + + "[coral][[" + data.getName() + "[coral]]:[white] " + newMessage, newMessage, p); } - }); - } else Call.sendMessage((PVars.tags ? data.tag : "") + "[coral][[" + data.getName() + "[coral]]:[white] " + m, m, p); } @@ -84,11 +83,13 @@ else if (nucleusPlugin != null) { } public static void initEvents() { + /* // try to modify destroy event to prevent potential error from nucleus Events.on(EventType.BlockDestroyEvent.class, e -> { }); - + */ + // clear VNW & RTV votes and disabled it on game over Events.on(EventType.GameOverEvent.class, e -> { PVars.canVote = false; @@ -103,31 +104,33 @@ public static void initEvents() { state.set(State.playing); }); - Events.on(EventType.PlayerConnect.class, e -> Threads.daemon("ConnectCheck_Player-" + e.player.id, () -> { - String name = Strings.stripGlyphs(Strings.stripColors(e.player.name)).strip(); - - // fix the admin bug - if (e.player.getInfo().admin) e.player.admin = true; - - // check if the nickname is empty without colors and emojis - if (name.isBlank()) { - e.player.kick(KickReason.nameEmpty); - return; - } - - // check the nickname of this player - if (manager.BansManager.checkName(e.player, name)) return; - - // prevent to duplicate nicknames - if (TempData.count(d -> d.stripedName.equals(name)) != 0) e.player.kick(KickReason.nameInUse); - - // check if player have a VPN - if (util.AntiVpn.checkIP(e.player.ip())) { - e.player.kick("[scarlet]VPN detected! []Please deactivate it to be able to connect to this server."); - ALog.write("VPN", "VPN found on player @ [@]", name, e.player.uuid()); - return; - } - })); + Events.on(EventType.PlayerConnect.class, e -> + Threads.daemon("ConnectCheck_Player-" + e.player.id, () -> { + String name = Strings.stripGlyphs(Strings.stripColors(e.player.name)).strip(); + + // fix the admin bug + if (e.player.getInfo().admin) e.player.admin = true; + + // check if the nickname is empty without colors and emojis + if (name.isBlank()) { + e.player.kick(KickReason.nameEmpty); + return; + } + + // check the nickname of this player + if (manager.BansManager.checkName(e.player, name)) return; + + // prevent to duplicate nicknames + if (TempData.count(d -> d.stripedName.equals(name)) != 0) e.player.kick(KickReason.nameInUse); + + // check if player have a VPN + if (util.AntiVpn.checkIP(e.player.ip())) { + e.player.kick("[scarlet]VPN detected! []Please deactivate it to be able to connect to this server."); + ALog.write("VPN", "VPN found on player @ [@]", name, e.player.uuid()); + return; + } + }) + ); Events.on(EventType.PlayerJoin.class, e -> { TempData data = TempData.put(e.player); // add player in TempData diff --git a/src/main/java/data/Switcher.java b/src/main/java/data/Switcher.java index abdab46..e7ad026 100644 --- a/src/main/java/data/Switcher.java +++ b/src/main/java/data/Switcher.java @@ -69,7 +69,7 @@ public ConnectReponse connect(mindustry.gen.Player player) { Host ping = ping(); if (ping != null) { - arc.util.Log.info("@ @ @ @ @ @", ping.address, ping.description, ping.mapname, ping.modeName, ping.versionType, ping.ping); + arc.util.Log.debug("Trace info of server: @ @ @ @ @ @", ping.address, ping.description, ping.mapname, ping.modeName, ping.versionType, ping.ping); } if (ping == null) reponse.failed("The server not responding. (Connexion timed out!)"); @@ -94,7 +94,7 @@ else if (stripedName.equals("lobby")) { lobby.name = stripedName; } else { - new_.changed = list.put(stripedName, new_) == null ? false : true; + new_.changed = list.put(stripedName, new_) != null; if (new_.changed) ordonedList.remove(s -> s.name.equals(new_.name)); ordonedList.add(new_); } @@ -151,6 +151,11 @@ public static int size() { return list.size; } + public static void clear() { + list.clear(); + ordonedList.clear(); + } + @SuppressWarnings("unchecked") public static void load() { if (Core.settings.has("SwitchList")) diff --git a/src/main/java/moreCommandsPlugin.java b/src/main/java/moreCommandsPlugin.java index 2248a84..e0acf1f 100644 --- a/src/main/java/moreCommandsPlugin.java +++ b/src/main/java/moreCommandsPlugin.java @@ -260,8 +260,10 @@ public void registerServerCommands(CommandHandler handler) { if (command == null) Log.err("This command doesn't exist!"); else if (arg.length > 1) { if (Strings.choiseOn(arg[1])) command.set(true); - else if (Strings.choiseOff(arg[1])) command.set(false); - else { + else if (Strings.choiseOff(arg[1])) { + if (command.name == "commands")Log.err("Why do that ? It can destroy the config!"); + else command.set(false); + }else { Log.err("Invalid value"); return; } @@ -552,6 +554,11 @@ else if (arg.length > 1) { } break; + case "clear": + Switcher.clear(); + Switcher.saveSettings(); + Log.info("Servers list cleared"); + break; default: Log.err("Invalid arguments."); } }); @@ -1585,7 +1592,7 @@ else if (reponse.reponse == Reponses.found) { Call.constructFinish(data.player.tileOn(), core, data.player.unit(), (byte) 0, team, false); data.player.sendMessage("[green]Core build" + (arg.length == 2 ? "for the team [accent]" + team.name : "")); - ALog.write("Core", "@ [@] build a @ at @,@ for the team @", data.stripedName, data.player.uuid(), core.name, data.player.tileX(), data.player.tileY(), team.name); + ALog.write("Core", "@ [@] build a @ at @,@ for team @", data.stripedName, data.player.uuid(), core.name, data.player.tileX(), data.player.tileY(), team.name); }); commands.add("tp", " [~|to_name|x,y...]", "Teleport to a location or player", true, false, (arg, data) -> {