Add promote and demote methods to the API (#938)
This commit is contained in:
@@ -26,9 +26,11 @@
|
||||
package me.lucko.luckperms.api;
|
||||
|
||||
/**
|
||||
* Represents the result of a mutation call.
|
||||
* Represents the result of a data mutation call on a LuckPerms object.
|
||||
*
|
||||
* <p>Usually as the result to a call on a {@link PermissionHolder} or {@link Track}.</p>
|
||||
*/
|
||||
public enum DataMutateResult {
|
||||
public enum DataMutateResult implements MutateResult {
|
||||
|
||||
/**
|
||||
* Indicates the mutation was a success
|
||||
@@ -50,39 +52,14 @@ public enum DataMutateResult {
|
||||
*/
|
||||
FAIL(false);
|
||||
|
||||
private final boolean value;
|
||||
private final boolean success;
|
||||
|
||||
DataMutateResult(boolean value) {
|
||||
this.value = value;
|
||||
DataMutateResult(boolean success) {
|
||||
this.success = success;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets a boolean representation of the result.
|
||||
*
|
||||
* @return a boolean representation
|
||||
*/
|
||||
public boolean asBoolean() {
|
||||
return this.value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets if the result indicates a success
|
||||
*
|
||||
* @return if the result indicates a success
|
||||
* @since 3.4
|
||||
*/
|
||||
@Override
|
||||
public boolean wasSuccess() {
|
||||
return this.value;
|
||||
return this.success;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets if the result indicates a failure
|
||||
*
|
||||
* @return if the result indicates a failure
|
||||
* @since 3.4
|
||||
*/
|
||||
public boolean wasFailure() {
|
||||
return !this.value;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,130 @@
|
||||
/*
|
||||
* This file is part of LuckPerms, licensed under the MIT License.
|
||||
*
|
||||
* Copyright (c) lucko (Luck) <luck@lucko.me>
|
||||
* Copyright (c) contributors
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
package me.lucko.luckperms.api;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
/**
|
||||
* Encapsulates the result of {@link User}s demotion along a {@link Track}.
|
||||
*
|
||||
* @since 4.2
|
||||
*/
|
||||
public interface DemotionResult extends MutateResult {
|
||||
|
||||
/**
|
||||
* Gets the status of the result.
|
||||
*
|
||||
* @return the status
|
||||
*/
|
||||
@Nonnull
|
||||
Status getStatus();
|
||||
|
||||
@Override
|
||||
default boolean wasSuccess() {
|
||||
return getStatus().wasSuccess();
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the name of the group the user was demoted from, if applicable.
|
||||
*
|
||||
* <p>Will only be present for results with a {@link #getStatus() status} of
|
||||
* {@link Status#SUCCESS} or {@link Status#REMOVED_FROM_FIRST_GROUP}.</p>
|
||||
*
|
||||
* <p>The value will also be set for results with the {@link Status#MALFORMED_TRACK} status,
|
||||
* with this value marking the group which no longer exists.</p>
|
||||
*
|
||||
* @return the group the user was demoted from.
|
||||
*/
|
||||
@Nonnull
|
||||
Optional<String> getGroupFrom();
|
||||
|
||||
/**
|
||||
* Gets the name of the group the user was demoted from, if applicable.
|
||||
*
|
||||
* <p>Will only be present for results with a {@link #getStatus() status} of
|
||||
* {@link Status#SUCCESS}.</p>
|
||||
*
|
||||
* @return the group the user was demoted to.
|
||||
*/
|
||||
@Nonnull
|
||||
Optional<String> getGroupTo();
|
||||
|
||||
/**
|
||||
* The result status
|
||||
*/
|
||||
enum Status implements MutateResult {
|
||||
|
||||
/**
|
||||
* Indicates that the user was demoted normally.
|
||||
*/
|
||||
SUCCESS(true),
|
||||
|
||||
/**
|
||||
* Indicates that the user was removed from the first group in the track.
|
||||
*
|
||||
* <p>This usually occurs when the user is currently on the first group, and was demoted
|
||||
* "over the start" of the track.</p>
|
||||
*/
|
||||
REMOVED_FROM_FIRST_GROUP(true),
|
||||
|
||||
/**
|
||||
* Indicates that the previous group in the track no longer exists.
|
||||
*/
|
||||
MALFORMED_TRACK(false),
|
||||
|
||||
/**
|
||||
* Indicates that the user isn't a member of any of the groups on this track.
|
||||
*/
|
||||
NOT_ON_TRACK(false),
|
||||
|
||||
/**
|
||||
* Indicates that the implementation was unable to determine the users current position on
|
||||
* this track.
|
||||
*
|
||||
* <p>This usually occurs when the user is on more than one group on the track.</p>
|
||||
*/
|
||||
AMBIGUOUS_CALL(false),
|
||||
|
||||
/**
|
||||
* An undefined failure occurred.
|
||||
*/
|
||||
UNDEFINED_FAILURE(false);
|
||||
|
||||
private final boolean success;
|
||||
|
||||
Status(boolean success) {
|
||||
this.success = success;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean wasSuccess() {
|
||||
return this.success;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,74 @@
|
||||
/*
|
||||
* This file is part of LuckPerms, licensed under the MIT License.
|
||||
*
|
||||
* Copyright (c) lucko (Luck) <luck@lucko.me>
|
||||
* Copyright (c) contributors
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
package me.lucko.luckperms.api;
|
||||
|
||||
/**
|
||||
* Represents the result to a "mutation" on an object.
|
||||
*
|
||||
* @since 4.2
|
||||
*/
|
||||
public interface MutateResult {
|
||||
|
||||
/**
|
||||
* Instance of {@link MutateResult} which always reports success.
|
||||
*/
|
||||
MutateResult GENERIC_SUCCESS = () -> true;
|
||||
|
||||
/**
|
||||
* Instance of {@link MutateResult} which always reports failure.
|
||||
*/
|
||||
MutateResult GENERIC_FAILURE = () -> false;
|
||||
|
||||
/**
|
||||
* Gets if the operation which produced this result completed successfully.
|
||||
*
|
||||
* @return if the result indicates a success
|
||||
*/
|
||||
boolean wasSuccess();
|
||||
|
||||
/**
|
||||
* Gets if the operation which produced this result failed.
|
||||
*
|
||||
* @return if the result indicates a failure
|
||||
*/
|
||||
default boolean wasFailure() {
|
||||
return !wasSuccess();
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets a boolean representation of the result.
|
||||
*
|
||||
* <p>A value of <code>true</code> marks that the operation {@link #wasSuccess() was a success}
|
||||
* and a value of <code>false</code> marks that the operation
|
||||
* {@link #wasFailure() was a failure}.</p>
|
||||
*
|
||||
* @return a boolean representation
|
||||
*/
|
||||
default boolean asBoolean() {
|
||||
return wasSuccess();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,130 @@
|
||||
/*
|
||||
* This file is part of LuckPerms, licensed under the MIT License.
|
||||
*
|
||||
* Copyright (c) lucko (Luck) <luck@lucko.me>
|
||||
* Copyright (c) contributors
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
package me.lucko.luckperms.api;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
/**
|
||||
* Encapsulates the result of {@link User}s promotion along a {@link Track}.
|
||||
*
|
||||
* @since 4.2
|
||||
*/
|
||||
public interface PromotionResult extends MutateResult {
|
||||
|
||||
/**
|
||||
* Gets the status of the result.
|
||||
*
|
||||
* @return the status
|
||||
*/
|
||||
@Nonnull
|
||||
Status getStatus();
|
||||
|
||||
@Override
|
||||
default boolean wasSuccess() {
|
||||
return getStatus().wasSuccess();
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the name of the group the user was promoted from, if applicable.
|
||||
*
|
||||
* <p>Will only be present for results with a {@link #getStatus() status} of
|
||||
* {@link Status#SUCCESS}.</p>
|
||||
*
|
||||
* @return the group the user was promoted from.
|
||||
*/
|
||||
@Nonnull
|
||||
Optional<String> getGroupFrom();
|
||||
|
||||
/**
|
||||
* Gets the name of the group the user was promoted from, if applicable.
|
||||
*
|
||||
* <p>Will only be present for results with a {@link #getStatus() status} of
|
||||
* {@link Status#SUCCESS} or {@link Status#ADDED_TO_FIRST_GROUP}.</p>
|
||||
*
|
||||
* <p>The value will also be set for results with the {@link Status#MALFORMED_TRACK} status,
|
||||
* with this value marking the group which no longer exists.</p>
|
||||
*
|
||||
* @return the group the user was promoted to.
|
||||
*/
|
||||
@Nonnull
|
||||
Optional<String> getGroupTo();
|
||||
|
||||
/**
|
||||
* The result status
|
||||
*/
|
||||
enum Status implements MutateResult {
|
||||
|
||||
/**
|
||||
* Indicates that the user was promoted normally.
|
||||
*/
|
||||
SUCCESS(true),
|
||||
|
||||
/**
|
||||
* Indicates that the user was added to the first group in the track.
|
||||
*
|
||||
* <p>This usually occurs when the user isn't already on any of the groups in the track.</p>
|
||||
*/
|
||||
ADDED_TO_FIRST_GROUP(true),
|
||||
|
||||
/**
|
||||
* Indicates that the next group in the track no longer exists.
|
||||
*/
|
||||
MALFORMED_TRACK(false),
|
||||
|
||||
/**
|
||||
* Indicates that the user is already a member of the group at the end of the track,
|
||||
* and as such cannot be promoted any further.
|
||||
*/
|
||||
END_OF_TRACK(false),
|
||||
|
||||
/**
|
||||
* Indicates that the implementation was unable to determine the users current position on
|
||||
* this track.
|
||||
*
|
||||
* <p>This usually occurs when the user is on more than one group on the track.</p>
|
||||
*/
|
||||
AMBIGUOUS_CALL(false),
|
||||
|
||||
/**
|
||||
* An undefined failure occurred.
|
||||
*/
|
||||
UNDEFINED_FAILURE(false);
|
||||
|
||||
private final boolean success;
|
||||
|
||||
Status(boolean success) {
|
||||
this.success = success;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean wasSuccess() {
|
||||
return this.success;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -25,6 +25,8 @@
|
||||
|
||||
package me.lucko.luckperms.api;
|
||||
|
||||
import me.lucko.luckperms.api.context.ContextSet;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
@@ -88,6 +90,28 @@ public interface Track {
|
||||
@Nullable
|
||||
String getPrevious(@Nonnull Group current);
|
||||
|
||||
/**
|
||||
* Promotes the given user along this track.
|
||||
*
|
||||
* @param user the user to promote
|
||||
* @param contextSet the contexts to promote the user in
|
||||
* @return the result of the action
|
||||
* @since 4.2
|
||||
*/
|
||||
@Nonnull
|
||||
PromotionResult promote(@Nonnull User user, @Nonnull ContextSet contextSet);
|
||||
|
||||
/**
|
||||
* Demotes the given user along this track.
|
||||
*
|
||||
* @param user the user to demote
|
||||
* @param contextSet the contexts to demote the user in
|
||||
* @return the result of the action
|
||||
* @since 4.2
|
||||
*/
|
||||
@Nonnull
|
||||
DemotionResult demote(@Nonnull User user, @Nonnull ContextSet contextSet);
|
||||
|
||||
/**
|
||||
* Appends a group to the end of this track
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user