mirror of
https://github.com/AtlasMediaGroup/TotalFreedomMod.git
synced 2024-11-26 17:05:01 +00:00
Resolves FS-316 by aggressively rewriting /blockedit
Disclaimer: I did this whilst sleep deprvied. I didn't know how the fuck NPath is calculated so to play it safe I aggressively rewrote the command. I also took the opportunity to make some of the command's messages more consistent with eachother (using restrict/restore instead of block/unblock).
This commit is contained in:
parent
3b61ba408f
commit
f0d6549eec
@ -5,134 +5,106 @@ import me.totalfreedom.totalfreedommod.punishments.Punishment;
|
||||
import me.totalfreedom.totalfreedommod.punishments.PunishmentType;
|
||||
import me.totalfreedom.totalfreedommod.rank.Rank;
|
||||
import me.totalfreedom.totalfreedommod.util.FUtil;
|
||||
import org.apache.commons.lang.ArrayUtils;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
@CommandPermissions(level = Rank.ADMIN, source = SourceType.BOTH)
|
||||
@CommandParameters(description = "Restricts/unrestricts 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> [[-s] <player> [reason] | list | purge | all]")
|
||||
public class Command_blockedit extends FreedomCommand
|
||||
{
|
||||
|
||||
@Override
|
||||
public boolean run(final CommandSender sender, final Player playerSender, final Command cmd, final String commandLabel, String[] args, final boolean senderIsConsole)
|
||||
{
|
||||
if (args.length == 0)
|
||||
if (args.length > 0)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
switch (args[0].toLowerCase())
|
||||
{
|
||||
case "list" ->
|
||||
{
|
||||
List<? extends Player> list = server.getOnlinePlayers().stream().filter(player ->
|
||||
plugin.pl.getPlayer(player).isEditBlocked()).sorted().toList();
|
||||
|
||||
if (args[0].equals("list"))
|
||||
{
|
||||
msg("The following have block modification abilities restricted:");
|
||||
int count = 0;
|
||||
for (Player player : server.getOnlinePlayers())
|
||||
{
|
||||
final FPlayer info = plugin.pl.getPlayer(player);
|
||||
if (info.isEditBlocked())
|
||||
{
|
||||
msg("- " + player.getName());
|
||||
++count;
|
||||
}
|
||||
}
|
||||
// Oh dear god, why do I have to do it like this?
|
||||
msg("There " + (list.size() != 1 ? "are " : "is ") + list.size() + " player"
|
||||
+ (list.size() != 1 ? "s" : "") + " online with restricted block modification abilities"
|
||||
+ (list.size() > 0 ? ":" : "."));
|
||||
|
||||
if (count == 0)
|
||||
list.forEach(player -> msg("- " + player.getName()));
|
||||
}
|
||||
case "purge" ->
|
||||
{
|
||||
msg("- none");
|
||||
}
|
||||
return true;
|
||||
}
|
||||
FUtil.adminAction(sender.getName(), "Restoring block modification abilities for all players", true);
|
||||
|
||||
if (args[0].equals("purge"))
|
||||
{
|
||||
FUtil.adminAction(sender.getName(), "Unblocking block modification abilities for all players", true);
|
||||
int count = 0;
|
||||
for (final Player player : this.server.getOnlinePlayers())
|
||||
{
|
||||
final FPlayer info = plugin.pl.getPlayer(player);
|
||||
if (info.isEditBlocked())
|
||||
{
|
||||
info.setEditBlocked(false);
|
||||
++count;
|
||||
}
|
||||
}
|
||||
msg("Unblocked all block modification abilities for " + count + " players.");
|
||||
return true;
|
||||
}
|
||||
List<? extends Player> list = server.getOnlinePlayers().stream().filter(player ->
|
||||
plugin.pl.getPlayer(player).isEditBlocked()).toList();
|
||||
|
||||
if (args[0].equals("all"))
|
||||
list.forEach(player ->
|
||||
{
|
||||
FUtil.adminAction(sender.getName(), "Blocking block modification abilities for all non-admins", true);
|
||||
int counter = 0;
|
||||
for (final Player player : this.server.getOnlinePlayers())
|
||||
{
|
||||
if (!plugin.al.isAdmin(player))
|
||||
{
|
||||
final FPlayer playerdata = plugin.pl.getPlayer(player);
|
||||
playerdata.setEditBlocked(true);
|
||||
++counter;
|
||||
}
|
||||
}
|
||||
plugin.pl.getPlayer(player).setEditBlocked(false);
|
||||
msg(player, "Your block modification abilities have been restored.", ChatColor.GREEN);
|
||||
});
|
||||
|
||||
msg("Blocked block modification abilities for " + counter + " players.");
|
||||
return true;
|
||||
msg("Restored block modification abilities for " + list.size() + " player"
|
||||
+ (list.size() != 1 ? "s" : "") + ".");
|
||||
}
|
||||
case "all", "-a" ->
|
||||
{
|
||||
FUtil.adminAction(sender.getName(), "Restricting block modification abilities for all non-admins", true);
|
||||
|
||||
final boolean smite = args[0].equals("-s");
|
||||
if (smite)
|
||||
{
|
||||
args = (String[])ArrayUtils.subarray(args, 1, args.length);
|
||||
if (args.length < 1)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
List<? extends Player> list = server.getOnlinePlayers().stream().filter(player ->
|
||||
!plugin.al.isAdmin(player)).toList();
|
||||
|
||||
final Player player2 = getPlayer(args[0]);
|
||||
if (player2 == null)
|
||||
list.forEach(player ->
|
||||
{
|
||||
msg(PLAYER_NOT_FOUND);
|
||||
return true;
|
||||
}
|
||||
plugin.pl.getPlayer(player).setEditBlocked(true);
|
||||
msg(player, "Your block modification abilities have been restricted.", ChatColor.RED);
|
||||
});
|
||||
|
||||
String reason = null;
|
||||
if (args.length > 1)
|
||||
{
|
||||
reason = StringUtils.join(args, " ", 1, args.length);
|
||||
msg("Restricted block modification abilities for " + list.size() + " player"
|
||||
+ (list.size() != 1 ? "s" : "") + ".");
|
||||
}
|
||||
|
||||
final FPlayer pd = plugin.pl.getPlayer(player2);
|
||||
if (pd.isEditBlocked())
|
||||
default -> Optional.ofNullable(getPlayer(args[0])).ifPresentOrElse(player ->
|
||||
{
|
||||
FUtil.adminAction(sender.getName(), "Unblocking block modification abilities for " + player2.getName(), true);
|
||||
pd.setEditBlocked(false);
|
||||
msg("Unblocking block modification abilities for " + player2.getName());
|
||||
msg(player2, "Your block modification abilities have been restored.", ChatColor.RED);
|
||||
FPlayer fPlayer = plugin.pl.getPlayer(player);
|
||||
|
||||
if (fPlayer.isEditBlocked())
|
||||
{
|
||||
FUtil.adminAction(sender.getName(), "Restoring block modification abilities for " + player.getName(), true);
|
||||
fPlayer.setEditBlocked(false);
|
||||
msg("Restored block modification abilities for " + player.getName() + ".");
|
||||
msg(player, "Your block modification abilities have been restored.", ChatColor.GREEN);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (plugin.al.isAdmin(player2))
|
||||
if (plugin.al.isAdmin(player))
|
||||
{
|
||||
msg(player2.getName() + " is an admin, and cannot have their block edits blocked.");
|
||||
msg(player.getName() + " is an admin, and as such cannot have their block modification abilities restricted.", ChatColor.RED);
|
||||
}
|
||||
else
|
||||
{
|
||||
FUtil.adminAction(sender.getName(), "Restricting block modification abilities for " + player.getName(), true);
|
||||
fPlayer.setEditBlocked(true);
|
||||
msg("Restricted block modification abilities for " + player.getName() + ".");
|
||||
msg(player, "Your block modification abilities have been restricted.", ChatColor.RED);
|
||||
|
||||
plugin.pul.logPunishment(new Punishment(player.getName(), FUtil.getIp(player),
|
||||
sender.getName(), PunishmentType.BLOCKEDIT, null));
|
||||
}
|
||||
}
|
||||
|
||||
}, () -> msg(PLAYER_NOT_FOUND));
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
FUtil.adminAction(sender.getName(), "Blocking block modification abilities for " + player2.getName(), true);
|
||||
pd.setEditBlocked(true);
|
||||
|
||||
if (smite)
|
||||
else
|
||||
{
|
||||
Command_smite.smite(sender, player2, reason);
|
||||
return false;
|
||||
}
|
||||
|
||||
msg(player2, "Your block modification abilities have been blocked.", ChatColor.RED);
|
||||
msg("Blocked all block modification abilities for " + player2.getName());
|
||||
|
||||
plugin.pul.logPunishment(new Punishment(player2.getName(), FUtil.getIp(player2), sender.getName(), PunishmentType.BLOCKEDIT, null));
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user