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 Aug 22, 2021
1 parent 4cbfe7e commit 7179c8a
Show file tree
Hide file tree
Showing 3 changed files with 73 additions and 54 deletions.
60 changes: 41 additions & 19 deletions src/main/java/moreCommandsPlugin.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,13 @@ public class moreCommandsPlugin extends mindustry.mod.Plugin {
votesRTV = new ArrayList<>(),
rainbowedPlayers = new ArrayList<>(),
effects = new ArrayList<>(),
adminCommands = new Seq<String>().addAll("team", "am", "kick", "pardon", "ban", "unban", "players", "kill", "tp", "core", "tchat", "spawn", "godmode").list(),
adminCommands = new Seq<String>().addAll("team", "am", "kick", "pardon", "ban", "unban", "players", "kill", "tp", "core", "tchat", "spawn", "godmode", "mute").list(),
bannedClients = new Seq<String>().addAll("VALVE", "tuttop", "CODEX", "IGGGAMES", "IgruhaOrg", "FreeTP.Org").list(),
defaultBannedNames = new Seq<String>().addAll("[Server]", "[server]", "@a", "@p", "@t", "~").list(),
defaultBannedIps = new ArrayList<>(),
bannedIps = new ArrayList<>(),
bannedNames = new ArrayList<>();
bannedNames = new ArrayList<>(),
mutedPlayers = new ArrayList<>();
private ObjectMap<Player, Team> rememberSpectate = new ObjectMap<>();
private ObjectMap<String, Float> godmodPlayers = new ObjectMap<>();
private Map selectedMap;
Expand Down Expand Up @@ -72,7 +73,7 @@ public moreCommandsPlugin() {
Events.on(EventType.WorldLoadEvent.class, e -> canVote = true); //re-enabled vote

Events.on(EventType.PlayerConnect.class, e -> {
//kick the player if there is [Server], [server], or @a in his nickname
//check the nickname of this player
nameCheck(e.player);

//check if the nickname is empty without colors
Expand Down Expand Up @@ -119,7 +120,8 @@ public moreCommandsPlugin() {
//recreate the tchat for the command /tchat
Events.on(EventType.PlayerChatEvent.class, e -> {
if (!e.message.startsWith("/")) {
if (tchat) {
if (mutedPlayers.contains(e.player.uuid())) Players.err(e.player, "You're muted, you can't speak.");
else if (tchat) {
Call.sendMessage(e.message, NetClient.colorizeName(e.player.id, e.player.name), e.player);
Log.info("<" + e.player.name + ": " + e.message + ">");
} else {
Expand Down Expand Up @@ -277,15 +279,11 @@ public void registerServerCommands(CommandHandler handler){
}
});

handler.register("manage-commands", "<list|commandName> [on|off]", "Enable/Disable a command. /!\\Requires server restart to apply changes.", arg -> {
handler.register("commands", "<list|commandName> [on|off]", "Enable/Disable a command. /!\\Requires server restart to apply changes.", arg -> {
if (arg[0].equals("list")) {
StringBuilder builder = new StringBuilder();
Seq<CommandsManager.Commands> client = new Seq<>();
Seq<CommandsManager.Commands> server = new Seq<>();
CommandsManager.copy().forEach(command -> {
if (command.name.startsWith("/")) client.add(command);
else server.add(command);
});
Seq<CommandsManager.Commands> client = new Seq<CommandsManager.Commands>().addAll(CommandsManager.copy().filter(c -> c.name.startsWith("/")));
Seq<CommandsManager.Commands> server = new Seq<CommandsManager.Commands>().addAll(CommandsManager.copy().filter(c -> !c.name.startsWith("/")));
int best1 = bestLength(client);
int best2 = bestLength(server);

Expand All @@ -301,19 +299,19 @@ public void registerServerCommands(CommandHandler handler){
builder = new StringBuilder();
}
} else {
Boolean command = CommandsManager.get(arg[0]);
CommandsManager.Commands command = CommandsManager.get(arg[0]);

if (command == null) Log.err("This command doesn't exist!");
else {
if (arg.length == 2) {
switch (arg[1]) {
case "on": case "true": case "1":
CommandsManager.set(arg[0], true);
command.set(true);
Log.info("Enabled ...");
break;

case "off": case "false": case "0":
CommandsManager.set(arg[0], false);
command.set(false);
Log.info("Disabled ...");
break;

Expand All @@ -323,8 +321,8 @@ public void registerServerCommands(CommandHandler handler){
}
CommandsManager.save();
CommandsManager.update(handler);
} else Log.info("The command '" + arg[0] + "' is currently " + (command ? "enabled" : "disabled"));

} else Log.info("The command '" + command.name + "' is currently " + (command.isActivate ? "enabled" : "disabled"));
}
}
});
Expand Down Expand Up @@ -1311,6 +1309,32 @@ public void run() {
}
});

handler.<Player>register("mute", "<username|ID> [reason...]", "mute a person by name or ID", (arg, player) -> {
if (!Players.adminCheck(player)) return;

Players result = Players.findByNameOrID(arg[0] + (arg.length == 2 ? " " + arg[1] : ""));
Player target = result.player;

if (target == null) Players.err(player, "Nobody with that name or ID could be found...");
else {
mutedPlayers.add(target.uuid());
Call.sendMessage("[scarlet]/!\\" + NetClient.colorizeName(target.id, target.name) + "[scarlet] has been muted of the server.");
Call.infoMessage(target.con, "You have been muted! [lightgray](by " + player.name + "[lightgray]) \n[scarlet]Reason: []" + (arg[1].isBlank() ? "<unknown>" : String.join(" ", result.rest)));
}
});

handler.<Player>register("unmute", "<username|ID>", "unmute a person by name or ID", (arg, player) -> {
if (!Players.adminCheck(player)) return;

Player target = Players.findByNameOrID(arg[0]).player;

if (target == null) Players.err(player, "Nobody with that name or ID could be found...");
else {
mutedPlayers.remove(target.uuid());
Call.infoMessage(target.con, "You have been unmuted! [lightgray](by " + player.name + "[lightgray])");
}
});

handler.<Player>register("kick", "<username|ID> [reason...]", "Kick a person by name or ID", (arg, player) -> {
if (!Players.adminCheck(player)) return;

Expand Down Expand Up @@ -1422,17 +1446,15 @@ private void saveSettings() {
}

private int bestLength(Seq<CommandsManager.Commands> list) {
ArrayList<String> newList = new ArrayList<>();
list.forEach(c -> newList.add(c.name));
return Strings.bestLength(newList);
return Strings.bestLength(list.map(c -> c.name).list());
}

private void setHandler(CommandHandler handler) {
new Thread() {
public void run() {
try {
Thread.sleep(1000);
CommandsManager.load(handler, netServer.clientCommands.getPrefix().equals(handler.getPrefix()));
CommandsManager.load(handler);
} catch (InterruptedException e) { e.printStackTrace(); }
}
}.start();
Expand Down
65 changes: 31 additions & 34 deletions src/main/java/util/CommandsManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,38 +4,32 @@
import arc.struct.ObjectMap;
import arc.struct.Seq;
import arc.util.CommandHandler;
import arc.util.Log;


public class CommandsManager {
private static ObjectMap<String, Boolean> commands = new ObjectMap<>(), temp = new ObjectMap<>();
private static String clientPrefix = mindustry.Vars.netServer.clientCommands.getPrefix();
private static volatile boolean canLoad = false;

public static Boolean get(String name) {
return commands.get(name);
public static Commands get(String name) {
Boolean result = commands.get(name);
return result == null ? null : new Commands(name, result);
}

public static boolean set(String name, boolean value) {
return commands.put(name, value);
public static void add(String name, boolean value) {
commands.put(name, value);
}

public static Seq<Commands> copy() {
Seq<Commands> copy = new Seq<>();
commands.forEach(command -> copy.add(new Commands(command.key, command.value)));
return copy;
Seq<Commands> result = new Seq<>();
commands.forEach(c -> result.add(new Commands(c.key, c.value)));

return result;
}

public static void save() {
StringBuilder builder = new StringBuilder();

if (!commands.isEmpty())
commands.forEach(command -> {
builder.append(command.key + " - ");
if (command.value) builder.append(1 + " | ");
else builder.append(0 + " | ");
});
else builder.append("");

Core.settings.put("handlerManager", builder.toString());
Core.settings.put("handlerManager", commands.toString(" | "));
Core.settings.forceSave();
}

Expand All @@ -44,24 +38,24 @@ public static void update(CommandHandler handler) {
if (command.value != temp.get(command.key)) {
handler.removeCommand("host");

handler.register("host", "[mapname] [mode]", "Open the server. Will default to survival and a random map if not specified.", arg -> {
arc.util.Log.warn("Changes have been made. Please restart the server for them to take effect. (tip: write 'exit' to shut down the server)");
});
handler.register("host", "[mapname] [mode]", "Open the server. Will default to survival and a random map if not specified.", arg ->
Log.warn("Changes have been made. Please restart the server for them to take effect. (tip: write 'exit' to shut down the server)")
);
return;
}
});
}

public static void load(CommandHandler handler, boolean isClient) {
public static void load(CommandHandler handler) {
while (!canLoad) {}

handler.getCommandList().forEach(command -> {
if (!commands.containsKey(handler.getPrefix() + command.text))
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 = (clientPrefix.equals(handler.getPrefix()) ? commands.keys().toSeq().filter(c -> c.startsWith(handler.getPrefix())) :
commands.keys().toSeq().filter(c -> !c.startsWith(clientPrefix))),
comparator = handler.getCommandList().map(command -> command.text);

commands.forEach(command -> {
Expand All @@ -79,16 +73,14 @@ public static void init() {
String content = Core.settings.has("handlerManager") ? Core.settings.getString("handlerManager") : "";

if (!content.equals("")) {
String[] temp;

for (String line : content.split(" \\| ")) {
temp = line.split(" \\- ");

if (temp.length == 2) {
if (temp[1].equals("1")) commands.put(temp[0], true);
else commands.put(temp[0], false);
try {
String[] temp;
for (String line : content.split(" \\| ")) {
temp = line.split("\\=");
commands.put(temp[0], Boolean.parseBoolean(temp[1]));
}
}
} catch (Exception e) { save(); }

} else save();

canLoad = true;
Expand All @@ -102,11 +94,16 @@ public static void clearSave() {

public static class Commands {
public final String name;
public final boolean isActivate;
public boolean isActivate;

private Commands(String name, boolean isActivate) {
this.name = name;
this.isActivate = isActivate;
}

public void set(boolean value) {
commands.put(name, value);
this.isActivate = value;
}
}
}
2 changes: 1 addition & 1 deletion src/main/resources/plugin.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@
"author": "Susideur (map)",
"main": "moreCommandsPlugin",
"description": "This mindustry plugin add more commands for admins and players.",
"version": 8.2
"version": 8.3
}

0 comments on commit 7179c8a

Please sign in to comment.