diff --git a/.locale/en_US.yml b/.locale/en_US.yml index aee4233d9..0bc2e51ff 100644 --- a/.locale/en_US.yml +++ b/.locale/en_US.yml @@ -25,10 +25,8 @@ already-has-temp-permission: "{0} already has this permission set temporarily!" does-not-have-temp-permission: "{0} does not have this permission set temporarily." user-not-found: "&bUser could not be found." user-not-online: "&bUser &a{0}&b is not online." -user-no-data: "&bUser &a{0}&b does not have any data loaded." user-save-success: "&7(User data was saved to storage)" user-save-error: "There was an error whilst saving the user." -user-create-fail: "There was an error whilst creating a new user." group-not-found: "&bGroup could not be found." group-save-success: "&7(Group data was saved to storage)" group-save-error: "There was an error whilst saving the group." @@ -38,7 +36,7 @@ track-save-error: "There was an error whilst saving the track." user-invalid-entry: "&d{0}&c is not a valid username/uuid." group-invalid-entry: "Group names can only contain alphanumeric characters." track-invalid-entry: "Track names can only contain alphanumeric characters." -server-invalid-entry: "Server names can only contain alphanumeric characters." +server-world-invalid-entry: "Server/world names can only contain alphanumeric characters and cannot exceed 36 characters in length." use-inherit-command: "Use the 'parent add' and 'parent remove' commands instead of specifying the node." verbose-invalid-filter: "&cInvalid verbose filter: &f{0}" verbose-on: "&bVerbose checking output set to &aTRUE &bfor all permissions." @@ -132,23 +130,15 @@ listparents: > 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." context-pair-inline: "&3{0}=&b{1}" context-pair--global-inline: "&eglobal" -context-pair-end: "&a." context-pair-sep: "&a, " context-pair: "&8(&7{0}=&f{1}&8)" check-permission: "&b{0}&a has permission &b{1}&a set to {2}&a in context {3}&a." -check-permission-inherited: "&b{0}&a has permission &b{1}&a set to {2}&a in context {3}&a, inherited from &b{4}&a." setpermission-success: "&aSet &b{0}&a to &b{1}&a for &b{2}&a in context {3}&a." 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." unsetpermission-success: "&aUnset &b{0}&a for &b{1}&a in context {2}&a." @@ -156,14 +146,17 @@ unset-temp-permission-success: "&aUnset temporary permission &b{0}&a for &b{1}&a set-inherit-success: "&b{0}&a now inherits permissions from &b{1}&a in context {2}&a." 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." set-parent-success: "&b{0}&a had their existing parent groups cleared, and now only inherits &b{1}&a in context {2}&a." +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." unset-inherit-success: "&b{0}&a no longer inherits permissions from &b{1}&a in context {2}&a." unset-temp-inherit-success: "&b{0}&a no longer temporarily inherits permissions from &b{1}&a in context {2}&a." -clear-success: "&b{0}&a's permissions were cleared. (&b{1}&a nodes were removed.)" -clear-success-singular: "&b{0}&a's permissions were cleared. (&b{1}&a node was removed.)" -parent-clear-success: "&b{0}&a's parents were cleared. (&b{1}&a nodes were removed.)" -parent-clear-success-singular: "&b{0}&a's parents were cleared. (&b{1}&a node was removed.)" -meta-clear-success: "&b{0}&a's meta was cleared. (&b{1}&a nodes were removed.)" -meta-clear-success-singular: "&b{0}&a's meta was cleared. (&b{1}&a node was removed.)" +clear-success: "&b{0}&a's permissions were cleared in context {1}&a. (&b{2}&a nodes were removed.)" +clear-success-singular: "&b{0}&a's permissions were cleared in context {1}&a. (&b{2}&a node was removed.)" +parent-clear-success: "&b{0}&a's parents were cleared in context {1}&a. &b{2}&a nodes were removed.)" +parent-clear-success-singular: "&b{0}&a's parents were cleared in context {1}&a. &b{2}&a node was removed.)" +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.)" +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.)" +meta-clear-success: "&b{0}&a's meta was cleared in context {1}&a. &b{2}&a nodes were removed.)" +meta-clear-success-singular: "&b{0}&a's meta was cleared in context {1}&a. &b{2}&a node was removed.)" illegal-date-error: "Could not parse date '{0}'." past-date-error: "You cannot set a date in the past!" chat-meta-prefix-header: "&b{0}'s Prefixes" @@ -182,9 +175,9 @@ does-not-have-chat-meta: "{0} doesn't have that {1} set." add-chatmeta-success: "&b{0}&a had {1} &f\"{2}&f\"&a set at a priority of &b{3}&a in context {4}&a." add-temp-chatmeta-success: "&b{0}&a had {1} &f\"{2}&f\"&a set at a priority of &b{3}&a for a duration of &b{4}&a in context {5}&a." remove-chatmeta-success: "&b{0}&a had {1} &f\"{2}&f\"&a at priority &b{3}&a removed in context {4}&a." -bulk-remove-chatmeta-success: "&b{0}&a had all {1}es at priority &b{3}&a removed in context {4}&a." +bulk-remove-chatmeta-success: "&b{0}&a had all {1}es at priority &b{2}&a removed in context {3}&a." remove-temp-chatmeta-success: "&b{0}&a had temporary {1} &f\"{2}&f\"&a at priority &b{3}&a removed in context {4}&a." -bulk-remove-temp-chatmeta-success: "&b{0}&a had all temporary {1}es at priority &b{3}&a removed in context {4}&a." +bulk-remove-temp-chatmeta-success: "&b{0}&a had all temporary {1}es at priority &b{2}&a removed in context {3}&a." already-has-meta: "{0} already has that meta key value pair set." set-meta-success: "&aSet meta value for key &f\"{0}&f\"&a to &f\"{1}&f\"&a for &b{2}&a in context {3}&a." set-meta-temp-success: "&aSet meta value for key &f\"{0}&f\"&a to &f\"{1}&f\"&a for &b{2}&a for a duration of &b{3}&a in context {4}&a." @@ -199,8 +192,6 @@ bulk-update-unknown-id: "&aOperation with id &b{0}&a does not exist or has expir bulk-update-starting: "&aRunning bulk update." bulk-update-success: "&bBulk update completed successfully." bulk-update-failure: "&cBulk update failed. Check the console for errors." -bulk-change-type-error: "Invalid type. Was expecting 'server' or 'world'." -bulk-change-success: "&aApplied bulk change successfully. {0} records were changed." user-info-general: > {PREFIX}&b&l> &bUser Info: &f{0}\n {PREFIX}&f- &3UUID: &f{1}\n @@ -220,7 +211,6 @@ user-info-data: > {PREFIX}&f- &3Current Suffix: {3} info-parent-header: "&f- &aParent Groups:" info-temp-parent-header: "&f- &aTemporary Parent Groups:" -user-getuuid: "&bThe UUID of &b{0}&b is &b{1}&b." user-removegroup-error-primary: "You cannot remove a user from their primary group." user-primarygroup-success: "&b{0}&a's primary group was set to &b{1}&a." user-primarygroup-warn-option: "&cWarning: The primary group calculation method being used by this server &7({0}) &cmay not reflect this change." @@ -238,9 +228,6 @@ user-demote-endoftrack: "The end of track &4{0}&c was reached, so &4{1}&c was re user-demote-error-malformed: > {PREFIX}The previous group on the track, {0}, no longer exists. Unable to demote user.\n {PREFIX}Either create the group, or remove it from the track and try again. -user-showpos: > - &aShowing &b{0}&a's position on track &b{1}&a.\n - {2} group-info-general: > {PREFIX}&b&l> &bGroup Info: &f{0}\n {PREFIX}&f- &3Display Name: &f{1}\n diff --git a/common/src/main/java/me/lucko/luckperms/common/commands/impl/generic/parent/CommandParent.java b/common/src/main/java/me/lucko/luckperms/common/commands/impl/generic/parent/CommandParent.java index 1f293b8d7..1b9b36add 100644 --- a/common/src/main/java/me/lucko/luckperms/common/commands/impl/generic/parent/CommandParent.java +++ b/common/src/main/java/me/lucko/luckperms/common/commands/impl/generic/parent/CommandParent.java @@ -42,6 +42,7 @@ public class CommandParent extends SharedMainCommand .add(new ParentAddTemp()) .add(new ParentRemoveTemp()) .add(new ParentClear()) + .add(new ParentClearTrack()) .build()); } } diff --git a/common/src/main/java/me/lucko/luckperms/common/commands/impl/generic/parent/ParentClearTrack.java b/common/src/main/java/me/lucko/luckperms/common/commands/impl/generic/parent/ParentClearTrack.java new file mode 100644 index 000000000..dd86c5117 --- /dev/null +++ b/common/src/main/java/me/lucko/luckperms/common/commands/impl/generic/parent/ParentClearTrack.java @@ -0,0 +1,111 @@ +/* + * This file is part of LuckPerms, licensed under the MIT License. + * + * Copyright (c) lucko (Luck) + * 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 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; + } +} diff --git a/common/src/main/java/me/lucko/luckperms/common/constants/Message.java b/common/src/main/java/me/lucko/luckperms/common/constants/Message.java index 0a0fe74b3..c9493e84a 100644 --- a/common/src/main/java/me/lucko/luckperms/common/constants/Message.java +++ b/common/src/main/java/me/lucko/luckperms/common/constants/Message.java @@ -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" + diff --git a/common/src/main/java/me/lucko/luckperms/common/constants/Permission.java b/common/src/main/java/me/lucko/luckperms/common/constants/Permission.java index 7a6233905..2863dda82 100644 --- a/common/src/main/java/me/lucko/luckperms/common/constants/Permission.java +++ b/common/src/main/java/me/lucko/luckperms/common/constants/Permission.java @@ -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),