mirror of
https://github.com/LuckPerms/LuckPerms.git
synced 2024-11-24 11:38:40 +01:00
Re-add showtracks/showpos commands
This commit is contained in:
parent
385aa6d438
commit
8da96e6e48
@ -159,7 +159,7 @@ public class Util {
|
||||
sb.append(" &8(&7server=&f").append(node.getServer().get()).append("&8)");
|
||||
}
|
||||
if (node.isWorldSpecific()) {
|
||||
sb.append(" &8(&7world&f").append(node.getWorld().get()).append("&8)");
|
||||
sb.append(" &8(&7world=&f").append(node.getWorld().get()).append("&8)");
|
||||
}
|
||||
sb.append("\n");
|
||||
}
|
||||
|
@ -0,0 +1,82 @@
|
||||
/*
|
||||
* Copyright (c) 2016 Lucko (Luck) <luck@lucko.me>
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
package me.lucko.luckperms.common.commands.generic.other;
|
||||
|
||||
import me.lucko.luckperms.api.Node;
|
||||
import me.lucko.luckperms.common.LuckPermsPlugin;
|
||||
import me.lucko.luckperms.common.commands.*;
|
||||
import me.lucko.luckperms.common.constants.Message;
|
||||
import me.lucko.luckperms.common.constants.Permission;
|
||||
import me.lucko.luckperms.common.core.PermissionHolder;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class HolderShowTracks<T extends PermissionHolder> extends SubCommand<T> {
|
||||
public HolderShowTracks(boolean user) {
|
||||
super("showtracks", "Lists the tracks that the object is on",
|
||||
user ? Permission.USER_SHOWTRACKS : Permission.GROUP_SHOWTRACKS, Predicate.alwaysFalse(), null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, T holder, List<String> args, String label) {
|
||||
if (!plugin.getDatastore().loadAllTracks().getUnchecked()) {
|
||||
Message.TRACKS_LOAD_ERROR.send(sender);
|
||||
return CommandResult.LOADING_ERROR;
|
||||
}
|
||||
|
||||
Set<Node> nodes = holder.getNodes().stream()
|
||||
.filter(Node::isGroupNode)
|
||||
.filter(Node::isPermanent)
|
||||
.collect(Collectors.toSet());
|
||||
|
||||
StringBuilder sb = new StringBuilder();
|
||||
|
||||
for (Node node : nodes) {
|
||||
String name = node.getGroupName();
|
||||
|
||||
plugin.getTrackManager().getAll().values().stream()
|
||||
.filter(t -> t.containsGroup(name))
|
||||
.forEach(t -> {
|
||||
sb.append("&a").append(t.getName()).append(": ").append(Util.listToArrowSep(t.getGroups(), name));
|
||||
if (node.isServerSpecific()) {
|
||||
sb.append(" &8(&7server=&f").append(node.getServer().get()).append("&8)");
|
||||
}
|
||||
if (node.isWorldSpecific()) {
|
||||
sb.append(" &8(&7world=&f").append(node.getWorld().get()).append("&8)");
|
||||
}
|
||||
sb.append("\n");
|
||||
});
|
||||
}
|
||||
|
||||
if (sb.length() == 0) {
|
||||
Message.LIST_TRACKS_EMPTY.send(sender, holder.getFriendlyName());
|
||||
return CommandResult.SUCCESS;
|
||||
} else {
|
||||
sb.deleteCharAt(sb.length() - 1);
|
||||
Message.LIST_TRACKS.send(sender, holder.getFriendlyName(), sb.toString());
|
||||
return CommandResult.SUCCESS;
|
||||
}
|
||||
}
|
||||
}
|
@ -28,6 +28,7 @@ import me.lucko.luckperms.common.commands.MainCommand;
|
||||
import me.lucko.luckperms.common.commands.Sender;
|
||||
import me.lucko.luckperms.common.commands.SubCommand;
|
||||
import me.lucko.luckperms.common.commands.generic.meta.CommandMeta;
|
||||
import me.lucko.luckperms.common.commands.generic.other.HolderShowTracks;
|
||||
import me.lucko.luckperms.common.commands.generic.parent.CommandParent;
|
||||
import me.lucko.luckperms.common.commands.generic.permission.CommandPermission;
|
||||
import me.lucko.luckperms.common.commands.group.subcommands.*;
|
||||
@ -44,7 +45,7 @@ public class GroupMainCommand extends MainCommand<Group> {
|
||||
.add(new CommandPermission<>(false))
|
||||
.add(new CommandParent<>(false))
|
||||
.add(new CommandMeta<>(false))
|
||||
.add(new GroupShowTracks())
|
||||
.add(new HolderShowTracks<>(false))
|
||||
.add(new GroupBulkChange())
|
||||
.add(new GroupClear())
|
||||
.add(new GroupRename())
|
||||
|
@ -1,56 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2016 Lucko (Luck) <luck@lucko.me>
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
package me.lucko.luckperms.common.commands.group.subcommands;
|
||||
|
||||
import me.lucko.luckperms.common.LuckPermsPlugin;
|
||||
import me.lucko.luckperms.common.commands.*;
|
||||
import me.lucko.luckperms.common.constants.Message;
|
||||
import me.lucko.luckperms.common.constants.Permission;
|
||||
import me.lucko.luckperms.common.groups.Group;
|
||||
import me.lucko.luckperms.common.tracks.Track;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class GroupShowTracks extends SubCommand<Group> {
|
||||
public GroupShowTracks() {
|
||||
super("showtracks", "Lists the tracks that the group features on", Permission.GROUP_SHOWTRACKS, Predicate.alwaysFalse(), null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, Group group, List<String> args, String label) {
|
||||
if (!plugin.getDatastore().loadAllTracks().getUnchecked()) {
|
||||
Message.TRACKS_LOAD_ERROR.send(sender);
|
||||
return CommandResult.LOADING_ERROR;
|
||||
}
|
||||
|
||||
Message.TRACKS_LIST.send(sender,
|
||||
Util.listToCommaSep(plugin.getTrackManager().getApplicableTracks(group.getName()).stream()
|
||||
.map(Track::getName)
|
||||
.collect(Collectors.toList())
|
||||
)
|
||||
);
|
||||
|
||||
return CommandResult.SUCCESS;
|
||||
}
|
||||
}
|
@ -29,6 +29,7 @@ import me.lucko.luckperms.common.commands.Sender;
|
||||
import me.lucko.luckperms.common.commands.SubCommand;
|
||||
import me.lucko.luckperms.common.commands.Util;
|
||||
import me.lucko.luckperms.common.commands.generic.meta.CommandMeta;
|
||||
import me.lucko.luckperms.common.commands.generic.other.HolderShowTracks;
|
||||
import me.lucko.luckperms.common.commands.generic.parent.CommandParent;
|
||||
import me.lucko.luckperms.common.commands.generic.permission.CommandPermission;
|
||||
import me.lucko.luckperms.common.commands.user.subcommands.*;
|
||||
@ -50,7 +51,7 @@ public class UserMainCommand extends MainCommand<User> {
|
||||
.add(new UserSetPrimaryGroup())
|
||||
.add(new UserPromote())
|
||||
.add(new UserDemote())
|
||||
.add(new UserShowPos())
|
||||
.add(new HolderShowTracks<>(true))
|
||||
.add(new UserBulkChange())
|
||||
.add(new UserClear())
|
||||
.build()
|
||||
|
@ -1,79 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2016 Lucko (Luck) <luck@lucko.me>
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
package me.lucko.luckperms.common.commands.user.subcommands;
|
||||
|
||||
import me.lucko.luckperms.common.LuckPermsPlugin;
|
||||
import me.lucko.luckperms.common.commands.*;
|
||||
import me.lucko.luckperms.common.constants.Message;
|
||||
import me.lucko.luckperms.common.constants.Permission;
|
||||
import me.lucko.luckperms.common.tracks.Track;
|
||||
import me.lucko.luckperms.common.users.User;
|
||||
import me.lucko.luckperms.common.utils.ArgumentChecker;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class UserShowPos extends SubCommand<User> {
|
||||
public UserShowPos() {
|
||||
super("showpos", "Shows the user's position on a track", Permission.USER_SHOWPOS, Predicate.not(1),
|
||||
Arg.list(Arg.create("track", true, "the track name"))
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, User user, List<String> args, String label) {
|
||||
final String trackName = args.get(0).toLowerCase();
|
||||
if (ArgumentChecker.checkName(trackName)) {
|
||||
Message.TRACK_INVALID_ENTRY.send(sender);
|
||||
return CommandResult.INVALID_ARGS;
|
||||
}
|
||||
|
||||
if (!plugin.getDatastore().loadTrack(trackName).getUnchecked()) {
|
||||
Message.TRACK_DOES_NOT_EXIST.send(sender);
|
||||
return CommandResult.INVALID_ARGS;
|
||||
}
|
||||
|
||||
Track track = plugin.getTrackManager().get(trackName);
|
||||
if (track == null) {
|
||||
Message.TRACK_DOES_NOT_EXIST.send(sender);
|
||||
return CommandResult.LOADING_ERROR;
|
||||
}
|
||||
|
||||
if (track.getSize() <= 1) {
|
||||
Message.TRACK_EMPTY.send(sender);
|
||||
return CommandResult.STATE_ERROR;
|
||||
}
|
||||
|
||||
if (!track.containsGroup(user.getPrimaryGroup())) {
|
||||
Message.TRACK_DOES_NOT_CONTAIN.send(sender, track.getName(), user.getPrimaryGroup());
|
||||
return CommandResult.STATE_ERROR;
|
||||
}
|
||||
|
||||
Message.USER_SHOWPOS.send(sender, user.getName(), track.getName(), Util.listToArrowSep(track.getGroups(), user.getPrimaryGroup()));
|
||||
return CommandResult.SUCCESS;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> onTabComplete(LuckPermsPlugin plugin, Sender sender, List<String> args) {
|
||||
return getTrackTabComplete(args, plugin);
|
||||
}
|
||||
}
|
@ -158,6 +158,8 @@ public enum Message {
|
||||
LISTPARENTS_TEMP("&b{0}'s Temporary Parent Groups:" + "\n" + "{1}", true),
|
||||
LISTGROUPS("&b{0}'s Groups:" + "\n" + "{1}", true),
|
||||
LISTGROUPS_TEMP("&b{0}'s Temporary Groups:" + "\n" + "{1}", true),
|
||||
LIST_TRACKS("&b{0}'s Tracks:" + "\n" + "{1}", true),
|
||||
LIST_TRACKS_EMPTY("{0} is not on any tracks.", true),
|
||||
|
||||
SETPERMISSION_SUCCESS("&aSet &b{0}&a to &b{1}&a for &b{2}&a.", true),
|
||||
SETPERMISSION_SERVER_SUCCESS("&aSet &b{0}&a to &b{1}&a for &b{2}&a on server &b{3}&a.", true),
|
||||
|
@ -81,7 +81,6 @@ public enum Permission {
|
||||
USER_SHOWTRACKS(set("showtracks"), Type.USER),
|
||||
USER_PROMOTE(set("promote"), Type.USER),
|
||||
USER_DEMOTE(set("demote"), Type.USER),
|
||||
USER_SHOWPOS(set("showpos"), Type.USER),
|
||||
USER_BULKCHANGE(set("bulkchange"), Type.USER),
|
||||
USER_CLEAR(set("clear"), Type.USER),
|
||||
|
||||
|
@ -24,22 +24,8 @@ package me.lucko.luckperms.common.tracks;
|
||||
|
||||
import me.lucko.luckperms.common.utils.AbstractManager;
|
||||
|
||||
import java.util.Set;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class TrackManager extends AbstractManager<String, Track> {
|
||||
|
||||
/**
|
||||
* Returns a set of tracks that contain at least one of the groups from the Set provided
|
||||
* @param group the group to filter by
|
||||
* @return a set of tracks that the groups could be a member of
|
||||
*/
|
||||
public Set<Track> getApplicableTracks(String group) {
|
||||
return getAll().values().stream()
|
||||
.filter(t -> t.containsGroup(group))
|
||||
.collect(Collectors.toSet());
|
||||
}
|
||||
|
||||
/**
|
||||
* Makes a new track object
|
||||
* @param name The name of the track
|
||||
|
@ -115,6 +115,9 @@ listparents: "&b{0}'s Parent Groups:\n{1}"
|
||||
listparents-temp: "&b{0}'s Temporary Parent Groups:\n{1}"
|
||||
listgroups: "&b{0}'s Groups:\n{1}"
|
||||
listgroups-temp: "&b{0}'s Temporary Groups:\n{1}"
|
||||
list-tracks: "&b{0}'s Tracks:\n{1}"
|
||||
list-tracks-empty: "{0} is not on any tracks."
|
||||
|
||||
setpermission-success: "&aSet &b{0}&a to &b{1}&a for &b{2}&a."
|
||||
setpermission-server-success: "&aSet &b{0}&a to &b{1}&a for &b{2}&a on server &b{3}&a."
|
||||
setpermission-server-world-success: "&aSet &b{0}&a to &b{1}&a for &b{2}&a on server &b{3}&a, world &b{4}&a."
|
||||
|
Loading…
Reference in New Issue
Block a user