Huge cleanup

This commit is contained in:
Luck 2016-06-29 15:35:57 +01:00
parent 0e449cdd7a
commit 84335afacd
43 changed files with 351 additions and 378 deletions

View File

@ -6,6 +6,7 @@ import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import java.lang.ref.WeakReference;
import java.util.Arrays;
class CommandManagerBukkit extends CommandManager implements CommandExecutor {
@ -15,15 +16,20 @@ class CommandManagerBukkit extends CommandManager implements CommandExecutor {
@Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
final WeakReference<CommandSender> cs = new WeakReference<>(sender);
return onCommand(new Sender() {
@Override
public void sendMessage(String s) {
sender.sendMessage(s);
CommandSender c = cs.get();
if (c != null) {
c.sendMessage(s);
}
}
@Override
public boolean hasPermission(String node) {
return sender.hasPermission(node);
CommandSender c = cs.get();
return c != null && c.hasPermission(node);
}
}, Arrays.asList(args));
}

View File

@ -123,8 +123,7 @@ public class LPBukkitPlugin extends JavaPlugin implements LuckPermsPlugin {
@Override
public String getPlayerStatus(UUID uuid) {
if (getServer().getPlayer(uuid) != null) return "&aOnline";
return "&cOffline";
return getServer().getPlayer(uuid) != null ? "&aOnline" : "&cOffline";
}
@Override

View File

@ -40,15 +40,11 @@ public class BukkitUser extends User {
}
// Clear existing permissions
for (String p : attachment.getPermissions().keySet()) {
attachment.setPermission(p, false);
}
attachment.getPermissions().keySet().stream().forEach(p -> attachment.setPermission(p, false));
// Re-add all defined permissions for the user
Map<String, Boolean> local = getLocalPermissions(getPlugin().getConfiguration().getServer(), null);
for (String node : local.keySet()) {
attachment.setPermission(node, local.get(node));
}
local.entrySet().stream().forEach(e -> attachment.setPermission(e.getKey(), e.getValue()));
});
}
}

View File

@ -54,8 +54,6 @@ public class BukkitUserManager extends UserManager {
@Override
public void updateAllUsers() {
for (Player p : plugin.getServer().getOnlinePlayers()) {
plugin.getDatastore().loadUser(p.getUniqueId());
}
plugin.getServer().getOnlinePlayers().stream().map(Player::getUniqueId).forEach(u -> plugin.getDatastore().loadUser(u));
}
}

View File

