mirror of
https://github.com/plexusorg/Plex.git
synced 2024-12-28 19:14:15 +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
2 changed files with 36 additions and 6 deletions
|
@ -16,6 +16,7 @@ import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Collections;
|
||||||
|
|
||||||
@CommandPermissions(permission = "plex.whohas")
|
@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")
|
@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]);
|
return messageComponent("materialNotFound", args[0]);
|
||||||
}
|
}
|
||||||
|
|
||||||
final List<TextComponent> players = Bukkit.getOnlinePlayers().stream().filter(player ->
|
boolean clearInventory = args.length > 1 && args[1].equalsIgnoreCase("clear");
|
||||||
player.getInventory().contains(material)).map(player -> Component.text(player.getName())).toList();
|
|
||||||
|
|
||||||
return players.isEmpty() ? messageComponent("nobodyHasThatMaterial") :
|
if (clearInventory && !sender.hasPermission("plex.whohas.clear"))
|
||||||
messageComponent("playersWithMaterial", Component.text(material.name()),
|
{
|
||||||
Component.join(JoinConfiguration.commas(true), players));
|
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
|
@Override
|
||||||
public @NotNull List<String> smartTabComplete(@NotNull CommandSender sender, @NotNull String alias, @NotNull String[] args) throws IllegalArgumentException
|
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
|
# 0 - The material name
|
||||||
# 1 - The players who have the material in their inventory
|
# 1 - The players who have the material in their inventory
|
||||||
playersWithMaterial: "<gray>Players with {0} in their inventory: {1}"
|
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."
|
nobodyHasThatMaterial: "<gray>No one online has that in their inventory."
|
||||||
# 0 - The attempted material name
|
# 0 - The attempted material name
|
||||||
materialNotFound: "<red>{0} is not a valid item/block name."
|
materialNotFound: "<red>{0} is not a valid item/block name."
|
||||||
|
|
Loading…
Reference in a new issue