TFM-4.3-Reloaded/src/main/java/me/StevenLawson/TotalFreedomMod/commands/Command_stfu.java

111 lines
3.6 KiB
Java
Raw Normal View History

2022-03-20 12:35:43 +00:00
package me.StevenLawson.TotalFreedomMod.commands;
import me.StevenLawson.TotalFreedomMod.admin.AdminList;
import me.StevenLawson.TotalFreedomMod.player.PlayerData;
import me.StevenLawson.TotalFreedomMod.util.Utilities;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
@CommandPermissions(level = AdminLevel.SUPER, source = SourceType.BOTH)
public class Command_stfu extends FreedomCommand {
@Override
public boolean run(CommandSender sender, org.bukkit.entity.Player sender_p, Command cmd, String commandLabel, String[] args, boolean senderIsConsole) {
if (args.length == 0 || args.length > 2) {
return false;
}
if (args[0].equalsIgnoreCase("list")) {
2022-03-23 23:48:41 +00:00
playerMsg(sender, "Muted players:");
2022-03-20 12:35:43 +00:00
PlayerData info;
int count = 0;
for (Player mp : server.getOnlinePlayers())
{
info = PlayerData.getPlayerData(mp);
if (info.isMuted())
{
2022-03-23 23:48:41 +00:00
playerMsg(sender, "- " + mp.getName());
2022-03-20 12:35:43 +00:00
count++;
}
}
if (count == 0)
{
2022-03-23 23:48:41 +00:00
playerMsg(sender, "- none");
2022-03-20 12:35:43 +00:00
}
}
else if (args[0].equalsIgnoreCase("purge"))
{
Utilities.adminAction(sender.getName(), "Unmuting all players.", true);
PlayerData info;
int count = 0;
for (Player mp : server.getOnlinePlayers())
{
info = PlayerData.getPlayerData(mp);
if (info.isMuted())
{
info.setMuted(false);
count++;
}
}
2022-03-23 23:48:41 +00:00
playerMsg(sender, "Unmuted " + count + " players.");
2022-03-20 12:35:43 +00:00
}
else if (args[0].equalsIgnoreCase("all"))
{
Utilities.adminAction(sender.getName(), "Muting all non-Superadmins", true);
PlayerData playerdata;
int counter = 0;
for (Player player : server.getOnlinePlayers())
{
if (!AdminList.isSuperAdmin(player))
{
playerdata = PlayerData.getPlayerData(player);
playerdata.setMuted(true);
counter++;
}
}
2022-03-23 23:48:41 +00:00
playerMsg(sender, "Muted " + counter + " players.");
2022-03-20 12:35:43 +00:00
}
else
{
final Player player = getPlayer(args[0]);
if (player == null)
{
sender.sendMessage(FreedomCommand.PLAYER_NOT_FOUND);
return true;
}
PlayerData playerdata = PlayerData.getPlayerData(player);
if (playerdata.isMuted())
{
Utilities.adminAction(sender.getName(), "Unmuting " + player.getName(), true);
playerdata.setMuted(false);
2022-03-23 23:48:41 +00:00
playerMsg(sender, "Unmuted " + player.getName());
2022-03-20 12:35:43 +00:00
}
else
{
if (!AdminList.isSuperAdmin(player))
{
Utilities.adminAction(sender.getName(), "Muting " + player.getName(), true);
playerdata.setMuted(true);
if (args.length == 2 && args[1].equalsIgnoreCase("-s"))
{
Command_smite.smite(player);
}
2022-03-23 23:48:41 +00:00
playerMsg(sender, "Muted " + player.getName());
2022-03-20 12:35:43 +00:00
}
else
{
2022-03-23 23:48:41 +00:00
playerMsg(sender, player.getName() + " is a superadmin, and can't be muted.");
2022-03-20 12:35:43 +00:00
}
}
}
return true;
}
}