@ -77,8 +77,7 @@ public class LPBungeePlugin extends Plugin implements LuckPermsPlugin {
@Override
public String getPlayerStatus(UUID uuid) {
if (getProxy().getPlayer(uuid) != null) return "&aOnline";
return "&cOffline";
return getProxy().getPlayer(uuid) != null ? "&aOnline" : "&cOffline";
}
@Override

View File

@ -6,6 +6,7 @@ import net.md_5.bungee.api.CommandSender;
import net.md_5.bungee.api.chat.TextComponent;
import net.md_5.bungee.api.plugin.Command;
import java.lang.ref.WeakReference;
import java.util.Arrays;
class MainCommand extends Command {
@ -19,15 +20,20 @@ class MainCommand extends Command {
@Override
public void execute(CommandSender sender, String[] args) {
final WeakReference<CommandSender> cs = new WeakReference<>(sender);
manager.onCommand(new Sender() {
@Override
public void sendMessage(String s) {
sender.sendMessage(new TextComponent(s));
final CommandSender c = cs.get();
if (c != null) {
c.sendMessage(new TextComponent(s));
}
}
@Override
public boolean hasPermission(String node) {
return sender.hasPermission(node);
final CommandSender c = cs.get();
return c != null && c.hasPermission(node);
}
}, Arrays.asList(args));
}

View File

@ -29,14 +29,10 @@ public class BungeeUser extends User {
// Clear existing permissions
Collection<String> perms = new ArrayList<>(player.getPermissions());
for (String p : perms) {
player.setPermission(p, false);
}
perms.stream().forEach(p -> player.setPermission(p, false));
// Re-add all defined permissions for the user
Map<String, Boolean> local = getLocalPermissions(getPlugin().getConfiguration().getServer(), null);
for (String node : local.keySet()) {
player.setPermission(node, local.get(node));
}
local.entrySet().stream().forEach(e -> player.setPermission(e.getKey(), e.getValue()));
}
}

View File

@ -41,8 +41,6 @@ public class BungeeUserManager extends UserManager {
@Override
public void updateAllUsers() {
for (ProxiedPlayer p : plugin.getProxy().getPlayers()) {
plugin.getDatastore().loadUser(p.getUniqueId());
}
plugin.getProxy().getPlayers().stream().map(ProxiedPlayer::getUniqueId).forEach(u -> plugin.getDatastore().loadUser(u));
}
}

View File

@ -15,6 +15,7 @@ import me.lucko.luckperms.commands.user.subcommands.*;
import java.util.ArrayList;
import java.util.List;
import java.util.Optional;
import java.util.logging.Level;
public class CommandManager {
@ -66,40 +67,34 @@ public class CommandManager {
*/
public boolean onCommand(Sender sender, List<String> args) {
if (args.size() == 0) {
Util.sendPluginMessage(sender, "&6Running &bLuckPerms " + plugin.getVersion() + "&6.");
mainCommands.stream()
.filter(c -> c.canUse(sender))
.forEach(c -> Util.sendPluginMessage(sender, "&e-> &d" + c.getUsage()));
} else {
String c = args.get(0);
MainCommand main = null;
for (MainCommand mainCommand : mainCommands) {
if (mainCommand.getName().equalsIgnoreCase(c)) {
main = mainCommand;
break;
}
}
if (main == null) {
Util.sendPluginMessage(sender, "Command not recognised.");
return true;
}
if (main.getRequiredArgsLength() == 0) {
main.execute(plugin, sender, null);
return true;
}
if (args.size() == 1) {
main.sendUsage(sender);
return true;
}
main.execute(plugin, sender, new ArrayList<>(args.subList(1, args.size())));
sendCommandUsage(sender);
return true;
}
Optional<MainCommand> o = mainCommands.stream().filter(m -> m.getName().equalsIgnoreCase(args.get(0))).limit(1).findAny();
if (!o.isPresent()) {
sendCommandUsage(sender);
return true;
}
final MainCommand main = o.get();
if (!main.canUse(sender)) {
sendCommandUsage(sender);
return true;
}
if (main.getRequiredArgsLength() == 0) {
main.execute(plugin, sender, null);
return true;
}
if (args.size() == 1) {
main.sendUsage(sender);
return true;
}
main.execute(plugin, sender, new ArrayList<>(args.subList(1, args.size())));
return true;
}
@ -109,4 +104,11 @@ public class CommandManager {
mainCommands.add(command);
}
private void sendCommandUsage(Sender sender) {
Util.sendPluginMessage(sender, "&6Running &bLuckPerms " + plugin.getVersion() + "&6.");
mainCommands.stream()
.filter(c -> c.canUse(sender))
.forEach(c -> Util.sendPluginMessage(sender, "&e-> &d" + c.getUsage()));
}
}

View File

@ -1,32 +1,29 @@
package me.lucko.luckperms.commands;
import lombok.AllArgsConstructor;
import lombok.Getter;
import me.lucko.luckperms.LuckPermsPlugin;
import java.util.List;
import java.util.stream.Collectors;
@Getter
@AllArgsConstructor
public abstract class MainCommand {
@Getter
private final String name;
@Getter
private final String usage;
@Getter
private final int requiredArgsLength;
protected MainCommand(String name, String usage, int requiredArgsLength) {
this.name = name;
this.usage = usage;
this.requiredArgsLength = requiredArgsLength;
}
protected abstract void execute(LuckPermsPlugin plugin, Sender sender, List<String> args);
public abstract List<? extends SubCommand> getSubCommands();
protected void sendUsage(Sender sender) {
if (getSubCommands().isEmpty()) {
Util.sendPluginMessage(sender, "&e-> &d" + getUsage());
return;
}
List<SubCommand> subs = getSubCommands().stream().filter(s -> s.isAuthorized(sender)).collect(Collectors.toList());
if (subs.size() > 0) {
Util.sendPluginMessage(sender, "&e" + getName() + " Sub Commands:");
@ -41,11 +38,6 @@ public abstract class MainCommand {
}
protected boolean canUse(Sender sender) {
for (SubCommand sc : getSubCommands()) {
if (sc.isAuthorized(sender)) {
return true;
}
}
return false;
return getSubCommands().stream().filter(sc -> sc.isAuthorized(sender)).count() != 0;
}
}

View File

@ -0,0 +1,65 @@
package me.lucko.luckperms.commands;
import lombok.AllArgsConstructor;
import lombok.Getter;
@AllArgsConstructor
public enum Permission {
SYNC("sync", null),
INFO("info", null),
DEBUG("debug", null),
CREATE_GROUP("creategroup", null),
DELETE_GROUP("deletegroup", null),
LIST_GROUPS("listgroups", null),
USER_INFO("info", PermissionGroup.USER),
USER_GETUUID("getuuid", PermissionGroup.USER),
USER_LISTNODES("listnodes", PermissionGroup.USER),
USER_HASPERMISSION("haspermission", PermissionGroup.USER),
USER_SETPERMISSION("setpermission", PermissionGroup.USER),
USER_UNSETPERMISSION("unsetpermission", PermissionGroup.USER),
USER_ADDGROUP("addgroup", PermissionGroup.USER),
USER_REMOVEGROUP("removegroup", PermissionGroup.USER),
USER_SETPRIMARYGROUP("setprimarygroup", PermissionGroup.USER),
USER_CLEAR("clear", PermissionGroup.USER),
GROUP_INFO("info", PermissionGroup.GROUP),
GROUP_LISTNODES("listnodes", PermissionGroup.GROUP),
GROUP_HASPERMISSION("haspermission", PermissionGroup.GROUP),
GROUP_SETPERMISSION("setpermission", PermissionGroup.GROUP),
GROUP_UNSETPERMISSION("unsetpermission", PermissionGroup.GROUP),
GROUP_SETINHERIT("setinherit", PermissionGroup.GROUP),
GROUP_UNSETINHERIT("unsetinherit", PermissionGroup.GROUP),
GROUP_CLEAR("clear", PermissionGroup.GROUP);
private String node;
private PermissionGroup group;
public boolean isAuthorized(Sender sender) {
if (sender.hasPermission("luckperms.*")) {
return true;
}
if (group != null) {
return group.isAuthorized(sender) || sender.hasPermission("luckperms." + group.getNode() + "." + node);
}
return sender.hasPermission("luckperms." + node);
}
@Getter
@AllArgsConstructor
private enum PermissionGroup {
USER("user"),
GROUP("group");
private String node;
private boolean isAuthorized(Sender sender) {
return sender.hasPermission("luckperms." + node + ".*");
}
}
}

View File

@ -1,30 +1,18 @@
package me.lucko.luckperms.commands;
import lombok.AllArgsConstructor;
import lombok.Getter;
@Getter
@AllArgsConstructor
public abstract class SubCommand {
@Getter
private final String name;
@Getter
private final String description;
@Getter
private final String usage;
@Getter
private final String permission;
protected SubCommand(String name, String description, String usage, String permission) {
this.name = name;
this.description = description;
this.usage = usage;
this.permission = permission;
}
private final Permission permission;
public boolean isAuthorized(Sender sender) {
return sender.hasPermission(permission) || sender.hasPermission("luckperms.*");
return permission.isAuthorized(sender);
}
public void sendUsage(Sender sender) {

View File

@ -20,8 +20,8 @@ public class Util {
// Stolen from Bukkit :>
char[] b = textToTranslate.toCharArray();
for(int i = 0; i < b.length - 1; ++i) {
if(b[i] == altColorChar && "0123456789AaBbCcDdEeFfKkLlMmNnOoRr".indexOf(b[i + 1]) > -1) {
for (int i = 0; i < b.length - 1; ++i) {
if (b[i] == altColorChar && "0123456789AaBbCcDdEeFfKkLlMmNnOoRr".indexOf(b[i + 1]) > -1) {
b[i] = 167;
b[i + 1] = Character.toLowerCase(b[i + 1]);
}
@ -42,11 +42,7 @@ public class Util {
if (strings.isEmpty()) return "&6None";
StringBuilder sb = new StringBuilder();
for (String s : strings) {
sb.append("&6").append(s).append("&7, ");
}
strings.stream().forEach(s -> sb.append("&6").append(s).append("&7, "));
return sb.delete(sb.length() - 2, sb.length()).toString();
}
@ -55,11 +51,11 @@ public class Util {
StringBuilder sb = new StringBuilder();
for (String node : nodes.keySet()) {
if (nodes.get(node)) {
sb.append("&a").append(node).append("&7, ");
for (Map.Entry<String, Boolean> e : nodes.entrySet()) {
if (e.getValue()) {
sb.append("&a").append(e.getKey()).append("&7, ");
} else {
sb.append("&c").append(node).append("&7, ");
sb.append("&c").append(e.getKey()).append("&7, ");
}
}

View File

@ -1,10 +1,7 @@
package me.lucko.luckperms.commands.group;
import me.lucko.luckperms.LuckPermsPlugin;
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.*;
import java.util.ArrayList;
import java.util.List;
@ -16,18 +13,12 @@ public class CreateGroupCommand extends MainCommand {
@Override
protected void execute(LuckPermsPlugin plugin, Sender sender, List<String> args) {
if (!sender.hasPermission("luckperms.creategroup")) {
Util.sendPluginMessage(sender, "You do not have permission to use this command!");
return;
}
if (args.size() == 0) {
sendUsage(sender);
return;
}
String groupName = args.get(0).toLowerCase();
plugin.getDatastore().loadGroup(groupName, success -> {
if (success) {
Util.sendPluginMessage(sender, "That group already exists!");
@ -51,6 +42,6 @@ public class CreateGroupCommand extends MainCommand {
@Override
protected boolean canUse(Sender sender) {
return sender.hasPermission("luckperms.creategroup") || sender.hasPermission("luckperms.*");
return Permission.CREATE_GROUP.isAuthorized(sender);
}
}

View File

@ -1,10 +1,7 @@
package me.lucko.luckperms.commands.group;
import me.lucko.luckperms.LuckPermsPlugin;
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.*;
import me.lucko.luckperms.groups.Group;
import java.util.ArrayList;
@ -17,11 +14,6 @@ public class DeleteGroupCommand extends MainCommand {
@Override
protected void execute(LuckPermsPlugin plugin, Sender sender, List<String> args) {
if (!sender.hasPermission("luckperms.deletegroup")) {
Util.sendPluginMessage(sender, "You do not have permission to use this command!");
return;
}
if (args.size() == 0) {
sendUsage(sender);
return;
@ -41,7 +33,7 @@ public class DeleteGroupCommand extends MainCommand {
Group group = plugin.getGroupManager().getGroup(groupName);
if (group == null) {
Util.sendPluginMessage(sender, "An unexpected error occurred.");
Util.sendPluginMessage(sender, "An unexpected error occurred. Group not loaded.");
} else {
plugin.getDatastore().deleteGroup(group, success1 -> {
if (!success1) {
@ -63,6 +55,6 @@ public class DeleteGroupCommand extends MainCommand {
@Override
protected boolean canUse(Sender sender) {
return sender.hasPermission("luckperms.deletegroup") || sender.hasPermission("luckperms.*");
return Permission.DELETE_GROUP.isAuthorized(sender);
}
}

View File

@ -9,7 +9,7 @@ import me.lucko.luckperms.groups.Group;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;
import java.util.Optional;
public class GroupMainCommand extends MainCommand {
@ -21,48 +21,37 @@ public class GroupMainCommand extends MainCommand {
@Override
protected void execute(LuckPermsPlugin plugin, Sender sender, List<String> args) {
if (args.size() <= 1) {
if (args.size() < 2) {
sendUsage(sender);
return;
}
Optional<GroupSubCommand> o = subCommands.stream().filter(s -> s.getName().equalsIgnoreCase(args.get(1))).limit(1).findAny();
if (!o.isPresent()) {
Util.sendPluginMessage(sender, "Command not recognised.");
return;
}
final GroupSubCommand sub = o.get();
if (!sub.isAuthorized(sender)) {
Util.sendPluginMessage(sender, "You do not have permission to use this command!");
return;
}
List<String> strippedArgs = new ArrayList<>();
if (args.size() > 2) {
strippedArgs.addAll(args.subList(2, args.size()));
}
String c = args.get(1);
GroupSubCommand tempSub = null;
for (GroupSubCommand s : subCommands) {
if (s.getName().equalsIgnoreCase(c)) {
tempSub = s;
break;
}
}
final GroupSubCommand sub = tempSub;
if (sub == null) {
Util.sendPluginMessage(sender, "Command not recognised.");
return;
}
if (!sub.isAuthorized(sender)) {
Util.sendPluginMessage(sender, "You do not have permission to use this command!");
return;
}
String g = args.get(0).toLowerCase();
plugin.getDatastore().loadGroup(g, success -> {
final String groupName = args.get(0).toLowerCase();
plugin.getDatastore().loadGroup(groupName, success -> {
if (!success) {
Util.sendPluginMessage(sender, "&eGroup could not be found.");
return;
}
Group group = plugin.getGroupManager().getGroup(g);
Group group = plugin.getGroupManager().getGroup(groupName);
if (group == null) {
Util.sendPluginMessage(sender, "&eGroup could not be found.");
return;
@ -86,18 +75,4 @@ public class GroupMainCommand extends MainCommand {
subCommands.add(subCommand);
}
@Override
protected void sendUsage(Sender sender) {
List<SubCommand> subs = getSubCommands().stream().filter(s -> s.isAuthorized(sender)).collect(Collectors.toList());
if (subs.size() > 0) {
Util.sendPluginMessage(sender, "&e" + getName() + " Sub Commands:");
for (SubCommand s : subs) {
s.sendUsage(sender);
}
} else {
Util.sendPluginMessage(sender, "You do not have permission to use this command!");
}
}
}

View File

@ -1,6 +1,7 @@
package me.lucko.luckperms.commands.group;
import me.lucko.luckperms.LuckPermsPlugin;
import me.lucko.luckperms.commands.Permission;
import me.lucko.luckperms.commands.Sender;
import me.lucko.luckperms.commands.SubCommand;
import me.lucko.luckperms.commands.Util;
@ -9,17 +10,12 @@ import me.lucko.luckperms.groups.Group;
import java.util.List;
public abstract class GroupSubCommand extends SubCommand {
protected GroupSubCommand(String name, String description, String usage, String permission) {
protected GroupSubCommand(String name, String description, String usage, Permission permission) {
super(name, description, usage, permission);
}
protected abstract void execute(LuckPermsPlugin plugin, Sender sender, Group group, List<String> args);
@Override
public boolean isAuthorized(Sender sender) {
return sender.hasPermission(getPermission()) || sender.hasPermission("luckperms.group.*") || sender.hasPermission("luckperms.*");
}
protected void saveGroup(Group group, Sender sender, LuckPermsPlugin plugin) {
plugin.getDatastore().saveGroup(group, success -> {
if (success) {

View File

@ -1,10 +1,7 @@
package me.lucko.luckperms.commands.group;
import me.lucko.luckperms.LuckPermsPlugin;
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.*;
import java.util.ArrayList;
import java.util.List;
@ -16,16 +13,12 @@ public class ListGroupsCommand extends MainCommand {
@Override
protected void execute(LuckPermsPlugin plugin, Sender sender, List<String> args) {
if (!sender.hasPermission("luckperms.listgroups")) {
Util.sendPluginMessage(sender, "You do not have permission to use this command!");
return;
}
plugin.getDatastore().loadAllGroups(success -> {
if (!success) {
Util.sendPluginMessage(sender, "Unable to load all groups.");
} else {
Util.sendPluginMessage(sender, "&aGroups: " + Util.listToCommaSep(new ArrayList<>(plugin.getGroupManager().getGroups().keySet())));
Util.sendPluginMessage(sender, "&aGroups: " +
Util.listToCommaSep(new ArrayList<>(plugin.getGroupManager().getGroups().keySet())));
}
});
}
@ -37,6 +30,6 @@ public class ListGroupsCommand extends MainCommand {
@Override
protected boolean canUse(Sender sender) {
return sender.hasPermission("luckperms.listgroups") || sender.hasPermission("luckperms.*");
return Permission.LIST_GROUPS.isAuthorized(sender);
}
}

View File

@ -1,6 +1,7 @@
package me.lucko.luckperms.commands.group.subcommands;
import me.lucko.luckperms.LuckPermsPlugin;
import me.lucko.luckperms.commands.Permission;
import me.lucko.luckperms.commands.Sender;
import me.lucko.luckperms.commands.Util;
import me.lucko.luckperms.commands.group.GroupSubCommand;
@ -10,8 +11,7 @@ import java.util.List;
public class GroupClearCommand extends GroupSubCommand {
public GroupClearCommand() {
super("clear", "Clears a groups permissions",
"/perms group <group> clear", "luckperms.group.clear");
super("clear", "Clears a groups permissions", "/perms group <group> clear", Permission.GROUP_CLEAR);
}
@Override
@ -24,6 +24,6 @@ public class GroupClearCommand extends GroupSubCommand {
@Override
public boolean isArgLengthInvalid(int argLength) {
return true;
return false;
}
}

View File

@ -1,6 +1,7 @@
package me.lucko.luckperms.commands.group.subcommands;
import me.lucko.luckperms.LuckPermsPlugin;
import me.lucko.luckperms.commands.Permission;
import me.lucko.luckperms.commands.Sender;
import me.lucko.luckperms.commands.Util;
import me.lucko.luckperms.commands.group.GroupSubCommand;
@ -11,13 +12,13 @@ import java.util.List;
public class GroupHasPermCommand extends GroupSubCommand {
public GroupHasPermCommand() {
super("haspermission", "Checks to see if a group has a certain permission node",
"/perms group <group> haspermission <node> [server]", "luckperms.group.haspermission");
"/perms group <group> haspermission <node> [server]", Permission.GROUP_HASPERMISSION);
}
@Override
protected void execute(LuckPermsPlugin plugin, Sender sender, Group group, List<String> args) {
if (args.size() >= 2) {
Util.sendBoolean(sender, args.get(0), group.hasPermission(args.get(0), true, args.get(1)));
if (args.size() == 2) {
Util.sendBoolean(sender, args.get(0), group.hasPermission(args.get(0), true, args.get(1).toLowerCase()));
} else {
Util.sendBoolean(sender, args.get(0), group.hasPermission(args.get(0), true, "global"));
}
@ -25,6 +26,6 @@ public class GroupHasPermCommand extends GroupSubCommand {
@Override
public boolean isArgLengthInvalid(int argLength) {
return argLength == 0;
return argLength != 1 && argLength != 2;
}
}

View File

@ -1,6 +1,7 @@
package me.lucko.luckperms.commands.group.subcommands;
import me.lucko.luckperms.LuckPermsPlugin;
import me.lucko.luckperms.commands.Permission;
import me.lucko.luckperms.commands.Sender;
import me.lucko.luckperms.commands.Util;
import me.lucko.luckperms.commands.group.GroupSubCommand;
@ -10,18 +11,16 @@ import java.util.List;
public class GroupInfoCommand extends GroupSubCommand {
public GroupInfoCommand() {
super("info", "Gives info about the group",
"/perms group <group> info", "luckperms.group.info");
super("info", "Gives info about the group", "/perms group <group> info", Permission.GROUP_INFO);
}
@Override
protected void execute(LuckPermsPlugin plugin, Sender sender, Group group, List<String> args) {
final String prefix = Util.PREFIX;
String sb = prefix + "&d-> &eGroup: &6" + group.getName() + "\n" +
prefix + "&d-> &ePermissions: &6" + group.getNodes().keySet().size() + "\n" +
prefix + "&d-> &bUse &a/perms group " + group.getName() + " listnodes &bto see all permissions.";
sender.sendMessage(Util.color(sb));
sender.sendMessage(Util.color(
Util.PREFIX + "&d-> &eGroup: &6" + group.getName() + "\n" +
Util.PREFIX + "&d-> &ePermissions: &6" + group.getNodes().keySet().size() + "\n" +
Util.PREFIX + "&d-> &bUse &a/perms group " + group.getName() + " listnodes &bto see all permissions."
));
}
@Override

View File

@ -1,6 +1,7 @@
package me.lucko.luckperms.commands.group.subcommands;
import me.lucko.luckperms.LuckPermsPlugin;
import me.lucko.luckperms.commands.Permission;
import me.lucko.luckperms.commands.Sender;
import me.lucko.luckperms.commands.Util;
import me.lucko.luckperms.commands.group.GroupSubCommand;
@ -10,8 +11,8 @@ import java.util.List;
public class GroupListNodesCommand extends GroupSubCommand {
public GroupListNodesCommand() {
super("listnodes", "Lists the permission nodes the group has",
"/perms group <group> listnodes", "luckperms.group.listnodes");
super("listnodes", "Lists the permission nodes the group has", "/perms group <group> listnodes",
Permission.GROUP_LISTNODES);
}
@Override

View File

@ -1,6 +1,7 @@
package me.lucko.luckperms.commands.group.subcommands;
import me.lucko.luckperms.LuckPermsPlugin;
import me.lucko.luckperms.commands.Permission;
import me.lucko.luckperms.commands.Sender;
import me.lucko.luckperms.commands.Util;
import me.lucko.luckperms.commands.group.GroupSubCommand;
@ -12,7 +13,7 @@ import java.util.List;
public class GroupSetInheritCommand extends GroupSubCommand {
public GroupSetInheritCommand() {
super("setinherit", "Sets another group for this group to inherit permissions from",
"/perms group <group> setinherit <group> [server]", "luckperms.group.setinherit");
"/perms group <group> setinherit <group> [server]", Permission.GROUP_SETINHERIT);
}
@Override
@ -23,16 +24,16 @@ public class GroupSetInheritCommand extends GroupSubCommand {
if (!success) {
Util.sendPluginMessage(sender, groupName + " does not exist!");
} else {
final String node = "group." + groupName;
try {
if (args.size() == 2) {
final String server = args.get(1).toLowerCase();
group.setPermission(node, true, server);
Util.sendPluginMessage(sender, "&b" + group.getName() + "&a now inherits permissions from &b" + groupName + "&a on server &b" + server + "&a.");
group.setPermission("group." + groupName, true, server);
Util.sendPluginMessage(sender, "&b" + group.getName() + "&a now inherits permissions from &b" +
groupName + "&a on server &b" + server + "&a.");
} else {
group.setPermission(node, true);
Util.sendPluginMessage(sender, "&b" + group.getName() + "&a now inherits permissions from &b" + groupName + "&a.");
group.setPermission("group." + groupName, true);
Util.sendPluginMessage(sender, "&b" + group.getName() + "&a now inherits permissions from &b" +
groupName + "&a.");
}
saveGroup(group, sender, plugin);
@ -45,6 +46,6 @@ public class GroupSetInheritCommand extends GroupSubCommand {
@Override
public boolean isArgLengthInvalid(int argLength) {
return argLength == 0;
return argLength != 1 && argLength != 2;
}
}

View File

@ -1,6 +1,7 @@
package me.lucko.luckperms.commands.group.subcommands;
import me.lucko.luckperms.LuckPermsPlugin;
import me.lucko.luckperms.commands.Permission;
import me.lucko.luckperms.commands.Sender;
import me.lucko.luckperms.commands.Util;
import me.lucko.luckperms.commands.group.GroupSubCommand;
@ -11,8 +12,8 @@ import java.util.List;
public class GroupSetPermissionCommand extends GroupSubCommand {
public GroupSetPermissionCommand() {
super("set", "Sets a permission for a group",
"/perms group <group> set <node> <true|false> [server]", "luckperms.group.setpermission");
super("set", "Sets a permission for a group", "/perms group <group> set <node> <true|false> [server]",
Permission.GROUP_SETPERMISSION);
}
@Override
@ -41,7 +42,8 @@ public class GroupSetPermissionCommand extends GroupSubCommand {
if (args.size() == 3) {
final String server = args.get(2).toLowerCase();
group.setPermission(node, b, server);
Util.sendPluginMessage(sender, "&aSet &b" + node + "&a to &b" + bool + "&a for &b" + group.getName() + "&a on server &b" + server + "&a.");
Util.sendPluginMessage(sender, "&aSet &b" + node + "&a to &b" + bool + "&a for &b" + group.getName() +
"&a on server &b" + server + "&a.");
} else {
group.setPermission(node, b);
Util.sendPluginMessage(sender, "&aSet &b" + node + "&a to " + bool + " for &b" + group.getName() + "&a.");
@ -55,6 +57,6 @@ public class GroupSetPermissionCommand extends GroupSubCommand {
@Override
public boolean isArgLengthInvalid(int argLength) {
return argLength < 2;
return argLength != 2 && argLength != 3;
}
}

View File

@ -1,6 +1,7 @@
package me.lucko.luckperms.commands.group.subcommands;
import me.lucko.luckperms.LuckPermsPlugin;
import me.lucko.luckperms.commands.Permission;
import me.lucko.luckperms.commands.Sender;
import me.lucko.luckperms.commands.Util;
import me.lucko.luckperms.commands.group.GroupSubCommand;
@ -12,7 +13,7 @@ import java.util.List;
public class GroupUnSetPermissionCommand extends GroupSubCommand {
public GroupUnSetPermissionCommand() {
super("unset", "Unsets a permission for a group",
"/perms group <group> unset <node> [server]", "luckperms.group.unsetpermission");
"/perms group <group> unset <node> [server]", Permission.GROUP_UNSETPERMISSION);
}
@Override
@ -33,7 +34,8 @@ public class GroupUnSetPermissionCommand extends GroupSubCommand {
if (args.size() == 2) {
final String server = args.get(1).toLowerCase();
group.unsetPermission(node, server);
Util.sendPluginMessage(sender, "&aUnset &b" + node + "&a for &b" + group.getName() + "&a on server &b" + server + "&a.");
Util.sendPluginMessage(sender, "&aUnset &b" + node + "&a for &b" + group.getName() + "&a on server &b" +
server + "&a.");
} else {
group.unsetPermission(node);
Util.sendPluginMessage(sender, "&aUnset &b" + node + "&a for &b" + group.getName() + "&a.");
@ -47,6 +49,6 @@ public class GroupUnSetPermissionCommand extends GroupSubCommand {
@Override
public boolean isArgLengthInvalid(int argLength) {
return argLength == 0;
return argLength != 1 && argLength != 2;
}
}

View File

@ -1,6 +1,7 @@
package me.lucko.luckperms.commands.group.subcommands;
import me.lucko.luckperms.LuckPermsPlugin;
import me.lucko.luckperms.commands.Permission;
import me.lucko.luckperms.commands.Sender;
import me.lucko.luckperms.commands.Util;
import me.lucko.luckperms.commands.group.GroupSubCommand;
@ -12,23 +13,25 @@ import java.util.List;
public class GroupUnsetInheritCommand extends GroupSubCommand {
public GroupUnsetInheritCommand() {
super("unsetinherit", "Unsets another group for this group to inherit permissions from",
"/perms group <group> unsetinherit <group> [server]", "luckperms.group.unsetinherit");
"/perms group <group> unsetinherit <group> [server]", Permission.GROUP_UNSETINHERIT);
}
@Override
protected void execute(LuckPermsPlugin plugin, Sender sender, Group group, List<String> args) {
String groupName = args.get(0).toLowerCase();
String server;
if (args.size() == 2) {
server = args.get(1).toLowerCase();
} else {
server = "global";
}
try {
group.unsetPermission("group." + groupName, server);
Util.sendPluginMessage(sender, "&b" + group.getName() + "&a no longer inherits permissions from &b" + groupName + "&a on server &b" + server + "&a.");
if (args.size() == 2) {
final String server = args.get(1).toLowerCase();
group.unsetPermission("group." + groupName, server);
Util.sendPluginMessage(sender, "&b" + group.getName() + "&a no longer inherits permissions from &b" +
groupName + "&a on server &b" + server + "&a.");
} else {
group.unsetPermission("group." + groupName);
Util.sendPluginMessage(sender, "&b" + group.getName() + "&a no longer inherits permissions from &b" +
groupName + "&a.");
}
saveGroup(group, sender, plugin);
} catch (ObjectLacksPermissionException e) {
Util.sendPluginMessage(sender, "That group does not inherit '" + groupName + "'.");
@ -37,6 +40,6 @@ public class GroupUnsetInheritCommand extends GroupSubCommand {
@Override
public boolean isArgLengthInvalid(int argLength) {
return argLength == 0;
return argLength != 1 && argLength != 2;
}
}

View File

@ -1,10 +1,7 @@
package me.lucko.luckperms.commands.misc;
import me.lucko.luckperms.LuckPermsPlugin;
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.*;
import java.util.ArrayList;
import java.util.List;
@ -16,11 +13,6 @@ public class DebugCommand extends MainCommand {
@Override
protected void execute(LuckPermsPlugin plugin, Sender sender, List<String> args) {
if (!sender.hasPermission("luckperms.debug")) {
Util.sendPluginMessage(sender, "You do not have permission to use this command!");
return;
}
Util.sendPluginMessage(sender, "&d&l> &dDebug Info");
Util.sendPluginMessage(sender, "&eOnline Players: &6" + plugin.getPlayerCount());
Util.sendPluginMessage(sender, "&eLoaded Users: &6" + plugin.getUserManager().getUsers().size());
@ -34,6 +26,6 @@ public class DebugCommand extends MainCommand {
@Override
protected boolean canUse(Sender sender) {
return sender.hasPermission("luckperms.debug") || sender.hasPermission("luckperms.*");
return Permission.DEBUG.isAuthorized(sender);
}
}

View File

@ -1,10 +1,7 @@
package me.lucko.luckperms.commands.misc;
import me.lucko.luckperms.LuckPermsPlugin;
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.*;
import java.util.ArrayList;
import java.util.List;
@ -16,11 +13,6 @@ public class InfoCommand extends MainCommand {
@Override
protected void execute(LuckPermsPlugin plugin, Sender sender, List<String> args) {
if (!sender.hasPermission("luckperms.info")) {
Util.sendPluginMessage(sender, "You do not have permission to use this command!");
return;
}
Util.sendPluginMessage(sender, "&6Running &bLuckPerms " + plugin.getVersion() + "&6.");
Util.sendPluginMessage(sender, "&eAuthor: &6Luck");
Util.sendPluginMessage(sender, "&eStorage Method: &6" + plugin.getDatastore().getName());
@ -33,6 +25,6 @@ public class InfoCommand extends MainCommand {
@Override
protected boolean canUse(Sender sender) {
return sender.hasPermission("luckperms.info") || sender.hasPermission("luckperms.*");
return Permission.INFO.isAuthorized(sender);
}
}

View File

@ -1,10 +1,7 @@
package me.lucko.luckperms.commands.misc;
import me.lucko.luckperms.LuckPermsPlugin;
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.*;
import java.util.ArrayList;
import java.util.List;
@ -16,11 +13,6 @@ public class SyncCommand extends MainCommand {
@Override
protected void execute(LuckPermsPlugin plugin, Sender sender, List<String> args) {
if (!sender.hasPermission("luckperms.sync")) {
Util.sendPluginMessage(sender, "You do not have permission to use this command!");
return;
}
Util.sendPluginMessage(sender, "&bRunning update task for all online users.");
plugin.runUpdateTask();
}
@ -32,6 +24,6 @@ public class SyncCommand extends MainCommand {
@Override
protected boolean canUse(Sender sender) {
return sender.hasPermission("luckperms.sync") || sender.hasPermission("luckperms.*");
return Permission.SYNC.isAuthorized(sender);
}
}

View File

@ -9,6 +9,7 @@ import me.lucko.luckperms.users.User;
import java.util.ArrayList;
import java.util.List;
import java.util.Optional;
import java.util.UUID;
public class UserMainCommand extends MainCommand{
@ -21,31 +22,19 @@ public class UserMainCommand extends MainCommand{
@Override
protected void execute(LuckPermsPlugin plugin, Sender sender, List<String> args) {
if (args.size() <= 1) {
if (args.size() < 2) {
sendUsage(sender);
return;
}
// The first argument is the name of the user, the second is the command
String command = args.get(1);
UserSubCommand tempSub = null;
Optional<UserSubCommand> o = subCommands.stream().filter(s -> s.getName().equalsIgnoreCase(args.get(1))).limit(1).findAny();
// Try to identify the command used
for (UserSubCommand s : subCommands) {
if (s.getName().equalsIgnoreCase(command)) {
tempSub = s;
break;
}
}
// The command the sender used
final UserSubCommand sub = tempSub;
if (sub == null) {
if (!o.isPresent()) {
Util.sendPluginMessage(sender, "Command not recognised.");
return;
}
final UserSubCommand sub = o.get();
if (!sub.isAuthorized(sender)) {
Util.sendPluginMessage(sender, "You do not have permission to use this command!");
return;
@ -57,8 +46,7 @@ public class UserMainCommand extends MainCommand{
strippedArgs.addAll(args.subList(2, args.size()));
}
String user = args.get(0);
final String user = args.get(0);
UUID u = Util.parseUuid(user);
if (u != null) {
runSub(plugin, sender, u, sub, strippedArgs);
@ -88,9 +76,8 @@ public class UserMainCommand extends MainCommand{
return;
}
User user1 = plugin.getUserManager().getUser(uuid);
if (user1 == null) {
User user = plugin.getUserManager().getUser(uuid);
if (user == null) {
Util.sendPluginMessage(sender, "&eUser could not be found.");
}
@ -99,8 +86,8 @@ public class UserMainCommand extends MainCommand{
return;
}
command.execute(plugin, sender, user1, strippedArgs);
plugin.getUserManager().cleanupUser(user1);
command.execute(plugin, sender, user, strippedArgs);
plugin.getUserManager().cleanupUser(user);
});
}

View File

@ -1,6 +1,7 @@
package me.lucko.luckperms.commands.user;
import me.lucko.luckperms.LuckPermsPlugin;
import me.lucko.luckperms.commands.Permission;
import me.lucko.luckperms.commands.Sender;
import me.lucko.luckperms.commands.SubCommand;
import me.lucko.luckperms.commands.Util;
@ -9,17 +10,12 @@ import me.lucko.luckperms.users.User;
import java.util.List;
public abstract class UserSubCommand extends SubCommand {
protected UserSubCommand(String name, String description, String usage, String permission) {
protected UserSubCommand(String name, String description, String usage, Permission permission) {
super(name, description, usage, permission);
}
protected abstract void execute(LuckPermsPlugin plugin, Sender sender, User user, List<String> args);
@Override
public boolean isAuthorized(Sender sender) {
return sender.hasPermission(getPermission()) || sender.hasPermission("luckperms.user.*") || sender.hasPermission("luckperms.*");
}
protected void saveUser(User user, Sender sender, LuckPermsPlugin plugin) {
user.refreshPermissions();

View File

@ -1,6 +1,7 @@
package me.lucko.luckperms.commands.user.subcommands;
import me.lucko.luckperms.LuckPermsPlugin;
import me.lucko.luckperms.commands.Permission;
import me.lucko.luckperms.commands.Sender;
import me.lucko.luckperms.commands.Util;
import me.lucko.luckperms.commands.user.UserSubCommand;
@ -12,34 +13,41 @@ import java.util.List;
public class UserAddGroupCommand extends UserSubCommand {
public UserAddGroupCommand() {
super("addgroup", "Adds the user to a group",
"/perms user <user> addgroup <group> [server]", "luckperms.user.addgroup");
super("addgroup", "Adds the user to a group", "/perms user <user> addgroup <group> [server]", Permission.USER_ADDGROUP);
}
@Override
protected void execute(LuckPermsPlugin plugin, Sender sender, User user, List<String> args) {
String group = args.get(0).toLowerCase();
String groupName = args.get(0).toLowerCase();
String server;
if (args.size() != 1) {
server = args.get(1);
} else {
server = "global";
}
plugin.getDatastore().loadGroup(groupName, success -> {
if (!success) {
Util.sendPluginMessage(sender, groupName + " does not exist!");
} else {
Group group = plugin.getGroupManager().getGroup(groupName);
if (group == null) {
Util.sendPluginMessage(sender, "That group does not exist!");
return;
}
Group group1 = plugin.getGroupManager().getGroup(group);
if (group1 == null) {
Util.sendPluginMessage(sender, "That group does not exist!");
return;
}
try {
if (args.size() == 2) {
final String server = args.get(1).toLowerCase();
user.addGroup(group, server);
Util.sendPluginMessage(sender, "&b" + user.getName() + "&a successfully added to group &b" +
groupName + "&a on the server &b" + server + "&a.");
} else {
user.addGroup(group);
Util.sendPluginMessage(sender, "&b" + user.getName() + "&a successfully added to group &b" +
groupName + "&a.");
}
try {
user.addGroup(group1, server);
Util.sendPluginMessage(sender, "&b" + user.getName() + "&a successfully added to group &b" + group + "&a on the server &b" + server + "&a.");
} catch (ObjectAlreadyHasException e) {
Util.sendPluginMessage(sender, "The user is already a member of that group.");
}
saveUser(user, sender, plugin);
saveUser(user, sender, plugin);
} catch (ObjectAlreadyHasException e) {
Util.sendPluginMessage(sender, "The user is already a member of that group.");
}
}
});
}
@Override

View File

@ -1,6 +1,7 @@
package me.lucko.luckperms.commands.user.subcommands;
import me.lucko.luckperms.LuckPermsPlugin;
import me.lucko.luckperms.commands.Permission;
import me.lucko.luckperms.commands.Sender;
import me.lucko.luckperms.commands.Util;
import me.lucko.luckperms.commands.user.UserSubCommand;
@ -10,8 +11,7 @@ import java.util.List;
public class UserClearCommand extends UserSubCommand {
public UserClearCommand() {
super("clear", "Clears a users permissions and groups",
"/perms user <user> clear", "luckperms.user.clear");
super("clear", "Clears a users permissions and groups", "/perms user <user> clear", Permission.USER_CLEAR);
}
@Override

View File

@ -1,6 +1,7 @@
package me.lucko.luckperms.commands.user.subcommands;
import me.lucko.luckperms.LuckPermsPlugin;
import me.lucko.luckperms.commands.Permission;
import me.lucko.luckperms.commands.Sender;
import me.lucko.luckperms.commands.Util;
import me.lucko.luckperms.commands.user.UserSubCommand;
@ -10,7 +11,7 @@ import java.util.List;
public class UserGetUUIDCommand extends UserSubCommand {
public UserGetUUIDCommand() {
super("getuuid", "Get the UUID of a user", "/perms user <user> getuuid", "luckperms.user.getuuid");
super("getuuid", "Get the UUID of a user", "/perms user <user> getuuid", Permission.USER_GETUUID);
}
@Override

View File

@ -1,6 +1,7 @@
package me.lucko.luckperms.commands.user.subcommands;
import me.lucko.luckperms.LuckPermsPlugin;
import me.lucko.luckperms.commands.Permission;
import me.lucko.luckperms.commands.Sender;
import me.lucko.luckperms.commands.Util;
import me.lucko.luckperms.commands.user.UserSubCommand;
@ -11,7 +12,7 @@ import java.util.List;
public class UserHasPermCommand extends UserSubCommand {
public UserHasPermCommand() {
super("haspermission", "Checks to see if a user has a certain permission node",
"/perms user <user> haspermission <node> [server]", "luckperms.user.haspermission");
"/perms user <user> haspermission <node> [server]", Permission.USER_HASPERMISSION);
}
@Override
@ -25,6 +26,6 @@ public class UserHasPermCommand extends UserSubCommand {
@Override
public boolean isArgLengthInvalid(int argLength) {
return argLength == 0;
return argLength != 1 && argLength != 2;
}
}

View File

@ -1,6 +1,7 @@
package me.lucko.luckperms.commands.user.subcommands;
import me.lucko.luckperms.LuckPermsPlugin;
import me.lucko.luckperms.commands.Permission;
import me.lucko.luckperms.commands.Sender;
import me.lucko.luckperms.commands.Util;
import me.lucko.luckperms.commands.user.UserSubCommand;
@ -10,22 +11,20 @@ import java.util.List;
public class UserInfoCommand extends UserSubCommand {
public UserInfoCommand() {
super("info", "Gives info about the user",
"/perms user <user> info", "luckperms.user.info");
super("info", "Gives info about the user", "/perms user <user> info", Permission.USER_INFO);
}
@Override
protected void execute(LuckPermsPlugin plugin, Sender sender, User user, List<String> args) {
final String prefix = Util.PREFIX;
String sb = prefix + "&d-> &eUser: &6" + user.getName() + "\n" +
prefix + "&d-> &eUUID: &6" + user.getUuid() + "\n" +
prefix + "&d-> &eStatus: " + plugin.getPlayerStatus(user.getUuid()) + "\n" +
prefix + "&d-> &eGroups: &6" + Util.listToCommaSep(user.getGroupNames()) + "\n" +
prefix + "&d-> &ePrimary Group: &6" + user.getPrimaryGroup() + "\n" +
prefix + "&d-> &ePermissions: &6" + (user.getNodes().keySet().size() - user.getGroupNames().size()) + "\n" +
prefix + "&d-> &bUse &a/perms user " + user.getName() + " listnodes &bto see all permissions.";
sender.sendMessage(Util.color(sb));
sender.sendMessage(Util.color(
Util.PREFIX + "&d-> &eUser: &6" + user.getName() + "\n" +
Util.PREFIX + "&d-> &eUUID: &6" + user.getUuid() + "\n" +
Util.PREFIX + "&d-> &eStatus: " + plugin.getPlayerStatus(user.getUuid()) + "\n" +
Util.PREFIX + "&d-> &eGroups: &6" + Util.listToCommaSep(user.getGroupNames()) + "\n" +
Util.PREFIX + "&d-> &ePrimary Group: &6" + user.getPrimaryGroup() + "\n" +
Util.PREFIX + "&d-> &ePermissions: &6" + (user.getNodes().keySet().size() - user.getGroupNames().size()) + "\n" +
Util.PREFIX + "&d-> &bUse &a/perms user " + user.getName() + " listnodes &bto see all permissions."
));
}
@Override

View File

@ -1,6 +1,7 @@
package me.lucko.luckperms.commands.user.subcommands;
import me.lucko.luckperms.LuckPermsPlugin;
import me.lucko.luckperms.commands.Permission;
import me.lucko.luckperms.commands.Sender;
import me.lucko.luckperms.commands.Util;
import me.lucko.luckperms.commands.user.UserSubCommand;
@ -10,8 +11,7 @@ import java.util.List;
public class UserListNodesCommand extends UserSubCommand {
public UserListNodesCommand() {
super("listnodes", "Lists the permission nodes the user has",
"/perms user <user> listnodes", "luckperms.user.listnodes");
super("listnodes", "Lists the permission nodes the user has", "/perms user <user> listnodes", Permission.USER_LISTNODES);
}
@Override

View File

@ -1,6 +1,7 @@
package me.lucko.luckperms.commands.user.subcommands;
import me.lucko.luckperms.LuckPermsPlugin;
import me.lucko.luckperms.commands.Permission;
import me.lucko.luckperms.commands.Sender;
import me.lucko.luckperms.commands.Util;
import me.lucko.luckperms.commands.user.UserSubCommand;
@ -12,39 +13,47 @@ import java.util.List;
public class UserRemoveGroupCommand extends UserSubCommand {
public UserRemoveGroupCommand() {
super("removegroup", "Removes a user from a group",
"/perms user <user> removegroup <group> [server]", "luckperms.user.removegroup");
super("removegroup", "Removes a user from a group", "/perms user <user> removegroup <group> [server]", Permission.USER_REMOVEGROUP);
}
@Override
protected void execute(LuckPermsPlugin plugin, Sender sender, User user, List<String> args) {
String group = args.get(0).toLowerCase();
String groupName = args.get(0).toLowerCase();
String server;
if (args.size() != 1) {
server = args.get(1);
} else {
server = "global";
}
plugin.getDatastore().loadGroup(groupName, success -> {
if (!success) {
Util.sendPluginMessage(sender, groupName + " does not exist!");
} else {
Group group = plugin.getGroupManager().getGroup(groupName);
if (group == null) {
Util.sendPluginMessage(sender, "That group does not exist!");
return;
}
Group group1 = plugin.getGroupManager().getGroup(group);
if (group1 == null) {
Util.sendPluginMessage(sender, "That group does not exist!");
return;
}
if ((args.size() == 1 || (args.size() == 2 && args.get(1).equalsIgnoreCase("global")))
&& user.getPrimaryGroup().equalsIgnoreCase(group.getName())) {
Util.sendPluginMessage(sender, "You cannot remove a user from their primary group.");
return;
}
if (server.equalsIgnoreCase("global") && user.getPrimaryGroup().equalsIgnoreCase(group1.getName())) {
Util.sendPluginMessage(sender, "You cannot remove a user from their primary group.");
return;
}
try {
if (args.size() == 2) {
final String server = args.get(1).toLowerCase();
user.removeGroup(group, server);
Util.sendPluginMessage(sender, "&b" + user.getName() + "&a was removed from group &b" +
groupName + "&a on server &b" + server + "&a.");
} else {
user.removeGroup(group);
Util.sendPluginMessage(sender, "&b" + user.getName() + "&a was removed from group &b" +
groupName + "&a.");
}
try {
user.removeGroup(group1, server);
Util.sendPluginMessage(sender, "&b" + user.getName() + "&a was removed from group &b" + group + "&a on server &b" + server + "&a.");
} catch (ObjectLacksPermissionException e) {
Util.sendPluginMessage(sender, "The user is not a member of that group.");
}
saveUser(user, sender, plugin);
saveUser(user, sender, plugin);
} catch (ObjectLacksPermissionException e) {
Util.sendPluginMessage(sender, "The user is not a member of that group.");
}
}
});
}
@Override

View File

@ -1,6 +1,7 @@
package me.lucko.luckperms.commands.user.subcommands;
import me.lucko.luckperms.LuckPermsPlugin;
import me.lucko.luckperms.commands.Permission;
import me.lucko.luckperms.commands.Sender;
import me.lucko.luckperms.commands.Util;
import me.lucko.luckperms.commands.user.UserSubCommand;
@ -12,7 +13,7 @@ import java.util.List;
public class UserSetPermissionCommand extends UserSubCommand {
public UserSetPermissionCommand() {
super("set", "Sets a permission for a user",
"/perms user <user> set <node> <true|false> [server]", "luckperms.user.setpermission");
"/perms user <user> set <node> <true|false> [server]", Permission.USER_SETPERMISSION);
}
@Override
@ -41,20 +42,21 @@ public class UserSetPermissionCommand extends UserSubCommand {
if (args.size() == 3) {
final String server = args.get(2).toLowerCase();
user.setPermission(node, b, server);
Util.sendPluginMessage(sender, "&aSet &b" + node + "&a to " + bool + " for &b" + user.getName() + "&a on server &b" + server + "&a.");
Util.sendPluginMessage(sender, "&aSet &b" + node + "&a to " + bool + " for &b" + user.getName() +
"&a on server &b" + server + "&a.");
} else {
user.setPermission(node, b);
Util.sendPluginMessage(sender, "&aSet &b" + node + "&a to " + bool + " for &b" + user.getName() + "&a.");
}
saveUser(user, sender, plugin);
} catch (ObjectAlreadyHasException e) {
Util.sendPluginMessage(sender, "That user already has this permission!");
}
saveUser(user, sender, plugin);
}
@Override
public boolean isArgLengthInvalid(int argLength) {
return argLength < 2;
return argLength != 2 && argLength != 3;
}
}

View File

@ -1,6 +1,7 @@
package me.lucko.luckperms.commands.user.subcommands;
import me.lucko.luckperms.LuckPermsPlugin;
import me.lucko.luckperms.commands.Permission;
import me.lucko.luckperms.commands.Sender;
import me.lucko.luckperms.commands.Util;
import me.lucko.luckperms.commands.user.UserSubCommand;
@ -12,7 +13,7 @@ import java.util.List;
public class UserSetPrimaryGroupCommand extends UserSubCommand {
public UserSetPrimaryGroupCommand() {
super("setprimarygroup", "Sets a users primary group",
"/perms user <user> setprimarygroup <group>", "luckperms.user.setprimarygroup");
"/perms user <user> setprimarygroup <group>", Permission.USER_SETPRIMARYGROUP);
}
@Override
@ -41,6 +42,6 @@ public class UserSetPrimaryGroupCommand extends UserSubCommand {
@Override
public boolean isArgLengthInvalid(int argLength) {
return argLength == 0;
return argLength != 1;
}
}

View File

@ -1,6 +1,7 @@
package me.lucko.luckperms.commands.user.subcommands;
import me.lucko.luckperms.LuckPermsPlugin;
import me.lucko.luckperms.commands.Permission;
import me.lucko.luckperms.commands.Sender;
import me.lucko.luckperms.commands.Util;
import me.lucko.luckperms.commands.user.UserSubCommand;
@ -12,7 +13,7 @@ import java.util.List;
public class UserUnSetPermissionCommand extends UserSubCommand {
public UserUnSetPermissionCommand() {
super("unset", "Unsets a permission for a user",
"/perms user <user> unset <node> [server]", "luckperms.user.unsetpermission");
"/perms user <user> unset <node> [server]", Permission.USER_UNSETPERMISSION);
}
@Override
@ -33,19 +34,21 @@ public class UserUnSetPermissionCommand extends UserSubCommand {
if (args.size() == 2) {
final String server = args.get(1).toLowerCase();
user.unsetPermission(node, server);
Util.sendPluginMessage(sender, "&aUnset &b" + node + "&a for &b" + user.getName() + "&a on server &b" + server + "&a.");
Util.sendPluginMessage(sender, "&aUnset &b" + node + "&a for &b" + user.getName() + "&a on server &b" +
server + "&a.");
} else {
user.unsetPermission(node);
Util.sendPluginMessage(sender, "&aUnset &b" + node + "&a for &b" + user.getName() + "&a.");
}
saveUser(user, sender, plugin);
} catch (ObjectLacksPermissionException e) {
Util.sendPluginMessage(sender, "That user does not have this permission set.");
}
saveUser(user, sender, plugin);
}
@Override
public boolean isArgLengthInvalid(int argLength) {
return argLength == 0;
return argLength != 1 && argLength != 2;
}
}

View File

@ -6,6 +6,7 @@ import me.lucko.luckperms.data.Datastore;
import me.lucko.luckperms.exceptions.ObjectAlreadyHasException;
import java.util.Map;
import java.util.NoSuchElementException;
import java.util.UUID;
import java.util.concurrent.ConcurrentHashMap;
@ -40,17 +41,13 @@ public abstract class UserManager {
* @param name The name to search by
* @return a {@link User} object if the user is loaded, returns null if the user is not loaded
*/
@SuppressWarnings("OptionalGetWithoutIsPresent")
public User getUser(String name) {
User user = null;
for (User u : users.values()) {
if (u.getName().equalsIgnoreCase(name)) {
user = u;
break;
}
try {
return users.values().stream().filter(u -> u.getName().equalsIgnoreCase(name)).limit(1).findAny().get();
} catch (NoSuchElementException e) {
return null;
}
return user;
}
/**

View File

@ -56,10 +56,7 @@ public abstract class PermissionObject {
*/
public boolean hasPermission(String node, Boolean b) {
if (node.startsWith("global/")) node = node.replace("global/", "");
if (b) {
return getNodes().containsKey(node) && getNodes().get(node);
}
return getNodes().containsKey(node) && !getNodes().get(node);
return b ? getNodes().containsKey(node) && getNodes().get(node) : getNodes().containsKey(node) && !getNodes().get(node);
}
/**
@ -108,7 +105,6 @@ public abstract class PermissionObject {
if (!getNodes().containsKey(node)) {
throw new ObjectLacksPermissionException();
}
getNodes().remove(node);
}