From f803082b154bb00e343090adc54a45056f88e9e8 Mon Sep 17 00:00:00 2001 From: Luck Date: Mon, 11 Jul 2016 20:56:01 +0100 Subject: [PATCH] Move all messages to one class --- .../luckperms/commands/CommandManager.java | 3 +- .../lucko/luckperms/commands/MainCommand.java | 3 +- .../lucko/luckperms/commands/SubCommand.java | 1 + .../commands/group/CreateGroupCommand.java | 12 +- .../commands/group/DeleteGroupCommand.java | 16 ++- .../commands/group/GroupMainCommand.java | 10 +- .../commands/group/GroupSubCommand.java | 8 +- .../commands/group/ListGroupsCommand.java | 12 +- .../group/subcommands/GroupClearCommand.java | 6 +- .../subcommands/GroupHasPermCommand.java | 2 +- .../group/subcommands/GroupInfoCommand.java | 10 +- .../subcommands/GroupListNodesCommand.java | 6 +- .../subcommands/GroupSetInheritCommand.java | 14 +- .../GroupSetPermissionCommand.java | 13 +- .../GroupUnSetPermissionCommand.java | 13 +- .../subcommands/GroupUnsetInheritCommand.java | 12 +- .../luckperms/commands/misc/DebugCommand.java | 13 +- .../luckperms/commands/misc/InfoCommand.java | 10 +- .../luckperms/commands/misc/SyncCommand.java | 8 +- .../commands/user/UserMainCommand.java | 15 ++- .../commands/user/UserSubCommand.java | 8 +- .../user/subcommands/UserAddGroupCommand.java | 16 +-- .../user/subcommands/UserClearCommand.java | 6 +- .../user/subcommands/UserGetUUIDCommand.java | 6 +- .../user/subcommands/UserHasPermCommand.java | 2 +- .../user/subcommands/UserInfoCommand.java | 16 +-- .../subcommands/UserListNodesCommand.java | 6 +- .../subcommands/UserRemoveGroupCommand.java | 55 +++----- .../subcommands/UserSetPermissionCommand.java | 13 +- .../UserSetPrimaryGroupCommand.java | 12 +- .../UserUnSetPermissionCommand.java | 13 +- .../lucko/luckperms/constants/Messages.java | 123 ++++++++++++++++++ .../{commands => constants}/Permission.java | 4 +- 33 files changed, 292 insertions(+), 175 deletions(-) create mode 100644 common/src/main/java/me/lucko/luckperms/constants/Messages.java rename common/src/main/java/me/lucko/luckperms/{commands => constants}/Permission.java (94%) diff --git a/common/src/main/java/me/lucko/luckperms/commands/CommandManager.java b/common/src/main/java/me/lucko/luckperms/commands/CommandManager.java index c7853cd7..56cf008c 100644 --- a/common/src/main/java/me/lucko/luckperms/commands/CommandManager.java +++ b/common/src/main/java/me/lucko/luckperms/commands/CommandManager.java @@ -12,6 +12,7 @@ import me.lucko.luckperms.commands.misc.InfoCommand; import me.lucko.luckperms.commands.misc.SyncCommand; import me.lucko.luckperms.commands.user.UserMainCommand; import me.lucko.luckperms.commands.user.subcommands.*; +import me.lucko.luckperms.constants.Messages; import java.util.ArrayList; import java.util.List; @@ -105,7 +106,7 @@ public class CommandManager { } private void sendCommandUsage(Sender sender) { - Util.sendPluginMessage(sender, "&6Running &bLuckPerms " + plugin.getVersion() + "&6."); + Messages.INFO_BRIEF.send(sender, plugin.getVersion()); mainCommands.stream() .filter(c -> c.canUse(sender)) diff --git a/common/src/main/java/me/lucko/luckperms/commands/MainCommand.java b/common/src/main/java/me/lucko/luckperms/commands/MainCommand.java index 480c04ae..89a5af36 100644 --- a/common/src/main/java/me/lucko/luckperms/commands/MainCommand.java +++ b/common/src/main/java/me/lucko/luckperms/commands/MainCommand.java @@ -3,6 +3,7 @@ package me.lucko.luckperms.commands; import lombok.AllArgsConstructor; import lombok.Getter; import me.lucko.luckperms.LuckPermsPlugin; +import me.lucko.luckperms.constants.Messages; import java.util.List; import java.util.stream.Collectors; @@ -33,7 +34,7 @@ public abstract class MainCommand { } } else { - Util.sendPluginMessage(sender, "You do not have permission to use this command!"); + Messages.COMMAND_NO_PERMISSION.send(sender); } } diff --git a/common/src/main/java/me/lucko/luckperms/commands/SubCommand.java b/common/src/main/java/me/lucko/luckperms/commands/SubCommand.java index 62bfe0d5..661327b9 100644 --- a/common/src/main/java/me/lucko/luckperms/commands/SubCommand.java +++ b/common/src/main/java/me/lucko/luckperms/commands/SubCommand.java @@ -2,6 +2,7 @@ package me.lucko.luckperms.commands; import lombok.AllArgsConstructor; import lombok.Getter; +import me.lucko.luckperms.constants.Permission; @Getter @AllArgsConstructor diff --git a/common/src/main/java/me/lucko/luckperms/commands/group/CreateGroupCommand.java b/common/src/main/java/me/lucko/luckperms/commands/group/CreateGroupCommand.java index 2fe8fbaa..f4fe72e9 100644 --- a/common/src/main/java/me/lucko/luckperms/commands/group/CreateGroupCommand.java +++ b/common/src/main/java/me/lucko/luckperms/commands/group/CreateGroupCommand.java @@ -1,7 +1,11 @@ package me.lucko.luckperms.commands.group; import me.lucko.luckperms.LuckPermsPlugin; -import me.lucko.luckperms.commands.*; +import me.lucko.luckperms.commands.MainCommand; +import me.lucko.luckperms.commands.Sender; +import me.lucko.luckperms.commands.SubCommand; +import me.lucko.luckperms.constants.Messages; +import me.lucko.luckperms.constants.Permission; import java.util.ArrayList; import java.util.List; @@ -21,13 +25,13 @@ public class CreateGroupCommand extends MainCommand { String groupName = args.get(0).toLowerCase(); plugin.getDatastore().loadGroup(groupName, success -> { if (success) { - Util.sendPluginMessage(sender, "That group already exists!"); + Messages.GROUP_ALREADY_EXISTS.send(sender); } else { plugin.getDatastore().createAndLoadGroup(groupName, success1 -> { if (!success1) { - Util.sendPluginMessage(sender, "There was an error whilst creating the group."); + Messages.CREATE_GROUP_ERROR.send(sender); } else { - Util.sendPluginMessage(sender, "&b" + groupName + "&a was successfully created."); + Messages.CREATE_GROUP_SUCCESS.send(sender, groupName); plugin.runUpdateTask(); } }); diff --git a/common/src/main/java/me/lucko/luckperms/commands/group/DeleteGroupCommand.java b/common/src/main/java/me/lucko/luckperms/commands/group/DeleteGroupCommand.java index 7d33fab3..5a5ee10c 100644 --- a/common/src/main/java/me/lucko/luckperms/commands/group/DeleteGroupCommand.java +++ b/common/src/main/java/me/lucko/luckperms/commands/group/DeleteGroupCommand.java @@ -1,7 +1,11 @@ package me.lucko.luckperms.commands.group; import me.lucko.luckperms.LuckPermsPlugin; -import me.lucko.luckperms.commands.*; +import me.lucko.luckperms.commands.MainCommand; +import me.lucko.luckperms.commands.Sender; +import me.lucko.luckperms.commands.SubCommand; +import me.lucko.luckperms.constants.Messages; +import me.lucko.luckperms.constants.Permission; import me.lucko.luckperms.groups.Group; import java.util.ArrayList; @@ -22,24 +26,24 @@ public class DeleteGroupCommand extends MainCommand { String groupName = args.get(0).toLowerCase(); if (groupName.equalsIgnoreCase(plugin.getConfiguration().getDefaultGroupName())) { - Util.sendPluginMessage(sender, "You cannot delete the default group."); + Messages.DELETE_GROUP_ERROR_DEFAULT.send(sender); return; } plugin.getDatastore().loadGroup(groupName, success -> { if (!success) { - Util.sendPluginMessage(sender, "That group does not exist!"); + Messages.GROUP_DOES_NOT_EXIST.send(sender); } else { Group group = plugin.getGroupManager().getGroup(groupName); if (group == null) { - Util.sendPluginMessage(sender, "An unexpected error occurred. Group not loaded."); + Messages.GROUP_LOAD_ERROR.send(sender); } else { plugin.getDatastore().deleteGroup(group, success1 -> { if (!success1) { - Util.sendPluginMessage(sender, "There was an error whilst deleting the group."); + Messages.DELETE_GROUP_ERROR.send(sender); } else { - Util.sendPluginMessage(sender, "&b" + groupName + "&a was successfully deleted."); + Messages.DELETE_GROUP_SUCCESS.send(sender, groupName); plugin.runUpdateTask(); } }); diff --git a/common/src/main/java/me/lucko/luckperms/commands/group/GroupMainCommand.java b/common/src/main/java/me/lucko/luckperms/commands/group/GroupMainCommand.java index 3f893d02..6feed818 100644 --- a/common/src/main/java/me/lucko/luckperms/commands/group/GroupMainCommand.java +++ b/common/src/main/java/me/lucko/luckperms/commands/group/GroupMainCommand.java @@ -4,7 +4,7 @@ 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.constants.Messages; import me.lucko.luckperms.groups.Group; import java.util.ArrayList; @@ -29,13 +29,13 @@ public class GroupMainCommand extends MainCommand { Optional o = subCommands.stream().filter(s -> s.getName().equalsIgnoreCase(args.get(1))).limit(1).findAny(); if (!o.isPresent()) { - Util.sendPluginMessage(sender, "Command not recognised."); + Messages.COMMAND_NOT_RECOGNISED.send(sender); return; } final GroupSubCommand sub = o.get(); if (!sub.isAuthorized(sender)) { - Util.sendPluginMessage(sender, "You do not have permission to use this command!"); + Messages.COMMAND_NO_PERMISSION.send(sender); return; } @@ -47,13 +47,13 @@ public class GroupMainCommand extends MainCommand { final String groupName = args.get(0).toLowerCase(); plugin.getDatastore().loadGroup(groupName, success -> { if (!success) { - Util.sendPluginMessage(sender, "&eGroup could not be found."); + Messages.GROUP_NOT_FOUND.send(sender); return; } Group group = plugin.getGroupManager().getGroup(groupName); if (group == null) { - Util.sendPluginMessage(sender, "&eGroup could not be found."); + Messages.GROUP_NOT_FOUND.send(sender); return; } diff --git a/common/src/main/java/me/lucko/luckperms/commands/group/GroupSubCommand.java b/common/src/main/java/me/lucko/luckperms/commands/group/GroupSubCommand.java index 21d736e1..31bcae0e 100644 --- a/common/src/main/java/me/lucko/luckperms/commands/group/GroupSubCommand.java +++ b/common/src/main/java/me/lucko/luckperms/commands/group/GroupSubCommand.java @@ -1,10 +1,10 @@ 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; +import me.lucko.luckperms.constants.Messages; +import me.lucko.luckperms.constants.Permission; import me.lucko.luckperms.groups.Group; import java.util.List; @@ -19,9 +19,9 @@ public abstract class GroupSubCommand extends SubCommand { protected void saveGroup(Group group, Sender sender, LuckPermsPlugin plugin) { plugin.getDatastore().saveGroup(group, success -> { if (success) { - Util.sendPluginMessage(sender, "&7(Group data was saved to the datastore)"); + Messages.GROUP_SAVE_SUCCESS.send(sender); } else { - Util.sendPluginMessage(sender, "There was an error whilst saving the group."); + Messages.GROUP_SAVE_ERROR.send(sender); } plugin.runUpdateTask(); diff --git a/common/src/main/java/me/lucko/luckperms/commands/group/ListGroupsCommand.java b/common/src/main/java/me/lucko/luckperms/commands/group/ListGroupsCommand.java index 0fe0a3ff..bf7b9eac 100644 --- a/common/src/main/java/me/lucko/luckperms/commands/group/ListGroupsCommand.java +++ b/common/src/main/java/me/lucko/luckperms/commands/group/ListGroupsCommand.java @@ -1,7 +1,12 @@ package me.lucko.luckperms.commands.group; import me.lucko.luckperms.LuckPermsPlugin; -import me.lucko.luckperms.commands.*; +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.constants.Messages; +import me.lucko.luckperms.constants.Permission; import java.util.ArrayList; import java.util.List; @@ -15,10 +20,9 @@ public class ListGroupsCommand extends MainCommand { protected void execute(LuckPermsPlugin plugin, Sender sender, List args) { plugin.getDatastore().loadAllGroups(success -> { if (!success) { - Util.sendPluginMessage(sender, "Unable to load all groups."); + Messages.GROUPS_LOAD_ERROR.send(sender); } else { - Util.sendPluginMessage(sender, "&aGroups: " + - Util.listToCommaSep(new ArrayList<>(plugin.getGroupManager().getGroups().keySet()))); + Messages.GROUPS_LIST.send(sender, Util.listToCommaSep(new ArrayList<>(plugin.getGroupManager().getGroups().keySet()))); } }); } diff --git a/common/src/main/java/me/lucko/luckperms/commands/group/subcommands/GroupClearCommand.java b/common/src/main/java/me/lucko/luckperms/commands/group/subcommands/GroupClearCommand.java index d04d0aae..6bd522bd 100644 --- a/common/src/main/java/me/lucko/luckperms/commands/group/subcommands/GroupClearCommand.java +++ b/common/src/main/java/me/lucko/luckperms/commands/group/subcommands/GroupClearCommand.java @@ -1,10 +1,10 @@ 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; +import me.lucko.luckperms.constants.Messages; +import me.lucko.luckperms.constants.Permission; import me.lucko.luckperms.groups.Group; import java.util.List; @@ -17,7 +17,7 @@ public class GroupClearCommand extends GroupSubCommand { @Override protected void execute(LuckPermsPlugin plugin, Sender sender, Group group, List args) { group.clearNodes(); - Util.sendPluginMessage(sender, "&b" + group.getName() + "&a's permissions were cleared."); + Messages.CLEAR_SUCCESS.send(sender, group.getName()); saveGroup(group, sender, plugin); } diff --git a/common/src/main/java/me/lucko/luckperms/commands/group/subcommands/GroupHasPermCommand.java b/common/src/main/java/me/lucko/luckperms/commands/group/subcommands/GroupHasPermCommand.java index 25debbff..7eb1181f 100644 --- a/common/src/main/java/me/lucko/luckperms/commands/group/subcommands/GroupHasPermCommand.java +++ b/common/src/main/java/me/lucko/luckperms/commands/group/subcommands/GroupHasPermCommand.java @@ -1,10 +1,10 @@ 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; +import me.lucko.luckperms.constants.Permission; import me.lucko.luckperms.groups.Group; import java.util.List; diff --git a/common/src/main/java/me/lucko/luckperms/commands/group/subcommands/GroupInfoCommand.java b/common/src/main/java/me/lucko/luckperms/commands/group/subcommands/GroupInfoCommand.java index 11e1b644..d4049c79 100644 --- a/common/src/main/java/me/lucko/luckperms/commands/group/subcommands/GroupInfoCommand.java +++ b/common/src/main/java/me/lucko/luckperms/commands/group/subcommands/GroupInfoCommand.java @@ -1,10 +1,10 @@ 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; +import me.lucko.luckperms.constants.Messages; +import me.lucko.luckperms.constants.Permission; import me.lucko.luckperms.groups.Group; import java.util.List; @@ -16,11 +16,7 @@ public class GroupInfoCommand extends GroupSubCommand { @Override protected void execute(LuckPermsPlugin plugin, Sender sender, Group group, List args) { - 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." - )); + Messages.GROUP_INFO.send(sender, group.getName(), group.getNodes().keySet().size(), group.getName()); } @Override diff --git a/common/src/main/java/me/lucko/luckperms/commands/group/subcommands/GroupListNodesCommand.java b/common/src/main/java/me/lucko/luckperms/commands/group/subcommands/GroupListNodesCommand.java index 177a1128..6b0b1fa8 100644 --- a/common/src/main/java/me/lucko/luckperms/commands/group/subcommands/GroupListNodesCommand.java +++ b/common/src/main/java/me/lucko/luckperms/commands/group/subcommands/GroupListNodesCommand.java @@ -1,10 +1,11 @@ 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; +import me.lucko.luckperms.constants.Messages; +import me.lucko.luckperms.constants.Permission; import me.lucko.luckperms.groups.Group; import java.util.List; @@ -17,8 +18,7 @@ public class GroupListNodesCommand extends GroupSubCommand { @Override protected void execute(LuckPermsPlugin plugin, Sender sender, Group group, List args) { - Util.sendPluginMessage(sender, "&e" + group.getName() + "'s Nodes:"); - sender.sendMessage(Util.color(Util.nodesToString(group.getNodes()))); + Messages.LISTNODES.send(sender, group.getName(), Util.nodesToString(group.getNodes())); } @Override diff --git a/common/src/main/java/me/lucko/luckperms/commands/group/subcommands/GroupSetInheritCommand.java b/common/src/main/java/me/lucko/luckperms/commands/group/subcommands/GroupSetInheritCommand.java index d0499624..145ee308 100644 --- a/common/src/main/java/me/lucko/luckperms/commands/group/subcommands/GroupSetInheritCommand.java +++ b/common/src/main/java/me/lucko/luckperms/commands/group/subcommands/GroupSetInheritCommand.java @@ -1,10 +1,10 @@ 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; +import me.lucko.luckperms.constants.Messages; +import me.lucko.luckperms.constants.Permission; import me.lucko.luckperms.exceptions.ObjectAlreadyHasException; import me.lucko.luckperms.groups.Group; @@ -22,23 +22,21 @@ public class GroupSetInheritCommand extends GroupSubCommand { plugin.getDatastore().loadGroup(groupName, success -> { if (!success) { - Util.sendPluginMessage(sender, groupName + " does not exist!"); + Messages.GROUP_LOAD_ERROR.send(sender); } else { try { if (args.size() == 2) { final String server = args.get(1).toLowerCase(); 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."); + Messages.GROUP_SETINHERIT_SERVER_SUCCESS.send(sender, group.getName(), groupName, server); } else { group.setPermission("group." + groupName, true); - Util.sendPluginMessage(sender, "&b" + group.getName() + "&a now inherits permissions from &b" + - groupName + "&a."); + Messages.GROUP_SETINHERIT_SUCCESS.send(sender, group.getName(), groupName); } saveGroup(group, sender, plugin); } catch (ObjectAlreadyHasException e) { - Util.sendPluginMessage(sender, group.getName() + " already inherits '" + groupName + "'."); + Messages.GROUP_ALREADY_INHERITS.send(sender, group.getName(), groupName); } } }); diff --git a/common/src/main/java/me/lucko/luckperms/commands/group/subcommands/GroupSetPermissionCommand.java b/common/src/main/java/me/lucko/luckperms/commands/group/subcommands/GroupSetPermissionCommand.java index f8284d68..4fabdeda 100644 --- a/common/src/main/java/me/lucko/luckperms/commands/group/subcommands/GroupSetPermissionCommand.java +++ b/common/src/main/java/me/lucko/luckperms/commands/group/subcommands/GroupSetPermissionCommand.java @@ -1,10 +1,10 @@ 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; +import me.lucko.luckperms.constants.Messages; +import me.lucko.luckperms.constants.Permission; import me.lucko.luckperms.exceptions.ObjectAlreadyHasException; import me.lucko.luckperms.groups.Group; @@ -27,7 +27,7 @@ public class GroupSetPermissionCommand extends GroupSubCommand { } if (node.matches("group\\..*")) { - Util.sendPluginMessage(sender, "Use the inherit command instead of specifying the node."); + Messages.GROUP_USE_INHERIT.send(sender); return; } @@ -42,16 +42,15 @@ 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."); + Messages.SETPERMISSION_SERVER_SUCCESS.send(sender, node, bool, group.getName(), server); } else { group.setPermission(node, b); - Util.sendPluginMessage(sender, "&aSet &b" + node + "&a to " + bool + " for &b" + group.getName() + "&a."); + Messages.SETPERMISSION_SUCCESS.send(sender, node, bool, group.getName()); } saveGroup(group, sender, plugin); } catch (ObjectAlreadyHasException e) { - Util.sendPluginMessage(sender, group.getName() + " already has this permission!"); + Messages.ALREADY_HASPERMISSION.send(sender, group.getName()); } } diff --git a/common/src/main/java/me/lucko/luckperms/commands/group/subcommands/GroupUnSetPermissionCommand.java b/common/src/main/java/me/lucko/luckperms/commands/group/subcommands/GroupUnSetPermissionCommand.java index 0f24f71c..081f693f 100644 --- a/common/src/main/java/me/lucko/luckperms/commands/group/subcommands/GroupUnSetPermissionCommand.java +++ b/common/src/main/java/me/lucko/luckperms/commands/group/subcommands/GroupUnSetPermissionCommand.java @@ -1,10 +1,10 @@ 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; +import me.lucko.luckperms.constants.Messages; +import me.lucko.luckperms.constants.Permission; import me.lucko.luckperms.exceptions.ObjectLacksPermissionException; import me.lucko.luckperms.groups.Group; @@ -26,7 +26,7 @@ public class GroupUnSetPermissionCommand extends GroupSubCommand { } if (node.matches("group\\..*")) { - Util.sendPluginMessage(sender, "Use the unsetinherit command instead of specifying the node."); + Messages.GROUP_USE_UNINHERIT.send(sender); return; } @@ -34,16 +34,15 @@ 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."); + Messages.UNSETPERMISSION_SERVER_SUCCESS.send(sender, node, group.getName(), server); } else { group.unsetPermission(node); - Util.sendPluginMessage(sender, "&aUnset &b" + node + "&a for &b" + group.getName() + "&a."); + Messages.UNSETPERMISSION_SUCCESS.send(sender, node, group.getName()); } saveGroup(group, sender, plugin); } catch (ObjectLacksPermissionException e) { - Util.sendPluginMessage(sender, "That group does not have this permission set."); + Messages.DOES_NOT_HAVEPERMISSION.send(sender, group.getName()); } } diff --git a/common/src/main/java/me/lucko/luckperms/commands/group/subcommands/GroupUnsetInheritCommand.java b/common/src/main/java/me/lucko/luckperms/commands/group/subcommands/GroupUnsetInheritCommand.java index 00644e3c..c488c392 100644 --- a/common/src/main/java/me/lucko/luckperms/commands/group/subcommands/GroupUnsetInheritCommand.java +++ b/common/src/main/java/me/lucko/luckperms/commands/group/subcommands/GroupUnsetInheritCommand.java @@ -1,10 +1,10 @@ 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; +import me.lucko.luckperms.constants.Messages; +import me.lucko.luckperms.constants.Permission; import me.lucko.luckperms.exceptions.ObjectLacksPermissionException; import me.lucko.luckperms.groups.Group; @@ -24,17 +24,15 @@ public class GroupUnsetInheritCommand extends GroupSubCommand { 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."); + Messages.GROUP_UNSETINHERIT_SERVER_SUCCESS.send(sender, group.getName(), groupName, server); } else { group.unsetPermission("group." + groupName); - Util.sendPluginMessage(sender, "&b" + group.getName() + "&a no longer inherits permissions from &b" + - groupName + "&a."); + Messages.GROUP_UNSETINHERIT_SUCCESS.send(sender, group.getName(), groupName); } saveGroup(group, sender, plugin); } catch (ObjectLacksPermissionException e) { - Util.sendPluginMessage(sender, "That group does not inherit '" + groupName + "'."); + Messages.GROUP_DOES_NOT_INHERIT.send(sender, group.getName(), groupName); } } diff --git a/common/src/main/java/me/lucko/luckperms/commands/misc/DebugCommand.java b/common/src/main/java/me/lucko/luckperms/commands/misc/DebugCommand.java index c89867df..da3aef9e 100644 --- a/common/src/main/java/me/lucko/luckperms/commands/misc/DebugCommand.java +++ b/common/src/main/java/me/lucko/luckperms/commands/misc/DebugCommand.java @@ -1,7 +1,11 @@ package me.lucko.luckperms.commands.misc; import me.lucko.luckperms.LuckPermsPlugin; -import me.lucko.luckperms.commands.*; +import me.lucko.luckperms.commands.MainCommand; +import me.lucko.luckperms.commands.Sender; +import me.lucko.luckperms.commands.SubCommand; +import me.lucko.luckperms.constants.Messages; +import me.lucko.luckperms.constants.Permission; import java.util.ArrayList; import java.util.List; @@ -13,10 +17,9 @@ public class DebugCommand extends MainCommand { @Override protected void execute(LuckPermsPlugin plugin, Sender sender, List args) { - 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()); - Util.sendPluginMessage(sender, "&eLoaded Groups: &6" + plugin.getGroupManager().getGroups().size()); + Messages.DEBUG.send(sender, plugin.getPlayerCount(), plugin.getUserManager().getUsers().size(), + plugin.getGroupManager().getGroups().size() + ); } @Override diff --git a/common/src/main/java/me/lucko/luckperms/commands/misc/InfoCommand.java b/common/src/main/java/me/lucko/luckperms/commands/misc/InfoCommand.java index b572512e..2fd0e5b9 100644 --- a/common/src/main/java/me/lucko/luckperms/commands/misc/InfoCommand.java +++ b/common/src/main/java/me/lucko/luckperms/commands/misc/InfoCommand.java @@ -1,7 +1,11 @@ package me.lucko.luckperms.commands.misc; import me.lucko.luckperms.LuckPermsPlugin; -import me.lucko.luckperms.commands.*; +import me.lucko.luckperms.commands.MainCommand; +import me.lucko.luckperms.commands.Sender; +import me.lucko.luckperms.commands.SubCommand; +import me.lucko.luckperms.constants.Messages; +import me.lucko.luckperms.constants.Permission; import java.util.ArrayList; import java.util.List; @@ -13,9 +17,7 @@ public class InfoCommand extends MainCommand { @Override protected void execute(LuckPermsPlugin plugin, Sender sender, List args) { - Util.sendPluginMessage(sender, "&6Running &bLuckPerms " + plugin.getVersion() + "&6."); - Util.sendPluginMessage(sender, "&eAuthor: &6Luck"); - Util.sendPluginMessage(sender, "&eStorage Method: &6" + plugin.getDatastore().getName()); + Messages.INFO.send(sender, plugin.getVersion(), plugin.getDatastore().getName()); } @Override diff --git a/common/src/main/java/me/lucko/luckperms/commands/misc/SyncCommand.java b/common/src/main/java/me/lucko/luckperms/commands/misc/SyncCommand.java index 2b0264bd..0a1dea1d 100644 --- a/common/src/main/java/me/lucko/luckperms/commands/misc/SyncCommand.java +++ b/common/src/main/java/me/lucko/luckperms/commands/misc/SyncCommand.java @@ -1,7 +1,11 @@ package me.lucko.luckperms.commands.misc; import me.lucko.luckperms.LuckPermsPlugin; -import me.lucko.luckperms.commands.*; +import me.lucko.luckperms.commands.MainCommand; +import me.lucko.luckperms.commands.Sender; +import me.lucko.luckperms.commands.SubCommand; +import me.lucko.luckperms.constants.Messages; +import me.lucko.luckperms.constants.Permission; import java.util.ArrayList; import java.util.List; @@ -13,7 +17,7 @@ public class SyncCommand extends MainCommand { @Override protected void execute(LuckPermsPlugin plugin, Sender sender, List args) { - Util.sendPluginMessage(sender, "&bRunning update task for all online users."); + Messages.UPDATE_TASK_RUN.send(sender); plugin.runUpdateTask(); } diff --git a/common/src/main/java/me/lucko/luckperms/commands/user/UserMainCommand.java b/common/src/main/java/me/lucko/luckperms/commands/user/UserMainCommand.java index e24dbe68..d8511177 100644 --- a/common/src/main/java/me/lucko/luckperms/commands/user/UserMainCommand.java +++ b/common/src/main/java/me/lucko/luckperms/commands/user/UserMainCommand.java @@ -5,6 +5,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.constants.Messages; import me.lucko.luckperms.users.User; import java.util.ArrayList; @@ -30,13 +31,13 @@ public class UserMainCommand extends MainCommand{ Optional o = subCommands.stream().filter(s -> s.getName().equalsIgnoreCase(args.get(1))).limit(1).findAny(); if (!o.isPresent()) { - Util.sendPluginMessage(sender, "Command not recognised."); + Messages.COMMAND_NOT_RECOGNISED.send(sender); return; } final UserSubCommand sub = o.get(); if (!sub.isAuthorized(sender)) { - Util.sendPluginMessage(sender, "You do not have permission to use this command!"); + Messages.COMMAND_NO_PERMISSION.send(sender); return; } @@ -54,11 +55,11 @@ public class UserMainCommand extends MainCommand{ } if (user.length() <= 16) { - Util.sendPluginMessage(sender, "&7(Attempting UUID lookup, since you specified a user)"); + Messages.USER_ATTEMPTING_LOOKUP.send(sender); plugin.getDatastore().getUUID(user, uuid -> { if (uuid == null) { - Util.sendPluginMessage(sender, "&eUser could not be found."); + Messages.USER_NOT_FOUND.send(sender); return; } runSub(plugin, sender, uuid, sub, strippedArgs); @@ -66,19 +67,19 @@ public class UserMainCommand extends MainCommand{ return; } - Util.sendPluginMessage(sender, "&d" + user + "&c is not a valid username/uuid."); + Messages.USER_INVALID_ENTRY.send(sender, user); } private void runSub(LuckPermsPlugin plugin, Sender sender, UUID uuid, UserSubCommand command, List strippedArgs) { plugin.getDatastore().loadUser(uuid, success -> { if (!success) { - Util.sendPluginMessage(sender, "&eUser could not be found."); + Messages.USER_NOT_FOUND.send(sender); return; } User user = plugin.getUserManager().getUser(uuid); if (user == null) { - Util.sendPluginMessage(sender, "&eUser could not be found."); + Messages.USER_NOT_FOUND.send(sender); } if (command.isArgLengthInvalid(strippedArgs.size())) { diff --git a/common/src/main/java/me/lucko/luckperms/commands/user/UserSubCommand.java b/common/src/main/java/me/lucko/luckperms/commands/user/UserSubCommand.java index f32b71b7..11120462 100644 --- a/common/src/main/java/me/lucko/luckperms/commands/user/UserSubCommand.java +++ b/common/src/main/java/me/lucko/luckperms/commands/user/UserSubCommand.java @@ -1,10 +1,10 @@ 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; +import me.lucko.luckperms.constants.Messages; +import me.lucko.luckperms.constants.Permission; import me.lucko.luckperms.users.User; import java.util.List; @@ -21,9 +21,9 @@ public abstract class UserSubCommand extends SubCommand { plugin.getDatastore().saveUser(user, success -> { if (success) { - Util.sendPluginMessage(sender, "&7(User data was saved to the datastore)"); + Messages.USER_SAVE_SUCCESS.send(sender); } else { - Util.sendPluginMessage(sender, "There was an error whilst saving the user."); + Messages.USER_SAVE_ERROR.send(sender); } }); } diff --git a/common/src/main/java/me/lucko/luckperms/commands/user/subcommands/UserAddGroupCommand.java b/common/src/main/java/me/lucko/luckperms/commands/user/subcommands/UserAddGroupCommand.java index 92168737..a965d26f 100644 --- a/common/src/main/java/me/lucko/luckperms/commands/user/subcommands/UserAddGroupCommand.java +++ b/common/src/main/java/me/lucko/luckperms/commands/user/subcommands/UserAddGroupCommand.java @@ -1,10 +1,10 @@ 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; +import me.lucko.luckperms.constants.Messages; +import me.lucko.luckperms.constants.Permission; import me.lucko.luckperms.exceptions.ObjectAlreadyHasException; import me.lucko.luckperms.groups.Group; import me.lucko.luckperms.users.User; @@ -22,11 +22,11 @@ public class UserAddGroupCommand extends UserSubCommand { plugin.getDatastore().loadGroup(groupName, success -> { if (!success) { - Util.sendPluginMessage(sender, groupName + " does not exist!"); + Messages.GROUP_DOES_NOT_EXIST.send(sender); } else { Group group = plugin.getGroupManager().getGroup(groupName); if (group == null) { - Util.sendPluginMessage(sender, "That group does not exist!"); + Messages.GROUP_DOES_NOT_EXIST.send(sender); return; } @@ -34,17 +34,15 @@ public class UserAddGroupCommand extends UserSubCommand { 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."); + Messages.USER_ADDGROUP_SERVER_SUCCESS.send(sender, user.getName(), groupName, server); } else { user.addGroup(group); - Util.sendPluginMessage(sender, "&b" + user.getName() + "&a successfully added to group &b" + - groupName + "&a."); + Messages.USER_ADDGROUP_SUCCESS.send(sender, user.getName(), groupName); } saveUser(user, sender, plugin); } catch (ObjectAlreadyHasException e) { - Util.sendPluginMessage(sender, "The user is already a member of that group."); + Messages.USER_ALREADY_MEMBER_OF.send(sender, user.getName(), group.getName()); } } }); diff --git a/common/src/main/java/me/lucko/luckperms/commands/user/subcommands/UserClearCommand.java b/common/src/main/java/me/lucko/luckperms/commands/user/subcommands/UserClearCommand.java index 81009a0e..370ab006 100644 --- a/common/src/main/java/me/lucko/luckperms/commands/user/subcommands/UserClearCommand.java +++ b/common/src/main/java/me/lucko/luckperms/commands/user/subcommands/UserClearCommand.java @@ -1,10 +1,10 @@ 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; +import me.lucko.luckperms.constants.Messages; +import me.lucko.luckperms.constants.Permission; import me.lucko.luckperms.users.User; import java.util.List; @@ -18,7 +18,7 @@ public class UserClearCommand extends UserSubCommand { protected void execute(LuckPermsPlugin plugin, Sender sender, User user, List args) { user.clearNodes(); plugin.getUserManager().giveDefaults(user); - Util.sendPluginMessage(sender, "&b" + user.getName() + "&a's permissions were cleared."); + Messages.CLEAR_SUCCESS.send(sender, user.getName()); saveUser(user, sender, plugin); } diff --git a/common/src/main/java/me/lucko/luckperms/commands/user/subcommands/UserGetUUIDCommand.java b/common/src/main/java/me/lucko/luckperms/commands/user/subcommands/UserGetUUIDCommand.java index 681c4a97..93ab1607 100644 --- a/common/src/main/java/me/lucko/luckperms/commands/user/subcommands/UserGetUUIDCommand.java +++ b/common/src/main/java/me/lucko/luckperms/commands/user/subcommands/UserGetUUIDCommand.java @@ -1,10 +1,10 @@ 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; +import me.lucko.luckperms.constants.Messages; +import me.lucko.luckperms.constants.Permission; import me.lucko.luckperms.users.User; import java.util.List; @@ -16,7 +16,7 @@ public class UserGetUUIDCommand extends UserSubCommand { @Override protected void execute(LuckPermsPlugin plugin, Sender sender, User user, List args) { - Util.sendPluginMessage(sender, "&bThe UUID of &e" + user.getName() + "&b is &e" + user.getUuid().toString() + "&b."); + Messages.USER_GETUUID.send(sender, user.getName(), user.getUuid().toString()); } @Override diff --git a/common/src/main/java/me/lucko/luckperms/commands/user/subcommands/UserHasPermCommand.java b/common/src/main/java/me/lucko/luckperms/commands/user/subcommands/UserHasPermCommand.java index 866a202a..567369d3 100644 --- a/common/src/main/java/me/lucko/luckperms/commands/user/subcommands/UserHasPermCommand.java +++ b/common/src/main/java/me/lucko/luckperms/commands/user/subcommands/UserHasPermCommand.java @@ -1,10 +1,10 @@ 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; +import me.lucko.luckperms.constants.Permission; import me.lucko.luckperms.users.User; import java.util.List; diff --git a/common/src/main/java/me/lucko/luckperms/commands/user/subcommands/UserInfoCommand.java b/common/src/main/java/me/lucko/luckperms/commands/user/subcommands/UserInfoCommand.java index e2ae7001..ae765253 100644 --- a/common/src/main/java/me/lucko/luckperms/commands/user/subcommands/UserInfoCommand.java +++ b/common/src/main/java/me/lucko/luckperms/commands/user/subcommands/UserInfoCommand.java @@ -1,10 +1,11 @@ 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; +import me.lucko.luckperms.constants.Messages; +import me.lucko.luckperms.constants.Permission; import me.lucko.luckperms.users.User; import java.util.List; @@ -16,15 +17,10 @@ public class UserInfoCommand extends UserSubCommand { @Override protected void execute(LuckPermsPlugin plugin, Sender sender, User user, List args) { - 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." - )); + Messages.USER_INFO.send(sender, user.getName(), user.getUuid(), plugin.getPlayerStatus(user.getUuid()), + Util.listToCommaSep(user.getGroupNames()), user.getPrimaryGroup(), + (user.getNodes().keySet().size() - user.getGroupNames().size()), user.getName() + ); } @Override diff --git a/common/src/main/java/me/lucko/luckperms/commands/user/subcommands/UserListNodesCommand.java b/common/src/main/java/me/lucko/luckperms/commands/user/subcommands/UserListNodesCommand.java index 8ca5cfdc..1df96093 100644 --- a/common/src/main/java/me/lucko/luckperms/commands/user/subcommands/UserListNodesCommand.java +++ b/common/src/main/java/me/lucko/luckperms/commands/user/subcommands/UserListNodesCommand.java @@ -1,10 +1,11 @@ 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; +import me.lucko.luckperms.constants.Messages; +import me.lucko.luckperms.constants.Permission; import me.lucko.luckperms.users.User; import java.util.List; @@ -16,8 +17,7 @@ public class UserListNodesCommand extends UserSubCommand { @Override protected void execute(LuckPermsPlugin plugin, Sender sender, User user, List args) { - Util.sendPluginMessage(sender, "&e" + user.getName() + "'s Nodes:"); - sender.sendMessage(Util.color(Util.nodesToString(user.getNodes()))); + Messages.LISTNODES.send(sender, user.getName(), Util.nodesToString(user.getNodes())); } @Override diff --git a/common/src/main/java/me/lucko/luckperms/commands/user/subcommands/UserRemoveGroupCommand.java b/common/src/main/java/me/lucko/luckperms/commands/user/subcommands/UserRemoveGroupCommand.java index fcfb8d19..8a79fddb 100644 --- a/common/src/main/java/me/lucko/luckperms/commands/user/subcommands/UserRemoveGroupCommand.java +++ b/common/src/main/java/me/lucko/luckperms/commands/user/subcommands/UserRemoveGroupCommand.java @@ -1,12 +1,11 @@ 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; +import me.lucko.luckperms.constants.Messages; +import me.lucko.luckperms.constants.Permission; import me.lucko.luckperms.exceptions.ObjectLacksPermissionException; -import me.lucko.luckperms.groups.Group; import me.lucko.luckperms.users.User; import java.util.List; @@ -20,40 +19,26 @@ public class UserRemoveGroupCommand extends UserSubCommand { protected void execute(LuckPermsPlugin plugin, Sender sender, User user, List args) { String groupName = args.get(0).toLowerCase(); - plugin.getDatastore().loadGroup(groupName, success -> { - if (!success) { - Util.sendPluginMessage(sender, groupName + " does not exist!"); + if ((args.size() == 1 || (args.size() == 2 && args.get(1).equalsIgnoreCase("global"))) + && user.getPrimaryGroup().equalsIgnoreCase(groupName)) { + Messages.USER_REMOVEGROUP_ERROR_PRIMARY.send(sender); + return; + } + + try { + if (args.size() == 2) { + final String server = args.get(1).toLowerCase(); + user.unsetPermission("group." + groupName, server); + Messages.USER_REMOVEGROUP_SERVER_SUCCESS.send(sender, user.getName(), groupName, server); } else { - Group group = plugin.getGroupManager().getGroup(groupName); - if (group == 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; - } - - 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."); - } - - saveUser(user, sender, plugin); - } catch (ObjectLacksPermissionException e) { - Util.sendPluginMessage(sender, "The user is not a member of that group."); - } + user.unsetPermission("group." + groupName); + Messages.USER_REMOVEGROUP_SUCCESS.send(sender, user.getName(), groupName); } - }); + + saveUser(user, sender, plugin); + } catch (ObjectLacksPermissionException e) { + Messages.USER_NOT_MEMBER_OF.send(sender, user.getName(), groupName); + } } @Override diff --git a/common/src/main/java/me/lucko/luckperms/commands/user/subcommands/UserSetPermissionCommand.java b/common/src/main/java/me/lucko/luckperms/commands/user/subcommands/UserSetPermissionCommand.java index 4c31140c..414846e8 100644 --- a/common/src/main/java/me/lucko/luckperms/commands/user/subcommands/UserSetPermissionCommand.java +++ b/common/src/main/java/me/lucko/luckperms/commands/user/subcommands/UserSetPermissionCommand.java @@ -1,10 +1,10 @@ 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; +import me.lucko.luckperms.constants.Messages; +import me.lucko.luckperms.constants.Permission; import me.lucko.luckperms.exceptions.ObjectAlreadyHasException; import me.lucko.luckperms.users.User; @@ -27,7 +27,7 @@ public class UserSetPermissionCommand extends UserSubCommand { } if (node.matches("group\\..*")) { - Util.sendPluginMessage(sender, "Use the addgroup command instead of specifying the node."); + Messages.USER_USE_ADDGROUP.send(sender); return; } @@ -42,16 +42,15 @@ 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."); + Messages.SETPERMISSION_SERVER_SUCCESS.send(sender, node, bool, user.getName(), server); } else { user.setPermission(node, b); - Util.sendPluginMessage(sender, "&aSet &b" + node + "&a to " + bool + " for &b" + user.getName() + "&a."); + Messages.SETPERMISSION_SUCCESS.send(sender, node, bool, user.getName()); } saveUser(user, sender, plugin); } catch (ObjectAlreadyHasException e) { - Util.sendPluginMessage(sender, "That user already has this permission!"); + Messages.ALREADY_HASPERMISSION.send(sender, user.getName()); } } diff --git a/common/src/main/java/me/lucko/luckperms/commands/user/subcommands/UserSetPrimaryGroupCommand.java b/common/src/main/java/me/lucko/luckperms/commands/user/subcommands/UserSetPrimaryGroupCommand.java index cb8e3a76..e8679823 100644 --- a/common/src/main/java/me/lucko/luckperms/commands/user/subcommands/UserSetPrimaryGroupCommand.java +++ b/common/src/main/java/me/lucko/luckperms/commands/user/subcommands/UserSetPrimaryGroupCommand.java @@ -1,10 +1,10 @@ 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; +import me.lucko.luckperms.constants.Messages; +import me.lucko.luckperms.constants.Permission; import me.lucko.luckperms.groups.Group; import me.lucko.luckperms.users.User; @@ -20,22 +20,22 @@ public class UserSetPrimaryGroupCommand extends UserSubCommand { protected void execute(LuckPermsPlugin plugin, Sender sender, User user, List args) { Group group = plugin.getGroupManager().getGroup(args.get(0).toLowerCase()); if (group == null) { - Util.sendPluginMessage(sender, "That group does not exist!"); + Messages.GROUP_DOES_NOT_EXIST.send(sender); return; } if (user.getPrimaryGroup().equalsIgnoreCase(group.getName())) { - Util.sendPluginMessage(sender, "The user already has this group set as their primary group."); + Messages.USER_PRIMARYGROUP_ERROR_ALREADYHAS.send(sender); return; } if (!user.isInGroup(group)) { - Util.sendPluginMessage(sender, "The user must be a member of the group first! Use &4/perms user addgroup "); + Messages.USER_PRIMARYGROUP_ERROR_NOTMEMBER.send(sender); return; } user.setPrimaryGroup(group.getName()); - Util.sendPluginMessage(sender, "&b" + user.getName() + "&a's primary group was set to &b" + group.getName() + "&a."); + Messages.USER_PRIMARYGROUP_SUCCESS.send(sender, user.getName(), group.getName()); saveUser(user, sender, plugin); } diff --git a/common/src/main/java/me/lucko/luckperms/commands/user/subcommands/UserUnSetPermissionCommand.java b/common/src/main/java/me/lucko/luckperms/commands/user/subcommands/UserUnSetPermissionCommand.java index bc882044..ae53c095 100644 --- a/common/src/main/java/me/lucko/luckperms/commands/user/subcommands/UserUnSetPermissionCommand.java +++ b/common/src/main/java/me/lucko/luckperms/commands/user/subcommands/UserUnSetPermissionCommand.java @@ -1,10 +1,10 @@ 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; +import me.lucko.luckperms.constants.Messages; +import me.lucko.luckperms.constants.Permission; import me.lucko.luckperms.exceptions.ObjectLacksPermissionException; import me.lucko.luckperms.users.User; @@ -26,7 +26,7 @@ public class UserUnSetPermissionCommand extends UserSubCommand { } if (node.matches("group\\..*")) { - Util.sendPluginMessage(sender, "Use the removegroup command instead of specifying the node."); + Messages.USER_USE_REMOVEGROUP.send(sender); return; } @@ -34,16 +34,15 @@ 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."); + Messages.UNSETPERMISSION_SERVER_SUCCESS.send(sender, node, user.getName(), server); } else { user.unsetPermission(node); - Util.sendPluginMessage(sender, "&aUnset &b" + node + "&a for &b" + user.getName() + "&a."); + Messages.UNSETPERMISSION_SUCCESS.send(sender, node, user.getName()); } saveUser(user, sender, plugin); } catch (ObjectLacksPermissionException e) { - Util.sendPluginMessage(sender, "That user does not have this permission set."); + Messages.DOES_NOT_HAVEPERMISSION.send(sender, user.getName()); } } diff --git a/common/src/main/java/me/lucko/luckperms/constants/Messages.java b/common/src/main/java/me/lucko/luckperms/constants/Messages.java new file mode 100644 index 00000000..dc6c0b38 --- /dev/null +++ b/common/src/main/java/me/lucko/luckperms/constants/Messages.java @@ -0,0 +1,123 @@ +package me.lucko.luckperms.constants; + +import lombok.AllArgsConstructor; +import me.lucko.luckperms.commands.Sender; +import me.lucko.luckperms.commands.Util; + +@SuppressWarnings("SpellCheckingInspection") +@AllArgsConstructor +public enum Messages { + + PREFIX("&7&l[&b&lL&a&lP&7&l] &c", false), + + COMMAND_NOT_RECOGNISED("Command not recognised.", true), + COMMAND_NO_PERMISSION("You do not have permission to use this command!", true), + INFO_BRIEF("&6Running &bLuckPerms %s&6.", true), + + + ALREADY_HASPERMISSION("%s already has this permission!", true), + DOES_NOT_HAVEPERMISSION("%s does not have this permission set.", true), + + USER_NOT_FOUND("&eUser could not be found.", true), + USER_SAVE_SUCCESS("&7(User data was saved to the datastore)", true), + USER_SAVE_ERROR("There was an error whilst saving the user.", true), + USER_ALREADY_MEMBER_OF("%s is already a member of '%s'.", true), + USER_NOT_MEMBER_OF("%s is not a member of '%s'.", true), + USER_USE_ADDGROUP("Use the addgroup command instead of specifying the node.", true), + USER_USE_REMOVEGROUP("Use the removegroup command instead of specifying the node.", true), + + GROUP_NOT_FOUND("&eGroup could not be found.", true), + GROUP_SAVE_SUCCESS("&7(Group data was saved to the datastore)", true), + GROUP_SAVE_ERROR("There was an error whilst saving the group.", true), + GROUP_ALREADY_INHERITS("%s already inherits '%s'.", true), + GROUP_DOES_NOT_INHERIT("%s does not inherit '%s'.", true), + GROUP_USE_INHERIT("Use the setinherit command instead of specifying the node.", true), + GROUP_USE_UNINHERIT("Use the unsetinherit command instead of specifying the node.", true), + + + USER_ATTEMPTING_LOOKUP("&7(Attempting UUID lookup, since you specified a user)", true), + USER_INVALID_ENTRY("&d%s&c is not a valid username/uuid.", true), + + GROUP_ALREADY_EXISTS("That group already exists!", true), + GROUP_DOES_NOT_EXIST("That group does not exist!", true), + + GROUP_LOAD_ERROR("An unexpected error occurred. Group not loaded.", true), + GROUPS_LOAD_ERROR("An unexpected error occurred. Unable to load all groups.", true), + + + UPDATE_TASK_RUN("&bRunning update task for all online users.", true), + INFO( + PREFIX + "&6Running &bLuckPerms %s&6." + "\n" + + PREFIX + "&eAuthor: &6Luck" + "\n" + + PREFIX + "&eStorage Method: &6%s", + false + ), + DEBUG( + PREFIX + "&d&l> &dDebug Info" + "\n" + + PREFIX + "&eOnline Players: &6%s" + "\n" + + PREFIX + "&eLoaded Users: &6%s" + "\n" + + PREFIX + "&eLoaded Groups: &6%s", + false + ), + + CREATE_GROUP_ERROR("There was an error whilst creating the group.", true), + CREATE_GROUP_SUCCESS("&b%s&a was successfully created.", true), + DELETE_GROUP_ERROR("There was an error whilst deleting the group.", true), + DELETE_GROUP_ERROR_DEFAULT("You cannot delete the default group.", true), + DELETE_GROUP_SUCCESS("&b%s&a was successfully deleted.", true), + GROUPS_LIST("&aGroups: %s", true), + + LISTNODES("&e%s's Nodes:" + "\n" + "%s", true), + SETPERMISSION_SUCCESS("&aSet &b%s&a to &b%s&a for &b%s&a.", true), + SETPERMISSION_SERVER_SUCCESS("&aSet &b%s&a to &b%s&a for &b%s&a on server &b%s&a.", true), + UNSETPERMISSION_SUCCESS("&aUnset &b%s&a for &b%s&a.", true), + UNSETPERMISSION_SERVER_SUCCESS("&aUnset &b%s&a for &b%s&a on server &b%$s&a.", true), + CLEAR_SUCCESS("&b%s&a's permissions were cleared.", true), + + USER_INFO( + PREFIX + "&d-> &eUser: &6%s" + "\n" + + PREFIX + "&d-> &eUUID: &6%s" + "\n" + + PREFIX + "&d-> &eStatus: %s" + "\n" + + PREFIX + "&d-> &eGroups: &6%s" + "\n" + + PREFIX + "&d-> &ePrimary Group: &6%s" + "\n" + + PREFIX + "&d-> &ePermissions: &6%s" + "\n" + + PREFIX + "&d-> &bUse &a/perms user %s listnodes &bto see all permissions.", + false + ), + USER_GETUUID("&bThe UUID of &e%s&b is &e%s&b.", true), + USER_ADDGROUP_SUCCESS("&b%s&a successfully added to group &b%s&a.", true), + USER_ADDGROUP_SERVER_SUCCESS("&b%s&a successfully added to group &b%s&a on server &b%s&a.", true), + USER_REMOVEGROUP_SUCCESS("&b%s&a was removed from group &b%s&a.", true), + USER_REMOVEGROUP_SERVER_SUCCESS("&b%s&a was removed from group &b%s&a on server &b%s&a.", true), + USER_REMOVEGROUP_ERROR_PRIMARY("You cannot remove a user from their primary group.", true), + USER_PRIMARYGROUP_SUCCESS("&b%s&a's primary group was set to &b%s&a.", true), + USER_PRIMARYGROUP_ERROR_ALREADYHAS("The user already has this group set as their primary group.", true), + USER_PRIMARYGROUP_ERROR_NOTMEMBER("The user must be a member of the group first! Use &4/perms user addgroup ", true), + + GROUP_INFO( + PREFIX + "&d-> &eGroup: &6%s" + "\n" + + PREFIX + "&d-> &ePermissions: &6%s" + "\n" + + PREFIX + "&d-> &bUse &a/perms group %s listnodes &bto see all permissions.", + false + ), + GROUP_SETINHERIT_SUCCESS("&b%s&a now inherits permissions from &b%s&a.", true), + GROUP_SETINHERIT_SERVER_SUCCESS("&b%s&a now inherits permissions from &b%s&a on server &b%s&a.", true), + GROUP_UNSETINHERIT_SUCCESS("&b%s&a no longer inherits permissions from &b%s&a.", true), + GROUP_UNSETINHERIT_SERVER_SUCCESS("&b%s&a no longer inherits permissions from &b%s&a on server &b%s&a.", true); + + private String message; + private boolean showPrefix; + + @Override + public String toString() { + return message; + } + + public void send(Sender sender, Object... objects) { + if (showPrefix) { + sender.sendMessage(Util.color(PREFIX + String.format(message, objects))); + } else { + sender.sendMessage(Util.color(String.format(message, objects))); + } + } +} diff --git a/common/src/main/java/me/lucko/luckperms/commands/Permission.java b/common/src/main/java/me/lucko/luckperms/constants/Permission.java similarity index 94% rename from common/src/main/java/me/lucko/luckperms/commands/Permission.java rename to common/src/main/java/me/lucko/luckperms/constants/Permission.java index b72e3830..258cb94d 100644 --- a/common/src/main/java/me/lucko/luckperms/commands/Permission.java +++ b/common/src/main/java/me/lucko/luckperms/constants/Permission.java @@ -1,8 +1,10 @@ -package me.lucko.luckperms.commands; +package me.lucko.luckperms.constants; import lombok.AllArgsConstructor; import lombok.Getter; +import me.lucko.luckperms.commands.Sender; +@SuppressWarnings("SpellCheckingInspection") @AllArgsConstructor public enum Permission {