Skip to content

Commit

Permalink
Mute improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
buj committed Nov 3, 2024
1 parent 57ac0aa commit e5370be
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 9 deletions.
12 changes: 10 additions & 2 deletions src/main/java/darkdustry/commands/ClientCommands.java
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,6 @@ public static void load() {
netServer.sendWorldData(player);
});

Commands.create("t").register((args, player) -> Translator.translate(other -> other.team() == player.team(), player, args[0], "commands.t.chat", player.team().color, player.coloredName()));
Commands.create("players").register(PageIterator::players);

Commands.create("settings")
Expand Down Expand Up @@ -287,5 +286,14 @@ public static void load() {
Admins.unmute(target);
Bundle.send(player, "commands.unmute.success", target.coloredName());
});

Commands.create("t")
.register((args, player) -> {
if (Admins.checkMuted(player)) {
Bundle.send(player, "commands.mute.message");
return;
}
Translator.translate(other -> other.team() == player.team(), player, args[0], "commands.t.chat", player.team().color, player.coloredName());
});
}
}
}
3 changes: 2 additions & 1 deletion src/main/java/darkdustry/features/Ranks.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import arc.struct.Seq;
import darkdustry.database.models.PlayerData;
import darkdustry.utils.Admins;
import lombok.NoArgsConstructor;
import mindustry.gen.Player;
import useful.Bundle;
Expand All @@ -11,7 +12,7 @@ public class Ranks {
public static final Seq<Rank> ranks = Seq.with(Rank.values());

public static void name(Player player, PlayerData data) {
player.name = data.name = data.rank.tag + player.getInfo().lastName;
player.name = data.name = data.rank.tag + player.getInfo().lastName + (Admins.checkMuted(player) ? " [gray](muted)" : "");
}

@NoArgsConstructor
Expand Down
11 changes: 10 additions & 1 deletion src/main/java/darkdustry/listeners/PluginEvents.java
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
package darkdustry.listeners;

import arc.Events;
import arc.struct.ObjectMap;
import arc.util.*;
import arc.util.Timer.Task;
import darkdustry.database.*;
import darkdustry.features.*;
import darkdustry.features.history.*;
import darkdustry.features.menus.MenuHandler;
import darkdustry.features.net.Socket;
import darkdustry.listeners.SocketEvents.ServerMessageEmbedEvent;
import darkdustry.utils.Admins;
import darkdustry.utils.Utils;
import discord4j.rest.util.Color;
import mindustry.content.*;
Expand All @@ -31,6 +34,7 @@
import static mindustry.server.ServerControl.*;

public class PluginEvents {
public static ObjectMap<Player, Task> updateNameTasks = new ObjectMap<>();

public static void load() {
if (config.allowSpecialSettings) SpecialSettings.load();
Expand Down Expand Up @@ -179,6 +183,11 @@ else if (data.discordLink)
Bundle.send(event.player, event.player.con.mobile ?
"welcome.message.mobile" :
"welcome.message", serverName.string(), discordServerUrl);

var mute = Database.getMute(event.player.uuid());
if (mute != null) {
updateNameTasks.put(event.player, Timer.schedule(() -> Ranks.name(event.player, data), (float) (mute.remaining()) / 1000 + 10));
}
});

Events.on(PlayerLeave.class, event -> {
Expand Down Expand Up @@ -351,4 +360,4 @@ else if (data.discordLink)
Log.info("Finished in " + passed);
}, config.backupDelaySec, config.backupDelaySec);
}
}
}
19 changes: 16 additions & 3 deletions src/main/java/darkdustry/listeners/SocketEvents.java
Original file line number Diff line number Diff line change
Expand Up @@ -67,11 +67,24 @@ public static void load() {

Socket.on(MuteEvent.class, event -> Groups.player.each(
player -> player.uuid().equals(event.mute.uuid),
player -> Cache.mutes.put(player.uuid(), event.mute)));
player -> {
Cache.mutes.put(player.uuid(), event.mute);
val data = Database.getPlayerDataOrCreate(player.uuid());
Ranks.name(player, data);

var mute = Database.getMute(player.uuid());
if (mute != null) {
var previous = PluginEvents.updateNameTasks.put(player, Timer.schedule(() -> Ranks.name(player, data), (float) (mute.remaining()) / 1000 + 10));
if (previous != null) previous.cancel();
}
}));

Socket.on(UnmuteEvent.class, event -> Groups.player.each(
player -> player.uuid().equals(event.uuid),
player -> Cache.mutes.put(player.uuid(), null)));
player -> {
Cache.mutes.remove(player.uuid());
Ranks.name(player, Database.getPlayerDataOrCreate(player.uuid()));
}));

Socket.on(BanEvent.class, event -> Groups.player.each(
player -> player.uuid().equals(event.ban.uuid) || player.ip().equals(event.ban.ip),
Expand Down Expand Up @@ -443,4 +456,4 @@ public EmbedResponse withFooter(String footer, Object... args) {
public record Field(String name, String value) {
}
}
}
}
4 changes: 2 additions & 2 deletions src/main/resources/plugin.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
"displayName": "Darkdustry Plugin",
"author": "Darkness & xzxADIxzx",
"description": "The main plugin for Darkdustry servers. Includes a lot of useful features.",
"version": "6.11",
"version": "6.12",
"main": "darkdustry.DarkdustryPlugin",
"repo": "Darkdustry-Coders/DarkdustryPlugin",
"dependencies": []
}
}

0 comments on commit e5370be

Please sign in to comment.