Add parent cleartrack command, cleanup Messages enum

This commit is contained in:
Luck
2017-05-09 16:26:55 +01:00
Unverified
parent e25d99129c
commit b240ca9939
5 changed files with 131 additions and 36 deletions
@@ -42,6 +42,7 @@ public class CommandParent<T extends PermissionHolder> extends SharedMainCommand
.add(new ParentAddTemp())
.add(new ParentRemoveTemp())
.add(new ParentClear())
.add(new ParentClearTrack())
.build());
}
}
@@ -0,0 +1,111 @@
/*
* This file is part of LuckPerms, licensed under the MIT License.
*
* Copyright (c) lucko (Luck) <luck@lucko.me>
* Copyright (c) contributors
*
* 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.impl.generic.parent;
import me.lucko.luckperms.api.context.MutableContextSet;
import me.lucko.luckperms.common.commands.Arg;
import me.lucko.luckperms.common.commands.CommandException;
import me.lucko.luckperms.common.commands.CommandResult;
import me.lucko.luckperms.common.commands.abstraction.SharedSubCommand;
import me.lucko.luckperms.common.commands.sender.Sender;
import me.lucko.luckperms.common.commands.utils.ArgumentUtils;
import me.lucko.luckperms.common.commands.utils.Util;
import me.lucko.luckperms.common.constants.DataConstraints;
import me.lucko.luckperms.common.constants.Message;
import me.lucko.luckperms.common.constants.Permission;
import me.lucko.luckperms.common.core.model.PermissionHolder;
import me.lucko.luckperms.common.core.model.Track;
import me.lucko.luckperms.common.core.model.User;
import me.lucko.luckperms.common.data.LogEntry;
import me.lucko.luckperms.common.plugin.LuckPermsPlugin;
import me.lucko.luckperms.common.utils.Predicates;
import java.util.List;
import java.util.stream.Collectors;
public class ParentClearTrack extends SharedSubCommand {
public ParentClearTrack() {
super("cleartrack", "Clears all parents on a given track", Permission.USER_PARENT_CLEAR_TRACK, Permission.GROUP_PARENT_CLEAR_TRACK, Predicates.is(0),
Arg.list(
Arg.create("track", true, "the track to remove on"),
Arg.create("context...", false, "the contexts to filter by")
)
);
}
@Override
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, PermissionHolder holder, List<String> args, String label) throws CommandException {
final String trackName = args.get(0).toLowerCase();
if (!DataConstraints.TRACK_NAME_TEST.test(trackName)) {
Message.TRACK_INVALID_ENTRY.send(sender);
return CommandResult.INVALID_ARGS;
}
if (!plugin.getStorage().loadTrack(trackName).join()) {
Message.TRACK_DOES_NOT_EXIST.send(sender);
return CommandResult.INVALID_ARGS;
}
Track track = plugin.getTrackManager().getIfLoaded(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;
}
int before = holder.getNodes().size();
MutableContextSet context = ArgumentUtils.handleContext(1, args, plugin);
if (context.isEmpty()) {
holder.removeIf(node -> node.isGroupNode() && track.containsGroup(node.getGroupName()));
} else {
holder.removeIf(node -> node.isGroupNode() && node.getFullContexts().equals(context) && track.containsGroup(node.getGroupName()));
}
if (holder instanceof User) {
plugin.getUserManager().giveDefaultIfNeeded(((User) holder), false);
}
int changed = before - holder.getNodes().size();
if (changed == 1) {
Message.PARENT_CLEAR_TRACK_SUCCESS_SINGULAR.send(sender, holder.getFriendlyName(), track.getName(), Util.contextSetToString(context), changed);
} else {
Message.PARENT_CLEAR_TRACK_SUCCESS.send(sender, holder.getFriendlyName(), track.getName(), Util.contextSetToString(context), changed);
}
LogEntry.build().actor(sender).acted(holder)
.action("parent cleartrack " + args.stream().map(ArgumentUtils.WRAPPER).collect(Collectors.joining(" ")))
.build().submit(plugin, sender);
save(holder, sender, plugin);
return CommandResult.SUCCESS;
}
}
@@ -73,10 +73,8 @@ public enum Message {
*/
USER_NOT_FOUND("&bUser could not be found.", true),
USER_NOT_ONLINE("&bUser &a{0}&b is not online.", true),
USER_NO_DATA("&bUser &a{0}&b does not have any data loaded.", true),
USER_SAVE_SUCCESS("&7(User data was saved to storage)", true),
USER_SAVE_ERROR("There was an error whilst saving the user.", true),
USER_CREATE_FAIL("There was an error whilst creating a new user.", true),
GROUP_NOT_FOUND("&bGroup could not be found.", true),
GROUP_SAVE_SUCCESS("&7(Group data was saved to storage)", true),
@@ -200,20 +198,16 @@ public enum Message {
LISTNODES_TEMP("&b{0}'s Temporary Nodes:" + "\n" + "{1}", true),
LISTPARENTS("&b{0}'s Parent Groups:" + "\n" + "{1}", true),
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),
CONTEXT_PAIR_INLINE("&3{0}=&b{1}", false),
CONTEXT_PAIR__GLOBAL_INLINE("&eglobal", false),
CONTEXT_PAIR_END("&a.", false),
CONTEXT_PAIR_SEP("&a, ", false),
CONTEXT_PAIR("&8(&7{0}=&f{1}&8)", false),
CHECK_PERMISSION("&b{0}&a has permission &b{1}&a set to {2}&a in context {3}&a.", true),
CHECK_PERMISSION_INHERITED("&b{0}&a has permission &b{1}&a set to {2}&a in context {3}&a, inherited from &b{4}&a.", true),
SETPERMISSION_SUCCESS("&aSet &b{0}&a to &b{1}&a for &b{2}&a in context {3}&a.", true),
SETPERMISSION_TEMP_SUCCESS("&aSet &b{0}&a to &b{1}&a for &b{2}&a for a duration of &b{3}&a in context {4}&a.", true),
UNSETPERMISSION_SUCCESS("&aUnset &b{0}&a for &b{1}&a in context {2}&a.", true),
@@ -221,7 +215,7 @@ public enum Message {
SET_INHERIT_SUCCESS("&b{0}&a now inherits permissions from &b{1}&a in context {2}&a.", true),
SET_TEMP_INHERIT_SUCCESS("&b{0}&a now inherits permissions from &b{1}&a for a duration of &b{2}&a in context {3}&a.", true),
SET_PARENT_SUCCESS("&b{0}&a had their existing parent groups cleared, and now only inherits &b{1}&a in context {2}&a.", true),
SET_TRACK_PARENT_SUCCESS("&b{0}&a had their existing parent groups in track &b{1}&a cleared, and now only inherits &b{2}&a in context {3}&a.", true),
SET_TRACK_PARENT_SUCCESS("&b{0}&a had their existing parent groups on track &b{1}&a cleared, and now only inherits &b{2}&a in context {3}&a.", true),
UNSET_INHERIT_SUCCESS("&b{0}&a no longer inherits permissions from &b{1}&a in context {2}&a.", true),
UNSET_TEMP_INHERIT_SUCCESS("&b{0}&a no longer temporarily inherits permissions from &b{1}&a in context {2}&a.", true),
@@ -229,6 +223,10 @@ public enum Message {
CLEAR_SUCCESS_SINGULAR("&b{0}&a's permissions were cleared in context {1}&a. (&b{2}&a node was removed.)", true),
PARENT_CLEAR_SUCCESS("&b{0}&a's parents were cleared in context {1}&a. &b{2}&a nodes were removed.)", true),
PARENT_CLEAR_SUCCESS_SINGULAR("&b{0}&a's parents were cleared in context {1}&a. &b{2}&a node was removed.)", true),
PARENT_CLEAR_TRACK_SUCCESS("&b{0}&a's parents on track &b{1}&a were cleared in context {2}&a. &b{3}&a nodes were removed.)", true),
PARENT_CLEAR_TRACK_SUCCESS_SINGULAR("&b{0}&a's parents on track &b{1}&a were cleared in context {2}&a. &b{3}&a node was removed.)", true),
META_CLEAR_SUCCESS("&b{0}&a's meta was cleared in context {1}&a. &b{2}&a nodes were removed.)", true),
META_CLEAR_SUCCESS_SINGULAR("&b{0}&a's meta was cleared in context {1}&a. &b{2}&a node was removed.)", true),
@@ -276,9 +274,6 @@ public enum Message {
BULK_UPDATE_SUCCESS("&bBulk update completed successfully.", true),
BULK_UPDATE_FAILURE("&cBulk update failed. Check the console for errors.", true),
BULK_CHANGE_TYPE_ERROR("Invalid type. Was expecting 'server' or 'world'.", true),
BULK_CHANGE_SUCCESS("&aApplied bulk change successfully. {0} records were changed.", true),
USER_INFO_GENERAL(
"{PREFIX}&b&l> &bUser Info: &f{0}" + "\n" +
"{PREFIX}&f- &3UUID: &f{1}" + "\n" +
@@ -327,7 +322,6 @@ public enum Message {
"{PREFIX}Either create the group, or remove it from the track and try again.",
false
),
USER_SHOWPOS("&aShowing &b{0}&a's position on track &b{1}&a.\n{2}", true),
GROUP_INFO_GENERAL(
"{PREFIX}&b&l> &bGroup Info: &f{0}" + "\n" +
@@ -74,6 +74,7 @@ public enum Permission {
USER_PARENT_ADDTEMP(list("parent.addtemp", "addtempgroup"), Type.USER),
USER_PARENT_REMOVETEMP(list("parent.removetemp", "removetempgroup"), Type.USER),
USER_PARENT_CLEAR(list("parent.clear"), Type.USER),
USER_PARENT_CLEAR_TRACK(list("parent.cleartrack"), Type.USER),
USER_META_INFO(list("meta.info", "chatmeta"), Type.USER),
USER_META_SET(list("meta.set", "setmeta"), Type.USER),
USER_META_UNSET(list("meta.unset", "unsetmeta"), Type.USER),
@@ -110,6 +111,7 @@ public enum Permission {
GROUP_PARENT_ADDTEMP(list("parent.addtemp", "settempinherit"), Type.GROUP),
GROUP_PARENT_REMOVETEMP(list("parent.removetemp", "unsettempinherit"), Type.GROUP),
GROUP_PARENT_CLEAR(list("parent.clear"), Type.GROUP),
GROUP_PARENT_CLEAR_TRACK(list("parent.cleartrack"), Type.GROUP),
GROUP_META_INFO(list("meta.info", "chatmeta"), Type.GROUP),
GROUP_META_SET(list("meta.set", "setmeta"), Type.GROUP),
GROUP_META_UNSET(list("meta.unset", "unsetmeta"), Type.GROUP),