Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
fa9324bda8 | ||
|
|
1e72f9d8fe | ||
|
|
50fd954599 | ||
|
|
b1e34b55f8 | ||
|
|
cff1b8a411 | ||
|
|
6ffa6720be | ||
|
|
f52a106165 | ||
|
|
bf247b71e1 | ||
|
|
66818e4c82 | ||
|
|
23d53d39b4 | ||
|
|
30ea5a5b69 | ||
|
|
e7a210dc06 | ||
|
|
497de9824a | ||
|
|
be74b50762 | ||
|
|
f2e06b56e7 | ||
|
|
f6aa20c300 | ||
|
|
5e16134f6f | ||
|
|
6165fcbb21 | ||
|
|
831e882db0 | ||
|
|
feb8bf4bd3 | ||
|
|
ce3ee866ca | ||
|
|
d29dd35689 | ||
|
|
3a0a89853f | ||
|
|
e7ca79d251 | ||
|
|
22426bab33 | ||
|
|
116094ea96 | ||
|
|
9df39a9545 | ||
|
|
b8f44df723 | ||
|
|
74f275eb69 | ||
|
|
1142cbcb2c | ||
|
|
37749e5829 | ||
|
|
f9025c7a51 | ||
|
|
c7bfc38477 | ||
|
|
7ca394d7b9 | ||
|
|
31884ea59d | ||
|
|
e79b7c7023 | ||
|
|
1fdb4e8ade | ||
|
|
53db8c5928 | ||
|
|
07514000a4 | ||
|
|
f28721e55a | ||
|
|
fc230291d3 | ||
|
|
89ff4cfa40 | ||
|
|
d786b6abb2 | ||
|
|
fb0e694155 | ||
|
|
cd6cac1fb6 | ||
|
|
ea07f05097 | ||
|
|
d84767af68 | ||
|
|
aab73a8d81 | ||
|
|
995fc2ccd8 | ||
|
|
60bcd5f643 | ||
|
|
ba04fb320b | ||
|
|
770b7dc282 | ||
|
|
ed85eee36c | ||
|
|
23df8a2df8 | ||
|
|
36cd388607 | ||
|
|
4d48ef1939 | ||
|
|
7970e2a1c6 | ||
|
|
cee96d7daa | ||
|
|
861c1ddd69 | ||
|
|
5dec5a54cb | ||
|
|
5c760aabd4 | ||
|
|
1a2fa5d8c3 | ||
|
|
ef0c53da82 | ||
|
|
3fd62a80e2 | ||
|
|
5c19dd8b15 | ||
|
|
1fc88e147f | ||
|
|
9b4bbe0500 | ||
|
|
b37fdd3619 | ||
|
|
ab00c41452 | ||
|
|
c15727377b | ||
|
|
1e6f32bdc4 | ||
|
|
42e69c98a7 | ||
|
|
a217727bb4 | ||
|
|
ba10b1c06e | ||
|
|
075ba33e8b | ||
|
|
19dbc7d90a | ||
|
|
ade70bb7ba | ||
|
|
4b67913eee | ||
|
|
75858c1555 | ||
|
|
659baaf5fb | ||
|
|
3c83c578eb | ||
|
|
3ddbf1da87 | ||
|
|
35cb5b81dc | ||
|
|
02d9b996a7 | ||
|
|
d4cf6a5ad7 | ||
|
|
9fdb4fa25f | ||
|
|
d5bc1cdf5d | ||
|
|
f5995c0afa | ||
|
|
2cc65160b4 | ||
|
|
57f5a7c4cd | ||
|
|
6aea3b53f3 | ||
|
|
9f5e194a6e | ||
|
|
0831585a27 | ||
|
|
b2cf6dce2d | ||
|
|
a3ebf86f6b | ||
|
|
2a305b1c55 | ||
|
|
2ea9b36c77 | ||
|
|
edaf174ebf | ||
|
|
c4497db06c | ||
|
|
9873415303 | ||
|
|
2b71476cfe | ||
|
|
44d14001e1 | ||
|
|
de5fda6a18 | ||
|
|
8b83a1d9a2 | ||
|
|
c0a0239eeb | ||
|
|
84f377451e | ||
|
|
21d0c9ab0e | ||
|
|
f9c1cdb4bd | ||
|
|
e89444141b | ||
|
|
9cd4e01d8e | ||
|
|
f7fa08d5e9 | ||
|
|
7a4135319f | ||
|
|
41fca40a36 | ||
|
|
9dbfa76b26 | ||
|
|
20eeade06f | ||
|
|
cd9f18ffdb | ||
|
|
f7baf67985 | ||
|
|
692bf30cf5 | ||
|
|
41b33fbd7a | ||
|
|
5dc551c05d | ||
|
|
dd7aee9d15 | ||
|
|
bbeed1e4ed | ||
|
|
471084a9ef | ||
|
|
6fc00976a0 | ||
|
|
4aa753515d | ||
|
|
7e933966cf | ||
|
|
b4d179f7b2 | ||
|
|
a51acdbc88 | ||
|
|
52e63a228d | ||
|
|
9424d2d2ba | ||
|
|
0c12eebe6f | ||
|
|
a15a0752f4 | ||
|
|
31cef46b56 | ||
|
|
bfe0126816 | ||
|
|
98b56691dd | ||
|
|
6451175d0e | ||
|
|
9b4319c42d | ||
|
|
e9e7d81ddf | ||
|
|
84afbf26f8 | ||
|
|
ca9037461a | ||
|
|
9a3eeca411 |
No files matched your search
@@ -1,250 +1,26 @@
|
||||

|
||||
# LuckPerms [](https://ci.lucko.me/job/LuckPerms/)
|
||||
A permissions implementation for Bukkit/Spigot, BungeeCord and Sponge.
|
||||
An advanced permissions implementation for Bukkit/Spigot, BungeeCord and Sponge.
|
||||
|
||||
## Links
|
||||
* **Development Builds** - <https://ci.lucko.me/job/LuckPerms>
|
||||
* **Javadocs** - <https://jd.lucko.me/LuckPerms>
|
||||
* **Wiki** - <https://github.com/lucko/LuckPerms/wiki>
|
||||
|
||||
## Features
|
||||
* **Group inheritance** - users can be members of multiple groups, groups can inherit other groups
|
||||
* **Temporary permissions** - users/groups can be given permissions that expire after a given time
|
||||
* **Wildcard permissions** - users/groups can be given wildcard permissions (e.g. "minecraft.command.*"), even when plugins haven't implemented their own wildcards.
|
||||
* **Temporary groups** - users/groups can be added to/inherit other groups temporarily
|
||||
* **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.
|
||||
* **Per-server permissions/groups** - define user/group permissions 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 / ladders** - users can be promoted/demoted along multiple group tracks
|
||||
* **Vault Support** - hooks into Vault to integrate with other plugins
|
||||
* **Developer API** - easily integrate LuckPerms into your own projects
|
||||
* **Advanced action logging** - keep track of permission changes over time
|
||||
* **Easy and simple setup and configuration using commands** - no editing yml files, yuck
|
||||
* **Negated permissions and groups** - define special rules for certain users/groups
|
||||
* **Regex permissions** - define special permissions using regex
|
||||
* **Shorthand nodes** - add nodes using the LuckPerms shorthand system
|
||||
* **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.
|
||||
* **Open Sourced, Free...** - you shouldn't have to pay $10+ for a "powerful" permissions plugin.
|
||||
* **BungeeCord compatible** - permissions, users and groups are synced across all LuckPerms instances
|
||||
* **Sponge compatible** - permissions, users and groups are synced across all LuckPerms instances (bukkit --> sponge, for example)
|
||||
* **Support for MySQL, SQLite & Flatfile (JSON)** - other storage methods coming soon (maybe)
|
||||
## Description
|
||||
LuckPerms is an advanced permissions implementation aiming to be a flexible, performant and reliable alternative to other permission systems, providing all the features you could ever possibly need in a permissions plugin, along with an extensive and well documented API for developers.
|
||||
|
||||
## Setup
|
||||
All configuration options are in the **config.yml/luckperms.conf** file, which is generated automagically when the plugin first starts.
|
||||
* [Spigot Plugin Page](https://www.spigotmc.org/resources/luckperms-an-advanced-permissions-system.28140/ "Spigot Plugin Page")
|
||||
* [Sponge Plugin Page](https://forums.spongepowered.org/t/luckperms-an-advanced-permissions-system/14274 "Sponge Plugin Page")
|
||||
|
||||
You can define the settings for per-server permissions, the storage method and credentials within this file.
|
||||
|
||||
## Info
|
||||
### Permission Calculation
|
||||
#### Permissions are calculated based on a priority system as follows.
|
||||
|
||||
* **Non wildcard/regex permissions will be overridden by normal permissions**
|
||||
|
||||
Example: if a user has a true permission set for "luckperms.\*", and a false permission set for "luckperms.something", the non-wildcard permission will override the wildcard, and "luckperms.something" will be set to false, despite the wildcard.
|
||||
|
||||
* **More specific wildcards override less specific ones**
|
||||
|
||||
Example: if a user has "luckperms.\*" set to true, but "luckperms.user.\*" set to false, all of the user permissions will be set to false, despite the more generic wildcard for "luckperms.*".
|
||||
|
||||
* **Temporary permissions will override non-temporary permissions.**
|
||||
|
||||
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.**
|
||||
|
||||
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 (provided they're on that server).
|
||||
|
||||
* **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.
|
||||
|
||||
### 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.
|
||||
|
||||
The only way around this is to decrease the sync interval.
|
||||
|
||||
### Shorthand Permissions
|
||||
LuckPerms has it's own system (although it's quite similar to PermissionsEx :P) that allows you to set permissions in a shorthand format.
|
||||
|
||||
Using the LuckPerms permission nodes as an example, say for instance, you wanted to let a user set and unset permissions for both groups and users.
|
||||
|
||||
Without shorthand, you would have to apply 4 nodes.
|
||||
```
|
||||
luckperms.user.setpermission
|
||||
luckperms.user.unsetpermission
|
||||
luckperms.group.setpermission
|
||||
luckperms.group.unsetpermission
|
||||
```
|
||||
However, with shorthand, you can just apply the following node:
|
||||
|
||||
`luckperms.(user|group).(setpermission|unsetpermission)`
|
||||
|
||||
You use brackets to define part of a node as a shorthand group, and then use the vertical bar `|` to separate entries.
|
||||
|
||||
There are some limitations, firstly, you cannot use shorthand in the first part of the node. (The "luckperms" part in the example above)
|
||||
|
||||
Additionally, you cannot combine shorthand and normal text in the same part of the node.
|
||||
For example, `luckperms.(user|group).(set|unset)permission` would not work.
|
||||
|
||||
### Regex
|
||||
LuckPerms has support for regex when defining permission nodes and server/world names.
|
||||
|
||||
Whenever regex is used, it MUST be prefixed with "R=", so LuckPerms knows to treat it as regex, and not as a normal string.
|
||||
|
||||
For example, if you wanted to give all members of the default group, the `essentials.fly` permission on all of your hub servers, where the hub server names are hub1, hub2, hub3, etc.
|
||||
You would use the command `/perms group default set essentials.fly true R=hub\d+`.
|
||||
|
||||
You can also use regex in permission nodes.
|
||||
Once again using LuckPerms permissions as an example, if you wanted a user to be able to create both groups and tracks, you would normally just add the two permission nodes. However with regex, you can just add one. `luckperms\.create.*` Remember to escape any characters, specifically dots, as the entire node will be parsed.
|
||||
|
||||
## API
|
||||
LuckPerms has an extensive API, allowing for easy integration with other projects. To use the Api, you need to obtain an instance of the `LuckPermsApi` interface. This can be done in a number of ways.
|
||||
|
||||
```java
|
||||
// On all platforms (throws IllegalStateException if the API is not loaded)
|
||||
final LuckPermsApi api = LuckPerms.getApi();
|
||||
|
||||
// Or with Optional
|
||||
Optional<LuckPermsApi> provider = LuckPerms.getApiSafe();
|
||||
if (provider.isPresent()) {
|
||||
final LuckPermsApi api = provider.get();
|
||||
}
|
||||
|
||||
// On Bukkit/Spigot
|
||||
ServicesManager manager = Bukkit.getServicesManager();
|
||||
if (manager.isProvidedFor(LuckPermsApi.class)) {
|
||||
final LuckPermsApi api = manager.getRegistration(LuckPermsApi.class).getProvider();
|
||||
}
|
||||
|
||||
// On Sponge
|
||||
Optional<LuckPermsApi> provider = Sponge.getServiceManager().provide(LuckPermsApi.class);
|
||||
if (provider.isPresent()) {
|
||||
final LuckPermsApi api = provider.get();
|
||||
}
|
||||
```
|
||||
|
||||
If you want to use LuckPerms in your onEnable method, you need to add the following to your plugins `plugin.yml`.
|
||||
```yml
|
||||
depend: [LuckPerms]
|
||||
```
|
||||
All of the available methods can be seen in the various interfaces in the `luckperms-api` module.
|
||||
|
||||
You can add LuckPerms as a Maven dependency by adding the following to your projects `pom.xml`.
|
||||
````xml
|
||||
<repositories>
|
||||
<repository>
|
||||
<id>luck-repo</id>
|
||||
<url>https://repo.lucko.me/</url>
|
||||
</repository>
|
||||
</repositories>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>me.lucko.luckperms</groupId>
|
||||
<artifactId>luckperms-api</artifactId>
|
||||
<version>2.1</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
````
|
||||
|
||||
## Versioning
|
||||
As of version 2.0, LuckPerms roughly follows the standards set out in Semantic Versioning.
|
||||
|
||||
The only difference is that the patch number is not included anywhere within the pom, and is calculated each build, based upon how may commits have been made since the last tag. (A new tag is made every minor version)
|
||||
|
||||
This means that API versions do not have a patch number (as no API changes are made in patches). API versions will be x.y, and each individual build of LuckPerms will follow x.y.z.
|
||||
|
||||
## Commands
|
||||
Command usage is printed to the console/chat whenever invalid arguments are provided. Simply typing /perms will list all commands a user has permission to use.
|
||||
|
||||
### Aliases
|
||||
| Bukkit | Bungee |
|
||||
|------------------|------------------|
|
||||
| /luckperms | /luckpermsbungee |
|
||||
| /perms | /bperms |
|
||||
| /permissions | /bpermissions |
|
||||
| /lp | /lpb |
|
||||
| /perm | /bperm |
|
||||
|
||||
Arguments: \<required\> [optional]
|
||||
|
||||
Users with OP have access to all commands.
|
||||
|
||||
Additionally, you can use wildcards to grant users access to a selection of commands.
|
||||
* **All commands** - luckperms.*
|
||||
* **All user commands** - luckperms.user.*
|
||||
* **All group commands** - luckperms.group.*
|
||||
* **All track commands** - luckperms.track.*
|
||||
|
||||
### General
|
||||
* /perms - n/a
|
||||
* /perms sync - luckperms.sync
|
||||
* /perms info - luckperms.info
|
||||
* /perms debug - luckperms.debug
|
||||
* /perms creategroup \<group\> - luckperms.creategroup
|
||||
* /perms deletegroup \<group\> - luckperms.deletegroup
|
||||
* /perms listgroups - luckperms.listgroups
|
||||
* /perms createtrack \<track\> - luckperms.createtrack
|
||||
* /perms deletetrack \<track\> - luckperms.deletetrack
|
||||
* /perms listtracks - luckperms.listtracks
|
||||
|
||||
### User
|
||||
* /perms user \<user\> info - luckperms.user.info
|
||||
* /perms user \<user\> getuuid - luckperms.user.getuuid
|
||||
* /perms user \<user\> listnodes - luckperms.user.listnodes
|
||||
* /perms user \<user\> haspermission \<node\> [server] [world] - luckperms.user.haspermission
|
||||
* /perms user \<user\> inheritspermission \<node\> [server] [world] - luckperms.user.inheritspermission
|
||||
* /perms user \<user\> set \<node\> \<true/false\> [server] [world] - luckperms.user.setpermission
|
||||
* /perms user \<user\> unset \<node\> [server] [world] - luckperms.user.unsetpermission
|
||||
* /perms user \<user\> addgroup \<group\> [server] [world] - luckperms.user.addgroup
|
||||
* /perms user \<user\> removegroup \<group\> [server] [world] - luckperms.user.removegroup
|
||||
* /perms user \<user\> settemp \<node\> \<true/false\> \<duration\> [server] [world] - luckperms.user.settemppermission
|
||||
* /perms user \<user\> unsettemp \<node\> [server] [world] - luckperms.user.unsettemppermission
|
||||
* /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\> showtracks - luckperms.user.showtracks
|
||||
* /perms user \<user\> promote \<track\> - luckperms.user.promote
|
||||
* /perms user \<user\> demote \<track\> - luckperms.user.demote
|
||||
* /perms user \<user\> showpos \<track\> - luckperms.user.showpos
|
||||
* /perms user \<user\> clear - luckperms.user.clear
|
||||
|
||||
### Group
|
||||
* /perms group \<group\> info - luckperms.group.info
|
||||
* /perms group \<group\> listnodes - luckperms.group.listnodes
|
||||
* /perms group \<group\> haspermission \<node\> [server] [world] - luckperms.group.haspermission
|
||||
* /perms group \<group\> inheritspermission \<node\> [server] [world] - luckperms.group.inheritspermission
|
||||
* /perms group \<group\> set \<node\> \<true/false\> [server] [world] - luckperms.group.setpermission
|
||||
* /perms group \<group\> unset \<node\> [server] [world] - luckperms.group.unsetpermission
|
||||
* /perms group \<group\> setinherit \<group\> [server] [world] - luckperms.group.setinherit
|
||||
* /perms group \<group\> unsetinherit \<group\> [server] [world] - luckperms.group.unsetinherit
|
||||
* /perms group \<group\> settemp \<node\> \<true/false\> \<duration\> [server] [world] - settemppermission
|
||||
* /perms group \<group\> unsettemp \<node\> [server] [world] - luckperms.group.unsettemppermission
|
||||
* /perms group \<group\> settempinherit \<group\> \<duration\> [server] [world] - luckperms.group.settempinherit
|
||||
* /perms group \<group\> unsettempinherit \<group\> [server] [world] - luckperms.group.unsettempinherit
|
||||
* /perms group \<group\> showtracks - luckperms.group.showtracks
|
||||
* /perms group \<group\> clear - luckperms.group.clear
|
||||
|
||||
### Track
|
||||
* /perms track \<track\> info - luckperms.track.info
|
||||
* /perms track \<track\> append \<group\> - luckperms.track.append
|
||||
* /perms track \<track\> insert \<group\> \<position\> - luckperms.track.insert
|
||||
* /perms track \<track\> remove \<group\> - luckperms.track.remove
|
||||
* /perms track \<track\> clear - luckperms.track.clear
|
||||
|
||||
### Log
|
||||
* /perms log recent [user] [page] - luckperms.log.recent
|
||||
* /perms log search \<query\> [page] - luckperms.log.search
|
||||
* /perms log notify [on|off] - luckperms.log.notify
|
||||
* /perms log userhistory \<user\> [page] - luckperms.log.userhistory
|
||||
* /perms log grouphistory \<group\> [page] - luckperms.log.grouphistory
|
||||
* /perms log trackhistory \<track\> [page] - luckperms.log.trackhistory
|
||||
## LuckPerms vs Other Plugins
|
||||

|
||||
_Features checked on 23rd Aug 2016. If you find any inaccuracies, please do let me know. I tried to be as fair as possible, and copy all major features from the respective plugin pages._
|
||||
|
||||
## License
|
||||
See LICENSE.md.
|
||||
See LICENSE.md.
|
||||
|
||||
## Thanks to:
|
||||
[](http://www.ej-technologies.com/products/jprofiler/overview.html)
|
||||
|
||||
Thanks to ej-technologies for granting LuckPerms an open source licence to their [java profiling software](http://www.ej-technologies.com/products/jprofiler/overview.html "Java Profiler").
|
||||
+12
-1
@@ -5,7 +5,7 @@
|
||||
<parent>
|
||||
<artifactId>luckperms</artifactId>
|
||||
<groupId>me.lucko.luckperms</groupId>
|
||||
<version>2.3</version>
|
||||
<version>2.9-SNAPSHOT</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
@@ -23,4 +23,15 @@
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
|
||||
<dependencies>
|
||||
<!-- guava -->
|
||||
<dependency>
|
||||
<groupId>com.google.guava</groupId>
|
||||
<artifactId>guava</artifactId>
|
||||
<version>19.0</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
</project>
|
||||
@@ -22,8 +22,6 @@
|
||||
|
||||
package me.lucko.luckperms;
|
||||
|
||||
import lombok.AccessLevel;
|
||||
import lombok.NoArgsConstructor;
|
||||
import me.lucko.luckperms.api.LuckPermsApi;
|
||||
|
||||
import java.util.Optional;
|
||||
@@ -31,12 +29,9 @@ import java.util.Optional;
|
||||
/**
|
||||
* Static access to LuckPerms
|
||||
*/
|
||||
@NoArgsConstructor(access = AccessLevel.PRIVATE)
|
||||
public final class LuckPerms {
|
||||
|
||||
private static LuckPermsApi api = null;
|
||||
|
||||
|
||||
/**
|
||||
* Gets an instance of {@link LuckPermsApi}
|
||||
* @return an api instance
|
||||
@@ -66,4 +61,8 @@ public final class LuckPerms {
|
||||
api = null;
|
||||
}
|
||||
|
||||
private LuckPerms() {
|
||||
throw new UnsupportedOperationException("This class cannot be instantiated.");
|
||||
}
|
||||
|
||||
}
|
||||
@@ -24,13 +24,11 @@ package me.lucko.luckperms.api;
|
||||
|
||||
import me.lucko.luckperms.api.data.Callback;
|
||||
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
* Wrapper interface for the internal Datastore instance
|
||||
*
|
||||
* <p> The implementations of this interface limit access to the datastore and add parameter checks to further prevent
|
||||
* errors and ensure all API interactions to not damage the state of the plugin.
|
||||
* Interface for the internal Datastore instance
|
||||
*/
|
||||
@SuppressWarnings("unused")
|
||||
public interface Datastore {
|
||||
@@ -38,16 +36,230 @@ public interface Datastore {
|
||||
String getName();
|
||||
boolean isAcceptingLogins();
|
||||
|
||||
Async async();
|
||||
/**
|
||||
* Gets the {@link Sync} interface.
|
||||
*
|
||||
* All operations through this interface are called immediately and in the same thread as they are called.
|
||||
* Datastore operations are thread blocking, and Sync operations should not be called on the main server thread.
|
||||
* @return the sync interface
|
||||
*/
|
||||
Sync sync();
|
||||
|
||||
/**
|
||||
* Gets the {@link Async} interface.
|
||||
*
|
||||
* All operations through this interface are called in a new, separate asynchronous thread.
|
||||
* When the operation is complete, the provided callback method is called, in applicable, in the main server thread.
|
||||
* @return the async interface
|
||||
*/
|
||||
Async async();
|
||||
|
||||
/**
|
||||
* Gets the {@link Future} interface.
|
||||
*
|
||||
* All operations through this interface are called in a new, separate asynchronous thread, similar to {@link Async}.
|
||||
* The only difference is that instead of providing a callback, a {@link java.util.concurrent.Future} is returned.
|
||||
* See the Oracle JavaDocs for usage of the Future class.
|
||||
* @return the future interface
|
||||
*/
|
||||
Future future();
|
||||
|
||||
/**
|
||||
* All operations through this interface are called immediately and in the same thread as they are called.
|
||||
* Datastore operations are thread blocking, and Sync operations should not be called on the main server thread.
|
||||
*/
|
||||
interface Sync {
|
||||
|
||||
/**
|
||||
* Saves an action to the datastore
|
||||
* @param entry the log entry to be saved
|
||||
* @return true if the operation completed successfully.
|
||||
* @throws NullPointerException if entry is null
|
||||
*/
|
||||
boolean logAction(LogEntry entry);
|
||||
|
||||
/**
|
||||
* Loads and returns the log from the datastore
|
||||
* @return a log instance, could be null
|
||||
*/
|
||||
Log getLog();
|
||||
|
||||
/**
|
||||
* Either loads or creates a user object, and loads it into the plugins internal storage
|
||||
* @param uuid the uuid of the user
|
||||
* @param username the users username. (if you want to specify <code>null</code> here, just input "null" as a string.)
|
||||
* @return true if the operation completed successfully.
|
||||
* @throws NullPointerException if uuid or username is null
|
||||
* @throws IllegalArgumentException if either of the parameters are invalid
|
||||
* @deprecated functionality of this method is taken on by {@link #loadUser(UUID, String)}
|
||||
*/
|
||||
@Deprecated
|
||||
boolean loadOrCreateUser(UUID uuid, String username);
|
||||
|
||||
/**
|
||||
* Loads a user from the datastore into the plugins internal storage.
|
||||
* @param uuid the uuid of the user to load
|
||||
* @return true if the user exists, and was loaded correctly.
|
||||
* @throws NullPointerException if uuid is null
|
||||
* @deprecated replaced by {@link #loadUser(UUID, String)}
|
||||
*/
|
||||
@Deprecated
|
||||
boolean loadUser(UUID uuid);
|
||||
|
||||
/**
|
||||
* Loads a user's data into the plugins internal storage.
|
||||
* @param uuid the uuid of the user to load
|
||||
* @param username the users username. (if you want to specify <code>null</code> here, just input "null" as a string.)
|
||||
* @return if the operation was performed successfully
|
||||
* @throws NullPointerException if uuid or username is null
|
||||
* @since 2.6
|
||||
*/
|
||||
boolean loadUser(UUID uuid, String username);
|
||||
|
||||
/**
|
||||
* Saves a user object into the datastore. You should call this after you make any changes to a user.
|
||||
* @param user the user to save
|
||||
* @return true if the operation completed successfully.
|
||||
* @throws NullPointerException if user is null
|
||||
* @throws IllegalStateException if the user instance was not obtained from LuckPerms.
|
||||
*/
|
||||
boolean saveUser(User user);
|
||||
|
||||
/**
|
||||
* Removes users from the datastore who are "default". This is called every time the plugin loads.
|
||||
* @return true if the operation completed successfully
|
||||
* @since 2.6
|
||||
*/
|
||||
boolean cleanupUsers();
|
||||
|
||||
/**
|
||||
* Gets a set all user's UUIDs who are "unique", and aren't just a member of the "default" group.
|
||||
* @return a set of uuids, or null if the operation failed.
|
||||
* @since 2.6
|
||||
*/
|
||||
Set<UUID> getUniqueUsers();
|
||||
|
||||
/**
|
||||
* Creates and loads a group into the plugins internal storage
|
||||
* @param name the name of the group
|
||||
* @return true if the operation completed successfully
|
||||
* @throws NullPointerException if name is null
|
||||
* @throws IllegalArgumentException if the name is invalid
|
||||
*/
|
||||
boolean createAndLoadGroup(String name);
|
||||
|
||||
/**
|
||||
* Loads a group into the plugins internal storage.
|
||||
* @param name the name of the group
|
||||
* @return true if the operation completed successfully
|
||||
* @throws NullPointerException if name is null
|
||||
* @throws IllegalArgumentException if the name is invalid
|
||||
*/
|
||||
boolean loadGroup(String name);
|
||||
|
||||
/**
|
||||
* Loads all groups from the datastore into the plugins internal storage
|
||||
* @return true if the operation completed successfully.
|
||||
*/
|
||||
boolean loadAllGroups();
|
||||
|
||||
/**
|
||||
* Saves a group back to the datastore. You should call this after you make any changes to a group.
|
||||
* @param group the group to save
|
||||
* @return true if the operation completed successfully.
|
||||
* @throws NullPointerException if group is null
|
||||
* @throws IllegalStateException if the group instance was not obtained from LuckPerms.
|
||||
*/
|
||||
boolean saveGroup(Group group);
|
||||
|
||||
/**
|
||||
* Permanently deletes a group from the datastore
|
||||
* @param group the group to delete
|
||||
* @return true if the operation completed successfully.
|
||||
* @throws NullPointerException if group is null
|
||||
* @throws IllegalStateException if the group instance was not obtained from LuckPerms.
|
||||
*/
|
||||
boolean deleteGroup(Group group);
|
||||
|
||||
/**
|
||||
* Creates and loads a track into the plugins internal storage
|
||||
* @param name the name of the track
|
||||
* @return true if the operation completed successfully
|
||||
* @throws NullPointerException if name is null
|
||||
* @throws IllegalArgumentException if the name is invalid
|
||||
*/
|
||||
boolean createAndLoadTrack(String name);
|
||||
|
||||
/**
|
||||
* Loads a track into the plugins internal storage.
|
||||
* @param name the name of the track
|
||||
* @return true if the operation completed successfully
|
||||
* @throws NullPointerException if name is null
|
||||
* @throws IllegalArgumentException if the name is invalid
|
||||
*/
|
||||
boolean loadTrack(String name);
|
||||
|
||||
/**
|
||||
* Loads all tracks from the datastore into the plugins internal storage
|
||||
* @return true if the operation completed successfully.
|
||||
*/
|
||||
boolean loadAllTracks();
|
||||
|
||||
/**
|
||||
* Saves a track back to the datastore. You should call this after you make any changes to a track.
|
||||
* @param track the track to save
|
||||
* @return true if the operation completed successfully.
|
||||
* @throws NullPointerException if track is null
|
||||
* @throws IllegalStateException if the track instance was not obtained from LuckPerms.
|
||||
*/
|
||||
boolean saveTrack(Track track);
|
||||
|
||||
/**
|
||||
* Permanently deletes a track from the datastore
|
||||
* @param track the track to delete
|
||||
* @return true if the operation completed successfully.
|
||||
* @throws NullPointerException if track is null
|
||||
* @throws IllegalStateException if the track instance was not obtained from LuckPerms.
|
||||
*/
|
||||
boolean deleteTrack(Track track);
|
||||
|
||||
/**
|
||||
* Saves UUID caching data to the datastore
|
||||
* @param username the users username
|
||||
* @param uuid the users mojang unique id
|
||||
* @return true if the operation completed successfully.
|
||||
* @throws NullPointerException if either parameters are null
|
||||
* @throws IllegalArgumentException if the username is invalid
|
||||
*/
|
||||
boolean saveUUIDData(String username, UUID uuid);
|
||||
|
||||
/**
|
||||
* Gets a UUID from a username
|
||||
* @param username the corresponding username
|
||||
* @return a uuid object, could be null
|
||||
* @throws NullPointerException if either parameters are null
|
||||
* @throws IllegalArgumentException if the username is invalid
|
||||
*/
|
||||
UUID getUUID(String username);
|
||||
}
|
||||
|
||||
/**
|
||||
* All operations through this interface are called in a new, separate asynchronous thread.
|
||||
* When the operation is complete, the provided callback method is called, in applicable, in the main server thread.
|
||||
*
|
||||
* See {@link Sync} for method documentation.
|
||||
*/
|
||||
interface Async {
|
||||
void logAction(LogEntry entry, Callback<Boolean> callback);
|
||||
void getLog(Callback<Log> callback);
|
||||
@Deprecated
|
||||
void loadOrCreateUser(UUID uuid, String username, Callback<Boolean> callback);
|
||||
@Deprecated
|
||||
void loadUser(UUID uuid, Callback<Boolean> callback);
|
||||
void loadUser(UUID uuid, String username, Callback<Boolean> callback);
|
||||
void saveUser(User user, Callback<Boolean> callback);
|
||||
void cleanupUsers(Callback<Boolean> callback);
|
||||
void getUniqueUsers(Callback<Set<UUID>> callback);
|
||||
void createAndLoadGroup(String name, Callback<Boolean> callback);
|
||||
void loadGroup(String name, Callback<Boolean> callback);
|
||||
void loadAllGroups(Callback<Boolean> callback);
|
||||
@@ -62,32 +274,24 @@ public interface Datastore {
|
||||
void getUUID(String username, Callback<UUID> callback);
|
||||
}
|
||||
|
||||
interface Sync {
|
||||
boolean logAction(LogEntry entry);
|
||||
Log getLog();
|
||||
boolean loadOrCreateUser(UUID uuid, String username);
|
||||
boolean loadUser(UUID uuid);
|
||||
boolean saveUser(User user);
|
||||
boolean createAndLoadGroup(String name);
|
||||
boolean loadGroup(String name);
|
||||
boolean loadAllGroups();
|
||||
boolean saveGroup(Group group);
|
||||
boolean deleteGroup(Group group);
|
||||
boolean createAndLoadTrack(String name);
|
||||
boolean loadTrack(String name);
|
||||
boolean loadAllTracks();
|
||||
boolean saveTrack(Track track);
|
||||
boolean deleteTrack(Track track);
|
||||
boolean saveUUIDData(String username, UUID uuid);
|
||||
UUID getUUID(String username);
|
||||
}
|
||||
|
||||
/**
|
||||
* All operations through this interface are called in a new, separate asynchronous thread, similar to {@link Async}.
|
||||
* The only difference is that instead of providing a callback, a {@link java.util.concurrent.Future} is returned.
|
||||
* See the Oracle JavaDocs for usage of the Future class.
|
||||
*
|
||||
* See {@link Sync} for method documentation.
|
||||
*/
|
||||
interface Future {
|
||||
java.util.concurrent.Future<Boolean> logAction(LogEntry entry);
|
||||
java.util.concurrent.Future<Log> getLog();
|
||||
@Deprecated
|
||||
java.util.concurrent.Future<Boolean> loadOrCreateUser(UUID uuid, String username);
|
||||
@Deprecated
|
||||
java.util.concurrent.Future<Boolean> loadUser(UUID uuid);
|
||||
java.util.concurrent.Future<Boolean> loadUser(UUID uuid, String username);
|
||||
java.util.concurrent.Future<Boolean> saveUser(User user);
|
||||
java.util.concurrent.Future<Boolean> cleanupUsers();
|
||||
java.util.concurrent.Future<Set<UUID>> getUniqueUsers();
|
||||
java.util.concurrent.Future<Boolean> createAndLoadGroup(String name);
|
||||
java.util.concurrent.Future<Boolean> loadGroup(String name);
|
||||
java.util.concurrent.Future<Boolean> loadAllGroups();
|
||||
|
||||
@@ -28,10 +28,7 @@ import me.lucko.luckperms.exceptions.ObjectLacksException;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Wrapper interface for internal Group instances
|
||||
*
|
||||
* <p> The implementations of this interface limit access to the Group and add parameter checks to further prevent
|
||||
* errors and ensure all API interactions to not damage the state of the group.
|
||||
* Interface for internal Group instances
|
||||
*/
|
||||
@SuppressWarnings("unused")
|
||||
public interface Group extends PermissionHolder {
|
||||
@@ -42,26 +39,34 @@ public interface Group extends PermissionHolder {
|
||||
String getName();
|
||||
|
||||
/**
|
||||
* check to see if a group inherits a group
|
||||
* Check to see if a group inherits a group
|
||||
* @param group The group to check membership of
|
||||
* @return true if the user is a member of the group
|
||||
* @return true if the group inherits the other group
|
||||
* @throws NullPointerException if the group is null
|
||||
* @throws IllegalStateException if the group instance was not obtained from LuckPerms.
|
||||
*/
|
||||
boolean inheritsGroup(Group group);
|
||||
|
||||
/**
|
||||
* check to see if the group inherits a group on a specific server
|
||||
* Check to see if the group inherits a group on a specific server
|
||||
* @param group The group to check membership of
|
||||
* @param server The server to check on
|
||||
* @return true if the group inherits the group
|
||||
* @return true if the group inherits the group on the server
|
||||
* @throws NullPointerException if the group or server is null
|
||||
* @throws IllegalStateException if the group instance was not obtained from LuckPerms.
|
||||
* @throws IllegalArgumentException if the server is invalid
|
||||
*/
|
||||
boolean inheritsGroup(Group group, String server);
|
||||
|
||||
/**
|
||||
* check to see if the group inherits a group on a specific server
|
||||
* Check to see if the group inherits a group on a specific server and world
|
||||
* @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 group inherits the group
|
||||
* @return true if the group inherits the group on the server and world
|
||||
* @throws NullPointerException if the group, server or world is null
|
||||
* @throws IllegalStateException if the group instance was not obtained from LuckPerms.
|
||||
* @throws IllegalArgumentException if the server or world is invalid
|
||||
*/
|
||||
boolean inheritsGroup(Group group, String server, String world);
|
||||
|
||||
@@ -69,101 +74,134 @@ public interface Group extends PermissionHolder {
|
||||
* Make this group inherit another group
|
||||
* @param group the group to be inherited
|
||||
* @throws ObjectAlreadyHasException if the group already inherits the group
|
||||
* @throws NullPointerException if the group is null
|
||||
* @throws IllegalStateException if the group instance was not obtained from LuckPerms.
|
||||
*/
|
||||
void setInheritGroup(Group group) throws ObjectAlreadyHasException;
|
||||
|
||||
/**
|
||||
* Make this group inherit another group on a specific server
|
||||
* @param group the group to be inherited
|
||||
* @param server The server to add the group on
|
||||
* @param server The server to inherit the group on
|
||||
* @throws ObjectAlreadyHasException if the group already inherits the group on that server
|
||||
* @throws NullPointerException if the group or server is null
|
||||
* @throws IllegalStateException if the group instance was not obtained from LuckPerms.
|
||||
* @throws IllegalArgumentException if the server is invalid
|
||||
*/
|
||||
void setInheritGroup(Group group, String server) throws ObjectAlreadyHasException;
|
||||
|
||||
/**
|
||||
* Make this group inherit another group on a specific server
|
||||
* Make this group inherit another group on a specific server and world
|
||||
* @param group the group to be inherited
|
||||
* @param server The server to add the group on
|
||||
* @param world The world to add the group on
|
||||
* @throws ObjectAlreadyHasException if the group already inherits the group on that server
|
||||
* @param server The server to inherit the group on
|
||||
* @param world The world to inherit the group on
|
||||
* @throws ObjectAlreadyHasException if the group already inherits the group on that server and world
|
||||
* @throws NullPointerException if the group, server or world is null
|
||||
* @throws IllegalStateException if the group instance was not obtained from LuckPerms.
|
||||
* @throws IllegalArgumentException if the server or world is invalid
|
||||
*/
|
||||
void setInheritGroup(Group group, String server, String world) throws ObjectAlreadyHasException;
|
||||
|
||||
/**
|
||||
* Make this group inherit another group on a specific server
|
||||
* Make this group inherit another group temporarily
|
||||
* @param group the group to be inherited
|
||||
* @param expireAt when the group should expire
|
||||
* @throws ObjectAlreadyHasException if the group already inherits the group on that server
|
||||
* @param expireAt the unix time when the group should expire
|
||||
* @throws ObjectAlreadyHasException if the group already inherits the group temporarily
|
||||
* @throws NullPointerException if the group is null
|
||||
* @throws IllegalStateException if the group instance was not obtained from LuckPerms.
|
||||
* @throws IllegalArgumentException if the expiry time is in the past
|
||||
*/
|
||||
void setInheritGroup(Group group, long expireAt) throws ObjectAlreadyHasException;
|
||||
|
||||
/**
|
||||
* Make this group inherit another group on a specific server
|
||||
* Make this group inherit another group on a specific server temporarily
|
||||
* @param group the group to be inherited
|
||||
* @param server The server to add the group on
|
||||
* @param server The server inherit add the group on
|
||||
* @param expireAt when the group should expire
|
||||
* @throws ObjectAlreadyHasException if the group already inherits the group on that server
|
||||
* @throws ObjectAlreadyHasException if the group already inherits the group on that server temporarily
|
||||
* @throws NullPointerException if the group or server is null
|
||||
* @throws IllegalStateException if the group instance was not obtained from LuckPerms.
|
||||
* @throws IllegalArgumentException if the expiry time is in the past or the server is invalid
|
||||
*/
|
||||
void setInheritGroup(Group group, String server, long expireAt) throws ObjectAlreadyHasException;
|
||||
|
||||
/**
|
||||
* Make this group inherit another group on a specific server
|
||||
* Make this group inherit another group on a specific server and world temporarily
|
||||
* @param group the group to be inherited
|
||||
* @param server The server to add the group on
|
||||
* @param world The world to add the group on
|
||||
* @param server The server to inherit the group on
|
||||
* @param world The world to inherit the group on
|
||||
* @param expireAt when the group should expire
|
||||
* @throws ObjectAlreadyHasException if the group already inherits the group on that server
|
||||
* @throws ObjectAlreadyHasException if the group already inherits the group on that server and world temporarily
|
||||
* @throws NullPointerException if the group, server or world is null
|
||||
* @throws IllegalStateException if the group instance was not obtained from LuckPerms.
|
||||
* @throws IllegalArgumentException if the expiry time is in the past or the server/world is invalid
|
||||
*/
|
||||
void setInheritGroup(Group group, String server, String world, long expireAt) throws ObjectAlreadyHasException;
|
||||
|
||||
/**
|
||||
* Remove a previously set inheritance
|
||||
* Remove a previously set inheritance rule
|
||||
* @param group the group to uninherit
|
||||
* @throws ObjectLacksException if the group does not already inherit the group
|
||||
* @throws NullPointerException if the group is null
|
||||
* @throws IllegalStateException if the group instance was not obtained from LuckPerms.
|
||||
*/
|
||||
void unsetInheritGroup(Group group) throws ObjectLacksException;
|
||||
|
||||
/**
|
||||
* Remove a previously set inheritance
|
||||
* Remove a previously set inheritance rule
|
||||
* @param group the group to uninherit
|
||||
* @param temporary if the group being removed is temporary
|
||||
* @throws ObjectLacksException if the group does not already inherit the group
|
||||
* @throws NullPointerException if the group is null
|
||||
* @throws IllegalStateException if the group instance was not obtained from LuckPerms.
|
||||
*/
|
||||
void unsetInheritGroup(Group group, boolean temporary) throws ObjectLacksException;
|
||||
|
||||
/**
|
||||
* Remove a previously set inheritance
|
||||
* Remove a previously set inheritance rule on a specific server
|
||||
* @param group the group to uninherit
|
||||
* @param server The server to remove the group on
|
||||
* @throws ObjectLacksException if the group does not already inherit the group
|
||||
* @throws ObjectLacksException if the group does not already inherit the group on that server
|
||||
* @throws NullPointerException if the group or server is null
|
||||
* @throws IllegalStateException if the group instance was not obtained from LuckPerms.
|
||||
* @throws IllegalArgumentException if the server is invalid
|
||||
*/
|
||||
void unsetInheritGroup(Group group, String server) throws ObjectLacksException;
|
||||
|
||||
/**
|
||||
* Remove a previously set inheritance
|
||||
* Remove a previously set inheritance rule on a specific server and world
|
||||
* @param group the group to uninherit
|
||||
* @param server The server to remove the group on
|
||||
* @param world The world to remove the group on
|
||||
* @throws ObjectLacksException if the group does not already inherit the group
|
||||
* @throws NullPointerException if the group, server or world is null
|
||||
* @throws IllegalStateException if the group instance was not obtained from LuckPerms.
|
||||
* @throws IllegalArgumentException if the server or world is invalid
|
||||
*/
|
||||
void unsetInheritGroup(Group group, String server, String world) throws ObjectLacksException;
|
||||
|
||||
/**
|
||||
* Remove a previously set inheritance
|
||||
* Remove a previously set inheritance rule on a specific server
|
||||
* @param group the group to uninherit
|
||||
* @param server The server to remove the group on
|
||||
* @param temporary if the group being removed is temporary
|
||||
* @throws ObjectLacksException if the group does not already inherit the group
|
||||
* @throws NullPointerException if the group or server is null
|
||||
* @throws IllegalStateException if the group instance was not obtained from LuckPerms.
|
||||
* @throws IllegalArgumentException if the expiry time is in the past or the server is invalid
|
||||
*/
|
||||
void unsetInheritGroup(Group group, String server, boolean temporary) throws ObjectLacksException;
|
||||
|
||||
/**
|
||||
* Remove a previously set inheritance
|
||||
* Remove a previously set inheritance rule on a specific server and world
|
||||
* @param group the group to uninherit
|
||||
* @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
|
||||
* @param temporary if the group being removed was set temporarily
|
||||
* @throws ObjectLacksException if the group does not already inherit the group
|
||||
* @throws NullPointerException if the group, server or world is null
|
||||
* @throws IllegalStateException if the group instance was not obtained from LuckPerms.
|
||||
* @throws IllegalArgumentException if the expiry time is in the past or the server/world is invalid
|
||||
*/
|
||||
void unsetInheritGroup(Group group, String server, String world, boolean temporary) throws ObjectLacksException;
|
||||
|
||||
@@ -183,6 +221,8 @@ public interface Group extends PermissionHolder {
|
||||
* @param server the server to check
|
||||
* @param world the world to check
|
||||
* @return a {@link List} of group names
|
||||
* @throws NullPointerException if the server or world is null
|
||||
* @throws IllegalArgumentException if the server or world is invalid
|
||||
*/
|
||||
List<String> getLocalGroups(String server, String world);
|
||||
|
||||
@@ -190,6 +230,8 @@ public interface Group extends PermissionHolder {
|
||||
* Get a {@link List} of the groups the group inherits on a specific server
|
||||
* @param server the server to check
|
||||
* @return a {@link List} of group names
|
||||
* @throws NullPointerException if the server is null
|
||||
* @throws IllegalArgumentException if the server is invalid
|
||||
*/
|
||||
List<String> getLocalGroups(String server);
|
||||
}
|
||||
@@ -22,11 +22,15 @@
|
||||
|
||||
package me.lucko.luckperms.api;
|
||||
|
||||
import me.lucko.luckperms.api.data.DatastoreConfiguration;
|
||||
import me.lucko.luckperms.api.data.MySQLConfiguration;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* A wrapper interface for the internal LuckPerms configuration, providing read only access.
|
||||
*/
|
||||
@SuppressWarnings("unused")
|
||||
public interface LPConfiguration {
|
||||
|
||||
/**
|
||||
@@ -41,12 +45,16 @@ public interface LPConfiguration {
|
||||
|
||||
/**
|
||||
* @return the default group, in a node representation
|
||||
* @deprecated as of 2.6, the default group is always "default"
|
||||
*/
|
||||
@Deprecated
|
||||
String getDefaultGroupNode();
|
||||
|
||||
/**
|
||||
* @return the name of the default group
|
||||
* @deprecated as of 2.6, the default group is always "default"
|
||||
*/
|
||||
@Deprecated
|
||||
String getDefaultGroupName();
|
||||
|
||||
/**
|
||||
@@ -54,6 +62,24 @@ public interface LPConfiguration {
|
||||
*/
|
||||
boolean getIncludeGlobalPerms();
|
||||
|
||||
/**
|
||||
* @return if the users on this server will have their global world permissions applied
|
||||
* @since 2.9
|
||||
*/
|
||||
boolean getIncludeGlobalWorldPerms();
|
||||
|
||||
/**
|
||||
* @return true if the platform is applying global groups
|
||||
* @since 2.9
|
||||
*/
|
||||
boolean getApplyGlobalGroups();
|
||||
|
||||
/**
|
||||
* @return true if the platform is applying global world groups
|
||||
* @since 2.9
|
||||
*/
|
||||
boolean getApplyGlobalWorldGroups();
|
||||
|
||||
/**
|
||||
* @return the online mode setting in the config
|
||||
*/
|
||||
@@ -75,13 +101,76 @@ public interface LPConfiguration {
|
||||
boolean getApplyShorthand();
|
||||
|
||||
/**
|
||||
* @return the database values set in the configuration
|
||||
* @return if LuckPerms will send notifications to users when permissions are modified
|
||||
* @since 2.7
|
||||
*/
|
||||
boolean getLogNotify();
|
||||
|
||||
/**
|
||||
* @return true if permission checks are being recorded / debugged
|
||||
* @since 2.9
|
||||
*/
|
||||
boolean getDebugPermissionChecks();
|
||||
|
||||
/**
|
||||
* @return true if the vanilla op system is enabled
|
||||
* @since 2.8
|
||||
*/
|
||||
boolean getEnableOps();
|
||||
|
||||
/**
|
||||
* @return true if opped players are allowed to use LuckPerms commands
|
||||
* @since 2.8
|
||||
*/
|
||||
boolean getCommandsAllowOp();
|
||||
|
||||
/**
|
||||
* @return true if auto op is enabled
|
||||
* @since 2.9
|
||||
*/
|
||||
boolean getAutoOp();
|
||||
|
||||
/**
|
||||
* @return the name of the server used within Vault operations
|
||||
* @since 2.7
|
||||
*/
|
||||
String getVaultServer();
|
||||
|
||||
/**
|
||||
* @return true if global permissions should be considered when retrieving meta or player groups
|
||||
* @since 2.7
|
||||
*/
|
||||
boolean getVaultIncludeGlobal();
|
||||
|
||||
/**
|
||||
* @return the database values set in the configuration
|
||||
* @deprecated use {@link #getDatastoreConfig()}
|
||||
*/
|
||||
@SuppressWarnings("deprecation")
|
||||
@Deprecated
|
||||
MySQLConfiguration getDatabaseValues();
|
||||
|
||||
/**
|
||||
* @return the values set for data storage in the configuration
|
||||
*/
|
||||
DatastoreConfiguration getDatastoreConfig();
|
||||
|
||||
/**
|
||||
* @return the storage method string from the configuration
|
||||
*/
|
||||
String getStorageMethod();
|
||||
|
||||
/**
|
||||
* @return true if split storage is enabled
|
||||
* @since 2.7
|
||||
*/
|
||||
boolean getSplitStorage();
|
||||
|
||||
/**
|
||||
* @return a map of split storage options, where the key is the storage section, and the value is the storage method.
|
||||
* For example: key = user, value = json
|
||||
* @since 2.7
|
||||
*/
|
||||
Map<String, String> getSplitStorageOptions();
|
||||
|
||||
}
|
||||
@@ -28,7 +28,7 @@ import java.util.UUID;
|
||||
|
||||
/**
|
||||
* Represents the internal LuckPerms log.
|
||||
* All content is immutable. You can add to the log using the {@link Datastore}, and then request an updated copy.
|
||||
* All content internally is immutable. You can add to the log using the {@link Datastore}, and then request an updated copy.
|
||||
*/
|
||||
@SuppressWarnings("unused")
|
||||
public interface Log {
|
||||
@@ -38,27 +38,124 @@ public interface Log {
|
||||
*/
|
||||
SortedSet<LogEntry> getContent();
|
||||
|
||||
/**
|
||||
* @return all content in this log
|
||||
*/
|
||||
SortedSet<LogEntry> getRecent();
|
||||
|
||||
/**
|
||||
* Gets the recent content separated by page
|
||||
* @param pageNo the page number
|
||||
* @return the page content
|
||||
*/
|
||||
SortedMap<Integer, LogEntry> getRecent(int pageNo);
|
||||
|
||||
/**
|
||||
* @return the max page number allowed in the {@link #getRecent(int)} method
|
||||
*/
|
||||
int getRecentMaxPages();
|
||||
|
||||
|
||||
/**
|
||||
* @param actor the uuid of the actor to filter by
|
||||
* @return all content in this log where is actor = uuid
|
||||
*/
|
||||
SortedSet<LogEntry> getRecent(UUID actor);
|
||||
|
||||
/**
|
||||
* Gets the recent content for the uuid, separated into pages
|
||||
* @param pageNo the page number
|
||||
* @param actor the uuid of the actor to filter by
|
||||
* @return the page content
|
||||
*/
|
||||
SortedMap<Integer, LogEntry> getRecent(int pageNo, UUID actor);
|
||||
|
||||
/**
|
||||
* @param actor the actor to filter by
|
||||
* @return the max page number allowed in the {@link #getRecent(int, UUID)} method
|
||||
*/
|
||||
int getRecentMaxPages(UUID actor);
|
||||
|
||||
|
||||
/**
|
||||
* @param uuid the uuid to filter by
|
||||
* @return all content in this log where the user = uuid
|
||||
*/
|
||||
SortedSet<LogEntry> getUserHistory(UUID uuid);
|
||||
|
||||
/**
|
||||
* Gets the user history content, separated by pages
|
||||
* @param pageNo the page number
|
||||
* @param uuid the uuid of the acted user to filter by
|
||||
* @return the page content
|
||||
*/
|
||||
SortedMap<Integer, LogEntry> getUserHistory(int pageNo, UUID uuid);
|
||||
|
||||
/**
|
||||
* @param uuid the uuid to filter by
|
||||
* @return the max page number allowed in the {@link #getUserHistory(int, UUID)} method
|
||||
*/
|
||||
int getUserHistoryMaxPages(UUID uuid);
|
||||
|
||||
|
||||
/**
|
||||
* @param name the name to filter by
|
||||
* @return all content in this log where the group = name
|
||||
*/
|
||||
SortedSet<LogEntry> getGroupHistory(String name);
|
||||
|
||||
/**
|
||||
* Gets the group history content, separated by pages
|
||||
* @param pageNo the page number
|
||||
* @param name the name of the acted group to filter by
|
||||
* @return the page content
|
||||
*/
|
||||
SortedMap<Integer, LogEntry> getGroupHistory(int pageNo, String name);
|
||||
|
||||
/**
|
||||
* @param name the name to filter by
|
||||
* @return the max page number allowed in the {@link #getGroupHistory(int, String)} method
|
||||
*/
|
||||
int getGroupHistoryMaxPages(String name);
|
||||
|
||||
|
||||
/**
|
||||
* @param name the name to filter by
|
||||
* @return all content in this log where the track = name
|
||||
*/
|
||||
SortedSet<LogEntry> getTrackHistory(String name);
|
||||
|
||||
/**
|
||||
* Gets the track history content, separated by pages
|
||||
* @param pageNo the page number
|
||||
* @param name the name of the acted track to filter by
|
||||
* @return the page content
|
||||
*/
|
||||
SortedMap<Integer, LogEntry> getTrackHistory(int pageNo, String name);
|
||||
|
||||
/**
|
||||
* @param name the name to filter by
|
||||
* @return the max page number allowed in the {@link #getTrackHistory(int, String)} method
|
||||
*/
|
||||
int getTrackHistoryMaxPages(String name);
|
||||
|
||||
/**
|
||||
* @param query the query to filter by
|
||||
* @return all content in this log where the content matches query
|
||||
*/
|
||||
SortedSet<LogEntry> getSearch(String query);
|
||||
|
||||
/**
|
||||
* Gets the search content, separated by pages
|
||||
* @param pageNo the page number
|
||||
* @param query the query to filter by
|
||||
* @return the page content
|
||||
*/
|
||||
SortedMap<Integer, LogEntry> getSearch(int pageNo, String query);
|
||||
|
||||
/**
|
||||
* @param query the query to filter by
|
||||
* @return the max page number allowed in the {@link #getSearch(int, String)} method
|
||||
*/
|
||||
int getSearchMaxPages(String query);
|
||||
}
|
||||
@@ -22,29 +22,63 @@
|
||||
|
||||
package me.lucko.luckperms.api;
|
||||
|
||||
import lombok.*;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
@Getter
|
||||
@Builder
|
||||
@ToString
|
||||
@EqualsAndHashCode
|
||||
@AllArgsConstructor
|
||||
public final class LogEntry implements Comparable<LogEntry> {
|
||||
/**
|
||||
* Represents a single entry in a log
|
||||
*/
|
||||
@SuppressWarnings({"unused", "WeakerAccess"})
|
||||
public class LogEntry implements Comparable<LogEntry> {
|
||||
public static LogEntryBuilder builder() {
|
||||
return new LogEntryBuilder();
|
||||
}
|
||||
|
||||
private static final String FORMAT = "&8(&e%s&8) [&a%s&8] (&b%s&8) &7--> &f%s";
|
||||
|
||||
@NonNull private final long timestamp;
|
||||
@NonNull private final UUID actor;
|
||||
@NonNull private final String actorName;
|
||||
@NonNull private final char type;
|
||||
private final UUID acted;
|
||||
@NonNull private final String actedName;
|
||||
@NonNull private final String action;
|
||||
private long timestamp;
|
||||
private UUID actor;
|
||||
private String actorName;
|
||||
private char type;
|
||||
private UUID acted;
|
||||
private String actedName;
|
||||
private String action;
|
||||
|
||||
public LogEntry(long timestamp, UUID actor, String actorName, char type, UUID acted, String actedName, String action) {
|
||||
if (actor == null) {
|
||||
throw new NullPointerException("actor");
|
||||
}
|
||||
if (actorName == null) {
|
||||
throw new NullPointerException("actorName");
|
||||
}
|
||||
if (actedName == null) {
|
||||
throw new NullPointerException("actedName");
|
||||
}
|
||||
if (action == null) {
|
||||
throw new NullPointerException("action");
|
||||
}
|
||||
|
||||
this.timestamp = timestamp;
|
||||
this.actor = actor;
|
||||
this.actorName = actorName;
|
||||
this.type = type;
|
||||
this.acted = acted;
|
||||
this.actedName = actedName;
|
||||
this.action = action;
|
||||
}
|
||||
|
||||
protected LogEntry() {
|
||||
this.timestamp = 0L;
|
||||
this.actor = null;
|
||||
this.actorName = null;
|
||||
this.type = Character.MIN_VALUE;
|
||||
this.acted = null;
|
||||
this.actedName = null;
|
||||
this.action = null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int compareTo(LogEntry o) {
|
||||
return Long.compare(timestamp, o.getTimestamp());
|
||||
return equals(o) ? 0 : (Long.compare(timestamp, o.getTimestamp()) == 0 ? 1 : Long.compare(timestamp, o.getTimestamp()));
|
||||
}
|
||||
|
||||
public boolean matchesSearch(String query) {
|
||||
@@ -55,10 +89,231 @@ public final class LogEntry implements Comparable<LogEntry> {
|
||||
|
||||
public String getFormatted() {
|
||||
return String.format(FORMAT,
|
||||
getActorName(),
|
||||
Character.toString(getType()),
|
||||
getActedName(),
|
||||
getAction()
|
||||
actorName,
|
||||
Character.toString(type),
|
||||
actedName,
|
||||
action
|
||||
);
|
||||
}
|
||||
|
||||
public long getTimestamp() {
|
||||
return timestamp;
|
||||
}
|
||||
|
||||
public UUID getActor() {
|
||||
return actor;
|
||||
}
|
||||
|
||||
public String getActorName() {
|
||||
return actorName;
|
||||
}
|
||||
|
||||
public char getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
public UUID getActed() {
|
||||
return acted;
|
||||
}
|
||||
|
||||
public String getActedName() {
|
||||
return actedName;
|
||||
}
|
||||
|
||||
public String getAction() {
|
||||
return action;
|
||||
}
|
||||
|
||||
void setTimestamp(long timestamp) {
|
||||
this.timestamp = timestamp;
|
||||
}
|
||||
|
||||
void setActor(UUID actor) {
|
||||
this.actor = actor;
|
||||
}
|
||||
|
||||
void setActorName(String actorName) {
|
||||
this.actorName = actorName;
|
||||
}
|
||||
|
||||
void setType(char type) {
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
void setActed(UUID acted) {
|
||||
this.acted = acted;
|
||||
}
|
||||
|
||||
void setActedName(String actedName) {
|
||||
this.actedName = actedName;
|
||||
}
|
||||
|
||||
void setAction(String action) {
|
||||
this.action = action;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "LogEntry(timestamp=" + this.getTimestamp() + ", actor=" + this.getActor() + ", actorName=" +
|
||||
this.getActorName() + ", type=" + this.getType() + ", acted=" + this.getActed() + ", actedName=" +
|
||||
this.getActedName() + ", action=" + this.getAction() + ")";
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (o == this) return true;
|
||||
if (!(o instanceof LogEntry)) return false;
|
||||
final LogEntry other = (LogEntry) o;
|
||||
if (this.getTimestamp() != other.getTimestamp()) return false;
|
||||
final Object this$actor = this.getActor();
|
||||
final Object other$actor = other.getActor();
|
||||
if (this$actor == null ? other$actor != null : !this$actor.equals(other$actor)) return false;
|
||||
final Object this$actorName = this.getActorName();
|
||||
final Object other$actorName = other.getActorName();
|
||||
if (this$actorName == null ? other$actorName != null : !this$actorName.equals(other$actorName)) return false;
|
||||
if (this.getType() != other.getType()) return false;
|
||||
final Object this$acted = this.getActed();
|
||||
final Object other$acted = other.getActed();
|
||||
if (this$acted == null ? other$acted != null : !this$acted.equals(other$acted)) return false;
|
||||
final Object this$actedName = this.getActedName();
|
||||
final Object other$actedName = other.getActedName();
|
||||
if (this$actedName == null ? other$actedName != null : !this$actedName.equals(other$actedName)) return false;
|
||||
final Object this$action = this.getAction();
|
||||
final Object other$action = other.getAction();
|
||||
return this$action == null ? other$action == null : this$action.equals(other$action);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
final int PRIME = 59;
|
||||
int result = 1;
|
||||
final long $timestamp = this.getTimestamp();
|
||||
result = result * PRIME + (int) ($timestamp >>> 32 ^ $timestamp);
|
||||
final Object $actor = this.getActor();
|
||||
result = result * PRIME + ($actor == null ? 43 : $actor.hashCode());
|
||||
final Object $actorName = this.getActorName();
|
||||
result = result * PRIME + ($actorName == null ? 43 : $actorName.hashCode());
|
||||
result = result * PRIME + this.getType();
|
||||
final Object $acted = this.getActed();
|
||||
result = result * PRIME + ($acted == null ? 43 : $acted.hashCode());
|
||||
final Object $actedName = this.getActedName();
|
||||
result = result * PRIME + ($actedName == null ? 43 : $actedName.hashCode());
|
||||
final Object $action = this.getAction();
|
||||
result = result * PRIME + ($action == null ? 43 : $action.hashCode());
|
||||
return result;
|
||||
}
|
||||
|
||||
public static class LogEntryBuilder extends AbstractLogEntryBuilder<LogEntry, LogEntry.LogEntryBuilder> {
|
||||
|
||||
@Override
|
||||
protected LogEntry createObj() {
|
||||
return new LogEntry();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected LogEntryBuilder getThis() {
|
||||
return this;
|
||||
}
|
||||
}
|
||||
|
||||
public static abstract class AbstractLogEntryBuilder<T extends LogEntry, B extends AbstractLogEntryBuilder<T, B>> {
|
||||
private T obj;
|
||||
private B thisObj;
|
||||
|
||||
public AbstractLogEntryBuilder() {
|
||||
obj = createObj();
|
||||
thisObj = getThis();
|
||||
}
|
||||
|
||||
protected abstract T createObj();
|
||||
protected abstract B getThis();
|
||||
|
||||
public long getTimestamp() {
|
||||
return obj.getTimestamp();
|
||||
}
|
||||
|
||||
public UUID getActor() {
|
||||
return obj.getActor();
|
||||
}
|
||||
|
||||
public String getActorName() {
|
||||
return obj.getActorName();
|
||||
}
|
||||
|
||||
public char getType() {
|
||||
return obj.getType();
|
||||
}
|
||||
|
||||
public UUID getActed() {
|
||||
return obj.getActed();
|
||||
}
|
||||
|
||||
public String getActedName() {
|
||||
return obj.getActedName();
|
||||
}
|
||||
|
||||
public String getAction() {
|
||||
return obj.getAction();
|
||||
}
|
||||
|
||||
public B timestamp(long timestamp) {
|
||||
obj.setTimestamp(timestamp);
|
||||
return thisObj;
|
||||
}
|
||||
|
||||
public B actor(UUID actor) {
|
||||
obj.setActor(actor);
|
||||
return thisObj;
|
||||
}
|
||||
|
||||
public B actorName(String actorName) {
|
||||
obj.setActorName(actorName);
|
||||
return thisObj;
|
||||
}
|
||||
|
||||
public B type(char type) {
|
||||
obj.setType(type);
|
||||
return thisObj;
|
||||
}
|
||||
|
||||
public B acted(UUID acted) {
|
||||
obj.setActed(acted);
|
||||
return thisObj;
|
||||
}
|
||||
|
||||
public B actedName(String actedName) {
|
||||
obj.setActedName(actedName);
|
||||
return thisObj;
|
||||
}
|
||||
|
||||
public B action(String action) {
|
||||
obj.setAction(action);
|
||||
return thisObj;
|
||||
}
|
||||
|
||||
public T build() {
|
||||
if (getActor() == null) {
|
||||
throw new NullPointerException("actor");
|
||||
}
|
||||
if (getActorName() == null) {
|
||||
throw new NullPointerException("actorName");
|
||||
}
|
||||
if (getActedName() == null) {
|
||||
throw new NullPointerException("actedName");
|
||||
}
|
||||
if (getAction() == null) {
|
||||
throw new NullPointerException("action");
|
||||
}
|
||||
|
||||
return obj;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "LogEntry.LogEntryBuilder(timestamp=" + getTimestamp() + ", actor=" + getActor() + ", actorName=" +
|
||||
getActorName() + ", type=" + getType() + ", acted=" + getActed() + ", actedName=" + getActedName() +
|
||||
", action=" + getAction() + ")";
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -23,7 +23,7 @@
|
||||
package me.lucko.luckperms.api;
|
||||
|
||||
/**
|
||||
* A wrapper class for platform logger instances.
|
||||
* A wrapper interface for platform logger instances.
|
||||
*
|
||||
* <p> Bukkit/Bungee both use java.util.logging, and Sponge uses org.slf4j. This class wraps those classes so the commons
|
||||
* module can access a logger.
|
||||
|
||||
@@ -22,12 +22,14 @@
|
||||
|
||||
package me.lucko.luckperms.api;
|
||||
|
||||
import me.lucko.luckperms.api.event.LPListener;
|
||||
|
||||
import java.util.Optional;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
* The root Api interface in LuckPerms
|
||||
* The root API interface in LuckPerms
|
||||
*/
|
||||
@SuppressWarnings("unused")
|
||||
public interface LuckPermsApi {
|
||||
@@ -37,11 +39,37 @@ public interface LuckPermsApi {
|
||||
*/
|
||||
void runUpdateTask();
|
||||
|
||||
/**
|
||||
* @return the version of the API running on the platform
|
||||
* @since 2.6
|
||||
*/
|
||||
double getApiVersion();
|
||||
|
||||
/**
|
||||
* @return the version of the plugin running on the platform
|
||||
*/
|
||||
String getVersion();
|
||||
|
||||
/**
|
||||
* @return the platform LuckPerms is running on
|
||||
* @since 2.7
|
||||
*/
|
||||
PlatformType getPlatformType();
|
||||
|
||||
/**
|
||||
* Registers a listener to be sent LuckPerms events
|
||||
* @param listener the listener instance
|
||||
* @throws NullPointerException if the listener is null
|
||||
*/
|
||||
void registerListener(LPListener listener);
|
||||
|
||||
/**
|
||||
* Unregisters a previously registered listener from the EventBus
|
||||
* @param listener the listener instance to unregister
|
||||
* @throws NullPointerException if the listener is null
|
||||
*/
|
||||
void unregisterListener(LPListener listener);
|
||||
|
||||
/**
|
||||
* Gets a wrapped {@link LPConfiguration} instance, with read only access
|
||||
* @return a configuration instance
|
||||
@@ -70,6 +98,7 @@ public interface LuckPermsApi {
|
||||
* Gets a wrapped user object from the user storage
|
||||
* @param uuid the uuid of the user to get
|
||||
* @return a {@link User} object, if one matching the uuid is loaded, or null if not
|
||||
* @throws NullPointerException if the uuid is null
|
||||
*/
|
||||
User getUser(UUID uuid);
|
||||
|
||||
@@ -77,6 +106,7 @@ public interface LuckPermsApi {
|
||||
* Gets a wrapped user object from the user storage. This method does not return null, unlike {@link #getUser(UUID)}
|
||||
* @param uuid the uuid of the user to get
|
||||
* @return an optional {@link User} object
|
||||
* @throws NullPointerException if the uuid is null
|
||||
*/
|
||||
Optional<User> getUserSafe(UUID uuid);
|
||||
|
||||
@@ -84,6 +114,7 @@ public interface LuckPermsApi {
|
||||
* Gets a wrapped user object from the user storage
|
||||
* @param name the username of the user to get
|
||||
* @return a {@link User} object, if one matching the uuid is loaded, or null if not
|
||||
* @throws NullPointerException if the name is null
|
||||
*/
|
||||
User getUser(String name);
|
||||
|
||||
@@ -91,6 +122,7 @@ public interface LuckPermsApi {
|
||||
* Gets a wrapped user object from the user storage. This method does not return null, unlike {@link #getUser(String)}
|
||||
* @param name the username of the user to get
|
||||
* @return an optional {@link User} object
|
||||
* @throws NullPointerException if the name is null
|
||||
*/
|
||||
Optional<User> getUserSafe(String name);
|
||||
|
||||
@@ -104,13 +136,23 @@ public interface LuckPermsApi {
|
||||
* Check if a user is loaded in memory
|
||||
* @param uuid the uuid to check for
|
||||
* @return true if the user is loaded
|
||||
* @throws NullPointerException if the uuid is null
|
||||
*/
|
||||
boolean isUserLoaded(UUID uuid);
|
||||
|
||||
/**
|
||||
* Unload a user from the internal storage, if they're not currently online.
|
||||
* @param user the user to unload
|
||||
* @throws NullPointerException if the user is null
|
||||
* @since 2.6
|
||||
*/
|
||||
void cleanupUser(User user);
|
||||
|
||||
/**
|
||||
* Gets a wrapped group object from the group storage
|
||||
* @param name the name of the group to get
|
||||
* @return a {@link Group} object, if one matching the name exists, or null if not
|
||||
* @throws NullPointerException if the name is null
|
||||
*/
|
||||
Group getGroup(String name);
|
||||
|
||||
@@ -118,6 +160,7 @@ public interface LuckPermsApi {
|
||||
* Gets a wrapped group object from the group storage. This method does not return null, unlike {@link #getGroup}
|
||||
* @param name the name of the group to get
|
||||
* @return an optional {@link Group} object
|
||||
* @throws NullPointerException if the name is null
|
||||
*/
|
||||
Optional<Group> getGroupSafe(String name);
|
||||
|
||||
@@ -131,6 +174,7 @@ public interface LuckPermsApi {
|
||||
* Check if a group is loaded in memory
|
||||
* @param name the name to check for
|
||||
* @return true if the group is loaded
|
||||
* @throws NullPointerException if the name is null
|
||||
*/
|
||||
boolean isGroupLoaded(String name);
|
||||
|
||||
@@ -138,13 +182,15 @@ public interface LuckPermsApi {
|
||||
* Gets a wrapped track object from the track storage
|
||||
* @param name the name of the track to get
|
||||
* @return a {@link Track} object, if one matching the name exists, or null if not
|
||||
* @throws NullPointerException if the name is null
|
||||
*/
|
||||
Track getTrack(String name);
|
||||
|
||||
/**
|
||||
* Gets a wrapped tracj object from the track storage. This method does not return null, unlike {@link #getTrack}
|
||||
* Gets a wrapped track object from the track storage. This method does not return null, unlike {@link #getTrack}
|
||||
* @param name the name of the track to get
|
||||
* @return an optional {@link Track} object
|
||||
* @throws NullPointerException if the name is null
|
||||
*/
|
||||
Optional<Track> getTrackSafe(String name);
|
||||
|
||||
@@ -158,7 +204,18 @@ public interface LuckPermsApi {
|
||||
* Check if a track is loaded in memory
|
||||
* @param name the name to check for
|
||||
* @return true if the track is loaded
|
||||
* @throws NullPointerException if the name is null
|
||||
*/
|
||||
boolean isTrackLoaded(String name);
|
||||
|
||||
/**
|
||||
* Returns a permission builder instance
|
||||
* @param permission the main permission node to build
|
||||
* @return a {@link Node.Builder} instance
|
||||
* @throws IllegalArgumentException if the permission is invalid
|
||||
* @throws NullPointerException if the permission is null
|
||||
* @since 2.6
|
||||
*/
|
||||
Node.Builder buildNode(String permission) throws IllegalArgumentException;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,316 @@
|
||||
/*
|
||||
* Copyright (c) 2016 Lucko (Luck) <luck@lucko.me>
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
package me.lucko.luckperms.api;
|
||||
|
||||
import me.lucko.luckperms.LuckPerms;
|
||||
import me.lucko.luckperms.exceptions.ObjectAlreadyHasException;
|
||||
import me.lucko.luckperms.exceptions.ObjectLacksException;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* A collection of utilities to help retrieve meta values for {@link PermissionHolder}s
|
||||
* @since 2.7
|
||||
*/
|
||||
public class MetaUtils {
|
||||
|
||||
private MetaUtils(){}
|
||||
|
||||
/**
|
||||
* Escapes special characters used within LuckPerms, so the string can be saved without issues
|
||||
* @param s the string to escape
|
||||
* @return an escaped string
|
||||
* @throws NullPointerException if the string is null
|
||||
*/
|
||||
public static String escapeCharacters(String s) {
|
||||
if (s == null) {
|
||||
throw new NullPointerException();
|
||||
}
|
||||
|
||||
s = s.replace(".", "{SEP}");
|
||||
s = s.replace("/", "{FSEP}");
|
||||
s = s.replace("$", "{DSEP}");
|
||||
|
||||
return s;
|
||||
}
|
||||
|
||||
/**
|
||||
* Unescapes special characters used within LuckPerms, the inverse of {@link #escapeCharacters(String)}
|
||||
* @param s the string to unescape
|
||||
* @return an unescaped string
|
||||
* @throws NullPointerException if the string is null
|
||||
*/
|
||||
public static String unescapeCharacters(String s) {
|
||||
if (s == null) {
|
||||
throw new NullPointerException();
|
||||
}
|
||||
|
||||
s = s.replace("{SEP}", ".");
|
||||
s = s.replace("{FSEP}", "/");
|
||||
s = s.replace("{DSEP}", "$");
|
||||
|
||||
return s;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets a meta value on a holder
|
||||
* @param holder the holder to apply the meta node to
|
||||
* @param server the server to apply the meta on, can be null
|
||||
* @param world the world to apply the meta on, can be null
|
||||
* @param node the meta node
|
||||
* @param value the meta value
|
||||
* @throws NullPointerException if the holder, node or value is null
|
||||
* @throws IllegalArgumentException if the node or value is empty
|
||||
*/
|
||||
public static void setMeta(PermissionHolder holder, String server, String world, String node, String value) {
|
||||
if (holder == null) {
|
||||
throw new NullPointerException("holder");
|
||||
}
|
||||
|
||||
if (node == null) {
|
||||
throw new NullPointerException("node");
|
||||
}
|
||||
|
||||
if (value == null) {
|
||||
throw new NullPointerException("value");
|
||||
}
|
||||
|
||||
if (node.equals("")) {
|
||||
throw new IllegalArgumentException("node is empty");
|
||||
}
|
||||
|
||||
if (value.equals("")) {
|
||||
throw new IllegalArgumentException("value is empty");
|
||||
}
|
||||
|
||||
if (server == null || server.equals("")) {
|
||||
server = "global";
|
||||
}
|
||||
|
||||
node = escapeCharacters(node);
|
||||
value = escapeCharacters(value);
|
||||
|
||||
Set<Node> toRemove = new HashSet<>();
|
||||
for (Node n : holder.getEnduringPermissions()) {
|
||||
if (n.isMeta() && n.getMeta().getKey().equals(node)) {
|
||||
toRemove.add(n);
|
||||
}
|
||||
}
|
||||
|
||||
for (Node n : toRemove) {
|
||||
try {
|
||||
holder.unsetPermission(n);
|
||||
} catch (ObjectLacksException ignored) {}
|
||||
}
|
||||
|
||||
Node.Builder metaNode = LuckPerms.getApi().buildNode("meta." + node + "." + value).setValue(true);
|
||||
if (!server.equalsIgnoreCase("global")) {
|
||||
metaNode.setServer(server);
|
||||
}
|
||||
if (world != null && !world.equals("")) {
|
||||
metaNode.setServer(server).setWorld(world);
|
||||
}
|
||||
|
||||
try {
|
||||
holder.setPermission(metaNode.build());
|
||||
} catch (ObjectAlreadyHasException ignored) {}
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets a meta value for the holder
|
||||
* @param holder the holder to get the meta from
|
||||
* @param server the server to retrieve the meta on, can be null
|
||||
* @param world the world to retrieve the meta on, can be null
|
||||
* @param node the node to get
|
||||
* @param defaultValue the default value to return if the node is not set
|
||||
* @param includeGlobal if global nodes should be considered when retrieving the meta
|
||||
* @return a meta string, or the default value if the user does not have the meta node
|
||||
* @throws NullPointerException if the holder or node is null
|
||||
* @throws IllegalArgumentException if the node is empty
|
||||
*/
|
||||
public static String getMeta(PermissionHolder holder, String server, String world, String node, String defaultValue, boolean includeGlobal) {
|
||||
if (holder == null) {
|
||||
throw new NullPointerException("holder");
|
||||
}
|
||||
|
||||
if (server == null || server.equals("")) {
|
||||
server = "global";
|
||||
}
|
||||
|
||||
if (node == null) {
|
||||
throw new NullPointerException("node");
|
||||
}
|
||||
|
||||
if (node.equals("")) {
|
||||
throw new IllegalArgumentException("node is empty");
|
||||
}
|
||||
|
||||
node = escapeCharacters(node);
|
||||
|
||||
for (Node n : holder.getPermissions()) {
|
||||
if (!n.getValue()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!n.isMeta()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!server.equalsIgnoreCase("global")) {
|
||||
if (!n.shouldApplyOnServer(server, includeGlobal, false)) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
if (!n.shouldApplyOnWorld(world, includeGlobal, false)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
Map.Entry<String, String> meta = n.getMeta();
|
||||
if (meta.getKey().equalsIgnoreCase(node)) {
|
||||
return unescapeCharacters(meta.getValue());
|
||||
}
|
||||
}
|
||||
|
||||
return defaultValue;
|
||||
}
|
||||
|
||||
private static void setChatMeta(boolean prefix, PermissionHolder holder, String value, int priority, String server, String world) {
|
||||
if (holder == null) {
|
||||
throw new NullPointerException("holder");
|
||||
}
|
||||
|
||||
if (value == null || value.equals("")) {
|
||||
throw new IllegalArgumentException("value is null/empty");
|
||||
}
|
||||
|
||||
Node.Builder node = LuckPerms.getApi().buildNode(prefix ? "prefix" : "suffix" + "." + priority + "." + escapeCharacters(value));
|
||||
node.setValue(true);
|
||||
if (!server.equalsIgnoreCase("global")) {
|
||||
node.setServer(server);
|
||||
}
|
||||
if (world != null && !world.equals("")) {
|
||||
node.setServer(server).setWorld(world);
|
||||
}
|
||||
|
||||
try {
|
||||
holder.setPermission(node.build());
|
||||
} catch (ObjectAlreadyHasException ignored) {}
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a prefix to a holder on a specific server and world
|
||||
* @param holder the holder to set the prefix for
|
||||
* @param prefix the prefix value
|
||||
* @param priority the priority to set the prefix at
|
||||
* @param server the server to set the prefix on, can be null
|
||||
* @param world the world to set the prefix on, can be null
|
||||
* @throws NullPointerException if the holder is null
|
||||
* @throws IllegalArgumentException if the prefix is null or empty
|
||||
*/
|
||||
public static void setPrefix(PermissionHolder holder, String prefix, int priority, String server, String world) {
|
||||
setChatMeta(true, holder, prefix, priority, server, world);
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a suffix to a holder on a specific server and world
|
||||
* @param holder the holder to set the suffix for
|
||||
* @param suffix the suffix value
|
||||
* @param priority the priority to set the suffix at
|
||||
* @param server the server to set the suffix on, can be null
|
||||
* @param world the world to set the suffix on, can be null
|
||||
* @throws NullPointerException if the holder is null
|
||||
* @throws IllegalArgumentException if the suffix is null or empty
|
||||
*/
|
||||
public static void setSuffix(PermissionHolder holder, String suffix, int priority, String server, String world) {
|
||||
setChatMeta(false, holder, suffix, priority, server, world);
|
||||
}
|
||||
|
||||
private static String getChatMeta(boolean prefix, PermissionHolder holder, String server, String world, boolean includeGlobal) {
|
||||
if (holder == null) {
|
||||
throw new NullPointerException("holder");
|
||||
}
|
||||
if (server == null) {
|
||||
server = "global";
|
||||
}
|
||||
|
||||
int priority = Integer.MIN_VALUE;
|
||||
String meta = null;
|
||||
for (Node n : holder.getAllNodes()) {
|
||||
if (!n.getValue()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!server.equalsIgnoreCase("global")) {
|
||||
if (!n.shouldApplyOnServer(server, includeGlobal, false)) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
if (!n.shouldApplyOnWorld(world, includeGlobal, false)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (prefix ? !n.isPrefix() : !n.isSuffix()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
Map.Entry<Integer, String> value = prefix ? n.getPrefix() : n.getSuffix();
|
||||
if (value.getKey() > priority) {
|
||||
meta = value.getValue();
|
||||
priority = value.getKey();
|
||||
}
|
||||
}
|
||||
|
||||
return meta == null ? "" : unescapeCharacters(meta);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a holders highest priority prefix, if they have one
|
||||
* @param holder the holder
|
||||
* @param server the server to retrieve the prefix on
|
||||
* @param world the world to retrieve the prefix on
|
||||
* @param includeGlobal if global nodes should be considered when retrieving the prefix
|
||||
* @return a prefix string, if the holder has one, or an empty string if not.
|
||||
* @throws NullPointerException if the holder is null
|
||||
*/
|
||||
public static String getPrefix(PermissionHolder holder, String server, String world, boolean includeGlobal) {
|
||||
return getChatMeta(true, holder, server, world, includeGlobal);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a holders highest priority suffix, if they have one
|
||||
* @param holder the holder
|
||||
* @param server the server to retrieve the suffix on
|
||||
* @param world the world to retrieve the suffix on
|
||||
* @param includeGlobal if global nodes should be considered when retrieving the suffix
|
||||
* @return a suffix string, if the holder has one, or an empty string if not.
|
||||
* @throws NullPointerException if the holder is null
|
||||
*/
|
||||
public static String getSuffix(PermissionHolder holder, String server, String world, boolean includeGlobal) {
|
||||
return getChatMeta(false, holder, server, world, includeGlobal);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,301 @@
|
||||
/*
|
||||
* Copyright (c) 2016 Lucko (Luck) <luck@lucko.me>
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
package me.lucko.luckperms.api;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
|
||||
/**
|
||||
* Represents an immutable node object
|
||||
* <p> Use {@link LuckPermsApi#buildNode(String)} to get an instance.
|
||||
* @since 2.6
|
||||
*/
|
||||
@SuppressWarnings("unused")
|
||||
public interface Node extends Map.Entry<String, Boolean> {
|
||||
|
||||
/**
|
||||
* @return the actual permission node
|
||||
*/
|
||||
String getPermission();
|
||||
|
||||
/**
|
||||
* Get what value the permission is set to. A negated node would return <code>false</code>.
|
||||
* @return the permission's value
|
||||
*/
|
||||
@Override
|
||||
Boolean getValue();
|
||||
|
||||
/**
|
||||
* @return the value of this node as a Tristate
|
||||
*/
|
||||
Tristate getTristate();
|
||||
|
||||
/**
|
||||
* @return true if the node is negated
|
||||
*/
|
||||
boolean isNegated();
|
||||
|
||||
/**
|
||||
* If this node is set to override explicitly.
|
||||
* This value does not persist across saves, and is therefore only useful for transient nodes
|
||||
* @return true if this node is set to override explicitly
|
||||
*/
|
||||
boolean isOverride();
|
||||
|
||||
/**
|
||||
* Gets the server this node applies on, if the node is server specific
|
||||
* @return an {@link Optional} containing the server, if one is defined
|
||||
*/
|
||||
Optional<String> getServer();
|
||||
|
||||
/**
|
||||
* Gets the world this node applies on, if the node is world specific
|
||||
* @return an {@link Optional} containing the world, if one is defined
|
||||
*/
|
||||
Optional<String> getWorld();
|
||||
|
||||
/**
|
||||
* @return true if this node is server specific
|
||||
*/
|
||||
boolean isServerSpecific();
|
||||
|
||||
/**
|
||||
* @return true if this node is server specific
|
||||
*/
|
||||
boolean isWorldSpecific();
|
||||
|
||||
/**
|
||||
* If this node should apply on a specific server
|
||||
* @param server the name of the server
|
||||
* @param includeGlobal if global permissions should apply
|
||||
* @param applyRegex if regex should be applied
|
||||
* @return true if the node should apply
|
||||
*/
|
||||
boolean shouldApplyOnServer(String server, boolean includeGlobal, boolean applyRegex);
|
||||
|
||||
/**
|
||||
* If this node should apply on a specific world
|
||||
* @param world the name of the world
|
||||
* @param includeGlobal if global permissions should apply
|
||||
* @param applyRegex if regex should be applied
|
||||
* @return true if the node should apply
|
||||
*/
|
||||
boolean shouldApplyOnWorld(String world, boolean includeGlobal, boolean applyRegex);
|
||||
|
||||
/**
|
||||
* If this node should apply given the specific context
|
||||
* @param context the context key value pairs
|
||||
* @return true if the node should apply
|
||||
*/
|
||||
boolean shouldApplyWithContext(Map<String, String> context);
|
||||
|
||||
/**
|
||||
* Similar to {@link #shouldApplyOnServer(String, boolean, boolean)}, except this method accepts a List
|
||||
* @param servers the list of servers
|
||||
* @param includeGlobal if global permissions should apply
|
||||
* @return true if the node should apply
|
||||
*/
|
||||
boolean shouldApplyOnAnyServers(List<String> servers, boolean includeGlobal);
|
||||
|
||||
/**
|
||||
* Similar to {@link #shouldApplyOnWorld(String, boolean, boolean)}, except this method accepts a List
|
||||
* @param worlds the list of world
|
||||
* @param includeGlobal if global permissions should apply
|
||||
* @return true if the node should apply
|
||||
*/
|
||||
boolean shouldApplyOnAnyWorlds(List<String> worlds, boolean includeGlobal);
|
||||
|
||||
/**
|
||||
* Resolves a list of wildcards that match this node
|
||||
* @param possibleNodes a list of possible permission nodes
|
||||
* @return a list of permissions that match this wildcard
|
||||
*/
|
||||
List<String> resolveWildcard(List<String> possibleNodes);
|
||||
|
||||
/**
|
||||
* Resolves any shorthand parts of this node and returns the full list
|
||||
* @return a list of full nodes
|
||||
*/
|
||||
List<String> resolveShorthand();
|
||||
|
||||
/**
|
||||
* @return true if this node will expire in the future
|
||||
*/
|
||||
boolean isTemporary();
|
||||
|
||||
/**
|
||||
* @return true if this node will not expire
|
||||
*/
|
||||
boolean isPermanent();
|
||||
|
||||
/**
|
||||
* @return the time in Unix time when this node will expire
|
||||
* @throws IllegalStateException if the node is not temporary
|
||||
*/
|
||||
long getExpiryUnixTime();
|
||||
|
||||
/**
|
||||
* @return the {@link Date} when this node will expire
|
||||
* @throws IllegalStateException if the node is not temporary
|
||||
*/
|
||||
Date getExpiry();
|
||||
|
||||
/**
|
||||
* @return the number of seconds until this permission will expire
|
||||
* @throws IllegalStateException if the node is not temporary
|
||||
*/
|
||||
long getSecondsTilExpiry();
|
||||
|
||||
/**
|
||||
* Return true if the node has expired.
|
||||
* This also returns false if the node is not temporary
|
||||
*
|
||||
* @return true if this node has expired
|
||||
*/
|
||||
boolean hasExpired();
|
||||
|
||||
/**
|
||||
* @return the extra contexts required for this node to apply
|
||||
*/
|
||||
Map<String, String> getExtraContexts();
|
||||
|
||||
/**
|
||||
* Converts this node into a serialized form
|
||||
* @return a serialized node string
|
||||
*/
|
||||
String toSerializedNode();
|
||||
|
||||
/**
|
||||
* @return true if this is a group node
|
||||
*/
|
||||
boolean isGroupNode();
|
||||
|
||||
/**
|
||||
* @return the name of the group
|
||||
* @throws IllegalStateException if this is not a group node. See {@link #isGroupNode()}
|
||||
*/
|
||||
String getGroupName();
|
||||
|
||||
/**
|
||||
* @return true is this node is a wildcard node
|
||||
*/
|
||||
boolean isWildcard();
|
||||
|
||||
/**
|
||||
* Gets the level of this wildcard, higher is more specific
|
||||
* @return the wildcard level
|
||||
* @throws IllegalStateException if this is not a wildcard
|
||||
*/
|
||||
int getWildcardLevel();
|
||||
|
||||
/**
|
||||
* @return true if this node is a meta node
|
||||
*/
|
||||
boolean isMeta();
|
||||
|
||||
/**
|
||||
* Gets the meta value from this node
|
||||
* @return the meta value
|
||||
* @throws IllegalStateException if this node is not a meta node
|
||||
*/
|
||||
Map.Entry<String, String> getMeta();
|
||||
|
||||
/**
|
||||
* @return true if this node is a prefix node
|
||||
*/
|
||||
boolean isPrefix();
|
||||
|
||||
/**
|
||||
* Gets the prefix value from this node
|
||||
* @return the prefix value
|
||||
* @throws IllegalStateException if this node is a not a prefix node
|
||||
*/
|
||||
Map.Entry<Integer, String> getPrefix();
|
||||
|
||||
/**
|
||||
* @return true if this node is a suffix node
|
||||
*/
|
||||
boolean isSuffix();
|
||||
|
||||
/**
|
||||
* Gets the suffix value from this node
|
||||
* @return the suffix value
|
||||
* @throws IllegalStateException if this node is a not a suffix node
|
||||
*/
|
||||
Map.Entry<Integer, String> getSuffix();
|
||||
|
||||
/**
|
||||
* Checks if this Node is equal to another node
|
||||
* @param obj the other node
|
||||
* @return true if this node is equal to the other provided
|
||||
* @see #equalsIgnoringValue(Node) for a less strict implementation of this method
|
||||
*/
|
||||
boolean equals(Object obj);
|
||||
|
||||
/**
|
||||
* Similar to {@link Node#equals(Object)}, except doesn't take note of the value
|
||||
* @param other the other node
|
||||
* @return true if the two nodes are almost equal
|
||||
*/
|
||||
boolean equalsIgnoringValue(Node other);
|
||||
|
||||
/**
|
||||
* Similar to {@link Node#equals(Object)}, except doesn't take note of the expiry time or value
|
||||
* @param other the other node
|
||||
* @return true if the two nodes are almost equal
|
||||
*/
|
||||
boolean almostEquals(Node other);
|
||||
|
||||
/**
|
||||
* Similar to {@link Node#equals(Object)}, except doesn't take note of the value or if the node is temporary
|
||||
* @param other the other node
|
||||
* @return true if the two nodes are almost equal
|
||||
* @since 2.8
|
||||
*/
|
||||
boolean equalsIgnoringValueOrTemp(Node other);
|
||||
|
||||
/**
|
||||
* Builds a Node instance
|
||||
*/
|
||||
interface Builder {
|
||||
Builder setNegated(boolean negated);
|
||||
Builder setValue(boolean value);
|
||||
|
||||
/**
|
||||
* Warning: this value does not persist, and disappears when the holder is re-loaded.
|
||||
* It is therefore only useful for transient nodes.
|
||||
*/
|
||||
Builder setOverride(boolean override);
|
||||
|
||||
Builder setExpiry(long expireAt);
|
||||
Builder setWorld(String world);
|
||||
Builder setServer(String server) throws IllegalArgumentException;
|
||||
Builder withExtraContext(String key, String value);
|
||||
Builder withExtraContext(Map<String, String> map);
|
||||
Builder withExtraContext(Map.Entry<String, String> entry);
|
||||
Node build();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -27,25 +27,83 @@ import me.lucko.luckperms.exceptions.ObjectLacksException;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.SortedSet;
|
||||
|
||||
/**
|
||||
* Wrapper interface for internal PermissionHolder (user/group) instances
|
||||
*
|
||||
* <p> The implementations of this interface limit access to the object and add parameter checks to further prevent
|
||||
* errors and ensure all API interactions to not damage the state of the object.
|
||||
* Interface for internal PermissionHolder (user/group) instances
|
||||
*/
|
||||
@SuppressWarnings("unused")
|
||||
public interface PermissionHolder {
|
||||
|
||||
/**
|
||||
* @return the identifier for this object. either a uuid string or name
|
||||
* However, you should really just use {@link User#getUuid()}, {@link User#getName()} or {@link Group#getName()}
|
||||
*/
|
||||
String getObjectName();
|
||||
|
||||
/**
|
||||
* Gets an immutable Set of the objects permission nodes
|
||||
* @return an immutable set of permissions in priority order
|
||||
* @since 2.6
|
||||
*/
|
||||
SortedSet<Node> getPermissions();
|
||||
|
||||
/**
|
||||
* Similar to {@link #getPermissions()}, except excluding transient permissions
|
||||
* @return a set of nodes
|
||||
* @since 2.6
|
||||
*/
|
||||
Set<Node> getEnduringPermissions();
|
||||
|
||||
/**
|
||||
* Similar to {@link #getPermissions()}, except excluding non-transient permissions
|
||||
* @return a set of nodes
|
||||
* @since 2.6
|
||||
*/
|
||||
Set<Node> getTransientPermissions();
|
||||
|
||||
|
||||
/**
|
||||
* Gets an immutable set of the nodes that this object has and inherits
|
||||
* @return an immutable set of permissions
|
||||
* @since 2.6
|
||||
*/
|
||||
Set<Node> getAllNodes();
|
||||
|
||||
/**
|
||||
* Gets an immutable Map of the objects permission nodes
|
||||
* @return an immutable map of permissions
|
||||
* @deprecated in favour of {@link #getPermissions()}
|
||||
*/
|
||||
@Deprecated
|
||||
Map<String, Boolean> getNodes();
|
||||
|
||||
/**
|
||||
* Checks to see if the object has a certain permission
|
||||
* @param node the node to check for
|
||||
* @return a Tristate for the holders permission status for the node
|
||||
* @throws NullPointerException if the node is null
|
||||
* @since 2.6
|
||||
*/
|
||||
Tristate hasPermission(Node node);
|
||||
|
||||
/**
|
||||
* Checks to see if the object has a certain permission
|
||||
* @param node the node to check for
|
||||
* @return a Tristate for the holders permission status for the node
|
||||
* @throws NullPointerException if the node is null
|
||||
* @since 2.6
|
||||
*/
|
||||
Tristate hasTransientPermission(Node node);
|
||||
|
||||
/**
|
||||
* Checks to see if the object has a certain permission
|
||||
* @param node The permission node
|
||||
* @param b If the node is true/false(negated)
|
||||
* @return true if the user has the permission
|
||||
* @return true if the object has the permission
|
||||
* @throws NullPointerException if the node is null
|
||||
* @throws IllegalArgumentException if the node is invalid
|
||||
*/
|
||||
boolean hasPermission(String node, boolean b);
|
||||
|
||||
@@ -54,26 +112,32 @@ public interface PermissionHolder {
|
||||
* @param node The permission node
|
||||
* @param b If the node is true/false(negated)
|
||||
* @param server The server
|
||||
* @return true if the user has the permission
|
||||
* @return true if the object has the permission
|
||||
* @throws NullPointerException if the node or server is null
|
||||
* @throws IllegalArgumentException if the node or server is invalid
|
||||
*/
|
||||
boolean hasPermission(String node, boolean b, String server);
|
||||
|
||||
/**
|
||||
* 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 and world
|
||||
* @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
|
||||
* @return true if the object has the permission
|
||||
* @throws NullPointerException if the node, server or world is null
|
||||
* @throws IllegalArgumentException if the node, server or world is invalid
|
||||
*/
|
||||
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
|
||||
* @param node The permission node
|
||||
* @param b If the node is true/false(negated)
|
||||
* @param temporary if the permission is temporary
|
||||
* @return true if the user has the permission
|
||||
* @return true if the object has the permission
|
||||
* @throws NullPointerException if the node is null
|
||||
* @throws IllegalArgumentException if the node is invalid
|
||||
*/
|
||||
boolean hasPermission(String node, boolean b, boolean temporary);
|
||||
|
||||
@@ -83,26 +147,41 @@ public interface PermissionHolder {
|
||||
* @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
|
||||
* @return true if the object has the permission
|
||||
* @throws NullPointerException if the node or server is null
|
||||
* @throws IllegalArgumentException if the node or server is invalid
|
||||
*/
|
||||
boolean hasPermission(String node, boolean b, String server, boolean temporary);
|
||||
|
||||
/**
|
||||
* 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 and world
|
||||
* @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
|
||||
* @return true if the object has the permission
|
||||
* @throws NullPointerException if the node, server or world is null
|
||||
* @throws IllegalArgumentException if the node, server or world is invalid
|
||||
*/
|
||||
boolean hasPermission(String node, boolean b, String server, String world, boolean temporary);
|
||||
|
||||
/**
|
||||
* Cheks to see if the object inherits a certain permission
|
||||
* @param node the node to check for
|
||||
* @return a Tristate for the holders inheritance status for the node
|
||||
* @throws NullPointerException if the node is null
|
||||
* @since 2.6
|
||||
*/
|
||||
Tristate inheritsPermission(Node node);
|
||||
|
||||
/**
|
||||
* Checks to see if the object inherits a certain permission
|
||||
* @param node The permission node
|
||||
* @param b If the node is true/false(negated)
|
||||
* @return true if the user inherits the permission
|
||||
* @return true if the object inherits the permission
|
||||
* @throws NullPointerException if the node is null
|
||||
* @throws IllegalArgumentException if the node is invalid
|
||||
*/
|
||||
boolean inheritsPermission(String node, boolean b);
|
||||
|
||||
@@ -111,175 +190,282 @@ public interface PermissionHolder {
|
||||
* @param node The permission node
|
||||
* @param b If the node is true/false(negated)
|
||||
* @param server The server
|
||||
* @return true if the user inherits the permission
|
||||
* @return true if the object inherits the permission
|
||||
* @throws NullPointerException if the node or server is null
|
||||
* @throws IllegalArgumentException if the node or server is invalid
|
||||
*/
|
||||
boolean inheritsPermission(String node, boolean b, String server);
|
||||
|
||||
/**
|
||||
* Checks to see the the object inherits a permission on a certain server
|
||||
* Checks to see the the object inherits a permission on a certain server and world
|
||||
* @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
|
||||
* @return true if the object inherits the permission
|
||||
* @throws NullPointerException if the node, server or world is null
|
||||
* @throws IllegalArgumentException if the node server or world is invalid
|
||||
*/
|
||||
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 permission
|
||||
* @param node The permission node
|
||||
* @param b If the node is true/false(negated)
|
||||
* @param temporary if the permission is temporary
|
||||
* @return true if the user inherits the permission
|
||||
* @return true if the object inherits the permission
|
||||
* @throws NullPointerException if the node is null
|
||||
* @throws IllegalArgumentException if the node is invalid
|
||||
*/
|
||||
boolean inheritsPermission(String node, boolean b, boolean temporary);
|
||||
|
||||
/**
|
||||
* Checks to see if the object inherits a certain permission
|
||||
* Checks to see if 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 temporary if the permission is temporary
|
||||
* @return true if the user inherits the permission
|
||||
* @return true if the object inherits the permission
|
||||
* @throws NullPointerException if the node or server is null
|
||||
* @throws IllegalArgumentException if the node or server is invalid
|
||||
*/
|
||||
boolean inheritsPermission(String node, boolean b, String server, boolean temporary);
|
||||
|
||||
/**
|
||||
* Checks to see if the object inherits a certain permission
|
||||
* Checks to see if the object inherits a permission on a certain server and world
|
||||
* @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
|
||||
* @return true if the object inherits the permission
|
||||
* @throws NullPointerException if the node, server or world is null
|
||||
* @throws IllegalArgumentException if the node, server or world if invalid
|
||||
*/
|
||||
boolean inheritsPermission(String node, boolean b, String server, String world, boolean temporary);
|
||||
|
||||
/**
|
||||
* Sets a permission for the object
|
||||
* @param node The node to be set
|
||||
* @throws ObjectAlreadyHasException if the object already has the permission
|
||||
* @throws NullPointerException if the node is null
|
||||
* @since 2.6
|
||||
*/
|
||||
void setPermission(Node node) throws ObjectAlreadyHasException;
|
||||
|
||||
/**
|
||||
* Sets a transient permission for the object
|
||||
*
|
||||
* <p> A transient node is a permission that does not persist.
|
||||
* Whenever a user logs out of the server, or the server restarts, this permission will disappear.
|
||||
* It is never saved to the datastore, and therefore will not apply on other servers.
|
||||
*
|
||||
* <p> This is useful if you want to temporarily set a permission for a user while they're online, but don't
|
||||
* want it to persist, and have to worry about removing it when they log out.
|
||||
*
|
||||
* <p> For unsetting a transient permission, see {@link #unsetTransientPermission(Node)}
|
||||
* @param node The node to be set
|
||||
* @throws ObjectAlreadyHasException if the object already has the permission
|
||||
* @throws NullPointerException if the node is null
|
||||
* @since 2.6
|
||||
*/
|
||||
void setTransientPermission(Node node) throws ObjectAlreadyHasException;
|
||||
|
||||
/**
|
||||
* Sets a permission for the object
|
||||
* @param node The node to be set
|
||||
* @param value What to set the node to - true/false(negated)
|
||||
* @throws ObjectAlreadyHasException if the object already has the permission
|
||||
* @throws NullPointerException if the node is null
|
||||
* @throws IllegalArgumentException if the node is invalid
|
||||
* @deprecated in favour of {@link #setPermission(Node)}
|
||||
*/
|
||||
@Deprecated
|
||||
void setPermission(String node, boolean value) throws ObjectAlreadyHasException;
|
||||
|
||||
/**
|
||||
* Sets a permission for the object
|
||||
* Sets a permission for the object on a specific server
|
||||
* @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
|
||||
* @throws ObjectAlreadyHasException if the object already has the permission
|
||||
* @throws NullPointerException if the node or server is null
|
||||
* @throws IllegalArgumentException if the node or server is invalid
|
||||
* @deprecated in favour of {@link #setPermission(Node)}
|
||||
*/
|
||||
@Deprecated
|
||||
void setPermission(String node, boolean value, String server) throws ObjectAlreadyHasException;
|
||||
|
||||
/**
|
||||
* Sets a permission for the object
|
||||
* Sets a permission for the object on a specific server and world
|
||||
* @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
|
||||
* @throws NullPointerException if the node, server or world is null
|
||||
* @throws IllegalArgumentException if the node, server or world is invalid
|
||||
* @deprecated in favour of {@link #setPermission(Node)}
|
||||
*/
|
||||
@Deprecated
|
||||
void setPermission(String node, boolean value, String server, String world) throws ObjectAlreadyHasException;
|
||||
|
||||
/**
|
||||
* Sets a permission for the object
|
||||
* Sets a temporary permission for the object
|
||||
* @param node The node to set
|
||||
* @param value What to set the node to - true/false(negated)
|
||||
* @param expireAt The time in unixtime when the permission will expire
|
||||
* @throws ObjectAlreadyHasException if the object already has the permission
|
||||
* @throws NullPointerException if the node is null
|
||||
* @throws IllegalArgumentException if the node is invalid or if the expiry time is in the past
|
||||
* @deprecated in favour of {@link #setPermission(Node)}
|
||||
*/
|
||||
@Deprecated
|
||||
void setPermission(String node, boolean value, long expireAt) throws ObjectAlreadyHasException;
|
||||
|
||||
/**
|
||||
* Sets a permission for the object
|
||||
* Sets a temporary permission for the object on a specific server
|
||||
* @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 expireAt The time in unixtime when the permission will expire
|
||||
* @throws ObjectAlreadyHasException if the object already has the permission
|
||||
* @throws NullPointerException if the node or server is null
|
||||
* @throws IllegalArgumentException if the node/server is invalid or if the expiry time is in the past
|
||||
* @deprecated in favour of {@link #setPermission(Node)}
|
||||
*/
|
||||
@Deprecated
|
||||
void setPermission(String node, boolean value, String server, long expireAt) throws ObjectAlreadyHasException;
|
||||
|
||||
/**
|
||||
* Sets a permission for the object
|
||||
* Sets a temporary permission for the object on a specific server and world
|
||||
* @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
|
||||
* @throws NullPointerException if the node, server or world is null
|
||||
* @throws IllegalArgumentException if the node/server/world is invalid, or if the expiry time is in the past
|
||||
* @deprecated in favour of {@link #setPermission(Node)}
|
||||
*/
|
||||
@Deprecated
|
||||
void setPermission(String node, boolean value, String server, String world, long expireAt) throws ObjectAlreadyHasException;
|
||||
|
||||
/**
|
||||
* Unsets a permission for the object
|
||||
* @param node The node to be unset
|
||||
* @throws ObjectLacksException if the node wasn't already set
|
||||
* @throws NullPointerException if the node is null
|
||||
* @since 2.6
|
||||
*/
|
||||
void unsetPermission(Node node) throws ObjectLacksException;
|
||||
|
||||
/**
|
||||
* Unsets a transient permission for the object
|
||||
* @param node The node to be unset
|
||||
* @throws ObjectLacksException if the node wasn't already set
|
||||
* @throws NullPointerException if the node is null
|
||||
* @since 2.6
|
||||
*/
|
||||
void unsetTransientPermission(Node node) throws ObjectLacksException;
|
||||
|
||||
/**
|
||||
* Unsets a permission for the object
|
||||
* @param node The node to be unset
|
||||
* @param temporary if the permission being removed is temporary
|
||||
* @throws ObjectLacksException if the node wasn't already set
|
||||
* @throws NullPointerException if the node is null
|
||||
* @throws IllegalArgumentException if the node is invalid
|
||||
* @deprecated in favour of {@link #unsetPermission(Node)}
|
||||
*/
|
||||
@Deprecated
|
||||
void unsetPermission(String node, boolean temporary) throws ObjectLacksException;
|
||||
|
||||
/**
|
||||
* Unsets a permission for the object
|
||||
* @param node The node to be unset
|
||||
* @throws ObjectLacksException if the node wasn't already set
|
||||
* @throws NullPointerException if the node is null
|
||||
* @throws IllegalArgumentException if the node is invalid
|
||||
* @deprecated in favour of {@link #unsetPermission(Node)}
|
||||
*/
|
||||
@Deprecated
|
||||
void unsetPermission(String node) throws ObjectLacksException;
|
||||
|
||||
/**
|
||||
* Unsets a permission for the object
|
||||
* Unsets a permission for the object on a specific server
|
||||
* @param node The node to be unset
|
||||
* @param server The server to unset the node on
|
||||
* @throws ObjectLacksException if the node wasn't already set
|
||||
* @throws NullPointerException if the node or server is null
|
||||
* @throws IllegalArgumentException if the node or server is invalid
|
||||
* @deprecated in favour of {@link #unsetPermission(Node)}
|
||||
*/
|
||||
@Deprecated
|
||||
void unsetPermission(String node, String server) throws ObjectLacksException;
|
||||
|
||||
/**
|
||||
* Unsets a permission for the object
|
||||
* Unsets a permission for the object on a specific server and world
|
||||
* @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
|
||||
* @throws NullPointerException if the node, server or world is null
|
||||
* @throws IllegalArgumentException if the node, server or world is invalid
|
||||
* @deprecated in favour of {@link #unsetPermission(Node)}
|
||||
*/
|
||||
@Deprecated
|
||||
void unsetPermission(String node, String server, String world) throws ObjectLacksException;
|
||||
|
||||
/**
|
||||
* Unsets a permission for the object
|
||||
* Unsets a permission for the object on a specific server
|
||||
* @param node The node to be unset
|
||||
* @param server The server to unset the node on
|
||||
* @param temporary if the permission being unset is temporary
|
||||
* @throws ObjectLacksException if the node wasn't already set
|
||||
* @throws NullPointerException if the node or server is null
|
||||
* @throws IllegalArgumentException if the node or server is invalid
|
||||
* @deprecated in favour of {@link #unsetPermission(Node)}
|
||||
*/
|
||||
@Deprecated
|
||||
void unsetPermission(String node, String server, boolean temporary) throws ObjectLacksException;
|
||||
|
||||
/**
|
||||
* Unsets a permission for the object
|
||||
* Unsets a permission for the object on a specific server and world
|
||||
* @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
|
||||
* @throws NullPointerException if the node, server or world is null
|
||||
* @throws IllegalArgumentException if the node, server or world is invalid
|
||||
* @deprecated in favour of {@link #unsetPermission(Node)}
|
||||
*/
|
||||
@Deprecated
|
||||
void unsetPermission(String node, String server, String world, boolean temporary) throws ObjectLacksException;
|
||||
|
||||
/**
|
||||
* Gets the permissions and inherited permissions that apply to a specific server
|
||||
* Gets the permissions and inherited permissions that apply to a specific server and world
|
||||
* @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)
|
||||
* @param possibleNodes A list of possible permission nodes for wildcard permission handling
|
||||
* @return a {@link Map} of the permissions
|
||||
* @deprecated in favour of {@link #getPermissions(String, String, Map, boolean, List, boolean)}
|
||||
*/
|
||||
@Deprecated
|
||||
Map<String, Boolean> getLocalPermissions(String server, String world, List<String> excludedGroups, List<String> possibleNodes);
|
||||
|
||||
/**
|
||||
* Gets the permissions and inherited permissions that apply to a specific server
|
||||
* Gets the permissions and inherited permissions that apply to a specific server and world
|
||||
* @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
|
||||
* @deprecated in favour of {@link #getPermissions(String, String, Map, boolean, List, boolean)}
|
||||
*/
|
||||
@Deprecated
|
||||
Map<String, Boolean> getLocalPermissions(String server, String world, List<String> excludedGroups);
|
||||
|
||||
/**
|
||||
@@ -288,7 +474,9 @@ public interface PermissionHolder {
|
||||
* @param excludedGroups Groups that shouldn't be inherited (to prevent circular inheritance issues)
|
||||
* @param possibleNodes A list of possible permission nodes for wildcard permission handling
|
||||
* @return a {@link Map} of the permissions
|
||||
* @deprecated in favour of {@link #getPermissions(String, String, Map, boolean, List, boolean)}
|
||||
*/
|
||||
@Deprecated
|
||||
Map<String, Boolean> getLocalPermissions(String server, List<String> excludedGroups, List<String> possibleNodes);
|
||||
|
||||
/**
|
||||
@@ -296,21 +484,54 @@ public interface PermissionHolder {
|
||||
* @param server The server to get nodes for
|
||||
* @param excludedGroups Groups that shouldn't be inherited (to prevent circular inheritance issues)
|
||||
* @return a {@link Map} of the permissions
|
||||
* @deprecated in favour of {@link #getPermissions(String, String, Map, boolean, List, boolean)}
|
||||
*/
|
||||
@Deprecated
|
||||
Map<String, Boolean> getLocalPermissions(String server, List<String> excludedGroups);
|
||||
|
||||
/**
|
||||
* Processes the objects and returns the temporary ones.
|
||||
* @return a map of temporary nodes
|
||||
* Convert the holders nodes into a Map of permissions to be applied on the platform
|
||||
* @param server the server
|
||||
* @param world the world
|
||||
* @param extraContext any extra context to filter by
|
||||
* @param includeGlobal whether to include global nodes
|
||||
* @param possibleNodes a list of possible permissions for resolving wildcards
|
||||
* @param applyGroups if inherited group permissions should be included
|
||||
* @return a map of permissions
|
||||
* @since 2.6
|
||||
*/
|
||||
Map<String, Boolean> getPermissions(String server, String world, Map<String, String> extraContext, boolean includeGlobal, List<String> possibleNodes, boolean applyGroups);
|
||||
|
||||
/**
|
||||
* Processes the nodes and returns the temporary ones.
|
||||
* @return a map of temporary nodes
|
||||
* @deprecated in favour of {@link #getTemporaryPermissionNodes()}
|
||||
*/
|
||||
@Deprecated
|
||||
Map<Map.Entry<String, Boolean>, Long> getTemporaryNodes();
|
||||
|
||||
/**
|
||||
* Processes the objects and returns the non-temporary ones.
|
||||
* @return a map of permanent nodes
|
||||
* Processes the nodes and returns the temporary ones.
|
||||
* @return a set of temporary nodes
|
||||
* @since 2.6
|
||||
*/
|
||||
Set<Node> getTemporaryPermissionNodes();
|
||||
|
||||
/**
|
||||
* Processes the nodes and returns the non-temporary ones.
|
||||
* @return a map of permanent nodes
|
||||
* @deprecated in favour of {@link #getPermanentPermissionNodes()}
|
||||
*/
|
||||
@Deprecated
|
||||
Map<String, Boolean> getPermanentNodes();
|
||||
|
||||
/**
|
||||
* Processes the nodes and returns the non-temporary ones.
|
||||
* @return a set of permanent nodes
|
||||
* @since 2.6
|
||||
*/
|
||||
Set<Node> getPermanentPermissionNodes();
|
||||
|
||||
/**
|
||||
* Removes temporary permissions that have expired
|
||||
*/
|
||||
|
||||
@@ -0,0 +1,49 @@
|
||||
/*
|
||||
* Copyright (c) 2016 Lucko (Luck) <luck@lucko.me>
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
package me.lucko.luckperms.api;
|
||||
|
||||
/**
|
||||
* Represents the platform type that LuckPerms is running on
|
||||
* @since 2.7
|
||||
*/
|
||||
public enum PlatformType {
|
||||
|
||||
BUKKIT("Bukkit"),
|
||||
BUNGEE("Bungee"),
|
||||
SPONGE("Sponge"),
|
||||
|
||||
/**
|
||||
* @since 2.9
|
||||
*/
|
||||
STANDALONE("Standalone");
|
||||
|
||||
private final String friendlyName;
|
||||
|
||||
PlatformType(String friendlyName) {
|
||||
this.friendlyName = friendlyName;
|
||||
}
|
||||
|
||||
public String getFriendlyName() {
|
||||
return friendlyName;
|
||||
}
|
||||
}
|
||||
@@ -28,19 +28,20 @@ import me.lucko.luckperms.exceptions.ObjectLacksException;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Wrapper interface for internal Track instances
|
||||
*
|
||||
* <p> The implementations of this interface limit access to the Track and add parameter checks to further prevent
|
||||
* errors and ensure all API interactions to not damage the state of the track.
|
||||
* Interface for internal Track instances
|
||||
*/
|
||||
@SuppressWarnings("unused")
|
||||
public interface Track {
|
||||
|
||||
/**
|
||||
* @return the name of this track
|
||||
*/
|
||||
String getName();
|
||||
|
||||
/**
|
||||
* Gets an ordered list of the groups on this track
|
||||
* @return am ordered {@link List} of the groups on this track
|
||||
* Index 0 is the first/lowest group in (or start of) the track
|
||||
* @return an ordered {@link List} of the groups on this track
|
||||
*/
|
||||
List<String> getGroups();
|
||||
|
||||
@@ -55,14 +56,18 @@ public interface Track {
|
||||
* @param current the group before the group being requested
|
||||
* @return the group name, or null if the end of the track has been reached
|
||||
* @throws ObjectLacksException if the track does not contain the group given
|
||||
* @throws NullPointerException if the group is null
|
||||
* @throws IllegalStateException if the group instance was not obtained from LuckPerms.
|
||||
*/
|
||||
String getNext(Group current) throws ObjectLacksException;
|
||||
|
||||
/**
|
||||
* Gets the group before the group provided
|
||||
* Gets the previous group on the track, before the one provided
|
||||
* @param current the group after the group being requested
|
||||
* @return the group name, or null if the start of the track has been reached
|
||||
* @throws ObjectLacksException if the track does not contain the group given
|
||||
* @throws NullPointerException if the group is null
|
||||
* @throws IllegalStateException if the group instance was not obtained from LuckPerms.
|
||||
*/
|
||||
String getPrevious(Group current) throws ObjectLacksException;
|
||||
|
||||
@@ -70,6 +75,8 @@ public interface Track {
|
||||
* Appends a group to the end of this track
|
||||
* @param group the group to append
|
||||
* @throws ObjectAlreadyHasException if the group is already on this track somewhere
|
||||
* @throws NullPointerException if the group is null
|
||||
* @throws IllegalStateException if the group instance was not obtained from LuckPerms.
|
||||
*/
|
||||
void appendGroup(Group group) throws ObjectAlreadyHasException;
|
||||
|
||||
@@ -79,6 +86,8 @@ public interface Track {
|
||||
* @param position the index position (a value of 0 inserts at the start)
|
||||
* @throws ObjectAlreadyHasException if the group is already on this track somewhere
|
||||
* @throws IndexOutOfBoundsException if the position is less than 0 or greater than the size of the track
|
||||
* @throws NullPointerException if the group is null
|
||||
* @throws IllegalStateException if the group instance was not obtained from LuckPerms.
|
||||
*/
|
||||
void insertGroup(Group group, int position) throws ObjectAlreadyHasException, IndexOutOfBoundsException;
|
||||
|
||||
@@ -86,6 +95,8 @@ public interface Track {
|
||||
* Removes a group from this track
|
||||
* @param group the group to remove
|
||||
* @throws ObjectLacksException if the group is not on this track
|
||||
* @throws NullPointerException if the group is null
|
||||
* @throws IllegalStateException if the group instance was not obtained from LuckPerms.
|
||||
*/
|
||||
void removeGroup(Group group) throws ObjectLacksException;
|
||||
|
||||
@@ -93,6 +104,7 @@ public interface Track {
|
||||
* Removes a group from this track
|
||||
* @param group the group to remove
|
||||
* @throws ObjectLacksException if the group is not on this track
|
||||
* @throws NullPointerException if the group is null
|
||||
*/
|
||||
void removeGroup(String group) throws ObjectLacksException;
|
||||
|
||||
@@ -100,6 +112,8 @@ public interface Track {
|
||||
* Checks if a group features on this track
|
||||
* @param group the group to check
|
||||
* @return true if the group is on this track
|
||||
* @throws NullPointerException if the group is null
|
||||
* @throws IllegalStateException if the group instance was not obtained from LuckPerms.
|
||||
*/
|
||||
boolean containsGroup(Group group);
|
||||
|
||||
@@ -107,6 +121,7 @@ public interface Track {
|
||||
* Checks if a group features on this track
|
||||
* @param group the group to check
|
||||
* @return true if the group is on this track
|
||||
* @throws NullPointerException if the group is null
|
||||
*/
|
||||
boolean containsGroup(String group);
|
||||
|
||||
|
||||
@@ -0,0 +1,47 @@
|
||||
/*
|
||||
* Copyright (c) 2016 Lucko (Luck) <luck@lucko.me>
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
package me.lucko.luckperms.api;
|
||||
|
||||
/**
|
||||
* Represents a permission value
|
||||
*/
|
||||
public enum Tristate {
|
||||
|
||||
TRUE(true),
|
||||
FALSE(false),
|
||||
UNDEFINED(false);
|
||||
|
||||
private final boolean booleanValue;
|
||||
|
||||
Tristate(boolean booleanValue) {
|
||||
this.booleanValue = booleanValue;
|
||||
}
|
||||
|
||||
public boolean asBoolean() {
|
||||
return booleanValue;
|
||||
}
|
||||
|
||||
public static Tristate fromBoolean(boolean b) {
|
||||
return b ? TRUE : FALSE;
|
||||
}
|
||||
}
|
||||
@@ -29,10 +29,7 @@ import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
* Wrapper interface for internal User instances
|
||||
*
|
||||
* <p> The implementations of this interface limit access to the User and add parameter checks to further prevent
|
||||
* errors and ensure all API interactions to not damage the state of the user.
|
||||
* Interface for internal User instances
|
||||
*/
|
||||
@SuppressWarnings("unused")
|
||||
public interface User extends PermissionHolder {
|
||||
@@ -55,10 +52,12 @@ public interface User extends PermissionHolder {
|
||||
|
||||
/**
|
||||
* Sets a users primary group
|
||||
* @param s the new primary group
|
||||
* @param group the new primary group
|
||||
* @throws ObjectAlreadyHasException if the user already has this set as their primary group
|
||||
* @throws IllegalStateException if the user is not a member of that group
|
||||
* @throws NullPointerException if the group is null
|
||||
*/
|
||||
void setPrimaryGroup(String s) throws ObjectAlreadyHasException;
|
||||
void setPrimaryGroup(String group) throws ObjectAlreadyHasException;
|
||||
|
||||
/**
|
||||
* Refresh and re-assign the users permissions
|
||||
@@ -69,6 +68,7 @@ public interface User extends PermissionHolder {
|
||||
* Check to see if the user is a member of a group
|
||||
* @param group The group to check membership of
|
||||
* @return true if the user is a member of the group
|
||||
* @throws NullPointerException if the group is null
|
||||
*/
|
||||
boolean isInGroup(Group group);
|
||||
|
||||
@@ -77,15 +77,19 @@ public interface User extends PermissionHolder {
|
||||
* @param group The group to check membership of
|
||||
* @param server The server to check on
|
||||
* @return true if the user is a member of the group
|
||||
* @throws NullPointerException if the group or server is null
|
||||
* @throws IllegalArgumentException if the server is invalid
|
||||
*/
|
||||
boolean isInGroup(Group group, String server);
|
||||
|
||||
/**
|
||||
* Check to see if a user is a member of a group on a specific server
|
||||
* Check to see if a user is a member of a group on a specific server and world
|
||||
* @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
|
||||
* @throws NullPointerException if the group, server or world is null
|
||||
* @throws IllegalArgumentException if the server or world is invalid
|
||||
*/
|
||||
boolean isInGroup(Group group, String server, String world);
|
||||
|
||||
@@ -93,6 +97,8 @@ public interface User extends PermissionHolder {
|
||||
* Add a user to a group
|
||||
* @param group The group to add the user to
|
||||
* @throws ObjectAlreadyHasException if the user is already a member of the group
|
||||
* @throws NullPointerException if the group is null
|
||||
* @throws IllegalStateException if the group instance was not obtained from LuckPerms.
|
||||
*/
|
||||
void addGroup(Group group) throws ObjectAlreadyHasException;
|
||||
|
||||
@@ -101,42 +107,57 @@ public interface User extends PermissionHolder {
|
||||
* @param group The group to add the user to
|
||||
* @param server The server to add the group on
|
||||
* @throws ObjectAlreadyHasException if the user is already a member of the group on that server
|
||||
* @throws NullPointerException if the group or server is null
|
||||
* @throws IllegalStateException if the group instance was not obtained from LuckPerms.
|
||||
* @throws IllegalArgumentException if the server is invalid
|
||||
*/
|
||||
void addGroup(Group group, String server) throws ObjectAlreadyHasException;
|
||||
|
||||
/**
|
||||
* Add a user to a group on a specific server
|
||||
* Add a user to a group on a specific server and world
|
||||
* @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
|
||||
* @throws NullPointerException if the group, server or world is null
|
||||
* @throws IllegalStateException if the group instance was not obtained from LuckPerms.
|
||||
* @throws IllegalArgumentException if the server or world is invalid
|
||||
*/
|
||||
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 temporarily on a specific server
|
||||
* @param group The group to add the user to
|
||||
* @param expireAt when the group should expire
|
||||
* @throws ObjectAlreadyHasException if the user is already a member of the group on that server
|
||||
* @throws NullPointerException if the group is null
|
||||
* @throws IllegalStateException if the group instance was not obtained from LuckPerms.
|
||||
* @throws IllegalArgumentException if the expiry time is in the past
|
||||
*/
|
||||
void addGroup(Group group, long expireAt) throws ObjectAlreadyHasException;
|
||||
|
||||
/**
|
||||
* Add a user to a group on a specific server
|
||||
* Add a user to a group temporarily on a specific server
|
||||
* @param group The group to add the user to
|
||||
* @param server The server 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
|
||||
* @throws NullPointerException if the group or server is null
|
||||
* @throws IllegalStateException if the group instance was not obtained from LuckPerms.
|
||||
* @throws IllegalArgumentException if the expiry time is in the past or the server is invalid
|
||||
*/
|
||||
void addGroup(Group group, String server, long expireAt) throws ObjectAlreadyHasException;
|
||||
|
||||
/**
|
||||
* Add a user to a group on a specific server
|
||||
* Add a user to a group temporarily on a specific server and world
|
||||
* @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
|
||||
* @throws NullPointerException if the group, server or world is null
|
||||
* @throws IllegalStateException if the group instance was not obtained from LuckPerms.
|
||||
* @throws IllegalArgumentException if the expiry time is in the past or the server/world is invalid
|
||||
*/
|
||||
void addGroup(Group group, String server, String world, long expireAt) throws ObjectAlreadyHasException;
|
||||
|
||||
@@ -144,6 +165,8 @@ public interface User extends PermissionHolder {
|
||||
* Remove the user from a group
|
||||
* @param group the group to remove the user from
|
||||
* @throws ObjectLacksException if the user isn't a member of the group
|
||||
* @throws NullPointerException if the group is null
|
||||
* @throws IllegalStateException if the group instance was not obtained from LuckPerms.
|
||||
*/
|
||||
void removeGroup(Group group) throws ObjectLacksException;
|
||||
|
||||
@@ -152,42 +175,56 @@ public interface User extends PermissionHolder {
|
||||
* @param group the group to remove the user from
|
||||
* @param temporary if the group being removed is temporary
|
||||
* @throws ObjectLacksException if the user isn't a member of the group
|
||||
* @throws NullPointerException if the group is null
|
||||
* @throws IllegalStateException if the group instance was not obtained from LuckPerms.
|
||||
*/
|
||||
void removeGroup(Group group, boolean temporary) throws ObjectLacksException;
|
||||
|
||||
/**
|
||||
* Remove the user from a group
|
||||
* Remove the user from a group on a specific server
|
||||
* @param group The group to remove the user from
|
||||
* @param server The server to remove the group on
|
||||
* @throws ObjectLacksException if the user isn't a member of the group
|
||||
* @throws NullPointerException if the group or server is null
|
||||
* @throws IllegalStateException if the group instance was not obtained from LuckPerms.
|
||||
* @throws IllegalArgumentException if the server is invalid
|
||||
*/
|
||||
void removeGroup(Group group, String server) throws ObjectLacksException;
|
||||
|
||||
/**
|
||||
* Remove the user from a group
|
||||
* Remove the user from a group on a specific server and world
|
||||
* @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
|
||||
* @throws NullPointerException if the group, server or world is null
|
||||
* @throws IllegalStateException if the group instance was not obtained from LuckPerms.
|
||||
* @throws IllegalArgumentException if the server or world is invalid
|
||||
*/
|
||||
void removeGroup(Group group, String server, String world) throws ObjectLacksException;
|
||||
|
||||
/**
|
||||
* Remove the user from a group
|
||||
* Remove the user from a group on a specific server
|
||||
* @param group The group to remove the user from
|
||||
* @param server The server 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
|
||||
* @throws NullPointerException if the group or server is null
|
||||
* @throws IllegalStateException if the group instance was not obtained from LuckPerms.
|
||||
* @throws IllegalArgumentException if the expiry time is in the past or the server is invalid
|
||||
*/
|
||||
void removeGroup(Group group, String server, boolean temporary) throws ObjectLacksException;
|
||||
|
||||
/**
|
||||
* Remove the user from a group
|
||||
* Remove the user from a group on a specific server and world
|
||||
* @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
|
||||
* @throws NullPointerException if the group, server or world is null
|
||||
* @throws IllegalStateException if the group instance was not obtained from LuckPerms.
|
||||
* @throws IllegalArgumentException if the expiry time is in the past or the server/world is invalid
|
||||
*/
|
||||
void removeGroup(Group group, String server, String world, boolean temporary) throws ObjectLacksException;
|
||||
|
||||
@@ -207,6 +244,8 @@ public interface User extends PermissionHolder {
|
||||
* @param server the server to check
|
||||
* @param world the world to check
|
||||
* @return a {@link List} of group names
|
||||
* @throws NullPointerException if the server or world is null
|
||||
* @throws IllegalArgumentException if the server or world is invalid
|
||||
*/
|
||||
List<String> getLocalGroups(String server, String world);
|
||||
|
||||
@@ -214,6 +253,8 @@ public interface User extends PermissionHolder {
|
||||
* 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
|
||||
* @throws NullPointerException if the server is null
|
||||
* @throws IllegalArgumentException if the server is invalid
|
||||
*/
|
||||
List<String> getLocalGroups(String server);
|
||||
|
||||
|
||||
@@ -25,7 +25,9 @@ package me.lucko.luckperms.api;
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
* This UuidCache is a means of allowing users to have the same internal UUID across a network of offline mode servers
|
||||
* A UUID cache for online users, between external Mojang UUIDs, and internal LuckPerms UUIDs.
|
||||
*
|
||||
* <p> This UuidCache is a means of allowing users to have the same internal UUID across a network of offline mode servers
|
||||
* or mixed offline mode and online mode servers. Platforms running in offline mode generate a random UUID for a user when
|
||||
* they first join the server, but this UUID will then not be consistent across the network. LuckPerms will instead check
|
||||
* the datastore cache, to get a UUID for a user that is consistent across an entire network.
|
||||
@@ -35,6 +37,7 @@ import java.util.UUID;
|
||||
*
|
||||
* <p> WARNING: THIS IS ONLY EFFECTIVE FOR ONLINE PLAYERS. USE THE DATASTORE METHODS FOR OFFLINE PLAYERS.
|
||||
*/
|
||||
@SuppressWarnings("unused")
|
||||
public interface UuidCache {
|
||||
|
||||
/**
|
||||
|
||||
@@ -22,23 +22,36 @@
|
||||
|
||||
package me.lucko.luckperms.api.data;
|
||||
|
||||
import lombok.NonNull;
|
||||
|
||||
import java.util.function.Consumer;
|
||||
|
||||
/**
|
||||
* A callback used to wait for the completion of asynchronous operations.
|
||||
* All callbacks are ran on the main server thread.
|
||||
* @param <T> the return type
|
||||
*/
|
||||
public interface Callback<T> {
|
||||
|
||||
/**
|
||||
* Called when the operation completes.
|
||||
* @param t the return value, may be null
|
||||
*/
|
||||
void onComplete(T t);
|
||||
|
||||
static <T> Callback<T> empty() {
|
||||
return t -> {};
|
||||
}
|
||||
|
||||
static <T> Callback<T> of(@NonNull Runnable runnable) {
|
||||
static <T> Callback<T> of(Runnable runnable) {
|
||||
if (runnable == null) {
|
||||
throw new NullPointerException("runnable");
|
||||
}
|
||||
return t -> runnable.run();
|
||||
}
|
||||
|
||||
static <T> Callback<T> of(@NonNull Consumer<T> consumer) {
|
||||
static <T> Callback<T> of(Consumer<T> consumer) {
|
||||
if (consumer == null) {
|
||||
throw new NullPointerException("consumer");
|
||||
}
|
||||
return consumer::accept;
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,37 @@
|
||||
/*
|
||||
* Copyright (c) 2016 Lucko (Luck) <luck@lucko.me>
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
package me.lucko.luckperms.api.data;
|
||||
|
||||
/**
|
||||
* Represents the data section of the main LuckPerms configuration.
|
||||
* All methods could return null.
|
||||
*/
|
||||
@SuppressWarnings("deprecation")
|
||||
public interface DatastoreConfiguration extends MySQLConfiguration {
|
||||
|
||||
String getAddress();
|
||||
String getDatabase();
|
||||
String getUsername();
|
||||
String getPassword();
|
||||
|
||||
}
|
||||
@@ -22,6 +22,10 @@
|
||||
|
||||
package me.lucko.luckperms.api.data;
|
||||
|
||||
/**
|
||||
* @deprecated Use {@link DatastoreConfiguration}. This is now used by multiple datastores, not just MySQL.
|
||||
*/
|
||||
@Deprecated
|
||||
public interface MySQLConfiguration {
|
||||
|
||||
String getAddress();
|
||||
|
||||
@@ -0,0 +1,57 @@
|
||||
/*
|
||||
* Copyright (c) 2016 Lucko (Luck) <luck@lucko.me>
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
package me.lucko.luckperms.api.event;
|
||||
|
||||
import me.lucko.luckperms.api.PermissionHolder;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
public class AbstractPermissionAddEvent extends TargetedEvent<PermissionHolder> {
|
||||
|
||||
private final String server;
|
||||
private final String world;
|
||||
private final long expiry;
|
||||
|
||||
protected AbstractPermissionAddEvent(String eventName, PermissionHolder target, String server, String world, long expiry) {
|
||||
super(eventName, target);
|
||||
this.server = server;
|
||||
this.world = world;
|
||||
this.expiry = expiry;
|
||||
}
|
||||
|
||||
public Optional<String> getServer() {
|
||||
return Optional.ofNullable(server);
|
||||
}
|
||||
|
||||
public Optional<String> getWorld() {
|
||||
return Optional.ofNullable(world);
|
||||
}
|
||||
|
||||
public boolean isTemporary() {
|
||||
return expiry != 0L;
|
||||
}
|
||||
|
||||
public long getExpiry() {
|
||||
return expiry;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
/*
|
||||
* Copyright (c) 2016 Lucko (Luck) <luck@lucko.me>
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
package me.lucko.luckperms.api.event;
|
||||
|
||||
import me.lucko.luckperms.api.Node;
|
||||
import me.lucko.luckperms.api.PermissionHolder;
|
||||
|
||||
/**
|
||||
* @since 2.6
|
||||
*/
|
||||
public class AbstractPermissionEvent extends TargetedEvent<PermissionHolder> {
|
||||
|
||||
private final Node node;
|
||||
|
||||
protected AbstractPermissionEvent(String eventName, PermissionHolder target, Node node) {
|
||||
super(eventName, target);
|
||||
this.node = node;
|
||||
}
|
||||
|
||||
public Node getNode() {
|
||||
return node;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,62 @@
|
||||
/*
|
||||
* Copyright (c) 2016 Lucko (Luck) <luck@lucko.me>
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
package me.lucko.luckperms.api.event;
|
||||
|
||||
import me.lucko.luckperms.api.PermissionHolder;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
public class AbstractPermissionRemoveEvent extends TargetedEvent<PermissionHolder> {
|
||||
|
||||
private final String server;
|
||||
private final String world;
|
||||
private final boolean temporary;
|
||||
|
||||
protected AbstractPermissionRemoveEvent(String eventName, PermissionHolder target, String server, String world, boolean temporary) {
|
||||
super(eventName, target);
|
||||
this.server = server;
|
||||
this.world = world;
|
||||
this.temporary = temporary;
|
||||
}
|
||||
|
||||
public Optional<String> getServer() {
|
||||
return Optional.ofNullable(server);
|
||||
}
|
||||
|
||||
public Optional<String> getWorld() {
|
||||
return Optional.ofNullable(world);
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated use {@link #isTemporary()}
|
||||
*/
|
||||
@Deprecated
|
||||
public boolean getTemporary() {
|
||||
return temporary;
|
||||
}
|
||||
|
||||
public boolean isTemporary() {
|
||||
return temporary;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
/*
|
||||
* Copyright (c) 2016 Lucko (Luck) <luck@lucko.me>
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
package me.lucko.luckperms.api.event;
|
||||
|
||||
/**
|
||||
* Event that allows listeners to set the cancelled state of an event.
|
||||
*/
|
||||
public abstract class CancellableEvent extends LPEvent {
|
||||
|
||||
private boolean cancelled = false;
|
||||
|
||||
protected CancellableEvent(String eventName) {
|
||||
super(eventName);
|
||||
}
|
||||
|
||||
public boolean isCancelled() {
|
||||
return cancelled;
|
||||
}
|
||||
|
||||
public void setCancelled(boolean cancelled) {
|
||||
this.cancelled = cancelled;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,61 @@
|
||||
/*
|
||||
* Copyright (c) 2016 Lucko (Luck) <luck@lucko.me>
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
package me.lucko.luckperms.api.event;
|
||||
|
||||
import me.lucko.luckperms.api.LuckPermsApi;
|
||||
|
||||
/**
|
||||
* Abstract LuckPerms Event class.
|
||||
*/
|
||||
public abstract class LPEvent {
|
||||
|
||||
/**
|
||||
* A link to the API instance provided for convenience.
|
||||
*/
|
||||
private LuckPermsApi api = null;
|
||||
|
||||
/**
|
||||
* A friendly name of the event
|
||||
*/
|
||||
private final String eventName;
|
||||
|
||||
protected LPEvent(String eventName) {
|
||||
this.eventName = eventName;
|
||||
}
|
||||
|
||||
public String getEventName() {
|
||||
return eventName;
|
||||
}
|
||||
|
||||
public LuckPermsApi getApi() {
|
||||
return api;
|
||||
}
|
||||
|
||||
public void setApi(LuckPermsApi api) {
|
||||
if (this.api != null) {
|
||||
throw new IllegalStateException("API can only be set once.");
|
||||
}
|
||||
this.api = api;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
/*
|
||||
* Copyright (c) 2016 Lucko (Luck) <luck@lucko.me>
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
package me.lucko.luckperms.api.event;
|
||||
|
||||
/**
|
||||
* Used to mark a class that listens for LuckPerms events
|
||||
*/
|
||||
public interface LPListener {
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
/*
|
||||
* Copyright (c) 2016 Lucko (Luck) <luck@lucko.me>
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
package me.lucko.luckperms.api.event;
|
||||
|
||||
/**
|
||||
* Represents an event acting upon a target
|
||||
* @param <T> the target type
|
||||
*/
|
||||
public class TargetedEvent<T> extends LPEvent {
|
||||
|
||||
private final T target;
|
||||
|
||||
protected TargetedEvent(String eventName, T target) {
|
||||
super(eventName);
|
||||
this.target = target;
|
||||
}
|
||||
|
||||
public T getTarget() {
|
||||
return target;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,58 @@
|
||||
/*
|
||||
* Copyright (c) 2016 Lucko (Luck) <luck@lucko.me>
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
package me.lucko.luckperms.api.event;
|
||||
|
||||
import me.lucko.luckperms.api.Track;
|
||||
import me.lucko.luckperms.api.User;
|
||||
|
||||
public abstract class TrackEvent extends LPEvent {
|
||||
|
||||
private final Track track;
|
||||
private final User user;
|
||||
private final String fromGroup;
|
||||
private final String toGroup;
|
||||
|
||||
protected TrackEvent(String eventName, Track track, User user, String fromGroup, String toGroup) {
|
||||
super(eventName);
|
||||
this.track = track;
|
||||
this.user = user;
|
||||
this.fromGroup = fromGroup;
|
||||
this.toGroup = toGroup;
|
||||
}
|
||||
|
||||
public Track getTrack() {
|
||||
return track;
|
||||
}
|
||||
|
||||
public User getUser() {
|
||||
return user;
|
||||
}
|
||||
|
||||
public String getFromGroup() {
|
||||
return fromGroup;
|
||||
}
|
||||
|
||||
public String getToGroup() {
|
||||
return toGroup;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
/*
|
||||
* Copyright (c) 2016 Lucko (Luck) <luck@lucko.me>
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
package me.lucko.luckperms.api.event;
|
||||
|
||||
import me.lucko.luckperms.api.User;
|
||||
|
||||
/**
|
||||
* Represents an event acting upon a user.
|
||||
*/
|
||||
public class UserEvent extends LPEvent {
|
||||
|
||||
private final User user;
|
||||
|
||||
protected UserEvent(String eventName, User user) {
|
||||
super(eventName);
|
||||
this.user = user;
|
||||
}
|
||||
|
||||
public User getUser() {
|
||||
return user;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
/*
|
||||
* Copyright (c) 2016 Lucko (Luck) <luck@lucko.me>
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
package me.lucko.luckperms.api.event.events;
|
||||
|
||||
import me.lucko.luckperms.api.Group;
|
||||
import me.lucko.luckperms.api.PermissionHolder;
|
||||
import me.lucko.luckperms.api.event.AbstractPermissionAddEvent;
|
||||
|
||||
/**
|
||||
* Called whenever a user or group is added to / starts to inherit another group
|
||||
*/
|
||||
public class GroupAddEvent extends AbstractPermissionAddEvent {
|
||||
|
||||
/**
|
||||
* The group being added to the target
|
||||
*/
|
||||
private final Group group;
|
||||
|
||||
public GroupAddEvent(PermissionHolder target, Group group, String server, String world, long expiry) {
|
||||
super("Group Add Event", target, server, world, expiry);
|
||||
this.group = group;
|
||||
}
|
||||
|
||||
public Group getGroup() {
|
||||
return group;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
/*
|
||||
* Copyright (c) 2016 Lucko (Luck) <luck@lucko.me>
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
package me.lucko.luckperms.api.event.events;
|
||||
|
||||
import me.lucko.luckperms.api.PermissionHolder;
|
||||
import me.lucko.luckperms.api.event.AbstractPermissionRemoveEvent;
|
||||
|
||||
/**
|
||||
* Called whenever a user or group is removed from / stops inheriting another group
|
||||
*/
|
||||
public class GroupRemoveEvent extends AbstractPermissionRemoveEvent {
|
||||
|
||||
/**
|
||||
* The name of group being removed from the target.
|
||||
* Be aware that this group may have already been deleted, and and instance may therefore not exist internally.
|
||||
*/
|
||||
private final String group;
|
||||
|
||||
public GroupRemoveEvent(PermissionHolder target, String group, String server, String world, boolean temporary) {
|
||||
super("Group Remove Event", target, server, world, temporary);
|
||||
this.group = group;
|
||||
}
|
||||
|
||||
public String getGroup() {
|
||||
return group;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,49 @@
|
||||
/*
|
||||
* Copyright (c) 2016 Lucko (Luck) <luck@lucko.me>
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
package me.lucko.luckperms.api.event.events;
|
||||
|
||||
import me.lucko.luckperms.api.LogEntry;
|
||||
import me.lucko.luckperms.api.event.CancellableEvent;
|
||||
|
||||
/**
|
||||
* Called before a LogEntry is broadcasted to players only with the notify permission.
|
||||
* The log entry will still be recorded in the datastore, regardless of the cancellation state of this event.
|
||||
* Cancelling this event only stops the broadcast.
|
||||
*/
|
||||
public class LogNotifyEvent extends CancellableEvent {
|
||||
|
||||
/**
|
||||
* The log entry to be broadcasted
|
||||
*/
|
||||
private final LogEntry entry;
|
||||
|
||||
public LogNotifyEvent(LogEntry entry) {
|
||||
super("Log Notify Event");
|
||||
this.entry = entry;
|
||||
}
|
||||
|
||||
public LogEntry getEntry() {
|
||||
return entry;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,45 @@
|
||||
/*
|
||||
* Copyright (c) 2016 Lucko (Luck) <luck@lucko.me>
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
package me.lucko.luckperms.api.event.events;
|
||||
|
||||
import me.lucko.luckperms.api.PermissionHolder;
|
||||
import me.lucko.luckperms.api.event.TargetedEvent;
|
||||
|
||||
/**
|
||||
* Called when a permission expires for an object.
|
||||
* @deprecated in favour of {@link PermissionNodeExpireEvent}
|
||||
*/
|
||||
@Deprecated
|
||||
public class PermissionExpireEvent extends TargetedEvent<PermissionHolder> {
|
||||
|
||||
private final String node;
|
||||
|
||||
public PermissionExpireEvent(PermissionHolder target, String node) {
|
||||
super("Permission Expire Event", target);
|
||||
this.node = node;
|
||||
}
|
||||
|
||||
public String getNode() {
|
||||
return node;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
/*
|
||||
* Copyright (c) 2016 Lucko (Luck) <luck@lucko.me>
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
package me.lucko.luckperms.api.event.events;
|
||||
|
||||
import me.lucko.luckperms.api.Node;
|
||||
import me.lucko.luckperms.api.PermissionHolder;
|
||||
import me.lucko.luckperms.api.event.AbstractPermissionEvent;
|
||||
|
||||
/**
|
||||
* Called when a temporary permission node expires
|
||||
* @since 2.6
|
||||
*/
|
||||
public class PermissionNodeExpireEvent extends AbstractPermissionEvent {
|
||||
public PermissionNodeExpireEvent(PermissionHolder target, Node node) {
|
||||
super("Permission Node Expire Event", target, node);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
/*
|
||||
* Copyright (c) 2016 Lucko (Luck) <luck@lucko.me>
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
package me.lucko.luckperms.api.event.events;
|
||||
|
||||
import me.lucko.luckperms.api.Node;
|
||||
import me.lucko.luckperms.api.PermissionHolder;
|
||||
import me.lucko.luckperms.api.event.AbstractPermissionEvent;
|
||||
|
||||
/**
|
||||
* Called when a permission node is set on a holder
|
||||
* @since 2.6
|
||||
*/
|
||||
public class PermissionNodeSetEvent extends AbstractPermissionEvent {
|
||||
public PermissionNodeSetEvent(PermissionHolder target, Node node) {
|
||||
super("Permission Node Set Event", target, node);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
/*
|
||||
* Copyright (c) 2016 Lucko (Luck) <luck@lucko.me>
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
package me.lucko.luckperms.api.event.events;
|
||||
|
||||
import me.lucko.luckperms.api.Node;
|
||||
import me.lucko.luckperms.api.PermissionHolder;
|
||||
import me.lucko.luckperms.api.event.AbstractPermissionEvent;
|
||||
|
||||
/**
|
||||
* Called when a permission node is unset from a holder
|
||||
* @since 2.6
|
||||
*/
|
||||
public class PermissionNodeUnsetEvent extends AbstractPermissionEvent {
|
||||
public PermissionNodeUnsetEvent(PermissionHolder target, Node node) {
|
||||
super("Permission Node Unset Event", target, node);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,58 @@
|
||||
/*
|
||||
* Copyright (c) 2016 Lucko (Luck) <luck@lucko.me>
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
package me.lucko.luckperms.api.event.events;
|
||||
|
||||
import me.lucko.luckperms.api.PermissionHolder;
|
||||
import me.lucko.luckperms.api.event.AbstractPermissionAddEvent;
|
||||
|
||||
import java.util.AbstractMap;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* Called whenever a user or group has a permission set.
|
||||
* @deprecated in favour of {@link PermissionNodeSetEvent}
|
||||
*/
|
||||
@Deprecated
|
||||
public class PermissionSetEvent extends AbstractPermissionAddEvent {
|
||||
|
||||
private final String node;
|
||||
private final boolean value;
|
||||
|
||||
public PermissionSetEvent(PermissionHolder target, String node, boolean value, String server, String world, long expiry) {
|
||||
super("Permission Set Event", target, server, world, expiry);
|
||||
this.node = node;
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
public String getNode() {
|
||||
return node;
|
||||
}
|
||||
|
||||
public boolean getValue() {
|
||||
return value;
|
||||
}
|
||||
|
||||
public Map.Entry<String, Boolean> getEntry() {
|
||||
return new AbstractMap.SimpleEntry<>(node, value);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,45 @@
|
||||
/*
|
||||
* Copyright (c) 2016 Lucko (Luck) <luck@lucko.me>
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
package me.lucko.luckperms.api.event.events;
|
||||
|
||||
import me.lucko.luckperms.api.PermissionHolder;
|
||||
import me.lucko.luckperms.api.event.AbstractPermissionRemoveEvent;
|
||||
|
||||
/**
|
||||
* Called whenever a user or group has a permission unset.
|
||||
* @deprecated in favour of {@link PermissionNodeUnsetEvent}
|
||||
*/
|
||||
@Deprecated
|
||||
public class PermissionUnsetEvent extends AbstractPermissionRemoveEvent {
|
||||
|
||||
private final String node;
|
||||
|
||||
public PermissionUnsetEvent(PermissionHolder target, String node, String server, String world, boolean temporary) {
|
||||
super("Permission Unset Event", target, server, world, temporary);
|
||||
this.node = node;
|
||||
}
|
||||
|
||||
public String getNode() {
|
||||
return node;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
/*
|
||||
* Copyright (c) 2016 Lucko (Luck) <luck@lucko.me>
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
package me.lucko.luckperms.api.event.events;
|
||||
|
||||
import me.lucko.luckperms.api.event.LPEvent;
|
||||
|
||||
/**
|
||||
* Called after the sync task has ran.
|
||||
*/
|
||||
public class PostSyncEvent extends LPEvent {
|
||||
|
||||
public PostSyncEvent() {
|
||||
super("Post Sync Event");
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
/*
|
||||
* Copyright (c) 2016 Lucko (Luck) <luck@lucko.me>
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
package me.lucko.luckperms.api.event.events;
|
||||
|
||||
import me.lucko.luckperms.api.event.CancellableEvent;
|
||||
|
||||
/**
|
||||
* Called before the sync task is about to run.
|
||||
* Set this event to cancelled to prevent the sync task from running.
|
||||
*/
|
||||
public class PreSyncEvent extends CancellableEvent {
|
||||
|
||||
public PreSyncEvent() {
|
||||
super("Pre Sync Event");
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
/*
|
||||
* Copyright (c) 2016 Lucko (Luck) <luck@lucko.me>
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
package me.lucko.luckperms.api.event.events;
|
||||
|
||||
import me.lucko.luckperms.api.Track;
|
||||
import me.lucko.luckperms.api.User;
|
||||
import me.lucko.luckperms.api.event.TrackEvent;
|
||||
|
||||
/**
|
||||
* Called whenever a user is demoted down a track
|
||||
*/
|
||||
public class UserDemoteEvent extends TrackEvent {
|
||||
|
||||
public UserDemoteEvent(Track track, User user, String from, String to) {
|
||||
super("User Demote Event", track, user, from, to);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,54 @@
|
||||
/*
|
||||
* Copyright (c) 2016 Lucko (Luck) <luck@lucko.me>
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
package me.lucko.luckperms.api.event.events;
|
||||
|
||||
import me.lucko.luckperms.api.event.LPEvent;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
* Called when the user logs into the network for the first time.
|
||||
* Particularly useful for networks with multiple lobbies, who want to welcome a user when they join for the first time.
|
||||
*
|
||||
* <p>This event is fired before the player has actually joined the game on the async login / auth event.
|
||||
* If you want to do something with the user, store the UUID in a set, and then check the set in the PlayerJoinEvent o.e.
|
||||
*/
|
||||
public class UserFirstLoginEvent extends LPEvent {
|
||||
|
||||
private final UUID uuid;
|
||||
private final String username;
|
||||
|
||||
public UserFirstLoginEvent(UUID uuid, String username) {
|
||||
super("User First Join Event");
|
||||
this.uuid = uuid;
|
||||
this.username = username;
|
||||
}
|
||||
|
||||
public UUID getUuid() {
|
||||
return uuid;
|
||||
}
|
||||
|
||||
public String getUsername() {
|
||||
return username;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
/*
|
||||
* Copyright (c) 2016 Lucko (Luck) <luck@lucko.me>
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
package me.lucko.luckperms.api.event.events;
|
||||
|
||||
import me.lucko.luckperms.api.User;
|
||||
import me.lucko.luckperms.api.event.UserEvent;
|
||||
|
||||
/**
|
||||
* Called after a user has their permissions refreshed.
|
||||
* If you cache user permissions within your own plugin, it's a good idea to update said cache whenever this event is called.
|
||||
*/
|
||||
public class UserPermissionRefreshEvent extends UserEvent {
|
||||
|
||||
public UserPermissionRefreshEvent(User user) {
|
||||
super("User Permission Refresh Event", user);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
/*
|
||||
* Copyright (c) 2016 Lucko (Luck) <luck@lucko.me>
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
package me.lucko.luckperms.api.event.events;
|
||||
|
||||
import me.lucko.luckperms.api.Track;
|
||||
import me.lucko.luckperms.api.User;
|
||||
import me.lucko.luckperms.api.event.TrackEvent;
|
||||
|
||||
/**
|
||||
* Called whenever a user is promoted up a track
|
||||
*/
|
||||
public class UserPromoteEvent extends TrackEvent {
|
||||
|
||||
public UserPromoteEvent(Track track, User user, String from, String to) {
|
||||
super("User Promote Event", track, user, from, to);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
/*
|
||||
* Copyright (c) 2016 Lucko (Luck) <luck@lucko.me>
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
package me.lucko.luckperms.exceptions;
|
||||
|
||||
/**
|
||||
* Thrown when a permission holding object doesn't / already has a permission or isn't / is already is a member of a group
|
||||
* @since 2.7
|
||||
*/
|
||||
public abstract class MembershipException extends Exception {
|
||||
}
|
||||
@@ -26,5 +26,5 @@ package me.lucko.luckperms.exceptions;
|
||||
* Thrown when a permission holding object already has a permission, is already a member of a group, or when a track
|
||||
* already contains a group.
|
||||
*/
|
||||
public class ObjectAlreadyHasException extends Exception {
|
||||
public class ObjectAlreadyHasException extends MembershipException {
|
||||
}
|
||||
@@ -26,5 +26,5 @@ package me.lucko.luckperms.exceptions;
|
||||
* Thrown when a permission holding object does not already have a permission, is not already a member of a group,
|
||||
* or when a track doesn't contain a group.
|
||||
*/
|
||||
public class ObjectLacksException extends Exception {
|
||||
public class ObjectLacksException extends MembershipException {
|
||||
}
|
||||
@@ -0,0 +1,119 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<parent>
|
||||
<artifactId>luckperms</artifactId>
|
||||
<groupId>me.lucko.luckperms</groupId>
|
||||
<version>2.9-SNAPSHOT</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<artifactId>luckperms-bukkit-legacy</artifactId>
|
||||
<build>
|
||||
<defaultGoal>clean package</defaultGoal>
|
||||
<finalName>LuckPerms-bukkit-legacy-${release.version}.${git.closest.tag.commit.count}</finalName>
|
||||
<resources>
|
||||
<resource>
|
||||
<directory>src/main/resources</directory>
|
||||
<filtering>true</filtering>
|
||||
</resource>
|
||||
</resources>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
<version>3.5.1</version>
|
||||
<configuration>
|
||||
<source>1.8</source>
|
||||
<target>1.8</target>
|
||||
</configuration>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-shade-plugin</artifactId>
|
||||
<version>2.4.3</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<phase>package</phase>
|
||||
<goals>
|
||||
<goal>shade</goal>
|
||||
</goals>
|
||||
<configuration>
|
||||
<minimizeJar>false</minimizeJar>
|
||||
<artifactSet>
|
||||
<excludes>
|
||||
<exclude>org.xerial:*</exclude>
|
||||
</excludes>
|
||||
</artifactSet>
|
||||
<relocations>
|
||||
<relocation>
|
||||
<pattern>org.slf4j</pattern>
|
||||
<shadedPattern>me.lucko.luckperms.lib.slf4j</shadedPattern>
|
||||
</relocation>
|
||||
<relocation>
|
||||
<pattern>com.zaxxer.hikari</pattern>
|
||||
<shadedPattern>me.lucko.luckperms.lib.hikari</shadedPattern>
|
||||
</relocation>
|
||||
<relocation>
|
||||
<pattern>com.mongodb</pattern>
|
||||
<shadedPattern>me.lucko.luckperms.lib.mongodb</shadedPattern>
|
||||
</relocation>
|
||||
<relocation>
|
||||
<pattern>org.bson</pattern>
|
||||
<shadedPattern>me.lucko.luckperms.lib.bson</shadedPattern>
|
||||
</relocation>
|
||||
<relocation>
|
||||
<pattern>org.h2</pattern>
|
||||
<shadedPattern>me.lucko.luckperms.lib.h2</shadedPattern>
|
||||
</relocation>
|
||||
</relocations>
|
||||
</configuration>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>pl.project13.maven</groupId>
|
||||
<artifactId>git-commit-id-plugin</artifactId>
|
||||
<version>2.2.1</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<goals>
|
||||
<goal>revision</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
<configuration>
|
||||
<injectAllReactorProjects>true</injectAllReactorProjects>
|
||||
</configuration>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
|
||||
<dependencies>
|
||||
<!-- LuckPerms Bukkit -->
|
||||
<dependency>
|
||||
<groupId>me.lucko.luckperms</groupId>
|
||||
<artifactId>luckperms-bukkit</artifactId>
|
||||
<version>${project.version}</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
|
||||
<!-- Shade gson and guava, as they are not included in earlier Bukkit releases -->
|
||||
<!-- gson -->
|
||||
<dependency>
|
||||
<groupId>com.google.code.gson</groupId>
|
||||
<artifactId>gson</artifactId>
|
||||
<version>2.7</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
<!-- guava -->
|
||||
<dependency>
|
||||
<groupId>com.google.guava</groupId>
|
||||
<artifactId>guava</artifactId>
|
||||
<version>19.0</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
</project>
|
||||
@@ -0,0 +1,52 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<parent>
|
||||
<artifactId>luckperms</artifactId>
|
||||
<groupId>me.lucko.luckperms</groupId>
|
||||
<version>2.9-SNAPSHOT</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<artifactId>luckperms-bukkit-placeholders</artifactId>
|
||||
<build>
|
||||
<finalName>LuckPermsPlaceholderExpansion</finalName>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
<version>3.5.1</version>
|
||||
<configuration>
|
||||
<source>1.8</source>
|
||||
<target>1.8</target>
|
||||
</configuration>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
|
||||
<dependencies>
|
||||
<!-- LuckPerms API -->
|
||||
<dependency>
|
||||
<groupId>me.lucko.luckperms</groupId>
|
||||
<artifactId>luckperms-api</artifactId>
|
||||
<version>2.8</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<!-- BukkitAPI -->
|
||||
<dependency>
|
||||
<groupId>org.bukkit</groupId>
|
||||
<artifactId>bukkit</artifactId>
|
||||
<version>1.8.8-R0.1-SNAPSHOT</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<!-- PlaceholderAPI -->
|
||||
<dependency>
|
||||
<groupId>me.clip</groupId>
|
||||
<artifactId>placeholderapi</artifactId>
|
||||
<version>2.2.0</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
</project>
|
||||
+182
@@ -0,0 +1,182 @@
|
||||
/*
|
||||
* Copyright (c) 2016 Lucko (Luck) <luck@lucko.me>
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
package me.lucko.luckperms.api.placeholders;
|
||||
|
||||
import me.clip.placeholderapi.PlaceholderAPIPlugin;
|
||||
import me.clip.placeholderapi.expansion.PlaceholderExpansion;
|
||||
import me.clip.placeholderapi.util.TimeUtil;
|
||||
import me.lucko.luckperms.api.*;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
/*
|
||||
* PlaceholderAPI Expansion for LuckPerms, implemented using the LuckPerms API.
|
||||
*
|
||||
* Placeholders:
|
||||
* - group_name
|
||||
* - has_permission_<node>
|
||||
* - inherits_permission_<node>
|
||||
* - in_group_<name>
|
||||
* - inherits_group_<name>
|
||||
* - on_track_<track>
|
||||
* - expiry_time_<node>
|
||||
* - group_expiry_time_<group>
|
||||
* - prefix
|
||||
* - suffix
|
||||
* - meta_<node>
|
||||
*/
|
||||
public class LuckPermsPlaceholderExpansion extends PlaceholderExpansion {
|
||||
private static final String IDENTIFIER = "luckperms";
|
||||
private static final String PLUGIN_NAME = "LuckPerms";
|
||||
private static final String AUTHOR = "Luck";
|
||||
|
||||
private LuckPermsApi api = null;
|
||||
|
||||
@Override
|
||||
public boolean canRegister() {
|
||||
return Bukkit.getServicesManager().isProvidedFor(LuckPermsApi.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean register() {
|
||||
if (!canRegister()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
api = Bukkit.getServicesManager().getRegistration(LuckPermsApi.class).getProvider();
|
||||
return super.register();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getVersion() {
|
||||
return "2.8";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String onPlaceholderRequest(Player player, String identifier) {
|
||||
if (player == null || api == null) {
|
||||
return "";
|
||||
}
|
||||
|
||||
Optional<User> u = api.getUserSafe(api.getUuidCache().getUUID(player.getUniqueId()));
|
||||
if (!u.isPresent()) {
|
||||
return "";
|
||||
}
|
||||
|
||||
identifier = identifier.toLowerCase();
|
||||
final User user = u.get();
|
||||
|
||||
if (identifier.equalsIgnoreCase("group_name")) {
|
||||
return user.getPrimaryGroup();
|
||||
}
|
||||
|
||||
if (identifier.startsWith("has_permission_") && identifier.length() > "has_permission_".length()) {
|
||||
String node = identifier.substring("has_permission_".length());
|
||||
return formatBoolean(user.hasPermission(node, true));
|
||||
}
|
||||
|
||||
if (identifier.startsWith("inherits_permission_") && identifier.length() > "inherits_permission_".length()) {
|
||||
String node = identifier.substring("inherits_permission_".length());
|
||||
return formatBoolean(user.inheritsPermission(node, true));
|
||||
}
|
||||
|
||||
if (identifier.startsWith("in_group_") && identifier.length() > "in_group_".length()) {
|
||||
String groupName = identifier.substring("in_group_".length());
|
||||
return formatBoolean(user.getGroupNames().contains(groupName));
|
||||
}
|
||||
|
||||
if (identifier.startsWith("inherits_group_") && identifier.length() > "inherits_group_".length()) {
|
||||
String groupName = identifier.substring("inherits_group_".length());
|
||||
return formatBoolean(user.getLocalGroups("global").contains(groupName));
|
||||
}
|
||||
|
||||
if (identifier.startsWith("on_track_") && identifier.length() > "on_track_".length()) {
|
||||
String trackName = identifier.substring("on_track_".length());
|
||||
|
||||
Optional<Track> track = api.getTrackSafe(trackName);
|
||||
if (!track.isPresent()) return "";
|
||||
|
||||
return formatBoolean(track.get().containsGroup(user.getPrimaryGroup()));
|
||||
}
|
||||
|
||||
if (identifier.startsWith("expiry_time_") && identifier.length() > "expiry_time_".length()) {
|
||||
String node = identifier.substring("expiry_time_".length());
|
||||
long currentTime = System.currentTimeMillis() / 1000L;
|
||||
for (Node n : user.getTemporaryPermissionNodes()) {
|
||||
if (n.getPermission().equalsIgnoreCase(node)) {
|
||||
return TimeUtil.getTime((int) (n.getExpiryUnixTime() - currentTime));
|
||||
}
|
||||
}
|
||||
|
||||
return "";
|
||||
}
|
||||
|
||||
if (identifier.startsWith("group_expiry_time_") && identifier.length() > "group_expiry_time_".length()) {
|
||||
String node = "group." + identifier.substring("group_expiry_time_".length());
|
||||
long currentTime = System.currentTimeMillis() / 1000L;
|
||||
for (Node n : user.getTemporaryPermissionNodes()) {
|
||||
if (n.getPermission().equalsIgnoreCase(node)) {
|
||||
return TimeUtil.getTime((int) (n.getExpiryUnixTime() - currentTime));
|
||||
}
|
||||
}
|
||||
|
||||
return "";
|
||||
}
|
||||
|
||||
if (identifier.equalsIgnoreCase("prefix")) {
|
||||
return MetaUtils.getPrefix(user, null, null, true);
|
||||
}
|
||||
|
||||
if (identifier.equalsIgnoreCase("suffix")) {
|
||||
return MetaUtils.getSuffix(user, null, null, true);
|
||||
}
|
||||
|
||||
if (identifier.startsWith("meta_") && identifier.length() > "meta_".length()) {
|
||||
String node = identifier.substring("meta_".length());
|
||||
return MetaUtils.getMeta(user, null, null, node, "", true);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getIdentifier() {
|
||||
return IDENTIFIER;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getPlugin() {
|
||||
return PLUGIN_NAME;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getAuthor() {
|
||||
return AUTHOR;
|
||||
}
|
||||
|
||||
private static String formatBoolean(boolean b) {
|
||||
return b ? PlaceholderAPIPlugin.booleanTrue() : PlaceholderAPIPlugin.booleanFalse();
|
||||
}
|
||||
}
|
||||
+25
-15
@@ -5,7 +5,7 @@
|
||||
<parent>
|
||||
<artifactId>luckperms</artifactId>
|
||||
<groupId>me.lucko.luckperms</groupId>
|
||||
<version>2.3</version>
|
||||
<version>2.9-SNAPSHOT</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
@@ -14,7 +14,7 @@
|
||||
|
||||
<build>
|
||||
<defaultGoal>clean package</defaultGoal>
|
||||
<finalName>LuckPerms-${project.version}.${git.closest.tag.commit.count}</finalName>
|
||||
<finalName>LuckPerms-${release.version}.${git.closest.tag.commit.count}</finalName>
|
||||
<sourceDirectory>${basedir}/src/main/java</sourceDirectory>
|
||||
<resources>
|
||||
<resource>
|
||||
@@ -43,7 +43,12 @@
|
||||
<goal>shade</goal>
|
||||
</goals>
|
||||
<configuration>
|
||||
<minimizeJar>true</minimizeJar>
|
||||
<minimizeJar>false</minimizeJar>
|
||||
<artifactSet>
|
||||
<excludes>
|
||||
<exclude>org.xerial:*</exclude>
|
||||
</excludes>
|
||||
</artifactSet>
|
||||
<relocations>
|
||||
<relocation>
|
||||
<pattern>org.slf4j</pattern>
|
||||
@@ -53,6 +58,18 @@
|
||||
<pattern>com.zaxxer.hikari</pattern>
|
||||
<shadedPattern>me.lucko.luckperms.lib.hikari</shadedPattern>
|
||||
</relocation>
|
||||
<relocation>
|
||||
<pattern>com.mongodb</pattern>
|
||||
<shadedPattern>me.lucko.luckperms.lib.mongodb</shadedPattern>
|
||||
</relocation>
|
||||
<relocation>
|
||||
<pattern>org.bson</pattern>
|
||||
<shadedPattern>me.lucko.luckperms.lib.bson</shadedPattern>
|
||||
</relocation>
|
||||
<relocation>
|
||||
<pattern>org.h2</pattern>
|
||||
<shadedPattern>me.lucko.luckperms.lib.h2</shadedPattern>
|
||||
</relocation>
|
||||
</relocations>
|
||||
</configuration>
|
||||
</execution>
|
||||
@@ -105,19 +122,12 @@
|
||||
<version>${project.version}</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
<!-- HikariCP -->
|
||||
<!-- Lombok -->
|
||||
<dependency>
|
||||
<groupId>com.zaxxer</groupId>
|
||||
<artifactId>HikariCP</artifactId>
|
||||
<version>2.4.7</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
<!-- slf4j library -->
|
||||
<dependency>
|
||||
<groupId>org.slf4j</groupId>
|
||||
<artifactId>slf4j-simple</artifactId>
|
||||
<version>1.7.9</version>
|
||||
<scope>compile</scope>
|
||||
<groupId>org.projectlombok</groupId>
|
||||
<artifactId>lombok</artifactId>
|
||||
<version>1.16.10</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
||||
@@ -22,8 +22,12 @@
|
||||
|
||||
package me.lucko.luckperms;
|
||||
|
||||
import com.google.common.base.Joiner;
|
||||
import com.google.common.base.Splitter;
|
||||
import me.lucko.luckperms.api.data.Callback;
|
||||
import me.lucko.luckperms.commands.CommandManager;
|
||||
import me.lucko.luckperms.commands.Util;
|
||||
import me.lucko.luckperms.constants.Patterns;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandExecutor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
@@ -39,7 +43,12 @@ class BukkitCommand extends CommandManager implements CommandExecutor, TabExecut
|
||||
|
||||
@Override
|
||||
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
|
||||
onCommand(BukkitSenderFactory.get().wrap(sender), label, Arrays.asList(args), Callback.empty());
|
||||
onCommand(
|
||||
BukkitSenderFactory.get().wrap(sender),
|
||||
label,
|
||||
Util.stripQuotes(Splitter.on(Patterns.COMMAND_SEPARATOR).omitEmptyStrings().splitToList(Joiner.on(' ').join(args))),
|
||||
Callback.empty()
|
||||
);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@@ -23,14 +23,19 @@
|
||||
package me.lucko.luckperms;
|
||||
|
||||
import me.lucko.luckperms.constants.Message;
|
||||
import me.lucko.luckperms.inject.Injector;
|
||||
import me.lucko.luckperms.inject.LPPermissible;
|
||||
import me.lucko.luckperms.users.BukkitUser;
|
||||
import me.lucko.luckperms.users.User;
|
||||
import me.lucko.luckperms.utils.AbstractListener;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.player.*;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
class BukkitListener extends AbstractListener implements Listener {
|
||||
private final LPBukkitPlugin plugin;
|
||||
|
||||
@@ -39,10 +44,10 @@ class BukkitListener extends AbstractListener implements Listener {
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
@EventHandler(priority = EventPriority.LOWEST)
|
||||
public void onPlayerPreLogin(AsyncPlayerPreLoginEvent e) {
|
||||
if (!plugin.getDatastore().isAcceptingLogins()) {
|
||||
// Datastore is disabled, prevent players from joining the server
|
||||
// The datastore is disabled, prevent players from joining the server
|
||||
e.disallow(AsyncPlayerPreLoginEvent.Result.KICK_OTHER, Message.LOADING_ERROR.toString());
|
||||
return;
|
||||
}
|
||||
@@ -50,7 +55,7 @@ class BukkitListener extends AbstractListener implements Listener {
|
||||
onAsyncLogin(e.getUniqueId(), e.getName());
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
@EventHandler(priority = EventPriority.LOWEST)
|
||||
public void onPlayerLogin(PlayerLoginEvent e) {
|
||||
final Player player = e.getPlayer();
|
||||
final User user = plugin.getUserManager().get(plugin.getUuidCache().getUUID(player.getUniqueId()));
|
||||
@@ -62,25 +67,56 @@ class BukkitListener extends AbstractListener implements Listener {
|
||||
|
||||
if (user instanceof BukkitUser) {
|
||||
BukkitUser u = (BukkitUser) user;
|
||||
u.setAttachment(player.addAttachment(plugin));
|
||||
|
||||
try {
|
||||
LPPermissible lpPermissible = new LPPermissible(player, plugin);
|
||||
Injector.inject(player, lpPermissible);
|
||||
u.setLpPermissible(lpPermissible);
|
||||
} catch (Throwable t) {
|
||||
t.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
user.refreshPermissions();
|
||||
plugin.doAsync(user::refreshPermissions);
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
@EventHandler(priority = EventPriority.LOWEST)
|
||||
public void onPlayerJoin(PlayerJoinEvent e) {
|
||||
// Refresh permissions again
|
||||
refreshPlayer(e.getPlayer().getUniqueId());
|
||||
UUID internal = plugin.getUuidCache().getUUID(e.getPlayer().getUniqueId());
|
||||
plugin.getUserManager().getWorldCache().put(internal, e.getPlayer().getWorld().getName());
|
||||
plugin.doAsync(() -> refreshPlayer(internal));
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
@EventHandler(priority = EventPriority.LOWEST)
|
||||
public void onPlayerChangedWorld(PlayerChangedWorldEvent e) {
|
||||
refreshPlayer(e.getPlayer().getUniqueId());
|
||||
UUID internal = plugin.getUuidCache().getUUID(e.getPlayer().getUniqueId());
|
||||
plugin.getUserManager().getWorldCache().put(internal, e.getPlayer().getWorld().getName());
|
||||
plugin.doAsync(() -> refreshPlayer(internal));
|
||||
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
@EventHandler(priority = EventPriority.LOWEST)
|
||||
public void onPlayerQuit(PlayerQuitEvent e) {
|
||||
plugin.getUserManager().getWorldCache().remove(plugin.getUuidCache().getUUID(e.getPlayer().getUniqueId()));
|
||||
onLeave(e.getPlayer().getUniqueId());
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onPlayerCommand(PlayerCommandPreprocessEvent e) {
|
||||
if (plugin.getConfiguration().getEnableOps()) {
|
||||
return;
|
||||
}
|
||||
|
||||
String s = e.getMessage()
|
||||
.replace("/", "")
|
||||
.replace("bukkit:", "")
|
||||
.replace("spigot:", "")
|
||||
.replace("minecraft:", "");
|
||||
|
||||
if (s.startsWith("op") || s.startsWith("deop")) {
|
||||
e.setCancelled(true);
|
||||
e.getPlayer().sendMessage(Message.OP_DISABLED.toString());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -34,8 +34,8 @@ import java.util.UUID;
|
||||
@NoArgsConstructor(access = AccessLevel.PRIVATE)
|
||||
public class BukkitSenderFactory extends SenderFactory<CommandSender> {
|
||||
private static BukkitSenderFactory instance = null;
|
||||
public static BukkitSenderFactory get() {
|
||||
if (instance == null){
|
||||
public static synchronized BukkitSenderFactory get() {
|
||||
if (instance == null) {
|
||||
instance = new BukkitSenderFactory();
|
||||
}
|
||||
return instance;
|
||||
|
||||
@@ -25,42 +25,49 @@ package me.lucko.luckperms;
|
||||
import lombok.Getter;
|
||||
import me.lucko.luckperms.api.Logger;
|
||||
import me.lucko.luckperms.api.LuckPermsApi;
|
||||
import me.lucko.luckperms.api.PlatformType;
|
||||
import me.lucko.luckperms.api.implementation.ApiProvider;
|
||||
import me.lucko.luckperms.api.vault.VaultHook;
|
||||
import me.lucko.luckperms.commands.ConsecutiveExecutor;
|
||||
import me.lucko.luckperms.commands.Sender;
|
||||
import me.lucko.luckperms.constants.Message;
|
||||
import me.lucko.luckperms.core.LPConfiguration;
|
||||
import me.lucko.luckperms.core.UuidCache;
|
||||
import me.lucko.luckperms.data.Importer;
|
||||
import me.lucko.luckperms.groups.GroupManager;
|
||||
import me.lucko.luckperms.runnables.ExpireTemporaryTask;
|
||||
import me.lucko.luckperms.runnables.UpdateTask;
|
||||
import me.lucko.luckperms.storage.Datastore;
|
||||
import me.lucko.luckperms.storage.methods.FlatfileDatastore;
|
||||
import me.lucko.luckperms.storage.methods.MySQLDatastore;
|
||||
import me.lucko.luckperms.storage.methods.SQLiteDatastore;
|
||||
import me.lucko.luckperms.storage.StorageFactory;
|
||||
import me.lucko.luckperms.tracks.TrackManager;
|
||||
import me.lucko.luckperms.users.BukkitUserManager;
|
||||
import me.lucko.luckperms.users.UserManager;
|
||||
import me.lucko.luckperms.utils.LogFactory;
|
||||
import org.bukkit.command.PluginCommand;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.permissions.Permission;
|
||||
import org.bukkit.permissions.PermissionDefault;
|
||||
import org.bukkit.plugin.PluginManager;
|
||||
import org.bukkit.plugin.ServicePriority;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@Getter
|
||||
public class LPBukkitPlugin extends JavaPlugin implements LuckPermsPlugin {
|
||||
private final Set<UUID> ignoringLogs = new HashSet<>();
|
||||
private final Set<UUID> ignoringLogs = ConcurrentHashMap.newKeySet();
|
||||
private LPConfiguration configuration;
|
||||
private UserManager userManager;
|
||||
private BukkitUserManager userManager;
|
||||
private GroupManager groupManager;
|
||||
private TrackManager trackManager;
|
||||
private Datastore datastore;
|
||||
private UuidCache uuidCache;
|
||||
private ApiProvider apiProvider;
|
||||
private Logger log;
|
||||
private Importer importer;
|
||||
private ConsecutiveExecutor consecutiveExecutor;
|
||||
|
||||
@Override
|
||||
public void onEnable() {
|
||||
@@ -81,38 +88,15 @@ public class LPBukkitPlugin extends JavaPlugin implements LuckPermsPlugin {
|
||||
main.setTabCompleter(commandManager);
|
||||
main.setAliases(Arrays.asList("perms", "lp", "permissions", "p", "perm"));
|
||||
|
||||
getLog().info("Detecting storage method...");
|
||||
final String storageMethod = configuration.getStorageMethod();
|
||||
if (storageMethod.equalsIgnoreCase("mysql")) {
|
||||
getLog().info("Using MySQL as storage method.");
|
||||
datastore = new MySQLDatastore(this, configuration.getDatabaseValues());
|
||||
} else if (storageMethod.equalsIgnoreCase("sqlite")) {
|
||||
getLog().info("Using SQLite as storage method.");
|
||||
datastore = new SQLiteDatastore(this, new File(getDataFolder(), "luckperms.sqlite"));
|
||||
} else if (storageMethod.equalsIgnoreCase("flatfile")) {
|
||||
getLog().info("Using Flatfile (JSON) as storage method.");
|
||||
datastore = new FlatfileDatastore(this, getDataFolder());
|
||||
} else {
|
||||
getLog().severe("Storage method '" + storageMethod + "' was not recognised. Using SQLite as fallback.");
|
||||
datastore = new SQLiteDatastore(this, new File(getDataFolder(), "luckperms.sqlite"));
|
||||
}
|
||||
|
||||
getLog().info("Initialising datastore...");
|
||||
datastore.init();
|
||||
datastore = StorageFactory.getDatastore(this, "h2");
|
||||
|
||||
getLog().info("Loading internal permission managers...");
|
||||
uuidCache = new UuidCache(getConfiguration().getOnlineMode());
|
||||
userManager = new BukkitUserManager(this);
|
||||
groupManager = new GroupManager(this);
|
||||
trackManager = new TrackManager();
|
||||
|
||||
// Run update task to refresh any online users
|
||||
getLog().info("Scheduling Update Task to refresh any online users.");
|
||||
try {
|
||||
new UpdateTask(this).run();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
importer = new Importer(commandManager);
|
||||
consecutiveExecutor = new ConsecutiveExecutor(commandManager);
|
||||
|
||||
int mins = getConfiguration().getSyncTime();
|
||||
if (mins > 0) {
|
||||
@@ -121,6 +105,8 @@ public class LPBukkitPlugin extends JavaPlugin implements LuckPermsPlugin {
|
||||
}
|
||||
|
||||
getServer().getScheduler().runTaskTimer(this, BukkitSenderFactory.get(), 1L, 1L);
|
||||
getServer().getScheduler().runTaskTimerAsynchronously(this, new ExpireTemporaryTask(this), 60L, 60L);
|
||||
getServer().getScheduler().runTaskTimerAsynchronously(this, consecutiveExecutor, 20L, 20L);
|
||||
|
||||
// Provide vault support
|
||||
getLog().info("Attempting to hook into Vault...");
|
||||
@@ -137,9 +123,22 @@ public class LPBukkitPlugin extends JavaPlugin implements LuckPermsPlugin {
|
||||
}
|
||||
|
||||
getLog().info("Registering API...");
|
||||
final ApiProvider provider = new ApiProvider(this);
|
||||
LuckPerms.registerProvider(provider);
|
||||
getServer().getServicesManager().register(LuckPermsApi.class, provider, this, ServicePriority.Normal);
|
||||
apiProvider = new ApiProvider(this);
|
||||
LuckPerms.registerProvider(apiProvider);
|
||||
getServer().getServicesManager().register(LuckPermsApi.class, apiProvider, this, ServicePriority.Normal);
|
||||
|
||||
// Run update task to refresh any online users
|
||||
getLog().info("Scheduling Update Task to refresh any online users.");
|
||||
try {
|
||||
new UpdateTask(this).run();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
registerPermissions(getConfiguration().getCommandsAllowOp() ? PermissionDefault.OP : PermissionDefault.FALSE);
|
||||
if (!getConfiguration().getEnableOps()) {
|
||||
getServer().getOperators().forEach(o -> o.setOp(false));
|
||||
}
|
||||
|
||||
getLog().info("Successfully loaded.");
|
||||
}
|
||||
@@ -169,6 +168,16 @@ public class LPBukkitPlugin extends JavaPlugin implements LuckPermsPlugin {
|
||||
return getDescription().getVersion();
|
||||
}
|
||||
|
||||
@Override
|
||||
public PlatformType getType() {
|
||||
return PlatformType.BUKKIT;
|
||||
}
|
||||
|
||||
@Override
|
||||
public File getMainDir() {
|
||||
return getDataFolder();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Message getPlayerStatus(UUID uuid) {
|
||||
return getServer().getPlayer(getUuidCache().getExternalUUID(uuid)) != null ? Message.PLAYER_ONLINE : Message.PLAYER_OFFLINE;
|
||||
@@ -185,8 +194,16 @@ public class LPBukkitPlugin extends JavaPlugin implements LuckPermsPlugin {
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Sender> getSenders() {
|
||||
return getServer().getOnlinePlayers().stream().map(p -> BukkitSenderFactory.get().wrap(p)).collect(Collectors.toList());
|
||||
public List<Sender> getNotifyListeners() {
|
||||
return getServer().getOnlinePlayers().stream()
|
||||
.map(p -> BukkitSenderFactory.get().wrap(p, Collections.singleton(me.lucko.luckperms.constants.Permission.LOG_NOTIFY)))
|
||||
.filter(me.lucko.luckperms.constants.Permission.LOG_NOTIFY::isAuthorized)
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
@Override
|
||||
public Sender getConsoleSender() {
|
||||
return BukkitSenderFactory.get().wrap(getServer().getConsoleSender());
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -201,8 +218,63 @@ public class LPBukkitPlugin extends JavaPlugin implements LuckPermsPlugin {
|
||||
return perms;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getPlugin(String name) {
|
||||
return getServer().getPluginManager().getPlugin(name);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getService(Class clazz) {
|
||||
return getServer().getServicesManager().load(clazz);
|
||||
}
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
@Override
|
||||
public UUID getUUID(String playerName) {
|
||||
try {
|
||||
return getServer().getOfflinePlayer(playerName).getUniqueId();
|
||||
} catch (Exception e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isPluginLoaded(String name) {
|
||||
return getServer().getPluginManager().isPluginEnabled(name);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void runUpdateTask() {
|
||||
getServer().getScheduler().runTaskAsynchronously(this, new UpdateTask(this));
|
||||
}
|
||||
|
||||
private void registerPermissions(PermissionDefault def) {
|
||||
PluginManager pm = getServer().getPluginManager();
|
||||
|
||||
Map<String, List<String>> wildcards = new HashMap<>();
|
||||
List<String> all = new ArrayList<>();
|
||||
for (me.lucko.luckperms.constants.Permission p : me.lucko.luckperms.constants.Permission.values()) {
|
||||
pm.addPermission(new Permission(p.getNode(), def));
|
||||
if (p.getGroup() != null) {
|
||||
if (!wildcards.containsKey(p.getGroup())) {
|
||||
wildcards.put(p.getGroup(), new ArrayList<>());
|
||||
}
|
||||
wildcards.get(p.getGroup()).add(p.getTag());
|
||||
}
|
||||
|
||||
all.add(p.getNode());
|
||||
}
|
||||
|
||||
for (Map.Entry<String, List<String>> e : wildcards.entrySet()) {
|
||||
pm.addPermission(new Permission(
|
||||
"luckperms." + e.getKey() + ".*", def,
|
||||
e.getValue().stream()
|
||||
.map(tag -> "luckperms." + e.getKey() + "." + tag)
|
||||
.collect(Collectors.toMap(s -> s, s -> true))
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
pm.addPermission(new Permission("luckperms.*", def, all.stream().collect(Collectors.toMap(s -> s, s -> true))));
|
||||
}
|
||||
}
|
||||
@@ -22,128 +22,316 @@
|
||||
|
||||
package me.lucko.luckperms.api.vault;
|
||||
|
||||
import lombok.NonNull;
|
||||
import lombok.Setter;
|
||||
import me.lucko.luckperms.LPBukkitPlugin;
|
||||
import me.lucko.luckperms.api.Node;
|
||||
import me.lucko.luckperms.core.PermissionHolder;
|
||||
import me.lucko.luckperms.exceptions.ObjectAlreadyHasException;
|
||||
import me.lucko.luckperms.groups.Group;
|
||||
import me.lucko.luckperms.users.User;
|
||||
import me.lucko.luckperms.utils.Contexts;
|
||||
import net.milkbowl.vault.chat.Chat;
|
||||
import net.milkbowl.vault.permission.Permission;
|
||||
|
||||
import java.util.Iterator;
|
||||
import java.util.Map;
|
||||
|
||||
import static me.lucko.luckperms.utils.ArgumentChecker.escapeCharacters;
|
||||
import static me.lucko.luckperms.utils.ArgumentChecker.unescapeCharacters;
|
||||
|
||||
/**
|
||||
* Dummy class for hooking with Vault plugins that need both Chat + Perms
|
||||
* This doesn't return anything useful, or change anything internally
|
||||
* Provides the Vault Chat service through the use of normal permission nodes.
|
||||
*
|
||||
* Registered on the lowest priority so other plugins can override
|
||||
* Prefixes / Suffixes:
|
||||
* Normal inheritance rules apply.
|
||||
* Permission Nodes = prefix.priority.value OR suffix.priority.value
|
||||
* If a user/group has / inherits multiple prefixes and suffixes, the one with the highest priority is the one that
|
||||
* will apply.
|
||||
*
|
||||
* Meta:
|
||||
* Normal inheritance rules DO NOT apply.
|
||||
* Permission Nodes = meta.node.value
|
||||
*
|
||||
* Node that special characters used within LuckPerms are escaped:
|
||||
* See {@link me.lucko.luckperms.utils.ArgumentChecker#escapeCharacters(String)}
|
||||
*
|
||||
* Registered on normal priority so other plugins can override.
|
||||
*/
|
||||
class VaultChatHook extends Chat {
|
||||
public class VaultChatHook extends Chat {
|
||||
|
||||
VaultChatHook(Permission perms) {
|
||||
@Setter
|
||||
private LPBukkitPlugin plugin;
|
||||
private final VaultPermissionHook perms;
|
||||
|
||||
VaultChatHook(VaultPermissionHook perms) {
|
||||
super(perms);
|
||||
}
|
||||
|
||||
private void throwNotSupported() {
|
||||
// throw new UnsupportedOperationException("LuckPerms cannot perform this operation.");
|
||||
this.perms = perms;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return "LuckPerms";
|
||||
return perms.getName();
|
||||
}
|
||||
|
||||
|
||||
public boolean isEnabled() {
|
||||
return true;
|
||||
return perms.isEnabled();
|
||||
}
|
||||
|
||||
public String getPlayerPrefix(String world, String player) {
|
||||
return "";
|
||||
private void saveMeta(PermissionHolder holder, String world, String node, String value) {
|
||||
if (holder == null) return;
|
||||
if (node.equals("")) return;
|
||||
node = escapeCharacters(node);
|
||||
value = escapeCharacters(value);
|
||||
|
||||
Iterator<Node> nodes = holder.getNodes().iterator();
|
||||
while (nodes.hasNext()) {
|
||||
Node n = nodes.next();
|
||||
if (n.isMeta() && n.getMeta().getKey().equals(node)) {
|
||||
nodes.remove();
|
||||
}
|
||||
}
|
||||
|
||||
Node.Builder metaNode = new me.lucko.luckperms.utils.Node.Builder("meta." + node + "." + value).setValue(true);
|
||||
if (!perms.getServer().equalsIgnoreCase("global")) {
|
||||
metaNode.setServer(perms.getServer());
|
||||
}
|
||||
if (world != null && !world.equals("")) {
|
||||
metaNode.setServer(perms.getServer()).setWorld(world);
|
||||
}
|
||||
|
||||
try {
|
||||
holder.setPermission(metaNode.build());
|
||||
} catch (ObjectAlreadyHasException ignored) {}
|
||||
|
||||
perms.objectSave(holder);
|
||||
}
|
||||
|
||||
public void setPlayerPrefix(String world, String player, String prefix) {
|
||||
throwNotSupported();
|
||||
}
|
||||
private String getMeta(PermissionHolder holder, String world, String node, String defaultValue) {
|
||||
if (holder == null) return defaultValue;
|
||||
if (node.equals("")) return defaultValue;
|
||||
node = escapeCharacters(node);
|
||||
|
||||
public String getPlayerSuffix(String world, String player) {
|
||||
return "";
|
||||
}
|
||||
for (Node n : holder.getPermissions(true)) {
|
||||
if (!n.getValue()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
public void setPlayerSuffix(String world, String player, String suffix) {
|
||||
throwNotSupported();
|
||||
}
|
||||
if (!n.isMeta()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
public String getGroupPrefix(String world, String group) {
|
||||
return "";
|
||||
}
|
||||
if (!n.shouldApplyOnServer(perms.getServer(), perms.isIncludeGlobal(), false)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
public void setGroupPrefix(String world, String group, String prefix) {
|
||||
throwNotSupported();
|
||||
}
|
||||
if (!n.shouldApplyOnWorld(world, perms.isIncludeGlobal(), false)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
public String getGroupSuffix(String world, String group) {
|
||||
return "";
|
||||
}
|
||||
Map.Entry<String, String> meta = n.getMeta();
|
||||
if (meta.getKey().equalsIgnoreCase(node)) {
|
||||
return unescapeCharacters(meta.getValue());
|
||||
}
|
||||
}
|
||||
|
||||
public void setGroupSuffix(String world, String group, String suffix) {
|
||||
throwNotSupported();
|
||||
}
|
||||
|
||||
public int getPlayerInfoInteger(String world, String player, String node, int defaultValue) {
|
||||
return defaultValue;
|
||||
}
|
||||
|
||||
public void setPlayerInfoInteger(String world, String player, String node, int value) {
|
||||
throwNotSupported();
|
||||
private void setChatMeta(boolean prefix, PermissionHolder holder, String value, String world) {
|
||||
if (holder == null) return;
|
||||
if (value.equals("")) return;
|
||||
|
||||
Node.Builder node = new me.lucko.luckperms.utils.Node.Builder(prefix ? "prefix" : "suffix" + ".1000." + escapeCharacters(value));
|
||||
node.setValue(true);
|
||||
if (!perms.getServer().equalsIgnoreCase("global")) {
|
||||
node.setServer(perms.getServer());
|
||||
}
|
||||
|
||||
if (world != null && !world.equals("")) {
|
||||
node.setServer(perms.getServer()).setWorld(world);
|
||||
}
|
||||
|
||||
try {
|
||||
holder.setPermission(node.build());
|
||||
} catch (ObjectAlreadyHasException ignored) {}
|
||||
|
||||
perms.objectSave(holder);
|
||||
}
|
||||
|
||||
public int getGroupInfoInteger(String world, String group, String node, int defaultValue) {
|
||||
return defaultValue;
|
||||
private String getChatMeta(boolean prefix, PermissionHolder holder, String world) {
|
||||
if (holder == null) return "";
|
||||
|
||||
int priority = Integer.MIN_VALUE;
|
||||
String meta = null;
|
||||
|
||||
for (Node n : holder.getAllNodes(null, Contexts.allowAll())) {
|
||||
if (!n.getValue()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (prefix ? !n.isPrefix() : !n.isSuffix()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!n.shouldApplyOnServer(perms.getServer(), perms.isIncludeGlobal(), false)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!n.shouldApplyOnWorld(world, perms.isIncludeGlobal(), false)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
Map.Entry<Integer, String> value = prefix ? n.getPrefix() : n.getSuffix();
|
||||
if (value.getKey() > priority) {
|
||||
meta = value.getValue();
|
||||
priority = value.getKey();
|
||||
}
|
||||
}
|
||||
|
||||
return meta == null ? "" : unescapeCharacters(meta);
|
||||
}
|
||||
|
||||
public void setGroupInfoInteger(String world, String group, String node, int value) {
|
||||
throwNotSupported();
|
||||
public String getPlayerPrefix(String world, @NonNull String player) {
|
||||
final User user = plugin.getUserManager().get(player);
|
||||
return getChatMeta(true, user, world);
|
||||
}
|
||||
|
||||
public double getPlayerInfoDouble(String world, String player, String node, double defaultValue) {
|
||||
return defaultValue;
|
||||
public void setPlayerPrefix(String world, @NonNull String player, @NonNull String prefix) {
|
||||
final User user = plugin.getUserManager().get(player);
|
||||
setChatMeta(true, user, prefix, world);
|
||||
}
|
||||
|
||||
public void setPlayerInfoDouble(String world, String player, String node, double value) {
|
||||
throwNotSupported();
|
||||
public String getPlayerSuffix(String world, @NonNull String player) {
|
||||
final User user = plugin.getUserManager().get(player);
|
||||
return getChatMeta(false, user, world);
|
||||
}
|
||||
|
||||
public double getGroupInfoDouble(String world, String group, String node, double defaultValue) {
|
||||
return defaultValue;
|
||||
public void setPlayerSuffix(String world, @NonNull String player, @NonNull String suffix) {
|
||||
final User user = plugin.getUserManager().get(player);
|
||||
setChatMeta(false, user, suffix, world);
|
||||
}
|
||||
|
||||
public void setGroupInfoDouble(String world, String group, String node, double value) {
|
||||
throwNotSupported();
|
||||
public String getGroupPrefix(String world, @NonNull String group) {
|
||||
final Group g = plugin.getGroupManager().get(group);
|
||||
return getChatMeta(false, g, world);
|
||||
}
|
||||
|
||||
public boolean getPlayerInfoBoolean(String world, String player, String node, boolean defaultValue) {
|
||||
return defaultValue;
|
||||
public void setGroupPrefix(String world, @NonNull String group, @NonNull String prefix) {
|
||||
final Group g = plugin.getGroupManager().get(group);
|
||||
setChatMeta(true, g, prefix, world);
|
||||
}
|
||||
|
||||
public void setPlayerInfoBoolean(String world, String player, String node, boolean value) {
|
||||
throwNotSupported();
|
||||
public String getGroupSuffix(String world, @NonNull String group) {
|
||||
final Group g = plugin.getGroupManager().get(group);
|
||||
return getChatMeta(false, g, world);
|
||||
}
|
||||
|
||||
public boolean getGroupInfoBoolean(String world, String group, String node, boolean defaultValue) {
|
||||
return defaultValue;
|
||||
public void setGroupSuffix(String world, @NonNull String group, @NonNull String suffix) {
|
||||
final Group g = plugin.getGroupManager().get(group);
|
||||
setChatMeta(false, g, suffix, world);
|
||||
}
|
||||
|
||||
public void setGroupInfoBoolean(String world, String group, String node, boolean value) {
|
||||
throwNotSupported();
|
||||
public int getPlayerInfoInteger(String world, @NonNull String player, @NonNull String node, int defaultValue) {
|
||||
final User user = plugin.getUserManager().get(player);
|
||||
try {
|
||||
return Integer.parseInt(getMeta(user, world, node, String.valueOf(defaultValue)));
|
||||
} catch (NumberFormatException e) {
|
||||
return defaultValue;
|
||||
}
|
||||
}
|
||||
|
||||
public String getPlayerInfoString(String world, String player, String node, String defaultValue) {
|
||||
return defaultValue;
|
||||
public void setPlayerInfoInteger(String world, @NonNull String player, @NonNull String node, int value) {
|
||||
final User user = plugin.getUserManager().get(player);
|
||||
saveMeta(user, world, node, String.valueOf(value));
|
||||
}
|
||||
|
||||
public void setPlayerInfoString(String world, String player, String node, String value) {
|
||||
throwNotSupported();
|
||||
public int getGroupInfoInteger(String world, @NonNull String group, @NonNull String node, int defaultValue) {
|
||||
final Group g = plugin.getGroupManager().get(group);
|
||||
try {
|
||||
return Integer.parseInt(getMeta(g, world, node, String.valueOf(defaultValue)));
|
||||
} catch (NumberFormatException e) {
|
||||
return defaultValue;
|
||||
}
|
||||
}
|
||||
|
||||
public String getGroupInfoString(String world, String group, String node, String defaultValue) {
|
||||
return defaultValue;
|
||||
public void setGroupInfoInteger(String world, @NonNull String group, @NonNull String node, int value) {
|
||||
final Group g = plugin.getGroupManager().get(group);
|
||||
saveMeta(g, world, node, String.valueOf(value));
|
||||
}
|
||||
|
||||
public void setGroupInfoString(String world, String group, String node, String value) {
|
||||
throwNotSupported();
|
||||
public double getPlayerInfoDouble(String world, @NonNull String player, @NonNull String node, double defaultValue) {
|
||||
final User user = plugin.getUserManager().get(player);
|
||||
try {
|
||||
return Double.parseDouble(getMeta(user, world, node, String.valueOf(defaultValue)));
|
||||
} catch (NumberFormatException e) {
|
||||
return defaultValue;
|
||||
}
|
||||
}
|
||||
|
||||
public void setPlayerInfoDouble(String world, @NonNull String player, @NonNull String node, double value) {
|
||||
final User user = plugin.getUserManager().get(player);
|
||||
saveMeta(user, world, node, String.valueOf(value));
|
||||
}
|
||||
|
||||
public double getGroupInfoDouble(String world, @NonNull String group, @NonNull String node, double defaultValue) {
|
||||
final Group g = plugin.getGroupManager().get(group);
|
||||
try {
|
||||
return Double.parseDouble(getMeta(g, world, node, String.valueOf(defaultValue)));
|
||||
} catch (NumberFormatException e) {
|
||||
return defaultValue;
|
||||
}
|
||||
}
|
||||
|
||||
public void setGroupInfoDouble(String world, @NonNull String group, @NonNull String node, double value) {
|
||||
final Group g = plugin.getGroupManager().get(group);
|
||||
saveMeta(g, world, node, String.valueOf(value));
|
||||
}
|
||||
|
||||
public boolean getPlayerInfoBoolean(String world, @NonNull String player, @NonNull String node, boolean defaultValue) {
|
||||
final User user = plugin.getUserManager().get(player);
|
||||
String s = getMeta(user, world, node, String.valueOf(defaultValue));
|
||||
if (!s.equalsIgnoreCase("true") && !s.equalsIgnoreCase("false")) {
|
||||
return defaultValue;
|
||||
}
|
||||
return Boolean.parseBoolean(s);
|
||||
}
|
||||
|
||||
public void setPlayerInfoBoolean(String world, @NonNull String player, @NonNull String node, boolean value) {
|
||||
final User user = plugin.getUserManager().get(player);
|
||||
saveMeta(user, world, node, String.valueOf(value));
|
||||
}
|
||||
|
||||
public boolean getGroupInfoBoolean(String world, @NonNull String group, @NonNull String node, boolean defaultValue) {
|
||||
final Group g = plugin.getGroupManager().get(group);
|
||||
String s = getMeta(g, world, node, String.valueOf(defaultValue));
|
||||
if (!s.equalsIgnoreCase("true") && !s.equalsIgnoreCase("false")) {
|
||||
return defaultValue;
|
||||
}
|
||||
return Boolean.parseBoolean(s);
|
||||
}
|
||||
|
||||
public void setGroupInfoBoolean(String world, @NonNull String group, @NonNull String node, boolean value) {
|
||||
final Group g = plugin.getGroupManager().get(group);
|
||||
saveMeta(g, world, node, String.valueOf(value));
|
||||
}
|
||||
|
||||
public String getPlayerInfoString(String world, @NonNull String player, @NonNull String node, String defaultValue) {
|
||||
final User user = plugin.getUserManager().get(player);
|
||||
return getMeta(user, world, node, defaultValue);
|
||||
}
|
||||
|
||||
public void setPlayerInfoString(String world, @NonNull String player, @NonNull String node, String value) {
|
||||
final User user = plugin.getUserManager().get(player);
|
||||
saveMeta(user, world, node, value);
|
||||
}
|
||||
|
||||
public String getGroupInfoString(String world, @NonNull String group, @NonNull String node, String defaultValue) {
|
||||
final Group g = plugin.getGroupManager().get(group);
|
||||
return getMeta(g, world, node, defaultValue);
|
||||
}
|
||||
|
||||
public void setGroupInfoString(String world, @NonNull String group, @NonNull String node, String value) {
|
||||
final Group g = plugin.getGroupManager().get(group);
|
||||
saveMeta(g, world, node, value);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -39,15 +39,18 @@ public class VaultHook {
|
||||
permissionHook = new VaultPermissionHook();
|
||||
}
|
||||
permissionHook.setPlugin(plugin);
|
||||
permissionHook.setServer(plugin.getConfiguration().getVaultServer());
|
||||
permissionHook.setIncludeGlobal(plugin.getConfiguration().getVaultIncludeGlobal());
|
||||
|
||||
if (chatHook == null) {
|
||||
chatHook = new VaultChatHook(permissionHook);
|
||||
}
|
||||
chatHook.setPlugin(plugin);
|
||||
|
||||
final ServicesManager sm = plugin.getServer().getServicesManager();
|
||||
sm.unregisterAll(plugin);
|
||||
sm.register(Permission.class, permissionHook, plugin, ServicePriority.High);
|
||||
sm.register(Chat.class, chatHook, plugin, ServicePriority.Lowest);
|
||||
sm.register(Chat.class, chatHook, plugin, ServicePriority.Low);
|
||||
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
|
||||
@@ -22,6 +22,7 @@
|
||||
|
||||
package me.lucko.luckperms.api.vault;
|
||||
|
||||
import lombok.Getter;
|
||||
import lombok.NonNull;
|
||||
import lombok.Setter;
|
||||
import me.lucko.luckperms.LPBukkitPlugin;
|
||||
@@ -33,11 +34,19 @@ import me.lucko.luckperms.groups.Group;
|
||||
import me.lucko.luckperms.users.User;
|
||||
import net.milkbowl.vault.permission.Permission;
|
||||
|
||||
class VaultPermissionHook extends Permission {
|
||||
public class VaultPermissionHook extends Permission {
|
||||
|
||||
@Setter
|
||||
private LPBukkitPlugin plugin;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
private String server = "global";
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
private boolean includeGlobal = true;
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return "LuckPerms";
|
||||
@@ -57,9 +66,9 @@ class VaultPermissionHook extends Permission {
|
||||
if (object == null) return false;
|
||||
|
||||
if (world != null && !world.equals("")) {
|
||||
return object.hasPermission(permission, true, "global", world);
|
||||
return object.hasPermission(permission, true, server, world);
|
||||
} else {
|
||||
return object.hasPermission(permission, true);
|
||||
return object.hasPermission(permission, true, server);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -68,9 +77,9 @@ class VaultPermissionHook extends Permission {
|
||||
|
||||
try {
|
||||
if (world != null && !world.equals("")) {
|
||||
object.setPermission(permission, true, "global", world);
|
||||
object.setPermission(permission, true, server, world);
|
||||
} else {
|
||||
object.setPermission(permission, true);
|
||||
object.setPermission(permission, true, server);
|
||||
}
|
||||
} catch (ObjectAlreadyHasException ignored) {}
|
||||
|
||||
@@ -83,9 +92,9 @@ class VaultPermissionHook extends Permission {
|
||||
|
||||
try {
|
||||
if (world != null && !world.equals("")) {
|
||||
object.unsetPermission(permission, "global", world);
|
||||
object.unsetPermission(permission, server, world);
|
||||
} else {
|
||||
object.unsetPermission(permission);
|
||||
object.unsetPermission(permission, server);
|
||||
}
|
||||
} catch (ObjectLacksException ignored) {}
|
||||
|
||||
@@ -93,7 +102,7 @@ class VaultPermissionHook extends Permission {
|
||||
return true;
|
||||
}
|
||||
|
||||
private void objectSave(PermissionHolder t) {
|
||||
void objectSave(PermissionHolder t) {
|
||||
if (t instanceof User) {
|
||||
((User) t).refreshPermissions();
|
||||
plugin.getDatastore().saveUser(((User) t), Callback.empty());
|
||||
@@ -147,7 +156,7 @@ class VaultPermissionHook extends Permission {
|
||||
if (group1 == null) return false;
|
||||
|
||||
if (world != null && !world.equals("")) {
|
||||
return user.isInGroup(group1, "global", world);
|
||||
return user.isInGroup(group1, server, world);
|
||||
} else {
|
||||
return user.isInGroup(group1);
|
||||
}
|
||||
@@ -163,7 +172,7 @@ class VaultPermissionHook extends Permission {
|
||||
|
||||
try {
|
||||
if (world != null && !world.equals("")) {
|
||||
user.addGroup(group, "global", world);
|
||||
user.addGroup(group, server, world);
|
||||
} else {
|
||||
user.addGroup(group);
|
||||
}
|
||||
@@ -182,7 +191,7 @@ class VaultPermissionHook extends Permission {
|
||||
|
||||
try {
|
||||
if (world != null && !world.equals("")) {
|
||||
user.removeGroup(group, "global", world);
|
||||
user.removeGroup(group, server, world);
|
||||
} else {
|
||||
user.removeGroup(group);
|
||||
}
|
||||
@@ -195,7 +204,7 @@ class VaultPermissionHook extends Permission {
|
||||
public String[] getPlayerGroups(String world, @NonNull String player) {
|
||||
final User user = plugin.getUserManager().get(player);
|
||||
return (user == null) ? new String[0] :
|
||||
world != null && !world.equals("") ? user.getLocalGroups("global", world).toArray(new String[0]) :
|
||||
world != null && !world.equals("") ? user.getGroups(server, world, includeGlobal).toArray(new String[0]) :
|
||||
user.getGroupNames().toArray(new String[0]);
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,108 @@
|
||||
/*
|
||||
* Copyright (c) 2016 Lucko (Luck) <luck@lucko.me>
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
package me.lucko.luckperms.inject;
|
||||
|
||||
import lombok.experimental.UtilityClass;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.permissions.Permissible;
|
||||
import org.bukkit.permissions.PermissibleBase;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
|
||||
/**
|
||||
* Injects a {@link LPPermissible} into a {@link Player}
|
||||
*/
|
||||
@UtilityClass
|
||||
public class Injector {
|
||||
private static Field HUMAN_ENTITY_FIELD;
|
||||
|
||||
static {
|
||||
try {
|
||||
HUMAN_ENTITY_FIELD = Class.forName(getInternalClassName("entity.CraftHumanEntity")).getDeclaredField("perm");
|
||||
HUMAN_ENTITY_FIELD.setAccessible(true);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean inject(CommandSender sender, PermissibleBase permissible) {
|
||||
try {
|
||||
Field f = getPermField(sender);
|
||||
f.set(sender, permissible);
|
||||
return true;
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean unInject(CommandSender sender) {
|
||||
try {
|
||||
Permissible permissible = getPermissible(sender);
|
||||
if (permissible instanceof LPPermissible) {
|
||||
getPermField(sender).set(sender, new PermissibleBase(sender));
|
||||
}
|
||||
return true;
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
private static Permissible getPermissible(CommandSender sender) {
|
||||
try {
|
||||
Field f = getPermField(sender);
|
||||
return (Permissible) f.get(sender);
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
private static Field getPermField(CommandSender sender) {
|
||||
if (sender instanceof Player) {
|
||||
return HUMAN_ENTITY_FIELD;
|
||||
}
|
||||
throw new RuntimeException("Couldn't get perm field for sender " + sender.getClass().getName());
|
||||
}
|
||||
|
||||
private static String getInternalClassName(String className) {
|
||||
Class server = Bukkit.getServer().getClass();
|
||||
if (!server.getSimpleName().equals("CraftServer")) {
|
||||
throw new RuntimeException("Couldn't inject into server " + server);
|
||||
}
|
||||
|
||||
String version;
|
||||
if (server.getName().equals("org.bukkit.craftbukkit.CraftServer")) {
|
||||
// Non versioned class
|
||||
version = ".";
|
||||
} else {
|
||||
version = server.getName().substring("org.bukkit.craftbukkit".length());
|
||||
version = version.substring(0, version.length() - "CraftServer".length());
|
||||
}
|
||||
|
||||
return "org.bukkit.craftbukkit" + version + className;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,303 @@
|
||||
/*
|
||||
* Copyright (c) 2016 Lucko (Luck) <luck@lucko.me>
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
package me.lucko.luckperms.inject;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
import lombok.NonNull;
|
||||
import me.lucko.luckperms.LuckPermsPlugin;
|
||||
import me.lucko.luckperms.api.Tristate;
|
||||
import me.lucko.luckperms.utils.PermissionCalculator;
|
||||
import me.lucko.luckperms.utils.PermissionProcessor;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.permissions.*;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.function.Supplier;
|
||||
import java.util.logging.Level;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* Modified PermissibleBase for LuckPerms
|
||||
*/
|
||||
public class LPPermissible extends PermissibleBase {
|
||||
|
||||
@Getter
|
||||
private final CommandSender parent;
|
||||
|
||||
private final PermissionCalculator calculator;
|
||||
|
||||
@Getter
|
||||
private final Map<String, Boolean> luckPermsPermissions = new ConcurrentHashMap<>();
|
||||
private final List<PermissionAttachment> attachments = new LinkedList<>();
|
||||
private final Map<String, PermissionAttachmentInfo> attachmentPermissions = new HashMap<>();
|
||||
|
||||
public LPPermissible(@NonNull CommandSender sender, LuckPermsPlugin plugin) {
|
||||
super(sender);
|
||||
this.parent = sender;
|
||||
|
||||
List<PermissionProcessor> processors = new ArrayList<>(5);
|
||||
processors.add(new PermissionCalculator.MapProcessor(luckPermsPermissions));
|
||||
processors.add(new AttachmentProcessor(attachmentPermissions));
|
||||
if (plugin.getConfiguration().getApplyWildcards()) {
|
||||
processors.add(new PermissionCalculator.WildcardProcessor(luckPermsPermissions));
|
||||
}
|
||||
if (plugin.getConfiguration().getApplyRegex()) {
|
||||
processors.add(new PermissionCalculator.RegexProcessor(luckPermsPermissions));
|
||||
}
|
||||
processors.add(new BukkitDefaultsProcessor(parent::isOp));
|
||||
|
||||
calculator = new PermissionCalculator(plugin, parent.getName(), plugin.getConfiguration().getDebugPermissionChecks(), processors);
|
||||
}
|
||||
|
||||
public void invalidateCache() {
|
||||
calculator.invalidateCache();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isOp() {
|
||||
return parent.isOp();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setOp(boolean value) {
|
||||
parent.setOp(value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isPermissionSet(@NonNull String name) {
|
||||
return luckPermsPermissions.containsKey(name.toLowerCase()) || attachmentPermissions.containsKey(name.toLowerCase());
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isPermissionSet(@NonNull Permission perm) {
|
||||
return isPermissionSet(perm.getName());
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasPermission(@NonNull String name) {
|
||||
Tristate ts = calculator.getPermissionValue(name);
|
||||
if (ts != Tristate.UNDEFINED) {
|
||||
return ts.asBoolean();
|
||||
}
|
||||
|
||||
return Permission.DEFAULT_PERMISSION.getValue(isOp());
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasPermission(@NonNull Permission perm) {
|
||||
Tristate ts = calculator.getPermissionValue(perm.getName());
|
||||
if (ts != Tristate.UNDEFINED) {
|
||||
return ts.asBoolean();
|
||||
}
|
||||
|
||||
return perm.getDefault().getValue(isOp());
|
||||
}
|
||||
|
||||
@Override
|
||||
public PermissionAttachment addAttachment(@NonNull Plugin plugin, @NonNull String name, boolean value) {
|
||||
if (!plugin.isEnabled()) {
|
||||
throw new IllegalArgumentException("Plugin " + plugin.getDescription().getFullName() + " is not enabled");
|
||||
}
|
||||
|
||||
PermissionAttachment result = addAttachment(plugin);
|
||||
result.setPermission(name, value);
|
||||
|
||||
recalculatePermissions();
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public PermissionAttachment addAttachment(@NonNull Plugin plugin) {
|
||||
if (!plugin.isEnabled()) {
|
||||
throw new IllegalArgumentException("Plugin " + plugin.getDescription().getFullName() + " is not enabled");
|
||||
}
|
||||
|
||||
PermissionAttachment result = new PermissionAttachment(plugin, parent);
|
||||
|
||||
attachments.add(result);
|
||||
recalculatePermissions();
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public PermissionAttachment addAttachment(@NonNull Plugin plugin, @NonNull String name, boolean value, int ticks) {
|
||||
if (!plugin.isEnabled()) {
|
||||
throw new IllegalArgumentException("Plugin " + plugin.getDescription().getFullName() + " is not enabled");
|
||||
}
|
||||
|
||||
PermissionAttachment result = addAttachment(plugin, ticks);
|
||||
if (result != null) {
|
||||
result.setPermission(name, value);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public PermissionAttachment addAttachment(@NonNull Plugin plugin, int ticks) {
|
||||
if (!plugin.isEnabled()) {
|
||||
throw new IllegalArgumentException("Plugin " + plugin.getDescription().getFullName() + " is not enabled");
|
||||
}
|
||||
|
||||
PermissionAttachment result = addAttachment(plugin);
|
||||
if (Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(plugin, new RemoveAttachmentRunnable(result), ticks) == -1) {
|
||||
Bukkit.getServer().getLogger().log(Level.WARNING, "Could not add PermissionAttachment to " + parent + " for plugin " + plugin.getDescription().getFullName() + ": Scheduler returned -1");
|
||||
result.remove();
|
||||
return null;
|
||||
} else {
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeAttachment(@NonNull PermissionAttachment attachment) {
|
||||
if (attachments.contains(attachment)) {
|
||||
attachments.remove(attachment);
|
||||
PermissionRemovedExecutor ex = attachment.getRemovalCallback();
|
||||
|
||||
if (ex != null) {
|
||||
ex.attachmentRemoved(attachment);
|
||||
}
|
||||
|
||||
recalculatePermissions();
|
||||
} else {
|
||||
throw new IllegalArgumentException("Given attachment is not part of Permissible object " + parent);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void recalculatePermissions() {
|
||||
if (attachmentPermissions == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
attachmentPermissions.clear();
|
||||
Set<Permission> defaults = Bukkit.getServer().getPluginManager().getDefaultPermissions(isOp());
|
||||
Bukkit.getServer().getPluginManager().subscribeToDefaultPerms(isOp(), parent);
|
||||
|
||||
for (Permission perm : defaults) {
|
||||
String name = perm.getName().toLowerCase();
|
||||
|
||||
attachmentPermissions.put(name, new PermissionAttachmentInfo(parent, name, null, true));
|
||||
Bukkit.getServer().getPluginManager().subscribeToPermission(name, parent);
|
||||
calculateChildPermissions(perm.getChildren(), false, null);
|
||||
}
|
||||
|
||||
for (PermissionAttachment attachment : attachments) {
|
||||
calculateChildPermissions(attachment.getPermissions(), false, attachment);
|
||||
}
|
||||
|
||||
invalidateCache();
|
||||
}
|
||||
|
||||
@Override
|
||||
public synchronized void clearPermissions() {
|
||||
Set<String> perms = attachmentPermissions.keySet();
|
||||
|
||||
for (String name : perms) {
|
||||
Bukkit.getServer().getPluginManager().unsubscribeFromPermission(name, parent);
|
||||
}
|
||||
|
||||
Bukkit.getServer().getPluginManager().unsubscribeFromDefaultPerms(false, parent);
|
||||
Bukkit.getServer().getPluginManager().unsubscribeFromDefaultPerms(true, parent);
|
||||
|
||||
attachmentPermissions.clear();
|
||||
}
|
||||
|
||||
private void calculateChildPermissions(Map<String, Boolean> children, boolean invert, PermissionAttachment attachment) {
|
||||
for (Map.Entry<String, Boolean> e : children.entrySet()) {
|
||||
Permission perm = Bukkit.getServer().getPluginManager().getPermission(e.getKey());
|
||||
boolean value = e.getValue() ^ invert;
|
||||
String name = e.getKey().toLowerCase();
|
||||
|
||||
attachmentPermissions.put(name, new PermissionAttachmentInfo(parent, name, attachment, value));
|
||||
Bukkit.getServer().getPluginManager().subscribeToPermission(name, parent);
|
||||
|
||||
if (perm != null) {
|
||||
calculateChildPermissions(perm.getChildren(), !value, attachment);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<PermissionAttachmentInfo> getEffectivePermissions() {
|
||||
Set<PermissionAttachmentInfo> perms = new HashSet<>();
|
||||
perms.addAll(attachmentPermissions.values());
|
||||
|
||||
perms.addAll(luckPermsPermissions.entrySet().stream()
|
||||
.map(e -> new PermissionAttachmentInfo(parent, e.getKey(), null, e.getValue()))
|
||||
.collect(Collectors.toList()));
|
||||
|
||||
return perms;
|
||||
}
|
||||
|
||||
private class RemoveAttachmentRunnable implements Runnable {
|
||||
private PermissionAttachment attachment;
|
||||
|
||||
private RemoveAttachmentRunnable(PermissionAttachment attachment) {
|
||||
this.attachment = attachment;
|
||||
}
|
||||
|
||||
public void run() {
|
||||
attachment.remove();
|
||||
}
|
||||
}
|
||||
|
||||
@AllArgsConstructor
|
||||
private static class AttachmentProcessor implements PermissionProcessor {
|
||||
|
||||
@Getter
|
||||
private final Map<String, PermissionAttachmentInfo> map;
|
||||
|
||||
@Override
|
||||
public Tristate hasPermission(String permission) {
|
||||
if (map.containsKey(permission)) {
|
||||
return Tristate.fromBoolean(map.get(permission).getValue());
|
||||
}
|
||||
|
||||
return Tristate.UNDEFINED;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@AllArgsConstructor
|
||||
private static class BukkitDefaultsProcessor implements PermissionProcessor {
|
||||
private final Supplier<Boolean> isOp;
|
||||
|
||||
@Override
|
||||
public Tristate hasPermission(String permission) {
|
||||
Permission defPerm = Bukkit.getServer().getPluginManager().getPermission(permission);
|
||||
if (defPerm != null) {
|
||||
return Tristate.fromBoolean(defPerm.getDefault().getValue(isOp.get()));
|
||||
} else {
|
||||
return Tristate.UNDEFINED;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -25,33 +25,22 @@ package me.lucko.luckperms.users;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import me.lucko.luckperms.LPBukkitPlugin;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.permissions.PermissionAttachment;
|
||||
import me.lucko.luckperms.api.event.events.UserPermissionRefreshEvent;
|
||||
import me.lucko.luckperms.api.implementation.internal.UserLink;
|
||||
import me.lucko.luckperms.inject.LPPermissible;
|
||||
import me.lucko.luckperms.utils.Contexts;
|
||||
import org.bukkit.permissions.Permissible;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.util.Collections;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
|
||||
public class BukkitUser extends User {
|
||||
private static Field permissionsField = null;
|
||||
private static Field getPermissionsField() {
|
||||
if (permissionsField == null) {
|
||||
try {
|
||||
permissionsField = PermissionAttachment.class.getDeclaredField("permissions");
|
||||
permissionsField.setAccessible(true);
|
||||
} catch (SecurityException | NoSuchFieldException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
return permissionsField;
|
||||
}
|
||||
|
||||
|
||||
private final LPBukkitPlugin plugin;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
private PermissionAttachment attachment = null;
|
||||
private LPPermissible lpPermissible = null;
|
||||
|
||||
BukkitUser(UUID uuid, LPBukkitPlugin plugin) {
|
||||
super(uuid, plugin);
|
||||
@@ -65,45 +54,69 @@ public class BukkitUser extends User {
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
public void refreshPermissions() {
|
||||
plugin.doSync(() -> {
|
||||
final Player player = plugin.getServer().getPlayer(plugin.getUuidCache().getExternalUUID(getUuid()));
|
||||
if (player == null) return;
|
||||
public synchronized void refreshPermissions() {
|
||||
if (lpPermissible == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (attachment == null) {
|
||||
getPlugin().getLog().warn("User " + getName() + " does not have a permissions attachment defined.");
|
||||
setAttachment(player.addAttachment(plugin));
|
||||
// Calculate the permissions that should be applied. This is done async, who cares about how long it takes or how often it's done.
|
||||
Map<String, Boolean> toApply = exportNodes(
|
||||
new Contexts(
|
||||
getPlugin().getConfiguration().getServer(),
|
||||
plugin.getUserManager().getWorldCache().get(getUuid()),
|
||||
null,
|
||||
getPlugin().getConfiguration().getIncludeGlobalPerms(),
|
||||
getPlugin().getConfiguration().getIncludeGlobalWorldPerms(),
|
||||
true,
|
||||
getPlugin().getConfiguration().getApplyGlobalGroups(),
|
||||
getPlugin().getConfiguration().getApplyGlobalWorldGroups()
|
||||
),
|
||||
Collections.emptyList()
|
||||
);
|
||||
|
||||
try {
|
||||
Map<String, Boolean> existing = lpPermissible.getLuckPermsPermissions();
|
||||
|
||||
boolean different = false;
|
||||
if (toApply.size() != existing.size()) {
|
||||
different = true;
|
||||
} else {
|
||||
for (Map.Entry<String, Boolean> e : existing.entrySet()) {
|
||||
if (toApply.containsKey(e.getKey()) && toApply.get(e.getKey()) == e.getValue()) {
|
||||
continue;
|
||||
}
|
||||
different = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// Calculate the permissions that should be applied
|
||||
Map<String, Boolean> toApply = getLocalPermissions(getPlugin().getConfiguration().getServer(), player.getWorld().getName(), null);
|
||||
if (!different) return;
|
||||
|
||||
try {
|
||||
Map<String, Boolean> existing = (Map<String, Boolean>) getPermissionsField().get(attachment);
|
||||
existing.clear();
|
||||
lpPermissible.invalidateCache();
|
||||
existing.putAll(toApply);
|
||||
|
||||
boolean different = false;
|
||||
if (toApply.size() != existing.size()) {
|
||||
different = true;
|
||||
} else {
|
||||
for (Map.Entry<String, Boolean> e : existing.entrySet()) {
|
||||
if (toApply.containsKey(e.getKey()) && toApply.get(e.getKey()) == e.getValue()) {
|
||||
continue;
|
||||
}
|
||||
different = true;
|
||||
if (plugin.getConfiguration().getAutoOp()) {
|
||||
boolean op = false;
|
||||
|
||||
for (Map.Entry<String, Boolean> e : toApply.entrySet()) {
|
||||
if (e.getKey().equalsIgnoreCase("luckperms.autoop") && e.getValue()) {
|
||||
op = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!different) return;
|
||||
|
||||
// Faster than recalculating permissions after each PermissionAttachment#setPermission
|
||||
existing.clear();
|
||||
existing.putAll(toApply);
|
||||
attachment.getPermissible().recalculatePermissions();
|
||||
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
final boolean finalOp = op;
|
||||
if (lpPermissible.isOp() != op) {
|
||||
final Permissible parent = lpPermissible.getParent();
|
||||
plugin.doSync(() -> parent.setOp(finalOp));
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
plugin.getApiProvider().fireEventAsync(new UserPermissionRefreshEvent(new UserLink(this)));
|
||||
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -22,39 +22,43 @@
|
||||
|
||||
package me.lucko.luckperms.users;
|
||||
|
||||
import lombok.Getter;
|
||||
import me.lucko.luckperms.LPBukkitPlugin;
|
||||
import me.lucko.luckperms.inject.Injector;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class BukkitUserManager extends UserManager {
|
||||
private final LPBukkitPlugin plugin;
|
||||
|
||||
@Getter
|
||||
private final Map<UUID, String> worldCache = new ConcurrentHashMap<>();
|
||||
|
||||
public BukkitUserManager(LPBukkitPlugin plugin) {
|
||||
super(plugin);
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void unload(User user) {
|
||||
if (user != null) {
|
||||
public void preUnload(User user) {
|
||||
if (user instanceof BukkitUser) {
|
||||
BukkitUser u = (BukkitUser) user;
|
||||
Player player = plugin.getServer().getPlayer(plugin.getUuidCache().getExternalUUID(u.getUuid()));
|
||||
if (player != null) {
|
||||
if (u.getLpPermissible() != null) {
|
||||
Injector.unInject(player);
|
||||
u.setLpPermissible(null);
|
||||
}
|
||||
|
||||
if (user instanceof BukkitUser) {
|
||||
BukkitUser u = (BukkitUser) user;
|
||||
|
||||
if (u.getAttachment() != null) {
|
||||
Player player = plugin.getServer().getPlayer(plugin.getUuidCache().getExternalUUID(u.getUuid()));
|
||||
|
||||
if (player != null) {
|
||||
player.removeAttachment(u.getAttachment());
|
||||
}
|
||||
u.setAttachment(null);
|
||||
if (plugin.getConfiguration().getAutoOp()) {
|
||||
player.setOp(false);
|
||||
}
|
||||
}
|
||||
|
||||
getAll().remove(user.getUuid());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -82,7 +86,7 @@ public class BukkitUserManager extends UserManager {
|
||||
Set<UUID> players = plugin.getServer().getOnlinePlayers().stream()
|
||||
.map(p -> plugin.getUuidCache().getUUID(p.getUniqueId()))
|
||||
.collect(Collectors.toSet());
|
||||
plugin.doAsync(() -> players.forEach(u -> plugin.getDatastore().loadUser(u)));
|
||||
plugin.doAsync(() -> players.forEach(u -> plugin.getDatastore().loadUser(u, "null")));
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -1,14 +1,27 @@
|
||||
# LuckPerms Configuration
|
||||
##############################################################################
|
||||
# +------------------------------------------------------------------------+ #
|
||||
# | LuckPerms Configuration | #
|
||||
# | https://github.com/lucko/LuckPerms | #
|
||||
# +------------------------------------------------------------------------+ #
|
||||
##############################################################################
|
||||
|
||||
# The name of the server, used for server specific permissions. Set to 'global' to disable.
|
||||
server: global
|
||||
|
||||
# The default group assigned to all users on their first join.
|
||||
default-group: default
|
||||
|
||||
# If users on this server should have their global permissions/groups applied.
|
||||
# If users on this server should have their global permissions applied.
|
||||
# If set to false, only server specific permissions will apply for users on this server
|
||||
include-global: true
|
||||
|
||||
# If users on this server should have their global world permissions applied.
|
||||
# If set to false, only world specific permissions will apply for users on this server
|
||||
include-global-world: true
|
||||
|
||||
# If users on this server should have global (non-server specific) groups applied
|
||||
apply-global-groups: true
|
||||
|
||||
# If users on this server should have global (non-world specific) groups applied
|
||||
apply-global-world-groups: true
|
||||
|
||||
# If this server is in offline or online mode.
|
||||
# This setting allows a player to have the same UUID across a network of offline mode/mixed servers.
|
||||
|
||||
@@ -20,31 +33,76 @@ include-global: true
|
||||
|
||||
# 2. You are only running one server instance using LuckPerms, (not a network)
|
||||
# In this case, set online-mode to true no matter what is set in server.properties. (we can just fallback to the servers uuid cache)
|
||||
|
||||
# 3. If your proxy is running in offline mode, and you are using PaperSpigot (https://ci.destroystokyo.com/job/PaperSpigot/),
|
||||
# you should set "bungee-online-mode" to false in the paper.yml, and set "online-mode" to true in all LuckPerms configs.
|
||||
# This approach is thoroughly recommended for offline mode networks.
|
||||
online-mode: true
|
||||
|
||||
# If the plugin should apply wildcard permissions.
|
||||
# If set to true, LuckPerms will detect wildcard permissions, and resolve & apply all registered permissions matching
|
||||
# the wildcard. This will only work for plugins that define all of their permissions to the server.
|
||||
# the wildcard.
|
||||
apply-wildcards: true
|
||||
|
||||
# If the plugin should parse regex permissions.
|
||||
# If set to true, LuckPerms will detect regex permissions, marked with "r=" at the start of the node, and resolve &
|
||||
# apply all registered permissions matching the regex. This will only work for plugins that define all of their
|
||||
# permissions to the server.
|
||||
# apply all registered permissions matching the regex.
|
||||
apply-regex: true
|
||||
|
||||
# If the plugin should complete and apply shorthand permissions.
|
||||
# If set to true, LuckPerms will detect and expand shorthand node patterns.
|
||||
apply-shorthand: true
|
||||
|
||||
# Which storage method the plugin should use.
|
||||
# Currently supported: mysql, sqlite, flatfile
|
||||
# Fill out connection info below if you're using MySQL
|
||||
storage-method: sqlite
|
||||
# If the plugin should send log notifications to users whenever permissions are modified.
|
||||
log-notify: true
|
||||
|
||||
sql:
|
||||
# If LuckPerms should print to console every time a plugin checks if a player has a permission
|
||||
debug-permission-checks: false
|
||||
|
||||
# If the vanilla OP system is enabled. If set to false, all users will be de-opped, and the op/deop commands will be disabled.
|
||||
enable-ops: true
|
||||
|
||||
# If set to true, any user with the permission "luckperms.autoop" will automatically be granted server operator status.
|
||||
# This permission can be inherited, or set on specific servers/worlds, temporarily, etc.
|
||||
# Additionally, setting this to true will force the "enable-ops" option above to false. All users will be de-opped unless
|
||||
# they have the permission node, and the op/deop commands will be disabled.
|
||||
#
|
||||
# It is recommended that you use this option instead of assigning a single '*' permission.
|
||||
auto-op: false
|
||||
|
||||
# If opped players should be allowed to use LuckPerms commands. Set to false to only allow users who have the permissions access to the commands
|
||||
commands-allow-op: true
|
||||
|
||||
# The name of the server used within Vault operations. If you don't want Vault operations to be server specific, set this
|
||||
# to "global".
|
||||
vault-server: global
|
||||
|
||||
# If global permissions should be considered when retrieving meta or player groups
|
||||
vault-include-global: true
|
||||
|
||||
# Which storage method the plugin should use.
|
||||
# Currently supported: mysql, sqlite, h2, json, yaml, mongodb
|
||||
# Fill out connection info below if you're using MySQL or MongoDB
|
||||
storage-method: h2
|
||||
|
||||
# This block enables support for split datastores.
|
||||
# Only touch this if you're sure that you know what you're doing.
|
||||
# I (the author) do not endorse nor recommend the use of this feature.
|
||||
split-storage:
|
||||
enabled: false
|
||||
methods:
|
||||
user: h2
|
||||
group: h2
|
||||
track: h2
|
||||
uuid: h2
|
||||
log: h2
|
||||
|
||||
data:
|
||||
address: localhost:3306
|
||||
database: minecraft
|
||||
username: root
|
||||
password: ''
|
||||
sync-minutes: 3
|
||||
|
||||
# Set to -1 to disable. If this is the only instance accessing the datastore, you can disable syncing.
|
||||
# e.g. if you're using sqlite or flatfile, this can be set to -1 to save resources.
|
||||
sync-minutes: 3
|
||||
@@ -1,125 +1,16 @@
|
||||
name: LuckPerms
|
||||
author: Luck
|
||||
version: ${project.version}.${git.closest.tag.commit.count}
|
||||
main: me.lucko.luckperms.LPBukkitPlugin
|
||||
softdepend: [Vault]
|
||||
version: ${release.version}.${git.closest.tag.commit.count}
|
||||
description: A permissions plugin
|
||||
author: Luck
|
||||
website: https://github.com/lucko/LuckPerms
|
||||
|
||||
main: me.lucko.luckperms.LPBukkitPlugin
|
||||
softdepend: [Vault, PermissionsEx, GroupManager, PowerfulPerms, zPermissions, bPermissions] # For migration
|
||||
|
||||
commands:
|
||||
luckperms:
|
||||
description: Manage permissions
|
||||
aliases: [perms, permissions, lp, p, perm]
|
||||
permissions:
|
||||
luckperms.*:
|
||||
description: Gives access to all LuckPerms commands
|
||||
children:
|
||||
luckperms.sync: true
|
||||
luckperms.info: true
|
||||
luckperms.debug: true
|
||||
luckperms.creategroup: true
|
||||
luckperms.deletegroup: true
|
||||
luckperms.listgroups: true
|
||||
luckperms.createtrack: true
|
||||
luckperms.deletetrack: true
|
||||
luckperms.listtracks: true
|
||||
luckperms.user.info: true
|
||||
luckperms.user.getuuid: true
|
||||
luckperms.user.listnodes: true
|
||||
luckperms.user.haspermission: true
|
||||
luckperms.user.inheritspermission: true
|
||||
luckperms.user.setpermission: true
|
||||
luckperms.user.unsetpermission: true
|
||||
luckperms.user.addgroup: true
|
||||
luckperms.user.removegroup: true
|
||||
luckperms.user.settemppermission: true
|
||||
luckperms.user.unsettemppermission: true
|
||||
luckperms.user.addtempgroup: true
|
||||
luckperms.user.removetempgroup: true
|
||||
luckperms.user.setprimarygroup: true
|
||||
luckperms.user.showtracks: true
|
||||
luckperms.user.promote: true
|
||||
luckperms.user.demote: true
|
||||
luckperms.user.showpos: true
|
||||
luckperms.user.clear: true
|
||||
luckperms.group.info: true
|
||||
luckperms.group.listnodes: true
|
||||
luckperms.group.haspermission: true
|
||||
luckperms.group.inheritspermission: true
|
||||
luckperms.group.setpermission: true
|
||||
luckperms.group.unsetpermission: true
|
||||
luckperms.group.setinherit: true
|
||||
luckperms.group.unsetinherit: true
|
||||
luckperms.group.settemppermission: true
|
||||
luckperms.group.unsettemppermission: true
|
||||
luckperms.group.settempinherit: true
|
||||
luckperms.group.unsettempinherit: true
|
||||
luckperms.group.showtracks: true
|
||||
luckperms.group.clear: true
|
||||
luckperms.track.info: true
|
||||
luckperms.track.append: true
|
||||
luckperms.track.insert: true
|
||||
luckperms.track.remove: true
|
||||
luckperms.track.clear: true
|
||||
luckperms.log.export: true
|
||||
luckperms.log.userhistory: true
|
||||
luckperms.log.grouphistory: true
|
||||
luckperms.log.trackhistory: true
|
||||
luckperms.log.notify: true
|
||||
luckperms.log.recent: true
|
||||
luckperms.log.search: true
|
||||
luckperms.user.*:
|
||||
description: Gives access to all LuckPerms user commands
|
||||
children:
|
||||
luckperms.user.info: true
|
||||
luckperms.user.getuuid: true
|
||||
luckperms.user.listnodes: true
|
||||
luckperms.user.haspermission: true
|
||||
luckperms.user.inheritspermission: true
|
||||
luckperms.user.setpermission: true
|
||||
luckperms.user.unsetpermission: true
|
||||
luckperms.user.addgroup: true
|
||||
luckperms.user.removegroup: true
|
||||
luckperms.user.settemppermission: true
|
||||
luckperms.user.unsettemppermission: true
|
||||
luckperms.user.addtempgroup: true
|
||||
luckperms.user.removetempgroup: true
|
||||
luckperms.user.setprimarygroup: true
|
||||
luckperms.user.showtracks: true
|
||||
luckperms.user.promote: true
|
||||
luckperms.user.demote: true
|
||||
luckperms.user.showpos: true
|
||||
luckperms.user.clear: true
|
||||
luckperms.group.*:
|
||||
description: Gives access to all LuckPerms group commands
|
||||
children:
|
||||
luckperms.group.info: true
|
||||
luckperms.group.listnodes: true
|
||||
luckperms.group.haspermission: true
|
||||
luckperms.group.inheritspermission: true
|
||||
luckperms.group.setpermission: true
|
||||
luckperms.group.unsetpermission: true
|
||||
luckperms.group.setinherit: true
|
||||
luckperms.group.unsetinherit: true
|
||||
luckperms.group.settemppermission: true
|
||||
luckperms.group.unsettemppermission: true
|
||||
luckperms.group.settempinherit: true
|
||||
luckperms.group.unsettempinherit: true
|
||||
luckperms.group.showtracks: true
|
||||
luckperms.group.clear: true
|
||||
luckperms.track.*:
|
||||
description: Gives access to all LuckPerms track commands
|
||||
children:
|
||||
luckperms.track.info: true
|
||||
luckperms.track.append: true
|
||||
luckperms.track.insert: true
|
||||
luckperms.track.remove: true
|
||||
luckperms.track.clear: true
|
||||
luckperms.log.*:
|
||||
description: Gives access to all LuckPerms log commands
|
||||
children:
|
||||
luckperms.log.export: true
|
||||
luckperms.log.userhistory: true
|
||||
luckperms.log.grouphistory: true
|
||||
luckperms.log.trackhistory: true
|
||||
luckperms.log.notify: true
|
||||
luckperms.log.recent: true
|
||||
luckperms.log.search: true
|
||||
|
||||
|
||||
# Permissions are registered programmatically instead of here.
|
||||
+24
-15
@@ -5,7 +5,7 @@
|
||||
<parent>
|
||||
<artifactId>luckperms</artifactId>
|
||||
<groupId>me.lucko.luckperms</groupId>
|
||||
<version>2.3</version>
|
||||
<version>2.9-SNAPSHOT</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
@@ -14,7 +14,7 @@
|
||||
|
||||
<build>
|
||||
<defaultGoal>clean package</defaultGoal>
|
||||
<finalName>LuckPermsBungee-${project.version}.${git.closest.tag.commit.count}</finalName>
|
||||
<finalName>LuckPermsBungee-${release.version}.${git.closest.tag.commit.count}</finalName>
|
||||
<sourceDirectory>${basedir}/src/main/java</sourceDirectory>
|
||||
<resources>
|
||||
<resource>
|
||||
@@ -43,7 +43,7 @@
|
||||
<goal>shade</goal>
|
||||
</goals>
|
||||
<configuration>
|
||||
<minimizeJar>true</minimizeJar>
|
||||
<minimizeJar>false</minimizeJar>
|
||||
<relocations>
|
||||
<relocation>
|
||||
<pattern>org.slf4j</pattern>
|
||||
@@ -53,6 +53,22 @@
|
||||
<pattern>com.zaxxer.hikari</pattern>
|
||||
<shadedPattern>me.lucko.luckperms.lib.hikari</shadedPattern>
|
||||
</relocation>
|
||||
<relocation>
|
||||
<pattern>com.mongodb</pattern>
|
||||
<shadedPattern>me.lucko.luckperms.lib.mongodb</shadedPattern>
|
||||
</relocation>
|
||||
<relocation>
|
||||
<pattern>org.bson</pattern>
|
||||
<shadedPattern>me.lucko.luckperms.lib.bson</shadedPattern>
|
||||
</relocation>
|
||||
<relocation>
|
||||
<pattern>org.h2</pattern>
|
||||
<shadedPattern>me.lucko.luckperms.lib.h2</shadedPattern>
|
||||
</relocation>
|
||||
<relocation>
|
||||
<pattern>org.sqlite</pattern>
|
||||
<shadedPattern>me.lucko.luckperms.lib.sqlite</shadedPattern>
|
||||
</relocation>
|
||||
</relocations>
|
||||
</configuration>
|
||||
</execution>
|
||||
@@ -98,19 +114,12 @@
|
||||
<version>${project.version}</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
<!-- HikariCP -->
|
||||
<!-- Lombok -->
|
||||
<dependency>
|
||||
<groupId>com.zaxxer</groupId>
|
||||
<artifactId>HikariCP</artifactId>
|
||||
<version>2.4.7</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
<!-- slf4j library -->
|
||||
<dependency>
|
||||
<groupId>org.slf4j</groupId>
|
||||
<artifactId>slf4j-simple</artifactId>
|
||||
<version>1.7.9</version>
|
||||
<scope>compile</scope>
|
||||
<groupId>org.projectlombok</groupId>
|
||||
<artifactId>lombok</artifactId>
|
||||
<version>1.16.10</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
|
||||
@@ -22,8 +22,12 @@
|
||||
|
||||
package me.lucko.luckperms;
|
||||
|
||||
import com.google.common.base.Joiner;
|
||||
import com.google.common.base.Splitter;
|
||||
import me.lucko.luckperms.api.data.Callback;
|
||||
import me.lucko.luckperms.commands.CommandManager;
|
||||
import me.lucko.luckperms.commands.Util;
|
||||
import me.lucko.luckperms.constants.Patterns;
|
||||
import net.md_5.bungee.api.CommandSender;
|
||||
import net.md_5.bungee.api.plugin.Command;
|
||||
import net.md_5.bungee.api.plugin.TabExecutor;
|
||||
@@ -40,7 +44,12 @@ class BungeeCommand extends Command implements TabExecutor {
|
||||
|
||||
@Override
|
||||
public void execute(CommandSender sender, String[] args) {
|
||||
manager.onCommand(BungeeSenderFactory.get().wrap(sender), "bperms", Arrays.asList(args), Callback.empty());
|
||||
manager.onCommand(
|
||||
BungeeSenderFactory.get().wrap(sender),
|
||||
"bperms",
|
||||
Util.stripQuotes(Splitter.on(Patterns.COMMAND_SEPARATOR).omitEmptyStrings().splitToList(Joiner.on(' ').join(args))),
|
||||
Callback.empty()
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -33,13 +33,11 @@ import net.md_5.bungee.api.event.*;
|
||||
import net.md_5.bungee.api.plugin.Listener;
|
||||
import net.md_5.bungee.event.EventHandler;
|
||||
|
||||
import java.lang.ref.WeakReference;
|
||||
import java.util.Collections;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
class BungeeListener extends AbstractListener implements Listener {
|
||||
@SuppressWarnings("WeakerAccess")
|
||||
public class BungeeListener extends AbstractListener implements Listener {
|
||||
private static final TextComponent WARN_MESSAGE = new TextComponent(Message.LOADING_ERROR.toString());
|
||||
private final LPBungeePlugin plugin;
|
||||
|
||||
@@ -51,22 +49,18 @@ class BungeeListener extends AbstractListener implements Listener {
|
||||
@EventHandler
|
||||
public void onPlayerPermissionCheck(PermissionCheckEvent e) {
|
||||
if (!(e.getSender() instanceof ProxiedPlayer)) {
|
||||
e.setHasPermission(true);
|
||||
return;
|
||||
}
|
||||
|
||||
final ProxiedPlayer player = ((ProxiedPlayer) e.getSender());
|
||||
final User user = plugin.getUserManager().get(plugin.getUuidCache().getUUID(player.getUniqueId()));
|
||||
if (user == null) return;
|
||||
|
||||
|
||||
final String server = player.getServer() == null ? null : (player.getServer().getInfo() == null ? null : player.getServer().getInfo().getName());
|
||||
Map<String, Boolean> local = user.getLocalPermissions(plugin.getConfiguration().getServer(), server, null, Collections.singletonList(e.getPermission()));
|
||||
for (Map.Entry<String, Boolean> en : local.entrySet()) {
|
||||
if (en.getKey().equalsIgnoreCase(e.getPermission())) {
|
||||
e.setHasPermission(en.getValue());
|
||||
return;
|
||||
}
|
||||
BungeePlayerCache playerCache = plugin.getPlayerCache().get(plugin.getUuidCache().getUUID(player.getUniqueId()));
|
||||
if (playerCache == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
e.setHasPermission(playerCache.getPermissionValue(e.getPermission()));
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
@@ -96,7 +90,7 @@ class BungeeListener extends AbstractListener implements Listener {
|
||||
|
||||
// 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.
|
||||
plugin.getDatastore().loadOrCreateUser(cache.getUUID(c.getUniqueId()), c.getName());
|
||||
plugin.getDatastore().loadUser(cache.getUUID(c.getUniqueId()), c.getName());
|
||||
final long time = System.currentTimeMillis() - startTime;
|
||||
if (time >= 1000) {
|
||||
plugin.getLog().warn("Processing login for " + c.getName() + " took " + time + "ms.");
|
||||
@@ -108,23 +102,20 @@ class BungeeListener extends AbstractListener implements Listener {
|
||||
@EventHandler
|
||||
public void onPlayerPostLogin(PostLoginEvent e) {
|
||||
final ProxiedPlayer player = e.getPlayer();
|
||||
final WeakReference<ProxiedPlayer> p = new WeakReference<>(player);
|
||||
final UUID internal = plugin.getUuidCache().getUUID(e.getPlayer().getUniqueId());
|
||||
final User user = plugin.getUserManager().get(internal);
|
||||
|
||||
final User user = plugin.getUserManager().get(plugin.getUuidCache().getUUID(e.getPlayer().getUniqueId()));
|
||||
if (user == null) {
|
||||
plugin.getProxy().getScheduler().schedule(plugin, () -> {
|
||||
final ProxiedPlayer pl = p.get();
|
||||
if (pl != null) {
|
||||
pl.sendMessage(WARN_MESSAGE);
|
||||
}
|
||||
}, 3, TimeUnit.SECONDS);
|
||||
plugin.getProxy().getScheduler().schedule(plugin, () -> player.sendMessage(WARN_MESSAGE), 3, TimeUnit.SECONDS);
|
||||
} else {
|
||||
plugin.getPlayerCache().put(internal, new BungeePlayerCache(plugin, e.getPlayer().getName()));
|
||||
user.refreshPermissions();
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onPlayerQuit(PlayerDisconnectEvent e) {
|
||||
plugin.getPlayerCache().remove(plugin.getUuidCache().getUUID(e.getPlayer().getUniqueId()));
|
||||
onLeave(e.getPlayer().getUniqueId());
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,61 @@
|
||||
/*
|
||||
* Copyright (c) 2016 Lucko (Luck) <luck@lucko.me>
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
package me.lucko.luckperms;
|
||||
|
||||
import lombok.Getter;
|
||||
import me.lucko.luckperms.utils.PermissionCalculator;
|
||||
import me.lucko.luckperms.utils.PermissionProcessor;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
public class BungeePlayerCache {
|
||||
|
||||
private final PermissionCalculator calculator;
|
||||
|
||||
@Getter
|
||||
private final Map<String, Boolean> permissions = new ConcurrentHashMap<>();
|
||||
|
||||
public BungeePlayerCache(LuckPermsPlugin plugin, String name) {
|
||||
List<PermissionProcessor> processors = new ArrayList<>(3);
|
||||
processors.add(new PermissionCalculator.MapProcessor(permissions));
|
||||
if (plugin.getConfiguration().getApplyWildcards()) {
|
||||
processors.add(new PermissionCalculator.WildcardProcessor(permissions));
|
||||
}
|
||||
if (plugin.getConfiguration().getApplyRegex()) {
|
||||
processors.add(new PermissionCalculator.RegexProcessor(permissions));
|
||||
}
|
||||
|
||||
calculator = new PermissionCalculator(plugin, name, plugin.getConfiguration().getDebugPermissionChecks(), processors);
|
||||
}
|
||||
|
||||
public void invalidateCache() {
|
||||
calculator.invalidateCache();
|
||||
}
|
||||
|
||||
public boolean getPermissionValue(String permission) {
|
||||
return calculator.getPermissionValue(permission).asBoolean();
|
||||
}
|
||||
}
|
||||
@@ -35,8 +35,8 @@ import java.util.UUID;
|
||||
@NoArgsConstructor(access = AccessLevel.PRIVATE)
|
||||
public class BungeeSenderFactory extends SenderFactory<CommandSender> {
|
||||
private static BungeeSenderFactory instance = null;
|
||||
public static BungeeSenderFactory get() {
|
||||
if (instance == null){
|
||||
public static synchronized BungeeSenderFactory get() {
|
||||
if (instance == null) {
|
||||
instance = new BungeeSenderFactory();
|
||||
}
|
||||
return instance;
|
||||
|
||||
@@ -24,17 +24,21 @@ package me.lucko.luckperms;
|
||||
|
||||
import lombok.Getter;
|
||||
import me.lucko.luckperms.api.Logger;
|
||||
import me.lucko.luckperms.api.PlatformType;
|
||||
import me.lucko.luckperms.api.implementation.ApiProvider;
|
||||
import me.lucko.luckperms.commands.CommandManager;
|
||||
import me.lucko.luckperms.commands.ConsecutiveExecutor;
|
||||
import me.lucko.luckperms.commands.Sender;
|
||||
import me.lucko.luckperms.constants.Message;
|
||||
import me.lucko.luckperms.constants.Permission;
|
||||
import me.lucko.luckperms.core.LPConfiguration;
|
||||
import me.lucko.luckperms.core.UuidCache;
|
||||
import me.lucko.luckperms.data.Importer;
|
||||
import me.lucko.luckperms.groups.GroupManager;
|
||||
import me.lucko.luckperms.runnables.ExpireTemporaryTask;
|
||||
import me.lucko.luckperms.runnables.UpdateTask;
|
||||
import me.lucko.luckperms.storage.Datastore;
|
||||
import me.lucko.luckperms.storage.methods.FlatfileDatastore;
|
||||
import me.lucko.luckperms.storage.methods.MySQLDatastore;
|
||||
import me.lucko.luckperms.storage.StorageFactory;
|
||||
import me.lucko.luckperms.tracks.TrackManager;
|
||||
import me.lucko.luckperms.users.BungeeUserManager;
|
||||
import me.lucko.luckperms.users.UserManager;
|
||||
@@ -42,20 +46,26 @@ import me.lucko.luckperms.utils.LogFactory;
|
||||
import net.md_5.bungee.api.connection.ProxiedPlayer;
|
||||
import net.md_5.bungee.api.plugin.Plugin;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@Getter
|
||||
public class LPBungeePlugin extends Plugin implements LuckPermsPlugin {
|
||||
private final Set<UUID> ignoringLogs = new HashSet<>();
|
||||
private final Map<UUID, BungeePlayerCache> playerCache = new ConcurrentHashMap<>();
|
||||
private final Set<UUID> ignoringLogs = ConcurrentHashMap.newKeySet();
|
||||
private LPConfiguration configuration;
|
||||
private UserManager userManager;
|
||||
private GroupManager groupManager;
|
||||
private TrackManager trackManager;
|
||||
private Datastore datastore;
|
||||
private UuidCache uuidCache;
|
||||
private ApiProvider apiProvider;
|
||||
private Logger log;
|
||||
private Importer importer;
|
||||
private ConsecutiveExecutor consecutiveExecutor;
|
||||
|
||||
@Override
|
||||
public void onEnable() {
|
||||
@@ -69,40 +79,21 @@ public class LPBungeePlugin extends Plugin implements LuckPermsPlugin {
|
||||
|
||||
// register commands
|
||||
getLog().info("Registering commands...");
|
||||
getProxy().getPluginManager().registerCommand(this, new BungeeCommand(new CommandManager(this)));
|
||||
CommandManager commandManager = new CommandManager(this);
|
||||
getProxy().getPluginManager().registerCommand(this, new BungeeCommand(commandManager));
|
||||
|
||||
// disable the default Bungee /perms command so it gets handled by the Bukkit plugin
|
||||
getProxy().getDisabledCommands().add("perms");
|
||||
|
||||
getLog().info("Detecting storage method...");
|
||||
final String storageMethod = configuration.getStorageMethod();
|
||||
if (storageMethod.equalsIgnoreCase("mysql")) {
|
||||
getLog().info("Using MySQL as storage method.");
|
||||
datastore = new MySQLDatastore(this, configuration.getDatabaseValues());
|
||||
} else if (storageMethod.equalsIgnoreCase("flatfile")) {
|
||||
getLog().info("Using Flatfile (JSON) as storage method.");
|
||||
datastore = new FlatfileDatastore(this, getDataFolder());
|
||||
} else {
|
||||
getLog().severe("Storage method '" + storageMethod + "' was not recognised. Using Flatfile as fallback.");
|
||||
datastore = new FlatfileDatastore(this, getDataFolder());
|
||||
}
|
||||
|
||||
getLog().info("Initialising datastore...");
|
||||
datastore.init();
|
||||
datastore = StorageFactory.getDatastore(this, "h2");
|
||||
|
||||
getLog().info("Loading internal permission managers...");
|
||||
uuidCache = new UuidCache(getConfiguration().getOnlineMode());
|
||||
userManager = new BungeeUserManager(this);
|
||||
groupManager = new GroupManager(this);
|
||||
trackManager = new TrackManager();
|
||||
|
||||
// Run update task to refresh any online users
|
||||
getLog().info("Scheduling Update Task to refresh any online users.");
|
||||
try {
|
||||
new UpdateTask(this).run();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
importer = new Importer(commandManager);
|
||||
consecutiveExecutor = new ConsecutiveExecutor(commandManager);
|
||||
|
||||
int mins = getConfiguration().getSyncTime();
|
||||
if (mins > 0) {
|
||||
@@ -111,9 +102,20 @@ public class LPBungeePlugin extends Plugin implements LuckPermsPlugin {
|
||||
|
||||
// 20 times per second (once per "tick")
|
||||
getProxy().getScheduler().schedule(this, BungeeSenderFactory.get(), 50L, 50L, TimeUnit.MILLISECONDS);
|
||||
getProxy().getScheduler().schedule(this, new ExpireTemporaryTask(this), 3L, 3L, TimeUnit.SECONDS);
|
||||
getProxy().getScheduler().schedule(this, consecutiveExecutor, 1L, 1L, TimeUnit.SECONDS);
|
||||
|
||||
getLog().info("Registering API...");
|
||||
LuckPerms.registerProvider(new ApiProvider(this));
|
||||
apiProvider = new ApiProvider(this);
|
||||
LuckPerms.registerProvider(apiProvider);
|
||||
|
||||
// Run update task to refresh any online users
|
||||
getLog().info("Scheduling Update Task to refresh any online users.");
|
||||
try {
|
||||
new UpdateTask(this).run();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
getLog().info("Successfully loaded.");
|
||||
}
|
||||
@@ -132,6 +134,16 @@ public class LPBungeePlugin extends Plugin implements LuckPermsPlugin {
|
||||
return getDescription().getVersion();
|
||||
}
|
||||
|
||||
@Override
|
||||
public PlatformType getType() {
|
||||
return PlatformType.BUNGEE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public File getMainDir() {
|
||||
return getDataFolder();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Message getPlayerStatus(UUID uuid) {
|
||||
return getProxy().getPlayer(getUuidCache().getExternalUUID(uuid)) != null ? Message.PLAYER_ONLINE : Message.PLAYER_OFFLINE;
|
||||
@@ -148,8 +160,16 @@ public class LPBungeePlugin extends Plugin implements LuckPermsPlugin {
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Sender> getSenders() {
|
||||
return getProxy().getPlayers().stream().map(p -> BungeeSenderFactory.get().wrap(p)).collect(Collectors.toList());
|
||||
public List<Sender> getNotifyListeners() {
|
||||
return getProxy().getPlayers().stream()
|
||||
.map(p -> BungeeSenderFactory.get().wrap(p, Collections.singleton(Permission.LOG_NOTIFY)))
|
||||
.filter(Permission.LOG_NOTIFY::isAuthorized)
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
@Override
|
||||
public Sender getConsoleSender() {
|
||||
return BungeeSenderFactory.get().wrap(getProxy().getConsole());
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -158,6 +178,29 @@ public class LPBungeePlugin extends Plugin implements LuckPermsPlugin {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getPlugin(String name) {
|
||||
return getProxy().getPluginManager().getPlugin(name);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getService(Class clazz) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public UUID getUUID(String playerName) {
|
||||
return null; // Not needed on Bungee
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isPluginLoaded(String name) {
|
||||
return getProxy().getPluginManager().getPlugins().stream()
|
||||
.filter(p -> p.getDescription().getName().equalsIgnoreCase(name))
|
||||
.findAny()
|
||||
.isPresent();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void runUpdateTask() {
|
||||
doAsync(new UpdateTask(this));
|
||||
|
||||
@@ -22,21 +22,80 @@
|
||||
|
||||
package me.lucko.luckperms.users;
|
||||
|
||||
import me.lucko.luckperms.BungeePlayerCache;
|
||||
import me.lucko.luckperms.LPBungeePlugin;
|
||||
import me.lucko.luckperms.api.event.events.UserPermissionRefreshEvent;
|
||||
import me.lucko.luckperms.api.implementation.internal.UserLink;
|
||||
import me.lucko.luckperms.utils.Contexts;
|
||||
import net.md_5.bungee.api.connection.ProxiedPlayer;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
|
||||
public class BungeeUser extends User {
|
||||
private final LPBungeePlugin plugin;
|
||||
|
||||
BungeeUser(UUID uuid, LPBungeePlugin plugin) {
|
||||
super(uuid, plugin);
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
BungeeUser(UUID uuid, String username, LPBungeePlugin plugin) {
|
||||
super(uuid, username, plugin);
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void refreshPermissions() {
|
||||
// Do nothing. Permissions are applied when needed in a listener.
|
||||
public synchronized void refreshPermissions() {
|
||||
ProxiedPlayer player = plugin.getProxy().getPlayer(plugin.getUuidCache().getExternalUUID(getUuid()));
|
||||
if (player == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
BungeePlayerCache playerCache = plugin.getPlayerCache().get(getUuid());
|
||||
if (playerCache == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
final String server = player.getServer() == null ? null : (player.getServer().getInfo() == null ? null : player.getServer().getInfo().getName());
|
||||
|
||||
// Calculate the permissions that should be applied. This is done async.
|
||||
Map<String, Boolean> toApply = exportNodes(
|
||||
new Contexts(
|
||||
plugin.getConfiguration().getServer(),
|
||||
server,
|
||||
null,
|
||||
plugin.getConfiguration().getIncludeGlobalPerms(),
|
||||
plugin.getConfiguration().getIncludeGlobalWorldPerms(),
|
||||
true,
|
||||
plugin.getConfiguration().getApplyGlobalGroups(),
|
||||
plugin.getConfiguration().getApplyGlobalWorldGroups()
|
||||
),
|
||||
Collections.emptyList()
|
||||
);
|
||||
|
||||
Map<String, Boolean> existing = playerCache.getPermissions();
|
||||
|
||||
boolean different = false;
|
||||
if (toApply.size() != existing.size()) {
|
||||
different = true;
|
||||
} else {
|
||||
for (Map.Entry<String, Boolean> e : existing.entrySet()) {
|
||||
if (toApply.containsKey(e.getKey()) && toApply.get(e.getKey()) == e.getValue()) {
|
||||
continue;
|
||||
}
|
||||
different = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!different) return;
|
||||
|
||||
existing.clear();
|
||||
playerCache.invalidateCache();
|
||||
existing.putAll(toApply);
|
||||
|
||||
plugin.getApiProvider().fireEventAsync(new UserPermissionRefreshEvent(new UserLink(this)));
|
||||
}
|
||||
}
|
||||
@@ -34,15 +34,6 @@ public class BungeeUserManager extends UserManager {
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void unload(User user) {
|
||||
if (user != null) {
|
||||
// Cannot clear the ProxiedPlayer's permission map, they're leaving so that will get GCed anyway
|
||||
// Calling getPermissions.clear() throws an UnsupportedOperationException
|
||||
getAll().remove(user.getUuid());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void cleanup(User user) {
|
||||
if (plugin.getProxy().getPlayer(plugin.getUuidCache().getExternalUUID(user.getUuid())) == null) {
|
||||
@@ -64,6 +55,6 @@ public class BungeeUserManager extends UserManager {
|
||||
public void updateAllUsers() {
|
||||
plugin.getProxy().getPlayers().stream()
|
||||
.map(p -> plugin.getUuidCache().getUUID(p.getUniqueId()))
|
||||
.forEach(u -> plugin.getDatastore().loadUser(u));
|
||||
.forEach(u -> plugin.getDatastore().loadUser(u, "null"));
|
||||
}
|
||||
}
|
||||
@@ -1,14 +1,27 @@
|
||||
# LuckPerms Configuration
|
||||
##############################################################################
|
||||
# +------------------------------------------------------------------------+ #
|
||||
# | LuckPerms Configuration | #
|
||||
# | https://github.com/lucko/LuckPerms | #
|
||||
# +------------------------------------------------------------------------+ #
|
||||
##############################################################################
|
||||
|
||||
# The name of the server, used for server specific permissions. Set to 'global' to disable.
|
||||
server: bungee
|
||||
|
||||
# The default group assigned to all users on their first join.
|
||||
default-group: default
|
||||
|
||||
# If users on this server should have their global permissions/groups applied.
|
||||
# If users on this server should have their global permissions applied.
|
||||
# If set to false, only server specific permissions will apply for users on this server
|
||||
include-global: false
|
||||
|
||||
# If users on this server should have their global world permissions applied.
|
||||
# If set to false, only world specific permissions will apply for users on this server
|
||||
include-global-world: true
|
||||
|
||||
# If users on this server should have global (non-server specific) groups applied
|
||||
apply-global-groups: true
|
||||
|
||||
# If users on this server should have global (non-world specific) groups applied
|
||||
apply-global-world-groups: true
|
||||
|
||||
# If this server is in offline or online mode.
|
||||
# This setting allows a player to have the same UUID across a network of offline mode/mixed servers.
|
||||
|
||||
@@ -20,31 +33,55 @@ include-global: false
|
||||
|
||||
# 2. You are only running one server instance using LuckPerms, (not a network)
|
||||
# In this case, set online-mode to true no matter what is set in server.properties. (we can just fallback to the servers uuid cache)
|
||||
|
||||
# 3. If your proxy is running in offline mode, and you are using PaperSpigot (https://ci.destroystokyo.com/job/PaperSpigot/),
|
||||
# you should set "bungee-online-mode" to false in the paper.yml, and set "online-mode" to true in all LuckPerms configs.
|
||||
# This approach is thoroughly recommended for offline mode networks.
|
||||
online-mode: true
|
||||
|
||||
# If the plugin should apply wildcard permissions.
|
||||
# If set to true, LuckPerms will detect wildcard permissions, and resolve & apply all registered permissions matching
|
||||
# the wildcard. This will only work for plugins that define all of their permissions to the server.
|
||||
# the wildcard.
|
||||
apply-wildcards: true
|
||||
|
||||
# If the plugin should parse regex permissions.
|
||||
# If set to true, LuckPerms will detect regex permissions, marked with "r=" at the start of the node, and resolve &
|
||||
# apply all registered permissions matching the regex. This will only work for plugins that define all of their
|
||||
# permissions to the server.
|
||||
# apply all registered permissions matching the regex.
|
||||
apply-regex: true
|
||||
|
||||
# If the plugin should complete and apply shorthand permissions.
|
||||
# If set to true, LuckPerms will detect and expand shorthand node patterns.
|
||||
apply-shorthand: true
|
||||
|
||||
# Which storage method the plugin should use.
|
||||
# Currently supported: mysql & flatfile
|
||||
# Fill out connection info below if you're using MySQL
|
||||
storage-method: flatfile
|
||||
# If the plugin should send log notifications to users whenever permissions are modified.
|
||||
log-notify: true
|
||||
|
||||
sql:
|
||||
# If LuckPerms should print to console every time a plugin checks if a player has a permission
|
||||
debug-permission-checks: false
|
||||
|
||||
# Which storage method the plugin should use.
|
||||
# Currently supported: mysql, sqlite, h2, json, yaml, mongodb
|
||||
# Fill out connection info below if you're using MySQL or MongoDB
|
||||
storage-method: h2
|
||||
|
||||
# This block enables support for split datastores.
|
||||
# Only touch this if you're sure that you know what you're doing.
|
||||
# I (the author) do not endorse nor recommend the use of this feature.
|
||||
split-storage:
|
||||
enabled: false
|
||||
methods:
|
||||
user: h2
|
||||
group: h2
|
||||
track: h2
|
||||
uuid: h2
|
||||
log: h2
|
||||
|
||||
data:
|
||||
address: localhost:3306
|
||||
database: minecraft
|
||||
username: root
|
||||
password: ''
|
||||
|
||||
# Set to -1 to disable. If this is the only instance accessing the datastore, you can disable syncing.
|
||||
# e.g. if you're using sqlite or flatfile, this can be set to -1 to save resources.
|
||||
sync-minutes: 3
|
||||
@@ -1,5 +1,6 @@
|
||||
name: LuckPerms
|
||||
version: ${release.version}.${git.closest.tag.commit.count}
|
||||
description: A permissions plugin
|
||||
author: Luck
|
||||
version: ${project.version}.${git.closest.tag.commit.count}
|
||||
main: me.lucko.luckperms.LPBungeePlugin
|
||||
description: A permissions plugin
|
||||
softdepends: [PowerfulPerms] # For migration
|
||||
+83
-1
@@ -5,7 +5,7 @@
|
||||
<parent>
|
||||
<artifactId>luckperms</artifactId>
|
||||
<groupId>me.lucko.luckperms</groupId>
|
||||
<version>2.3</version>
|
||||
<version>2.9-SNAPSHOT</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
@@ -39,6 +39,27 @@
|
||||
<version>2.4.7</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
<!-- SQLite -->
|
||||
<dependency>
|
||||
<groupId>org.xerial</groupId>
|
||||
<artifactId>sqlite-jdbc</artifactId>
|
||||
<version>3.8.11.2</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
<!-- H2 -->
|
||||
<dependency>
|
||||
<groupId>com.h2database</groupId>
|
||||
<artifactId>h2</artifactId>
|
||||
<version>1.4.192</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
<!-- MongoDB -->
|
||||
<dependency>
|
||||
<groupId>org.mongodb</groupId>
|
||||
<artifactId>mongo-java-driver</artifactId>
|
||||
<version>3.3.0</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
<!-- slf4j library -->
|
||||
<dependency>
|
||||
<groupId>org.slf4j</groupId>
|
||||
@@ -46,6 +67,13 @@
|
||||
<version>1.7.9</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
<!-- SnakeYAML -->
|
||||
<dependency>
|
||||
<groupId>org.yaml</groupId>
|
||||
<artifactId>snakeyaml</artifactId>
|
||||
<version>1.14</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<!-- gson -->
|
||||
<dependency>
|
||||
<groupId>com.google.code.gson</groupId>
|
||||
@@ -60,6 +88,60 @@
|
||||
<version>19.0</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<!-- Lombok -->
|
||||
<dependency>
|
||||
<groupId>org.projectlombok</groupId>
|
||||
<artifactId>lombok</artifactId>
|
||||
<version>1.16.10</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<!-- **************Migration Plugins************** -->
|
||||
<dependency>
|
||||
<groupId>org.tyrannyofheaven.bukkit</groupId>
|
||||
<artifactId>zPermissions</artifactId>
|
||||
<version>1.3</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>ru.tehkode</groupId>
|
||||
<artifactId>PermissionsEx</artifactId>
|
||||
<version>1.23</version>
|
||||
<scope>provided</scope>
|
||||
<exclusions>
|
||||
<exclusion>
|
||||
<groupId>org.bukkit</groupId>
|
||||
<artifactId>bukkit</artifactId>
|
||||
</exclusion>
|
||||
<exclusion>
|
||||
<groupId>net.gravitydevelopment.updater</groupId>
|
||||
<artifactId>updater</artifactId>
|
||||
</exclusion>
|
||||
</exclusions>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.github.cheesesoftware</groupId>
|
||||
<artifactId>PowerfulPermsAPI</artifactId>
|
||||
<version>1.0.1</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.anjocaido</groupId>
|
||||
<artifactId>GroupManager</artifactId>
|
||||
<version>1.4</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>net.alpenblock</groupId>
|
||||
<artifactId>BungeePerms</artifactId>
|
||||
<version>3.0-dev-52</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>de.bananaco</groupId>
|
||||
<artifactId>bpermissions-api</artifactId>
|
||||
<version>2.12</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
</project>
|
||||
@@ -23,15 +23,20 @@
|
||||
package me.lucko.luckperms;
|
||||
|
||||
import me.lucko.luckperms.api.Logger;
|
||||
import me.lucko.luckperms.api.PlatformType;
|
||||
import me.lucko.luckperms.api.implementation.ApiProvider;
|
||||
import me.lucko.luckperms.commands.ConsecutiveExecutor;
|
||||
import me.lucko.luckperms.commands.Sender;
|
||||
import me.lucko.luckperms.constants.Message;
|
||||
import me.lucko.luckperms.core.LPConfiguration;
|
||||
import me.lucko.luckperms.core.UuidCache;
|
||||
import me.lucko.luckperms.data.Importer;
|
||||
import me.lucko.luckperms.groups.GroupManager;
|
||||
import me.lucko.luckperms.storage.Datastore;
|
||||
import me.lucko.luckperms.tracks.TrackManager;
|
||||
import me.lucko.luckperms.users.UserManager;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
@@ -42,53 +47,40 @@ import java.util.UUID;
|
||||
*/
|
||||
public interface LuckPermsPlugin {
|
||||
|
||||
/**
|
||||
* Retrieves the {@link UserManager} used to manage users and their permissions/groups
|
||||
* @return the {@link UserManager} instance
|
||||
/*
|
||||
* Access to all of the main internal manager classes
|
||||
*/
|
||||
UserManager getUserManager();
|
||||
|
||||
/**
|
||||
* Retrieves the {@link GroupManager} used to manage the loaded groups and modify their permissions
|
||||
* @return the {@link GroupManager} instance
|
||||
*/
|
||||
GroupManager getGroupManager();
|
||||
|
||||
/**
|
||||
* Retrieves the {@link TrackManager} used to manage the loaded tracks
|
||||
* @return the {@link TrackManager} instance
|
||||
*/
|
||||
TrackManager getTrackManager();
|
||||
|
||||
/**
|
||||
* Retrieves the {@link LPConfiguration} for getting values from the config
|
||||
* @return the {@link LPConfiguration} implementation for the platform
|
||||
*/
|
||||
LPConfiguration getConfiguration();
|
||||
|
||||
/**
|
||||
* Retrieves the {@link Datastore} for loading/saving plugin data
|
||||
* @return the {@link Datastore} object
|
||||
*/
|
||||
Datastore getDatastore();
|
||||
|
||||
/**
|
||||
* Retrieves the {@link Logger} for the plugin
|
||||
* @return the plugin's {@link Logger}
|
||||
*/
|
||||
Logger getLog();
|
||||
|
||||
/**
|
||||
* Retrieves the {@link UuidCache} for the plugin
|
||||
* @return the plugin's {@link UuidCache}
|
||||
*/
|
||||
UuidCache getUuidCache();
|
||||
ApiProvider getApiProvider();
|
||||
Importer getImporter();
|
||||
ConsecutiveExecutor getConsecutiveExecutor();
|
||||
|
||||
/**
|
||||
* @return the version of the plugin
|
||||
*/
|
||||
String getVersion();
|
||||
|
||||
/**
|
||||
* @return the platform type
|
||||
*/
|
||||
PlatformType getType();
|
||||
|
||||
/**
|
||||
* @return the main plugin directory
|
||||
*/
|
||||
File getMainDir();
|
||||
|
||||
/**
|
||||
* @return the platforms data folder
|
||||
*/
|
||||
File getDataFolder();
|
||||
|
||||
/**
|
||||
* Returns a colored string indicating the status of a player
|
||||
* @param uuid The player's uuid
|
||||
@@ -109,10 +101,14 @@ public interface LuckPermsPlugin {
|
||||
List<String> getPlayerList();
|
||||
|
||||
/**
|
||||
* Gets a list of all Senders online on the platform
|
||||
* @return a {@link List} of senders
|
||||
* @return a {@link List} of senders online on the platform
|
||||
*/
|
||||
List<Sender> getSenders();
|
||||
List<Sender> getNotifyListeners();
|
||||
|
||||
/**
|
||||
* @return the console sender of the instance
|
||||
*/
|
||||
Sender getConsoleSender();
|
||||
|
||||
/**
|
||||
* Gets all possible permission nodes, used for resolving wildcards
|
||||
@@ -126,6 +122,34 @@ public interface LuckPermsPlugin {
|
||||
*/
|
||||
Set<UUID> getIgnoringLogs();
|
||||
|
||||
/**
|
||||
* Gets a loaded plugins instance from the platform
|
||||
* @param name the name of the plugin
|
||||
* @return a plugin instance
|
||||
*/
|
||||
Object getPlugin(String name);
|
||||
|
||||
/**
|
||||
* Gets a provided service from the platform.
|
||||
* @param clazz the class of the service
|
||||
* @return the service instance, if it is provided for
|
||||
*/
|
||||
Object getService(Class clazz);
|
||||
|
||||
/**
|
||||
* Used as a backup for migration
|
||||
* @param playerName the players name
|
||||
* @return a uuid if found, or null if not
|
||||
*/
|
||||
UUID getUUID(String playerName);
|
||||
|
||||
/**
|
||||
* Checks if a plugin is loaded on the platform
|
||||
* @param name the name of the plugin
|
||||
* @return true if the plugin is loaded
|
||||
*/
|
||||
boolean isPluginLoaded(String name);
|
||||
|
||||
/**
|
||||
* Runs an update task
|
||||
*/
|
||||
@@ -142,4 +166,5 @@ public interface LuckPermsPlugin {
|
||||
* @param r the task to run
|
||||
*/
|
||||
void doSync(Runnable r);
|
||||
|
||||
}
|
||||
@@ -22,10 +22,13 @@
|
||||
|
||||
package me.lucko.luckperms.api.implementation;
|
||||
|
||||
import com.google.common.eventbus.EventBus;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.NonNull;
|
||||
import me.lucko.luckperms.LuckPermsPlugin;
|
||||
import me.lucko.luckperms.api.*;
|
||||
import me.lucko.luckperms.api.event.LPEvent;
|
||||
import me.lucko.luckperms.api.event.LPListener;
|
||||
import me.lucko.luckperms.api.implementation.internal.*;
|
||||
|
||||
import java.util.Optional;
|
||||
@@ -33,23 +36,60 @@ import java.util.Set;
|
||||
import java.util.UUID;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import static me.lucko.luckperms.api.implementation.internal.Utils.checkNode;
|
||||
|
||||
/**
|
||||
* Provides static access to LuckPerms
|
||||
* Implements the LuckPerms API using the plugin instance
|
||||
*/
|
||||
@AllArgsConstructor
|
||||
public class ApiProvider implements LuckPermsApi {
|
||||
private final LuckPermsPlugin plugin;
|
||||
private final EventBus eventBus = new EventBus("LuckPerms");
|
||||
|
||||
public void fireEventAsync(LPEvent event) {
|
||||
plugin.doAsync(() -> fireEvent(event));
|
||||
}
|
||||
|
||||
public void fireEvent(LPEvent event) {
|
||||
try {
|
||||
event.setApi(this);
|
||||
eventBus.post(event);
|
||||
} catch (Exception e) {
|
||||
getLogger().severe("Couldn't fire LuckPerms Event: " + event.getEventName());
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void runUpdateTask() {
|
||||
plugin.runUpdateTask();
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getApiVersion() {
|
||||
return 2.9;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getVersion() {
|
||||
return plugin.getVersion();
|
||||
}
|
||||
|
||||
@Override
|
||||
public PlatformType getPlatformType() {
|
||||
return plugin.getType();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void registerListener(@NonNull LPListener listener) {
|
||||
eventBus.register(listener);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void unregisterListener(@NonNull LPListener listener) {
|
||||
eventBus.unregister(listener);
|
||||
}
|
||||
|
||||
@Override
|
||||
public LPConfiguration getConfiguration() {
|
||||
return new LPConfigurationLink(plugin.getConfiguration());
|
||||
@@ -81,7 +121,7 @@ public class ApiProvider implements LuckPermsApi {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Optional<User> getUserSafe(UUID uuid) {
|
||||
public Optional<User> getUserSafe(@NonNull UUID uuid) {
|
||||
return Optional.ofNullable(getUser(uuid));
|
||||
}
|
||||
|
||||
@@ -96,7 +136,7 @@ public class ApiProvider implements LuckPermsApi {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Optional<User> getUserSafe(String name) {
|
||||
public Optional<User> getUserSafe(@NonNull String name) {
|
||||
return Optional.ofNullable(getUser(name));
|
||||
}
|
||||
|
||||
@@ -110,6 +150,12 @@ public class ApiProvider implements LuckPermsApi {
|
||||
return plugin.getUserManager().isLoaded(uuid);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void cleanupUser(@NonNull User user) {
|
||||
Utils.checkUser(user);
|
||||
plugin.getUserManager().cleanup(((UserLink) user).getMaster());
|
||||
}
|
||||
|
||||
@Override
|
||||
public Group getGroup(@NonNull String name) {
|
||||
final me.lucko.luckperms.groups.Group group = plugin.getGroupManager().get(name);
|
||||
@@ -121,7 +167,7 @@ public class ApiProvider implements LuckPermsApi {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Optional<Group> getGroupSafe(String name) {
|
||||
public Optional<Group> getGroupSafe(@NonNull String name) {
|
||||
return Optional.ofNullable(getGroup(name));
|
||||
}
|
||||
|
||||
@@ -146,7 +192,7 @@ public class ApiProvider implements LuckPermsApi {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Optional<Track> getTrackSafe(String name) {
|
||||
public Optional<Track> getTrackSafe(@NonNull String name) {
|
||||
return Optional.ofNullable(getTrack(name));
|
||||
}
|
||||
|
||||
@@ -159,4 +205,9 @@ public class ApiProvider implements LuckPermsApi {
|
||||
public boolean isTrackLoaded(@NonNull String name) {
|
||||
return plugin.getTrackManager().isLoaded(name);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Node.Builder buildNode(@NonNull String permission) throws IllegalArgumentException {
|
||||
return new me.lucko.luckperms.utils.Node.Builder(checkNode(permission));
|
||||
}
|
||||
}
|
||||
+58
-6
@@ -30,6 +30,7 @@ import me.lucko.luckperms.LuckPermsPlugin;
|
||||
import me.lucko.luckperms.api.*;
|
||||
import me.lucko.luckperms.api.data.Callback;
|
||||
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.CountDownLatch;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
@@ -106,12 +107,17 @@ public class DatastoreLink implements Datastore {
|
||||
|
||||
@Override
|
||||
public void loadOrCreateUser(@NonNull UUID uuid, @NonNull String username, Callback<Boolean> callback) {
|
||||
master.loadOrCreateUser(uuid, checkUsername(username), checkCallback(callback));
|
||||
master.loadUser(uuid, checkUsername(username), checkCallback(callback));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void loadUser(@NonNull UUID uuid, Callback<Boolean> callback) {
|
||||
master.loadUser(uuid, checkCallback(callback));
|
||||
master.loadUser(uuid, "null", checkCallback(callback));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void loadUser(@NonNull UUID uuid, @NonNull String username, Callback<Boolean> callback) {
|
||||
master.loadUser(uuid, checkUsername(username), checkCallback(callback));
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -120,6 +126,16 @@ public class DatastoreLink implements Datastore {
|
||||
master.saveUser(((UserLink) user).getMaster(), checkCallback(callback));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void cleanupUsers(Callback<Boolean> callback) {
|
||||
master.cleanupUsers(checkCallback(callback));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void getUniqueUsers(Callback<Set<UUID>> callback) {
|
||||
master.getUniqueUsers(checkCallback(callback));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void createAndLoadGroup(@NonNull String name, Callback<Boolean> callback) {
|
||||
master.createAndLoadGroup(checkName(name), checkCallback(callback));
|
||||
@@ -204,12 +220,17 @@ public class DatastoreLink implements Datastore {
|
||||
|
||||
@Override
|
||||
public boolean loadOrCreateUser(@NonNull UUID uuid, @NonNull String username) {
|
||||
return master.loadOrCreateUser(uuid, checkUsername(username));
|
||||
return master.loadUser(uuid, checkUsername(username));
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean loadUser(@NonNull UUID uuid) {
|
||||
return master.loadUser(uuid);
|
||||
return master.loadUser(uuid, "null");
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean loadUser(@NonNull UUID uuid, @NonNull String username) {
|
||||
return master.loadUser(uuid, checkUsername(username));
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -218,6 +239,16 @@ public class DatastoreLink implements Datastore {
|
||||
return master.saveUser(((UserLink) user).getMaster());
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean cleanupUsers() {
|
||||
return master.cleanupUsers();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<UUID> getUniqueUsers() {
|
||||
return master.getUniqueUsers();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean createAndLoadGroup(@NonNull String name) {
|
||||
return master.createAndLoadGroup(checkName(name));
|
||||
@@ -307,14 +338,21 @@ public class DatastoreLink implements Datastore {
|
||||
@Override
|
||||
public java.util.concurrent.Future<Boolean> loadOrCreateUser(@NonNull UUID uuid, @NonNull String username) {
|
||||
LPFuture<Boolean> lpf = new LPFuture<>();
|
||||
master.loadOrCreateUser(uuid, checkUsername(username), lpf);
|
||||
master.loadUser(uuid, checkUsername(username), lpf);
|
||||
return lpf;
|
||||
}
|
||||
|
||||
@Override
|
||||
public java.util.concurrent.Future<Boolean> loadUser(@NonNull UUID uuid) {
|
||||
LPFuture<Boolean> lpf = new LPFuture<>();
|
||||
master.loadUser(uuid, lpf);
|
||||
master.loadUser(uuid, "null", lpf);
|
||||
return lpf;
|
||||
}
|
||||
|
||||
@Override
|
||||
public java.util.concurrent.Future<Boolean> loadUser(@NonNull UUID uuid, @NonNull String username) {
|
||||
LPFuture<Boolean> lpf = new LPFuture<>();
|
||||
master.loadUser(uuid, checkUsername(username), lpf);
|
||||
return lpf;
|
||||
}
|
||||
|
||||
@@ -326,6 +364,20 @@ public class DatastoreLink implements Datastore {
|
||||
return lpf;
|
||||
}
|
||||
|
||||
@Override
|
||||
public java.util.concurrent.Future<Boolean> cleanupUsers() {
|
||||
LPFuture<Boolean> lpf = new LPFuture<>();
|
||||
master.cleanupUsers(lpf);
|
||||
return lpf;
|
||||
}
|
||||
|
||||
@Override
|
||||
public java.util.concurrent.Future<Set<UUID>> getUniqueUsers() {
|
||||
LPFuture<Set<UUID>> lpf = new LPFuture<>();
|
||||
master.getUniqueUsers(lpf);
|
||||
return lpf;
|
||||
}
|
||||
|
||||
@Override
|
||||
public java.util.concurrent.Future<Boolean> createAndLoadGroup(@NonNull String name) {
|
||||
LPFuture<Boolean> lpf = new LPFuture<>();
|
||||
|
||||
+70
@@ -24,8 +24,11 @@ package me.lucko.luckperms.api.implementation.internal;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import me.lucko.luckperms.api.LPConfiguration;
|
||||
import me.lucko.luckperms.api.data.DatastoreConfiguration;
|
||||
import me.lucko.luckperms.api.data.MySQLConfiguration;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* Provides a link between {@link LPConfiguration} and {@link me.lucko.luckperms.core.LPConfiguration}
|
||||
*/
|
||||
@@ -58,6 +61,21 @@ public class LPConfigurationLink implements LPConfiguration {
|
||||
return master.getIncludeGlobalPerms();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean getIncludeGlobalWorldPerms() {
|
||||
return master.getIncludeGlobalWorldPerms();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean getApplyGlobalGroups() {
|
||||
return master.getApplyGlobalGroups();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean getApplyGlobalWorldGroups() {
|
||||
return master.getApplyGlobalWorldGroups();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean getOnlineMode() {
|
||||
return master.getOnlineMode();
|
||||
@@ -78,8 +96,49 @@ public class LPConfigurationLink implements LPConfiguration {
|
||||
return master.getApplyShorthand();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean getLogNotify() {
|
||||
return master.getLogNotify();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean getDebugPermissionChecks() {
|
||||
return master.getDebugPermissionChecks();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean getEnableOps() {
|
||||
return master.getEnableOps();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean getCommandsAllowOp() {
|
||||
return master.getCommandsAllowOp();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean getAutoOp() {
|
||||
return master.getAutoOp();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getVaultServer() {
|
||||
return master.getVaultServer();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean getVaultIncludeGlobal() {
|
||||
return master.getVaultIncludeGlobal();
|
||||
}
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
@Override
|
||||
public MySQLConfiguration getDatabaseValues() {
|
||||
return getDatastoreConfig();
|
||||
}
|
||||
|
||||
@Override
|
||||
public DatastoreConfiguration getDatastoreConfig() {
|
||||
return master.getDatabaseValues();
|
||||
}
|
||||
|
||||
@@ -87,4 +146,15 @@ public class LPConfigurationLink implements LPConfiguration {
|
||||
public String getStorageMethod() {
|
||||
return master.getStorageMethod();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean getSplitStorage() {
|
||||
return master.getSplitStorage();
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
public Map<String, String> getSplitStorageOptions() {
|
||||
return master.getSplitStorageOptions();
|
||||
}
|
||||
}
|
||||
+85
-8
@@ -22,25 +22,26 @@
|
||||
|
||||
package me.lucko.luckperms.api.implementation.internal;
|
||||
|
||||
import lombok.AccessLevel;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.NonNull;
|
||||
import me.lucko.luckperms.api.Node;
|
||||
import me.lucko.luckperms.api.PermissionHolder;
|
||||
import me.lucko.luckperms.api.Tristate;
|
||||
import me.lucko.luckperms.exceptions.ObjectAlreadyHasException;
|
||||
import me.lucko.luckperms.exceptions.ObjectLacksException;
|
||||
import me.lucko.luckperms.utils.Contexts;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.*;
|
||||
|
||||
import static me.lucko.luckperms.api.implementation.internal.Utils.*;
|
||||
import static me.lucko.luckperms.core.PermissionHolder.exportToLegacy;
|
||||
|
||||
/**
|
||||
* Provides a link between {@link PermissionHolder} and {@link me.lucko.luckperms.core.PermissionHolder}
|
||||
*/
|
||||
@SuppressWarnings("unused")
|
||||
@AllArgsConstructor(access = AccessLevel.PACKAGE)
|
||||
class PermissionHolderLink implements PermissionHolder {
|
||||
@SuppressWarnings({"unused", "deprecation"})
|
||||
@AllArgsConstructor
|
||||
public class PermissionHolderLink implements PermissionHolder {
|
||||
|
||||
@NonNull
|
||||
private final me.lucko.luckperms.core.PermissionHolder master;
|
||||
@@ -50,9 +51,39 @@ class PermissionHolderLink implements PermissionHolder {
|
||||
return master.getObjectName();
|
||||
}
|
||||
|
||||
@Override
|
||||
public SortedSet<Node> getPermissions() {
|
||||
return Collections.unmodifiableSortedSet(master.getPermissions(false));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<Node> getEnduringPermissions() {
|
||||
return Collections.unmodifiableSet(master.getNodes());
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<Node> getTransientPermissions() {
|
||||
return Collections.unmodifiableSet(master.getTransientNodes());
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<Node> getAllNodes() {
|
||||
return Collections.unmodifiableSet(master.getAllNodes(Collections.emptyList(), Contexts.allowAll()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, Boolean> getNodes() {
|
||||
return Collections.unmodifiableMap(master.getNodes());
|
||||
return exportToLegacy(master.getNodes());
|
||||
}
|
||||
|
||||
@Override
|
||||
public Tristate hasPermission(@NonNull Node node) {
|
||||
return master.hasPermission(node, false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Tristate hasTransientPermission(@NonNull Node node) {
|
||||
return master.hasPermission(node, true);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -85,6 +116,11 @@ class PermissionHolderLink implements PermissionHolder {
|
||||
return master.hasPermission(node, b, checkServer(server), world, temporary);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Tristate inheritsPermission(@NonNull Node node) {
|
||||
return master.inheritsPermission(node);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean inheritsPermission(@NonNull String node, @NonNull boolean b) {
|
||||
return master.inheritsPermission(node, b);
|
||||
@@ -115,6 +151,16 @@ class PermissionHolderLink implements PermissionHolder {
|
||||
return master.inheritsPermission(node, b, checkServer(server), world, temporary);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setPermission(@NonNull Node node) throws ObjectAlreadyHasException {
|
||||
master.setPermission(node);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setTransientPermission(@NonNull Node node) throws ObjectAlreadyHasException {
|
||||
master.setTransientPermission(node);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setPermission(@NonNull String node, @NonNull boolean value) throws ObjectAlreadyHasException {
|
||||
master.setPermission(checkNode(node), value);
|
||||
@@ -145,6 +191,16 @@ class PermissionHolderLink implements PermissionHolder {
|
||||
master.setPermission(checkNode(node), value, checkServer(server), world, checkTime(expireAt));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void unsetPermission(@NonNull Node node) throws ObjectLacksException {
|
||||
master.unsetPermission(node);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void unsetTransientPermission(@NonNull Node node) throws ObjectLacksException {
|
||||
master.unsetTransientPermission(node);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void unsetPermission(@NonNull String node, @NonNull boolean temporary) throws ObjectLacksException {
|
||||
master.unsetPermission(checkNode(node), temporary);
|
||||
@@ -195,13 +251,34 @@ class PermissionHolderLink implements PermissionHolder {
|
||||
return master.getLocalPermissions(server, excludedGroups);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, Boolean> getPermissions(String server, String world, Map<String, String> extraContext, boolean includeGlobal, List<String> possibleNodes, boolean applyGroups) {
|
||||
return master.exportNodes(new Contexts(server, world, extraContext, includeGlobal, includeGlobal, applyGroups, true, true), possibleNodes);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<Map.Entry<String, Boolean>, Long> getTemporaryNodes() {
|
||||
Map<Map.Entry<String, Boolean>, Long> m = new HashMap<>();
|
||||
|
||||
for (Node node : master.getTemporaryNodes()) {
|
||||
m.put(new AbstractMap.SimpleEntry<>(node.getKey(), node.getValue()), node.getExpiryUnixTime());
|
||||
}
|
||||
|
||||
return m;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<Node> getTemporaryPermissionNodes() {
|
||||
return master.getTemporaryNodes();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, Boolean> getPermanentNodes() {
|
||||
return exportToLegacy(master.getPermanentNodes());
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<Node> getPermanentPermissionNodes() {
|
||||
return master.getPermanentNodes();
|
||||
}
|
||||
|
||||
|
||||
@@ -22,7 +22,6 @@
|
||||
|
||||
package me.lucko.luckperms.api.implementation.internal;
|
||||
|
||||
import lombok.AccessLevel;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.Getter;
|
||||
import lombok.NonNull;
|
||||
@@ -43,7 +42,7 @@ import static me.lucko.luckperms.api.implementation.internal.Utils.*;
|
||||
@SuppressWarnings("unused")
|
||||
public class UserLink extends PermissionHolderLink implements User {
|
||||
|
||||
@Getter(AccessLevel.PACKAGE)
|
||||
@Getter
|
||||
private final me.lucko.luckperms.users.User master;
|
||||
|
||||
@Getter
|
||||
@@ -66,7 +65,7 @@ public class UserLink extends PermissionHolderLink implements User {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setPrimaryGroup(String s) throws ObjectAlreadyHasException {
|
||||
public void setPrimaryGroup(@NonNull String s) throws ObjectAlreadyHasException {
|
||||
if (getPrimaryGroup().equalsIgnoreCase(s)) {
|
||||
throw new ObjectAlreadyHasException();
|
||||
}
|
||||
|
||||
@@ -29,27 +29,27 @@ import me.lucko.luckperms.api.User;
|
||||
import me.lucko.luckperms.utils.ArgumentChecker;
|
||||
|
||||
@UtilityClass
|
||||
class Utils {
|
||||
public class Utils {
|
||||
|
||||
static void checkUser(User user) {
|
||||
public static void checkUser(User user) {
|
||||
if (!(user instanceof UserLink)) {
|
||||
throw new IllegalArgumentException("User instance cannot be handled by this implementation.");
|
||||
throw new IllegalStateException("User instance cannot be handled by this implementation.");
|
||||
}
|
||||
}
|
||||
|
||||
static void checkGroup(Group group) {
|
||||
public static void checkGroup(Group group) {
|
||||
if (!(group instanceof GroupLink)) {
|
||||
throw new IllegalArgumentException("Group instance cannot be handled by this implementation.");
|
||||
throw new IllegalStateException("Group instance cannot be handled by this implementation.");
|
||||
}
|
||||
}
|
||||
|
||||
static void checkTrack(Track track) {
|
||||
public static void checkTrack(Track track) {
|
||||
if (!(track instanceof TrackLink)) {
|
||||
throw new IllegalArgumentException("Track instance cannot be handled by this implementation.");
|
||||
throw new IllegalStateException("Track instance cannot be handled by this implementation.");
|
||||
}
|
||||
}
|
||||
|
||||
static String checkUsername(String s) {
|
||||
public static String checkUsername(String s) {
|
||||
if (ArgumentChecker.checkUsername(s)) {
|
||||
throw new IllegalArgumentException("Invalid username entry '" + s + "'. Usernames must be less than 16 chars" +
|
||||
" and only contain 'a-z A-Z 1-9 _'.");
|
||||
@@ -57,7 +57,7 @@ class Utils {
|
||||
return s;
|
||||
}
|
||||
|
||||
static String checkName(String s) {
|
||||
public static String checkName(String s) {
|
||||
if (ArgumentChecker.checkName(s)) {
|
||||
throw new IllegalArgumentException("Invalid name entry '" + s + "'. Names must be less than 37 chars" +
|
||||
" and only contain 'a-z A-Z 1-9'.");
|
||||
@@ -65,21 +65,21 @@ class Utils {
|
||||
return s.toLowerCase();
|
||||
}
|
||||
|
||||
static String checkServer(String s) {
|
||||
public static String checkServer(String s) {
|
||||
if (ArgumentChecker.checkServer(s)) {
|
||||
throw new IllegalArgumentException("Invalid server entry '" + s + "'. Server names can only contain alphanumeric characters.");
|
||||
}
|
||||
return s;
|
||||
}
|
||||
|
||||
static String checkNode(String s) {
|
||||
public static String checkNode(String s) {
|
||||
if (ArgumentChecker.checkNode(s)) {
|
||||
throw new IllegalArgumentException("Invalid node entry '" + s + "'. Nodes cannot contain '/' or '$' characters.");
|
||||
}
|
||||
return s;
|
||||
}
|
||||
|
||||
static long checkTime(long l) {
|
||||
public static long checkTime(long l) {
|
||||
if (ArgumentChecker.checkTime(l)) {
|
||||
throw new IllegalArgumentException("Unix time '" + l + "' is invalid, as it has already passed.");
|
||||
}
|
||||
|
||||
@@ -32,9 +32,8 @@ import me.lucko.luckperms.commands.group.DeleteGroup;
|
||||
import me.lucko.luckperms.commands.group.GroupMainCommand;
|
||||
import me.lucko.luckperms.commands.group.ListGroups;
|
||||
import me.lucko.luckperms.commands.log.LogMainCommand;
|
||||
import me.lucko.luckperms.commands.misc.DebugCommand;
|
||||
import me.lucko.luckperms.commands.misc.InfoCommand;
|
||||
import me.lucko.luckperms.commands.misc.SyncCommand;
|
||||
import me.lucko.luckperms.commands.migration.MigrationMainCommand;
|
||||
import me.lucko.luckperms.commands.misc.*;
|
||||
import me.lucko.luckperms.commands.track.CreateTrack;
|
||||
import me.lucko.luckperms.commands.track.DeleteTrack;
|
||||
import me.lucko.luckperms.commands.track.ListTracks;
|
||||
@@ -61,6 +60,10 @@ public class CommandManager {
|
||||
.add(new SyncCommand())
|
||||
.add(new InfoCommand())
|
||||
.add(new DebugCommand())
|
||||
.add(new ImportCommand())
|
||||
.add(new ExportCommand())
|
||||
.add(new QueueCommand())
|
||||
.add(new MigrationMainCommand())
|
||||
.add(new CreateGroup())
|
||||
.add(new DeleteGroup())
|
||||
.add(new ListGroups())
|
||||
@@ -144,18 +147,28 @@ public class CommandManager {
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
public List<String> onTabComplete(Sender sender, List<String> args) {
|
||||
final List<MainCommand> mains = mainCommands.stream().filter(m -> m.isAuthorized(sender)).collect(Collectors.toList());
|
||||
final List<MainCommand> mains = mainCommands.stream()
|
||||
.filter(m -> m.isAuthorized(sender))
|
||||
.collect(Collectors.toList());
|
||||
|
||||
if (args.size() <= 1) {
|
||||
if (args.isEmpty() || args.get(0).equalsIgnoreCase("")) {
|
||||
return mains.stream().map(MainCommand::getName).map(String::toLowerCase).collect(Collectors.toList());
|
||||
return mains.stream()
|
||||
.map(m -> m.getName().toLowerCase())
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
return mains.stream().map(MainCommand::getName).map(String::toLowerCase)
|
||||
.filter(s -> s.startsWith(args.get(0).toLowerCase())).collect(Collectors.toList());
|
||||
return mains.stream()
|
||||
.map(m -> m.getName().toLowerCase())
|
||||
.filter(s -> s.startsWith(args.get(0).toLowerCase()))
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
Optional<MainCommand> o = mains.stream().filter(m -> m.getName().equalsIgnoreCase(args.get(0))).limit(1).findAny();
|
||||
Optional<MainCommand> o = mains.stream()
|
||||
.filter(m -> m.getName().equalsIgnoreCase(args.get(0)))
|
||||
.limit(1)
|
||||
.findAny();
|
||||
|
||||
if (!o.isPresent()) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
@@ -0,0 +1,72 @@
|
||||
/*
|
||||
* Copyright (c) 2016 Lucko (Luck) <luck@lucko.me>
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
package me.lucko.luckperms.commands;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Executes commands consecutively
|
||||
*/
|
||||
@RequiredArgsConstructor
|
||||
public class ConsecutiveExecutor implements Runnable {
|
||||
private final CommandManager manager;
|
||||
|
||||
private final List<QueuedCommand> commands = new ArrayList<>();
|
||||
|
||||
public void queueCommand(QueuedCommand command) {
|
||||
synchronized (commands) {
|
||||
commands.add(command);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
final List<QueuedCommand> toExecute = new ArrayList<>();
|
||||
synchronized (commands) {
|
||||
toExecute.addAll(commands);
|
||||
commands.clear();
|
||||
}
|
||||
|
||||
if (toExecute.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
|
||||
for (QueuedCommand command : toExecute) {
|
||||
manager.onCommand(command.getSender(), "perms", command.getArgs());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Getter
|
||||
@AllArgsConstructor
|
||||
public static class QueuedCommand {
|
||||
private final Sender sender;
|
||||
private final List<String> args;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -76,7 +76,10 @@ public abstract class MainCommand<T> {
|
||||
return CommandResult.INVALID_ARGS;
|
||||
}
|
||||
|
||||
Optional<SubCommand<T>> o = subCommands.stream().filter(s -> s.getName().equalsIgnoreCase(args.get(requiredArgsLength - 1))).limit(1).findAny();
|
||||
Optional<SubCommand<T>> o = getSubCommands().stream()
|
||||
.filter(s -> s.getName().equalsIgnoreCase(args.get(requiredArgsLength - 1)))
|
||||
.limit(1)
|
||||
.findAny();
|
||||
|
||||
if (!o.isPresent()) {
|
||||
Message.COMMAND_NOT_RECOGNISED.send(sender);
|
||||
@@ -121,7 +124,7 @@ public abstract class MainCommand<T> {
|
||||
protected abstract void cleanup(T t, LuckPermsPlugin plugin);
|
||||
|
||||
/**
|
||||
* Get a list of objects for tab completion
|
||||
* Get a list of {@link T} objects for tab completion
|
||||
* @param plugin a link to the main plugin instance
|
||||
* @return a list of strings
|
||||
*/
|
||||
@@ -138,7 +141,10 @@ public abstract class MainCommand<T> {
|
||||
return;
|
||||
}
|
||||
|
||||
List<SubCommand> subs = getSubCommands().stream().filter(s -> s.isAuthorized(sender)).collect(Collectors.toList());
|
||||
List<SubCommand> subs = getSubCommands().stream()
|
||||
.filter(s -> s.isAuthorized(sender))
|
||||
.collect(Collectors.toList());
|
||||
|
||||
if (subs.size() > 0) {
|
||||
Util.sendPluginMessage(sender, "&e" + getName() + " Sub Commands:");
|
||||
|
||||
@@ -168,20 +174,33 @@ public abstract class MainCommand<T> {
|
||||
return objects;
|
||||
}
|
||||
|
||||
return objects.stream().filter(s -> s.toLowerCase().startsWith(args.get(0).toLowerCase())).collect(Collectors.toList());
|
||||
return objects.stream()
|
||||
.filter(s -> s.toLowerCase().startsWith(args.get(0).toLowerCase()))
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
final List<SubCommand<T>> subs = getSubCommands().stream().filter(s -> s.isAuthorized(sender)).collect(Collectors.toList());
|
||||
final List<SubCommand<T>> subs = getSubCommands().stream()
|
||||
.filter(s -> s.isAuthorized(sender))
|
||||
.collect(Collectors.toList());
|
||||
|
||||
if (args.size() == 2) {
|
||||
if (args.get(1).equalsIgnoreCase("")) {
|
||||
return subs.stream().map(SubCommand::getName).map(String::toLowerCase).collect(Collectors.toList());
|
||||
return subs.stream()
|
||||
.map(m -> m.getName().toLowerCase())
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
return subs.stream().map(SubCommand::getName).map(String::toLowerCase)
|
||||
.filter(s -> s.toLowerCase().startsWith(args.get(1).toLowerCase())).collect(Collectors.toList());
|
||||
return subs.stream()
|
||||
.map(m -> m.getName().toLowerCase())
|
||||
.filter(s -> s.toLowerCase().startsWith(args.get(1).toLowerCase()))
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
Optional<SubCommand<T>> o = subs.stream().filter(s -> s.getName().equalsIgnoreCase(args.get(1))).limit(1).findAny();
|
||||
Optional<SubCommand<T>> o = subs.stream()
|
||||
.filter(s -> s.getName().equalsIgnoreCase(args.get(1)))
|
||||
.limit(1)
|
||||
.findAny();
|
||||
|
||||
if (!o.isPresent()) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
@@ -22,11 +22,14 @@
|
||||
|
||||
package me.lucko.luckperms.commands;
|
||||
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import lombok.Getter;
|
||||
import me.lucko.luckperms.constants.Constants;
|
||||
import me.lucko.luckperms.constants.Permission;
|
||||
|
||||
import java.lang.ref.WeakReference;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
@@ -34,9 +37,8 @@ import java.util.stream.Collectors;
|
||||
* @param <T> the command sender type
|
||||
*/
|
||||
public abstract class SenderFactory<T> implements Runnable {
|
||||
// Ensures messages are sent in order, etc.
|
||||
private final List<Runnable> tasks = new ArrayList<>();
|
||||
|
||||
private final Map<T, List<String>> messages = new HashMap<>();
|
||||
private final AtomicBoolean shouldSend = new AtomicBoolean(false);
|
||||
private final SenderFactory<T> factory = this;
|
||||
|
||||
protected abstract String getName(T t);
|
||||
@@ -45,46 +47,78 @@ public abstract class SenderFactory<T> implements Runnable {
|
||||
protected abstract boolean hasPermission(T t, String node);
|
||||
|
||||
public final Sender wrap(T t) {
|
||||
return new Sender() {
|
||||
final WeakReference<T> tRef = new WeakReference<>(t);
|
||||
return new SenderImp(t, null);
|
||||
}
|
||||
|
||||
// Cache these permissions, so they can be accessed async
|
||||
final Map<Permission, Boolean> perms = Arrays.stream(Permission.values())
|
||||
.map(p -> new AbstractMap.SimpleEntry<>(p, factory.hasPermission(t, p.getNode())))
|
||||
.collect(Collectors.toMap(AbstractMap.SimpleEntry::getKey, AbstractMap.SimpleEntry::getValue));
|
||||
|
||||
@Getter
|
||||
final String name = factory.getName(t);
|
||||
|
||||
@Getter
|
||||
final UUID uuid = factory.getUuid(t);
|
||||
|
||||
@Override
|
||||
public void sendMessage(String s) {
|
||||
final T t = tRef.get();
|
||||
if (t != null) {
|
||||
synchronized (tasks) {
|
||||
tasks.add(() -> factory.sendMessage(t, s));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasPermission(Permission permission) {
|
||||
synchronized (perms) {
|
||||
return perms.get(permission);
|
||||
}
|
||||
}
|
||||
};
|
||||
public final Sender wrap(T t, Set<Permission> toCheck) {
|
||||
return new SenderImp(t, toCheck);
|
||||
}
|
||||
|
||||
@Override
|
||||
public final void run() {
|
||||
synchronized (tasks) {
|
||||
if (!tasks.isEmpty()) {
|
||||
tasks.forEach(Runnable::run);
|
||||
tasks.clear();
|
||||
if (!shouldSend.getAndSet(false)) {
|
||||
return;
|
||||
}
|
||||
|
||||
synchronized (messages) {
|
||||
for (Map.Entry<T, List<String>> e : messages.entrySet()) {
|
||||
for (String s : e.getValue()) {
|
||||
factory.sendMessage(e.getKey(), s);
|
||||
}
|
||||
}
|
||||
|
||||
messages.clear();
|
||||
}
|
||||
}
|
||||
|
||||
private class SenderImp implements Sender {
|
||||
private final WeakReference<T> tRef;
|
||||
|
||||
// Cache these permissions, so they can be accessed async
|
||||
private Map<Permission, Boolean> perms;
|
||||
|
||||
@Getter
|
||||
private final String name;
|
||||
|
||||
@Getter
|
||||
private final UUID uuid;
|
||||
|
||||
private final boolean console;
|
||||
|
||||
private SenderImp(T t, Set<Permission> toCheck) {
|
||||
this.tRef = new WeakReference<>(t);
|
||||
this.name = factory.getName(t);
|
||||
this.uuid = factory.getUuid(t);
|
||||
this.console = this.uuid.equals(Constants.getConsoleUUID()) || this.uuid.equals(Constants.getImporterUUID());
|
||||
|
||||
if (!this.console) {
|
||||
if (toCheck == null || toCheck.isEmpty()) {
|
||||
this.perms = ImmutableMap.copyOf(Arrays.stream(Permission.values())
|
||||
.collect(Collectors.toMap(p -> p, p -> factory.hasPermission(t, p.getNode()))));
|
||||
} else {
|
||||
this.perms = ImmutableMap.copyOf(toCheck.stream().collect(Collectors.toMap(p -> p, p -> factory.hasPermission(t, p.getNode()))));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sendMessage(String s) {
|
||||
final T t = tRef.get();
|
||||
if (t != null) {
|
||||
synchronized (messages) {
|
||||
if (!messages.containsKey(t)) {
|
||||
messages.put(t, new ArrayList<>());
|
||||
}
|
||||
|
||||
messages.get(t).add(s);
|
||||
}
|
||||
shouldSend.set(true);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasPermission(Permission permission) {
|
||||
return console || perms.get(permission);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -110,10 +110,11 @@ public abstract class SubCommand<T> {
|
||||
return permission.isAuthorized(sender);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
----------------------------------------------------------------------------------
|
||||
Utility methods used by #onTabComplete and #execute implementations in sub classes
|
||||
----------------------------------------------------------------------------------
|
||||
* ----------------------------------------------------------------------------------
|
||||
* Utility methods used by #onTabComplete and #execute implementations in sub classes
|
||||
* ----------------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
protected static List<String> getGroupTabComplete(List<String> args, LuckPermsPlugin plugin) {
|
||||
@@ -145,38 +146,32 @@ public abstract class SubCommand<T> {
|
||||
}
|
||||
|
||||
protected static void save(User user, Sender sender, LuckPermsPlugin plugin) {
|
||||
user.refreshPermissions();
|
||||
if (plugin.getDatastore().saveUser(user)) {
|
||||
Message.USER_SAVE_SUCCESS.send(sender);
|
||||
} else {
|
||||
Message.USER_SAVE_ERROR.send(sender);
|
||||
}
|
||||
|
||||
plugin.getDatastore().saveUser(user, success -> {
|
||||
if (success) {
|
||||
Message.USER_SAVE_SUCCESS.send(sender);
|
||||
} else {
|
||||
Message.USER_SAVE_ERROR.send(sender);
|
||||
}
|
||||
});
|
||||
user.refreshPermissions();
|
||||
}
|
||||
|
||||
protected static void save(Group group, Sender sender, LuckPermsPlugin plugin) {
|
||||
plugin.getDatastore().saveGroup(group, success -> {
|
||||
if (success) {
|
||||
Message.GROUP_SAVE_SUCCESS.send(sender);
|
||||
} else {
|
||||
Message.GROUP_SAVE_ERROR.send(sender);
|
||||
}
|
||||
if (plugin.getDatastore().saveGroup(group)) {
|
||||
Message.GROUP_SAVE_SUCCESS.send(sender);
|
||||
} else {
|
||||
Message.GROUP_SAVE_ERROR.send(sender);
|
||||
}
|
||||
|
||||
plugin.runUpdateTask();
|
||||
});
|
||||
plugin.runUpdateTask();
|
||||
}
|
||||
|
||||
protected static void save(Track track, Sender sender, LuckPermsPlugin plugin) {
|
||||
plugin.getDatastore().saveTrack(track, success -> {
|
||||
if (success) {
|
||||
Message.TRACK_SAVE_SUCCESS.send(sender);
|
||||
} else {
|
||||
Message.TRACK_SAVE_ERROR.send(sender);
|
||||
}
|
||||
if (plugin.getDatastore().saveTrack(track)) {
|
||||
Message.TRACK_SAVE_SUCCESS.send(sender);
|
||||
} else {
|
||||
Message.TRACK_SAVE_ERROR.send(sender);
|
||||
}
|
||||
|
||||
plugin.runUpdateTask();
|
||||
});
|
||||
plugin.runUpdateTask();
|
||||
}
|
||||
}
|
||||
@@ -23,13 +23,12 @@
|
||||
package me.lucko.luckperms.commands;
|
||||
|
||||
import lombok.experimental.UtilityClass;
|
||||
import me.lucko.luckperms.api.Node;
|
||||
import me.lucko.luckperms.constants.Message;
|
||||
import me.lucko.luckperms.constants.Patterns;
|
||||
import me.lucko.luckperms.utils.DateUtil;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
import java.util.*;
|
||||
|
||||
@UtilityClass
|
||||
public class Util {
|
||||
@@ -38,6 +37,22 @@ public class Util {
|
||||
sender.sendMessage(color(Message.PREFIX + message));
|
||||
}
|
||||
|
||||
public static List<String> stripQuotes(List<String> input) {
|
||||
input = new ArrayList<>(input);
|
||||
ListIterator<String> iterator = input.listIterator();
|
||||
while (iterator.hasNext()) {
|
||||
String value = iterator.next();
|
||||
if (!(value.length() >= 3)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (value.charAt(0) == '"' && value.charAt(value.length() - 1) == '"') {
|
||||
iterator.set(value.substring(1, value.length() - 1));
|
||||
}
|
||||
}
|
||||
return input;
|
||||
}
|
||||
|
||||
public static String color(String s) {
|
||||
return translateAlternateColorCodes('&', s);
|
||||
}
|
||||
@@ -114,35 +129,53 @@ public class Util {
|
||||
return sb.delete(sb.length() - 6, sb.length()).toString();
|
||||
}
|
||||
|
||||
public static String permNodesToString(Map<String, Boolean> nodes) {
|
||||
if (nodes.isEmpty()) return "&6None";
|
||||
|
||||
public static String permNodesToString(SortedSet<Node> nodes) {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
|
||||
for (Map.Entry<String, Boolean> e : nodes.entrySet()) {
|
||||
if (e.getValue()) {
|
||||
sb.append("&a").append(e.getKey()).append("&7, ");
|
||||
} else {
|
||||
sb.append("&c").append(e.getKey()).append("&7, ");
|
||||
for (Node node : nodes) {
|
||||
if (node.isTemporary()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
sb.append("&6-> ").append(node.getValue() ? "&a" : "&c");
|
||||
sb.append(node.getPermission());
|
||||
if (node.isServerSpecific()) {
|
||||
sb.append(" &7(&f").append(node.getServer().get()).append("&7)");
|
||||
}
|
||||
if (node.isWorldSpecific()) {
|
||||
sb.append(" &7(&f").append(node.getWorld().get()).append("&7)");
|
||||
}
|
||||
sb.append("\n");
|
||||
}
|
||||
|
||||
return sb.delete(sb.length() - 2, sb.length()).toString();
|
||||
if (sb.length() == 0) {
|
||||
return "&6None";
|
||||
}
|
||||
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
public static String tempNodesToString(Map<Map.Entry<String, Boolean>, Long> nodes) {
|
||||
if (nodes.isEmpty()) return "&6None";
|
||||
|
||||
public static String tempNodesToString(SortedSet<Node> nodes) {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
|
||||
for (Map.Entry<Map.Entry<String, Boolean>, Long> e : nodes.entrySet()) {
|
||||
if (e.getKey().getValue()) {
|
||||
sb.append("&a").append(e.getKey().getKey()).append("&6 - expires in ")
|
||||
.append(DateUtil.formatDateDiff(e.getValue())).append("\n");
|
||||
} else {
|
||||
sb.append("&c").append(e.getKey().getKey()).append("&6 - expires in ")
|
||||
.append(DateUtil.formatDateDiff(e.getValue())).append("\n");
|
||||
for (Node node : nodes) {
|
||||
if (!node.isTemporary()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
sb.append("&6-> ").append(node.getValue() ? "&a" : "&c");
|
||||
sb.append(node.getPermission());
|
||||
if (node.isServerSpecific()) {
|
||||
sb.append(" &7(&f").append(node.getServer().get()).append("&7)");
|
||||
}
|
||||
if (node.isWorldSpecific()) {
|
||||
sb.append(" &7(&f").append(node.getWorld().get()).append("&7)");
|
||||
}
|
||||
|
||||
sb.append("&6 - expires in ").append(DateUtil.formatDateDiff(node.getExpiryUnixTime())).append("\n");
|
||||
}
|
||||
|
||||
if (sb.length() == 0) {
|
||||
return "&6None";
|
||||
}
|
||||
|
||||
return sb.toString();
|
||||
@@ -161,4 +194,25 @@ public class Util {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static synchronized MetaComparator getMetaComparator() {
|
||||
if (metaComparator == null) {
|
||||
metaComparator = new MetaComparator();
|
||||
}
|
||||
return metaComparator;
|
||||
}
|
||||
|
||||
|
||||
private static MetaComparator metaComparator = null;
|
||||
public class MetaComparator implements Comparator<Map.Entry<Integer, String>> {
|
||||
|
||||
@Override
|
||||
public int compare(Map.Entry<Integer, String> o1, Map.Entry<Integer, String> o2) {
|
||||
int result = Integer.compare(o1.getKey(), o2.getKey());
|
||||
if (result == 0) {
|
||||
result = o1.getValue().compareTo(o2.getValue());
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -28,7 +28,7 @@ import me.lucko.luckperms.commands.Sender;
|
||||
import me.lucko.luckperms.commands.SingleMainCommand;
|
||||
import me.lucko.luckperms.constants.Message;
|
||||
import me.lucko.luckperms.constants.Permission;
|
||||
import me.lucko.luckperms.data.LogEntryBuilder;
|
||||
import me.lucko.luckperms.data.LogEntry;
|
||||
import me.lucko.luckperms.utils.ArgumentChecker;
|
||||
|
||||
import java.util.List;
|
||||
@@ -62,7 +62,7 @@ public class CreateGroup extends SingleMainCommand {
|
||||
}
|
||||
|
||||
Message.CREATE_SUCCESS.send(sender, groupName);
|
||||
LogEntryBuilder.get().actor(sender).actedName(groupName).type('G').action("create").submit(plugin);
|
||||
LogEntry.build().actor(sender).actedName(groupName).type('G').action("create").build().submit(plugin, sender);
|
||||
plugin.runUpdateTask();
|
||||
return CommandResult.SUCCESS;
|
||||
}
|
||||
|
||||
@@ -28,9 +28,8 @@ import me.lucko.luckperms.commands.Sender;
|
||||
import me.lucko.luckperms.commands.SingleMainCommand;
|
||||
import me.lucko.luckperms.constants.Message;
|
||||
import me.lucko.luckperms.constants.Permission;
|
||||
import me.lucko.luckperms.data.LogEntryBuilder;
|
||||
import me.lucko.luckperms.data.LogEntry;
|
||||
import me.lucko.luckperms.groups.Group;
|
||||
import me.lucko.luckperms.utils.ArgumentChecker;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
@@ -56,11 +55,6 @@ public class DeleteGroup extends SingleMainCommand {
|
||||
return CommandResult.INVALID_ARGS;
|
||||
}
|
||||
|
||||
if (ArgumentChecker.checkName(groupName)) {
|
||||
Message.GROUP_INVALID_ENTRY.send(sender);
|
||||
return CommandResult.INVALID_ARGS;
|
||||
}
|
||||
|
||||
if (!plugin.getDatastore().loadGroup(groupName)) {
|
||||
Message.GROUP_DOES_NOT_EXIST.send(sender);
|
||||
return CommandResult.INVALID_ARGS;
|
||||
@@ -78,7 +72,7 @@ public class DeleteGroup extends SingleMainCommand {
|
||||
}
|
||||
|
||||
Message.DELETE_SUCCESS.send(sender, groupName);
|
||||
LogEntryBuilder.get().actor(sender).actedName(groupName).type('G').action("delete").submit(plugin);
|
||||
LogEntry.build().actor(sender).actedName(groupName).type('G').action("delete").build().submit(plugin, sender);
|
||||
plugin.runUpdateTask();
|
||||
return CommandResult.SUCCESS;
|
||||
}
|
||||
@@ -92,7 +86,8 @@ public class DeleteGroup extends SingleMainCommand {
|
||||
return groups;
|
||||
}
|
||||
|
||||
return groups.stream().filter(s -> s.toLowerCase().startsWith(args.get(0).toLowerCase())).collect(Collectors.toList());
|
||||
return groups.stream().filter(s -> s.toLowerCase().startsWith(args.get(0).toLowerCase()))
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
return Collections.emptyList();
|
||||
|
||||
@@ -30,7 +30,6 @@ import me.lucko.luckperms.commands.SubCommand;
|
||||
import me.lucko.luckperms.commands.group.subcommands.*;
|
||||
import me.lucko.luckperms.constants.Message;
|
||||
import me.lucko.luckperms.groups.Group;
|
||||
import me.lucko.luckperms.utils.ArgumentChecker;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
@@ -51,18 +50,23 @@ public class GroupMainCommand extends MainCommand<Group> {
|
||||
.add(new GroupSetTempInherit())
|
||||
.add(new GroupUnsetTempInherit())
|
||||
.add(new GroupShowTracks())
|
||||
.add(new GroupChatMeta())
|
||||
.add(new GroupAddPrefix())
|
||||
.add(new GroupAddSuffix())
|
||||
.add(new GroupRemovePrefix())
|
||||
.add(new GroupRemoveSuffix())
|
||||
.add(new GroupAddTempPrefix())
|
||||
.add(new GroupAddTempSuffix())
|
||||
.add(new GroupRemoveTempPrefix())
|
||||
.add(new GroupRemoveTempSuffix())
|
||||
.add(new GroupClear())
|
||||
.add(new GroupRename())
|
||||
.build()
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Group getTarget(String target, LuckPermsPlugin plugin, Sender sender) {
|
||||
if (ArgumentChecker.checkName(target)) {
|
||||
Message.GROUP_INVALID_ENTRY.send(sender);
|
||||
return null;
|
||||
}
|
||||
|
||||
if (!plugin.getDatastore().loadGroup(target)) {
|
||||
Message.GROUP_NOT_FOUND.send(sender);
|
||||
return null;
|
||||
|
||||
+96
@@ -0,0 +1,96 @@
|
||||
/*
|
||||
* Copyright (c) 2016 Lucko (Luck) <luck@lucko.me>
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
package me.lucko.luckperms.commands.group.subcommands;
|
||||
|
||||
import me.lucko.luckperms.LuckPermsPlugin;
|
||||
import me.lucko.luckperms.commands.CommandResult;
|
||||
import me.lucko.luckperms.commands.Predicate;
|
||||
import me.lucko.luckperms.commands.Sender;
|
||||
import me.lucko.luckperms.commands.SubCommand;
|
||||
import me.lucko.luckperms.constants.Message;
|
||||
import me.lucko.luckperms.constants.Permission;
|
||||
import me.lucko.luckperms.data.LogEntry;
|
||||
import me.lucko.luckperms.exceptions.ObjectAlreadyHasException;
|
||||
import me.lucko.luckperms.groups.Group;
|
||||
import me.lucko.luckperms.utils.ArgumentChecker;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class GroupAddPrefix extends SubCommand<Group> {
|
||||
public GroupAddPrefix() {
|
||||
super("addprefix", "Adds a prefix to the group", "/%s group <group> addprefix <priority> <prefix> [server] [world]",
|
||||
Permission.GROUP_ADDPREFIX, Predicate.notInRange(2, 4));
|
||||
}
|
||||
|
||||
@Override
|
||||
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, Group group, List<String> args, String label) {
|
||||
final String prefix = args.get(1).replace("{SPACE}", " ");
|
||||
int priority;
|
||||
try {
|
||||
priority = Integer.parseInt(args.get(0));
|
||||
} catch (NumberFormatException e) {
|
||||
Message.META_INVALID_PRIORITY.send(sender, args.get(0));
|
||||
return CommandResult.INVALID_ARGS;
|
||||
}
|
||||
|
||||
final String node = "prefix." + priority + "." + ArgumentChecker.escapeCharacters(prefix);
|
||||
|
||||
try {
|
||||
if (args.size() >= 3) {
|
||||
final String server = args.get(2).toLowerCase();
|
||||
if (ArgumentChecker.checkServer(server)) {
|
||||
Message.SERVER_INVALID_ENTRY.send(sender);
|
||||
return CommandResult.INVALID_ARGS;
|
||||
}
|
||||
|
||||
if (args.size() == 3) {
|
||||
group.setPermission(node, true, server);
|
||||
Message.ADDPREFIX_SERVER_SUCCESS.send(sender, group.getName(), prefix, priority, server);
|
||||
LogEntry.build().actor(sender).acted(group)
|
||||
.action("addprefix " + priority + " " + args.get(1) + " " + server)
|
||||
.build().submit(plugin, sender);
|
||||
} else {
|
||||
final String world = args.get(3).toLowerCase();
|
||||
group.setPermission(node, true, server, world);
|
||||
Message.ADDPREFIX_SERVER_WORLD_SUCCESS.send(sender, group.getName(), prefix, priority, server, world);
|
||||
LogEntry.build().actor(sender).acted(group)
|
||||
.action("addprefix " + priority + " " + args.get(1) + " " + server + " " + world)
|
||||
.build().submit(plugin, sender);
|
||||
}
|
||||
|
||||
} else {
|
||||
group.setPermission(node, true);
|
||||
Message.ADDPREFIX_SUCCESS.send(sender, group.getName(), prefix, priority);
|
||||
LogEntry.build().actor(sender).acted(group)
|
||||
.action("addprefix " + priority + " " + args.get(1))
|
||||
.build().submit(plugin, sender);
|
||||
}
|
||||
|
||||
save(group, sender, plugin);
|
||||
return CommandResult.SUCCESS;
|
||||
} catch (ObjectAlreadyHasException e) {
|
||||
Message.ALREADY_HAS_PREFIX.send(sender, group.getName());
|
||||
return CommandResult.STATE_ERROR;
|
||||
}
|
||||
}
|
||||
}
|
||||
+96
@@ -0,0 +1,96 @@
|
||||
/*
|
||||
* Copyright (c) 2016 Lucko (Luck) <luck@lucko.me>
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
package me.lucko.luckperms.commands.group.subcommands;
|
||||
|
||||
import me.lucko.luckperms.LuckPermsPlugin;
|
||||
import me.lucko.luckperms.commands.CommandResult;
|
||||
import me.lucko.luckperms.commands.Predicate;
|
||||
import me.lucko.luckperms.commands.Sender;
|
||||
import me.lucko.luckperms.commands.SubCommand;
|
||||
import me.lucko.luckperms.constants.Message;
|
||||
import me.lucko.luckperms.constants.Permission;
|
||||
import me.lucko.luckperms.data.LogEntry;
|
||||
import me.lucko.luckperms.exceptions.ObjectAlreadyHasException;
|
||||
import me.lucko.luckperms.groups.Group;
|
||||
import me.lucko.luckperms.utils.ArgumentChecker;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class GroupAddSuffix extends SubCommand<Group> {
|
||||
public GroupAddSuffix() {
|
||||
super("addsuffix", "Adds a suffix to the group", "/%s group <group> addsuffix <priority> <suffix> [server] [world]",
|
||||
Permission.GROUP_ADDSUFFIX, Predicate.notInRange(2, 4));
|
||||
}
|
||||
|
||||
@Override
|
||||
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, Group group, List<String> args, String label) {
|
||||
final String suffix = args.get(1).replace("{SPACE}", " ");
|
||||
int priority;
|
||||
try {
|
||||
priority = Integer.parseInt(args.get(0));
|
||||
} catch (NumberFormatException e) {
|
||||
Message.META_INVALID_PRIORITY.send(sender, args.get(0));
|
||||
return CommandResult.INVALID_ARGS;
|
||||
}
|
||||
|
||||
final String node = "suffix." + priority + "." + ArgumentChecker.escapeCharacters(suffix);
|
||||
|
||||
try {
|
||||
if (args.size() >= 3) {
|
||||
final String server = args.get(2).toLowerCase();
|
||||
if (ArgumentChecker.checkServer(server)) {
|
||||
Message.SERVER_INVALID_ENTRY.send(sender);
|
||||
return CommandResult.INVALID_ARGS;
|
||||
}
|
||||
|
||||
if (args.size() == 3) {
|
||||
group.setPermission(node, true, server);
|
||||
Message.ADDSUFFIX_SERVER_SUCCESS.send(sender, group.getName(), suffix, priority, server);
|
||||
LogEntry.build().actor(sender).acted(group)
|
||||
.action("addsuffix " + priority + " " + args.get(1) + " " + server)
|
||||
.build().submit(plugin, sender);
|
||||
} else {
|
||||
final String world = args.get(3).toLowerCase();
|
||||
group.setPermission(node, true, server, world);
|
||||
Message.ADDSUFFIX_SERVER_WORLD_SUCCESS.send(sender, group.getName(), suffix, priority, server, world);
|
||||
LogEntry.build().actor(sender).acted(group)
|
||||
.action("addsuffix " + priority + " " + args.get(1) + " " + server + " " + world)
|
||||
.build().submit(plugin, sender);
|
||||
}
|
||||
|
||||
} else {
|
||||
group.setPermission(node, true);
|
||||
Message.ADDSUFFIX_SUCCESS.send(sender, group.getName(), suffix, priority);
|
||||
LogEntry.build().actor(sender).acted(group)
|
||||
.action("addsuffix " + priority + " " + args.get(1))
|
||||
.build().submit(plugin, sender);
|
||||
}
|
||||
|
||||
save(group, sender, plugin);
|
||||
return CommandResult.SUCCESS;
|
||||
} catch (ObjectAlreadyHasException e) {
|
||||
Message.ALREADY_HAS_SUFFIX.send(sender, group.getName());
|
||||
return CommandResult.STATE_ERROR;
|
||||
}
|
||||
}
|
||||
}
|
||||
+114
@@ -0,0 +1,114 @@
|
||||
/*
|
||||
* Copyright (c) 2016 Lucko (Luck) <luck@lucko.me>
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
package me.lucko.luckperms.commands.group.subcommands;
|
||||
|
||||
import me.lucko.luckperms.LuckPermsPlugin;
|
||||
import me.lucko.luckperms.commands.CommandResult;
|
||||
import me.lucko.luckperms.commands.Predicate;
|
||||
import me.lucko.luckperms.commands.Sender;
|
||||
import me.lucko.luckperms.commands.SubCommand;
|
||||
import me.lucko.luckperms.constants.Message;
|
||||
import me.lucko.luckperms.constants.Permission;
|
||||
import me.lucko.luckperms.data.LogEntry;
|
||||
import me.lucko.luckperms.exceptions.ObjectAlreadyHasException;
|
||||
import me.lucko.luckperms.groups.Group;
|
||||
import me.lucko.luckperms.utils.ArgumentChecker;
|
||||
import me.lucko.luckperms.utils.DateUtil;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class GroupAddTempPrefix extends SubCommand<Group> {
|
||||
public GroupAddTempPrefix() {
|
||||
super("addtempprefix", "Adds a prefix to the group temporarily", "/%s group <group> addtempprefix <priority> <prefix> <duration> [server] [world]",
|
||||
Permission.GROUP_ADD_TEMP_PREFIX, Predicate.notInRange(3, 5));
|
||||
}
|
||||
|
||||
@Override
|
||||
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, Group group, List<String> args, String label) {
|
||||
final String prefix = args.get(1).replace("{SPACE}", " ");
|
||||
int priority;
|
||||
try {
|
||||
priority = Integer.parseInt(args.get(0));
|
||||
} catch (NumberFormatException e) {
|
||||
Message.META_INVALID_PRIORITY.send(sender, args.get(0));
|
||||
return CommandResult.INVALID_ARGS;
|
||||
}
|
||||
|
||||
long duration;
|
||||
try {
|
||||
duration = Long.parseLong(args.get(2));
|
||||
} catch (NumberFormatException e) {
|
||||
try {
|
||||
duration = DateUtil.parseDateDiff(args.get(2), true);
|
||||
} catch (DateUtil.IllegalDateException e1) {
|
||||
Message.ILLEGAL_DATE_ERROR.send(sender, args.get(2));
|
||||
return CommandResult.INVALID_ARGS;
|
||||
}
|
||||
}
|
||||
|
||||
if (DateUtil.shouldExpire(duration)) {
|
||||
Message.PAST_DATE_ERROR.send(sender);
|
||||
return CommandResult.INVALID_ARGS;
|
||||
}
|
||||
|
||||
final String node = "prefix." + priority + "." + ArgumentChecker.escapeCharacters(prefix);
|
||||
|
||||
try {
|
||||
if (args.size() >= 4) {
|
||||
final String server = args.get(3).toLowerCase();
|
||||
if (ArgumentChecker.checkServer(server)) {
|
||||
Message.SERVER_INVALID_ENTRY.send(sender);
|
||||
return CommandResult.INVALID_ARGS;
|
||||
}
|
||||
|
||||
if (args.size() == 4) {
|
||||
group.setPermission(node, true, server, duration);
|
||||
Message.ADD_TEMP_PREFIX_SERVER_SUCCESS.send(sender, group.getName(), prefix, priority, server, DateUtil.formatDateDiff(duration));
|
||||
LogEntry.build().actor(sender).acted(group)
|
||||
.action("addtempprefix " + priority + " " + args.get(1) + " " + duration + " " + server)
|
||||
.build().submit(plugin, sender);
|
||||
} else {
|
||||
final String world = args.get(4).toLowerCase();
|
||||
group.setPermission(node, true, server, world, duration);
|
||||
Message.ADD_TEMP_PREFIX_SERVER_WORLD_SUCCESS.send(sender, group.getName(), prefix, priority, server, world, DateUtil.formatDateDiff(duration));
|
||||
LogEntry.build().actor(sender).acted(group)
|
||||
.action("addtempprefix " + priority + " " + args.get(1) + " " + duration + " " + server + " " + world)
|
||||
.build().submit(plugin, sender);
|
||||
}
|
||||
|
||||
} else {
|
||||
group.setPermission(node, true, duration);
|
||||
Message.ADD_TEMP_PREFIX_SUCCESS.send(sender, group.getName(), prefix, priority, DateUtil.formatDateDiff(duration));
|
||||
LogEntry.build().actor(sender).acted(group)
|
||||
.action("addtempprefix " + priority + " " + args.get(1) + " " + duration)
|
||||
.build().submit(plugin, sender);
|
||||
}
|
||||
|
||||
save(group, sender, plugin);
|
||||
return CommandResult.SUCCESS;
|
||||
} catch (ObjectAlreadyHasException e) {
|
||||
Message.ALREADY_HAS_PREFIX.send(sender, group.getName());
|
||||
return CommandResult.STATE_ERROR;
|
||||
}
|
||||
}
|
||||
}
|
||||
+114
@@ -0,0 +1,114 @@
|
||||
/*
|
||||
* Copyright (c) 2016 Lucko (Luck) <luck@lucko.me>
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
package me.lucko.luckperms.commands.group.subcommands;
|
||||
|
||||
import me.lucko.luckperms.LuckPermsPlugin;
|
||||
import me.lucko.luckperms.commands.CommandResult;
|
||||
import me.lucko.luckperms.commands.Predicate;
|
||||
import me.lucko.luckperms.commands.Sender;
|
||||
import me.lucko.luckperms.commands.SubCommand;
|
||||
import me.lucko.luckperms.constants.Message;
|
||||
import me.lucko.luckperms.constants.Permission;
|
||||
import me.lucko.luckperms.data.LogEntry;
|
||||
import me.lucko.luckperms.exceptions.ObjectAlreadyHasException;
|
||||
import me.lucko.luckperms.groups.Group;
|
||||
import me.lucko.luckperms.utils.ArgumentChecker;
|
||||
import me.lucko.luckperms.utils.DateUtil;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class GroupAddTempSuffix extends SubCommand<Group> {
|
||||
public GroupAddTempSuffix() {
|
||||
super("addtempsuffix", "Adds a suffix to the group temporarily", "/%s group <group> addtempsuffix <priority> <suffix> <duration> [server] [world]",
|
||||
Permission.GROUP_ADD_TEMP_SUFFIX, Predicate.notInRange(3, 5));
|
||||
}
|
||||
|
||||
@Override
|
||||
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, Group group, List<String> args, String label) {
|
||||
final String suffix = args.get(1).replace("{SPACE}", " ");
|
||||
int priority;
|
||||
try {
|
||||
priority = Integer.parseInt(args.get(0));
|
||||
} catch (NumberFormatException e) {
|
||||
Message.META_INVALID_PRIORITY.send(sender, args.get(0));
|
||||
return CommandResult.INVALID_ARGS;
|
||||
}
|
||||
|
||||
long duration;
|
||||
try {
|
||||
duration = Long.parseLong(args.get(2));
|
||||
} catch (NumberFormatException e) {
|
||||
try {
|
||||
duration = DateUtil.parseDateDiff(args.get(2), true);
|
||||
} catch (DateUtil.IllegalDateException e1) {
|
||||
Message.ILLEGAL_DATE_ERROR.send(sender, args.get(2));
|
||||
return CommandResult.INVALID_ARGS;
|
||||
}
|
||||
}
|
||||
|
||||
if (DateUtil.shouldExpire(duration)) {
|
||||
Message.PAST_DATE_ERROR.send(sender);
|
||||
return CommandResult.INVALID_ARGS;
|
||||
}
|
||||
|
||||
final String node = "suffix." + priority + "." + ArgumentChecker.escapeCharacters(suffix);
|
||||
|
||||
try {
|
||||
if (args.size() >= 4) {
|
||||
final String server = args.get(3).toLowerCase();
|
||||
if (ArgumentChecker.checkServer(server)) {
|
||||
Message.SERVER_INVALID_ENTRY.send(sender);
|
||||
return CommandResult.INVALID_ARGS;
|
||||
}
|
||||
|
||||
if (args.size() == 4) {
|
||||
group.setPermission(node, true, server, duration);
|
||||
Message.ADD_TEMP_SUFFIX_SERVER_SUCCESS.send(sender, group.getName(), suffix, priority, server, DateUtil.formatDateDiff(duration));
|
||||
LogEntry.build().actor(sender).acted(group)
|
||||
.action("addtempsuffix " + priority + " " + args.get(1) + " " + duration + " " + server)
|
||||
.build().submit(plugin, sender);
|
||||
} else {
|
||||
final String world = args.get(4).toLowerCase();
|
||||
group.setPermission(node, true, server, world, duration);
|
||||
Message.ADD_TEMP_SUFFIX_SERVER_WORLD_SUCCESS.send(sender, group.getName(), suffix, priority, server, world, DateUtil.formatDateDiff(duration));
|
||||
LogEntry.build().actor(sender).acted(group)
|
||||
.action("addtempsuffix " + priority + " " + args.get(1) + " " + duration + " " + server + " " + world)
|
||||
.build().submit(plugin, sender);
|
||||
}
|
||||
|
||||
} else {
|
||||
group.setPermission(node, true, duration);
|
||||
Message.ADD_TEMP_SUFFIX_SUCCESS.send(sender, group.getName(), suffix, priority, DateUtil.formatDateDiff(duration));
|
||||
LogEntry.build().actor(sender).acted(group)
|
||||
.action("addtempsuffix " + priority + " " + args.get(1) + " " + duration)
|
||||
.build().submit(plugin, sender);
|
||||
}
|
||||
|
||||
save(group, sender, plugin);
|
||||
return CommandResult.SUCCESS;
|
||||
} catch (ObjectAlreadyHasException e) {
|
||||
Message.ALREADY_HAS_SUFFIX.send(sender, group.getName());
|
||||
return CommandResult.STATE_ERROR;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,90 @@
|
||||
/*
|
||||
* Copyright (c) 2016 Lucko (Luck) <luck@lucko.me>
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
package me.lucko.luckperms.commands.group.subcommands;
|
||||
|
||||
import me.lucko.luckperms.LuckPermsPlugin;
|
||||
import me.lucko.luckperms.api.Node;
|
||||
import me.lucko.luckperms.commands.*;
|
||||
import me.lucko.luckperms.constants.Message;
|
||||
import me.lucko.luckperms.constants.Permission;
|
||||
import me.lucko.luckperms.groups.Group;
|
||||
import me.lucko.luckperms.utils.Contexts;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
public class GroupChatMeta extends SubCommand<Group> {
|
||||
public GroupChatMeta() {
|
||||
super("chatmeta", "Displays a groups chat meta", "/%s group <group> chatmeta", Permission.GROUP_CHATMETA,
|
||||
Predicate.alwaysFalse());
|
||||
}
|
||||
|
||||
@Override
|
||||
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, Group group, List<String> args, String label) {
|
||||
SortedSet<Map.Entry<Integer, String>> prefixes = new TreeSet<>(Util.getMetaComparator().reversed());
|
||||
SortedSet<Map.Entry<Integer, String>> suffixes = new TreeSet<>(Util.getMetaComparator().reversed());
|
||||
|
||||
for (Node node : group.getAllNodes(null, Contexts.allowAll())) {
|
||||
if (!node.isSuffix() && !node.isPrefix()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
StringBuilder sb = new StringBuilder();
|
||||
if (node.isServerSpecific()) {
|
||||
if (node.isWorldSpecific()) {
|
||||
sb.append("&6W=").append(node.getWorld().get()).append(" ");
|
||||
}
|
||||
sb.append("&6S=").append(node.getServer().get()).append(" ");
|
||||
}
|
||||
|
||||
if (node.isPrefix()) {
|
||||
sb.append(node.getPrefix().getValue());
|
||||
prefixes.add(new AbstractMap.SimpleEntry<>(node.getPrefix().getKey(), sb.toString()));
|
||||
}
|
||||
|
||||
if (node.isSuffix()) {
|
||||
sb.append(node.getSuffix().getValue());
|
||||
suffixes.add(new AbstractMap.SimpleEntry<>(node.getSuffix().getKey(), sb.toString()));
|
||||
}
|
||||
}
|
||||
|
||||
if (prefixes.isEmpty()) {
|
||||
Message.CHAT_META_PREFIX_NONE.send(sender, group.getName());
|
||||
} else {
|
||||
Message.CHAT_META_PREFIX_HEADER.send(sender, group.getName());
|
||||
for (Map.Entry<Integer, String> e : prefixes) {
|
||||
Message.CHAT_META_ENTRY.send(sender, e.getKey(), e.getValue());
|
||||
}
|
||||
}
|
||||
|
||||
if (suffixes.isEmpty()) {
|
||||
Message.CHAT_META_SUFFIX_NONE.send(sender, group.getName());
|
||||
} else {
|
||||
Message.CHAT_META_SUFFIX_HEADER.send(sender, group.getName());
|
||||
for (Map.Entry<Integer, String> e : suffixes) {
|
||||
Message.CHAT_META_ENTRY.send(sender, e.getKey(), e.getValue());
|
||||
}
|
||||
}
|
||||
|
||||
return CommandResult.SUCCESS;
|
||||
}
|
||||
}
|
||||
@@ -29,7 +29,7 @@ import me.lucko.luckperms.commands.Sender;
|
||||
import me.lucko.luckperms.commands.SubCommand;
|
||||
import me.lucko.luckperms.constants.Message;
|
||||
import me.lucko.luckperms.constants.Permission;
|
||||
import me.lucko.luckperms.data.LogEntryBuilder;
|
||||
import me.lucko.luckperms.data.LogEntry;
|
||||
import me.lucko.luckperms.groups.Group;
|
||||
|
||||
import java.util.List;
|
||||
@@ -44,7 +44,7 @@ public class GroupClear extends SubCommand<Group> {
|
||||
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, Group group, List<String> args, String label) {
|
||||
group.clearNodes();
|
||||
Message.CLEAR_SUCCESS.send(sender, group.getName());
|
||||
LogEntryBuilder.get().actor(sender).acted(group).action("clear").submit(plugin);
|
||||
LogEntry.build().actor(sender).acted(group).action("clear").build().submit(plugin, sender);
|
||||
save(group, sender, plugin);
|
||||
return CommandResult.SUCCESS;
|
||||
}
|
||||
|
||||
@@ -43,8 +43,8 @@ public class GroupInfo extends SubCommand<Group> {
|
||||
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, Group group, List<String> args, String label) {
|
||||
Message.GROUP_INFO.send(sender,
|
||||
group.getName(),
|
||||
group.getPermanentNodes().keySet().size(),
|
||||
group.getTemporaryNodes().keySet().size(),
|
||||
group.getPermanentNodes().size(),
|
||||
group.getTemporaryNodes().size(),
|
||||
label,
|
||||
group.getName()
|
||||
);
|
||||
|
||||
+2
-2
@@ -38,8 +38,8 @@ public class GroupListNodes extends SubCommand<Group> {
|
||||
|
||||
@Override
|
||||
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, Group group, List<String> args, String label) {
|
||||
Message.LISTNODES.send(sender, group.getName(), Util.permNodesToString(group.getPermanentNodes()));
|
||||
Message.LISTNODES_TEMP.send(sender, group.getName(), Util.tempNodesToString(group.getTemporaryNodes()));
|
||||
Message.LISTNODES.send(sender, group.getName(), Util.permNodesToString(group.getPermissions(false)));
|
||||
Message.LISTNODES_TEMP.send(sender, group.getName(), Util.tempNodesToString(group.getPermissions(false)));
|
||||
return CommandResult.SUCCESS;
|
||||
}
|
||||
}
|
||||
Loaded 100 of 225 files, more files were not shown because too many files have changed in this diff.
Show more
Reference in new issue
Block a user