TotalFreedomMod/src/main/java/me/totalfreedom/totalfreedommod/command/Command_op.java

63 lines
2.1 KiB
Java
Raw Normal View History

package me.totalfreedom.totalfreedommod.command;
2020-04-14 06:40:22 +00:00
import java.util.ArrayList;
import java.util.List;
import me.totalfreedom.totalfreedommod.rank.Rank;
import me.totalfreedom.totalfreedommod.util.FUtil;
2020-04-14 06:40:22 +00:00
import org.apache.commons.lang.StringUtils;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
@CommandPermissions(level = Rank.OP, source = SourceType.BOTH, cooldown = 5)
2020-04-14 06:40:22 +00:00
@CommandParameters(description = "OP a player", usage = "/<command> <partialname>")
public class Command_op extends FreedomCommand
{
2020-07-22 21:40:58 +00:00
@Override
public boolean run(CommandSender sender, Player playerSender, Command cmd, String commandLabel, String[] args, boolean senderIsConsole)
{
2020-04-14 06:40:22 +00:00
if (args.length < 1)
{
return false;
}
2020-04-14 06:40:22 +00:00
boolean silent = false;
if (args.length == 2)
{
2020-04-14 06:40:22 +00:00
silent = args[1].equalsIgnoreCase("-s");
}
2020-04-14 06:40:22 +00:00
final String targetName = args[0].toLowerCase();
List<String> matchedPlayerNames = new ArrayList<>();
2020-04-14 06:40:22 +00:00
for (final Player player : server.getOnlinePlayers())
{
if (player.getName().toLowerCase().contains(targetName) || player.getDisplayName().toLowerCase().contains(targetName)
|| player.getName().contains(targetName) || player.getDisplayName().contains(targetName))
{
if (!player.isOp() && !plugin.al.isVanished(player.getName()))
2020-04-14 06:40:22 +00:00
{
matchedPlayerNames.add(player.getName());
player.setOp(true);
Right, so this change applies only to commands. For the sake of code consistency, I tried to change as many as possible to use `FreedomCommand.msg` instead of `CommandSender.sendMessage` for their messages. Here are a list of the files containing those changes: * Command_adminworld.java * Command_adventure.java * Command_banip.java * Command_blockedit.java * Command_blockpvp.java * Command_cage.java * Command_cartsit.java * Command_clearchat.java * Command_clearinventory.java * Command_commandlist.java * Command_creative.java * Command_deop.java * Command_deopall.java * Command_dispfill.java * Command_doom.java * Command_gcmd.java * Command_hubworld.java * Command_inspect.java * Command_list.java * Command_lockup.java * Command_manageshop.java * Command_manuallyverify.java * Command_masterbuilderworld.java * Command_mbconfig.java * Command_moblimiter.java * Command_mp44.java * Command_mute.java * Command_nickfilter.java * Command_op.java * Command_opall.java * Command_opme.java * Command_potion.java (Also corrected the inconsistent "player not found" message's color) * Command_rank.java * Command_ride.java * Command_saconfig.java * Command_scare.java * Command_setplayerlimit.java * Command_settotalvotes.java * Command_smite.java * Command_spectator.java * Command_survival.java * Command_unblockcmd.java * Command_uncage.java * Command_unmute.java * Command_verifynoadmin.java Here are some commands I added functionality to: * Command_dispfill.java: Added some code that hooks into the CoreProtect API to log the items being removed from and added into the dispensers. * Command_setlever.java: Added some code that hooks into the CoreProtect API to log the levers being interacted with. Here's a command I fixed a critical bug in: * Command_setlever.java
2021-04-05 23:13:26 +00:00
msg(player, YOU_ARE_OP);
plugin.rm.updateDisplay(player);
2020-04-14 06:40:22 +00:00
}
}
}
2020-04-14 06:40:22 +00:00
if (!matchedPlayerNames.isEmpty())
{
2020-04-14 06:40:22 +00:00
if (!silent)
{
FUtil.adminAction(sender.getName(), "Opping " + StringUtils.join(matchedPlayerNames, ", "), false);
}
}
2020-04-14 06:40:22 +00:00
else
2019-01-12 03:05:12 +00:00
{
msg("Either the player is already opped, or the player could not be found.");
2019-01-12 03:05:12 +00:00
}
return true;
}
2020-07-22 21:40:58 +00:00
}