mirror of
https://github.com/AtlasMediaGroup/TotalFreedomMod.git
synced 2024-11-26 17:05:01 +00:00
Resolves FS-318 by rewriting the /mute command
This has the fortunate side-effect of also fixing several bugs present in the original command.
This commit is contained in:
parent
f0d6549eec
commit
af18299613
@ -1,7 +1,5 @@
|
||||
package me.totalfreedom.totalfreedommod;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import me.totalfreedom.totalfreedommod.config.ConfigEntry;
|
||||
import me.totalfreedom.totalfreedommod.player.FPlayer;
|
||||
import me.totalfreedom.totalfreedommod.util.FLog;
|
||||
@ -13,13 +11,9 @@ import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.player.AsyncPlayerChatEvent;
|
||||
import org.bukkit.event.player.PlayerCommandPreprocessEvent;
|
||||
import org.bukkit.event.player.PlayerJoinEvent;
|
||||
|
||||
public class Muter extends FreedomService
|
||||
{
|
||||
|
||||
public final List<String> MUTED_PLAYERS = new ArrayList<>();
|
||||
|
||||
@Override
|
||||
public void onStart()
|
||||
{
|
||||
@ -45,7 +39,6 @@ public class Muter extends FreedomService
|
||||
if (plugin.al.isAdminSync(player))
|
||||
{
|
||||
fPlayer.setMuted(false);
|
||||
MUTED_PLAYERS.remove(player.getName());
|
||||
return;
|
||||
}
|
||||
|
||||
@ -98,16 +91,4 @@ public class Muter extends FreedomService
|
||||
FLog.info(String.format("[PREPROCESS_COMMAND] %s(%s): %s", player.getName(), ChatColor.stripColor(player.getDisplayName()), message), true);
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.LOW)
|
||||
public void onPlayerJoin(PlayerJoinEvent event)
|
||||
{
|
||||
Player player = event.getPlayer();
|
||||
FPlayer playerdata = plugin.pl.getPlayer(player);
|
||||
|
||||
if (MUTED_PLAYERS.contains(player.getName()))
|
||||
{
|
||||
playerdata.setMuted(true);
|
||||
}
|
||||
}
|
||||
}
|
@ -14,7 +14,7 @@ import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
@CommandPermissions(level = Rank.ADMIN, source = SourceType.BOTH)
|
||||
@CommandParameters(description = "Restricts/restores block modification abilities for everyone on the server or a certain player.", usage = "/<command> [[-s] <player> [reason] | list | purge | all]")
|
||||
@CommandParameters(description = "Restricts/restores block modification abilities for everyone on the server or a certain player.", usage = "/<command> [<player> [reason] | list | purge | all]")
|
||||
public class Command_blockedit extends FreedomCommand
|
||||
{
|
||||
@Override
|
||||
|
@ -1,10 +1,6 @@
|
||||
package me.totalfreedom.totalfreedommod.command;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import me.totalfreedom.totalfreedommod.player.FPlayer;
|
||||
import java.util.*;
|
||||
import me.totalfreedom.totalfreedommod.punishments.Punishment;
|
||||
import me.totalfreedom.totalfreedommod.punishments.PunishmentType;
|
||||
import me.totalfreedom.totalfreedommod.rank.Rank;
|
||||
@ -20,7 +16,6 @@ import org.bukkit.entity.Player;
|
||||
@CommandParameters(description = "Mutes a player with brute force.", usage = "/<command> <[-s | -q] <player> [reason] | list | purge | all>", aliases = "stfu")
|
||||
public class Command_mute extends FreedomCommand
|
||||
{
|
||||
|
||||
@Override
|
||||
public boolean run(CommandSender sender, Player playerSender, Command cmd, String commandLabel, String[] args, boolean senderIsConsole)
|
||||
{
|
||||
@ -29,134 +24,110 @@ public class Command_mute extends FreedomCommand
|
||||
return false;
|
||||
}
|
||||
|
||||
if (args[0].equalsIgnoreCase("list"))
|
||||
switch (args[0].toLowerCase())
|
||||
{
|
||||
case "list" ->
|
||||
{
|
||||
msg("Muted players:");
|
||||
FPlayer info;
|
||||
int count = 0;
|
||||
for (Player mp : server.getOnlinePlayers())
|
||||
{
|
||||
info = plugin.pl.getPlayer(mp);
|
||||
if (info.isMuted())
|
||||
{
|
||||
msg("- " + mp.getName());
|
||||
count++;
|
||||
}
|
||||
}
|
||||
if (count == 0)
|
||||
{
|
||||
List<? extends Player> list = server.getOnlinePlayers().stream().filter(player ->
|
||||
plugin.pl.getPlayer(player).isMuted()).toList();
|
||||
|
||||
if (list.size() > 0)
|
||||
list.forEach(player -> msg("- " + player.getName()));
|
||||
else
|
||||
msg("- none");
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
if (args[0].equalsIgnoreCase("purge"))
|
||||
case "purge" ->
|
||||
{
|
||||
FUtil.adminAction(sender.getName(), "Unmuting all players.", true);
|
||||
FPlayer info;
|
||||
int count = 0;
|
||||
for (Player mp : server.getOnlinePlayers())
|
||||
{
|
||||
info = plugin.pl.getPlayer(mp);
|
||||
if (info.isMuted())
|
||||
{
|
||||
info.setMuted(false);
|
||||
mp.sendTitle(ChatColor.RED + "You've been unmuted.", ChatColor.YELLOW + "Be sure to follow the rules!", 20, 100, 60);
|
||||
count++;
|
||||
}
|
||||
}
|
||||
plugin.mu.MUTED_PLAYERS.clear();
|
||||
msg("Unmuted " + count + " players.");
|
||||
return true;
|
||||
}
|
||||
FUtil.adminAction(sender.getName(), "Unmuting all players", true);
|
||||
List<? extends Player> list = server.getOnlinePlayers().stream().filter(player ->
|
||||
plugin.pl.getPlayer(player).isMuted()).toList();
|
||||
|
||||
if (args[0].equalsIgnoreCase("all"))
|
||||
list.forEach(player ->
|
||||
{
|
||||
plugin.pl.getPlayer(player).setMuted(false);
|
||||
player.sendTitle(ChatColor.RED + "You have been unmuted.",
|
||||
ChatColor.YELLOW + "Be sure to follow the rules!", 20, 100, 60);
|
||||
});
|
||||
|
||||
msg("Unmuted " + list.size() + " player" + (list.size() != 1 ? "s" : "") + ".");
|
||||
}
|
||||
case "all" ->
|
||||
{
|
||||
FUtil.adminAction(sender.getName(), "Muting all non-admins", true);
|
||||
List<? extends Player> list = server.getOnlinePlayers().stream().filter(player ->
|
||||
!plugin.al.isAdmin(player)).toList();
|
||||
|
||||
FPlayer playerdata;
|
||||
int counter = 0;
|
||||
for (Player player : server.getOnlinePlayers())
|
||||
list.forEach(player ->
|
||||
{
|
||||
if (!plugin.al.isAdmin(player))
|
||||
{
|
||||
player.sendTitle(ChatColor.RED + "You've been muted globally.", ChatColor.YELLOW + "Please be patient and you will be unmuted shortly.", 20, 100, 60);
|
||||
playerdata = plugin.pl.getPlayer(player);
|
||||
playerdata.setMuted(true);
|
||||
counter++;
|
||||
}
|
||||
}
|
||||
plugin.pl.getPlayer(player).setMuted(true);
|
||||
player.sendTitle(ChatColor.RED + "You've been muted globally.",
|
||||
ChatColor.YELLOW + "Please be patient and you will be unmuted shortly.", 20, 100, 60);
|
||||
});
|
||||
|
||||
msg("Muted " + counter + " players.");
|
||||
return true;
|
||||
msg("Muted " + list.size() + " player" + (list.size() != 1 ? "s" : "") + ".");
|
||||
}
|
||||
|
||||
// -s option (smite)
|
||||
boolean smite = args[0].equals("-s");
|
||||
// -q option (shadowmute)
|
||||
boolean quiet = args[0].equals("-q");
|
||||
if (smite || quiet)
|
||||
default ->
|
||||
{
|
||||
boolean quiet = args[0].equalsIgnoreCase("-q");
|
||||
boolean smite = args[0].equalsIgnoreCase("-s");
|
||||
|
||||
// Handling the -q parameter
|
||||
if (quiet || smite)
|
||||
{
|
||||
if (args.length == 1) return false;
|
||||
args = ArrayUtils.subarray(args, 1, args.length);
|
||||
}
|
||||
|
||||
if (args.length < 1)
|
||||
// Handling the (optional) reason
|
||||
String reason = args.length > 1 ? StringUtils.join(args, " ", 1, args.length) : null;
|
||||
|
||||
// Showtime
|
||||
Optional.ofNullable(getPlayer(args[0])).ifPresentOrElse(player ->
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
final Player player = getPlayer(args[0]);
|
||||
if (player == null)
|
||||
{
|
||||
msg(PLAYER_NOT_FOUND);
|
||||
return true;
|
||||
}
|
||||
|
||||
String reason = null;
|
||||
if (args.length > 1)
|
||||
{
|
||||
reason = StringUtils.join(args, " ", 1, args.length);
|
||||
}
|
||||
|
||||
FPlayer playerdata = plugin.pl.getPlayer(player);
|
||||
if (plugin.al.isAdmin(player))
|
||||
{
|
||||
msg(player.getName() + " is an admin, and can't be muted.");
|
||||
return true;
|
||||
msg(player.getName() + " is an admin, and as such can't be muted.", ChatColor.RED);
|
||||
return;
|
||||
}
|
||||
else if (plugin.pl.getPlayer(player).isMuted())
|
||||
{
|
||||
msg(player.getName() + " is already muted.", ChatColor.RED);
|
||||
return;
|
||||
}
|
||||
|
||||
if (!playerdata.isMuted())
|
||||
// Don't broadcast the mute if it was quiet
|
||||
if (!quiet)
|
||||
{
|
||||
playerdata.setMuted(true);
|
||||
player.sendTitle(ChatColor.RED + "You've been muted.", ChatColor.YELLOW + "Be sure to follow the rules!", 20, 100, 60);
|
||||
|
||||
if (quiet)
|
||||
{
|
||||
msg("Muted " + player.getName() + " quietly");
|
||||
return true; // doesn't announce reason
|
||||
}
|
||||
|
||||
FUtil.adminAction(sender.getName(), "Muting " + player.getName(), true);
|
||||
|
||||
if (reason != null)
|
||||
{
|
||||
msg(player, ChatColor.RED + "Reason: " + ChatColor.YELLOW + reason);
|
||||
}
|
||||
|
||||
// Smite the player if we're supposed to
|
||||
if (smite)
|
||||
{
|
||||
Command_smite.smite(sender, player, reason);
|
||||
Command_smite.smite(sender, player, reason, true, false);
|
||||
}
|
||||
|
||||
msg(player, "You have been muted by " + ChatColor.YELLOW + sender.getName(), ChatColor.RED);
|
||||
msg("Muted " + player.getName());
|
||||
// Mutes the player
|
||||
plugin.pl.getPlayer(player).setMuted(true);
|
||||
|
||||
plugin.pul.logPunishment(new Punishment(player.getName(), FUtil.getIp(player), sender.getName(), PunishmentType.MUTE, reason));
|
||||
}
|
||||
else
|
||||
// Notify the player that they have been muted
|
||||
player.sendTitle(ChatColor.RED + "You've been muted.",
|
||||
ChatColor.YELLOW + "Be sure to follow the rules!", 20, 100, 60);
|
||||
msg(player, "You have been muted by " + ChatColor.YELLOW + sender.getName()
|
||||
+ ChatColor.RED + ".", ChatColor.RED);
|
||||
|
||||
// Give them the reason if one is present.
|
||||
if (reason != null)
|
||||
{
|
||||
msg(ChatColor.RED + "That player is already muted.");
|
||||
msg(player, "Reason: " + ChatColor.YELLOW + reason, ChatColor.RED);
|
||||
}
|
||||
|
||||
msg((quiet ? "Quietly m" : "M") + "uted " + player.getName() + ".");
|
||||
plugin.pul.logPunishment(new Punishment(player.getName(), FUtil.getIp(player), sender.getName(),
|
||||
PunishmentType.MUTE, reason));
|
||||
}, () -> msg(PLAYER_NOT_FOUND));
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
|
@ -294,7 +294,6 @@ public class FPlayer
|
||||
public void setMuted(boolean muted, int minutes)
|
||||
{
|
||||
FUtil.cancel(unmuteTask);
|
||||
plugin.mu.MUTED_PLAYERS.remove(getPlayer().getName());
|
||||
unmuteTask = null;
|
||||
|
||||
if (!muted)
|
||||
@ -307,8 +306,6 @@ public class FPlayer
|
||||
return;
|
||||
}
|
||||
|
||||
plugin.mu.MUTED_PLAYERS.add(getPlayer().getName());
|
||||
|
||||
// TODO: Simplify this into a Consumer<BukkitTask> lambda?
|
||||
unmuteTask = new BukkitRunnable()
|
||||
{
|
||||
@ -323,7 +320,6 @@ public class FPlayer
|
||||
else
|
||||
{
|
||||
FUtil.adminAction(ConfigEntry.SERVER_NAME.getString(), "Unmuting " + getName(), false);
|
||||
plugin.mu.MUTED_PLAYERS.remove(getName());
|
||||
}
|
||||
}
|
||||
}.runTaskLater(plugin, minutes * (60L * 20L));
|
||||
|
Loading…
Reference in New Issue
Block a user