Per-world permissions

This commit is contained in:
Luck 2016-07-25 18:19:36 +01:00
parent 9ad40be210
commit ebeb69dd3a
38 changed files with 950 additions and 296 deletions

View File

@ -1,5 +1,5 @@
# LuckPerms # LuckPerms
A (fairly bad) permissions implementation for Bukkit/BungeeCord. A permissions implementation for Bukkit/BungeeCord.
## Features ## Features
* **Group inheritance** - users can be members of multiple groups, groups can inherit other groups * **Group inheritance** - users can be members of multiple groups, groups can inherit other groups
@ -8,19 +8,20 @@ A (fairly bad) permissions implementation for Bukkit/BungeeCord.
* **Multi-server support** - data is synced across all servers/platforms * **Multi-server support** - data is synced across all servers/platforms
* **Full offline-mode/mixed-mode support** - player permissions are synced properly over offline-mode or mixed online/offline-mode networks. * **Full offline-mode/mixed-mode support** - player permissions are synced properly over offline-mode or mixed online/offline-mode networks.
* **Per-server permissions/groups** - define user/group permissions that only apply on certain servers * **Per-server permissions/groups** - define user/group permissions that only apply on certain servers
* **Server-specific groups** - define groups that only apply on certain servers * **Per-world permissions/groups** - define user/group permissions that only apply on certain worlds (on BungeeCord, a connected Bukkit/Spigot instance is treated as a world)
* **Tracks / paths** - users can be promoted/demoted along multiple group tracks * **Tracks / paths / ladders** - users can be promoted/demoted along multiple group tracks
* **Vault Support** - hooks into Vault to integrate with other plugins * **Vault Support** - hooks into Vault to integrate with other plugins
* **Developer API** - easily integrate LuckPerms into your own projects * **Developer API** - easily integrate LuckPerms into your own projects
* **Easy and simple setup and configuration using commands** - no editing yml files, yuck * **Easy and simple setup and configuration using commands** - no editing yml files, yuck
* **Negated permissions and groups** - define special rules for certain users/groups
* **Full support for UUIDs, even in Offline Mode** - users can change their usernames without losing permissions. In offline mode, a single user has the same internal UUID across a network.
* **Permission data stored within MySQL in a json format** - easily integrate the LuckPerms backend into your other projects
* **Well documented** - API methods have comprehensive Java docs, it's clear what each method does.
* **Efficient/lightweight** - maybe? Who knows, it might be. * **Efficient/lightweight** - maybe? Who knows, it might be.
* **Open Sourced, Free...** - you shouldn't have to pay $10+ for a "powerful" permissions plugin.
* **BungeeCord compatible** - permissions, users and groups are synced across Bukkit/BungeeCord instances * **BungeeCord compatible** - permissions, users and groups are synced across Bukkit/BungeeCord instances
* **Support for MySQL, SQLite & Flatfile (JSON)** - other storage methods coming soon (maybe) * **Support for MySQL, SQLite & Flatfile (JSON)** - other storage methods coming soon (maybe)
##### Possible Caveats
* Currently only supports MySQL, SQLite & Flatfile (JSON) (support for more methods might come in the future)
* Not at all tested and could produce unexpected/buggy results and errors
## Setup ## Setup
All configuration options are in the **config.yml** file, which is generated automagically when the plugin first starts. All configuration options are in the **config.yml** file, which is generated automagically when the plugin first starts.
@ -34,13 +35,17 @@ Permissions are calculated based on a priority system as follows.
Example: if a user has a false permission set for "test.node", and a temporary true permission set for "test.node", the temporary permission will override the permanent one, and the user will be granted the true node. Example: if a user has a false permission set for "test.node", and a temporary true permission set for "test.node", the temporary permission will override the permanent one, and the user will be granted the true node.
* World specific permissions will override generic permissions.
Example: if a user has a global "fly.use" permission, and then has a negated "fly.use" permission in the "world_nether" world, the world specific permission will override the globally defined one, and the user will be granted the negated node (provided they're in that world, of course.).
* Server specific permissions will override generic/global permissions. * Server specific permissions will override generic/global permissions.
Example: if a user has a global "fly.use" permission, and then has a negated "fly.use" permission on the "factions" server, the server specific permission will override the globally defined one, and the user will be granted the negated node. Example: if a user has a global "fly.use" permission, and then has a negated "fly.use" permission on the "factions" server, the server specific permission will override the globally defined one, and the user will be granted the negated node.
* Inherited permissions will be overridden by an objects own permissions. * Inherited permissions will be overridden by an objects own permissions.
Example: A user is a member of the default group, which grants "some.thing.perm", but the users own permissions has "some.thing.perm" set to false. The inherited permission will be overridden by the users own permissions, and the user will be granted the negative node. Example: A user is a member of the default group, which grants "some.thing.perm", but the users own permissions has "some.thing.perm" set to false. The inherited permission will be overridden by the users own permissions, and the user will be granted the negative node (provided they're on that server).
### Temporary Permissions ### Temporary Permissions
Temporary permissions are checked each time a user/group is loaded, and when the sync task runs. This means if you set a temporary permission to expire after 30 seconds, it won't actually be removed until the sync task runs. Temporary permissions are checked each time a user/group is loaded, and when the sync task runs. This means if you set a temporary permission to expire after 30 seconds, it won't actually be removed until the sync task runs.
@ -101,15 +106,16 @@ Additionally, you can use wildcards to grant users access to a selection of comm
* /perms user \<user\> info - luckperms.user.info * /perms user \<user\> info - luckperms.user.info
* /perms user \<user\> getuuid - luckperms.user.getuuid * /perms user \<user\> getuuid - luckperms.user.getuuid
* /perms user \<user\> listnodes - luckperms.user.listnodes * /perms user \<user\> listnodes - luckperms.user.listnodes
* /perms user \<user\> haspermission \<node\> [server] - luckperms.user.haspermission * /perms user \<user\> haspermission \<node\> [server] [world] - luckperms.user.haspermission
* /perms user \<user\> inheritspermission \<node\> [server] - luckperms.user.inheritspermission * /perms user \<user\> inheritspermission \<node\> [server] [world] - luckperms.user.inheritspermission
* /perms user \<user\> set \<node\> \<true/false\> [server] - luckperms.user.setpermission * /perms user \<user\> set \<node\> \<true/false\> [server] [world] - luckperms.user.setpermission
* /perms user \<user\> unset \<node\> [server] - luckperms.user.unsetpermission * /perms user \<user\> unset \<node\> [server] [world] - luckperms.user.unsetpermission
* /perms user \<user\> addgroup \<group\> [server] - luckperms.user.addgroup * /perms user \<user\> addgroup \<group\> [server] [world] - luckperms.user.addgroup
* /perms user \<user\> removegroup \<group\> [server] - luckperms.user.removegroup * /perms user \<user\> removegroup \<group\> [server] [world] - luckperms.user.removegroup
* /perms user \<user\> settemp \<node\> \<true/false\> \<duration\> [server] - luckperms.user.settemppermission * /perms user \<user\> settemp \<node\> \<true/false\> \<duration\> [server] [world] - luckperms.user.settemppermission
* /perms user \<user\> addtempgroup \<group\> \<duration\> [server] - luckperms.user.addtempgroup * /perms user \<user\> unsettemp \<node\> [server] [world] - luckperms.user.unsettemppermission
* /perms user \<user\> removetempgroup \<group\> [server] - luckperms.user.removetempgroup * /perms user \<user\> addtempgroup \<group\> \<duration\> [server] [world] - luckperms.user.addtempgroup
* /perms user \<user\> removetempgroup \<group\> [server] [world] - luckperms.user.removetempgroup
* /perms user \<user\> setprimarygroup \<group\> - luckperms.user.setprimarygroup * /perms user \<user\> setprimarygroup \<group\> - luckperms.user.setprimarygroup
* /perms user \<user\> showtracks - luckperms.user.showtracks * /perms user \<user\> showtracks - luckperms.user.showtracks
* /perms user \<user\> promote \<track\> - luckperms.user.promote * /perms user \<user\> promote \<track\> - luckperms.user.promote
@ -120,16 +126,16 @@ Additionally, you can use wildcards to grant users access to a selection of comm
### Group ### Group
* /perms group \<group\> info - luckperms.group.info * /perms group \<group\> info - luckperms.group.info
* /perms group \<group\> listnodes - luckperms.group.listnodes * /perms group \<group\> listnodes - luckperms.group.listnodes
* /perms group \<group\> haspermission \<node\> [server] - luckperms.group.haspermission * /perms group \<group\> haspermission \<node\> [server] [world] - luckperms.group.haspermission
* /perms group \<group\> inheritspermission \<node\> [server] - luckperms.group.inheritspermission * /perms group \<group\> inheritspermission \<node\> [server] [world] - luckperms.group.inheritspermission
* /perms group \<group\> set \<node\> \<true/false\> [server] - luckperms.group.setpermission * /perms group \<group\> set \<node\> \<true/false\> [server] [world] - luckperms.group.setpermission
* /perms group \<group\> unset \<node\> [server] - luckperms.group.unsetpermission * /perms group \<group\> unset \<node\> [server] [world] - luckperms.group.unsetpermission
* /perms group \<group\> setinherit \<group\> [server] - luckperms.group.setinherit * /perms group \<group\> setinherit \<group\> [server] [world] - luckperms.group.setinherit
* /perms group \<group\> unsetinherit \<group\> [server] - luckperms.group.unsetinherit * /perms group \<group\> unsetinherit \<group\> [server] [world] - luckperms.group.unsetinherit
* /perms group \<group\> settemp \<node\> \<true/false\> \<duration\> [server] - settemppermission * /perms group \<group\> settemp \<node\> \<true/false\> \<duration\> [server] [world] - settemppermission
* /perms group \<group\> unsettemp \<node\> [server] - luckperms.group.unsettemppermission * /perms group \<group\> unsettemp \<node\> [server] [world] - luckperms.group.unsettemppermission
* /perms group \<group\> settempinherit \<group\> \<duration\> [server] - luckperms.group.settempinherit * /perms group \<group\> settempinherit \<group\> \<duration\> [server] [world] - luckperms.group.settempinherit
* /perms group \<group\> unsettempinherit \<group\> [server] - luckperms.group.unsettempinherit * /perms group \<group\> unsettempinherit \<group\> [server] [world] - luckperms.group.unsettempinherit
* /perms group \<group\> showtracks - luckperms.group.showtracks * /perms group \<group\> showtracks - luckperms.group.showtracks
* /perms group \<group\> clear - luckperms.group.clear * /perms group \<group\> clear - luckperms.group.clear

View File

@ -35,6 +35,16 @@ public interface PermissionObject {
*/ */
boolean hasPermission(String node, boolean b, String server); boolean hasPermission(String node, boolean b, String server);
/**
* Checks to see the the object has a permission on a certain server
* @param node The permission node
* @param b If the node is true/false(negated)
* @param server The server
* @param world The world
* @return true if the user has the permission
*/
boolean hasPermission(String node, boolean b, String server, String world);
/** /**
* Checks to see the the object has a permission on a certain server * Checks to see the the object has a permission on a certain server
* @param node The permission node * @param node The permission node
@ -44,6 +54,27 @@ public interface PermissionObject {
*/ */
boolean hasPermission(String node, boolean b, boolean temporary); boolean hasPermission(String node, boolean b, boolean temporary);
/**
* Checks to see the the object has a permission on a certain server
* @param node The permission node
* @param b If the node is true/false(negated)
* @param server The server to check on
* @param temporary if the permission is temporary
* @return true if the user has the permission
*/
boolean hasPermission(String node, boolean b, String server, boolean temporary);
/**
* Checks to see the the object has a permission on a certain server
* @param node The permission node
* @param b If the node is true/false(negated)
* @param server The server to check on
* @param world The world to check on
* @param temporary if the permission is temporary
* @return true if the user has the permission
*/
boolean hasPermission(String node, boolean b, String server, String world, boolean temporary);
/** /**
* Checks to see if the object inherits a certain permission * Checks to see if the object inherits a certain permission
* @param node The permission node * @param node The permission node
@ -61,6 +92,16 @@ public interface PermissionObject {
*/ */
boolean inheritsPermission(String node, boolean b, String server); boolean inheritsPermission(String node, boolean b, String server);
/**
* Checks to see the the object inherits a permission on a certain server
* @param node The permission node
* @param b If the node is true/false(negated)
* @param server The server
* @param world The world
* @return true if the user inherits the permission
*/
boolean inheritsPermission(String node, boolean b, String server, String world);
/** /**
* Checks to see if the object inherits a certain permission * Checks to see if the object inherits a certain permission
* @param node The permission node * @param node The permission node
@ -70,6 +111,27 @@ public interface PermissionObject {
*/ */
boolean inheritsPermission(String node, boolean b, boolean temporary); boolean inheritsPermission(String node, boolean b, boolean temporary);
/**
* Checks to see if the object inherits a certain permission
* @param node The permission node
* @param b If the node is true/false(negated)
* @param server The server
* @param temporary if the permission is temporary
* @return true if the user inherits the permission
*/
boolean inheritsPermission(String node, boolean b, String server, boolean temporary);
/**
* Checks to see if the object inherits a certain permission
* @param node The permission node
* @param b If the node is true/false(negated)
* @param server The server
* @param world The world
* @param temporary if the permission is temporary
* @return true if the user inherits the permission
*/
boolean inheritsPermission(String node, boolean b, String server, String world, boolean temporary);
/** /**
* Sets a permission for the object * Sets a permission for the object
* @param node The node to be set * @param node The node to be set
@ -87,6 +149,16 @@ public interface PermissionObject {
*/ */
void setPermission(String node, boolean value, String server) throws ObjectAlreadyHasException; void setPermission(String node, boolean value, String server) throws ObjectAlreadyHasException;
/**
* Sets a permission for the object
* @param node The node to set
* @param value What to set the node to - true/false(negated)
* @param server The server to set the permission on
* @param world The world to set the permission on
* @throws ObjectAlreadyHasException if the object already has the permission
*/
void setPermission(String node, boolean value, String server, String world) throws ObjectAlreadyHasException;
/** /**
* Sets a permission for the object * Sets a permission for the object
* @param node The node to set * @param node The node to set
@ -106,6 +178,17 @@ public interface PermissionObject {
*/ */
void setPermission(String node, boolean value, String server, long expireAt) throws ObjectAlreadyHasException; void setPermission(String node, boolean value, String server, long expireAt) throws ObjectAlreadyHasException;
/**
* Sets a permission for the object
* @param node The node to set
* @param value What to set the node to - true/false(negated)
* @param server The server to set the permission on
* @param world The world to set the permission on
* @param expireAt The time in unixtime when the permission will expire
* @throws ObjectAlreadyHasException if the object already has the permission
*/
void setPermission(String node, boolean value, String server, String world, long expireAt) throws ObjectAlreadyHasException;
/** /**
* Unsets a permission for the object * Unsets a permission for the object
* @param node The node to be unset * @param node The node to be unset
@ -129,6 +212,15 @@ public interface PermissionObject {
*/ */
void unsetPermission(String node, String server) throws ObjectLacksException; void unsetPermission(String node, String server) throws ObjectLacksException;
/**
* Unsets a permission for the object
* @param node The node to be unset
* @param server The server to unset the node on
* @param world The world to unset the node on
* @throws ObjectLacksException if the node wasn't already set
*/
void unsetPermission(String node, String server, String world) throws ObjectLacksException;
/** /**
* Unsets a permission for the object * Unsets a permission for the object
* @param node The node to be unset * @param node The node to be unset
@ -138,6 +230,25 @@ public interface PermissionObject {
*/ */
void unsetPermission(String node, String server, boolean temporary) throws ObjectLacksException; void unsetPermission(String node, String server, boolean temporary) throws ObjectLacksException;
/**
* Unsets a permission for the object
* @param node The node to be unset
* @param server The server to unset the node on
* @param world The world to unset the node on
* @param temporary if the permission being unset is temporary
* @throws ObjectLacksException if the node wasn't already set
*/
void unsetPermission(String node, String server, String world, boolean temporary) throws ObjectLacksException;
/**
* Gets the permissions and inherited permissions that apply to a specific server
* @param server The server to get nodes for
* @param world The world to get nodes for
* @param excludedGroups Groups that shouldn't be inherited (to prevent circular inheritance issues)
* @return a {@link Map} of the permissions
*/
Map<String, Boolean> getLocalPermissions(String server, String world, List<String> excludedGroups);
/** /**
* Gets the permissions and inherited permissions that apply to a specific server * Gets the permissions and inherited permissions that apply to a specific server
* @param server The server to get nodes for (can be null) * @param server The server to get nodes for (can be null)

View File

@ -14,10 +14,32 @@ import java.util.UUID;
@SuppressWarnings("unused") @SuppressWarnings("unused")
public interface User extends PermissionObject { public interface User extends PermissionObject {
/**
* @return the users Mojang assigned unique id
*/
UUID getUuid(); UUID getUuid();
/**
* @return the Users Username
*/
String getName(); String getName();
/**
* Gets the users primary group
* @return the users primary group
*/
String getPrimaryGroup(); String getPrimaryGroup();
/**
* Sets a users primary group
* @param s the new primary group
* @throws ObjectAlreadyHasException if the user already has this set as their primary group
*/
void setPrimaryGroup(String s) throws ObjectAlreadyHasException; void setPrimaryGroup(String s) throws ObjectAlreadyHasException;
/**
* Refresh and re-assign the users permissions
*/
void refreshPermissions(); void refreshPermissions();
/** /**
@ -35,6 +57,15 @@ public interface User extends PermissionObject {
*/ */
boolean isInGroup(Group group, String server); boolean isInGroup(Group group, String server);
/**
* Check to see if a user is a member of a group on a specific server
* @param group The group to check membership of
* @param server The server to check on
* @param world The world to check on
* @return true if the user is a member of the group
*/
boolean isInGroup(Group group, String server, String world);
/** /**
* Add a user to a group * Add a user to a group
* @param group The group to add the user to * @param group The group to add the user to
@ -50,6 +81,15 @@ public interface User extends PermissionObject {
*/ */
void addGroup(Group group, String server) throws ObjectAlreadyHasException; void addGroup(Group group, String server) throws ObjectAlreadyHasException;
/**
* Add a user to a group on a specific server
* @param group The group to add the user to
* @param server The server to add the group on
* @param world The world to add the group on
* @throws ObjectAlreadyHasException if the user is already a member of the group on that server
*/
void addGroup(Group group, String server, String world) throws ObjectAlreadyHasException;
/** /**
* Add a user to a group on a specific server * Add a user to a group on a specific server
* @param group The group to add the user to * @param group The group to add the user to
@ -67,6 +107,16 @@ public interface User extends PermissionObject {
*/ */
void addGroup(Group group, String server, long expireAt) throws ObjectAlreadyHasException; void addGroup(Group group, String server, long expireAt) throws ObjectAlreadyHasException;
/**
* Add a user to a group on a specific server
* @param group The group to add the user to
* @param server The server to add the group on
* @param world The world to add the group on
* @param expireAt when the group should expire
* @throws ObjectAlreadyHasException if the user is already a member of the group on that server
*/
void addGroup(Group group, String server, String world, long expireAt) throws ObjectAlreadyHasException;
/** /**
* Remove the user from a group * Remove the user from a group
* @param group the group to remove the user from * @param group the group to remove the user from
@ -90,6 +140,15 @@ public interface User extends PermissionObject {
*/ */
void removeGroup(Group group, String server) throws ObjectLacksException; void removeGroup(Group group, String server) throws ObjectLacksException;
/**
* Remove the user from a group
* @param group The group to remove the user from
* @param server The server to remove the group on
* @param world The world to remove the group on
* @throws ObjectLacksException if the user isn't a member of the group
*/
void removeGroup(Group group, String server, String world) throws ObjectLacksException;
/** /**
* Remove the user from a group * Remove the user from a group
* @param group The group to remove the user from * @param group The group to remove the user from
@ -99,6 +158,16 @@ public interface User extends PermissionObject {
*/ */
void removeGroup(Group group, String server, boolean temporary) throws ObjectLacksException; void removeGroup(Group group, String server, boolean temporary) throws ObjectLacksException;
/**
* Remove the user from a group
* @param group The group to remove the user from
* @param server The server to remove the group on
* @param world The world to remove the group on
* @param temporary if the group being removed is temporary
* @throws ObjectLacksException if the user isn't a member of the group
*/
void removeGroup(Group group, String server, String world, boolean temporary) throws ObjectLacksException;
/** /**
* Clear all of the users permission nodes * Clear all of the users permission nodes
*/ */
@ -110,6 +179,13 @@ public interface User extends PermissionObject {
*/ */
List<String> getGroupNames(); List<String> getGroupNames();
/**
* Get a {@link List} of the groups the user is a member of on a specific server
* @param server the server to check
* @return a {@link List} of group names
*/
List<String> getLocalGroups(String server, String world);
/** /**
* Get a {@link List} of the groups the user is a member of on a specific server * Get a {@link List} of the groups the user is a member of on a specific server
* @param server the server to check * @param server the server to check

View File

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

View File

@ -1,6 +1,6 @@
package me.lucko.luckperms.listeners; package me.lucko.luckperms.listeners;
import lombok.RequiredArgsConstructor; import lombok.AllArgsConstructor;
import me.lucko.luckperms.LPBukkitPlugin; import me.lucko.luckperms.LPBukkitPlugin;
import me.lucko.luckperms.commands.Util; import me.lucko.luckperms.commands.Util;
import me.lucko.luckperms.constants.Message; import me.lucko.luckperms.constants.Message;
@ -10,38 +10,15 @@ import me.lucko.luckperms.utils.UuidCache;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler; import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener; import org.bukkit.event.Listener;
import org.bukkit.event.player.AsyncPlayerPreLoginEvent; import org.bukkit.event.player.*;
import org.bukkit.event.player.PlayerJoinEvent;
import org.bukkit.event.player.PlayerLoginEvent;
import org.bukkit.event.player.PlayerQuitEvent;
import java.util.UUID; import java.util.UUID;
@RequiredArgsConstructor @AllArgsConstructor
public class PlayerListener implements Listener { public class PlayerListener implements Listener {
private static final String KICK_MESSAGE = Util.color(Message.PREFIX + "User data could not be loaded. Please contact an administrator."); private static final String KICK_MESSAGE = Util.color(Message.PREFIX + "User data could not be loaded. Please contact an administrator.");
private final LPBukkitPlugin plugin; private final LPBukkitPlugin plugin;
/*
cache: username --> uuid
returns mojang if not in offline mode
if server in offline mode:
go to datastore, look for uuid, add to cache.
*** player prelogin, load or create, using CACHE uuid
*** player login, we get their username and check if it's there
*** player join, save uuid data and refresh
*** player quit, unload
*/
@EventHandler @EventHandler
public void onPlayerPreLogin(AsyncPlayerPreLoginEvent e) { public void onPlayerPreLogin(AsyncPlayerPreLoginEvent e) {
if (!plugin.getDatastore().isAcceptingLogins()) { if (!plugin.getDatastore().isAcceptingLogins()) {
@ -54,22 +31,24 @@ public class PlayerListener implements Listener {
if (!cache.isOnlineMode()) { if (!cache.isOnlineMode()) {
UUID uuid = plugin.getDatastore().getUUID(e.getName()); UUID uuid = plugin.getDatastore().getUUID(e.getName());
if (uuid != null) { if (uuid != null) {
cache.addToCache(e.getName(), uuid); cache.addToCache(e.getUniqueId(), uuid);
} else { } else {
cache.addToCache(e.getName(), e.getUniqueId()); // No previous data for this player
cache.addToCache(e.getUniqueId(), e.getUniqueId());
plugin.getDatastore().saveUUIDData(e.getName(), e.getUniqueId(), b -> {}); plugin.getDatastore().saveUUIDData(e.getName(), e.getUniqueId(), b -> {});
} }
} else { } else {
// Online mode, no cache needed. This is just for name -> uuid lookup.
plugin.getDatastore().saveUUIDData(e.getName(), e.getUniqueId(), b -> {}); plugin.getDatastore().saveUUIDData(e.getName(), e.getUniqueId(), b -> {});
} }
plugin.getDatastore().loadOrCreateUser(cache.getUUID(e.getName(), e.getUniqueId()), e.getName()); plugin.getDatastore().loadOrCreateUser(cache.getUUID(e.getUniqueId()), e.getName());
} }
@EventHandler @EventHandler
public void onPlayerLogin(PlayerLoginEvent e) { public void onPlayerLogin(PlayerLoginEvent e) {
final Player player = e.getPlayer(); final Player player = e.getPlayer();
final User user = plugin.getUserManager().getUser(plugin.getUuidCache().getUUID(e.getPlayer().getName(), e.getPlayer().getUniqueId())); final User user = plugin.getUserManager().getUser(plugin.getUuidCache().getUUID(e.getPlayer().getUniqueId()));
if (user == null) { if (user == null) {
e.disallow(PlayerLoginEvent.Result.KICK_OTHER, KICK_MESSAGE); e.disallow(PlayerLoginEvent.Result.KICK_OTHER, KICK_MESSAGE);
@ -87,10 +66,7 @@ public class PlayerListener implements Listener {
@EventHandler @EventHandler
public void onPlayerJoin(PlayerJoinEvent e) { public void onPlayerJoin(PlayerJoinEvent e) {
// Refresh permissions again // Refresh permissions again
final User user = plugin.getUserManager().getUser(plugin.getUuidCache().getUUID(e.getPlayer().getName(), e.getPlayer().getUniqueId())); refreshPlayer(e.getPlayer());
if (user != null) {
user.refreshPermissions();
}
} }
@EventHandler @EventHandler
@ -99,10 +75,22 @@ public class PlayerListener implements Listener {
final UuidCache cache = plugin.getUuidCache(); final UuidCache cache = plugin.getUuidCache();
// Unload the user from memory when they disconnect; // Unload the user from memory when they disconnect;
cache.clearCache(player.getName()); cache.clearCache(player.getUniqueId());
final User user = plugin.getUserManager().getUser(cache.getUUID(player.getName(), player.getUniqueId())); final User user = plugin.getUserManager().getUser(cache.getUUID(player.getUniqueId()));
plugin.getUserManager().unloadUser(user); plugin.getUserManager().unloadUser(user);
} }
@EventHandler
public void onPlayerChangedWorld(PlayerChangedWorldEvent e) {
refreshPlayer(e.getPlayer());
}
private void refreshPlayer(Player p) {
final User user = plugin.getUserManager().getUser(plugin.getUuidCache().getUUID(p.getUniqueId()));
if (user != null) {
user.refreshPermissions();
}
}
} }

View File

@ -30,7 +30,7 @@ public class BukkitUser extends User {
@Override @Override
public void refreshPermissions() { public void refreshPermissions() {
plugin.doSync(() -> { plugin.doSync(() -> {
final Player player = plugin.getServer().getPlayer(getUuid()); final Player player = plugin.getServer().getPlayer(plugin.getUuidCache().getExternalUUID(getUuid()));
if (player == null) return; if (player == null) return;
if (attachment == null) { if (attachment == null) {
@ -42,7 +42,7 @@ public class BukkitUser extends User {
attachment.getPermissions().keySet().forEach(p -> attachment.setPermission(p, false)); attachment.getPermissions().keySet().forEach(p -> attachment.setPermission(p, false));
// Re-add all defined permissions for the user // Re-add all defined permissions for the user
Map<String, Boolean> local = getLocalPermissions(getPlugin().getConfiguration().getServer(), null); Map<String, Boolean> local = getLocalPermissions(getPlugin().getConfiguration().getServer(), player.getWorld().getName(), null);
local.entrySet().forEach(e -> attachment.setPermission(e.getKey(), e.getValue())); local.entrySet().forEach(e -> attachment.setPermission(e.getKey(), e.getValue()));
}); });
} }

View File

@ -23,7 +23,7 @@ public class BukkitUserManager extends UserManager {
BukkitUser u = (BukkitUser) user; BukkitUser u = (BukkitUser) user;
if (u.getAttachment() != null) { if (u.getAttachment() != null) {
Player player = plugin.getServer().getPlayer(u.getUuid()); Player player = plugin.getServer().getPlayer(plugin.getUuidCache().getExternalUUID(u.getUuid()));
if (player != null) { if (player != null) {
player.removeAttachment(u.getAttachment()); player.removeAttachment(u.getAttachment());
@ -38,7 +38,7 @@ public class BukkitUserManager extends UserManager {
@Override @Override
public void cleanupUser(User user) { public void cleanupUser(User user) {
if (plugin.getServer().getPlayer(user.getUuid()) == null) { if (plugin.getServer().getPlayer(plugin.getUuidCache().getExternalUUID(user.getUuid())) == null) {
unloadUser(user); unloadUser(user);
} }
} }
@ -58,7 +58,7 @@ public class BukkitUserManager extends UserManager {
// Sometimes called async, so we need to get the players on the Bukkit thread. // Sometimes called async, so we need to get the players on the Bukkit thread.
plugin.doSync(() -> { plugin.doSync(() -> {
Set<UUID> players = plugin.getServer().getOnlinePlayers().stream() Set<UUID> players = plugin.getServer().getOnlinePlayers().stream()
.map(p -> plugin.getUuidCache().getUUID(p.getName(), p.getUniqueId())) .map(p -> plugin.getUuidCache().getUUID(p.getUniqueId()))
.collect(Collectors.toSet()); .collect(Collectors.toSet());
plugin.doAsync(() -> players.forEach(u -> plugin.getDatastore().loadUser(u))); plugin.doAsync(() -> players.forEach(u -> plugin.getDatastore().loadUser(u)));
}); });

View File

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

View File

@ -12,6 +12,7 @@ import net.md_5.bungee.api.connection.ProxiedPlayer;
import net.md_5.bungee.api.event.LoginEvent; import net.md_5.bungee.api.event.LoginEvent;
import net.md_5.bungee.api.event.PlayerDisconnectEvent; import net.md_5.bungee.api.event.PlayerDisconnectEvent;
import net.md_5.bungee.api.event.PostLoginEvent; import net.md_5.bungee.api.event.PostLoginEvent;
import net.md_5.bungee.api.event.ServerSwitchEvent;
import net.md_5.bungee.api.plugin.Listener; import net.md_5.bungee.api.plugin.Listener;
import net.md_5.bungee.event.EventHandler; import net.md_5.bungee.event.EventHandler;
@ -39,18 +40,20 @@ public class PlayerListener implements Listener {
if (!cache.isOnlineMode()) { if (!cache.isOnlineMode()) {
UUID uuid = plugin.getDatastore().getUUID(c.getName()); UUID uuid = plugin.getDatastore().getUUID(c.getName());
if (uuid != null) { if (uuid != null) {
cache.addToCache(c.getName(), uuid); cache.addToCache(c.getUniqueId(), uuid);
} else { } else {
cache.addToCache(c.getName(), c.getUniqueId()); // No previous data for this player
cache.addToCache(c.getUniqueId(), c.getUniqueId());
plugin.getDatastore().saveUUIDData(c.getName(), c.getUniqueId()); plugin.getDatastore().saveUUIDData(c.getName(), c.getUniqueId());
} }
} else { } else {
// Online mode, no cache needed. This is just for name -> uuid lookup.
plugin.getDatastore().saveUUIDData(c.getName(), c.getUniqueId()); plugin.getDatastore().saveUUIDData(c.getName(), c.getUniqueId());
} }
// We have to make a new user on this thread whilst the connection is being held, or we get concurrency issues as the Bukkit server // We have to make a new user on this thread whilst the connection is being held, or we get concurrency issues as the Bukkit server
// and the BungeeCord server try to make a new user at the same time. // and the BungeeCord server try to make a new user at the same time.
plugin.getDatastore().loadOrCreateUser(cache.getUUID(c.getName(), c.getUniqueId()), c.getName()); plugin.getDatastore().loadOrCreateUser(cache.getUUID(c.getUniqueId()), c.getName());
e.completeIntent(plugin); e.completeIntent(plugin);
}); });
} }
@ -60,7 +63,7 @@ public class PlayerListener implements Listener {
final ProxiedPlayer player = e.getPlayer(); final ProxiedPlayer player = e.getPlayer();
final WeakReference<ProxiedPlayer> p = new WeakReference<>(player); final WeakReference<ProxiedPlayer> p = new WeakReference<>(player);
final User user = plugin.getUserManager().getUser(plugin.getUuidCache().getUUID(e.getPlayer().getName(), e.getPlayer().getUniqueId())); final User user = plugin.getUserManager().getUser(plugin.getUuidCache().getUUID(e.getPlayer().getUniqueId()));
if (user == null) { if (user == null) {
plugin.getProxy().getScheduler().schedule(plugin, () -> { plugin.getProxy().getScheduler().schedule(plugin, () -> {
final ProxiedPlayer pl = p.get(); final ProxiedPlayer pl = p.get();
@ -79,9 +82,17 @@ public class PlayerListener implements Listener {
final UuidCache cache = plugin.getUuidCache(); final UuidCache cache = plugin.getUuidCache();
// Unload the user from memory when they disconnect; // Unload the user from memory when they disconnect;
cache.clearCache(player.getName()); cache.clearCache(player.getUniqueId());
final User user = plugin.getUserManager().getUser(cache.getUUID(player.getName(), player.getUniqueId())); final User user = plugin.getUserManager().getUser(cache.getUUID(player.getUniqueId()));
plugin.getUserManager().unloadUser(user); plugin.getUserManager().unloadUser(user);
} }
@EventHandler
public void onPlayerServerSwitch(ServerSwitchEvent e) {
final User user = plugin.getUserManager().getUser(plugin.getUuidCache().getUUID(e.getPlayer().getUniqueId()));
if (user != null) {
user.refreshPermissions();
}
}
} }

View File

@ -24,7 +24,7 @@ public class BungeeUser extends User {
@Override @Override
public void refreshPermissions() { public void refreshPermissions() {
ProxiedPlayer player = plugin.getProxy().getPlayer(getUuid()); ProxiedPlayer player = plugin.getProxy().getPlayer(plugin.getUuidCache().getExternalUUID(getUuid()));
if (player == null) return; if (player == null) return;
// Clear existing permissions // Clear existing permissions
@ -32,7 +32,8 @@ public class BungeeUser extends User {
perms.forEach(p -> player.setPermission(p, false)); perms.forEach(p -> player.setPermission(p, false));
// Re-add all defined permissions for the user // Re-add all defined permissions for the user
Map<String, Boolean> local = getLocalPermissions(getPlugin().getConfiguration().getServer(), null); final String server = player.getServer() == null ? null : (player.getServer().getInfo() == null ? null : player.getServer().getInfo().getName());
Map<String, Boolean> local = getLocalPermissions(getPlugin().getConfiguration().getServer(), server, null);
local.entrySet().forEach(e -> player.setPermission(e.getKey(), e.getValue())); local.entrySet().forEach(e -> player.setPermission(e.getKey(), e.getValue()));
} }
} }

View File

@ -23,7 +23,7 @@ public class BungeeUserManager extends UserManager {
@Override @Override
public void cleanupUser(User user) { public void cleanupUser(User user) {
if (plugin.getProxy().getPlayer(user.getUuid()) == null) { if (plugin.getProxy().getPlayer(plugin.getUuidCache().getExternalUUID(user.getUuid())) == null) {
unloadUser(user); unloadUser(user);
} }
} }
@ -41,7 +41,7 @@ public class BungeeUserManager extends UserManager {
@Override @Override
public void updateAllUsers() { public void updateAllUsers() {
plugin.getProxy().getPlayers().stream() plugin.getProxy().getPlayers().stream()
.map(p -> plugin.getUuidCache().getUUID(p.getName(), p.getUniqueId())) .map(p -> plugin.getUuidCache().getUUID(p.getUniqueId()))
.forEach(u -> plugin.getDatastore().loadUser(u)); .forEach(u -> plugin.getDatastore().loadUser(u));
} }
} }

View File

@ -64,11 +64,26 @@ class PermissionObjectLink implements PermissionObject {
return master.hasPermission(node, b, checkServer(server)); return master.hasPermission(node, b, checkServer(server));
} }
@Override
public boolean hasPermission(@NonNull String node, @NonNull boolean b, @NonNull String server, @NonNull String world) {
return master.hasPermission(node, b, checkServer(server), world);
}
@Override @Override
public boolean hasPermission(@NonNull String node, @NonNull boolean b, @NonNull boolean temporary) { public boolean hasPermission(@NonNull String node, @NonNull boolean b, @NonNull boolean temporary) {
return master.hasPermission(node, b, temporary); return master.hasPermission(node, b, temporary);
} }
@Override
public boolean hasPermission(@NonNull String node, @NonNull boolean b, @NonNull String server, @NonNull boolean temporary) {
return master.hasPermission(node, b, checkServer(server), temporary);
}
@Override
public boolean hasPermission(@NonNull String node, @NonNull boolean b, @NonNull String server, @NonNull String world, @NonNull boolean temporary) {
return master.hasPermission(node, b, checkServer(server), world, temporary);
}
@Override @Override
public boolean inheritsPermission(@NonNull String node, @NonNull boolean b) { public boolean inheritsPermission(@NonNull String node, @NonNull boolean b) {
return master.inheritsPermission(node, b); return master.inheritsPermission(node, b);
@ -79,11 +94,26 @@ class PermissionObjectLink implements PermissionObject {
return master.inheritsPermission(node, b, checkServer(server)); return master.inheritsPermission(node, b, checkServer(server));
} }
@Override
public boolean inheritsPermission(@NonNull String node, @NonNull boolean b, @NonNull String server, @NonNull String world) {
return master.inheritsPermission(node, b, checkServer(server), world);
}
@Override @Override
public boolean inheritsPermission(@NonNull String node, @NonNull boolean b, @NonNull boolean temporary) { public boolean inheritsPermission(@NonNull String node, @NonNull boolean b, @NonNull boolean temporary) {
return master.inheritsPermission(node, b, temporary); return master.inheritsPermission(node, b, temporary);
} }
@Override
public boolean inheritsPermission(@NonNull String node, @NonNull boolean b, @NonNull String server, @NonNull boolean temporary) {
return master.inheritsPermission(node, b, checkServer(server), temporary);
}
@Override
public boolean inheritsPermission(@NonNull String node, @NonNull boolean b, @NonNull String server, @NonNull String world, @NonNull boolean temporary) {
return master.inheritsPermission(node, b, checkServer(server), world, temporary);
}
@Override @Override
public void setPermission(@NonNull String node, @NonNull boolean value) throws ObjectAlreadyHasException { public void setPermission(@NonNull String node, @NonNull boolean value) throws ObjectAlreadyHasException {
master.setPermission(checkNode(node), value); master.setPermission(checkNode(node), value);
@ -94,6 +124,11 @@ class PermissionObjectLink implements PermissionObject {
master.setPermission(checkNode(node), value, checkServer(server)); master.setPermission(checkNode(node), value, checkServer(server));
} }
@Override
public void setPermission(@NonNull String node, @NonNull boolean value, @NonNull String server, @NonNull String world) throws ObjectAlreadyHasException {
master.setPermission(checkNode(node), value, checkServer(server), world);
}
@Override @Override
public void setPermission(@NonNull String node, @NonNull boolean value, @NonNull long expireAt) throws ObjectAlreadyHasException { public void setPermission(@NonNull String node, @NonNull boolean value, @NonNull long expireAt) throws ObjectAlreadyHasException {
master.setPermission(checkNode(node), value, checkTime(expireAt)); master.setPermission(checkNode(node), value, checkTime(expireAt));
@ -104,6 +139,11 @@ class PermissionObjectLink implements PermissionObject {
master.setPermission(checkNode(node), value, checkServer(server), checkTime(expireAt)); master.setPermission(checkNode(node), value, checkServer(server), checkTime(expireAt));
} }
@Override
public void setPermission(@NonNull String node, @NonNull boolean value, @NonNull String server, @NonNull String world, @NonNull long expireAt) throws ObjectAlreadyHasException {
master.setPermission(checkNode(node), value, checkServer(server), world, checkTime(expireAt));
}
@Override @Override
public void unsetPermission(@NonNull String node, @NonNull boolean temporary) throws ObjectLacksException { public void unsetPermission(@NonNull String node, @NonNull boolean temporary) throws ObjectLacksException {
master.unsetPermission(checkNode(node), temporary); master.unsetPermission(checkNode(node), temporary);
@ -119,11 +159,26 @@ class PermissionObjectLink implements PermissionObject {
master.unsetPermission(checkNode(node), checkServer(server)); master.unsetPermission(checkNode(node), checkServer(server));
} }
@Override
public void unsetPermission(@NonNull String node, @NonNull String server, @NonNull String world) throws ObjectLacksException {
master.unsetPermission(checkNode(node), checkServer(server), world);
}
@Override @Override
public void unsetPermission(@NonNull String node, @NonNull String server, @NonNull boolean temporary) throws ObjectLacksException { public void unsetPermission(@NonNull String node, @NonNull String server, @NonNull boolean temporary) throws ObjectLacksException {
master.unsetPermission(checkNode(node), checkServer(server), temporary); master.unsetPermission(checkNode(node), checkServer(server), temporary);
} }
@Override
public void unsetPermission(@NonNull String node, @NonNull String server, @NonNull String world, @NonNull boolean temporary) throws ObjectLacksException {
master.unsetPermission(checkNode(node), checkServer(server), world, temporary);
}
@Override
public Map<String, Boolean> getLocalPermissions(String server, String world, List<String> excludedGroups) {
return master.getLocalPermissions(server, world, excludedGroups);
}
@Override @Override
public Map<String, Boolean> getLocalPermissions(String server, List<String> excludedGroups) { public Map<String, Boolean> getLocalPermissions(String server, List<String> excludedGroups) {
return master.getLocalPermissions(server, excludedGroups); return master.getLocalPermissions(server, excludedGroups);

View File

@ -70,6 +70,12 @@ public class UserLink extends PermissionObjectLink implements User {
return master.isInGroup(((GroupLink) group).getMaster(), server); return master.isInGroup(((GroupLink) group).getMaster(), server);
} }
@Override
public boolean isInGroup(@NonNull Group group, @NonNull String server, @NonNull String world) {
Utils.checkGroup(group);
return master.isInGroup(((GroupLink) group).getMaster(), server, world);
}
@Override @Override
public void addGroup(@NonNull Group group) throws ObjectAlreadyHasException { public void addGroup(@NonNull Group group) throws ObjectAlreadyHasException {
Utils.checkGroup(group); Utils.checkGroup(group);
@ -82,6 +88,12 @@ public class UserLink extends PermissionObjectLink implements User {
master.addGroup(((GroupLink) group).getMaster(), checkServer(server)); master.addGroup(((GroupLink) group).getMaster(), checkServer(server));
} }
@Override
public void addGroup(@NonNull Group group, @NonNull String server, @NonNull String world) throws ObjectAlreadyHasException {
Utils.checkGroup(group);
master.addGroup(((GroupLink) group).getMaster(), checkServer(server), world);
}
@Override @Override
public void addGroup(@NonNull Group group, @NonNull long expireAt) throws ObjectAlreadyHasException { public void addGroup(@NonNull Group group, @NonNull long expireAt) throws ObjectAlreadyHasException {
Utils.checkGroup(group); Utils.checkGroup(group);
@ -94,6 +106,12 @@ public class UserLink extends PermissionObjectLink implements User {
master.addGroup(((GroupLink) group).getMaster(), checkServer(server), checkTime(expireAt)); master.addGroup(((GroupLink) group).getMaster(), checkServer(server), checkTime(expireAt));
} }
@Override
public void addGroup(@NonNull Group group, @NonNull String server, @NonNull String world, @NonNull long expireAt) throws ObjectAlreadyHasException {
Utils.checkGroup(group);
master.addGroup(((GroupLink) group).getMaster(), checkServer(server), world, checkTime(expireAt));
}
@Override @Override
public void removeGroup(@NonNull Group group) throws ObjectLacksException { public void removeGroup(@NonNull Group group) throws ObjectLacksException {
Utils.checkGroup(group); Utils.checkGroup(group);
@ -112,12 +130,24 @@ public class UserLink extends PermissionObjectLink implements User {
master.removeGroup(((GroupLink) group).getMaster(), checkServer(server)); master.removeGroup(((GroupLink) group).getMaster(), checkServer(server));
} }
@Override
public void removeGroup(@NonNull Group group, @NonNull String server, @NonNull String world) throws ObjectLacksException {
Utils.checkGroup(group);
master.removeGroup(((GroupLink) group).getMaster(), checkServer(server), world);
}
@Override @Override
public void removeGroup(@NonNull Group group, @NonNull String server, @NonNull boolean temporary) throws ObjectLacksException { public void removeGroup(@NonNull Group group, @NonNull String server, @NonNull boolean temporary) throws ObjectLacksException {
Utils.checkGroup(group); Utils.checkGroup(group);
master.removeGroup(((GroupLink) group).getMaster(), checkServer(server), temporary); master.removeGroup(((GroupLink) group).getMaster(), checkServer(server), temporary);
} }
@Override
public void removeGroup(@NonNull Group group, @NonNull String server, @NonNull String world, @NonNull boolean temporary) throws ObjectLacksException {
Utils.checkGroup(group);
master.removeGroup(((GroupLink) group).getMaster(), checkServer(server), world, temporary);
}
@Override @Override
public void clearNodes() { public void clearNodes() {
master.clearNodes(); master.clearNodes();
@ -128,6 +158,11 @@ public class UserLink extends PermissionObjectLink implements User {
return master.getGroupNames(); return master.getGroupNames();
} }
@Override
public List<String> getLocalGroups(@NonNull String server, @NonNull String world) {
return master.getLocalGroups(checkServer(server), world);
}
@Override @Override
public List<String> getLocalGroups(@NonNull String server) { public List<String> getLocalGroups(@NonNull String server) {
return master.getLocalGroups(checkServer(server)); return master.getLocalGroups(checkServer(server));

View File

@ -14,18 +14,23 @@ import java.util.List;
public class GroupHasPerm extends GroupSubCommand { public class GroupHasPerm extends GroupSubCommand {
public GroupHasPerm() { public GroupHasPerm() {
super("haspermission", "Checks to see if a group has a certain permission node", super("haspermission", "Checks to see if a group has a certain permission node",
"/%s group <group> haspermission <node> [server]", Permission.GROUP_HASPERMISSION); "/%s group <group> haspermission <node> [server] [world]", Permission.GROUP_HASPERMISSION);
} }
@Override @Override
protected void execute(LuckPermsPlugin plugin, Sender sender, Group group, List<String> args, String label) { protected void execute(LuckPermsPlugin plugin, Sender sender, Group group, List<String> args, String label) {
if (args.size() == 2) { if (args.size() >= 2) {
if (Patterns.NON_ALPHA_NUMERIC.matcher(args.get(1)).find()) { if (Patterns.NON_ALPHA_NUMERIC.matcher(args.get(1)).find()) {
Message.SERVER_INVALID_ENTRY.send(sender); Message.SERVER_INVALID_ENTRY.send(sender);
return; return;
} }
Util.sendBoolean(sender, args.get(0), group.hasPermission(args.get(0), true, args.get(1).toLowerCase())); if (args.size() == 2) {
Util.sendBoolean(sender, args.get(0), group.hasPermission(args.get(0), true, args.get(1)));
} else {
Util.sendBoolean(sender, args.get(0), group.hasPermission(args.get(0), true, args.get(1), args.get(2)));
}
} else { } else {
Util.sendBoolean(sender, args.get(0), group.hasPermission(args.get(0), true, "global")); Util.sendBoolean(sender, args.get(0), group.hasPermission(args.get(0), true, "global"));
} }
@ -33,6 +38,6 @@ public class GroupHasPerm extends GroupSubCommand {
@Override @Override
public boolean isArgLengthInvalid(int argLength) { public boolean isArgLengthInvalid(int argLength) {
return argLength != 1 && argLength != 2; return argLength != 1 && argLength != 2 && argLength != 3;
} }
} }

View File

@ -14,18 +14,23 @@ import java.util.List;
public class GroupInheritsPerm extends GroupSubCommand { public class GroupInheritsPerm extends GroupSubCommand {
public GroupInheritsPerm() { public GroupInheritsPerm() {
super("inheritspermission", "Checks to see if a group inherits a certain permission node", super("inheritspermission", "Checks to see if a group inherits a certain permission node",
"/%s group <group> inheritspermission <node> [server]", Permission.GROUP_INHERITSPERMISSION); "/%s group <group> inheritspermission <node> [server] [world]", Permission.GROUP_INHERITSPERMISSION);
} }
@Override @Override
protected void execute(LuckPermsPlugin plugin, Sender sender, Group group, List<String> args, String label) { protected void execute(LuckPermsPlugin plugin, Sender sender, Group group, List<String> args, String label) {
if (args.size() == 2) { if (args.size() >= 2) {
if (Patterns.NON_ALPHA_NUMERIC.matcher(args.get(1)).find()) { if (Patterns.NON_ALPHA_NUMERIC.matcher(args.get(1)).find()) {
Message.SERVER_INVALID_ENTRY.send(sender); Message.SERVER_INVALID_ENTRY.send(sender);
return; return;
} }
Util.sendBoolean(sender, args.get(0), group.inheritsPermission(args.get(0), true, args.get(1).toLowerCase())); if (args.size() == 2) {
Util.sendBoolean(sender, args.get(0), group.inheritsPermission(args.get(0), true, args.get(1)));
} else {
Util.sendBoolean(sender, args.get(0), group.inheritsPermission(args.get(0), true, args.get(1), args.get(2)));
}
} else { } else {
Util.sendBoolean(sender, args.get(0), group.inheritsPermission(args.get(0), true)); Util.sendBoolean(sender, args.get(0), group.inheritsPermission(args.get(0), true));
} }
@ -33,6 +38,6 @@ public class GroupInheritsPerm extends GroupSubCommand {
@Override @Override
public boolean isArgLengthInvalid(int argLength) { public boolean isArgLengthInvalid(int argLength) {
return argLength != 1 && argLength != 2; return argLength != 1 && argLength != 2 && argLength != 3;
} }
} }

View File

@ -14,7 +14,7 @@ import java.util.List;
public class GroupSetInherit extends GroupSubCommand { public class GroupSetInherit extends GroupSubCommand {
public GroupSetInherit() { public GroupSetInherit() {
super("setinherit", "Sets another group for this group to inherit permissions from", super("setinherit", "Sets another group for this group to inherit permissions from",
"/%s group <group> setinherit <group> [server]", Permission.GROUP_SETINHERIT); "/%s group <group> setinherit <group> [server] [world]", Permission.GROUP_SETINHERIT);
} }
@Override @Override
@ -31,15 +31,22 @@ public class GroupSetInherit extends GroupSubCommand {
Message.GROUP_LOAD_ERROR.send(sender); Message.GROUP_LOAD_ERROR.send(sender);
} else { } else {
try { try {
if (args.size() == 2) { if (args.size() >= 2) {
final String server = args.get(1).toLowerCase(); final String server = args.get(1).toLowerCase();
if (Patterns.NON_ALPHA_NUMERIC.matcher(server).find()) { if (Patterns.NON_ALPHA_NUMERIC.matcher(server).find()) {
Message.SERVER_INVALID_ENTRY.send(sender); Message.SERVER_INVALID_ENTRY.send(sender);
return; return;
} }
group.setPermission("group." + groupName, true, server); if (args.size() == 2) {
Message.GROUP_SETINHERIT_SERVER_SUCCESS.send(sender, group.getName(), groupName, server); group.setPermission("group." + groupName, true, server);
Message.GROUP_SETINHERIT_SERVER_SUCCESS.send(sender, group.getName(), groupName, server);
} else {
final String world = args.get(2).toLowerCase();
group.setPermission("group." + groupName, true, server, world);
Message.GROUP_SETINHERIT_SERVER_WORLD_SUCCESS.send(sender, group.getName(), groupName, server, world);
}
} else { } else {
group.setPermission("group." + groupName, true); group.setPermission("group." + groupName, true);
Message.GROUP_SETINHERIT_SUCCESS.send(sender, group.getName(), groupName); Message.GROUP_SETINHERIT_SUCCESS.send(sender, group.getName(), groupName);
@ -60,6 +67,6 @@ public class GroupSetInherit extends GroupSubCommand {
@Override @Override
public boolean isArgLengthInvalid(int argLength) { public boolean isArgLengthInvalid(int argLength) {
return argLength != 1 && argLength != 2; return argLength != 1 && argLength != 2 && argLength != 3;
} }
} }

View File

@ -13,7 +13,7 @@ import java.util.List;
public class GroupSetPermission extends GroupSubCommand { public class GroupSetPermission extends GroupSubCommand {
public GroupSetPermission() { public GroupSetPermission() {
super("set", "Sets a permission for a group", "/%s group <group> set <node> <true|false> [server]", super("set", "Sets a permission for a group", "/%s group <group> set <node> <true|false> [server] [world]",
Permission.GROUP_SETPERMISSION); Permission.GROUP_SETPERMISSION);
} }
@ -40,15 +40,22 @@ public class GroupSetPermission extends GroupSubCommand {
boolean b = Boolean.parseBoolean(bool); boolean b = Boolean.parseBoolean(bool);
try { try {
if (args.size() == 3) { if (args.size() >= 3) {
final String server = args.get(2).toLowerCase(); final String server = args.get(2).toLowerCase();
if (Patterns.NON_ALPHA_NUMERIC.matcher(server).find()) { if (Patterns.NON_ALPHA_NUMERIC.matcher(server).find()) {
Message.SERVER_INVALID_ENTRY.send(sender); Message.SERVER_INVALID_ENTRY.send(sender);
return; return;
} }
group.setPermission(node, b, server); if (args.size() == 3) {
Message.SETPERMISSION_SERVER_SUCCESS.send(sender, node, bool, group.getName(), server); group.setPermission(node, b, server);
Message.SETPERMISSION_SERVER_SUCCESS.send(sender, node, bool, group.getName(), server);
} else {
final String world = args.get(3).toLowerCase();
group.setPermission(node, b, server, world);
Message.SETPERMISSION_SERVER_WORLD_SUCCESS.send(sender, node, bool, group.getName(), server, world);
}
} else { } else {
group.setPermission(node, b); group.setPermission(node, b);
Message.SETPERMISSION_SUCCESS.send(sender, node, bool, group.getName()); Message.SETPERMISSION_SUCCESS.send(sender, node, bool, group.getName());
@ -67,6 +74,6 @@ public class GroupSetPermission extends GroupSubCommand {
@Override @Override
public boolean isArgLengthInvalid(int argLength) { public boolean isArgLengthInvalid(int argLength) {
return argLength != 2 && argLength != 3; return argLength != 2 && argLength != 3 && argLength != 4;
} }
} }

View File

@ -15,7 +15,7 @@ import java.util.List;
public class GroupSetTempInherit extends GroupSubCommand { public class GroupSetTempInherit extends GroupSubCommand {
public GroupSetTempInherit() { public GroupSetTempInherit() {
super("settempinherit", "Sets another group for this group to inherit permissions from temporarily", super("settempinherit", "Sets another group for this group to inherit permissions from temporarily",
"/%s group <group> settempinherit <group> <duration> [server]", Permission.GROUP_SET_TEMP_INHERIT); "/%s group <group> settempinherit <group> <duration> [server] [world]", Permission.GROUP_SET_TEMP_INHERIT);
} }
@Override @Override
@ -45,16 +45,24 @@ public class GroupSetTempInherit extends GroupSubCommand {
Message.GROUP_LOAD_ERROR.send(sender); Message.GROUP_LOAD_ERROR.send(sender);
} else { } else {
try { try {
if (args.size() == 3) { if (args.size() >= 3) {
final String server = args.get(2).toLowerCase(); final String server = args.get(2).toLowerCase();
if (Patterns.NON_ALPHA_NUMERIC.matcher(server).find()) { if (Patterns.NON_ALPHA_NUMERIC.matcher(server).find()) {
Message.SERVER_INVALID_ENTRY.send(sender); Message.SERVER_INVALID_ENTRY.send(sender);
return; return;
} }
group.setPermission("group." + groupName, true, server, duration); if (args.size() == 3) {
Message.GROUP_SET_TEMP_INHERIT_SERVER_SUCCESS.send(sender, group.getName(), groupName, server, group.setPermission("group." + groupName, true, server, duration);
DateUtil.formatDateDiff(duration)); Message.GROUP_SET_TEMP_INHERIT_SERVER_SUCCESS.send(sender, group.getName(), groupName, server,
DateUtil.formatDateDiff(duration));
} else {
final String world = args.get(3).toLowerCase();
group.setPermission("group." + groupName, true, server, world, duration);
Message.GROUP_SET_TEMP_INHERIT_SERVER_WORLD_SUCCESS.send(sender, group.getName(), groupName, server,
world, DateUtil.formatDateDiff(duration));
}
} else { } else {
group.setPermission("group." + groupName, true, duration); group.setPermission("group." + groupName, true, duration);
Message.GROUP_SET_TEMP_INHERIT_SUCCESS.send(sender, group.getName(), groupName, DateUtil.formatDateDiff(duration)); Message.GROUP_SET_TEMP_INHERIT_SUCCESS.send(sender, group.getName(), groupName, DateUtil.formatDateDiff(duration));
@ -75,6 +83,6 @@ public class GroupSetTempInherit extends GroupSubCommand {
@Override @Override
public boolean isArgLengthInvalid(int argLength) { public boolean isArgLengthInvalid(int argLength) {
return argLength != 2 && argLength != 3; return argLength != 2 && argLength != 3 && argLength != 4;
} }
} }

View File

@ -14,8 +14,8 @@ import java.util.List;
public class GroupSetTempPermission extends GroupSubCommand { public class GroupSetTempPermission extends GroupSubCommand {
public GroupSetTempPermission() { public GroupSetTempPermission() {
super("settemp", "Sets a temporary permission for a group", "/%s group <group> settemp <node> <true|false> <duration> [server]", super("settemp", "Sets a temporary permission for a group",
Permission.GROUP_SET_TEMP_PERMISSION); "/%s group <group> settemp <node> <true|false> <duration> [server] [world]", Permission.GROUP_SET_TEMP_PERMISSION);
} }
@Override @Override
@ -54,15 +54,24 @@ public class GroupSetTempPermission extends GroupSubCommand {
} }
try { try {
if (args.size() == 4) { if (args.size() >= 4) {
final String server = args.get(3).toLowerCase(); final String server = args.get(3).toLowerCase();
if (Patterns.NON_ALPHA_NUMERIC.matcher(server).find()) { if (Patterns.NON_ALPHA_NUMERIC.matcher(server).find()) {
Message.SERVER_INVALID_ENTRY.send(sender); Message.SERVER_INVALID_ENTRY.send(sender);
return; return;
} }
group.setPermission(node, b, server, duration); if (args.size() == 4) {
Message.SETPERMISSION_TEMP_SERVER_SUCCESS.send(sender, node, bool, group.getName(), server, DateUtil.formatDateDiff(duration)); group.setPermission(node, b, server, duration);
Message.SETPERMISSION_TEMP_SERVER_SUCCESS.send(sender, node, bool, group.getName(), server,
DateUtil.formatDateDiff(duration));
} else {
final String world = args.get(4).toLowerCase();
group.setPermission(node, b, server, world, duration);
Message.SETPERMISSION_TEMP_SERVER_WORLD_SUCCESS.send(sender, node, bool, group.getName(), server,
world, DateUtil.formatDateDiff(duration));
}
} else { } else {
group.setPermission(node, b, duration); group.setPermission(node, b, duration);
Message.SETPERMISSION_TEMP_SUCCESS.send(sender, node, bool, group.getName(), DateUtil.formatDateDiff(duration)); Message.SETPERMISSION_TEMP_SUCCESS.send(sender, node, bool, group.getName(), DateUtil.formatDateDiff(duration));
@ -81,6 +90,6 @@ public class GroupSetTempPermission extends GroupSubCommand {
@Override @Override
public boolean isArgLengthInvalid(int argLength) { public boolean isArgLengthInvalid(int argLength) {
return argLength != 3 && argLength != 4; return argLength != 3 && argLength != 4 && argLength != 5;
} }
} }

View File

@ -14,7 +14,7 @@ import java.util.List;
public class GroupUnSetPermission extends GroupSubCommand { public class GroupUnSetPermission extends GroupSubCommand {
public GroupUnSetPermission() { public GroupUnSetPermission() {
super("unset", "Unsets a permission for a group", super("unset", "Unsets a permission for a group",
"/%s group <group> unset <node> [server]", Permission.GROUP_UNSETPERMISSION); "/%s group <group> unset <node> [server] [world]", Permission.GROUP_UNSETPERMISSION);
} }
@Override @Override
@ -32,15 +32,22 @@ public class GroupUnSetPermission extends GroupSubCommand {
} }
try { try {
if (args.size() == 2) { if (args.size() >= 2) {
final String server = args.get(1).toLowerCase(); final String server = args.get(1).toLowerCase();
if (Patterns.NON_ALPHA_NUMERIC.matcher(server).find()) { if (Patterns.NON_ALPHA_NUMERIC.matcher(server).find()) {
Message.SERVER_INVALID_ENTRY.send(sender); Message.SERVER_INVALID_ENTRY.send(sender);
return; return;
} }
group.unsetPermission(node, server); if (args.size() == 2) {
Message.UNSETPERMISSION_SERVER_SUCCESS.send(sender, node, group.getName(), server); group.unsetPermission(node, server);
Message.UNSETPERMISSION_SERVER_SUCCESS.send(sender, node, group.getName(), server);
} else {
final String world = args.get(2).toLowerCase();
group.unsetPermission(node, server, world);
Message.UNSETPERMISSION_SERVER_WORLD_SUCCESS.send(sender, node, group.getName(), server, world);
}
} else { } else {
group.unsetPermission(node); group.unsetPermission(node);
Message.UNSETPERMISSION_SUCCESS.send(sender, node, group.getName()); Message.UNSETPERMISSION_SUCCESS.send(sender, node, group.getName());
@ -54,6 +61,6 @@ public class GroupUnSetPermission extends GroupSubCommand {
@Override @Override
public boolean isArgLengthInvalid(int argLength) { public boolean isArgLengthInvalid(int argLength) {
return argLength != 1 && argLength != 2; return argLength != 1 && argLength != 2 && argLength != 3;
} }
} }

View File

@ -14,7 +14,7 @@ import java.util.List;
public class GroupUnsetInherit extends GroupSubCommand { public class GroupUnsetInherit extends GroupSubCommand {
public GroupUnsetInherit() { public GroupUnsetInherit() {
super("unsetinherit", "Unsets another group for this group to inherit permissions from", super("unsetinherit", "Unsets another group for this group to inherit permissions from",
"/%s group <group> unsetinherit <group> [server]", Permission.GROUP_UNSETINHERIT); "/%s group <group> unsetinherit <group> [server] [world]", Permission.GROUP_UNSETINHERIT);
} }
@Override @Override
@ -27,15 +27,22 @@ public class GroupUnsetInherit extends GroupSubCommand {
} }
try { try {
if (args.size() == 2) { if (args.size() >= 2) {
final String server = args.get(1).toLowerCase(); final String server = args.get(1).toLowerCase();
if (Patterns.NON_ALPHA_NUMERIC.matcher(server).find()) { if (Patterns.NON_ALPHA_NUMERIC.matcher(server).find()) {
Message.SERVER_INVALID_ENTRY.send(sender); Message.SERVER_INVALID_ENTRY.send(sender);
return; return;
} }
group.unsetPermission("group." + groupName, server); if (args.size() == 2) {
Message.GROUP_UNSETINHERIT_SERVER_SUCCESS.send(sender, group.getName(), groupName, server); group.unsetPermission("group." + groupName, server);
Message.GROUP_UNSETINHERIT_SERVER_SUCCESS.send(sender, group.getName(), groupName, server);
} else {
final String world = args.get(2).toLowerCase();
group.unsetPermission("group." + groupName, server, world);
Message.GROUP_UNSETINHERIT_SERVER_WORLD_SUCCESS.send(sender, group.getName(), groupName, server, world);
}
} else { } else {
group.unsetPermission("group." + groupName); group.unsetPermission("group." + groupName);
Message.GROUP_UNSETINHERIT_SUCCESS.send(sender, group.getName(), groupName); Message.GROUP_UNSETINHERIT_SUCCESS.send(sender, group.getName(), groupName);
@ -54,6 +61,6 @@ public class GroupUnsetInherit extends GroupSubCommand {
@Override @Override
public boolean isArgLengthInvalid(int argLength) { public boolean isArgLengthInvalid(int argLength) {
return argLength != 1 && argLength != 2; return argLength != 1 && argLength != 2 && argLength != 3;
} }
} }

View File

@ -14,7 +14,7 @@ import java.util.List;
public class GroupUnsetTempInherit extends GroupSubCommand { public class GroupUnsetTempInherit extends GroupSubCommand {
public GroupUnsetTempInherit() { public GroupUnsetTempInherit() {
super("unsettempinherit", "Unsets another group for this group to inherit permissions from", super("unsettempinherit", "Unsets another group for this group to inherit permissions from",
"/%s group <group> unsettempinherit <group> [server]", Permission.GROUP_UNSET_TEMP_INHERIT); "/%s group <group> unsettempinherit <group> [server] [world]", Permission.GROUP_UNSET_TEMP_INHERIT);
} }
@Override @Override
@ -27,15 +27,22 @@ public class GroupUnsetTempInherit extends GroupSubCommand {
} }
try { try {
if (args.size() == 2) { if (args.size() >= 2) {
final String server = args.get(1).toLowerCase(); final String server = args.get(1).toLowerCase();
if (Patterns.NON_ALPHA_NUMERIC.matcher(server).find()) { if (Patterns.NON_ALPHA_NUMERIC.matcher(server).find()) {
Message.SERVER_INVALID_ENTRY.send(sender); Message.SERVER_INVALID_ENTRY.send(sender);
return; return;
} }
group.unsetPermission("group." + groupName, server, true); if (args.size() == 2) {
Message.GROUP_UNSET_TEMP_INHERIT_SERVER_SUCCESS.send(sender, group.getName(), groupName, server); group.unsetPermission("group." + groupName, server, true);
Message.GROUP_UNSET_TEMP_INHERIT_SERVER_SUCCESS.send(sender, group.getName(), groupName, server);
} else {
final String world = args.get(2).toLowerCase();
group.unsetPermission("group." + groupName, server, world, true);
Message.GROUP_UNSET_TEMP_INHERIT_SERVER_WORLD_SUCCESS.send(sender, group.getName(), groupName, server, world);
}
} else { } else {
group.unsetPermission("group." + groupName, true); group.unsetPermission("group." + groupName, true);
Message.GROUP_UNSET_TEMP_INHERIT_SUCCESS.send(sender, group.getName(), groupName); Message.GROUP_UNSET_TEMP_INHERIT_SUCCESS.send(sender, group.getName(), groupName);
@ -54,6 +61,6 @@ public class GroupUnsetTempInherit extends GroupSubCommand {
@Override @Override
public boolean isArgLengthInvalid(int argLength) { public boolean isArgLengthInvalid(int argLength) {
return argLength != 1 && argLength != 2; return argLength != 1 && argLength != 2 && argLength != 3;
} }
} }

View File

@ -14,7 +14,7 @@ import java.util.List;
public class GroupUnsetTempPermission extends GroupSubCommand { public class GroupUnsetTempPermission extends GroupSubCommand {
public GroupUnsetTempPermission() { public GroupUnsetTempPermission() {
super("unsettemp", "Unsets a temporary permission for a group", super("unsettemp", "Unsets a temporary permission for a group",
"/%s group <group> unsettemp <node> [server]", Permission.GROUP_UNSET_TEMP_PERMISSION); "/%s group <group> unsettemp <node> [server] [world]", Permission.GROUP_UNSET_TEMP_PERMISSION);
} }
@Override @Override
@ -32,15 +32,22 @@ public class GroupUnsetTempPermission extends GroupSubCommand {
} }
try { try {
if (args.size() == 2) { if (args.size() >= 2) {
final String server = args.get(1).toLowerCase(); final String server = args.get(1).toLowerCase();
if (Patterns.NON_ALPHA_NUMERIC.matcher(server).find()) { if (Patterns.NON_ALPHA_NUMERIC.matcher(server).find()) {
Message.SERVER_INVALID_ENTRY.send(sender); Message.SERVER_INVALID_ENTRY.send(sender);
return; return;
} }
group.unsetPermission(node, server); if (args.size() == 2) {
Message.UNSET_TEMP_PERMISSION_SERVER_SUCCESS.send(sender, node, group.getName(), server, true); group.unsetPermission(node, server);
Message.UNSET_TEMP_PERMISSION_SERVER_SUCCESS.send(sender, node, group.getName(), server);
} else {
final String world = args.get(2).toLowerCase();
group.unsetPermission(node, server, world);
Message.UNSET_TEMP_PERMISSION_SERVER_WORLD_SUCCESS.send(sender, node, group.getName(), server, world);
}
} else { } else {
group.unsetPermission(node, true); group.unsetPermission(node, true);
Message.UNSET_TEMP_PERMISSION_SUCCESS.send(sender, node, group.getName()); Message.UNSET_TEMP_PERMISSION_SUCCESS.send(sender, node, group.getName());
@ -54,6 +61,6 @@ public class GroupUnsetTempPermission extends GroupSubCommand {
@Override @Override
public boolean isArgLengthInvalid(int argLength) { public boolean isArgLengthInvalid(int argLength) {
return argLength != 1 && argLength != 2; return argLength != 1 && argLength != 2 && argLength != 3;
} }
} }

View File

@ -14,7 +14,7 @@ import java.util.List;
public class UserAddGroup extends UserSubCommand { public class UserAddGroup extends UserSubCommand {
public UserAddGroup() { public UserAddGroup() {
super("addgroup", "Adds the user to a group", "/%s user <user> addgroup <group> [server]", Permission.USER_ADDGROUP); super("addgroup", "Adds the user to a group", "/%s user <user> addgroup <group> [server] [world]", Permission.USER_ADDGROUP);
} }
@Override @Override
@ -37,15 +37,22 @@ public class UserAddGroup extends UserSubCommand {
} }
try { try {
if (args.size() == 2) { if (args.size() >= 2) {
final String server = args.get(1).toLowerCase(); final String server = args.get(1).toLowerCase();
if (Patterns.NON_ALPHA_NUMERIC.matcher(server).find()) { if (Patterns.NON_ALPHA_NUMERIC.matcher(server).find()) {
Message.SERVER_INVALID_ENTRY.send(sender); Message.SERVER_INVALID_ENTRY.send(sender);
return; return;
} }
user.addGroup(group, server); if (args.size() == 2) {
Message.USER_ADDGROUP_SERVER_SUCCESS.send(sender, user.getName(), groupName, server); user.addGroup(group, server);
Message.USER_ADDGROUP_SERVER_SUCCESS.send(sender, user.getName(), groupName, server);
} else {
final String world = args.get(2).toLowerCase();
user.addGroup(group, server, world);
Message.USER_ADDGROUP_SERVER_WORLD_SUCCESS.send(sender, user.getName(), groupName, server, world);
}
} else { } else {
user.addGroup(group); user.addGroup(group);
Message.USER_ADDGROUP_SUCCESS.send(sender, user.getName(), groupName); Message.USER_ADDGROUP_SUCCESS.send(sender, user.getName(), groupName);
@ -66,6 +73,6 @@ public class UserAddGroup extends UserSubCommand {
@Override @Override
public boolean isArgLengthInvalid(int argLength) { public boolean isArgLengthInvalid(int argLength) {
return (argLength != 1 && argLength != 2); return (argLength != 1 && argLength != 2 && argLength != 3);
} }
} }

View File

@ -15,8 +15,8 @@ import java.util.List;
public class UserAddTempGroup extends UserSubCommand { public class UserAddTempGroup extends UserSubCommand {
public UserAddTempGroup() { public UserAddTempGroup() {
super("addtempgroup", "Adds the user to a group temporarily", "/%s user <user> addtempgroup <group> <duration> [server]", super("addtempgroup", "Adds the user to a group temporarily",
Permission.USER_ADDTEMPGROUP); "/%s user <user> addtempgroup <group> <duration> [server] [world]", Permission.USER_ADDTEMPGROUP);
} }
@Override @Override
@ -52,16 +52,24 @@ public class UserAddTempGroup extends UserSubCommand {
} }
try { try {
if (args.size() == 3) { if (args.size() >= 3) {
final String server = args.get(2).toLowerCase(); final String server = args.get(2).toLowerCase();
if (Patterns.NON_ALPHA_NUMERIC.matcher(server).find()) { if (Patterns.NON_ALPHA_NUMERIC.matcher(server).find()) {
Message.SERVER_INVALID_ENTRY.send(sender); Message.SERVER_INVALID_ENTRY.send(sender);
return; return;
} }
user.addGroup(group, server, duration); if (args.size() == 3) {
Message.USER_ADDTEMPGROUP_SERVER_SUCCESS.send(sender, user.getName(), groupName, server, user.addGroup(group, server, duration);
DateUtil.formatDateDiff(duration)); Message.USER_ADDTEMPGROUP_SERVER_SUCCESS.send(sender, user.getName(), groupName, server,
DateUtil.formatDateDiff(duration));
} else {
final String world = args.get(3).toLowerCase();
user.addGroup(group, server, world, duration);
Message.USER_ADDTEMPGROUP_SERVER_WORLD_SUCCESS.send(sender, user.getName(), groupName, server,
world, DateUtil.formatDateDiff(duration));
}
} else { } else {
user.addGroup(group, duration); user.addGroup(group, duration);
Message.USER_ADDTEMPGROUP_SUCCESS.send(sender, user.getName(), groupName, DateUtil.formatDateDiff(duration)); Message.USER_ADDTEMPGROUP_SUCCESS.send(sender, user.getName(), groupName, DateUtil.formatDateDiff(duration));
@ -82,6 +90,6 @@ public class UserAddTempGroup extends UserSubCommand {
@Override @Override
public boolean isArgLengthInvalid(int argLength) { public boolean isArgLengthInvalid(int argLength) {
return (argLength != 2 && argLength != 3); return (argLength != 2 && argLength != 3 && argLength != 4);
} }
} }

View File

@ -14,7 +14,7 @@ import java.util.List;
public class UserHasPerm extends UserSubCommand { public class UserHasPerm extends UserSubCommand {
public UserHasPerm() { public UserHasPerm() {
super("haspermission", "Checks to see if a user has a certain permission node", super("haspermission", "Checks to see if a user has a certain permission node",
"/%s user <user> haspermission <node> [server]", Permission.USER_HASPERMISSION); "/%s user <user> haspermission <node> [server] [world]", Permission.USER_HASPERMISSION);
} }
@Override @Override
@ -25,7 +25,12 @@ public class UserHasPerm extends UserSubCommand {
return; return;
} }
Util.sendBoolean(sender, args.get(0), user.hasPermission(args.get(0), true, args.get(1))); if (args.size() == 2) {
Util.sendBoolean(sender, args.get(0), user.hasPermission(args.get(0), true, args.get(1)));
} else {
Util.sendBoolean(sender, args.get(0), user.hasPermission(args.get(0), true, args.get(1), args.get(2)));
}
} else { } else {
Util.sendBoolean(sender, args.get(0), user.hasPermission(args.get(0), true, "global")); Util.sendBoolean(sender, args.get(0), user.hasPermission(args.get(0), true, "global"));
} }
@ -33,6 +38,6 @@ public class UserHasPerm extends UserSubCommand {
@Override @Override
public boolean isArgLengthInvalid(int argLength) { public boolean isArgLengthInvalid(int argLength) {
return argLength != 1 && argLength != 2; return argLength != 1 && argLength != 2 && argLength != 3;
} }
} }

View File

@ -14,7 +14,7 @@ import java.util.List;
public class UserInheritsPerm extends UserSubCommand { public class UserInheritsPerm extends UserSubCommand {
public UserInheritsPerm() { public UserInheritsPerm() {
super("inheritspermission", "Checks to see if a user inherits a certain permission node", super("inheritspermission", "Checks to see if a user inherits a certain permission node",
"/%s user <user> inheritspermission <node> [server]", Permission.USER_INHERITSPERMISSION); "/%s user <user> inheritspermission <node> [server] [world]", Permission.USER_INHERITSPERMISSION);
} }
@Override @Override
@ -25,7 +25,12 @@ public class UserInheritsPerm extends UserSubCommand {
return; return;
} }
Util.sendBoolean(sender, args.get(0), user.inheritsPermission(args.get(0), true, args.get(1))); if (args.size() == 2) {
Util.sendBoolean(sender, args.get(0), user.inheritsPermission(args.get(0), true, args.get(1)));
} else {
Util.sendBoolean(sender, args.get(0), user.inheritsPermission(args.get(0), true, args.get(1), args.get(2)));
}
} else { } else {
Util.sendBoolean(sender, args.get(0), user.inheritsPermission(args.get(0), true)); Util.sendBoolean(sender, args.get(0), user.inheritsPermission(args.get(0), true));
} }
@ -33,6 +38,6 @@ public class UserInheritsPerm extends UserSubCommand {
@Override @Override
public boolean isArgLengthInvalid(int argLength) { public boolean isArgLengthInvalid(int argLength) {
return argLength != 1 && argLength != 2; return argLength != 1 && argLength != 2 && argLength != 3;
} }
} }

View File

@ -13,7 +13,7 @@ import java.util.List;
public class UserRemoveGroup extends UserSubCommand { public class UserRemoveGroup extends UserSubCommand {
public UserRemoveGroup() { public UserRemoveGroup() {
super("removegroup", "Removes a user from a group", "/%s user <user> removegroup <group> [server]", Permission.USER_REMOVEGROUP); super("removegroup", "Removes a user from a group", "/%s user <user> removegroup <group> [server] [world]", Permission.USER_REMOVEGROUP);
} }
@Override @Override
@ -32,15 +32,22 @@ public class UserRemoveGroup extends UserSubCommand {
} }
try { try {
if (args.size() == 2) { if (args.size() >= 2) {
final String server = args.get(1).toLowerCase(); final String server = args.get(1).toLowerCase();
if (Patterns.NON_ALPHA_NUMERIC.matcher(server).find()) { if (Patterns.NON_ALPHA_NUMERIC.matcher(server).find()) {
Message.SERVER_INVALID_ENTRY.send(sender); Message.SERVER_INVALID_ENTRY.send(sender);
return; return;
} }
user.unsetPermission("group." + groupName, server); if (args.size() == 2) {
Message.USER_REMOVEGROUP_SERVER_SUCCESS.send(sender, user.getName(), groupName, server); user.unsetPermission("group." + groupName, server);
Message.USER_REMOVEGROUP_SERVER_SUCCESS.send(sender, user.getName(), groupName, server);
} else {
final String world = args.get(2).toLowerCase();
user.unsetPermission("group." + groupName, server, world);
Message.USER_REMOVEGROUP_SERVER_WORLD_SUCCESS.send(sender, user.getName(), groupName, server, world);
}
} else { } else {
user.unsetPermission("group." + groupName); user.unsetPermission("group." + groupName);
Message.USER_REMOVEGROUP_SUCCESS.send(sender, user.getName(), groupName); Message.USER_REMOVEGROUP_SUCCESS.send(sender, user.getName(), groupName);
@ -59,6 +66,6 @@ public class UserRemoveGroup extends UserSubCommand {
@Override @Override
public boolean isArgLengthInvalid(int argLength) { public boolean isArgLengthInvalid(int argLength) {
return (argLength != 1 && argLength != 2); return (argLength != 1 && argLength != 2 && argLength != 3);
} }
} }

View File

@ -13,7 +13,8 @@ import java.util.List;
public class UserRemoveTempGroup extends UserSubCommand { public class UserRemoveTempGroup extends UserSubCommand {
public UserRemoveTempGroup() { public UserRemoveTempGroup() {
super("removetempgroup", "Removes a user from a temporary group", "/%s user <user> removetempgroup <group> [server]", Permission.USER_REMOVETEMPGROUP); super("removetempgroup", "Removes a user from a temporary group",
"/%s user <user> removetempgroup <group> [server] [world]", Permission.USER_REMOVETEMPGROUP);
} }
@Override @Override
@ -26,15 +27,22 @@ public class UserRemoveTempGroup extends UserSubCommand {
} }
try { try {
if (args.size() == 2) { if (args.size() >= 2) {
final String server = args.get(1).toLowerCase(); final String server = args.get(1).toLowerCase();
if (Patterns.NON_ALPHA_NUMERIC.matcher(server).find()) { if (Patterns.NON_ALPHA_NUMERIC.matcher(server).find()) {
Message.SERVER_INVALID_ENTRY.send(sender); Message.SERVER_INVALID_ENTRY.send(sender);
return; return;
} }
user.unsetPermission("group." + groupName, server, true); if (args.size() == 2) {
Message.USER_REMOVETEMPGROUP_SERVER_SUCCESS.send(sender, user.getName(), groupName, server); user.unsetPermission("group." + groupName, server, true);
Message.USER_REMOVETEMPGROUP_SERVER_SUCCESS.send(sender, user.getName(), groupName, server);
} else {
final String world = args.get(2).toLowerCase();
user.unsetPermission("group." + groupName, server, world, true);
Message.USER_REMOVETEMPGROUP_SERVER_WORLD_SUCCESS.send(sender, user.getName(), groupName, server, world);
}
} else { } else {
user.unsetPermission("group." + groupName, true); user.unsetPermission("group." + groupName, true);
Message.USER_REMOVETEMPGROUP_SUCCESS.send(sender, user.getName(), groupName); Message.USER_REMOVETEMPGROUP_SUCCESS.send(sender, user.getName(), groupName);
@ -53,6 +61,6 @@ public class UserRemoveTempGroup extends UserSubCommand {
@Override @Override
public boolean isArgLengthInvalid(int argLength) { public boolean isArgLengthInvalid(int argLength) {
return (argLength != 1 && argLength != 2); return (argLength != 1 && argLength != 2 && argLength != 3);
} }
} }

View File

@ -14,7 +14,7 @@ import java.util.List;
public class UserSetPermission extends UserSubCommand { public class UserSetPermission extends UserSubCommand {
public UserSetPermission() { public UserSetPermission() {
super("set", "Sets a permission for a user", super("set", "Sets a permission for a user",
"/%s user <user> set <node> <true|false> [server]", Permission.USER_SETPERMISSION); "/%s user <user> set <node> <true|false> [server] [world]", Permission.USER_SETPERMISSION);
} }
@Override @Override
@ -40,15 +40,22 @@ public class UserSetPermission extends UserSubCommand {
boolean b = Boolean.parseBoolean(bool); boolean b = Boolean.parseBoolean(bool);
try { try {
if (args.size() == 3) { if (args.size() >= 3) {
final String server = args.get(2).toLowerCase(); final String server = args.get(2).toLowerCase();
if (Patterns.NON_ALPHA_NUMERIC.matcher(server).find()) { if (Patterns.NON_ALPHA_NUMERIC.matcher(server).find()) {
Message.SERVER_INVALID_ENTRY.send(sender); Message.SERVER_INVALID_ENTRY.send(sender);
return; return;
} }
user.setPermission(node, b, server); if (args.size() == 3) {
Message.SETPERMISSION_SERVER_SUCCESS.send(sender, node, bool, user.getName(), server); user.setPermission(node, b, server);
Message.SETPERMISSION_SERVER_SUCCESS.send(sender, node, bool, user.getName(), server);
} else {
final String world = args.get(3).toLowerCase();
user.setPermission(node, b, server, world);
Message.SETPERMISSION_SERVER_WORLD_SUCCESS.send(sender, node, bool, user.getName(), server, world);
}
} else { } else {
user.setPermission(node, b); user.setPermission(node, b);
Message.SETPERMISSION_SUCCESS.send(sender, node, bool, user.getName()); Message.SETPERMISSION_SUCCESS.send(sender, node, bool, user.getName());
@ -67,6 +74,6 @@ public class UserSetPermission extends UserSubCommand {
@Override @Override
public boolean isArgLengthInvalid(int argLength) { public boolean isArgLengthInvalid(int argLength) {
return argLength != 2 && argLength != 3; return argLength != 2 && argLength != 3 && argLength != 4;
} }
} }

View File

@ -15,7 +15,7 @@ import java.util.List;
public class UserSetTempPermission extends UserSubCommand { public class UserSetTempPermission extends UserSubCommand {
public UserSetTempPermission() { public UserSetTempPermission() {
super("settemp", "Sets a temporary permission for a user", super("settemp", "Sets a temporary permission for a user",
"/%s user <user> settemp <node> <true|false> <duration> [server]", Permission.USER_SET_TEMP_PERMISSION); "/%s user <user> settemp <node> <true|false> <duration> [server] [world]", Permission.USER_SET_TEMP_PERMISSION);
} }
@Override @Override
@ -54,15 +54,22 @@ public class UserSetTempPermission extends UserSubCommand {
} }
try { try {
if (args.size() == 4) { if (args.size() >= 4) {
final String server = args.get(3).toLowerCase(); final String server = args.get(3).toLowerCase();
if (Patterns.NON_ALPHA_NUMERIC.matcher(server).find()) { if (Patterns.NON_ALPHA_NUMERIC.matcher(server).find()) {
Message.SERVER_INVALID_ENTRY.send(sender); Message.SERVER_INVALID_ENTRY.send(sender);
return; return;
} }
user.setPermission(node, b, server, duration); if (args.size() == 4) {
Message.SETPERMISSION_TEMP_SERVER_SUCCESS.send(sender, node, bool, user.getName(), server, DateUtil.formatDateDiff(duration)); user.setPermission(node, b, server, duration);
Message.SETPERMISSION_TEMP_SERVER_SUCCESS.send(sender, node, bool, user.getName(), server, DateUtil.formatDateDiff(duration));
} else {
final String world = args.get(4).toLowerCase();
user.setPermission(node, b, server, world, duration);
Message.SETPERMISSION_TEMP_SERVER_WORLD_SUCCESS.send(sender, node, bool, user.getName(), server, world, DateUtil.formatDateDiff(duration));
}
} else { } else {
user.setPermission(node, b, duration); user.setPermission(node, b, duration);
Message.SETPERMISSION_TEMP_SUCCESS.send(sender, node, bool, user.getName(), DateUtil.formatDateDiff(duration)); Message.SETPERMISSION_TEMP_SUCCESS.send(sender, node, bool, user.getName(), DateUtil.formatDateDiff(duration));
@ -81,6 +88,6 @@ public class UserSetTempPermission extends UserSubCommand {
@Override @Override
public boolean isArgLengthInvalid(int argLength) { public boolean isArgLengthInvalid(int argLength) {
return argLength != 3 && argLength != 4; return argLength != 3 && argLength != 4 && argLength != 5;
} }
} }

View File

@ -14,7 +14,7 @@ import java.util.List;
public class UserUnSetPermission extends UserSubCommand { public class UserUnSetPermission extends UserSubCommand {
public UserUnSetPermission() { public UserUnSetPermission() {
super("unset", "Unsets a permission for a user", super("unset", "Unsets a permission for a user",
"/%s user <user> unset <node> [server]", Permission.USER_UNSETPERMISSION); "/%s user <user> unset <node> [server] [world]", Permission.USER_UNSETPERMISSION);
} }
@Override @Override
@ -32,15 +32,22 @@ public class UserUnSetPermission extends UserSubCommand {
} }
try { try {
if (args.size() == 2) { if (args.size() >= 2) {
final String server = args.get(1).toLowerCase(); final String server = args.get(1).toLowerCase();
if (Patterns.NON_ALPHA_NUMERIC.matcher(server).find()) { if (Patterns.NON_ALPHA_NUMERIC.matcher(server).find()) {
Message.SERVER_INVALID_ENTRY.send(sender); Message.SERVER_INVALID_ENTRY.send(sender);
return; return;
} }
user.unsetPermission(node, server); if (args.size() == 2) {
Message.UNSETPERMISSION_SERVER_SUCCESS.send(sender, node, user.getName(), server); user.unsetPermission(node, server);
Message.UNSETPERMISSION_SERVER_SUCCESS.send(sender, node, user.getName(), server);
} else {
final String world = args.get(2).toLowerCase();
user.unsetPermission(node, server, world);
Message.UNSETPERMISSION_SERVER_WORLD_SUCCESS.send(sender, node, user.getName(), server, world);
}
} else { } else {
user.unsetPermission(node); user.unsetPermission(node);
Message.UNSETPERMISSION_SUCCESS.send(sender, node, user.getName()); Message.UNSETPERMISSION_SUCCESS.send(sender, node, user.getName());
@ -54,6 +61,6 @@ public class UserUnSetPermission extends UserSubCommand {
@Override @Override
public boolean isArgLengthInvalid(int argLength) { public boolean isArgLengthInvalid(int argLength) {
return argLength != 1 && argLength != 2; return argLength != 1 && argLength != 2 && argLength != 3;
} }
} }

View File

@ -14,7 +14,7 @@ import java.util.List;
public class UserUnsetTempPermission extends UserSubCommand { public class UserUnsetTempPermission extends UserSubCommand {
public UserUnsetTempPermission() { public UserUnsetTempPermission() {
super("unsettemp", "Unsets a temporary permission for a user", super("unsettemp", "Unsets a temporary permission for a user",
"/%s user <user> unsettemp <node> [server]", Permission.USER_UNSET_TEMP_PERMISSION); "/%s user <user> unsettemp <node> [server] [world]", Permission.USER_UNSET_TEMP_PERMISSION);
} }
@Override @Override
@ -32,15 +32,22 @@ public class UserUnsetTempPermission extends UserSubCommand {
} }
try { try {
if (args.size() == 2) { if (args.size() >= 2) {
final String server = args.get(1).toLowerCase(); final String server = args.get(1).toLowerCase();
if (Patterns.NON_ALPHA_NUMERIC.matcher(server).find()) { if (Patterns.NON_ALPHA_NUMERIC.matcher(server).find()) {
Message.SERVER_INVALID_ENTRY.send(sender); Message.SERVER_INVALID_ENTRY.send(sender);
return; return;
} }
user.unsetPermission(node, server, true); if (args.size() == 2) {
Message.UNSET_TEMP_PERMISSION_SERVER_SUCCESS.send(sender, node, user.getName(), server); user.unsetPermission(node, server, true);
Message.UNSET_TEMP_PERMISSION_SERVER_SUCCESS.send(sender, node, user.getName(), server);
} else {
final String world = args.get(2).toLowerCase();
user.unsetPermission(node, server, world, true);
Message.UNSET_TEMP_PERMISSION_SERVER_WORLD_SUCCESS.send(sender, node, user.getName(), server, world);
}
} else { } else {
user.unsetPermission(node, true); user.unsetPermission(node, true);
Message.UNSET_TEMP_PERMISSION_SUCCESS.send(sender, node, user.getName()); Message.UNSET_TEMP_PERMISSION_SUCCESS.send(sender, node, user.getName());
@ -54,6 +61,6 @@ public class UserUnsetTempPermission extends UserSubCommand {
@Override @Override
public boolean isArgLengthInvalid(int argLength) { public boolean isArgLengthInvalid(int argLength) {
return argLength != 1 && argLength != 2; return argLength != 1 && argLength != 2 && argLength != 3;
} }
} }

View File

@ -1,11 +1,9 @@
package me.lucko.luckperms.constants; package me.lucko.luckperms.constants;
import lombok.AllArgsConstructor;
import me.lucko.luckperms.commands.Sender; import me.lucko.luckperms.commands.Sender;
import me.lucko.luckperms.commands.Util; import me.lucko.luckperms.commands.Util;
@SuppressWarnings("SpellCheckingInspection") @SuppressWarnings("SpellCheckingInspection")
@AllArgsConstructor
public enum Message { public enum Message {
/** /**
@ -125,12 +123,16 @@ public enum Message {
LISTNODES_TEMP("&e%s's Temporary Nodes:" + "\n" + "%s", true), LISTNODES_TEMP("&e%s's Temporary Nodes:" + "\n" + "%s", true),
SETPERMISSION_SUCCESS("&aSet &b%s&a to &b%s&a for &b%s&a.", 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), SETPERMISSION_SERVER_SUCCESS("&aSet &b%s&a to &b%s&a for &b%s&a on server &b%s&a.", true),
SETPERMISSION_SERVER_WORLD_SUCCESS("&aSet &b%s&a to &b%s&a for &b%s&a on server &b%s&a, world &b%s&a.", true),
SETPERMISSION_TEMP_SUCCESS("&aSet &b%s&a to &b%s&a for &b%s&a for a duration of &b%s&a.", true), SETPERMISSION_TEMP_SUCCESS("&aSet &b%s&a to &b%s&a for &b%s&a for a duration of &b%s&a.", true),
SETPERMISSION_TEMP_SERVER_SUCCESS("&aSet &b%s&a to &b%s&a for &b%s&a on server &b%s&a for a duration of &b%s&a.", true), SETPERMISSION_TEMP_SERVER_SUCCESS("&aSet &b%s&a to &b%s&a for &b%s&a on server &b%s&a for a duration of &b%s&a.", true),
SETPERMISSION_TEMP_SERVER_WORLD_SUCCESS("&aSet &b%s&a to &b%s&a for &b%s&a on server &b%s&a, world &b%s&a, for a duration of &b%s&a.", true),
UNSETPERMISSION_SUCCESS("&aUnset &b%s&a for &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), UNSETPERMISSION_SERVER_SUCCESS("&aUnset &b%s&a for &b%s&a on server &b%$s&a.", true),
UNSETPERMISSION_SERVER_WORLD_SUCCESS("&aUnset &b%s&a for &b%s&a on server &b%$s&a, world &b%$s&a.", true),
UNSET_TEMP_PERMISSION_SUCCESS("&aUnset temporary permission &b%s&a for &b%s&a.", true), UNSET_TEMP_PERMISSION_SUCCESS("&aUnset temporary permission &b%s&a for &b%s&a.", true),
UNSET_TEMP_PERMISSION_SERVER_SUCCESS("&aUnset temporary permission &b%s&a for &b%s&a on server &b%$s&a.", true), UNSET_TEMP_PERMISSION_SERVER_SUCCESS("&aUnset temporary permission &b%s&a for &b%s&a on server &b%$s&a.", true),
UNSET_TEMP_PERMISSION_SERVER_WORLD_SUCCESS("&aUnset temporary permission &b%s&a for &b%s&a on server &b%$s&a, world &b%$s&a.", true),
CLEAR_SUCCESS("&b%s&a's permissions were cleared.", true), CLEAR_SUCCESS("&b%s&a's permissions were cleared.", true),
ILLEGAL_DATE_ERROR("Could not parse date '%s'.", true), ILLEGAL_DATE_ERROR("Could not parse date '%s'.", true),
PAST_DATE_ERROR("You cannot set a date in the past!", true), PAST_DATE_ERROR("You cannot set a date in the past!", true),
@ -149,12 +151,16 @@ public enum Message {
USER_GETUUID("&bThe UUID of &e%s&b is &e%s&b.", true), 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_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_ADDGROUP_SERVER_SUCCESS("&b%s&a successfully added to group &b%s&a on server &b%s&a.", true),
USER_ADDGROUP_SERVER_WORLD_SUCCESS("&b%s&a successfully added to group &b%s&a on server &b%s&a, world &b%s&a.", true),
USER_ADDTEMPGROUP_SUCCESS("&b%s&a successfully added to group &b%s&a for a duration of &b%s&a.", true), USER_ADDTEMPGROUP_SUCCESS("&b%s&a successfully added to group &b%s&a for a duration of &b%s&a.", true),
USER_ADDTEMPGROUP_SERVER_SUCCESS("&b%s&a successfully added to group &b%s&a on server &b%s&a for a duration of &b%s&a.", true), USER_ADDTEMPGROUP_SERVER_SUCCESS("&b%s&a successfully added to group &b%s&a on server &b%s&a for a duration of &b%s&a.", true),
USER_ADDTEMPGROUP_SERVER_WORLD_SUCCESS("&b%s&a successfully added to group &b%s&a on server &b%s&a, world &b%s&a, for a duration of &b%s&a.", true),
USER_REMOVEGROUP_SUCCESS("&b%s&a was removed from group &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_SERVER_SUCCESS("&b%s&a was removed from group &b%s&a on server &b%s&a.", true),
USER_REMOVEGROUP_SERVER_WORLD_SUCCESS("&b%s&a was removed from group &b%s&a on server &b%s&a, world &b%s&a.", true),
USER_REMOVETEMPGROUP_SUCCESS("&b%s&a was removed from temproary group &b%s&a.", true), USER_REMOVETEMPGROUP_SUCCESS("&b%s&a was removed from temproary group &b%s&a.", true),
USER_REMOVETEMPGROUP_SERVER_SUCCESS("&b%s&a was removed from temporary group &b%s&a on server &b%s&a.", true), USER_REMOVETEMPGROUP_SERVER_SUCCESS("&b%s&a was removed from temporary group &b%s&a on server &b%s&a.", true),
USER_REMOVETEMPGROUP_SERVER_WORLD_SUCCESS("&b%s&a was removed from temporary group &b%s&a on server &b%s&a, world &b%s&a.", true),
USER_REMOVEGROUP_ERROR_PRIMARY("You cannot remove a user from their primary group.", 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_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_ALREADYHAS("The user already has this group set as their primary group.", true),
@ -189,12 +195,16 @@ public enum Message {
), ),
GROUP_SETINHERIT_SUCCESS("&b%s&a now inherits permissions from &b%s&a.", true), 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_SETINHERIT_SERVER_SUCCESS("&b%s&a now inherits permissions from &b%s&a on server &b%s&a.", true),
GROUP_SETINHERIT_SERVER_WORLD_SUCCESS("&b%s&a now inherits permissions from &b%s&a on server &b%s&a, world &b%s&a.", true),
GROUP_SET_TEMP_INHERIT_SUCCESS("&b%s&a now inherits permissions from &b%s&a for a duration of &b%s&a.", true), GROUP_SET_TEMP_INHERIT_SUCCESS("&b%s&a now inherits permissions from &b%s&a for a duration of &b%s&a.", true),
GROUP_SET_TEMP_INHERIT_SERVER_SUCCESS("&b%s&a now inherits permissions from &b%s&a on server &b%s&a for a duration of &b%s&a.", true), GROUP_SET_TEMP_INHERIT_SERVER_SUCCESS("&b%s&a now inherits permissions from &b%s&a on server &b%s&a for a duration of &b%s&a.", true),
GROUP_SET_TEMP_INHERIT_SERVER_WORLD_SUCCESS("&b%s&a now inherits permissions from &b%s&a on server &b%s&a, world &b%s&a, for a duration of &b%s&a.", true),
GROUP_UNSETINHERIT_SUCCESS("&b%s&a no longer inherits permissions from &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), GROUP_UNSETINHERIT_SERVER_SUCCESS("&b%s&a no longer inherits permissions from &b%s&a on server &b%s&a.", true),
GROUP_UNSETINHERIT_SERVER_WORLD_SUCCESS("&b%s&a no longer inherits permissions from &b%s&a on server &b%s&a, world &b%s&a.", true),
GROUP_UNSET_TEMP_INHERIT_SUCCESS("&b%s&a no longer temporarily inherits permissions from &b%s&a.", true), GROUP_UNSET_TEMP_INHERIT_SUCCESS("&b%s&a no longer temporarily inherits permissions from &b%s&a.", true),
GROUP_UNSET_TEMP_INHERIT_SERVER_SUCCESS("&b%s&a no longer temporarily inherits permissions from &b%s&a on server &b%s&a.", true), GROUP_UNSET_TEMP_INHERIT_SERVER_SUCCESS("&b%s&a no longer temporarily inherits permissions from &b%s&a on server &b%s&a.", true),
GROUP_UNSET_TEMP_INHERIT_SERVER_WORLD_SUCCESS("&b%s&a no longer temporarily inherits permissions from &b%s&a on server &b%s&a, world &b%s&a.", true),
TRACK_INFO( TRACK_INFO(
PREFIX + "&d-> &eTrack: &6%s" + "\n" + PREFIX + "&d-> &eTrack: &6%s" + "\n" +
@ -211,6 +221,11 @@ public enum Message {
private String message; private String message;
private boolean showPrefix; private boolean showPrefix;
Message(String message, boolean showPrefix) {
this.message = Util.color(message);
this.showPrefix = showPrefix;
}
@Override @Override
public String toString() { public String toString() {
return message; return message;
@ -218,9 +233,9 @@ public enum Message {
public void send(Sender sender, Object... objects) { public void send(Sender sender, Object... objects) {
if (showPrefix) { if (showPrefix) {
sender.sendMessage(Util.color(PREFIX + String.format(message, objects))); sender.sendMessage(PREFIX + String.format(message, objects));
} else { } else {
sender.sendMessage(Util.color(String.format(message, objects))); sender.sendMessage(String.format(message, objects));
} }
} }
} }

View File

@ -11,7 +11,9 @@ import me.lucko.luckperms.groups.Group;
import me.lucko.luckperms.utils.Patterns; import me.lucko.luckperms.utils.Patterns;
import me.lucko.luckperms.utils.PermissionObject; import me.lucko.luckperms.utils.PermissionObject;
import java.util.*; import java.util.List;
import java.util.Map;
import java.util.UUID;
import java.util.stream.Collectors; import java.util.stream.Collectors;
@ToString(of = {"uuid"}) @ToString(of = {"uuid"})
@ -74,6 +76,17 @@ public abstract class User extends PermissionObject {
return hasPermission("group." + group.getName(), true, server); return hasPermission("group." + group.getName(), true, server);
} }
/**
* Check to see if a user is a member of a group on a specific server
* @param group The group to check membership of
* @param server The server to check on
* @param world The world to check on
* @return true if the user is a member of the group
*/
public boolean isInGroup(Group group, String server, String world) {
return hasPermission("group." + group.getName(), true, server, world);
}
/** /**
* Add a user to a group * Add a user to a group
* @param group The group to add the user to * @param group The group to add the user to
@ -97,6 +110,21 @@ public abstract class User extends PermissionObject {
setPermission("group." + group.getName(), true, server); setPermission("group." + group.getName(), true, server);
} }
/**
* Add a user to a group on a specific server
* @param group The group to add the user to
* @param server The server to add the group on
* @param world The world to add the group on
* @throws ObjectAlreadyHasException if the user is already a member of the group on that server
*/
public void addGroup(Group group, String server, String world) throws ObjectAlreadyHasException {
if (server == null) {
server = "global";
}
setPermission("group." + group.getName(), true, server, world);
}
/** /**
* Add a user to a group on a specific server * Add a user to a group on a specific server
* @param group The group to add the user to * @param group The group to add the user to
@ -122,6 +150,22 @@ public abstract class User extends PermissionObject {
setPermission("group." + group.getName(), true, server, expireAt); setPermission("group." + group.getName(), true, server, expireAt);
} }
/**
* Add a user to a group on a specific server
* @param group The group to add the user to
* @param server The server to add the group on
* @param world The world to add the group on
* @param expireAt when the group should expire
* @throws ObjectAlreadyHasException if the user is already a member of the group on that server
*/
public void addGroup(Group group, String server, String world, long expireAt) throws ObjectAlreadyHasException {
if (server == null) {
server = "global";
}
setPermission("group." + group.getName(), true, server, world, expireAt);
}
/** /**
* Remove the user from a group * Remove the user from a group
* @param group the group to remove the user from * @param group the group to remove the user from
@ -155,6 +199,21 @@ public abstract class User extends PermissionObject {
unsetPermission("group." + group.getName(), server); unsetPermission("group." + group.getName(), server);
} }
/**
* Remove the user from a group
* @param group The group to remove the user from
* @param server The server to remove the group on
* @param world The world to remove the group on
* @throws ObjectLacksException if the user isn't a member of the group
*/
public void removeGroup(Group group, String server, String world) throws ObjectLacksException {
if (server == null) {
server = "global";
}
unsetPermission("group." + group.getName(), server, world);
}
/** /**
* Remove the user from a group * Remove the user from a group
* @param group The group to remove the user from * @param group The group to remove the user from
@ -170,6 +229,22 @@ public abstract class User extends PermissionObject {
unsetPermission("group." + group.getName(), server, temporary); unsetPermission("group." + group.getName(), server, temporary);
} }
/**
* Remove the user from a group
* @param group The group to remove the user from
* @param server The server to remove the group on
* @param world The world to remove the group on
* @param temporary if the group being removed is temporary
* @throws ObjectLacksException if the user isn't a member of the group
*/
public void removeGroup(Group group, String server, String world, boolean temporary) throws ObjectLacksException {
if (server == null) {
server = "global";
}
unsetPermission("group." + group.getName(), server, world, temporary);
}
/** /**
* Clear all of the users permission nodes * Clear all of the users permission nodes
*/ */
@ -187,96 +262,38 @@ public abstract class User extends PermissionObject {
return getGroups(null, null, true); return getGroups(null, null, true);
} }
/**
* Get a {@link List} of the groups the user is a member of on a specific server
* @param server the server to check
* @return a {@link List} of group names
*/
public List<String> getLocalGroups(String server, String world) {
return getGroups(server, world, false);
}
/** /**
* Get a {@link List} of the groups the user is a member of on a specific server * Get a {@link List} of the groups the user is a member of on a specific server
* @param server the server to check * @param server the server to check
* @return a {@link List} of group names * @return a {@link List} of group names
*/ */
public List<String> getLocalGroups(String server) { public List<String> getLocalGroups(String server) {
return getGroups(server, null, false); return getLocalGroups(server, null);
} }
/** /**
* Get a {@link List} of the groups the user is a member of on a specific server with the option to include global * Get a {@link List} of the groups the user is a member of on a specific server with the option to include global
* groups or all groups * groups or all groups
* @param server Which server to check on * @param server Which server to check on
* @param excludedGroups groups to exclude (prevents circular inheritance issues) * @param world Which world to check on
* @param includeGlobal Whether to include global groups * @param includeGlobal Whether to include global groups
* @return a {@link List} of group names * @return a {@link List} of group names
*/ */
private List<String> getGroups(String server, List<String> excludedGroups, boolean includeGlobal) { private List<String> getGroups(String server, String world, boolean includeGlobal) {
if (excludedGroups == null) { // Call super #getPermissions method, and just sort through those
excludedGroups = new ArrayList<>(); Map<String, Boolean> perms = getPermissions(server, world, null, includeGlobal);
} return perms.keySet().stream()
.filter(s -> Patterns.GROUP_MATCH.matcher(s).matches())
excludedGroups.add(getObjectName()); .map(s -> Patterns.DOT_SPLIT.split(s, 2)[1])
List<String> groups = new ArrayList<>(); .collect(Collectors.toList());
if (server == null || server.equals("")) {
server = "global";
}
/*
Priority:
1. server specific group nodes
2. group nodes
*/
final Map<String, Boolean> serverSpecificGroups = new HashMap<>();
final Map<String, Boolean> groupNodes = new HashMap<>();
// Sorts the permissions and puts them into a priority order
for (Map.Entry<String, Boolean> node : convertTemporaryPerms().entrySet()) {
serverSpecific:
if (node.getKey().contains("/")) {
String[] parts = Patterns.SERVER_SPLIT.split(node.getKey(), 2);
if (parts[0].equalsIgnoreCase("global")) {
// REGULAR
break serverSpecific;
}
if (!parts[0].equalsIgnoreCase(server)) {
// SERVER SPECIFIC BUT DOES NOT APPLY
continue;
}
if (Patterns.GROUP_MATCH.matcher(parts[1]).matches()) {
// SERVER SPECIFIC AND GROUP
serverSpecificGroups.put(node.getKey(), node.getValue());
continue;
}
continue;
}
// Skip adding global permissions if they are not requested
if (!includeGlobal) continue;
if (Patterns.GROUP_MATCH.matcher(node.getKey()).matches()) {
// GROUP
groupNodes.put(node.getKey(), node.getValue());
}
}
// If a group is negated at a higher priority, the group should not then be applied at a lower priority
serverSpecificGroups.entrySet().stream().filter(node -> !node.getValue()).forEach(node -> {
groupNodes.remove(node.getKey());
groupNodes.remove(Patterns.SERVER_SPLIT.split(node.getKey(), 2)[1]);
});
groups.addAll(serverSpecificGroups.entrySet().stream()
.filter(Map.Entry::getValue)
.map(e -> Patterns.DOT_SPLIT.split(e.getKey(), 2)[1])
.collect(Collectors.toList())
);
groups.addAll(groupNodes.entrySet().stream()
.filter(Map.Entry::getValue)
.map(e -> Patterns.DOT_SPLIT.split(e.getKey(), 2)[1])
.collect(Collectors.toList())
);
return groups;
} }
} }

View File

@ -7,6 +7,7 @@ import java.util.regex.Pattern;
@UtilityClass @UtilityClass
public class Patterns { public class Patterns {
public static final Pattern SERVER_SPLIT = Pattern.compile("\\/"); public static final Pattern SERVER_SPLIT = Pattern.compile("\\/");
public static final Pattern WORLD_SPLIT = Pattern.compile("\\-");
public static final Pattern TEMP_SPLIT = Pattern.compile("\\$"); public static final Pattern TEMP_SPLIT = Pattern.compile("\\$");
public static final Pattern DOT_SPLIT = Pattern.compile("\\."); public static final Pattern DOT_SPLIT = Pattern.compile("\\.");
public static final Pattern GROUP_MATCH = Pattern.compile("group\\..*"); public static final Pattern GROUP_MATCH = Pattern.compile("group\\..*");

View File

@ -89,6 +89,18 @@ public abstract class PermissionObject {
return hasPermission(server + "/" + node, b); return hasPermission(server + "/" + node, b);
} }
/**
* Checks to see the the object has a permission on a certain server
* @param node The permission node
* @param b If the node is true/false(negated)
* @param server The server
* @param world The world
* @return true if the user has the permission
*/
public boolean hasPermission(String node, boolean b, String server, String world) {
return hasPermission(server + "-" + world + "/" + node, b);
}
/** /**
* Checks to see the the object has a permission on a certain server * Checks to see the the object has a permission on a certain server
* @param node The permission node * @param node The permission node
@ -100,6 +112,31 @@ public abstract class PermissionObject {
return hasPermission(node + (temporary ? "$a" : ""), b); return hasPermission(node + (temporary ? "$a" : ""), b);
} }
/**
* Checks to see the the object has a permission on a certain server
* @param node The permission node
* @param b If the node is true/false(negated)
* @param server The server to check on
* @param temporary if the permission is temporary
* @return true if the user has the permission
*/
public boolean hasPermission(String node, boolean b, String server, boolean temporary) {
return hasPermission(server + "/" + node + (temporary ? "$a" : ""), b);
}
/**
* Checks to see the the object has a permission on a certain server
* @param node The permission node
* @param b If the node is true/false(negated)
* @param server The server to check on
* @param world The world to check on
* @param temporary if the permission is temporary
* @return true if the user has the permission
*/
public boolean hasPermission(String node, boolean b, String server, String world, boolean temporary) {
return hasPermission(server + "-" + world + "/" + node + (temporary ? "$a" : ""), b);
}
/** /**
* Checks to see if the object inherits a certain permission * Checks to see if the object inherits a certain permission
* @param node The permission node * @param node The permission node
@ -124,10 +161,29 @@ public abstract class PermissionObject {
* @return true if the user inherits the permission * @return true if the user inherits the permission
*/ */
public boolean inheritsPermission(String node, boolean b, String server) { public boolean inheritsPermission(String node, boolean b, String server) {
if (server.contains("-")) {
// Use other method
final String[] parts = Patterns.WORLD_SPLIT.split(server, 2);
return inheritsPermission(node, b, parts[0], parts[1]);
}
final Map<String, Boolean> local = getLocalPermissions(server, null); final Map<String, Boolean> local = getLocalPermissions(server, null);
return hasPermission(local, node, b); return hasPermission(local, node, b);
} }
/**
* Checks to see the the object inherits a permission on a certain server
* @param node The permission node
* @param b If the node is true/false(negated)
* @param server The server
* @param world The world
* @return true if the user inherits the permission
*/
public boolean inheritsPermission(String node, boolean b, String server, String world) {
final Map<String, Boolean> local = getLocalPermissions(server, world, null);
return hasPermission(local, node, b);
}
/** /**
* Checks to see if the object inherits a certain permission * Checks to see if the object inherits a certain permission
* @param node The permission node * @param node The permission node
@ -139,6 +195,31 @@ public abstract class PermissionObject {
return inheritsPermission(node + (temporary ? "$a" : ""), b); return inheritsPermission(node + (temporary ? "$a" : ""), b);
} }
/**
* Checks to see if the object inherits a certain permission
* @param node The permission node
* @param b If the node is true/false(negated)
* @param server The server
* @param temporary if the permission is temporary
* @return true if the user inherits the permission
*/
public boolean inheritsPermission(String node, boolean b, String server, boolean temporary) {
return inheritsPermission(server + "/" + node + (temporary ? "$a" : ""), b);
}
/**
* Checks to see if the object inherits a certain permission
* @param node The permission node
* @param b If the node is true/false(negated)
* @param server The server
* @param world The world
* @param temporary if the permission is temporary
* @return true if the user inherits the permission
*/
public boolean inheritsPermission(String node, boolean b, String server, String world, boolean temporary) {
return inheritsPermission(server + "-" + world + "/" + node + (temporary ? "$a" : ""), b);
}
/** /**
* Sets a permission for the object * Sets a permission for the object
* @param node The node to be set * @param node The node to be set
@ -164,6 +245,18 @@ public abstract class PermissionObject {
setPermission(server + "/" + node, value); setPermission(server + "/" + node, value);
} }
/**
* Sets a permission for the object
* @param node The node to set
* @param value What to set the node to - true/false(negated)
* @param server The server to set the permission on
* @param world The world to set the permission on
* @throws ObjectAlreadyHasException if the object already has the permission
*/
public void setPermission(String node, boolean value, String server, String world) throws ObjectAlreadyHasException {
setPermission(server + "-" + world + "/" + node, value);
}
/** /**
* Sets a permission for the object * Sets a permission for the object
* @param node The node to set * @param node The node to set
@ -187,6 +280,19 @@ public abstract class PermissionObject {
setPermission(node + "$" + expireAt, value, server); setPermission(node + "$" + expireAt, value, server);
} }
/**
* Sets a permission for the object
* @param node The node to set
* @param value What to set the node to - true/false(negated)
* @param server The server to set the permission on
* @param world The world to set the permission on
* @param expireAt The time in unixtime when the permission will expire
* @throws ObjectAlreadyHasException if the object already has the permission
*/
public void setPermission(String node, boolean value, String server, String world, long expireAt) throws ObjectAlreadyHasException {
setPermission(node + "$" + expireAt, value, server, world);
}
/** /**
* Unsets a permission for the object * Unsets a permission for the object
* @param node The node to be unset * @param node The node to be unset
@ -234,6 +340,17 @@ public abstract class PermissionObject {
unsetPermission(server + "/" + node); unsetPermission(server + "/" + node);
} }
/**
* Unsets a permission for the object
* @param node The node to be unset
* @param server The server to unset the node on
* @param world The world to unset the node on
* @throws ObjectLacksException if the node wasn't already set
*/
public void unsetPermission(String node, String server, String world) throws ObjectLacksException {
unsetPermission(server + "-" + world + "/" + node);
}
/** /**
* Unsets a permission for the object * Unsets a permission for the object
* @param node The node to be unset * @param node The node to be unset
@ -245,6 +362,29 @@ public abstract class PermissionObject {
unsetPermission(server + "/" + node, temporary); unsetPermission(server + "/" + node, temporary);
} }
/**
* Unsets a permission for the object
* @param node The node to be unset
* @param server The server to unset the node on
* @param world The world to unset the node on
* @param temporary if the permission being unset is temporary
* @throws ObjectLacksException if the node wasn't already set
*/
public void unsetPermission(String node, String server, String world, boolean temporary) throws ObjectLacksException {
unsetPermission(server + "-" + world + "/" + node, temporary);
}
/**
* Gets the permissions and inherited permissions that apply to a specific server
* @param server The server to get nodes for
* @param world The world to get nodes for
* @param excludedGroups Groups that shouldn't be inherited (to prevent circular inheritance issues)
* @return a {@link Map} of the permissions
*/
public Map<String, Boolean> getLocalPermissions(String server, String world, List<String> excludedGroups) {
return getPermissions(server, world, excludedGroups, plugin.getConfiguration().getIncludeGlobalPerms());
}
/** /**
* Gets the permissions and inherited permissions that apply to a specific server * Gets the permissions and inherited permissions that apply to a specific server
* @param server The server to get nodes for * @param server The server to get nodes for
@ -252,7 +392,7 @@ public abstract class PermissionObject {
* @return a {@link Map} of the permissions * @return a {@link Map} of the permissions
*/ */
public Map<String, Boolean> getLocalPermissions(String server, List<String> excludedGroups) { public Map<String, Boolean> getLocalPermissions(String server, List<String> excludedGroups) {
return getPermissions(server, excludedGroups, plugin.getConfiguration().getIncludeGlobalPerms()); return getLocalPermissions(server, null, excludedGroups);
} }
/** /**
@ -287,7 +427,7 @@ public abstract class PermissionObject {
.forEach(s -> this.nodes.remove(s)); .forEach(s -> this.nodes.remove(s));
} }
protected Map<String, Boolean> convertTemporaryPerms() { private Map<String, Boolean> convertTemporaryPerms() {
auditTemporaryPermissions(); auditTemporaryPermissions();
Map<String, Boolean> nodes = new HashMap<>(); Map<String, Boolean> nodes = new HashMap<>();
@ -306,7 +446,7 @@ public abstract class PermissionObject {
return nodes; return nodes;
} }
private Map<String, Boolean> getPermissions(String server, List<String> excludedGroups, boolean includeGlobal) { protected Map<String, Boolean> getPermissions(String server, String world, List<String> excludedGroups, boolean includeGlobal) {
if (excludedGroups == null) { if (excludedGroups == null) {
excludedGroups = new ArrayList<>(); excludedGroups = new ArrayList<>();
} }
@ -318,17 +458,25 @@ public abstract class PermissionObject {
server = "global"; server = "global";
} }
if (world != null && world.equalsIgnoreCase("")) {
world = null;
}
/* /*
Priority: Priority:
1. server specific nodes 1. server+world specific nodes
2. user nodes 2. server specific nodes
3. server specific group nodes 3. user nodes
4. group nodes 4. server+world specific group nodes
5. server specific group nodes
6. group nodes
*/ */
final Map<String, Boolean> serverWorldSpecificNodes = new HashMap<>();
final Map<String, Boolean> serverSpecificNodes = new HashMap<>(); final Map<String, Boolean> serverSpecificNodes = new HashMap<>();
final Map<String, Boolean> userNodes = new HashMap<>(); final Map<String, Boolean> userNodes = new HashMap<>();
final Map<String, Boolean> serverWorldSpecificGroups = new HashMap<>();
final Map<String, Boolean> serverSpecificGroups = new HashMap<>(); final Map<String, Boolean> serverSpecificGroups = new HashMap<>();
final Map<String, Boolean> groupNodes = new HashMap<>(); final Map<String, Boolean> groupNodes = new HashMap<>();
@ -337,6 +485,33 @@ public abstract class PermissionObject {
serverSpecific: serverSpecific:
if (node.getKey().contains("/")) { if (node.getKey().contains("/")) {
String[] parts = Patterns.SERVER_SPLIT.split(node.getKey(), 2); String[] parts = Patterns.SERVER_SPLIT.split(node.getKey(), 2);
// 0=server(+world) 1=node
// WORLD SPECIFIC
if (parts[0].contains("-")) {
String[] serverParts = Patterns.WORLD_SPLIT.split(parts[0], 2);
// 0=server 1=world
if ((!serverParts[0].equalsIgnoreCase("global") || !includeGlobal) && (!serverParts[0].equalsIgnoreCase(server))) {
// GLOBAL AND UNWANTED OR SERVER SPECIFIC BUT DOES NOT APPLY :(((
continue;
}
if (world != null && !serverParts[1].equalsIgnoreCase(world)) {
// WORLD SPECIFIC BUT DOES NOT APPLY
continue;
}
if (Patterns.GROUP_MATCH.matcher(parts[1]).matches()) {
// SERVER+WORLD SPECIFIC AND GROUP
serverWorldSpecificGroups.put(node.getKey(), node.getValue());
continue;
}
// SERVER+WORLD SPECIFIC
serverWorldSpecificNodes.put(node.getKey(), node.getValue());
continue;
}
if (parts[0].equalsIgnoreCase("global")) { if (parts[0].equalsIgnoreCase("global")) {
// REGULAR // REGULAR
@ -362,17 +537,30 @@ public abstract class PermissionObject {
// Skip adding global permissions if they are not requested // Skip adding global permissions if they are not requested
if (!includeGlobal) continue; if (!includeGlobal) continue;
if (Patterns.GROUP_MATCH.matcher(node.getKey()).matches()) { // Could be here if the server was set to global.
String n = node.getKey();
if (n.contains("/")) {
n = Patterns.SERVER_SPLIT.split(n, 2)[0];
}
if (Patterns.GROUP_MATCH.matcher(n).matches()) {
// GROUP // GROUP
groupNodes.put(node.getKey(), node.getValue()); groupNodes.put(n, node.getValue());
continue; continue;
} }
// JUST NORMAL // JUST NORMAL
userNodes.put(node.getKey(), node.getValue()); userNodes.put(n, node.getValue());
} }
// If a group is negated at a higher priority, the group should not then be applied at a lower priority // If a group is negated at a higher priority, the group should not then be applied at a lower priority
serverWorldSpecificGroups.entrySet().stream().filter(node -> !node.getValue()).forEach(node -> {
groupNodes.remove(node.getKey());
groupNodes.remove(Patterns.SERVER_SPLIT.split(node.getKey(), 2)[1]);
serverSpecificGroups.remove(node.getKey());
serverSpecificGroups.remove(Patterns.SERVER_SPLIT.split(node.getKey(), 2)[1]);
serverSpecificGroups.remove(Patterns.WORLD_SPLIT.split(node.getKey(), 2)[0] + "/" + Patterns.SERVER_SPLIT.split(node.getKey(), 2)[1]);
});
serverSpecificGroups.entrySet().stream().filter(node -> !node.getValue()).forEach(node -> { serverSpecificGroups.entrySet().stream().filter(node -> !node.getValue()).forEach(node -> {
groupNodes.remove(node.getKey()); groupNodes.remove(node.getKey());
groupNodes.remove(Patterns.SERVER_SPLIT.split(node.getKey(), 2)[1]); groupNodes.remove(Patterns.SERVER_SPLIT.split(node.getKey(), 2)[1]);
@ -399,24 +587,26 @@ public abstract class PermissionObject {
} }
} }
// Apply next priority: serverSpecificGroups // Apply next priorities: serverSpecificGroups and then serverWorldSpecificGroups
for (Map.Entry<String, Boolean> groupNode : serverSpecificGroups.entrySet()) { for (Map<String, Boolean> m : Arrays.asList(serverSpecificGroups, serverWorldSpecificGroups)) {
final String rawNode = Patterns.SERVER_SPLIT.split(groupNode.getKey())[1]; for (Map.Entry<String, Boolean> groupNode : m.entrySet()) {
final String rawNode = Patterns.SERVER_SPLIT.split(groupNode.getKey())[1];
// Add the actual group perm node, so other plugins can hook // Add the actual group perm node, so other plugins can hook
perms.put(rawNode, groupNode.getValue()); perms.put(rawNode, groupNode.getValue());
// Don't add negated groups // Don't add negated groups
if (!groupNode.getValue()) continue; if (!groupNode.getValue()) continue;
String groupName = Patterns.DOT_SPLIT.split(rawNode, 2)[1]; String groupName = Patterns.DOT_SPLIT.split(rawNode, 2)[1];
if (!excludedGroups.contains(groupName)) { if (!excludedGroups.contains(groupName)) {
Group group = plugin.getGroupManager().getGroup(groupName); Group group = plugin.getGroupManager().getGroup(groupName);
if (group != null) { if (group != null) {
perms.putAll(group.getLocalPermissions(server, excludedGroups)); perms.putAll(group.getLocalPermissions(server, excludedGroups));
} else { } else {
plugin.getLogger().warning("Error whilst refreshing the permissions of '" + objectName + "'." + plugin.getLogger().warning("Error whilst refreshing the permissions of '" + objectName + "'." +
"\n The group '" + groupName + "' is not loaded."); "\n The group '" + groupName + "' is not loaded.");
}
} }
} }
} }
@ -424,10 +614,12 @@ public abstract class PermissionObject {
// Apply next priority: userNodes // Apply next priority: userNodes
perms.putAll(userNodes); perms.putAll(userNodes);
// Apply highest priority: serverSpecificNodes // Apply final priorities: serverSpecificNodes and then serverWorldSpecificNodes
for (Map.Entry<String, Boolean> node : serverSpecificNodes.entrySet()) { for (Map<String, Boolean> m : Arrays.asList(serverSpecificNodes, serverWorldSpecificNodes)) {
final String rawNode = Patterns.SERVER_SPLIT.split(node.getKey())[1]; for (Map.Entry<String, Boolean> node : m.entrySet()) {
perms.put(rawNode, node.getValue()); final String rawNode = Patterns.SERVER_SPLIT.split(node.getKey())[1];
perms.put(rawNode, node.getValue());
}
} }
return perms; return perms;

View File

@ -3,12 +3,14 @@ package me.lucko.luckperms.utils;
import lombok.Getter; import lombok.Getter;
import java.util.Map; import java.util.Map;
import java.util.Optional;
import java.util.UUID; import java.util.UUID;
import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentHashMap;
public class UuidCache { public class UuidCache {
private Map<String, UUID> cache; // External UUID --> Internal UUID
private Map<UUID, UUID> cache;
@Getter @Getter
private final boolean onlineMode; private final boolean onlineMode;
@ -21,18 +23,25 @@ public class UuidCache {
} }
} }
public UUID getUUID(String name, UUID fallback) { public UUID getUUID(UUID external) {
return onlineMode ? fallback : (cache.containsKey(name) ? cache.get(name) : fallback); return onlineMode ? external : (cache.containsKey(external) ? cache.get(external) : external);
} }
public void addToCache(String name, UUID uuid) { public UUID getExternalUUID(UUID internal) {
if (onlineMode) return; if (onlineMode) return internal;
cache.put(name, uuid);
Optional<UUID> external = cache.entrySet().stream().filter(e -> e.getValue().equals(internal)).map(Map.Entry::getKey).findFirst();
return external.isPresent() ? external.get() : internal;
} }
public void clearCache(String name) { public void addToCache(UUID external, UUID internal) {
if (onlineMode) return; if (onlineMode) return;
cache.remove(name); cache.put(external, internal);
}
public void clearCache(UUID external) {
if (onlineMode) return;
cache.remove(external);
} }
} }