mirror of
https://github.com/plexusorg/Plex.git
synced 2024-12-22 17:17:37 +00:00
Added functionality that clears all players with a specified item (#82)
* Update WhoHasCMD.java Added functionality that clears all players with a specified item * Added functionality that clears all players with a specified item * Altered tab completion to include "clear" argument * Update WhoHasCMD.java --------- Co-authored-by: Telesphoreo <me@telesphoreo.me>
This commit is contained in:
parent
6ce4843829
commit
532e82472b
@ -16,6 +16,7 @@ import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Collections;
|
||||
|
||||
@CommandPermissions(permission = "plex.whohas")
|
||||
@CommandParameters(name = "whohas", description = "Returns a list of players with a specific item in their inventory.", usage = "/<command> <material>", aliases = "wh")
|
||||
@ -36,17 +37,43 @@ public class WhoHasCMD extends PlexCommand
|
||||
return messageComponent("materialNotFound", args[0]);
|
||||
}
|
||||
|
||||
final List<TextComponent> players = Bukkit.getOnlinePlayers().stream().filter(player ->
|
||||
player.getInventory().contains(material)).map(player -> Component.text(player.getName())).toList();
|
||||
boolean clearInventory = args.length > 1 && args[1].equalsIgnoreCase("clear");
|
||||
|
||||
return players.isEmpty() ? messageComponent("nobodyHasThatMaterial") :
|
||||
messageComponent("playersWithMaterial", Component.text(material.name()),
|
||||
Component.join(JoinConfiguration.commas(true), players));
|
||||
if (clearInventory && !sender.hasPermission("plex.whohas.clear"))
|
||||
{
|
||||
return messageComponent("noPermissionNode", "plex.whohas.clear");
|
||||
}
|
||||
|
||||
List<TextComponent> players = Bukkit.getOnlinePlayers().stream().filter(player ->
|
||||
player.getInventory().contains(material)).map(player -> {
|
||||
if (clearInventory)
|
||||
{
|
||||
player.getInventory().remove(material);
|
||||
player.updateInventory();
|
||||
}
|
||||
return Component.text(player.getName());
|
||||
}).toList();
|
||||
|
||||
return players.isEmpty() ?
|
||||
messageComponent("nobodyHasThatMaterial") :
|
||||
(clearInventory ?
|
||||
messageComponent("playersMaterialCleared", Component.text(material.name()),
|
||||
Component.join(JoinConfiguration.commas(true), players)) :
|
||||
messageComponent("playersWithMaterial", Component.text(material.name()),
|
||||
Component.join(JoinConfiguration.commas(true), players)));
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull List<String> smartTabComplete(@NotNull CommandSender sender, @NotNull String alias, @NotNull String[] args) throws IllegalArgumentException
|
||||
{
|
||||
return args.length == 1 && silentCheckPermission(sender, this.getPermission()) ? Arrays.stream(Material.values()).map(Enum::name).toList() : ImmutableList.of();
|
||||
if (args.length == 1 && silentCheckPermission(sender, this.getPermission()))
|
||||
{
|
||||
return Arrays.stream(Material.values()).map(Enum::name).toList();
|
||||
}
|
||||
else if (args.length == 2 && silentCheckPermission(sender, "plex.whohas.clear"))
|
||||
{
|
||||
return Collections.singletonList("clear");
|
||||
}
|
||||
return ImmutableList.of();
|
||||
}
|
||||
}
|
||||
|
@ -200,6 +200,9 @@ rankRequired: "<red>Policy requires that you must state your rank in your login
|
||||
# 0 - The material name
|
||||
# 1 - The players who have the material in their inventory
|
||||
playersWithMaterial: "<gray>Players with {0} in their inventory: {1}"
|
||||
# 0 - The material name
|
||||
# 1 - The players who have the material in their inventory
|
||||
playersMaterialCleared: "<gray>{0} has been removed from the following players: {1}"
|
||||
nobodyHasThatMaterial: "<gray>No one online has that in their inventory."
|
||||
# 0 - The attempted material name
|
||||
materialNotFound: "<red>{0} is not a valid item/block name."
|
||||
|
Loading…
Reference in New Issue
Block a user