Filter duplicates, handle permissions in multicommand, support more commands

This commit is contained in:
samczsun 2017-01-17 18:32:09 -05:00 committed by cnr
parent 8b1fe8302e
commit 7c829f8712
6 changed files with 52 additions and 11 deletions

View File

@ -15,7 +15,7 @@ public class BoosterCommand extends MultiCommandBase<BoosterManager>
{ {
public BoosterCommand(BoosterManager plugin) public BoosterCommand(BoosterManager plugin)
{ {
super(plugin, Rank.ALL, "amplifier", "booster"); super(plugin, Rank.ALL, "amplifier");
AddCommand(new AddCommand(plugin)); AddCommand(new AddCommand(plugin));
AddCommand(new GuiCommand(plugin)); AddCommand(new GuiCommand(plugin));

View File

@ -170,7 +170,7 @@ public class CommandCenter implements Listener, IPacketHandler
return; return;
} }
List<String> results = new ArrayList<>(); Set<String> results = new HashSet<>();
String commandName = message.substring(1); String commandName = message.substring(1);
String[] args = new String[0]; String[] args = new String[0];
@ -192,7 +192,7 @@ public class CommandCenter implements Listener, IPacketHandler
if (command != null) if (command != null)
{ {
if (ClientManager.Get(packetInfo.getPlayer()).GetRank().has(packetInfo.getPlayer(), command.GetRequiredRank(), command.GetSpecificRanks(), true) if (ClientManager.Get(packetInfo.getPlayer()).GetRank().has(packetInfo.getPlayer(), command.GetRequiredRank(), command.GetSpecificRanks(), false)
|| UtilPlayer.isCommandAllowed(packetInfo.getPlayer(), commandName.toLowerCase())) || UtilPlayer.isCommandAllowed(packetInfo.getPlayer(), commandName.toLowerCase()))
{ {
List<String> tmpres = command.onTabComplete(packetInfo.getPlayer(), commandName.toLowerCase(), args); List<String> tmpres = command.onTabComplete(packetInfo.getPlayer(), commandName.toLowerCase(), args);
@ -207,7 +207,6 @@ public class CommandCenter implements Listener, IPacketHandler
else else
{ {
// System.out.println("Path 2"); // System.out.println("Path 2");
Set<String> commands = new HashSet<>();
for (ICommand command : Commands.values()) for (ICommand command : Commands.values())
{ {
if (ClientManager.Get(packetInfo.getPlayer()).GetRank().has(packetInfo.getPlayer(), command.GetRequiredRank(), command.GetSpecificRanks(), false) if (ClientManager.Get(packetInfo.getPlayer()).GetRank().has(packetInfo.getPlayer(), command.GetRequiredRank(), command.GetSpecificRanks(), false)
@ -217,12 +216,11 @@ public class CommandCenter implements Listener, IPacketHandler
{ {
if (alias.startsWith(commandName)) if (alias.startsWith(commandName))
{ {
commands.add("/" + alias.toLowerCase()); results.add("/" + alias.toLowerCase());
} }
} }
} }
} }
results.addAll(commands);
} }
// System.out.println("Final results: " + results); // System.out.println("Final results: " + results);

View File

@ -3,6 +3,7 @@ package mineplex.core.command;
import java.util.Collection; import java.util.Collection;
import java.util.List; import java.util.List;
import java.util.Locale; import java.util.Locale;
import java.util.stream.Stream;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
@ -101,7 +102,12 @@ public abstract class MultiCommandBase<PluginType extends MiniPlugin> extends Co
} }
else if (args.length == 1) else if (args.length == 1)
{ {
return getMatches(args[0], Commands.values().stream().map(ICommand::Aliases).flatMap(Collection::stream)); Stream<ICommand> stream = Commands.values().stream();
if (sender instanceof Player)
{
stream = stream.filter(command -> _commandCenter.GetClientManager().Get((Player) sender).GetRank().has((Player) sender, command.GetRequiredRank(), command.GetSpecificRanks(), false));
}
return getMatches(args[0], stream.map(ICommand::Aliases).flatMap(Collection::stream));
} }
return null; return null;

View File

@ -12,7 +12,7 @@ public class ResendAdminCommand extends CommandBase<MessageManager>
{ {
public ResendAdminCommand(MessageManager plugin) public ResendAdminCommand(MessageManager plugin)
{ {
super(plugin, Rank.ALL, "ra"); super(plugin, Rank.HELPER, "ra");
} }
@Override @Override
@ -24,9 +24,6 @@ public class ResendAdminCommand extends CommandBase<MessageManager>
} }
else else
{ {
if (!Plugin.GetClientManager().Get(caller).GetRank().has(caller, Rank.HELPER, true))
return;
String lastTo = Plugin.Get(caller).LastAdminTo; String lastTo = Plugin.Get(caller).LastAdminTo;
// Get To // Get To

View File

@ -1,11 +1,15 @@
package mineplex.core.party.command.gui; package mineplex.core.party.command.gui;
import java.util.List;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import mineplex.core.command.CommandBase; import mineplex.core.command.CommandBase;
import mineplex.core.common.Rank; import mineplex.core.common.Rank;
import mineplex.core.common.util.F; import mineplex.core.common.util.F;
import mineplex.core.common.util.UtilPlayer; import mineplex.core.common.util.UtilPlayer;
import mineplex.core.party.InviteData;
import mineplex.core.party.PartyManager; import mineplex.core.party.PartyManager;
public class PartyGUIAcceptInviteCommand extends CommandBase<PartyManager> public class PartyGUIAcceptInviteCommand extends CommandBase<PartyManager>
@ -26,4 +30,20 @@ public class PartyGUIAcceptInviteCommand extends CommandBase<PartyManager>
Plugin.acceptInviteBySender(caller, args[0]); Plugin.acceptInviteBySender(caller, args[0]);
} }
@Override
public List<String> onTabComplete(CommandSender sender, String commandLabel, String[] args)
{
if (sender instanceof Player)
{
if (args.length == 1)
{
Player player = (Player) sender;
return getMatches(args[0], Plugin.getInviteManager().getAllInvites(player).stream().map(InviteData::getInviterName));
}
}
return null;
}
} }

View File

@ -1,11 +1,16 @@
package mineplex.core.party.command.gui; package mineplex.core.party.command.gui;
import java.util.List;
import java.util.stream.Collectors;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import mineplex.core.command.CommandBase; import mineplex.core.command.CommandBase;
import mineplex.core.common.Rank; import mineplex.core.common.Rank;
import mineplex.core.common.util.F; import mineplex.core.common.util.F;
import mineplex.core.common.util.UtilPlayer; import mineplex.core.common.util.UtilPlayer;
import mineplex.core.party.InviteData;
import mineplex.core.party.PartyManager; import mineplex.core.party.PartyManager;
public class PartyGUIDenyInviteCommand extends CommandBase<PartyManager> public class PartyGUIDenyInviteCommand extends CommandBase<PartyManager>
@ -25,4 +30,19 @@ public class PartyGUIDenyInviteCommand extends CommandBase<PartyManager>
} }
Plugin.denyInviteBySender(caller, args[0]); Plugin.denyInviteBySender(caller, args[0]);
} }
@Override
public List<String> onTabComplete(CommandSender sender, String commandLabel, String[] args)
{
if (sender instanceof Player)
{
if (args.length == 1)
{
Player player = (Player) sender;
return getMatches(args[0], Plugin.getInviteManager().getAllInvites(player).stream().map(InviteData::getInviterName).collect(Collectors.toList()));
}
}
return null;
}
} }