Skip to content
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

Implement Permissions API #229

Draft
wants to merge 59 commits into
base: dev/v2
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 8 commits
Commits
Show all changes
59 commits
Select commit Hold shift + click to select a range
11e0492
start permissions api
MrIvanPlays Nov 22, 2022
2dba238
more foundation
MrIvanPlays Nov 22, 2022
6fde59f
allNodesWithContext
MrIvanPlays Nov 22, 2022
3cea14e
add weight
MrIvanPlays Nov 22, 2022
5856160
Merge branch 'dev/2.0.0' of https://github.com/ArcanePlugins/Treasury…
MrIvanPlays Nov 23, 2022
4ca5ce8
progress
MrIvanPlays Nov 23, 2022
a12c1b3
bring some consistency in NodeFactory
MrIvanPlays Nov 23, 2022
2978084
retrieveHeldContexts
MrIvanPlays Nov 23, 2022
94defc8
simplify space check
MrIvanPlays Nov 24, 2022
4cbbc25
Merge branch 'dev/2.0.0' of https://github.com/ArcanePlugins/Treasury…
MrIvanPlays Nov 27, 2022
73f0695
Merge branch 'new/permissions-api' of https://github.com/ArcanePlugin…
MrIvanPlays Nov 27, 2022
e698aeb
add removeNode
MrIvanPlays Nov 27, 2022
4afceec
allNodesKeys
MrIvanPlays Nov 27, 2022
c62b477
parentNodeHolder
MrIvanPlays Nov 27, 2022
bb411e9
Merge branch 'dev/2.0.0' of https://github.com/ArcanePlugins/Treasury…
MrIvanPlays Nov 27, 2022
9aee46c
Merge branch 'dev/2.0.0' of https://github.com/ArcanePlugins/Treasury…
MrIvanPlays Nov 28, 2022
7779ac5
Merge branch 'dev/2.0.0' of https://github.com/ArcanePlugins/Treasury…
MrIvanPlays Nov 28, 2022
5b399c6
Merge branch 'dev/2.0.0' of https://github.com/ArcanePlugins/Treasury…
MrIvanPlays Nov 28, 2022
4082e78
Merge branch 'dev/2.0.0' of https://github.com/ArcanePlugins/Treasury…
MrIvanPlays Nov 29, 2022
4abc1ed
add missing annotation so that github actions builds
MrIvanPlays Nov 29, 2022
5fcbdd7
Merge branch 'dev/2.0.0' of https://github.com/ArcanePlugins/Treasury…
MrIvanPlays Nov 29, 2022
16eb615
Merge branch 'dev/2.0.0' of https://github.com/ArcanePlugins/Treasury…
MrIvanPlays Nov 29, 2022
06b8cc2
NodeHolderGroup
MrIvanPlays Nov 29, 2022
49f8120
Merge branch 'dev/2.0.0' of https://github.com/ArcanePlugins/Treasury…
MrIvanPlays Nov 30, 2022
c102ce0
require context to be specified for retrieve and insertOrModify
MrIvanPlays Nov 30, 2022
ddef41d
also for removeNode
MrIvanPlays Nov 30, 2022
213884c
remove hasNode(Node<?>)
MrIvanPlays Nov 30, 2022
4d47ce8
group methods
MrIvanPlays Nov 30, 2022
46e594a
do not hardcode contexts and types
MrIvanPlays Nov 30, 2022
a966915
fix node factory
MrIvanPlays Nov 30, 2022
5b13b61
Merge branch 'dev/2.0.0' of https://github.com/ArcanePlugins/Treasury…
MrIvanPlays Dec 1, 2022
cee38b7
Merge branch 'dev/2.0.0' of https://github.com/ArcanePlugins/Treasury…
MrIvanPlays Dec 5, 2022
3726e34
Merge branch 'dev/2.0.0' of https://github.com/ArcanePlugins/Treasury…
MrIvanPlays Dec 11, 2022
067f29b
remove ContextSet#registerContext and document it
MrIvanPlays Dec 11, 2022
2d79a88
remove "hasNode"
MrIvanPlays Dec 11, 2022
adb9c9a
make ContextSet iterable
MrIvanPlays Dec 11, 2022
98269eb
specify nullability
MrIvanPlays Dec 11, 2022
3891a02
Merge branch 'dev/2.0.0' of https://github.com/ArcanePlugins/Treasury…
MrIvanPlays Dec 26, 2022
3a7eb23
basic events
MrIvanPlays Dec 26, 2022
68e90f3
Merge branch 'dev/2.0.0' of https://github.com/ArcanePlugins/Treasury…
MrIvanPlays Jan 7, 2023
eb81eae
use namespacedkey here too
MrIvanPlays Jan 7, 2023
dac47d7
Merge branch 'dev/2.0.0' of https://github.com/ArcanePlugins/Treasury…
MrIvanPlays Feb 2, 2023
f37c380
some small changes
MrIvanPlays Feb 2, 2023
235db89
Merge branch 'dev/2.0.0' of https://github.com/ArcanePlugins/Treasury…
MrIvanPlays Feb 16, 2023
82bb05e
change weight to primitive value
MrIvanPlays Feb 16, 2023
7159a0f
Merge branch 'dev/2.0.0' of https://github.com/ArcanePlugins/Treasury…
MrIvanPlays Apr 5, 2023
789878c
Update with dev/2.0.0
MrIvanPlays Apr 5, 2023
f633b43
rework nodes
MrIvanPlays Apr 9, 2023
2c870d2
some changes
MrIvanPlays Apr 10, 2023
49ce899
forgot annos, whoops
MrIvanPlays Apr 10, 2023
46ef940
Merge branch 'dev/2.0.0' of https://github.com/ArcanePlugins/Treasury…
MrIvanPlays Apr 26, 2023
4bd2284
Transform NodeEvent
MrIvanPlays Apr 26, 2023
afe4506
Update constructors of delegating events
MrIvanPlays Apr 26, 2023
3deb463
Merge branch 'dev/v2' of https://github.com/ArcanePlugins/Treasury in…
MrIvanPlays Jul 2, 2023
8817874
Merge branch 'dev/v2' of https://github.com/ArcanePlugins/Treasury in…
MrIvanPlays Jul 6, 2023
c0540a4
Write some javadocs
MrIvanPlays Jul 6, 2023
e235362
NotNull
MrIvanPlays Jul 6, 2023
516f31d
Merge branch 'dev/v2' of https://github.com/ArcanePlugins/Treasury in…
MrIvanPlays Jul 11, 2023
9c2d517
Document Node.Builder
MrIvanPlays Jul 11, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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();
MrIvanPlays marked this conversation as resolved.
Show resolved Hide resolved

}
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;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/*
* 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");
}
boolean hasSpace = false;
for (int i = 0; i < value.length(); i++) {
if (Character.isWhitespace(value.charAt(i))) {
hasSpace = true;
break;
}
}
if (hasSpace) {
throw new IllegalArgumentException("Invalid value: value should not contain spaces!");
}
MrIvanPlays marked this conversation as resolved.
Show resolved Hide resolved
return new Context(type, value);
}
}
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.
Show resolved Hide resolved

@NotNull String key();

@NotNull Data data();

@NotNull Node<Data> copyWithNewData(
@NotNull Context context, @Nullable Integer weight, @NotNull Data data
);

}
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
);

}
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.
Show resolved Hide resolved

}
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();
}

}
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;
}

}
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;
}

}
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 {

}
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 {

}