Skip to content

Commit

Permalink
Add files via upload
Browse files Browse the repository at this point in the history
  • Loading branch information
ZetaMap authored Jul 9, 2021
1 parent ae60b49 commit 41c4146
Show file tree
Hide file tree
Showing 3 changed files with 109 additions and 10 deletions.
19 changes: 10 additions & 9 deletions src/main/java/moreCommandsPlugin.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import arc.util.Log;
import arc.util.Strings;

import util.Bundles;
import util.CommandsManager;
import util.CommandsManager.Commands;
import util.Effects;
Expand Down Expand Up @@ -53,6 +54,7 @@ public void init() {
}

public moreCommandsPlugin() {
Bundles.init();
Effects.init();

//clear VNW & RTV votes and disabled it on game over
Expand Down Expand Up @@ -950,14 +952,15 @@ public void run() {
target.unit().set(co[0]*8, co[1]*8);
Call.setPosition(target.con, co[0]*8, co[1]*8);
new Thread() {
public void run() {
public void run(Player p) {
try {
Thread.sleep(100);
p.sendMessage(p.con.lastReceivedClientTime + 100+ "");
Thread.sleep(p.con.lastReceivedClientTime + 100);
Config.strict.set(true);
Core.settings.forceSave();
} catch (InterruptedException e) {}
}
}.start();
}.run(target);
} else {
target.unit().set(co[0]*8, co[1]*8);
Call.setPosition(target.con, co[0]*8, co[1]*8);
Expand Down Expand Up @@ -1122,9 +1125,8 @@ public void run() {
if (target == null) Players.err(player, "Nobody with that name or ID could be found...");
else {
Call.sendMessage("[scarlet]/!\\" + NetClient.colorizeName(target.id, target.name) + "[scarlet] has been kicked of the server.");
// I do this while waiting to find the bundles
target.kick("You have been kicked from the server!\n[scarlet]Reason: []" + (arg.length == 2 ? String.join(" ", result.rest) : "<unknown>"));
//target.kick(KickReason.kick.toString() + "\n[scarlet]Reason: []" + (arg.length == 2 ? String.join(" ", result.rest) : "<unknown>"));
if (Bundles.dontUseBundle) target.kick("You have been kicked from the server!\n[scarlet]Reason: []" + (arg.length == 2 ? String.join(" ", result.rest) : "<unknown>"));
else target.kick(KickReason.kick.toString() + "\n[scarlet]Reason: []" + (arg.length == 2 ? String.join(" ", result.rest) : "<unknown>"));
}
});

Expand All @@ -1149,9 +1151,8 @@ public void run() {
else {
netServer.admins.banPlayer(target.uuid());
Call.sendMessage("[scarlet]/!\\ " + NetClient.colorizeName(target.id, target.name) + "[scarlet] has been banned of the server.");
// I do this while waiting to find the bundles
target.kick("You are banned on this server!\n[scarlet]Reason: []" + (arg.length == 2 ? String.join(" ", result.rest) : "<unknown>"));
//target.kick(KickReason.banned.toString() + "\n[scarlet]Reason: []" + (arg.length == 2 ? String.join(" ", result.rest) : "<unknown>"));
if (Bundles.dontUseBundle) target.kick("You are banned on this server!\n[scarlet]Reason: []" + (arg.length == 2 ? String.join(" ", result.rest) : "<unknown>"));
else target.kick(KickReason.banned.toString() + "\n[scarlet]Reason: []" + (arg.length == 2 ? String.join(" ", result.rest) : "<unknown>"));
}
});

Expand Down
97 changes: 97 additions & 0 deletions src/main/java/util/Bundles.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
package util;

import java.util.Locale;

import arc.Core;
import arc.files.Fi;
import arc.struct.Seq;
import arc.util.I18NBundle;
import arc.util.Log;

public class Bundles {
public static boolean dontUseBundle = false;
private static Locale country = Locale.getDefault();
private static Fi baseBundle = Core.files.local("config/bundles/bundle.properties");
private static Fi file = Core.files.local(String.format("config/bundles/bundle_%s.properties", country.getLanguage()));
private static String bundlesURL = "https://raw.githubusercontent.com/Anuken/Mindustry/master/core/assets/bundles/bundle_%s.properties";
private static String[] bundleKeys = {"server.closing",
"server.kicked.kick",
"server.kicked.whitelist",
"server.kicked.serverClose",
"server.kicked.vote",
"server.kicked.clientOutdated",
"server.kicked.serverOutdated",
"server.kicked.banned",
"server.kicked.typeMismatch",
"server.kicked.playerLimit",
"server.kicked.recentKick",
"server.kicked.nameInUse",
"server.kicked.nameEmpty",
"server.kicked.idInUse",
"server.kicked.customClient",
"server.kicked.gameover",
"server.kicked.serverRestarting"};

public static void init() {
if (findBundle() == null) {
Log.info("No bundle found for your language. Try to download bundle ...");

Core.net.httpGet(String.format(bundlesURL, country.getLanguage()), reponse -> {
Log.info("Bundle found! Bundle installation in progress ...");
file.writeBytes(reponse.getResult());
String content = searchKeys(file.readString());
file.writeString(content);
baseBundle.writeString(content);

}, error -> {
Log.err("Failed to download bundle in your language!");
dontUseBundle = true;
return;
});
}

try { Core.bundle = I18NBundle.createBundle(Core.files.local("config/bundles/bundle")); }
catch (Exception e) {
Log.err("Error: An error occurred while loading the bundle! The server will do without translations.");
dontUseBundle = true;
}
}

private static String searchKeys(String content) {
Seq<Object> lines = new Seq<>().addAll(content.lines().toArray());
Seq<String> newContent = new Seq<>();

for (String key : bundleKeys) {
lines.forEach(line -> {
if (((String) line).startsWith(key)) newContent.add((String) line);
});
}
return newContent.toString("\n");
}

private static Fi findBundle() {
if (file.exists()) {
if (file.readString().isBlank()) return null;
else {
Seq<Object> lines = new Seq<>().addAll(file.readString().lines().toArray());
Seq<String> proof = new Seq<>();

for (String key : bundleKeys) {
for (Object line : lines) {
if (((String) line).startsWith(key)) {
proof.add(key);
break;
}
}
}
return proof.size == bundleKeys.length ? file : null;
}
}
try { file.file().createNewFile(); }
catch (Exception e) {}

file.writeString("");
return null;

}
}
3 changes: 2 additions & 1 deletion src/main/java/util/CommandsManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,8 @@ public static void load(CommandHandler handler, boolean isClient) {
commands.put(handler.getPrefix() + command.text, true);
});

Seq<String> list = (isClient ? commands.keys().toSeq().filter(c -> c.startsWith(handler.getPrefix())) : commands.keys().toSeq().filter(c -> !c.startsWith(mindustry.Vars.netServer.clientCommands.getPrefix()))),
Seq<String> list = (isClient ? commands.keys().toSeq().filter(c -> c.startsWith(handler.getPrefix())) :
commands.keys().toSeq().filter(c -> !c.startsWith(mindustry.Vars.netServer.clientCommands.getPrefix()))),
comparator = handler.getCommandList().map(command -> command.text);

commands.forEach(command -> {
Expand Down

0 comments on commit 41c4146

Please sign in to comment.