Skip to content

Commit

Permalink
bugs fix
Browse files Browse the repository at this point in the history
  • Loading branch information
ZetaMap committed Jan 31, 2023
1 parent 2b00d9a commit b61a17a
Show file tree
Hide file tree
Showing 5 changed files with 69 additions and 49 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
* `anti-vpn [on|off|token] [your_token]` Anti VPN service.
* `filters <help|on|off>` Enabled/disabled filters.
* `effect <list|on|off> [id|name]` Enabled/disabled a particles effect.
* `switch <help|list|add|remove> [name] [ip] [onlyAdmin]` Configure the list of servers in the switch.
* `switch <help|list|add|remove|clear> [name] [ip] [onlyAdmin]` Configure the list of servers in the switch.
* `tag <help|arg0> [ID|] [tagName...]` Configure the tag system.
* `ban <list|add|remove|reset> [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.
Expand Down
11 changes: 8 additions & 3 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down
83 changes: 43 additions & 40 deletions src/main/java/ContentRegister.java
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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);
}

Expand All @@ -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;
Expand All @@ -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
Expand Down
9 changes: 7 additions & 2 deletions src/main/java/data/Switcher.java
Original file line number Diff line number Diff line change
Expand Up @@ -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!)");
Expand All @@ -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_);
}
Expand Down Expand Up @@ -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"))
Expand Down
13 changes: 10 additions & 3 deletions src/main/java/moreCommandsPlugin.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -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.");
}
});
Expand Down Expand Up @@ -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", "<filter|name|x,y> [~|to_name|x,y...]", "Teleport to a location or player", true, false, (arg, data) -> {
Expand Down

0 comments on commit b61a17a

Please sign in to comment.