Modified /qop and /qdeop to be a bit less spammy when multiple matches are found.

This commit is contained in:
StevenLawson 2014-08-13 20:11:12 -04:00
parent 429269d8d2
commit 97cde0cfd4
2 changed files with 32 additions and 24 deletions

View File

@ -1,7 +1,10 @@
package me.StevenLawson.TotalFreedomMod.Commands; package me.StevenLawson.TotalFreedomMod.Commands;
import java.util.ArrayList;
import java.util.List;
import me.StevenLawson.TotalFreedomMod.TFM_Util; import me.StevenLawson.TotalFreedomMod.TFM_Util;
import me.StevenLawson.TotalFreedomMod.TotalFreedomMod; import me.StevenLawson.TotalFreedomMod.TotalFreedomMod;
import net.minecraft.util.org.apache.commons.lang3.StringUtils;
import org.bukkit.command.Command; import org.bukkit.command.Command;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
@ -24,26 +27,27 @@ public class Command_qdeop extends TFM_Command
silent = args[1].equalsIgnoreCase("-s"); silent = args[1].equalsIgnoreCase("-s");
} }
boolean matched_player = false; final String targetName = args[0].toLowerCase();
String targetName = args[0].toLowerCase(); final List<String> matchedPlayerNames = new ArrayList<String>();
for (final Player player : server.getOnlinePlayers())
for (Player player : server.getOnlinePlayers())
{ {
if (player.getName().toLowerCase().indexOf(targetName) != -1 || player.getDisplayName().toLowerCase().indexOf(targetName) != -1) if (player.getName().toLowerCase().contains(targetName) || player.getDisplayName().toLowerCase().contains(targetName))
{ {
matched_player = true; matchedPlayerNames.add(player.getName());
if (!silent)
{
TFM_Util.adminAction(sender.getName(), "De-opping " + player.getName(), false);
}
player.setOp(false); player.setOp(false);
player.sendMessage(TotalFreedomMod.YOU_ARE_NOT_OP); player.sendMessage(TotalFreedomMod.YOU_ARE_NOT_OP);
} }
} }
if (!matched_player) if (!matchedPlayerNames.isEmpty())
{
if (!silent)
{
TFM_Util.adminAction(sender.getName(), "De-opping " + StringUtils.join(matchedPlayerNames, ", "), false);
}
}
else
{ {
playerMsg("No targets matched."); playerMsg("No targets matched.");
} }

View File

@ -1,7 +1,10 @@
package me.StevenLawson.TotalFreedomMod.Commands; package me.StevenLawson.TotalFreedomMod.Commands;
import java.util.ArrayList;
import java.util.List;
import me.StevenLawson.TotalFreedomMod.TFM_Util; import me.StevenLawson.TotalFreedomMod.TFM_Util;
import me.StevenLawson.TotalFreedomMod.TotalFreedomMod; import me.StevenLawson.TotalFreedomMod.TotalFreedomMod;
import net.minecraft.util.org.apache.commons.lang3.StringUtils;
import org.bukkit.command.Command; import org.bukkit.command.Command;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
@ -24,26 +27,27 @@ public class Command_qop extends TFM_Command
silent = args[1].equalsIgnoreCase("-s"); silent = args[1].equalsIgnoreCase("-s");
} }
boolean matched_player = false; final String targetName = args[0].toLowerCase();
String targetName = args[0].toLowerCase(); final List<String> matchedPlayerNames = new ArrayList<String>();
for (final Player player : server.getOnlinePlayers())
for (Player player : server.getOnlinePlayers())
{ {
if (player.getName().toLowerCase().indexOf(targetName) != -1 || player.getDisplayName().toLowerCase().indexOf(targetName) != -1) if (player.getName().toLowerCase().contains(targetName) || player.getDisplayName().toLowerCase().contains(targetName))
{ {
matched_player = true; matchedPlayerNames.add(player.getName());
if (!silent)
{
TFM_Util.adminAction(sender.getName(), "Opping " + player.getName(), false);
}
player.setOp(true); player.setOp(true);
player.sendMessage(TotalFreedomMod.YOU_ARE_OP); player.sendMessage(TotalFreedomMod.YOU_ARE_OP);
} }
} }
if (!matched_player) if (!matchedPlayerNames.isEmpty())
{
if (!silent)
{
TFM_Util.adminAction(sender.getName(), "Opping " + StringUtils.join(matchedPlayerNames, ", "), false);
}
}
else
{ {
playerMsg("No targets matched."); playerMsg("No targets matched.");
} }