49 lines
1.8 KiB
Java
49 lines
1.8 KiB
Java
package com.alttd.chat.commands;
|
|
|
|
import com.alttd.chat.ChatPlugin;
|
|
import com.alttd.chat.config.Config;
|
|
import com.alttd.chat.util.Utility;
|
|
import net.kyori.adventure.text.ComponentLike;
|
|
import org.bukkit.Bukkit;
|
|
import org.bukkit.command.Command;
|
|
import org.bukkit.command.CommandExecutor;
|
|
import org.bukkit.command.CommandSender;
|
|
import org.bukkit.entity.Player;
|
|
import org.bukkit.scheduler.BukkitRunnable;
|
|
import org.jetbrains.annotations.NotNull;
|
|
|
|
import java.util.UUID;
|
|
|
|
public class MuteServer implements CommandExecutor {
|
|
|
|
@Override
|
|
public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, String[] args) {
|
|
if (!(sender instanceof Player player)) { // must be a player
|
|
return true;
|
|
}
|
|
new BukkitRunnable() {
|
|
@Override
|
|
public void run() {
|
|
UUID uuid = player.getUniqueId();
|
|
if (!Utility.hasPermission(uuid, Config.SERVERMUTEPERMISSION)) {
|
|
sender.sendRichMessage("<red>You don't have permission to use this command.</red>");
|
|
return;
|
|
}
|
|
|
|
ChatPlugin.getInstance().toggleServerMuted();
|
|
|
|
ComponentLike component;
|
|
if (ChatPlugin.getInstance().serverMuted()) {
|
|
component = Utility.parseMiniMessage(Utility.getDisplayName(player.getUniqueId(), player.getName()) + " <red>muted</red><white> chat.");
|
|
} else {
|
|
component = Utility.parseMiniMessage(Utility.getDisplayName(player.getUniqueId(), player.getName()) + " <green>un-muted</green><white> chat.");
|
|
}
|
|
|
|
Bukkit.getOnlinePlayers().forEach(player -> player.sendMessage(component));
|
|
}
|
|
}.runTaskAsynchronously(ChatPlugin.getInstance());
|
|
return false;
|
|
}
|
|
|
|
}
|