Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
03450c3339 | ||
|
|
56e11b8b85 | ||
|
|
5e23b6961e | ||
|
|
98c5a91beb | ||
|
|
d6cd0b162b | ||
|
|
1c064daccb | ||
|
|
0cfdd8c862 | ||
|
|
a9619bc08c | ||
|
|
a7a84952fe | ||
|
|
9c867dee28 | ||
|
|
db862b38c9 | ||
|
|
cba12c3e78 | ||
|
|
0ecd899ec5 | ||
|
|
e9805b7532 | ||
|
|
c000b9c009 | ||
|
|
8f6435b9e8 | ||
|
|
a3604c7464 | ||
|
|
10574748ff | ||
|
|
c7336dbcad | ||
|
|
ebeb69dd3a | ||
|
|
9ad40be210 | ||
|
|
df209f6515 | ||
|
|
d32d6b5474 | ||
|
|
623b7b775c | ||
|
|
b3b687d9b7 | ||
|
|
a413c0a50a | ||
|
|
1870893fe1 | ||
|
|
f24562c642 | ||
|
|
ea358e88e1 | ||
|
|
cdf8a4ce18 | ||
|
|
24ff465679 | ||
|
|
d33a3ffcea | ||
|
|
874a90253b | ||
|
|
90b6f41f13 | ||
|
|
33fc4f537a | ||
|
|
42322ef932 | ||
|
|
d5a6a4261d | ||
|
|
69ab488c47 | ||
|
|
ad9b190a7c | ||
|
|
f35cb95001 | ||
|
|
f803082b15 | ||
|
|
2413f0f379 | ||
|
|
7ca7fdd472 | ||
|
|
f6e3f1ca0b | ||
|
|
84335afacd | ||
|
|
0e449cdd7a | ||
|
|
3c83c31e9f | ||
|
|
776ec45701 | ||
|
|
ebbc0511bf | ||
|
|
d4c335e33e | ||
|
|
e5e1333769 | ||
|
|
d855be1c65 | ||
|
|
d35774b401 | ||
|
|
1b09488859 | ||
|
|
697b349167 | ||
|
|
34ca3b3c25 | ||
|
|
e07a346e16 | ||
|
|
4610b3db7e | ||
|
|
0781637617 | ||
|
|
85989aeb7c | ||
|
|
0380b7017d | ||
|
|
91e24ccba1 | ||
|
|
10a58e372c | ||
|
|
60f6bac903 | ||
|
|
f6d8fb5286 | ||
|
|
484bc44288 | ||
|
|
00c3a8b415 | ||
|
|
20f34d9b45 | ||
|
|
50f4a84d04 | ||
|
|
96476a2796 | ||
|
|
17883f21d6 |
No files matched your search
@@ -1,28 +1,182 @@
|
||||
# LuckPerms
|
||||
A quite possibly shit™ permissions implementation for Bukkit/BungeeCord.
|
||||
# LuckPerms [](https://ci.lucko.me/job/LuckPerms/)
|
||||
A permissions implementation for Bukkit/Spigot, BungeeCord and Sponge.
|
||||
|
||||
### Why?
|
||||
Yeah, I don't know. There are other more advanced, optimized, better programmed and thoroughly tested alternative plugins around, you should probably use those instead. I just wanted some specific features, and something that was compatible with BungeeCord.
|
||||
## Links
|
||||
* **Development Builds** - <https://ci.lucko.me/job/LuckPerms>
|
||||
* **Javadocs** - <https://jd.lucko.me/LuckPerms>
|
||||
|
||||
### Features
|
||||
- **Group inheritance** - users can be members of multiple groups, groups can inherit other groups
|
||||
- **Multi-server support** - data is synced across all servers/platforms
|
||||
- **Per-server permissions/groups** - define permissions that only apply on certain servers
|
||||
- **Vault Support** - hooks into Vault to integrate with other plugins
|
||||
- **Everything is configured using commands** - no editing yml files, yuck
|
||||
- **Efficient** - maybe? Who knows, it might be.
|
||||
- **BungeeCord compatible** - my main motive for making this was that all other Bungee/Bukkit compatible perms plugins are utter aids. (At least, I couldn't find any decent ones)
|
||||
## 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
|
||||
* **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
|
||||
* **Easy and simple setup and configuration using commands** - no editing yml files, yuck
|
||||
* **Negated permissions and groups** - define special rules for certain users/groups
|
||||
* **Full support for UUIDs, even in Offline Mode** - users can change their usernames without losing permissions. In offline mode, a single user has the same internal UUID across a network.
|
||||
* **Permission data stored within MySQL in a json format** - easily integrate the LuckPerms backend into your other projects
|
||||
* **Well documented** - API methods have comprehensive Java docs, it's clear what each method does.
|
||||
* **Efficient/lightweight** - maybe? Who knows, it might be.
|
||||
* **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)
|
||||
|
||||
### Caveats
|
||||
- Only supports MySQL
|
||||
- Not at all tested and could be super unreliable
|
||||
- It's quite possibly shit™
|
||||
## Setup
|
||||
All configuration options are in the **config.yml/luckperms.conf** file, which is generated automagically when the plugin first starts.
|
||||
|
||||
So, not anything major, really ¯\ _(ツ)_ /¯
|
||||
You can define the settings for per-server permissions, the storage method and credentials within this file.
|
||||
|
||||
### Commands
|
||||
Command usage is printed when you supply too little arguments.
|
||||
## Info
|
||||
### Permission Calculation
|
||||
Permissions are calculated based on a priority system as follows.
|
||||
|
||||
Bukkit: `/luckperms` `/perms` `/permissions` `/lp` `/perm`
|
||||
* Temporary permissions will override non-temporary permissions.
|
||||
|
||||
Bungee: `/luckpermsbungee` `/bperms` `/bpermissions` `/lpb` `/bperm`
|
||||
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.
|
||||
|
||||
* 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 (provided they're on that server).
|
||||
|
||||
### 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.
|
||||
|
||||
## 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
|
||||
final LuckPermsApi api = LuckPerms.getApi();
|
||||
|
||||
// On Bukkit/Spigot
|
||||
final LuckPermsApi api = Bukkit.getServicesManager().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>1.5</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
````
|
||||
|
||||
## 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
|
||||
|
||||
## License
|
||||
See LICENSE.md.
|
||||
+27
@@ -0,0 +1,27 @@
|
||||
<?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>1.5</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<version>1.5</version>
|
||||
<artifactId>luckperms-api</artifactId>
|
||||
<build>
|
||||
<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>
|
||||
</project>
|
||||
@@ -0,0 +1,30 @@
|
||||
package me.lucko.luckperms;
|
||||
|
||||
import lombok.AccessLevel;
|
||||
import lombok.NoArgsConstructor;
|
||||
import me.lucko.luckperms.api.LuckPermsApi;
|
||||
|
||||
/**
|
||||
* Static access to LuckPerms
|
||||
*/
|
||||
@NoArgsConstructor(access = AccessLevel.PRIVATE)
|
||||
public class LuckPerms {
|
||||
|
||||
private static LuckPermsApi api = null;
|
||||
|
||||
public static LuckPermsApi getApi() {
|
||||
if (api == null) {
|
||||
throw new IllegalStateException("API is not loaded.");
|
||||
}
|
||||
return api;
|
||||
}
|
||||
|
||||
static void registerProvider(LuckPermsApi luckPermsApi) {
|
||||
api = luckPermsApi;
|
||||
}
|
||||
|
||||
static void unregisterProvider() {
|
||||
api = null;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,56 @@
|
||||
package me.lucko.luckperms.api;
|
||||
|
||||
import me.lucko.luckperms.api.data.Callback;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
* Wrapper interface for the internal Datastore instance
|
||||
* 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.
|
||||
*/
|
||||
@SuppressWarnings("unused")
|
||||
public interface Datastore {
|
||||
|
||||
String getName();
|
||||
boolean isAcceptingLogins();
|
||||
|
||||
Async async();
|
||||
Sync sync();
|
||||
|
||||
interface Async {
|
||||
void loadOrCreateUser(UUID uuid, String username, Callback<Boolean> callback);
|
||||
void loadUser(UUID uuid, Callback<Boolean> callback);
|
||||
void saveUser(User user, Callback<Boolean> callback);
|
||||
void createAndLoadGroup(String name, Callback<Boolean> callback);
|
||||
void loadGroup(String name, Callback<Boolean> callback);
|
||||
void loadAllGroups(Callback<Boolean> callback);
|
||||
void saveGroup(Group group, Callback<Boolean> callback);
|
||||
void deleteGroup(Group group, Callback<Boolean> callback);
|
||||
void createAndLoadTrack(String name, Callback<Boolean> callback);
|
||||
void loadTrack(String name, Callback<Boolean> callback);
|
||||
void loadAllTracks(Callback<Boolean> callback);
|
||||
void saveTrack(Track track, Callback<Boolean> callback);
|
||||
void deleteTrack(Track track, Callback<Boolean> callback);
|
||||
void saveUUIDData(String username, UUID uuid, Callback<Boolean> callback);
|
||||
void getUUID(String username, Callback<UUID> callback);
|
||||
}
|
||||
|
||||
interface Sync {
|
||||
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);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,172 @@
|
||||
package me.lucko.luckperms.api;
|
||||
|
||||
import me.lucko.luckperms.exceptions.ObjectAlreadyHasException;
|
||||
import me.lucko.luckperms.exceptions.ObjectLacksException;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Wrapper interface for internal Group instances
|
||||
* 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.
|
||||
*/
|
||||
@SuppressWarnings("unused")
|
||||
public interface Group extends PermissionObject {
|
||||
|
||||
/**
|
||||
* @return the name of the group
|
||||
*/
|
||||
String getName();
|
||||
|
||||
/**
|
||||
* 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
|
||||
*/
|
||||
boolean inheritsGroup(Group group);
|
||||
|
||||
/**
|
||||
* 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
|
||||
*/
|
||||
boolean inheritsGroup(Group group, String 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
|
||||
* @param world The world to check on
|
||||
* @return true if the group inherits the group
|
||||
*/
|
||||
boolean inheritsGroup(Group group, String server, String world);
|
||||
|
||||
/**
|
||||
* Make this group inherit another group
|
||||
* @param group the group to be inherited
|
||||
* @throws ObjectAlreadyHasException if the group already inherits the group
|
||||
*/
|
||||
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
|
||||
* @throws ObjectAlreadyHasException if the group already inherits the group on that server
|
||||
*/
|
||||
void setInheritGroup(Group group, String server) 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 world The world to add the group on
|
||||
* @throws ObjectAlreadyHasException if the group already inherits the group on that server
|
||||
*/
|
||||
void setInheritGroup(Group group, String server, String world) throws ObjectAlreadyHasException;
|
||||
|
||||
/**
|
||||
* Make this group inherit another group on a specific server
|
||||
* @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
|
||||
*/
|
||||
void setInheritGroup(Group group, long expireAt) 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 expireAt when the group should expire
|
||||
* @throws ObjectAlreadyHasException if the group already inherits the group on that server
|
||||
*/
|
||||
void setInheritGroup(Group group, String server, long expireAt) 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 world The world to add the group on
|
||||
* @param expireAt when the group should expire
|
||||
* @throws ObjectAlreadyHasException if the group already inherits the group on that server
|
||||
*/
|
||||
void setInheritGroup(Group group, String server, String world, long expireAt) throws ObjectAlreadyHasException;
|
||||
|
||||
/**
|
||||
* Remove a previously set inheritance
|
||||
* @param group the group to uninherit
|
||||
* @throws ObjectLacksException if the group does not already inherit the group
|
||||
*/
|
||||
void unsetInheritGroup(Group group) throws ObjectLacksException;
|
||||
|
||||
/**
|
||||
* Remove a previously set inheritance
|
||||
* @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
|
||||
*/
|
||||
void unsetInheritGroup(Group group, boolean temporary) throws ObjectLacksException;
|
||||
|
||||
/**
|
||||
* Remove a previously set inheritance
|
||||
* @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
|
||||
*/
|
||||
void unsetInheritGroup(Group group, String server) throws ObjectLacksException;
|
||||
|
||||
/**
|
||||
* Remove a previously set inheritance
|
||||
* @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
|
||||
*/
|
||||
void unsetInheritGroup(Group group, String server, String world) throws ObjectLacksException;
|
||||
|
||||
/**
|
||||
* Remove a previously set inheritance
|
||||
* @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
|
||||
*/
|
||||
void unsetInheritGroup(Group group, String server, boolean temporary) throws ObjectLacksException;
|
||||
|
||||
/**
|
||||
* Remove a previously set inheritance
|
||||
* @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
|
||||
* @throws ObjectLacksException if the group does not already inherit the group
|
||||
*/
|
||||
void unsetInheritGroup(Group group, String server, String world, boolean temporary) throws ObjectLacksException;
|
||||
|
||||
/**
|
||||
* Clear all of the groups permission nodes
|
||||
*/
|
||||
void clearNodes();
|
||||
|
||||
/**
|
||||
* Get a {@link List} of all of the groups the group inherits, on all servers
|
||||
* @return a {@link List} of group names
|
||||
*/
|
||||
List<String> getGroupNames();
|
||||
|
||||
/**
|
||||
* Get a {@link List} of the groups the group inherits on a specific server
|
||||
* @param server the server to check
|
||||
* @param world the world to check
|
||||
* @return a {@link List} of group names
|
||||
*/
|
||||
List<String> getLocalGroups(String server, String world);
|
||||
|
||||
/**
|
||||
* 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
|
||||
*/
|
||||
List<String> getLocalGroups(String server);
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
package me.lucko.luckperms.api;
|
||||
|
||||
public interface Logger {
|
||||
|
||||
void info(String s);
|
||||
void warn(String s);
|
||||
void severe(String s);
|
||||
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
package me.lucko.luckperms.api;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
public interface LuckPermsApi {
|
||||
|
||||
void runUpdateTask();
|
||||
String getVersion();
|
||||
|
||||
Datastore getDatastore();
|
||||
Logger getLogger();
|
||||
|
||||
User getUser(UUID uuid);
|
||||
User getUser(String name);
|
||||
boolean isUserLoaded(UUID uuid);
|
||||
|
||||
Group getGroup(String name);
|
||||
boolean isGroupLoaded(String name);
|
||||
|
||||
Track getTrack(String name);
|
||||
boolean isTrackLoaded(String name);
|
||||
|
||||
}
|
||||
@@ -0,0 +1,277 @@
|
||||
package me.lucko.luckperms.api;
|
||||
|
||||
import me.lucko.luckperms.exceptions.ObjectAlreadyHasException;
|
||||
import me.lucko.luckperms.exceptions.ObjectLacksException;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* Wrapper interface for internal PermissionObject (user/group) instances
|
||||
* 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.
|
||||
*/
|
||||
@SuppressWarnings("unused")
|
||||
public interface PermissionObject {
|
||||
|
||||
String getObjectName();
|
||||
|
||||
Map<String, Boolean> getNodes();
|
||||
|
||||
/**
|
||||
* 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
|
||||
*/
|
||||
boolean hasPermission(String node, boolean b);
|
||||
|
||||
/**
|
||||
* Checks to see the the object has a permission on a certain server
|
||||
* @param node The permission node
|
||||
* @param b If the node is true/false(negated)
|
||||
* @param server The server
|
||||
* @return true if the user has the permission
|
||||
*/
|
||||
boolean hasPermission(String node, boolean b, String server);
|
||||
|
||||
/**
|
||||
* Checks to see the the object has a permission on a certain server
|
||||
* @param node The permission node
|
||||
* @param b If the node is true/false(negated)
|
||||
* @param server The server
|
||||
* @param world The world
|
||||
* @return true if the user has the permission
|
||||
*/
|
||||
boolean hasPermission(String node, boolean b, String server, String world);
|
||||
|
||||
/**
|
||||
* Checks to see the the object has a permission on a certain server
|
||||
* @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
|
||||
*/
|
||||
boolean hasPermission(String node, boolean b, boolean temporary);
|
||||
|
||||
/**
|
||||
* Checks to see the the object has a permission on a certain server
|
||||
* @param node The permission node
|
||||
* @param b If the node is true/false(negated)
|
||||
* @param server The server to check on
|
||||
* @param temporary if the permission is temporary
|
||||
* @return true if the user has the permission
|
||||
*/
|
||||
boolean hasPermission(String node, boolean b, String server, boolean temporary);
|
||||
|
||||
/**
|
||||
* Checks to see the the object has a permission on a certain server
|
||||
* @param node The permission node
|
||||
* @param b If the node is true/false(negated)
|
||||
* @param server The server to check on
|
||||
* @param world The world to check on
|
||||
* @param temporary if the permission is temporary
|
||||
* @return true if the user has the permission
|
||||
*/
|
||||
boolean hasPermission(String node, boolean b, String server, String world, boolean temporary);
|
||||
|
||||
/**
|
||||
* Checks to see if the object inherits a certain permission
|
||||
* @param node The permission node
|
||||
* @param b If the node is true/false(negated)
|
||||
* @return true if the user inherits the permission
|
||||
*/
|
||||
boolean inheritsPermission(String node, boolean b);
|
||||
|
||||
/**
|
||||
* Checks to see the the object inherits a permission on a certain server
|
||||
* @param node The permission node
|
||||
* @param b If the node is true/false(negated)
|
||||
* @param server The server
|
||||
* @return true if the user inherits the permission
|
||||
*/
|
||||
boolean inheritsPermission(String node, boolean b, String server);
|
||||
|
||||
/**
|
||||
* Checks to see the the object inherits a permission on a certain server
|
||||
* @param node The permission node
|
||||
* @param b If the node is true/false(negated)
|
||||
* @param server The server
|
||||
* @param world The world
|
||||
* @return true if the user inherits the permission
|
||||
*/
|
||||
boolean inheritsPermission(String node, boolean b, String server, String world);
|
||||
|
||||
/**
|
||||
* Checks to see if the object inherits a certain permission
|
||||
* @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
|
||||
*/
|
||||
boolean inheritsPermission(String node, boolean b, boolean temporary);
|
||||
|
||||
/**
|
||||
* Checks to see if the object inherits a certain permission
|
||||
* @param node The permission node
|
||||
* @param b If the node is true/false(negated)
|
||||
* @param server The server
|
||||
* @param temporary if the permission is temporary
|
||||
* @return true if the user inherits the permission
|
||||
*/
|
||||
boolean inheritsPermission(String node, boolean b, String server, boolean temporary);
|
||||
|
||||
/**
|
||||
* Checks to see if the object inherits a certain permission
|
||||
* @param node The permission node
|
||||
* @param b If the node is true/false(negated)
|
||||
* @param server The server
|
||||
* @param world The world
|
||||
* @param temporary if the permission is temporary
|
||||
* @return true if the user inherits the permission
|
||||
*/
|
||||
boolean inheritsPermission(String node, boolean b, String server, String world, boolean temporary);
|
||||
|
||||
/**
|
||||
* Sets a permission for the object
|
||||
* @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
|
||||
*/
|
||||
void setPermission(String node, boolean value) throws ObjectAlreadyHasException;
|
||||
|
||||
/**
|
||||
* Sets a permission for the object
|
||||
* @param node The node to set
|
||||
* @param value What to set the node to - true/false(negated)
|
||||
* @param server The server to set the permission on
|
||||
* @throws ObjectAlreadyHasException if the object already has the permission
|
||||
*/
|
||||
void setPermission(String node, boolean value, String server) throws ObjectAlreadyHasException;
|
||||
|
||||
/**
|
||||
* Sets a permission for the object
|
||||
* @param node The node to set
|
||||
* @param value What to set the node to - true/false(negated)
|
||||
* @param server The server to set the permission on
|
||||
* @param world The world to set the permission on
|
||||
* @throws ObjectAlreadyHasException if the object already has the permission
|
||||
*/
|
||||
void setPermission(String node, boolean value, String server, String world) throws ObjectAlreadyHasException;
|
||||
|
||||
/**
|
||||
* Sets a permission for the object
|
||||
* @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
|
||||
*/
|
||||
void setPermission(String node, boolean value, long expireAt) throws ObjectAlreadyHasException;
|
||||
|
||||
/**
|
||||
* Sets a permission for the object
|
||||
* @param node The node to set
|
||||
* @param value What to set the node to - true/false(negated)
|
||||
* @param server The server to set the permission on
|
||||
* @param expireAt The time in unixtime when the permission will expire
|
||||
* @throws ObjectAlreadyHasException if the object already has the permission
|
||||
*/
|
||||
void setPermission(String node, boolean value, String server, long expireAt) throws ObjectAlreadyHasException;
|
||||
|
||||
/**
|
||||
* Sets a permission for the object
|
||||
* @param node The node to set
|
||||
* @param value What to set the node to - true/false(negated)
|
||||
* @param server The server to set the permission on
|
||||
* @param world The world to set the permission on
|
||||
* @param expireAt The time in unixtime when the permission will expire
|
||||
* @throws ObjectAlreadyHasException if the object already has the permission
|
||||
*/
|
||||
void setPermission(String node, boolean value, String server, String world, long expireAt) throws ObjectAlreadyHasException;
|
||||
|
||||
/**
|
||||
* Unsets a permission for the object
|
||||
* @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
|
||||
*/
|
||||
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
|
||||
*/
|
||||
void unsetPermission(String node) throws ObjectLacksException;
|
||||
|
||||
/**
|
||||
* Unsets a permission for the object
|
||||
* @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
|
||||
*/
|
||||
void unsetPermission(String node, String server) throws ObjectLacksException;
|
||||
|
||||
/**
|
||||
* Unsets a permission for the object
|
||||
* @param node The node to be unset
|
||||
* @param server The server to unset the node on
|
||||
* @param world The world to unset the node on
|
||||
* @throws ObjectLacksException if the node wasn't already set
|
||||
*/
|
||||
void unsetPermission(String node, String server, String world) throws ObjectLacksException;
|
||||
|
||||
/**
|
||||
* Unsets a permission for the object
|
||||
* @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
|
||||
*/
|
||||
void unsetPermission(String node, String server, boolean temporary) throws ObjectLacksException;
|
||||
|
||||
/**
|
||||
* Unsets a permission for the object
|
||||
* @param node The node to be unset
|
||||
* @param server The server to unset the node on
|
||||
* @param world The world to unset the node on
|
||||
* @param temporary if the permission being unset is temporary
|
||||
* @throws ObjectLacksException if the node wasn't already set
|
||||
*/
|
||||
void unsetPermission(String node, String server, String world, boolean temporary) throws ObjectLacksException;
|
||||
|
||||
/**
|
||||
* Gets the permissions and inherited permissions that apply to a specific server
|
||||
* @param server The server to get nodes for
|
||||
* @param world The world to get nodes for
|
||||
* @param excludedGroups Groups that shouldn't be inherited (to prevent circular inheritance issues)
|
||||
* @return a {@link Map} of the permissions
|
||||
*/
|
||||
Map<String, Boolean> getLocalPermissions(String server, String world, List<String> excludedGroups);
|
||||
|
||||
/**
|
||||
* Gets the permissions and inherited permissions that apply to a specific server
|
||||
* @param server The server to get nodes for (can be null)
|
||||
* @param excludedGroups Groups that shouldn't be inherited, can be null (to prevent circular inheritance issues)
|
||||
* @return a {@link Map} of the permissions
|
||||
*/
|
||||
Map<String, Boolean> getLocalPermissions(String server, List<String> excludedGroups);
|
||||
|
||||
/**
|
||||
* Processes the objects and returns the temporary ones.
|
||||
* @return a map of temporary nodes
|
||||
*/
|
||||
Map<Map.Entry<String, Boolean>, Long> getTemporaryNodes();
|
||||
|
||||
/**
|
||||
* Processes the objects and returns the non-temporary ones.
|
||||
* @return a map of permanent nodes
|
||||
*/
|
||||
Map<String, Boolean> getPermanentNodes();
|
||||
|
||||
/**
|
||||
* Removes temporary permissions that have expired
|
||||
*/
|
||||
void auditTemporaryPermissions();
|
||||
|
||||
}
|
||||
@@ -0,0 +1,95 @@
|
||||
package me.lucko.luckperms.api;
|
||||
|
||||
import me.lucko.luckperms.exceptions.ObjectAlreadyHasException;
|
||||
import me.lucko.luckperms.exceptions.ObjectLacksException;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Wrapper interface for internal Track instances
|
||||
* 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.
|
||||
*/
|
||||
@SuppressWarnings("unused")
|
||||
public interface Track {
|
||||
|
||||
String getName();
|
||||
|
||||
/**
|
||||
* Gets an ordered list of the groups on this track
|
||||
* @return am ordered {@link List} of the groups on this track
|
||||
*/
|
||||
List<String> getGroups();
|
||||
|
||||
/**
|
||||
* Gets the number of groups on this track
|
||||
* @return the number of groups on this track
|
||||
*/
|
||||
int getSize();
|
||||
|
||||
/**
|
||||
* Gets the next group on the track, after the one provided
|
||||
* @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
|
||||
*/
|
||||
String getNext(Group current) throws ObjectLacksException;
|
||||
|
||||
/**
|
||||
* Gets the group before the group 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
|
||||
*/
|
||||
String getPrevious(Group current) throws ObjectLacksException;
|
||||
|
||||
/**
|
||||
* 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
|
||||
*/
|
||||
void appendGroup(Group group) throws ObjectAlreadyHasException;
|
||||
|
||||
/**
|
||||
* Inserts a group at a certain position on this track
|
||||
* @param group the group to be inserted
|
||||
* @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
|
||||
*/
|
||||
void insertGroup(Group group, int position) throws ObjectAlreadyHasException, IndexOutOfBoundsException;
|
||||
|
||||
/**
|
||||
* Removes a group from this track
|
||||
* @param group the group to remove
|
||||
* @throws ObjectLacksException if the group is not on this track
|
||||
*/
|
||||
void removeGroup(Group group) throws ObjectLacksException;
|
||||
|
||||
/**
|
||||
* Removes a group from this track
|
||||
* @param group the group to remove
|
||||
* @throws ObjectLacksException if the group is not on this track
|
||||
*/
|
||||
void removeGroup(String group) throws ObjectLacksException;
|
||||
|
||||
/**
|
||||
* Checks if a group features on this track
|
||||
* @param group the group to check
|
||||
* @return true if the group is on this track
|
||||
*/
|
||||
boolean containsGroup(Group group);
|
||||
|
||||
/**
|
||||
* Checks if a group features on this track
|
||||
* @param group the group to check
|
||||
* @return true if the group is on this track
|
||||
*/
|
||||
boolean containsGroup(String group);
|
||||
|
||||
/**
|
||||
* Clear all of the groups within this track
|
||||
*/
|
||||
void clearGroups();
|
||||
|
||||
}
|
||||
@@ -0,0 +1,197 @@
|
||||
package me.lucko.luckperms.api;
|
||||
|
||||
import me.lucko.luckperms.exceptions.ObjectAlreadyHasException;
|
||||
import me.lucko.luckperms.exceptions.ObjectLacksException;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
* Wrapper interface for internal User instances
|
||||
* 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.
|
||||
*/
|
||||
@SuppressWarnings("unused")
|
||||
public interface User extends PermissionObject {
|
||||
|
||||
/**
|
||||
* @return the users Mojang assigned unique id
|
||||
*/
|
||||
UUID getUuid();
|
||||
|
||||
/**
|
||||
* @return the Users Username
|
||||
*/
|
||||
String getName();
|
||||
|
||||
/**
|
||||
* Gets the users primary group
|
||||
* @return the users primary group
|
||||
*/
|
||||
String getPrimaryGroup();
|
||||
|
||||
/**
|
||||
* Sets a users primary group
|
||||
* @param s the new primary group
|
||||
* @throws ObjectAlreadyHasException if the user already has this set as their primary group
|
||||
*/
|
||||
void setPrimaryGroup(String s) throws ObjectAlreadyHasException;
|
||||
|
||||
/**
|
||||
* Refresh and re-assign the users permissions
|
||||
*/
|
||||
void refreshPermissions();
|
||||
|
||||
/**
|
||||
* 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
|
||||
*/
|
||||
boolean isInGroup(Group group);
|
||||
|
||||
/**
|
||||
* Check to see if a user is a member of a group on a specific server
|
||||
* @param group The group to check membership of
|
||||
* @param server The server to check on
|
||||
* @return true if the user is a member of the group
|
||||
*/
|
||||
boolean isInGroup(Group group, String server);
|
||||
|
||||
/**
|
||||
* Check to see if a user is a member of a group on a specific server
|
||||
* @param group The group to check membership of
|
||||
* @param server The server to check on
|
||||
* @param world The world to check on
|
||||
* @return true if the user is a member of the group
|
||||
*/
|
||||
boolean isInGroup(Group group, String server, String world);
|
||||
|
||||
/**
|
||||
* Add a user to a group
|
||||
* @param group The group to add the user to
|
||||
* @throws ObjectAlreadyHasException if the user is already a member of the group
|
||||
*/
|
||||
void addGroup(Group group) throws ObjectAlreadyHasException;
|
||||
|
||||
/**
|
||||
* Add a user to a group on a specific server
|
||||
* @param group The group to add the user to
|
||||
* @param server The server to add the group on
|
||||
* @throws ObjectAlreadyHasException if the user is already a member of the group on that server
|
||||
*/
|
||||
void addGroup(Group group, String server) throws ObjectAlreadyHasException;
|
||||
|
||||
/**
|
||||
* Add a user to a group on a specific server
|
||||
* @param group The group to add the user to
|
||||
* @param server The server to add the group on
|
||||
* @param world The world to add the group on
|
||||
* @throws ObjectAlreadyHasException if the user is already a member of the group on that server
|
||||
*/
|
||||
void addGroup(Group group, String server, String world) throws ObjectAlreadyHasException;
|
||||
|
||||
/**
|
||||
* Add a user to a group on a specific server
|
||||
* @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
|
||||
*/
|
||||
void addGroup(Group group, long expireAt) throws ObjectAlreadyHasException;
|
||||
|
||||
/**
|
||||
* Add a user to a group on a specific server
|
||||
* @param group The group to add the user to
|
||||
* @param server The server to add the group on
|
||||
* @param expireAt when the group should expire
|
||||
* @throws ObjectAlreadyHasException if the user is already a member of the group on that server
|
||||
*/
|
||||
void addGroup(Group group, String server, long expireAt) throws ObjectAlreadyHasException;
|
||||
|
||||
/**
|
||||
* Add a user to a group on a specific server
|
||||
* @param group The group to add the user to
|
||||
* @param server The server to add the group on
|
||||
* @param world The world to add the group on
|
||||
* @param expireAt when the group should expire
|
||||
* @throws ObjectAlreadyHasException if the user is already a member of the group on that server
|
||||
*/
|
||||
void addGroup(Group group, String server, String world, long expireAt) throws ObjectAlreadyHasException;
|
||||
|
||||
/**
|
||||
* Remove the user from a group
|
||||
* @param group the group to remove the user from
|
||||
* @throws ObjectLacksException if the user isn't a member of the group
|
||||
*/
|
||||
void removeGroup(Group group) throws ObjectLacksException;
|
||||
|
||||
/**
|
||||
* Remove the user from a group
|
||||
* @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
|
||||
*/
|
||||
void removeGroup(Group group, boolean temporary) throws ObjectLacksException;
|
||||
|
||||
/**
|
||||
* Remove the user from a group
|
||||
* @param group The group to remove the user from
|
||||
* @param server The server to remove the group on
|
||||
* @throws ObjectLacksException if the user isn't a member of the group
|
||||
*/
|
||||
void removeGroup(Group group, String server) throws ObjectLacksException;
|
||||
|
||||
/**
|
||||
* Remove the user from a group
|
||||
* @param group The group to remove the user from
|
||||
* @param server The server to remove the group on
|
||||
* @param world The world to remove the group on
|
||||
* @throws ObjectLacksException if the user isn't a member of the group
|
||||
*/
|
||||
void removeGroup(Group group, String server, String world) throws ObjectLacksException;
|
||||
|
||||
/**
|
||||
* Remove the user from a group
|
||||
* @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
|
||||
*/
|
||||
void removeGroup(Group group, String server, boolean temporary) throws ObjectLacksException;
|
||||
|
||||
/**
|
||||
* Remove the user from a group
|
||||
* @param group The group to remove the user from
|
||||
* @param server The server to remove the group on
|
||||
* @param world The world to remove the group on
|
||||
* @param temporary if the group being removed is temporary
|
||||
* @throws ObjectLacksException if the user isn't a member of the group
|
||||
*/
|
||||
void removeGroup(Group group, String server, String world, boolean temporary) throws ObjectLacksException;
|
||||
|
||||
/**
|
||||
* Clear all of the users permission nodes
|
||||
*/
|
||||
void clearNodes();
|
||||
|
||||
/**
|
||||
* Get a {@link List} of all of the groups the user is a member of, on all servers
|
||||
* @return a {@link List} of group names
|
||||
*/
|
||||
List<String> getGroupNames();
|
||||
|
||||
/**
|
||||
* Get a {@link List} of the groups the user is a member of on a specific server
|
||||
* @param server the server to check
|
||||
* @param world the world to check
|
||||
* @return a {@link List} of group names
|
||||
*/
|
||||
List<String> getLocalGroups(String server, String world);
|
||||
|
||||
/**
|
||||
* Get a {@link List} of the groups the user is a member of on a specific server
|
||||
* @param server the server to check
|
||||
* @return a {@link List} of group names
|
||||
*/
|
||||
List<String> getLocalGroups(String server);
|
||||
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
package me.lucko.luckperms.api.data;
|
||||
|
||||
public interface Callback<T> {
|
||||
|
||||
void onComplete(T t);
|
||||
|
||||
}
|
||||
File renamed without changes.
@@ -0,0 +1,4 @@
|
||||
package me.lucko.luckperms.exceptions;
|
||||
|
||||
public class ObjectLacksException extends Exception {
|
||||
}
|
||||
+16
-9
@@ -4,13 +4,13 @@
|
||||
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</groupId>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
<groupId>me.lucko.luckperms</groupId>
|
||||
<version>1.5</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<artifactId>luckperms-bukkit</artifactId>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
<version>1.5</version>
|
||||
<packaging>jar</packaging>
|
||||
<name>LuckPerms</name>
|
||||
|
||||
@@ -28,7 +28,7 @@
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
<version>3.2</version>
|
||||
<version>3.5.1</version>
|
||||
<configuration>
|
||||
<source>1.8</source>
|
||||
<target>1.8</target>
|
||||
@@ -37,7 +37,7 @@
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-shade-plugin</artifactId>
|
||||
<version>2.3</version>
|
||||
<version>2.4.3</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<phase>package</phase>
|
||||
@@ -65,15 +65,22 @@
|
||||
<dependency>
|
||||
<groupId>net.milkbowl.vault</groupId>
|
||||
<artifactId>VaultAPI</artifactId>
|
||||
<version>1.5</version>
|
||||
<version>1.6</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<!-- LuckPerms Common -->
|
||||
<dependency>
|
||||
<groupId>me.lucko</groupId>
|
||||
<groupId>me.lucko.luckperms</groupId>
|
||||
<artifactId>luckperms-common</artifactId>
|
||||
<version>${project.parent.version}</version>
|
||||
<version>1.5</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
<!-- LuckPerms API -->
|
||||
<dependency>
|
||||
<groupId>me.lucko.luckperms</groupId>
|
||||
<artifactId>luckperms-api</artifactId>
|
||||
<version>1.5</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
||||
</project>
|
||||
@@ -0,0 +1,49 @@
|
||||
package me.lucko.luckperms;
|
||||
|
||||
import me.lucko.luckperms.commands.CommandManager;
|
||||
import me.lucko.luckperms.commands.Sender;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandExecutor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.command.TabExecutor;
|
||||
|
||||
import java.lang.ref.WeakReference;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
class BukkitCommand extends CommandManager implements CommandExecutor, TabExecutor {
|
||||
BukkitCommand(LuckPermsPlugin plugin) {
|
||||
super(plugin);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
|
||||
return onCommand(makeSender(sender), label, Arrays.asList(args));
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public List<String> onTabComplete(CommandSender sender, Command command, String label, String[] args) {
|
||||
return onTabComplete(makeSender(sender), Arrays.asList(args));
|
||||
}
|
||||
|
||||
private static Sender makeSender(CommandSender sender) {
|
||||
return new Sender() {
|
||||
final WeakReference<CommandSender> cs = new WeakReference<>(sender);
|
||||
|
||||
@Override
|
||||
public void sendMessage(String s) {
|
||||
final CommandSender c = cs.get();
|
||||
if (c != null) {
|
||||
c.sendMessage(s);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasPermission(String node) {
|
||||
final CommandSender c = cs.get();
|
||||
return c != null && c.hasPermission(node);
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -7,65 +7,49 @@ import org.bukkit.configuration.file.YamlConfiguration;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
|
||||
public class BukkitConfig implements LPConfiguration {
|
||||
private final LPBukkitPlugin plugin;
|
||||
class BukkitConfig extends LPConfiguration<LPBukkitPlugin> {
|
||||
private YamlConfiguration configuration;
|
||||
|
||||
public BukkitConfig(LPBukkitPlugin plugin) {
|
||||
this.plugin = plugin;
|
||||
create();
|
||||
BukkitConfig(LPBukkitPlugin plugin) {
|
||||
super(plugin, "global", true, "sqlite");
|
||||
}
|
||||
|
||||
private void create() {
|
||||
File configFile = new File(plugin.getDataFolder(), "config.yml");
|
||||
@SuppressWarnings("ResultOfMethodCallIgnored")
|
||||
@Override
|
||||
protected void init() {
|
||||
File configFile = new File(getPlugin().getDataFolder(), "config.yml");
|
||||
|
||||
if (!configFile.exists()) {
|
||||
configFile.getParentFile().mkdirs();
|
||||
plugin.saveResource("config.yml", false);
|
||||
getPlugin().saveResource("config.yml", false);
|
||||
}
|
||||
|
||||
configuration = new YamlConfiguration();
|
||||
|
||||
try {
|
||||
configuration.load(configFile);
|
||||
|
||||
} catch (InvalidConfigurationException | IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getServer() {
|
||||
return configuration.getString("server");
|
||||
protected void set(String path, Object value) {
|
||||
configuration.set(path, value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getPrefix() {
|
||||
return configuration.getString("prefix");
|
||||
protected String getString(String path, String def) {
|
||||
return configuration.getString(path, def);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getSyncTime() {
|
||||
return configuration.getInt("sql.sync-minutes");
|
||||
protected int getInt(String path, int def) {
|
||||
return configuration.getInt(path, def);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDefaultGroupNode() {
|
||||
return "luckperms.group." + configuration.getString("default-group");
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDefaultGroupName() {
|
||||
return configuration.getString("default-group");
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean getIncludeGlobalPerms() {
|
||||
return configuration.getBoolean("include-global");
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDatabaseValue(String value) {
|
||||
return configuration.getString("sql." + value);
|
||||
protected boolean getBoolean(String path, boolean def) {
|
||||
return configuration.getBoolean(path, def);
|
||||
}
|
||||
}
|
||||
@@ -1,30 +0,0 @@
|
||||
package me.lucko.luckperms;
|
||||
|
||||
import me.lucko.luckperms.commands.CommandManager;
|
||||
import me.lucko.luckperms.commands.Sender;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandExecutor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
class CommandManagerBukkit extends CommandManager implements CommandExecutor {
|
||||
CommandManagerBukkit(LuckPermsPlugin plugin) {
|
||||
super(plugin);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
|
||||
return onCommand(new Sender() {
|
||||
@Override
|
||||
public void sendMessage(String s) {
|
||||
sender.sendMessage(s);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasPermission(String node) {
|
||||
return sender.hasPermission(node);
|
||||
}
|
||||
}, Arrays.asList(args));
|
||||
}
|
||||
}
|
||||
@@ -1,37 +1,48 @@
|
||||
package me.lucko.luckperms;
|
||||
|
||||
import lombok.Getter;
|
||||
import me.lucko.luckperms.api.Logger;
|
||||
import me.lucko.luckperms.api.LuckPermsApi;
|
||||
import me.lucko.luckperms.api.implementation.ApiProvider;
|
||||
import me.lucko.luckperms.api.vault.VaultHook;
|
||||
import me.lucko.luckperms.data.Datastore;
|
||||
import me.lucko.luckperms.data.DatastoreConfiguration;
|
||||
import me.lucko.luckperms.data.HikariDatastore;
|
||||
import me.lucko.luckperms.data.methods.FlatfileDatastore;
|
||||
import me.lucko.luckperms.data.methods.MySQLDatastore;
|
||||
import me.lucko.luckperms.data.methods.SQLiteDatastore;
|
||||
import me.lucko.luckperms.groups.GroupManager;
|
||||
import me.lucko.luckperms.listeners.PlayerListener;
|
||||
import me.lucko.luckperms.runnables.UpdateTask;
|
||||
import me.lucko.luckperms.tracks.TrackManager;
|
||||
import me.lucko.luckperms.users.BukkitUserManager;
|
||||
import me.lucko.luckperms.users.UserManager;
|
||||
import me.lucko.luckperms.utils.LPConfiguration;
|
||||
import net.milkbowl.vault.permission.Permission;
|
||||
import me.lucko.luckperms.utils.LogUtil;
|
||||
import me.lucko.luckperms.utils.UuidCache;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.command.PluginCommand;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.plugin.PluginManager;
|
||||
import org.bukkit.plugin.RegisteredServiceProvider;
|
||||
import org.bukkit.plugin.ServicePriority;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@Getter
|
||||
public class LPBukkitPlugin extends JavaPlugin implements LuckPermsPlugin {
|
||||
public static final String VERSION = "v1.0";
|
||||
|
||||
private LPConfiguration configuration;
|
||||
private UserManager userManager;
|
||||
private GroupManager groupManager;
|
||||
private TrackManager trackManager;
|
||||
private Datastore datastore;
|
||||
private UuidCache uuidCache;
|
||||
|
||||
@Override
|
||||
public void onEnable() {
|
||||
getLog().info("Loading configuration...");
|
||||
configuration = new BukkitConfig(this);
|
||||
|
||||
// register events
|
||||
@@ -39,41 +50,82 @@ public class LPBukkitPlugin extends JavaPlugin implements LuckPermsPlugin {
|
||||
pm.registerEvents(new PlayerListener(this), this);
|
||||
|
||||
// register commands
|
||||
CommandManagerBukkit commandManager = new CommandManagerBukkit(this);
|
||||
getLog().info("Registering commands...");
|
||||
BukkitCommand commandManager = new BukkitCommand(this);
|
||||
PluginCommand main = getServer().getPluginCommand("luckperms");
|
||||
main.setExecutor(commandManager);
|
||||
main.setTabCompleter(commandManager);
|
||||
main.setAliases(Arrays.asList("perms", "lp", "permissions", "p", "perm"));
|
||||
|
||||
datastore = new HikariDatastore(this);
|
||||
datastore.init(new DatastoreConfiguration(
|
||||
configuration.getDatabaseValue("address"),
|
||||
configuration.getDatabaseValue("database"),
|
||||
configuration.getDatabaseValue("username"),
|
||||
configuration.getDatabaseValue("password")
|
||||
));
|
||||
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();
|
||||
|
||||
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();
|
||||
}
|
||||
|
||||
int mins = getConfiguration().getSyncTime();
|
||||
if (mins > 0) {
|
||||
long ticks = mins * 60 * 20;
|
||||
new UpdateTask(this).runTaskTimer(this, ticks, ticks);
|
||||
getServer().getScheduler().runTaskTimerAsynchronously(this, new UpdateTask(this), ticks, ticks);
|
||||
}
|
||||
|
||||
// Provide vault support
|
||||
getLog().info("Attempting to hook into Vault...");
|
||||
try {
|
||||
if (getServer().getPluginManager().isPluginEnabled("Vault")) {
|
||||
getServer().getServicesManager().register(Permission.class, new VaultHook(this), this, ServicePriority.High);
|
||||
getLogger().info("Registered Vault permission hook.");
|
||||
VaultHook.hook(this);
|
||||
getLog().info("Registered Vault permission & chat hook.");
|
||||
} else {
|
||||
getLogger().info("Vault not found.");
|
||||
getLog().info("Vault not found.");
|
||||
}
|
||||
} catch (Exception e) {
|
||||
getLogger().warning("Error whilst hooking into Vault.");
|
||||
getLog().severe("Error occurred whilst hooking into Vault.");
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
getLog().info("Registering API...");
|
||||
final ApiProvider provider = new ApiProvider(this);
|
||||
LuckPerms.registerProvider(provider);
|
||||
getServer().getServicesManager().register(LuckPermsApi.class, provider, this, ServicePriority.Normal);
|
||||
|
||||
getLog().info("Successfully loaded.");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDisable() {
|
||||
getLog().info("Closing datastore...");
|
||||
datastore.shutdown();
|
||||
|
||||
getLog().info("Unregistering API...");
|
||||
LuckPerms.unregisterProvider();
|
||||
getServer().getServicesManager().unregisterAll(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -86,15 +138,19 @@ public class LPBukkitPlugin extends JavaPlugin implements LuckPermsPlugin {
|
||||
Bukkit.getScheduler().runTask(this, r);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Logger getLog() {
|
||||
return LogUtil.wrap(getLogger());
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getVersion() {
|
||||
return VERSION;
|
||||
return getDescription().getVersion();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getPlayerStatus(UUID uuid) {
|
||||
if (getServer().getPlayer(uuid) != null) return "&aOnline";
|
||||
return "&cOffline";
|
||||
return getServer().getPlayer(getUuidCache().getExternalUUID(uuid)) != null ? "&aOnline" : "&cOffline";
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -102,8 +158,13 @@ public class LPBukkitPlugin extends JavaPlugin implements LuckPermsPlugin {
|
||||
return getServer().getOnlinePlayers().size();
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getPlayerList() {
|
||||
return getServer().getOnlinePlayers().stream().map(Player::getName).collect(Collectors.toList());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void runUpdateTask() {
|
||||
new UpdateTask(this).runTask(this);
|
||||
getServer().getScheduler().runTaskAsynchronously(this, new UpdateTask(this));
|
||||
}
|
||||
}
|
||||
@@ -1,150 +0,0 @@
|
||||
package me.lucko.luckperms;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import me.lucko.luckperms.exceptions.ObjectAlreadyHasException;
|
||||
import me.lucko.luckperms.exceptions.ObjectLacksPermissionException;
|
||||
import me.lucko.luckperms.groups.Group;
|
||||
import me.lucko.luckperms.users.User;
|
||||
import net.milkbowl.vault.permission.Permission;
|
||||
|
||||
@AllArgsConstructor
|
||||
public class VaultHook extends Permission {
|
||||
private final LPBukkitPlugin plugin;
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return "LuckPerms";
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isEnabled() {
|
||||
return plugin.getDatastore().isAcceptingLogins();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasSuperPermsCompat() {
|
||||
// Idk???
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean playerHas(String world, String player, String permission) {
|
||||
final User user = plugin.getUserManager().getUser(player);
|
||||
return user != null && user.hasPermission(permission, true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean playerAdd(String world, String player, String permission) {
|
||||
final User user = plugin.getUserManager().getUser(player);
|
||||
if (user == null) return false;
|
||||
|
||||
try {
|
||||
user.setPermission(permission, true);
|
||||
} catch (ObjectAlreadyHasException ignored) {}
|
||||
plugin.getUserManager().saveUser(user, plugin.getDatastore());
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean playerRemove(String world, String player, String permission) {
|
||||
final User user = plugin.getUserManager().getUser(player);
|
||||
if (user == null) return false;
|
||||
|
||||
try {
|
||||
user.unsetPermission(permission);
|
||||
} catch (ObjectLacksPermissionException ignored) {}
|
||||
plugin.getUserManager().saveUser(user, plugin.getDatastore());
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean groupHas(String world, String groupName, String permission) {
|
||||
final Group group = plugin.getGroupManager().getGroup(groupName);
|
||||
return group != null && group.hasPermission(permission, true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean groupAdd(String world, String groupName, String permission) {
|
||||
final Group group = plugin.getGroupManager().getGroup(groupName);
|
||||
if (group == null) return false;
|
||||
|
||||
try {
|
||||
group.setPermission(permission, true);
|
||||
} catch (ObjectAlreadyHasException ignored) {}
|
||||
plugin.runUpdateTask();
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean groupRemove(String world, String groupName, String permission) {
|
||||
final Group group = plugin.getGroupManager().getGroup(groupName);
|
||||
if (group == null) return false;
|
||||
|
||||
try {
|
||||
group.unsetPermission(permission);
|
||||
} catch (ObjectLacksPermissionException ignored) {}
|
||||
plugin.runUpdateTask();
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean playerInGroup(String world, String player, String group) {
|
||||
final User user = plugin.getUserManager().getUser(player);
|
||||
if (user == null) return false;
|
||||
|
||||
return user.getGroupNames().contains(group);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean playerAddGroup(String world, String player, String groupName) {
|
||||
final User user = plugin.getUserManager().getUser(player);
|
||||
if (user == null) return false;
|
||||
|
||||
final Group group = plugin.getGroupManager().getGroup(groupName);
|
||||
if (group == null) return false;
|
||||
|
||||
try {
|
||||
user.addGroup(group);
|
||||
} catch (ObjectAlreadyHasException ignored) {}
|
||||
plugin.getUserManager().saveUser(user, plugin.getDatastore());
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean playerRemoveGroup(String world, String player, String groupName) {
|
||||
final User user = plugin.getUserManager().getUser(player);
|
||||
if (user == null) return false;
|
||||
|
||||
final Group group = plugin.getGroupManager().getGroup(groupName);
|
||||
if (group == null) return false;
|
||||
|
||||
try {
|
||||
user.removeGroup(group);
|
||||
} catch (ObjectLacksPermissionException ignored) {}
|
||||
plugin.getUserManager().saveUser(user, plugin.getDatastore());
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String[] getPlayerGroups(String world, String player) {
|
||||
final User user = plugin.getUserManager().getUser(player);
|
||||
if (user == null) return new String[0];
|
||||
|
||||
return user.getGroupNames().toArray(new String[0]);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getPrimaryGroup(String world, String player) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String[] getGroups() {
|
||||
return plugin.getGroupManager().getGroups().keySet().toArray(new String[0]);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasGroupSupport() {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,127 @@
|
||||
package me.lucko.luckperms.api.vault;
|
||||
|
||||
import net.milkbowl.vault.chat.Chat;
|
||||
import net.milkbowl.vault.permission.Permission;
|
||||
|
||||
/**
|
||||
* Dummy class for hooking with Vault plugins that need both Chat + Perms
|
||||
* This doesn't return anything useful, or change anything internally
|
||||
*
|
||||
* Registered on the lowest priority so other plugins can override
|
||||
*/
|
||||
class VaultChatHook extends Chat {
|
||||
|
||||
VaultChatHook(Permission perms) {
|
||||
super(perms);
|
||||
}
|
||||
|
||||
private void throwNotSupported() {
|
||||
// throw new UnsupportedOperationException("LuckPerms cannot perform this operation.");
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return "LuckPerms";
|
||||
}
|
||||
|
||||
|
||||
public boolean isEnabled() {
|
||||
return true;
|
||||
}
|
||||
|
||||
public String getPlayerPrefix(String world, String player) {
|
||||
return "";
|
||||
}
|
||||
|
||||
public void setPlayerPrefix(String world, String player, String prefix) {
|
||||
throwNotSupported();
|
||||
}
|
||||
|
||||
public String getPlayerSuffix(String world, String player) {
|
||||
return "";
|
||||
}
|
||||
|
||||
public void setPlayerSuffix(String world, String player, String suffix) {
|
||||
throwNotSupported();
|
||||
}
|
||||
|
||||
public String getGroupPrefix(String world, String group) {
|
||||
return "";
|
||||
}
|
||||
|
||||
public void setGroupPrefix(String world, String group, String prefix) {
|
||||
throwNotSupported();
|
||||
}
|
||||
|
||||
public String getGroupSuffix(String world, String group) {
|
||||
return "";
|
||||
}
|
||||
|
||||
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();
|
||||
}
|
||||
|
||||
public int getGroupInfoInteger(String world, String group, String node, int defaultValue) {
|
||||
return defaultValue;
|
||||
}
|
||||
|
||||
public void setGroupInfoInteger(String world, String group, String node, int value) {
|
||||
throwNotSupported();
|
||||
}
|
||||
|
||||
public double getPlayerInfoDouble(String world, String player, String node, double defaultValue) {
|
||||
return defaultValue;
|
||||
}
|
||||
|
||||
public void setPlayerInfoDouble(String world, String player, String node, double value) {
|
||||
throwNotSupported();
|
||||
}
|
||||
|
||||
public double getGroupInfoDouble(String world, String group, String node, double defaultValue) {
|
||||
return defaultValue;
|
||||
}
|
||||
|
||||
public void setGroupInfoDouble(String world, String group, String node, double value) {
|
||||
throwNotSupported();
|
||||
}
|
||||
|
||||
public boolean getPlayerInfoBoolean(String world, String player, String node, boolean defaultValue) {
|
||||
return defaultValue;
|
||||
}
|
||||
|
||||
public void setPlayerInfoBoolean(String world, String player, String node, boolean value) {
|
||||
throwNotSupported();
|
||||
}
|
||||
|
||||
public boolean getGroupInfoBoolean(String world, String group, String node, boolean defaultValue) {
|
||||
return defaultValue;
|
||||
}
|
||||
|
||||
public void setGroupInfoBoolean(String world, String group, String node, boolean value) {
|
||||
throwNotSupported();
|
||||
}
|
||||
|
||||
public String getPlayerInfoString(String world, String player, String node, String defaultValue) {
|
||||
return defaultValue;
|
||||
}
|
||||
|
||||
public void setPlayerInfoString(String world, String player, String node, String value) {
|
||||
throwNotSupported();
|
||||
}
|
||||
|
||||
public String getGroupInfoString(String world, String group, String node, String defaultValue) {
|
||||
return defaultValue;
|
||||
}
|
||||
|
||||
public void setGroupInfoString(String world, String group, String node, String value) {
|
||||
throwNotSupported();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
package me.lucko.luckperms.api.vault;
|
||||
|
||||
import me.lucko.luckperms.LPBukkitPlugin;
|
||||
import net.milkbowl.vault.chat.Chat;
|
||||
import net.milkbowl.vault.permission.Permission;
|
||||
import org.bukkit.plugin.ServicePriority;
|
||||
import org.bukkit.plugin.ServicesManager;
|
||||
|
||||
public class VaultHook {
|
||||
|
||||
private static VaultChatHook chatHook = null;
|
||||
private static VaultPermissionHook permissionHook = null;
|
||||
|
||||
public static void hook(LPBukkitPlugin plugin) {
|
||||
try {
|
||||
if (permissionHook == null) {
|
||||
permissionHook = new VaultPermissionHook();
|
||||
}
|
||||
permissionHook.setPlugin(plugin);
|
||||
|
||||
if (chatHook == null) {
|
||||
chatHook = new VaultChatHook(permissionHook);
|
||||
}
|
||||
|
||||
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);
|
||||
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,197 @@
|
||||
package me.lucko.luckperms.api.vault;
|
||||
|
||||
import lombok.NonNull;
|
||||
import lombok.Setter;
|
||||
import me.lucko.luckperms.LPBukkitPlugin;
|
||||
import me.lucko.luckperms.exceptions.ObjectAlreadyHasException;
|
||||
import me.lucko.luckperms.exceptions.ObjectLacksException;
|
||||
import me.lucko.luckperms.groups.Group;
|
||||
import me.lucko.luckperms.users.User;
|
||||
import me.lucko.luckperms.utils.PermissionObject;
|
||||
import net.milkbowl.vault.permission.Permission;
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
class VaultPermissionHook extends Permission {
|
||||
|
||||
@Setter
|
||||
private LPBukkitPlugin plugin;
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return "LuckPerms";
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isEnabled() {
|
||||
return plugin.getDatastore().isAcceptingLogins();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasSuperPermsCompat() {
|
||||
return true;
|
||||
}
|
||||
|
||||
private boolean objectHas(String world, PermissionObject object, String permission) {
|
||||
if (object == null) return false;
|
||||
|
||||
if (world != null && !world.equals("")) {
|
||||
return object.hasPermission(permission, true, "global", world);
|
||||
} else {
|
||||
return object.hasPermission(permission, true);
|
||||
}
|
||||
}
|
||||
|
||||
private boolean objectAdd(String world, PermissionObject object, String permission) {
|
||||
if (object == null) return false;
|
||||
|
||||
try {
|
||||
if (world != null && !world.equals("")) {
|
||||
object.setPermission(permission, true, "global", world);
|
||||
} else {
|
||||
object.setPermission(permission, true);
|
||||
}
|
||||
} catch (ObjectAlreadyHasException ignored) {}
|
||||
|
||||
objectSave(object);
|
||||
return true;
|
||||
}
|
||||
|
||||
private boolean objectRemove(String world, PermissionObject object, String permission) {
|
||||
if (object == null) return false;
|
||||
|
||||
try {
|
||||
if (world != null && !world.equals("")) {
|
||||
object.unsetPermission(permission, "global", world);
|
||||
} else {
|
||||
object.unsetPermission(permission);
|
||||
}
|
||||
} catch (ObjectLacksException ignored) {}
|
||||
|
||||
objectSave(object);
|
||||
return true;
|
||||
}
|
||||
|
||||
private void objectSave(PermissionObject t) {
|
||||
if (t instanceof User) {
|
||||
((User) t).refreshPermissions();
|
||||
plugin.getDatastore().saveUser(((User) t), aBoolean -> {});
|
||||
}
|
||||
if (t instanceof Group) {
|
||||
plugin.getDatastore().saveGroup(((Group) t), aBoolean -> plugin.runUpdateTask());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean playerHas(String world, @NonNull String player, @NonNull String permission) {
|
||||
return objectHas(world, plugin.getUserManager().getUser(player), permission);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean playerAdd(String world, @NonNull String player, @NonNull String permission) {
|
||||
final User user = plugin.getUserManager().getUser(player);
|
||||
return objectAdd(world, user, permission);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean playerRemove(String world, @NonNull String player, @NonNull String permission) {
|
||||
final User user = plugin.getUserManager().getUser(player);
|
||||
return objectRemove(world, user, permission);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean groupHas(String world, @NonNull String groupName, @NonNull String permission) {
|
||||
final Group group = plugin.getGroupManager().getGroup(groupName);
|
||||
return objectHas(world, group, permission);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean groupAdd(String world, @NonNull String groupName, @NonNull String permission) {
|
||||
final Group group = plugin.getGroupManager().getGroup(groupName);
|
||||
return objectAdd(world, group, permission);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean groupRemove(String world, @NonNull String groupName, @NonNull String permission) {
|
||||
final Group group = plugin.getGroupManager().getGroup(groupName);
|
||||
return objectRemove(world, group, permission);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean playerInGroup(String world, @NonNull String player, @NonNull String group) {
|
||||
final User user = plugin.getUserManager().getUser(player);
|
||||
if (user == null) return false;
|
||||
|
||||
final Group group1 = plugin.getGroupManager().getGroup(group);
|
||||
if (group1 == null) return false;
|
||||
|
||||
if (world != null && !world.equals("")) {
|
||||
return user.isInGroup(group1, "global", world);
|
||||
} else {
|
||||
return user.isInGroup(group1);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean playerAddGroup(String world, @NonNull String player, @NonNull String groupName) {
|
||||
final User user = plugin.getUserManager().getUser(player);
|
||||
if (user == null) return false;
|
||||
|
||||
final Group group = plugin.getGroupManager().getGroup(groupName);
|
||||
if (group == null) return false;
|
||||
|
||||
try {
|
||||
if (world != null && !world.equals("")) {
|
||||
user.addGroup(group, "global", world);
|
||||
} else {
|
||||
user.addGroup(group);
|
||||
}
|
||||
} catch (ObjectAlreadyHasException ignored) {}
|
||||
objectSave(user);
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean playerRemoveGroup(String world, @NonNull String player, @NonNull String groupName) {
|
||||
final User user = plugin.getUserManager().getUser(player);
|
||||
if (user == null) return false;
|
||||
|
||||
final Group group = plugin.getGroupManager().getGroup(groupName);
|
||||
if (group == null) return false;
|
||||
|
||||
try {
|
||||
if (world != null && !world.equals("")) {
|
||||
user.removeGroup(group, "global", world);
|
||||
} else {
|
||||
user.removeGroup(group);
|
||||
}
|
||||
} catch (ObjectLacksException ignored) {}
|
||||
objectSave(user);
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String[] getPlayerGroups(String world, @NonNull String player) {
|
||||
final User user = plugin.getUserManager().getUser(player);
|
||||
return (user == null) ? new String[0] :
|
||||
world != null && !world.equals("") ? user.getLocalGroups("global", world).toArray(new String[0]) :
|
||||
user.getGroupNames().toArray(new String[0]);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getPrimaryGroup(String world, @NonNull String player) {
|
||||
final User user = plugin.getUserManager().getUser(player);
|
||||
return (user == null) ? null : user.getPrimaryGroup();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String[] getGroups() {
|
||||
return plugin.getGroupManager().getGroups().keySet().toArray(new String[0]);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasGroupSupport() {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -2,39 +2,61 @@ package me.lucko.luckperms.listeners;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import me.lucko.luckperms.LPBukkitPlugin;
|
||||
import me.lucko.luckperms.commands.Util;
|
||||
import me.lucko.luckperms.constants.Message;
|
||||
import me.lucko.luckperms.users.BukkitUser;
|
||||
import me.lucko.luckperms.users.User;
|
||||
import org.bukkit.ChatColor;
|
||||
import me.lucko.luckperms.utils.UuidCache;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.player.AsyncPlayerPreLoginEvent;
|
||||
import org.bukkit.event.player.PlayerJoinEvent;
|
||||
import org.bukkit.event.player.PlayerLoginEvent;
|
||||
import org.bukkit.event.player.PlayerQuitEvent;
|
||||
import org.bukkit.event.player.*;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
@AllArgsConstructor
|
||||
public class PlayerListener implements Listener {
|
||||
private static final String KICK_MESSAGE = Util.color(Message.PREFIX + "User data could not be loaded. Please contact an administrator.");
|
||||
private final LPBukkitPlugin plugin;
|
||||
|
||||
@EventHandler
|
||||
public void onPlayerPreLogin(AsyncPlayerPreLoginEvent e) {
|
||||
final long startTime = System.currentTimeMillis();
|
||||
if (!plugin.getDatastore().isAcceptingLogins()) {
|
||||
e.disallow(AsyncPlayerPreLoginEvent.Result.KICK_OTHER, color(plugin.getConfiguration().getPrefix() +
|
||||
"&cError whilst validating login with the network. \nPlease contact an administrator."));
|
||||
// Datastore is disabled, prevent players from joining the server
|
||||
e.disallow(AsyncPlayerPreLoginEvent.Result.KICK_OTHER, KICK_MESSAGE);
|
||||
return;
|
||||
}
|
||||
plugin.getDatastore().loadOrCreateUser(e.getUniqueId(), e.getName());
|
||||
|
||||
final UuidCache cache = plugin.getUuidCache();
|
||||
if (!cache.isOnlineMode()) {
|
||||
UUID uuid = plugin.getDatastore().getUUID(e.getName());
|
||||
if (uuid != null) {
|
||||
cache.addToCache(e.getUniqueId(), uuid);
|
||||
} else {
|
||||
// No previous data for this player
|
||||
cache.addToCache(e.getUniqueId(), e.getUniqueId());
|
||||
plugin.getDatastore().saveUUIDData(e.getName(), e.getUniqueId(), b -> {});
|
||||
}
|
||||
} else {
|
||||
// Online mode, no cache needed. This is just for name -> uuid lookup.
|
||||
plugin.getDatastore().saveUUIDData(e.getName(), e.getUniqueId(), b -> {});
|
||||
}
|
||||
|
||||
plugin.getDatastore().loadOrCreateUser(cache.getUUID(e.getUniqueId()), e.getName());
|
||||
final long time = System.currentTimeMillis() - startTime;
|
||||
if (time >= 1000) {
|
||||
plugin.getLog().warn("Processing login for " + e.getName() + " took " + time + "ms.");
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onPlayerLogin(PlayerLoginEvent e) {
|
||||
Player player = e.getPlayer();
|
||||
User user = plugin.getUserManager().getUser(player.getUniqueId());
|
||||
final Player player = e.getPlayer();
|
||||
final User user = plugin.getUserManager().getUser(plugin.getUuidCache().getUUID(player.getUniqueId()));
|
||||
|
||||
if (user == null) {
|
||||
e.disallow(PlayerLoginEvent.Result.KICK_OTHER, color(plugin.getConfiguration().getPrefix() +
|
||||
"&cUser data could not be loaded. Please contact an administrator."));
|
||||
e.disallow(PlayerLoginEvent.Result.KICK_OTHER, KICK_MESSAGE);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -48,28 +70,32 @@ public class PlayerListener implements Listener {
|
||||
|
||||
@EventHandler
|
||||
public void onPlayerJoin(PlayerJoinEvent e) {
|
||||
// Save UUID data for the player
|
||||
plugin.getDatastore().saveUUIDData(e.getPlayer().getName(), e.getPlayer().getUniqueId(), success -> {});
|
||||
|
||||
User user = plugin.getUserManager().getUser(e.getPlayer().getUniqueId());
|
||||
if (user != null) {
|
||||
// Refresh permissions again
|
||||
user.refreshPermissions();
|
||||
}
|
||||
// Refresh permissions again
|
||||
refreshPlayer(e.getPlayer());
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onPlayerChangedWorld(PlayerChangedWorldEvent e) {
|
||||
refreshPlayer(e.getPlayer());
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onPlayerQuit(PlayerQuitEvent e) {
|
||||
Player player = e.getPlayer();
|
||||
final Player player = e.getPlayer();
|
||||
final UuidCache cache = plugin.getUuidCache();
|
||||
|
||||
// Unload the user from memory when they disconnect
|
||||
User user = plugin.getUserManager().getUser(player.getUniqueId());
|
||||
// Unload the user from memory when they disconnect;
|
||||
cache.clearCache(player.getUniqueId());
|
||||
|
||||
final User user = plugin.getUserManager().getUser(cache.getUUID(player.getUniqueId()));
|
||||
plugin.getUserManager().unloadUser(user);
|
||||
}
|
||||
|
||||
public static String color(String string) {
|
||||
return ChatColor.translateAlternateColorCodes('&', string);
|
||||
private void refreshPlayer(Player p) {
|
||||
final User user = plugin.getUserManager().getUser(plugin.getUuidCache().getUUID(p.getUniqueId()));
|
||||
if (user != null) {
|
||||
user.refreshPermissions();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,25 +0,0 @@
|
||||
package me.lucko.luckperms.runnables;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import me.lucko.luckperms.LPBukkitPlugin;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.scheduler.BukkitRunnable;
|
||||
|
||||
@AllArgsConstructor
|
||||
public class UpdateTask extends BukkitRunnable {
|
||||
private final LPBukkitPlugin plugin;
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
plugin.getLogger().info("Running update task.");
|
||||
|
||||
// Re-load all of the groups
|
||||
plugin.getGroupManager().loadAllGroups();
|
||||
|
||||
// Refresh all online users.
|
||||
for (Player p : Bukkit.getOnlinePlayers()) {
|
||||
plugin.getDatastore().loadUser(p.getUniqueId(), success -> {});
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -3,7 +3,6 @@ package me.lucko.luckperms.users;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import me.lucko.luckperms.LPBukkitPlugin;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.permissions.PermissionAttachment;
|
||||
|
||||
@@ -18,35 +17,33 @@ public class BukkitUser extends User {
|
||||
@Setter
|
||||
private PermissionAttachment attachment = null;
|
||||
|
||||
public BukkitUser(UUID uuid, LPBukkitPlugin plugin) {
|
||||
BukkitUser(UUID uuid, LPBukkitPlugin plugin) {
|
||||
super(uuid, plugin);
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
public BukkitUser(UUID uuid, String username, LPBukkitPlugin plugin) {
|
||||
BukkitUser(UUID uuid, String username, LPBukkitPlugin plugin) {
|
||||
super(uuid, username, plugin);
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void refreshPermissions() {
|
||||
Player player = Bukkit.getPlayer(getUuid());
|
||||
if (player == null) return;
|
||||
plugin.doSync(() -> {
|
||||
final Player player = plugin.getServer().getPlayer(plugin.getUuidCache().getExternalUUID(getUuid()));
|
||||
if (player == null) return;
|
||||
|
||||
if (attachment == null) {
|
||||
getPlugin().getLogger().warning("User " + getName() + " does not have a permissions attachment defined.");
|
||||
setAttachment(player.addAttachment(plugin));
|
||||
}
|
||||
if (attachment == null) {
|
||||
getPlugin().getLog().warn("User " + getName() + " does not have a permissions attachment defined.");
|
||||
setAttachment(player.addAttachment(plugin));
|
||||
}
|
||||
|
||||
// Clear existing permissions
|
||||
for (String p : attachment.getPermissions().keySet()) {
|
||||
attachment.setPermission(p, false);
|
||||
}
|
||||
// Clear existing permissions
|
||||
attachment.getPermissions().keySet().forEach(p -> attachment.setPermission(p, false));
|
||||
|
||||
// Re-add all defined permissions for the user
|
||||
Map<String, Boolean> local = getLocalPermissions(getPlugin().getConfiguration().getServer(), null);
|
||||
for (String node : local.keySet()) {
|
||||
attachment.setPermission(node, local.get(node));
|
||||
}
|
||||
// Re-add all defined permissions for the user
|
||||
Map<String, Boolean> local = getLocalPermissions(getPlugin().getConfiguration().getServer(), player.getWorld().getName(), null);
|
||||
local.entrySet().forEach(e -> attachment.setPermission(e.getKey(), e.getValue()));
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -1,15 +1,17 @@
|
||||
package me.lucko.luckperms.users;
|
||||
|
||||
import me.lucko.luckperms.LPBukkitPlugin;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class BukkitUserManager extends UserManager {
|
||||
private final LPBukkitPlugin plugin;
|
||||
|
||||
public BukkitUserManager(LPBukkitPlugin plugin) {
|
||||
super(plugin);
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
@@ -21,7 +23,7 @@ public class BukkitUserManager extends UserManager {
|
||||
BukkitUser u = (BukkitUser) user;
|
||||
|
||||
if (u.getAttachment() != null) {
|
||||
Player player = Bukkit.getPlayer(u.getUuid());
|
||||
Player player = plugin.getServer().getPlayer(plugin.getUuidCache().getExternalUUID(u.getUuid()));
|
||||
|
||||
if (player != null) {
|
||||
player.removeAttachment(u.getAttachment());
|
||||
@@ -36,7 +38,7 @@ public class BukkitUserManager extends UserManager {
|
||||
|
||||
@Override
|
||||
public void cleanupUser(User user) {
|
||||
if (Bukkit.getPlayer(user.getUuid()) == null) {
|
||||
if (plugin.getServer().getPlayer(plugin.getUuidCache().getExternalUUID(user.getUuid())) == null) {
|
||||
unloadUser(user);
|
||||
}
|
||||
}
|
||||
@@ -50,4 +52,15 @@ public class BukkitUserManager extends UserManager {
|
||||
public User makeUser(UUID uuid, String username) {
|
||||
return new BukkitUser(uuid, username, plugin);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateAllUsers() {
|
||||
// Sometimes called async, so we need to get the players on the Bukkit thread.
|
||||
plugin.doSync(() -> {
|
||||
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)));
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -3,13 +3,29 @@
|
||||
# The name of the server, used for server specific permissions. Set to 'global' to disable.
|
||||
server: global
|
||||
|
||||
# The default group assigned to all user on join. e.g. a value of "default" = luckperms.group.default
|
||||
# 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.
|
||||
include-global: true
|
||||
|
||||
prefix: '&7&l[&b&lL&a&lP&7&l] &c'
|
||||
# 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.
|
||||
|
||||
# You should generally reflect the setting in server.properties here. Except when...
|
||||
|
||||
# 1. You have Spigot servers connected to a BungeeCord proxy, with online-mode set to false, but 'bungeecord' set to true in the spigot.yml
|
||||
# AND 'ip-forward' set to true in the BungeeCord config.yml
|
||||
# In this case, set online-mode in LuckPerms to true, despite the server being in offline mode.
|
||||
|
||||
# 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)
|
||||
online-mode: 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
|
||||
|
||||
sql:
|
||||
address: localhost:3306
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
name: LuckPerms
|
||||
author: Luck
|
||||
version: 1.0
|
||||
version: ${project.version}
|
||||
main: me.lucko.luckperms.LPBukkitPlugin
|
||||
softdepend: [Vault]
|
||||
description: A permissions plugin
|
||||
|
||||
+16
-10
@@ -4,19 +4,19 @@
|
||||
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</groupId>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
<groupId>me.lucko.luckperms</groupId>
|
||||
<version>1.5</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<artifactId>luckperms-bungee</artifactId>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
<version>1.5</version>
|
||||
<packaging>jar</packaging>
|
||||
<name>LuckPerms</name>
|
||||
|
||||
<build>
|
||||
<defaultGoal>clean package</defaultGoal>
|
||||
<finalName>LuckPerms</finalName>
|
||||
<finalName>LuckPermsBungee</finalName>
|
||||
<sourceDirectory>${basedir}/src/main/java</sourceDirectory>
|
||||
<resources>
|
||||
<resource>
|
||||
@@ -28,7 +28,7 @@
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
<version>3.2</version>
|
||||
<version>3.5.1</version>
|
||||
<configuration>
|
||||
<source>1.8</source>
|
||||
<target>1.8</target>
|
||||
@@ -37,7 +37,7 @@
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-shade-plugin</artifactId>
|
||||
<version>2.3</version>
|
||||
<version>2.4.3</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<phase>package</phase>
|
||||
@@ -59,16 +59,22 @@
|
||||
<groupId>net.md-5</groupId>
|
||||
<artifactId>bungeecord-api</artifactId>
|
||||
<version>1.9-SNAPSHOT</version>
|
||||
<type>jar</type>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<!-- LuckPerms Common -->
|
||||
<dependency>
|
||||
<groupId>me.lucko</groupId>
|
||||
<groupId>me.lucko.luckperms</groupId>
|
||||
<artifactId>luckperms-common</artifactId>
|
||||
<version>${project.parent.version}</version>
|
||||
<version>1.5</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
<!-- LuckPerms API -->
|
||||
<dependency>
|
||||
<groupId>me.lucko.luckperms</groupId>
|
||||
<artifactId>luckperms-api</artifactId>
|
||||
<version>1.5</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
</project>
|
||||
</project>
|
||||
@@ -0,0 +1,50 @@
|
||||
package me.lucko.luckperms;
|
||||
|
||||
import me.lucko.luckperms.commands.CommandManager;
|
||||
import me.lucko.luckperms.commands.Sender;
|
||||
import net.md_5.bungee.api.CommandSender;
|
||||
import net.md_5.bungee.api.chat.TextComponent;
|
||||
import net.md_5.bungee.api.plugin.Command;
|
||||
import net.md_5.bungee.api.plugin.TabExecutor;
|
||||
|
||||
import java.lang.ref.WeakReference;
|
||||
import java.util.Arrays;
|
||||
|
||||
class BungeeCommand extends Command implements TabExecutor {
|
||||
private final CommandManager manager;
|
||||
|
||||
public BungeeCommand(CommandManager manager) {
|
||||
super("luckpermsbungee", null, "bperms", "lpb", "bpermissions", "bp", "bperm");
|
||||
this.manager = manager;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(CommandSender sender, String[] args) {
|
||||
manager.onCommand(makeSender(sender), "bperms", Arrays.asList(args));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Iterable<String> onTabComplete(CommandSender sender, String[] args) {
|
||||
return manager.onTabComplete(makeSender(sender), Arrays.asList(args));
|
||||
}
|
||||
|
||||
private static Sender makeSender(CommandSender sender) {
|
||||
return new Sender() {
|
||||
final WeakReference<CommandSender> cs = new WeakReference<>(sender);
|
||||
|
||||
@Override
|
||||
public void sendMessage(String s) {
|
||||
final CommandSender c = cs.get();
|
||||
if (c != null) {
|
||||
c.sendMessage(new TextComponent(s));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasPermission(String node) {
|
||||
final CommandSender c = cs.get();
|
||||
return c != null && c.hasPermission(node);
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -10,29 +10,20 @@ import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.nio.file.Files;
|
||||
|
||||
public class BungeeConfig implements LPConfiguration {
|
||||
private final LPBungeePlugin plugin;
|
||||
class BungeeConfig extends LPConfiguration<LPBungeePlugin> {
|
||||
private Configuration configuration;
|
||||
|
||||
public BungeeConfig(LPBungeePlugin plugin) {
|
||||
this.plugin = plugin;
|
||||
reload();
|
||||
}
|
||||
|
||||
private void reload() {
|
||||
try {
|
||||
configuration = ConfigurationProvider.getProvider(YamlConfiguration.class).load(makeFile("config.yml"));
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
BungeeConfig(LPBungeePlugin plugin) {
|
||||
super(plugin, "bungee", false, "flatfile");
|
||||
}
|
||||
|
||||
@SuppressWarnings("ResultOfMethodCallIgnored")
|
||||
private File makeFile(String file) throws IOException {
|
||||
File cfg = new File(plugin.getDataFolder(), file);
|
||||
File cfg = new File(getPlugin().getDataFolder(), file);
|
||||
|
||||
if (!cfg.exists()) {
|
||||
plugin.getDataFolder().mkdir();
|
||||
try (InputStream is = plugin.getResourceAsStream(file)) {
|
||||
getPlugin().getDataFolder().mkdir();
|
||||
try (InputStream is = getPlugin().getResourceAsStream(file)) {
|
||||
Files.copy(is, cfg.toPath());
|
||||
}
|
||||
}
|
||||
@@ -40,39 +31,32 @@ public class BungeeConfig implements LPConfiguration {
|
||||
return cfg;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public String getServer() {
|
||||
return configuration.getString("server");
|
||||
protected void init() {
|
||||
try {
|
||||
configuration = ConfigurationProvider.getProvider(YamlConfiguration.class).load(makeFile("config.yml"));
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getPrefix() {
|
||||
return configuration.getString("prefix");
|
||||
protected void set(String path, Object value) {
|
||||
configuration.set(path, value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getSyncTime() {
|
||||
return configuration.getInt("sql.sync-minutes");
|
||||
protected String getString(String path, String def) {
|
||||
return configuration.getString(path, def);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDefaultGroupNode() {
|
||||
return "luckperms.group." + configuration.getString("default-group");
|
||||
protected int getInt(String path, int def) {
|
||||
return configuration.getInt(path, def);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDefaultGroupName() {
|
||||
return configuration.getString("default-group");
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean getIncludeGlobalPerms() {
|
||||
return configuration.getBoolean("include-global");
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDatabaseValue(String value) {
|
||||
return configuration.getString("sql." + value);
|
||||
protected boolean getBoolean(String path, boolean def) {
|
||||
return configuration.getBoolean(path, def);
|
||||
}
|
||||
}
|
||||
@@ -1,83 +1,116 @@
|
||||
package me.lucko.luckperms;
|
||||
|
||||
import lombok.Getter;
|
||||
import me.lucko.luckperms.api.Logger;
|
||||
import me.lucko.luckperms.api.implementation.ApiProvider;
|
||||
import me.lucko.luckperms.commands.CommandManager;
|
||||
import me.lucko.luckperms.data.Datastore;
|
||||
import me.lucko.luckperms.data.DatastoreConfiguration;
|
||||
import me.lucko.luckperms.data.HikariDatastore;
|
||||
import me.lucko.luckperms.data.methods.FlatfileDatastore;
|
||||
import me.lucko.luckperms.data.methods.MySQLDatastore;
|
||||
import me.lucko.luckperms.groups.GroupManager;
|
||||
import me.lucko.luckperms.listeners.PlayerListener;
|
||||
import me.lucko.luckperms.runnables.UpdateTask;
|
||||
import me.lucko.luckperms.tracks.TrackManager;
|
||||
import me.lucko.luckperms.users.BungeeUserManager;
|
||||
import me.lucko.luckperms.users.UserManager;
|
||||
import me.lucko.luckperms.utils.LPConfiguration;
|
||||
import me.lucko.luckperms.utils.LogUtil;
|
||||
import me.lucko.luckperms.utils.UuidCache;
|
||||
import net.md_5.bungee.api.connection.ProxiedPlayer;
|
||||
import net.md_5.bungee.api.plugin.Plugin;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@Getter
|
||||
public class LPBungeePlugin extends Plugin implements LuckPermsPlugin {
|
||||
public static final String VERSION = "v1.0";
|
||||
|
||||
@Getter
|
||||
LPConfiguration configuration;
|
||||
|
||||
@Getter
|
||||
UserManager userManager;
|
||||
|
||||
@Getter
|
||||
GroupManager groupManager;
|
||||
|
||||
@Getter
|
||||
Datastore datastore;
|
||||
private LPConfiguration configuration;
|
||||
private UserManager userManager;
|
||||
private GroupManager groupManager;
|
||||
private TrackManager trackManager;
|
||||
private Datastore datastore;
|
||||
private UuidCache uuidCache;
|
||||
|
||||
@Override
|
||||
public void onEnable() {
|
||||
getLog().info("Loading configuration...");
|
||||
configuration = new BungeeConfig(this);
|
||||
|
||||
// register events
|
||||
getProxy().getPluginManager().registerListener(this, new PlayerListener(this));
|
||||
|
||||
// register commands
|
||||
getProxy().getPluginManager().registerCommand(this, new MainCommand(new CommandManager(this)));
|
||||
getLog().info("Registering commands...");
|
||||
getProxy().getPluginManager().registerCommand(this, new BungeeCommand(new CommandManager(this)));
|
||||
|
||||
datastore = new HikariDatastore(this);
|
||||
datastore.init(new DatastoreConfiguration(
|
||||
configuration.getDatabaseValue("address"),
|
||||
configuration.getDatabaseValue("database"),
|
||||
configuration.getDatabaseValue("username"),
|
||||
configuration.getDatabaseValue("password")
|
||||
));
|
||||
// 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();
|
||||
|
||||
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();
|
||||
}
|
||||
|
||||
int mins = getConfiguration().getSyncTime();
|
||||
if (mins > 0) {
|
||||
getProxy().getScheduler().schedule(this, new UpdateTask(this), mins, mins, TimeUnit.MINUTES);
|
||||
}
|
||||
}
|
||||
|
||||
getLog().info("Registering API...");
|
||||
LuckPerms.registerProvider(new ApiProvider(this));
|
||||
|
||||
@Override
|
||||
public UserManager getUserManager() {
|
||||
return userManager;
|
||||
getLog().info("Successfully loaded.");
|
||||
}
|
||||
|
||||
@Override
|
||||
public GroupManager getGroupManager() {
|
||||
return groupManager;
|
||||
public void onDisable() {
|
||||
getLog().info("Closing datastore...");
|
||||
datastore.shutdown();
|
||||
|
||||
getLog().info("Unregistering API...");
|
||||
LuckPerms.unregisterProvider();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Logger getLog() {
|
||||
return LogUtil.wrap(getLogger());
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getVersion() {
|
||||
return VERSION;
|
||||
return getDescription().getVersion();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getPlayerStatus(UUID uuid) {
|
||||
if (getProxy().getPlayer(uuid) != null) return "&aOnline";
|
||||
return "&cOffline";
|
||||
return getProxy().getPlayer(getUuidCache().getExternalUUID(uuid)) != null ? "&aOnline" : "&cOffline";
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -86,18 +119,13 @@ public class LPBungeePlugin extends Plugin implements LuckPermsPlugin {
|
||||
}
|
||||
|
||||
@Override
|
||||
public LPConfiguration getConfiguration() {
|
||||
return configuration;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Datastore getDatastore() {
|
||||
return datastore;
|
||||
public List<String> getPlayerList() {
|
||||
return getProxy().getPlayers().stream().map(ProxiedPlayer::getName).collect(Collectors.toList());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void runUpdateTask() {
|
||||
new UpdateTask(this).run();
|
||||
doAsync(new UpdateTask(this));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -1,34 +0,0 @@
|
||||
package me.lucko.luckperms;
|
||||
|
||||
import me.lucko.luckperms.commands.CommandManager;
|
||||
import me.lucko.luckperms.commands.Sender;
|
||||
import net.md_5.bungee.api.CommandSender;
|
||||
import net.md_5.bungee.api.chat.TextComponent;
|
||||
import net.md_5.bungee.api.plugin.Command;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
public class MainCommand extends Command {
|
||||
private final CommandManager manager;
|
||||
|
||||
public MainCommand(CommandManager manager) {
|
||||
super("luckpermsbungee", "luckperms.use", "bperms", "lpb", "bpermissions", "bp", "bperm");
|
||||
this.manager = manager;
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(CommandSender sender, String[] args) {
|
||||
manager.onCommand(new Sender() {
|
||||
@Override
|
||||
public void sendMessage(String s) {
|
||||
sender.sendMessage(new TextComponent(s));
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasPermission(String node) {
|
||||
return sender.hasPermission(node);
|
||||
}
|
||||
}, Arrays.asList(args));
|
||||
}
|
||||
}
|
||||
@@ -3,42 +3,101 @@ package me.lucko.luckperms.listeners;
|
||||
import lombok.AllArgsConstructor;
|
||||
import me.lucko.luckperms.LPBungeePlugin;
|
||||
import me.lucko.luckperms.commands.Util;
|
||||
import me.lucko.luckperms.data.Datastore;
|
||||
import me.lucko.luckperms.constants.Message;
|
||||
import me.lucko.luckperms.users.User;
|
||||
import me.lucko.luckperms.utils.UuidCache;
|
||||
import net.md_5.bungee.api.chat.TextComponent;
|
||||
import net.md_5.bungee.api.connection.PendingConnection;
|
||||
import net.md_5.bungee.api.connection.ProxiedPlayer;
|
||||
import net.md_5.bungee.api.event.LoginEvent;
|
||||
import net.md_5.bungee.api.event.PlayerDisconnectEvent;
|
||||
import net.md_5.bungee.api.event.PostLoginEvent;
|
||||
import net.md_5.bungee.api.event.ServerSwitchEvent;
|
||||
import net.md_5.bungee.api.plugin.Listener;
|
||||
import net.md_5.bungee.event.EventHandler;
|
||||
|
||||
import java.lang.ref.WeakReference;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
@AllArgsConstructor
|
||||
public class PlayerListener implements Listener {
|
||||
|
||||
private static final TextComponent WARN_MESSAGE = new TextComponent(Util.color(
|
||||
Message.PREFIX + "Permissions data could not be loaded. Please contact an administrator.")
|
||||
);
|
||||
private final LPBungeePlugin plugin;
|
||||
|
||||
@EventHandler
|
||||
public void onPlayerLogin(LoginEvent e) {
|
||||
/* Delay the login here, as we want to cache UUID data before the player is connected to a backend bukkit server.
|
||||
This means that a player will have the same UUID across the network, even if parts of the network are running in
|
||||
Offline mode. */
|
||||
e.registerIntent(plugin);
|
||||
plugin.doAsync(() -> {
|
||||
final long startTime = System.currentTimeMillis();
|
||||
final UuidCache cache = plugin.getUuidCache();
|
||||
final PendingConnection c = e.getConnection();
|
||||
|
||||
if (!cache.isOnlineMode()) {
|
||||
UUID uuid = plugin.getDatastore().getUUID(c.getName());
|
||||
if (uuid != null) {
|
||||
cache.addToCache(c.getUniqueId(), uuid);
|
||||
} else {
|
||||
// No previous data for this player
|
||||
cache.addToCache(c.getUniqueId(), c.getUniqueId());
|
||||
plugin.getDatastore().saveUUIDData(c.getName(), c.getUniqueId());
|
||||
}
|
||||
} else {
|
||||
// Online mode, no cache needed. This is just for name -> uuid lookup.
|
||||
plugin.getDatastore().saveUUIDData(c.getName(), c.getUniqueId());
|
||||
}
|
||||
|
||||
// We have to make a new user on this thread whilst the connection is being held, or we get concurrency issues as the Bukkit server
|
||||
// and the BungeeCord server try to make a new user at the same time.
|
||||
plugin.getDatastore().loadOrCreateUser(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.");
|
||||
}
|
||||
e.completeIntent(plugin);
|
||||
});
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onPlayerPostLogin(PostLoginEvent e) {
|
||||
final ProxiedPlayer player = e.getPlayer();
|
||||
final WeakReference<ProxiedPlayer> p = new WeakReference<>(player);
|
||||
|
||||
plugin.getDatastore().loadOrCreateUser(player.getUniqueId(), player.getName(), success -> {
|
||||
if (!success) {
|
||||
e.getPlayer().sendMessage(new TextComponent(Util.color("&e&l[LP] &cPermissions data could not be loaded. Please contact an administrator.")));
|
||||
} else {
|
||||
User user = plugin.getUserManager().getUser(player.getUniqueId());
|
||||
user.refreshPermissions();
|
||||
}
|
||||
});
|
||||
|
||||
plugin.getDatastore().saveUUIDData(e.getPlayer().getName(), e.getPlayer().getUniqueId(), success -> {});
|
||||
final User user = plugin.getUserManager().getUser(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);
|
||||
} else {
|
||||
user.refreshPermissions();
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onPlayerQuit(PlayerDisconnectEvent e) {
|
||||
ProxiedPlayer player = e.getPlayer();
|
||||
final ProxiedPlayer player = e.getPlayer();
|
||||
final UuidCache cache = plugin.getUuidCache();
|
||||
|
||||
// Unload the user from memory when they disconnect
|
||||
User user = plugin.getUserManager().getUser(player.getUniqueId());
|
||||
// Unload the user from memory when they disconnect;
|
||||
cache.clearCache(player.getUniqueId());
|
||||
|
||||
final User user = plugin.getUserManager().getUser(cache.getUUID(player.getUniqueId()));
|
||||
plugin.getUserManager().unloadUser(user);
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onPlayerServerSwitch(ServerSwitchEvent e) {
|
||||
final User user = plugin.getUserManager().getUser(plugin.getUuidCache().getUUID(e.getPlayer().getUniqueId()));
|
||||
if (user != null) {
|
||||
user.refreshPermissions();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,23 +0,0 @@
|
||||
package me.lucko.luckperms.runnables;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import me.lucko.luckperms.LPBungeePlugin;
|
||||
import net.md_5.bungee.api.connection.ProxiedPlayer;
|
||||
|
||||
@AllArgsConstructor
|
||||
public class UpdateTask implements Runnable {
|
||||
private final LPBungeePlugin plugin;
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
plugin.getLogger().info("Running update task.");
|
||||
|
||||
// Re-load all of the groups
|
||||
plugin.getGroupManager().loadAllGroups();
|
||||
|
||||
// Refresh all online users.
|
||||
for (ProxiedPlayer p : plugin.getProxy().getPlayers()) {
|
||||
plugin.getDatastore().loadUser(p.getUniqueId(), success -> {});
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -9,34 +9,30 @@ import java.util.Map;
|
||||
import java.util.UUID;
|
||||
|
||||
public class BungeeUser extends User {
|
||||
|
||||
private final LPBungeePlugin plugin;
|
||||
|
||||
public BungeeUser(UUID uuid, LPBungeePlugin plugin) {
|
||||
BungeeUser(UUID uuid, LPBungeePlugin plugin) {
|
||||
super(uuid, plugin);
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
public BungeeUser(UUID uuid, String username, LPBungeePlugin plugin) {
|
||||
BungeeUser(UUID uuid, String username, LPBungeePlugin plugin) {
|
||||
super(uuid, username, plugin);
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void refreshPermissions() {
|
||||
ProxiedPlayer player = plugin.getProxy().getPlayer(getUuid());
|
||||
ProxiedPlayer player = plugin.getProxy().getPlayer(plugin.getUuidCache().getExternalUUID(getUuid()));
|
||||
if (player == null) return;
|
||||
|
||||
// Clear existing permissions
|
||||
Collection<String> perms = new ArrayList<>(player.getPermissions());
|
||||
for (String p : perms) {
|
||||
player.setPermission(p, false);
|
||||
}
|
||||
perms.forEach(p -> player.setPermission(p, false));
|
||||
|
||||
// Re-add all defined permissions for the user
|
||||
Map<String, Boolean> local = getLocalPermissions(getPlugin().getConfiguration().getServer(), null);
|
||||
for (String node : local.keySet()) {
|
||||
player.setPermission(node, local.get(node));
|
||||
}
|
||||
final String server = player.getServer() == null ? null : (player.getServer().getInfo() == null ? null : player.getServer().getInfo().getName());
|
||||
Map<String, Boolean> local = getLocalPermissions(getPlugin().getConfiguration().getServer(), server, null);
|
||||
local.entrySet().forEach(e -> player.setPermission(e.getKey(), e.getValue()));
|
||||
}
|
||||
}
|
||||
@@ -1,7 +1,6 @@
|
||||
package me.lucko.luckperms.users;
|
||||
|
||||
import me.lucko.luckperms.LPBungeePlugin;
|
||||
import net.md_5.bungee.api.connection.ProxiedPlayer;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
@@ -9,25 +8,22 @@ public class BungeeUserManager extends UserManager {
|
||||
private final LPBungeePlugin plugin;
|
||||
|
||||
public BungeeUserManager(LPBungeePlugin plugin) {
|
||||
super(plugin);
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void unloadUser(User user) {
|
||||
if (user != null) {
|
||||
|
||||
ProxiedPlayer player = plugin.getProxy().getPlayer(user.getUuid());
|
||||
if (player != null) {
|
||||
player.getPermissions().clear();
|
||||
}
|
||||
|
||||
// Cannot clear the ProxiedPlayer's permission map, they're leaving so that will get GCed anyway
|
||||
// Calling getPermissions.clear() throws an UnsupportedOperationException
|
||||
getUsers().remove(user.getUuid());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void cleanupUser(User user) {
|
||||
if (plugin.getProxy().getPlayer(user.getUuid()) == null) {
|
||||
if (plugin.getProxy().getPlayer(plugin.getUuidCache().getExternalUUID(user.getUuid())) == null) {
|
||||
unloadUser(user);
|
||||
}
|
||||
}
|
||||
@@ -41,4 +37,11 @@ public class BungeeUserManager extends UserManager {
|
||||
public User makeUser(UUID uuid, String username) {
|
||||
return new BungeeUser(uuid, username, plugin);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateAllUsers() {
|
||||
plugin.getProxy().getPlayers().stream()
|
||||
.map(p -> plugin.getUuidCache().getUUID(p.getUniqueId()))
|
||||
.forEach(u -> plugin.getDatastore().loadUser(u));
|
||||
}
|
||||
}
|
||||
@@ -3,13 +3,29 @@
|
||||
# The name of the server, used for server specific permissions. Set to 'global' to disable.
|
||||
server: bungee
|
||||
|
||||
# The default group assigned to all user on join. e.g. a value of "default" = luckperms.group.default
|
||||
# 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.
|
||||
include-global: false
|
||||
|
||||
prefix: '&7&l[&b&lL&a&lP&7&l] &c'
|
||||
# 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.
|
||||
|
||||
# You should generally reflect the setting in server.properties here. Except when...
|
||||
|
||||
# 1. You have Spigot servers connected to a BungeeCord proxy, with online-mode set to false, but 'bungeecord' set to true in the spigot.yml
|
||||
# AND 'ip-forward' set to true in the BungeeCord config.yml
|
||||
# In this case, set online-mode in LuckPerms to true, despite the server being in offline mode.
|
||||
|
||||
# 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)
|
||||
online-mode: 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
|
||||
|
||||
sql:
|
||||
address: localhost:3306
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
name: LuckPerms
|
||||
author: Luck
|
||||
version: ${project.version}
|
||||
main: me.lucko.luckperms.LPBungeePlugin
|
||||
author: Luck
|
||||
description: A permissions plugin
|
||||
+16
-4
@@ -4,18 +4,19 @@
|
||||
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</groupId>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
<groupId>me.lucko.luckperms</groupId>
|
||||
<version>1.5</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<version>1.5</version>
|
||||
<artifactId>luckperms-common</artifactId>
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
<version>3.2</version>
|
||||
<version>3.5.1</version>
|
||||
<configuration>
|
||||
<source>1.8</source>
|
||||
<target>1.8</target>
|
||||
@@ -23,4 +24,15 @@
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
</project>
|
||||
|
||||
<dependencies>
|
||||
<!-- LuckPerms API -->
|
||||
<dependency>
|
||||
<groupId>me.lucko.luckperms</groupId>
|
||||
<artifactId>luckperms-api</artifactId>
|
||||
<version>1.5</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
</project>
|
||||
@@ -1,27 +1,36 @@
|
||||
package me.lucko.luckperms;
|
||||
|
||||
import me.lucko.luckperms.api.Logger;
|
||||
import me.lucko.luckperms.data.Datastore;
|
||||
import me.lucko.luckperms.groups.GroupManager;
|
||||
import me.lucko.luckperms.tracks.TrackManager;
|
||||
import me.lucko.luckperms.users.UserManager;
|
||||
import me.lucko.luckperms.utils.LPConfiguration;
|
||||
import me.lucko.luckperms.utils.UuidCache;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
public interface LuckPermsPlugin {
|
||||
|
||||
/**
|
||||
* Retrieves the {@link UserManager} used to manage users and their permissions/groups
|
||||
* @return the {@link UserManager} object
|
||||
* @return the {@link UserManager} instance
|
||||
*/
|
||||
UserManager getUserManager();
|
||||
|
||||
/**
|
||||
* Retrieves the {@link GroupManager} used to manage the loaded groups and modify their permissions
|
||||
* @return the {@link GroupManager} object
|
||||
* @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
|
||||
@@ -38,7 +47,13 @@ public interface LuckPermsPlugin {
|
||||
* Retrieves the {@link Logger} for the plugin
|
||||
* @return the plugin's {@link Logger}
|
||||
*/
|
||||
Logger getLogger();
|
||||
Logger getLog();
|
||||
|
||||
/**
|
||||
* Retrieves the {@link UuidCache} for the plugin
|
||||
* @return the plugin's {@link UuidCache}
|
||||
*/
|
||||
UuidCache getUuidCache();
|
||||
|
||||
/**
|
||||
* @return the version of the plugin
|
||||
@@ -58,6 +73,12 @@ public interface LuckPermsPlugin {
|
||||
*/
|
||||
int getPlayerCount();
|
||||
|
||||
/**
|
||||
* Gets the usernames of the users online on the platform
|
||||
* @return a {@link List} of usernames
|
||||
*/
|
||||
List<String> getPlayerList();
|
||||
|
||||
/**
|
||||
* Runs an update task
|
||||
*/
|
||||
|
||||
@@ -0,0 +1,95 @@
|
||||
package me.lucko.luckperms.api.implementation;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.NonNull;
|
||||
import me.lucko.luckperms.LuckPermsPlugin;
|
||||
import me.lucko.luckperms.api.*;
|
||||
import me.lucko.luckperms.api.implementation.internal.DatastoreLink;
|
||||
import me.lucko.luckperms.api.implementation.internal.GroupLink;
|
||||
import me.lucko.luckperms.api.implementation.internal.TrackLink;
|
||||
import me.lucko.luckperms.api.implementation.internal.UserLink;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
* Provides static access to LuckPerms
|
||||
*/
|
||||
@AllArgsConstructor
|
||||
public class ApiProvider implements LuckPermsApi {
|
||||
private final LuckPermsPlugin plugin;
|
||||
|
||||
@Override
|
||||
public void runUpdateTask() {
|
||||
plugin.runUpdateTask();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getVersion() {
|
||||
return plugin.getVersion();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Datastore getDatastore() {
|
||||
return new DatastoreLink(plugin.getDatastore());
|
||||
}
|
||||
|
||||
@Override
|
||||
public Logger getLogger() {
|
||||
return plugin.getLog();
|
||||
}
|
||||
|
||||
@Override
|
||||
public User getUser(@NonNull UUID uuid) {
|
||||
final me.lucko.luckperms.users.User user = plugin.getUserManager().getUser(uuid);
|
||||
if (user == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return new UserLink(user);
|
||||
}
|
||||
|
||||
@Override
|
||||
public User getUser(@NonNull String name) {
|
||||
final me.lucko.luckperms.users.User user = plugin.getUserManager().getUser(name);
|
||||
if (user == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return new UserLink(user);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isUserLoaded(@NonNull UUID uuid) {
|
||||
return plugin.getUserManager().isLoaded(uuid);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Group getGroup(@NonNull String name) {
|
||||
final me.lucko.luckperms.groups.Group group = plugin.getGroupManager().getGroup(name);
|
||||
if (group == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return new GroupLink(group);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isGroupLoaded(@NonNull String name) {
|
||||
return plugin.getGroupManager().isLoaded(name);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Track getTrack(@NonNull String name) {
|
||||
final me.lucko.luckperms.tracks.Track track = plugin.getTrackManager().getTrack(name);
|
||||
if (track == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return new TrackLink(track);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isTrackLoaded(@NonNull String name) {
|
||||
return plugin.getTrackManager().isLoaded(name);
|
||||
}
|
||||
}
|
||||
+244
@@ -0,0 +1,244 @@
|
||||
package me.lucko.luckperms.api.implementation.internal;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.NonNull;
|
||||
import me.lucko.luckperms.api.Datastore;
|
||||
import me.lucko.luckperms.api.Group;
|
||||
import me.lucko.luckperms.api.Track;
|
||||
import me.lucko.luckperms.api.User;
|
||||
import me.lucko.luckperms.api.data.Callback;
|
||||
import me.lucko.luckperms.utils.Patterns;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
* Provides a link between {@link Datastore} and {@link me.lucko.luckperms.data.Datastore}
|
||||
*/
|
||||
@SuppressWarnings({"unused", "WeakerAccess"})
|
||||
public class DatastoreLink implements Datastore {
|
||||
|
||||
private final me.lucko.luckperms.data.Datastore master;
|
||||
private final Async async;
|
||||
private final Sync sync;
|
||||
|
||||
public DatastoreLink(@NonNull me.lucko.luckperms.data.Datastore master) {
|
||||
this.master = master;
|
||||
this.async = new Async(master);
|
||||
this.sync = new Sync(master);
|
||||
}
|
||||
|
||||
private static String checkUsername(String s) {
|
||||
if (s.length() > 16 || Patterns.NON_USERNAME.matcher(s).find()) {
|
||||
throw new IllegalArgumentException("Invalid username entry '" + s + "'. Usernames must be less than 16 chars" +
|
||||
" and only contain 'a-z A-Z 1-9 _'.");
|
||||
}
|
||||
return s;
|
||||
}
|
||||
|
||||
private static String checkName(String s) {
|
||||
if (s.length() > 36 || Patterns.NON_ALPHA_NUMERIC.matcher(s).find()) {
|
||||
throw new IllegalArgumentException("Invalid name entry '" + s + "'. Names must be less than 37 chars" +
|
||||
" and only contain 'a-z A-Z 1-9'.");
|
||||
}
|
||||
return s.toLowerCase();
|
||||
}
|
||||
|
||||
private static <T> Callback<T> checkCallback(Callback<T> c) {
|
||||
// If no callback was given, just send an empty one
|
||||
if (c == null) {
|
||||
c = t -> {};
|
||||
}
|
||||
return c;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return master.getName();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isAcceptingLogins() {
|
||||
return master.isAcceptingLogins();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Async async() {
|
||||
return async;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Sync sync() {
|
||||
return sync;
|
||||
}
|
||||
|
||||
@AllArgsConstructor
|
||||
public class Async implements Datastore.Async {
|
||||
private final me.lucko.luckperms.data.Datastore master;
|
||||
|
||||
@Override
|
||||
public void loadOrCreateUser(@NonNull UUID uuid, @NonNull String username, Callback<Boolean> callback) {
|
||||
master.loadOrCreateUser(uuid, checkUsername(username), checkCallback(callback));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void loadUser(@NonNull UUID uuid, Callback<Boolean> callback) {
|
||||
master.loadUser(uuid, checkCallback(callback));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void saveUser(@NonNull User user, Callback<Boolean> callback) {
|
||||
Utils.checkUser(user);
|
||||
master.saveUser(((UserLink) user).getMaster(), checkCallback(callback));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void createAndLoadGroup(@NonNull String name, Callback<Boolean> callback) {
|
||||
master.createAndLoadGroup(checkName(name), checkCallback(callback));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void loadGroup(@NonNull String name, Callback<Boolean> callback) {
|
||||
master.loadGroup(checkName(name), checkCallback(callback));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void loadAllGroups(Callback<Boolean> callback) {
|
||||
master.loadAllGroups(checkCallback(callback));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void saveGroup(@NonNull Group group, Callback<Boolean> callback) {
|
||||
Utils.checkGroup(group);
|
||||
master.saveGroup(((GroupLink) group).getMaster(), checkCallback(callback));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deleteGroup(@NonNull Group group, Callback<Boolean> callback) {
|
||||
Utils.checkGroup(group);
|
||||
master.deleteGroup(((GroupLink) group).getMaster(), checkCallback(callback));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void createAndLoadTrack(@NonNull String name, Callback<Boolean> callback) {
|
||||
master.createAndLoadTrack(checkName(name), checkCallback(callback));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void loadTrack(@NonNull String name, Callback<Boolean> callback) {
|
||||
master.loadTrack(checkName(name), checkCallback(callback));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void loadAllTracks(Callback<Boolean> callback) {
|
||||
master.loadAllTracks(checkCallback(callback));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void saveTrack(@NonNull Track track, Callback<Boolean> callback) {
|
||||
Utils.checkTrack(track);
|
||||
master.saveTrack(((TrackLink) track).getMaster(), checkCallback(callback));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deleteTrack(@NonNull Track track, Callback<Boolean> callback) {
|
||||
Utils.checkTrack(track);
|
||||
master.deleteTrack(((TrackLink) track).getMaster(), checkCallback(callback));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void saveUUIDData(@NonNull String username, @NonNull UUID uuid, Callback<Boolean> callback) {
|
||||
master.saveUUIDData(checkUsername(username), uuid, checkCallback(callback));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void getUUID(@NonNull String username, Callback<UUID> callback) {
|
||||
master.getUUID(checkUsername(username), checkCallback(callback));
|
||||
}
|
||||
}
|
||||
|
||||
@AllArgsConstructor
|
||||
public class Sync implements Datastore.Sync {
|
||||
private final me.lucko.luckperms.data.Datastore master;
|
||||
|
||||
@Override
|
||||
public boolean loadOrCreateUser(@NonNull UUID uuid, @NonNull String username) {
|
||||
return master.loadOrCreateUser(uuid, checkUsername(username));
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean loadUser(@NonNull UUID uuid) {
|
||||
return master.loadUser(uuid);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean saveUser(@NonNull User user) {
|
||||
Utils.checkUser(user);
|
||||
return master.saveUser(((UserLink) user).getMaster());
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean createAndLoadGroup(@NonNull String name) {
|
||||
return master.createAndLoadGroup(checkName(name));
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean loadGroup(@NonNull String name) {
|
||||
return master.loadGroup(checkName(name));
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean loadAllGroups() {
|
||||
return master.loadAllGroups();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean saveGroup(@NonNull Group group) {
|
||||
Utils.checkGroup(group);
|
||||
return master.saveGroup(((GroupLink) group).getMaster());
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean deleteGroup(@NonNull Group group) {
|
||||
Utils.checkGroup(group);
|
||||
return master.deleteGroup(((GroupLink) group).getMaster());
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean createAndLoadTrack(@NonNull String name) {
|
||||
return master.createAndLoadTrack(checkName(name));
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean loadTrack(@NonNull String name) {
|
||||
return master.loadTrack(checkName(name));
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean loadAllTracks() {
|
||||
return master.loadAllTracks();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean saveTrack(@NonNull Track track) {
|
||||
Utils.checkTrack(track);
|
||||
return master.saveTrack(((TrackLink) track).getMaster());
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean deleteTrack(@NonNull Track track) {
|
||||
Utils.checkTrack(track);
|
||||
return master.deleteTrack(((TrackLink) track).getMaster());
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean saveUUIDData(@NonNull String username, @NonNull UUID uuid) {
|
||||
return master.saveUUIDData(checkUsername(username), uuid);
|
||||
}
|
||||
|
||||
@Override
|
||||
public UUID getUUID(@NonNull String username) {
|
||||
return master.getUUID(checkUsername(username));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,140 @@
|
||||
package me.lucko.luckperms.api.implementation.internal;
|
||||
|
||||
import lombok.AccessLevel;
|
||||
import lombok.Getter;
|
||||
import lombok.NonNull;
|
||||
import me.lucko.luckperms.api.Group;
|
||||
import me.lucko.luckperms.exceptions.ObjectAlreadyHasException;
|
||||
import me.lucko.luckperms.exceptions.ObjectLacksException;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Provides a link between {@link Group} and {@link me.lucko.luckperms.groups.Group}
|
||||
*/
|
||||
@SuppressWarnings("unused")
|
||||
public class GroupLink extends PermissionObjectLink implements Group {
|
||||
|
||||
@Getter(AccessLevel.PACKAGE)
|
||||
private final me.lucko.luckperms.groups.Group master;
|
||||
|
||||
public GroupLink(@NonNull me.lucko.luckperms.groups.Group master) {
|
||||
super(master);
|
||||
this.master = master;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return master.getName();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean inheritsGroup(@NonNull Group group) {
|
||||
Utils.checkGroup(group);
|
||||
return master.inheritsGroup(((GroupLink) group).getMaster());
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean inheritsGroup(@NonNull Group group, @NonNull String server) {
|
||||
Utils.checkGroup(group);
|
||||
return master.inheritsGroup(((GroupLink) group).getMaster(), server);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean inheritsGroup(@NonNull Group group, @NonNull String server, @NonNull String world) {
|
||||
Utils.checkGroup(group);
|
||||
return master.inheritsGroup(((GroupLink) group).getMaster(), server, world);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setInheritGroup(@NonNull Group group) throws ObjectAlreadyHasException {
|
||||
Utils.checkGroup(group);
|
||||
master.setInheritGroup(((GroupLink) group).getMaster());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setInheritGroup(@NonNull Group group, @NonNull String server) throws ObjectAlreadyHasException {
|
||||
Utils.checkGroup(group);
|
||||
master.setInheritGroup(((GroupLink) group).getMaster(), checkServer(server));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setInheritGroup(@NonNull Group group, @NonNull String server, @NonNull String world) throws ObjectAlreadyHasException {
|
||||
Utils.checkGroup(group);
|
||||
master.setInheritGroup(((GroupLink) group).getMaster(), checkServer(server), world);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setInheritGroup(@NonNull Group group, @NonNull long expireAt) throws ObjectAlreadyHasException {
|
||||
Utils.checkGroup(group);
|
||||
master.setInheritGroup(((GroupLink) group).getMaster(), checkTime(expireAt));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setInheritGroup(@NonNull Group group, @NonNull String server, @NonNull long expireAt) throws ObjectAlreadyHasException {
|
||||
Utils.checkGroup(group);
|
||||
master.setInheritGroup(((GroupLink) group).getMaster(), checkServer(server), checkTime(expireAt));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setInheritGroup(@NonNull Group group, @NonNull String server, @NonNull String world, @NonNull long expireAt) throws ObjectAlreadyHasException {
|
||||
Utils.checkGroup(group);
|
||||
master.setInheritGroup(((GroupLink) group).getMaster(), checkServer(server), world, checkTime(expireAt));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void unsetInheritGroup(@NonNull Group group) throws ObjectLacksException {
|
||||
Utils.checkGroup(group);
|
||||
master.unsetInheritGroup(((GroupLink) group).getMaster());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void unsetInheritGroup(@NonNull Group group, @NonNull boolean temporary) throws ObjectLacksException {
|
||||
Utils.checkGroup(group);
|
||||
master.unsetInheritGroup(((GroupLink) group).getMaster(), temporary);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void unsetInheritGroup(@NonNull Group group, @NonNull String server) throws ObjectLacksException {
|
||||
Utils.checkGroup(group);
|
||||
master.unsetInheritGroup(((GroupLink) group).getMaster(), checkServer(server));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void unsetInheritGroup(@NonNull Group group, @NonNull String server, @NonNull String world) throws ObjectLacksException {
|
||||
Utils.checkGroup(group);
|
||||
master.unsetInheritGroup(((GroupLink) group).getMaster(), checkServer(server), world);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void unsetInheritGroup(@NonNull Group group, @NonNull String server, @NonNull boolean temporary) throws ObjectLacksException {
|
||||
Utils.checkGroup(group);
|
||||
master.unsetInheritGroup(((GroupLink) group).getMaster(), checkServer(server), temporary);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void unsetInheritGroup(@NonNull Group group, @NonNull String server, @NonNull String world, @NonNull boolean temporary) throws ObjectLacksException {
|
||||
Utils.checkGroup(group);
|
||||
master.unsetInheritGroup(((GroupLink) group).getMaster(), checkServer(server), world, temporary);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void clearNodes() {
|
||||
master.clearNodes();
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getGroupNames() {
|
||||
return master.getGroupNames();
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getLocalGroups(@NonNull String server, @NonNull String world) {
|
||||
return master.getLocalGroups(checkServer(server), world);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getLocalGroups(@NonNull String server) {
|
||||
return master.getLocalGroups(checkServer(server));
|
||||
}
|
||||
}
|
||||
+202
@@ -0,0 +1,202 @@
|
||||
package me.lucko.luckperms.api.implementation.internal;
|
||||
|
||||
import lombok.AccessLevel;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.NonNull;
|
||||
import me.lucko.luckperms.api.PermissionObject;
|
||||
import me.lucko.luckperms.exceptions.ObjectAlreadyHasException;
|
||||
import me.lucko.luckperms.exceptions.ObjectLacksException;
|
||||
import me.lucko.luckperms.utils.DateUtil;
|
||||
import me.lucko.luckperms.utils.Patterns;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* Provides a link between {@link PermissionObject} and {@link me.lucko.luckperms.utils.PermissionObject}
|
||||
*/
|
||||
@SuppressWarnings("unused")
|
||||
@AllArgsConstructor(access = AccessLevel.PACKAGE)
|
||||
class PermissionObjectLink implements PermissionObject {
|
||||
|
||||
@NonNull
|
||||
private final me.lucko.luckperms.utils.PermissionObject master;
|
||||
|
||||
static String checkServer(String s) {
|
||||
if (Patterns.NON_ALPHA_NUMERIC.matcher(s).find()) {
|
||||
throw new IllegalArgumentException("Invalid server entry '" + s + "'. Server names can only contain alphanumeric characters.");
|
||||
}
|
||||
return s;
|
||||
}
|
||||
|
||||
private static String checkNode(String s) {
|
||||
if (s.contains("/") || s.contains("$")) {
|
||||
throw new IllegalArgumentException("Invalid node entry '" + s + "'. Nodes cannot contain '/' or '$' characters.");
|
||||
}
|
||||
return s;
|
||||
}
|
||||
|
||||
static long checkTime(long l) {
|
||||
if (DateUtil.shouldExpire(l)) {
|
||||
throw new IllegalArgumentException("Unix time '" + l + "' is invalid, as it has already passed.");
|
||||
}
|
||||
return l;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getObjectName() {
|
||||
return master.getObjectName();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, Boolean> getNodes() {
|
||||
return Collections.unmodifiableMap(master.getNodes());
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasPermission(@NonNull String node, @NonNull boolean b) {
|
||||
return master.hasPermission(node, b);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasPermission(@NonNull String node, @NonNull boolean b, @NonNull String server) {
|
||||
return master.hasPermission(node, b, checkServer(server));
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasPermission(@NonNull String node, @NonNull boolean b, @NonNull String server, @NonNull String world) {
|
||||
return master.hasPermission(node, b, checkServer(server), world);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasPermission(@NonNull String node, @NonNull boolean b, @NonNull boolean temporary) {
|
||||
return master.hasPermission(node, b, temporary);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasPermission(@NonNull String node, @NonNull boolean b, @NonNull String server, @NonNull boolean temporary) {
|
||||
return master.hasPermission(node, b, checkServer(server), temporary);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasPermission(@NonNull String node, @NonNull boolean b, @NonNull String server, @NonNull String world, @NonNull boolean temporary) {
|
||||
return master.hasPermission(node, b, checkServer(server), world, temporary);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean inheritsPermission(@NonNull String node, @NonNull boolean b) {
|
||||
return master.inheritsPermission(node, b);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean inheritsPermission(@NonNull String node, @NonNull boolean b, @NonNull String server) {
|
||||
return master.inheritsPermission(node, b, checkServer(server));
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean inheritsPermission(@NonNull String node, @NonNull boolean b, @NonNull String server, @NonNull String world) {
|
||||
return master.inheritsPermission(node, b, checkServer(server), world);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean inheritsPermission(@NonNull String node, @NonNull boolean b, @NonNull boolean temporary) {
|
||||
return master.inheritsPermission(node, b, temporary);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean inheritsPermission(@NonNull String node, @NonNull boolean b, @NonNull String server, @NonNull boolean temporary) {
|
||||
return master.inheritsPermission(node, b, checkServer(server), temporary);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean inheritsPermission(@NonNull String node, @NonNull boolean b, @NonNull String server, @NonNull String world, @NonNull boolean temporary) {
|
||||
return master.inheritsPermission(node, b, checkServer(server), world, temporary);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setPermission(@NonNull String node, @NonNull boolean value) throws ObjectAlreadyHasException {
|
||||
master.setPermission(checkNode(node), value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setPermission(@NonNull String node, @NonNull boolean value, @NonNull String server) throws ObjectAlreadyHasException {
|
||||
master.setPermission(checkNode(node), value, checkServer(server));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setPermission(@NonNull String node, @NonNull boolean value, @NonNull String server, @NonNull String world) throws ObjectAlreadyHasException {
|
||||
master.setPermission(checkNode(node), value, checkServer(server), world);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setPermission(@NonNull String node, @NonNull boolean value, @NonNull long expireAt) throws ObjectAlreadyHasException {
|
||||
master.setPermission(checkNode(node), value, checkTime(expireAt));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setPermission(@NonNull String node, @NonNull boolean value, @NonNull String server, @NonNull long expireAt) throws ObjectAlreadyHasException {
|
||||
master.setPermission(checkNode(node), value, checkServer(server), checkTime(expireAt));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setPermission(@NonNull String node, @NonNull boolean value, @NonNull String server, @NonNull String world, @NonNull long expireAt) throws ObjectAlreadyHasException {
|
||||
master.setPermission(checkNode(node), value, checkServer(server), world, checkTime(expireAt));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void unsetPermission(@NonNull String node, @NonNull boolean temporary) throws ObjectLacksException {
|
||||
master.unsetPermission(checkNode(node), temporary);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void unsetPermission(@NonNull String node) throws ObjectLacksException {
|
||||
master.unsetPermission(checkNode(node));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void unsetPermission(@NonNull String node, @NonNull String server) throws ObjectLacksException {
|
||||
master.unsetPermission(checkNode(node), checkServer(server));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void unsetPermission(@NonNull String node, @NonNull String server, @NonNull String world) throws ObjectLacksException {
|
||||
master.unsetPermission(checkNode(node), checkServer(server), world);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void unsetPermission(@NonNull String node, @NonNull String server, @NonNull boolean temporary) throws ObjectLacksException {
|
||||
master.unsetPermission(checkNode(node), checkServer(server), temporary);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void unsetPermission(@NonNull String node, @NonNull String server, @NonNull String world, @NonNull boolean temporary) throws ObjectLacksException {
|
||||
master.unsetPermission(checkNode(node), checkServer(server), world, temporary);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, Boolean> getLocalPermissions(String server, String world, List<String> excludedGroups) {
|
||||
return master.getLocalPermissions(server, world, excludedGroups);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, Boolean> getLocalPermissions(String server, List<String> excludedGroups) {
|
||||
return master.getLocalPermissions(server, excludedGroups);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<Map.Entry<String, Boolean>, Long> getTemporaryNodes() {
|
||||
return master.getTemporaryNodes();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, Boolean> getPermanentNodes() {
|
||||
return master.getPermanentNodes();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void auditTemporaryPermissions() {
|
||||
master.auditTemporaryPermissions();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,90 @@
|
||||
package me.lucko.luckperms.api.implementation.internal;
|
||||
|
||||
import lombok.AccessLevel;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
import lombok.NonNull;
|
||||
import me.lucko.luckperms.api.Group;
|
||||
import me.lucko.luckperms.api.Track;
|
||||
import me.lucko.luckperms.exceptions.ObjectAlreadyHasException;
|
||||
import me.lucko.luckperms.exceptions.ObjectLacksException;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Provides a link between {@link Track} and {@link me.lucko.luckperms.tracks.Track}
|
||||
*/
|
||||
@SuppressWarnings("unused")
|
||||
@AllArgsConstructor
|
||||
public class TrackLink implements Track {
|
||||
|
||||
@NonNull
|
||||
@Getter(AccessLevel.PACKAGE)
|
||||
private final me.lucko.luckperms.tracks.Track master;
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return master.getName();
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getGroups() {
|
||||
return master.getGroups();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getSize() {
|
||||
return master.getSize();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getNext(@NonNull Group current) throws ObjectLacksException {
|
||||
Utils.checkGroup(current);
|
||||
return master.getNext(((GroupLink) current).getMaster());
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getPrevious(@NonNull Group current) throws ObjectLacksException {
|
||||
Utils.checkGroup(current);
|
||||
return master.getPrevious(((GroupLink) current).getMaster());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void appendGroup(@NonNull Group group) throws ObjectAlreadyHasException {
|
||||
Utils.checkGroup(group);
|
||||
master.appendGroup(((GroupLink) group).getMaster());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void insertGroup(@NonNull Group group, @NonNull int position) throws ObjectAlreadyHasException, IndexOutOfBoundsException {
|
||||
Utils.checkGroup(group);
|
||||
master.insertGroup(((GroupLink) group).getMaster(), position);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeGroup(@NonNull Group group) throws ObjectLacksException {
|
||||
Utils.checkGroup(group);
|
||||
master.removeGroup(((GroupLink) group).getMaster());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeGroup(@NonNull String group) throws ObjectLacksException {
|
||||
master.removeGroup(group);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean containsGroup(@NonNull Group group) {
|
||||
Utils.checkGroup(group);
|
||||
return master.containsGroup(((GroupLink) group).getMaster());
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean containsGroup(@NonNull String group) {
|
||||
return master.containsGroup(group);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void clearGroups() {
|
||||
master.clearGroups();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,171 @@
|
||||
package me.lucko.luckperms.api.implementation.internal;
|
||||
|
||||
import lombok.AccessLevel;
|
||||
import lombok.Getter;
|
||||
import lombok.NonNull;
|
||||
import me.lucko.luckperms.api.Group;
|
||||
import me.lucko.luckperms.api.User;
|
||||
import me.lucko.luckperms.exceptions.ObjectAlreadyHasException;
|
||||
import me.lucko.luckperms.exceptions.ObjectLacksException;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
* Provides a link between {@link User} and {@link me.lucko.luckperms.users.User}
|
||||
*/
|
||||
@SuppressWarnings("unused")
|
||||
public class UserLink extends PermissionObjectLink implements User {
|
||||
|
||||
@Getter(AccessLevel.PACKAGE)
|
||||
private final me.lucko.luckperms.users.User master;
|
||||
|
||||
public UserLink(@NonNull me.lucko.luckperms.users.User master) {
|
||||
super(master);
|
||||
this.master = master;
|
||||
}
|
||||
|
||||
@Override
|
||||
public UUID getUuid() {
|
||||
return master.getUuid();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return master.getName();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getPrimaryGroup() {
|
||||
return master.getPrimaryGroup();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setPrimaryGroup(String s) throws ObjectAlreadyHasException {
|
||||
if (getPrimaryGroup().equalsIgnoreCase(s)) {
|
||||
throw new ObjectAlreadyHasException();
|
||||
}
|
||||
|
||||
if (!getGroupNames().contains(s.toLowerCase())) {
|
||||
throw new IllegalStateException("User is not a member of that group.");
|
||||
}
|
||||
|
||||
master.setPrimaryGroup(s.toLowerCase());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void refreshPermissions() {
|
||||
master.refreshPermissions();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isInGroup(@NonNull Group group) {
|
||||
Utils.checkGroup(group);
|
||||
return master.isInGroup(((GroupLink) group).getMaster());
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isInGroup(@NonNull Group group, @NonNull String server) {
|
||||
Utils.checkGroup(group);
|
||||
return master.isInGroup(((GroupLink) group).getMaster(), server);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isInGroup(@NonNull Group group, @NonNull String server, @NonNull String world) {
|
||||
Utils.checkGroup(group);
|
||||
return master.isInGroup(((GroupLink) group).getMaster(), server, world);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addGroup(@NonNull Group group) throws ObjectAlreadyHasException {
|
||||
Utils.checkGroup(group);
|
||||
master.addGroup(((GroupLink) group).getMaster());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addGroup(@NonNull Group group, @NonNull String server) throws ObjectAlreadyHasException {
|
||||
Utils.checkGroup(group);
|
||||
master.addGroup(((GroupLink) group).getMaster(), checkServer(server));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addGroup(@NonNull Group group, @NonNull String server, @NonNull String world) throws ObjectAlreadyHasException {
|
||||
Utils.checkGroup(group);
|
||||
master.addGroup(((GroupLink) group).getMaster(), checkServer(server), world);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addGroup(@NonNull Group group, @NonNull long expireAt) throws ObjectAlreadyHasException {
|
||||
Utils.checkGroup(group);
|
||||
master.addGroup(((GroupLink) group).getMaster(), checkTime(expireAt));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addGroup(@NonNull Group group, @NonNull String server, @NonNull long expireAt) throws ObjectAlreadyHasException {
|
||||
Utils.checkGroup(group);
|
||||
master.addGroup(((GroupLink) group).getMaster(), checkServer(server), checkTime(expireAt));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addGroup(@NonNull Group group, @NonNull String server, @NonNull String world, @NonNull long expireAt) throws ObjectAlreadyHasException {
|
||||
Utils.checkGroup(group);
|
||||
master.addGroup(((GroupLink) group).getMaster(), checkServer(server), world, checkTime(expireAt));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeGroup(@NonNull Group group) throws ObjectLacksException {
|
||||
Utils.checkGroup(group);
|
||||
master.removeGroup(((GroupLink) group).getMaster());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeGroup(@NonNull Group group, @NonNull boolean temporary) throws ObjectLacksException {
|
||||
Utils.checkGroup(group);
|
||||
master.removeGroup(((GroupLink) group).getMaster(), temporary);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeGroup(@NonNull Group group, @NonNull String server) throws ObjectLacksException {
|
||||
Utils.checkGroup(group);
|
||||
master.removeGroup(((GroupLink) group).getMaster(), checkServer(server));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeGroup(@NonNull Group group, @NonNull String server, @NonNull String world) throws ObjectLacksException {
|
||||
Utils.checkGroup(group);
|
||||
master.removeGroup(((GroupLink) group).getMaster(), checkServer(server), world);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeGroup(@NonNull Group group, @NonNull String server, @NonNull boolean temporary) throws ObjectLacksException {
|
||||
Utils.checkGroup(group);
|
||||
master.removeGroup(((GroupLink) group).getMaster(), checkServer(server), temporary);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeGroup(@NonNull Group group, @NonNull String server, @NonNull String world, @NonNull boolean temporary) throws ObjectLacksException {
|
||||
Utils.checkGroup(group);
|
||||
master.removeGroup(((GroupLink) group).getMaster(), checkServer(server), world, temporary);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void clearNodes() {
|
||||
master.clearNodes();
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getGroupNames() {
|
||||
return master.getGroupNames();
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getLocalGroups(@NonNull String server, @NonNull String world) {
|
||||
return master.getLocalGroups(checkServer(server), world);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getLocalGroups(@NonNull String server) {
|
||||
return master.getLocalGroups(checkServer(server));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
package me.lucko.luckperms.api.implementation.internal;
|
||||
|
||||
import me.lucko.luckperms.api.Group;
|
||||
import me.lucko.luckperms.api.Track;
|
||||
import me.lucko.luckperms.api.User;
|
||||
|
||||
class Utils {
|
||||
|
||||
static void checkUser(User user) {
|
||||
if (!(user instanceof UserLink)) {
|
||||
throw new IllegalArgumentException("User instance cannot be handled by this implementation.");
|
||||
}
|
||||
}
|
||||
|
||||
static void checkGroup(Group group) {
|
||||
if (!(group instanceof GroupLink)) {
|
||||
throw new IllegalArgumentException("Group instance cannot be handled by this implementation.");
|
||||
}
|
||||
}
|
||||
|
||||
static void checkTrack(Track track) {
|
||||
if (!(track instanceof TrackLink)) {
|
||||
throw new IllegalArgumentException("Track instance cannot be handled by this implementation.");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -2,20 +2,28 @@ package me.lucko.luckperms.commands;
|
||||
|
||||
import lombok.Getter;
|
||||
import me.lucko.luckperms.LuckPermsPlugin;
|
||||
import me.lucko.luckperms.commands.group.CreateGroupCommand;
|
||||
import me.lucko.luckperms.commands.group.DeleteGroupCommand;
|
||||
import me.lucko.luckperms.commands.group.CreateGroup;
|
||||
import me.lucko.luckperms.commands.group.DeleteGroup;
|
||||
import me.lucko.luckperms.commands.group.GroupMainCommand;
|
||||
import me.lucko.luckperms.commands.group.ListGroupsCommand;
|
||||
import me.lucko.luckperms.commands.group.ListGroups;
|
||||
import me.lucko.luckperms.commands.group.subcommands.*;
|
||||
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.track.CreateTrack;
|
||||
import me.lucko.luckperms.commands.track.DeleteTrack;
|
||||
import me.lucko.luckperms.commands.track.ListTracks;
|
||||
import me.lucko.luckperms.commands.track.TrackMainCommand;
|
||||
import me.lucko.luckperms.commands.track.subcommands.*;
|
||||
import me.lucko.luckperms.commands.user.UserMainCommand;
|
||||
import me.lucko.luckperms.commands.user.subcommands.*;
|
||||
import me.lucko.luckperms.constants.Message;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.logging.Level;
|
||||
import java.util.Optional;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class CommandManager {
|
||||
private final LuckPermsPlugin plugin;
|
||||
@@ -28,86 +36,140 @@ public class CommandManager {
|
||||
|
||||
UserMainCommand userCommand = new UserMainCommand();
|
||||
this.registerMainCommand(userCommand);
|
||||
userCommand.registerSubCommand(new UserAddGroupCommand());
|
||||
userCommand.registerSubCommand(new UserClearCommand());
|
||||
userCommand.registerSubCommand(new UserGetUUIDCommand());
|
||||
userCommand.registerSubCommand(new UserHasPermCommand());
|
||||
userCommand.registerSubCommand(new UserInfoCommand());
|
||||
userCommand.registerSubCommand(new UserListNodesCommand());
|
||||
userCommand.registerSubCommand(new UserRemoveGroupCommand());
|
||||
userCommand.registerSubCommand(new UserSetPermissionCommand());
|
||||
userCommand.registerSubCommand(new UserUnSetPermissionCommand());
|
||||
userCommand.registerSubCommand(new UserInfo());
|
||||
userCommand.registerSubCommand(new UserGetUUID());
|
||||
userCommand.registerSubCommand(new UserListNodes());
|
||||
userCommand.registerSubCommand(new UserHasPerm());
|
||||
userCommand.registerSubCommand(new UserInheritsPerm());
|
||||
userCommand.registerSubCommand(new UserSetPermission());
|
||||
userCommand.registerSubCommand(new UserUnSetPermission());
|
||||
userCommand.registerSubCommand(new UserAddGroup());
|
||||
userCommand.registerSubCommand(new UserRemoveGroup());
|
||||
userCommand.registerSubCommand(new UserSetTempPermission());
|
||||
userCommand.registerSubCommand(new UserUnsetTempPermission());
|
||||
userCommand.registerSubCommand(new UserAddTempGroup());
|
||||
userCommand.registerSubCommand(new UserRemoveTempGroup());
|
||||
userCommand.registerSubCommand(new UserSetPrimaryGroup());
|
||||
userCommand.registerSubCommand(new UserShowTracks());
|
||||
userCommand.registerSubCommand(new UserPromote());
|
||||
userCommand.registerSubCommand(new UserDemote());
|
||||
userCommand.registerSubCommand(new UserShowPos());
|
||||
userCommand.registerSubCommand(new UserClear());
|
||||
|
||||
GroupMainCommand groupCommand = new GroupMainCommand();
|
||||
this.registerMainCommand(groupCommand);
|
||||
groupCommand.registerSubCommand(new GroupClearCommand());
|
||||
groupCommand.registerSubCommand(new GroupHasPermCommand());
|
||||
groupCommand.registerSubCommand(new GroupInfoCommand());
|
||||
groupCommand.registerSubCommand(new GroupListNodesCommand());
|
||||
groupCommand.registerSubCommand(new GroupSetInheritCommand());
|
||||
groupCommand.registerSubCommand(new GroupSetPermissionCommand());
|
||||
groupCommand.registerSubCommand(new GroupUnsetInheritCommand());
|
||||
groupCommand.registerSubCommand(new GroupUnSetPermissionCommand());
|
||||
groupCommand.registerSubCommand(new GroupInfo());
|
||||
groupCommand.registerSubCommand(new GroupListNodes());
|
||||
groupCommand.registerSubCommand(new GroupHasPerm());
|
||||
groupCommand.registerSubCommand(new GroupInheritsPerm());
|
||||
groupCommand.registerSubCommand(new GroupSetPermission());
|
||||
groupCommand.registerSubCommand(new GroupUnSetPermission());
|
||||
groupCommand.registerSubCommand(new GroupSetInherit());
|
||||
groupCommand.registerSubCommand(new GroupUnsetInherit());
|
||||
groupCommand.registerSubCommand(new GroupSetTempPermission());
|
||||
groupCommand.registerSubCommand(new GroupUnsetTempPermission());
|
||||
groupCommand.registerSubCommand(new GroupSetTempInherit());
|
||||
groupCommand.registerSubCommand(new GroupUnsetTempInherit());
|
||||
groupCommand.registerSubCommand(new GroupShowTracks());
|
||||
groupCommand.registerSubCommand(new GroupClear());
|
||||
|
||||
TrackMainCommand trackCommand = new TrackMainCommand();
|
||||
this.registerMainCommand(trackCommand);
|
||||
trackCommand.registerSubCommand(new TrackInfo());
|
||||
trackCommand.registerSubCommand(new TrackAppend());
|
||||
trackCommand.registerSubCommand(new TrackInsert());
|
||||
trackCommand.registerSubCommand(new TrackRemove());
|
||||
trackCommand.registerSubCommand(new TrackClear());
|
||||
|
||||
this.registerMainCommand(new CreateGroupCommand());
|
||||
this.registerMainCommand(new DeleteGroupCommand());
|
||||
this.registerMainCommand(new ListGroupsCommand());
|
||||
this.registerMainCommand(new DebugCommand());
|
||||
this.registerMainCommand(new InfoCommand());
|
||||
this.registerMainCommand(new SyncCommand());
|
||||
this.registerMainCommand(new InfoCommand());
|
||||
this.registerMainCommand(new DebugCommand());
|
||||
this.registerMainCommand(new CreateGroup());
|
||||
this.registerMainCommand(new DeleteGroup());
|
||||
this.registerMainCommand(new ListGroups());
|
||||
this.registerMainCommand(new CreateTrack());
|
||||
this.registerMainCommand(new DeleteTrack());
|
||||
this.registerMainCommand(new ListTracks());
|
||||
}
|
||||
|
||||
/**
|
||||
* Generic on command method to be called from the command executor object of the platform
|
||||
* @param sender who sent the command
|
||||
* @param label the command label used
|
||||
* @param args the arguments provided
|
||||
* @return if the command was successful (hint: it always is :> )
|
||||
* @return if the command was successful
|
||||
*/
|
||||
public boolean onCommand(Sender sender, List<String> args) {
|
||||
public boolean onCommand(Sender sender, String label, List<String> args) {
|
||||
if (args.size() == 0) {
|
||||
Util.sendPluginMessage(sender, "&6Running &bLuckPerms " + plugin.getVersion() + "&6.");
|
||||
|
||||
if (sender.hasPermission("luckperms.info")) {
|
||||
for (MainCommand c : mainCommands) {
|
||||
Util.sendPluginMessage(sender, "&e-> &d" + c.getUsage());
|
||||
}
|
||||
}
|
||||
|
||||
} else {
|
||||
String c = args.get(0);
|
||||
MainCommand main = null;
|
||||
|
||||
for (MainCommand mainCommand : mainCommands) {
|
||||
if (mainCommand.getName().equalsIgnoreCase(c)) {
|
||||
main = mainCommand;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (main == null) {
|
||||
Util.sendPluginMessage(sender, "Command not recognised.");
|
||||
return true;
|
||||
}
|
||||
|
||||
if (main.getRequiredArgsLength() == 0) {
|
||||
main.execute(plugin, sender, null);
|
||||
return true;
|
||||
}
|
||||
|
||||
if (args.size() == 1) {
|
||||
main.sendUsage(sender);
|
||||
return true;
|
||||
}
|
||||
|
||||
main.execute(plugin, sender, new ArrayList<>(args.subList(1, args.size())));
|
||||
sendCommandUsage(sender, label);
|
||||
return true;
|
||||
}
|
||||
|
||||
Optional<MainCommand> o = mainCommands.stream().filter(m -> m.getName().equalsIgnoreCase(args.get(0))).limit(1).findAny();
|
||||
|
||||
if (!o.isPresent()) {
|
||||
sendCommandUsage(sender, label);
|
||||
return true;
|
||||
}
|
||||
|
||||
final MainCommand main = o.get();
|
||||
if (!main.isAuthorized(sender)) {
|
||||
sendCommandUsage(sender, label);
|
||||
return true;
|
||||
}
|
||||
|
||||
if (main.getRequiredArgsLength() == 0) {
|
||||
main.execute(plugin, sender, null, label);
|
||||
return true;
|
||||
}
|
||||
|
||||
if (args.size() == 1) {
|
||||
main.sendUsage(sender, label);
|
||||
return true;
|
||||
}
|
||||
|
||||
main.execute(plugin, sender, new ArrayList<>(args.subList(1, args.size())), label);
|
||||
return true;
|
||||
|
||||
}
|
||||
|
||||
public void registerMainCommand(MainCommand command) {
|
||||
plugin.getLogger().log(Level.INFO, "[CommandManager] Registered main command '" + command.getName() + "'");
|
||||
/**
|
||||
* Generic tab complete method to be called from the command executor object of the platform
|
||||
* @param sender who is tab completing
|
||||
* @param args the arguments provided so far
|
||||
* @return a list of suggestions
|
||||
*/
|
||||
@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());
|
||||
|
||||
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(MainCommand::getName).map(String::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();
|
||||
if (!o.isPresent()) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
return o.get().onTabComplete(sender, args.subList(1, args.size()), plugin);
|
||||
}
|
||||
|
||||
private void registerMainCommand(MainCommand command) {
|
||||
plugin.getLog().info("[CommandManager] Registered main command '" + command.getName() + "'");
|
||||
mainCommands.add(command);
|
||||
}
|
||||
|
||||
private void sendCommandUsage(Sender sender, String label) {
|
||||
Message.INFO_BRIEF.send(sender, plugin.getVersion());
|
||||
|
||||
mainCommands.stream()
|
||||
.filter(c -> c.isAuthorized(sender))
|
||||
.forEach(c -> Util.sendPluginMessage(sender, "&e-> &d" + String.format(c.getUsage(), label)));
|
||||
}
|
||||
}
|
||||
@@ -1,42 +1,161 @@
|
||||
package me.lucko.luckperms.commands;
|
||||
|
||||
import lombok.Getter;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import me.lucko.luckperms.LuckPermsPlugin;
|
||||
import me.lucko.luckperms.api.data.Callback;
|
||||
import me.lucko.luckperms.constants.Message;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public abstract class MainCommand {
|
||||
@Getter
|
||||
@RequiredArgsConstructor
|
||||
public abstract class MainCommand<T> {
|
||||
|
||||
@Getter
|
||||
/**
|
||||
* The name of the main command
|
||||
*/
|
||||
private final String name;
|
||||
|
||||
@Getter
|
||||
/**
|
||||
* The command usage
|
||||
*/
|
||||
private final String usage;
|
||||
|
||||
@Getter
|
||||
/**
|
||||
* How many arguments are required for the command to run
|
||||
*/
|
||||
private final int requiredArgsLength;
|
||||
|
||||
public MainCommand(String name, String usage, int requiredArgsLength) {
|
||||
this.name = name;
|
||||
this.usage = usage;
|
||||
this.requiredArgsLength = requiredArgsLength;
|
||||
/**
|
||||
* A list of the sub commands under this main command
|
||||
*/
|
||||
@Getter
|
||||
private final List<SubCommand<T>> subCommands = new ArrayList<>();
|
||||
|
||||
/**
|
||||
* Called when this main command is ran
|
||||
* @param plugin a link to the main plugin instance
|
||||
* @param sender the sender to executed the command
|
||||
* @param args the stripped arguments given
|
||||
* @param label the command label used
|
||||
*/
|
||||
protected void execute(LuckPermsPlugin plugin, Sender sender, List<String> args, String label) {
|
||||
if (args.size() < 2) {
|
||||
sendUsage(sender, label);
|
||||
return;
|
||||
}
|
||||
|
||||
Optional<SubCommand<T>> o = subCommands.stream().filter(s -> s.getName().equalsIgnoreCase(args.get(1))).limit(1).findAny();
|
||||
|
||||
if (!o.isPresent()) {
|
||||
Message.COMMAND_NOT_RECOGNISED.send(sender);
|
||||
return;
|
||||
}
|
||||
|
||||
final SubCommand<T> sub = o.get();
|
||||
if (!sub.isAuthorized(sender)) {
|
||||
Message.COMMAND_NO_PERMISSION.send(sender);
|
||||
return;
|
||||
}
|
||||
|
||||
List<String> strippedArgs = new ArrayList<>();
|
||||
if (args.size() > 2) {
|
||||
strippedArgs.addAll(args.subList(2, args.size()));
|
||||
}
|
||||
|
||||
if (sub.getIsArgumentInvalid().test(strippedArgs.size())) {
|
||||
sub.sendUsage(sender, label);
|
||||
return;
|
||||
}
|
||||
|
||||
final String name = args.get(0).toLowerCase();
|
||||
getTarget(name, plugin, sender, t -> sub.execute(plugin, sender, t, strippedArgs, label));
|
||||
}
|
||||
|
||||
protected abstract void execute(LuckPermsPlugin plugin, Sender sender, List<String> args);
|
||||
public abstract List<? extends SubCommand> getSubCommands();
|
||||
/**
|
||||
* Gets the object the command is acting upon, and runs the callback if successful
|
||||
* @param target the name of the object to be looked up
|
||||
* @param plugin a link to the main plugin instance
|
||||
* @param sender the user who send the command (used to send error messages if the lookup was unsuccessful)
|
||||
* @param onSuccess the callback to run when the lookup is completed
|
||||
*/
|
||||
protected abstract void getTarget(String target, LuckPermsPlugin plugin, Sender sender, Callback<T> onSuccess);
|
||||
|
||||
/**
|
||||
* Get a list of objects for tab completion
|
||||
* @param plugin a link to the main plugin instance
|
||||
* @return a list of strings
|
||||
*/
|
||||
protected abstract List<String> getObjects(LuckPermsPlugin plugin);
|
||||
|
||||
/**
|
||||
* Send the command usage to a sender
|
||||
* @param sender the sender to send the usage to
|
||||
* @param label the command label used
|
||||
*/
|
||||
protected void sendUsage(Sender sender, String label) {
|
||||
if (getSubCommands().isEmpty()) {
|
||||
Util.sendPluginMessage(sender, "&e-> &d" + String.format(getUsage(), label));
|
||||
return;
|
||||
}
|
||||
|
||||
protected void sendUsage(Sender sender) {
|
||||
List<SubCommand> subs = getSubCommands().stream().filter(s -> s.isAuthorized(sender)).collect(Collectors.toList());
|
||||
if (subs.size() > 0) {
|
||||
Util.sendPluginMessage(sender, "&e" + getName() + " Sub Commands:");
|
||||
|
||||
for (SubCommand s : subs) {
|
||||
s.sendUsage(sender);
|
||||
s.sendUsage(sender, label);
|
||||
}
|
||||
|
||||
} else {
|
||||
Util.sendPluginMessage(sender, "You do not have permission to use this command!");
|
||||
Message.COMMAND_NO_PERMISSION.send(sender);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* If a sender has permission to use this command
|
||||
* @param sender the sender trying to use the command
|
||||
* @return true if the sender can use the command
|
||||
*/
|
||||
protected boolean isAuthorized(Sender sender) {
|
||||
return getSubCommands().stream().filter(sc -> sc.isAuthorized(sender)).count() != 0;
|
||||
}
|
||||
|
||||
protected List<String> onTabComplete(Sender sender, List<String> args, LuckPermsPlugin plugin) {
|
||||
final List<String> objects = getObjects(plugin);
|
||||
|
||||
if (args.size() <= 1) {
|
||||
if (args.isEmpty() || args.get(0).equalsIgnoreCase("")) {
|
||||
return objects;
|
||||
}
|
||||
|
||||
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());
|
||||
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(SubCommand::getName).map(String::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();
|
||||
if (!o.isPresent()) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
return o.get().onTabComplete(sender, args.subList(2, args.size()), plugin);
|
||||
}
|
||||
|
||||
public void registerSubCommand(SubCommand<T> subCommand) {
|
||||
subCommands.add(subCommand);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,53 @@
|
||||
package me.lucko.luckperms.commands;
|
||||
|
||||
import lombok.experimental.UtilityClass;
|
||||
|
||||
import java.util.Set;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.IntStream;
|
||||
|
||||
@UtilityClass
|
||||
public class Predicate {
|
||||
public static <T> java.util.function.Predicate<T> alwaysFalse() {
|
||||
return t -> false;
|
||||
}
|
||||
|
||||
public static <T> java.util.function.Predicate<T> alwaysTrue() {
|
||||
return t -> true;
|
||||
}
|
||||
|
||||
public static java.util.function.Predicate<Integer> notInRange(Integer start, Integer end) {
|
||||
return inverse(inRange(start, end));
|
||||
}
|
||||
|
||||
public static java.util.function.Predicate<Integer> inRange(Integer start, Integer end) {
|
||||
return isOneOf(IntStream.rangeClosed(start, end).boxed().collect(Collectors.toSet()));
|
||||
}
|
||||
|
||||
public static <T> java.util.function.Predicate<T> notOneOf(Set<T> ts) {
|
||||
return inverse(isOneOf(ts));
|
||||
}
|
||||
|
||||
public static <T> java.util.function.Predicate<T> isOneOf(Set<T> ta) {
|
||||
return t -> {
|
||||
for (T i : ta) {
|
||||
if (i == t) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
};
|
||||
}
|
||||
|
||||
public static <T> java.util.function.Predicate<T> not(T t) {
|
||||
return inverse(is(t));
|
||||
}
|
||||
|
||||
public static <T> java.util.function.Predicate<T> is(T t) {
|
||||
return t2 -> t == t2;
|
||||
}
|
||||
|
||||
public static <T> java.util.function.Predicate<T> inverse(java.util.function.Predicate<T> t) {
|
||||
return t2 -> !t.test(t2);
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,8 @@
|
||||
package me.lucko.luckperms.commands;
|
||||
|
||||
/**
|
||||
* Wrapper class to represent a CommandSender in Bukkit/Bungee within the luckperms-common command implementations.
|
||||
*/
|
||||
public interface Sender {
|
||||
|
||||
void sendMessage(String s);
|
||||
|
||||
@@ -0,0 +1,50 @@
|
||||
package me.lucko.luckperms.commands;
|
||||
|
||||
import me.lucko.luckperms.LuckPermsPlugin;
|
||||
import me.lucko.luckperms.api.data.Callback;
|
||||
import me.lucko.luckperms.constants.Permission;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* An extension of {@link MainCommand} for implementations without any subcommands
|
||||
*/
|
||||
public class SingleMainCommand extends MainCommand<Object> {
|
||||
private final Permission permission;
|
||||
|
||||
public SingleMainCommand(String name, String usage, int requiredArgsLength, Permission permission) {
|
||||
super(name, usage, requiredArgsLength);
|
||||
this.permission = permission;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void execute(LuckPermsPlugin plugin, Sender sender, List<String> args, String label) {
|
||||
// Do nothing, allow the implementation to override this
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void getTarget(String target, LuckPermsPlugin plugin, Sender sender, Callback onSuccess) {
|
||||
// Do nothing, don't run callback
|
||||
}
|
||||
|
||||
@Override
|
||||
protected List<String> getObjects(LuckPermsPlugin plugin) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected List<String> onTabComplete(Sender sender, List<String> args, LuckPermsPlugin plugin) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<SubCommand<Object>> getSubCommands() {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean isAuthorized(Sender sender) {
|
||||
return permission.isAuthorized(sender);
|
||||
}
|
||||
}
|
||||
@@ -1,35 +1,160 @@
|
||||
package me.lucko.luckperms.commands;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
import me.lucko.luckperms.LuckPermsPlugin;
|
||||
import me.lucko.luckperms.constants.Message;
|
||||
import me.lucko.luckperms.constants.Permission;
|
||||
import me.lucko.luckperms.groups.Group;
|
||||
import me.lucko.luckperms.tracks.Track;
|
||||
import me.lucko.luckperms.users.User;
|
||||
|
||||
public abstract class SubCommand {
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.function.Predicate;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@Getter
|
||||
/**
|
||||
* Abstract SubCommand class
|
||||
*/
|
||||
@Getter
|
||||
@AllArgsConstructor
|
||||
public abstract class SubCommand<T> {
|
||||
|
||||
/**
|
||||
* The name of the sub command
|
||||
*/
|
||||
private final String name;
|
||||
|
||||
@Getter
|
||||
/**
|
||||
* A brief description of what the sub command does
|
||||
*/
|
||||
private final String description;
|
||||
|
||||
@Getter
|
||||
/**
|
||||
* The command usage
|
||||
*/
|
||||
private final String usage;
|
||||
|
||||
@Getter
|
||||
private final String permission;
|
||||
/**
|
||||
* The permission needed to use this command
|
||||
*/
|
||||
private final Permission permission;
|
||||
|
||||
public SubCommand(String name, String description, String usage, String permission) {
|
||||
this.name = name;
|
||||
this.description = description;
|
||||
this.usage = usage;
|
||||
this.permission = permission;
|
||||
/**
|
||||
* Predicate to test if the argument length given is invalid
|
||||
*/
|
||||
private final Predicate<? super Integer> isArgumentInvalid;
|
||||
|
||||
/**
|
||||
* Called when this sub command is ran
|
||||
* @param plugin a link to the main plugin instance
|
||||
* @param sender the sender to executed the command
|
||||
* @param t the object the command is operating on
|
||||
* @param args the stripped arguments given
|
||||
* @param label the command label used
|
||||
*/
|
||||
public abstract void execute(LuckPermsPlugin plugin, Sender sender, T t, List<String> args, String label);
|
||||
|
||||
/**
|
||||
* Send the command usage to a sender
|
||||
* @param sender the sender to send the usage to
|
||||
* @param label the command label used
|
||||
*/
|
||||
public void sendUsage(Sender sender, String label) {
|
||||
Util.sendPluginMessage(sender, "&e-> &d" + String.format(getUsage(), label));
|
||||
}
|
||||
|
||||
/**
|
||||
* If a sender has permission to use this command
|
||||
* @param sender the sender trying to use the command
|
||||
* @return true if the sender can use the command
|
||||
*/
|
||||
public boolean isAuthorized(Sender sender) {
|
||||
return sender.hasPermission(permission);
|
||||
return permission.isAuthorized(sender);
|
||||
}
|
||||
|
||||
public void sendUsage(Sender sender) {
|
||||
Util.sendPluginMessage(sender, "&e-> &d" + getUsage());
|
||||
/**
|
||||
* Returns a list of suggestions, which are empty by default. Sub classes that give tab complete suggestions override
|
||||
* this method to give their own list.
|
||||
* @param sender who is tab completing
|
||||
* @param args the arguments so far
|
||||
* @param plugin the plugin instance
|
||||
* @return a list of suggestions
|
||||
*/
|
||||
public List<String> onTabComplete(Sender sender, List<String> args, LuckPermsPlugin plugin) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
public abstract boolean isArgLengthInvalid(int argLength);
|
||||
/*
|
||||
----------------------------------------------------------------------------------
|
||||
Utility methods used by #onTabComplete and #execute implementations in sub classes
|
||||
----------------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
protected static List<String> getGroupTabComplete(List<String> args, LuckPermsPlugin plugin) {
|
||||
return getTabComplete(new ArrayList<>(plugin.getGroupManager().getGroups().keySet()), args);
|
||||
}
|
||||
|
||||
protected static List<String> getTrackTabComplete(List<String> args, LuckPermsPlugin plugin) {
|
||||
return getTabComplete(new ArrayList<>(plugin.getTrackManager().getTracks().keySet()), args);
|
||||
}
|
||||
|
||||
protected static List<String> getBoolTabComplete(List<String> args) {
|
||||
if (args.size() == 2) {
|
||||
return Arrays.asList("true", "false");
|
||||
} else {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
}
|
||||
|
||||
private static List<String> getTabComplete(List<String> options, List<String> args) {
|
||||
if (args.size() <= 1) {
|
||||
if (args.isEmpty() || args.get(0).equalsIgnoreCase("")) {
|
||||
return options;
|
||||
}
|
||||
|
||||
return options.stream().filter(s -> s.toLowerCase().startsWith(args.get(0).toLowerCase())).collect(Collectors.toList());
|
||||
}
|
||||
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
protected static void saveUser(User user, Sender sender, LuckPermsPlugin plugin) {
|
||||
user.refreshPermissions();
|
||||
|
||||
plugin.getDatastore().saveUser(user, success -> {
|
||||
if (success) {
|
||||
Message.USER_SAVE_SUCCESS.send(sender);
|
||||
} else {
|
||||
Message.USER_SAVE_ERROR.send(sender);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
protected static void saveGroup(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);
|
||||
}
|
||||
|
||||
plugin.runUpdateTask();
|
||||
});
|
||||
}
|
||||
|
||||
protected static void saveTrack(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);
|
||||
}
|
||||
|
||||
plugin.runUpdateTask();
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -1,14 +1,18 @@
|
||||
package me.lucko.luckperms.commands;
|
||||
|
||||
import lombok.experimental.UtilityClass;
|
||||
import me.lucko.luckperms.constants.Message;
|
||||
import me.lucko.luckperms.utils.DateUtil;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
|
||||
@UtilityClass
|
||||
public class Util {
|
||||
|
||||
public static void sendPluginMessage(Sender sender, String message) {
|
||||
// TODO: Pull the prefix from the config somehow
|
||||
sender.sendMessage(color("&7&l[&b&lL&a&lP&7&l] &c" + message));
|
||||
sender.sendMessage(color(Message.PREFIX + message));
|
||||
}
|
||||
|
||||
public static String color(String s) {
|
||||
@@ -19,8 +23,8 @@ public class Util {
|
||||
// Stolen from Bukkit :>
|
||||
char[] b = textToTranslate.toCharArray();
|
||||
|
||||
for(int i = 0; i < b.length - 1; ++i) {
|
||||
if(b[i] == altColorChar && "0123456789AaBbCcDdEeFfKkLlMmNnOoRr".indexOf(b[i + 1]) > -1) {
|
||||
for (int i = 0; i < b.length - 1; ++i) {
|
||||
if (b[i] == altColorChar && "0123456789AaBbCcDdEeFfKkLlMmNnOoRr".indexOf(b[i + 1]) > -1) {
|
||||
b[i] = 167;
|
||||
b[i + 1] = Character.toLowerCase(b[i + 1]);
|
||||
}
|
||||
@@ -41,28 +45,80 @@ public class Util {
|
||||
if (strings.isEmpty()) return "&6None";
|
||||
|
||||
StringBuilder sb = new StringBuilder();
|
||||
strings.forEach(s -> sb.append("&6").append(s).append("&7, "));
|
||||
return sb.delete(sb.length() - 2, sb.length()).toString();
|
||||
}
|
||||
|
||||
public static String listToArrowSep(List<String> strings, String highlight) {
|
||||
if (strings.isEmpty()) return "&6None";
|
||||
|
||||
StringBuilder sb = new StringBuilder();
|
||||
for (String s : strings) {
|
||||
sb.append("&6").append(s).append("&7, ");
|
||||
if (s.equalsIgnoreCase(highlight)) {
|
||||
sb.append("&e").append(s).append("&7 ---> ");
|
||||
} else {
|
||||
sb.append("&6").append(s).append("&7 ---> ");
|
||||
}
|
||||
}
|
||||
return sb.delete(sb.length() - 6, sb.length()).toString();
|
||||
}
|
||||
|
||||
public static String listToArrowSep(List<String> strings, String highlightFirst, String highlightSecond, boolean reversed) {
|
||||
if (strings.isEmpty()) return "&6None";
|
||||
|
||||
StringBuilder sb = new StringBuilder();
|
||||
for (String s : strings) {
|
||||
if (s.equalsIgnoreCase(highlightFirst)) {
|
||||
sb.append("&e").append(s).append("&4").append(reversed ? " <--- " : " ---> ");
|
||||
} else if (s.equalsIgnoreCase(highlightSecond)) {
|
||||
sb.append("&e").append(s).append("&7").append(reversed ? " <--- " : " ---> ");
|
||||
} else {
|
||||
sb.append("&6").append(s).append("&7").append(reversed ? " <--- " : " ---> ");
|
||||
}
|
||||
}
|
||||
return sb.delete(sb.length() - 6, sb.length()).toString();
|
||||
}
|
||||
|
||||
public static String listToArrowSep(List<String> strings) {
|
||||
if (strings.isEmpty()) return "&6None";
|
||||
|
||||
StringBuilder sb = new StringBuilder();
|
||||
strings.forEach(s -> sb.append("&6").append(s).append("&e ---> "));
|
||||
return sb.delete(sb.length() - 6, sb.length()).toString();
|
||||
}
|
||||
|
||||
public static String permNodesToString(Map<String, Boolean> nodes) {
|
||||
if (nodes.isEmpty()) return "&6None";
|
||||
|
||||
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, ");
|
||||
}
|
||||
}
|
||||
|
||||
return sb.delete(sb.length() - 2, sb.length()).toString();
|
||||
}
|
||||
|
||||
public static String nodesToString(Map<String, Boolean> nodes) {
|
||||
public static String tempNodesToString(Map<Map.Entry<String, Boolean>, Long> nodes) {
|
||||
if (nodes.isEmpty()) return "&6None";
|
||||
|
||||
StringBuilder sb = new StringBuilder();
|
||||
|
||||
for (String node : nodes.keySet()) {
|
||||
if (nodes.get(node)) {
|
||||
sb.append("&a").append(node).append("&7, ");
|
||||
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(node).append("&7, ");
|
||||
sb.append("&c").append(e.getKey().getKey()).append("&6 - expires in ")
|
||||
.append(DateUtil.formatDateDiff(e.getValue())).append("\n");
|
||||
}
|
||||
}
|
||||
|
||||
return sb.delete(sb.length() - 2, sb.length()).toString();
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
public static UUID parseUuid(String s) {
|
||||
|
||||
@@ -0,0 +1,51 @@
|
||||
package me.lucko.luckperms.commands.group;
|
||||
|
||||
import me.lucko.luckperms.LuckPermsPlugin;
|
||||
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.utils.Patterns;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class CreateGroup extends SingleMainCommand {
|
||||
public CreateGroup() {
|
||||
super("CreateGroup", "/%s creategroup <group>", 1, Permission.CREATE_GROUP);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void execute(LuckPermsPlugin plugin, Sender sender, List<String> args, String label) {
|
||||
if (args.size() == 0) {
|
||||
sendUsage(sender, label);
|
||||
return;
|
||||
}
|
||||
|
||||
String groupName = args.get(0).toLowerCase();
|
||||
|
||||
if (groupName.length() > 36) {
|
||||
Message.GROUP_NAME_TOO_LONG.send(sender, groupName);
|
||||
return;
|
||||
}
|
||||
|
||||
if (Patterns.NON_ALPHA_NUMERIC.matcher(groupName).find()) {
|
||||
Message.GROUP_INVALID_ENTRY.send(sender);
|
||||
return;
|
||||
}
|
||||
|
||||
plugin.getDatastore().loadGroup(groupName, success -> {
|
||||
if (success) {
|
||||
Message.GROUP_ALREADY_EXISTS.send(sender);
|
||||
} else {
|
||||
plugin.getDatastore().createAndLoadGroup(groupName, success1 -> {
|
||||
if (!success1) {
|
||||
Message.CREATE_GROUP_ERROR.send(sender);
|
||||
} else {
|
||||
Message.CREATE_SUCCESS.send(sender, groupName);
|
||||
plugin.runUpdateTask();
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -1,51 +0,0 @@
|
||||
package me.lucko.luckperms.commands.group;
|
||||
|
||||
import me.lucko.luckperms.LuckPermsPlugin;
|
||||
import me.lucko.luckperms.commands.MainCommand;
|
||||
import me.lucko.luckperms.commands.Sender;
|
||||
import me.lucko.luckperms.commands.SubCommand;
|
||||
import me.lucko.luckperms.commands.Util;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class CreateGroupCommand extends MainCommand {
|
||||
public CreateGroupCommand() {
|
||||
super("CreateGroup", "/perms creategroup <group>", 1);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void execute(LuckPermsPlugin plugin, Sender sender, List<String> args) {
|
||||
if (!sender.hasPermission("luckperms.creategroup")) {
|
||||
Util.sendPluginMessage(sender, "You do not have permission to use this command!");
|
||||
return;
|
||||
}
|
||||
|
||||
if (args.size() == 0) {
|
||||
sendUsage(sender);
|
||||
return;
|
||||
}
|
||||
|
||||
String groupName = args.get(0).toLowerCase();
|
||||
|
||||
plugin.getDatastore().loadGroup(groupName, success -> {
|
||||
if (success) {
|
||||
Util.sendPluginMessage(sender, "That group already exists!");
|
||||
} else {
|
||||
plugin.getDatastore().createAndLoadGroup(groupName, success1 -> {
|
||||
if (!success1) {
|
||||
Util.sendPluginMessage(sender, "There was an error whilst creating the group.");
|
||||
} else {
|
||||
Util.sendPluginMessage(sender, "&b" + groupName + "&a was successfully created.");
|
||||
plugin.runUpdateTask();
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<SubCommand> getSubCommands() {
|
||||
return new ArrayList<>();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,76 @@
|
||||
package me.lucko.luckperms.commands.group;
|
||||
|
||||
import me.lucko.luckperms.LuckPermsPlugin;
|
||||
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.groups.Group;
|
||||
import me.lucko.luckperms.utils.Patterns;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class DeleteGroup extends SingleMainCommand {
|
||||
public DeleteGroup() {
|
||||
super("DeleteGroup", "/%s deletegroup <group>", 1, Permission.DELETE_GROUP);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void execute(LuckPermsPlugin plugin, Sender sender, List<String> args, String label) {
|
||||
if (args.size() == 0) {
|
||||
sendUsage(sender, label);
|
||||
return;
|
||||
}
|
||||
|
||||
String groupName = args.get(0).toLowerCase();
|
||||
|
||||
if (groupName.equalsIgnoreCase(plugin.getConfiguration().getDefaultGroupName())) {
|
||||
Message.DELETE_GROUP_ERROR_DEFAULT.send(sender);
|
||||
return;
|
||||
}
|
||||
|
||||
if (Patterns.NON_ALPHA_NUMERIC.matcher(groupName).find()) {
|
||||
Message.GROUP_INVALID_ENTRY.send(sender);
|
||||
return;
|
||||
}
|
||||
|
||||
plugin.getDatastore().loadGroup(groupName, success -> {
|
||||
if (!success) {
|
||||
Message.GROUP_DOES_NOT_EXIST.send(sender);
|
||||
} else {
|
||||
|
||||
Group group = plugin.getGroupManager().getGroup(groupName);
|
||||
if (group == null) {
|
||||
Message.GROUP_LOAD_ERROR.send(sender);
|
||||
} else {
|
||||
plugin.getDatastore().deleteGroup(group, success1 -> {
|
||||
if (!success1) {
|
||||
Message.DELETE_GROUP_ERROR.send(sender);
|
||||
} else {
|
||||
Message.DELETE_SUCCESS.send(sender, groupName);
|
||||
plugin.runUpdateTask();
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
protected List<String> onTabComplete(Sender sender, List<String> args, LuckPermsPlugin plugin) {
|
||||
final List<String> groups = new ArrayList<>(plugin.getGroupManager().getGroups().keySet());
|
||||
|
||||
if (args.size() <= 1) {
|
||||
if (args.isEmpty() || args.get(0).equalsIgnoreCase("")) {
|
||||
return groups;
|
||||
}
|
||||
|
||||
return groups.stream().filter(s -> s.toLowerCase().startsWith(args.get(0).toLowerCase())).collect(Collectors.toList());
|
||||
}
|
||||
|
||||
return Collections.emptyList();
|
||||
}
|
||||
}
|
||||
@@ -1,63 +0,0 @@
|
||||
package me.lucko.luckperms.commands.group;
|
||||
|
||||
import me.lucko.luckperms.LuckPermsPlugin;
|
||||
import me.lucko.luckperms.commands.MainCommand;
|
||||
import me.lucko.luckperms.commands.Sender;
|
||||
import me.lucko.luckperms.commands.SubCommand;
|
||||
import me.lucko.luckperms.commands.Util;
|
||||
import me.lucko.luckperms.groups.Group;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class DeleteGroupCommand extends MainCommand {
|
||||
public DeleteGroupCommand() {
|
||||
super("DeleteGroup", "/perms deletegroup <group>", 1);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void execute(LuckPermsPlugin plugin, Sender sender, List<String> args) {
|
||||
if (!sender.hasPermission("luckperms.deletegroup")) {
|
||||
Util.sendPluginMessage(sender, "You do not have permission to use this command!");
|
||||
return;
|
||||
}
|
||||
|
||||
if (args.size() == 0) {
|
||||
sendUsage(sender);
|
||||
return;
|
||||
}
|
||||
|
||||
String groupName = args.get(0).toLowerCase();
|
||||
|
||||
if (groupName.equalsIgnoreCase(plugin.getConfiguration().getDefaultGroupName())) {
|
||||
Util.sendPluginMessage(sender, "You cannot delete the default group.");
|
||||
return;
|
||||
}
|
||||
|
||||
plugin.getDatastore().loadGroup(groupName, success -> {
|
||||
if (!success) {
|
||||
Util.sendPluginMessage(sender, "That group does not exist!");
|
||||
} else {
|
||||
|
||||
Group group = plugin.getGroupManager().getGroup(groupName);
|
||||
if (group == null) {
|
||||
Util.sendPluginMessage(sender, "An unexpected error occurred.");
|
||||
} else {
|
||||
plugin.getDatastore().deleteGroup(group, success1 -> {
|
||||
if (!success1) {
|
||||
Util.sendPluginMessage(sender, "There was an error whilst creating the group.");
|
||||
} else {
|
||||
Util.sendPluginMessage(sender, "&b" + groupName + "&a was successfully deleted.");
|
||||
plugin.runUpdateTask();
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<SubCommand> getSubCommands() {
|
||||
return new ArrayList<>();
|
||||
}
|
||||
}
|
||||
@@ -1,103 +1,46 @@
|
||||
package me.lucko.luckperms.commands.group;
|
||||
|
||||
import me.lucko.luckperms.LuckPermsPlugin;
|
||||
import me.lucko.luckperms.api.data.Callback;
|
||||
import me.lucko.luckperms.commands.MainCommand;
|
||||
import me.lucko.luckperms.commands.Sender;
|
||||
import me.lucko.luckperms.commands.SubCommand;
|
||||
import me.lucko.luckperms.commands.Util;
|
||||
import me.lucko.luckperms.constants.Message;
|
||||
import me.lucko.luckperms.groups.Group;
|
||||
import me.lucko.luckperms.utils.Patterns;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class GroupMainCommand extends MainCommand {
|
||||
|
||||
private final List<GroupSubCommand> subCommands = new ArrayList<>();
|
||||
|
||||
public class GroupMainCommand extends MainCommand<Group> {
|
||||
public GroupMainCommand() {
|
||||
super("Group", "/perms group <group>", 2);
|
||||
super("Group", "/%s group <group>", 2);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void execute(LuckPermsPlugin plugin, Sender sender, List<String> args) {
|
||||
if (args.size() <= 1) {
|
||||
sendUsage(sender);
|
||||
protected void getTarget(String target, LuckPermsPlugin plugin, Sender sender, Callback<Group> onSuccess) {
|
||||
if (Patterns.NON_ALPHA_NUMERIC.matcher(target).find()) {
|
||||
Message.GROUP_INVALID_ENTRY.send(sender);
|
||||
return;
|
||||
}
|
||||
|
||||
List<String> strippedArgs = new ArrayList<>();
|
||||
if (args.size() > 2) {
|
||||
strippedArgs.addAll(args.subList(2, args.size()));
|
||||
}
|
||||
|
||||
String c = args.get(1);
|
||||
GroupSubCommand tempSub = null;
|
||||
|
||||
for (GroupSubCommand s : subCommands) {
|
||||
if (s.getName().equalsIgnoreCase(c)) {
|
||||
tempSub = s;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
final GroupSubCommand sub = tempSub;
|
||||
|
||||
if (sub == null) {
|
||||
Util.sendPluginMessage(sender, "Command not recognised.");
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
if (!sub.isAuthorized(sender)) {
|
||||
Util.sendPluginMessage(sender, "You do not have permission to use this command!");
|
||||
return;
|
||||
}
|
||||
|
||||
String g = args.get(0).toLowerCase();
|
||||
|
||||
plugin.getDatastore().loadGroup(g, success -> {
|
||||
plugin.getDatastore().loadGroup(target, success -> {
|
||||
if (!success) {
|
||||
Util.sendPluginMessage(sender, "&eGroup could not be found.");
|
||||
Message.GROUP_NOT_FOUND.send(sender);
|
||||
return;
|
||||
}
|
||||
|
||||
Group group = plugin.getGroupManager().getGroup(g);
|
||||
Group group = plugin.getGroupManager().getGroup(target);
|
||||
if (group == null) {
|
||||
Util.sendPluginMessage(sender, "&eGroup could not be found.");
|
||||
Message.GROUP_NOT_FOUND.send(sender);
|
||||
return;
|
||||
}
|
||||
|
||||
if (sub.isArgLengthInvalid(strippedArgs.size())) {
|
||||
sub.sendUsage(sender);
|
||||
return;
|
||||
}
|
||||
|
||||
sub.execute(plugin, sender, group, strippedArgs);
|
||||
onSuccess.onComplete(group);
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<? extends SubCommand> getSubCommands() {
|
||||
return subCommands;
|
||||
}
|
||||
|
||||
public void registerSubCommand(GroupSubCommand subCommand) {
|
||||
subCommands.add(subCommand);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void sendUsage(Sender sender) {
|
||||
List<SubCommand> subs = getSubCommands().stream().filter(s -> s.isAuthorized(sender)).collect(Collectors.toList());
|
||||
if (subs.size() > 0) {
|
||||
Util.sendPluginMessage(sender, "&e" + getName() + " Sub Commands:");
|
||||
|
||||
for (SubCommand s : subs) {
|
||||
s.sendUsage(sender);
|
||||
}
|
||||
|
||||
} else {
|
||||
Util.sendPluginMessage(sender, "You do not have permission to use this command!");
|
||||
}
|
||||
protected List<String> getObjects(LuckPermsPlugin plugin) {
|
||||
return new ArrayList<>(plugin.getGroupManager().getGroups().keySet());
|
||||
}
|
||||
}
|
||||
@@ -1,29 +0,0 @@
|
||||
package me.lucko.luckperms.commands.group;
|
||||
|
||||
import me.lucko.luckperms.LuckPermsPlugin;
|
||||
import me.lucko.luckperms.commands.Sender;
|
||||
import me.lucko.luckperms.commands.SubCommand;
|
||||
import me.lucko.luckperms.commands.Util;
|
||||
import me.lucko.luckperms.groups.Group;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public abstract class GroupSubCommand extends SubCommand {
|
||||
public GroupSubCommand(String name, String description, String usage, String permission) {
|
||||
super(name, description, usage, permission);
|
||||
}
|
||||
|
||||
protected abstract void execute(LuckPermsPlugin plugin, Sender sender, Group group, List<String> args);
|
||||
|
||||
protected void saveGroup(Group group, Sender sender, LuckPermsPlugin plugin) {
|
||||
plugin.getDatastore().saveGroup(group, success -> {
|
||||
if (success) {
|
||||
Util.sendPluginMessage(sender, "&7(Group data was saved to the datastore)");
|
||||
} else {
|
||||
Util.sendPluginMessage(sender, "There was an error whilst saving the group.");
|
||||
}
|
||||
|
||||
plugin.runUpdateTask();
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
package me.lucko.luckperms.commands.group;
|
||||
|
||||
import me.lucko.luckperms.LuckPermsPlugin;
|
||||
import me.lucko.luckperms.commands.Sender;
|
||||
import me.lucko.luckperms.commands.SingleMainCommand;
|
||||
import me.lucko.luckperms.commands.Util;
|
||||
import me.lucko.luckperms.constants.Message;
|
||||
import me.lucko.luckperms.constants.Permission;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class ListGroups extends SingleMainCommand {
|
||||
public ListGroups() {
|
||||
super("ListGroups", "/%s listgroups", 0, Permission.LIST_GROUPS);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void execute(LuckPermsPlugin plugin, Sender sender, List<String> args, String label) {
|
||||
plugin.getDatastore().loadAllGroups(success -> {
|
||||
if (!success) {
|
||||
Message.GROUPS_LOAD_ERROR.send(sender);
|
||||
} else {
|
||||
Message.GROUPS_LIST.send(sender, Util.listToCommaSep(new ArrayList<>(plugin.getGroupManager().getGroups().keySet())));
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -1,37 +0,0 @@
|
||||
package me.lucko.luckperms.commands.group;
|
||||
|
||||
import me.lucko.luckperms.LuckPermsPlugin;
|
||||
import me.lucko.luckperms.commands.MainCommand;
|
||||
import me.lucko.luckperms.commands.Sender;
|
||||
import me.lucko.luckperms.commands.SubCommand;
|
||||
import me.lucko.luckperms.commands.Util;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class ListGroupsCommand extends MainCommand {
|
||||
public ListGroupsCommand() {
|
||||
super("ListGroups", "/perms listgroups", 0);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void execute(LuckPermsPlugin plugin, Sender sender, List<String> args) {
|
||||
if (!sender.hasPermission("luckperms.listgroups")) {
|
||||
Util.sendPluginMessage(sender, "You do not have permission to use this command!");
|
||||
return;
|
||||
}
|
||||
|
||||
plugin.getDatastore().loadAllGroups(success -> {
|
||||
if (!success) {
|
||||
Util.sendPluginMessage(sender, "Unable to load all groups.");
|
||||
} else {
|
||||
Util.sendPluginMessage(sender, "&aGroups: " + Util.listToCommaSep(new ArrayList<>(plugin.getGroupManager().getGroups().keySet())));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<SubCommand> getSubCommands() {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
package me.lucko.luckperms.commands.group.subcommands;
|
||||
|
||||
import me.lucko.luckperms.LuckPermsPlugin;
|
||||
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.groups.Group;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class GroupClear extends SubCommand<Group> {
|
||||
public GroupClear() {
|
||||
super("clear", "Clears a groups permissions", "/%s group <group> clear", Permission.GROUP_CLEAR,
|
||||
Predicate.alwaysFalse());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(LuckPermsPlugin plugin, Sender sender, Group group, List<String> args, String label) {
|
||||
group.clearNodes();
|
||||
Message.CLEAR_SUCCESS.send(sender, group.getName());
|
||||
|
||||
saveGroup(group, sender, plugin);
|
||||
}
|
||||
}
|
||||
-29
@@ -1,29 +0,0 @@
|
||||
package me.lucko.luckperms.commands.group.subcommands;
|
||||
|
||||
import me.lucko.luckperms.LuckPermsPlugin;
|
||||
import me.lucko.luckperms.commands.Sender;
|
||||
import me.lucko.luckperms.commands.Util;
|
||||
import me.lucko.luckperms.commands.group.GroupSubCommand;
|
||||
import me.lucko.luckperms.groups.Group;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class GroupClearCommand extends GroupSubCommand {
|
||||
public GroupClearCommand() {
|
||||
super("clear", "Clears a groups permissions",
|
||||
"/perms group <group> clear", "luckperms.group.clear");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void execute(LuckPermsPlugin plugin, Sender sender, Group group, List<String> args) {
|
||||
group.clearNodes();
|
||||
Util.sendPluginMessage(sender, "&b" + group.getName() + "&a's permissions were cleared.");
|
||||
|
||||
saveGroup(group, sender, plugin);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isArgLengthInvalid(int argLength) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
package me.lucko.luckperms.commands.group.subcommands;
|
||||
|
||||
import me.lucko.luckperms.LuckPermsPlugin;
|
||||
import me.lucko.luckperms.commands.Predicate;
|
||||
import me.lucko.luckperms.commands.Sender;
|
||||
import me.lucko.luckperms.commands.SubCommand;
|
||||
import me.lucko.luckperms.commands.Util;
|
||||
import me.lucko.luckperms.constants.Message;
|
||||
import me.lucko.luckperms.constants.Permission;
|
||||
import me.lucko.luckperms.groups.Group;
|
||||
import me.lucko.luckperms.utils.Patterns;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class GroupHasPerm extends SubCommand<Group> {
|
||||
public GroupHasPerm() {
|
||||
super("haspermission", "Checks to see if a group has a certain permission node",
|
||||
"/%s group <group> haspermission <node> [server] [world]", Permission.GROUP_HASPERMISSION,
|
||||
Predicate.notInRange(1, 3));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(LuckPermsPlugin plugin, Sender sender, Group group, List<String> args, String label) {
|
||||
if (args.size() >= 2) {
|
||||
if (Patterns.NON_ALPHA_NUMERIC.matcher(args.get(1)).find()) {
|
||||
Message.SERVER_INVALID_ENTRY.send(sender);
|
||||
return;
|
||||
}
|
||||
|
||||
if (args.size() == 2) {
|
||||
Util.sendBoolean(sender, args.get(0), group.hasPermission(args.get(0), true, args.get(1)));
|
||||
} else {
|
||||
Util.sendBoolean(sender, args.get(0), group.hasPermission(args.get(0), true, args.get(1), args.get(2)));
|
||||
}
|
||||
|
||||
} else {
|
||||
Util.sendBoolean(sender, args.get(0), group.hasPermission(args.get(0), true, "global"));
|
||||
}
|
||||
}
|
||||
}
|
||||
-30
@@ -1,30 +0,0 @@
|
||||
package me.lucko.luckperms.commands.group.subcommands;
|
||||
|
||||
import me.lucko.luckperms.LuckPermsPlugin;
|
||||
import me.lucko.luckperms.commands.Sender;
|
||||
import me.lucko.luckperms.commands.Util;
|
||||
import me.lucko.luckperms.commands.group.GroupSubCommand;
|
||||
import me.lucko.luckperms.groups.Group;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class GroupHasPermCommand extends GroupSubCommand {
|
||||
public GroupHasPermCommand() {
|
||||
super("haspermission", "Checks to see if a group has a certain permission node",
|
||||
"/perms group <group> haspermission <node> [server]", "luckperms.group.haspermission");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void execute(LuckPermsPlugin plugin, Sender sender, Group group, List<String> args) {
|
||||
if (args.size() >= 2) {
|
||||
Util.sendBoolean(sender, args.get(0), group.hasPermission(args.get(0), true, args.get(1)));
|
||||
} else {
|
||||
Util.sendBoolean(sender, args.get(0), group.hasPermission(args.get(0), true, "global"));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isArgLengthInvalid(int argLength) {
|
||||
return argLength == 0;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
package me.lucko.luckperms.commands.group.subcommands;
|
||||
|
||||
import me.lucko.luckperms.LuckPermsPlugin;
|
||||
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.groups.Group;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class GroupInfo extends SubCommand<Group> {
|
||||
public GroupInfo() {
|
||||
super("info", "Gives info about the group", "/%s group <group> info", Permission.GROUP_INFO,
|
||||
Predicate.alwaysFalse());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void 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(), label, group.getName());
|
||||
}
|
||||
}
|
||||
-31
@@ -1,31 +0,0 @@
|
||||
package me.lucko.luckperms.commands.group.subcommands;
|
||||
|
||||
import me.lucko.luckperms.LuckPermsPlugin;
|
||||
import me.lucko.luckperms.commands.Sender;
|
||||
import me.lucko.luckperms.commands.Util;
|
||||
import me.lucko.luckperms.commands.group.GroupSubCommand;
|
||||
import me.lucko.luckperms.groups.Group;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class GroupInfoCommand extends GroupSubCommand {
|
||||
public GroupInfoCommand() {
|
||||
super("info", "Gives info about the group",
|
||||
"/perms group <group> info", "luckperms.group.info");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void execute(LuckPermsPlugin plugin, Sender sender, Group group, List<String> args) {
|
||||
final String prefix = plugin.getConfiguration().getPrefix();
|
||||
String sb = prefix + "&d-> &eGroup: &6" + group.getName() + "\n" +
|
||||
prefix + "&d-> &ePermissions: &6" + group.getNodes().keySet().size() + "\n" +
|
||||
prefix + "&d-> &bUse &a/perms group " + group.getName() + " listnodes &bto see all permissions.";
|
||||
|
||||
sender.sendMessage(Util.color(sb));
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isArgLengthInvalid(int argLength) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
+40
@@ -0,0 +1,40 @@
|
||||
package me.lucko.luckperms.commands.group.subcommands;
|
||||
|
||||
import me.lucko.luckperms.LuckPermsPlugin;
|
||||
import me.lucko.luckperms.commands.Predicate;
|
||||
import me.lucko.luckperms.commands.Sender;
|
||||
import me.lucko.luckperms.commands.SubCommand;
|
||||
import me.lucko.luckperms.commands.Util;
|
||||
import me.lucko.luckperms.constants.Message;
|
||||
import me.lucko.luckperms.constants.Permission;
|
||||
import me.lucko.luckperms.groups.Group;
|
||||
import me.lucko.luckperms.utils.Patterns;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class GroupInheritsPerm extends SubCommand<Group> {
|
||||
public GroupInheritsPerm() {
|
||||
super("inheritspermission", "Checks to see if a group inherits a certain permission node",
|
||||
"/%s group <group> inheritspermission <node> [server] [world]", Permission.GROUP_INHERITSPERMISSION,
|
||||
Predicate.notInRange(1, 3));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(LuckPermsPlugin plugin, Sender sender, Group group, List<String> args, String label) {
|
||||
if (args.size() >= 2) {
|
||||
if (Patterns.NON_ALPHA_NUMERIC.matcher(args.get(1)).find()) {
|
||||
Message.SERVER_INVALID_ENTRY.send(sender);
|
||||
return;
|
||||
}
|
||||
|
||||
if (args.size() == 2) {
|
||||
Util.sendBoolean(sender, args.get(0), group.inheritsPermission(args.get(0), true, args.get(1)));
|
||||
} else {
|
||||
Util.sendBoolean(sender, args.get(0), group.inheritsPermission(args.get(0), true, args.get(1), args.get(2)));
|
||||
}
|
||||
|
||||
} else {
|
||||
Util.sendBoolean(sender, args.get(0), group.inheritsPermission(args.get(0), true));
|
||||
}
|
||||
}
|
||||
}
|
||||
+25
@@ -0,0 +1,25 @@
|
||||
package me.lucko.luckperms.commands.group.subcommands;
|
||||
|
||||
import me.lucko.luckperms.LuckPermsPlugin;
|
||||
import me.lucko.luckperms.commands.Predicate;
|
||||
import me.lucko.luckperms.commands.Sender;
|
||||
import me.lucko.luckperms.commands.SubCommand;
|
||||
import me.lucko.luckperms.commands.Util;
|
||||
import me.lucko.luckperms.constants.Message;
|
||||
import me.lucko.luckperms.constants.Permission;
|
||||
import me.lucko.luckperms.groups.Group;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class GroupListNodes extends SubCommand<Group> {
|
||||
public GroupListNodes() {
|
||||
super("listnodes", "Lists the permission nodes the group has", "/%s group <group> listnodes",
|
||||
Permission.GROUP_LISTNODES, Predicate.alwaysFalse());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void 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()));
|
||||
}
|
||||
}
|
||||
-27
@@ -1,27 +0,0 @@
|
||||
package me.lucko.luckperms.commands.group.subcommands;
|
||||
|
||||
import me.lucko.luckperms.LuckPermsPlugin;
|
||||
import me.lucko.luckperms.commands.Sender;
|
||||
import me.lucko.luckperms.commands.Util;
|
||||
import me.lucko.luckperms.commands.group.GroupSubCommand;
|
||||
import me.lucko.luckperms.groups.Group;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class GroupListNodesCommand extends GroupSubCommand {
|
||||
public GroupListNodesCommand() {
|
||||
super("listnodes", "Lists the permission nodes the group has",
|
||||
"/perms group <group> listnodes", "luckperms.group.listnodes");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void execute(LuckPermsPlugin plugin, Sender sender, Group group, List<String> args) {
|
||||
Util.sendPluginMessage(sender, "&e" + group.getName() + "'s Nodes:");
|
||||
sender.sendMessage(Util.color(Util.nodesToString(group.getNodes())));
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isArgLengthInvalid(int argLength) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
+69
@@ -0,0 +1,69 @@
|
||||
package me.lucko.luckperms.commands.group.subcommands;
|
||||
|
||||
import me.lucko.luckperms.LuckPermsPlugin;
|
||||
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.exceptions.ObjectAlreadyHasException;
|
||||
import me.lucko.luckperms.groups.Group;
|
||||
import me.lucko.luckperms.utils.Patterns;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class GroupSetInherit extends SubCommand<Group> {
|
||||
public GroupSetInherit() {
|
||||
super("setinherit", "Sets another group for this group to inherit permissions from",
|
||||
"/%s group <group> setinherit <group> [server] [world]", Permission.GROUP_SETINHERIT,
|
||||
Predicate.notInRange(1, 3));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(LuckPermsPlugin plugin, Sender sender, Group group, List<String> args, String label) {
|
||||
String groupName = args.get(0).toLowerCase();
|
||||
|
||||
if (groupName.contains("/") || groupName.contains("$")) {
|
||||
sendUsage(sender, label);
|
||||
return;
|
||||
}
|
||||
|
||||
plugin.getDatastore().loadGroup(groupName, success -> {
|
||||
if (!success) {
|
||||
Message.GROUP_LOAD_ERROR.send(sender);
|
||||
} else {
|
||||
try {
|
||||
if (args.size() >= 2) {
|
||||
final String server = args.get(1).toLowerCase();
|
||||
if (Patterns.NON_ALPHA_NUMERIC.matcher(server).find()) {
|
||||
Message.SERVER_INVALID_ENTRY.send(sender);
|
||||
return;
|
||||
}
|
||||
|
||||
if (args.size() == 2) {
|
||||
group.setPermission("group." + groupName, true, server);
|
||||
Message.GROUP_SETINHERIT_SERVER_SUCCESS.send(sender, group.getName(), groupName, server);
|
||||
} else {
|
||||
final String world = args.get(2).toLowerCase();
|
||||
group.setPermission("group." + groupName, true, server, world);
|
||||
Message.GROUP_SETINHERIT_SERVER_WORLD_SUCCESS.send(sender, group.getName(), groupName, server, world);
|
||||
}
|
||||
|
||||
} else {
|
||||
group.setPermission("group." + groupName, true);
|
||||
Message.GROUP_SETINHERIT_SUCCESS.send(sender, group.getName(), groupName);
|
||||
}
|
||||
|
||||
saveGroup(group, sender, plugin);
|
||||
} catch (ObjectAlreadyHasException e) {
|
||||
Message.GROUP_ALREADY_INHERITS.send(sender, group.getName(), groupName);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> onTabComplete(Sender sender, List<String> args, LuckPermsPlugin plugin) {
|
||||
return getGroupTabComplete(args, plugin);
|
||||
}
|
||||
}
|
||||
-50
@@ -1,50 +0,0 @@
|
||||
package me.lucko.luckperms.commands.group.subcommands;
|
||||
|
||||
import me.lucko.luckperms.LuckPermsPlugin;
|
||||
import me.lucko.luckperms.commands.Sender;
|
||||
import me.lucko.luckperms.commands.Util;
|
||||
import me.lucko.luckperms.commands.group.GroupSubCommand;
|
||||
import me.lucko.luckperms.exceptions.ObjectAlreadyHasException;
|
||||
import me.lucko.luckperms.groups.Group;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class GroupSetInheritCommand extends GroupSubCommand {
|
||||
public GroupSetInheritCommand() {
|
||||
super("setinherit", "Sets another group for this group to inherit permissions from",
|
||||
"/perms group <group> setinherit <group> [server]", "luckperms.group.setinherit");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void execute(LuckPermsPlugin plugin, Sender sender, Group group, List<String> args) {
|
||||
String groupName = args.get(0).toLowerCase();
|
||||
|
||||
plugin.getDatastore().loadGroup(groupName, success -> {
|
||||
if (!success) {
|
||||
Util.sendPluginMessage(sender, groupName + " does not exist!");
|
||||
} else {
|
||||
final String node = "luckperms.group." + groupName;
|
||||
|
||||
try {
|
||||
if (args.size() == 2) {
|
||||
final String server = args.get(1).toLowerCase();
|
||||
group.setPermission(node, true, server);
|
||||
Util.sendPluginMessage(sender, "&b" + group.getName() + "&a now inherits permissions from &b" + groupName + "&a on server &b" + server + "&a.");
|
||||
} else {
|
||||
group.setPermission(node, true);
|
||||
Util.sendPluginMessage(sender, "&b" + group.getName() + "&a now inherits permissions from &b" + groupName + "&a.");
|
||||
}
|
||||
|
||||
saveGroup(group, sender, plugin);
|
||||
} catch (ObjectAlreadyHasException e) {
|
||||
Util.sendPluginMessage(sender, group.getName() + " already inherits '" + groupName + "'.");
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isArgLengthInvalid(int argLength) {
|
||||
return argLength == 0;
|
||||
}
|
||||
}
|
||||
+75
@@ -0,0 +1,75 @@
|
||||
package me.lucko.luckperms.commands.group.subcommands;
|
||||
|
||||
import me.lucko.luckperms.LuckPermsPlugin;
|
||||
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.exceptions.ObjectAlreadyHasException;
|
||||
import me.lucko.luckperms.groups.Group;
|
||||
import me.lucko.luckperms.utils.Patterns;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class GroupSetPermission extends SubCommand<Group> {
|
||||
public GroupSetPermission() {
|
||||
super("set", "Sets a permission for a group", "/%s group <group> set <node> <true|false> [server] [world]",
|
||||
Permission.GROUP_SETPERMISSION, Predicate.notInRange(2, 4));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(LuckPermsPlugin plugin, Sender sender, Group group, List<String> args, String label) {
|
||||
String node = args.get(0);
|
||||
String bool = args.get(1).toLowerCase();
|
||||
|
||||
if (node.contains("/") || node.contains("$")) {
|
||||
sendUsage(sender, label);
|
||||
return;
|
||||
}
|
||||
|
||||
if (Patterns.GROUP_MATCH.matcher(node).matches()) {
|
||||
Message.GROUP_USE_INHERIT.send(sender);
|
||||
return;
|
||||
}
|
||||
|
||||
if (!bool.equalsIgnoreCase("true") && !bool.equalsIgnoreCase("false")) {
|
||||
sendUsage(sender, label);
|
||||
return;
|
||||
}
|
||||
|
||||
boolean b = Boolean.parseBoolean(bool);
|
||||
|
||||
try {
|
||||
if (args.size() >= 3) {
|
||||
final String server = args.get(2).toLowerCase();
|
||||
if (Patterns.NON_ALPHA_NUMERIC.matcher(server).find()) {
|
||||
Message.SERVER_INVALID_ENTRY.send(sender);
|
||||
return;
|
||||
}
|
||||
|
||||
if (args.size() == 3) {
|
||||
group.setPermission(node, b, server);
|
||||
Message.SETPERMISSION_SERVER_SUCCESS.send(sender, node, bool, group.getName(), server);
|
||||
} else {
|
||||
final String world = args.get(3).toLowerCase();
|
||||
group.setPermission(node, b, server, world);
|
||||
Message.SETPERMISSION_SERVER_WORLD_SUCCESS.send(sender, node, bool, group.getName(), server, world);
|
||||
}
|
||||
|
||||
} else {
|
||||
group.setPermission(node, b);
|
||||
Message.SETPERMISSION_SUCCESS.send(sender, node, bool, group.getName());
|
||||
}
|
||||
|
||||
saveGroup(group, sender, plugin);
|
||||
} catch (ObjectAlreadyHasException e) {
|
||||
Message.ALREADY_HASPERMISSION.send(sender, group.getName());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> onTabComplete(Sender sender, List<String> args, LuckPermsPlugin plugin) {
|
||||
return getBoolTabComplete(args);
|
||||
}
|
||||
}
|
||||
-60
@@ -1,60 +0,0 @@
|
||||
package me.lucko.luckperms.commands.group.subcommands;
|
||||
|
||||
import me.lucko.luckperms.LuckPermsPlugin;
|
||||
import me.lucko.luckperms.commands.Sender;
|
||||
import me.lucko.luckperms.commands.Util;
|
||||
import me.lucko.luckperms.commands.group.GroupSubCommand;
|
||||
import me.lucko.luckperms.exceptions.ObjectAlreadyHasException;
|
||||
import me.lucko.luckperms.groups.Group;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class GroupSetPermissionCommand extends GroupSubCommand {
|
||||
public GroupSetPermissionCommand() {
|
||||
super("set", "Sets a permission for a group",
|
||||
"/perms group <group> set <node> <true|false> [server]", "luckperms.group.setpermission");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void execute(LuckPermsPlugin plugin, Sender sender, Group group, List<String> args) {
|
||||
String node = args.get(0);
|
||||
String bool = args.get(1);
|
||||
|
||||
if (node.contains("/")) {
|
||||
sendUsage(sender);
|
||||
return;
|
||||
}
|
||||
|
||||
if (node.matches(".*luckperms\\.group\\..*")) {
|
||||
Util.sendPluginMessage(sender, "Use the inherit command instead of specifying the node.");
|
||||
return;
|
||||
}
|
||||
|
||||
if (!bool.equalsIgnoreCase("true") && !bool.equalsIgnoreCase("false")) {
|
||||
sendUsage(sender);
|
||||
return;
|
||||
}
|
||||
|
||||
boolean b = Boolean.parseBoolean(bool);
|
||||
|
||||
try {
|
||||
if (args.size() == 3) {
|
||||
final String server = args.get(2).toLowerCase();
|
||||
group.setPermission(node, b, server);
|
||||
Util.sendPluginMessage(sender, "&aSet &b" + node + "&a to &b" + bool + "&a for &b" + group.getName() + "&a on server &b" + server + "&a.");
|
||||
} else {
|
||||
group.setPermission(node, b);
|
||||
Util.sendPluginMessage(sender, "&aSet &b" + node + "&a to " + bool + " for &b" + group.getName() + "&a.");
|
||||
}
|
||||
|
||||
saveGroup(group, sender, plugin);
|
||||
} catch (ObjectAlreadyHasException e) {
|
||||
Util.sendPluginMessage(sender, group.getName() + " already has this permission!");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isArgLengthInvalid(int argLength) {
|
||||
return argLength < 2;
|
||||
}
|
||||
}
|
||||
+85
@@ -0,0 +1,85 @@
|
||||
package me.lucko.luckperms.commands.group.subcommands;
|
||||
|
||||
import me.lucko.luckperms.LuckPermsPlugin;
|
||||
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.exceptions.ObjectAlreadyHasException;
|
||||
import me.lucko.luckperms.groups.Group;
|
||||
import me.lucko.luckperms.utils.DateUtil;
|
||||
import me.lucko.luckperms.utils.Patterns;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class GroupSetTempInherit extends SubCommand<Group> {
|
||||
public GroupSetTempInherit() {
|
||||
super("settempinherit", "Sets another group for this group to inherit permissions from temporarily",
|
||||
"/%s group <group> settempinherit <group> <duration> [server] [world]",
|
||||
Permission.GROUP_SET_TEMP_INHERIT, Predicate.notInRange(2, 4));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(LuckPermsPlugin plugin, Sender sender, Group group, List<String> args, String label) {
|
||||
String groupName = args.get(0).toLowerCase();
|
||||
|
||||
if (groupName.contains("/") || groupName.contains("$")) {
|
||||
sendUsage(sender, label);
|
||||
return;
|
||||
}
|
||||
|
||||
long duration;
|
||||
try {
|
||||
duration = DateUtil.parseDateDiff(args.get(1), true);
|
||||
} catch (DateUtil.IllegalDateException e) {
|
||||
Message.ILLEGAL_DATE_ERROR.send(sender, args.get(1));
|
||||
return;
|
||||
}
|
||||
|
||||
if (DateUtil.shouldExpire(duration)) {
|
||||
Message.PAST_DATE_ERROR.send(sender);
|
||||
return;
|
||||
}
|
||||
|
||||
plugin.getDatastore().loadGroup(groupName, success -> {
|
||||
if (!success) {
|
||||
Message.GROUP_LOAD_ERROR.send(sender);
|
||||
} else {
|
||||
try {
|
||||
if (args.size() >= 3) {
|
||||
final String server = args.get(2).toLowerCase();
|
||||
if (Patterns.NON_ALPHA_NUMERIC.matcher(server).find()) {
|
||||
Message.SERVER_INVALID_ENTRY.send(sender);
|
||||
return;
|
||||
}
|
||||
|
||||
if (args.size() == 3) {
|
||||
group.setPermission("group." + groupName, true, server, duration);
|
||||
Message.GROUP_SET_TEMP_INHERIT_SERVER_SUCCESS.send(sender, group.getName(), groupName, server,
|
||||
DateUtil.formatDateDiff(duration));
|
||||
} else {
|
||||
final String world = args.get(3).toLowerCase();
|
||||
group.setPermission("group." + groupName, true, server, world, duration);
|
||||
Message.GROUP_SET_TEMP_INHERIT_SERVER_WORLD_SUCCESS.send(sender, group.getName(), groupName, server,
|
||||
world, DateUtil.formatDateDiff(duration));
|
||||
}
|
||||
|
||||
} else {
|
||||
group.setPermission("group." + groupName, true, duration);
|
||||
Message.GROUP_SET_TEMP_INHERIT_SUCCESS.send(sender, group.getName(), groupName, DateUtil.formatDateDiff(duration));
|
||||
}
|
||||
|
||||
saveGroup(group, sender, plugin);
|
||||
} catch (ObjectAlreadyHasException e) {
|
||||
Message.GROUP_ALREADY_TEMP_INHERITS.send(sender, group.getName(), groupName);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> onTabComplete(Sender sender, List<String> args, LuckPermsPlugin plugin) {
|
||||
return getGroupTabComplete(args, plugin);
|
||||
}
|
||||
}
|
||||
+92
@@ -0,0 +1,92 @@
|
||||
package me.lucko.luckperms.commands.group.subcommands;
|
||||
|
||||
import me.lucko.luckperms.LuckPermsPlugin;
|
||||
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.exceptions.ObjectAlreadyHasException;
|
||||
import me.lucko.luckperms.groups.Group;
|
||||
import me.lucko.luckperms.utils.DateUtil;
|
||||
import me.lucko.luckperms.utils.Patterns;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class GroupSetTempPermission extends SubCommand<Group> {
|
||||
public GroupSetTempPermission() {
|
||||
super("settemp", "Sets a temporary permission for a group",
|
||||
"/%s group <group> settemp <node> <true|false> <duration> [server] [world]",
|
||||
Permission.GROUP_SET_TEMP_PERMISSION, Predicate.notInRange(3, 5));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(LuckPermsPlugin plugin, Sender sender, Group group, List<String> args, String label) {
|
||||
String node = args.get(0);
|
||||
String bool = args.get(1).toLowerCase();
|
||||
|
||||
if (node.contains("/") || node.contains("$")) {
|
||||
sendUsage(sender, label);
|
||||
return;
|
||||
}
|
||||
|
||||
if (Patterns.GROUP_MATCH.matcher(node).matches()) {
|
||||
Message.GROUP_USE_INHERIT.send(sender);
|
||||
return;
|
||||
}
|
||||
|
||||
if (!bool.equalsIgnoreCase("true") && !bool.equalsIgnoreCase("false")) {
|
||||
sendUsage(sender, label);
|
||||
return;
|
||||
}
|
||||
|
||||
boolean b = Boolean.parseBoolean(bool);
|
||||
|
||||
long duration;
|
||||
try {
|
||||
duration = DateUtil.parseDateDiff(args.get(2), true);
|
||||
} catch (DateUtil.IllegalDateException e) {
|
||||
Message.ILLEGAL_DATE_ERROR.send(sender, args.get(2));
|
||||
return;
|
||||
}
|
||||
|
||||
if (DateUtil.shouldExpire(duration)) {
|
||||
Message.PAST_DATE_ERROR.send(sender);
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
if (args.size() >= 4) {
|
||||
final String server = args.get(3).toLowerCase();
|
||||
if (Patterns.NON_ALPHA_NUMERIC.matcher(server).find()) {
|
||||
Message.SERVER_INVALID_ENTRY.send(sender);
|
||||
return;
|
||||
}
|
||||
|
||||
if (args.size() == 4) {
|
||||
group.setPermission(node, b, server, duration);
|
||||
Message.SETPERMISSION_TEMP_SERVER_SUCCESS.send(sender, node, bool, group.getName(), server,
|
||||
DateUtil.formatDateDiff(duration));
|
||||
} else {
|
||||
final String world = args.get(4).toLowerCase();
|
||||
group.setPermission(node, b, server, world, duration);
|
||||
Message.SETPERMISSION_TEMP_SERVER_WORLD_SUCCESS.send(sender, node, bool, group.getName(), server,
|
||||
world, DateUtil.formatDateDiff(duration));
|
||||
}
|
||||
|
||||
} else {
|
||||
group.setPermission(node, b, duration);
|
||||
Message.SETPERMISSION_TEMP_SUCCESS.send(sender, node, bool, group.getName(), DateUtil.formatDateDiff(duration));
|
||||
}
|
||||
|
||||
saveGroup(group, sender, plugin);
|
||||
} catch (ObjectAlreadyHasException e) {
|
||||
Message.ALREADY_HAS_TEMP_PERMISSION.send(sender, group.getName());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> onTabComplete(Sender sender, List<String> args, LuckPermsPlugin plugin) {
|
||||
return getBoolTabComplete(args);
|
||||
}
|
||||
}
|
||||
+34
@@ -0,0 +1,34 @@
|
||||
package me.lucko.luckperms.commands.group.subcommands;
|
||||
|
||||
import me.lucko.luckperms.LuckPermsPlugin;
|
||||
import me.lucko.luckperms.commands.Predicate;
|
||||
import me.lucko.luckperms.commands.Sender;
|
||||
import me.lucko.luckperms.commands.SubCommand;
|
||||
import me.lucko.luckperms.commands.Util;
|
||||
import me.lucko.luckperms.constants.Message;
|
||||
import me.lucko.luckperms.constants.Permission;
|
||||
import me.lucko.luckperms.groups.Group;
|
||||
import me.lucko.luckperms.tracks.Track;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class GroupShowTracks extends SubCommand<Group> {
|
||||
public GroupShowTracks() {
|
||||
super("showtracks", "Lists the tracks that this group features on", "/%s group <group> showtracks",
|
||||
Permission.GROUP_SHOWTRACKS, Predicate.alwaysFalse());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(LuckPermsPlugin plugin, Sender sender, Group group, List<String> args, String label) {
|
||||
plugin.getDatastore().loadAllTracks(success -> {
|
||||
if (!success) {
|
||||
Message.TRACKS_LOAD_ERROR.send(sender);
|
||||
return;
|
||||
}
|
||||
|
||||
Message.TRACKS_LIST.send(sender, Util.listToCommaSep(
|
||||
plugin.getTrackManager().getApplicableTracks(group.getName()).stream().map(Track::getName).collect(Collectors.toList())));
|
||||
});
|
||||
}
|
||||
}
|
||||
+62
@@ -0,0 +1,62 @@
|
||||
package me.lucko.luckperms.commands.group.subcommands;
|
||||
|
||||
import me.lucko.luckperms.LuckPermsPlugin;
|
||||
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.exceptions.ObjectLacksException;
|
||||
import me.lucko.luckperms.groups.Group;
|
||||
import me.lucko.luckperms.utils.Patterns;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class GroupUnSetPermission extends SubCommand<Group> {
|
||||
public GroupUnSetPermission() {
|
||||
super("unset", "Unsets a permission for a group", "/%s group <group> unset <node> [server] [world]",
|
||||
Permission.GROUP_UNSETPERMISSION, Predicate.notInRange(1, 3));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(LuckPermsPlugin plugin, Sender sender, Group group, List<String> args, String label) {
|
||||
String node = args.get(0);
|
||||
|
||||
if (node.contains("/") || node.contains("$")) {
|
||||
sendUsage(sender, label);
|
||||
return;
|
||||
}
|
||||
|
||||
if (Patterns.GROUP_MATCH.matcher(node).matches()) {
|
||||
Message.GROUP_USE_UNINHERIT.send(sender);
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
if (args.size() >= 2) {
|
||||
final String server = args.get(1).toLowerCase();
|
||||
if (Patterns.NON_ALPHA_NUMERIC.matcher(server).find()) {
|
||||
Message.SERVER_INVALID_ENTRY.send(sender);
|
||||
return;
|
||||
}
|
||||
|
||||
if (args.size() == 2) {
|
||||
group.unsetPermission(node, server);
|
||||
Message.UNSETPERMISSION_SERVER_SUCCESS.send(sender, node, group.getName(), server);
|
||||
} else {
|
||||
final String world = args.get(2).toLowerCase();
|
||||
group.unsetPermission(node, server, world);
|
||||
Message.UNSETPERMISSION_SERVER_WORLD_SUCCESS.send(sender, node, group.getName(), server, world);
|
||||
}
|
||||
|
||||
} else {
|
||||
group.unsetPermission(node);
|
||||
Message.UNSETPERMISSION_SUCCESS.send(sender, node, group.getName());
|
||||
}
|
||||
|
||||
saveGroup(group, sender, plugin);
|
||||
} catch (ObjectLacksException e) {
|
||||
Message.DOES_NOT_HAVEPERMISSION.send(sender, group.getName());
|
||||
}
|
||||
}
|
||||
}
|
||||
-52
@@ -1,52 +0,0 @@
|
||||
package me.lucko.luckperms.commands.group.subcommands;
|
||||
|
||||
import me.lucko.luckperms.LuckPermsPlugin;
|
||||
import me.lucko.luckperms.commands.Sender;
|
||||
import me.lucko.luckperms.commands.Util;
|
||||
import me.lucko.luckperms.commands.group.GroupSubCommand;
|
||||
import me.lucko.luckperms.exceptions.ObjectLacksPermissionException;
|
||||
import me.lucko.luckperms.groups.Group;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class GroupUnSetPermissionCommand extends GroupSubCommand {
|
||||
public GroupUnSetPermissionCommand() {
|
||||
super("unset", "Unsets a permission for a group",
|
||||
"/perms group <group> unset <node> [server]", "luckperms.group.unsetpermission");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void execute(LuckPermsPlugin plugin, Sender sender, Group group, List<String> args) {
|
||||
String node = args.get(0);
|
||||
|
||||
if (node.contains("/")) {
|
||||
sendUsage(sender);
|
||||
return;
|
||||
}
|
||||
|
||||
if (node.matches(".*luckperms\\.group\\..*")) {
|
||||
Util.sendPluginMessage(sender, "Use the uninherit command instead of specifying the node.");
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
if (args.size() == 2) {
|
||||
final String server = args.get(1).toLowerCase();
|
||||
group.unsetPermission(node, server);
|
||||
Util.sendPluginMessage(sender, "&aUnset &b" + node + "&a for &b" + group.getName() + "&a on server &b" + server + "&a.");
|
||||
} else {
|
||||
group.unsetPermission(node);
|
||||
Util.sendPluginMessage(sender, "&aUnset &b" + node + "&a for &b" + group.getName() + "&a.");
|
||||
}
|
||||
|
||||
saveGroup(group, sender, plugin);
|
||||
} catch (ObjectLacksPermissionException e) {
|
||||
Util.sendPluginMessage(sender, "That group does not have this permission set.");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isArgLengthInvalid(int argLength) {
|
||||
return argLength == 0;
|
||||
}
|
||||
}
|
||||
+63
@@ -0,0 +1,63 @@
|
||||
package me.lucko.luckperms.commands.group.subcommands;
|
||||
|
||||
import me.lucko.luckperms.LuckPermsPlugin;
|
||||
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.exceptions.ObjectLacksException;
|
||||
import me.lucko.luckperms.groups.Group;
|
||||
import me.lucko.luckperms.utils.Patterns;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class GroupUnsetInherit extends SubCommand<Group> {
|
||||
public GroupUnsetInherit() {
|
||||
super("unsetinherit", "Unsets another group for this group to inherit permissions from",
|
||||
"/%s group <group> unsetinherit <group> [server] [world]", Permission.GROUP_UNSETINHERIT,
|
||||
Predicate.notInRange(1, 3));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(LuckPermsPlugin plugin, Sender sender, Group group, List<String> args, String label) {
|
||||
String groupName = args.get(0).toLowerCase();
|
||||
|
||||
if (groupName.contains("/") || groupName.contains("$")) {
|
||||
sendUsage(sender, label);
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
if (args.size() >= 2) {
|
||||
final String server = args.get(1).toLowerCase();
|
||||
if (Patterns.NON_ALPHA_NUMERIC.matcher(server).find()) {
|
||||
Message.SERVER_INVALID_ENTRY.send(sender);
|
||||
return;
|
||||
}
|
||||
|
||||
if (args.size() == 2) {
|
||||
group.unsetPermission("group." + groupName, server);
|
||||
Message.GROUP_UNSETINHERIT_SERVER_SUCCESS.send(sender, group.getName(), groupName, server);
|
||||
} else {
|
||||
final String world = args.get(2).toLowerCase();
|
||||
group.unsetPermission("group." + groupName, server, world);
|
||||
Message.GROUP_UNSETINHERIT_SERVER_WORLD_SUCCESS.send(sender, group.getName(), groupName, server, world);
|
||||
}
|
||||
|
||||
} else {
|
||||
group.unsetPermission("group." + groupName);
|
||||
Message.GROUP_UNSETINHERIT_SUCCESS.send(sender, group.getName(), groupName);
|
||||
}
|
||||
|
||||
saveGroup(group, sender, plugin);
|
||||
} catch (ObjectLacksException e) {
|
||||
Message.GROUP_DOES_NOT_INHERIT.send(sender, group.getName(), groupName);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> onTabComplete(Sender sender, List<String> args, LuckPermsPlugin plugin) {
|
||||
return getGroupTabComplete(args, plugin);
|
||||
}
|
||||
}
|
||||
-42
@@ -1,42 +0,0 @@
|
||||
package me.lucko.luckperms.commands.group.subcommands;
|
||||
|
||||
import me.lucko.luckperms.LuckPermsPlugin;
|
||||
import me.lucko.luckperms.commands.Sender;
|
||||
import me.lucko.luckperms.commands.Util;
|
||||
import me.lucko.luckperms.commands.group.GroupSubCommand;
|
||||
import me.lucko.luckperms.exceptions.ObjectLacksPermissionException;
|
||||
import me.lucko.luckperms.groups.Group;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class GroupUnsetInheritCommand extends GroupSubCommand {
|
||||
public GroupUnsetInheritCommand() {
|
||||
super("unsetinherit", "Unsets another group for this group to inherit permissions from",
|
||||
"/perms group <group> unsetinherit <group> [server]", "luckperms.group.unsetinherit");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void execute(LuckPermsPlugin plugin, Sender sender, Group group, List<String> args) {
|
||||
String groupName = args.get(0).toLowerCase();
|
||||
|
||||
String server;
|
||||
if (args.size() == 2) {
|
||||
server = args.get(1).toLowerCase();
|
||||
} else {
|
||||
server = "global";
|
||||
}
|
||||
|
||||
try {
|
||||
group.unsetPermission("luckperms.group." + groupName, server);
|
||||
Util.sendPluginMessage(sender, "&b" + group.getName() + "&a no longer inherits permissions from &b" + groupName + "&a on server &b" + server + "&a.");
|
||||
saveGroup(group, sender, plugin);
|
||||
} catch (ObjectLacksPermissionException e) {
|
||||
Util.sendPluginMessage(sender, "That group does not inherit '" + groupName + "'.");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isArgLengthInvalid(int argLength) {
|
||||
return argLength == 0;
|
||||
}
|
||||
}
|
||||
+63
@@ -0,0 +1,63 @@
|
||||
package me.lucko.luckperms.commands.group.subcommands;
|
||||
|
||||
import me.lucko.luckperms.LuckPermsPlugin;
|
||||
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.exceptions.ObjectLacksException;
|
||||
import me.lucko.luckperms.groups.Group;
|
||||
import me.lucko.luckperms.utils.Patterns;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class GroupUnsetTempInherit extends SubCommand<Group> {
|
||||
public GroupUnsetTempInherit() {
|
||||
super("unsettempinherit", "Unsets another group for this group to inherit permissions from",
|
||||
"/%s group <group> unsettempinherit <group> [server] [world]", Permission.GROUP_UNSET_TEMP_INHERIT,
|
||||
Predicate.notInRange(1, 3));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(LuckPermsPlugin plugin, Sender sender, Group group, List<String> args, String label) {
|
||||
String groupName = args.get(0).toLowerCase();
|
||||
|
||||
if (groupName.contains("/") || groupName.contains("$")) {
|
||||
sendUsage(sender, label);
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
if (args.size() >= 2) {
|
||||
final String server = args.get(1).toLowerCase();
|
||||
if (Patterns.NON_ALPHA_NUMERIC.matcher(server).find()) {
|
||||
Message.SERVER_INVALID_ENTRY.send(sender);
|
||||
return;
|
||||
}
|
||||
|
||||
if (args.size() == 2) {
|
||||
group.unsetPermission("group." + groupName, server, true);
|
||||
Message.GROUP_UNSET_TEMP_INHERIT_SERVER_SUCCESS.send(sender, group.getName(), groupName, server);
|
||||
} else {
|
||||
final String world = args.get(2).toLowerCase();
|
||||
group.unsetPermission("group." + groupName, server, world, true);
|
||||
Message.GROUP_UNSET_TEMP_INHERIT_SERVER_WORLD_SUCCESS.send(sender, group.getName(), groupName, server, world);
|
||||
}
|
||||
|
||||
} else {
|
||||
group.unsetPermission("group." + groupName, true);
|
||||
Message.GROUP_UNSET_TEMP_INHERIT_SUCCESS.send(sender, group.getName(), groupName);
|
||||
}
|
||||
|
||||
saveGroup(group, sender, plugin);
|
||||
} catch (ObjectLacksException e) {
|
||||
Message.GROUP_DOES_NOT_TEMP_INHERIT.send(sender, group.getName(), groupName);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> onTabComplete(Sender sender, List<String> args, LuckPermsPlugin plugin) {
|
||||
return getGroupTabComplete(args, plugin);
|
||||
}
|
||||
}
|
||||
+63
@@ -0,0 +1,63 @@
|
||||
package me.lucko.luckperms.commands.group.subcommands;
|
||||
|
||||
import me.lucko.luckperms.LuckPermsPlugin;
|
||||
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.exceptions.ObjectLacksException;
|
||||
import me.lucko.luckperms.groups.Group;
|
||||
import me.lucko.luckperms.utils.Patterns;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class GroupUnsetTempPermission extends SubCommand<Group> {
|
||||
public GroupUnsetTempPermission() {
|
||||
super("unsettemp", "Unsets a temporary permission for a group",
|
||||
"/%s group <group> unsettemp <node> [server] [world]", Permission.GROUP_UNSET_TEMP_PERMISSION,
|
||||
Predicate.notInRange(1, 3));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(LuckPermsPlugin plugin, Sender sender, Group group, List<String> args, String label) {
|
||||
String node = args.get(0);
|
||||
|
||||
if (node.contains("/") || node.contains("$")) {
|
||||
sendUsage(sender, label);
|
||||
return;
|
||||
}
|
||||
|
||||
if (Patterns.GROUP_MATCH.matcher(node).matches()) {
|
||||
Message.GROUP_USE_UNINHERIT.send(sender);
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
if (args.size() >= 2) {
|
||||
final String server = args.get(1).toLowerCase();
|
||||
if (Patterns.NON_ALPHA_NUMERIC.matcher(server).find()) {
|
||||
Message.SERVER_INVALID_ENTRY.send(sender);
|
||||
return;
|
||||
}
|
||||
|
||||
if (args.size() == 2) {
|
||||
group.unsetPermission(node, server);
|
||||
Message.UNSET_TEMP_PERMISSION_SERVER_SUCCESS.send(sender, node, group.getName(), server);
|
||||
} else {
|
||||
final String world = args.get(2).toLowerCase();
|
||||
group.unsetPermission(node, server, world);
|
||||
Message.UNSET_TEMP_PERMISSION_SERVER_WORLD_SUCCESS.send(sender, node, group.getName(), server, world);
|
||||
}
|
||||
|
||||
} else {
|
||||
group.unsetPermission(node, true);
|
||||
Message.UNSET_TEMP_PERMISSION_SUCCESS.send(sender, node, group.getName());
|
||||
}
|
||||
|
||||
saveGroup(group, sender, plugin);
|
||||
} catch (ObjectLacksException e) {
|
||||
Message.DOES_NOT_HAVE_TEMP_PERMISSION.send(sender, group.getName());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,34 +1,22 @@
|
||||
package me.lucko.luckperms.commands.misc;
|
||||
|
||||
import me.lucko.luckperms.LuckPermsPlugin;
|
||||
import me.lucko.luckperms.commands.MainCommand;
|
||||
import me.lucko.luckperms.commands.Sender;
|
||||
import me.lucko.luckperms.commands.SubCommand;
|
||||
import me.lucko.luckperms.commands.Util;
|
||||
import me.lucko.luckperms.commands.SingleMainCommand;
|
||||
import me.lucko.luckperms.constants.Message;
|
||||
import me.lucko.luckperms.constants.Permission;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class DebugCommand extends MainCommand {
|
||||
public class DebugCommand extends SingleMainCommand {
|
||||
public DebugCommand() {
|
||||
super("Debug", "/perms debug", 0);
|
||||
super("Debug", "/%s debug", 0, Permission.DEBUG);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void execute(LuckPermsPlugin plugin, Sender sender, List<String> args) {
|
||||
if (!sender.hasPermission("luckperms.debug")) {
|
||||
Util.sendPluginMessage(sender, "You do not have permission to use this command!");
|
||||
return;
|
||||
}
|
||||
|
||||
Util.sendPluginMessage(sender, "&d>> Debug Info");
|
||||
Util.sendPluginMessage(sender, "&eOnline Players: &6" + plugin.getPlayerCount());
|
||||
Util.sendPluginMessage(sender, "&eLoaded Users: &6" + plugin.getUserManager().getUsers().size());
|
||||
Util.sendPluginMessage(sender, "&eLoaded Groups: &6" + plugin.getGroupManager().getGroups().size());
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<? extends SubCommand> getSubCommands() {
|
||||
return new ArrayList<>();
|
||||
protected void execute(LuckPermsPlugin plugin, Sender sender, List<String> args, String label) {
|
||||
Message.DEBUG.send(sender, plugin.getPlayerCount(), plugin.getUserManager().getUsers().size(),
|
||||
plugin.getGroupManager().getGroups().size(), plugin.getTrackManager().getTracks().size()
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -1,33 +1,23 @@
|
||||
package me.lucko.luckperms.commands.misc;
|
||||
|
||||
import me.lucko.luckperms.LuckPermsPlugin;
|
||||
import me.lucko.luckperms.commands.MainCommand;
|
||||
import me.lucko.luckperms.commands.Sender;
|
||||
import me.lucko.luckperms.commands.SubCommand;
|
||||
import me.lucko.luckperms.commands.Util;
|
||||
import me.lucko.luckperms.commands.SingleMainCommand;
|
||||
import me.lucko.luckperms.constants.Message;
|
||||
import me.lucko.luckperms.constants.Permission;
|
||||
import me.lucko.luckperms.utils.LPConfiguration;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class InfoCommand extends MainCommand {
|
||||
public class InfoCommand extends SingleMainCommand {
|
||||
public InfoCommand() {
|
||||
super("Info", "/perms info", 0);
|
||||
super("Info", "/%s info", 0, Permission.INFO);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void execute(LuckPermsPlugin plugin, Sender sender, List<String> args) {
|
||||
if (!sender.hasPermission("luckperms.info")) {
|
||||
Util.sendPluginMessage(sender, "You do not have permission to use this command!");
|
||||
return;
|
||||
}
|
||||
|
||||
Util.sendPluginMessage(sender, "&6Running &bLuckPerms " + plugin.getVersion() + "&6.");
|
||||
Util.sendPluginMessage(sender, "&eAuthor: &6Luck");
|
||||
Util.sendPluginMessage(sender, "&eStorage Method: &6" + plugin.getDatastore().getName());
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<? extends SubCommand> getSubCommands() {
|
||||
return new ArrayList<>();
|
||||
protected void execute(LuckPermsPlugin plugin, Sender sender, List<String> args, String label) {
|
||||
final LPConfiguration c = plugin.getConfiguration();
|
||||
Message.INFO.send(sender, plugin.getVersion(), plugin.getDatastore().getName(), c.getServer(),
|
||||
c.getDefaultGroupName(), c.getSyncTime(), c.getIncludeGlobalPerms(), c.getOnlineMode());
|
||||
}
|
||||
}
|
||||
@@ -1,32 +1,21 @@
|
||||
package me.lucko.luckperms.commands.misc;
|
||||
|
||||
import me.lucko.luckperms.LuckPermsPlugin;
|
||||
import me.lucko.luckperms.commands.MainCommand;
|
||||
import me.lucko.luckperms.commands.Sender;
|
||||
import me.lucko.luckperms.commands.SubCommand;
|
||||
import me.lucko.luckperms.commands.Util;
|
||||
import me.lucko.luckperms.commands.SingleMainCommand;
|
||||
import me.lucko.luckperms.constants.Message;
|
||||
import me.lucko.luckperms.constants.Permission;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class SyncCommand extends MainCommand {
|
||||
public class SyncCommand extends SingleMainCommand {
|
||||
public SyncCommand() {
|
||||
super("Sync", "/perms sync", 0);
|
||||
super("Sync", "/%s sync", 0, Permission.SYNC);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void execute(LuckPermsPlugin plugin, Sender sender, List<String> args) {
|
||||
if (!sender.hasPermission("luckperms.sync")) {
|
||||
Util.sendPluginMessage(sender, "You do not have permission to use this command!");
|
||||
return;
|
||||
}
|
||||
|
||||
Util.sendPluginMessage(sender, "&bRunning update task for all online users.");
|
||||
protected void execute(LuckPermsPlugin plugin, Sender sender, List<String> args, String label) {
|
||||
Message.UPDATE_TASK_RUN.send(sender);
|
||||
plugin.runUpdateTask();
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<? extends SubCommand> getSubCommands() {
|
||||
return new ArrayList<>();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,51 @@
|
||||
package me.lucko.luckperms.commands.track;
|
||||
|
||||
import me.lucko.luckperms.LuckPermsPlugin;
|
||||
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.utils.Patterns;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class CreateTrack extends SingleMainCommand {
|
||||
public CreateTrack() {
|
||||
super("CreateTrack", "/%s createtrack <track>", 1, Permission.CREATE_TRACK);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void execute(LuckPermsPlugin plugin, Sender sender, List<String> args, String label) {
|
||||
if (args.size() == 0) {
|
||||
sendUsage(sender, label);
|
||||
return;
|
||||
}
|
||||
|
||||
String trackName = args.get(0).toLowerCase();
|
||||
|
||||
if (trackName.length() > 36) {
|
||||
Message.TRACK_NAME_TOO_LONG.send(sender, trackName);
|
||||
return;
|
||||
}
|
||||
|
||||
if (Patterns.NON_ALPHA_NUMERIC.matcher(trackName).find()) {
|
||||
Message.TRACK_INVALID_ENTRY.send(sender);
|
||||
return;
|
||||
}
|
||||
|
||||
plugin.getDatastore().loadTrack(trackName, success -> {
|
||||
if (success) {
|
||||
Message.TRACK_ALREADY_EXISTS.send(sender);
|
||||
} else {
|
||||
plugin.getDatastore().createAndLoadTrack(trackName, success1 -> {
|
||||
if (!success1) {
|
||||
Message.CREATE_TRACK_ERROR.send(sender);
|
||||
} else {
|
||||
Message.CREATE_SUCCESS.send(sender, trackName);
|
||||
plugin.runUpdateTask();
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,71 @@
|
||||
package me.lucko.luckperms.commands.track;
|
||||
|
||||
import me.lucko.luckperms.LuckPermsPlugin;
|
||||
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.tracks.Track;
|
||||
import me.lucko.luckperms.utils.Patterns;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class DeleteTrack extends SingleMainCommand {
|
||||
public DeleteTrack() {
|
||||
super("DeleteTrack", "/%s deletetrack <track>", 1, Permission.DELETE_TRACK);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void execute(LuckPermsPlugin plugin, Sender sender, List<String> args, String label) {
|
||||
if (args.size() == 0) {
|
||||
sendUsage(sender, label);
|
||||
return;
|
||||
}
|
||||
|
||||
String trackName = args.get(0).toLowerCase();
|
||||
|
||||
if (Patterns.NON_ALPHA_NUMERIC.matcher(trackName).find()) {
|
||||
Message.TRACK_INVALID_ENTRY.send(sender);
|
||||
return;
|
||||
}
|
||||
|
||||
plugin.getDatastore().loadTrack(trackName, success -> {
|
||||
if (!success) {
|
||||
Message.TRACK_DOES_NOT_EXIST.send(sender);
|
||||
} else {
|
||||
|
||||
Track track = plugin.getTrackManager().getTrack(trackName);
|
||||
if (track == null) {
|
||||
Message.TRACK_LOAD_ERROR.send(sender);
|
||||
} else {
|
||||
plugin.getDatastore().deleteTrack(track, success1 -> {
|
||||
if (!success1) {
|
||||
Message.DELETE_TRACK_ERROR.send(sender);
|
||||
} else {
|
||||
Message.DELETE_SUCCESS.send(sender, trackName);
|
||||
plugin.runUpdateTask();
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
protected List<String> onTabComplete(Sender sender, List<String> args, LuckPermsPlugin plugin) {
|
||||
final List<String> tracks = new ArrayList<>(plugin.getTrackManager().getTracks().keySet());
|
||||
|
||||
if (args.size() <= 1) {
|
||||
if (args.isEmpty() || args.get(0).equalsIgnoreCase("")) {
|
||||
return tracks;
|
||||
}
|
||||
|
||||
return tracks.stream().filter(s -> s.toLowerCase().startsWith(args.get(0).toLowerCase())).collect(Collectors.toList());
|
||||
}
|
||||
|
||||
return Collections.emptyList();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
package me.lucko.luckperms.commands.track;
|
||||
|
||||
import me.lucko.luckperms.LuckPermsPlugin;
|
||||
import me.lucko.luckperms.commands.Sender;
|
||||
import me.lucko.luckperms.commands.SingleMainCommand;
|
||||
import me.lucko.luckperms.commands.Util;
|
||||
import me.lucko.luckperms.constants.Message;
|
||||
import me.lucko.luckperms.constants.Permission;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class ListTracks extends SingleMainCommand {
|
||||
public ListTracks() {
|
||||
super("ListTracks", "/%s listtracks", 0, Permission.LIST_TRACKS);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void execute(LuckPermsPlugin plugin, Sender sender, List<String> args, String label) {
|
||||
plugin.getDatastore().loadAllTracks(success -> {
|
||||
if (!success) {
|
||||
Message.TRACKS_LOAD_ERROR.send(sender);
|
||||
} else {
|
||||
Message.TRACKS_LIST.send(sender, Util.listToCommaSep(new ArrayList<>(plugin.getTrackManager().getTracks().keySet())));
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
package me.lucko.luckperms.commands.track;
|
||||
|
||||
import me.lucko.luckperms.LuckPermsPlugin;
|
||||
import me.lucko.luckperms.api.data.Callback;
|
||||
import me.lucko.luckperms.commands.MainCommand;
|
||||
import me.lucko.luckperms.commands.Sender;
|
||||
import me.lucko.luckperms.constants.Message;
|
||||
import me.lucko.luckperms.tracks.Track;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class TrackMainCommand extends MainCommand<Track> {
|
||||
public TrackMainCommand() {
|
||||
super("Track", "/%s track <track>", 2);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void getTarget(String target, LuckPermsPlugin plugin, Sender sender, Callback<Track> onSuccess) {
|
||||
plugin.getDatastore().loadTrack(target, success -> {
|
||||
if (!success) {
|
||||
Message.TRACK_NOT_FOUND.send(sender);
|
||||
return;
|
||||
}
|
||||
|
||||
Track track = plugin.getTrackManager().getTrack(target);
|
||||
if (track == null) {
|
||||
Message.TRACK_NOT_FOUND.send(sender);
|
||||
return;
|
||||
}
|
||||
|
||||
onSuccess.onComplete(track);
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
protected List<String> getObjects(LuckPermsPlugin plugin) {
|
||||
return new ArrayList<>(plugin.getTrackManager().getTracks().keySet());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,52 @@
|
||||
package me.lucko.luckperms.commands.track.subcommands;
|
||||
|
||||
import me.lucko.luckperms.LuckPermsPlugin;
|
||||
import me.lucko.luckperms.commands.Predicate;
|
||||
import me.lucko.luckperms.commands.Sender;
|
||||
import me.lucko.luckperms.commands.SubCommand;
|
||||
import me.lucko.luckperms.commands.Util;
|
||||
import me.lucko.luckperms.constants.Message;
|
||||
import me.lucko.luckperms.constants.Permission;
|
||||
import me.lucko.luckperms.exceptions.ObjectAlreadyHasException;
|
||||
import me.lucko.luckperms.groups.Group;
|
||||
import me.lucko.luckperms.tracks.Track;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class TrackAppend extends SubCommand<Track> {
|
||||
public TrackAppend() {
|
||||
super("append", "Appends a group onto the end of the track", "/%s track <track> append <group>",
|
||||
Permission.TRACK_APPEND, Predicate.not(1));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(LuckPermsPlugin plugin, Sender sender, Track track, List<String> args, String label) {
|
||||
String groupName = args.get(0).toLowerCase();
|
||||
|
||||
plugin.getDatastore().loadGroup(groupName, success -> {
|
||||
if (!success) {
|
||||
Message.GROUP_DOES_NOT_EXIST.send(sender);
|
||||
} else {
|
||||
Group group = plugin.getGroupManager().getGroup(groupName);
|
||||
if (group == null) {
|
||||
Message.GROUP_DOES_NOT_EXIST.send(sender);
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
track.appendGroup(group);
|
||||
Message.TRACK_APPEND_SUCCESS.send(sender, group.getName(), track.getName());
|
||||
Message.EMPTY.send(sender, Util.listToArrowSep(track.getGroups(), group.getName()));
|
||||
saveTrack(track, sender, plugin);
|
||||
} catch (ObjectAlreadyHasException e) {
|
||||
Message.TRACK_ALREADY_CONTAINS.send(sender, track.getName(), group.getName());
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> onTabComplete(Sender sender, List<String> args, LuckPermsPlugin plugin) {
|
||||
return getGroupTabComplete(args, plugin);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
package me.lucko.luckperms.commands.track.subcommands;
|
||||
|
||||
import me.lucko.luckperms.LuckPermsPlugin;
|
||||
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.tracks.Track;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class TrackClear extends SubCommand<Track> {
|
||||
public TrackClear() {
|
||||
super("clear", "Clears the groups on the track", "/%s track <track> clear", Permission.TRACK_CLEAR,
|
||||
Predicate.alwaysFalse());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(LuckPermsPlugin plugin, Sender sender, Track track, List<String> args, String label) {
|
||||
track.clearGroups();
|
||||
Message.TRACK_CLEAR.send(sender, track.getName());
|
||||
saveTrack(track, sender, plugin);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
package me.lucko.luckperms.commands.track.subcommands;
|
||||
|
||||
import me.lucko.luckperms.LuckPermsPlugin;
|
||||
import me.lucko.luckperms.commands.Predicate;
|
||||
import me.lucko.luckperms.commands.Sender;
|
||||
import me.lucko.luckperms.commands.SubCommand;
|
||||
import me.lucko.luckperms.commands.Util;
|
||||
import me.lucko.luckperms.constants.Message;
|
||||
import me.lucko.luckperms.constants.Permission;
|
||||
import me.lucko.luckperms.tracks.Track;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class TrackInfo extends SubCommand<Track> {
|
||||
public TrackInfo() {
|
||||
super("info", "Gives info about the track", "/%s track <track> info", Permission.TRACK_INFO,
|
||||
Predicate.alwaysFalse());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(LuckPermsPlugin plugin, Sender sender, Track track, List<String> args, String label) {
|
||||
Message.TRACK_INFO.send(sender, track.getName(), Util.listToArrowSep(track.getGroups()));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,61 @@
|
||||
package me.lucko.luckperms.commands.track.subcommands;
|
||||
|
||||
import me.lucko.luckperms.LuckPermsPlugin;
|
||||
import me.lucko.luckperms.commands.Predicate;
|
||||
import me.lucko.luckperms.commands.Sender;
|
||||
import me.lucko.luckperms.commands.SubCommand;
|
||||
import me.lucko.luckperms.commands.Util;
|
||||
import me.lucko.luckperms.constants.Message;
|
||||
import me.lucko.luckperms.constants.Permission;
|
||||
import me.lucko.luckperms.exceptions.ObjectAlreadyHasException;
|
||||
import me.lucko.luckperms.groups.Group;
|
||||
import me.lucko.luckperms.tracks.Track;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class TrackInsert extends SubCommand<Track> {
|
||||
public TrackInsert() {
|
||||
super("insert", "Inserts a group at a given position along the track",
|
||||
"/%s track <track> insert <group> <position>", Permission.TRACK_INSERT, Predicate.not(2));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(LuckPermsPlugin plugin, Sender sender, Track track, List<String> args, String label) {
|
||||
String groupName = args.get(0).toLowerCase();
|
||||
int pos;
|
||||
try {
|
||||
pos = Integer.parseInt(args.get(1));
|
||||
} catch (NumberFormatException e) {
|
||||
Message.TRACK_INSERT_ERROR_NUMBER.send(sender, args.get(1));
|
||||
return;
|
||||
}
|
||||
|
||||
plugin.getDatastore().loadGroup(groupName, success -> {
|
||||
if (!success) {
|
||||
Message.GROUP_DOES_NOT_EXIST.send(sender);
|
||||
} else {
|
||||
Group group = plugin.getGroupManager().getGroup(groupName);
|
||||
if (group == null) {
|
||||
Message.GROUP_DOES_NOT_EXIST.send(sender);
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
track.insertGroup(group, pos - 1);
|
||||
Message.TRACK_INSERT_SUCCESS.send(sender, group.getName(), track.getName(), pos);
|
||||
Message.EMPTY.send(sender, Util.listToArrowSep(track.getGroups(), group.getName()));
|
||||
saveTrack(track, sender, plugin);
|
||||
} catch (ObjectAlreadyHasException e) {
|
||||
Message.TRACK_ALREADY_CONTAINS.send(sender, track.getName(), group.getName());
|
||||
} catch (IndexOutOfBoundsException e) {
|
||||
Message.TRACK_INSERT_ERROR_INVALID_POS.send(sender, pos);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> onTabComplete(Sender sender, List<String> args, LuckPermsPlugin plugin) {
|
||||
return getGroupTabComplete(args, plugin);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
package me.lucko.luckperms.commands.track.subcommands;
|
||||
|
||||
import me.lucko.luckperms.LuckPermsPlugin;
|
||||
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.exceptions.ObjectLacksException;
|
||||
import me.lucko.luckperms.tracks.Track;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class TrackRemove extends SubCommand<Track> {
|
||||
public TrackRemove() {
|
||||
super("remove", "Removes a group from the track", "/%s track <track> remove <group>", Permission.TRACK_REMOVE,
|
||||
Predicate.not(1));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(LuckPermsPlugin plugin, Sender sender, Track track, List<String> args, String label) {
|
||||
String groupName = args.get(0).toLowerCase();
|
||||
try {
|
||||
track.removeGroup(groupName);
|
||||
Message.TRACK_REMOVE_SUCCESS.send(sender, groupName, track.getName());
|
||||
saveTrack(track, sender, plugin);
|
||||
} catch (ObjectLacksException e) {
|
||||
Message.TRACK_DOES_NOT_CONTAIN.send(sender, track.getName(), groupName);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> onTabComplete(Sender sender, List<String> args, LuckPermsPlugin plugin) {
|
||||
return getGroupTabComplete(args, plugin);
|
||||
}
|
||||
}
|
||||
@@ -1,115 +1,72 @@
|
||||
package me.lucko.luckperms.commands.user;
|
||||
|
||||
import me.lucko.luckperms.LuckPermsPlugin;
|
||||
import me.lucko.luckperms.api.data.Callback;
|
||||
import me.lucko.luckperms.commands.MainCommand;
|
||||
import me.lucko.luckperms.commands.Sender;
|
||||
import me.lucko.luckperms.commands.SubCommand;
|
||||
import me.lucko.luckperms.commands.Util;
|
||||
import me.lucko.luckperms.constants.Message;
|
||||
import me.lucko.luckperms.users.User;
|
||||
import me.lucko.luckperms.utils.Patterns;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
public class UserMainCommand extends MainCommand{
|
||||
|
||||
private final List<UserSubCommand> subCommands = new ArrayList<>();
|
||||
|
||||
public class UserMainCommand extends MainCommand<User> {
|
||||
public UserMainCommand() {
|
||||
super("User", "/perms user <user>", 2);
|
||||
super("User", "/%s user <user>", 2);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void execute(LuckPermsPlugin plugin, Sender sender, List<String> args) {
|
||||
if (args.size() <= 1) {
|
||||
sendUsage(sender);
|
||||
return;
|
||||
}
|
||||
|
||||
// The first argument is the name of the user, the second is the command
|
||||
String command = args.get(1);
|
||||
UserSubCommand tempSub = null;
|
||||
|
||||
// Try to identify the command used
|
||||
for (UserSubCommand s : subCommands) {
|
||||
if (s.getName().equalsIgnoreCase(command)) {
|
||||
tempSub = s;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// The command the sender used
|
||||
final UserSubCommand sub = tempSub;
|
||||
|
||||
if (sub == null) {
|
||||
Util.sendPluginMessage(sender, "Command not recognised.");
|
||||
return;
|
||||
}
|
||||
|
||||
if (!sub.isAuthorized(sender)) {
|
||||
Util.sendPluginMessage(sender, "You do not have permission to use this command!");
|
||||
return;
|
||||
}
|
||||
|
||||
// The arguments to be passed onto the sub command
|
||||
List<String> strippedArgs = new ArrayList<>();
|
||||
if (args.size() > 2) {
|
||||
strippedArgs.addAll(args.subList(2, args.size()));
|
||||
}
|
||||
|
||||
String user = args.get(0);
|
||||
|
||||
UUID u = Util.parseUuid(user);
|
||||
protected void getTarget(String target, LuckPermsPlugin plugin, Sender sender, Callback<User> onSuccess) {
|
||||
UUID u = Util.parseUuid(target);
|
||||
if (u != null) {
|
||||
runSub(plugin, sender, u, sub, strippedArgs);
|
||||
runSub(plugin, sender, u, onSuccess);
|
||||
return;
|
||||
}
|
||||
|
||||
if (user.length() <= 16) {
|
||||
Util.sendPluginMessage(sender, "&7(Attempting UUID lookup, since you specified a user)");
|
||||
if (target.length() <= 16) {
|
||||
if (Patterns.NON_USERNAME.matcher(target).find()) {
|
||||
Message.USER_INVALID_ENTRY.send(sender, target);
|
||||
return;
|
||||
}
|
||||
|
||||
plugin.getDatastore().getUUID(user, uuid -> {
|
||||
Message.USER_ATTEMPTING_LOOKUP.send(sender);
|
||||
|
||||
plugin.getDatastore().getUUID(target, uuid -> {
|
||||
if (uuid == null) {
|
||||
Util.sendPluginMessage(sender, "&eUser could not be found.");
|
||||
Message.USER_NOT_FOUND.send(sender);
|
||||
return;
|
||||
}
|
||||
runSub(plugin, sender, uuid, sub, strippedArgs);
|
||||
|
||||
runSub(plugin, sender, uuid, onSuccess);
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
Util.sendPluginMessage(sender, "&d" + user + "&c is not a valid username/uuid.");
|
||||
Message.USER_INVALID_ENTRY.send(sender, target);
|
||||
}
|
||||
|
||||
private void runSub(LuckPermsPlugin plugin, Sender sender, UUID uuid, UserSubCommand command, List<String> strippedArgs) {
|
||||
private void runSub(LuckPermsPlugin plugin, Sender sender, UUID uuid, Callback<User> onSuccess) {
|
||||
plugin.getDatastore().loadUser(uuid, success -> {
|
||||
if (!success) {
|
||||
Util.sendPluginMessage(sender, "&eUser could not be found.");
|
||||
Message.USER_NOT_FOUND.send(sender);
|
||||
return;
|
||||
}
|
||||
|
||||
User user1 = plugin.getUserManager().getUser(uuid);
|
||||
|
||||
if (user1 == null) {
|
||||
Util.sendPluginMessage(sender, "&eUser could not be found.");
|
||||
}
|
||||
|
||||
if (command.isArgLengthInvalid(strippedArgs.size())) {
|
||||
command.sendUsage(sender);
|
||||
User user = plugin.getUserManager().getUser(uuid);
|
||||
if (user == null) {
|
||||
Message.USER_NOT_FOUND.send(sender);
|
||||
return;
|
||||
}
|
||||
|
||||
command.execute(plugin, sender, user1, strippedArgs);
|
||||
plugin.getUserManager().cleanupUser(user1);
|
||||
onSuccess.onComplete(user);
|
||||
plugin.getUserManager().cleanupUser(user);
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<? extends SubCommand> getSubCommands() {
|
||||
return subCommands;
|
||||
}
|
||||
|
||||
public void registerSubCommand(UserSubCommand subCommand) {
|
||||
subCommands.add(subCommand);
|
||||
protected List<String> getObjects(LuckPermsPlugin plugin) {
|
||||
return plugin.getPlayerList();
|
||||
}
|
||||
}
|
||||
@@ -1,29 +0,0 @@
|
||||
package me.lucko.luckperms.commands.user;
|
||||
|
||||
import me.lucko.luckperms.LuckPermsPlugin;
|
||||
import me.lucko.luckperms.commands.Sender;
|
||||
import me.lucko.luckperms.commands.SubCommand;
|
||||
import me.lucko.luckperms.commands.Util;
|
||||
import me.lucko.luckperms.users.User;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public abstract class UserSubCommand extends SubCommand {
|
||||
public UserSubCommand(String name, String description, String usage, String permission) {
|
||||
super(name, description, usage, permission);
|
||||
}
|
||||
|
||||
protected abstract void execute(LuckPermsPlugin plugin, Sender sender, User user, List<String> args);
|
||||
|
||||
protected void saveUser(User user, Sender sender, LuckPermsPlugin plugin) {
|
||||
user.refreshPermissions();
|
||||
|
||||
plugin.getDatastore().saveUser(user, success -> {
|
||||
if (success) {
|
||||
Util.sendPluginMessage(sender, "&7(User data was saved to the datastore)");
|
||||
} else {
|
||||
Util.sendPluginMessage(sender, "There was an error whilst saving the user.");
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,75 @@
|
||||
package me.lucko.luckperms.commands.user.subcommands;
|
||||
|
||||
import me.lucko.luckperms.LuckPermsPlugin;
|
||||
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.exceptions.ObjectAlreadyHasException;
|
||||
import me.lucko.luckperms.groups.Group;
|
||||
import me.lucko.luckperms.users.User;
|
||||
import me.lucko.luckperms.utils.Patterns;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class UserAddGroup extends SubCommand<User> {
|
||||
public UserAddGroup() {
|
||||
super("addgroup", "Adds the user to a group", "/%s user <user> addgroup <group> [server] [world]",
|
||||
Permission.USER_ADDGROUP, Predicate.notInRange(1, 3));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(LuckPermsPlugin plugin, Sender sender, User user, List<String> args, String label) {
|
||||
String groupName = args.get(0).toLowerCase();
|
||||
|
||||
if (groupName.contains("/") || groupName.contains("$")) {
|
||||
sendUsage(sender, label);
|
||||
return;
|
||||
}
|
||||
|
||||
plugin.getDatastore().loadGroup(groupName, success -> {
|
||||
if (!success) {
|
||||
Message.GROUP_DOES_NOT_EXIST.send(sender);
|
||||
} else {
|
||||
Group group = plugin.getGroupManager().getGroup(groupName);
|
||||
if (group == null) {
|
||||
Message.GROUP_DOES_NOT_EXIST.send(sender);
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
if (args.size() >= 2) {
|
||||
final String server = args.get(1).toLowerCase();
|
||||
if (Patterns.NON_ALPHA_NUMERIC.matcher(server).find()) {
|
||||
Message.SERVER_INVALID_ENTRY.send(sender);
|
||||
return;
|
||||
}
|
||||
|
||||
if (args.size() == 2) {
|
||||
user.addGroup(group, server);
|
||||
Message.USER_ADDGROUP_SERVER_SUCCESS.send(sender, user.getName(), groupName, server);
|
||||
} else {
|
||||
final String world = args.get(2).toLowerCase();
|
||||
user.addGroup(group, server, world);
|
||||
Message.USER_ADDGROUP_SERVER_WORLD_SUCCESS.send(sender, user.getName(), groupName, server, world);
|
||||
}
|
||||
|
||||
} else {
|
||||
user.addGroup(group);
|
||||
Message.USER_ADDGROUP_SUCCESS.send(sender, user.getName(), groupName);
|
||||
}
|
||||
|
||||
saveUser(user, sender, plugin);
|
||||
} catch (ObjectAlreadyHasException e) {
|
||||
Message.USER_ALREADY_MEMBER_OF.send(sender, user.getName(), group.getName());
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> onTabComplete(Sender sender, List<String> args, LuckPermsPlugin plugin) {
|
||||
return getGroupTabComplete(args, plugin);
|
||||
}
|
||||
}
|
||||
Loaded 100 of 159 files, more files were not shown because too many files have changed in this diff.
Show more
Reference in new issue
Block a user