mirror of
https://github.com/AtlasMediaGroup/TotalFreedomMod.git
synced 2024-11-01 05:57:09 +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
36663385ab
commit
1937a3d4de
@ -1,7 +1,5 @@
|
|||||||
package me.totalfreedom.totalfreedommod;
|
package me.totalfreedom.totalfreedommod;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
|
||||||
import me.totalfreedom.totalfreedommod.config.ConfigEntry;
|
import me.totalfreedom.totalfreedommod.config.ConfigEntry;
|
||||||
import me.totalfreedom.totalfreedommod.player.FPlayer;
|
import me.totalfreedom.totalfreedommod.player.FPlayer;
|
||||||
import me.totalfreedom.totalfreedommod.util.FLog;
|
import me.totalfreedom.totalfreedommod.util.FLog;
|
||||||
@ -13,13 +11,9 @@ import org.bukkit.event.EventHandler;
|
|||||||
import org.bukkit.event.EventPriority;
|
import org.bukkit.event.EventPriority;
|
||||||
import org.bukkit.event.player.AsyncPlayerChatEvent;
|
import org.bukkit.event.player.AsyncPlayerChatEvent;
|
||||||
import org.bukkit.event.player.PlayerCommandPreprocessEvent;
|
import org.bukkit.event.player.PlayerCommandPreprocessEvent;
|
||||||
import org.bukkit.event.player.PlayerJoinEvent;
|
|
||||||
|
|
||||||
public class Muter extends FreedomService
|
public class Muter extends FreedomService
|
||||||
{
|
{
|
||||||
|
|
||||||
public final List<String> MUTED_PLAYERS = new ArrayList<>();
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onStart()
|
public void onStart()
|
||||||
{
|
{
|
||||||
@ -45,7 +39,6 @@ public class Muter extends FreedomService
|
|||||||
if (plugin.al.isAdminSync(player))
|
if (plugin.al.isAdminSync(player))
|
||||||
{
|
{
|
||||||
fPlayer.setMuted(false);
|
fPlayer.setMuted(false);
|
||||||
MUTED_PLAYERS.remove(player.getName());
|
|
||||||
return;
|
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);
|
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;
|
import java.util.Optional;
|
||||||
|
|
||||||
@CommandPermissions(level = Rank.ADMIN, source = SourceType.BOTH)
|
@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
|
public class Command_blockedit extends FreedomCommand
|
||||||
{
|
{
|
||||||
@Override
|
@Override
|
||||||
|
@ -1,10 +1,6 @@
|
|||||||
package me.totalfreedom.totalfreedommod.command;
|
package me.totalfreedom.totalfreedommod.command;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.*;
|
||||||
import java.util.Arrays;
|
|
||||||
import java.util.Collections;
|
|
||||||
import java.util.List;
|
|
||||||
import me.totalfreedom.totalfreedommod.player.FPlayer;
|
|
||||||
import me.totalfreedom.totalfreedommod.punishments.Punishment;
|
import me.totalfreedom.totalfreedommod.punishments.Punishment;
|
||||||
import me.totalfreedom.totalfreedommod.punishments.PunishmentType;
|
import me.totalfreedom.totalfreedommod.punishments.PunishmentType;
|
||||||
import me.totalfreedom.totalfreedommod.rank.Rank;
|
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")
|
@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
|
public class Command_mute extends FreedomCommand
|
||||||
{
|
{
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean run(CommandSender sender, Player playerSender, Command cmd, String commandLabel, String[] args, boolean senderIsConsole)
|
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;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (args[0].equalsIgnoreCase("list"))
|
switch (args[0].toLowerCase())
|
||||||
{
|
{
|
||||||
msg("Muted players:");
|
case "list" ->
|
||||||
FPlayer info;
|
|
||||||
int count = 0;
|
|
||||||
for (Player mp : server.getOnlinePlayers())
|
|
||||||
{
|
{
|
||||||
info = plugin.pl.getPlayer(mp);
|
msg("Muted players:");
|
||||||
if (info.isMuted())
|
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");
|
||||||
|
}
|
||||||
|
case "purge" ->
|
||||||
|
{
|
||||||
|
FUtil.adminAction(sender.getName(), "Unmuting all players", true);
|
||||||
|
List<? extends Player> list = server.getOnlinePlayers().stream().filter(player ->
|
||||||
|
plugin.pl.getPlayer(player).isMuted()).toList();
|
||||||
|
|
||||||
|
list.forEach(player ->
|
||||||
{
|
{
|
||||||
msg("- " + mp.getName());
|
plugin.pl.getPlayer(player).setMuted(false);
|
||||||
count++;
|
player.sendTitle(ChatColor.RED + "You have been unmuted.",
|
||||||
}
|
ChatColor.YELLOW + "Be sure to follow the rules!", 20, 100, 60);
|
||||||
}
|
});
|
||||||
if (count == 0)
|
|
||||||
{
|
|
||||||
msg("- none");
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
msg("Unmuted " + list.size() + " player" + (list.size() != 1 ? "s" : "") + ".");
|
||||||
}
|
}
|
||||||
|
case "all" ->
|
||||||
if (args[0].equalsIgnoreCase("purge"))
|
|
||||||
{
|
|
||||||
FUtil.adminAction(sender.getName(), "Unmuting all players.", true);
|
|
||||||
FPlayer info;
|
|
||||||
int count = 0;
|
|
||||||
for (Player mp : server.getOnlinePlayers())
|
|
||||||
{
|
{
|
||||||
info = plugin.pl.getPlayer(mp);
|
FUtil.adminAction(sender.getName(), "Muting all non-admins", true);
|
||||||
if (info.isMuted())
|
List<? extends Player> list = server.getOnlinePlayers().stream().filter(player ->
|
||||||
|
!plugin.al.isAdmin(player)).toList();
|
||||||
|
|
||||||
|
list.forEach(player ->
|
||||||
{
|
{
|
||||||
info.setMuted(false);
|
plugin.pl.getPlayer(player).setMuted(true);
|
||||||
mp.sendTitle(ChatColor.RED + "You've been unmuted.", ChatColor.YELLOW + "Be sure to follow the rules!", 20, 100, 60);
|
player.sendTitle(ChatColor.RED + "You've been muted globally.",
|
||||||
count++;
|
ChatColor.YELLOW + "Please be patient and you will be unmuted shortly.", 20, 100, 60);
|
||||||
}
|
});
|
||||||
|
|
||||||
|
msg("Muted " + list.size() + " player" + (list.size() != 1 ? "s" : "") + ".");
|
||||||
}
|
}
|
||||||
plugin.mu.MUTED_PLAYERS.clear();
|
default ->
|
||||||
msg("Unmuted " + count + " players.");
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (args[0].equalsIgnoreCase("all"))
|
|
||||||
{
|
|
||||||
FUtil.adminAction(sender.getName(), "Muting all non-admins", true);
|
|
||||||
|
|
||||||
FPlayer playerdata;
|
|
||||||
int counter = 0;
|
|
||||||
for (Player player : server.getOnlinePlayers())
|
|
||||||
{
|
{
|
||||||
if (!plugin.al.isAdmin(player))
|
boolean quiet = args[0].equalsIgnoreCase("-q");
|
||||||
|
boolean smite = args[0].equalsIgnoreCase("-s");
|
||||||
|
|
||||||
|
// Handling the -q parameter
|
||||||
|
if (quiet || smite)
|
||||||
{
|
{
|
||||||
player.sendTitle(ChatColor.RED + "You've been muted globally.", ChatColor.YELLOW + "Please be patient and you will be unmuted shortly.", 20, 100, 60);
|
if (args.length == 1) return false;
|
||||||
playerdata = plugin.pl.getPlayer(player);
|
args = ArrayUtils.subarray(args, 1, args.length);
|
||||||
playerdata.setMuted(true);
|
|
||||||
counter++;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Handling the (optional) reason
|
||||||
|
String reason = args.length > 1 ? StringUtils.join(args, " ", 1, args.length) : null;
|
||||||
|
|
||||||
|
// Showtime
|
||||||
|
Optional.ofNullable(getPlayer(args[0])).ifPresentOrElse(player ->
|
||||||
|
{
|
||||||
|
if (plugin.al.isAdmin(player))
|
||||||
|
{
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Don't broadcast the mute if it was quiet
|
||||||
|
if (!quiet)
|
||||||
|
{
|
||||||
|
FUtil.adminAction(sender.getName(), "Muting " + player.getName(), true);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Smite the player if we're supposed to
|
||||||
|
if (smite)
|
||||||
|
{
|
||||||
|
Command_smite.smite(sender, player, reason, true, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Mutes the player
|
||||||
|
plugin.pl.getPlayer(player).setMuted(true);
|
||||||
|
|
||||||
|
// 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(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));
|
||||||
}
|
}
|
||||||
|
|
||||||
msg("Muted " + counter + " players.");
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
// -s option (smite)
|
|
||||||
boolean smite = args[0].equals("-s");
|
|
||||||
// -q option (shadowmute)
|
|
||||||
boolean quiet = args[0].equals("-q");
|
|
||||||
if (smite || quiet)
|
|
||||||
{
|
|
||||||
args = ArrayUtils.subarray(args, 1, args.length);
|
|
||||||
|
|
||||||
if (args.length < 1)
|
|
||||||
{
|
|
||||||
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;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!playerdata.isMuted())
|
|
||||||
{
|
|
||||||
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);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (smite)
|
|
||||||
{
|
|
||||||
Command_smite.smite(sender, player, reason);
|
|
||||||
}
|
|
||||||
|
|
||||||
msg(player, "You have been muted by " + ChatColor.YELLOW + sender.getName(), ChatColor.RED);
|
|
||||||
msg("Muted " + player.getName());
|
|
||||||
|
|
||||||
plugin.pul.logPunishment(new Punishment(player.getName(), FUtil.getIp(player), sender.getName(), PunishmentType.MUTE, reason));
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
msg(ChatColor.RED + "That player is already muted.");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
@ -294,7 +294,6 @@ public class FPlayer
|
|||||||
public void setMuted(boolean muted, int minutes)
|
public void setMuted(boolean muted, int minutes)
|
||||||
{
|
{
|
||||||
FUtil.cancel(unmuteTask);
|
FUtil.cancel(unmuteTask);
|
||||||
plugin.mu.MUTED_PLAYERS.remove(getPlayer().getName());
|
|
||||||
unmuteTask = null;
|
unmuteTask = null;
|
||||||
|
|
||||||
if (!muted)
|
if (!muted)
|
||||||
@ -307,8 +306,6 @@ public class FPlayer
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
plugin.mu.MUTED_PLAYERS.add(getPlayer().getName());
|
|
||||||
|
|
||||||
// TODO: Simplify this into a Consumer<BukkitTask> lambda?
|
// TODO: Simplify this into a Consumer<BukkitTask> lambda?
|
||||||
unmuteTask = new BukkitRunnable()
|
unmuteTask = new BukkitRunnable()
|
||||||
{
|
{
|
||||||
@ -323,7 +320,6 @@ public class FPlayer
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
FUtil.adminAction(ConfigEntry.SERVER_NAME.getString(), "Unmuting " + getName(), false);
|
FUtil.adminAction(ConfigEntry.SERVER_NAME.getString(), "Unmuting " + getName(), false);
|
||||||
plugin.mu.MUTED_PLAYERS.remove(getName());
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}.runTaskLater(plugin, minutes * (60L * 20L));
|
}.runTaskLater(plugin, minutes * (60L * 20L));
|
||||||
|
Loading…
Reference in New Issue
Block a user