From 7c829f8712d6f7e38bbb60b32a2b0c11785fcbc3 Mon Sep 17 00:00:00 2001 From: samczsun Date: Tue, 17 Jan 2017 18:32:09 -0500 Subject: [PATCH] Filter duplicates, handle permissions in multicommand, support more commands --- .../core/boosters/command/BoosterCommand.java | 2 +- .../mineplex/core/command/CommandCenter.java | 8 +++----- .../core/command/MultiCommandBase.java | 8 +++++++- .../message/commands/ResendAdminCommand.java | 5 +---- .../gui/PartyGUIAcceptInviteCommand.java | 20 +++++++++++++++++++ .../gui/PartyGUIDenyInviteCommand.java | 20 +++++++++++++++++++ 6 files changed, 52 insertions(+), 11 deletions(-) diff --git a/Plugins/Mineplex.Core/src/mineplex/core/boosters/command/BoosterCommand.java b/Plugins/Mineplex.Core/src/mineplex/core/boosters/command/BoosterCommand.java index 44a429ac6..42866745b 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/boosters/command/BoosterCommand.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/boosters/command/BoosterCommand.java @@ -15,7 +15,7 @@ public class BoosterCommand extends MultiCommandBase { public BoosterCommand(BoosterManager plugin) { - super(plugin, Rank.ALL, "amplifier", "booster"); + super(plugin, Rank.ALL, "amplifier"); AddCommand(new AddCommand(plugin)); AddCommand(new GuiCommand(plugin)); diff --git a/Plugins/Mineplex.Core/src/mineplex/core/command/CommandCenter.java b/Plugins/Mineplex.Core/src/mineplex/core/command/CommandCenter.java index dad9e99c4..5ab90fc5a 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/command/CommandCenter.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/command/CommandCenter.java @@ -170,7 +170,7 @@ public class CommandCenter implements Listener, IPacketHandler return; } - List results = new ArrayList<>(); + Set results = new HashSet<>(); String commandName = message.substring(1); String[] args = new String[0]; @@ -192,7 +192,7 @@ public class CommandCenter implements Listener, IPacketHandler 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())) { List tmpres = command.onTabComplete(packetInfo.getPlayer(), commandName.toLowerCase(), args); @@ -207,7 +207,6 @@ public class CommandCenter implements Listener, IPacketHandler else { // System.out.println("Path 2"); - Set commands = new HashSet<>(); for (ICommand command : Commands.values()) { 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)) { - commands.add("/" + alias.toLowerCase()); + results.add("/" + alias.toLowerCase()); } } } } - results.addAll(commands); } // System.out.println("Final results: " + results); diff --git a/Plugins/Mineplex.Core/src/mineplex/core/command/MultiCommandBase.java b/Plugins/Mineplex.Core/src/mineplex/core/command/MultiCommandBase.java index 2ba7c8c21..a8d751c9c 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/command/MultiCommandBase.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/command/MultiCommandBase.java @@ -3,6 +3,7 @@ package mineplex.core.command; import java.util.Collection; import java.util.List; import java.util.Locale; +import java.util.stream.Stream; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; @@ -101,7 +102,12 @@ public abstract class MultiCommandBase extends Co } else if (args.length == 1) { - return getMatches(args[0], Commands.values().stream().map(ICommand::Aliases).flatMap(Collection::stream)); + Stream 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; diff --git a/Plugins/Mineplex.Core/src/mineplex/core/message/commands/ResendAdminCommand.java b/Plugins/Mineplex.Core/src/mineplex/core/message/commands/ResendAdminCommand.java index d201c296f..3d5b1ce93 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/message/commands/ResendAdminCommand.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/message/commands/ResendAdminCommand.java @@ -12,7 +12,7 @@ public class ResendAdminCommand extends CommandBase { public ResendAdminCommand(MessageManager plugin) { - super(plugin, Rank.ALL, "ra"); + super(plugin, Rank.HELPER, "ra"); } @Override @@ -24,9 +24,6 @@ public class ResendAdminCommand extends CommandBase } else { - if (!Plugin.GetClientManager().Get(caller).GetRank().has(caller, Rank.HELPER, true)) - return; - String lastTo = Plugin.Get(caller).LastAdminTo; // Get To diff --git a/Plugins/Mineplex.Core/src/mineplex/core/party/command/gui/PartyGUIAcceptInviteCommand.java b/Plugins/Mineplex.Core/src/mineplex/core/party/command/gui/PartyGUIAcceptInviteCommand.java index 5a182b060..9f1f6fa80 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/party/command/gui/PartyGUIAcceptInviteCommand.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/party/command/gui/PartyGUIAcceptInviteCommand.java @@ -1,11 +1,15 @@ package mineplex.core.party.command.gui; +import java.util.List; + +import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; import mineplex.core.command.CommandBase; import mineplex.core.common.Rank; import mineplex.core.common.util.F; import mineplex.core.common.util.UtilPlayer; +import mineplex.core.party.InviteData; import mineplex.core.party.PartyManager; public class PartyGUIAcceptInviteCommand extends CommandBase @@ -26,4 +30,20 @@ public class PartyGUIAcceptInviteCommand extends CommandBase Plugin.acceptInviteBySender(caller, args[0]); } + + @Override + public List 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; + } } diff --git a/Plugins/Mineplex.Core/src/mineplex/core/party/command/gui/PartyGUIDenyInviteCommand.java b/Plugins/Mineplex.Core/src/mineplex/core/party/command/gui/PartyGUIDenyInviteCommand.java index f77d078a0..6b53c1c61 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/party/command/gui/PartyGUIDenyInviteCommand.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/party/command/gui/PartyGUIDenyInviteCommand.java @@ -1,11 +1,16 @@ 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 mineplex.core.command.CommandBase; import mineplex.core.common.Rank; import mineplex.core.common.util.F; import mineplex.core.common.util.UtilPlayer; +import mineplex.core.party.InviteData; import mineplex.core.party.PartyManager; public class PartyGUIDenyInviteCommand extends CommandBase @@ -25,4 +30,19 @@ public class PartyGUIDenyInviteCommand extends CommandBase } Plugin.denyInviteBySender(caller, args[0]); } + + @Override + public List 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; + } }