-
Notifications
You must be signed in to change notification settings - Fork 15
Implement Permissions API #229
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
MrIvanPlays
wants to merge
59
commits into
dev/v2
Choose a base branch
from
new/permissions-api
base: dev/v2
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from 9 commits
Commits
Show all changes
59 commits
Select commit
Hold shift + click to select a range
11e0492
start permissions api
MrIvanPlays 2dba238
more foundation
MrIvanPlays 6fde59f
allNodesWithContext
MrIvanPlays 3cea14e
add weight
MrIvanPlays 5856160
Merge branch 'dev/2.0.0' of https://github.com/ArcanePlugins/Treasury…
MrIvanPlays 4ca5ce8
progress
MrIvanPlays a12c1b3
bring some consistency in NodeFactory
MrIvanPlays 2978084
retrieveHeldContexts
MrIvanPlays 94defc8
simplify space check
MrIvanPlays 4cbbc25
Merge branch 'dev/2.0.0' of https://github.com/ArcanePlugins/Treasury…
MrIvanPlays 73f0695
Merge branch 'new/permissions-api' of https://github.com/ArcanePlugin…
MrIvanPlays e698aeb
add removeNode
MrIvanPlays 4afceec
allNodesKeys
MrIvanPlays c62b477
parentNodeHolder
MrIvanPlays bb411e9
Merge branch 'dev/2.0.0' of https://github.com/ArcanePlugins/Treasury…
MrIvanPlays 9aee46c
Merge branch 'dev/2.0.0' of https://github.com/ArcanePlugins/Treasury…
MrIvanPlays 7779ac5
Merge branch 'dev/2.0.0' of https://github.com/ArcanePlugins/Treasury…
MrIvanPlays 5b399c6
Merge branch 'dev/2.0.0' of https://github.com/ArcanePlugins/Treasury…
MrIvanPlays 4082e78
Merge branch 'dev/2.0.0' of https://github.com/ArcanePlugins/Treasury…
MrIvanPlays 4abc1ed
add missing annotation so that github actions builds
MrIvanPlays 5fcbdd7
Merge branch 'dev/2.0.0' of https://github.com/ArcanePlugins/Treasury…
MrIvanPlays 16eb615
Merge branch 'dev/2.0.0' of https://github.com/ArcanePlugins/Treasury…
MrIvanPlays 06b8cc2
NodeHolderGroup
MrIvanPlays 49f8120
Merge branch 'dev/2.0.0' of https://github.com/ArcanePlugins/Treasury…
MrIvanPlays c102ce0
require context to be specified for retrieve and insertOrModify
MrIvanPlays ddef41d
also for removeNode
MrIvanPlays 213884c
remove hasNode(Node<?>)
MrIvanPlays 4d47ce8
group methods
MrIvanPlays 46e594a
do not hardcode contexts and types
MrIvanPlays a966915
fix node factory
MrIvanPlays 5b13b61
Merge branch 'dev/2.0.0' of https://github.com/ArcanePlugins/Treasury…
MrIvanPlays cee38b7
Merge branch 'dev/2.0.0' of https://github.com/ArcanePlugins/Treasury…
MrIvanPlays 3726e34
Merge branch 'dev/2.0.0' of https://github.com/ArcanePlugins/Treasury…
MrIvanPlays 067f29b
remove ContextSet#registerContext and document it
MrIvanPlays 2d79a88
remove "hasNode"
MrIvanPlays adb9c9a
make ContextSet iterable
MrIvanPlays 98269eb
specify nullability
MrIvanPlays 3891a02
Merge branch 'dev/2.0.0' of https://github.com/ArcanePlugins/Treasury…
MrIvanPlays 3a7eb23
basic events
MrIvanPlays 68e90f3
Merge branch 'dev/2.0.0' of https://github.com/ArcanePlugins/Treasury…
MrIvanPlays eb81eae
use namespacedkey here too
MrIvanPlays dac47d7
Merge branch 'dev/2.0.0' of https://github.com/ArcanePlugins/Treasury…
MrIvanPlays f37c380
some small changes
MrIvanPlays 235db89
Merge branch 'dev/2.0.0' of https://github.com/ArcanePlugins/Treasury…
MrIvanPlays 82bb05e
change weight to primitive value
MrIvanPlays 7159a0f
Merge branch 'dev/2.0.0' of https://github.com/ArcanePlugins/Treasury…
MrIvanPlays 789878c
Update with dev/2.0.0
MrIvanPlays f633b43
rework nodes
MrIvanPlays 2c870d2
some changes
MrIvanPlays 49ce899
forgot annos, whoops
MrIvanPlays 46ef940
Merge branch 'dev/2.0.0' of https://github.com/ArcanePlugins/Treasury…
MrIvanPlays 4bd2284
Transform NodeEvent
MrIvanPlays afe4506
Update constructors of delegating events
MrIvanPlays 3deb463
Merge branch 'dev/v2' of https://github.com/ArcanePlugins/Treasury in…
MrIvanPlays 8817874
Merge branch 'dev/v2' of https://github.com/ArcanePlugins/Treasury in…
MrIvanPlays c0540a4
Write some javadocs
MrIvanPlays e235362
NotNull
MrIvanPlays 516f31d
Merge branch 'dev/v2' of https://github.com/ArcanePlugins/Treasury in…
MrIvanPlays 9c2d517
Document Node.Builder
MrIvanPlays File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
28 changes: 28 additions & 0 deletions
28
api/src/main/java/me/lokka30/treasury/api/permission/PermissionsProvider.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,28 @@ | ||
| /* | ||
| * This file is/was part of Treasury. To read more information about Treasury such as its licensing, see <https://github.com/ArcanePlugins/Treasury>. | ||
| */ | ||
|
|
||
| package me.lokka30.treasury.api.permission; | ||
|
|
||
| import java.util.Collection; | ||
| import java.util.UUID; | ||
| import java.util.concurrent.CompletableFuture; | ||
| import me.lokka30.treasury.api.common.response.Response; | ||
| import me.lokka30.treasury.api.permission.node.NodeFactory; | ||
| import me.lokka30.treasury.api.permission.node.holder.NodeHolder; | ||
| import me.lokka30.treasury.api.permission.node.holder.NodeHolderPlayer; | ||
| import org.jetbrains.annotations.NotNull; | ||
|
|
||
| public interface PermissionsProvider { | ||
|
|
||
| @NotNull NodeFactory nodeFactory(); | ||
|
|
||
| @NotNull CompletableFuture<Response<NodeHolderPlayer>> retrievePlayerNodeHolder(@NotNull UUID uuid); | ||
|
|
||
| @NotNull CompletableFuture<Response<NodeHolder>> retrieveNodeHolder(@NotNull String identifier); | ||
|
|
||
| @NotNull CompletableFuture<Response<Collection<UUID>>> allPlayerNodeHolders(); | ||
|
|
||
| @NotNull CompletableFuture<Response<Collection<String>>> allNodeHolders(); | ||
|
|
||
| } | ||
29 changes: 29 additions & 0 deletions
29
api/src/main/java/me/lokka30/treasury/api/permission/context/Context.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,29 @@ | ||
| /* | ||
| * This file is/was part of Treasury. To read more information about Treasury such as its licensing, see <https://github.com/ArcanePlugins/Treasury>. | ||
| */ | ||
|
|
||
| package me.lokka30.treasury.api.permission.context; | ||
|
|
||
| import org.jetbrains.annotations.NotNull; | ||
|
|
||
| public final class Context { | ||
|
|
||
| private final ContextType type; | ||
| private final String value; | ||
|
|
||
| Context(@NotNull ContextType type, @NotNull String value) { | ||
| this.type = type; | ||
| this.value = value; | ||
| } | ||
|
|
||
| @NotNull | ||
| public ContextType type() { | ||
| return this.type; | ||
| } | ||
|
|
||
| @NotNull | ||
| public String value() { | ||
| return this.value; | ||
| } | ||
|
|
||
| } |
35 changes: 35 additions & 0 deletions
35
api/src/main/java/me/lokka30/treasury/api/permission/context/ContextType.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,35 @@ | ||
| /* | ||
| * This file is/was part of Treasury. To read more information about Treasury such as its licensing, see <https://github.com/ArcanePlugins/Treasury>. | ||
| */ | ||
|
|
||
| package me.lokka30.treasury.api.permission.context; | ||
|
|
||
| import org.jetbrains.annotations.NotNull; | ||
|
|
||
| public enum ContextType { | ||
| GLOBAL, | ||
| WORLD, | ||
| SERVER | ||
| ; | ||
|
|
||
| private static final Context global = new Context(ContextType.GLOBAL, ""); | ||
|
|
||
| @NotNull | ||
| public static Context global() { | ||
| return global; | ||
| } | ||
|
|
||
| @NotNull | ||
| public static Context newContext(@NotNull ContextType type, @NotNull String value) { | ||
| if (type == GLOBAL) { | ||
| return global; | ||
| } | ||
| if (value.isEmpty()) { | ||
| throw new IllegalArgumentException("value is empty"); | ||
| } | ||
| if (value.indexOf(' ') != -1) { | ||
| throw new IllegalArgumentException("Invalid value: value should not contain spaces!"); | ||
| } | ||
| return new Context(type, value); | ||
| } | ||
| } |
28 changes: 28 additions & 0 deletions
28
api/src/main/java/me/lokka30/treasury/api/permission/node/Node.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,28 @@ | ||
| /* | ||
| * This file is/was part of Treasury. To read more information about Treasury such as its licensing, see <https://github.com/ArcanePlugins/Treasury>. | ||
| */ | ||
|
|
||
| package me.lokka30.treasury.api.permission.node; | ||
|
|
||
| import me.lokka30.treasury.api.permission.context.Context; | ||
| import me.lokka30.treasury.api.permission.node.type.NodeType; | ||
| import org.jetbrains.annotations.NotNull; | ||
| import org.jetbrains.annotations.Nullable; | ||
|
|
||
| public interface Node<Data> { | ||
|
|
||
| @NotNull NodeType<Data> nodeType(); | ||
|
|
||
| @NotNull Context context(); | ||
|
|
||
| @Nullable Integer weight(); | ||
|
MrIvanPlays marked this conversation as resolved.
Outdated
|
||
|
|
||
| @NotNull String key(); | ||
|
|
||
| @NotNull Data data(); | ||
|
|
||
| @NotNull Node<Data> copyWithNewData( | ||
| @NotNull Context context, @Nullable Integer weight, @NotNull Data data | ||
| ); | ||
|
|
||
| } | ||
49 changes: 49 additions & 0 deletions
49
api/src/main/java/me/lokka30/treasury/api/permission/node/NodeFactory.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,49 @@ | ||
| /* | ||
| * This file is/was part of Treasury. To read more information about Treasury such as its licensing, see <https://github.com/ArcanePlugins/Treasury>. | ||
| */ | ||
|
|
||
| package me.lokka30.treasury.api.permission.node; | ||
|
|
||
| import me.lokka30.treasury.api.common.misc.TriState; | ||
| import me.lokka30.treasury.api.permission.context.Context; | ||
| import me.lokka30.treasury.api.permission.context.ContextType; | ||
| import me.lokka30.treasury.api.permission.node.type.PermissionNode; | ||
| import org.jetbrains.annotations.NotNull; | ||
| import org.jetbrains.annotations.Nullable; | ||
|
|
||
| public abstract class NodeFactory { | ||
|
|
||
| @NotNull | ||
| public PermissionNode createPermissionNode(@NotNull String permission) { | ||
| return this.createPermissionNode(permission, ContextType.global()); | ||
| } | ||
|
|
||
| public PermissionNode createPermissionNode( | ||
| @NotNull String permission, @NotNull Context context | ||
| ) { | ||
| return this.createPermissionNode(permission, context, (Integer) null); | ||
| } | ||
|
|
||
| @NotNull | ||
| public PermissionNode createPermissionNode( | ||
| @NotNull String permission, @NotNull Context context, @Nullable Integer weight | ||
| ) { | ||
| return this.createPermissionNode(permission, context, weight, TriState.UNSPECIFIED); | ||
| } | ||
|
|
||
| @NotNull | ||
| public PermissionNode createPermissionNode( | ||
| @NotNull String permission, @NotNull Context context, @NotNull TriState value | ||
| ) { | ||
| return this.createPermissionNode(permission, context, null, value); | ||
| } | ||
|
|
||
| @NotNull | ||
| public abstract PermissionNode createPermissionNode( | ||
| @NotNull String permission, | ||
| @NotNull Context context, | ||
| @Nullable Integer weight, | ||
| @NotNull TriState value | ||
| ); | ||
|
|
||
| } |
43 changes: 43 additions & 0 deletions
43
api/src/main/java/me/lokka30/treasury/api/permission/node/holder/NodeHolder.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,43 @@ | ||
| /* | ||
| * This file is/was part of Treasury. To read more information about Treasury such as its licensing, see <https://github.com/ArcanePlugins/Treasury>. | ||
| */ | ||
|
|
||
| package me.lokka30.treasury.api.permission.node.holder; | ||
|
|
||
| import java.util.Collection; | ||
| import java.util.Optional; | ||
| import java.util.concurrent.CompletableFuture; | ||
| import me.lokka30.treasury.api.common.misc.TriState; | ||
| import me.lokka30.treasury.api.common.response.Response; | ||
| import me.lokka30.treasury.api.permission.context.Context; | ||
| import me.lokka30.treasury.api.permission.node.Node; | ||
| import me.lokka30.treasury.api.permission.node.type.NodeType; | ||
| import org.jetbrains.annotations.NotNull; | ||
|
|
||
| public interface NodeHolder { | ||
|
|
||
| @NotNull String getIdentifier(); | ||
|
|
||
| @NotNull CompletableFuture<Response<Collection<Node<?>>>> allNodes(); | ||
|
|
||
| @NotNull <Data> CompletableFuture<Response<Collection<Node<Data>>>> allNodesWithType(@NotNull NodeType<Data> nodeType); | ||
|
|
||
| @NotNull CompletableFuture<Response<Collection<Node<?>>>> allNodesWithContext(@NotNull Context context); | ||
|
|
||
| @NotNull CompletableFuture<Response<TriState>> hasNode(@NotNull Node<?> node); | ||
|
|
||
| @NotNull CompletableFuture<Response<TriState>> hasNode(@NotNull String nodeKey); | ||
|
|
||
| @NotNull <Data> CompletableFuture<Response<Optional<Node<Data>>>> retrieveNodeWithKey(@NotNull String key); | ||
|
|
||
| /** | ||
| * Retrieves all the {@link Context contexts} this {@code NodeHolder} holds {@link Node nodes} | ||
| * under. | ||
| * | ||
| * @return | ||
| */ | ||
| @NotNull CompletableFuture<Response<Collection<NodeHolder>>> retrieveHeldContexts(); | ||
|
|
||
| @NotNull <Data> CompletableFuture<Response<TriState>> insertOrModifyNode(@NotNull Node<Data> node); | ||
|
MrIvanPlays marked this conversation as resolved.
Outdated
|
||
|
|
||
| } | ||
20 changes: 20 additions & 0 deletions
20
api/src/main/java/me/lokka30/treasury/api/permission/node/holder/NodeHolderPlayer.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| /* | ||
| * This file is/was part of Treasury. To read more information about Treasury such as its licensing, see <https://github.com/ArcanePlugins/Treasury>. | ||
| */ | ||
|
|
||
| package me.lokka30.treasury.api.permission.node.holder; | ||
|
|
||
| import java.util.UUID; | ||
| import org.jetbrains.annotations.NotNull; | ||
|
|
||
| public interface NodeHolderPlayer extends NodeHolder { | ||
|
|
||
| @NotNull UUID getUniqueId(); | ||
|
|
||
| @Override | ||
| @NotNull | ||
| default String getIdentifier() { | ||
| return this.getUniqueId().toString(); | ||
| } | ||
|
|
||
| } |
25 changes: 25 additions & 0 deletions
25
api/src/main/java/me/lokka30/treasury/api/permission/node/type/NodeType.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,25 @@ | ||
| /* | ||
| * This file is/was part of Treasury. To read more information about Treasury such as its licensing, see <https://github.com/ArcanePlugins/Treasury>. | ||
| */ | ||
|
|
||
| package me.lokka30.treasury.api.permission.node.type; | ||
|
|
||
| import me.lokka30.treasury.api.common.misc.TriState; | ||
| import org.jetbrains.annotations.NotNull; | ||
|
|
||
| public final class NodeType<Data> { | ||
|
|
||
| public static final NodeType<TriState> PERMISSION = new NodeType<>(TriState.class); | ||
|
|
||
| private final Class<Data> dataClass; | ||
|
|
||
| private NodeType(@NotNull Class<Data> dataClass) { | ||
| this.dataClass = dataClass; | ||
| } | ||
|
|
||
| @NotNull | ||
| public Class<Data> dataClass() { | ||
| return this.dataClass; | ||
| } | ||
|
|
||
| } |
20 changes: 20 additions & 0 deletions
20
api/src/main/java/me/lokka30/treasury/api/permission/node/type/PermissionNode.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| /* | ||
| * This file is/was part of Treasury. To read more information about Treasury such as its licensing, see <https://github.com/ArcanePlugins/Treasury>. | ||
| */ | ||
|
|
||
| package me.lokka30.treasury.api.permission.node.type; | ||
|
|
||
| import me.lokka30.treasury.api.common.misc.TriState; | ||
| import me.lokka30.treasury.api.permission.node.Node; | ||
| import me.lokka30.treasury.api.permission.node.type.NodeType; | ||
| import org.jetbrains.annotations.NotNull; | ||
|
|
||
| public interface PermissionNode extends Node<TriState> { | ||
|
|
||
| @Override | ||
| @NotNull | ||
| default NodeType<TriState> nodeType() { | ||
| return NodeType.PERMISSION; | ||
| } | ||
|
|
||
| } |
6 changes: 6 additions & 0 deletions
6
api/src/main/java/me/lokka30/treasury/api/permission/node/type/PrefixNode.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| package me.lokka30.treasury.api.permission.node.type; | ||
|
|
||
| // todo | ||
| public interface PrefixNode { | ||
|
|
||
| } |
6 changes: 6 additions & 0 deletions
6
api/src/main/java/me/lokka30/treasury/api/permission/node/type/SuffixNode.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| package me.lokka30.treasury.api.permission.node.type; | ||
|
|
||
| // todo | ||
| public interface SuffixNode { | ||
|
|
||
| } |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.