mirror of
https://github.com/LuckPerms/LuckPerms.git
synced 2026-11-25 08:44:21 +00:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
6798fb21b2 | ||
|
|
89ff3b169b | ||
|
|
abddb265be | ||
|
|
b328fa74a7 | ||
|
|
f97aa651a0 | ||
|
|
8d86eed0a7 | ||
|
|
05f906a759 | ||
|
|
4b16be1b75 | ||
|
|
bd97a7c5d2 | ||
|
|
a3a23d8870 | ||
|
|
30bddceac5 | ||
|
|
989a2cc89c | ||
|
|
3f17e8c3c8 | ||
|
|
140e6b08ca | ||
|
|
6a39b721ba | ||
|
|
1df6f4b9df | ||
|
|
9493fb3a7a | ||
|
|
0d1f3b855f | ||
|
|
0982154a15 | ||
|
|
378f3f5efa | ||
|
|
9b8d6e1dc7 | ||
|
|
6540c695de | ||
|
|
1d71ec07be | ||
|
|
c837dd5cc8 | ||
|
|
bc52e4da0e | ||
|
|
f0b4040458 | ||
|
|
d804c4be2a | ||
|
|
ede413a213 | ||
|
|
9cee319ed9 | ||
|
|
f7b281f655 | ||
|
|
8dbb083b90 | ||
|
|
0be6d658ed | ||
|
|
1efce41767 | ||
|
|
da23b6ea9a | ||
|
|
a61d3b3fd4 | ||
|
|
ab9284b80f | ||
|
|
424af27a47 | ||
|
|
5039a05055 | ||
|
|
d150b22eae | ||
|
|
a617675771 | ||
|
|
f27034bb35 | ||
|
|
86b203c21b | ||
|
|
73c5a1ad9b | ||
|
|
81c71777cb | ||
|
|
599072eef6 | ||
|
|
02ea3afbe9 | ||
|
|
0c1a2e82bf | ||
|
|
f89fb87c92 | ||
|
|
98d6cf842a | ||
|
|
69dc02b2c2 | ||
|
|
7d1a3d32e9 | ||
|
|
d93cc826b2 | ||
|
|
8025f3a082 | ||
|
|
247871f678 | ||
|
|
327c8b83be | ||
|
|
0f8c334de8 | ||
|
|
292d4cd450 | ||
|
|
38d1c9974b | ||
|
|
0be7300677 | ||
|
|
c03585aeca | ||
|
|
d39dad3287 | ||
|
|
0a3ca3affe | ||
|
|
b7cf0e6bc7 | ||
|
|
7430013cc3 | ||
|
|
6dd093fe72 | ||
|
|
8a8d6f16ae | ||
|
|
2e16844141 | ||
|
|
a152cc47c7 | ||
|
|
241507228f | ||
|
|
8aa7d272fa | ||
|
|
01ac5382ea | ||
|
|
02b88a8357 | ||
|
|
c99d6556db | ||
|
|
1db777cd31 | ||
|
|
aea44fc8bc | ||
|
|
c0da9d49d9 | ||
|
|
ce42573f43 | ||
|
|
148fe4c729 | ||
|
|
32fd484b58 | ||
|
|
7d24e748b7 | ||
|
|
f1a1612f5d | ||
|
|
6501e5cf8d | ||
|
|
cd4a684613 | ||
|
|
d06fda6d9d | ||
|
|
139010e75b | ||
|
|
7638b07e34 | ||
|
|
f7bf4416c9 | ||
|
|
2b96b656a9 | ||
|
|
0fe251b6ec | ||
|
|
a1afc70bcb | ||
|
|
ced3e6959c | ||
|
|
1c229d54d9 | ||
|
|
dd50193c18 | ||
|
|
ab0f9bbdbd | ||
|
|
055d181c67 | ||
|
|
7042c45deb | ||
|
|
960c2291b6 | ||
|
|
773bfe1407 | ||
|
|
a23f995717 | ||
|
|
bd509b3c75 | ||
|
|
a0f8ba9afb | ||
|
|
a71e040c6d | ||
|
|
454abec468 | ||
|
|
96035d5257 | ||
|
|
9f2b59f2a2 | ||
|
|
a54046907d | ||
|
|
2ce5679373 | ||
|
|
2dad9f84fc | ||
|
|
a81a361a93 | ||
|
|
4660e68abf | ||
|
|
f8a77cf809 | ||
|
|
0abe9598f6 | ||
|
|
20de713716 | ||
|
|
9dbef6acc2 | ||
|
|
4c93bf7cf0 | ||
|
|
a8fea0fc49 | ||
|
|
2d5975d6e3 | ||
|
|
6874cfd5b1 | ||
|
|
d34013396a | ||
|
|
a35b0915ab | ||
|
|
b35f3b4375 | ||
|
|
f4f9612789 | ||
|
|
bfc79c6051 | ||
|
|
d3e60487bb | ||
|
|
f36f411a8d | ||
|
|
35f4aea69f | ||
|
|
8795383e7c | ||
|
|
fc4750706b | ||
|
|
0ae59bd3e6 | ||
|
|
61fd14c816 | ||
|
|
c7d3d87b09 | ||
|
|
5e68f7b58c | ||
|
|
8a692200d5 | ||
|
|
829eacb0fb | ||
|
|
9aeca91f22 | ||
|
|
1bdb512826 | ||
|
|
060fa6e5f7 | ||
|
|
171a54c0fc | ||
|
|
17406b448d | ||
|
|
b4b661a3ad | ||
|
|
4857969ca4 | ||
|
|
d9d01e09aa | ||
|
|
dadca97d8a | ||
|
|
8afba8b53d | ||
|
|
85dac1184c | ||
|
|
4167460d28 | ||
|
|
1d8a60749d | ||
|
|
31a597ca81 | ||
|
|
e5e77ffec5 | ||
|
|
41c3df41b4 | ||
|
|
053066f1a7 | ||
|
|
21135dac07 | ||
|
|
22ccce3208 | ||
|
|
70aa3964ee | ||
|
|
167489823a | ||
|
|
d1426f1b37 | ||
|
|
7dcdc59c8e | ||
|
|
1e13ee87af | ||
|
|
5101c1a759 | ||
|
|
74bb079625 | ||
|
|
2da7979d94 | ||
|
|
4ecb2c7c27 | ||
|
|
251f51b01c | ||
|
|
2fba9b83af | ||
|
|
1c97cb3cec | ||
|
|
25511f898c | ||
|
|
d820f153a9 | ||
|
|
77b06acad4 | ||
|
|
6760a96527 | ||
|
|
257f426ab9 | ||
|
|
3771a50f30 | ||
|
|
85ee211172 | ||
|
|
1b7a66b41a | ||
|
|
8f9a1aa931 | ||
|
|
8b60fd0e55 | ||
|
|
cd7b3b4f6e | ||
|
|
83b0f62d59 | ||
|
|
dd3a78ada8 |
No files matched your search
File renamed without changes.
@@ -1,34 +1,44 @@
|
|||||||

|

|
||||||
# LuckPerms [](https://ci.lucko.me/job/LuckPerms/)
|
# LuckPerms [](https://ci.lucko.me/job/LuckPerms/)
|
||||||
An advanced permissions implementation for Bukkit/Spigot, BungeeCord and Sponge.
|
|
||||||
|
|
||||||
## Links
|
|
||||||
* **Development Builds** - <https://ci.lucko.me/job/LuckPerms>
|
|
||||||
* **Javadocs** - <https://jd.lucko.me/LuckPerms>
|
|
||||||
* **Wiki** - <https://github.com/lucko/LuckPerms/wiki>
|
|
||||||
|
|
||||||
## Description
|
|
||||||
LuckPerms is an advanced permissions implementation aiming to be a fast, reliable and flexible alternative to existing permission plugins. The project's main goals are centered around high performance and a wide feature set, filling the gaps of functionality and building upon existing features found in other plugins.
|
LuckPerms is an advanced permissions implementation aiming to be a fast, reliable and flexible alternative to existing permission plugins. The project's main goals are centered around high performance and a wide feature set, filling the gaps of functionality and building upon existing features found in other plugins.
|
||||||
|
|
||||||
LuckPerms also includes an extensive API for developers, and support for a variety of Minecraft server software & data storage options.
|
LuckPerms also includes an extensive API for developers, and support for a variety of Minecraft server software & data storage options.
|
||||||
|
|
||||||
See the charts below for a partial list of features & comparison with other providers.
|
[See the charts below](https://github.com/lucko/LuckPerms#luckperms-vs-other-plugins) for a partial list of features & comparison with other providers.
|
||||||
|
|
||||||
* [Spigot Plugin Release Page](https://www.spigotmc.org/resources/luckperms-an-advanced-permissions-system.28140/ "Spigot Plugin Page")
|
* [Spigot Plugin Release Page](https://www.spigotmc.org/resources/luckperms-an-advanced-permissions-system.28140/ "Spigot Plugin Page")
|
||||||
* [Sponge Plugin Release Page](https://forums.spongepowered.org/t/luckperms-an-advanced-permissions-system/14274 "Sponge Plugin Page")
|
* [Sponge Plugin Release Page](https://forums.spongepowered.org/t/luckperms-an-advanced-permissions-system/14274 "Sponge Plugin Page")
|
||||||
|
|
||||||
|
## Useful Links
|
||||||
|
* **Development Builds** - <https://ci.lucko.me/job/LuckPerms>
|
||||||
|
* **Javadocs** - <https://jd.lucko.me/LuckPerms>
|
||||||
|
* **Wiki** - <https://github.com/lucko/LuckPerms/wiki>
|
||||||
|
|
||||||
|
## Building
|
||||||
|
LuckPerms uses Maven to handle dependencies.
|
||||||
|
|
||||||
|
#### Requirements
|
||||||
|
* Maven 3.3.x (the older versions will not work.)
|
||||||
|
* Git
|
||||||
|
|
||||||
|
#### Then run
|
||||||
|
```sh
|
||||||
|
git clone https://github.com/lucko/LuckPerms.git
|
||||||
|
mvn clean package
|
||||||
|
```
|
||||||
|
|
||||||
|
## License
|
||||||
|
LuckPerms is licensed under the permissive MIT license. Please see [`LICENSE.txt`](https://github.com/lucko/LuckPerms/blob/master/LICENSE.txt) for more info.
|
||||||
|
|
||||||
## LuckPerms vs Other Plugins
|
## LuckPerms vs Other Plugins
|
||||||
### Bukkit
|
### Bukkit
|
||||||

|

|
||||||
_Features checked on 23rd Aug 2016. If you find any inaccuracies, please do let me know. I tried to be as fair as possible, and copy all major features from the respective plugin pages._
|
###### _Features checked on 23rd Aug 2016. If you find any inaccuracies, please let me know._
|
||||||
### Sponge
|
### Sponge
|
||||||

|

|
||||||
_Features checked on 8th Oct 2016. If you find any inaccuracies, please do let me know. I tried to be as fair as possible, and copy all major features from the respective plugin pages._
|
###### _Features checked on 8th Oct 2016. If you find any inaccuracies, please let me know._
|
||||||
|
|
||||||
## License
|
## Thanks
|
||||||
LuckPerms is licensed under the permissive MIT license. See LICENSE.md for more info.
|
|
||||||
|
|
||||||
## Sponsor
|
|
||||||
[](http://www.ej-technologies.com/products/jprofiler/overview.html)
|
[](http://www.ej-technologies.com/products/jprofiler/overview.html)
|
||||||
|
|
||||||
Thanks to ej-technologies for granting LuckPerms an open source licence to their [Java Profiling Software](http://www.ej-technologies.com/products/jprofiler/overview.html "Java Profiler").
|
Thanks to ej-technologies for granting LuckPerms an open source licence to their [Java Profiling Software](http://www.ej-technologies.com/products/jprofiler/overview.html "Java Profiler").
|
||||||
+1
-1
@@ -5,7 +5,7 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<artifactId>luckperms</artifactId>
|
<artifactId>luckperms</artifactId>
|
||||||
<groupId>me.lucko.luckperms</groupId>
|
<groupId>me.lucko.luckperms</groupId>
|
||||||
<version>2.16-SNAPSHOT</version>
|
<version>3.0-SNAPSHOT</version>
|
||||||
</parent>
|
</parent>
|
||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
|
||||||
|
|||||||
@@ -27,13 +27,16 @@ import me.lucko.luckperms.api.LuckPermsApi;
|
|||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Static access to LuckPerms
|
* Singleton for the {@link LuckPermsApi}.
|
||||||
|
*
|
||||||
|
* <p> Ideally, the ServiceManager for the platform should be used to obtain and cache an instance, however, this can be
|
||||||
|
* used if you need static access.
|
||||||
*/
|
*/
|
||||||
public final class LuckPerms {
|
public final class LuckPerms {
|
||||||
private static LuckPermsApi api = null;
|
private static LuckPermsApi api = null;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets an instance of {@link LuckPermsApi}
|
* Gets an instance of {@link LuckPermsApi}, throwing {@link IllegalStateException} if the API is not loaded.
|
||||||
*
|
*
|
||||||
* @return an api instance
|
* @return an api instance
|
||||||
* @throws IllegalStateException if the api is not loaded
|
* @throws IllegalStateException if the api is not loaded
|
||||||
@@ -46,8 +49,10 @@ public final class LuckPerms {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets an instance of {@link LuckPermsApi} safely. Unlike {@link LuckPerms#getApi}, this method will not throw an
|
* Gets an instance of {@link LuckPermsApi} safely.
|
||||||
* {@link IllegalStateException} if the api is not loaded, rather return an empty {@link Optional}.
|
*
|
||||||
|
* <p> Unlike {@link LuckPerms#getApi}, this method will not throw an {@link IllegalStateException} if the API is
|
||||||
|
* not loaded, rather return an empty {@link Optional}.
|
||||||
*
|
*
|
||||||
* @return an optional api instance
|
* @return an optional api instance
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -24,11 +24,10 @@ package me.lucko.luckperms.api;
|
|||||||
|
|
||||||
import me.lucko.luckperms.api.context.ContextSet;
|
import me.lucko.luckperms.api.context.ContextSet;
|
||||||
|
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Represents the context and options for a permission lookup.
|
* Context and options for a permission lookup.
|
||||||
* All values are immutable.
|
*
|
||||||
|
* <p> All values are immutable.
|
||||||
*
|
*
|
||||||
* @since 2.11
|
* @since 2.11
|
||||||
*/
|
*/
|
||||||
@@ -50,45 +49,39 @@ public class Contexts {
|
|||||||
return new Contexts(context, includeGlobal, includeGlobalWorld, applyGroups, applyGlobalGroups, applyGlobalWorldGroups, op);
|
return new Contexts(context, includeGlobal, includeGlobalWorld, applyGroups, applyGlobalGroups, applyGlobalWorldGroups, op);
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("deprecation")
|
|
||||||
@Deprecated
|
|
||||||
public static Contexts of(Map<String, String> context, boolean includeGlobal, boolean includeGlobalWorld, boolean applyGroups, boolean applyGlobalGroups, boolean applyGlobalWorldGroups) {
|
|
||||||
return new Contexts(context, includeGlobal, includeGlobalWorld, applyGroups, applyGlobalGroups, applyGlobalWorldGroups);
|
|
||||||
}
|
|
||||||
|
|
||||||
@SuppressWarnings("deprecation")
|
|
||||||
@Deprecated
|
|
||||||
public static Contexts of(Map<String, String> context, boolean includeGlobal, boolean includeGlobalWorld, boolean applyGroups, boolean applyGlobalGroups, boolean applyGlobalWorldGroups, boolean op) {
|
|
||||||
return new Contexts(context, includeGlobal, includeGlobalWorld, applyGroups, applyGlobalGroups, applyGlobalWorldGroups, op);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The contexts that apply for this lookup
|
* The contexts that apply for this lookup
|
||||||
* The keys for servers and worlds are defined as static values.
|
* The keys for servers and worlds are defined as static values.
|
||||||
*/
|
*/
|
||||||
private final ContextSet context;
|
private final ContextSet context;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The mode to parse defaults on Bukkit
|
* The mode to parse defaults on Bukkit
|
||||||
*
|
*
|
||||||
* @since 2.12
|
* @since 2.12
|
||||||
*/
|
*/
|
||||||
private final boolean op;
|
private final boolean op;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* If global or non server specific nodes should be applied
|
* If global or non server specific nodes should be applied
|
||||||
*/
|
*/
|
||||||
private final boolean includeGlobal;
|
private final boolean includeGlobal;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* If global or non world specific nodes should be applied
|
* If global or non world specific nodes should be applied
|
||||||
*/
|
*/
|
||||||
private final boolean includeGlobalWorld;
|
private final boolean includeGlobalWorld;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* If parent groups should be applied
|
* If parent groups should be applied
|
||||||
*/
|
*/
|
||||||
private final boolean applyGroups;
|
private final boolean applyGroups;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* If global or non server specific group memberships should be applied
|
* If global or non server specific group memberships should be applied
|
||||||
*/
|
*/
|
||||||
private final boolean applyGlobalGroups;
|
private final boolean applyGlobalGroups;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* If global or non world specific group memberships should be applied
|
* If global or non world specific group memberships should be applied
|
||||||
*/
|
*/
|
||||||
@@ -108,17 +101,6 @@ public class Contexts {
|
|||||||
this.op = op;
|
this.op = op;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Deprecated
|
|
||||||
public Contexts(Map<String, String> context, boolean includeGlobal, boolean includeGlobalWorld, boolean applyGroups, boolean applyGlobalGroups, boolean applyGlobalWorldGroups, boolean op) {
|
|
||||||
this(context == null ? null : ContextSet.fromMap(context), includeGlobal, includeGlobalWorld, applyGroups, applyGlobalGroups, applyGlobalWorldGroups, op);
|
|
||||||
}
|
|
||||||
|
|
||||||
@SuppressWarnings("deprecation")
|
|
||||||
@Deprecated
|
|
||||||
public Contexts(Map<String, String> context, boolean includeGlobal, boolean includeGlobalWorld, boolean applyGroups, boolean applyGlobalGroups, boolean applyGlobalWorldGroups) {
|
|
||||||
this(context, includeGlobal, includeGlobalWorld, applyGroups, applyGlobalGroups, applyGlobalWorldGroups, false);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the contexts that apply for this lookup
|
* Gets the contexts that apply for this lookup
|
||||||
*
|
*
|
||||||
@@ -129,17 +111,6 @@ public class Contexts {
|
|||||||
return this.context;
|
return this.context;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Gets the contexts that apply for this lookup
|
|
||||||
*
|
|
||||||
* @return an immutable map of context key value pairs
|
|
||||||
* @deprecated in favour of {@link #getContexts()}
|
|
||||||
*/
|
|
||||||
@Deprecated
|
|
||||||
public Map<String, String> getContext() {
|
|
||||||
return this.context.toMap();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets if OP defaults should be included
|
* Gets if OP defaults should be included
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -1,185 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (c) 2016 Lucko (Luck) <[email protected]>
|
|
||||||
*
|
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
||||||
* of this software and associated documentation files (the "Software"), to deal
|
|
||||||
* in the Software without restriction, including without limitation the rights
|
|
||||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
||||||
* copies of the Software, and to permit persons to whom the Software is
|
|
||||||
* furnished to do so, subject to the following conditions:
|
|
||||||
*
|
|
||||||
* The above copyright notice and this permission notice shall be included in all
|
|
||||||
* copies or substantial portions of the Software.
|
|
||||||
*
|
|
||||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
||||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
||||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
||||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
||||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
||||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
||||||
* SOFTWARE.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package me.lucko.luckperms.api;
|
|
||||||
|
|
||||||
import me.lucko.luckperms.api.data.Callback;
|
|
||||||
|
|
||||||
import java.util.Set;
|
|
||||||
import java.util.UUID;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Interface for the internal Datastore instance
|
|
||||||
*
|
|
||||||
* @deprecated as of version 2.14 in favour of {@link Storage}.
|
|
||||||
*/
|
|
||||||
@Deprecated
|
|
||||||
public interface Datastore {
|
|
||||||
|
|
||||||
String getName();
|
|
||||||
|
|
||||||
boolean isAcceptingLogins();
|
|
||||||
|
|
||||||
@Deprecated
|
|
||||||
Sync sync();
|
|
||||||
|
|
||||||
@Deprecated
|
|
||||||
Async async();
|
|
||||||
|
|
||||||
@Deprecated
|
|
||||||
Future future();
|
|
||||||
|
|
||||||
@Deprecated
|
|
||||||
interface Sync {
|
|
||||||
boolean logAction(LogEntry entry);
|
|
||||||
|
|
||||||
Log getLog();
|
|
||||||
|
|
||||||
@Deprecated
|
|
||||||
boolean loadOrCreateUser(UUID uuid, String username);
|
|
||||||
|
|
||||||
@Deprecated
|
|
||||||
boolean loadUser(UUID uuid);
|
|
||||||
|
|
||||||
boolean loadUser(UUID uuid, String username);
|
|
||||||
|
|
||||||
boolean saveUser(User user);
|
|
||||||
|
|
||||||
boolean cleanupUsers();
|
|
||||||
|
|
||||||
Set<UUID> getUniqueUsers();
|
|
||||||
|
|
||||||
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);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Deprecated
|
|
||||||
interface Async {
|
|
||||||
void logAction(LogEntry entry, Callback<Boolean> callback);
|
|
||||||
|
|
||||||
void getLog(Callback<Log> callback);
|
|
||||||
|
|
||||||
@Deprecated
|
|
||||||
void loadOrCreateUser(UUID uuid, String username, Callback<Boolean> callback);
|
|
||||||
|
|
||||||
@Deprecated
|
|
||||||
void loadUser(UUID uuid, Callback<Boolean> callback);
|
|
||||||
|
|
||||||
void loadUser(UUID uuid, String username, Callback<Boolean> callback);
|
|
||||||
|
|
||||||
void saveUser(User user, Callback<Boolean> callback);
|
|
||||||
|
|
||||||
void cleanupUsers(Callback<Boolean> callback);
|
|
||||||
|
|
||||||
void getUniqueUsers(Callback<Set<UUID>> callback);
|
|
||||||
|
|
||||||
void createAndLoadGroup(String name, Callback<Boolean> callback);
|
|
||||||
|
|
||||||
void loadGroup(String name, Callback<Boolean> callback);
|
|
||||||
|
|
||||||
void loadAllGroups(Callback<Boolean> callback);
|
|
||||||
|
|
||||||
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);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Deprecated
|
|
||||||
interface Future {
|
|
||||||
java.util.concurrent.Future<Boolean> logAction(LogEntry entry);
|
|
||||||
|
|
||||||
java.util.concurrent.Future<Log> getLog();
|
|
||||||
|
|
||||||
@Deprecated
|
|
||||||
java.util.concurrent.Future<Boolean> loadOrCreateUser(UUID uuid, String username);
|
|
||||||
|
|
||||||
@Deprecated
|
|
||||||
java.util.concurrent.Future<Boolean> loadUser(UUID uuid);
|
|
||||||
|
|
||||||
java.util.concurrent.Future<Boolean> loadUser(UUID uuid, String username);
|
|
||||||
|
|
||||||
java.util.concurrent.Future<Boolean> saveUser(User user);
|
|
||||||
|
|
||||||
java.util.concurrent.Future<Boolean> cleanupUsers();
|
|
||||||
|
|
||||||
java.util.concurrent.Future<Set<UUID>> getUniqueUsers();
|
|
||||||
|
|
||||||
java.util.concurrent.Future<Boolean> createAndLoadGroup(String name);
|
|
||||||
|
|
||||||
java.util.concurrent.Future<Boolean> loadGroup(String name);
|
|
||||||
|
|
||||||
java.util.concurrent.Future<Boolean> loadAllGroups();
|
|
||||||
|
|
||||||
java.util.concurrent.Future<Boolean> saveGroup(Group group);
|
|
||||||
|
|
||||||
java.util.concurrent.Future<Boolean> deleteGroup(Group group);
|
|
||||||
|
|
||||||
java.util.concurrent.Future<Boolean> createAndLoadTrack(String name);
|
|
||||||
|
|
||||||
java.util.concurrent.Future<Boolean> loadTrack(String name);
|
|
||||||
|
|
||||||
java.util.concurrent.Future<Boolean> loadAllTracks();
|
|
||||||
|
|
||||||
java.util.concurrent.Future<Boolean> saveTrack(Track track);
|
|
||||||
|
|
||||||
java.util.concurrent.Future<Boolean> deleteTrack(Track track);
|
|
||||||
|
|
||||||
java.util.concurrent.Future<Boolean> saveUUIDData(String username, UUID uuid);
|
|
||||||
|
|
||||||
java.util.concurrent.Future<UUID> getUUID(String username);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -26,14 +26,16 @@ import me.lucko.luckperms.exceptions.ObjectAlreadyHasException;
|
|||||||
import me.lucko.luckperms.exceptions.ObjectLacksException;
|
import me.lucko.luckperms.exceptions.ObjectLacksException;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.OptionalInt;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Interface for internal Group instances
|
* A group which holds permission data.
|
||||||
*/
|
*/
|
||||||
@SuppressWarnings("unused")
|
|
||||||
public interface Group extends PermissionHolder {
|
public interface Group extends PermissionHolder {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* Get the name of the group
|
||||||
|
*
|
||||||
* @return the name of the group
|
* @return the name of the group
|
||||||
*/
|
*/
|
||||||
String getName();
|
String getName();
|
||||||
@@ -220,11 +222,6 @@ public interface Group extends PermissionHolder {
|
|||||||
*/
|
*/
|
||||||
void unsetInheritGroup(Group group, String server, String world, boolean temporary) throws ObjectLacksException;
|
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
|
* Get a {@link List} of all of the groups the group inherits, on all servers
|
||||||
*
|
*
|
||||||
@@ -236,6 +233,17 @@ public interface Group extends PermissionHolder {
|
|||||||
* Get a {@link List} of the groups the group inherits on a specific server
|
* Get a {@link List} of the groups the group inherits on a specific server
|
||||||
*
|
*
|
||||||
* @param server the server to check
|
* @param server the server to check
|
||||||
|
* @return a {@link List} of group names
|
||||||
|
* @throws NullPointerException if the server is null
|
||||||
|
* @throws IllegalArgumentException if the server is invalid
|
||||||
|
*/
|
||||||
|
List<String> getLocalGroups(String server);
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get a {@link List} of the groups the group inherits on a specific server and world
|
||||||
|
*
|
||||||
|
* @param server the server to check
|
||||||
* @param world the world to check
|
* @param world the world to check
|
||||||
* @return a {@link List} of group names
|
* @return a {@link List} of group names
|
||||||
* @throws NullPointerException if the server or world is null
|
* @throws NullPointerException if the server or world is null
|
||||||
@@ -244,12 +252,11 @@ public interface Group extends PermissionHolder {
|
|||||||
List<String> getLocalGroups(String server, String world);
|
List<String> getLocalGroups(String server, String world);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get a {@link List} of the groups the group inherits on a specific server
|
* Gets the weight of this group, is present.
|
||||||
*
|
*
|
||||||
* @param server the server to check
|
* @return the group weight
|
||||||
* @return a {@link List} of group names
|
* @since 2.17
|
||||||
* @throws NullPointerException if the server is null
|
|
||||||
* @throws IllegalArgumentException if the server is invalid
|
|
||||||
*/
|
*/
|
||||||
List<String> getLocalGroups(String server);
|
OptionalInt getWeight();
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,94 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2016 Lucko (Luck) <[email protected]>
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
* of this software and associated documentation files (the "Software"), to deal
|
||||||
|
* in the Software without restriction, including without limitation the rights
|
||||||
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
* copies of the Software, and to permit persons to whom the Software is
|
||||||
|
* furnished to do so, subject to the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be included in all
|
||||||
|
* copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
|
* SOFTWARE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package me.lucko.luckperms.api;
|
||||||
|
|
||||||
|
import com.google.common.collect.Multimap;
|
||||||
|
|
||||||
|
import java.util.Optional;
|
||||||
|
import java.util.OptionalLong;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A relationship between a Holder and a permission
|
||||||
|
*
|
||||||
|
* @param <T> the identifier type of the holder
|
||||||
|
* @since 2.17
|
||||||
|
*/
|
||||||
|
public interface HeldPermission<T> {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the holder of the permission
|
||||||
|
*
|
||||||
|
* @return the holder
|
||||||
|
*/
|
||||||
|
T getHolder();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the permission being held
|
||||||
|
*
|
||||||
|
* @return the permission
|
||||||
|
*/
|
||||||
|
String getPermission();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the value of the permission
|
||||||
|
*
|
||||||
|
* @return the value
|
||||||
|
*/
|
||||||
|
boolean getValue();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the server where the permission is held
|
||||||
|
*
|
||||||
|
* @return the server
|
||||||
|
*/
|
||||||
|
Optional<String> getServer();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the world where the permission is held
|
||||||
|
*
|
||||||
|
* @return the world
|
||||||
|
*/
|
||||||
|
Optional<String> getWorld();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the time in unix time when the permission will expire
|
||||||
|
*
|
||||||
|
* @return the expiry time
|
||||||
|
*/
|
||||||
|
OptionalLong getExpiry();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the context for the permission.
|
||||||
|
*
|
||||||
|
* @return the context
|
||||||
|
*/
|
||||||
|
Multimap<String, String> getContext();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Converts this permission into a Node
|
||||||
|
*
|
||||||
|
* @return a Node copy of this permission
|
||||||
|
*/
|
||||||
|
Node asNode();
|
||||||
|
|
||||||
|
}
|
||||||
@@ -23,152 +23,140 @@
|
|||||||
package me.lucko.luckperms.api;
|
package me.lucko.luckperms.api;
|
||||||
|
|
||||||
import me.lucko.luckperms.api.data.DatastoreConfiguration;
|
import me.lucko.luckperms.api.data.DatastoreConfiguration;
|
||||||
import me.lucko.luckperms.api.data.MySQLConfiguration;
|
|
||||||
|
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A wrapper interface for the internal LuckPerms configuration, providing read only access.
|
* Read-only access to the LuckPerms configuration settings
|
||||||
*/
|
*/
|
||||||
@SuppressWarnings("unused")
|
|
||||||
public interface LPConfiguration {
|
public interface LPConfiguration {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* Returns the name of this server
|
||||||
* @return the name of this server
|
* @return the name of this server
|
||||||
*/
|
*/
|
||||||
String getServer();
|
String getServer();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* Returns how often a sync task will run in minutes
|
||||||
* @return how often a sync task will run in minutes
|
* @return how often a sync task will run in minutes
|
||||||
*/
|
*/
|
||||||
int getSyncTime();
|
int getSyncTime();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return the default group, in a node representation
|
* Returns if the users on this server will have their global permissions applied
|
||||||
* @deprecated as of 2.6, the default group is always "default"
|
|
||||||
*/
|
|
||||||
@Deprecated
|
|
||||||
String getDefaultGroupNode();
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @return the name of the default group
|
|
||||||
* @deprecated as of 2.6, the default group is always "default"
|
|
||||||
*/
|
|
||||||
@Deprecated
|
|
||||||
String getDefaultGroupName();
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @return if the users on this server will have their global permissions applied
|
* @return if the users on this server will have their global permissions applied
|
||||||
*/
|
*/
|
||||||
boolean getIncludeGlobalPerms();
|
boolean getIncludeGlobalPerms();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* Returns if the users on this server will have their global world permissions applied
|
||||||
* @return if the users on this server will have their global world permissions applied
|
* @return if the users on this server will have their global world permissions applied
|
||||||
* @since 2.9
|
* @since 2.9
|
||||||
*/
|
*/
|
||||||
boolean getIncludeGlobalWorldPerms();
|
boolean getIncludeGlobalWorldPerms();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* Returns true if the platform is applying global groups
|
||||||
* @return true if the platform is applying global groups
|
* @return true if the platform is applying global groups
|
||||||
* @since 2.9
|
* @since 2.9
|
||||||
*/
|
*/
|
||||||
boolean getApplyGlobalGroups();
|
boolean getApplyGlobalGroups();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* Returns true if the platform is applying global world groups
|
||||||
* @return true if the platform is applying global world groups
|
* @return true if the platform is applying global world groups
|
||||||
* @since 2.9
|
* @since 2.9
|
||||||
*/
|
*/
|
||||||
boolean getApplyGlobalWorldGroups();
|
boolean getApplyGlobalWorldGroups();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return the online mode setting in the config
|
* Returns the online mode setting
|
||||||
|
* @return the online mode setting
|
||||||
*/
|
*/
|
||||||
boolean getOnlineMode();
|
boolean getOnlineMode();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* Returns if LuckPerms is applying wildcard permissions
|
||||||
* @return if LuckPerms is applying wildcard permissions
|
* @return if LuckPerms is applying wildcard permissions
|
||||||
*/
|
*/
|
||||||
boolean getApplyWildcards();
|
boolean getApplyWildcards();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* Returns if LuckPerms is resolving and applying regex permissions
|
||||||
* @return if LuckPerms is resolving and applying regex permissions
|
* @return if LuckPerms is resolving and applying regex permissions
|
||||||
*/
|
*/
|
||||||
boolean getApplyRegex();
|
boolean getApplyRegex();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* Returns if LuckPerms is expanding shorthand permissions
|
||||||
* @return if LuckPerms is expanding shorthand permissions
|
* @return if LuckPerms is expanding shorthand permissions
|
||||||
*/
|
*/
|
||||||
boolean getApplyShorthand();
|
boolean getApplyShorthand();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* Returns if LuckPerms will send notifications to users when permissions are modified
|
||||||
* @return if LuckPerms will send notifications to users when permissions are modified
|
* @return if LuckPerms will send notifications to users when permissions are modified
|
||||||
* @since 2.7
|
* @since 2.7
|
||||||
*/
|
*/
|
||||||
boolean getLogNotify();
|
boolean getLogNotify();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return true if permission checks are being recorded / debugged
|
* Returns true if the vanilla op system is enabled
|
||||||
* @since 2.9
|
|
||||||
* @deprecated as this value is now always false. Functionality was replaced by the verbose command.
|
|
||||||
*/
|
|
||||||
@Deprecated
|
|
||||||
boolean getDebugPermissionChecks();
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @return true if the vanilla op system is enabled
|
* @return true if the vanilla op system is enabled
|
||||||
* @since 2.8
|
* @since 2.8
|
||||||
*/
|
*/
|
||||||
boolean getEnableOps();
|
boolean getEnableOps();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* Returns true if opped players are allowed to use LuckPerms commands
|
||||||
* @return true if opped players are allowed to use LuckPerms commands
|
* @return true if opped players are allowed to use LuckPerms commands
|
||||||
* @since 2.8
|
* @since 2.8
|
||||||
*/
|
*/
|
||||||
boolean getCommandsAllowOp();
|
boolean getCommandsAllowOp();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* Returns true if auto op is enabled
|
||||||
* @return true if auto op is enabled
|
* @return true if auto op is enabled
|
||||||
* @since 2.9
|
* @since 2.9
|
||||||
*/
|
*/
|
||||||
boolean getAutoOp();
|
boolean getAutoOp();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* Returns the name of the server used within Vault operations
|
||||||
* @return the name of the server used within Vault operations
|
* @return the name of the server used within Vault operations
|
||||||
* @since 2.7
|
* @since 2.7
|
||||||
*/
|
*/
|
||||||
String getVaultServer();
|
String getVaultServer();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* Returns true if global permissions should be considered when retrieving meta or player groups
|
||||||
* @return true if global permissions should be considered when retrieving meta or player groups
|
* @return true if global permissions should be considered when retrieving meta or player groups
|
||||||
* @since 2.7
|
* @since 2.7
|
||||||
*/
|
*/
|
||||||
boolean getVaultIncludeGlobal();
|
boolean getVaultIncludeGlobal();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return the database values set in the configuration
|
* Returns the values set for data storage in the configuration
|
||||||
* @deprecated use {@link #getDatastoreConfig()}
|
|
||||||
*/
|
|
||||||
@SuppressWarnings("deprecation")
|
|
||||||
@Deprecated
|
|
||||||
MySQLConfiguration getDatabaseValues();
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @return the values set for data storage in the configuration
|
* @return the values set for data storage in the configuration
|
||||||
*/
|
*/
|
||||||
DatastoreConfiguration getDatastoreConfig();
|
DatastoreConfiguration getDatastoreConfig();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* Returns the storage method string from the configuration
|
||||||
* @return the storage method string from the configuration
|
* @return the storage method string from the configuration
|
||||||
*/
|
*/
|
||||||
String getStorageMethod();
|
String getStorageMethod();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* Returns true if split storage is enabled
|
||||||
* @return true if split storage is enabled
|
* @return true if split storage is enabled
|
||||||
* @since 2.7
|
* @since 2.7
|
||||||
*/
|
*/
|
||||||
boolean getSplitStorage();
|
boolean getSplitStorage();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* Returns a map of split storage options
|
||||||
* @return a map of split storage options, where the key is the storage section, and the value is the storage
|
* @return a map of split storage options, where the key is the storage section, and the value is the storage
|
||||||
* method. For example: key = user, value = json
|
* method. For example: key = user, value = json
|
||||||
* @since 2.7
|
* @since 2.7
|
||||||
|
|||||||
@@ -23,14 +23,14 @@
|
|||||||
package me.lucko.luckperms.api;
|
package me.lucko.luckperms.api;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Represents a Node and where it was inherited from.
|
* A node with a traceable origin
|
||||||
*
|
*
|
||||||
* @since 2.11
|
* @since 2.11
|
||||||
*/
|
*/
|
||||||
public interface LocalizedNode extends Node {
|
public interface LocalizedNode extends Node {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the node
|
* Gets the delegate node
|
||||||
*
|
*
|
||||||
* @return the node this instance is representing
|
* @return the node this instance is representing
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -27,10 +27,11 @@ import java.util.SortedSet;
|
|||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Represents the internal LuckPerms log. All content internally is immutable. You can add to the log using the {@link
|
* Represents the internal LuckPerms log.
|
||||||
* Datastore}, and then request an updated copy.
|
*
|
||||||
|
* <p> The returned instance provides a copy of the data at the time of retrieval. Any changes made to log entries will
|
||||||
|
* only apply to this instance of the log. You can add to the log using the {@link Storage}, and then request an updated copy.
|
||||||
*/
|
*/
|
||||||
@SuppressWarnings("unused")
|
|
||||||
public interface Log {
|
public interface Log {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -48,6 +49,8 @@ public interface Log {
|
|||||||
*
|
*
|
||||||
* @param pageNo the page number
|
* @param pageNo the page number
|
||||||
* @return the page content
|
* @return the page content
|
||||||
|
* @throws IllegalArgumentException if the pageNo is less than 1
|
||||||
|
* @throws IllegalStateException if the log doesn't contain enough entries to populate the page. See {@link #getRecentMaxPages()}}
|
||||||
*/
|
*/
|
||||||
SortedMap<Integer, LogEntry> getRecent(int pageNo);
|
SortedMap<Integer, LogEntry> getRecent(int pageNo);
|
||||||
|
|
||||||
@@ -69,6 +72,8 @@ public interface Log {
|
|||||||
* @param pageNo the page number
|
* @param pageNo the page number
|
||||||
* @param actor the uuid of the actor to filter by
|
* @param actor the uuid of the actor to filter by
|
||||||
* @return the page content
|
* @return the page content
|
||||||
|
* @throws IllegalArgumentException if the pageNo is less than 1
|
||||||
|
* @throws IllegalStateException if the log doesn't contain enough entries to populate the page. See {@link #getRecentMaxPages(UUID)}}
|
||||||
*/
|
*/
|
||||||
SortedMap<Integer, LogEntry> getRecent(int pageNo, UUID actor);
|
SortedMap<Integer, LogEntry> getRecent(int pageNo, UUID actor);
|
||||||
|
|
||||||
@@ -91,6 +96,8 @@ public interface Log {
|
|||||||
* @param pageNo the page number
|
* @param pageNo the page number
|
||||||
* @param uuid the uuid of the acted user to filter by
|
* @param uuid the uuid of the acted user to filter by
|
||||||
* @return the page content
|
* @return the page content
|
||||||
|
* @throws IllegalArgumentException if the pageNo is less than 1
|
||||||
|
* @throws IllegalStateException if the log doesn't contain enough entries to populate the page. See {@link #getUserHistoryMaxPages(UUID)}}
|
||||||
*/
|
*/
|
||||||
SortedMap<Integer, LogEntry> getUserHistory(int pageNo, UUID uuid);
|
SortedMap<Integer, LogEntry> getUserHistory(int pageNo, UUID uuid);
|
||||||
|
|
||||||
@@ -113,6 +120,8 @@ public interface Log {
|
|||||||
* @param pageNo the page number
|
* @param pageNo the page number
|
||||||
* @param name the name of the acted group to filter by
|
* @param name the name of the acted group to filter by
|
||||||
* @return the page content
|
* @return the page content
|
||||||
|
* @throws IllegalArgumentException if the pageNo is less than 1
|
||||||
|
* @throws IllegalStateException if the log doesn't contain enough entries to populate the page. See {@link #getGroupHistoryMaxPages(String)}}
|
||||||
*/
|
*/
|
||||||
SortedMap<Integer, LogEntry> getGroupHistory(int pageNo, String name);
|
SortedMap<Integer, LogEntry> getGroupHistory(int pageNo, String name);
|
||||||
|
|
||||||
@@ -141,9 +150,12 @@ public interface Log {
|
|||||||
/**
|
/**
|
||||||
* @param name the name to filter by
|
* @param name the name to filter by
|
||||||
* @return the max page number allowed in the {@link #getTrackHistory(int, String)} method
|
* @return the max page number allowed in the {@link #getTrackHistory(int, String)} method
|
||||||
|
* @throws IllegalArgumentException if the pageNo is less than 1
|
||||||
|
* @throws IllegalStateException if the log doesn't contain enough entries to populate the page. See {@link #getTrackHistoryMaxPages(String)}}
|
||||||
*/
|
*/
|
||||||
int getTrackHistoryMaxPages(String name);
|
int getTrackHistoryMaxPages(String name);
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param query the query to filter by
|
* @param query the query to filter by
|
||||||
* @return all content in this log where the content matches query
|
* @return all content in this log where the content matches query
|
||||||
@@ -156,6 +168,8 @@ public interface Log {
|
|||||||
* @param pageNo the page number
|
* @param pageNo the page number
|
||||||
* @param query the query to filter by
|
* @param query the query to filter by
|
||||||
* @return the page content
|
* @return the page content
|
||||||
|
* @throws IllegalArgumentException if the pageNo is less than 1
|
||||||
|
* @throws IllegalStateException if the log doesn't contain enough entries to populate the page. See {@link #getSearchMaxPages(String)}}
|
||||||
*/
|
*/
|
||||||
SortedMap<Integer, LogEntry> getSearch(int pageNo, String query);
|
SortedMap<Integer, LogEntry> getSearch(int pageNo, String query);
|
||||||
|
|
||||||
|
|||||||
@@ -25,9 +25,10 @@ package me.lucko.luckperms.api;
|
|||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Represents a single entry in a log
|
* A single entry in the log
|
||||||
|
*
|
||||||
|
* <p> Implements {@link Comparable} ordering based upon the timestamp of the entry.
|
||||||
*/
|
*/
|
||||||
@SuppressWarnings({"unused", "WeakerAccess"})
|
|
||||||
public class LogEntry implements Comparable<LogEntry> {
|
public class LogEntry implements Comparable<LogEntry> {
|
||||||
private static final String FORMAT = "&8(&e%s&8) [&a%s&8] (&b%s&8) &7--> &f%s";
|
private static final String FORMAT = "&8(&e%s&8) [&a%s&8] (&b%s&8) &7--> &f%s";
|
||||||
|
|
||||||
@@ -154,9 +155,15 @@ public class LogEntry implements Comparable<LogEntry> {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return "LogEntry(timestamp=" + this.getTimestamp() + ", actor=" + this.getActor() + ", actorName=" +
|
return "LogEntry(" +
|
||||||
this.getActorName() + ", type=" + this.getType() + ", acted=" + this.getActed() + ", actedName=" +
|
"timestamp=" + this.getTimestamp() + ", " +
|
||||||
this.getActedName() + ", action=" + this.getAction() + ")";
|
"actor=" + this.getActor() + ", " +
|
||||||
|
"actorName=" + this.getActorName() + ", " +
|
||||||
|
"type=" + this.getType() + ", " +
|
||||||
|
"acted=" + this.getActed() + ", " +
|
||||||
|
"actedName=" + this.getActedName() + ", " +
|
||||||
|
"action=" + this.getAction() +
|
||||||
|
")";
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -165,41 +172,25 @@ public class LogEntry implements Comparable<LogEntry> {
|
|||||||
if (!(o instanceof LogEntry)) return false;
|
if (!(o instanceof LogEntry)) return false;
|
||||||
final LogEntry other = (LogEntry) o;
|
final LogEntry other = (LogEntry) o;
|
||||||
if (this.getTimestamp() != other.getTimestamp()) return false;
|
if (this.getTimestamp() != other.getTimestamp()) return false;
|
||||||
final Object this$actor = this.getActor();
|
if (this.getActor() == null ? other.getActor() != null : !this.getActor().equals(other.getActor())) return false;
|
||||||
final Object other$actor = other.getActor();
|
if (this.getActorName() == null ? other.getActorName() != null : !this.getActorName().equals(other.getActorName())) return false;
|
||||||
if (this$actor == null ? other$actor != null : !this$actor.equals(other$actor)) return false;
|
|
||||||
final Object this$actorName = this.getActorName();
|
|
||||||
final Object other$actorName = other.getActorName();
|
|
||||||
if (this$actorName == null ? other$actorName != null : !this$actorName.equals(other$actorName)) return false;
|
|
||||||
if (this.getType() != other.getType()) return false;
|
if (this.getType() != other.getType()) return false;
|
||||||
final Object this$acted = this.getActed();
|
if (this.getActed() == null ? other.getActed() != null : !this.getActed().equals(other.getActed())) return false;
|
||||||
final Object other$acted = other.getActed();
|
if (this.getActedName() == null ? other.getActedName() != null : !this.getActedName().equals(other.getActedName())) return false;
|
||||||
if (this$acted == null ? other$acted != null : !this$acted.equals(other$acted)) return false;
|
return this.getAction() == null ? other.getAction() == null : this.getAction().equals(other.getAction());
|
||||||
final Object this$actedName = this.getActedName();
|
|
||||||
final Object other$actedName = other.getActedName();
|
|
||||||
if (this$actedName == null ? other$actedName != null : !this$actedName.equals(other$actedName)) return false;
|
|
||||||
final Object this$action = this.getAction();
|
|
||||||
final Object other$action = other.getAction();
|
|
||||||
return this$action == null ? other$action == null : this$action.equals(other$action);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int hashCode() {
|
public int hashCode() {
|
||||||
final int PRIME = 59;
|
final int PRIME = 59;
|
||||||
int result = 1;
|
int result = 1;
|
||||||
final long $timestamp = this.getTimestamp();
|
result = result * PRIME + (int) (this.getTimestamp() >>> 32 ^ this.getTimestamp());
|
||||||
result = result * PRIME + (int) ($timestamp >>> 32 ^ $timestamp);
|
result = result * PRIME + (this.getActor() == null ? 43 : this.getActor().hashCode());
|
||||||
final Object $actor = this.getActor();
|
result = result * PRIME + (this.getActorName() == null ? 43 : this.getActorName().hashCode());
|
||||||
result = result * PRIME + ($actor == null ? 43 : $actor.hashCode());
|
|
||||||
final Object $actorName = this.getActorName();
|
|
||||||
result = result * PRIME + ($actorName == null ? 43 : $actorName.hashCode());
|
|
||||||
result = result * PRIME + this.getType();
|
result = result * PRIME + this.getType();
|
||||||
final Object $acted = this.getActed();
|
result = result * PRIME + (this.getActed() == null ? 43 : this.getActed().hashCode());
|
||||||
result = result * PRIME + ($acted == null ? 43 : $acted.hashCode());
|
result = result * PRIME + (this.getActedName() == null ? 43 : this.getActedName().hashCode());
|
||||||
final Object $actedName = this.getActedName();
|
result = result * PRIME + (this.getAction() == null ? 43 : this.getAction().hashCode());
|
||||||
result = result * PRIME + ($actedName == null ? 43 : $actedName.hashCode());
|
|
||||||
final Object $action = this.getAction();
|
|
||||||
result = result * PRIME + ($action == null ? 43 : $action.hashCode());
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -214,6 +205,7 @@ public class LogEntry implements Comparable<LogEntry> {
|
|||||||
protected LogEntryBuilder getThis() {
|
protected LogEntryBuilder getThis() {
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static abstract class AbstractLogEntryBuilder<T extends LogEntry, B extends AbstractLogEntryBuilder<T, B>> {
|
public static abstract class AbstractLogEntryBuilder<T extends LogEntry, B extends AbstractLogEntryBuilder<T, B>> {
|
||||||
@@ -311,9 +303,15 @@ public class LogEntry implements Comparable<LogEntry> {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return "LogEntry.LogEntryBuilder(timestamp=" + getTimestamp() + ", actor=" + getActor() + ", actorName=" +
|
return "LogEntry.LogEntryBuilder(" +
|
||||||
getActorName() + ", type=" + getType() + ", acted=" + getActed() + ", actedName=" + getActedName() +
|
"timestamp=" + this.getTimestamp() + ", " +
|
||||||
", action=" + getAction() + ")";
|
"actor=" + this.getActor() + ", " +
|
||||||
|
"actorName=" + this.getActorName() + ", " +
|
||||||
|
"type=" + this.getType() + ", " +
|
||||||
|
"acted=" + this.getActed() + ", " +
|
||||||
|
"actedName=" + this.getActedName() + ", " +
|
||||||
|
"action=" + this.getAction() +
|
||||||
|
")";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -23,7 +23,7 @@
|
|||||||
package me.lucko.luckperms.api;
|
package me.lucko.luckperms.api;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A wrapper interface for platform logger instances.
|
* A wrapper interface for platform logger instances
|
||||||
*
|
*
|
||||||
* <p> Bukkit/Bungee both use java.util.logging, and Sponge uses org.slf4j. This class wraps those classes so the
|
* <p> Bukkit/Bungee both use java.util.logging, and Sponge uses org.slf4j. This class wraps those classes so the
|
||||||
* commons module can access a logger.
|
* commons module can access a logger.
|
||||||
|
|||||||
@@ -22,18 +22,17 @@
|
|||||||
|
|
||||||
package me.lucko.luckperms.api;
|
package me.lucko.luckperms.api;
|
||||||
|
|
||||||
import me.lucko.luckperms.api.context.ContextListener;
|
import me.lucko.luckperms.api.context.ContextCalculator;
|
||||||
import me.lucko.luckperms.api.context.IContextCalculator;
|
import me.lucko.luckperms.api.context.ContextSet;
|
||||||
import me.lucko.luckperms.api.event.LPListener;
|
import me.lucko.luckperms.api.event.EventBus;
|
||||||
|
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The root API interface in LuckPerms
|
* The root API interface for LuckPerms
|
||||||
*/
|
*/
|
||||||
@SuppressWarnings("unused")
|
|
||||||
public interface LuckPermsApi {
|
public interface LuckPermsApi {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -42,37 +41,31 @@ public interface LuckPermsApi {
|
|||||||
void runUpdateTask();
|
void runUpdateTask();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* Gets the API version
|
||||||
* @return the version of the API running on the platform
|
* @return the version of the API running on the platform
|
||||||
* @since 2.6
|
* @since 2.6
|
||||||
*/
|
*/
|
||||||
double getApiVersion();
|
double getApiVersion();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* Gets the plugin version
|
||||||
* @return the version of the plugin running on the platform
|
* @return the version of the plugin running on the platform
|
||||||
*/
|
*/
|
||||||
String getVersion();
|
String getVersion();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* Gets the platform LuckPerms is running on
|
||||||
* @return the platform LuckPerms is running on
|
* @return the platform LuckPerms is running on
|
||||||
* @since 2.7
|
* @since 2.7
|
||||||
*/
|
*/
|
||||||
PlatformType getPlatformType();
|
PlatformType getPlatformType();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Registers a listener to be sent LuckPerms events
|
* Gets the event bus, used for subscribing to events
|
||||||
*
|
* @return the event bus
|
||||||
* @param listener the listener instance
|
* @since 3.0
|
||||||
* @throws NullPointerException if the listener is null
|
|
||||||
*/
|
*/
|
||||||
void registerListener(LPListener listener);
|
EventBus getEventBus();
|
||||||
|
|
||||||
/**
|
|
||||||
* Unregisters a previously registered listener from the EventBus
|
|
||||||
*
|
|
||||||
* @param listener the listener instance to unregister
|
|
||||||
* @throws NullPointerException if the listener is null
|
|
||||||
*/
|
|
||||||
void unregisterListener(LPListener listener);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets a wrapped {@link LPConfiguration} instance, with read only access
|
* Gets a wrapped {@link LPConfiguration} instance, with read only access
|
||||||
@@ -89,16 +82,6 @@ public interface LuckPermsApi {
|
|||||||
*/
|
*/
|
||||||
Storage getStorage();
|
Storage getStorage();
|
||||||
|
|
||||||
/**
|
|
||||||
* Gets a wrapped Datastore instance.
|
|
||||||
*
|
|
||||||
* @return a datastore instance
|
|
||||||
* @deprecated in favour of {@link #getStorage()}
|
|
||||||
*/
|
|
||||||
@SuppressWarnings("deprecation")
|
|
||||||
@Deprecated
|
|
||||||
Datastore getDatastore();
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the messaging service in use on the platform, if present.
|
* Gets the messaging service in use on the platform, if present.
|
||||||
*
|
*
|
||||||
@@ -250,6 +233,13 @@ public interface LuckPermsApi {
|
|||||||
*/
|
*/
|
||||||
boolean isTrackLoaded(String name);
|
boolean isTrackLoaded(String name);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the node factory instance for the platform
|
||||||
|
*
|
||||||
|
* @return the node factory
|
||||||
|
*/
|
||||||
|
NodeFactory getNodeFactory();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns a permission builder instance
|
* Returns a permission builder instance
|
||||||
*
|
*
|
||||||
@@ -267,23 +257,25 @@ public interface LuckPermsApi {
|
|||||||
* @param contextCalculator the context calculator to register. The type MUST be the player class of the platform.
|
* @param contextCalculator the context calculator to register. The type MUST be the player class of the platform.
|
||||||
* @throws ClassCastException if the type is not the player class of the platform.
|
* @throws ClassCastException if the type is not the player class of the platform.
|
||||||
*/
|
*/
|
||||||
void registerContextCalculator(IContextCalculator<?> contextCalculator);
|
void registerContextCalculator(ContextCalculator<?> contextCalculator);
|
||||||
|
|
||||||
/**
|
|
||||||
* Registers a custom context listener to the server,
|
|
||||||
*
|
|
||||||
* @param contextListener the context listener to register. The type MUST be the player class of the platform.
|
|
||||||
* @throws ClassCastException if the type is not the player class of the platform.
|
|
||||||
*/
|
|
||||||
void registerContextListener(ContextListener<?> contextListener);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets a calculated context instance for the user using the rules of the platform.
|
* Gets a calculated context instance for the user using the rules of the platform.
|
||||||
* These values are calculated using the options in the configuration, and the provided calculators.
|
*
|
||||||
|
* <p> These values are calculated using the options in the configuration, and the provided calculators.
|
||||||
*
|
*
|
||||||
* @param user the user to get contexts for
|
* @param user the user to get contexts for
|
||||||
* @return an optional containing contexts. Will return empty if the user is not online.
|
* @return an optional containing contexts. Will return empty if the user is not online.
|
||||||
*/
|
*/
|
||||||
Optional<Contexts> getContextForUser(User user);
|
Optional<Contexts> getContextForUser(User user);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets set of contexts applicable to a player using the platforms {@link ContextCalculator}s.
|
||||||
|
*
|
||||||
|
* @param player the player to calculate for. Must be the player instance for the platform.
|
||||||
|
* @return a set of contexts.
|
||||||
|
* @since 2.17
|
||||||
|
*/
|
||||||
|
ContextSet getContextForPlayer(Object player);
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -23,7 +23,7 @@
|
|||||||
package me.lucko.luckperms.api;
|
package me.lucko.luckperms.api;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Exposes any networking provider being used on the platform. e.g. Redis
|
* A means to push changes to other servers using the platforms networking
|
||||||
*
|
*
|
||||||
* @since 2.14
|
* @since 2.14
|
||||||
*/
|
*/
|
||||||
@@ -31,7 +31,9 @@ public interface MessagingService {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Uses the messaging service to inform other servers about changes.
|
* Uses the messaging service to inform other servers about changes.
|
||||||
* This will push the update asynchronously, and this method will return almost immediately.
|
*
|
||||||
|
* <p> This will push the update asynchronously, and this method will return immediately. Calling this method is
|
||||||
|
* equivalent to running "/lp networksync", except will not sync this server.
|
||||||
*/
|
*/
|
||||||
void pushUpdate();
|
void pushUpdate();
|
||||||
|
|
||||||
|
|||||||
@@ -37,6 +37,20 @@ import java.util.Set;
|
|||||||
*/
|
*/
|
||||||
public class MetaUtils {
|
public class MetaUtils {
|
||||||
|
|
||||||
|
private static String escapeDelimiters(String s, String... delims) {
|
||||||
|
for (String delim : delims) {
|
||||||
|
s = s.replace(delim, "\\" + delim);
|
||||||
|
}
|
||||||
|
return s;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static String unescapeDelimiters(String s, String... delims) {
|
||||||
|
for (String delim : delims) {
|
||||||
|
s = s.replace("\\" + delim, delim);
|
||||||
|
}
|
||||||
|
return s;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Escapes special characters used within LuckPerms, so the string can be saved without issues
|
* Escapes special characters used within LuckPerms, so the string can be saved without issues
|
||||||
*
|
*
|
||||||
@@ -49,11 +63,7 @@ public class MetaUtils {
|
|||||||
throw new NullPointerException();
|
throw new NullPointerException();
|
||||||
}
|
}
|
||||||
|
|
||||||
s = s.replace(".", "{SEP}");
|
return escapeDelimiters(s, ".", "/", "-", "$");
|
||||||
s = s.replace("/", "{FSEP}");
|
|
||||||
s = s.replace("$", "{DSEP}");
|
|
||||||
|
|
||||||
return s;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -71,6 +81,7 @@ public class MetaUtils {
|
|||||||
s = s.replace("{SEP}", ".");
|
s = s.replace("{SEP}", ".");
|
||||||
s = s.replace("{FSEP}", "/");
|
s = s.replace("{FSEP}", "/");
|
||||||
s = s.replace("{DSEP}", "$");
|
s = s.replace("{DSEP}", "$");
|
||||||
|
s = unescapeDelimiters(s, ".", "/", "-", "$");
|
||||||
|
|
||||||
return s;
|
return s;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -31,12 +31,12 @@ import java.util.Optional;
|
|||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Represents an immutable node object
|
* An immutable permission node
|
||||||
|
*
|
||||||
* <p> Use {@link LuckPermsApi#buildNode(String)} to get an instance.
|
* <p> Use {@link LuckPermsApi#buildNode(String)} to get an instance.
|
||||||
*
|
*
|
||||||
* @since 2.6
|
* @since 2.6
|
||||||
*/
|
*/
|
||||||
@SuppressWarnings("unused")
|
|
||||||
public interface Node extends Map.Entry<String, Boolean> {
|
public interface Node extends Map.Entry<String, Boolean> {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -133,31 +133,6 @@ public interface Node extends Map.Entry<String, Boolean> {
|
|||||||
*/
|
*/
|
||||||
boolean shouldApplyWithContext(ContextSet context);
|
boolean shouldApplyWithContext(ContextSet context);
|
||||||
|
|
||||||
/**
|
|
||||||
* If this node should apply in the given context
|
|
||||||
*
|
|
||||||
* @param context the context key value pairs
|
|
||||||
* @param worldAndServer if world and server contexts should be checked
|
|
||||||
* @return true if the node should apply
|
|
||||||
* @deprecated in favour of {@link #shouldApplyWithContext(ContextSet, boolean)}
|
|
||||||
*/
|
|
||||||
@Deprecated
|
|
||||||
default boolean shouldApplyWithContext(Map<String, String> context, boolean worldAndServer) {
|
|
||||||
return shouldApplyWithContext(ContextSet.fromMap(context), worldAndServer);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* If this node should apply in the given context
|
|
||||||
*
|
|
||||||
* @param context the context key value pairs
|
|
||||||
* @return true if the node should apply
|
|
||||||
* @deprecated in favour of {@link #shouldApplyWithContext(ContextSet)}
|
|
||||||
*/
|
|
||||||
@Deprecated
|
|
||||||
default boolean shouldApplyWithContext(Map<String, String> context) {
|
|
||||||
return shouldApplyWithContext(ContextSet.fromMap(context));
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Similar to {@link #shouldApplyOnServer(String, boolean, boolean)}, except this method accepts a List
|
* Similar to {@link #shouldApplyOnServer(String, boolean, boolean)}, except this method accepts a List
|
||||||
*
|
*
|
||||||
@@ -227,15 +202,6 @@ public interface Node extends Map.Entry<String, Boolean> {
|
|||||||
*/
|
*/
|
||||||
boolean hasExpired();
|
boolean hasExpired();
|
||||||
|
|
||||||
/**
|
|
||||||
* @return the extra contexts required for this node to apply
|
|
||||||
* @deprecated in favour of {@link #getContexts()}
|
|
||||||
*/
|
|
||||||
@Deprecated
|
|
||||||
default Map<String, String> getExtraContexts() {
|
|
||||||
return getContexts().toMap();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return the extra contexts required for this node to apply
|
* @return the extra contexts required for this node to apply
|
||||||
* @since 2.13
|
* @since 2.13
|
||||||
|
|||||||
@@ -0,0 +1,101 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2016 Lucko (Luck) <[email protected]>
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
* of this software and associated documentation files (the "Software"), to deal
|
||||||
|
* in the Software without restriction, including without limitation the rights
|
||||||
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
* copies of the Software, and to permit persons to whom the Software is
|
||||||
|
* furnished to do so, subject to the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be included in all
|
||||||
|
* copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
|
* SOFTWARE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package me.lucko.luckperms.api;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Builds {@link Node} instances
|
||||||
|
*
|
||||||
|
* @since 2.17
|
||||||
|
*/
|
||||||
|
public interface NodeFactory {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a node from a serialised node string
|
||||||
|
*
|
||||||
|
* @param serialisedPermission the serialised permission string
|
||||||
|
* @param value the value of the node
|
||||||
|
* @return a node instance
|
||||||
|
* @throws NullPointerException if the permission is null
|
||||||
|
*/
|
||||||
|
Node fromSerialisedNode(String serialisedPermission, boolean value);
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a new node builder from a given base permission string
|
||||||
|
*
|
||||||
|
* @param permission the permission
|
||||||
|
* @return a node builder instance
|
||||||
|
* @throws NullPointerException if the permission is null
|
||||||
|
*/
|
||||||
|
Node.Builder newBuilder(String permission);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a node builder instance from an existing node
|
||||||
|
*
|
||||||
|
* @param other the other node
|
||||||
|
* @return a node builder instance
|
||||||
|
* @throws NullPointerException if the other node is null
|
||||||
|
*/
|
||||||
|
Node.Builder newBuilderFromExisting(Node other);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a node builder from a serialised node string
|
||||||
|
* @param serialisedPermission the serialised permission string
|
||||||
|
* @param value the value of the node
|
||||||
|
* @return a node builder instance
|
||||||
|
* @throws NullPointerException if the permission is null
|
||||||
|
*/
|
||||||
|
Node.Builder newBuilderFromSerialisedNode(String serialisedPermission, boolean value);
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a node builder from a key value pair
|
||||||
|
*
|
||||||
|
* @param key the key
|
||||||
|
* @param value the value
|
||||||
|
* @return a node builder instance
|
||||||
|
* @throws NullPointerException if the key or value is null
|
||||||
|
*/
|
||||||
|
Node.Builder makeMetaNode(String key, String value);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a node builder from a prefix string and priority
|
||||||
|
*
|
||||||
|
* @param priority the priority
|
||||||
|
* @param prefix the prefix string
|
||||||
|
* @return a node builder instance
|
||||||
|
* @throws NullPointerException if the prefix is null
|
||||||
|
*/
|
||||||
|
Node.Builder makePrefixNode(int priority, String prefix);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a node builder from a prefix string and priority
|
||||||
|
*
|
||||||
|
* @param priority the priority
|
||||||
|
* @param suffix the suffix string
|
||||||
|
* @return a node builder instance
|
||||||
|
* @throws NullPointerException if the suffix is null
|
||||||
|
*/
|
||||||
|
Node.Builder makeSuffixNode(int priority, String suffix);
|
||||||
|
|
||||||
|
}
|
||||||
@@ -25,25 +25,29 @@ package me.lucko.luckperms.api;
|
|||||||
import me.lucko.luckperms.exceptions.ObjectAlreadyHasException;
|
import me.lucko.luckperms.exceptions.ObjectAlreadyHasException;
|
||||||
import me.lucko.luckperms.exceptions.ObjectLacksException;
|
import me.lucko.luckperms.exceptions.ObjectLacksException;
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.SortedSet;
|
import java.util.SortedSet;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Interface for internal PermissionHolder (user/group) instances
|
* An object capable of holding permissions
|
||||||
|
*
|
||||||
|
* <p> Any changes made will be lost unless the instance is saved back to the {@link Storage}.
|
||||||
*/
|
*/
|
||||||
@SuppressWarnings("unused")
|
|
||||||
public interface PermissionHolder {
|
public interface PermissionHolder {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return the identifier for this object. either a uuid string or name However, you should really just use {@link
|
* Gets the objects name
|
||||||
* User#getUuid()}, {@link User#getName()} or {@link Group#getName()}
|
*
|
||||||
|
* <p> {@link User#getUuid()}, {@link User#getName()} or {@link Group#getName()} should normally be used instead of
|
||||||
|
* this method.
|
||||||
|
*
|
||||||
|
* @return the identifier for this object. Either a uuid string or name.
|
||||||
*/
|
*/
|
||||||
String getObjectName();
|
String getObjectName();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets an immutable Set of the objects permission nodes
|
* Gets a sorted set of all held permissions.
|
||||||
*
|
*
|
||||||
* @return an immutable set of permissions in priority order
|
* @return an immutable set of permissions in priority order
|
||||||
* @since 2.6
|
* @since 2.6
|
||||||
@@ -51,31 +55,22 @@ public interface PermissionHolder {
|
|||||||
SortedSet<? extends Node> getPermissions();
|
SortedSet<? extends Node> getPermissions();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Similar to {@link #getPermissions()}, except excluding transient permissions
|
* Similar to {@link #getPermissions()}, except without transient permissions
|
||||||
*
|
*
|
||||||
* @return a set of nodes
|
* @return a set of nodes
|
||||||
* @since 2.6
|
* @since 2.6
|
||||||
*/
|
*/
|
||||||
Set<Node> getEnduringPermissions();
|
Set<? extends Node> getEnduringPermissions();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Similar to {@link #getPermissions()}, except excluding non-transient permissions
|
* Gets an immutable set of all transiently held permissions.
|
||||||
|
*
|
||||||
|
* <p> Transient permissions only exist for the duration of the session.
|
||||||
*
|
*
|
||||||
* @return a set of nodes
|
* @return a set of nodes
|
||||||
* @since 2.6
|
* @since 2.6
|
||||||
*/
|
*/
|
||||||
Set<Node> getTransientPermissions();
|
Set<? extends Node> getTransientPermissions();
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Gets an immutable set of the nodes that this object has and inherits
|
|
||||||
*
|
|
||||||
* @return an immutable set of permissions
|
|
||||||
* @since 2.6
|
|
||||||
* @deprecated in favour of {@link #getAllNodes(Contexts)}
|
|
||||||
*/
|
|
||||||
@Deprecated
|
|
||||||
Set<Node> getAllNodes();
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets a mutable sorted set of the nodes that this object has and inherits, filtered by context
|
* Gets a mutable sorted set of the nodes that this object has and inherits, filtered by context
|
||||||
@@ -91,7 +86,7 @@ public interface PermissionHolder {
|
|||||||
SortedSet<LocalizedNode> getAllNodes(Contexts contexts);
|
SortedSet<LocalizedNode> getAllNodes(Contexts contexts);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets a mutable set of the nodes that is objects has and inherits, filtered by context.
|
* Gets a mutable set of the nodes that this object has and inherits, filtered by context.
|
||||||
* Unlike {@link #getAllNodes(Contexts)}, this method WILL filter individual nodes, and only return ones that fully
|
* Unlike {@link #getAllNodes(Contexts)}, this method WILL filter individual nodes, and only return ones that fully
|
||||||
* meet the context provided.
|
* meet the context provided.
|
||||||
*
|
*
|
||||||
@@ -103,13 +98,17 @@ public interface PermissionHolder {
|
|||||||
Set<LocalizedNode> getAllNodesFiltered(Contexts contexts);
|
Set<LocalizedNode> getAllNodesFiltered(Contexts contexts);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets an immutable Map of the objects permission nodes
|
* Converts the output of {@link #getAllNodesFiltered(Contexts)}, and expands shorthand permissions.
|
||||||
*
|
* @param contexts the context for the lookup
|
||||||
* @return an immutable map of permissions
|
* @param lowerCase if the keys should be made lowercase whilst being exported
|
||||||
* @deprecated in favour of {@link #getPermissions()}
|
* @return a mutable map of permissions
|
||||||
*/
|
*/
|
||||||
@Deprecated
|
Map<String, Boolean> exportNodes(Contexts contexts, boolean lowerCase);
|
||||||
Map<String, Boolean> getNodes();
|
|
||||||
|
/**
|
||||||
|
* Removes temporary permissions that have expired
|
||||||
|
*/
|
||||||
|
void auditTemporaryPermissions();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Checks to see if the object has a certain permission
|
* Checks to see if the object has a certain permission
|
||||||
@@ -509,94 +508,91 @@ public interface PermissionHolder {
|
|||||||
void unsetPermission(String node, String server, String world, boolean temporary) throws ObjectLacksException;
|
void unsetPermission(String node, String server, String world, boolean temporary) throws ObjectLacksException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the permissions and inherited permissions that apply to a specific server and world
|
* Clears all nodes held by the object
|
||||||
*
|
*
|
||||||
* @param server The server to get nodes for
|
* @since 2.17
|
||||||
* @param world The world to get nodes for
|
|
||||||
* @param excludedGroups Groups that shouldn't be inherited (to prevent circular inheritance issues)
|
|
||||||
* @param possibleNodes A list of possible permission nodes for wildcard permission handling
|
|
||||||
* @return a {@link Map} of the permissions
|
|
||||||
* @deprecated in favour of {@link #getPermissions(String, String, Map, boolean, List, boolean)}
|
|
||||||
*/
|
*/
|
||||||
@Deprecated
|
void clearNodes();
|
||||||
Map<String, Boolean> getLocalPermissions(String server, String world, List<String> excludedGroups, List<String> possibleNodes);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the permissions and inherited permissions that apply to a specific server and world
|
* Clears all nodes held by the object on a specific server
|
||||||
*
|
*
|
||||||
* @param server The server to get nodes for
|
* @param server the server to filter by, can be null
|
||||||
* @param world The world to get nodes for
|
* @since 2.17
|
||||||
* @param excludedGroups Groups that shouldn't be inherited (to prevent circular inheritance issues)
|
|
||||||
* @return a {@link Map} of the permissions
|
|
||||||
* @deprecated in favour of {@link #getPermissions(String, String, Map, boolean, List, boolean)}
|
|
||||||
*/
|
*/
|
||||||
@Deprecated
|
void clearNodes(String server);
|
||||||
Map<String, Boolean> getLocalPermissions(String server, String world, List<String> excludedGroups);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the permissions and inherited permissions that apply to a specific server
|
* Clears all nodes held by the object on a specific server and world
|
||||||
*
|
*
|
||||||
* @param server The server to get nodes for
|
* @param server the server to filter by, can be null
|
||||||
* @param excludedGroups Groups that shouldn't be inherited (to prevent circular inheritance issues)
|
* @param world the world to filter by, can be null
|
||||||
* @param possibleNodes A list of possible permission nodes for wildcard permission handling
|
* @since 2.17
|
||||||
* @return a {@link Map} of the permissions
|
|
||||||
* @deprecated in favour of {@link #getPermissions(String, String, Map, boolean, List, boolean)}
|
|
||||||
*/
|
*/
|
||||||
@Deprecated
|
void clearNodes(String server, String world);
|
||||||
Map<String, Boolean> getLocalPermissions(String server, List<String> excludedGroups, List<String> possibleNodes);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the permissions and inherited permissions that apply to a specific server
|
* Clears all parent groups
|
||||||
*
|
*
|
||||||
* @param server The server to get nodes for
|
* @since 2.17
|
||||||
* @param excludedGroups Groups that shouldn't be inherited (to prevent circular inheritance issues)
|
|
||||||
* @return a {@link Map} of the permissions
|
|
||||||
* @deprecated in favour of {@link #getPermissions(String, String, Map, boolean, List, boolean)}
|
|
||||||
*/
|
*/
|
||||||
@Deprecated
|
void clearParents();
|
||||||
Map<String, Boolean> getLocalPermissions(String server, List<String> excludedGroups);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Convert the holders nodes into a Map of permissions to be applied on the platform
|
* Clears all parents on a specific server
|
||||||
*
|
*
|
||||||
* @param server the server
|
* @param server the server to filter by, can be null
|
||||||
* @param world the world
|
* @since 2.17
|
||||||
* @param extraContext any extra context to filter by
|
|
||||||
* @param includeGlobal whether to include global nodes
|
|
||||||
* @param possibleNodes a list of possible permissions for resolving wildcards
|
|
||||||
* @param applyGroups if inherited group permissions should be included
|
|
||||||
* @return a map of permissions
|
|
||||||
* @since 2.6
|
|
||||||
* @deprecated in favour of {@link #getAllNodesFiltered(Contexts)}
|
|
||||||
*/
|
*/
|
||||||
@Deprecated
|
void clearParents(String server);
|
||||||
Map<String, Boolean> getPermissions(String server, String world, Map<String, String> extraContext, boolean includeGlobal, List<String> possibleNodes, boolean applyGroups);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Processes the nodes and returns the temporary ones.
|
* Clears all parents on a specific server and world
|
||||||
*
|
*
|
||||||
* @return a map of temporary nodes
|
* @param server the server to filter by, can be null
|
||||||
* @deprecated in favour of {@link #getTemporaryPermissionNodes()}
|
* @param world the world to filter by, can be null
|
||||||
|
* @since 2.17
|
||||||
*/
|
*/
|
||||||
@Deprecated
|
void clearParents(String server, String world);
|
||||||
Map<Map.Entry<String, Boolean>, Long> getTemporaryNodes();
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Processes the nodes and returns the temporary ones.
|
* Clears all meta held by the object
|
||||||
*
|
*
|
||||||
* @return a set of temporary nodes
|
* @since 2.17
|
||||||
* @since 2.6
|
|
||||||
*/
|
*/
|
||||||
Set<Node> getTemporaryPermissionNodes();
|
void clearMeta();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Processes the nodes and returns the non-temporary ones.
|
* Clears all meta held by the object on a specific server
|
||||||
*
|
*
|
||||||
* @return a map of permanent nodes
|
* @param server the server to filter by, can be null
|
||||||
* @deprecated in favour of {@link #getPermanentPermissionNodes()}
|
* @since 2.17
|
||||||
*/
|
*/
|
||||||
@Deprecated
|
void clearMeta(String server);
|
||||||
Map<String, Boolean> getPermanentNodes();
|
|
||||||
|
/**
|
||||||
|
* Clears all meta held by the object on a specific server and world
|
||||||
|
*
|
||||||
|
* @param server the server to filter by, can be null
|
||||||
|
* @param world the world to filter by, can be null
|
||||||
|
* @since 2.17
|
||||||
|
*/
|
||||||
|
void clearMeta(String server, String world);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Clears all meta for a given key.
|
||||||
|
*
|
||||||
|
* @param key the meta key
|
||||||
|
* @param server the server to filter by, can be null
|
||||||
|
* @param world the world to filter by, can be null
|
||||||
|
* @param temporary whether the query is for temporary nodes or not.
|
||||||
|
*/
|
||||||
|
void clearMetaKeys(String key, String server, String world, boolean temporary);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Clears all transient permissions the holder has.
|
||||||
|
*/
|
||||||
|
void clearTransientNodes();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Processes the nodes and returns the non-temporary ones.
|
* Processes the nodes and returns the non-temporary ones.
|
||||||
@@ -607,8 +603,11 @@ public interface PermissionHolder {
|
|||||||
Set<Node> getPermanentPermissionNodes();
|
Set<Node> getPermanentPermissionNodes();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Removes temporary permissions that have expired
|
* Processes the nodes and returns the temporary ones.
|
||||||
|
*
|
||||||
|
* @return a set of temporary nodes
|
||||||
|
* @since 2.6
|
||||||
*/
|
*/
|
||||||
void auditTemporaryPermissions();
|
Set<Node> getTemporaryPermissionNodes();
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -23,7 +23,7 @@
|
|||||||
package me.lucko.luckperms.api;
|
package me.lucko.luckperms.api;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Represents the platform type that LuckPerms is running on
|
* The platforms which LuckPerms can run on
|
||||||
*
|
*
|
||||||
* @since 2.7
|
* @since 2.7
|
||||||
*/
|
*/
|
||||||
@@ -31,12 +31,7 @@ public enum PlatformType {
|
|||||||
|
|
||||||
BUKKIT("Bukkit"),
|
BUKKIT("Bukkit"),
|
||||||
BUNGEE("Bungee"),
|
BUNGEE("Bungee"),
|
||||||
SPONGE("Sponge"),
|
SPONGE("Sponge");
|
||||||
|
|
||||||
/**
|
|
||||||
* @since 2.9
|
|
||||||
*/
|
|
||||||
STANDALONE("Standalone");
|
|
||||||
|
|
||||||
private final String friendlyName;
|
private final String friendlyName;
|
||||||
|
|
||||||
|
|||||||
@@ -22,6 +22,7 @@
|
|||||||
|
|
||||||
package me.lucko.luckperms.api;
|
package me.lucko.luckperms.api;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
import java.util.concurrent.CompletableFuture;
|
import java.util.concurrent.CompletableFuture;
|
||||||
@@ -29,7 +30,7 @@ import java.util.concurrent.Executor;
|
|||||||
import java.util.function.Consumer;
|
import java.util.function.Consumer;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Interface for the internal Storage instance
|
* A means of loading and saving data to/from the Storage provider.
|
||||||
*
|
*
|
||||||
* <p>All methods return {@link CompletableFuture}s, which will be populated with the result once the data has been
|
* <p>All methods return {@link CompletableFuture}s, which will be populated with the result once the data has been
|
||||||
* loaded asynchronously. Care should be taken when using the methods to ensure that the main server thread is not
|
* loaded asynchronously. Care should be taken when using the methods to ensure that the main server thread is not
|
||||||
@@ -124,6 +125,16 @@ public interface Storage {
|
|||||||
*/
|
*/
|
||||||
CompletableFuture<Set<UUID>> getUniqueUsers();
|
CompletableFuture<Set<UUID>> getUniqueUsers();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Searches for a list of users with a given permission.
|
||||||
|
*
|
||||||
|
* @param permission the permission to search for
|
||||||
|
* @return a list of held permissions, or null if the operation failed
|
||||||
|
* @throws NullPointerException if the permission is null
|
||||||
|
* @since 2.17
|
||||||
|
*/
|
||||||
|
CompletableFuture<List<HeldPermission<UUID>>> getUsersWithPermission(String permission);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates and loads a group into the plugins local storage
|
* Creates and loads a group into the plugins local storage
|
||||||
*
|
*
|
||||||
@@ -171,6 +182,16 @@ public interface Storage {
|
|||||||
*/
|
*/
|
||||||
CompletableFuture<Boolean> deleteGroup(Group group);
|
CompletableFuture<Boolean> deleteGroup(Group group);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Searches for a list of groups with a given permission.
|
||||||
|
*
|
||||||
|
* @param permission the permission to search for
|
||||||
|
* @return a list of held permissions, or null if the operation failed
|
||||||
|
* @throws NullPointerException if the permission is null
|
||||||
|
* @since 2.17
|
||||||
|
*/
|
||||||
|
CompletableFuture<List<HeldPermission<String>>> getGroupsWithPermission(String permission);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates and loads a track into the plugins local storage
|
* Creates and loads a track into the plugins local storage
|
||||||
*
|
*
|
||||||
@@ -239,4 +260,14 @@ public interface Storage {
|
|||||||
*/
|
*/
|
||||||
CompletableFuture<UUID> getUUID(String username);
|
CompletableFuture<UUID> getUUID(String username);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets a username from a UUID
|
||||||
|
*
|
||||||
|
* @param uuid the corresponding uuid
|
||||||
|
* @return a name string, could be null
|
||||||
|
* @throws NullPointerException if either parameters are null
|
||||||
|
* @since 2.17
|
||||||
|
*/
|
||||||
|
CompletableFuture<String> getName(UUID uuid);
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -28,19 +28,20 @@ import me.lucko.luckperms.exceptions.ObjectLacksException;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Interface for internal Track instances
|
* An ordered collection of groups for easy promotions and demotions
|
||||||
*/
|
*/
|
||||||
@SuppressWarnings("unused")
|
|
||||||
public interface Track {
|
public interface Track {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* Gets the name of this track
|
||||||
* @return the name of this track
|
* @return the name of this track
|
||||||
*/
|
*/
|
||||||
String getName();
|
String getName();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets an ordered list of the groups on this track
|
* Gets an ordered list of the groups on this track
|
||||||
* Index 0 is the first/lowest group in (or start of) the track
|
*
|
||||||
|
* <p> Index 0 is the first/lowest group in (or start of) the track
|
||||||
*
|
*
|
||||||
* @return an ordered {@link List} of the groups on this track
|
* @return an ordered {@link List} of the groups on this track
|
||||||
*/
|
*/
|
||||||
@@ -136,7 +137,7 @@ public interface Track {
|
|||||||
boolean containsGroup(String group);
|
boolean containsGroup(String group);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Clear all of the groups within this track
|
* Clear all of the groups from this track
|
||||||
*/
|
*/
|
||||||
void clearGroups();
|
void clearGroups();
|
||||||
|
|
||||||
|
|||||||
@@ -23,14 +23,34 @@
|
|||||||
package me.lucko.luckperms.api;
|
package me.lucko.luckperms.api;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Represents a permission value
|
* Represents a permission setting.
|
||||||
|
*
|
||||||
|
* <p> Consider a value of {@link #FALSE} to be a "negated" setting, and a value of {@link #UNDEFINED} to be a
|
||||||
|
* non-existent value.
|
||||||
*/
|
*/
|
||||||
public enum Tristate {
|
public enum Tristate {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A value indicating a holder has a permission set.
|
||||||
|
*/
|
||||||
TRUE(true),
|
TRUE(true),
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A value indicating a holder has a negated value for a permission.
|
||||||
|
*/
|
||||||
FALSE(false),
|
FALSE(false),
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A value indicating a holder doesn't have a value for a permission set.
|
||||||
|
*/
|
||||||
UNDEFINED(false);
|
UNDEFINED(false);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Converts from {@link Boolean} a boolean
|
||||||
|
*
|
||||||
|
* @param b the boolean
|
||||||
|
* @return {@link #TRUE} or {@link #FALSE}, depending on the value of the boolean.
|
||||||
|
*/
|
||||||
public static Tristate fromBoolean(boolean b) {
|
public static Tristate fromBoolean(boolean b) {
|
||||||
return b ? TRUE : FALSE;
|
return b ? TRUE : FALSE;
|
||||||
}
|
}
|
||||||
@@ -41,6 +61,12 @@ public enum Tristate {
|
|||||||
this.booleanValue = booleanValue;
|
this.booleanValue = booleanValue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the value of the Tristate as a boolean.
|
||||||
|
* <p> A value of {@link #UNDEFINED} converts to false.
|
||||||
|
*
|
||||||
|
* @return a boolean representation of the Tristate.
|
||||||
|
*/
|
||||||
public boolean asBoolean() {
|
public boolean asBoolean() {
|
||||||
return booleanValue;
|
return booleanValue;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -31,17 +31,20 @@ import java.util.Optional;
|
|||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Interface for internal User instances
|
* A player holding permission data
|
||||||
*/
|
*/
|
||||||
@SuppressWarnings("unused")
|
|
||||||
public interface User extends PermissionHolder {
|
public interface User extends PermissionHolder {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* Gets the users unique ID
|
||||||
|
*
|
||||||
* @return the users Mojang assigned unique id
|
* @return the users Mojang assigned unique id
|
||||||
*/
|
*/
|
||||||
UUID getUuid();
|
UUID getUuid();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* Gets the users username
|
||||||
|
*
|
||||||
* @return the Users Username
|
* @return the Users Username
|
||||||
*/
|
*/
|
||||||
String getName();
|
String getName();
|
||||||
@@ -64,7 +67,10 @@ public interface User extends PermissionHolder {
|
|||||||
void setPrimaryGroup(String group) throws ObjectAlreadyHasException;
|
void setPrimaryGroup(String group) throws ObjectAlreadyHasException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Refresh and re-assign the users permissions
|
* Refresh and re-assign the users permissions.
|
||||||
|
*
|
||||||
|
* <p> This request is not buffered, and the refresh call will be ran directly. This should ideally be called on
|
||||||
|
* an asynchronous thread.
|
||||||
*/
|
*/
|
||||||
void refreshPermissions();
|
void refreshPermissions();
|
||||||
|
|
||||||
@@ -76,6 +82,13 @@ public interface User extends PermissionHolder {
|
|||||||
*/
|
*/
|
||||||
Optional<UserData> getUserDataCache();
|
Optional<UserData> getUserDataCache();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets up the users data cache, if the don't have one setup already.
|
||||||
|
*
|
||||||
|
* @since 2.17
|
||||||
|
*/
|
||||||
|
void setupDataCache();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Check to see if the user is a member of a group
|
* Check to see if the user is a member of a group
|
||||||
*
|
*
|
||||||
@@ -255,11 +268,6 @@ public interface User extends PermissionHolder {
|
|||||||
*/
|
*/
|
||||||
void removeGroup(Group group, String server, String world, boolean temporary) throws ObjectLacksException;
|
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
|
* Get a {@link List} of all of the groups the user is a member of, on all servers
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -28,16 +28,15 @@ import java.util.UUID;
|
|||||||
* A UUID cache for online users, between external Mojang UUIDs, and internal LuckPerms UUIDs.
|
* A UUID cache for online users, between external Mojang UUIDs, and internal LuckPerms UUIDs.
|
||||||
*
|
*
|
||||||
* <p> This UuidCache is a means of allowing users to have the same internal UUID across a network of offline mode
|
* <p> This UuidCache is a means of allowing users to have the same internal UUID across a network of offline mode
|
||||||
* servers or mixed offline mode and online mode servers. Platforms running in offline mode generate a random UUID for a
|
* servers or mixed offline mode and online mode servers. Platforms running in offline mode generate a UUID for a
|
||||||
* user when they first join the server, but this UUID will then not be consistent across the network. LuckPerms will
|
* user when they first join the server, but this UUID will then not be consistent across the network. LuckPerms will
|
||||||
* instead check the datastore cache, to get a UUID for a user that is consistent across an entire network.
|
* instead check the datastore cache, to get a UUID for a user that is consistent across an entire network.
|
||||||
*
|
*
|
||||||
* <p> If you want to get a user object from the Storage using the api on a server in offline mode, you will need to use
|
* <p> If you want to get a user object from the Storage using the api on a server in offline mode, you will need to use
|
||||||
* this cache, OR use Storage#getUUID, for users that are not online.
|
* this cache, OR use Storage#getUUID, for users that are not online.
|
||||||
*
|
*
|
||||||
* <p> WARNING: THIS IS ONLY EFFECTIVE FOR ONLINE PLAYERS. USE THE DATASTORE METHODS FOR OFFLINE PLAYERS.
|
* <p> THIS IS ONLY EFFECTIVE FOR ONLINE PLAYERS. USE THE DATASTORE METHODS FOR OFFLINE PLAYERS.
|
||||||
*/
|
*/
|
||||||
@SuppressWarnings("unused")
|
|
||||||
public interface UuidCache {
|
public interface UuidCache {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -44,7 +44,8 @@ public interface PermissionData {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Invalidates the underlying permission calculator cache.
|
* Invalidates the underlying permission calculator cache.
|
||||||
* Can be called to allow for an update in defaults.
|
*
|
||||||
|
* <p> Can be called to allow for an update in defaults.
|
||||||
*/
|
*/
|
||||||
void invalidateCache();
|
void invalidateCache();
|
||||||
|
|
||||||
|
|||||||
@@ -38,7 +38,8 @@ public interface UserData {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets PermissionData from the cache, given a specified context.
|
* Gets PermissionData from the cache, given a specified context.
|
||||||
* If the data is not cached, it is calculated. Therefore, this call could be costly.
|
*
|
||||||
|
* <p> If the data is not cached, it is calculated. Therefore, this call could be costly.
|
||||||
*
|
*
|
||||||
* @param contexts the contexts to get the permission data in
|
* @param contexts the contexts to get the permission data in
|
||||||
* @return a permission data instance
|
* @return a permission data instance
|
||||||
@@ -48,7 +49,8 @@ public interface UserData {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets MetaData from the cache, given a specified context.
|
* Gets MetaData from the cache, given a specified context.
|
||||||
* If the data is not cached, it is calculated. Therefore, this call could be costly.
|
*
|
||||||
|
* <p> If the data is not cached, it is calculated. Therefore, this call could be costly.
|
||||||
*
|
*
|
||||||
* @param contexts the contexts to get the permission data in
|
* @param contexts the contexts to get the permission data in
|
||||||
* @return a meta data instance
|
* @return a meta data instance
|
||||||
@@ -75,8 +77,10 @@ public interface UserData {
|
|||||||
MetaData calculateMeta(Contexts contexts);
|
MetaData calculateMeta(Contexts contexts);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Calculates permission data and stores it in the cache. If there is already data cached for the given contexts,
|
* Calculates permission data and stores it in the cache.
|
||||||
* and if the resultant output is different, the cached value is updated.
|
*
|
||||||
|
* <p> If there is already data cached for the given contexts, and if the resultant output is different,
|
||||||
|
* the cached value is updated.
|
||||||
*
|
*
|
||||||
* @param contexts the contexts to recalculate in.
|
* @param contexts the contexts to recalculate in.
|
||||||
* @throws NullPointerException if contexts is null
|
* @throws NullPointerException if contexts is null
|
||||||
@@ -84,8 +88,10 @@ public interface UserData {
|
|||||||
void recalculatePermissions(Contexts contexts);
|
void recalculatePermissions(Contexts contexts);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Calculates meta data and stores it in the cache. If there is already data cached for the given contexts,
|
* Calculates meta data and stores it in the cache.
|
||||||
* and if the resultant output is different, the cached value is updated.
|
*
|
||||||
|
* <p> If there is already data cached for the given contexts, and if the resultant output is different,
|
||||||
|
* the cached value is updated.
|
||||||
*
|
*
|
||||||
* @param contexts the contexts to recalculate in.
|
* @param contexts the contexts to recalculate in.
|
||||||
* @throws NullPointerException if contexts is null
|
* @throws NullPointerException if contexts is null
|
||||||
@@ -111,8 +117,9 @@ public interface UserData {
|
|||||||
void preCalculate(Set<Contexts> contexts);
|
void preCalculate(Set<Contexts> contexts);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Ensures that PermissionData and MetaData is cached for a context. If the cache does not contain any data for the
|
* Ensures that PermissionData and MetaData is cached for a context.
|
||||||
* context, it will be calculated and saved.
|
*
|
||||||
|
* <p> If the cache does not contain any data for the context, it will be calculated and saved.
|
||||||
*
|
*
|
||||||
* @param contexts the contexts to pre-calculate for
|
* @param contexts the contexts to pre-calculate for
|
||||||
* @throws NullPointerException if contexts is null
|
* @throws NullPointerException if contexts is null
|
||||||
|
|||||||
@@ -22,55 +22,34 @@
|
|||||||
|
|
||||||
package me.lucko.luckperms.api.context;
|
package me.lucko.luckperms.api.context;
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.concurrent.CopyOnWriteArrayList;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A simple implementation of the listener aspects of {@link IContextCalculator}
|
* Calculates whether contexts are applicable to {@link T}
|
||||||
*
|
*
|
||||||
* @param <T> the subject type
|
* <p>Somewhat inspired by the system used on Sponge.
|
||||||
|
*
|
||||||
|
* @param <T> the subject type. Is ALWAYS the player class of the platform.
|
||||||
*/
|
*/
|
||||||
public abstract class ContextCalculator<T> implements IContextCalculator<T> {
|
public interface ContextCalculator<T> {
|
||||||
private final List<ContextListener<T>> listeners = new CopyOnWriteArrayList<>();
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Pushes an update to all registered {@link ContextListener}s.
|
* Gives the subject all of the applicable contexts they meet
|
||||||
* Make sure any changes are applied internally before this method is called.
|
|
||||||
*
|
*
|
||||||
* @param subject the subject that changed
|
* @param subject the subject to add contexts to
|
||||||
* @param before the context state before the change
|
* @param accumulator a map of contexts to add to
|
||||||
* @param current the context state after the change (now)
|
* @return the map
|
||||||
* @throws NullPointerException if any parameters are null
|
* @since 2.13
|
||||||
*/
|
*/
|
||||||
protected void pushUpdate(T subject, Map.Entry<String, String> before, Map.Entry<String, String> current) {
|
MutableContextSet giveApplicableContext(T subject, MutableContextSet accumulator);
|
||||||
if (subject == null) {
|
|
||||||
throw new NullPointerException("subject");
|
|
||||||
}
|
|
||||||
if (before == null) {
|
|
||||||
throw new NullPointerException("before");
|
|
||||||
}
|
|
||||||
if (current == null) {
|
|
||||||
throw new NullPointerException("current");
|
|
||||||
}
|
|
||||||
|
|
||||||
for (ContextListener<T> listener : listeners) {
|
/**
|
||||||
try {
|
* Checks to see if a context is applicable to a subject
|
||||||
listener.onContextChange(subject, before, current);
|
*
|
||||||
} catch (Exception e) {
|
* @param subject the subject to check against
|
||||||
System.out.println("Exception whilst passing context change to listener: " + listener);
|
* @param context the context to check for
|
||||||
e.printStackTrace();
|
* @return true if met, or false if not. If this calculator does not calculate the given context, return false.
|
||||||
}
|
*/
|
||||||
}
|
boolean isContextApplicable(T subject, Map.Entry<String, String> context);
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void addListener(ContextListener<T> listener) {
|
|
||||||
if (listener == null) {
|
|
||||||
throw new NullPointerException("listener");
|
|
||||||
}
|
|
||||||
|
|
||||||
listeners.add(listener);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -65,7 +65,7 @@ public interface ContextSet {
|
|||||||
* @return a new ImmutableContextSet representing the pairs in the iterable
|
* @return a new ImmutableContextSet representing the pairs in the iterable
|
||||||
* @throws NullPointerException if the iterable is null
|
* @throws NullPointerException if the iterable is null
|
||||||
*/
|
*/
|
||||||
static ImmutableContextSet fromEntries(Iterable<Map.Entry<String, String>> iterable) {
|
static ImmutableContextSet fromEntries(Iterable<? extends Map.Entry<String, String>> iterable) {
|
||||||
return ImmutableContextSet.fromEntries(iterable);
|
return ImmutableContextSet.fromEntries(iterable);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,92 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (c) 2016 Lucko (Luck) <[email protected]>
|
|
||||||
*
|
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
||||||
* of this software and associated documentation files (the "Software"), to deal
|
|
||||||
* in the Software without restriction, including without limitation the rights
|
|
||||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
||||||
* copies of the Software, and to permit persons to whom the Software is
|
|
||||||
* furnished to do so, subject to the following conditions:
|
|
||||||
*
|
|
||||||
* The above copyright notice and this permission notice shall be included in all
|
|
||||||
* copies or substantial portions of the Software.
|
|
||||||
*
|
|
||||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
||||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
||||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
||||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
||||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
||||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
||||||
* SOFTWARE.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package me.lucko.luckperms.api.context;
|
|
||||||
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Calculates whether contexts are applicable to {@link T}
|
|
||||||
*
|
|
||||||
* <p>Somewhat inspired by the system used on Sponge.
|
|
||||||
*
|
|
||||||
* @param <T> the subject type. Is ALWAYS the player class of the platform.
|
|
||||||
*/
|
|
||||||
public interface IContextCalculator<T> {
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Gives the subject all of the applicable contexts they meet
|
|
||||||
*
|
|
||||||
* @param subject the subject to add contexts to
|
|
||||||
* @param accumulator a map of contexts to add to
|
|
||||||
* @return the map
|
|
||||||
* @deprecated in favour of {@link #giveApplicableContext(Object, MutableContextSet)}. Older implementations of this
|
|
||||||
* interface will still work, as the replacement method is given as a default, and falls back to using this method.
|
|
||||||
*/
|
|
||||||
@Deprecated
|
|
||||||
default Map<String, String> giveApplicableContext(T subject, Map<String, String> accumulator) {
|
|
||||||
MutableContextSet acc = new MutableContextSet();
|
|
||||||
giveApplicableContext(subject, acc);
|
|
||||||
|
|
||||||
accumulator.putAll(acc.toMap());
|
|
||||||
return accumulator;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Gives the subject all of the applicable contexts they meet
|
|
||||||
*
|
|
||||||
* <p><b>You MUST implement this method. The default is only provided for backwards compatibility with
|
|
||||||
* {@link #giveApplicableContext(Object, Map)}.</b>
|
|
||||||
*
|
|
||||||
* @param subject the subject to add contexts to
|
|
||||||
* @param accumulator a map of contexts to add to
|
|
||||||
* @return the map
|
|
||||||
* @since 2.13
|
|
||||||
*/
|
|
||||||
@SuppressWarnings("deprecation")
|
|
||||||
default MutableContextSet giveApplicableContext(T subject, MutableContextSet accumulator) {
|
|
||||||
Map<String, String> acc = new HashMap<>();
|
|
||||||
giveApplicableContext(subject, acc);
|
|
||||||
|
|
||||||
accumulator.addAll(acc.entrySet());
|
|
||||||
return accumulator;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Checks to see if a context is applicable to a subject
|
|
||||||
*
|
|
||||||
* @param subject the subject to check against
|
|
||||||
* @param context the context to check for
|
|
||||||
* @return true if met, or false if not. If this calculator does not calculate the given context, return false.
|
|
||||||
*/
|
|
||||||
boolean isContextApplicable(T subject, Map.Entry<String, String> context);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Adds a listener to be called whenever a context handled by this calculator changes
|
|
||||||
*
|
|
||||||
* @param listener the listener instance
|
|
||||||
* @throws NullPointerException if listener is null
|
|
||||||
*/
|
|
||||||
void addListener(ContextListener<T> listener);
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -30,7 +30,6 @@ import com.google.common.collect.Multimap;
|
|||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.stream.Collectors;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* An immutable implementation of {@link ContextSet}.
|
* An immutable implementation of {@link ContextSet}.
|
||||||
@@ -71,13 +70,12 @@ public final class ImmutableContextSet implements ContextSet {
|
|||||||
throw new NullPointerException("map");
|
throw new NullPointerException("map");
|
||||||
}
|
}
|
||||||
|
|
||||||
return new ImmutableContextSet(ImmutableMultimap.copyOf(
|
ImmutableMultimap.Builder<String, String> b = ImmutableMultimap.builder();
|
||||||
map.entrySet().stream()
|
for (Map.Entry<String, String> e : map.entrySet()) {
|
||||||
.collect(Collectors.toMap(
|
b.put(e.getKey(), e.getValue());
|
||||||
e -> e.getKey().toLowerCase(),
|
}
|
||||||
Map.Entry::getValue
|
|
||||||
)).entrySet()
|
return new ImmutableContextSet(b.build());
|
||||||
));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -87,7 +85,7 @@ public final class ImmutableContextSet implements ContextSet {
|
|||||||
* @return a new ImmutableContextSet representing the pairs in the iterable
|
* @return a new ImmutableContextSet representing the pairs in the iterable
|
||||||
* @throws NullPointerException if the iterable is null
|
* @throws NullPointerException if the iterable is null
|
||||||
*/
|
*/
|
||||||
public static ImmutableContextSet fromEntries(Iterable<Map.Entry<String, String>> iterable) {
|
public static ImmutableContextSet fromEntries(Iterable<? extends Map.Entry<String, String>> iterable) {
|
||||||
if (iterable == null) {
|
if (iterable == null) {
|
||||||
throw new NullPointerException("iterable");
|
throw new NullPointerException("iterable");
|
||||||
}
|
}
|
||||||
@@ -160,7 +158,12 @@ public final class ImmutableContextSet implements ContextSet {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Map<String, String> toMap() {
|
public Map<String, String> toMap() {
|
||||||
return ImmutableMap.copyOf(map.entries());
|
ImmutableMap.Builder<String, String> m = ImmutableMap.builder();
|
||||||
|
for (Map.Entry<String, String> e : map.entries()) {
|
||||||
|
m.put(e.getKey(), e.getValue());
|
||||||
|
}
|
||||||
|
|
||||||
|
return m.build();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -84,7 +84,7 @@ public final class MutableContextSet implements ContextSet {
|
|||||||
* @return a new MutableContextSet representing the pairs in the iterable
|
* @return a new MutableContextSet representing the pairs in the iterable
|
||||||
* @throws NullPointerException if the iterable is null
|
* @throws NullPointerException if the iterable is null
|
||||||
*/
|
*/
|
||||||
public static MutableContextSet fromEntries(Iterable<Map.Entry<String, String>> iterable) {
|
public static MutableContextSet fromEntries(Iterable<? extends Map.Entry<String, String>> iterable) {
|
||||||
if (iterable == null) {
|
if (iterable == null) {
|
||||||
throw new NullPointerException("iterable");
|
throw new NullPointerException("iterable");
|
||||||
}
|
}
|
||||||
@@ -168,7 +168,12 @@ public final class MutableContextSet implements ContextSet {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Map<String, String> toMap() {
|
public Map<String, String> toMap() {
|
||||||
return ImmutableMap.copyOf(map.entries());
|
ImmutableMap.Builder<String, String> m = ImmutableMap.builder();
|
||||||
|
for (Map.Entry<String, String> e : map.entries()) {
|
||||||
|
m.put(e.getKey(), e.getValue());
|
||||||
|
}
|
||||||
|
|
||||||
|
return m.build();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -277,7 +282,7 @@ public final class MutableContextSet implements ContextSet {
|
|||||||
* @param iterable an iterable of key value context pairs
|
* @param iterable an iterable of key value context pairs
|
||||||
* @throws NullPointerException if iterable is null
|
* @throws NullPointerException if iterable is null
|
||||||
*/
|
*/
|
||||||
public void addAll(Iterable<Map.Entry<String, String>> iterable) {
|
public void addAll(Iterable<? extends Map.Entry<String, String>> iterable) {
|
||||||
if (iterable == null) {
|
if (iterable == null) {
|
||||||
throw new NullPointerException("contexts");
|
throw new NullPointerException("contexts");
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,78 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (c) 2016 Lucko (Luck) <[email protected]>
|
|
||||||
*
|
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
||||||
* of this software and associated documentation files (the "Software"), to deal
|
|
||||||
* in the Software without restriction, including without limitation the rights
|
|
||||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
||||||
* copies of the Software, and to permit persons to whom the Software is
|
|
||||||
* furnished to do so, subject to the following conditions:
|
|
||||||
*
|
|
||||||
* The above copyright notice and this permission notice shall be included in all
|
|
||||||
* copies or substantial portions of the Software.
|
|
||||||
*
|
|
||||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
||||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
||||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
||||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
||||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
||||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
||||||
* SOFTWARE.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package me.lucko.luckperms.api.data;
|
|
||||||
|
|
||||||
import java.util.function.Consumer;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* A callback used to wait for the completion of asynchronous operations.
|
|
||||||
* All callbacks are ran on the main server thread.
|
|
||||||
*
|
|
||||||
* @param <T> the return type
|
|
||||||
* @deprecated in favour of {@link Consumer}
|
|
||||||
*/
|
|
||||||
@Deprecated
|
|
||||||
public interface Callback<T> {
|
|
||||||
|
|
||||||
static <T> Callback<T> empty() {
|
|
||||||
return t -> {
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
static <T> Callback<T> of(Runnable runnable) {
|
|
||||||
if (runnable == null) {
|
|
||||||
throw new NullPointerException("runnable");
|
|
||||||
}
|
|
||||||
return t -> runnable.run();
|
|
||||||
}
|
|
||||||
|
|
||||||
static <T> Callback<T> of(Consumer<T> consumer) {
|
|
||||||
if (consumer == null) {
|
|
||||||
throw new NullPointerException("consumer");
|
|
||||||
}
|
|
||||||
return consumer::accept;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Helper method for converting old {@link Callback}s to use the new {@link me.lucko.luckperms.api.Storage}
|
|
||||||
* interface.
|
|
||||||
*
|
|
||||||
* @param callback the callback to convert
|
|
||||||
* @param <T> the return type
|
|
||||||
* @return a consumer instance
|
|
||||||
* @since 2.14
|
|
||||||
* @deprecated in favour of just using {@link Consumer}s.
|
|
||||||
*/
|
|
||||||
@Deprecated
|
|
||||||
static <T> Consumer<T> convertToConsumer(Callback<T> callback) {
|
|
||||||
return callback::onComplete;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Called when the operation completes.
|
|
||||||
*
|
|
||||||
* @param t the return value, may be null
|
|
||||||
*/
|
|
||||||
void onComplete(T t);
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -26,8 +26,7 @@ package me.lucko.luckperms.api.data;
|
|||||||
* Represents the data section of the main LuckPerms configuration.
|
* Represents the data section of the main LuckPerms configuration.
|
||||||
* All methods could return null.
|
* All methods could return null.
|
||||||
*/
|
*/
|
||||||
@SuppressWarnings("deprecation")
|
public interface DatastoreConfiguration {
|
||||||
public interface DatastoreConfiguration extends MySQLConfiguration {
|
|
||||||
|
|
||||||
String getAddress();
|
String getAddress();
|
||||||
|
|
||||||
|
|||||||
+9
-12
@@ -22,21 +22,18 @@
|
|||||||
|
|
||||||
package me.lucko.luckperms.api.event;
|
package me.lucko.luckperms.api.event;
|
||||||
|
|
||||||
import me.lucko.luckperms.api.User;
|
import java.util.concurrent.atomic.AtomicBoolean;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Represents an event acting upon a user.
|
* Represents an event that can be cancelled
|
||||||
*/
|
*/
|
||||||
public class UserEvent extends LPEvent {
|
public interface Cancellable {
|
||||||
|
|
||||||
private final User user;
|
/**
|
||||||
|
* Gets an {@link AtomicBoolean} holding the cancellation state of the event
|
||||||
|
*
|
||||||
|
* @return the cancellation
|
||||||
|
*/
|
||||||
|
AtomicBoolean getCancellationState();
|
||||||
|
|
||||||
protected UserEvent(String eventName, User user) {
|
|
||||||
super(eventName);
|
|
||||||
this.user = user;
|
|
||||||
}
|
|
||||||
|
|
||||||
public User getUser() {
|
|
||||||
return user;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,54 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2016 Lucko (Luck) <[email protected]>
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
* of this software and associated documentation files (the "Software"), to deal
|
||||||
|
* in the Software without restriction, including without limitation the rights
|
||||||
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
* copies of the Software, and to permit persons to whom the Software is
|
||||||
|
* furnished to do so, subject to the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be included in all
|
||||||
|
* copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
|
* SOFTWARE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package me.lucko.luckperms.api.event;
|
||||||
|
|
||||||
|
import java.util.Set;
|
||||||
|
import java.util.function.Consumer;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The LuckPerms event bus. Used for subscribing (or registering listeners) to events.
|
||||||
|
*
|
||||||
|
* @since 3.0
|
||||||
|
*/
|
||||||
|
public interface EventBus {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Subscribe to an event
|
||||||
|
*
|
||||||
|
* @param eventClass the event class
|
||||||
|
* @param handler the event handler
|
||||||
|
* @param <T> the event class
|
||||||
|
* @return an event handler instance representing this subscription
|
||||||
|
*/
|
||||||
|
<T extends LuckPermsEvent> EventHandler<T> subscribe(Class<T> eventClass, Consumer<T> handler);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets a set of all registered handlers for a given event
|
||||||
|
*
|
||||||
|
* @param eventClass the event to find handlers for
|
||||||
|
* @param <T> the event class
|
||||||
|
* @return an immutable set of event handlers
|
||||||
|
*/
|
||||||
|
<T extends LuckPermsEvent> Set<EventHandler<T>> getHandlers(Class<T> eventClass);
|
||||||
|
|
||||||
|
}
|
||||||
+38
-31
@@ -22,41 +22,48 @@
|
|||||||
|
|
||||||
package me.lucko.luckperms.api.event;
|
package me.lucko.luckperms.api.event;
|
||||||
|
|
||||||
import me.lucko.luckperms.api.PermissionHolder;
|
import java.util.function.Consumer;
|
||||||
|
|
||||||
import java.util.Optional;
|
/**
|
||||||
|
* Represents a handler for a LuckPerms event
|
||||||
public class AbstractPermissionRemoveEvent extends TargetedEvent<PermissionHolder> {
|
*
|
||||||
|
* @param <T> the event class
|
||||||
private final String server;
|
*/
|
||||||
private final String world;
|
public interface EventHandler<T extends LuckPermsEvent> {
|
||||||
private final boolean temporary;
|
|
||||||
|
|
||||||
protected AbstractPermissionRemoveEvent(String eventName, PermissionHolder target, String server, String world, boolean temporary) {
|
|
||||||
super(eventName, target);
|
|
||||||
this.server = server;
|
|
||||||
this.world = world;
|
|
||||||
this.temporary = temporary;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Optional<String> getServer() {
|
|
||||||
return Optional.ofNullable(server);
|
|
||||||
}
|
|
||||||
|
|
||||||
public Optional<String> getWorld() {
|
|
||||||
return Optional.ofNullable(world);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @deprecated use {@link #isTemporary()}
|
* Gets the class this handler is listening to
|
||||||
|
*
|
||||||
|
* @return the event class
|
||||||
*/
|
*/
|
||||||
@Deprecated
|
Class<T> getEventClass();
|
||||||
public boolean getTemporary() {
|
|
||||||
return temporary;
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean isTemporary() {
|
/**
|
||||||
return temporary;
|
* Returns true if this handler is active
|
||||||
}
|
*
|
||||||
|
* @return true if this handler is still active
|
||||||
|
*/
|
||||||
|
boolean isActive();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Unregisters this handler from the event bus
|
||||||
|
*
|
||||||
|
* @return true if the handler wasn't already unregistered
|
||||||
|
*/
|
||||||
|
boolean unregister();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the event consumer responsible for handling the event
|
||||||
|
*
|
||||||
|
* @return the event consumer
|
||||||
|
*/
|
||||||
|
Consumer<T> getConsumer();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the number of times this handler has been called
|
||||||
|
*
|
||||||
|
* @return the number of times this handler has been called
|
||||||
|
*/
|
||||||
|
int getCallCount();
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,41 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2016 Lucko (Luck) <[email protected]>
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
* of this software and associated documentation files (the "Software"), to deal
|
||||||
|
* in the Software without restriction, including without limitation the rights
|
||||||
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
* copies of the Software, and to permit persons to whom the Software is
|
||||||
|
* furnished to do so, subject to the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be included in all
|
||||||
|
* copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
|
* SOFTWARE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package me.lucko.luckperms.api.event;
|
||||||
|
|
||||||
|
import me.lucko.luckperms.api.LuckPermsApi;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The base event interface
|
||||||
|
*
|
||||||
|
* @since 3.0
|
||||||
|
*/
|
||||||
|
public interface LuckPermsEvent {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the API instance this event was dispatched from
|
||||||
|
*
|
||||||
|
* @return the api instance
|
||||||
|
*/
|
||||||
|
LuckPermsApi getApi();
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,45 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2016 Lucko (Luck) <[email protected]>
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
* of this software and associated documentation files (the "Software"), to deal
|
||||||
|
* in the Software without restriction, including without limitation the rights
|
||||||
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
* copies of the Software, and to permit persons to whom the Software is
|
||||||
|
* furnished to do so, subject to the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be included in all
|
||||||
|
* copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
|
* SOFTWARE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package me.lucko.luckperms.api.event.cause;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The cause of a group/track creation
|
||||||
|
*/
|
||||||
|
public enum CreationCause {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The creation was caused by a command
|
||||||
|
*/
|
||||||
|
COMMAND,
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The creation was caused by an API call
|
||||||
|
*/
|
||||||
|
API,
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The creation was caused by a LuckPerms internal
|
||||||
|
*/
|
||||||
|
INTERNAL;
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,45 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2016 Lucko (Luck) <[email protected]>
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
* of this software and associated documentation files (the "Software"), to deal
|
||||||
|
* in the Software without restriction, including without limitation the rights
|
||||||
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
* copies of the Software, and to permit persons to whom the Software is
|
||||||
|
* furnished to do so, subject to the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be included in all
|
||||||
|
* copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
|
* SOFTWARE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package me.lucko.luckperms.api.event.cause;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The cause of a group/track deletion
|
||||||
|
*/
|
||||||
|
public enum DeletionCause {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The deletion was caused by a command
|
||||||
|
*/
|
||||||
|
COMMAND,
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The deletion was caused by an API call
|
||||||
|
*/
|
||||||
|
API,
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The deletion was caused by a LuckPerms internal
|
||||||
|
*/
|
||||||
|
INTERNAL;
|
||||||
|
|
||||||
|
}
|
||||||
@@ -1,47 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (c) 2016 Lucko (Luck) <[email protected]>
|
|
||||||
*
|
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
||||||
* of this software and associated documentation files (the "Software"), to deal
|
|
||||||
* in the Software without restriction, including without limitation the rights
|
|
||||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
||||||
* copies of the Software, and to permit persons to whom the Software is
|
|
||||||
* furnished to do so, subject to the following conditions:
|
|
||||||
*
|
|
||||||
* The above copyright notice and this permission notice shall be included in all
|
|
||||||
* copies or substantial portions of the Software.
|
|
||||||
*
|
|
||||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
||||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
||||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
||||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
||||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
||||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
||||||
* SOFTWARE.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package me.lucko.luckperms.api.event.events;
|
|
||||||
|
|
||||||
import me.lucko.luckperms.api.PermissionHolder;
|
|
||||||
import me.lucko.luckperms.api.event.AbstractPermissionRemoveEvent;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Called whenever a user or group is removed from / stops inheriting another group
|
|
||||||
*/
|
|
||||||
public class GroupRemoveEvent extends AbstractPermissionRemoveEvent {
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The name of group being removed from the target.
|
|
||||||
* Be aware that this group may have already been deleted, and and instance may therefore not exist internally.
|
|
||||||
*/
|
|
||||||
private final String group;
|
|
||||||
|
|
||||||
public GroupRemoveEvent(PermissionHolder target, String group, String server, String world, boolean temporary) {
|
|
||||||
super("Group Remove Event", target, server, world, temporary);
|
|
||||||
this.group = group;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getGroup() {
|
|
||||||
return group;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,46 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (c) 2016 Lucko (Luck) <[email protected]>
|
|
||||||
*
|
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
||||||
* of this software and associated documentation files (the "Software"), to deal
|
|
||||||
* in the Software without restriction, including without limitation the rights
|
|
||||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
||||||
* copies of the Software, and to permit persons to whom the Software is
|
|
||||||
* furnished to do so, subject to the following conditions:
|
|
||||||
*
|
|
||||||
* The above copyright notice and this permission notice shall be included in all
|
|
||||||
* copies or substantial portions of the Software.
|
|
||||||
*
|
|
||||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
||||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
||||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
||||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
||||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
||||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
||||||
* SOFTWARE.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package me.lucko.luckperms.api.event.events;
|
|
||||||
|
|
||||||
import me.lucko.luckperms.api.PermissionHolder;
|
|
||||||
import me.lucko.luckperms.api.event.AbstractPermissionRemoveEvent;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Called whenever a user or group has a permission unset.
|
|
||||||
*
|
|
||||||
* @deprecated in favour of {@link PermissionNodeUnsetEvent}
|
|
||||||
*/
|
|
||||||
@Deprecated
|
|
||||||
public class PermissionUnsetEvent extends AbstractPermissionRemoveEvent {
|
|
||||||
|
|
||||||
private final String node;
|
|
||||||
|
|
||||||
public PermissionUnsetEvent(PermissionHolder target, String node, String server, String world, boolean temporary) {
|
|
||||||
super("Permission Unset Event", target, server, world, temporary);
|
|
||||||
this.node = node;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getNode() {
|
|
||||||
return node;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -0,0 +1,48 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2016 Lucko (Luck) <[email protected]>
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
* of this software and associated documentation files (the "Software"), to deal
|
||||||
|
* in the Software without restriction, including without limitation the rights
|
||||||
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
* copies of the Software, and to permit persons to whom the Software is
|
||||||
|
* furnished to do so, subject to the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be included in all
|
||||||
|
* copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
|
* SOFTWARE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package me.lucko.luckperms.api.event.group;
|
||||||
|
|
||||||
|
import me.lucko.luckperms.api.Group;
|
||||||
|
import me.lucko.luckperms.api.event.LuckPermsEvent;
|
||||||
|
import me.lucko.luckperms.api.event.cause.CreationCause;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Called when a group is created
|
||||||
|
*/
|
||||||
|
public interface GroupCreateEvent extends LuckPermsEvent {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the new group
|
||||||
|
*
|
||||||
|
* @return the new group
|
||||||
|
*/
|
||||||
|
Group getGroup();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the cause of the creation
|
||||||
|
*
|
||||||
|
* @return the cause of the creation
|
||||||
|
*/
|
||||||
|
CreationCause getCause();
|
||||||
|
|
||||||
|
}
|
||||||
+29
-10
@@ -20,19 +20,38 @@
|
|||||||
* SOFTWARE.
|
* SOFTWARE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package me.lucko.luckperms.api.event.events;
|
package me.lucko.luckperms.api.event.group;
|
||||||
|
|
||||||
import me.lucko.luckperms.api.Node;
|
import me.lucko.luckperms.api.Node;
|
||||||
import me.lucko.luckperms.api.PermissionHolder;
|
import me.lucko.luckperms.api.event.LuckPermsEvent;
|
||||||
import me.lucko.luckperms.api.event.AbstractPermissionEvent;
|
import me.lucko.luckperms.api.event.cause.DeletionCause;
|
||||||
|
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Called when a permission node is unset from a holder
|
* Called when a group is deleted
|
||||||
*
|
|
||||||
* @since 2.6
|
|
||||||
*/
|
*/
|
||||||
public class PermissionNodeUnsetEvent extends AbstractPermissionEvent {
|
public interface GroupDeleteEvent extends LuckPermsEvent {
|
||||||
public PermissionNodeUnsetEvent(PermissionHolder target, Node node) {
|
|
||||||
super("Permission Node Unset Event", target, node);
|
/**
|
||||||
}
|
* Gets the name of the deleted group
|
||||||
|
*
|
||||||
|
* @return the name of the deleted group
|
||||||
|
*/
|
||||||
|
String getGroupName();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets an immutable copy of the groups existing data
|
||||||
|
*
|
||||||
|
* @return a copy of the groups existing data
|
||||||
|
*/
|
||||||
|
Set<Node> getExistingData();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the cause of the deletion
|
||||||
|
*
|
||||||
|
* @return the cause of the deletion
|
||||||
|
*/
|
||||||
|
DeletionCause getCause();
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,34 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2016 Lucko (Luck) <[email protected]>
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
* of this software and associated documentation files (the "Software"), to deal
|
||||||
|
* in the Software without restriction, including without limitation the rights
|
||||||
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
* copies of the Software, and to permit persons to whom the Software is
|
||||||
|
* furnished to do so, subject to the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be included in all
|
||||||
|
* copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
|
* SOFTWARE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package me.lucko.luckperms.api.event.group;
|
||||||
|
|
||||||
|
import me.lucko.luckperms.api.event.LuckPermsEvent;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Called when all groups have been loaded in from storage.
|
||||||
|
*
|
||||||
|
* <p>Usually only called on startup and in sync tasks.</p>
|
||||||
|
*/
|
||||||
|
public interface GroupLoadAllEvent extends LuckPermsEvent {
|
||||||
|
|
||||||
|
}
|
||||||
+14
-15
@@ -20,24 +20,23 @@
|
|||||||
* SOFTWARE.
|
* SOFTWARE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package me.lucko.luckperms.api.event;
|
package me.lucko.luckperms.api.event.group;
|
||||||
|
|
||||||
|
import me.lucko.luckperms.api.Group;
|
||||||
|
import me.lucko.luckperms.api.event.LuckPermsEvent;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Event that allows listeners to set the cancelled state of an event.
|
* Called when a group is loaded into memory from the storage.
|
||||||
|
*
|
||||||
|
* Note that this event is not the same as {@link GroupCreateEvent}
|
||||||
*/
|
*/
|
||||||
public abstract class CancellableEvent extends LPEvent {
|
public interface GroupLoadEvent extends LuckPermsEvent {
|
||||||
|
|
||||||
private boolean cancelled = false;
|
/**
|
||||||
|
* Gets the group that was loaded
|
||||||
|
*
|
||||||
|
* @return the group that was loaded
|
||||||
|
*/
|
||||||
|
Group getGroup();
|
||||||
|
|
||||||
protected CancellableEvent(String eventName) {
|
|
||||||
super(eventName);
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean isCancelled() {
|
|
||||||
return cancelled;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setCancelled(boolean cancelled) {
|
|
||||||
this.cancelled = cancelled;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,41 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2016 Lucko (Luck) <[email protected]>
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
* of this software and associated documentation files (the "Software"), to deal
|
||||||
|
* in the Software without restriction, including without limitation the rights
|
||||||
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
* copies of the Software, and to permit persons to whom the Software is
|
||||||
|
* furnished to do so, subject to the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be included in all
|
||||||
|
* copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
|
* SOFTWARE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package me.lucko.luckperms.api.event.log;
|
||||||
|
|
||||||
|
import me.lucko.luckperms.api.LogEntry;
|
||||||
|
import me.lucko.luckperms.api.event.Cancellable;
|
||||||
|
import me.lucko.luckperms.api.event.LuckPermsEvent;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Called when a log entry is about to be sent to notifiable players on the platform
|
||||||
|
*/
|
||||||
|
public interface LogBroadcastEvent extends LuckPermsEvent, Cancellable {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the log entry to be broadcasted
|
||||||
|
*
|
||||||
|
* @return the log entry to be broadcasted
|
||||||
|
*/
|
||||||
|
LogEntry getEntry();
|
||||||
|
|
||||||
|
}
|
||||||
+12
-14
@@ -20,24 +20,22 @@
|
|||||||
* SOFTWARE.
|
* SOFTWARE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package me.lucko.luckperms.api.event;
|
package me.lucko.luckperms.api.event.log;
|
||||||
|
|
||||||
import me.lucko.luckperms.api.Node;
|
import me.lucko.luckperms.api.LogEntry;
|
||||||
import me.lucko.luckperms.api.PermissionHolder;
|
import me.lucko.luckperms.api.event.Cancellable;
|
||||||
|
import me.lucko.luckperms.api.event.LuckPermsEvent;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @since 2.6
|
* Called when a log is about to be published to the storage file/table
|
||||||
*/
|
*/
|
||||||
public class AbstractPermissionEvent extends TargetedEvent<PermissionHolder> {
|
public interface LogPublishEvent extends LuckPermsEvent, Cancellable {
|
||||||
|
|
||||||
private final Node node;
|
/**
|
||||||
|
* Gets the log entry to be published
|
||||||
|
*
|
||||||
|
* @return the log entry to be published
|
||||||
|
*/
|
||||||
|
LogEntry getEntry();
|
||||||
|
|
||||||
protected AbstractPermissionEvent(String eventName, PermissionHolder target, Node node) {
|
|
||||||
super(eventName, target);
|
|
||||||
this.node = node;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Node getNode() {
|
|
||||||
return node;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
+11
-10
@@ -20,19 +20,20 @@
|
|||||||
* SOFTWARE.
|
* SOFTWARE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package me.lucko.luckperms.api.data;
|
package me.lucko.luckperms.api.event.node;
|
||||||
|
|
||||||
|
import me.lucko.luckperms.api.Node;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @deprecated Use {@link DatastoreConfiguration}. This is now used by multiple datastores, not just MySQL.
|
* Called when a node is added to a holder
|
||||||
*/
|
*/
|
||||||
@Deprecated
|
public interface NodeAddEvent extends NodeMutateEvent {
|
||||||
public interface MySQLConfiguration {
|
|
||||||
|
|
||||||
String getAddress();
|
/**
|
||||||
|
* Gets the node that was added
|
||||||
|
*
|
||||||
|
* @return the node that was added
|
||||||
|
*/
|
||||||
|
Node getNode();
|
||||||
|
|
||||||
String getDatabase();
|
|
||||||
|
|
||||||
String getUsername();
|
|
||||||
|
|
||||||
String getPassword();
|
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,30 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2016 Lucko (Luck) <[email protected]>
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
* of this software and associated documentation files (the "Software"), to deal
|
||||||
|
* in the Software without restriction, including without limitation the rights
|
||||||
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
* copies of the Software, and to permit persons to whom the Software is
|
||||||
|
* furnished to do so, subject to the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be included in all
|
||||||
|
* copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
|
* SOFTWARE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package me.lucko.luckperms.api.event.node;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Called when a holder has their nodes cleared
|
||||||
|
*/
|
||||||
|
public interface NodeClearEvent extends NodeMutateEvent {
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,75 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2016 Lucko (Luck) <[email protected]>
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
* of this software and associated documentation files (the "Software"), to deal
|
||||||
|
* in the Software without restriction, including without limitation the rights
|
||||||
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
* copies of the Software, and to permit persons to whom the Software is
|
||||||
|
* furnished to do so, subject to the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be included in all
|
||||||
|
* copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
|
* SOFTWARE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package me.lucko.luckperms.api.event.node;
|
||||||
|
|
||||||
|
import me.lucko.luckperms.api.Node;
|
||||||
|
import me.lucko.luckperms.api.PermissionHolder;
|
||||||
|
import me.lucko.luckperms.api.event.LuckPermsEvent;
|
||||||
|
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Called when a node is added to/removed from a user/group
|
||||||
|
*/
|
||||||
|
public interface NodeMutateEvent extends LuckPermsEvent {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the target of the event
|
||||||
|
*
|
||||||
|
* @return the event target
|
||||||
|
*/
|
||||||
|
PermissionHolder getTarget();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets an immutable copy of the holders data before the change
|
||||||
|
*
|
||||||
|
* @return the data before the change
|
||||||
|
*/
|
||||||
|
Set<Node> getDataBefore();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets an immutable copy of the holders data after the change
|
||||||
|
*
|
||||||
|
* @return the data after the change
|
||||||
|
*/
|
||||||
|
Set<Node> getDataAfter();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets whether the target of this event is a {@link me.lucko.luckperms.api.User}
|
||||||
|
*
|
||||||
|
* <p>This is equivalent to checking if getTarget() instanceof User</p>
|
||||||
|
*
|
||||||
|
* @return if the event is targeting a user
|
||||||
|
*/
|
||||||
|
boolean isUser();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets whether the target of this event is a {@link me.lucko.luckperms.api.Group}
|
||||||
|
*
|
||||||
|
* <p>This is equivalent to checking if getTarget() instanceof Group</p>
|
||||||
|
*
|
||||||
|
* @return if the event is targeting a group
|
||||||
|
*/
|
||||||
|
boolean isGroup();
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,39 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2016 Lucko (Luck) <[email protected]>
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
* of this software and associated documentation files (the "Software"), to deal
|
||||||
|
* in the Software without restriction, including without limitation the rights
|
||||||
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
* copies of the Software, and to permit persons to whom the Software is
|
||||||
|
* furnished to do so, subject to the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be included in all
|
||||||
|
* copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
|
* SOFTWARE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package me.lucko.luckperms.api.event.node;
|
||||||
|
|
||||||
|
import me.lucko.luckperms.api.Node;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Called when a node is removed from a holder
|
||||||
|
*/
|
||||||
|
public interface NodeRemoveEvent extends NodeMutateEvent {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the node that was removed
|
||||||
|
*
|
||||||
|
* @return the node that was removed
|
||||||
|
*/
|
||||||
|
Node getNode();
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,32 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2016 Lucko (Luck) <[email protected]>
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
* of this software and associated documentation files (the "Software"), to deal
|
||||||
|
* in the Software without restriction, including without limitation the rights
|
||||||
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
* copies of the Software, and to permit persons to whom the Software is
|
||||||
|
* furnished to do so, subject to the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be included in all
|
||||||
|
* copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
|
* SOFTWARE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package me.lucko.luckperms.api.event.sync;
|
||||||
|
|
||||||
|
import me.lucko.luckperms.api.event.LuckPermsEvent;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Called when the configuration is reloaded
|
||||||
|
*/
|
||||||
|
public interface ConfigReloadEvent extends LuckPermsEvent {
|
||||||
|
|
||||||
|
}
|
||||||
+4
-8
@@ -20,17 +20,13 @@
|
|||||||
* SOFTWARE.
|
* SOFTWARE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package me.lucko.luckperms.api.event.events;
|
package me.lucko.luckperms.api.event.sync;
|
||||||
|
|
||||||
import me.lucko.luckperms.api.event.LPEvent;
|
import me.lucko.luckperms.api.event.LuckPermsEvent;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Called after the sync task has ran.
|
* Called when an sync task has been completed
|
||||||
*/
|
*/
|
||||||
public class PostSyncEvent extends LPEvent {
|
public interface PostSyncEvent extends LuckPermsEvent {
|
||||||
|
|
||||||
public PostSyncEvent() {
|
|
||||||
super("Post Sync Event");
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,42 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2016 Lucko (Luck) <[email protected]>
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
* of this software and associated documentation files (the "Software"), to deal
|
||||||
|
* in the Software without restriction, including without limitation the rights
|
||||||
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
* copies of the Software, and to permit persons to whom the Software is
|
||||||
|
* furnished to do so, subject to the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be included in all
|
||||||
|
* copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
|
* SOFTWARE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package me.lucko.luckperms.api.event.sync;
|
||||||
|
|
||||||
|
import me.lucko.luckperms.api.event.Cancellable;
|
||||||
|
import me.lucko.luckperms.api.event.LuckPermsEvent;
|
||||||
|
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Called before a network sync task runs
|
||||||
|
*/
|
||||||
|
public interface PreNetworkSyncEvent extends LuckPermsEvent, Cancellable {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the ID of the sync request
|
||||||
|
*
|
||||||
|
* @return the id of the sync request
|
||||||
|
*/
|
||||||
|
UUID getSyncId();
|
||||||
|
|
||||||
|
}
|
||||||
+5
-9
@@ -20,18 +20,14 @@
|
|||||||
* SOFTWARE.
|
* SOFTWARE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package me.lucko.luckperms.api.event.events;
|
package me.lucko.luckperms.api.event.sync;
|
||||||
|
|
||||||
import me.lucko.luckperms.api.event.CancellableEvent;
|
import me.lucko.luckperms.api.event.Cancellable;
|
||||||
|
import me.lucko.luckperms.api.event.LuckPermsEvent;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Called before the sync task is about to run.
|
* Called before a sync task runs
|
||||||
* Set this event to cancelled to prevent the sync task from running.
|
|
||||||
*/
|
*/
|
||||||
public class PreSyncEvent extends CancellableEvent {
|
public interface PreSyncEvent extends LuckPermsEvent, Cancellable {
|
||||||
|
|
||||||
public PreSyncEvent() {
|
|
||||||
super("Pre Sync Event");
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,48 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2016 Lucko (Luck) <[email protected]>
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
* of this software and associated documentation files (the "Software"), to deal
|
||||||
|
* in the Software without restriction, including without limitation the rights
|
||||||
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
* copies of the Software, and to permit persons to whom the Software is
|
||||||
|
* furnished to do so, subject to the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be included in all
|
||||||
|
* copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
|
* SOFTWARE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package me.lucko.luckperms.api.event.track;
|
||||||
|
|
||||||
|
import me.lucko.luckperms.api.Track;
|
||||||
|
import me.lucko.luckperms.api.event.LuckPermsEvent;
|
||||||
|
import me.lucko.luckperms.api.event.cause.CreationCause;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Called when a track is created
|
||||||
|
*/
|
||||||
|
public interface TrackCreateEvent extends LuckPermsEvent {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the new track
|
||||||
|
*
|
||||||
|
* @return the new track
|
||||||
|
*/
|
||||||
|
Track getTrack();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the cause of the creation
|
||||||
|
*
|
||||||
|
* @return the cause of the creation
|
||||||
|
*/
|
||||||
|
CreationCause getCause();
|
||||||
|
|
||||||
|
}
|
||||||
+24
-15
@@ -20,28 +20,37 @@
|
|||||||
* SOFTWARE.
|
* SOFTWARE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package me.lucko.luckperms.api.event.events;
|
package me.lucko.luckperms.api.event.track;
|
||||||
|
|
||||||
import me.lucko.luckperms.api.Group;
|
import me.lucko.luckperms.api.event.LuckPermsEvent;
|
||||||
import me.lucko.luckperms.api.PermissionHolder;
|
import me.lucko.luckperms.api.event.cause.DeletionCause;
|
||||||
import me.lucko.luckperms.api.event.AbstractPermissionAddEvent;
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Called whenever a user or group is added to / starts to inherit another group
|
* Called when a track is deleted
|
||||||
*/
|
*/
|
||||||
public class GroupAddEvent extends AbstractPermissionAddEvent {
|
public interface TrackDeleteEvent extends LuckPermsEvent {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The group being added to the target
|
* Gets the name of the deleted track
|
||||||
|
*
|
||||||
|
* @return the name of the deleted track
|
||||||
*/
|
*/
|
||||||
private final Group group;
|
String getTrackName();
|
||||||
|
|
||||||
public GroupAddEvent(PermissionHolder target, Group group, String server, String world, long expiry) {
|
/**
|
||||||
super("Group Add Event", target, server, world, expiry);
|
* Gets an immutable copy of the tracks existing data
|
||||||
this.group = group;
|
*
|
||||||
}
|
* @return a copy of the tracks existing data
|
||||||
|
*/
|
||||||
|
List<String> getExistingData();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the cause of the deletion
|
||||||
|
*
|
||||||
|
* @return the cause of the deletion
|
||||||
|
*/
|
||||||
|
DeletionCause getCause();
|
||||||
|
|
||||||
public Group getGroup() {
|
|
||||||
return group;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,34 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2016 Lucko (Luck) <[email protected]>
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
* of this software and associated documentation files (the "Software"), to deal
|
||||||
|
* in the Software without restriction, including without limitation the rights
|
||||||
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
* copies of the Software, and to permit persons to whom the Software is
|
||||||
|
* furnished to do so, subject to the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be included in all
|
||||||
|
* copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
|
* SOFTWARE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package me.lucko.luckperms.api.event.track;
|
||||||
|
|
||||||
|
import me.lucko.luckperms.api.event.LuckPermsEvent;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Called when all tracks have been loaded in from storage.
|
||||||
|
*
|
||||||
|
* <p>Usually only called on startup and in sync tasks.</p>
|
||||||
|
*/
|
||||||
|
public interface TrackLoadAllEvent extends LuckPermsEvent {
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,42 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2016 Lucko (Luck) <[email protected]>
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
* of this software and associated documentation files (the "Software"), to deal
|
||||||
|
* in the Software without restriction, including without limitation the rights
|
||||||
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
* copies of the Software, and to permit persons to whom the Software is
|
||||||
|
* furnished to do so, subject to the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be included in all
|
||||||
|
* copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
|
* SOFTWARE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package me.lucko.luckperms.api.event.track;
|
||||||
|
|
||||||
|
import me.lucko.luckperms.api.Track;
|
||||||
|
import me.lucko.luckperms.api.event.LuckPermsEvent;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Called when a track is loaded into memory from the storage.
|
||||||
|
*
|
||||||
|
* Note that this event is not the same as {@link TrackCreateEvent}
|
||||||
|
*/
|
||||||
|
public interface TrackLoadEvent extends LuckPermsEvent {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the track that was loaded
|
||||||
|
*
|
||||||
|
* @return the track that was loaded
|
||||||
|
*/
|
||||||
|
Track getTrack();
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,37 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2016 Lucko (Luck) <[email protected]>
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
* of this software and associated documentation files (the "Software"), to deal
|
||||||
|
* in the Software without restriction, including without limitation the rights
|
||||||
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
* copies of the Software, and to permit persons to whom the Software is
|
||||||
|
* furnished to do so, subject to the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be included in all
|
||||||
|
* copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
|
* SOFTWARE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package me.lucko.luckperms.api.event.track.mutate;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Called when a group is added to a track
|
||||||
|
*/
|
||||||
|
public interface TrackAddGroupEvent extends TrackMutateEvent {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the group that was added
|
||||||
|
*
|
||||||
|
* @return the group that was added
|
||||||
|
*/
|
||||||
|
String getGroup();
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,30 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2016 Lucko (Luck) <[email protected]>
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
* of this software and associated documentation files (the "Software"), to deal
|
||||||
|
* in the Software without restriction, including without limitation the rights
|
||||||
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
* copies of the Software, and to permit persons to whom the Software is
|
||||||
|
* furnished to do so, subject to the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be included in all
|
||||||
|
* copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
|
* SOFTWARE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package me.lucko.luckperms.api.event.track.mutate;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Called when a track is cleared
|
||||||
|
*/
|
||||||
|
public interface TrackClearEvent extends TrackMutateEvent {
|
||||||
|
|
||||||
|
}
|
||||||
+23
-16
@@ -20,30 +20,37 @@
|
|||||||
* SOFTWARE.
|
* SOFTWARE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package me.lucko.luckperms.api.event.events;
|
package me.lucko.luckperms.api.event.track.mutate;
|
||||||
|
|
||||||
import me.lucko.luckperms.api.LogEntry;
|
import me.lucko.luckperms.api.Track;
|
||||||
import me.lucko.luckperms.api.event.CancellableEvent;
|
import me.lucko.luckperms.api.event.LuckPermsEvent;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Called before a LogEntry is broadcasted to players only with the notify permission.
|
* Called when a track is changed
|
||||||
* The log entry will still be recorded in the datastore, regardless of the cancellation state of this event.
|
|
||||||
* Cancelling this event only stops the broadcast.
|
|
||||||
*/
|
*/
|
||||||
public class LogNotifyEvent extends CancellableEvent {
|
public interface TrackMutateEvent extends LuckPermsEvent {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The log entry to be broadcasted
|
* Gets the track that was mutated
|
||||||
|
*
|
||||||
|
* @return the track that was mutated
|
||||||
*/
|
*/
|
||||||
private final LogEntry entry;
|
Track getTrack();
|
||||||
|
|
||||||
public LogNotifyEvent(LogEntry entry) {
|
/**
|
||||||
super("Log Notify Event");
|
* Gets an immutable copy of the tracks data before the change
|
||||||
this.entry = entry;
|
*
|
||||||
}
|
* @return the data before the change
|
||||||
|
*/
|
||||||
|
List<String> getDataBefore();
|
||||||
|
|
||||||
public LogEntry getEntry() {
|
/**
|
||||||
return entry;
|
* Gets an immutable copy of the tracks data after the change
|
||||||
}
|
*
|
||||||
|
* @return the data after the change
|
||||||
|
*/
|
||||||
|
List<String> getDataAfter();
|
||||||
|
|
||||||
}
|
}
|
||||||
+37
@@ -0,0 +1,37 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2016 Lucko (Luck) <[email protected]>
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
* of this software and associated documentation files (the "Software"), to deal
|
||||||
|
* in the Software without restriction, including without limitation the rights
|
||||||
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
* copies of the Software, and to permit persons to whom the Software is
|
||||||
|
* furnished to do so, subject to the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be included in all
|
||||||
|
* copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
|
* SOFTWARE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package me.lucko.luckperms.api.event.track.mutate;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Called when a group is removed from a track
|
||||||
|
*/
|
||||||
|
public interface TrackRemoveGroupEvent extends TrackMutateEvent {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the group that was removed
|
||||||
|
*
|
||||||
|
* @return the group that was removed
|
||||||
|
*/
|
||||||
|
String getGroup();
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,48 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2016 Lucko (Luck) <[email protected]>
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
* of this software and associated documentation files (the "Software"), to deal
|
||||||
|
* in the Software without restriction, including without limitation the rights
|
||||||
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
* copies of the Software, and to permit persons to whom the Software is
|
||||||
|
* furnished to do so, subject to the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be included in all
|
||||||
|
* copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
|
* SOFTWARE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package me.lucko.luckperms.api.event.user;
|
||||||
|
|
||||||
|
import me.lucko.luckperms.api.User;
|
||||||
|
import me.lucko.luckperms.api.caching.UserData;
|
||||||
|
import me.lucko.luckperms.api.event.LuckPermsEvent;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Called when a users {@link me.lucko.luckperms.api.caching.UserData} is loaded.
|
||||||
|
*/
|
||||||
|
public interface UserCacheLoadEvent extends LuckPermsEvent {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the user whose data was loaded
|
||||||
|
*
|
||||||
|
* @return the user
|
||||||
|
*/
|
||||||
|
User getUser();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the data that was loaded
|
||||||
|
*
|
||||||
|
* @return the loaded data
|
||||||
|
*/
|
||||||
|
UserData getLoadedData();
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,48 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2016 Lucko (Luck) <[email protected]>
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
* of this software and associated documentation files (the "Software"), to deal
|
||||||
|
* in the Software without restriction, including without limitation the rights
|
||||||
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
* copies of the Software, and to permit persons to whom the Software is
|
||||||
|
* furnished to do so, subject to the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be included in all
|
||||||
|
* copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
|
* SOFTWARE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package me.lucko.luckperms.api.event.user;
|
||||||
|
|
||||||
|
import me.lucko.luckperms.api.User;
|
||||||
|
import me.lucko.luckperms.api.caching.UserData;
|
||||||
|
import me.lucko.luckperms.api.event.LuckPermsEvent;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Called when a users cached data is refreshed
|
||||||
|
*/
|
||||||
|
public interface UserDataRecalculateEvent extends LuckPermsEvent {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the user whose data was recalculated
|
||||||
|
*
|
||||||
|
* @return the user
|
||||||
|
*/
|
||||||
|
User getUser();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the data that was recalculated
|
||||||
|
*
|
||||||
|
* @return the data
|
||||||
|
*/
|
||||||
|
UserData getData();
|
||||||
|
|
||||||
|
}
|
||||||
+22
-20
@@ -20,35 +20,37 @@
|
|||||||
* SOFTWARE.
|
* SOFTWARE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package me.lucko.luckperms.api.event.events;
|
package me.lucko.luckperms.api.event.user;
|
||||||
|
|
||||||
import me.lucko.luckperms.api.event.LPEvent;
|
import me.lucko.luckperms.api.event.LuckPermsEvent;
|
||||||
|
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Called when the user logs into the network for the first time. Particularly useful for networks with multiple
|
* Called when the user logs into the network for the first time.
|
||||||
* lobbies, who want to welcome a user when they join for the first time.
|
*
|
||||||
|
* <p>Particularly useful for networks with multiple
|
||||||
|
* lobbies, who want to welcome a user when they join for the first time.</p>
|
||||||
*
|
*
|
||||||
* <p>This event is fired before the player has actually joined the game on the async login / auth event. If you want to
|
* <p>This event is fired before the player has actually joined the game on the async login / auth event. If you want to
|
||||||
* do something with the user, store the UUID in a set, and then check the set in the PlayerJoinEvent o.e.
|
* do something with the user, store the UUID in a set, and then check the set in the PlayerJoinEvent o.e.</p>
|
||||||
|
*
|
||||||
|
* <p>The users data will not be loaded when this event is called.</p>
|
||||||
*/
|
*/
|
||||||
public class UserFirstLoginEvent extends LPEvent {
|
public interface UserFirstLoginEvent extends LuckPermsEvent {
|
||||||
|
|
||||||
private final UUID uuid;
|
/**
|
||||||
private final String username;
|
* Gets the UUID of the user
|
||||||
|
*
|
||||||
|
* @return the uuid of the user
|
||||||
|
*/
|
||||||
|
UUID getUuid();
|
||||||
|
|
||||||
public UserFirstLoginEvent(UUID uuid, String username) {
|
/**
|
||||||
super("User First Join Event");
|
* Gets the username of the user
|
||||||
this.uuid = uuid;
|
*
|
||||||
this.username = username;
|
* @return the username of the user
|
||||||
}
|
*/
|
||||||
|
String getUsername();
|
||||||
|
|
||||||
public UUID getUuid() {
|
|
||||||
return uuid;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getUsername() {
|
|
||||||
return username;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
+10
-8
@@ -20,19 +20,21 @@
|
|||||||
* SOFTWARE.
|
* SOFTWARE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package me.lucko.luckperms.api.event.events;
|
package me.lucko.luckperms.api.event.user;
|
||||||
|
|
||||||
import me.lucko.luckperms.api.Track;
|
|
||||||
import me.lucko.luckperms.api.User;
|
import me.lucko.luckperms.api.User;
|
||||||
import me.lucko.luckperms.api.event.TrackEvent;
|
import me.lucko.luckperms.api.event.LuckPermsEvent;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Called whenever a user is demoted down a track
|
* Called when a user is loaded into memory from the storage.
|
||||||
*/
|
*/
|
||||||
public class UserDemoteEvent extends TrackEvent {
|
public interface UserLoadEvent extends LuckPermsEvent {
|
||||||
|
|
||||||
public UserDemoteEvent(Track track, User user, String from, String to) {
|
/**
|
||||||
super("User Demote Event", track, user, from, to);
|
* Gets the user that was loaded
|
||||||
}
|
*
|
||||||
|
* @return the user that was loaded
|
||||||
|
*/
|
||||||
|
User getUser();
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,40 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2016 Lucko (Luck) <[email protected]>
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
* of this software and associated documentation files (the "Software"), to deal
|
||||||
|
* in the Software without restriction, including without limitation the rights
|
||||||
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
* copies of the Software, and to permit persons to whom the Software is
|
||||||
|
* furnished to do so, subject to the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be included in all
|
||||||
|
* copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
|
* SOFTWARE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package me.lucko.luckperms.api.event.user.track;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Represents the type of action performed in a {@link UserTrackEvent}
|
||||||
|
*/
|
||||||
|
public enum TrackAction {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The user was promoted up a track
|
||||||
|
*/
|
||||||
|
PROMOTION,
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The user was demoted down a track
|
||||||
|
*/
|
||||||
|
DEMOTION;
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,32 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2016 Lucko (Luck) <[email protected]>
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
* of this software and associated documentation files (the "Software"), to deal
|
||||||
|
* in the Software without restriction, including without limitation the rights
|
||||||
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
* copies of the Software, and to permit persons to whom the Software is
|
||||||
|
* furnished to do so, subject to the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be included in all
|
||||||
|
* copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
|
* SOFTWARE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package me.lucko.luckperms.api.event.user.track;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Called when a user is demoted down a track.
|
||||||
|
*
|
||||||
|
* <p>{@link #getAction()} is always {@link TrackAction#DEMOTION}</p>
|
||||||
|
*/
|
||||||
|
public interface UserDemoteEvent extends UserTrackEvent {
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,32 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2016 Lucko (Luck) <[email protected]>
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
* of this software and associated documentation files (the "Software"), to deal
|
||||||
|
* in the Software without restriction, including without limitation the rights
|
||||||
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
* copies of the Software, and to permit persons to whom the Software is
|
||||||
|
* furnished to do so, subject to the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be included in all
|
||||||
|
* copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
|
* SOFTWARE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package me.lucko.luckperms.api.event.user.track;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Called when a user is promoted up a track.
|
||||||
|
*
|
||||||
|
* <p>{@link #getAction()} is always {@link TrackAction#PROMOTION}</p>
|
||||||
|
*/
|
||||||
|
public interface UserPromoteEvent extends UserTrackEvent {
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,73 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2016 Lucko (Luck) <[email protected]>
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
* of this software and associated documentation files (the "Software"), to deal
|
||||||
|
* in the Software without restriction, including without limitation the rights
|
||||||
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
* copies of the Software, and to permit persons to whom the Software is
|
||||||
|
* furnished to do so, subject to the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be included in all
|
||||||
|
* copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
|
* SOFTWARE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package me.lucko.luckperms.api.event.user.track;
|
||||||
|
|
||||||
|
import me.lucko.luckperms.api.Track;
|
||||||
|
import me.lucko.luckperms.api.User;
|
||||||
|
import me.lucko.luckperms.api.event.LuckPermsEvent;
|
||||||
|
|
||||||
|
import java.util.Optional;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Called when a user interacts with a track through a promotion or demotion
|
||||||
|
*/
|
||||||
|
public interface UserTrackEvent extends LuckPermsEvent {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the track involved in the event
|
||||||
|
*
|
||||||
|
* @return the track involved in the event
|
||||||
|
*/
|
||||||
|
Track getTrack();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the user who was promoted or demoted
|
||||||
|
*
|
||||||
|
* @return the user involved in the event
|
||||||
|
*/
|
||||||
|
User getUser();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the action performed
|
||||||
|
*
|
||||||
|
* @return the action performed
|
||||||
|
*/
|
||||||
|
TrackAction getAction();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the group the user was promoted/demoted from.
|
||||||
|
*
|
||||||
|
* <p>May be {@link Optional#empty()} if the user wasn't already placed on the track.</p>
|
||||||
|
*
|
||||||
|
* @return the group the user was promoted/demoted from
|
||||||
|
*/
|
||||||
|
Optional<String> getGroupFrom();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the group the user was promoted/demoted to
|
||||||
|
*
|
||||||
|
* @return the group the user was promoted/demoted to
|
||||||
|
*/
|
||||||
|
Optional<String> getGroupTo();
|
||||||
|
|
||||||
|
}
|
||||||
+12
-52
@@ -5,19 +5,26 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<artifactId>luckperms</artifactId>
|
<artifactId>luckperms</artifactId>
|
||||||
<groupId>me.lucko.luckperms</groupId>
|
<groupId>me.lucko.luckperms</groupId>
|
||||||
<version>2.16-SNAPSHOT</version>
|
<version>3.0-SNAPSHOT</version>
|
||||||
</parent>
|
</parent>
|
||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
|
||||||
<artifactId>luckperms-bukkit-legacy</artifactId>
|
<artifactId>luckperms-bukkit-legacy</artifactId>
|
||||||
<build>
|
<build>
|
||||||
<defaultGoal>clean package</defaultGoal>
|
<defaultGoal>clean package</defaultGoal>
|
||||||
<finalName>LuckPerms-bukkit-legacy-${release.version}.${git.closest.tag.commit.count}</finalName>
|
<finalName>LuckPerms-Bukkit-Legacy-${release.version}.${patch.version}</finalName>
|
||||||
<resources>
|
<resources>
|
||||||
<resource>
|
<resource>
|
||||||
<directory>src/main/resources</directory>
|
<directory>src/main/resources</directory>
|
||||||
<filtering>true</filtering>
|
<filtering>true</filtering>
|
||||||
</resource>
|
</resource>
|
||||||
|
<resource>
|
||||||
|
<directory>../</directory>
|
||||||
|
<filtering>false</filtering>
|
||||||
|
<includes>
|
||||||
|
<include>LICENSE.txt</include>
|
||||||
|
</includes>
|
||||||
|
</resource>
|
||||||
</resources>
|
</resources>
|
||||||
<plugins>
|
<plugins>
|
||||||
<plugin>
|
<plugin>
|
||||||
@@ -41,32 +48,8 @@
|
|||||||
</goals>
|
</goals>
|
||||||
<configuration>
|
<configuration>
|
||||||
<minimizeJar>false</minimizeJar>
|
<minimizeJar>false</minimizeJar>
|
||||||
<artifactSet>
|
<createDependencyReducedPom>false</createDependencyReducedPom>
|
||||||
<excludes>
|
|
||||||
<exclude>org.xerial:*</exclude>
|
|
||||||
</excludes>
|
|
||||||
</artifactSet>
|
|
||||||
<relocations>
|
<relocations>
|
||||||
<relocation>
|
|
||||||
<pattern>org.slf4j</pattern>
|
|
||||||
<shadedPattern>me.lucko.luckperms.lib.slf4j</shadedPattern>
|
|
||||||
</relocation>
|
|
||||||
<relocation>
|
|
||||||
<pattern>com.zaxxer.hikari</pattern>
|
|
||||||
<shadedPattern>me.lucko.luckperms.lib.hikari</shadedPattern>
|
|
||||||
</relocation>
|
|
||||||
<relocation>
|
|
||||||
<pattern>com.mongodb</pattern>
|
|
||||||
<shadedPattern>me.lucko.luckperms.lib.mongodb</shadedPattern>
|
|
||||||
</relocation>
|
|
||||||
<relocation>
|
|
||||||
<pattern>org.bson</pattern>
|
|
||||||
<shadedPattern>me.lucko.luckperms.lib.bson</shadedPattern>
|
|
||||||
</relocation>
|
|
||||||
<relocation>
|
|
||||||
<pattern>org.h2</pattern>
|
|
||||||
<shadedPattern>me.lucko.luckperms.lib.h2</shadedPattern>
|
|
||||||
</relocation>
|
|
||||||
<relocation>
|
<relocation>
|
||||||
<pattern>com.google.common</pattern>
|
<pattern>com.google.common</pattern>
|
||||||
<shadedPattern>me.lucko.luckperms.lib.guava</shadedPattern>
|
<shadedPattern>me.lucko.luckperms.lib.guava</shadedPattern>
|
||||||
@@ -76,37 +59,14 @@
|
|||||||
<shadedPattern>me.lucko.luckperms.lib.gson</shadedPattern>
|
<shadedPattern>me.lucko.luckperms.lib.gson</shadedPattern>
|
||||||
</relocation>
|
</relocation>
|
||||||
<relocation>
|
<relocation>
|
||||||
<pattern>redis.clients.jedis</pattern>
|
<pattern>io.github.mkremins.fanciful</pattern>
|
||||||
<shadedPattern>me.lucko.luckperms.lib.jedis.jedis</shadedPattern>
|
<shadedPattern>me.lucko.luckperms.lib.fanciful</shadedPattern>
|
||||||
</relocation>
|
|
||||||
<relocation>
|
|
||||||
<pattern>redis.clients.util</pattern>
|
|
||||||
<shadedPattern>me.lucko.luckperms.lib.jedis.util</shadedPattern>
|
|
||||||
</relocation>
|
|
||||||
<relocation>
|
|
||||||
<pattern>org.apache.commons.pool2</pattern>
|
|
||||||
<shadedPattern>me.lucko.luckperms.lib.jedis.pool2</shadedPattern>
|
|
||||||
</relocation>
|
</relocation>
|
||||||
</relocations>
|
</relocations>
|
||||||
</configuration>
|
</configuration>
|
||||||
</execution>
|
</execution>
|
||||||
</executions>
|
</executions>
|
||||||
</plugin>
|
</plugin>
|
||||||
<plugin>
|
|
||||||
<groupId>pl.project13.maven</groupId>
|
|
||||||
<artifactId>git-commit-id-plugin</artifactId>
|
|
||||||
<version>2.2.1</version>
|
|
||||||
<executions>
|
|
||||||
<execution>
|
|
||||||
<goals>
|
|
||||||
<goal>revision</goal>
|
|
||||||
</goals>
|
|
||||||
</execution>
|
|
||||||
</executions>
|
|
||||||
<configuration>
|
|
||||||
<injectAllReactorProjects>true</injectAllReactorProjects>
|
|
||||||
</configuration>
|
|
||||||
</plugin>
|
|
||||||
</plugins>
|
</plugins>
|
||||||
</build>
|
</build>
|
||||||
|
|
||||||
|
|||||||
@@ -5,13 +5,22 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<artifactId>luckperms</artifactId>
|
<artifactId>luckperms</artifactId>
|
||||||
<groupId>me.lucko.luckperms</groupId>
|
<groupId>me.lucko.luckperms</groupId>
|
||||||
<version>2.16-SNAPSHOT</version>
|
<version>3.0-SNAPSHOT</version>
|
||||||
</parent>
|
</parent>
|
||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
|
||||||
<artifactId>luckperms-bukkit-placeholders</artifactId>
|
<artifactId>luckperms-bukkit-placeholders</artifactId>
|
||||||
<build>
|
<build>
|
||||||
<finalName>LuckPermsPlaceholderExpansion</finalName>
|
<finalName>LuckPermsPlaceholderExpansion</finalName>
|
||||||
|
<resources>
|
||||||
|
<resource>
|
||||||
|
<directory>../</directory>
|
||||||
|
<filtering>false</filtering>
|
||||||
|
<includes>
|
||||||
|
<include>LICENSE.txt</include>
|
||||||
|
</includes>
|
||||||
|
</resource>
|
||||||
|
</resources>
|
||||||
<plugins>
|
<plugins>
|
||||||
<plugin>
|
<plugin>
|
||||||
<groupId>org.apache.maven.plugins</groupId>
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
|
|||||||
+28
-54
@@ -5,7 +5,7 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<artifactId>luckperms</artifactId>
|
<artifactId>luckperms</artifactId>
|
||||||
<groupId>me.lucko.luckperms</groupId>
|
<groupId>me.lucko.luckperms</groupId>
|
||||||
<version>2.16-SNAPSHOT</version>
|
<version>3.0-SNAPSHOT</version>
|
||||||
</parent>
|
</parent>
|
||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
|
||||||
@@ -14,13 +14,20 @@
|
|||||||
|
|
||||||
<build>
|
<build>
|
||||||
<defaultGoal>clean package</defaultGoal>
|
<defaultGoal>clean package</defaultGoal>
|
||||||
<finalName>LuckPerms-${release.version}.${git.closest.tag.commit.count}</finalName>
|
<finalName>LuckPerms-Bukkit-${release.version}.${patch.version}</finalName>
|
||||||
<sourceDirectory>${basedir}/src/main/java</sourceDirectory>
|
<sourceDirectory>${basedir}/src/main/java</sourceDirectory>
|
||||||
<resources>
|
<resources>
|
||||||
<resource>
|
<resource>
|
||||||
<directory>src/main/resources</directory>
|
<directory>src/main/resources</directory>
|
||||||
<filtering>true</filtering>
|
<filtering>true</filtering>
|
||||||
</resource>
|
</resource>
|
||||||
|
<resource>
|
||||||
|
<directory>../</directory>
|
||||||
|
<filtering>false</filtering>
|
||||||
|
<includes>
|
||||||
|
<include>LICENSE.txt</include>
|
||||||
|
</includes>
|
||||||
|
</resource>
|
||||||
</resources>
|
</resources>
|
||||||
<plugins>
|
<plugins>
|
||||||
<plugin>
|
<plugin>
|
||||||
@@ -44,72 +51,25 @@
|
|||||||
</goals>
|
</goals>
|
||||||
<configuration>
|
<configuration>
|
||||||
<minimizeJar>false</minimizeJar>
|
<minimizeJar>false</minimizeJar>
|
||||||
<artifactSet>
|
<createDependencyReducedPom>false</createDependencyReducedPom>
|
||||||
<excludes>
|
|
||||||
<exclude>org.xerial:*</exclude>
|
|
||||||
</excludes>
|
|
||||||
</artifactSet>
|
|
||||||
<relocations>
|
<relocations>
|
||||||
<relocation>
|
<relocation>
|
||||||
<pattern>org.slf4j</pattern>
|
<pattern>io.github.mkremins.fanciful</pattern>
|
||||||
<shadedPattern>me.lucko.luckperms.lib.slf4j</shadedPattern>
|
<shadedPattern>me.lucko.luckperms.lib.fanciful</shadedPattern>
|
||||||
</relocation>
|
|
||||||
<relocation>
|
|
||||||
<pattern>com.zaxxer.hikari</pattern>
|
|
||||||
<shadedPattern>me.lucko.luckperms.lib.hikari</shadedPattern>
|
|
||||||
</relocation>
|
|
||||||
<relocation>
|
|
||||||
<pattern>com.mongodb</pattern>
|
|
||||||
<shadedPattern>me.lucko.luckperms.lib.mongodb</shadedPattern>
|
|
||||||
</relocation>
|
|
||||||
<relocation>
|
|
||||||
<pattern>org.bson</pattern>
|
|
||||||
<shadedPattern>me.lucko.luckperms.lib.bson</shadedPattern>
|
|
||||||
</relocation>
|
|
||||||
<relocation>
|
|
||||||
<pattern>org.h2</pattern>
|
|
||||||
<shadedPattern>me.lucko.luckperms.lib.h2</shadedPattern>
|
|
||||||
</relocation>
|
|
||||||
<relocation>
|
|
||||||
<pattern>redis.clients.jedis</pattern>
|
|
||||||
<shadedPattern>me.lucko.luckperms.lib.jedis.jedis</shadedPattern>
|
|
||||||
</relocation>
|
|
||||||
<relocation>
|
|
||||||
<pattern>redis.clients.util</pattern>
|
|
||||||
<shadedPattern>me.lucko.luckperms.lib.jedis.util</shadedPattern>
|
|
||||||
</relocation>
|
|
||||||
<relocation>
|
|
||||||
<pattern>org.apache.commons.pool2</pattern>
|
|
||||||
<shadedPattern>me.lucko.luckperms.lib.jedis.pool2</shadedPattern>
|
|
||||||
</relocation>
|
</relocation>
|
||||||
</relocations>
|
</relocations>
|
||||||
</configuration>
|
</configuration>
|
||||||
</execution>
|
</execution>
|
||||||
</executions>
|
</executions>
|
||||||
</plugin>
|
</plugin>
|
||||||
<plugin>
|
|
||||||
<groupId>pl.project13.maven</groupId>
|
|
||||||
<artifactId>git-commit-id-plugin</artifactId>
|
|
||||||
<version>2.2.1</version>
|
|
||||||
<executions>
|
|
||||||
<execution>
|
|
||||||
<goals>
|
|
||||||
<goal>revision</goal>
|
|
||||||
</goals>
|
|
||||||
</execution>
|
|
||||||
</executions>
|
|
||||||
<configuration>
|
|
||||||
<injectAllReactorProjects>true</injectAllReactorProjects>
|
|
||||||
</configuration>
|
|
||||||
</plugin>
|
|
||||||
</plugins>
|
</plugins>
|
||||||
</build>
|
</build>
|
||||||
|
|
||||||
<dependencies>
|
<dependencies>
|
||||||
<!-- BukkitAPI -->
|
<!-- BukkitAPI -->
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.bukkit</groupId>
|
<groupId>org.spigotmc</groupId>
|
||||||
<artifactId>bukkit</artifactId>
|
<artifactId>spigot-api</artifactId>
|
||||||
<version>1.8.8-R0.1-SNAPSHOT</version>
|
<version>1.8.8-R0.1-SNAPSHOT</version>
|
||||||
<scope>provided</scope>
|
<scope>provided</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
@@ -134,6 +94,20 @@
|
|||||||
<version>${project.version}</version>
|
<version>${project.version}</version>
|
||||||
<scope>compile</scope>
|
<scope>compile</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<!-- LilyPad - used as a messaging service -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>lilypad.client.connect</groupId>
|
||||||
|
<artifactId>api</artifactId>
|
||||||
|
<version>0.0.1-SNAPSHOT</version>
|
||||||
|
<scope>provided</scope>
|
||||||
|
</dependency>
|
||||||
|
<!-- HikariCP - needed as source -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.zaxxer</groupId>
|
||||||
|
<artifactId>HikariCP</artifactId>
|
||||||
|
<version>2.5.1</version>
|
||||||
|
<scope>provided</scope>
|
||||||
|
</dependency>
|
||||||
<!-- Lombok -->
|
<!-- Lombok -->
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.projectlombok</groupId>
|
<groupId>org.projectlombok</groupId>
|
||||||
|
|||||||
@@ -30,7 +30,7 @@ import me.lucko.luckperms.api.Contexts;
|
|||||||
import me.lucko.luckperms.bukkit.calculators.AttachmentProcessor;
|
import me.lucko.luckperms.bukkit.calculators.AttachmentProcessor;
|
||||||
import me.lucko.luckperms.bukkit.calculators.ChildProcessor;
|
import me.lucko.luckperms.bukkit.calculators.ChildProcessor;
|
||||||
import me.lucko.luckperms.bukkit.calculators.DefaultsProcessor;
|
import me.lucko.luckperms.bukkit.calculators.DefaultsProcessor;
|
||||||
import me.lucko.luckperms.bukkit.inject.Injector;
|
import me.lucko.luckperms.bukkit.model.Injector;
|
||||||
import me.lucko.luckperms.bukkit.model.LPPermissible;
|
import me.lucko.luckperms.bukkit.model.LPPermissible;
|
||||||
import me.lucko.luckperms.common.calculators.AbstractCalculatorFactory;
|
import me.lucko.luckperms.common.calculators.AbstractCalculatorFactory;
|
||||||
import me.lucko.luckperms.common.calculators.PermissionCalculator;
|
import me.lucko.luckperms.common.calculators.PermissionCalculator;
|
||||||
@@ -38,6 +38,7 @@ import me.lucko.luckperms.common.calculators.PermissionProcessor;
|
|||||||
import me.lucko.luckperms.common.calculators.processors.MapProcessor;
|
import me.lucko.luckperms.common.calculators.processors.MapProcessor;
|
||||||
import me.lucko.luckperms.common.calculators.processors.RegexProcessor;
|
import me.lucko.luckperms.common.calculators.processors.RegexProcessor;
|
||||||
import me.lucko.luckperms.common.calculators.processors.WildcardProcessor;
|
import me.lucko.luckperms.common.calculators.processors.WildcardProcessor;
|
||||||
|
import me.lucko.luckperms.common.config.ConfigKeys;
|
||||||
import me.lucko.luckperms.common.core.model.User;
|
import me.lucko.luckperms.common.core.model.User;
|
||||||
|
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
@@ -57,12 +58,12 @@ public class BukkitCalculatorFactory extends AbstractCalculatorFactory {
|
|||||||
LPPermissible permissible = Injector.getPermissible(uuid);
|
LPPermissible permissible = Injector.getPermissible(uuid);
|
||||||
return permissible == null ? null : permissible.getAttachmentPermissions();
|
return permissible == null ? null : permissible.getAttachmentPermissions();
|
||||||
}));
|
}));
|
||||||
if (plugin.getConfiguration().isApplyingWildcards()) {
|
if (plugin.getConfiguration().get(ConfigKeys.APPLYING_REGEX)) {
|
||||||
processors.add(new WildcardProcessor());
|
|
||||||
}
|
|
||||||
if (plugin.getConfiguration().isApplyingRegex()) {
|
|
||||||
processors.add(new RegexProcessor());
|
processors.add(new RegexProcessor());
|
||||||
}
|
}
|
||||||
|
if (plugin.getConfiguration().get(ConfigKeys.APPLYING_WILDCARDS)) {
|
||||||
|
processors.add(new WildcardProcessor());
|
||||||
|
}
|
||||||
processors.add(new DefaultsProcessor(contexts.isOp(), plugin.getDefaultsProvider()));
|
processors.add(new DefaultsProcessor(contexts.isOp(), plugin.getDefaultsProvider()));
|
||||||
|
|
||||||
return registerCalculator(new PermissionCalculator(plugin, user.getName(), processors.build()));
|
return registerCalculator(new PermissionCalculator(plugin, user.getName(), processors.build()));
|
||||||
|
|||||||
@@ -37,7 +37,7 @@ import org.bukkit.command.TabExecutor;
|
|||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
class BukkitCommand extends CommandManager implements CommandExecutor, TabExecutor {
|
public class BukkitCommand extends CommandManager implements CommandExecutor, TabExecutor {
|
||||||
private final LPBukkitPlugin plugin;
|
private final LPBukkitPlugin plugin;
|
||||||
|
|
||||||
BukkitCommand(LPBukkitPlugin plugin) {
|
BukkitCommand(LPBukkitPlugin plugin) {
|
||||||
@@ -50,8 +50,7 @@ class BukkitCommand extends CommandManager implements CommandExecutor, TabExecut
|
|||||||
onCommand(
|
onCommand(
|
||||||
plugin.getSenderFactory().wrap(sender),
|
plugin.getSenderFactory().wrap(sender),
|
||||||
label,
|
label,
|
||||||
Util.stripQuotes(Splitter.on(Patterns.COMMAND_SEPARATOR).omitEmptyStrings().splitToList(Joiner.on(' ').join(args))),
|
Util.stripQuotes(Splitter.on(Patterns.COMMAND_SEPARATOR).omitEmptyStrings().splitToList(Joiner.on(' ').join(args)))
|
||||||
null
|
|
||||||
);
|
);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -22,6 +22,9 @@
|
|||||||
|
|
||||||
package me.lucko.luckperms.bukkit;
|
package me.lucko.luckperms.bukkit;
|
||||||
|
|
||||||
|
import lombok.Getter;
|
||||||
|
import lombok.RequiredArgsConstructor;
|
||||||
|
|
||||||
import me.lucko.luckperms.common.config.AbstractConfiguration;
|
import me.lucko.luckperms.common.config.AbstractConfiguration;
|
||||||
|
|
||||||
import org.bukkit.configuration.ConfigurationSection;
|
import org.bukkit.configuration.ConfigurationSection;
|
||||||
@@ -34,48 +37,48 @@ import java.util.Map;
|
|||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
class BukkitConfig extends AbstractConfiguration<LPBukkitPlugin> {
|
@RequiredArgsConstructor
|
||||||
|
public class BukkitConfig extends AbstractConfiguration {
|
||||||
|
|
||||||
|
@Getter
|
||||||
|
private final LPBukkitPlugin plugin;
|
||||||
|
|
||||||
private YamlConfiguration configuration;
|
private YamlConfiguration configuration;
|
||||||
|
|
||||||
BukkitConfig(LPBukkitPlugin plugin) {
|
|
||||||
super(plugin, "global", true, "sqlite");
|
|
||||||
}
|
|
||||||
|
|
||||||
@SuppressWarnings("ResultOfMethodCallIgnored")
|
|
||||||
@Override
|
@Override
|
||||||
protected void init() {
|
public void init() {
|
||||||
File configFile = new File(getPlugin().getDataFolder(), "config.yml");
|
File configFile = new File(plugin.getDataFolder(), "config.yml");
|
||||||
|
|
||||||
if (!configFile.exists()) {
|
if (!configFile.exists()) {
|
||||||
configFile.getParentFile().mkdirs();
|
configFile.getParentFile().mkdirs();
|
||||||
getPlugin().saveResource("config.yml", false);
|
plugin.saveResource("config.yml", false);
|
||||||
}
|
}
|
||||||
|
|
||||||
configuration = YamlConfiguration.loadConfiguration(configFile);
|
configuration = YamlConfiguration.loadConfiguration(configFile);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected String getString(String path, String def) {
|
public String getString(String path, String def) {
|
||||||
return configuration.getString(path, def);
|
return configuration.getString(path, def);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected int getInt(String path, int def) {
|
public int getInt(String path, int def) {
|
||||||
return configuration.getInt(path, def);
|
return configuration.getInt(path, def);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected boolean getBoolean(String path, boolean def) {
|
public boolean getBoolean(String path, boolean def) {
|
||||||
return configuration.getBoolean(path, def);
|
return configuration.getBoolean(path, def);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected List<String> getList(String path, List<String> def) {
|
public List<String> getList(String path, List<String> def) {
|
||||||
return Optional.ofNullable(configuration.getStringList(path)).orElse(def);
|
return Optional.ofNullable(configuration.getStringList(path)).orElse(def);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected List<String> getObjectList(String path, List<String> def) {
|
public List<String> getObjectList(String path, List<String> def) {
|
||||||
ConfigurationSection section = configuration.getConfigurationSection(path);
|
ConfigurationSection section = configuration.getConfigurationSection(path);
|
||||||
if (section == null) {
|
if (section == null) {
|
||||||
return def;
|
return def;
|
||||||
@@ -84,9 +87,8 @@ class BukkitConfig extends AbstractConfiguration<LPBukkitPlugin> {
|
|||||||
return Optional.ofNullable(section.getKeys(false).stream().collect(Collectors.toList())).orElse(def);
|
return Optional.ofNullable(section.getKeys(false).stream().collect(Collectors.toList())).orElse(def);
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
|
||||||
@Override
|
@Override
|
||||||
protected Map<String, String> getMap(String path, Map<String, String> def) {
|
public Map<String, String> getMap(String path, Map<String, String> def) {
|
||||||
Map<String, String> map = new HashMap<>();
|
Map<String, String> map = new HashMap<>();
|
||||||
ConfigurationSection section = configuration.getConfigurationSection(path);
|
ConfigurationSection section = configuration.getConfigurationSection(path);
|
||||||
if (section == null) {
|
if (section == null) {
|
||||||
|
|||||||
@@ -22,8 +22,9 @@
|
|||||||
|
|
||||||
package me.lucko.luckperms.bukkit;
|
package me.lucko.luckperms.bukkit;
|
||||||
|
|
||||||
import me.lucko.luckperms.bukkit.inject.Injector;
|
import me.lucko.luckperms.bukkit.model.Injector;
|
||||||
import me.lucko.luckperms.bukkit.model.LPPermissible;
|
import me.lucko.luckperms.bukkit.model.LPPermissible;
|
||||||
|
import me.lucko.luckperms.common.config.ConfigKeys;
|
||||||
import me.lucko.luckperms.common.constants.Message;
|
import me.lucko.luckperms.common.constants.Message;
|
||||||
import me.lucko.luckperms.common.core.model.User;
|
import me.lucko.luckperms.common.core.model.User;
|
||||||
import me.lucko.luckperms.common.utils.AbstractListener;
|
import me.lucko.luckperms.common.utils.AbstractListener;
|
||||||
@@ -33,15 +34,21 @@ import org.bukkit.event.EventHandler;
|
|||||||
import org.bukkit.event.EventPriority;
|
import org.bukkit.event.EventPriority;
|
||||||
import org.bukkit.event.Listener;
|
import org.bukkit.event.Listener;
|
||||||
import org.bukkit.event.player.AsyncPlayerPreLoginEvent;
|
import org.bukkit.event.player.AsyncPlayerPreLoginEvent;
|
||||||
|
import org.bukkit.event.player.PlayerChangedWorldEvent;
|
||||||
import org.bukkit.event.player.PlayerCommandPreprocessEvent;
|
import org.bukkit.event.player.PlayerCommandPreprocessEvent;
|
||||||
import org.bukkit.event.player.PlayerLoginEvent;
|
import org.bukkit.event.player.PlayerLoginEvent;
|
||||||
import org.bukkit.event.player.PlayerQuitEvent;
|
import org.bukkit.event.player.PlayerQuitEvent;
|
||||||
import org.bukkit.event.server.PluginEnableEvent;
|
import org.bukkit.event.server.PluginEnableEvent;
|
||||||
|
|
||||||
|
import java.util.Collections;
|
||||||
|
import java.util.HashSet;
|
||||||
|
import java.util.Set;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
class BukkitListener extends AbstractListener implements Listener {
|
class BukkitListener extends AbstractListener implements Listener {
|
||||||
private final LPBukkitPlugin plugin;
|
private final LPBukkitPlugin plugin;
|
||||||
|
private final Set<UUID> deniedAsyncLogin = Collections.synchronizedSet(new HashSet<>());
|
||||||
|
private final Set<UUID> deniedLogin = new HashSet<>();
|
||||||
|
|
||||||
BukkitListener(LPBukkitPlugin plugin) {
|
BukkitListener(LPBukkitPlugin plugin) {
|
||||||
super(plugin);
|
super(plugin);
|
||||||
@@ -50,7 +57,13 @@ class BukkitListener extends AbstractListener implements Listener {
|
|||||||
|
|
||||||
@EventHandler(priority = EventPriority.LOW)
|
@EventHandler(priority = EventPriority.LOW)
|
||||||
public void onPlayerPreLogin(AsyncPlayerPreLoginEvent e) {
|
public void onPlayerPreLogin(AsyncPlayerPreLoginEvent e) {
|
||||||
|
if (e.getLoginResult() != AsyncPlayerPreLoginEvent.Result.ALLOWED) {
|
||||||
|
deniedAsyncLogin.add(e.getUniqueId());
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (!plugin.isStarted() || !plugin.getStorage().isAcceptingLogins()) {
|
if (!plugin.isStarted() || !plugin.getStorage().isAcceptingLogins()) {
|
||||||
|
deniedAsyncLogin.add(e.getUniqueId());
|
||||||
|
|
||||||
// The datastore is disabled, prevent players from joining the server
|
// The datastore is disabled, prevent players from joining the server
|
||||||
e.disallow(AsyncPlayerPreLoginEvent.Result.KICK_OTHER, Message.LOADING_ERROR.toString());
|
e.disallow(AsyncPlayerPreLoginEvent.Result.KICK_OTHER, Message.LOADING_ERROR.toString());
|
||||||
@@ -63,6 +76,11 @@ class BukkitListener extends AbstractListener implements Listener {
|
|||||||
|
|
||||||
@EventHandler(priority = EventPriority.MONITOR)
|
@EventHandler(priority = EventPriority.MONITOR)
|
||||||
public void onPlayerPreLoginMonitor(AsyncPlayerPreLoginEvent e) {
|
public void onPlayerPreLoginMonitor(AsyncPlayerPreLoginEvent e) {
|
||||||
|
// If they were denied before/at LOW, then don't bother handling here.
|
||||||
|
if (deniedAsyncLogin.remove(e.getUniqueId())) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (plugin.isStarted() && plugin.getStorage().isAcceptingLogins() && e.getLoginResult() != AsyncPlayerPreLoginEvent.Result.ALLOWED) {
|
if (plugin.isStarted() && plugin.getStorage().isAcceptingLogins() && e.getLoginResult() != AsyncPlayerPreLoginEvent.Result.ALLOWED) {
|
||||||
|
|
||||||
// Login event was cancelled by another plugin
|
// Login event was cancelled by another plugin
|
||||||
@@ -70,12 +88,19 @@ class BukkitListener extends AbstractListener implements Listener {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler(priority = EventPriority.LOWEST)
|
@EventHandler(priority = EventPriority.LOW)
|
||||||
public void onPlayerLogin(PlayerLoginEvent e) {
|
public void onPlayerLogin(PlayerLoginEvent e) {
|
||||||
|
if (e.getResult() != PlayerLoginEvent.Result.ALLOWED) {
|
||||||
|
deniedLogin.add(e.getPlayer().getUniqueId());
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
final Player player = e.getPlayer();
|
final Player player = e.getPlayer();
|
||||||
final User user = plugin.getUserManager().get(plugin.getUuidCache().getUUID(player.getUniqueId()));
|
final User user = plugin.getUserManager().get(plugin.getUuidCache().getUUID(player.getUniqueId()));
|
||||||
|
|
||||||
if (user == null) {
|
if (user == null) {
|
||||||
|
deniedLogin.add(e.getPlayer().getUniqueId());
|
||||||
|
|
||||||
// User wasn't loaded for whatever reason.
|
// User wasn't loaded for whatever reason.
|
||||||
e.disallow(PlayerLoginEvent.Result.KICK_OTHER, Message.LOADING_ERROR.toString());
|
e.disallow(PlayerLoginEvent.Result.KICK_OTHER, Message.LOADING_ERROR.toString());
|
||||||
return;
|
return;
|
||||||
@@ -92,6 +117,8 @@ class BukkitListener extends AbstractListener implements Listener {
|
|||||||
t.printStackTrace();
|
t.printStackTrace();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
plugin.refreshAutoOp(player);
|
||||||
|
|
||||||
if (player.isOp()) {
|
if (player.isOp()) {
|
||||||
|
|
||||||
// We assume all users are not op, but those who are need extra calculation.
|
// We assume all users are not op, but those who are need extra calculation.
|
||||||
@@ -103,24 +130,27 @@ class BukkitListener extends AbstractListener implements Listener {
|
|||||||
public void onPlayerLoginMonitor(PlayerLoginEvent e) {
|
public void onPlayerLoginMonitor(PlayerLoginEvent e) {
|
||||||
if (e.getResult() != PlayerLoginEvent.Result.ALLOWED) {
|
if (e.getResult() != PlayerLoginEvent.Result.ALLOWED) {
|
||||||
|
|
||||||
|
// If they were denied before/at LOW, then don't bother handling here.
|
||||||
|
if (deniedLogin.remove(e.getPlayer().getUniqueId())) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
// The player got denied on sync login.
|
// The player got denied on sync login.
|
||||||
onLeave(e.getPlayer().getUniqueId());
|
plugin.getServer().getScheduler().runTaskLater(plugin, () -> onLeave(e.getPlayer().getUniqueId()), 20L);
|
||||||
|
} else {
|
||||||
|
plugin.refreshAutoOp(e.getPlayer());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler(priority = EventPriority.MONITOR) // Allow other plugins to see data when this event gets called.
|
@EventHandler(priority = EventPriority.MONITOR) // Allow other plugins to see data when this event gets called.
|
||||||
public void onPlayerQuit(PlayerQuitEvent e) {
|
public void onPlayerQuit(PlayerQuitEvent e) {
|
||||||
final Player player = e.getPlayer();
|
final Player player = e.getPlayer();
|
||||||
final UUID internal = plugin.getUuidCache().getUUID(player.getUniqueId());
|
|
||||||
|
|
||||||
// Remove from World cache
|
|
||||||
plugin.getWorldCalculator().getWorldCache().remove(internal);
|
|
||||||
|
|
||||||
// Remove the custom permissible
|
// Remove the custom permissible
|
||||||
Injector.unInject(player);
|
Injector.unInject(player, true, true);
|
||||||
|
|
||||||
// Handle auto op
|
// Handle auto op
|
||||||
if (plugin.getConfiguration().isAutoOp()) {
|
if (plugin.getConfiguration().get(ConfigKeys.AUTO_OP)) {
|
||||||
player.setOp(false);
|
player.setOp(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -130,7 +160,7 @@ class BukkitListener extends AbstractListener implements Listener {
|
|||||||
|
|
||||||
@EventHandler
|
@EventHandler
|
||||||
public void onPlayerCommand(PlayerCommandPreprocessEvent e) {
|
public void onPlayerCommand(PlayerCommandPreprocessEvent e) {
|
||||||
if (plugin.getConfiguration().isOpsEnabled()) {
|
if (plugin.getConfiguration().get(ConfigKeys.OPS_ENABLED)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -140,7 +170,7 @@ class BukkitListener extends AbstractListener implements Listener {
|
|||||||
.replace("spigot:", "")
|
.replace("spigot:", "")
|
||||||
.replace("minecraft:", "");
|
.replace("minecraft:", "");
|
||||||
|
|
||||||
if (s.startsWith("op") || s.startsWith("deop")) {
|
if (s.equals("op") || s.startsWith("op ") || s.equals("deop") || s.startsWith("deop ")) {
|
||||||
e.setCancelled(true);
|
e.setCancelled(true);
|
||||||
e.getPlayer().sendMessage(Message.OP_DISABLED.toString());
|
e.getPlayer().sendMessage(Message.OP_DISABLED.toString());
|
||||||
}
|
}
|
||||||
@@ -152,4 +182,9 @@ class BukkitListener extends AbstractListener implements Listener {
|
|||||||
plugin.tryVaultHook(true);
|
plugin.tryVaultHook(true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@EventHandler
|
||||||
|
public void onWorldChange(PlayerChangedWorldEvent e) {
|
||||||
|
plugin.refreshAutoOp(e.getPlayer());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -22,18 +22,24 @@
|
|||||||
|
|
||||||
package me.lucko.luckperms.bukkit;
|
package me.lucko.luckperms.bukkit;
|
||||||
|
|
||||||
import me.lucko.luckperms.common.LuckPermsPlugin;
|
import me.lucko.luckperms.bukkit.compat.MessageHandler;
|
||||||
import me.lucko.luckperms.common.commands.sender.SenderFactory;
|
import me.lucko.luckperms.common.commands.sender.SenderFactory;
|
||||||
import me.lucko.luckperms.common.constants.Constants;
|
import me.lucko.luckperms.common.constants.Constants;
|
||||||
|
import me.lucko.luckperms.common.plugin.LuckPermsPlugin;
|
||||||
|
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
|
import io.github.mkremins.fanciful.FancyMessage;
|
||||||
|
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
public class BukkitSenderFactory extends SenderFactory<CommandSender> {
|
public class BukkitSenderFactory extends SenderFactory<CommandSender> {
|
||||||
|
private final MessageHandler messageHandler;
|
||||||
|
|
||||||
public BukkitSenderFactory(LuckPermsPlugin plugin) {
|
public BukkitSenderFactory(LuckPermsPlugin plugin) {
|
||||||
super(plugin);
|
super(plugin);
|
||||||
|
messageHandler = new MessageHandler();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -41,7 +47,7 @@ public class BukkitSenderFactory extends SenderFactory<CommandSender> {
|
|||||||
if (sender instanceof Player) {
|
if (sender instanceof Player) {
|
||||||
return sender.getName();
|
return sender.getName();
|
||||||
}
|
}
|
||||||
return Constants.getConsoleName();
|
return Constants.CONSOLE_NAME;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -49,7 +55,7 @@ public class BukkitSenderFactory extends SenderFactory<CommandSender> {
|
|||||||
if (sender instanceof Player) {
|
if (sender instanceof Player) {
|
||||||
return ((Player) sender).getUniqueId();
|
return ((Player) sender).getUniqueId();
|
||||||
}
|
}
|
||||||
return Constants.getConsoleUUID();
|
return Constants.CONSOLE_UUID;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -57,6 +63,11 @@ public class BukkitSenderFactory extends SenderFactory<CommandSender> {
|
|||||||
sender.sendMessage(s);
|
sender.sendMessage(s);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void sendMessage(CommandSender sender, FancyMessage message) {
|
||||||
|
messageHandler.sendJsonMessage(sender, message);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected boolean hasPermission(CommandSender sender, String node) {
|
protected boolean hasPermission(CommandSender sender, String node) {
|
||||||
return sender.hasPermission(node);
|
return sender.hasPermission(node);
|
||||||
|
|||||||
@@ -24,89 +24,99 @@ package me.lucko.luckperms.bukkit;
|
|||||||
|
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
|
|
||||||
import com.google.common.collect.ImmutableMap;
|
|
||||||
|
|
||||||
import me.lucko.luckperms.ApiHandler;
|
|
||||||
import me.lucko.luckperms.api.Contexts;
|
import me.lucko.luckperms.api.Contexts;
|
||||||
import me.lucko.luckperms.api.Logger;
|
import me.lucko.luckperms.api.Logger;
|
||||||
import me.lucko.luckperms.api.LuckPermsApi;
|
import me.lucko.luckperms.api.LuckPermsApi;
|
||||||
import me.lucko.luckperms.api.PlatformType;
|
import me.lucko.luckperms.api.PlatformType;
|
||||||
import me.lucko.luckperms.api.context.ContextSet;
|
import me.lucko.luckperms.api.context.ContextSet;
|
||||||
import me.lucko.luckperms.api.context.MutableContextSet;
|
import me.lucko.luckperms.api.context.MutableContextSet;
|
||||||
import me.lucko.luckperms.bukkit.calculators.AutoOPListener;
|
import me.lucko.luckperms.bukkit.messaging.BungeeMessagingService;
|
||||||
|
import me.lucko.luckperms.bukkit.messaging.LilyPadMessagingService;
|
||||||
import me.lucko.luckperms.bukkit.model.ChildPermissionProvider;
|
import me.lucko.luckperms.bukkit.model.ChildPermissionProvider;
|
||||||
import me.lucko.luckperms.bukkit.model.DefaultsProvider;
|
import me.lucko.luckperms.bukkit.model.DefaultsProvider;
|
||||||
|
import me.lucko.luckperms.bukkit.model.Injector;
|
||||||
|
import me.lucko.luckperms.bukkit.model.LPPermissible;
|
||||||
import me.lucko.luckperms.bukkit.vault.VaultHook;
|
import me.lucko.luckperms.bukkit.vault.VaultHook;
|
||||||
import me.lucko.luckperms.common.LuckPermsPlugin;
|
import me.lucko.luckperms.common.api.ApiHandler;
|
||||||
import me.lucko.luckperms.common.api.ApiProvider;
|
import me.lucko.luckperms.common.api.ApiProvider;
|
||||||
|
import me.lucko.luckperms.common.caching.handlers.CachedStateManager;
|
||||||
import me.lucko.luckperms.common.calculators.CalculatorFactory;
|
import me.lucko.luckperms.common.calculators.CalculatorFactory;
|
||||||
import me.lucko.luckperms.common.commands.ConsecutiveExecutor;
|
|
||||||
import me.lucko.luckperms.common.commands.sender.Sender;
|
import me.lucko.luckperms.common.commands.sender.Sender;
|
||||||
import me.lucko.luckperms.common.config.LPConfiguration;
|
import me.lucko.luckperms.common.config.ConfigKeys;
|
||||||
|
import me.lucko.luckperms.common.config.LuckPermsConfiguration;
|
||||||
import me.lucko.luckperms.common.constants.Permission;
|
import me.lucko.luckperms.common.constants.Permission;
|
||||||
import me.lucko.luckperms.common.contexts.ContextManager;
|
import me.lucko.luckperms.common.contexts.ContextManager;
|
||||||
import me.lucko.luckperms.common.contexts.ServerCalculator;
|
import me.lucko.luckperms.common.contexts.ServerCalculator;
|
||||||
import me.lucko.luckperms.common.core.UuidCache;
|
import me.lucko.luckperms.common.core.UuidCache;
|
||||||
import me.lucko.luckperms.common.core.model.User;
|
import me.lucko.luckperms.common.core.model.User;
|
||||||
import me.lucko.luckperms.common.data.Importer;
|
import me.lucko.luckperms.common.data.Importer;
|
||||||
|
import me.lucko.luckperms.common.debug.DebugHandler;
|
||||||
|
import me.lucko.luckperms.common.dependencies.DependencyManager;
|
||||||
|
import me.lucko.luckperms.common.locale.LocaleManager;
|
||||||
|
import me.lucko.luckperms.common.locale.NoopLocaleManager;
|
||||||
|
import me.lucko.luckperms.common.locale.SimpleLocaleManager;
|
||||||
import me.lucko.luckperms.common.managers.GroupManager;
|
import me.lucko.luckperms.common.managers.GroupManager;
|
||||||
import me.lucko.luckperms.common.managers.TrackManager;
|
import me.lucko.luckperms.common.managers.TrackManager;
|
||||||
import me.lucko.luckperms.common.managers.UserManager;
|
import me.lucko.luckperms.common.managers.UserManager;
|
||||||
import me.lucko.luckperms.common.managers.impl.GenericGroupManager;
|
import me.lucko.luckperms.common.managers.impl.GenericGroupManager;
|
||||||
import me.lucko.luckperms.common.managers.impl.GenericTrackManager;
|
import me.lucko.luckperms.common.managers.impl.GenericTrackManager;
|
||||||
import me.lucko.luckperms.common.managers.impl.GenericUserManager;
|
import me.lucko.luckperms.common.managers.impl.GenericUserManager;
|
||||||
|
import me.lucko.luckperms.common.messaging.InternalMessagingService;
|
||||||
import me.lucko.luckperms.common.messaging.RedisMessaging;
|
import me.lucko.luckperms.common.messaging.RedisMessaging;
|
||||||
|
import me.lucko.luckperms.common.plugin.LuckPermsPlugin;
|
||||||
import me.lucko.luckperms.common.storage.Storage;
|
import me.lucko.luckperms.common.storage.Storage;
|
||||||
import me.lucko.luckperms.common.storage.StorageFactory;
|
import me.lucko.luckperms.common.storage.StorageFactory;
|
||||||
|
import me.lucko.luckperms.common.storage.StorageType;
|
||||||
|
import me.lucko.luckperms.common.tasks.CacheHousekeepingTask;
|
||||||
import me.lucko.luckperms.common.tasks.ExpireTemporaryTask;
|
import me.lucko.luckperms.common.tasks.ExpireTemporaryTask;
|
||||||
import me.lucko.luckperms.common.tasks.UpdateTask;
|
import me.lucko.luckperms.common.tasks.UpdateTask;
|
||||||
|
import me.lucko.luckperms.common.treeview.PermissionVault;
|
||||||
import me.lucko.luckperms.common.utils.BufferedRequest;
|
import me.lucko.luckperms.common.utils.BufferedRequest;
|
||||||
import me.lucko.luckperms.common.utils.DebugHandler;
|
import me.lucko.luckperms.common.utils.LoggerImpl;
|
||||||
import me.lucko.luckperms.common.utils.LocaleManager;
|
|
||||||
import me.lucko.luckperms.common.utils.LogFactory;
|
|
||||||
import me.lucko.luckperms.common.utils.PermissionCache;
|
|
||||||
|
|
||||||
import org.bukkit.World;
|
import org.bukkit.World;
|
||||||
import org.bukkit.command.PluginCommand;
|
import org.bukkit.command.PluginCommand;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
import org.bukkit.event.HandlerList;
|
||||||
import org.bukkit.permissions.PermissionDefault;
|
import org.bukkit.permissions.PermissionDefault;
|
||||||
import org.bukkit.plugin.PluginManager;
|
import org.bukkit.plugin.PluginManager;
|
||||||
import org.bukkit.plugin.ServicePriority;
|
import org.bukkit.plugin.ServicePriority;
|
||||||
import org.bukkit.plugin.java.JavaPlugin;
|
import org.bukkit.plugin.java.JavaPlugin;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
|
import java.io.InputStream;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.LinkedHashMap;
|
import java.util.LinkedHashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
import java.util.Optional;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
import java.util.concurrent.ConcurrentHashMap;
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
import java.util.concurrent.Executor;
|
|
||||||
import java.util.concurrent.Executors;
|
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
@Getter
|
@Getter
|
||||||
public class LPBukkitPlugin extends JavaPlugin implements LuckPermsPlugin {
|
public class LPBukkitPlugin extends JavaPlugin implements LuckPermsPlugin {
|
||||||
private final Set<UUID> ignoringLogs = ConcurrentHashMap.newKeySet();
|
private Set<UUID> ignoringLogs;
|
||||||
private Executor syncExecutor;
|
private LPBukkitScheduler scheduler;
|
||||||
private Executor asyncExecutor;
|
private BukkitCommand commandManager;
|
||||||
private VaultHook vaultHook = null;
|
private VaultHook vaultHook = null;
|
||||||
private LPConfiguration configuration;
|
private LuckPermsConfiguration configuration;
|
||||||
private UserManager userManager;
|
private UserManager userManager;
|
||||||
private GroupManager groupManager;
|
private GroupManager groupManager;
|
||||||
private TrackManager trackManager;
|
private TrackManager trackManager;
|
||||||
private Storage storage;
|
private Storage storage;
|
||||||
private RedisMessaging redisMessaging = null;
|
private InternalMessagingService messagingService = null;
|
||||||
private UuidCache uuidCache;
|
private UuidCache uuidCache;
|
||||||
|
private BukkitListener listener;
|
||||||
private ApiProvider apiProvider;
|
private ApiProvider apiProvider;
|
||||||
private Logger log;
|
private Logger log;
|
||||||
private Importer importer;
|
private Importer importer;
|
||||||
private ConsecutiveExecutor consecutiveExecutor;
|
|
||||||
private DefaultsProvider defaultsProvider;
|
private DefaultsProvider defaultsProvider;
|
||||||
private ChildPermissionProvider childPermissionProvider;
|
private ChildPermissionProvider childPermissionProvider;
|
||||||
private LocaleManager localeManager;
|
private LocaleManager localeManager;
|
||||||
|
private CachedStateManager cachedStateManager;
|
||||||
private ContextManager<Player> contextManager;
|
private ContextManager<Player> contextManager;
|
||||||
private WorldCalculator worldCalculator;
|
private WorldCalculator worldCalculator;
|
||||||
private CalculatorFactory calculatorFactory;
|
private CalculatorFactory calculatorFactory;
|
||||||
@@ -114,70 +124,92 @@ public class LPBukkitPlugin extends JavaPlugin implements LuckPermsPlugin {
|
|||||||
private boolean started = false;
|
private boolean started = false;
|
||||||
private DebugHandler debugHandler;
|
private DebugHandler debugHandler;
|
||||||
private BukkitSenderFactory senderFactory;
|
private BukkitSenderFactory senderFactory;
|
||||||
private PermissionCache permissionCache;
|
private PermissionVault permissionVault;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onEnable() {
|
public void onEnable() {
|
||||||
// Used whilst the server is still starting
|
scheduler = new LPBukkitScheduler(this);
|
||||||
asyncExecutor = Executors.newCachedThreadPool();
|
|
||||||
syncExecutor = r -> getServer().getScheduler().runTask(this, r);
|
|
||||||
Executor bukkitAsyncExecutor = r -> getServer().getScheduler().runTaskAsynchronously(this, r);
|
|
||||||
|
|
||||||
log = LogFactory.wrap(getLogger());
|
localeManager = new NoopLocaleManager();
|
||||||
debugHandler = new DebugHandler(bukkitAsyncExecutor);
|
|
||||||
senderFactory = new BukkitSenderFactory(this);
|
senderFactory = new BukkitSenderFactory(this);
|
||||||
permissionCache = new PermissionCache(bukkitAsyncExecutor);
|
log = new LoggerImpl(getConsoleSender());
|
||||||
|
LuckPermsPlugin.sendStartupBanner(getConsoleSender(), this);
|
||||||
|
|
||||||
|
ignoringLogs = ConcurrentHashMap.newKeySet();
|
||||||
|
debugHandler = new DebugHandler(scheduler.getAsyncBukkitExecutor(), getVersion());
|
||||||
|
permissionVault = new PermissionVault(scheduler.getAsyncBukkitExecutor());
|
||||||
|
|
||||||
getLog().info("Loading configuration...");
|
getLog().info("Loading configuration...");
|
||||||
configuration = new BukkitConfig(this);
|
configuration = new BukkitConfig(this);
|
||||||
|
configuration.init();
|
||||||
|
configuration.loadAll();
|
||||||
|
|
||||||
|
Set<StorageType> storageTypes = StorageFactory.getRequiredTypes(this, StorageType.H2);
|
||||||
|
DependencyManager.loadDependencies(this, storageTypes);
|
||||||
|
|
||||||
// setup the Bukkit defaults hook
|
// setup the Bukkit defaults hook
|
||||||
defaultsProvider = new DefaultsProvider();
|
defaultsProvider = new DefaultsProvider();
|
||||||
childPermissionProvider = new ChildPermissionProvider();
|
childPermissionProvider = new ChildPermissionProvider();
|
||||||
|
|
||||||
// give all plugins a chance to load their defaults, then refresh.
|
// give all plugins a chance to load their permissions, then refresh.
|
||||||
getServer().getScheduler().runTaskLater(this, () -> {
|
scheduler.doSyncLater(() -> {
|
||||||
defaultsProvider.refresh();
|
defaultsProvider.refresh();
|
||||||
childPermissionProvider.setup();
|
childPermissionProvider.setup();
|
||||||
|
|
||||||
getServer().getScheduler().runTaskAsynchronously(this, () -> {
|
Set<String> perms = new HashSet<>();
|
||||||
for (Map.Entry<String, Boolean> e : defaultsProvider.getOpDefaults().entrySet()) {
|
getServer().getPluginManager().getPermissions().forEach(p -> {
|
||||||
permissionCache.offer(e.getKey());
|
perms.add(p.getName());
|
||||||
}
|
perms.addAll(p.getChildren().keySet());
|
||||||
|
|
||||||
for (Map.Entry<String, Boolean> e : defaultsProvider.getNonOpDefaults().entrySet()) {
|
|
||||||
permissionCache.offer(e.getKey());
|
|
||||||
}
|
|
||||||
|
|
||||||
ImmutableMap<Map.Entry<String, Boolean>, ImmutableMap<String, Boolean>> permissions = childPermissionProvider.getPermissions();
|
|
||||||
for (Map.Entry<Map.Entry<String, Boolean>, ImmutableMap<String, Boolean>> e : permissions.entrySet()) {
|
|
||||||
permissionCache.offer(e.getKey().getKey());
|
|
||||||
for (Map.Entry<String, Boolean> e1 : e.getValue().entrySet()) {
|
|
||||||
permissionCache.offer(e1.getKey());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
perms.forEach(p -> permissionVault.offer(p));
|
||||||
}, 1L);
|
}, 1L);
|
||||||
|
|
||||||
// register events
|
// register events
|
||||||
PluginManager pm = getServer().getPluginManager();
|
PluginManager pm = getServer().getPluginManager();
|
||||||
pm.registerEvents(new BukkitListener(this), this);
|
listener = new BukkitListener(this);
|
||||||
|
pm.registerEvents(listener, this);
|
||||||
|
|
||||||
// initialise datastore
|
// initialise datastore
|
||||||
storage = StorageFactory.getInstance(this, "h2");
|
storage = StorageFactory.getInstance(this, StorageType.H2);
|
||||||
|
|
||||||
// initialise redis
|
// initialise messaging
|
||||||
if (getConfiguration().isRedisEnabled()) {
|
String messagingType = getConfiguration().get(ConfigKeys.MESSAGING_SERVICE).toLowerCase();
|
||||||
|
if (messagingType.equals("none") && getConfiguration().get(ConfigKeys.REDIS_ENABLED)) {
|
||||||
|
messagingType = "redis";
|
||||||
|
}
|
||||||
|
if (messagingType.equals("redis")) {
|
||||||
getLog().info("Loading redis...");
|
getLog().info("Loading redis...");
|
||||||
redisMessaging = new RedisMessaging(this);
|
if (getConfiguration().get(ConfigKeys.REDIS_ENABLED)) {
|
||||||
try {
|
RedisMessaging redis = new RedisMessaging(this);
|
||||||
redisMessaging.init(getConfiguration().getRedisAddress(), getConfiguration().getRedisPassword());
|
try {
|
||||||
getLog().info("Loaded redis successfully...");
|
redis.init(getConfiguration().get(ConfigKeys.REDIS_ADDRESS), getConfiguration().get(ConfigKeys.REDIS_PASSWORD));
|
||||||
} catch (Exception e) {
|
getLog().info("Loaded redis successfully...");
|
||||||
getLog().info("Couldn't load redis...");
|
|
||||||
e.printStackTrace();
|
messagingService = redis;
|
||||||
|
} catch (Exception e) {
|
||||||
|
getLog().warn("Couldn't load redis...");
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
getLog().warn("Messaging Service was set to redis, but redis is not enabled!");
|
||||||
}
|
}
|
||||||
|
} else if (messagingType.equals("bungee")) {
|
||||||
|
getLog().info("Loading bungee messaging service...");
|
||||||
|
BungeeMessagingService bungeeMessaging = new BungeeMessagingService(this);
|
||||||
|
bungeeMessaging.init();
|
||||||
|
messagingService = bungeeMessaging;
|
||||||
|
} else if (messagingType.equals("lilypad")) {
|
||||||
|
getLog().info("Loading LilyPad messaging service...");
|
||||||
|
if (getServer().getPluginManager().getPlugin("LilyPad-Connect") == null) {
|
||||||
|
getLog().warn("LilyPad-Connect plugin not present.");
|
||||||
|
} else {
|
||||||
|
LilyPadMessagingService lilyPadMessaging = new LilyPadMessagingService(this);
|
||||||
|
lilyPadMessaging.init();
|
||||||
|
messagingService = lilyPadMessaging;
|
||||||
|
}
|
||||||
|
} else if (!messagingType.equals("none")) {
|
||||||
|
getLog().warn("Messaging service '" + messagingType + "' not recognised.");
|
||||||
}
|
}
|
||||||
|
|
||||||
// setup the update task buffer
|
// setup the update task buffer
|
||||||
@@ -190,7 +222,7 @@ public class LPBukkitPlugin extends JavaPlugin implements LuckPermsPlugin {
|
|||||||
};
|
};
|
||||||
|
|
||||||
// load locale
|
// load locale
|
||||||
localeManager = new LocaleManager();
|
localeManager = new SimpleLocaleManager();
|
||||||
File locale = new File(getDataFolder(), "lang.yml");
|
File locale = new File(getDataFolder(), "lang.yml");
|
||||||
if (locale.exists()) {
|
if (locale.exists()) {
|
||||||
getLog().info("Found locale file. Attempting to load from it.");
|
getLog().info("Found locale file. Attempting to load from it.");
|
||||||
@@ -203,32 +235,26 @@ public class LPBukkitPlugin extends JavaPlugin implements LuckPermsPlugin {
|
|||||||
|
|
||||||
// register commands
|
// register commands
|
||||||
getLog().info("Registering commands...");
|
getLog().info("Registering commands...");
|
||||||
BukkitCommand commandManager = new BukkitCommand(this);
|
commandManager = new BukkitCommand(this);
|
||||||
PluginCommand main = getServer().getPluginCommand("luckperms");
|
PluginCommand main = getServer().getPluginCommand("luckperms");
|
||||||
main.setExecutor(commandManager);
|
main.setExecutor(commandManager);
|
||||||
main.setTabCompleter(commandManager);
|
main.setTabCompleter(commandManager);
|
||||||
main.setAliases(Arrays.asList("perms", "lp", "permissions", "p", "perm"));
|
main.setAliases(Arrays.asList("perms", "lp", "permissions", "perm"));
|
||||||
|
|
||||||
// load internal managers
|
// load internal managers
|
||||||
getLog().info("Loading internal permission managers...");
|
getLog().info("Loading internal permission managers...");
|
||||||
uuidCache = new UuidCache(getConfiguration().isOnlineMode());
|
uuidCache = new UuidCache(this);
|
||||||
userManager = new GenericUserManager(this);
|
userManager = new GenericUserManager(this);
|
||||||
groupManager = new GenericGroupManager(this);
|
groupManager = new GenericGroupManager(this);
|
||||||
trackManager = new GenericTrackManager();
|
trackManager = new GenericTrackManager(this);
|
||||||
importer = new Importer(commandManager);
|
importer = new Importer(commandManager);
|
||||||
consecutiveExecutor = new ConsecutiveExecutor(commandManager);
|
|
||||||
calculatorFactory = new BukkitCalculatorFactory(this);
|
calculatorFactory = new BukkitCalculatorFactory(this);
|
||||||
|
cachedStateManager = new CachedStateManager(this);
|
||||||
|
|
||||||
contextManager = new ContextManager<>();
|
contextManager = new ContextManager<>();
|
||||||
worldCalculator = new WorldCalculator(this);
|
worldCalculator = new WorldCalculator(this);
|
||||||
pm.registerEvents(worldCalculator, this);
|
|
||||||
contextManager.registerCalculator(worldCalculator);
|
contextManager.registerCalculator(worldCalculator);
|
||||||
contextManager.registerCalculator(new ServerCalculator<>(getConfiguration().getServer()));
|
contextManager.registerCalculator(new ServerCalculator<>(getConfiguration()));
|
||||||
|
|
||||||
// handle server operators
|
|
||||||
if (getConfiguration().isAutoOp()) {
|
|
||||||
contextManager.registerListener(new AutoOPListener());
|
|
||||||
}
|
|
||||||
|
|
||||||
// Provide vault support
|
// Provide vault support
|
||||||
tryVaultHook(false);
|
tryVaultHook(false);
|
||||||
@@ -241,43 +267,83 @@ public class LPBukkitPlugin extends JavaPlugin implements LuckPermsPlugin {
|
|||||||
|
|
||||||
|
|
||||||
// schedule update tasks
|
// schedule update tasks
|
||||||
int mins = getConfiguration().getSyncTime();
|
int mins = getConfiguration().get(ConfigKeys.SYNC_TIME);
|
||||||
if (mins > 0) {
|
if (mins > 0) {
|
||||||
long ticks = mins * 60 * 20;
|
long ticks = mins * 60 * 20;
|
||||||
getServer().getScheduler().runTaskTimerAsynchronously(this, () -> updateTaskBuffer.request(), 20L, ticks);
|
scheduler.doAsyncRepeating(() -> updateTaskBuffer.request(), ticks);
|
||||||
}
|
}
|
||||||
|
scheduler.doAsyncLater(() -> updateTaskBuffer.request(), 40L);
|
||||||
|
|
||||||
// run an update instantly.
|
// run an update instantly.
|
||||||
updateTaskBuffer.requestDirectly();
|
updateTaskBuffer.requestDirectly();
|
||||||
|
|
||||||
// register tasks
|
// register tasks
|
||||||
getServer().getScheduler().runTaskTimerAsynchronously(this, new ExpireTemporaryTask(this), 60L, 60L);
|
scheduler.doAsyncRepeating(new ExpireTemporaryTask(this), 60L);
|
||||||
getServer().getScheduler().runTaskTimerAsynchronously(this, consecutiveExecutor, 20L, 20L);
|
scheduler.doAsyncRepeating(new CacheHousekeepingTask(this), 2400L);
|
||||||
|
|
||||||
// register permissions
|
// register permissions
|
||||||
registerPermissions(getConfiguration().isCommandsAllowOp() ? PermissionDefault.OP : PermissionDefault.FALSE);
|
registerPermissions(getConfiguration().get(ConfigKeys.COMMANDS_ALLOW_OP) ? PermissionDefault.OP : PermissionDefault.FALSE);
|
||||||
if (!getConfiguration().isOpsEnabled()) {
|
if (!getConfiguration().get(ConfigKeys.OPS_ENABLED)) {
|
||||||
getServer().getScheduler().runTask(this, () -> getServer().getOperators().forEach(o -> o.setOp(false)));
|
scheduler.doSync(() -> getServer().getOperators().forEach(o -> o.setOp(false)));
|
||||||
}
|
}
|
||||||
|
|
||||||
// replace the temporary executor when the Bukkit one starts
|
// replace the temporary executor when the Bukkit one starts
|
||||||
getServer().getScheduler().runTaskAsynchronously(this, () -> {
|
getServer().getScheduler().runTaskAsynchronously(this, () -> {
|
||||||
asyncExecutor = bukkitAsyncExecutor;
|
scheduler.setUseBukkitAsync(true);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// Load any online users (in the case of a reload)
|
||||||
|
for (Player player : getServer().getOnlinePlayers()) {
|
||||||
|
scheduler.doAsync(() -> {
|
||||||
|
listener.onAsyncLogin(player.getUniqueId(), player.getName());
|
||||||
|
User user = getUserManager().get(getUuidCache().getUUID(player.getUniqueId()));
|
||||||
|
if (user != null) {
|
||||||
|
scheduler.doSync(() -> {
|
||||||
|
try {
|
||||||
|
LPPermissible lpPermissible = new LPPermissible(player, user, this);
|
||||||
|
Injector.inject(player, lpPermissible);
|
||||||
|
} catch (Throwable t) {
|
||||||
|
t.printStackTrace();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
started = true;
|
started = true;
|
||||||
getLog().info("Successfully loaded.");
|
getLog().info("Successfully loaded.");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onDisable() {
|
public void onDisable() {
|
||||||
|
// Switch back to the LP executor, the bukkit one won't allow new tasks
|
||||||
|
scheduler.setUseBukkitAsync(false);
|
||||||
|
|
||||||
started = false;
|
started = false;
|
||||||
|
|
||||||
|
defaultsProvider.close();
|
||||||
|
permissionVault.setShutdown(true);
|
||||||
|
debugHandler.setShutdown(true);
|
||||||
|
|
||||||
|
for (Player player : getServer().getOnlinePlayers()) {
|
||||||
|
Injector.unInject(player, false, false);
|
||||||
|
if (getConfiguration().get(ConfigKeys.AUTO_OP)) {
|
||||||
|
player.setOp(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
final User user = getUserManager().get(getUuidCache().getUUID(player.getUniqueId()));
|
||||||
|
if (user != null) {
|
||||||
|
user.unregisterData();
|
||||||
|
getUserManager().unload(user);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
getLog().info("Closing datastore...");
|
getLog().info("Closing datastore...");
|
||||||
storage.shutdown();
|
storage.shutdown();
|
||||||
|
|
||||||
if (redisMessaging != null) {
|
if (messagingService != null) {
|
||||||
getLog().info("Closing redis...");
|
getLog().info("Closing messaging service...");
|
||||||
redisMessaging.shutdown();
|
messagingService.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
getLog().info("Unregistering API...");
|
getLog().info("Unregistering API...");
|
||||||
@@ -287,6 +353,38 @@ public class LPBukkitPlugin extends JavaPlugin implements LuckPermsPlugin {
|
|||||||
if (vaultHook != null) {
|
if (vaultHook != null) {
|
||||||
vaultHook.unhook(this);
|
vaultHook.unhook(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
scheduler.shutdown();
|
||||||
|
|
||||||
|
// Bukkit will do this again when #onDisable completes, but we do it early to prevent NPEs elsewhere.
|
||||||
|
getServer().getScheduler().cancelTasks(this);
|
||||||
|
HandlerList.unregisterAll(this);
|
||||||
|
|
||||||
|
// Null everything
|
||||||
|
ignoringLogs = null;
|
||||||
|
vaultHook = null;
|
||||||
|
configuration = null;
|
||||||
|
userManager = null;
|
||||||
|
groupManager = null;
|
||||||
|
trackManager = null;
|
||||||
|
storage = null;
|
||||||
|
messagingService = null;
|
||||||
|
uuidCache = null;
|
||||||
|
listener = null;
|
||||||
|
apiProvider = null;
|
||||||
|
log = null;
|
||||||
|
importer = null;
|
||||||
|
defaultsProvider = null;
|
||||||
|
childPermissionProvider = null;
|
||||||
|
localeManager = null;
|
||||||
|
cachedStateManager = null;
|
||||||
|
contextManager = null;
|
||||||
|
worldCalculator = null;
|
||||||
|
calculatorFactory = null;
|
||||||
|
updateTaskBuffer = null;
|
||||||
|
debugHandler = null;
|
||||||
|
senderFactory = null;
|
||||||
|
permissionVault = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void tryVaultHook(boolean force) {
|
public void tryVaultHook(boolean force) {
|
||||||
@@ -311,18 +409,26 @@ public class LPBukkitPlugin extends JavaPlugin implements LuckPermsPlugin {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void doAsync(Runnable r) {
|
public void onUserRefresh(User user) {
|
||||||
asyncExecutor.execute(r);
|
LPPermissible lpp = Injector.getPermissible(uuidCache.getExternalUUID(user.getUuid()));
|
||||||
|
if (lpp != null) {
|
||||||
|
lpp.updateSubscriptions();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
public void refreshAutoOp(Player player) {
|
||||||
public void doSync(Runnable r) {
|
if (getConfiguration().get(ConfigKeys.AUTO_OP)) {
|
||||||
syncExecutor.execute(r);
|
try {
|
||||||
}
|
LPPermissible permissible = Injector.getPermissible(player.getUniqueId());
|
||||||
|
if (permissible == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
Map<String, Boolean> backing = permissible.getUser().getUserData().getPermissionData(permissible.calculateContexts()).getImmutableBacking();
|
||||||
public void doAsyncRepeating(Runnable r, long interval) {
|
boolean op = Optional.ofNullable(backing.get("luckperms.autoop")).orElse(false);
|
||||||
getServer().getScheduler().runTaskTimerAsynchronously(this, r, interval, interval);
|
player.setOp(op);
|
||||||
|
} catch (Exception ignored) {}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -331,13 +437,28 @@ public class LPBukkitPlugin extends JavaPlugin implements LuckPermsPlugin {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public PlatformType getType() {
|
public PlatformType getServerType() {
|
||||||
return PlatformType.BUKKIT;
|
return PlatformType.BUKKIT;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public File getMainDir() {
|
public String getServerName() {
|
||||||
return getDataFolder();
|
return getServer().getName();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getServerVersion() {
|
||||||
|
return getServer().getVersion();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public File getDataDirectory() {
|
||||||
|
return super.getDataFolder();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public InputStream getResourceStream(String path) {
|
||||||
|
return getResource(path);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -353,11 +474,11 @@ public class LPBukkitPlugin extends JavaPlugin implements LuckPermsPlugin {
|
|||||||
}
|
}
|
||||||
return new Contexts(
|
return new Contexts(
|
||||||
getContextManager().getApplicableContext(player),
|
getContextManager().getApplicableContext(player),
|
||||||
getConfiguration().isIncludingGlobalPerms(),
|
getConfiguration().get(ConfigKeys.INCLUDING_GLOBAL_PERMS),
|
||||||
getConfiguration().isIncludingGlobalWorldPerms(),
|
getConfiguration().get(ConfigKeys.INCLUDING_GLOBAL_WORLD_PERMS),
|
||||||
true,
|
true,
|
||||||
getConfiguration().isApplyingGlobalGroups(),
|
getConfiguration().get(ConfigKeys.APPLYING_GLOBAL_GROUPS),
|
||||||
getConfiguration().isApplyingGlobalWorldGroups(),
|
getConfiguration().get(ConfigKeys.APPLYING_GLOBAL_WORLD_GROUPS),
|
||||||
player.isOp()
|
player.isOp()
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@@ -378,12 +499,12 @@ public class LPBukkitPlugin extends JavaPlugin implements LuckPermsPlugin {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isOnline(UUID external) {
|
public boolean isPlayerOnline(UUID external) {
|
||||||
return getServer().getPlayer(external) != null;
|
return getServer().getPlayer(external) != null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<Sender> getSenders() {
|
public List<Sender> getOnlineSenders() {
|
||||||
return getServer().getOnlinePlayers().stream()
|
return getServer().getOnlinePlayers().stream()
|
||||||
.map(p -> getSenderFactory().wrap(p))
|
.map(p -> getSenderFactory().wrap(p))
|
||||||
.collect(Collectors.toList());
|
.collect(Collectors.toList());
|
||||||
@@ -398,14 +519,14 @@ public class LPBukkitPlugin extends JavaPlugin implements LuckPermsPlugin {
|
|||||||
public Set<Contexts> getPreProcessContexts(boolean op) {
|
public Set<Contexts> getPreProcessContexts(boolean op) {
|
||||||
Set<ContextSet> c = new HashSet<>();
|
Set<ContextSet> c = new HashSet<>();
|
||||||
c.add(ContextSet.empty());
|
c.add(ContextSet.empty());
|
||||||
c.add(ContextSet.singleton("server", getConfiguration().getServer()));
|
c.add(ContextSet.singleton("server", getConfiguration().get(ConfigKeys.SERVER)));
|
||||||
|
|
||||||
// Pre process all worlds
|
// Pre process all worlds
|
||||||
c.addAll(getServer().getWorlds().stream()
|
c.addAll(getServer().getWorlds().stream()
|
||||||
.map(World::getName)
|
.map(World::getName)
|
||||||
.map(s -> {
|
.map(s -> {
|
||||||
MutableContextSet set = MutableContextSet.create();
|
MutableContextSet set = MutableContextSet.create();
|
||||||
set.add("server", getConfiguration().getServer());
|
set.add("server", getConfiguration().get(ConfigKeys.SERVER));
|
||||||
set.add("world", s);
|
set.add("world", s);
|
||||||
return set.makeImmutable();
|
return set.makeImmutable();
|
||||||
})
|
})
|
||||||
@@ -413,13 +534,13 @@ public class LPBukkitPlugin extends JavaPlugin implements LuckPermsPlugin {
|
|||||||
);
|
);
|
||||||
|
|
||||||
// Pre process the separate Vault server, if any
|
// Pre process the separate Vault server, if any
|
||||||
if (!getConfiguration().getServer().equals(getConfiguration().getVaultServer())) {
|
if (!getConfiguration().get(ConfigKeys.SERVER).equals(getConfiguration().get(ConfigKeys.VAULT_SERVER))) {
|
||||||
c.add(ContextSet.singleton("server", getConfiguration().getVaultServer()));
|
c.add(ContextSet.singleton("server", getConfiguration().get(ConfigKeys.VAULT_SERVER)));
|
||||||
c.addAll(getServer().getWorlds().stream()
|
c.addAll(getServer().getWorlds().stream()
|
||||||
.map(World::getName)
|
.map(World::getName)
|
||||||
.map(s -> {
|
.map(s -> {
|
||||||
MutableContextSet set = MutableContextSet.create();
|
MutableContextSet set = MutableContextSet.create();
|
||||||
set.add("server", getConfiguration().getVaultServer());
|
set.add("server", getConfiguration().get(ConfigKeys.VAULT_SERVER));
|
||||||
set.add("world", s);
|
set.add("world", s);
|
||||||
return set.makeImmutable();
|
return set.makeImmutable();
|
||||||
})
|
})
|
||||||
@@ -433,25 +554,25 @@ public class LPBukkitPlugin extends JavaPlugin implements LuckPermsPlugin {
|
|||||||
contexts.addAll(c.stream()
|
contexts.addAll(c.stream()
|
||||||
.map(set -> new Contexts(
|
.map(set -> new Contexts(
|
||||||
set,
|
set,
|
||||||
getConfiguration().isIncludingGlobalPerms(),
|
getConfiguration().get(ConfigKeys.INCLUDING_GLOBAL_PERMS),
|
||||||
getConfiguration().isIncludingGlobalWorldPerms(),
|
getConfiguration().get(ConfigKeys.INCLUDING_GLOBAL_WORLD_PERMS),
|
||||||
true,
|
true,
|
||||||
getConfiguration().isApplyingGlobalGroups(),
|
getConfiguration().get(ConfigKeys.APPLYING_GLOBAL_GROUPS),
|
||||||
getConfiguration().isApplyingGlobalWorldGroups(),
|
getConfiguration().get(ConfigKeys.APPLYING_GLOBAL_WORLD_GROUPS),
|
||||||
op
|
op
|
||||||
))
|
))
|
||||||
.collect(Collectors.toSet())
|
.collect(Collectors.toSet())
|
||||||
);
|
);
|
||||||
|
|
||||||
// Check for and include varying Vault config options
|
// Check for and include varying Vault config options
|
||||||
boolean vaultDiff = getConfiguration().isVaultIncludingGlobal() != getConfiguration().isIncludingGlobalPerms() ||
|
boolean vaultDiff = getConfiguration().get(ConfigKeys.VAULT_INCLUDING_GLOBAL) != getConfiguration().get(ConfigKeys.INCLUDING_GLOBAL_PERMS) ||
|
||||||
!getConfiguration().isIncludingGlobalWorldPerms() ||
|
!getConfiguration().get(ConfigKeys.INCLUDING_GLOBAL_WORLD_PERMS) ||
|
||||||
!getConfiguration().isApplyingGlobalGroups() ||
|
!getConfiguration().get(ConfigKeys.APPLYING_GLOBAL_GROUPS) ||
|
||||||
!getConfiguration().isApplyingGlobalWorldGroups();
|
!getConfiguration().get(ConfigKeys.APPLYING_GLOBAL_WORLD_GROUPS);
|
||||||
|
|
||||||
if (vaultDiff) {
|
if (vaultDiff) {
|
||||||
contexts.addAll(c.stream()
|
contexts.addAll(c.stream()
|
||||||
.map(map -> new Contexts(map, getConfiguration().isVaultIncludingGlobal(), true, true, true, true, op))
|
.map(map -> new Contexts(map, getConfiguration().get(ConfigKeys.VAULT_INCLUDING_GLOBAL), true, true, true, true, op))
|
||||||
.collect(Collectors.toSet())
|
.collect(Collectors.toSet())
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@@ -463,33 +584,22 @@ public class LPBukkitPlugin extends JavaPlugin implements LuckPermsPlugin {
|
|||||||
public LinkedHashMap<String, Object> getExtraInfo() {
|
public LinkedHashMap<String, Object> getExtraInfo() {
|
||||||
LinkedHashMap<String, Object> map = new LinkedHashMap<>();
|
LinkedHashMap<String, Object> map = new LinkedHashMap<>();
|
||||||
map.put("Vault Enabled", vaultHook != null);
|
map.put("Vault Enabled", vaultHook != null);
|
||||||
map.put("Vault Server", configuration.getVaultServer());
|
map.put("Vault Server", configuration.get(ConfigKeys.VAULT_SERVER));
|
||||||
map.put("Bukkit Defaults count", defaultsProvider.size());
|
map.put("Bukkit Defaults count", defaultsProvider.size());
|
||||||
map.put("Bukkit Child Permissions count", childPermissionProvider.getPermissions().size());
|
map.put("Bukkit Child Permissions count", childPermissionProvider.getPermissions().size());
|
||||||
map.put("World Cache size", worldCalculator.getWorldCache().size());
|
map.put("Vault Including Global", configuration.get(ConfigKeys.VAULT_INCLUDING_GLOBAL));
|
||||||
map.put("Vault Including Global", configuration.isVaultIncludingGlobal());
|
map.put("Vault Ignoring World", configuration.get(ConfigKeys.VAULT_IGNORE_WORLD));
|
||||||
map.put("Vault Ignoring World", configuration.isVaultIgnoreWorld());
|
map.put("Vault Primary Group Overrides", configuration.get(ConfigKeys.VAULT_PRIMARY_GROUP_OVERRIDES));
|
||||||
map.put("Vault Primary Group Overrides", configuration.isVaultPrimaryGroupOverrides());
|
map.put("Vault Debug", configuration.get(ConfigKeys.VAULT_DEBUG));
|
||||||
map.put("Vault Debug", configuration.isVaultDebug());
|
map.put("OPs Enabled", configuration.get(ConfigKeys.OPS_ENABLED));
|
||||||
map.put("OPs Enabled", configuration.isOpsEnabled());
|
map.put("Auto OP", configuration.get(ConfigKeys.AUTO_OP));
|
||||||
map.put("Auto OP", configuration.isAutoOp());
|
map.put("Commands Allow OPs", configuration.get(ConfigKeys.COMMANDS_ALLOW_OP));
|
||||||
map.put("Commands Allow OPs", configuration.isCommandsAllowOp());
|
|
||||||
return map;
|
return map;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public Object getPlugin(String name) {
|
|
||||||
return getServer().getPluginManager().getPlugin(name);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Object getService(Class clazz) {
|
|
||||||
return getServer().getServicesManager().load(clazz);
|
|
||||||
}
|
|
||||||
|
|
||||||
@SuppressWarnings("deprecation")
|
@SuppressWarnings("deprecation")
|
||||||
@Override
|
@Override
|
||||||
public UUID getUUID(String playerName) {
|
public UUID getUuidFromUsername(String playerName) {
|
||||||
try {
|
try {
|
||||||
return getServer().getOfflinePlayer(playerName).getUniqueId();
|
return getServer().getOfflinePlayer(playerName).getUniqueId();
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
@@ -497,11 +607,6 @@ public class LPBukkitPlugin extends JavaPlugin implements LuckPermsPlugin {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean isPluginLoaded(String name) {
|
|
||||||
return getServer().getPluginManager().isPluginEnabled(name);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void registerPermissions(PermissionDefault def) {
|
private void registerPermissions(PermissionDefault def) {
|
||||||
PluginManager pm = getServer().getPluginManager();
|
PluginManager pm = getServer().getPluginManager();
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,116 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2016 Lucko (Luck) <[email protected]>
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
* of this software and associated documentation files (the "Software"), to deal
|
||||||
|
* in the Software without restriction, including without limitation the rights
|
||||||
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
* copies of the Software, and to permit persons to whom the Software is
|
||||||
|
* furnished to do so, subject to the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be included in all
|
||||||
|
* copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
|
* SOFTWARE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package me.lucko.luckperms.bukkit;
|
||||||
|
|
||||||
|
import lombok.Getter;
|
||||||
|
import lombok.Setter;
|
||||||
|
|
||||||
|
import me.lucko.luckperms.common.plugin.LuckPermsScheduler;
|
||||||
|
|
||||||
|
import org.bukkit.scheduler.BukkitTask;
|
||||||
|
|
||||||
|
import java.util.Set;
|
||||||
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
|
import java.util.concurrent.Executor;
|
||||||
|
import java.util.concurrent.ExecutorService;
|
||||||
|
import java.util.concurrent.Executors;
|
||||||
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
|
public class LPBukkitScheduler implements LuckPermsScheduler {
|
||||||
|
private final LPBukkitPlugin plugin;
|
||||||
|
|
||||||
|
@Getter
|
||||||
|
private ExecutorService asyncLpExecutor;
|
||||||
|
@Getter
|
||||||
|
private Executor asyncBukkitExecutor;
|
||||||
|
private Executor syncExecutor;
|
||||||
|
|
||||||
|
@Getter
|
||||||
|
@Setter
|
||||||
|
private boolean useBukkitAsync = false;
|
||||||
|
|
||||||
|
private Set<BukkitTask> tasks = ConcurrentHashMap.newKeySet();
|
||||||
|
|
||||||
|
public LPBukkitScheduler(LPBukkitPlugin plugin) {
|
||||||
|
this.plugin = plugin;
|
||||||
|
|
||||||
|
this.asyncLpExecutor = Executors.newCachedThreadPool();
|
||||||
|
this.asyncBukkitExecutor = r -> plugin.getServer().getScheduler().runTaskAsynchronously(plugin, r);
|
||||||
|
this.syncExecutor = r -> plugin.getServer().getScheduler().runTask(plugin, r);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Executor getAsyncExecutor() {
|
||||||
|
return useBukkitAsync ? asyncBukkitExecutor : asyncLpExecutor;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Executor getSyncExecutor() {
|
||||||
|
return syncExecutor;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void doAsync(Runnable r) {
|
||||||
|
getAsyncExecutor().execute(r);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void doSync(Runnable r) {
|
||||||
|
getSyncExecutor().execute(r);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void doAsyncRepeating(Runnable r, long interval) {
|
||||||
|
BukkitTask task = plugin.getServer().getScheduler().runTaskTimerAsynchronously(plugin, r, interval, interval);
|
||||||
|
tasks.add(task);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void doSyncRepeating(Runnable r, long interval) {
|
||||||
|
BukkitTask task = plugin.getServer().getScheduler().runTaskTimer(plugin, r, interval, interval);
|
||||||
|
tasks.add(task);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void doAsyncLater(Runnable r, long delay) {
|
||||||
|
plugin.getServer().getScheduler().runTaskLaterAsynchronously(plugin, r, delay);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void doSyncLater(Runnable r, long delay) {
|
||||||
|
plugin.getServer().getScheduler().runTaskLater(plugin, r, delay);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void shutdown() {
|
||||||
|
tasks.forEach(BukkitTask::cancel);
|
||||||
|
// wait for executor
|
||||||
|
asyncLpExecutor.shutdown();
|
||||||
|
try {
|
||||||
|
asyncLpExecutor.awaitTermination(30, TimeUnit.SECONDS);
|
||||||
|
} catch (InterruptedException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -22,35 +22,25 @@
|
|||||||
|
|
||||||
package me.lucko.luckperms.bukkit;
|
package me.lucko.luckperms.bukkit;
|
||||||
|
|
||||||
import lombok.Getter;
|
|
||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
|
|
||||||
import com.google.common.collect.Maps;
|
import com.google.common.collect.Maps;
|
||||||
|
|
||||||
import me.lucko.luckperms.api.context.ContextCalculator;
|
import me.lucko.luckperms.api.context.ContextCalculator;
|
||||||
import me.lucko.luckperms.api.context.MutableContextSet;
|
import me.lucko.luckperms.api.context.MutableContextSet;
|
||||||
import me.lucko.luckperms.common.LuckPermsPlugin;
|
import me.lucko.luckperms.common.config.ConfigKeys;
|
||||||
|
import me.lucko.luckperms.common.plugin.LuckPermsPlugin;
|
||||||
|
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.event.EventHandler;
|
|
||||||
import org.bukkit.event.EventPriority;
|
|
||||||
import org.bukkit.event.Listener;
|
|
||||||
import org.bukkit.event.player.PlayerChangedWorldEvent;
|
|
||||||
import org.bukkit.event.player.PlayerLoginEvent;
|
|
||||||
|
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.UUID;
|
|
||||||
import java.util.concurrent.ConcurrentHashMap;
|
|
||||||
|
|
||||||
@RequiredArgsConstructor
|
@RequiredArgsConstructor
|
||||||
public class WorldCalculator extends ContextCalculator<Player> implements Listener {
|
public class WorldCalculator implements ContextCalculator<Player> {
|
||||||
private static final String WORLD_KEY = "world";
|
private static final String WORLD_KEY = "world";
|
||||||
|
|
||||||
private final LuckPermsPlugin plugin;
|
private final LuckPermsPlugin plugin;
|
||||||
|
|
||||||
@Getter
|
|
||||||
private final Map<UUID, String> worldCache = new ConcurrentHashMap<>();
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public MutableContextSet giveApplicableContext(Player subject, MutableContextSet accumulator) {
|
public MutableContextSet giveApplicableContext(Player subject, MutableContextSet accumulator) {
|
||||||
String world = getWorld(subject);
|
String world = getWorld(subject);
|
||||||
@@ -73,34 +63,7 @@ public class WorldCalculator extends ContextCalculator<Player> implements Listen
|
|||||||
}
|
}
|
||||||
|
|
||||||
private String getWorld(Player player) {
|
private String getWorld(Player player) {
|
||||||
UUID internal = plugin.getUuidCache().getUUID(player.getUniqueId());
|
String world = player.getWorld().getName();
|
||||||
String world = worldCache.get(internal);
|
return plugin.getConfiguration().get(ConfigKeys.WORLD_REWRITES).getOrDefault(world, world);
|
||||||
if (world == null) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
return plugin.getConfiguration().getWorldRewrites().getOrDefault(world, world);
|
|
||||||
}
|
|
||||||
|
|
||||||
@EventHandler(priority = EventPriority.LOW)
|
|
||||||
public void onPlayerJoin(PlayerLoginEvent e) {
|
|
||||||
UUID internal = plugin.getUuidCache().getUUID(e.getPlayer().getUniqueId());
|
|
||||||
worldCache.put(internal, e.getPlayer().getWorld().getName());
|
|
||||||
pushUpdate(
|
|
||||||
e.getPlayer(),
|
|
||||||
Maps.immutableEntry(WORLD_KEY, null),
|
|
||||||
Maps.immutableEntry(WORLD_KEY, e.getPlayer().getWorld().getName())
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
@EventHandler(priority = EventPriority.LOWEST)
|
|
||||||
public void onPlayerChangedWorld(PlayerChangedWorldEvent e) {
|
|
||||||
UUID internal = plugin.getUuidCache().getUUID(e.getPlayer().getUniqueId());
|
|
||||||
worldCache.put(internal, e.getPlayer().getWorld().getName());
|
|
||||||
pushUpdate(
|
|
||||||
e.getPlayer(),
|
|
||||||
Maps.immutableEntry(WORLD_KEY, e.getFrom().getName()),
|
|
||||||
Maps.immutableEntry(WORLD_KEY, e.getPlayer().getWorld().getName())
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,122 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2016 Lucko (Luck) <[email protected]>
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
* of this software and associated documentation files (the "Software"), to deal
|
||||||
|
* in the Software without restriction, including without limitation the rights
|
||||||
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
* copies of the Software, and to permit persons to whom the Software is
|
||||||
|
* furnished to do so, subject to the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be included in all
|
||||||
|
* copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
|
* SOFTWARE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package me.lucko.luckperms.bukkit.compat;
|
||||||
|
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
|
import java.lang.reflect.Constructor;
|
||||||
|
import java.lang.reflect.Field;
|
||||||
|
import java.lang.reflect.Method;
|
||||||
|
|
||||||
|
public class BukkitJsonMessageHandler {
|
||||||
|
private static boolean setup = false;
|
||||||
|
private static boolean triedAndFailed = false;
|
||||||
|
|
||||||
|
private static Method GET_HANDLE_METHOD;
|
||||||
|
private static Field PLAYER_CONNECTION_FIELD;
|
||||||
|
private static Method SEND_PACKET_METHOD;
|
||||||
|
private static Constructor<?> PACKET_CHAT_CONSTRUCTOR;
|
||||||
|
private static Method SERIALIZE_METHOD;
|
||||||
|
|
||||||
|
private static void setup(Object player) throws Exception {
|
||||||
|
Class<?> craftPlayerClass = player.getClass();
|
||||||
|
GET_HANDLE_METHOD = craftPlayerClass.getDeclaredMethod("getHandle");
|
||||||
|
|
||||||
|
Object handleObject = GET_HANDLE_METHOD.invoke(player);
|
||||||
|
Class<?> handleClass = handleObject.getClass();
|
||||||
|
|
||||||
|
PLAYER_CONNECTION_FIELD = handleClass.getDeclaredField("playerConnection");
|
||||||
|
|
||||||
|
Object playerConnectionObject = PLAYER_CONNECTION_FIELD.get(handleObject);
|
||||||
|
|
||||||
|
Method[] playerConnectionMethods = playerConnectionObject.getClass().getDeclaredMethods();
|
||||||
|
for (Method m : playerConnectionMethods) {
|
||||||
|
if (m.getName().equals("sendPacket")) {
|
||||||
|
SEND_PACKET_METHOD = m;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Class<?> packetChatClass = Class.forName(getVersionedClassName("PacketPlayOutChat"));
|
||||||
|
Constructor[] packetConstructors = packetChatClass.getDeclaredConstructors();
|
||||||
|
for (Constructor c : packetConstructors) {
|
||||||
|
Class<?>[] parameters = c.getParameterTypes();
|
||||||
|
if (parameters.length == 1 && parameters[0].getName().endsWith("IChatBaseComponent")) {
|
||||||
|
PACKET_CHAT_CONSTRUCTOR = c;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Class<?> baseComponentClass = Class.forName(getVersionedClassName("IChatBaseComponent"));
|
||||||
|
Class<?> chatSerializerClass = baseComponentClass.getClasses()[0];
|
||||||
|
|
||||||
|
SERIALIZE_METHOD = chatSerializerClass.getDeclaredMethod("a", String.class);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static String getVersionedClassName(String className) {
|
||||||
|
Class server = Bukkit.getServer().getClass();
|
||||||
|
if (!server.getSimpleName().equals("CraftServer")) {
|
||||||
|
throw new RuntimeException("Couldn't reflect into server " + server);
|
||||||
|
}
|
||||||
|
|
||||||
|
String version;
|
||||||
|
if (server.getName().equals("org.bukkit.craftbukkit.CraftServer")) {
|
||||||
|
// Non versioned class
|
||||||
|
version = ".";
|
||||||
|
} else {
|
||||||
|
version = server.getName().substring("org.bukkit.craftbukkit".length());
|
||||||
|
version = version.substring(0, version.length() - "CraftServer".length());
|
||||||
|
}
|
||||||
|
|
||||||
|
return "net.minecraft.server" + version + className;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static synchronized boolean trySetup(Object player) {
|
||||||
|
if (setup) return true;
|
||||||
|
if (triedAndFailed) return false;
|
||||||
|
|
||||||
|
try {
|
||||||
|
setup(player);
|
||||||
|
setup = true;
|
||||||
|
return true;
|
||||||
|
} catch (Exception e) {
|
||||||
|
triedAndFailed = true;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean sendJsonMessage(Player player, String json) {
|
||||||
|
if (!trySetup(player)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
Object connection = PLAYER_CONNECTION_FIELD.get(GET_HANDLE_METHOD.invoke(player));
|
||||||
|
SEND_PACKET_METHOD.invoke(connection, PACKET_CHAT_CONSTRUCTOR.newInstance(SERIALIZE_METHOD.invoke(null, json)));
|
||||||
|
return true;
|
||||||
|
} catch (Exception e) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,68 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2016 Lucko (Luck) <[email protected]>
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
* of this software and associated documentation files (the "Software"), to deal
|
||||||
|
* in the Software without restriction, including without limitation the rights
|
||||||
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
* copies of the Software, and to permit persons to whom the Software is
|
||||||
|
* furnished to do so, subject to the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be included in all
|
||||||
|
* copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
|
* SOFTWARE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package me.lucko.luckperms.bukkit.compat;
|
||||||
|
|
||||||
|
import org.bukkit.command.CommandSender;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
|
import io.github.mkremins.fanciful.FancyMessage;
|
||||||
|
|
||||||
|
public class MessageHandler {
|
||||||
|
private final BukkitJsonMessageHandler bukkitHandler;
|
||||||
|
private final SpigotJsonMessageHandler spigotHandler;
|
||||||
|
|
||||||
|
public MessageHandler() {
|
||||||
|
bukkitHandler = new BukkitJsonMessageHandler();
|
||||||
|
spigotHandler = isSpigot() ? new SpigotJsonMessageHandler() : null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void sendJsonMessage(CommandSender sender, FancyMessage message) {
|
||||||
|
if (sender instanceof Player) {
|
||||||
|
Player player = (Player) sender;
|
||||||
|
String json = message.toJSONString();
|
||||||
|
|
||||||
|
// Try Bukkit.
|
||||||
|
if (bukkitHandler.sendJsonMessage(player, json)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Try Spigot.
|
||||||
|
if (spigotHandler != null && spigotHandler.sendJsonMessage(player, json)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Fallback to Bukkit
|
||||||
|
sender.sendMessage(message.toOldMessageFormat());
|
||||||
|
}
|
||||||
|
|
||||||
|
private static boolean isSpigot() {
|
||||||
|
try {
|
||||||
|
Class.forName("net.md_5.bungee.chat.ComponentSerializer");
|
||||||
|
return true;
|
||||||
|
} catch (ClassNotFoundException e) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,40 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2016 Lucko (Luck) <[email protected]>
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
* of this software and associated documentation files (the "Software"), to deal
|
||||||
|
* in the Software without restriction, including without limitation the rights
|
||||||
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
* copies of the Software, and to permit persons to whom the Software is
|
||||||
|
* furnished to do so, subject to the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be included in all
|
||||||
|
* copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
|
* SOFTWARE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package me.lucko.luckperms.bukkit.compat;
|
||||||
|
|
||||||
|
import net.md_5.bungee.chat.ComponentSerializer;
|
||||||
|
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
|
public class SpigotJsonMessageHandler {
|
||||||
|
|
||||||
|
public boolean sendJsonMessage(Player player, String json) {
|
||||||
|
try {
|
||||||
|
player.spigot().sendMessage(ComponentSerializer.parse(json));
|
||||||
|
return true;
|
||||||
|
} catch (Exception e) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,95 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2016 Lucko (Luck) <[email protected]>
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
* of this software and associated documentation files (the "Software"), to deal
|
||||||
|
* in the Software without restriction, including without limitation the rights
|
||||||
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
* copies of the Software, and to permit persons to whom the Software is
|
||||||
|
* furnished to do so, subject to the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be included in all
|
||||||
|
* copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
|
* SOFTWARE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package me.lucko.luckperms.bukkit.messaging;
|
||||||
|
|
||||||
|
import com.google.common.collect.Iterables;
|
||||||
|
import com.google.common.io.ByteArrayDataInput;
|
||||||
|
import com.google.common.io.ByteArrayDataOutput;
|
||||||
|
import com.google.common.io.ByteStreams;
|
||||||
|
|
||||||
|
import me.lucko.luckperms.bukkit.LPBukkitPlugin;
|
||||||
|
import me.lucko.luckperms.common.messaging.AbstractMessagingService;
|
||||||
|
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
import org.bukkit.plugin.messaging.PluginMessageListener;
|
||||||
|
import org.bukkit.scheduler.BukkitRunnable;
|
||||||
|
|
||||||
|
import java.util.Collection;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* An implementation of {@link me.lucko.luckperms.api.MessagingService} using the plugin messaging channels.
|
||||||
|
*/
|
||||||
|
public class BungeeMessagingService extends AbstractMessagingService implements PluginMessageListener {
|
||||||
|
private final LPBukkitPlugin plugin;
|
||||||
|
|
||||||
|
public BungeeMessagingService(LPBukkitPlugin plugin) {
|
||||||
|
super(plugin, "Bungee");
|
||||||
|
this.plugin = plugin;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void init() {
|
||||||
|
plugin.getServer().getMessenger().registerOutgoingPluginChannel(plugin, CHANNEL);
|
||||||
|
plugin.getServer().getMessenger().registerIncomingPluginChannel(plugin, CHANNEL, this);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void close() {
|
||||||
|
plugin.getServer().getMessenger().unregisterIncomingPluginChannel(plugin, CHANNEL);
|
||||||
|
plugin.getServer().getMessenger().unregisterOutgoingPluginChannel(plugin, CHANNEL);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void sendMessage(String channel, String message) {
|
||||||
|
new BukkitRunnable() {
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
Collection<? extends Player> players = plugin.getServer().getOnlinePlayers();
|
||||||
|
if (players.isEmpty()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
Player p = Iterables.getFirst(players, null);
|
||||||
|
|
||||||
|
ByteArrayDataOutput out = ByteStreams.newDataOutput();
|
||||||
|
out.writeUTF(message);
|
||||||
|
|
||||||
|
byte[] data = out.toByteArray();
|
||||||
|
|
||||||
|
p.sendPluginMessage(plugin, channel, data);
|
||||||
|
cancel();
|
||||||
|
}
|
||||||
|
}.runTaskTimer(plugin, 1L, 100L);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onPluginMessageReceived(String s, Player player, byte[] bytes) {
|
||||||
|
if (!s.equals(CHANNEL)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
ByteArrayDataInput in = ByteStreams.newDataInput(bytes);
|
||||||
|
String msg = in.readUTF();
|
||||||
|
|
||||||
|
onMessage(s, msg, null);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,90 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2016 Lucko (Luck) <[email protected]>
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
* of this software and associated documentation files (the "Software"), to deal
|
||||||
|
* in the Software without restriction, including without limitation the rights
|
||||||
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
* copies of the Software, and to permit persons to whom the Software is
|
||||||
|
* furnished to do so, subject to the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be included in all
|
||||||
|
* copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
|
* SOFTWARE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package me.lucko.luckperms.bukkit.messaging;
|
||||||
|
|
||||||
|
import me.lucko.luckperms.bukkit.LPBukkitPlugin;
|
||||||
|
import me.lucko.luckperms.common.messaging.AbstractMessagingService;
|
||||||
|
|
||||||
|
import lilypad.client.connect.api.Connect;
|
||||||
|
import lilypad.client.connect.api.event.EventListener;
|
||||||
|
import lilypad.client.connect.api.event.MessageEvent;
|
||||||
|
import lilypad.client.connect.api.request.RequestException;
|
||||||
|
import lilypad.client.connect.api.request.impl.MessageRequest;
|
||||||
|
|
||||||
|
import java.io.UnsupportedEncodingException;
|
||||||
|
import java.util.Collections;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* An implementation of {@link me.lucko.luckperms.api.MessagingService} using LilyPad.
|
||||||
|
*/
|
||||||
|
public class LilyPadMessagingService extends AbstractMessagingService {
|
||||||
|
private final LPBukkitPlugin plugin;
|
||||||
|
private Connect connect;
|
||||||
|
|
||||||
|
public LilyPadMessagingService(LPBukkitPlugin plugin) {
|
||||||
|
super(plugin, "LilyPad");
|
||||||
|
this.plugin = plugin;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void init() {
|
||||||
|
connect = plugin.getServer().getServicesManager().getRegistration(Connect.class).getProvider();
|
||||||
|
connect.registerEvents(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void close() {
|
||||||
|
connect.unregisterEvents(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void sendMessage(String channel, String message) {
|
||||||
|
MessageRequest request;
|
||||||
|
|
||||||
|
try {
|
||||||
|
request = new MessageRequest(Collections.emptyList(), channel, message);
|
||||||
|
} catch (UnsupportedEncodingException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
connect.request(request);
|
||||||
|
} catch (RequestException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@EventListener
|
||||||
|
public void onMessage(MessageEvent event) {
|
||||||
|
plugin.doAsync(() -> {
|
||||||
|
try {
|
||||||
|
String channel = event.getChannel();
|
||||||
|
String message = event.getMessageAsString();
|
||||||
|
|
||||||
|
onMessage(channel, message, null);
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
+105
-132
@@ -29,19 +29,17 @@ import de.bananaco.bpermissions.api.Permission;
|
|||||||
import de.bananaco.bpermissions.api.World;
|
import de.bananaco.bpermissions.api.World;
|
||||||
import de.bananaco.bpermissions.api.WorldManager;
|
import de.bananaco.bpermissions.api.WorldManager;
|
||||||
|
|
||||||
import me.lucko.luckperms.api.Logger;
|
|
||||||
import me.lucko.luckperms.api.MetaUtils;
|
import me.lucko.luckperms.api.MetaUtils;
|
||||||
import me.lucko.luckperms.common.LuckPermsPlugin;
|
import me.lucko.luckperms.api.event.cause.CreationCause;
|
||||||
import me.lucko.luckperms.common.commands.CommandException;
|
import me.lucko.luckperms.common.commands.CommandException;
|
||||||
import me.lucko.luckperms.common.commands.CommandResult;
|
import me.lucko.luckperms.common.commands.CommandResult;
|
||||||
import me.lucko.luckperms.common.commands.SubCommand;
|
import me.lucko.luckperms.common.commands.SubCommand;
|
||||||
import me.lucko.luckperms.common.commands.sender.Sender;
|
import me.lucko.luckperms.common.commands.sender.Sender;
|
||||||
import me.lucko.luckperms.common.constants.Constants;
|
|
||||||
import me.lucko.luckperms.common.core.model.PermissionHolder;
|
import me.lucko.luckperms.common.core.model.PermissionHolder;
|
||||||
import me.lucko.luckperms.common.core.model.User;
|
import me.lucko.luckperms.common.core.model.User;
|
||||||
import me.lucko.luckperms.common.data.LogEntry;
|
import me.lucko.luckperms.common.plugin.LuckPermsPlugin;
|
||||||
import me.lucko.luckperms.common.utils.Predicates;
|
import me.lucko.luckperms.common.utils.Predicates;
|
||||||
import me.lucko.luckperms.exceptions.ObjectAlreadyHasException;
|
import me.lucko.luckperms.common.utils.ProgressLogger;
|
||||||
|
|
||||||
import java.lang.reflect.Field;
|
import java.lang.reflect.Field;
|
||||||
import java.lang.reflect.Method;
|
import java.lang.reflect.Method;
|
||||||
@@ -50,6 +48,7 @@ import java.util.List;
|
|||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
import java.util.concurrent.atomic.AtomicInteger;
|
||||||
|
|
||||||
import static me.lucko.luckperms.common.constants.Permission.MIGRATION;
|
import static me.lucko.luckperms.common.constants.Permission.MIGRATION;
|
||||||
|
|
||||||
@@ -67,6 +66,101 @@ public class MigrationBPermissions extends SubCommand<Object> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public MigrationBPermissions() {
|
||||||
|
super("bpermissions", "Migration from bPermissions", MIGRATION, Predicates.alwaysFalse(), null);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, Object o, List<String> args, String label) throws CommandException {
|
||||||
|
ProgressLogger log = new ProgressLogger("bPermissions");
|
||||||
|
log.addListener(plugin.getConsoleSender());
|
||||||
|
log.addListener(sender);
|
||||||
|
|
||||||
|
log.log("Starting.");
|
||||||
|
|
||||||
|
WorldManager worldManager = WorldManager.getInstance();
|
||||||
|
if (worldManager == null) {
|
||||||
|
log.logErr("Plugin not loaded.");
|
||||||
|
return CommandResult.STATE_ERROR;
|
||||||
|
}
|
||||||
|
|
||||||
|
log.log("Forcing the plugin to load all data. This could take a while.");
|
||||||
|
for (World world : worldManager.getAllWorlds()) {
|
||||||
|
log.log("Loading users in world " + world.getName());
|
||||||
|
Set<String> users = getUsers(world);
|
||||||
|
if (users == null) {
|
||||||
|
log.logErr("Couldn't get a list of users.");
|
||||||
|
return CommandResult.FAILURE;
|
||||||
|
}
|
||||||
|
AtomicInteger userLoadCount = new AtomicInteger(0);
|
||||||
|
users.forEach(s -> {
|
||||||
|
world.loadOne(s, CalculableType.USER);
|
||||||
|
log.logProgress("Forcefully loaded {} users so far.", userLoadCount.incrementAndGet());
|
||||||
|
});
|
||||||
|
}
|
||||||
|
log.log("Forcefully loaded all users.");
|
||||||
|
|
||||||
|
// Migrate one world at a time.
|
||||||
|
log.log("Starting world migration.");
|
||||||
|
for (World world : worldManager.getAllWorlds()) {
|
||||||
|
log.log("Migrating world: " + world.getName());
|
||||||
|
|
||||||
|
// Migrate all groups
|
||||||
|
log.log("Starting group migration in world " + world.getName() + ".");
|
||||||
|
AtomicInteger groupCount = new AtomicInteger(0);
|
||||||
|
for (Calculable group : world.getAll(CalculableType.GROUP)) {
|
||||||
|
String groupName = group.getName().toLowerCase();
|
||||||
|
if (group.getName().equalsIgnoreCase(world.getDefaultGroup())) {
|
||||||
|
groupName = "default";
|
||||||
|
}
|
||||||
|
|
||||||
|
// Make a LuckPerms group for the one being migrated.
|
||||||
|
plugin.getStorage().createAndLoadGroup(groupName, CreationCause.INTERNAL).join();
|
||||||
|
me.lucko.luckperms.common.core.model.Group lpGroup = plugin.getGroupManager().getIfLoaded(groupName);
|
||||||
|
|
||||||
|
migrateHolder(log, world, group, lpGroup);
|
||||||
|
plugin.getStorage().saveGroup(lpGroup);
|
||||||
|
|
||||||
|
log.logAllProgress("Migrated {} groups so far.", groupCount.incrementAndGet());
|
||||||
|
}
|
||||||
|
log.log("Migrated " + groupCount.get() + " groups in world " + world.getName() + ".");
|
||||||
|
|
||||||
|
// Migrate all users
|
||||||
|
log.log("Starting user migration in world " + world.getName() + ".");
|
||||||
|
AtomicInteger userCount = new AtomicInteger(0);
|
||||||
|
for (Calculable user : world.getAll(CalculableType.USER)) {
|
||||||
|
// There is no mention of UUIDs in the API. I assume that name = uuid. idk?
|
||||||
|
UUID uuid;
|
||||||
|
try {
|
||||||
|
uuid = UUID.fromString(user.getName());
|
||||||
|
} catch (IllegalArgumentException e) {
|
||||||
|
uuid = plugin.getUuidFromUsername(user.getName());
|
||||||
|
}
|
||||||
|
|
||||||
|
if (uuid == null) {
|
||||||
|
log.logErr("Unable to migrate user " + user.getName() + ". Cannot to get UUID.");
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Make a LuckPerms user for the one being migrated.
|
||||||
|
plugin.getStorage().loadUser(uuid, "null").join();
|
||||||
|
User lpUser = plugin.getUserManager().get(uuid);
|
||||||
|
|
||||||
|
migrateHolder(log, world, user, lpUser);
|
||||||
|
|
||||||
|
plugin.getStorage().saveUser(lpUser);
|
||||||
|
plugin.getUserManager().cleanup(lpUser);
|
||||||
|
|
||||||
|
log.logProgress("Migrated {} users so far.", userCount.incrementAndGet());
|
||||||
|
}
|
||||||
|
|
||||||
|
log.log("Migrated " + userCount.get() + " users in world " + world.getName() + ".");
|
||||||
|
}
|
||||||
|
|
||||||
|
log.log("Success! Migration complete.");
|
||||||
|
return CommandResult.SUCCESS;
|
||||||
|
}
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
private static Set<String> getUsers(World world) {
|
private static Set<String> getUsers(World world) {
|
||||||
try {
|
try {
|
||||||
@@ -93,33 +187,21 @@ public class MigrationBPermissions extends SubCommand<Object> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void migrateHolder(LuckPermsPlugin plugin, World world, Calculable c, PermissionHolder holder) {
|
private static void migrateHolder(ProgressLogger log, World world, Calculable c, PermissionHolder holder) {
|
||||||
// Migrate the groups permissions in this world
|
// Migrate the groups permissions in this world
|
||||||
for (Permission p : c.getPermissions()) {
|
for (Permission p : c.getPermissions()) {
|
||||||
try {
|
try {
|
||||||
holder.setPermission(p.name(), p.isTrue(), "global", world.getName());
|
holder.setPermission(p.name(), p.isTrue(), "global", world.getName());
|
||||||
LogEntry.build()
|
|
||||||
.actor(Constants.getConsoleUUID()).actorName(Constants.getConsoleName())
|
|
||||||
.acted(holder).action("set " + p.name() + " " + p.isTrue() + " global " + world.getName())
|
|
||||||
.build().submit(plugin);
|
|
||||||
} catch (Exception ex) {
|
} catch (Exception ex) {
|
||||||
if (!(ex instanceof ObjectAlreadyHasException)) {
|
log.handleException(ex);
|
||||||
ex.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Include any child permissions
|
// Include any child permissions
|
||||||
for (Map.Entry<String, Boolean> child : p.getChildren().entrySet()) {
|
for (Map.Entry<String, Boolean> child : p.getChildren().entrySet()) {
|
||||||
try {
|
try {
|
||||||
holder.setPermission(child.getKey(), child.getValue(), "global", world.getName());
|
holder.setPermission(child.getKey(), child.getValue(), "global", world.getName());
|
||||||
LogEntry.build()
|
|
||||||
.actor(Constants.getConsoleUUID()).actorName(Constants.getConsoleName())
|
|
||||||
.acted(holder).action("set " + child.getKey() + " " + child.getValue() + " global " + world.getName())
|
|
||||||
.build().submit(plugin);
|
|
||||||
} catch (Exception ex) {
|
} catch (Exception ex) {
|
||||||
if (!(ex instanceof ObjectAlreadyHasException)) {
|
log.handleException(ex);
|
||||||
ex.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -128,14 +210,8 @@ public class MigrationBPermissions extends SubCommand<Object> {
|
|||||||
for (Group parent : c.getGroups()) {
|
for (Group parent : c.getGroups()) {
|
||||||
try {
|
try {
|
||||||
holder.setPermission("group." + parent.getName(), true, "global", world.getName());
|
holder.setPermission("group." + parent.getName(), true, "global", world.getName());
|
||||||
LogEntry.build()
|
|
||||||
.actor(Constants.getConsoleUUID()).actorName(Constants.getConsoleName())
|
|
||||||
.acted(holder).action("setinherit " + parent.getName() + " global " + world.getName())
|
|
||||||
.build().submit(plugin);
|
|
||||||
} catch (Exception ex) {
|
} catch (Exception ex) {
|
||||||
if (!(ex instanceof ObjectAlreadyHasException)) {
|
log.handleException(ex);
|
||||||
ex.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -145,121 +221,18 @@ public class MigrationBPermissions extends SubCommand<Object> {
|
|||||||
String chatMeta = MetaUtils.escapeCharacters(meta.getValue());
|
String chatMeta = MetaUtils.escapeCharacters(meta.getValue());
|
||||||
try {
|
try {
|
||||||
holder.setPermission(meta.getKey().toLowerCase() + "." + c.getPriority() + "." + chatMeta, true);
|
holder.setPermission(meta.getKey().toLowerCase() + "." + c.getPriority() + "." + chatMeta, true);
|
||||||
LogEntry.build()
|
|
||||||
.actor(Constants.getConsoleUUID()).actorName(Constants.getConsoleName())
|
|
||||||
.acted(holder).action("set " + meta.getKey().toLowerCase() + "." + c.getPriority() + "." + chatMeta + " true")
|
|
||||||
.build().submit(plugin);
|
|
||||||
} catch (Exception ex) {
|
} catch (Exception ex) {
|
||||||
if (!(ex instanceof ObjectAlreadyHasException)) {
|
log.handleException(ex);
|
||||||
ex.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
holder.setPermission("meta." + meta.getKey() + "." + meta.getValue(), true, "global", world.getName());
|
holder.setPermission("meta." + meta.getKey() + "." + meta.getValue(), true, "global", world.getName());
|
||||||
LogEntry.build()
|
|
||||||
.actor(Constants.getConsoleUUID()).actorName(Constants.getConsoleName())
|
|
||||||
.acted(holder).action("set meta." + meta.getKey() + "." + meta.getValue() + " true global " + world.getName())
|
|
||||||
.build().submit(plugin);
|
|
||||||
} catch (Exception ex) {
|
} catch (Exception ex) {
|
||||||
if (!(ex instanceof ObjectAlreadyHasException)) {
|
log.handleException(ex);
|
||||||
ex.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public MigrationBPermissions() {
|
|
||||||
super("bpermissions", "Migration from bPermissions", MIGRATION, Predicates.alwaysFalse(), null);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, Object o, List<String> args, String label) throws CommandException {
|
|
||||||
final Logger log = plugin.getLog();
|
|
||||||
|
|
||||||
WorldManager worldManager = WorldManager.getInstance();
|
|
||||||
if (worldManager == null) {
|
|
||||||
log.severe("bPermissions Migration: Error -> bPermissions is not loaded.");
|
|
||||||
return CommandResult.STATE_ERROR;
|
|
||||||
}
|
|
||||||
|
|
||||||
log.info("bPermissions Migration: Forcing the plugin to load all data. This could take a while.");
|
|
||||||
for (World world : worldManager.getAllWorlds()) {
|
|
||||||
Set<String> users = getUsers(world);
|
|
||||||
if (users == null) {
|
|
||||||
log.severe("bPermissions Migration: Couldn't get a list of users.");
|
|
||||||
return CommandResult.FAILURE;
|
|
||||||
}
|
|
||||||
users.forEach(s -> world.loadOne(s, CalculableType.USER));
|
|
||||||
}
|
|
||||||
|
|
||||||
// Migrate one world at a time.
|
|
||||||
log.info("bPermissions Migration: Starting world migration.");
|
|
||||||
for (World world : worldManager.getAllWorlds()) {
|
|
||||||
log.info("bPermissions Migration: Migrating world: " + world.getName());
|
|
||||||
|
|
||||||
// Migrate all groups
|
|
||||||
log.info("bPermissions Migration: Starting group migration in world " + world.getName() + ".");
|
|
||||||
int groupCount = 0;
|
|
||||||
for (Calculable group : world.getAll(CalculableType.GROUP)) {
|
|
||||||
groupCount++;
|
|
||||||
String groupName = group.getName().toLowerCase();
|
|
||||||
if (group.getName().equalsIgnoreCase(world.getDefaultGroup())) {
|
|
||||||
groupName = "default";
|
|
||||||
}
|
|
||||||
|
|
||||||
// Make a LuckPerms group for the one being migrated.
|
|
||||||
plugin.getStorage().createAndLoadGroup(groupName).join();
|
|
||||||
me.lucko.luckperms.common.core.model.Group lpGroup = plugin.getGroupManager().getIfLoaded(groupName);
|
|
||||||
try {
|
|
||||||
LogEntry.build()
|
|
||||||
.actor(Constants.getConsoleUUID()).actorName(Constants.getConsoleName())
|
|
||||||
.acted(lpGroup).action("create")
|
|
||||||
.build().submit(plugin);
|
|
||||||
} catch (Exception ex) {
|
|
||||||
ex.printStackTrace();
|
|
||||||
}
|
|
||||||
|
|
||||||
migrateHolder(plugin, world, group, lpGroup);
|
|
||||||
plugin.getStorage().saveGroup(lpGroup);
|
|
||||||
}
|
|
||||||
log.info("bPermissions Migration: Migrated " + groupCount + " groups in world " + world.getName() + ".");
|
|
||||||
|
|
||||||
// Migrate all users
|
|
||||||
log.info("bPermissions Migration: Starting user migration in world " + world.getName() + ".");
|
|
||||||
int userCount = 0;
|
|
||||||
for (Calculable user : world.getAll(CalculableType.USER)) {
|
|
||||||
userCount++;
|
|
||||||
|
|
||||||
// There is no mention of UUIDs in the API. I assume that name = uuid. idk?
|
|
||||||
UUID uuid;
|
|
||||||
try {
|
|
||||||
uuid = UUID.fromString(user.getName());
|
|
||||||
} catch (IllegalArgumentException e) {
|
|
||||||
uuid = plugin.getUUID(user.getName());
|
|
||||||
}
|
|
||||||
|
|
||||||
if (uuid == null) {
|
|
||||||
log.info("bPermissions Migration: Unable to migrate user " + user.getName() + ". Unable to get UUID.");
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Make a LuckPerms user for the one being migrated.
|
|
||||||
plugin.getStorage().loadUser(uuid, "null").join();
|
|
||||||
User lpUser = plugin.getUserManager().get(uuid);
|
|
||||||
|
|
||||||
migrateHolder(plugin, world, user, lpUser);
|
|
||||||
|
|
||||||
plugin.getStorage().saveUser(lpUser);
|
|
||||||
plugin.getUserManager().cleanup(lpUser);
|
|
||||||
}
|
|
||||||
|
|
||||||
log.info("bPermissions Migration: Migrated " + userCount + " users in world " + world.getName() + ".");
|
|
||||||
}
|
|
||||||
|
|
||||||
log.info("bPermissions Migration: Success! Completed without any errors.");
|
|
||||||
return CommandResult.SUCCESS;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
+79
-93
@@ -22,18 +22,18 @@
|
|||||||
|
|
||||||
package me.lucko.luckperms.bukkit.migration;
|
package me.lucko.luckperms.bukkit.migration;
|
||||||
|
|
||||||
import me.lucko.luckperms.api.Logger;
|
import com.google.common.collect.Maps;
|
||||||
import me.lucko.luckperms.common.LuckPermsPlugin;
|
|
||||||
|
import me.lucko.luckperms.api.event.cause.CreationCause;
|
||||||
import me.lucko.luckperms.common.commands.Arg;
|
import me.lucko.luckperms.common.commands.Arg;
|
||||||
import me.lucko.luckperms.common.commands.CommandException;
|
import me.lucko.luckperms.common.commands.CommandException;
|
||||||
import me.lucko.luckperms.common.commands.CommandResult;
|
import me.lucko.luckperms.common.commands.CommandResult;
|
||||||
import me.lucko.luckperms.common.commands.SubCommand;
|
import me.lucko.luckperms.common.commands.SubCommand;
|
||||||
import me.lucko.luckperms.common.commands.sender.Sender;
|
import me.lucko.luckperms.common.commands.sender.Sender;
|
||||||
import me.lucko.luckperms.common.constants.Constants;
|
|
||||||
import me.lucko.luckperms.common.constants.Permission;
|
import me.lucko.luckperms.common.constants.Permission;
|
||||||
import me.lucko.luckperms.common.core.NodeFactory;
|
import me.lucko.luckperms.common.plugin.LuckPermsPlugin;
|
||||||
import me.lucko.luckperms.common.data.LogEntry;
|
|
||||||
import me.lucko.luckperms.common.utils.Predicates;
|
import me.lucko.luckperms.common.utils.Predicates;
|
||||||
|
import me.lucko.luckperms.common.utils.ProgressLogger;
|
||||||
import me.lucko.luckperms.exceptions.ObjectAlreadyHasException;
|
import me.lucko.luckperms.exceptions.ObjectAlreadyHasException;
|
||||||
import me.lucko.luckperms.exceptions.ObjectLacksException;
|
import me.lucko.luckperms.exceptions.ObjectLacksException;
|
||||||
|
|
||||||
@@ -43,50 +43,56 @@ import org.anjocaido.groupmanager.data.Group;
|
|||||||
import org.anjocaido.groupmanager.data.User;
|
import org.anjocaido.groupmanager.data.User;
|
||||||
import org.anjocaido.groupmanager.dataholder.WorldDataHolder;
|
import org.anjocaido.groupmanager.dataholder.WorldDataHolder;
|
||||||
import org.anjocaido.groupmanager.dataholder.worlds.WorldsHolder;
|
import org.anjocaido.groupmanager.dataholder.worlds.WorldsHolder;
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.World;
|
||||||
|
|
||||||
import java.util.AbstractMap;
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
import java.util.concurrent.atomic.AtomicInteger;
|
||||||
|
import java.util.function.Function;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
public class MigrationGroupManager extends SubCommand<Object> {
|
public class MigrationGroupManager extends SubCommand<Object> {
|
||||||
public MigrationGroupManager() {
|
public MigrationGroupManager() {
|
||||||
super("groupmanager", "Migration from GroupManager", Permission.MIGRATION, Predicates.is(0),
|
super("groupmanager", "Migration from GroupManager", Permission.MIGRATION, Predicates.is(0),
|
||||||
Arg.list(Arg.create("world names...", false, "a list of worlds to migrate permissions from"))
|
Arg.list(Arg.create("migrate as global", true, "if world permissions should be ignored, and just migrated as global"))
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, Object o, List<String> args, String label) throws CommandException {
|
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, Object o, List<String> args, String label) throws CommandException {
|
||||||
final Logger log = plugin.getLog();
|
ProgressLogger log = new ProgressLogger("GroupManager");
|
||||||
if (!plugin.isPluginLoaded("GroupManager")) {
|
log.addListener(plugin.getConsoleSender());
|
||||||
log.severe("GroupManager Migration: Error -> GroupManager is not loaded.");
|
log.addListener(sender);
|
||||||
|
|
||||||
|
log.log("Starting.");
|
||||||
|
|
||||||
|
if (!args.get(0).equalsIgnoreCase("true") && !args.get(0).equalsIgnoreCase("false")) {
|
||||||
|
log.logErr("Was expecting true/false, but got " + args.get(0) + " instead.");
|
||||||
|
return CommandResult.STATE_ERROR;
|
||||||
|
}
|
||||||
|
boolean migrateAsGlobal = Boolean.parseBoolean(args.get(0));
|
||||||
|
final Function<String, String> worldMappingFunc = s -> migrateAsGlobal ? "" : s;
|
||||||
|
|
||||||
|
if (!Bukkit.getPluginManager().isPluginEnabled("GroupManager")) {
|
||||||
|
log.logErr("Plugin not loaded.");
|
||||||
return CommandResult.STATE_ERROR;
|
return CommandResult.STATE_ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
final List<String> worlds = args.stream()
|
List<String> worlds = Bukkit.getWorlds().stream().map(World::getName).map(String::toLowerCase).collect(Collectors.toList());
|
||||||
.map(String::toLowerCase)
|
|
||||||
.collect(Collectors.toList());
|
|
||||||
|
|
||||||
GroupManager gm = (GroupManager) plugin.getPlugin("GroupManager");
|
GroupManager gm = (GroupManager) Bukkit.getPluginManager().getPlugin("GroupManager");
|
||||||
|
|
||||||
// Migrate Global Groups
|
// Migrate Global Groups
|
||||||
log.info("GroupManager Migration: Starting Global Group migration.");
|
log.log("Starting global group migration.");
|
||||||
GlobalGroups gg = GroupManager.getGlobalGroups();
|
GlobalGroups gg = GroupManager.getGlobalGroups();
|
||||||
|
|
||||||
|
AtomicInteger globalGroupCount = new AtomicInteger(0);
|
||||||
for (Group g : gg.getGroupList()) {
|
for (Group g : gg.getGroupList()) {
|
||||||
plugin.getStorage().createAndLoadGroup(g.getName().toLowerCase()).join();
|
plugin.getStorage().createAndLoadGroup(g.getName().toLowerCase(), CreationCause.INTERNAL).join();
|
||||||
me.lucko.luckperms.common.core.model.Group group = plugin.getGroupManager().getIfLoaded(g.getName().toLowerCase());
|
me.lucko.luckperms.common.core.model.Group group = plugin.getGroupManager().getIfLoaded(g.getName().toLowerCase());
|
||||||
try {
|
|
||||||
LogEntry.build()
|
|
||||||
.actor(Constants.getConsoleUUID()).actorName(Constants.getConsoleName())
|
|
||||||
.acted(group).action("create")
|
|
||||||
.build().submit(plugin);
|
|
||||||
} catch (Exception ex) {
|
|
||||||
ex.printStackTrace();
|
|
||||||
}
|
|
||||||
|
|
||||||
for (String node : g.getPermissionList()) {
|
for (String node : g.getPermissionList()) {
|
||||||
boolean value = true;
|
boolean value = true;
|
||||||
@@ -100,47 +106,45 @@ public class MigrationGroupManager extends SubCommand<Object> {
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
group.setPermission(node, value);
|
group.setPermission(node, value);
|
||||||
LogEntry.build()
|
|
||||||
.actor(Constants.getConsoleUUID()).actorName(Constants.getConsoleName())
|
|
||||||
.acted(group).action("set " + node + " " + value)
|
|
||||||
.build().submit(plugin);
|
|
||||||
} catch (Exception ex) {
|
} catch (Exception ex) {
|
||||||
if (!(ex instanceof ObjectAlreadyHasException)) {
|
log.handleException(ex);
|
||||||
ex.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for (String s : g.getInherits()) {
|
for (String s : g.getInherits()) {
|
||||||
try {
|
try {
|
||||||
group.setPermission("group." + s.toLowerCase(), true);
|
group.setPermission("group." + s.toLowerCase(), true);
|
||||||
LogEntry.build()
|
|
||||||
.actor(Constants.getConsoleUUID()).actorName(Constants.getConsoleName())
|
|
||||||
.acted(group).action("setinherit " + s.toLowerCase())
|
|
||||||
.build().submit(plugin);
|
|
||||||
} catch (Exception ex) {
|
} catch (Exception ex) {
|
||||||
if (!(ex instanceof ObjectAlreadyHasException)) {
|
log.handleException(ex);
|
||||||
ex.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
plugin.getStorage().saveGroup(group);
|
plugin.getStorage().saveGroup(group);
|
||||||
|
log.logAllProgress("Migrated {} groups so far.", globalGroupCount.incrementAndGet());
|
||||||
}
|
}
|
||||||
|
log.log("Migrated " + globalGroupCount.get() + " global groups");
|
||||||
|
|
||||||
|
// Collect data
|
||||||
|
|
||||||
|
// UUID --> Map<Entry<String, String>, Boolean> where k=world, v = node
|
||||||
Map<UUID, Map<Map.Entry<String, String>, Boolean>> users = new HashMap<>();
|
Map<UUID, Map<Map.Entry<String, String>, Boolean>> users = new HashMap<>();
|
||||||
|
// UUID --> primary group name
|
||||||
Map<UUID, String> primaryGroups = new HashMap<>();
|
Map<UUID, String> primaryGroups = new HashMap<>();
|
||||||
|
|
||||||
|
// String --> Map<Entry<String, String>, Boolean> where k=world, v = node
|
||||||
Map<String, Map<Map.Entry<String, String>, Boolean>> groups = new HashMap<>();
|
Map<String, Map<Map.Entry<String, String>, Boolean>> groups = new HashMap<>();
|
||||||
|
|
||||||
WorldsHolder wh = gm.getWorldsHolder();
|
WorldsHolder wh = gm.getWorldsHolder();
|
||||||
|
|
||||||
// Collect data for all users and groups.
|
// Collect data for all users and groups.
|
||||||
log.info("GroupManager Migration: Starting user and group migration.");
|
log.log("Collecting user and group data.");
|
||||||
for (String world : worlds) {
|
for (String world : worlds) {
|
||||||
world = world.toLowerCase();
|
world = world.toLowerCase();
|
||||||
|
log.log("Querying world " + world);
|
||||||
|
|
||||||
WorldDataHolder wdh = wh.getWorldData(world);
|
WorldDataHolder wdh = wh.getWorldData(world);
|
||||||
|
|
||||||
|
AtomicInteger groupWorldCount = new AtomicInteger(0);
|
||||||
for (Group g : wdh.getGroupList()) {
|
for (Group g : wdh.getGroupList()) {
|
||||||
groups.putIfAbsent(g.getName().toLowerCase(), new HashMap<>());
|
groups.putIfAbsent(g.getName().toLowerCase(), new HashMap<>());
|
||||||
|
|
||||||
@@ -154,19 +158,23 @@ public class MigrationGroupManager extends SubCommand<Object> {
|
|||||||
value = true;
|
value = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
groups.get(g.getName().toLowerCase()).put(new AbstractMap.SimpleEntry<>(world, node), value);
|
groups.get(g.getName().toLowerCase()).put(Maps.immutableEntry(worldMappingFunc.apply(world), node), value);
|
||||||
}
|
}
|
||||||
|
|
||||||
for (String s : g.getInherits()) {
|
for (String s : g.getInherits()) {
|
||||||
groups.get(g.getName().toLowerCase()).put(new AbstractMap.SimpleEntry<>(world, "group." + s.toLowerCase()), true);
|
groups.get(g.getName().toLowerCase()).put(Maps.immutableEntry(worldMappingFunc.apply(world), "group." + s.toLowerCase()), true);
|
||||||
}
|
}
|
||||||
|
log.logAllProgress("Migrated {} groups so far in world " + world, groupWorldCount.incrementAndGet());
|
||||||
}
|
}
|
||||||
|
log.log("Migrated " + groupWorldCount.get() + " groups in world " + world);
|
||||||
|
|
||||||
|
AtomicInteger userWorldCount = new AtomicInteger(0);
|
||||||
for (User user : wdh.getUserList()) {
|
for (User user : wdh.getUserList()) {
|
||||||
UUID uuid;
|
UUID uuid;
|
||||||
try {
|
try {
|
||||||
uuid = UUID.fromString(user.getUUID());
|
uuid = UUID.fromString(user.getUUID());
|
||||||
} catch (IllegalArgumentException e) {
|
} catch (IllegalArgumentException e) {
|
||||||
|
log.logErr("Could not parse UUID for user: " + user.getUUID());
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -182,66 +190,56 @@ public class MigrationGroupManager extends SubCommand<Object> {
|
|||||||
value = true;
|
value = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
users.get(uuid).put(new AbstractMap.SimpleEntry<>(world, node), value);
|
users.get(uuid).put(Maps.immutableEntry(worldMappingFunc.apply(world), node), value);
|
||||||
}
|
}
|
||||||
|
|
||||||
String finalWorld = world;
|
String finalWorld = worldMappingFunc.apply(world);
|
||||||
|
|
||||||
|
// Collect sub groups
|
||||||
users.get(uuid).putAll(user.subGroupListStringCopy().stream()
|
users.get(uuid).putAll(user.subGroupListStringCopy().stream()
|
||||||
.map(n -> "group." + n)
|
.map(n -> "group." + n)
|
||||||
.map(n -> new AbstractMap.SimpleEntry<>(finalWorld, n))
|
.map(n -> Maps.immutableEntry(finalWorld, n))
|
||||||
.collect(Collectors.toMap(n -> n, n -> true))
|
.collect(Collectors.toMap(n -> n, n -> true))
|
||||||
);
|
);
|
||||||
primaryGroups.put(uuid, user.getGroupName());
|
primaryGroups.put(uuid, user.getGroupName());
|
||||||
|
|
||||||
|
log.logProgress("Migrated {} users so far in world " + world, userWorldCount.incrementAndGet());
|
||||||
}
|
}
|
||||||
|
log.log("Migrated " + userWorldCount.get() + " users in world " + world);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
log.info("GroupManager Migration: All existing GroupManager data has been processed. Now beginning the import process.");
|
log.log("All data has now been processed, now starting the import process.");
|
||||||
log.info("GroupManager Migration: Found a total of " + users.size() + " users and " + groups.size() + " groups.");
|
log.log("Found a total of " + users.size() + " users and " + groups.size() + " groups.");
|
||||||
|
|
||||||
|
log.log("Starting group migration.");
|
||||||
|
AtomicInteger groupCount = new AtomicInteger(0);
|
||||||
for (Map.Entry<String, Map<Map.Entry<String, String>, Boolean>> e : groups.entrySet()) {
|
for (Map.Entry<String, Map<Map.Entry<String, String>, Boolean>> e : groups.entrySet()) {
|
||||||
plugin.getStorage().createAndLoadGroup(e.getKey()).join();
|
plugin.getStorage().createAndLoadGroup(e.getKey(), CreationCause.INTERNAL).join();
|
||||||
me.lucko.luckperms.common.core.model.Group group = plugin.getGroupManager().getIfLoaded(e.getKey());
|
me.lucko.luckperms.common.core.model.Group group = plugin.getGroupManager().getIfLoaded(e.getKey());
|
||||||
try {
|
|
||||||
LogEntry.build()
|
|
||||||
.actor(Constants.getConsoleUUID()).actorName(Constants.getConsoleName())
|
|
||||||
.acted(group).action("create")
|
|
||||||
.build().submit(plugin);
|
|
||||||
} catch (Exception ex) {
|
|
||||||
ex.printStackTrace();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
for (Map.Entry<Map.Entry<String, String>, Boolean> n : e.getValue().entrySet()) {
|
for (Map.Entry<Map.Entry<String, String>, Boolean> n : e.getValue().entrySet()) {
|
||||||
// n.key.key = world
|
// n.key.key = world
|
||||||
// n.key.value = node
|
// n.key.value = node
|
||||||
// n.value = true/false
|
// n.value = true/false
|
||||||
try {
|
try {
|
||||||
group.setPermission(NodeFactory.fromSerialisedNode("global-" + n.getKey().getKey() + "/" + n.getKey().getValue(), n.getValue()));
|
if (n.getKey().getKey().equals("")) {
|
||||||
|
group.setPermission(n.getKey().getValue(), n.getValue());
|
||||||
if (n.getKey().getValue().startsWith("group.")) {
|
|
||||||
String groupName = n.getKey().getValue().substring(6);
|
|
||||||
LogEntry.build()
|
|
||||||
.actor(Constants.getConsoleUUID()).actorName(Constants.getConsoleName())
|
|
||||||
.acted(group).action("setinherit " + groupName + " global " + n.getKey().getKey())
|
|
||||||
.build().submit(plugin);
|
|
||||||
} else {
|
} else {
|
||||||
LogEntry.build()
|
group.setPermission(n.getKey().getValue(), n.getValue(), "global", n.getKey().getKey());
|
||||||
.actor(Constants.getConsoleUUID()).actorName(Constants.getConsoleName())
|
|
||||||
.acted(group).action("set " + n.getKey().getValue() + " " + n.getValue() + " global " + n.getKey().getKey())
|
|
||||||
.build().submit(plugin);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
} catch (Exception ex) {
|
} catch (Exception ex) {
|
||||||
if (!(ex instanceof ObjectAlreadyHasException)) {
|
log.handleException(ex);
|
||||||
ex.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
plugin.getStorage().saveGroup(group);
|
plugin.getStorage().saveGroup(group);
|
||||||
|
log.logAllProgress("Migrated {} groups so far.", groupCount.incrementAndGet());
|
||||||
}
|
}
|
||||||
|
log.log("Migrated " + groupCount.get() + " groups");
|
||||||
|
|
||||||
|
log.log("Starting user migration.");
|
||||||
|
AtomicInteger userCount = new AtomicInteger(0);
|
||||||
for (Map.Entry<UUID, Map<Map.Entry<String, String>, Boolean>> e : users.entrySet()) {
|
for (Map.Entry<UUID, Map<Map.Entry<String, String>, Boolean>> e : users.entrySet()) {
|
||||||
plugin.getStorage().loadUser(e.getKey(), "null").join();
|
plugin.getStorage().loadUser(e.getKey(), "null").join();
|
||||||
me.lucko.luckperms.common.core.model.User user = plugin.getUserManager().get(e.getKey());
|
me.lucko.luckperms.common.core.model.User user = plugin.getUserManager().get(e.getKey());
|
||||||
@@ -251,25 +249,13 @@ public class MigrationGroupManager extends SubCommand<Object> {
|
|||||||
// n.key.value = node
|
// n.key.value = node
|
||||||
// n.value = true/false
|
// n.value = true/false
|
||||||
try {
|
try {
|
||||||
user.setPermission(NodeFactory.fromSerialisedNode("global-" + n.getKey().getKey() + "/" + n.getKey().getValue(), n.getValue()));
|
if (n.getKey().getKey().equals("")) {
|
||||||
|
user.setPermission(n.getKey().getValue(), n.getValue());
|
||||||
if (n.getKey().getValue().startsWith("group.")) {
|
|
||||||
String group = n.getKey().getValue().substring(6);
|
|
||||||
LogEntry.build()
|
|
||||||
.actor(Constants.getConsoleUUID()).actorName(Constants.getConsoleName())
|
|
||||||
.acted(user).action("addgroup " + group + " global " + n.getKey().getKey())
|
|
||||||
.build().submit(plugin);
|
|
||||||
} else {
|
} else {
|
||||||
LogEntry.build()
|
user.setPermission(n.getKey().getValue(), n.getValue(), "global", n.getKey().getKey());
|
||||||
.actor(Constants.getConsoleUUID()).actorName(Constants.getConsoleName())
|
|
||||||
.acted(user).action("set " + n.getKey().getValue() + " " + n.getValue() + " global " + n.getKey().getKey())
|
|
||||||
.build().submit(plugin);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
} catch (Exception ex) {
|
} catch (Exception ex) {
|
||||||
if (!(ex instanceof ObjectAlreadyHasException)) {
|
log.handleException(ex);
|
||||||
ex.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -277,20 +263,20 @@ public class MigrationGroupManager extends SubCommand<Object> {
|
|||||||
if (primaryGroup != null) {
|
if (primaryGroup != null) {
|
||||||
try {
|
try {
|
||||||
user.setPermission("group." + primaryGroup, true);
|
user.setPermission("group." + primaryGroup, true);
|
||||||
} catch (ObjectAlreadyHasException ignored) {
|
} catch (ObjectAlreadyHasException ignored) {}
|
||||||
}
|
|
||||||
user.setPrimaryGroup(primaryGroup);
|
user.setPrimaryGroup(primaryGroup);
|
||||||
try {
|
try {
|
||||||
user.unsetPermission("group.default");
|
user.unsetPermission("group.default");
|
||||||
} catch (ObjectLacksException ignored) {
|
} catch (ObjectLacksException ignored) {}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
plugin.getStorage().saveUser(user);
|
plugin.getStorage().saveUser(user);
|
||||||
plugin.getUserManager().cleanup(user);
|
plugin.getUserManager().cleanup(user);
|
||||||
|
log.logProgress("Migrated {} users so far.", userCount.incrementAndGet());
|
||||||
}
|
}
|
||||||
|
|
||||||
log.info("GroupManager Migration: Success! Completed without any errors.");
|
log.log("Migrated " + userCount.get() + " users.");
|
||||||
|
log.log("Success! Migration complete.");
|
||||||
return CommandResult.SUCCESS;
|
return CommandResult.SUCCESS;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
+105
-190
@@ -22,27 +22,23 @@
|
|||||||
|
|
||||||
package me.lucko.luckperms.bukkit.migration;
|
package me.lucko.luckperms.bukkit.migration;
|
||||||
|
|
||||||
import me.lucko.luckperms.api.Logger;
|
|
||||||
import me.lucko.luckperms.api.MetaUtils;
|
import me.lucko.luckperms.api.MetaUtils;
|
||||||
import me.lucko.luckperms.api.PlatformType;
|
import me.lucko.luckperms.api.event.cause.CreationCause;
|
||||||
import me.lucko.luckperms.common.LuckPermsPlugin;
|
|
||||||
import me.lucko.luckperms.common.commands.Arg;
|
|
||||||
import me.lucko.luckperms.common.commands.CommandException;
|
import me.lucko.luckperms.common.commands.CommandException;
|
||||||
import me.lucko.luckperms.common.commands.CommandResult;
|
import me.lucko.luckperms.common.commands.CommandResult;
|
||||||
import me.lucko.luckperms.common.commands.SubCommand;
|
import me.lucko.luckperms.common.commands.SubCommand;
|
||||||
import me.lucko.luckperms.common.commands.sender.Sender;
|
import me.lucko.luckperms.common.commands.sender.Sender;
|
||||||
import me.lucko.luckperms.common.constants.Constants;
|
|
||||||
import me.lucko.luckperms.common.constants.Permission;
|
import me.lucko.luckperms.common.constants.Permission;
|
||||||
import me.lucko.luckperms.common.core.model.Group;
|
import me.lucko.luckperms.common.core.model.Group;
|
||||||
import me.lucko.luckperms.common.core.model.User;
|
import me.lucko.luckperms.common.core.model.User;
|
||||||
import me.lucko.luckperms.common.data.LogEntry;
|
import me.lucko.luckperms.common.plugin.LuckPermsPlugin;
|
||||||
import me.lucko.luckperms.common.utils.Predicates;
|
import me.lucko.luckperms.common.utils.Predicates;
|
||||||
|
import me.lucko.luckperms.common.utils.ProgressLogger;
|
||||||
import me.lucko.luckperms.exceptions.ObjectAlreadyHasException;
|
import me.lucko.luckperms.exceptions.ObjectAlreadyHasException;
|
||||||
|
import me.lucko.luckperms.exceptions.ObjectLacksException;
|
||||||
|
|
||||||
import java.lang.reflect.Field;
|
import org.bukkit.Bukkit;
|
||||||
import java.util.List;
|
import org.bukkit.World;
|
||||||
import java.util.UUID;
|
|
||||||
import java.util.stream.Collectors;
|
|
||||||
|
|
||||||
import ru.tehkode.permissions.NativeInterface;
|
import ru.tehkode.permissions.NativeInterface;
|
||||||
import ru.tehkode.permissions.PermissionGroup;
|
import ru.tehkode.permissions.PermissionGroup;
|
||||||
@@ -50,33 +46,34 @@ import ru.tehkode.permissions.PermissionManager;
|
|||||||
import ru.tehkode.permissions.PermissionUser;
|
import ru.tehkode.permissions.PermissionUser;
|
||||||
import ru.tehkode.permissions.bukkit.PermissionsEx;
|
import ru.tehkode.permissions.bukkit.PermissionsEx;
|
||||||
|
|
||||||
|
import java.lang.reflect.Field;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.UUID;
|
||||||
|
import java.util.concurrent.atomic.AtomicInteger;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
public class MigrationPermissionsEx extends SubCommand<Object> {
|
public class MigrationPermissionsEx extends SubCommand<Object> {
|
||||||
public MigrationPermissionsEx() {
|
public MigrationPermissionsEx() {
|
||||||
super("permissionsex", "Migration from PermissionsEx", Permission.MIGRATION, Predicates.alwaysFalse(),
|
super("permissionsex", "Migration from PermissionsEx", Permission.MIGRATION, Predicates.alwaysFalse(), null);
|
||||||
Arg.list(Arg.create("world names...", false, "a list of worlds to migrate permissions from"))
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("deprecation")
|
@SuppressWarnings("deprecation")
|
||||||
@Override
|
@Override
|
||||||
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, Object o, List<String> args, String label) throws CommandException {
|
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, Object o, List<String> args, String label) throws CommandException {
|
||||||
final Logger log = plugin.getLog();
|
ProgressLogger log = new ProgressLogger("PermissionsEx");
|
||||||
if (!plugin.isPluginLoaded("PermissionsEx")) {
|
log.addListener(plugin.getConsoleSender());
|
||||||
log.severe("PermissionsEx Migration: Error -> PermissionsEx is not loaded.");
|
log.addListener(sender);
|
||||||
|
|
||||||
|
log.log("Starting.");
|
||||||
|
|
||||||
|
if (!Bukkit.getPluginManager().isPluginEnabled("PermissionsEx")) {
|
||||||
|
log.logErr("Plugin not loaded.");
|
||||||
return CommandResult.STATE_ERROR;
|
return CommandResult.STATE_ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (plugin.getType() != PlatformType.BUKKIT) {
|
List<String> worlds = Bukkit.getWorlds().stream().map(World::getName).map(String::toLowerCase).collect(Collectors.toList());
|
||||||
// Sponge uses a completely different version of PEX.
|
|
||||||
log.severe("PEX import is not supported on this platform.");
|
|
||||||
return CommandResult.STATE_ERROR;
|
|
||||||
}
|
|
||||||
|
|
||||||
final List<String> worlds = args.stream()
|
PermissionsEx pex = (PermissionsEx) Bukkit.getPluginManager().getPlugin("PermissionsEx");
|
||||||
.map(String::toLowerCase)
|
|
||||||
.collect(Collectors.toList());
|
|
||||||
|
|
||||||
PermissionsEx pex = (PermissionsEx) plugin.getPlugin("PermissionsEx");
|
|
||||||
PermissionManager manager = pex.getPermissionsManager();
|
PermissionManager manager = pex.getPermissionsManager();
|
||||||
|
|
||||||
NativeInterface ni;
|
NativeInterface ni;
|
||||||
@@ -89,28 +86,22 @@ public class MigrationPermissionsEx extends SubCommand<Object> {
|
|||||||
return CommandResult.FAILURE;
|
return CommandResult.FAILURE;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Migrate all groups.
|
log.log("Calculating group weightings.");
|
||||||
log.info("PermissionsEx Migration: Starting group migration.");
|
int maxWeight = 0;
|
||||||
|
|
||||||
int maxGroupWeight = 0;
|
|
||||||
int groupCount = 0;
|
|
||||||
|
|
||||||
for (PermissionGroup group : manager.getGroupList()) {
|
for (PermissionGroup group : manager.getGroupList()) {
|
||||||
int groupWeight = group.getWeight() * -1;
|
maxWeight = Math.max(maxWeight, group.getRank());
|
||||||
groupCount++;
|
}
|
||||||
maxGroupWeight = Math.max(maxGroupWeight, groupWeight);
|
maxWeight += 5;
|
||||||
|
|
||||||
|
// Migrate all groups.
|
||||||
|
log.log("Starting group migration.");
|
||||||
|
AtomicInteger groupCount = new AtomicInteger(0);
|
||||||
|
for (PermissionGroup group : manager.getGroupList()) {
|
||||||
|
int groupWeight = maxWeight - group.getRank();
|
||||||
|
|
||||||
final String name = group.getName().toLowerCase();
|
final String name = group.getName().toLowerCase();
|
||||||
plugin.getStorage().createAndLoadGroup(name).join();
|
plugin.getStorage().createAndLoadGroup(name, CreationCause.INTERNAL).join();
|
||||||
Group lpGroup = plugin.getGroupManager().getIfLoaded(name);
|
Group lpGroup = plugin.getGroupManager().getIfLoaded(name);
|
||||||
try {
|
|
||||||
LogEntry.build()
|
|
||||||
.actor(Constants.getConsoleUUID()).actorName(Constants.getConsoleName())
|
|
||||||
.acted(lpGroup).action("create")
|
|
||||||
.build().submit(plugin);
|
|
||||||
} catch (Exception ex) {
|
|
||||||
ex.printStackTrace();
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
for (String node : group.getOwnPermissions(null)) {
|
for (String node : group.getOwnPermissions(null)) {
|
||||||
@@ -122,40 +113,26 @@ public class MigrationPermissionsEx extends SubCommand<Object> {
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
lpGroup.setPermission(node, value);
|
lpGroup.setPermission(node, value);
|
||||||
LogEntry.build()
|
|
||||||
.actor(Constants.getConsoleUUID()).actorName(Constants.getConsoleName())
|
|
||||||
.acted(lpGroup).action("set " + node + " " + value)
|
|
||||||
.build().submit(plugin);
|
|
||||||
} catch (Exception ex) {
|
} catch (Exception ex) {
|
||||||
if (!(ex instanceof ObjectAlreadyHasException)) {
|
log.handleException(ex);
|
||||||
ex.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (NullPointerException ignored) {
|
} catch (NullPointerException ignored) {
|
||||||
// Probably won't happen. I have no API docs on getOwnPermissions#null though.
|
// No docs on if #getOwnPermissions(null) is ok. Should be fine though.
|
||||||
}
|
}
|
||||||
|
|
||||||
if (worlds != null && !worlds.isEmpty()) {
|
for (String world : worlds) {
|
||||||
for (String world : worlds) {
|
for (String node : group.getOwnPermissions(world)) {
|
||||||
for (String node : group.getOwnPermissions(world)) {
|
boolean value = true;
|
||||||
boolean value = true;
|
if (node.startsWith("-")) {
|
||||||
if (node.startsWith("-")) {
|
node = node.substring(1);
|
||||||
node = node.substring(1);
|
value = false;
|
||||||
value = false;
|
}
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
lpGroup.setPermission(node, value, "global", world);
|
lpGroup.setPermission(node, value, "global", world.toLowerCase());
|
||||||
LogEntry.build()
|
} catch (Exception ex) {
|
||||||
.actor(Constants.getConsoleUUID()).actorName(Constants.getConsoleName())
|
log.handleException(ex);
|
||||||
.acted(lpGroup).action("set " + node + " " + value + " global " + world)
|
|
||||||
.build().submit(plugin);
|
|
||||||
} catch (Exception ex) {
|
|
||||||
if (!(ex instanceof ObjectAlreadyHasException)) {
|
|
||||||
ex.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -163,31 +140,17 @@ public class MigrationPermissionsEx extends SubCommand<Object> {
|
|||||||
for (PermissionGroup g : group.getParents()) {
|
for (PermissionGroup g : group.getParents()) {
|
||||||
try {
|
try {
|
||||||
lpGroup.setPermission("group." + g.getName().toLowerCase(), true);
|
lpGroup.setPermission("group." + g.getName().toLowerCase(), true);
|
||||||
LogEntry.build()
|
|
||||||
.actor(Constants.getConsoleUUID()).actorName(Constants.getConsoleName())
|
|
||||||
.acted(lpGroup).action("setinherit " + g.getName().toLowerCase())
|
|
||||||
.build().submit(plugin);
|
|
||||||
} catch (Exception ex) {
|
} catch (Exception ex) {
|
||||||
if (!(ex instanceof ObjectAlreadyHasException)) {
|
log.handleException(ex);
|
||||||
ex.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (worlds != null && !worlds.isEmpty()) {
|
for (String world : worlds) {
|
||||||
for (String world : worlds) {
|
for (PermissionGroup g : group.getParents(world)) {
|
||||||
for (PermissionGroup g : group.getParents(world)) {
|
try {
|
||||||
try {
|
lpGroup.setPermission("group." + g.getName().toLowerCase(), true, "global", world.toLowerCase());
|
||||||
lpGroup.setPermission("group." + g.getName().toLowerCase(), true, "global", world);
|
} catch (Exception ex) {
|
||||||
LogEntry.build()
|
log.handleException(ex);
|
||||||
.actor(Constants.getConsoleUUID()).actorName(Constants.getConsoleName())
|
|
||||||
.acted(lpGroup).action("setinherit " + g.getName().toLowerCase() + " global " + world)
|
|
||||||
.build().submit(plugin);
|
|
||||||
} catch (Exception ex) {
|
|
||||||
if (!(ex instanceof ObjectAlreadyHasException)) {
|
|
||||||
ex.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -199,14 +162,8 @@ public class MigrationPermissionsEx extends SubCommand<Object> {
|
|||||||
prefix = MetaUtils.escapeCharacters(prefix);
|
prefix = MetaUtils.escapeCharacters(prefix);
|
||||||
try {
|
try {
|
||||||
lpGroup.setPermission("prefix." + groupWeight + "." + prefix, true);
|
lpGroup.setPermission("prefix." + groupWeight + "." + prefix, true);
|
||||||
LogEntry.build()
|
|
||||||
.actor(Constants.getConsoleUUID()).actorName(Constants.getConsoleName())
|
|
||||||
.acted(lpGroup).action("set prefix." + groupWeight + "." + prefix + " true")
|
|
||||||
.build().submit(plugin);
|
|
||||||
} catch (Exception ex) {
|
} catch (Exception ex) {
|
||||||
if (!(ex instanceof ObjectAlreadyHasException)) {
|
log.handleException(ex);
|
||||||
ex.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -214,46 +171,40 @@ public class MigrationPermissionsEx extends SubCommand<Object> {
|
|||||||
suffix = MetaUtils.escapeCharacters(suffix);
|
suffix = MetaUtils.escapeCharacters(suffix);
|
||||||
try {
|
try {
|
||||||
lpGroup.setPermission("suffix." + groupWeight + "." + suffix, true);
|
lpGroup.setPermission("suffix." + groupWeight + "." + suffix, true);
|
||||||
LogEntry.build()
|
|
||||||
.actor(Constants.getConsoleUUID()).actorName(Constants.getConsoleName())
|
|
||||||
.acted(lpGroup).action("set suffix." + groupWeight + "." + suffix + " true")
|
|
||||||
.build().submit(plugin);
|
|
||||||
} catch (Exception ex) {
|
} catch (Exception ex) {
|
||||||
if (!(ex instanceof ObjectAlreadyHasException)) {
|
log.handleException(ex);
|
||||||
ex.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
plugin.getStorage().saveGroup(lpGroup);
|
plugin.getStorage().saveGroup(lpGroup);
|
||||||
|
log.logAllProgress("Migrated {} groups so far.", groupCount.incrementAndGet());
|
||||||
}
|
}
|
||||||
|
log.log("Migrated " + groupCount.get() + " groups");
|
||||||
log.info("PermissionsEx Migration: Migrated " + groupCount + " groups");
|
|
||||||
|
|
||||||
// Migrate all users
|
// Migrate all users
|
||||||
log.info("PermissionsEx Migration: Starting user migration.");
|
log.log("Starting user migration.");
|
||||||
int userCount = 0;
|
AtomicInteger userCount = new AtomicInteger(0);
|
||||||
maxGroupWeight++;
|
|
||||||
for (PermissionUser user : manager.getUsers()) {
|
|
||||||
UUID u = null;
|
|
||||||
|
|
||||||
|
// Increment the max weight from the group migrations. All user meta should override.
|
||||||
|
maxWeight += 5;
|
||||||
|
|
||||||
|
for (PermissionUser user : manager.getUsers()) {
|
||||||
|
UUID u;
|
||||||
try {
|
try {
|
||||||
u = UUID.fromString(user.getIdentifier());
|
u = UUID.fromString(user.getIdentifier());
|
||||||
} catch (IllegalArgumentException e) {
|
} catch (IllegalArgumentException e) {
|
||||||
u = ni.nameToUUID(user.getIdentifier());
|
u = ni.nameToUUID(user.getIdentifier());
|
||||||
if (u == null) {
|
if (u == null) {
|
||||||
u = plugin.getUUID(user.getIdentifier());
|
u = plugin.getUuidFromUsername(user.getIdentifier());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (u == null) {
|
if (u == null) {
|
||||||
log.severe("Unable to get a UUID for user identifier: " + user.getIdentifier());
|
log.logErr("Unable to get a UUID for user identifier: " + user.getIdentifier());
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
userCount++;
|
plugin.getStorage().loadUser(u, user.getName()).join();
|
||||||
plugin.getStorage().loadUser(u, "null").join();
|
|
||||||
User lpUser = plugin.getUserManager().get(u);
|
User lpUser = plugin.getUserManager().get(u);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
@@ -266,40 +217,26 @@ public class MigrationPermissionsEx extends SubCommand<Object> {
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
lpUser.setPermission(node, value);
|
lpUser.setPermission(node, value);
|
||||||
LogEntry.build()
|
|
||||||
.actor(Constants.getConsoleUUID()).actorName(Constants.getConsoleName())
|
|
||||||
.acted(lpUser).action("set " + node + " " + value)
|
|
||||||
.build().submit(plugin);
|
|
||||||
} catch (Exception ex) {
|
} catch (Exception ex) {
|
||||||
if (!(ex instanceof ObjectAlreadyHasException)) {
|
log.handleException(ex);
|
||||||
ex.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (NullPointerException ignored) {
|
} catch (NullPointerException ignored) {
|
||||||
// Probably won't happen. I have no API docs on getOwnPermissions#null though.
|
// No docs on if #getOwnPermissions(null) is ok. Should be fine though.
|
||||||
}
|
}
|
||||||
|
|
||||||
if (worlds != null && !worlds.isEmpty()) {
|
for (String world : worlds) {
|
||||||
for (String world : worlds) {
|
for (String node : user.getOwnPermissions(world)) {
|
||||||
for (String node : user.getOwnPermissions(world)) {
|
boolean value = true;
|
||||||
boolean value = true;
|
if (node.startsWith("-")) {
|
||||||
if (node.startsWith("-")) {
|
node = node.substring(1);
|
||||||
node = node.substring(1);
|
value = false;
|
||||||
value = false;
|
}
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
lpUser.setPermission(node, value, "global", world);
|
lpUser.setPermission(node, value, "global", world.toLowerCase());
|
||||||
LogEntry.build()
|
} catch (Exception ex) {
|
||||||
.actor(Constants.getConsoleUUID()).actorName(Constants.getConsoleName())
|
log.handleException(ex);
|
||||||
.acted(lpUser).action("set " + node + " " + value + " global " + world)
|
|
||||||
.build().submit(plugin);
|
|
||||||
} catch (Exception ex) {
|
|
||||||
if (!(ex instanceof ObjectAlreadyHasException)) {
|
|
||||||
ex.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -307,31 +244,17 @@ public class MigrationPermissionsEx extends SubCommand<Object> {
|
|||||||
for (String s : user.getGroupNames()) {
|
for (String s : user.getGroupNames()) {
|
||||||
try {
|
try {
|
||||||
lpUser.setPermission("group." + s.toLowerCase(), true);
|
lpUser.setPermission("group." + s.toLowerCase(), true);
|
||||||
LogEntry.build()
|
|
||||||
.actor(Constants.getConsoleUUID()).actorName(Constants.getConsoleName())
|
|
||||||
.acted(lpUser).action("addgroup " + s.toLowerCase())
|
|
||||||
.build().submit(plugin);
|
|
||||||
} catch (Exception ex) {
|
} catch (Exception ex) {
|
||||||
if (!(ex instanceof ObjectAlreadyHasException)) {
|
log.handleException(ex);
|
||||||
ex.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (worlds != null && !worlds.isEmpty()) {
|
for (String world : worlds) {
|
||||||
for (String world : worlds) {
|
for (String s : user.getGroupNames(world)) {
|
||||||
for (String s : user.getGroupNames(world)) {
|
try {
|
||||||
try {
|
lpUser.setPermission("group." + s.toLowerCase(), true, "global", world.toLowerCase());
|
||||||
lpUser.setPermission("group." + s.toLowerCase(), true, "global", world);
|
} catch (Exception ex) {
|
||||||
LogEntry.build()
|
log.handleException(ex);
|
||||||
.actor(Constants.getConsoleUUID()).actorName(Constants.getConsoleName())
|
|
||||||
.acted(lpUser).action("addgroup " + s.toLowerCase() + " global " + world)
|
|
||||||
.build().submit(plugin);
|
|
||||||
} catch (Exception ex) {
|
|
||||||
if (!(ex instanceof ObjectAlreadyHasException)) {
|
|
||||||
ex.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -342,56 +265,48 @@ public class MigrationPermissionsEx extends SubCommand<Object> {
|
|||||||
if (prefix != null && !prefix.equals("")) {
|
if (prefix != null && !prefix.equals("")) {
|
||||||
prefix = MetaUtils.escapeCharacters(prefix);
|
prefix = MetaUtils.escapeCharacters(prefix);
|
||||||
try {
|
try {
|
||||||
lpUser.setPermission("prefix." + maxGroupWeight + "." + prefix, true);
|
lpUser.setPermission("prefix." + maxWeight + "." + prefix, true);
|
||||||
LogEntry.build()
|
|
||||||
.actor(Constants.getConsoleUUID()).actorName(Constants.getConsoleName())
|
|
||||||
.acted(lpUser).action("set prefix." + maxGroupWeight + "." + prefix + " true")
|
|
||||||
.build().submit(plugin);
|
|
||||||
} catch (Exception ex) {
|
} catch (Exception ex) {
|
||||||
if (!(ex instanceof ObjectAlreadyHasException)) {
|
log.handleException(ex);
|
||||||
ex.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (suffix != null && !suffix.equals("")) {
|
if (suffix != null && !suffix.equals("")) {
|
||||||
suffix = MetaUtils.escapeCharacters(suffix);
|
suffix = MetaUtils.escapeCharacters(suffix);
|
||||||
try {
|
try {
|
||||||
lpUser.setPermission("suffix." + maxGroupWeight + "." + suffix, true);
|
lpUser.setPermission("suffix." + maxWeight + "." + suffix, true);
|
||||||
LogEntry.build()
|
|
||||||
.actor(Constants.getConsoleUUID()).actorName(Constants.getConsoleName())
|
|
||||||
.acted(lpUser).action("set suffix." + maxGroupWeight + "." + suffix + " true")
|
|
||||||
.build().submit(plugin);
|
|
||||||
} catch (Exception ex) {
|
} catch (Exception ex) {
|
||||||
if (!(ex instanceof ObjectAlreadyHasException)) {
|
log.handleException(ex);
|
||||||
ex.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Lowest rank is the highest group #logic
|
||||||
String primary = null;
|
String primary = null;
|
||||||
int weight = -100;
|
int weight = Integer.MAX_VALUE;
|
||||||
for (PermissionGroup group : user.getOwnParents()) {
|
for (PermissionGroup group : user.getOwnParents()) {
|
||||||
if (group.getRank() > weight) {
|
if (group.getRank() < weight) {
|
||||||
primary = group.getName();
|
primary = group.getName();
|
||||||
weight = group.getWeight();
|
weight = group.getRank();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (primary != null) {
|
if (primary != null && !primary.equalsIgnoreCase("default")) {
|
||||||
try {
|
try {
|
||||||
lpUser.setPermission("group." + primary.toLowerCase(), true);
|
lpUser.setPermission("group." + primary.toLowerCase(), true);
|
||||||
} catch (ObjectAlreadyHasException ignored) {
|
} catch (ObjectAlreadyHasException ignored) {}
|
||||||
}
|
|
||||||
lpUser.setPrimaryGroup(primary);
|
lpUser.setPrimaryGroup(primary);
|
||||||
|
try {
|
||||||
|
lpUser.unsetPermission("group.default");
|
||||||
|
} catch (ObjectLacksException ignored) {}
|
||||||
}
|
}
|
||||||
|
|
||||||
plugin.getUserManager().cleanup(lpUser);
|
plugin.getUserManager().cleanup(lpUser);
|
||||||
plugin.getStorage().saveUser(lpUser);
|
plugin.getStorage().saveUser(lpUser);
|
||||||
|
log.logProgress("Migrated {} users so far.", userCount.incrementAndGet());
|
||||||
}
|
}
|
||||||
|
|
||||||
log.info("PermissionsEx Migration: Migrated " + userCount + " users.");
|
log.log("Migrated " + userCount.get() + " users.");
|
||||||
log.info("PermissionsEx Migration: Success! Completed without any errors.");
|
log.log("Success! Migration complete.");
|
||||||
return CommandResult.SUCCESS;
|
return CommandResult.SUCCESS;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
+126
-219
@@ -22,8 +22,6 @@
|
|||||||
|
|
||||||
package me.lucko.luckperms.bukkit.migration;
|
package me.lucko.luckperms.bukkit.migration;
|
||||||
|
|
||||||
import lombok.Cleanup;
|
|
||||||
|
|
||||||
import com.github.cheesesoftware.PowerfulPermsAPI.CachedGroup;
|
import com.github.cheesesoftware.PowerfulPermsAPI.CachedGroup;
|
||||||
import com.github.cheesesoftware.PowerfulPermsAPI.Group;
|
import com.github.cheesesoftware.PowerfulPermsAPI.Group;
|
||||||
import com.github.cheesesoftware.PowerfulPermsAPI.Permission;
|
import com.github.cheesesoftware.PowerfulPermsAPI.Permission;
|
||||||
@@ -33,21 +31,20 @@ import com.github.cheesesoftware.PowerfulPermsAPI.ResultRunnable;
|
|||||||
import com.google.common.util.concurrent.ListenableFuture;
|
import com.google.common.util.concurrent.ListenableFuture;
|
||||||
import com.zaxxer.hikari.HikariDataSource;
|
import com.zaxxer.hikari.HikariDataSource;
|
||||||
|
|
||||||
import me.lucko.luckperms.api.Logger;
|
import me.lucko.luckperms.api.event.cause.CreationCause;
|
||||||
import me.lucko.luckperms.api.data.Callback;
|
|
||||||
import me.lucko.luckperms.bukkit.migration.utils.LPResultRunnable;
|
import me.lucko.luckperms.bukkit.migration.utils.LPResultRunnable;
|
||||||
import me.lucko.luckperms.common.LuckPermsPlugin;
|
|
||||||
import me.lucko.luckperms.common.commands.Arg;
|
import me.lucko.luckperms.common.commands.Arg;
|
||||||
import me.lucko.luckperms.common.commands.CommandException;
|
import me.lucko.luckperms.common.commands.CommandException;
|
||||||
import me.lucko.luckperms.common.commands.CommandResult;
|
import me.lucko.luckperms.common.commands.CommandResult;
|
||||||
import me.lucko.luckperms.common.commands.SubCommand;
|
import me.lucko.luckperms.common.commands.SubCommand;
|
||||||
import me.lucko.luckperms.common.commands.sender.Sender;
|
import me.lucko.luckperms.common.commands.sender.Sender;
|
||||||
import me.lucko.luckperms.common.constants.Constants;
|
|
||||||
import me.lucko.luckperms.common.core.model.PermissionHolder;
|
import me.lucko.luckperms.common.core.model.PermissionHolder;
|
||||||
import me.lucko.luckperms.common.core.model.User;
|
import me.lucko.luckperms.common.core.model.User;
|
||||||
import me.lucko.luckperms.common.data.LogEntry;
|
import me.lucko.luckperms.common.plugin.LuckPermsPlugin;
|
||||||
import me.lucko.luckperms.common.utils.Predicates;
|
import me.lucko.luckperms.common.utils.Predicates;
|
||||||
import me.lucko.luckperms.exceptions.ObjectAlreadyHasException;
|
import me.lucko.luckperms.common.utils.ProgressLogger;
|
||||||
|
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
|
|
||||||
import java.lang.reflect.InvocationTargetException;
|
import java.lang.reflect.InvocationTargetException;
|
||||||
import java.lang.reflect.Method;
|
import java.lang.reflect.Method;
|
||||||
@@ -64,25 +61,18 @@ import java.util.Set;
|
|||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
import java.util.concurrent.CountDownLatch;
|
import java.util.concurrent.CountDownLatch;
|
||||||
import java.util.concurrent.ExecutionException;
|
import java.util.concurrent.ExecutionException;
|
||||||
|
import java.util.concurrent.atomic.AtomicInteger;
|
||||||
|
import java.util.function.Consumer;
|
||||||
|
|
||||||
import static me.lucko.luckperms.common.constants.Permission.MIGRATION;
|
import static me.lucko.luckperms.common.constants.Permission.MIGRATION;
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
|
||||||
public class MigrationPowerfulPerms extends SubCommand<Object> {
|
public class MigrationPowerfulPerms extends SubCommand<Object> {
|
||||||
/* <sadness>
|
|
||||||
The PowerfulPerms API is a complete joke. Seriously, it would probably be easier reflecting into the actual plugin.
|
|
||||||
Methods move about randomly every version...
|
|
||||||
|
|
||||||
What kind of API requires reflection to function with multiple versions...
|
|
||||||
Doesn't that just defeat the whole god damn point of having an API in the first place?
|
|
||||||
Whatever happened to depreciation?
|
|
||||||
</sadness> */
|
|
||||||
|
|
||||||
private static Method getPlayerPermissionsMethod = null;
|
private static Method getPlayerPermissionsMethod = null;
|
||||||
private static Method getPlayerGroupsMethod = null;
|
private static Method getPlayerGroupsMethod = null;
|
||||||
private static Method getGroupMethod = null;
|
private static Method getGroupMethod = null;
|
||||||
|
|
||||||
// lol
|
// lol, nice "api"
|
||||||
private static boolean superLegacy = false;
|
private static boolean superLegacy = false;
|
||||||
private static boolean legacy = false;
|
private static boolean legacy = false;
|
||||||
|
|
||||||
@@ -90,29 +80,25 @@ public class MigrationPowerfulPerms extends SubCommand<Object> {
|
|||||||
try {
|
try {
|
||||||
Class.forName("com.github.cheesesoftware.PowerfulPermsAPI.ResponseRunnable");
|
Class.forName("com.github.cheesesoftware.PowerfulPermsAPI.ResponseRunnable");
|
||||||
legacy = true;
|
legacy = true;
|
||||||
} catch (ClassNotFoundException ignored) {
|
} catch (ClassNotFoundException ignored) {}
|
||||||
}
|
|
||||||
|
|
||||||
if (legacy) {
|
if (legacy) {
|
||||||
try {
|
try {
|
||||||
getPlayerPermissionsMethod = PermissionManager.class.getMethod("getPlayerOwnPermissions", UUID.class, ResultRunnable.class);
|
getPlayerPermissionsMethod = PermissionManager.class.getMethod("getPlayerOwnPermissions", UUID.class, ResultRunnable.class);
|
||||||
getPlayerPermissionsMethod.setAccessible(true);
|
getPlayerPermissionsMethod.setAccessible(true);
|
||||||
} catch (NoSuchMethodException ignored) {
|
} catch (NoSuchMethodException ignored) {}
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
try {
|
try {
|
||||||
getPlayerPermissionsMethod = PermissionManager.class.getMethod("getPlayerOwnPermissions", UUID.class);
|
getPlayerPermissionsMethod = PermissionManager.class.getMethod("getPlayerOwnPermissions", UUID.class);
|
||||||
getPlayerPermissionsMethod.setAccessible(true);
|
getPlayerPermissionsMethod.setAccessible(true);
|
||||||
} catch (NoSuchMethodException ignored) {
|
} catch (NoSuchMethodException ignored) {}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
getGroupMethod = CachedGroup.class.getMethod("getGroup");
|
getGroupMethod = CachedGroup.class.getMethod("getGroup");
|
||||||
getGroupMethod.setAccessible(true);
|
getGroupMethod.setAccessible(true);
|
||||||
superLegacy = true;
|
superLegacy = true;
|
||||||
} catch (NoSuchMethodException ignored) {
|
} catch (NoSuchMethodException ignored) {}
|
||||||
}
|
|
||||||
|
|
||||||
if (!legacy) {
|
if (!legacy) {
|
||||||
try {
|
try {
|
||||||
@@ -136,42 +122,6 @@ public class MigrationPowerfulPerms extends SubCommand<Object> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void getPlayerPermissions(PermissionManager manager, UUID uuid, Callback<List<Permission>> callback) {
|
|
||||||
if (legacy) {
|
|
||||||
try {
|
|
||||||
getPlayerPermissionsMethod.invoke(manager, uuid, new LPResultRunnable<List<Permission>>() {
|
|
||||||
@Override
|
|
||||||
public void run() {
|
|
||||||
callback.onComplete(getResult());
|
|
||||||
}
|
|
||||||
});
|
|
||||||
} catch (IllegalAccessException | InvocationTargetException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
try {
|
|
||||||
ListenableFuture<List<Permission>> lf = (ListenableFuture<List<Permission>>) getPlayerPermissionsMethod.invoke(manager, uuid);
|
|
||||||
try {
|
|
||||||
if (lf.isDone()) {
|
|
||||||
callback.onComplete(lf.get());
|
|
||||||
} else {
|
|
||||||
lf.addListener(() -> {
|
|
||||||
try {
|
|
||||||
callback.onComplete(lf.get());
|
|
||||||
} catch (InterruptedException | ExecutionException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}, Runnable::run);
|
|
||||||
}
|
|
||||||
} catch (InterruptedException | ExecutionException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
} catch (IllegalAccessException | InvocationTargetException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public MigrationPowerfulPerms() {
|
public MigrationPowerfulPerms() {
|
||||||
super("powerfulperms", "Migration from PowerfulPerms", MIGRATION, Predicates.not(5),
|
super("powerfulperms", "Migration from PowerfulPerms", MIGRATION, Predicates.not(5),
|
||||||
Arg.list(
|
Arg.list(
|
||||||
@@ -187,17 +137,22 @@ public class MigrationPowerfulPerms extends SubCommand<Object> {
|
|||||||
@Override
|
@Override
|
||||||
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, Object o, List<String> args, String label) throws CommandException {
|
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, Object o, List<String> args, String label) throws CommandException {
|
||||||
try {
|
try {
|
||||||
return run(plugin, args);
|
return run(plugin, sender, args);
|
||||||
} catch (Throwable t) {
|
} catch (Throwable t) {
|
||||||
t.printStackTrace();
|
t.printStackTrace();
|
||||||
return CommandResult.FAILURE;
|
return CommandResult.FAILURE;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private CommandResult run(LuckPermsPlugin plugin, List<String> args) {
|
private CommandResult run(LuckPermsPlugin plugin, Sender sender, List<String> args) {
|
||||||
final Logger log = plugin.getLog();
|
ProgressLogger log = new ProgressLogger("PowerfulPerms");
|
||||||
if (!plugin.isPluginLoaded("PowerfulPerms")) {
|
log.addListener(plugin.getConsoleSender());
|
||||||
log.severe("PowerfulPerms Migration: Error -> PowerfulPerms is not loaded.");
|
log.addListener(sender);
|
||||||
|
|
||||||
|
log.log("Starting.");
|
||||||
|
|
||||||
|
if (!Bukkit.getPluginManager().isPluginEnabled("PowerfulPerms")) {
|
||||||
|
log.logErr("PowerfulPerms is not loaded.");
|
||||||
return CommandResult.STATE_ERROR;
|
return CommandResult.STATE_ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -208,100 +163,90 @@ public class MigrationPowerfulPerms extends SubCommand<Object> {
|
|||||||
final String dbTable = args.get(4);
|
final String dbTable = args.get(4);
|
||||||
|
|
||||||
// Find a list of UUIDs
|
// Find a list of UUIDs
|
||||||
log.info("PowerfulPerms Migration: Getting a list of UUIDs to migrate.");
|
log.log("Getting a list of UUIDs to migrate.");
|
||||||
|
|
||||||
@Cleanup HikariDataSource hikari = new HikariDataSource();
|
|
||||||
hikari.setMaximumPoolSize(2);
|
|
||||||
hikari.setDataSourceClassName("com.mysql.jdbc.jdbc2.optional.MysqlDataSource");
|
|
||||||
hikari.addDataSourceProperty("serverName", address.split(":")[0]);
|
|
||||||
hikari.addDataSourceProperty("port", address.split(":")[1]);
|
|
||||||
hikari.addDataSourceProperty("databaseName", database);
|
|
||||||
hikari.addDataSourceProperty("user", username);
|
|
||||||
hikari.addDataSourceProperty("password", password);
|
|
||||||
|
|
||||||
Set<UUID> uuids = new HashSet<>();
|
Set<UUID> uuids = new HashSet<>();
|
||||||
|
|
||||||
try {
|
try (HikariDataSource hikari = new HikariDataSource()) {
|
||||||
@Cleanup Connection connection = hikari.getConnection();
|
hikari.setMaximumPoolSize(2);
|
||||||
DatabaseMetaData meta = connection.getMetaData();
|
hikari.setDataSourceClassName("com.mysql.jdbc.jdbc2.optional.MysqlDataSource");
|
||||||
|
hikari.addDataSourceProperty("serverName", address.split(":")[0]);
|
||||||
|
hikari.addDataSourceProperty("port", address.split(":")[1]);
|
||||||
|
hikari.addDataSourceProperty("databaseName", database);
|
||||||
|
hikari.addDataSourceProperty("user", username);
|
||||||
|
hikari.addDataSourceProperty("password", password);
|
||||||
|
|
||||||
@Cleanup ResultSet tables = meta.getTables(null, null, dbTable, null);
|
try (Connection c = hikari.getConnection()) {
|
||||||
if (!tables.next()) {
|
DatabaseMetaData meta = c.getMetaData();
|
||||||
log.severe("PowerfulPerms Migration: Error - Couldn't find table.");
|
|
||||||
return CommandResult.FAILURE;
|
|
||||||
|
|
||||||
} else {
|
try (ResultSet rs = meta.getTables(null, null, dbTable, null)) {
|
||||||
@Cleanup PreparedStatement columnPs = connection.prepareStatement("SELECT COLUMN_NAME, COLUMN_TYPE FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME=?");
|
if (!rs.next()) {
|
||||||
columnPs.setString(1, dbTable);
|
log.log("Error - Couldn't find table.");
|
||||||
@Cleanup ResultSet columnRs = columnPs.executeQuery();
|
return CommandResult.FAILURE;
|
||||||
|
}
|
||||||
log.info("Found table: " + dbTable);
|
|
||||||
while (columnRs.next()) {
|
|
||||||
log.info("" + columnRs.getString("COLUMN_NAME") + " - " + columnRs.getString("COLUMN_TYPE"));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Cleanup PreparedStatement preparedStatement = connection.prepareStatement("SELECT `uuid` FROM " + dbTable);
|
|
||||||
@Cleanup ResultSet resultSet = preparedStatement.executeQuery();
|
|
||||||
|
|
||||||
while (resultSet.next()) {
|
|
||||||
uuids.add(UUID.fromString(resultSet.getString("uuid")));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
try (Connection c = hikari.getConnection()) {
|
||||||
|
try (PreparedStatement ps = c.prepareStatement("SELECT COLUMN_NAME, COLUMN_TYPE FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME=?")) {
|
||||||
|
ps.setString(1, dbTable);
|
||||||
|
|
||||||
|
try (ResultSet rs = ps.executeQuery()) {
|
||||||
|
log.log("Found table: " + dbTable);
|
||||||
|
while (rs.next()) {
|
||||||
|
log.log("" + rs.getString("COLUMN_NAME") + " - " + rs.getString("COLUMN_TYPE"));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
try (PreparedStatement ps = c.prepareStatement("SELECT `uuid` FROM " + dbTable)) {
|
||||||
|
try (ResultSet rs = ps.executeQuery()) {
|
||||||
|
while (rs.next()) {
|
||||||
|
uuids.add(UUID.fromString(rs.getString("uuid")));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
return CommandResult.FAILURE;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (uuids.isEmpty()) {
|
if (uuids.isEmpty()) {
|
||||||
log.severe("PowerfulPerms Migration: Error - Unable to find any UUIDs to migrate.");
|
log.logErr("Unable to find any UUIDs to migrate.");
|
||||||
return CommandResult.FAILURE;
|
return CommandResult.FAILURE;
|
||||||
}
|
}
|
||||||
|
|
||||||
log.info("PowerfulPerms Migration: Found " + uuids.size() + " uuids. Starting migration.");
|
log.log("Found " + uuids.size() + " uuids. Starting migration.");
|
||||||
|
|
||||||
PowerfulPermsPlugin ppPlugin = (PowerfulPermsPlugin) plugin.getPlugin("PowerfulPerms");
|
PowerfulPermsPlugin ppPlugin = (PowerfulPermsPlugin) Bukkit.getPluginManager().getPlugin("PowerfulPerms");
|
||||||
PermissionManager pm = ppPlugin.getPermissionManager();
|
PermissionManager pm = ppPlugin.getPermissionManager();
|
||||||
|
|
||||||
// Groups first.
|
// Groups first.
|
||||||
log.info("PowerfulPerms Migration: Starting group migration.");
|
log.log("Starting group migration.");
|
||||||
|
AtomicInteger groupCount = new AtomicInteger(0);
|
||||||
Map<Integer, Group> groups = pm.getGroups(); // All versions
|
Map<Integer, Group> groups = pm.getGroups(); // All versions
|
||||||
for (Group g : groups.values()) {
|
for (Group g : groups.values()) {
|
||||||
plugin.getStorage().createAndLoadGroup(g.getName().toLowerCase()).join();
|
plugin.getStorage().createAndLoadGroup(g.getName().toLowerCase(), CreationCause.INTERNAL).join();
|
||||||
final me.lucko.luckperms.common.core.model.Group group = plugin.getGroupManager().getIfLoaded(g.getName().toLowerCase());
|
final me.lucko.luckperms.common.core.model.Group group = plugin.getGroupManager().getIfLoaded(g.getName().toLowerCase());
|
||||||
try {
|
|
||||||
LogEntry.build()
|
|
||||||
.actor(Constants.getConsoleUUID()).actorName(Constants.getConsoleName())
|
|
||||||
.acted(group).action("create")
|
|
||||||
.build().submit(plugin);
|
|
||||||
} catch (Exception ex) {
|
|
||||||
ex.printStackTrace();
|
|
||||||
}
|
|
||||||
|
|
||||||
for (Permission p : g.getOwnPermissions()) { // All versions
|
for (Permission p : g.getOwnPermissions()) { // All versions
|
||||||
applyPerm(group, p, plugin);
|
applyPerm(group, p, log);
|
||||||
}
|
}
|
||||||
|
|
||||||
for (Group parent : g.getParents()) { // All versions
|
for (Group parent : g.getParents()) { // All versions
|
||||||
try {
|
try {
|
||||||
group.setPermission("group." + parent.getName().toLowerCase(), true);
|
group.setPermission("group." + parent.getName().toLowerCase(), true);
|
||||||
LogEntry.build()
|
|
||||||
.actor(Constants.getConsoleUUID()).actorName(Constants.getConsoleName())
|
|
||||||
.acted(group).action("setinherit " + parent.getName().toLowerCase()) // All versions
|
|
||||||
.build().submit(plugin);
|
|
||||||
} catch (Exception ex) {
|
} catch (Exception ex) {
|
||||||
if (!(ex instanceof ObjectAlreadyHasException)) {
|
log.handleException(ex);
|
||||||
ex.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
plugin.getStorage().saveGroup(group);
|
plugin.getStorage().saveGroup(group);
|
||||||
|
log.logAllProgress("Migrated {} groups so far.", groupCount.incrementAndGet());
|
||||||
}
|
}
|
||||||
log.info("PowerfulPerms Migration: Group migration complete.");
|
log.log("Migrated " + groupCount.get() + " groups");
|
||||||
|
|
||||||
// Now users.
|
// Now users.
|
||||||
log.info("PowerfulPerms Migration: Starting user migration.");
|
log.log("Starting user migration.");
|
||||||
final Map<UUID, CountDownLatch> progress = new HashMap<>();
|
final Map<UUID, CountDownLatch> progress = new HashMap<>();
|
||||||
|
|
||||||
// Migrate all users and their groups
|
// Migrate all users and their groups
|
||||||
@@ -314,7 +259,7 @@ public class MigrationPowerfulPerms extends SubCommand<Object> {
|
|||||||
|
|
||||||
// Get a list of Permissions held by the user from the PP API.
|
// Get a list of Permissions held by the user from the PP API.
|
||||||
getPlayerPermissions(pm, uuid, perms -> { // Changes each version
|
getPlayerPermissions(pm, uuid, perms -> { // Changes each version
|
||||||
perms.forEach(p -> applyPerm(user, p, plugin));
|
perms.forEach(p -> applyPerm(user, p, log));
|
||||||
|
|
||||||
// Update the progress so the user can be saved and unloaded.
|
// Update the progress so the user can be saved and unloaded.
|
||||||
synchronized (progress) {
|
synchronized (progress) {
|
||||||
@@ -327,7 +272,7 @@ public class MigrationPowerfulPerms extends SubCommand<Object> {
|
|||||||
});
|
});
|
||||||
|
|
||||||
// Migrate the user's groups to LuckPerms from PP.
|
// Migrate the user's groups to LuckPerms from PP.
|
||||||
Callback<Map<String, List<CachedGroup>>> callback = groups1 -> {
|
Consumer<Map<String, List<CachedGroup>>> callback = groups1 -> {
|
||||||
for (Map.Entry<String, List<CachedGroup>> e : groups1.entrySet()) {
|
for (Map.Entry<String, List<CachedGroup>> e : groups1.entrySet()) {
|
||||||
final String server;
|
final String server;
|
||||||
if (e.getKey() != null && (e.getKey().equals("") || e.getKey().equalsIgnoreCase("all"))) {
|
if (e.getKey() != null && (e.getKey().equals("") || e.getKey().equalsIgnoreCase("all"))) {
|
||||||
@@ -352,26 +297,14 @@ public class MigrationPowerfulPerms extends SubCommand<Object> {
|
|||||||
if (server == null) {
|
if (server == null) {
|
||||||
try {
|
try {
|
||||||
user.setPermission("group." + g.getName().toLowerCase(), true);
|
user.setPermission("group." + g.getName().toLowerCase(), true);
|
||||||
LogEntry.build()
|
|
||||||
.actor(Constants.getConsoleUUID()).actorName(Constants.getConsoleName())
|
|
||||||
.acted(user).action("addgroup " + g.getName().toLowerCase())
|
|
||||||
.build().submit(plugin);
|
|
||||||
} catch (Exception ex) {
|
} catch (Exception ex) {
|
||||||
if (!(ex instanceof ObjectAlreadyHasException)) {
|
log.handleException(ex);
|
||||||
ex.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
try {
|
try {
|
||||||
user.setPermission("group." + g.getName().toLowerCase(), true, server);
|
user.setPermission("group." + g.getName().toLowerCase(), true, server);
|
||||||
LogEntry.build()
|
|
||||||
.actor(Constants.getConsoleUUID()).actorName(Constants.getConsoleName())
|
|
||||||
.acted(user).action("addgroup " + g.getName().toLowerCase() + " " + server)
|
|
||||||
.build().submit(plugin);
|
|
||||||
} catch (Exception ex) {
|
} catch (Exception ex) {
|
||||||
if (!(ex instanceof ObjectAlreadyHasException)) {
|
log.handleException(ex);
|
||||||
ex.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -385,26 +318,14 @@ public class MigrationPowerfulPerms extends SubCommand<Object> {
|
|||||||
if (server == null) {
|
if (server == null) {
|
||||||
try {
|
try {
|
||||||
user.setPermission("group." + group.getName().toLowerCase(), true, g.getExpirationDate().getTime() / 1000L);
|
user.setPermission("group." + group.getName().toLowerCase(), true, g.getExpirationDate().getTime() / 1000L);
|
||||||
LogEntry.build()
|
|
||||||
.actor(Constants.getConsoleUUID()).actorName(Constants.getConsoleName())
|
|
||||||
.acted(user).action("addtempgroup " + group.getName().toLowerCase() + " " + g.getExpirationDate().getTime() / 1000L)
|
|
||||||
.build().submit(plugin);
|
|
||||||
} catch (Exception ex) {
|
} catch (Exception ex) {
|
||||||
if (!(ex instanceof ObjectAlreadyHasException)) {
|
log.handleException(ex);
|
||||||
ex.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
try {
|
try {
|
||||||
user.setPermission("group." + group.getName().toLowerCase(), true, server, g.getExpirationDate().getTime() / 1000L);
|
user.setPermission("group." + group.getName().toLowerCase(), true, server, g.getExpirationDate().getTime() / 1000L);
|
||||||
LogEntry.build()
|
|
||||||
.actor(Constants.getConsoleUUID()).actorName(Constants.getConsoleName())
|
|
||||||
.acted(user).action("addtempgroup " + group.getName().toLowerCase() + " " + g.getExpirationDate().getTime() / 1000L + " " + server)
|
|
||||||
.build().submit(plugin);
|
|
||||||
} catch (Exception ex) {
|
} catch (Exception ex) {
|
||||||
if (!(ex instanceof ObjectAlreadyHasException)) {
|
log.handleException(ex);
|
||||||
ex.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -412,26 +333,14 @@ public class MigrationPowerfulPerms extends SubCommand<Object> {
|
|||||||
if (server == null) {
|
if (server == null) {
|
||||||
try {
|
try {
|
||||||
user.setPermission("group." + group.getName().toLowerCase(), true);
|
user.setPermission("group." + group.getName().toLowerCase(), true);
|
||||||
LogEntry.build()
|
|
||||||
.actor(Constants.getConsoleUUID()).actorName(Constants.getConsoleName())
|
|
||||||
.acted(user).action("addgroup " + group.getName().toLowerCase())
|
|
||||||
.build().submit(plugin);
|
|
||||||
} catch (Exception ex) {
|
} catch (Exception ex) {
|
||||||
if (!(ex instanceof ObjectAlreadyHasException)) {
|
log.handleException(ex);
|
||||||
ex.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
try {
|
try {
|
||||||
user.setPermission("group." + group.getName().toLowerCase(), true, server);
|
user.setPermission("group." + group.getName().toLowerCase(), true, server);
|
||||||
LogEntry.build()
|
|
||||||
.actor(Constants.getConsoleUUID()).actorName(Constants.getConsoleName())
|
|
||||||
.acted(user).action("addgroup " + group.getName().toLowerCase() + " " + server)
|
|
||||||
.build().submit(plugin);
|
|
||||||
} catch (Exception ex) {
|
} catch (Exception ex) {
|
||||||
if (!(ex instanceof ObjectAlreadyHasException)) {
|
log.handleException(ex);
|
||||||
ex.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -454,11 +363,11 @@ public class MigrationPowerfulPerms extends SubCommand<Object> {
|
|||||||
ListenableFuture<LinkedHashMap<String, List<CachedGroup>>> future = (ListenableFuture<LinkedHashMap<String, List<CachedGroup>>>) getPlayerGroupsMethod.invoke(pm, uuid);
|
ListenableFuture<LinkedHashMap<String, List<CachedGroup>>> future = (ListenableFuture<LinkedHashMap<String, List<CachedGroup>>>) getPlayerGroupsMethod.invoke(pm, uuid);
|
||||||
try {
|
try {
|
||||||
if (future.isDone()) {
|
if (future.isDone()) {
|
||||||
callback.onComplete(future.get());
|
callback.accept(future.get());
|
||||||
} else {
|
} else {
|
||||||
future.addListener(() -> {
|
future.addListener(() -> {
|
||||||
try {
|
try {
|
||||||
callback.onComplete(future.get());
|
callback.accept(future.get());
|
||||||
} catch (InterruptedException | ExecutionException e) {
|
} catch (InterruptedException | ExecutionException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
@@ -468,7 +377,6 @@ public class MigrationPowerfulPerms extends SubCommand<Object> {
|
|||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
} catch (IllegalAccessException | InvocationTargetException e) {
|
} catch (IllegalAccessException | InvocationTargetException e) {
|
||||||
log.info("PowerfulPerms Migration: Error");
|
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
@@ -476,11 +384,10 @@ public class MigrationPowerfulPerms extends SubCommand<Object> {
|
|||||||
getPlayerGroupsMethod.invoke(pm, uuid, new LPResultRunnable<LinkedHashMap<String, List<CachedGroup>>>() {
|
getPlayerGroupsMethod.invoke(pm, uuid, new LPResultRunnable<LinkedHashMap<String, List<CachedGroup>>>() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
callback.onComplete(getResult());
|
callback.accept(getResult());
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
} catch (IllegalAccessException | InvocationTargetException e) {
|
} catch (IllegalAccessException | InvocationTargetException e) {
|
||||||
log.info("PowerfulPerms Migration: Error");
|
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -488,7 +395,7 @@ public class MigrationPowerfulPerms extends SubCommand<Object> {
|
|||||||
|
|
||||||
// All groups are migrated, but there may still be some users being migrated.
|
// All groups are migrated, but there may still be some users being migrated.
|
||||||
// This block will wait for all users to be completed.
|
// This block will wait for all users to be completed.
|
||||||
log.info("PowerfulPerms Migration: Waiting for user migration to complete. This may take some time");
|
log.log("Waiting for user migration to complete. This may take some time");
|
||||||
boolean sleep = true;
|
boolean sleep = true;
|
||||||
while (sleep) {
|
while (sleep) {
|
||||||
sleep = false;
|
sleep = false;
|
||||||
@@ -511,11 +418,11 @@ public class MigrationPowerfulPerms extends SubCommand<Object> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// We done.
|
// We done.
|
||||||
log.info("PowerfulPerms Migration: Success! Completed without any errors.");
|
log.log("Success! Migration complete.");
|
||||||
return CommandResult.SUCCESS;
|
return CommandResult.SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void applyPerm(PermissionHolder holder, Permission p, LuckPermsPlugin plugin) {
|
private void applyPerm(PermissionHolder holder, Permission p, ProgressLogger log) {
|
||||||
String node = p.getPermissionString();
|
String node = p.getPermissionString();
|
||||||
boolean value = true;
|
boolean value = true;
|
||||||
if (node.startsWith("!")) {
|
if (node.startsWith("!")) {
|
||||||
@@ -548,26 +455,14 @@ public class MigrationPowerfulPerms extends SubCommand<Object> {
|
|||||||
if (expireAt == 0L) {
|
if (expireAt == 0L) {
|
||||||
try {
|
try {
|
||||||
holder.setPermission(node, value, server, world);
|
holder.setPermission(node, value, server, world);
|
||||||
LogEntry.build()
|
|
||||||
.actor(Constants.getConsoleUUID()).actorName(Constants.getConsoleName())
|
|
||||||
.acted(holder).action("set " + node + " " + value + " " + server + " " + world)
|
|
||||||
.build().submit(plugin);
|
|
||||||
} catch (Exception ex) {
|
} catch (Exception ex) {
|
||||||
if (!(ex instanceof ObjectAlreadyHasException)) {
|
log.handleException(ex);
|
||||||
ex.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
try {
|
try {
|
||||||
holder.setPermission(node, value, server, world, expireAt);
|
holder.setPermission(node, value, server, world, expireAt);
|
||||||
LogEntry.build()
|
|
||||||
.actor(Constants.getConsoleUUID()).actorName(Constants.getConsoleName())
|
|
||||||
.acted(holder).action("settemp " + node + " " + value + " " + expireAt + " " + server + " " + world)
|
|
||||||
.build().submit(plugin);
|
|
||||||
} catch (Exception ex) {
|
} catch (Exception ex) {
|
||||||
if (!(ex instanceof ObjectAlreadyHasException)) {
|
log.handleException(ex);
|
||||||
ex.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -575,54 +470,66 @@ public class MigrationPowerfulPerms extends SubCommand<Object> {
|
|||||||
if (expireAt == 0L) {
|
if (expireAt == 0L) {
|
||||||
try {
|
try {
|
||||||
holder.setPermission(node, value, server);
|
holder.setPermission(node, value, server);
|
||||||
LogEntry.build()
|
|
||||||
.actor(Constants.getConsoleUUID()).actorName(Constants.getConsoleName())
|
|
||||||
.acted(holder).action("set " + node + " " + value + " " + server)
|
|
||||||
.build().submit(plugin);
|
|
||||||
} catch (Exception ex) {
|
} catch (Exception ex) {
|
||||||
if (!(ex instanceof ObjectAlreadyHasException)) {
|
log.handleException(ex);
|
||||||
ex.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
try {
|
try {
|
||||||
holder.setPermission(node, value, server, expireAt);
|
holder.setPermission(node, value, server, expireAt);
|
||||||
LogEntry.build()
|
|
||||||
.actor(Constants.getConsoleUUID()).actorName(Constants.getConsoleName())
|
|
||||||
.acted(holder).action("settemp " + node + " " + value + " " + expireAt + " " + server)
|
|
||||||
.build().submit(plugin);
|
|
||||||
} catch (Exception ex) {
|
} catch (Exception ex) {
|
||||||
if (!(ex instanceof ObjectAlreadyHasException)) {
|
log.handleException(ex);
|
||||||
ex.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (expireAt == 0L) {
|
if (expireAt == 0L) {
|
||||||
try {
|
try {
|
||||||
holder.setPermission(node, value);
|
holder.setPermission(node, value);
|
||||||
LogEntry.build()
|
|
||||||
.actor(Constants.getConsoleUUID()).actorName(Constants.getConsoleName())
|
|
||||||
.acted(holder).action("set " + node + " " + value)
|
|
||||||
.build().submit(plugin);
|
|
||||||
} catch (Exception ex) {
|
} catch (Exception ex) {
|
||||||
if (!(ex instanceof ObjectAlreadyHasException)) {
|
log.handleException(ex);
|
||||||
ex.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
try {
|
try {
|
||||||
holder.setPermission(node, value, expireAt);
|
holder.setPermission(node, value, expireAt);
|
||||||
LogEntry.build()
|
|
||||||
.actor(Constants.getConsoleUUID()).actorName(Constants.getConsoleName())
|
|
||||||
.acted(holder).action("settemp " + node + " " + value + " " + expireAt)
|
|
||||||
.build().submit(plugin);
|
|
||||||
} catch (Exception ex) {
|
} catch (Exception ex) {
|
||||||
if (!(ex instanceof ObjectAlreadyHasException)) {
|
log.handleException(ex);
|
||||||
ex.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static void getPlayerPermissions(PermissionManager manager, UUID uuid, Consumer<List<Permission>> callback) {
|
||||||
|
if (legacy) {
|
||||||
|
try {
|
||||||
|
getPlayerPermissionsMethod.invoke(manager, uuid, new LPResultRunnable<List<Permission>>() {
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
callback.accept(getResult());
|
||||||
|
}
|
||||||
|
});
|
||||||
|
} catch (IllegalAccessException | InvocationTargetException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
try {
|
||||||
|
ListenableFuture<List<Permission>> lf = (ListenableFuture<List<Permission>>) getPlayerPermissionsMethod.invoke(manager, uuid);
|
||||||
|
try {
|
||||||
|
if (lf.isDone()) {
|
||||||
|
callback.accept(lf.get());
|
||||||
|
} else {
|
||||||
|
lf.addListener(() -> {
|
||||||
|
try {
|
||||||
|
callback.accept(lf.get());
|
||||||
|
} catch (InterruptedException | ExecutionException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}, Runnable::run);
|
||||||
|
}
|
||||||
|
} catch (InterruptedException | ExecutionException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
} catch (IllegalAccessException | InvocationTargetException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
+55
-30
@@ -22,8 +22,7 @@
|
|||||||
|
|
||||||
package me.lucko.luckperms.bukkit.migration;
|
package me.lucko.luckperms.bukkit.migration;
|
||||||
|
|
||||||
import me.lucko.luckperms.api.Logger;
|
import me.lucko.luckperms.api.event.cause.CreationCause;
|
||||||
import me.lucko.luckperms.common.LuckPermsPlugin;
|
|
||||||
import me.lucko.luckperms.common.commands.CommandException;
|
import me.lucko.luckperms.common.commands.CommandException;
|
||||||
import me.lucko.luckperms.common.commands.CommandResult;
|
import me.lucko.luckperms.common.commands.CommandResult;
|
||||||
import me.lucko.luckperms.common.commands.SubCommand;
|
import me.lucko.luckperms.common.commands.SubCommand;
|
||||||
@@ -34,19 +33,24 @@ import me.lucko.luckperms.common.core.model.Group;
|
|||||||
import me.lucko.luckperms.common.core.model.PermissionHolder;
|
import me.lucko.luckperms.common.core.model.PermissionHolder;
|
||||||
import me.lucko.luckperms.common.core.model.Track;
|
import me.lucko.luckperms.common.core.model.Track;
|
||||||
import me.lucko.luckperms.common.core.model.User;
|
import me.lucko.luckperms.common.core.model.User;
|
||||||
|
import me.lucko.luckperms.common.plugin.LuckPermsPlugin;
|
||||||
import me.lucko.luckperms.common.utils.Predicates;
|
import me.lucko.luckperms.common.utils.Predicates;
|
||||||
|
import me.lucko.luckperms.common.utils.ProgressLogger;
|
||||||
import me.lucko.luckperms.exceptions.ObjectAlreadyHasException;
|
import me.lucko.luckperms.exceptions.ObjectAlreadyHasException;
|
||||||
|
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
import org.tyrannyofheaven.bukkit.zPermissions.ZPermissionsService;
|
import org.tyrannyofheaven.bukkit.zPermissions.ZPermissionsService;
|
||||||
import org.tyrannyofheaven.bukkit.zPermissions.dao.PermissionService;
|
import org.tyrannyofheaven.bukkit.zPermissions.dao.PermissionService;
|
||||||
import org.tyrannyofheaven.bukkit.zPermissions.model.EntityMetadata;
|
import org.tyrannyofheaven.bukkit.zPermissions.model.EntityMetadata;
|
||||||
import org.tyrannyofheaven.bukkit.zPermissions.model.Entry;
|
import org.tyrannyofheaven.bukkit.zPermissions.model.Entry;
|
||||||
import org.tyrannyofheaven.bukkit.zPermissions.model.Inheritance;
|
import org.tyrannyofheaven.bukkit.zPermissions.model.Inheritance;
|
||||||
|
import org.tyrannyofheaven.bukkit.zPermissions.model.Membership;
|
||||||
import org.tyrannyofheaven.bukkit.zPermissions.model.PermissionEntity;
|
import org.tyrannyofheaven.bukkit.zPermissions.model.PermissionEntity;
|
||||||
|
|
||||||
import java.lang.reflect.Field;
|
import java.lang.reflect.Field;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
import java.util.concurrent.atomic.AtomicInteger;
|
||||||
|
|
||||||
public class MigrationZPermissions extends SubCommand<Object> {
|
public class MigrationZPermissions extends SubCommand<Object> {
|
||||||
public MigrationZPermissions() {
|
public MigrationZPermissions() {
|
||||||
@@ -55,20 +59,25 @@ public class MigrationZPermissions extends SubCommand<Object> {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, Object o, List<String> args, String label) throws CommandException {
|
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, Object o, List<String> args, String label) throws CommandException {
|
||||||
final Logger log = plugin.getLog();
|
ProgressLogger log = new ProgressLogger("PermissionManager");
|
||||||
if (!plugin.isPluginLoaded("zPermissions")) {
|
log.addListener(plugin.getConsoleSender());
|
||||||
log.severe("zPermissions Migration: Error -> zPermissions is not loaded.");
|
log.addListener(sender);
|
||||||
|
|
||||||
|
log.log("Starting.");
|
||||||
|
|
||||||
|
if (!Bukkit.getPluginManager().isPluginEnabled("zPermissions")) {
|
||||||
|
log.logErr("zPermissions is not loaded.");
|
||||||
return CommandResult.STATE_ERROR;
|
return CommandResult.STATE_ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
ZPermissionsService service = (ZPermissionsService) plugin.getService(ZPermissionsService.class);
|
if (!Bukkit.getServicesManager().isProvidedFor(ZPermissionsService.class)) {
|
||||||
if (service == null) {
|
log.logErr("zPermissions is not loaded.");
|
||||||
log.severe("zPermissions Migration: Error -> zPermissions is not loaded.");
|
|
||||||
return CommandResult.STATE_ERROR;
|
return CommandResult.STATE_ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ZPermissionsService service = Bukkit.getServicesManager().getRegistration(ZPermissionsService.class).getProvider();
|
||||||
|
|
||||||
PermissionService internalService;
|
PermissionService internalService;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
Field psField = service.getClass().getDeclaredField("permissionService");
|
Field psField = service.getClass().getDeclaredField("permissionService");
|
||||||
psField.setAccessible(true);
|
psField.setAccessible(true);
|
||||||
@@ -79,69 +88,85 @@ public class MigrationZPermissions extends SubCommand<Object> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Migrate all groups
|
// Migrate all groups
|
||||||
log.info("zPermissions Migration: Starting group migration.");
|
log.log("Starting group migration.");
|
||||||
|
AtomicInteger groupCount = new AtomicInteger(0);
|
||||||
for (String g : service.getAllGroups()) {
|
for (String g : service.getAllGroups()) {
|
||||||
plugin.getStorage().createAndLoadGroup(g.toLowerCase()).join();
|
plugin.getStorage().createAndLoadGroup(g.toLowerCase(), CreationCause.INTERNAL).join();
|
||||||
Group group = plugin.getGroupManager().getIfLoaded(g.toLowerCase());
|
Group group = plugin.getGroupManager().getIfLoaded(g.toLowerCase());
|
||||||
|
|
||||||
PermissionEntity entity = internalService.getEntity(g, null, true);
|
PermissionEntity entity = internalService.getEntity(g, null, true);
|
||||||
migrateEntity(group, entity);
|
migrateEntity(group, entity, null);
|
||||||
|
|
||||||
plugin.getStorage().saveGroup(group);
|
plugin.getStorage().saveGroup(group);
|
||||||
|
log.logAllProgress("Migrated {} groups so far.", groupCount.incrementAndGet());
|
||||||
}
|
}
|
||||||
|
log.log("Migrated " + groupCount.get() + " groups");
|
||||||
|
|
||||||
// Migrate all tracks
|
// Migrate all tracks
|
||||||
log.info("zPermissions Migration: Starting track migration.");
|
log.log("Starting track migration.");
|
||||||
|
AtomicInteger trackCount = new AtomicInteger(0);
|
||||||
for (String t : service.getAllTracks()) {
|
for (String t : service.getAllTracks()) {
|
||||||
plugin.getStorage().createAndLoadTrack(t.toLowerCase()).join();
|
plugin.getStorage().createAndLoadTrack(t.toLowerCase(), CreationCause.INTERNAL).join();
|
||||||
Track track = plugin.getTrackManager().getIfLoaded(t.toLowerCase());
|
Track track = plugin.getTrackManager().getIfLoaded(t.toLowerCase());
|
||||||
track.setGroups(service.getTrackGroups(t));
|
track.setGroups(service.getTrackGroups(t));
|
||||||
plugin.getStorage().saveTrack(track);
|
plugin.getStorage().saveTrack(track);
|
||||||
|
log.logAllProgress("Migrated {} tracks so far.", trackCount.incrementAndGet());
|
||||||
}
|
}
|
||||||
|
log.log("Migrated " + trackCount.get() + " tracks");
|
||||||
|
|
||||||
// Migrate all users.
|
// Migrate all users.
|
||||||
log.info("zPermissions Migration: Starting user migration.");
|
log.log("Starting user migration.");
|
||||||
|
AtomicInteger userCount = new AtomicInteger(0);
|
||||||
for (UUID u : service.getAllPlayersUUID()) {
|
for (UUID u : service.getAllPlayersUUID()) {
|
||||||
plugin.getStorage().loadUser(u, "null").join();
|
plugin.getStorage().loadUser(u, "null").join();
|
||||||
User user = plugin.getUserManager().get(u);
|
User user = plugin.getUserManager().get(u);
|
||||||
|
|
||||||
PermissionEntity entity = internalService.getEntity(null, u, false);
|
PermissionEntity entity = internalService.getEntity(null, u, false);
|
||||||
migrateEntity(user, entity);
|
migrateEntity(user, entity, internalService.getGroups(u));
|
||||||
|
|
||||||
user.setPrimaryGroup(service.getPlayerPrimaryGroup(u));
|
user.setPrimaryGroup(service.getPlayerPrimaryGroup(u));
|
||||||
|
|
||||||
|
if (!entity.isGroup()) {
|
||||||
|
user.setName(entity.getDisplayName());
|
||||||
|
}
|
||||||
|
|
||||||
plugin.getUserManager().cleanup(user);
|
plugin.getUserManager().cleanup(user);
|
||||||
plugin.getStorage().saveUser(user);
|
plugin.getStorage().saveUser(user);
|
||||||
|
log.logProgress("Migrated {} users so far.", userCount.incrementAndGet());
|
||||||
}
|
}
|
||||||
|
|
||||||
log.info("zPermissions Migration: Success! Completed without any errors.");
|
log.log("Migrated " + userCount.get() + " users.");
|
||||||
|
log.log("Success! Migration complete.");
|
||||||
return CommandResult.SUCCESS;
|
return CommandResult.SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void migrateEntity(PermissionHolder group, PermissionEntity entity) {
|
private void migrateEntity(PermissionHolder group, PermissionEntity entity, List<Membership> memberships) {
|
||||||
for (Entry e : entity.getPermissions()) {
|
for (Entry e : entity.getPermissions()) {
|
||||||
if (e.getWorld() != null) {
|
if (e.getWorld() != null) {
|
||||||
try {
|
try {
|
||||||
group.setPermission(e.getPermission(), true, "global", e.getWorld().getName());
|
group.setPermission(e.getPermission(), true, "global", e.getWorld().getName());
|
||||||
} catch (ObjectAlreadyHasException ignored) {
|
} catch (ObjectAlreadyHasException ignored) {}
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
try {
|
try {
|
||||||
group.setPermission(e.getPermission(), true); // TODO handle negated.
|
group.setPermission(e.getPermission(), true); // TODO handle negated.
|
||||||
} catch (ObjectAlreadyHasException ignored) {
|
} catch (ObjectAlreadyHasException ignored) {}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for (Inheritance inheritance : entity.getInheritancesAsChild()) {
|
if (entity.isGroup()) {
|
||||||
if (!inheritance.getChild().getId().equals(entity.getId())) {
|
for (Inheritance inheritance : entity.getInheritancesAsChild()) {
|
||||||
new Throwable("Illegal inheritance").printStackTrace();
|
try {
|
||||||
continue;
|
if (!inheritance.getParent().getName().equals(group.getObjectName())) {
|
||||||
|
group.setPermission("group." + inheritance.getParent().getName(), true);
|
||||||
|
}
|
||||||
|
} catch (ObjectAlreadyHasException ignored) {}
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
try {
|
// entity.getMemberships() doesn't work (always returns 0 records)
|
||||||
group.setPermission("group." + inheritance.getParent(), true);
|
for (Membership membership : memberships) {
|
||||||
} catch (ObjectAlreadyHasException ignored) {
|
try {
|
||||||
|
group.setPermission("group." + membership.getGroup().getDisplayName(), true);
|
||||||
|
} catch (ObjectAlreadyHasException ignored) {}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -36,6 +36,33 @@ import java.util.Map;
|
|||||||
|
|
||||||
public class ChildPermissionProvider {
|
public class ChildPermissionProvider {
|
||||||
|
|
||||||
|
@Getter
|
||||||
|
private ImmutableMap<Map.Entry<String, Boolean>, ImmutableMap<String, Boolean>> permissions = ImmutableMap.of();
|
||||||
|
|
||||||
|
public void setup() {
|
||||||
|
ImmutableMap.Builder<Map.Entry<String, Boolean>, ImmutableMap<String, Boolean>> permissions = ImmutableMap.builder();
|
||||||
|
|
||||||
|
for (Permission permission : Bukkit.getServer().getPluginManager().getPermissions()) {
|
||||||
|
// handle true
|
||||||
|
Map<String, Boolean> trueChildren = new HashMap<>();
|
||||||
|
resolveChildren(trueChildren, Collections.singletonMap(permission.getName(), true), false);
|
||||||
|
trueChildren.remove(permission.getName(), true);
|
||||||
|
if (!trueChildren.isEmpty()) {
|
||||||
|
permissions.put(Maps.immutableEntry(permission.getName().toLowerCase(), true), ImmutableMap.copyOf(trueChildren));
|
||||||
|
}
|
||||||
|
|
||||||
|
// handle false
|
||||||
|
Map<String, Boolean> falseChildren = new HashMap<>();
|
||||||
|
resolveChildren(falseChildren, Collections.singletonMap(permission.getName(), false), false);
|
||||||
|
falseChildren.remove(permission.getName(), false);
|
||||||
|
if (!falseChildren.isEmpty()) {
|
||||||
|
permissions.put(Maps.immutableEntry(permission.getName().toLowerCase(), false), ImmutableMap.copyOf(falseChildren));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
this.permissions = permissions.build();
|
||||||
|
}
|
||||||
|
|
||||||
private static void resolveChildren(Map<String, Boolean> accumulator, Map<String, Boolean> children, boolean invert) {
|
private static void resolveChildren(Map<String, Boolean> accumulator, Map<String, Boolean> children, boolean invert) {
|
||||||
for (Map.Entry<String, Boolean> e : children.entrySet()) {
|
for (Map.Entry<String, Boolean> e : children.entrySet()) {
|
||||||
if (accumulator.containsKey(e.getKey())) {
|
if (accumulator.containsKey(e.getKey())) {
|
||||||
@@ -53,25 +80,4 @@ public class ChildPermissionProvider {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Getter
|
|
||||||
private ImmutableMap<Map.Entry<String, Boolean>, ImmutableMap<String, Boolean>> permissions = ImmutableMap.of();
|
|
||||||
|
|
||||||
public void setup() {
|
|
||||||
Map<Map.Entry<String, Boolean>, ImmutableMap<String, Boolean>> permissions = new HashMap<>();
|
|
||||||
|
|
||||||
for (Permission permission : Bukkit.getServer().getPluginManager().getPermissions()) {
|
|
||||||
// handle true
|
|
||||||
Map<String, Boolean> children = new HashMap<>();
|
|
||||||
resolveChildren(children, Collections.singletonMap(permission.getName(), true), false);
|
|
||||||
permissions.put(Maps.immutableEntry(permission.getName().toLowerCase(), true), ImmutableMap.copyOf(children));
|
|
||||||
|
|
||||||
// handle false
|
|
||||||
Map<String, Boolean> nChildren = new HashMap<>();
|
|
||||||
resolveChildren(nChildren, Collections.singletonMap(permission.getName(), false), false);
|
|
||||||
permissions.put(Maps.immutableEntry(permission.getName().toLowerCase(), false), ImmutableMap.copyOf(nChildren));
|
|
||||||
}
|
|
||||||
|
|
||||||
this.permissions = ImmutableMap.copyOf(permissions);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
@@ -22,7 +22,6 @@
|
|||||||
|
|
||||||
package me.lucko.luckperms.bukkit.model;
|
package me.lucko.luckperms.bukkit.model;
|
||||||
|
|
||||||
import lombok.AllArgsConstructor;
|
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
|
|
||||||
import com.google.common.collect.ImmutableMap;
|
import com.google.common.collect.ImmutableMap;
|
||||||
@@ -30,19 +29,61 @@ import com.google.common.collect.ImmutableMap;
|
|||||||
import me.lucko.luckperms.api.Tristate;
|
import me.lucko.luckperms.api.Tristate;
|
||||||
|
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.permissions.Permissible;
|
|
||||||
import org.bukkit.permissions.Permission;
|
import org.bukkit.permissions.Permission;
|
||||||
import org.bukkit.permissions.PermissionAttachment;
|
|
||||||
import org.bukkit.permissions.PermissionAttachmentInfo;
|
|
||||||
import org.bukkit.plugin.Plugin;
|
|
||||||
|
|
||||||
import java.util.Collections;
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
public class DefaultsProvider {
|
public class DefaultsProvider {
|
||||||
|
|
||||||
|
@Getter
|
||||||
|
private Map<String, Boolean> opDefaults = ImmutableMap.of();
|
||||||
|
private final DummyPermissible opDummy = new DummyPermissible(this::refreshOp);
|
||||||
|
|
||||||
|
@Getter
|
||||||
|
private Map<String, Boolean> nonOpDefaults = ImmutableMap.of();
|
||||||
|
private final DummyPermissible nonOpDummy = new DummyPermissible(this::refreshNonOp);
|
||||||
|
|
||||||
|
public void refresh() {
|
||||||
|
refreshOp();
|
||||||
|
refreshNonOp();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void refreshOp() {
|
||||||
|
unregisterDefaults(opDefaults, opDummy);
|
||||||
|
|
||||||
|
Map<String, Boolean> builder = new HashMap<>();
|
||||||
|
calculateDefaults(builder, opDummy, true);
|
||||||
|
|
||||||
|
opDefaults = ImmutableMap.copyOf(builder);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void refreshNonOp() {
|
||||||
|
unregisterDefaults(nonOpDefaults, nonOpDummy);
|
||||||
|
|
||||||
|
Map<String, Boolean> builder = new HashMap<>();
|
||||||
|
calculateDefaults(builder, nonOpDummy, false);
|
||||||
|
|
||||||
|
nonOpDefaults = ImmutableMap.copyOf(builder);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void close() {
|
||||||
|
unregisterDefaults(opDefaults, opDummy);
|
||||||
|
unregisterDefaults(nonOpDefaults, nonOpDummy);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Tristate hasDefault(String permission, boolean isOp) {
|
||||||
|
Map<String, Boolean> map = isOp ? opDefaults : nonOpDefaults;
|
||||||
|
|
||||||
|
Boolean b = map.get(permission);
|
||||||
|
return b == null ? Tristate.UNDEFINED : Tristate.fromBoolean(b);
|
||||||
|
}
|
||||||
|
|
||||||
|
public int size() {
|
||||||
|
return opDefaults.size() + nonOpDefaults.size();
|
||||||
|
}
|
||||||
|
|
||||||
private static void unregisterDefaults(Map<String, Boolean> map, DummyPermissible p) {
|
private static void unregisterDefaults(Map<String, Boolean> map, DummyPermissible p) {
|
||||||
Set<String> perms = map.keySet();
|
Set<String> perms = map.keySet();
|
||||||
|
|
||||||
@@ -81,115 +122,4 @@ public class DefaultsProvider {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Getter
|
|
||||||
private Map<String, Boolean> opDefaults = ImmutableMap.of();
|
|
||||||
private final DummyPermissible opDummy = new DummyPermissible(this::refreshOp);
|
|
||||||
@Getter
|
|
||||||
private Map<String, Boolean> nonOpDefaults = ImmutableMap.of();
|
|
||||||
private final DummyPermissible nonOpDummy = new DummyPermissible(this::refreshNonOp);
|
|
||||||
|
|
||||||
public void refresh() {
|
|
||||||
refreshOp();
|
|
||||||
refreshNonOp();
|
|
||||||
}
|
|
||||||
|
|
||||||
private void refreshOp() {
|
|
||||||
unregisterDefaults(opDefaults, opDummy);
|
|
||||||
|
|
||||||
Map<String, Boolean> builder = new HashMap<>();
|
|
||||||
calculateDefaults(builder, opDummy, true);
|
|
||||||
|
|
||||||
opDefaults = ImmutableMap.copyOf(builder);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void refreshNonOp() {
|
|
||||||
unregisterDefaults(nonOpDefaults, nonOpDummy);
|
|
||||||
|
|
||||||
Map<String, Boolean> builder = new HashMap<>();
|
|
||||||
calculateDefaults(builder, nonOpDummy, false);
|
|
||||||
|
|
||||||
nonOpDefaults = ImmutableMap.copyOf(builder);
|
|
||||||
}
|
|
||||||
|
|
||||||
public Tristate hasDefault(String permission, boolean isOp) {
|
|
||||||
Map<String, Boolean> map = isOp ? opDefaults : nonOpDefaults;
|
|
||||||
|
|
||||||
Boolean b = map.get(permission);
|
|
||||||
return b == null ? Tristate.UNDEFINED : Tristate.fromBoolean(b);
|
|
||||||
}
|
|
||||||
|
|
||||||
public int size() {
|
|
||||||
return opDefaults.size() + nonOpDefaults.size();
|
|
||||||
}
|
|
||||||
|
|
||||||
@AllArgsConstructor
|
|
||||||
private static class DummyPermissible implements Permissible {
|
|
||||||
private final Runnable onRefresh;
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void recalculatePermissions() {
|
|
||||||
onRefresh.run();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Set<PermissionAttachmentInfo> getEffectivePermissions() {
|
|
||||||
return Collections.emptySet();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean isPermissionSet(String name) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean isPermissionSet(Permission perm) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean hasPermission(String name) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean hasPermission(Permission perm) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public PermissionAttachment addAttachment(Plugin plugin, String name, boolean value) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public PermissionAttachment addAttachment(Plugin plugin) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public PermissionAttachment addAttachment(Plugin plugin, String name, boolean value, int ticks) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public PermissionAttachment addAttachment(Plugin plugin, int ticks) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void removeAttachment(PermissionAttachment attachment) {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean isOp() {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void setOp(boolean value) {
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,104 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2016 Lucko (Luck) <[email protected]>
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
* of this software and associated documentation files (the "Software"), to deal
|
||||||
|
* in the Software without restriction, including without limitation the rights
|
||||||
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
* copies of the Software, and to permit persons to whom the Software is
|
||||||
|
* furnished to do so, subject to the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be included in all
|
||||||
|
* copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
|
* SOFTWARE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package me.lucko.luckperms.bukkit.model;
|
||||||
|
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
|
||||||
|
import org.bukkit.permissions.Permissible;
|
||||||
|
import org.bukkit.permissions.Permission;
|
||||||
|
import org.bukkit.permissions.PermissionAttachment;
|
||||||
|
import org.bukkit.permissions.PermissionAttachmentInfo;
|
||||||
|
import org.bukkit.plugin.Plugin;
|
||||||
|
|
||||||
|
import java.util.Collections;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
|
@AllArgsConstructor
|
||||||
|
public class DummyPermissible implements Permissible {
|
||||||
|
private final Runnable onRefresh;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void recalculatePermissions() {
|
||||||
|
onRefresh.run();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Set<PermissionAttachmentInfo> getEffectivePermissions() {
|
||||||
|
return Collections.emptySet();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isPermissionSet(String name) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isPermissionSet(Permission perm) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean hasPermission(String name) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean hasPermission(Permission perm) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public PermissionAttachment addAttachment(Plugin plugin, String name, boolean value) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public PermissionAttachment addAttachment(Plugin plugin) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public PermissionAttachment addAttachment(Plugin plugin, String name, boolean value, int ticks) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public PermissionAttachment addAttachment(Plugin plugin, int ticks) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void removeAttachment(PermissionAttachment attachment) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isOp() {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setOp(boolean value) {
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
+1
-1
@@ -20,7 +20,7 @@
|
|||||||
* SOFTWARE.
|
* SOFTWARE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package me.lucko.luckperms.bukkit.inject;
|
package me.lucko.luckperms.bukkit.model;
|
||||||
|
|
||||||
import org.bukkit.permissions.PermissibleBase;
|
import org.bukkit.permissions.PermissibleBase;
|
||||||
import org.bukkit.permissions.Permission;
|
import org.bukkit.permissions.Permission;
|
||||||
+56
-13
@@ -20,17 +20,17 @@
|
|||||||
* SOFTWARE.
|
* SOFTWARE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package me.lucko.luckperms.bukkit.inject;
|
package me.lucko.luckperms.bukkit.model;
|
||||||
|
|
||||||
import lombok.experimental.UtilityClass;
|
import lombok.experimental.UtilityClass;
|
||||||
|
|
||||||
import me.lucko.luckperms.bukkit.model.LPPermissible;
|
|
||||||
|
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.permissions.Permissible;
|
import org.bukkit.permissions.PermissibleBase;
|
||||||
|
import org.bukkit.permissions.PermissionAttachment;
|
||||||
|
|
||||||
import java.lang.reflect.Field;
|
import java.lang.reflect.Field;
|
||||||
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
import java.util.concurrent.ConcurrentHashMap;
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
@@ -41,21 +41,44 @@ import java.util.concurrent.ConcurrentHashMap;
|
|||||||
@UtilityClass
|
@UtilityClass
|
||||||
public class Injector {
|
public class Injector {
|
||||||
private static final Map<UUID, LPPermissible> INJECTED_PERMISSIBLES = new ConcurrentHashMap<>();
|
private static final Map<UUID, LPPermissible> INJECTED_PERMISSIBLES = new ConcurrentHashMap<>();
|
||||||
|
|
||||||
private static Field HUMAN_ENTITY_FIELD;
|
private static Field HUMAN_ENTITY_FIELD;
|
||||||
|
private static Field PERMISSIBLEBASE_ATTACHMENTS;
|
||||||
|
|
||||||
static {
|
static {
|
||||||
try {
|
try {
|
||||||
HUMAN_ENTITY_FIELD = Class.forName(getVersionedClassName("entity.CraftHumanEntity")).getDeclaredField("perm");
|
HUMAN_ENTITY_FIELD = Class.forName(getVersionedClassName("entity.CraftHumanEntity")).getDeclaredField("perm");
|
||||||
HUMAN_ENTITY_FIELD.setAccessible(true);
|
HUMAN_ENTITY_FIELD.setAccessible(true);
|
||||||
|
|
||||||
|
PERMISSIBLEBASE_ATTACHMENTS = PermissibleBase.class.getDeclaredField("attachments");
|
||||||
|
PERMISSIBLEBASE_ATTACHMENTS.setAccessible(true);
|
||||||
|
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean inject(Player player, LPPermissible permissible) {
|
public static boolean inject(Player player, LPPermissible lpPermissible) {
|
||||||
try {
|
try {
|
||||||
HUMAN_ENTITY_FIELD.set(player, permissible);
|
PermissibleBase existing = (PermissibleBase) HUMAN_ENTITY_FIELD.get(player);
|
||||||
INJECTED_PERMISSIBLES.put(player.getUniqueId(), permissible);
|
if (existing instanceof LPPermissible) {
|
||||||
|
// uh oh
|
||||||
|
throw new IllegalStateException();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Move attachments over from the old permissible.
|
||||||
|
List<PermissionAttachment> attachments = (List<PermissionAttachment>) PERMISSIBLEBASE_ATTACHMENTS.get(existing);
|
||||||
|
lpPermissible.addAttachments(attachments);
|
||||||
|
attachments.clear();
|
||||||
|
existing.clearPermissions();
|
||||||
|
|
||||||
|
lpPermissible.recalculatePermissions();
|
||||||
|
lpPermissible.setOldPermissible(existing);
|
||||||
|
|
||||||
|
lpPermissible.updateSubscriptionsAsync();
|
||||||
|
|
||||||
|
HUMAN_ENTITY_FIELD.set(player, lpPermissible);
|
||||||
|
INJECTED_PERMISSIBLES.put(player.getUniqueId(), lpPermissible);
|
||||||
return true;
|
return true;
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
@@ -63,14 +86,34 @@ public class Injector {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean unInject(Player player) {
|
public static boolean unInject(Player player, boolean dummy, boolean unsubscribe) {
|
||||||
try {
|
try {
|
||||||
Permissible permissible = (Permissible) HUMAN_ENTITY_FIELD.get(player);
|
PermissibleBase permissible = (PermissibleBase) HUMAN_ENTITY_FIELD.get(player);
|
||||||
if (permissible instanceof LPPermissible) {
|
if (permissible instanceof LPPermissible) {
|
||||||
/* The player is most likely leaving. Bukkit will attempt to call #clearPermissions, so we cannot set to null.
|
|
||||||
However, there's no need to re-inject a real PermissibleBase, so we just inject a dummy instead.
|
permissible.clearPermissions();
|
||||||
This saves tick time, pointlessly recalculating defaults when the instance will never be used. */
|
|
||||||
HUMAN_ENTITY_FIELD.set(player, new DummyPermissibleBase());
|
if (unsubscribe) {
|
||||||
|
((LPPermissible) permissible).unsubscribeFromAllAsync();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (dummy) {
|
||||||
|
HUMAN_ENTITY_FIELD.set(player, new DummyPermissibleBase());
|
||||||
|
} else {
|
||||||
|
LPPermissible lpp = ((LPPermissible) permissible);
|
||||||
|
List<PermissionAttachment> attachments = lpp.getAttachments();
|
||||||
|
|
||||||
|
PermissibleBase newPb = lpp.getOldPermissible();
|
||||||
|
if (newPb == null) {
|
||||||
|
newPb = new PermissibleBase(player);
|
||||||
|
}
|
||||||
|
|
||||||
|
List<PermissionAttachment> newAttachments = (List<PermissionAttachment>) PERMISSIBLEBASE_ATTACHMENTS.get(newPb);
|
||||||
|
newAttachments.addAll(attachments);
|
||||||
|
attachments.clear();
|
||||||
|
|
||||||
|
HUMAN_ENTITY_FIELD.set(player, newPb);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
INJECTED_PERMISSIBLES.remove(player.getUniqueId());
|
INJECTED_PERMISSIBLES.remove(player.getUniqueId());
|
||||||
return true;
|
return true;
|
||||||
@@ -24,10 +24,13 @@ package me.lucko.luckperms.bukkit.model;
|
|||||||
|
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
import lombok.NonNull;
|
import lombok.NonNull;
|
||||||
|
import lombok.Setter;
|
||||||
|
|
||||||
import me.lucko.luckperms.api.Contexts;
|
import me.lucko.luckperms.api.Contexts;
|
||||||
import me.lucko.luckperms.api.Tristate;
|
import me.lucko.luckperms.api.Tristate;
|
||||||
import me.lucko.luckperms.bukkit.LPBukkitPlugin;
|
import me.lucko.luckperms.bukkit.LPBukkitPlugin;
|
||||||
|
import me.lucko.luckperms.common.caching.UserCache;
|
||||||
|
import me.lucko.luckperms.common.config.ConfigKeys;
|
||||||
import me.lucko.luckperms.common.core.model.User;
|
import me.lucko.luckperms.common.core.model.User;
|
||||||
|
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
@@ -39,50 +42,87 @@ import org.bukkit.permissions.PermissionAttachmentInfo;
|
|||||||
import org.bukkit.permissions.PermissionRemovedExecutor;
|
import org.bukkit.permissions.PermissionRemovedExecutor;
|
||||||
import org.bukkit.plugin.Plugin;
|
import org.bukkit.plugin.Plugin;
|
||||||
|
|
||||||
import java.util.HashMap;
|
import java.util.Collections;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.LinkedList;
|
import java.util.LinkedList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
import java.util.logging.Level;
|
import java.util.logging.Level;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Modified PermissibleBase for LuckPerms
|
* Modified PermissibleBase for LuckPerms
|
||||||
*/
|
*/
|
||||||
|
@Getter
|
||||||
public class LPPermissible extends PermissibleBase {
|
public class LPPermissible extends PermissibleBase {
|
||||||
|
|
||||||
@Getter
|
|
||||||
private final User user;
|
private final User user;
|
||||||
|
|
||||||
@Getter
|
|
||||||
private final Player parent;
|
private final Player parent;
|
||||||
|
|
||||||
private final LPBukkitPlugin plugin;
|
private final LPBukkitPlugin plugin;
|
||||||
|
private final SubscriptionManager subscriptions;
|
||||||
|
|
||||||
|
@Setter
|
||||||
|
private PermissibleBase oldPermissible = null;
|
||||||
|
|
||||||
// Attachment stuff.
|
// Attachment stuff.
|
||||||
@Getter
|
private final Map<String, PermissionAttachmentInfo> attachmentPermissions = new ConcurrentHashMap<>();
|
||||||
private final Map<String, PermissionAttachmentInfo> attachmentPermissions = new HashMap<>();
|
private final List<PermissionAttachment> attachments = Collections.synchronizedList(new LinkedList<>());
|
||||||
private final List<PermissionAttachment> attachments = new LinkedList<>();
|
|
||||||
|
|
||||||
public LPPermissible(@NonNull Player parent, User user, LPBukkitPlugin plugin) {
|
public LPPermissible(@NonNull Player parent, User user, LPBukkitPlugin plugin) {
|
||||||
super(parent);
|
super(parent);
|
||||||
this.user = user;
|
this.user = user;
|
||||||
this.parent = parent;
|
this.parent = parent;
|
||||||
this.plugin = plugin;
|
this.plugin = plugin;
|
||||||
|
this.subscriptions = new SubscriptionManager(this);
|
||||||
|
|
||||||
recalculatePermissions();
|
// recalculatePermissions();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void updateSubscriptionsAsync() {
|
||||||
|
plugin.doAsync(this::updateSubscriptions);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void updateSubscriptions() {
|
||||||
|
UserCache cache = user.getUserData();
|
||||||
|
if (cache == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
Set<String> ent = new HashSet<>(cache.getPermissionData(calculateContexts()).getImmutableBacking().keySet());
|
||||||
|
|
||||||
|
if (parent.isOp()) {
|
||||||
|
ent.addAll(plugin.getDefaultsProvider().getOpDefaults().keySet());
|
||||||
|
} else {
|
||||||
|
ent.addAll(plugin.getDefaultsProvider().getNonOpDefaults().keySet());
|
||||||
|
}
|
||||||
|
|
||||||
|
subscriptions.subscribe(ent);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void unsubscribeFromAllAsync() {
|
||||||
|
plugin.doAsync(this::unsubscribeFromAll);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void unsubscribeFromAll() {
|
||||||
|
subscriptions.subscribe(Collections.emptySet());
|
||||||
|
}
|
||||||
|
|
||||||
|
public void addAttachments(List<PermissionAttachment> attachments) {
|
||||||
|
for (PermissionAttachment attachment : attachments) {
|
||||||
|
this.attachments.add(attachment);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public Contexts calculateContexts() {
|
public Contexts calculateContexts() {
|
||||||
return new Contexts(
|
return new Contexts(
|
||||||
plugin.getContextManager().getApplicableContext(parent),
|
plugin.getContextManager().getApplicableContext(parent),
|
||||||
plugin.getConfiguration().isIncludingGlobalPerms(),
|
plugin.getConfiguration().get(ConfigKeys.INCLUDING_GLOBAL_PERMS),
|
||||||
plugin.getConfiguration().isIncludingGlobalWorldPerms(),
|
plugin.getConfiguration().get(ConfigKeys.INCLUDING_GLOBAL_WORLD_PERMS),
|
||||||
true,
|
true,
|
||||||
plugin.getConfiguration().isApplyingGlobalGroups(),
|
plugin.getConfiguration().get(ConfigKeys.APPLYING_GLOBAL_GROUPS),
|
||||||
plugin.getConfiguration().isApplyingGlobalWorldGroups(),
|
plugin.getConfiguration().get(ConfigKeys.APPLYING_GLOBAL_WORLD_GROUPS),
|
||||||
parent.isOp()
|
parent.isOp()
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@@ -195,7 +235,7 @@ public class LPPermissible extends PermissibleBase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
PermissionAttachment result = addAttachment(plugin);
|
PermissionAttachment result = addAttachment(plugin);
|
||||||
if (Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(plugin, () -> result.remove(), ticks) == -1) {
|
if (Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(plugin, result::remove, ticks) == -1) {
|
||||||
Bukkit.getServer().getLogger().log(Level.WARNING, "Could not add PermissionAttachment to " + parent + " for plugin " + plugin.getDescription().getFullName() + ": Scheduler returned -1");
|
Bukkit.getServer().getLogger().log(Level.WARNING, "Could not add PermissionAttachment to " + parent + " for plugin " + plugin.getDescription().getFullName() + ": Scheduler returned -1");
|
||||||
result.remove();
|
result.remove();
|
||||||
return null;
|
return null;
|
||||||
@@ -245,8 +285,8 @@ public class LPPermissible extends PermissibleBase {
|
|||||||
Bukkit.getServer().getPluginManager().unsubscribeFromPermission(name, parent);
|
Bukkit.getServer().getPluginManager().unsubscribeFromPermission(name, parent);
|
||||||
}
|
}
|
||||||
|
|
||||||
Bukkit.getServer().getPluginManager().unsubscribeFromDefaultPerms(false, parent);
|
// Bukkit.getServer().getPluginManager().unsubscribeFromDefaultPerms(false, parent);
|
||||||
Bukkit.getServer().getPluginManager().unsubscribeFromDefaultPerms(true, parent);
|
// Bukkit.getServer().getPluginManager().unsubscribeFromDefaultPerms(true, parent);
|
||||||
|
|
||||||
attachmentPermissions.clear();
|
attachmentPermissions.clear();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,91 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2016 Lucko (Luck) <luck@lucko.me>
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
* of this software and associated documentation files (the "Software"), to deal
|
||||||
|
* in the Software without restriction, including without limitation the rights
|
||||||
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
* copies of the Software, and to permit persons to whom the Software is
|
||||||
|
* furnished to do so, subject to the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be included in all
|
||||||
|
* copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
|
* SOFTWARE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package me.lucko.luckperms.bukkit.model;
|
||||||
|
|
||||||
|
import lombok.RequiredArgsConstructor;
|
||||||
|
|
||||||
|
import com.google.common.collect.ImmutableSet;
|
||||||
|
import com.google.common.collect.Maps;
|
||||||
|
|
||||||
|
import org.bukkit.permissions.Permission;
|
||||||
|
|
||||||
|
import java.util.HashSet;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Handles permission subscriptions with Bukkits plugin manager, for a given LPPermissible.
|
||||||
|
*
|
||||||
|
* Bukkit for some reason sometimes uses subscription status to determine whether a permissible has a given node, instead
|
||||||
|
* of checking directly with {@link org.bukkit.permissions.Permissible#hasPermission(Permission)}.
|
||||||
|
*
|
||||||
|
* {@link org.bukkit.Bukkit#broadcast(String, String)} is a good example of this.
|
||||||
|
*/
|
||||||
|
@RequiredArgsConstructor
|
||||||
|
public class SubscriptionManager {
|
||||||
|
|
||||||
|
private final LPPermissible permissible;
|
||||||
|
private Set<String> currentSubscriptions = ImmutableSet.of();
|
||||||
|
|
||||||
|
public synchronized void subscribe(Set<String> perms) {
|
||||||
|
Set<String> newPerms = ImmutableSet.copyOf(perms);
|
||||||
|
|
||||||
|
// we compare changes to avoid unnecessary time wasted on the main thread mutating this data.
|
||||||
|
// the changes can be calculated here async, and then only the needed changes can be applied.
|
||||||
|
Map.Entry<Set<String>, Set<String>> changes = compareSets(newPerms, currentSubscriptions);
|
||||||
|
|
||||||
|
Set<String> toAdd = changes.getKey();
|
||||||
|
Set<String> toRemove = changes.getValue();
|
||||||
|
|
||||||
|
permissible.getPlugin().doSync(() -> {
|
||||||
|
for (String s : toAdd) {
|
||||||
|
permissible.getPlugin().getServer().getPluginManager().subscribeToPermission(s, permissible.getParent());
|
||||||
|
}
|
||||||
|
for (String s : toRemove) {
|
||||||
|
permissible.getPlugin().getServer().getPluginManager().unsubscribeFromPermission(s, permissible.getParent());
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
this.currentSubscriptions = newPerms;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Compares two sets
|
||||||
|
* @param local the local set
|
||||||
|
* @param remote the remote set
|
||||||
|
* @return the entries to add to remote, and the entries to remove from remote
|
||||||
|
*/
|
||||||
|
private static Map.Entry<Set<String>, Set<String>> compareSets(Set<String> local, Set<String> remote) {
|
||||||
|
// entries in local but not remote need to be added
|
||||||
|
// entries in remote but not local need to be removed
|
||||||
|
|
||||||
|
Set<String> toAdd = new HashSet<>(local);
|
||||||
|
toAdd.removeAll(remote);
|
||||||
|
|
||||||
|
Set<String> toRemove = new HashSet<>(remote);
|
||||||
|
toRemove.removeAll(local);
|
||||||
|
|
||||||
|
return Maps.immutableEntry(toAdd, toRemove);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
Loaded 100 of 435 files, more files were not shown because too many files have changed in this diff.
Show more
Reference in new issue
Block a user