mirror of
https://github.com/LuckPerms/LuckPerms.git
synced 2024-12-28 03:57:36 +01:00
Refactor meta commands, working towards #23
This commit is contained in:
parent
2c43f6bf21
commit
d433a5461d
@ -123,7 +123,7 @@ public abstract class SubCommand<T> {
|
||||
* @return true if the sender can use the command
|
||||
*/
|
||||
public boolean isAuthorized(Sender sender) {
|
||||
return permission.isAuthorized(sender);
|
||||
return permission == null || permission.isAuthorized(sender);
|
||||
}
|
||||
|
||||
|
||||
|
@ -28,6 +28,7 @@ import me.lucko.luckperms.commands.MainCommand;
|
||||
import me.lucko.luckperms.commands.Sender;
|
||||
import me.lucko.luckperms.commands.SubCommand;
|
||||
import me.lucko.luckperms.commands.group.subcommands.*;
|
||||
import me.lucko.luckperms.commands.meta.MetaCommands;
|
||||
import me.lucko.luckperms.constants.Message;
|
||||
import me.lucko.luckperms.groups.Group;
|
||||
|
||||
@ -51,16 +52,7 @@ public class GroupMainCommand extends MainCommand<Group> {
|
||||
.add(new GroupSetTempInherit())
|
||||
.add(new GroupUnsetTempInherit())
|
||||
.add(new GroupShowTracks())
|
||||
.add(new GroupChatMeta())
|
||||
.add(new GroupAddPrefix())
|
||||
.add(new GroupAddSuffix())
|
||||
.add(new GroupRemovePrefix())
|
||||
.add(new GroupRemoveSuffix())
|
||||
.add(new GroupAddTempPrefix())
|
||||
.add(new GroupAddTempSuffix())
|
||||
.add(new GroupRemoveTempPrefix())
|
||||
.add(new GroupRemoveTempSuffix())
|
||||
.add(new GroupClearMeta())
|
||||
.add(new MetaCommands<>())
|
||||
.add(new GroupBulkChange())
|
||||
.add(new GroupClear())
|
||||
.add(new GroupRename())
|
||||
|
@ -1,118 +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.commands.group.subcommands;
|
||||
|
||||
import me.lucko.luckperms.LuckPermsPlugin;
|
||||
import me.lucko.luckperms.commands.*;
|
||||
import me.lucko.luckperms.constants.Message;
|
||||
import me.lucko.luckperms.constants.Permission;
|
||||
import me.lucko.luckperms.data.LogEntry;
|
||||
import me.lucko.luckperms.exceptions.ObjectAlreadyHasException;
|
||||
import me.lucko.luckperms.groups.Group;
|
||||
import me.lucko.luckperms.utils.ArgumentChecker;
|
||||
import me.lucko.luckperms.utils.DateUtil;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class GroupAddTempPrefix extends SubCommand<Group> {
|
||||
public GroupAddTempPrefix() {
|
||||
super("addtempprefix", "Adds a prefix to the group temporarily", Permission.GROUP_ADD_TEMP_PREFIX, Predicate.notInRange(3, 5),
|
||||
Arg.list(
|
||||
Arg.create("priority", true, "the priority to add the prefix at"),
|
||||
Arg.create("prefix", true, "the prefix string"),
|
||||
Arg.create("duration", true, "the duration until the prefix expires"),
|
||||
Arg.create("server", false, "the server to add the prefix on"),
|
||||
Arg.create("world", false, "the world to add the prefix on")
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, Group group, List<String> args, String label) {
|
||||
final String prefix = args.get(1).replace("{SPACE}", " ");
|
||||
int priority;
|
||||
try {
|
||||
priority = Integer.parseInt(args.get(0));
|
||||
} catch (NumberFormatException e) {
|
||||
Message.META_INVALID_PRIORITY.send(sender, args.get(0));
|
||||
return CommandResult.INVALID_ARGS;
|
||||
}
|
||||
|
||||
long duration;
|
||||
try {
|
||||
duration = Long.parseLong(args.get(2));
|
||||
} catch (NumberFormatException e) {
|
||||
try {
|
||||
duration = DateUtil.parseDateDiff(args.get(2), true);
|
||||
} catch (DateUtil.IllegalDateException e1) {
|
||||
Message.ILLEGAL_DATE_ERROR.send(sender, args.get(2));
|
||||
return CommandResult.INVALID_ARGS;
|
||||
}
|
||||
}
|
||||
|
||||
if (DateUtil.shouldExpire(duration)) {
|
||||
Message.PAST_DATE_ERROR.send(sender);
|
||||
return CommandResult.INVALID_ARGS;
|
||||
}
|
||||
|
||||
final String node = "prefix." + priority + "." + ArgumentChecker.escapeCharacters(prefix);
|
||||
|
||||
try {
|
||||
if (args.size() >= 4) {
|
||||
final String server = args.get(3).toLowerCase();
|
||||
if (ArgumentChecker.checkServer(server)) {
|
||||
Message.SERVER_INVALID_ENTRY.send(sender);
|
||||
return CommandResult.INVALID_ARGS;
|
||||
}
|
||||
|
||||
if (args.size() == 4) {
|
||||
group.setPermission(node, true, server, duration);
|
||||
Message.ADD_TEMP_PREFIX_SERVER_SUCCESS.send(sender, group.getDisplayName(), prefix, priority, server, DateUtil.formatDateDiff(duration));
|
||||
LogEntry.build().actor(sender).acted(group)
|
||||
.action("addtempprefix " + priority + " " + args.get(1) + " " + duration + " " + server)
|
||||
.build().submit(plugin, sender);
|
||||
} else {
|
||||
final String world = args.get(4).toLowerCase();
|
||||
group.setPermission(node, true, server, world, duration);
|
||||
Message.ADD_TEMP_PREFIX_SERVER_WORLD_SUCCESS.send(sender, group.getDisplayName(), prefix, priority, server, world, DateUtil.formatDateDiff(duration));
|
||||
LogEntry.build().actor(sender).acted(group)
|
||||
.action("addtempprefix " + priority + " " + args.get(1) + " " + duration + " " + server + " " + world)
|
||||
.build().submit(plugin, sender);
|
||||
}
|
||||
|
||||
} else {
|
||||
group.setPermission(node, true, duration);
|
||||
Message.ADD_TEMP_PREFIX_SUCCESS.send(sender, group.getDisplayName(), prefix, priority, DateUtil.formatDateDiff(duration));
|
||||
LogEntry.build().actor(sender).acted(group)
|
||||
.action("addtempprefix " + priority + " " + args.get(1) + " " + duration)
|
||||
.build().submit(plugin, sender);
|
||||
}
|
||||
|
||||
save(group, sender, plugin);
|
||||
return CommandResult.SUCCESS;
|
||||
} catch (ObjectAlreadyHasException e) {
|
||||
Message.ALREADY_HAS_PREFIX.send(sender, group.getDisplayName());
|
||||
return CommandResult.STATE_ERROR;
|
||||
}
|
||||
}
|
||||
}
|
@ -1,118 +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.commands.group.subcommands;
|
||||
|
||||
import me.lucko.luckperms.LuckPermsPlugin;
|
||||
import me.lucko.luckperms.commands.*;
|
||||
import me.lucko.luckperms.constants.Message;
|
||||
import me.lucko.luckperms.constants.Permission;
|
||||
import me.lucko.luckperms.data.LogEntry;
|
||||
import me.lucko.luckperms.exceptions.ObjectAlreadyHasException;
|
||||
import me.lucko.luckperms.groups.Group;
|
||||
import me.lucko.luckperms.utils.ArgumentChecker;
|
||||
import me.lucko.luckperms.utils.DateUtil;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class GroupAddTempSuffix extends SubCommand<Group> {
|
||||
public GroupAddTempSuffix() {
|
||||
super("addtempsuffix", "Adds a suffix to the group temporarily", Permission.GROUP_ADD_TEMP_SUFFIX, Predicate.notInRange(3, 5),
|
||||
Arg.list(
|
||||
Arg.create("priority", true, "the priority to add the suffix at"),
|
||||
Arg.create("suffix", true, "the suffix string"),
|
||||
Arg.create("duration", true, "the duration until the suffix expires"),
|
||||
Arg.create("server", false, "the server to add the suffix on"),
|
||||
Arg.create("world", false, "the world to add the suffix on")
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, Group group, List<String> args, String label) {
|
||||
final String suffix = args.get(1).replace("{SPACE}", " ");
|
||||
int priority;
|
||||
try {
|
||||
priority = Integer.parseInt(args.get(0));
|
||||
} catch (NumberFormatException e) {
|
||||
Message.META_INVALID_PRIORITY.send(sender, args.get(0));
|
||||
return CommandResult.INVALID_ARGS;
|
||||
}
|
||||
|
||||
long duration;
|
||||
try {
|
||||
duration = Long.parseLong(args.get(2));
|
||||
} catch (NumberFormatException e) {
|
||||
try {
|
||||
duration = DateUtil.parseDateDiff(args.get(2), true);
|
||||
} catch (DateUtil.IllegalDateException e1) {
|
||||
Message.ILLEGAL_DATE_ERROR.send(sender, args.get(2));
|
||||
return CommandResult.INVALID_ARGS;
|
||||
}
|
||||
}
|
||||
|
||||
if (DateUtil.shouldExpire(duration)) {
|
||||
Message.PAST_DATE_ERROR.send(sender);
|
||||
return CommandResult.INVALID_ARGS;
|
||||
}
|
||||
|
||||
final String node = "suffix." + priority + "." + ArgumentChecker.escapeCharacters(suffix);
|
||||
|
||||
try {
|
||||
if (args.size() >= 4) {
|
||||
final String server = args.get(3).toLowerCase();
|
||||
if (ArgumentChecker.checkServer(server)) {
|
||||
Message.SERVER_INVALID_ENTRY.send(sender);
|
||||
return CommandResult.INVALID_ARGS;
|
||||
}
|
||||
|
||||
if (args.size() == 4) {
|
||||
group.setPermission(node, true, server, duration);
|
||||
Message.ADD_TEMP_SUFFIX_SERVER_SUCCESS.send(sender, group.getDisplayName(), suffix, priority, server, DateUtil.formatDateDiff(duration));
|
||||
LogEntry.build().actor(sender).acted(group)
|
||||
.action("addtempsuffix " + priority + " " + args.get(1) + " " + duration + " " + server)
|
||||
.build().submit(plugin, sender);
|
||||
} else {
|
||||
final String world = args.get(4).toLowerCase();
|
||||
group.setPermission(node, true, server, world, duration);
|
||||
Message.ADD_TEMP_SUFFIX_SERVER_WORLD_SUCCESS.send(sender, group.getDisplayName(), suffix, priority, server, world, DateUtil.formatDateDiff(duration));
|
||||
LogEntry.build().actor(sender).acted(group)
|
||||
.action("addtempsuffix " + priority + " " + args.get(1) + " " + duration + " " + server + " " + world)
|
||||
.build().submit(plugin, sender);
|
||||
}
|
||||
|
||||
} else {
|
||||
group.setPermission(node, true, duration);
|
||||
Message.ADD_TEMP_SUFFIX_SUCCESS.send(sender, group.getDisplayName(), suffix, priority, DateUtil.formatDateDiff(duration));
|
||||
LogEntry.build().actor(sender).acted(group)
|
||||
.action("addtempsuffix " + priority + " " + args.get(1) + " " + duration)
|
||||
.build().submit(plugin, sender);
|
||||
}
|
||||
|
||||
save(group, sender, plugin);
|
||||
return CommandResult.SUCCESS;
|
||||
} catch (ObjectAlreadyHasException e) {
|
||||
Message.ALREADY_HAS_SUFFIX.send(sender, group.getDisplayName());
|
||||
return CommandResult.STATE_ERROR;
|
||||
}
|
||||
}
|
||||
}
|
@ -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.commands.group.subcommands;
|
||||
|
||||
import me.lucko.luckperms.LuckPermsPlugin;
|
||||
import me.lucko.luckperms.commands.*;
|
||||
import me.lucko.luckperms.constants.Message;
|
||||
import me.lucko.luckperms.constants.Permission;
|
||||
import me.lucko.luckperms.data.LogEntry;
|
||||
import me.lucko.luckperms.groups.Group;
|
||||
import me.lucko.luckperms.utils.ArgumentChecker;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class GroupClearMeta extends SubCommand<Group> {
|
||||
public GroupClearMeta() {
|
||||
super("clearmeta", "Clears the groups's meta", Permission.GROUP_CLEARMETA, Predicate.notInRange(0, 2),
|
||||
Arg.list(
|
||||
Arg.create("server", false, "the server name to filter by"),
|
||||
Arg.create("world", false, "the world name to filter by")
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, Group group, List<String> args, String label) {
|
||||
int before = group.getNodes().size();
|
||||
|
||||
if (args.size() == 0) {
|
||||
group.clearMeta();
|
||||
} else {
|
||||
final String server = args.get(0);
|
||||
if (ArgumentChecker.checkServer(server)) {
|
||||
Message.SERVER_INVALID_ENTRY.send(sender);
|
||||
return CommandResult.INVALID_ARGS;
|
||||
}
|
||||
|
||||
if (args.size() == 2) {
|
||||
final String world = args.get(1);
|
||||
group.clearMeta(server, world);
|
||||
|
||||
} else {
|
||||
group.clearMeta(server);
|
||||
}
|
||||
}
|
||||
|
||||
int changed = before - group.getNodes().size();
|
||||
if (changed == 1) {
|
||||
Message.META_CLEAR_SUCCESS_SINGULAR.send(sender, group.getName(), changed);
|
||||
} else {
|
||||
Message.META_CLEAR_SUCCESS.send(sender, group.getName(), changed);
|
||||
}
|
||||
|
||||
LogEntry.build().actor(sender).acted(group).action("clearmeta " + args.stream().collect(Collectors.joining(" "))).build().submit(plugin, sender);
|
||||
save(group, sender, plugin);
|
||||
return CommandResult.SUCCESS;
|
||||
}
|
||||
}
|
@ -1,153 +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.commands.group.subcommands;
|
||||
|
||||
import me.lucko.luckperms.LuckPermsPlugin;
|
||||
import me.lucko.luckperms.api.Node;
|
||||
import me.lucko.luckperms.commands.*;
|
||||
import me.lucko.luckperms.constants.Message;
|
||||
import me.lucko.luckperms.constants.Permission;
|
||||
import me.lucko.luckperms.data.LogEntry;
|
||||
import me.lucko.luckperms.exceptions.ObjectLacksException;
|
||||
import me.lucko.luckperms.groups.Group;
|
||||
import me.lucko.luckperms.utils.ArgumentChecker;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class GroupRemovePrefix extends SubCommand<Group> {
|
||||
public GroupRemovePrefix() {
|
||||
super("removeprefix", "Removes a prefix from the group", Permission.GROUP_REMOVEPREFIX, Predicate.notInRange(2, 4),
|
||||
Arg.list(
|
||||
Arg.create("priority", true, "the priority to remove the prefix at"),
|
||||
Arg.create("prefix", true, "the prefix string to remove"),
|
||||
Arg.create("server", false, "the server to remove the prefix on"),
|
||||
Arg.create("world", false, "the world to remove the prefix on")
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, Group group, List<String> args, String label) {
|
||||
final String prefix = args.get(1).replace("{SPACE}", " ");
|
||||
int priority;
|
||||
try {
|
||||
priority = Integer.parseInt(args.get(0));
|
||||
} catch (NumberFormatException e) {
|
||||
Message.META_INVALID_PRIORITY.send(sender, args.get(0));
|
||||
return CommandResult.INVALID_ARGS;
|
||||
}
|
||||
|
||||
if (prefix.equalsIgnoreCase("null")) {
|
||||
String server = null;
|
||||
String world = null;
|
||||
|
||||
if (args.size() >= 3) {
|
||||
server = args.get(2).toLowerCase();
|
||||
if (ArgumentChecker.checkServer(server)) {
|
||||
Message.SERVER_INVALID_ENTRY.send(sender);
|
||||
return CommandResult.INVALID_ARGS;
|
||||
}
|
||||
|
||||
if (args.size() != 3) {
|
||||
world = args.get(3).toLowerCase();
|
||||
}
|
||||
}
|
||||
|
||||
List<Node> toRemove = new ArrayList<>();
|
||||
for (Node node : group.getNodes()) {
|
||||
if (!node.isPrefix()) continue;
|
||||
if (node.getPrefix().getKey() != priority) continue;
|
||||
if (node.isTemporary()) continue;
|
||||
|
||||
if (node.getServer().isPresent()) {
|
||||
if (server == null) continue;
|
||||
if (!node.getServer().get().equalsIgnoreCase(server)) continue;
|
||||
} else {
|
||||
if (server != null) continue;
|
||||
}
|
||||
|
||||
if (node.getWorld().isPresent()) {
|
||||
if (world == null) continue;
|
||||
if (!node.getWorld().get().equalsIgnoreCase(world)) continue;
|
||||
} else {
|
||||
if (world != null) continue;
|
||||
}
|
||||
|
||||
toRemove.add(node);
|
||||
}
|
||||
|
||||
toRemove.forEach(n -> {
|
||||
try {
|
||||
group.unsetPermission(n);
|
||||
} catch (ObjectLacksException ignored) {}
|
||||
});
|
||||
|
||||
Message.BULK_CHANGE_SUCCESS.send(sender, toRemove.size());
|
||||
save(group, sender, plugin);
|
||||
return CommandResult.SUCCESS;
|
||||
|
||||
} else {
|
||||
|
||||
final String node = "prefix." + priority + "." + ArgumentChecker.escapeCharacters(prefix);
|
||||
|
||||
try {
|
||||
if (args.size() >= 3) {
|
||||
final String server = args.get(2).toLowerCase();
|
||||
if (ArgumentChecker.checkServer(server)) {
|
||||
Message.SERVER_INVALID_ENTRY.send(sender);
|
||||
return CommandResult.INVALID_ARGS;
|
||||
}
|
||||
|
||||
if (args.size() == 3) {
|
||||
group.unsetPermission(node, server);
|
||||
Message.REMOVEPREFIX_SERVER_SUCCESS.send(sender, group.getDisplayName(), prefix, priority, server);
|
||||
LogEntry.build().actor(sender).acted(group)
|
||||
.action("removeprefix " + priority + " " + args.get(1) + " " + server)
|
||||
.build().submit(plugin, sender);
|
||||
} else {
|
||||
final String world = args.get(3).toLowerCase();
|
||||
group.unsetPermission(node, server, world);
|
||||
Message.REMOVEPREFIX_SERVER_WORLD_SUCCESS.send(sender, group.getDisplayName(), prefix, priority, server, world);
|
||||
LogEntry.build().actor(sender).acted(group)
|
||||
.action("removeprefix " + priority + " " + args.get(1) + " " + server + " " + world)
|
||||
.build().submit(plugin, sender);
|
||||
}
|
||||
|
||||
} else {
|
||||
group.unsetPermission(node);
|
||||
Message.REMOVEPREFIX_SUCCESS.send(sender, group.getDisplayName(), prefix, priority);
|
||||
LogEntry.build().actor(sender).acted(group)
|
||||
.action("removeprefix " + priority + " " + args.get(1))
|
||||
.build().submit(plugin, sender);
|
||||
}
|
||||
|
||||
save(group, sender, plugin);
|
||||
return CommandResult.SUCCESS;
|
||||
} catch (ObjectLacksException e) {
|
||||
Message.DOES_NOT_HAVE_PREFIX.send(sender, group.getDisplayName());
|
||||
return CommandResult.STATE_ERROR;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -1,153 +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.commands.group.subcommands;
|
||||
|
||||
import me.lucko.luckperms.LuckPermsPlugin;
|
||||
import me.lucko.luckperms.api.Node;
|
||||
import me.lucko.luckperms.commands.*;
|
||||
import me.lucko.luckperms.constants.Message;
|
||||
import me.lucko.luckperms.constants.Permission;
|
||||
import me.lucko.luckperms.data.LogEntry;
|
||||
import me.lucko.luckperms.exceptions.ObjectLacksException;
|
||||
import me.lucko.luckperms.groups.Group;
|
||||
import me.lucko.luckperms.utils.ArgumentChecker;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class GroupRemoveSuffix extends SubCommand<Group> {
|
||||
public GroupRemoveSuffix() {
|
||||
super("removesuffix", "Removes a suffix from the group", Permission.GROUP_REMOVESUFFIX, Predicate.notInRange(2, 4),
|
||||
Arg.list(
|
||||
Arg.create("priority", true, "the priority to remove the suffix at"),
|
||||
Arg.create("suffix", true, "the suffix string to remove"),
|
||||
Arg.create("server", false, "the server to remove the suffix on"),
|
||||
Arg.create("world", false, "the world to remove the suffix on")
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, Group group, List<String> args, String label) {
|
||||
final String suffix = args.get(1).replace("{SPACE}", " ");
|
||||
int priority;
|
||||
try {
|
||||
priority = Integer.parseInt(args.get(0));
|
||||
} catch (NumberFormatException e) {
|
||||
Message.META_INVALID_PRIORITY.send(sender, args.get(0));
|
||||
return CommandResult.INVALID_ARGS;
|
||||
}
|
||||
|
||||
if (suffix.equalsIgnoreCase("null")) {
|
||||
String server = null;
|
||||
String world = null;
|
||||
|
||||
if (args.size() >= 3) {
|
||||
server = args.get(2).toLowerCase();
|
||||
if (ArgumentChecker.checkServer(server)) {
|
||||
Message.SERVER_INVALID_ENTRY.send(sender);
|
||||
return CommandResult.INVALID_ARGS;
|
||||
}
|
||||
|
||||
if (args.size() != 3) {
|
||||
world = args.get(3).toLowerCase();
|
||||
}
|
||||
}
|
||||
|
||||
List<Node> toRemove = new ArrayList<>();
|
||||
for (Node node : group.getNodes()) {
|
||||
if (!node.isSuffix()) continue;
|
||||
if (node.getSuffix().getKey() != priority) continue;
|
||||
if (node.isTemporary()) continue;
|
||||
|
||||
if (node.getServer().isPresent()) {
|
||||
if (server == null) continue;
|
||||
if (!node.getServer().get().equalsIgnoreCase(server)) continue;
|
||||
} else {
|
||||
if (server != null) continue;
|
||||
}
|
||||
|
||||
if (node.getWorld().isPresent()) {
|
||||
if (world == null) continue;
|
||||
if (!node.getWorld().get().equalsIgnoreCase(world)) continue;
|
||||
} else {
|
||||
if (world != null) continue;
|
||||
}
|
||||
|
||||
toRemove.add(node);
|
||||
}
|
||||
|
||||
toRemove.forEach(n -> {
|
||||
try {
|
||||
group.unsetPermission(n);
|
||||
} catch (ObjectLacksException ignored) {}
|
||||
});
|
||||
|
||||
Message.BULK_CHANGE_SUCCESS.send(sender, toRemove.size());
|
||||
save(group, sender, plugin);
|
||||
return CommandResult.SUCCESS;
|
||||
|
||||
} else {
|
||||
|
||||
final String node = "suffix." + priority + "." + ArgumentChecker.escapeCharacters(suffix);
|
||||
|
||||
try {
|
||||
if (args.size() >= 3) {
|
||||
final String server = args.get(2).toLowerCase();
|
||||
if (ArgumentChecker.checkServer(server)) {
|
||||
Message.SERVER_INVALID_ENTRY.send(sender);
|
||||
return CommandResult.INVALID_ARGS;
|
||||
}
|
||||
|
||||
if (args.size() == 3) {
|
||||
group.unsetPermission(node, server);
|
||||
Message.REMOVESUFFIX_SERVER_SUCCESS.send(sender, group.getDisplayName(), suffix, priority, server);
|
||||
LogEntry.build().actor(sender).acted(group)
|
||||
.action("removesuffix " + priority + " " + args.get(1) + " " + server)
|
||||
.build().submit(plugin, sender);
|
||||
} else {
|
||||
final String world = args.get(3).toLowerCase();
|
||||
group.unsetPermission(node, server, world);
|
||||
Message.REMOVESUFFIX_SERVER_WORLD_SUCCESS.send(sender, group.getDisplayName(), suffix, priority, server, world);
|
||||
LogEntry.build().actor(sender).acted(group)
|
||||
.action("removesuffix " + priority + " " + args.get(1) + " " + server + " " + world)
|
||||
.build().submit(plugin, sender);
|
||||
}
|
||||
|
||||
} else {
|
||||
group.unsetPermission(node);
|
||||
Message.REMOVESUFFIX_SUCCESS.send(sender, group.getDisplayName(), suffix, priority);
|
||||
LogEntry.build().actor(sender).acted(group)
|
||||
.action("removesuffix " + priority + " " + args.get(1))
|
||||
.build().submit(plugin, sender);
|
||||
}
|
||||
|
||||
save(group, sender, plugin);
|
||||
return CommandResult.SUCCESS;
|
||||
} catch (ObjectLacksException e) {
|
||||
Message.DOES_NOT_HAVE_SUFFIX.send(sender, group.getDisplayName());
|
||||
return CommandResult.STATE_ERROR;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -1,154 +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.commands.group.subcommands;
|
||||
|
||||
import me.lucko.luckperms.LuckPermsPlugin;
|
||||
import me.lucko.luckperms.api.Node;
|
||||
import me.lucko.luckperms.commands.*;
|
||||
import me.lucko.luckperms.constants.Message;
|
||||
import me.lucko.luckperms.constants.Permission;
|
||||
import me.lucko.luckperms.data.LogEntry;
|
||||
import me.lucko.luckperms.exceptions.ObjectLacksException;
|
||||
import me.lucko.luckperms.groups.Group;
|
||||
import me.lucko.luckperms.utils.ArgumentChecker;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class GroupRemoveTempPrefix extends SubCommand<Group> {
|
||||
public GroupRemoveTempPrefix() {
|
||||
super("removetempprefix", "Removes a temporary prefix from the group", Permission.GROUP_REMOVE_TEMP_PREFIX,
|
||||
Predicate.notInRange(2, 4),
|
||||
Arg.list(
|
||||
Arg.create("priority", true, "the priority to remove the prefix at"),
|
||||
Arg.create("prefix", true, "the prefix string to remove"),
|
||||
Arg.create("server", false, "the server to remove the prefix on"),
|
||||
Arg.create("world", false, "the world to remove the prefix on")
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, Group group, List<String> args, String label) {
|
||||
final String prefix = args.get(1).replace("{SPACE}", " ");
|
||||
int priority;
|
||||
try {
|
||||
priority = Integer.parseInt(args.get(0));
|
||||
} catch (NumberFormatException e) {
|
||||
Message.META_INVALID_PRIORITY.send(sender, args.get(0));
|
||||
return CommandResult.INVALID_ARGS;
|
||||
}
|
||||
|
||||
if (prefix.equalsIgnoreCase("null")) {
|
||||
String server = null;
|
||||
String world = null;
|
||||
|
||||
if (args.size() >= 3) {
|
||||
server = args.get(2).toLowerCase();
|
||||
if (ArgumentChecker.checkServer(server)) {
|
||||
Message.SERVER_INVALID_ENTRY.send(sender);
|
||||
return CommandResult.INVALID_ARGS;
|
||||
}
|
||||
|
||||
if (args.size() != 3) {
|
||||
world = args.get(3).toLowerCase();
|
||||
}
|
||||
}
|
||||
|
||||
List<Node> toRemove = new ArrayList<>();
|
||||
for (Node node : group.getNodes()) {
|
||||
if (!node.isPrefix()) continue;
|
||||
if (node.getPrefix().getKey() != priority) continue;
|
||||
if (node.isPermanent()) continue;
|
||||
|
||||
if (node.getServer().isPresent()) {
|
||||
if (server == null) continue;
|
||||
if (!node.getServer().get().equalsIgnoreCase(server)) continue;
|
||||
} else {
|
||||
if (server != null) continue;
|
||||
}
|
||||
|
||||
if (node.getWorld().isPresent()) {
|
||||
if (world == null) continue;
|
||||
if (!node.getWorld().get().equalsIgnoreCase(world)) continue;
|
||||
} else {
|
||||
if (world != null) continue;
|
||||
}
|
||||
|
||||
toRemove.add(node);
|
||||
}
|
||||
|
||||
toRemove.forEach(n -> {
|
||||
try {
|
||||
group.unsetPermission(n);
|
||||
} catch (ObjectLacksException ignored) {}
|
||||
});
|
||||
|
||||
Message.BULK_CHANGE_SUCCESS.send(sender, toRemove.size());
|
||||
save(group, sender, plugin);
|
||||
return CommandResult.SUCCESS;
|
||||
|
||||
} else {
|
||||
|
||||
final String node = "prefix." + priority + "." + ArgumentChecker.escapeCharacters(prefix);
|
||||
|
||||
try {
|
||||
if (args.size() >= 3) {
|
||||
final String server = args.get(2).toLowerCase();
|
||||
if (ArgumentChecker.checkServer(server)) {
|
||||
Message.SERVER_INVALID_ENTRY.send(sender);
|
||||
return CommandResult.INVALID_ARGS;
|
||||
}
|
||||
|
||||
if (args.size() == 3) {
|
||||
group.unsetPermission(node, server, true);
|
||||
Message.REMOVE_TEMP_PREFIX_SERVER_SUCCESS.send(sender, group.getDisplayName(), prefix, priority, server);
|
||||
LogEntry.build().actor(sender).acted(group)
|
||||
.action("removetempprefix " + priority + " " + args.get(1) + " " + server)
|
||||
.build().submit(plugin, sender);
|
||||
} else {
|
||||
final String world = args.get(3).toLowerCase();
|
||||
group.unsetPermission(node, server, world, true);
|
||||
Message.REMOVE_TEMP_PREFIX_SERVER_WORLD_SUCCESS.send(sender, group.getDisplayName(), prefix, priority, server, world);
|
||||
LogEntry.build().actor(sender).acted(group)
|
||||
.action("removetempprefix " + priority + " " + args.get(1) + " " + server + " " + world)
|
||||
.build().submit(plugin, sender);
|
||||
}
|
||||
|
||||
} else {
|
||||
group.unsetPermission(node, true);
|
||||
Message.REMOVE_TEMP_PREFIX_SUCCESS.send(sender, group.getDisplayName(), prefix, priority);
|
||||
LogEntry.build().actor(sender).acted(group)
|
||||
.action("removetempprefix " + priority + " " + args.get(1))
|
||||
.build().submit(plugin, sender);
|
||||
}
|
||||
|
||||
save(group, sender, plugin);
|
||||
return CommandResult.SUCCESS;
|
||||
} catch (ObjectLacksException e) {
|
||||
Message.DOES_NOT_HAVE_PREFIX.send(sender, group.getDisplayName());
|
||||
return CommandResult.STATE_ERROR;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -1,154 +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.commands.group.subcommands;
|
||||
|
||||
import me.lucko.luckperms.LuckPermsPlugin;
|
||||
import me.lucko.luckperms.api.Node;
|
||||
import me.lucko.luckperms.commands.*;
|
||||
import me.lucko.luckperms.constants.Message;
|
||||
import me.lucko.luckperms.constants.Permission;
|
||||
import me.lucko.luckperms.data.LogEntry;
|
||||
import me.lucko.luckperms.exceptions.ObjectLacksException;
|
||||
import me.lucko.luckperms.groups.Group;
|
||||
import me.lucko.luckperms.utils.ArgumentChecker;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class GroupRemoveTempSuffix extends SubCommand<Group> {
|
||||
public GroupRemoveTempSuffix() {
|
||||
super("removetempsuffix", "Removes a temporary suffix from the group", Permission.GROUP_REMOVE_TEMP_SUFFIX,
|
||||
Predicate.notInRange(2, 4),
|
||||
Arg.list(
|
||||
Arg.create("priority", true, "the priority to remove the suffix at"),
|
||||
Arg.create("suffix", true, "the suffix string to remove"),
|
||||
Arg.create("server", false, "the server to remove the suffix on"),
|
||||
Arg.create("world", false, "the world to remove the suffix on")
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, Group group, List<String> args, String label) {
|
||||
final String suffix = args.get(1).replace("{SPACE}", " ");
|
||||
int priority;
|
||||
try {
|
||||
priority = Integer.parseInt(args.get(0));
|
||||
} catch (NumberFormatException e) {
|
||||
Message.META_INVALID_PRIORITY.send(sender, args.get(0));
|
||||
return CommandResult.INVALID_ARGS;
|
||||
}
|
||||
|
||||
if (suffix.equalsIgnoreCase("null")) {
|
||||
String server = null;
|
||||
String world = null;
|
||||
|
||||
if (args.size() >= 3) {
|
||||
server = args.get(2).toLowerCase();
|
||||
if (ArgumentChecker.checkServer(server)) {
|
||||
Message.SERVER_INVALID_ENTRY.send(sender);
|
||||
return CommandResult.INVALID_ARGS;
|
||||
}
|
||||
|
||||
if (args.size() != 3) {
|
||||
world = args.get(3).toLowerCase();
|
||||
}
|
||||
}
|
||||
|
||||
List<Node> toRemove = new ArrayList<>();
|
||||
for (Node node : group.getNodes()) {
|
||||
if (!node.isSuffix()) continue;
|
||||
if (node.getSuffix().getKey() != priority) continue;
|
||||
if (node.isPermanent()) continue;
|
||||
|
||||
if (node.getServer().isPresent()) {
|
||||
if (server == null) continue;
|
||||
if (!node.getServer().get().equalsIgnoreCase(server)) continue;
|
||||
} else {
|
||||
if (server != null) continue;
|
||||
}
|
||||
|
||||
if (node.getWorld().isPresent()) {
|
||||
if (world == null) continue;
|
||||
if (!node.getWorld().get().equalsIgnoreCase(world)) continue;
|
||||
} else {
|
||||
if (world != null) continue;
|
||||
}
|
||||
|
||||
toRemove.add(node);
|
||||
}
|
||||
|
||||
toRemove.forEach(n -> {
|
||||
try {
|
||||
group.unsetPermission(n);
|
||||
} catch (ObjectLacksException ignored) {}
|
||||
});
|
||||
|
||||
Message.BULK_CHANGE_SUCCESS.send(sender, toRemove.size());
|
||||
save(group, sender, plugin);
|
||||
return CommandResult.SUCCESS;
|
||||
|
||||
} else {
|
||||
|
||||
final String node = "suffix." + priority + "." + ArgumentChecker.escapeCharacters(suffix);
|
||||
|
||||
try {
|
||||
if (args.size() >= 3) {
|
||||
final String server = args.get(2).toLowerCase();
|
||||
if (ArgumentChecker.checkServer(server)) {
|
||||
Message.SERVER_INVALID_ENTRY.send(sender);
|
||||
return CommandResult.INVALID_ARGS;
|
||||
}
|
||||
|
||||
if (args.size() == 3) {
|
||||
group.unsetPermission(node, server, true);
|
||||
Message.REMOVE_TEMP_SUFFIX_SERVER_SUCCESS.send(sender, group.getDisplayName(), suffix, priority, server);
|
||||
LogEntry.build().actor(sender).acted(group)
|
||||
.action("removetempsuffix " + priority + " " + args.get(1) + " " + server)
|
||||
.build().submit(plugin, sender);
|
||||
} else {
|
||||
final String world = args.get(3).toLowerCase();
|
||||
group.unsetPermission(node, server, world, true);
|
||||
Message.REMOVE_TEMP_SUFFIX_SERVER_WORLD_SUCCESS.send(sender, group.getDisplayName(), suffix, priority, server, world);
|
||||
LogEntry.build().actor(sender).acted(group)
|
||||
.action("removetempsuffix " + priority + " " + args.get(1) + " " + server + " " + world)
|
||||
.build().submit(plugin, sender);
|
||||
}
|
||||
|
||||
} else {
|
||||
group.unsetPermission(node, true);
|
||||
Message.REMOVE_TEMP_SUFFIX_SUCCESS.send(sender, group.getDisplayName(), suffix, priority);
|
||||
LogEntry.build().actor(sender).acted(group)
|
||||
.action("removetempsuffix " + priority + " " + args.get(1))
|
||||
.build().submit(plugin, sender);
|
||||
}
|
||||
|
||||
save(group, sender, plugin);
|
||||
return CommandResult.SUCCESS;
|
||||
} catch (ObjectLacksException e) {
|
||||
Message.DOES_NOT_HAVE_SUFFIX.send(sender, group.getDisplayName());
|
||||
return CommandResult.STATE_ERROR;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,114 @@
|
||||
/*
|
||||
* 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.commands.meta;
|
||||
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import me.lucko.luckperms.LuckPermsPlugin;
|
||||
import me.lucko.luckperms.commands.*;
|
||||
import me.lucko.luckperms.commands.meta.subcommands.*;
|
||||
import me.lucko.luckperms.constants.Message;
|
||||
import me.lucko.luckperms.core.PermissionHolder;
|
||||
import me.lucko.luckperms.users.User;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class MetaCommands<T extends PermissionHolder> extends SubCommand<T> {
|
||||
private final List<MetaSubCommand> subCommands = ImmutableList.<MetaSubCommand>builder()
|
||||
.add(new MetaInfo())
|
||||
.add(new MetaAddPrefix())
|
||||
.add(new MetaAddSuffix())
|
||||
.add(new MetaRemovePrefix())
|
||||
.add(new MetaRemoveSuffix())
|
||||
.add(new MetaAddTempPrefix())
|
||||
.add(new MetaAddTempSuffix())
|
||||
.add(new MetaRemoveTempPrefix())
|
||||
.add(new MetaRemoveTempSuffix())
|
||||
.add(new MetaClear())
|
||||
.build();
|
||||
|
||||
public MetaCommands() {
|
||||
super("meta", "Edit metadata values", null, Predicate.alwaysFalse(), null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, T t, List<String> args, String label) {
|
||||
boolean user = t instanceof User;
|
||||
|
||||
if (args.size() == 0) {
|
||||
sendUsageMeta(sender, user, label);
|
||||
return CommandResult.INVALID_ARGS;
|
||||
}
|
||||
|
||||
Optional<MetaSubCommand> o = subCommands.stream()
|
||||
.filter(s -> s.getName().equalsIgnoreCase(args.get(0)))
|
||||
.limit(1)
|
||||
.findAny();
|
||||
|
||||
if (!o.isPresent()) {
|
||||
Message.COMMAND_NOT_RECOGNISED.send(sender);
|
||||
return CommandResult.INVALID_ARGS;
|
||||
}
|
||||
|
||||
final MetaSubCommand sub = o.get();
|
||||
if (!sub.isAuthorized(sender, user)) {
|
||||
Message.COMMAND_NO_PERMISSION.send(sender);
|
||||
return CommandResult.NO_PERMISSION;
|
||||
}
|
||||
|
||||
List<String> strippedArgs = new ArrayList<>();
|
||||
if (args.size() > 1) {
|
||||
strippedArgs.addAll(args.subList(1, args.size()));
|
||||
}
|
||||
|
||||
if (sub.getIsArgumentInvalid().test(strippedArgs.size())) {
|
||||
sub.sendDetailedUsage(sender);
|
||||
return CommandResult.INVALID_ARGS;
|
||||
}
|
||||
|
||||
return sub.execute(plugin, sender, t, strippedArgs);
|
||||
}
|
||||
|
||||
private void sendUsageMeta(Sender sender, boolean user, String label) {
|
||||
List<MetaSubCommand> subs = subCommands.stream()
|
||||
.filter(s -> s.isAuthorized(sender, user))
|
||||
.collect(Collectors.toList());
|
||||
|
||||
if (subs.size() > 0) {
|
||||
if (user) {
|
||||
Util.sendPluginMessage(sender, "&bMeta Sub Commands: &7(" + String.format("/%s user <user> meta ...)", label));
|
||||
} else {
|
||||
Util.sendPluginMessage(sender, "&bMeta Sub Commands: &7(" + String.format("/%s group <group> meta ...)", label));
|
||||
}
|
||||
|
||||
for (MetaSubCommand s : subs) {
|
||||
s.sendUsage(sender);
|
||||
}
|
||||
|
||||
} else {
|
||||
Message.COMMAND_NO_PERMISSION.send(sender);
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,124 @@
|
||||
/*
|
||||
* 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.commands.meta;
|
||||
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
import me.lucko.luckperms.LuckPermsPlugin;
|
||||
import me.lucko.luckperms.commands.Arg;
|
||||
import me.lucko.luckperms.commands.CommandResult;
|
||||
import me.lucko.luckperms.commands.Sender;
|
||||
import me.lucko.luckperms.commands.Util;
|
||||
import me.lucko.luckperms.constants.Message;
|
||||
import me.lucko.luckperms.constants.Permission;
|
||||
import me.lucko.luckperms.core.PermissionHolder;
|
||||
import me.lucko.luckperms.groups.Group;
|
||||
import me.lucko.luckperms.users.User;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.function.Predicate;
|
||||
|
||||
@Getter
|
||||
@AllArgsConstructor
|
||||
public abstract class MetaSubCommand {
|
||||
/**
|
||||
* The name of the sub command
|
||||
*/
|
||||
private final String name;
|
||||
|
||||
/**
|
||||
* A brief description of what the sub command does
|
||||
*/
|
||||
private final String description;
|
||||
|
||||
/**
|
||||
* The permission needed to use this command
|
||||
*/
|
||||
private final Permission userPermission;
|
||||
private final Permission groupPermission;
|
||||
|
||||
/**
|
||||
* Predicate to test if the argument length given is invalid
|
||||
*/
|
||||
private final Predicate<? super Integer> isArgumentInvalid;
|
||||
|
||||
private final ImmutableList<Arg> args;
|
||||
|
||||
public abstract CommandResult execute(LuckPermsPlugin plugin, Sender sender, PermissionHolder holder, List<String> args);
|
||||
|
||||
public void sendUsage(Sender sender) {
|
||||
String usage = "";
|
||||
if (args != null) {
|
||||
usage += "&3 - &7";
|
||||
for (Arg arg : args) {
|
||||
usage += arg.asPrettyString() + " ";
|
||||
}
|
||||
}
|
||||
|
||||
Util.sendPluginMessage(sender, "&3> &a" + getName() + usage);
|
||||
}
|
||||
|
||||
public void sendDetailedUsage(Sender sender) {
|
||||
Util.sendPluginMessage(sender, "&3&lCommand Usage &3- &b" + getName());
|
||||
Util.sendPluginMessage(sender, "&b> &7" + getDescription());
|
||||
if (args != null) {
|
||||
Util.sendPluginMessage(sender, "&3Arguments:");
|
||||
for (Arg arg : args) {
|
||||
Util.sendPluginMessage(sender, "&b- " + arg.asPrettyString() + "&3 -> &7" + arg.getDescription());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public boolean isAuthorized(Sender sender, boolean user) {
|
||||
return user ? userPermission.isAuthorized(sender) : groupPermission.isAuthorized(sender);
|
||||
}
|
||||
|
||||
protected static void save(PermissionHolder holder, Sender sender, LuckPermsPlugin plugin) {
|
||||
if (holder instanceof User) {
|
||||
User user = ((User) holder);
|
||||
if (plugin.getDatastore().saveUser(user)) {
|
||||
Message.USER_SAVE_SUCCESS.send(sender);
|
||||
} else {
|
||||
Message.USER_SAVE_ERROR.send(sender);
|
||||
}
|
||||
|
||||
user.refreshPermissions();
|
||||
return;
|
||||
}
|
||||
|
||||
if (holder instanceof Group) {
|
||||
Group group = ((Group) holder);
|
||||
if (plugin.getDatastore().saveGroup(group)) {
|
||||
Message.GROUP_SAVE_SUCCESS.send(sender);
|
||||
} else {
|
||||
Message.GROUP_SAVE_ERROR.send(sender);
|
||||
}
|
||||
|
||||
plugin.runUpdateTask();
|
||||
return;
|
||||
}
|
||||
|
||||
throw new IllegalArgumentException();
|
||||
}
|
||||
}
|
@ -20,22 +20,26 @@
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
package me.lucko.luckperms.commands.group.subcommands;
|
||||
package me.lucko.luckperms.commands.meta.subcommands;
|
||||
|
||||
import me.lucko.luckperms.LuckPermsPlugin;
|
||||
import me.lucko.luckperms.commands.*;
|
||||
import me.lucko.luckperms.commands.Arg;
|
||||
import me.lucko.luckperms.commands.CommandResult;
|
||||
import me.lucko.luckperms.commands.Predicate;
|
||||
import me.lucko.luckperms.commands.Sender;
|
||||
import me.lucko.luckperms.commands.meta.MetaSubCommand;
|
||||
import me.lucko.luckperms.constants.Message;
|
||||
import me.lucko.luckperms.constants.Permission;
|
||||
import me.lucko.luckperms.core.PermissionHolder;
|
||||
import me.lucko.luckperms.data.LogEntry;
|
||||
import me.lucko.luckperms.exceptions.ObjectAlreadyHasException;
|
||||
import me.lucko.luckperms.groups.Group;
|
||||
import me.lucko.luckperms.utils.ArgumentChecker;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class GroupAddPrefix extends SubCommand<Group> {
|
||||
public GroupAddPrefix() {
|
||||
super("addprefix", "Adds a prefix to the group", Permission.GROUP_ADDPREFIX, Predicate.notInRange(2, 4),
|
||||
public class MetaAddPrefix extends MetaSubCommand {
|
||||
public MetaAddPrefix() {
|
||||
super("addprefix", "Adds a prefix", Permission.USER_ADDPREFIX, Permission.GROUP_ADDPREFIX, Predicate.notInRange(2, 4),
|
||||
Arg.list(
|
||||
Arg.create("priority", true, "the priority to add the prefix at"),
|
||||
Arg.create("prefix", true, "the prefix string"),
|
||||
@ -46,7 +50,7 @@ public class GroupAddPrefix extends SubCommand<Group> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, Group group, List<String> args, String label) {
|
||||
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, PermissionHolder holder, List<String> args) {
|
||||
final String prefix = args.get(1).replace("{SPACE}", " ");
|
||||
int priority;
|
||||
try {
|
||||
@ -67,32 +71,32 @@ public class GroupAddPrefix extends SubCommand<Group> {
|
||||
}
|
||||
|
||||
if (args.size() == 3) {
|
||||
group.setPermission(node, true, server);
|
||||
Message.ADDPREFIX_SERVER_SUCCESS.send(sender, group.getDisplayName(), prefix, priority, server);
|
||||
LogEntry.build().actor(sender).acted(group)
|
||||
.action("addprefix " + priority + " " + args.get(1) + " " + server)
|
||||
holder.setPermission(node, true, server);
|
||||
Message.ADDPREFIX_SERVER_SUCCESS.send(sender, holder.getFriendlyName(), prefix, priority, server);
|
||||
LogEntry.build().actor(sender).acted(holder)
|
||||
.action("meta addprefix " + priority + " " + args.get(1) + " " + server)
|
||||
.build().submit(plugin, sender);
|
||||
} else {
|
||||
final String world = args.get(3).toLowerCase();
|
||||
group.setPermission(node, true, server, world);
|
||||
Message.ADDPREFIX_SERVER_WORLD_SUCCESS.send(sender, group.getDisplayName(), prefix, priority, server, world);
|
||||
LogEntry.build().actor(sender).acted(group)
|
||||
.action("addprefix " + priority + " " + args.get(1) + " " + server + " " + world)
|
||||
holder.setPermission(node, true, server, world);
|
||||
Message.ADDPREFIX_SERVER_WORLD_SUCCESS.send(sender, holder.getFriendlyName(), prefix, priority, server, world);
|
||||
LogEntry.build().actor(sender).acted(holder)
|
||||
.action("meta addprefix " + priority + " " + args.get(1) + " " + server + " " + world)
|
||||
.build().submit(plugin, sender);
|
||||
}
|
||||
|
||||
} else {
|
||||
group.setPermission(node, true);
|
||||
Message.ADDPREFIX_SUCCESS.send(sender, group.getDisplayName(), prefix, priority);
|
||||
LogEntry.build().actor(sender).acted(group)
|
||||
.action("addprefix " + priority + " " + args.get(1))
|
||||
holder.setPermission(node, true);
|
||||
Message.ADDPREFIX_SUCCESS.send(sender, holder.getFriendlyName(), prefix, priority);
|
||||
LogEntry.build().actor(sender).acted(holder)
|
||||
.action("meta addprefix " + priority + " " + args.get(1))
|
||||
.build().submit(plugin, sender);
|
||||
}
|
||||
|
||||
save(group, sender, plugin);
|
||||
save(holder, sender, plugin);
|
||||
return CommandResult.SUCCESS;
|
||||
} catch (ObjectAlreadyHasException e) {
|
||||
Message.ALREADY_HAS_PREFIX.send(sender, group.getDisplayName());
|
||||
Message.ALREADY_HAS_PREFIX.send(sender, holder.getFriendlyName());
|
||||
return CommandResult.STATE_ERROR;
|
||||
}
|
||||
}
|
@ -20,22 +20,26 @@
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
package me.lucko.luckperms.commands.group.subcommands;
|
||||
package me.lucko.luckperms.commands.meta.subcommands;
|
||||
|
||||
import me.lucko.luckperms.LuckPermsPlugin;
|
||||
import me.lucko.luckperms.commands.*;
|
||||
import me.lucko.luckperms.commands.Arg;
|
||||
import me.lucko.luckperms.commands.CommandResult;
|
||||
import me.lucko.luckperms.commands.Predicate;
|
||||
import me.lucko.luckperms.commands.Sender;
|
||||
import me.lucko.luckperms.commands.meta.MetaSubCommand;
|
||||
import me.lucko.luckperms.constants.Message;
|
||||
import me.lucko.luckperms.constants.Permission;
|
||||
import me.lucko.luckperms.core.PermissionHolder;
|
||||
import me.lucko.luckperms.data.LogEntry;
|
||||
import me.lucko.luckperms.exceptions.ObjectAlreadyHasException;
|
||||
import me.lucko.luckperms.groups.Group;
|
||||
import me.lucko.luckperms.utils.ArgumentChecker;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class GroupAddSuffix extends SubCommand<Group> {
|
||||
public GroupAddSuffix() {
|
||||
super("addsuffix", "Adds a suffix to the group", Permission.GROUP_ADDSUFFIX, Predicate.notInRange(2, 4),
|
||||
public class MetaAddSuffix extends MetaSubCommand {
|
||||
public MetaAddSuffix() {
|
||||
super("addsuffix", "Adds a suffix", Permission.USER_ADDSUFFIX, Permission.GROUP_ADDSUFFIX, Predicate.notInRange(2, 4),
|
||||
Arg.list(
|
||||
Arg.create("priority", true, "the priority to add the suffix at"),
|
||||
Arg.create("suffix", true, "the suffix string"),
|
||||
@ -46,7 +50,7 @@ public class GroupAddSuffix extends SubCommand<Group> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, Group group, List<String> args, String label) {
|
||||
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, PermissionHolder holder, List<String> args) {
|
||||
final String suffix = args.get(1).replace("{SPACE}", " ");
|
||||
int priority;
|
||||
try {
|
||||
@ -67,32 +71,32 @@ public class GroupAddSuffix extends SubCommand<Group> {
|
||||
}
|
||||
|
||||
if (args.size() == 3) {
|
||||
group.setPermission(node, true, server);
|
||||
Message.ADDSUFFIX_SERVER_SUCCESS.send(sender, group.getDisplayName(), suffix, priority, server);
|
||||
LogEntry.build().actor(sender).acted(group)
|
||||
.action("addsuffix " + priority + " " + args.get(1) + " " + server)
|
||||
holder.setPermission(node, true, server);
|
||||
Message.ADDSUFFIX_SERVER_SUCCESS.send(sender, holder.getFriendlyName(), suffix, priority, server);
|
||||
LogEntry.build().actor(sender).acted(holder)
|
||||
.action("meta addsuffix " + priority + " " + args.get(1) + " " + server)
|
||||
.build().submit(plugin, sender);
|
||||
} else {
|
||||
final String world = args.get(3).toLowerCase();
|
||||
group.setPermission(node, true, server, world);
|
||||
Message.ADDSUFFIX_SERVER_WORLD_SUCCESS.send(sender, group.getDisplayName(), suffix, priority, server, world);
|
||||
LogEntry.build().actor(sender).acted(group)
|
||||
.action("addsuffix " + priority + " " + args.get(1) + " " + server + " " + world)
|
||||
holder.setPermission(node, true, server, world);
|
||||
Message.ADDSUFFIX_SERVER_WORLD_SUCCESS.send(sender, holder.getFriendlyName(), suffix, priority, server, world);
|
||||
LogEntry.build().actor(sender).acted(holder)
|
||||
.action("meta addsuffix " + priority + " " + args.get(1) + " " + server + " " + world)
|
||||
.build().submit(plugin, sender);
|
||||
}
|
||||
|
||||
} else {
|
||||
group.setPermission(node, true);
|
||||
Message.ADDSUFFIX_SUCCESS.send(sender, group.getDisplayName(), suffix, priority);
|
||||
LogEntry.build().actor(sender).acted(group)
|
||||
.action("addsuffix " + priority + " " + args.get(1))
|
||||
holder.setPermission(node, true);
|
||||
Message.ADDSUFFIX_SUCCESS.send(sender, holder.getFriendlyName(), suffix, priority);
|
||||
LogEntry.build().actor(sender).acted(holder)
|
||||
.action("meta addsuffix " + priority + " " + args.get(1))
|
||||
.build().submit(plugin, sender);
|
||||
}
|
||||
|
||||
save(group, sender, plugin);
|
||||
save(holder, sender, plugin);
|
||||
return CommandResult.SUCCESS;
|
||||
} catch (ObjectAlreadyHasException e) {
|
||||
Message.ALREADY_HAS_SUFFIX.send(sender, group.getDisplayName());
|
||||
Message.ALREADY_HAS_SUFFIX.send(sender, holder.getFriendlyName());
|
||||
return CommandResult.STATE_ERROR;
|
||||
}
|
||||
}
|
@ -20,23 +20,27 @@
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
package me.lucko.luckperms.commands.user.subcommands;
|
||||
package me.lucko.luckperms.commands.meta.subcommands;
|
||||
|
||||
import me.lucko.luckperms.LuckPermsPlugin;
|
||||
import me.lucko.luckperms.commands.*;
|
||||
import me.lucko.luckperms.commands.Arg;
|
||||
import me.lucko.luckperms.commands.CommandResult;
|
||||
import me.lucko.luckperms.commands.Predicate;
|
||||
import me.lucko.luckperms.commands.Sender;
|
||||
import me.lucko.luckperms.commands.meta.MetaSubCommand;
|
||||
import me.lucko.luckperms.constants.Message;
|
||||
import me.lucko.luckperms.constants.Permission;
|
||||
import me.lucko.luckperms.core.PermissionHolder;
|
||||
import me.lucko.luckperms.data.LogEntry;
|
||||
import me.lucko.luckperms.exceptions.ObjectAlreadyHasException;
|
||||
import me.lucko.luckperms.users.User;
|
||||
import me.lucko.luckperms.utils.ArgumentChecker;
|
||||
import me.lucko.luckperms.utils.DateUtil;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class UserAddTempPrefix extends SubCommand<User> {
|
||||
public UserAddTempPrefix() {
|
||||
super("addtempprefix", "Adds a prefix to the user temporarily", Permission.USER_ADD_TEMP_PREFIX, Predicate.notInRange(3, 5),
|
||||
public class MetaAddTempPrefix extends MetaSubCommand {
|
||||
public MetaAddTempPrefix() {
|
||||
super("addtempprefix", "Adds a prefix temporarily", Permission.USER_ADD_TEMP_PREFIX, Permission.GROUP_ADD_TEMP_PREFIX, Predicate.notInRange(3, 5),
|
||||
Arg.list(
|
||||
Arg.create("priority", true, "the priority to add the prefix at"),
|
||||
Arg.create("prefix", true, "the prefix string"),
|
||||
@ -48,7 +52,7 @@ public class UserAddTempPrefix extends SubCommand<User> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, User user, List<String> args, String label) {
|
||||
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, PermissionHolder holder, List<String> args) {
|
||||
final String prefix = args.get(1).replace("{SPACE}", " ");
|
||||
int priority;
|
||||
try {
|
||||
@ -86,32 +90,32 @@ public class UserAddTempPrefix extends SubCommand<User> {
|
||||
}
|
||||
|
||||
if (args.size() == 4) {
|
||||
user.setPermission(node, true, server, duration);
|
||||
Message.ADD_TEMP_PREFIX_SERVER_SUCCESS.send(sender, user.getName(), prefix, priority, server, DateUtil.formatDateDiff(duration));
|
||||
LogEntry.build().actor(sender).acted(user)
|
||||
.action("addtempprefix " + priority + " " + args.get(1) + " " + duration + " " + server)
|
||||
holder.setPermission(node, true, server, duration);
|
||||
Message.ADD_TEMP_PREFIX_SERVER_SUCCESS.send(sender, holder.getFriendlyName(), prefix, priority, server, DateUtil.formatDateDiff(duration));
|
||||
LogEntry.build().actor(sender).acted(holder)
|
||||
.action("meta addtempprefix " + priority + " " + args.get(1) + " " + duration + " " + server)
|
||||
.build().submit(plugin, sender);
|
||||
} else {
|
||||
final String world = args.get(4).toLowerCase();
|
||||
user.setPermission(node, true, server, world, duration);
|
||||
Message.ADD_TEMP_PREFIX_SERVER_WORLD_SUCCESS.send(sender, user.getName(), prefix, priority, server, world, DateUtil.formatDateDiff(duration));
|
||||
LogEntry.build().actor(sender).acted(user)
|
||||
.action("addtempprefix " + priority + " " + args.get(1) + " " + duration + " " + server + " " + world)
|
||||
holder.setPermission(node, true, server, world, duration);
|
||||
Message.ADD_TEMP_PREFIX_SERVER_WORLD_SUCCESS.send(sender, holder.getFriendlyName(), prefix, priority, server, world, DateUtil.formatDateDiff(duration));
|
||||
LogEntry.build().actor(sender).acted(holder)
|
||||
.action("meta addtempprefix " + priority + " " + args.get(1) + " " + duration + " " + server + " " + world)
|
||||
.build().submit(plugin, sender);
|
||||
}
|
||||
|
||||
} else {
|
||||
user.setPermission(node, true, duration);
|
||||
Message.ADD_TEMP_PREFIX_SUCCESS.send(sender, user.getName(), prefix, priority, DateUtil.formatDateDiff(duration));
|
||||
LogEntry.build().actor(sender).acted(user)
|
||||
.action("addtempprefix " + priority + " " + args.get(1) + " " + duration)
|
||||
holder.setPermission(node, true, duration);
|
||||
Message.ADD_TEMP_PREFIX_SUCCESS.send(sender, holder.getFriendlyName(), prefix, priority, DateUtil.formatDateDiff(duration));
|
||||
LogEntry.build().actor(sender).acted(holder)
|
||||
.action("meta addtempprefix " + priority + " " + args.get(1) + " " + duration)
|
||||
.build().submit(plugin, sender);
|
||||
}
|
||||
|
||||
save(user, sender, plugin);
|
||||
save(holder, sender, plugin);
|
||||
return CommandResult.SUCCESS;
|
||||
} catch (ObjectAlreadyHasException e) {
|
||||
Message.ALREADY_HAS_PREFIX.send(sender, user.getName());
|
||||
Message.ALREADY_HAS_PREFIX.send(sender, holder.getFriendlyName());
|
||||
return CommandResult.STATE_ERROR;
|
||||
}
|
||||
}
|
@ -20,23 +20,27 @@
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
package me.lucko.luckperms.commands.user.subcommands;
|
||||
package me.lucko.luckperms.commands.meta.subcommands;
|
||||
|
||||
import me.lucko.luckperms.LuckPermsPlugin;
|
||||
import me.lucko.luckperms.commands.*;
|
||||
import me.lucko.luckperms.commands.Arg;
|
||||
import me.lucko.luckperms.commands.CommandResult;
|
||||
import me.lucko.luckperms.commands.Predicate;
|
||||
import me.lucko.luckperms.commands.Sender;
|
||||
import me.lucko.luckperms.commands.meta.MetaSubCommand;
|
||||
import me.lucko.luckperms.constants.Message;
|
||||
import me.lucko.luckperms.constants.Permission;
|
||||
import me.lucko.luckperms.core.PermissionHolder;
|
||||
import me.lucko.luckperms.data.LogEntry;
|
||||
import me.lucko.luckperms.exceptions.ObjectAlreadyHasException;
|
||||
import me.lucko.luckperms.users.User;
|
||||
import me.lucko.luckperms.utils.ArgumentChecker;
|
||||
import me.lucko.luckperms.utils.DateUtil;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class UserAddTempSuffix extends SubCommand<User> {
|
||||
public UserAddTempSuffix() {
|
||||
super("addtempsuffix", "Adds a suffix to the user temporarily", Permission.USER_ADD_TEMP_SUFFIX, Predicate.notInRange(3, 5),
|
||||
public class MetaAddTempSuffix extends MetaSubCommand {
|
||||
public MetaAddTempSuffix() {
|
||||
super("addtempsuffix", "Adds a suffix temporarily", Permission.USER_ADD_TEMP_SUFFIX, Permission.GROUP_ADD_TEMP_SUFFIX, Predicate.notInRange(3, 5),
|
||||
Arg.list(
|
||||
Arg.create("priority", true, "the priority to add the suffix at"),
|
||||
Arg.create("suffix", true, "the suffix string"),
|
||||
@ -48,7 +52,7 @@ public class UserAddTempSuffix extends SubCommand<User> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, User user, List<String> args, String label) {
|
||||
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, PermissionHolder holder, List<String> args) {
|
||||
final String suffix = args.get(1).replace("{SPACE}", " ");
|
||||
int priority;
|
||||
try {
|
||||
@ -86,32 +90,32 @@ public class UserAddTempSuffix extends SubCommand<User> {
|
||||
}
|
||||
|
||||
if (args.size() == 4) {
|
||||
user.setPermission(node, true, server, duration);
|
||||
Message.ADD_TEMP_SUFFIX_SERVER_SUCCESS.send(sender, user.getName(), suffix, priority, server, DateUtil.formatDateDiff(duration));
|
||||
LogEntry.build().actor(sender).acted(user)
|
||||
.action("addtempsuffix " + priority + " " + args.get(1) + " " + duration + " " + server)
|
||||
holder.setPermission(node, true, server, duration);
|
||||
Message.ADD_TEMP_SUFFIX_SERVER_SUCCESS.send(sender, holder.getFriendlyName(), suffix, priority, server, DateUtil.formatDateDiff(duration));
|
||||
LogEntry.build().actor(sender).acted(holder)
|
||||
.action("meta addtempsuffix " + priority + " " + args.get(1) + " " + duration + " " + server)
|
||||
.build().submit(plugin, sender);
|
||||
} else {
|
||||
final String world = args.get(4).toLowerCase();
|
||||
user.setPermission(node, true, server, world, duration);
|
||||
Message.ADD_TEMP_SUFFIX_SERVER_WORLD_SUCCESS.send(sender, user.getName(), suffix, priority, server, world, DateUtil.formatDateDiff(duration));
|
||||
LogEntry.build().actor(sender).acted(user)
|
||||
.action("addtempsuffix " + priority + " " + args.get(1) + " " + duration + " " + server + " " + world)
|
||||
holder.setPermission(node, true, server, world, duration);
|
||||
Message.ADD_TEMP_SUFFIX_SERVER_WORLD_SUCCESS.send(sender, holder.getFriendlyName(), suffix, priority, server, world, DateUtil.formatDateDiff(duration));
|
||||
LogEntry.build().actor(sender).acted(holder)
|
||||
.action("meta addtempsuffix " + priority + " " + args.get(1) + " " + duration + " " + server + " " + world)
|
||||
.build().submit(plugin, sender);
|
||||
}
|
||||
|
||||
} else {
|
||||
user.setPermission(node, true, duration);
|
||||
Message.ADD_TEMP_SUFFIX_SUCCESS.send(sender, user.getName(), suffix, priority, DateUtil.formatDateDiff(duration));
|
||||
LogEntry.build().actor(sender).acted(user)
|
||||
.action("addtempsuffix " + priority + " " + args.get(1) + " " + duration)
|
||||
holder.setPermission(node, true, duration);
|
||||
Message.ADD_TEMP_SUFFIX_SUCCESS.send(sender, holder.getFriendlyName(), suffix, priority, DateUtil.formatDateDiff(duration));
|
||||
LogEntry.build().actor(sender).acted(holder)
|
||||
.action("meta addtempsuffix " + priority + " " + args.get(1) + " " + duration)
|
||||
.build().submit(plugin, sender);
|
||||
}
|
||||
|
||||
save(user, sender, plugin);
|
||||
save(holder, sender, plugin);
|
||||
return CommandResult.SUCCESS;
|
||||
} catch (ObjectAlreadyHasException e) {
|
||||
Message.ALREADY_HAS_SUFFIX.send(sender, user.getName());
|
||||
Message.ALREADY_HAS_SUFFIX.send(sender, holder.getFriendlyName());
|
||||
return CommandResult.STATE_ERROR;
|
||||
}
|
||||
}
|
@ -20,22 +20,26 @@
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
package me.lucko.luckperms.commands.user.subcommands;
|
||||
package me.lucko.luckperms.commands.meta.subcommands;
|
||||
|
||||
import me.lucko.luckperms.LuckPermsPlugin;
|
||||
import me.lucko.luckperms.commands.*;
|
||||
import me.lucko.luckperms.commands.Arg;
|
||||
import me.lucko.luckperms.commands.CommandResult;
|
||||
import me.lucko.luckperms.commands.Predicate;
|
||||
import me.lucko.luckperms.commands.Sender;
|
||||
import me.lucko.luckperms.commands.meta.MetaSubCommand;
|
||||
import me.lucko.luckperms.constants.Message;
|
||||
import me.lucko.luckperms.constants.Permission;
|
||||
import me.lucko.luckperms.core.PermissionHolder;
|
||||
import me.lucko.luckperms.data.LogEntry;
|
||||
import me.lucko.luckperms.users.User;
|
||||
import me.lucko.luckperms.utils.ArgumentChecker;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class UserClearMeta extends SubCommand<User> {
|
||||
public UserClearMeta() {
|
||||
super("clearmeta", "Clears the user's meta", Permission.USER_CLEARMETA, Predicate.notInRange(0, 2),
|
||||
public class MetaClear extends MetaSubCommand {
|
||||
public MetaClear() {
|
||||
super("clear", "Clears all chat meta", Permission.USER_CLEARMETA, Permission.GROUP_CLEARMETA, Predicate.notInRange(0, 2),
|
||||
Arg.list(
|
||||
Arg.create("server", false, "the server name to filter by"),
|
||||
Arg.create("world", false, "the world name to filter by")
|
||||
@ -44,11 +48,11 @@ public class UserClearMeta extends SubCommand<User> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, User user, List<String> args, String label) {
|
||||
int before = user.getNodes().size();
|
||||
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, PermissionHolder holder, List<String> args) {
|
||||
int before = holder.getNodes().size();
|
||||
|
||||
if (args.size() == 0) {
|
||||
user.clearMeta();
|
||||
holder.clearMeta();
|
||||
} else {
|
||||
final String server = args.get(0);
|
||||
if (ArgumentChecker.checkServer(server)) {
|
||||
@ -58,22 +62,22 @@ public class UserClearMeta extends SubCommand<User> {
|
||||
|
||||
if (args.size() == 2) {
|
||||
final String world = args.get(1);
|
||||
user.clearMeta(server, world);
|
||||
holder.clearMeta(server, world);
|
||||
|
||||
} else {
|
||||
user.clearMeta(server);
|
||||
holder.clearMeta(server);
|
||||
}
|
||||
}
|
||||
|
||||
int changed = before - user.getNodes().size();
|
||||
int changed = before - holder.getNodes().size();
|
||||
if (changed == 1) {
|
||||
Message.META_CLEAR_SUCCESS_SINGULAR.send(sender, user.getName(), changed);
|
||||
Message.META_CLEAR_SUCCESS_SINGULAR.send(sender, holder.getFriendlyName(), changed);
|
||||
} else {
|
||||
Message.META_CLEAR_SUCCESS.send(sender, user.getName(), changed);
|
||||
Message.META_CLEAR_SUCCESS.send(sender, holder.getFriendlyName(), changed);
|
||||
}
|
||||
|
||||
LogEntry.build().actor(sender).acted(user).action("clearmeta " + args.stream().collect(Collectors.joining(" "))).build().submit(plugin, sender);
|
||||
save(user, sender, plugin);
|
||||
LogEntry.build().actor(sender).acted(holder).action("meta clear " + args.stream().collect(Collectors.joining(" "))).build().submit(plugin, sender);
|
||||
save(holder, sender, plugin);
|
||||
return CommandResult.SUCCESS;
|
||||
}
|
||||
}
|
@ -20,29 +20,33 @@
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
package me.lucko.luckperms.commands.group.subcommands;
|
||||
package me.lucko.luckperms.commands.meta.subcommands;
|
||||
|
||||
import me.lucko.luckperms.LuckPermsPlugin;
|
||||
import me.lucko.luckperms.api.Contexts;
|
||||
import me.lucko.luckperms.api.Node;
|
||||
import me.lucko.luckperms.commands.*;
|
||||
import me.lucko.luckperms.commands.CommandResult;
|
||||
import me.lucko.luckperms.commands.Predicate;
|
||||
import me.lucko.luckperms.commands.Sender;
|
||||
import me.lucko.luckperms.commands.Util;
|
||||
import me.lucko.luckperms.commands.meta.MetaSubCommand;
|
||||
import me.lucko.luckperms.constants.Message;
|
||||
import me.lucko.luckperms.constants.Permission;
|
||||
import me.lucko.luckperms.groups.Group;
|
||||
import me.lucko.luckperms.core.PermissionHolder;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
public class GroupChatMeta extends SubCommand<Group> {
|
||||
public GroupChatMeta() {
|
||||
super("chatmeta", "Lists the group's chat meta", Permission.GROUP_CHATMETA, Predicate.alwaysFalse(), null);
|
||||
public class MetaInfo extends MetaSubCommand {
|
||||
public MetaInfo() {
|
||||
super("info", "Shows all chat meta", Permission.USER_CHATMETA, Permission.GROUP_CHATMETA, Predicate.alwaysFalse(), null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, Group group, List<String> args, String label) {
|
||||
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, PermissionHolder holder, List<String> args) {
|
||||
SortedSet<Map.Entry<Integer, String>> prefixes = new TreeSet<>(Util.getMetaComparator().reversed());
|
||||
SortedSet<Map.Entry<Integer, String>> suffixes = new TreeSet<>(Util.getMetaComparator().reversed());
|
||||
|
||||
for (Node node : group.getAllNodes(null, Contexts.allowAll())) {
|
||||
for (Node node : holder.getAllNodes(null, Contexts.allowAll())) {
|
||||
if (!node.isSuffix() && !node.isPrefix()) {
|
||||
continue;
|
||||
}
|
||||
@ -67,18 +71,18 @@ public class GroupChatMeta extends SubCommand<Group> {
|
||||
}
|
||||
|
||||
if (prefixes.isEmpty()) {
|
||||
Message.CHAT_META_PREFIX_NONE.send(sender, group.getDisplayName());
|
||||
Message.CHAT_META_PREFIX_NONE.send(sender, holder.getFriendlyName());
|
||||
} else {
|
||||
Message.CHAT_META_PREFIX_HEADER.send(sender, group.getDisplayName());
|
||||
Message.CHAT_META_PREFIX_HEADER.send(sender, holder.getFriendlyName());
|
||||
for (Map.Entry<Integer, String> e : prefixes) {
|
||||
Message.CHAT_META_ENTRY.send(sender, e.getKey(), e.getValue());
|
||||
}
|
||||
}
|
||||
|
||||
if (suffixes.isEmpty()) {
|
||||
Message.CHAT_META_SUFFIX_NONE.send(sender, group.getDisplayName());
|
||||
Message.CHAT_META_SUFFIX_NONE.send(sender, holder.getFriendlyName());
|
||||
} else {
|
||||
Message.CHAT_META_SUFFIX_HEADER.send(sender, group.getDisplayName());
|
||||
Message.CHAT_META_SUFFIX_HEADER.send(sender, holder.getFriendlyName());
|
||||
for (Map.Entry<Integer, String> e : suffixes) {
|
||||
Message.CHAT_META_ENTRY.send(sender, e.getKey(), e.getValue());
|
||||
}
|
@ -20,35 +20,39 @@
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
package me.lucko.luckperms.commands.user.subcommands;
|
||||
package me.lucko.luckperms.commands.meta.subcommands;
|
||||
|
||||
import me.lucko.luckperms.LuckPermsPlugin;
|
||||
import me.lucko.luckperms.api.Node;
|
||||
import me.lucko.luckperms.commands.*;
|
||||
import me.lucko.luckperms.commands.Arg;
|
||||
import me.lucko.luckperms.commands.CommandResult;
|
||||
import me.lucko.luckperms.commands.Predicate;
|
||||
import me.lucko.luckperms.commands.Sender;
|
||||
import me.lucko.luckperms.commands.meta.MetaSubCommand;
|
||||
import me.lucko.luckperms.constants.Message;
|
||||
import me.lucko.luckperms.constants.Permission;
|
||||
import me.lucko.luckperms.core.PermissionHolder;
|
||||
import me.lucko.luckperms.data.LogEntry;
|
||||
import me.lucko.luckperms.exceptions.ObjectLacksException;
|
||||
import me.lucko.luckperms.users.User;
|
||||
import me.lucko.luckperms.utils.ArgumentChecker;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class UserRemovePrefix extends SubCommand<User> {
|
||||
public UserRemovePrefix() {
|
||||
super("removeprefix", "Removes a prefix from the user", Permission.USER_REMOVEPREFIX, Predicate.notInRange(2, 4),
|
||||
public class MetaRemovePrefix extends MetaSubCommand {
|
||||
public MetaRemovePrefix() {
|
||||
super("removeprefix", "Removes a prefix", Permission.USER_REMOVEPREFIX, Permission.GROUP_REMOVEPREFIX, Predicate.notInRange(2, 4),
|
||||
Arg.list(
|
||||
Arg.create("priority", true, "the priority to remove the prefix at"),
|
||||
Arg.create("prefix", true, "the prefix string to remove"),
|
||||
Arg.create("server", false, "the server to remove the prefix on"),
|
||||
Arg.create("world", false, "the world to remove the prefix on")
|
||||
Arg.create("priority", true, "the priority to add the prefix at"),
|
||||
Arg.create("prefix", true, "the prefix string"),
|
||||
Arg.create("server", false, "the server to add the prefix on"),
|
||||
Arg.create("world", false, "the world to add the prefix on")
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, User user, List<String> args, String label) {
|
||||
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, PermissionHolder holder, List<String> args) {
|
||||
final String prefix = args.get(1).replace("{SPACE}", " ");
|
||||
int priority;
|
||||
try {
|
||||
@ -75,7 +79,7 @@ public class UserRemovePrefix extends SubCommand<User> {
|
||||
}
|
||||
|
||||
List<Node> toRemove = new ArrayList<>();
|
||||
for (Node node : user.getNodes()) {
|
||||
for (Node node : holder.getNodes()) {
|
||||
if (!node.isPrefix()) continue;
|
||||
if (node.getPrefix().getKey() != priority) continue;
|
||||
if (node.isTemporary()) continue;
|
||||
@ -99,12 +103,12 @@ public class UserRemovePrefix extends SubCommand<User> {
|
||||
|
||||
toRemove.forEach(n -> {
|
||||
try {
|
||||
user.unsetPermission(n);
|
||||
holder.unsetPermission(n);
|
||||
} catch (ObjectLacksException ignored) {}
|
||||
});
|
||||
|
||||
Message.BULK_CHANGE_SUCCESS.send(sender, toRemove.size());
|
||||
save(user, sender, plugin);
|
||||
save(holder, sender, plugin);
|
||||
return CommandResult.SUCCESS;
|
||||
|
||||
} else {
|
||||
@ -120,32 +124,32 @@ public class UserRemovePrefix extends SubCommand<User> {
|
||||
}
|
||||
|
||||
if (args.size() == 3) {
|
||||
user.unsetPermission(node, server);
|
||||
Message.REMOVEPREFIX_SERVER_SUCCESS.send(sender, user.getName(), prefix, priority, server);
|
||||
LogEntry.build().actor(sender).acted(user)
|
||||
.action("removeprefix " + priority + " " + args.get(1) + " " + server)
|
||||
holder.unsetPermission(node, server);
|
||||
Message.REMOVEPREFIX_SERVER_SUCCESS.send(sender, holder.getFriendlyName(), prefix, priority, server);
|
||||
LogEntry.build().actor(sender).acted(holder)
|
||||
.action("meta removeprefix " + priority + " " + args.get(1) + " " + server)
|
||||
.build().submit(plugin, sender);
|
||||
} else {
|
||||
final String world = args.get(3).toLowerCase();
|
||||
user.unsetPermission(node, server, world);
|
||||
Message.REMOVEPREFIX_SERVER_WORLD_SUCCESS.send(sender, user.getName(), prefix, priority, server, world);
|
||||
LogEntry.build().actor(sender).acted(user)
|
||||
.action("removeprefix " + priority + " " + args.get(1) + " " + server + " " + world)
|
||||
holder.unsetPermission(node, server, world);
|
||||
Message.REMOVEPREFIX_SERVER_WORLD_SUCCESS.send(sender, holder.getFriendlyName(), prefix, priority, server, world);
|
||||
LogEntry.build().actor(sender).acted(holder)
|
||||
.action("meta removeprefix " + priority + " " + args.get(1) + " " + server + " " + world)
|
||||
.build().submit(plugin, sender);
|
||||
}
|
||||
|
||||
} else {
|
||||
user.unsetPermission(node);
|
||||
Message.REMOVEPREFIX_SUCCESS.send(sender, user.getName(), prefix, priority);
|
||||
LogEntry.build().actor(sender).acted(user)
|
||||
.action("removeprefix " + priority + " " + args.get(1))
|
||||
holder.unsetPermission(node);
|
||||
Message.REMOVEPREFIX_SUCCESS.send(sender, holder.getFriendlyName(), prefix, priority);
|
||||
LogEntry.build().actor(sender).acted(holder)
|
||||
.action("meta removeprefix " + priority + " " + args.get(1))
|
||||
.build().submit(plugin, sender);
|
||||
}
|
||||
|
||||
save(user, sender, plugin);
|
||||
save(holder, sender, plugin);
|
||||
return CommandResult.SUCCESS;
|
||||
} catch (ObjectLacksException e) {
|
||||
Message.DOES_NOT_HAVE_PREFIX.send(sender, user.getName());
|
||||
Message.DOES_NOT_HAVE_PREFIX.send(sender, holder.getFriendlyName());
|
||||
return CommandResult.STATE_ERROR;
|
||||
}
|
||||
}
|
@ -20,35 +20,39 @@
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
package me.lucko.luckperms.commands.user.subcommands;
|
||||
package me.lucko.luckperms.commands.meta.subcommands;
|
||||
|
||||
import me.lucko.luckperms.LuckPermsPlugin;
|
||||
import me.lucko.luckperms.api.Node;
|
||||
import me.lucko.luckperms.commands.*;
|
||||
import me.lucko.luckperms.commands.Arg;
|
||||
import me.lucko.luckperms.commands.CommandResult;
|
||||
import me.lucko.luckperms.commands.Predicate;
|
||||
import me.lucko.luckperms.commands.Sender;
|
||||
import me.lucko.luckperms.commands.meta.MetaSubCommand;
|
||||
import me.lucko.luckperms.constants.Message;
|
||||
import me.lucko.luckperms.constants.Permission;
|
||||
import me.lucko.luckperms.core.PermissionHolder;
|
||||
import me.lucko.luckperms.data.LogEntry;
|
||||
import me.lucko.luckperms.exceptions.ObjectLacksException;
|
||||
import me.lucko.luckperms.users.User;
|
||||
import me.lucko.luckperms.utils.ArgumentChecker;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class UserRemoveSuffix extends SubCommand<User> {
|
||||
public UserRemoveSuffix() {
|
||||
super("removesuffix", "Removes a suffix from the user", Permission.USER_REMOVESUFFIX, Predicate.notInRange(2, 4),
|
||||
public class MetaRemoveSuffix extends MetaSubCommand {
|
||||
public MetaRemoveSuffix() {
|
||||
super("removesuffix", "Removes a suffix", Permission.USER_REMOVESUFFIX, Permission.GROUP_REMOVESUFFIX, Predicate.notInRange(2, 4),
|
||||
Arg.list(
|
||||
Arg.create("priority", true, "the priority to remove the suffix at"),
|
||||
Arg.create("suffix", true, "the suffix string to remove"),
|
||||
Arg.create("server", false, "the server to remove the suffix on"),
|
||||
Arg.create("world", false, "the world to remove the suffix on")
|
||||
Arg.create("priority", true, "the priority to add the suffix at"),
|
||||
Arg.create("suffix", true, "the suffix string"),
|
||||
Arg.create("server", false, "the server to add the suffix on"),
|
||||
Arg.create("world", false, "the world to add the suffix on")
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, User user, List<String> args, String label) {
|
||||
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, PermissionHolder holder, List<String> args) {
|
||||
final String suffix = args.get(1).replace("{SPACE}", " ");
|
||||
int priority;
|
||||
try {
|
||||
@ -75,7 +79,7 @@ public class UserRemoveSuffix extends SubCommand<User> {
|
||||
}
|
||||
|
||||
List<Node> toRemove = new ArrayList<>();
|
||||
for (Node node : user.getNodes()) {
|
||||
for (Node node : holder.getNodes()) {
|
||||
if (!node.isSuffix()) continue;
|
||||
if (node.getSuffix().getKey() != priority) continue;
|
||||
if (node.isTemporary()) continue;
|
||||
@ -99,12 +103,12 @@ public class UserRemoveSuffix extends SubCommand<User> {
|
||||
|
||||
toRemove.forEach(n -> {
|
||||
try {
|
||||
user.unsetPermission(n);
|
||||
holder.unsetPermission(n);
|
||||
} catch (ObjectLacksException ignored) {}
|
||||
});
|
||||
|
||||
Message.BULK_CHANGE_SUCCESS.send(sender, toRemove.size());
|
||||
save(user, sender, plugin);
|
||||
save(holder, sender, plugin);
|
||||
return CommandResult.SUCCESS;
|
||||
|
||||
} else {
|
||||
@ -120,32 +124,32 @@ public class UserRemoveSuffix extends SubCommand<User> {
|
||||
}
|
||||
|
||||
if (args.size() == 3) {
|
||||
user.unsetPermission(node, server);
|
||||
Message.REMOVESUFFIX_SERVER_SUCCESS.send(sender, user.getName(), suffix, priority, server);
|
||||
LogEntry.build().actor(sender).acted(user)
|
||||
.action("removesuffix " + priority + " " + args.get(1) + " " + server)
|
||||
holder.unsetPermission(node, server);
|
||||
Message.REMOVESUFFIX_SERVER_SUCCESS.send(sender, holder.getFriendlyName(), suffix, priority, server);
|
||||
LogEntry.build().actor(sender).acted(holder)
|
||||
.action("meta removesuffix " + priority + " " + args.get(1) + " " + server)
|
||||
.build().submit(plugin, sender);
|
||||
} else {
|
||||
final String world = args.get(3).toLowerCase();
|
||||
user.unsetPermission(node, server, world);
|
||||
Message.REMOVESUFFIX_SERVER_WORLD_SUCCESS.send(sender, user.getName(), suffix, priority, server, world);
|
||||
LogEntry.build().actor(sender).acted(user)
|
||||
.action("removesuffix " + priority + " " + args.get(1) + " " + server + " " + world)
|
||||
holder.unsetPermission(node, server, world);
|
||||
Message.REMOVESUFFIX_SERVER_WORLD_SUCCESS.send(sender, holder.getFriendlyName(), suffix, priority, server, world);
|
||||
LogEntry.build().actor(sender).acted(holder)
|
||||
.action("meta removesuffix " + priority + " " + args.get(1) + " " + server + " " + world)
|
||||
.build().submit(plugin, sender);
|
||||
}
|
||||
|
||||
} else {
|
||||
user.unsetPermission(node);
|
||||
Message.REMOVESUFFIX_SUCCESS.send(sender, user.getName(), suffix, priority);
|
||||
LogEntry.build().actor(sender).acted(user)
|
||||
.action("removesuffix " + priority + " " + args.get(1))
|
||||
holder.unsetPermission(node);
|
||||
Message.REMOVESUFFIX_SUCCESS.send(sender, holder.getFriendlyName(), suffix, priority);
|
||||
LogEntry.build().actor(sender).acted(holder)
|
||||
.action("meta removesuffix " + priority + " " + args.get(1))
|
||||
.build().submit(plugin, sender);
|
||||
}
|
||||
|
||||
save(user, sender, plugin);
|
||||
save(holder, sender, plugin);
|
||||
return CommandResult.SUCCESS;
|
||||
} catch (ObjectLacksException e) {
|
||||
Message.DOES_NOT_HAVE_SUFFIX.send(sender, user.getName());
|
||||
Message.DOES_NOT_HAVE_SUFFIX.send(sender, holder.getFriendlyName());
|
||||
return CommandResult.STATE_ERROR;
|
||||
}
|
||||
}
|
@ -20,36 +20,39 @@
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
package me.lucko.luckperms.commands.user.subcommands;
|
||||
package me.lucko.luckperms.commands.meta.subcommands;
|
||||
|
||||
import me.lucko.luckperms.LuckPermsPlugin;
|
||||
import me.lucko.luckperms.api.Node;
|
||||
import me.lucko.luckperms.commands.*;
|
||||
import me.lucko.luckperms.commands.Arg;
|
||||
import me.lucko.luckperms.commands.CommandResult;
|
||||
import me.lucko.luckperms.commands.Predicate;
|
||||
import me.lucko.luckperms.commands.Sender;
|
||||
import me.lucko.luckperms.commands.meta.MetaSubCommand;
|
||||
import me.lucko.luckperms.constants.Message;
|
||||
import me.lucko.luckperms.constants.Permission;
|
||||
import me.lucko.luckperms.core.PermissionHolder;
|
||||
import me.lucko.luckperms.data.LogEntry;
|
||||
import me.lucko.luckperms.exceptions.ObjectLacksException;
|
||||
import me.lucko.luckperms.users.User;
|
||||
import me.lucko.luckperms.utils.ArgumentChecker;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class UserRemoveTempPrefix extends SubCommand<User> {
|
||||
public UserRemoveTempPrefix() {
|
||||
super("removetempprefix", "Removes the temporary prefix from a user", Permission.USER_REMOVE_TEMP_PREFIX,
|
||||
Predicate.notInRange(2, 4),
|
||||
public class MetaRemoveTempPrefix extends MetaSubCommand {
|
||||
public MetaRemoveTempPrefix() {
|
||||
super("removetempprefix", "Removes a temporary prefix", Permission.USER_REMOVE_TEMP_PREFIX, Permission.GROUP_REMOVE_TEMP_PREFIX, Predicate.notInRange(2, 4),
|
||||
Arg.list(
|
||||
Arg.create("priority", true, "the priority to remove the prefix at"),
|
||||
Arg.create("prefix", true, "the prefix string to remove"),
|
||||
Arg.create("server", false, "the server to remove the prefix on"),
|
||||
Arg.create("world", false, "the world to remove the prefix on")
|
||||
Arg.create("priority", true, "the priority to add the prefix at"),
|
||||
Arg.create("prefix", true, "the prefix string"),
|
||||
Arg.create("server", false, "the server to add the prefix on"),
|
||||
Arg.create("world", false, "the world to add the prefix on")
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, User user, List<String> args, String label) {
|
||||
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, PermissionHolder holder, List<String> args) {
|
||||
final String prefix = args.get(1).replace("{SPACE}", " ");
|
||||
int priority;
|
||||
try {
|
||||
@ -76,7 +79,7 @@ public class UserRemoveTempPrefix extends SubCommand<User> {
|
||||
}
|
||||
|
||||
List<Node> toRemove = new ArrayList<>();
|
||||
for (Node node : user.getNodes()) {
|
||||
for (Node node : holder.getNodes()) {
|
||||
if (!node.isPrefix()) continue;
|
||||
if (node.getPrefix().getKey() != priority) continue;
|
||||
if (node.isPermanent()) continue;
|
||||
@ -100,12 +103,12 @@ public class UserRemoveTempPrefix extends SubCommand<User> {
|
||||
|
||||
toRemove.forEach(n -> {
|
||||
try {
|
||||
user.unsetPermission(n);
|
||||
holder.unsetPermission(n);
|
||||
} catch (ObjectLacksException ignored) {}
|
||||
});
|
||||
|
||||
Message.BULK_CHANGE_SUCCESS.send(sender, toRemove.size());
|
||||
save(user, sender, plugin);
|
||||
save(holder, sender, plugin);
|
||||
return CommandResult.SUCCESS;
|
||||
|
||||
} else {
|
||||
@ -121,32 +124,32 @@ public class UserRemoveTempPrefix extends SubCommand<User> {
|
||||
}
|
||||
|
||||
if (args.size() == 3) {
|
||||
user.unsetPermission(node, server, true);
|
||||
Message.REMOVE_TEMP_PREFIX_SERVER_SUCCESS.send(sender, user.getName(), prefix, priority, server);
|
||||
LogEntry.build().actor(sender).acted(user)
|
||||
.action("removetempprefix " + priority + " " + args.get(1) + " " + server)
|
||||
holder.unsetPermission(node, server, true);
|
||||
Message.REMOVE_TEMP_PREFIX_SERVER_SUCCESS.send(sender, holder.getFriendlyName(), prefix, priority, server);
|
||||
LogEntry.build().actor(sender).acted(holder)
|
||||
.action("meta removetempprefix " + priority + " " + args.get(1) + " " + server)
|
||||
.build().submit(plugin, sender);
|
||||
} else {
|
||||
final String world = args.get(3).toLowerCase();
|
||||
user.unsetPermission(node, server, world, true);
|
||||
Message.REMOVE_TEMP_PREFIX_SERVER_WORLD_SUCCESS.send(sender, user.getName(), prefix, priority, server, world);
|
||||
LogEntry.build().actor(sender).acted(user)
|
||||
.action("removetempprefix " + priority + " " + args.get(1) + " " + server + " " + world)
|
||||
holder.unsetPermission(node, server, world, true);
|
||||
Message.REMOVE_TEMP_PREFIX_SERVER_WORLD_SUCCESS.send(sender, holder.getFriendlyName(), prefix, priority, server, world);
|
||||
LogEntry.build().actor(sender).acted(holder)
|
||||
.action("meta removetempprefix " + priority + " " + args.get(1) + " " + server + " " + world)
|
||||
.build().submit(plugin, sender);
|
||||
}
|
||||
|
||||
} else {
|
||||
user.unsetPermission(node, true);
|
||||
Message.REMOVE_TEMP_PREFIX_SUCCESS.send(sender, user.getName(), prefix, priority);
|
||||
LogEntry.build().actor(sender).acted(user)
|
||||
.action("removetempprefix " + priority + " " + args.get(1))
|
||||
holder.unsetPermission(node, true);
|
||||
Message.REMOVE_TEMP_PREFIX_SUCCESS.send(sender, holder.getFriendlyName(), prefix, priority);
|
||||
LogEntry.build().actor(sender).acted(holder)
|
||||
.action("meta removetempprefix " + priority + " " + args.get(1))
|
||||
.build().submit(plugin, sender);
|
||||
}
|
||||
|
||||
save(user, sender, plugin);
|
||||
save(holder, sender, plugin);
|
||||
return CommandResult.SUCCESS;
|
||||
} catch (ObjectLacksException e) {
|
||||
Message.DOES_NOT_HAVE_PREFIX.send(sender, user.getName());
|
||||
Message.DOES_NOT_HAVE_PREFIX.send(sender, holder.getFriendlyName());
|
||||
return CommandResult.STATE_ERROR;
|
||||
}
|
||||
}
|
@ -20,36 +20,39 @@
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
package me.lucko.luckperms.commands.user.subcommands;
|
||||
package me.lucko.luckperms.commands.meta.subcommands;
|
||||
|
||||
import me.lucko.luckperms.LuckPermsPlugin;
|
||||
import me.lucko.luckperms.api.Node;
|
||||
import me.lucko.luckperms.commands.*;
|
||||
import me.lucko.luckperms.commands.Arg;
|
||||
import me.lucko.luckperms.commands.CommandResult;
|
||||
import me.lucko.luckperms.commands.Predicate;
|
||||
import me.lucko.luckperms.commands.Sender;
|
||||
import me.lucko.luckperms.commands.meta.MetaSubCommand;
|
||||
import me.lucko.luckperms.constants.Message;
|
||||
import me.lucko.luckperms.constants.Permission;
|
||||
import me.lucko.luckperms.core.PermissionHolder;
|
||||
import me.lucko.luckperms.data.LogEntry;
|
||||
import me.lucko.luckperms.exceptions.ObjectLacksException;
|
||||
import me.lucko.luckperms.users.User;
|
||||
import me.lucko.luckperms.utils.ArgumentChecker;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class UserRemoveTempSuffix extends SubCommand<User> {
|
||||
public UserRemoveTempSuffix() {
|
||||
super("removetempsuffix", "Removes the temporary suffix from a user", Permission.USER_REMOVE_TEMP_SUFFIX,
|
||||
Predicate.notInRange(2, 4),
|
||||
public class MetaRemoveTempSuffix extends MetaSubCommand {
|
||||
public MetaRemoveTempSuffix() {
|
||||
super("removetempsuffix", "Removes a temporary suffix", Permission.USER_REMOVE_TEMP_SUFFIX, Permission.GROUP_REMOVE_TEMP_SUFFIX, Predicate.notInRange(2, 4),
|
||||
Arg.list(
|
||||
Arg.create("priority", true, "the priority to remove the suffix at"),
|
||||
Arg.create("suffix", true, "the suffix string to remove"),
|
||||
Arg.create("server", false, "the server to remove the suffix on"),
|
||||
Arg.create("world", false, "the world to remove the suffix on")
|
||||
Arg.create("priority", true, "the priority to add the suffix at"),
|
||||
Arg.create("suffix", true, "the suffix string"),
|
||||
Arg.create("server", false, "the server to add the suffix on"),
|
||||
Arg.create("world", false, "the world to add the suffix on")
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, User user, List<String> args, String label) {
|
||||
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, PermissionHolder holder, List<String> args) {
|
||||
final String suffix = args.get(1).replace("{SPACE}", " ");
|
||||
int priority;
|
||||
try {
|
||||
@ -76,7 +79,7 @@ public class UserRemoveTempSuffix extends SubCommand<User> {
|
||||
}
|
||||
|
||||
List<Node> toRemove = new ArrayList<>();
|
||||
for (Node node : user.getNodes()) {
|
||||
for (Node node : holder.getNodes()) {
|
||||
if (!node.isSuffix()) continue;
|
||||
if (node.getSuffix().getKey() != priority) continue;
|
||||
if (node.isPermanent()) continue;
|
||||
@ -100,12 +103,12 @@ public class UserRemoveTempSuffix extends SubCommand<User> {
|
||||
|
||||
toRemove.forEach(n -> {
|
||||
try {
|
||||
user.unsetPermission(n);
|
||||
holder.unsetPermission(n);
|
||||
} catch (ObjectLacksException ignored) {}
|
||||
});
|
||||
|
||||
Message.BULK_CHANGE_SUCCESS.send(sender, toRemove.size());
|
||||
save(user, sender, plugin);
|
||||
save(holder, sender, plugin);
|
||||
return CommandResult.SUCCESS;
|
||||
|
||||
} else {
|
||||
@ -121,32 +124,32 @@ public class UserRemoveTempSuffix extends SubCommand<User> {
|
||||
}
|
||||
|
||||
if (args.size() == 3) {
|
||||
user.unsetPermission(node, server, true);
|
||||
Message.REMOVE_TEMP_SUFFIX_SERVER_SUCCESS.send(sender, user.getName(), suffix, priority, server);
|
||||
LogEntry.build().actor(sender).acted(user)
|
||||
.action("removetempsuffix " + priority + " " + args.get(1) + " " + server)
|
||||
holder.unsetPermission(node, server, true);
|
||||
Message.REMOVE_TEMP_SUFFIX_SERVER_SUCCESS.send(sender, holder.getFriendlyName(), suffix, priority, server);
|
||||
LogEntry.build().actor(sender).acted(holder)
|
||||
.action("meta removetempsuffix " + priority + " " + args.get(1) + " " + server)
|
||||
.build().submit(plugin, sender);
|
||||
} else {
|
||||
final String world = args.get(3).toLowerCase();
|
||||
user.unsetPermission(node, server, world, true);
|
||||
Message.REMOVE_TEMP_SUFFIX_SERVER_WORLD_SUCCESS.send(sender, user.getName(), suffix, priority, server, world);
|
||||
LogEntry.build().actor(sender).acted(user)
|
||||
.action("removetempsuffix " + priority + " " + args.get(1) + " " + server + " " + world)
|
||||
holder.unsetPermission(node, server, world, true);
|
||||
Message.REMOVE_TEMP_SUFFIX_SERVER_WORLD_SUCCESS.send(sender, holder.getFriendlyName(), suffix, priority, server, world);
|
||||
LogEntry.build().actor(sender).acted(holder)
|
||||
.action("meta removetempsuffix " + priority + " " + args.get(1) + " " + server + " " + world)
|
||||
.build().submit(plugin, sender);
|
||||
}
|
||||
|
||||
} else {
|
||||
user.unsetPermission(node, true);
|
||||
Message.REMOVE_TEMP_SUFFIX_SUCCESS.send(sender, user.getName(), suffix, priority);
|
||||
LogEntry.build().actor(sender).acted(user)
|
||||
.action("removetempsuffix " + priority + " " + args.get(1))
|
||||
holder.unsetPermission(node, true);
|
||||
Message.REMOVE_TEMP_SUFFIX_SUCCESS.send(sender, holder.getFriendlyName(), suffix, priority);
|
||||
LogEntry.build().actor(sender).acted(holder)
|
||||
.action("meta removetempsuffix " + priority + " " + args.get(1))
|
||||
.build().submit(plugin, sender);
|
||||
}
|
||||
|
||||
save(user, sender, plugin);
|
||||
save(holder, sender, plugin);
|
||||
return CommandResult.SUCCESS;
|
||||
} catch (ObjectLacksException e) {
|
||||
Message.DOES_NOT_HAVE_SUFFIX.send(sender, user.getName());
|
||||
Message.DOES_NOT_HAVE_SUFFIX.send(sender, holder.getFriendlyName());
|
||||
return CommandResult.STATE_ERROR;
|
||||
}
|
||||
}
|
@ -28,6 +28,7 @@ import me.lucko.luckperms.commands.MainCommand;
|
||||
import me.lucko.luckperms.commands.Sender;
|
||||
import me.lucko.luckperms.commands.SubCommand;
|
||||
import me.lucko.luckperms.commands.Util;
|
||||
import me.lucko.luckperms.commands.meta.MetaCommands;
|
||||
import me.lucko.luckperms.commands.user.subcommands.*;
|
||||
import me.lucko.luckperms.constants.Message;
|
||||
import me.lucko.luckperms.constants.Patterns;
|
||||
@ -58,16 +59,7 @@ public class UserMainCommand extends MainCommand<User> {
|
||||
.add(new UserPromote())
|
||||
.add(new UserDemote())
|
||||
.add(new UserShowPos())
|
||||
.add(new UserChatMeta())
|
||||
.add(new UserAddPrefix())
|
||||
.add(new UserAddSuffix())
|
||||
.add(new UserRemovePrefix())
|
||||
.add(new UserRemoveSuffix())
|
||||
.add(new UserAddTempPrefix())
|
||||
.add(new UserAddTempSuffix())
|
||||
.add(new UserRemoveTempPrefix())
|
||||
.add(new UserRemoveTempSuffix())
|
||||
.add(new UserClearMeta())
|
||||
.add(new MetaCommands<>())
|
||||
.add(new UserBulkChange())
|
||||
.add(new UserClear())
|
||||
.build()
|
||||
|
@ -1,99 +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.commands.user.subcommands;
|
||||
|
||||
import me.lucko.luckperms.LuckPermsPlugin;
|
||||
import me.lucko.luckperms.commands.*;
|
||||
import me.lucko.luckperms.constants.Message;
|
||||
import me.lucko.luckperms.constants.Permission;
|
||||
import me.lucko.luckperms.data.LogEntry;
|
||||
import me.lucko.luckperms.exceptions.ObjectAlreadyHasException;
|
||||
import me.lucko.luckperms.users.User;
|
||||
import me.lucko.luckperms.utils.ArgumentChecker;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class UserAddPrefix extends SubCommand<User> {
|
||||
public UserAddPrefix() {
|
||||
super("addprefix", "Adds a prefix to the user", Permission.USER_ADDPREFIX, Predicate.notInRange(2, 4),
|
||||
Arg.list(
|
||||
Arg.create("priority", true, "the priority to add the prefix at"),
|
||||
Arg.create("prefix", true, "the prefix string"),
|
||||
Arg.create("server", false, "the server to add the prefix on"),
|
||||
Arg.create("world", false, "the world to add the prefix on")
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, User user, List<String> args, String label) {
|
||||
final String prefix = args.get(1).replace("{SPACE}", " ");
|
||||
int priority;
|
||||
try {
|
||||
priority = Integer.parseInt(args.get(0));
|
||||
} catch (NumberFormatException e) {
|
||||
Message.META_INVALID_PRIORITY.send(sender, args.get(0));
|
||||
return CommandResult.INVALID_ARGS;
|
||||
}
|
||||
|
||||
final String node = "prefix." + priority + "." + ArgumentChecker.escapeCharacters(prefix);
|
||||
|
||||
try {
|
||||
if (args.size() >= 3) {
|
||||
final String server = args.get(2).toLowerCase();
|
||||
if (ArgumentChecker.checkServer(server)) {
|
||||
Message.SERVER_INVALID_ENTRY.send(sender);
|
||||
return CommandResult.INVALID_ARGS;
|
||||
}
|
||||
|
||||
if (args.size() == 3) {
|
||||
user.setPermission(node, true, server);
|
||||
Message.ADDPREFIX_SERVER_SUCCESS.send(sender, user.getName(), prefix, priority, server);
|
||||
LogEntry.build().actor(sender).acted(user)
|
||||
.action("addprefix " + priority + " " + args.get(1) + " " + server)
|
||||
.build().submit(plugin, sender);
|
||||
} else {
|
||||
final String world = args.get(3).toLowerCase();
|
||||
user.setPermission(node, true, server, world);
|
||||
Message.ADDPREFIX_SERVER_WORLD_SUCCESS.send(sender, user.getName(), prefix, priority, server, world);
|
||||
LogEntry.build().actor(sender).acted(user)
|
||||
.action("addprefix " + priority + " " + args.get(1) + " " + server + " " + world)
|
||||
.build().submit(plugin, sender);
|
||||
}
|
||||
|
||||
} else {
|
||||
user.setPermission(node, true);
|
||||
Message.ADDPREFIX_SUCCESS.send(sender, user.getName(), prefix, priority);
|
||||
LogEntry.build().actor(sender).acted(user)
|
||||
.action("addprefix " + priority + " " + args.get(1))
|
||||
.build().submit(plugin, sender);
|
||||
}
|
||||
|
||||
save(user, sender, plugin);
|
||||
return CommandResult.SUCCESS;
|
||||
} catch (ObjectAlreadyHasException e) {
|
||||
Message.ALREADY_HAS_PREFIX.send(sender, user.getName());
|
||||
return CommandResult.STATE_ERROR;
|
||||
}
|
||||
}
|
||||
}
|
@ -1,99 +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.commands.user.subcommands;
|
||||
|
||||
import me.lucko.luckperms.LuckPermsPlugin;
|
||||
import me.lucko.luckperms.commands.*;
|
||||
import me.lucko.luckperms.constants.Message;
|
||||
import me.lucko.luckperms.constants.Permission;
|
||||
import me.lucko.luckperms.data.LogEntry;
|
||||
import me.lucko.luckperms.exceptions.ObjectAlreadyHasException;
|
||||
import me.lucko.luckperms.users.User;
|
||||
import me.lucko.luckperms.utils.ArgumentChecker;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class UserAddSuffix extends SubCommand<User> {
|
||||
public UserAddSuffix() {
|
||||
super("addsuffix", "Adds a suffix to the user", Permission.USER_ADDSUFFIX, Predicate.notInRange(2, 4),
|
||||
Arg.list(
|
||||
Arg.create("priority", true, "the priority to add the suffix at"),
|
||||
Arg.create("suffix", true, "the suffix string"),
|
||||
Arg.create("server", false, "the server to add the suffix on"),
|
||||
Arg.create("world", false, "the world to add the suffix on")
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, User user, List<String> args, String label) {
|
||||
final String suffix = args.get(1).replace("{SPACE}", " ");
|
||||
int priority;
|
||||
try {
|
||||
priority = Integer.parseInt(args.get(0));
|
||||
} catch (NumberFormatException e) {
|
||||
Message.META_INVALID_PRIORITY.send(sender, args.get(0));
|
||||
return CommandResult.INVALID_ARGS;
|
||||
}
|
||||
|
||||
final String node = "suffix." + priority + "." + ArgumentChecker.escapeCharacters(suffix);
|
||||
|
||||
try {
|
||||
if (args.size() >= 3) {
|
||||
final String server = args.get(2).toLowerCase();
|
||||
if (ArgumentChecker.checkServer(server)) {
|
||||
Message.SERVER_INVALID_ENTRY.send(sender);
|
||||
return CommandResult.INVALID_ARGS;
|
||||
}
|
||||
|
||||
if (args.size() == 3) {
|
||||
user.setPermission(node, true, server);
|
||||
Message.ADDSUFFIX_SERVER_SUCCESS.send(sender, user.getName(), suffix, priority, server);
|
||||
LogEntry.build().actor(sender).acted(user)
|
||||
.action("addsuffix " + priority + " " + args.get(1) + " " + server)
|
||||
.build().submit(plugin, sender);
|
||||
} else {
|
||||
final String world = args.get(3).toLowerCase();
|
||||
user.setPermission(node, true, server, world);
|
||||
Message.ADDSUFFIX_SERVER_WORLD_SUCCESS.send(sender, user.getName(), suffix, priority, server, world);
|
||||
LogEntry.build().actor(sender).acted(user)
|
||||
.action("addsuffix " + priority + " " + args.get(1) + " " + server + " " + world)
|
||||
.build().submit(plugin, sender);
|
||||
}
|
||||
|
||||
} else {
|
||||
user.setPermission(node, true);
|
||||
Message.ADDSUFFIX_SUCCESS.send(sender, user.getName(), suffix, priority);
|
||||
LogEntry.build().actor(sender).acted(user)
|
||||
.action("addsuffix " + priority + " " + args.get(1))
|
||||
.build().submit(plugin, sender);
|
||||
}
|
||||
|
||||
save(user, sender, plugin);
|
||||
return CommandResult.SUCCESS;
|
||||
} catch (ObjectAlreadyHasException e) {
|
||||
Message.ALREADY_HAS_SUFFIX.send(sender, user.getName());
|
||||
return CommandResult.STATE_ERROR;
|
||||
}
|
||||
}
|
||||
}
|
@ -1,93 +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.commands.user.subcommands;
|
||||
|
||||
import me.lucko.luckperms.LuckPermsPlugin;
|
||||
import me.lucko.luckperms.api.Contexts;
|
||||
import me.lucko.luckperms.api.Node;
|
||||
import me.lucko.luckperms.commands.*;
|
||||
import me.lucko.luckperms.constants.Message;
|
||||
import me.lucko.luckperms.constants.Permission;
|
||||
import me.lucko.luckperms.users.User;
|
||||
|
||||
import java.util.AbstractMap.SimpleEntry;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.SortedSet;
|
||||
import java.util.TreeSet;
|
||||
|
||||
public class UserChatMeta extends SubCommand<User> {
|
||||
public UserChatMeta() {
|
||||
super("chatmeta", "Lists the user's chat meta", Permission.USER_CHATMETA, Predicate.alwaysFalse(), null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, User user, List<String> args, String label) {
|
||||
SortedSet<Map.Entry<Integer, String>> prefixes = new TreeSet<>(Util.getMetaComparator().reversed());
|
||||
SortedSet<Map.Entry<Integer, String>> suffixes = new TreeSet<>(Util.getMetaComparator().reversed());
|
||||
|
||||
for (Node node : user.getAllNodes(null, Contexts.allowAll())) {
|
||||
if (!node.isSuffix() && !node.isPrefix()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
StringBuilder sb = new StringBuilder();
|
||||
if (node.isServerSpecific()) {
|
||||
if (node.isWorldSpecific()) {
|
||||
sb.append("&6W=").append(node.getWorld().get()).append(" ");
|
||||
}
|
||||
sb.append("&6S=").append(node.getServer().get()).append(" ");
|
||||
}
|
||||
|
||||
if (node.isPrefix()) {
|
||||
sb.append(node.getPrefix().getValue());
|
||||
prefixes.add(new SimpleEntry<>(node.getPrefix().getKey(), sb.toString()));
|
||||
}
|
||||
|
||||
if (node.isSuffix()) {
|
||||
sb.append(node.getSuffix().getValue());
|
||||
suffixes.add(new SimpleEntry<>(node.getSuffix().getKey(), sb.toString()));
|
||||
}
|
||||
}
|
||||
|
||||
if (prefixes.isEmpty()) {
|
||||
Message.CHAT_META_PREFIX_NONE.send(sender, user.getName());
|
||||
} else {
|
||||
Message.CHAT_META_PREFIX_HEADER.send(sender, user.getName());
|
||||
for (Map.Entry<Integer, String> e : prefixes) {
|
||||
Message.CHAT_META_ENTRY.send(sender, e.getKey(), e.getValue());
|
||||
}
|
||||
}
|
||||
|
||||
if (suffixes.isEmpty()) {
|
||||
Message.CHAT_META_SUFFIX_NONE.send(sender, user.getName());
|
||||
} else {
|
||||
Message.CHAT_META_SUFFIX_HEADER.send(sender, user.getName());
|
||||
for (Map.Entry<Integer, String> e : suffixes) {
|
||||
Message.CHAT_META_ENTRY.send(sender, e.getKey(), e.getValue());
|
||||
}
|
||||
}
|
||||
|
||||
return CommandResult.SUCCESS;
|
||||
}
|
||||
}
|
@ -81,6 +81,8 @@ public abstract class PermissionHolder {
|
||||
@Getter
|
||||
private final Lock ioLock = new ReentrantLock();
|
||||
|
||||
public abstract String getFriendlyName();
|
||||
|
||||
private void invalidateCache(boolean enduring) {
|
||||
if (enduring) {
|
||||
enduringCache.invalidate();
|
||||
|
@ -63,6 +63,11 @@ public class Group extends PermissionHolder implements Identifiable<String> {
|
||||
return dn.equals(name) ? name : name + " (" + dn + ")";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getFriendlyName() {
|
||||
return getDisplayName();
|
||||
}
|
||||
|
||||
/**
|
||||
* check to see if a group inherits a group
|
||||
* @param group The group to check membership of
|
||||
|
@ -79,6 +79,11 @@ public abstract class User extends PermissionHolder implements Identifiable<User
|
||||
return UserIdentifier.of(uuid, name);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getFriendlyName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
/**
|
||||
* Refresh and re-assign the users permissions
|
||||
*/
|
||||
|
Loading…
Reference in New Issue
Block a user