Add operator parameter
This commit is contained in:
1 parent
573f69d9cd
commit
1682b13e1a
5 files changed
+198
No files matched your search
@@ -42,6 +42,7 @@ import org.spongepowered.api.command.parameter.managed.ValueParameter;
|
||||
import org.spongepowered.api.command.parameter.managed.ValueParameterModifier;
|
||||
import org.spongepowered.api.command.parameter.managed.ValueParser;
|
||||
import org.spongepowered.api.command.parameter.managed.ValueUsage;
|
||||
import org.spongepowered.api.command.parameter.managed.operator.Operator;
|
||||
import org.spongepowered.api.command.parameter.managed.standard.ResourceKeyedValueParameters;
|
||||
import org.spongepowered.api.command.parameter.managed.standard.VariableValueParameters;
|
||||
import org.spongepowered.api.data.persistence.DataContainer;
|
||||
@@ -519,6 +520,16 @@ public interface Parameter {
|
||||
return Parameter.builder(Long.class, ResourceKeyedValueParameters.LONG);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a builder that has the {@link ValueParameter} set to
|
||||
* {@link ResourceKeyedValueParameters#OPERATOR}.
|
||||
*
|
||||
* @return A {@link Parameter.Value.Builder}
|
||||
*/
|
||||
static Parameter.Value.Builder<Operator> operator() {
|
||||
return Parameter.builder(Operator.class, ResourceKeyedValueParameters.OPERATOR);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a builder that has the {@link ValueParameter} set to
|
||||
* {@link ResourceKeyedValueParameters#PLAYER}.
|
||||
|
||||
@@ -0,0 +1,79 @@
|
||||
/*
|
||||
* This file is part of SpongeAPI, licensed under the MIT License (MIT).
|
||||
*
|
||||
* Copyright (c) SpongePowered <https://www.spongepowered.org>
|
||||
* 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 org.spongepowered.api.command.parameter.managed.operator;
|
||||
|
||||
import org.spongepowered.api.command.parameter.managed.standard.ResourceKeyedValueParameters;
|
||||
import org.spongepowered.api.util.annotation.CatalogedBy;
|
||||
|
||||
/**
|
||||
* Represents an operator that can be specified in a command.
|
||||
*
|
||||
* @see ResourceKeyedValueParameters#OPERATOR
|
||||
*/
|
||||
@CatalogedBy(Operators.class)
|
||||
public interface Operator {
|
||||
|
||||
/**
|
||||
* The string representation of this operator
|
||||
*
|
||||
* @return The representation
|
||||
*/
|
||||
String asString();
|
||||
|
||||
/**
|
||||
* An operator that can operate on two numbers and return a number.
|
||||
*/
|
||||
interface Simple extends Operator {
|
||||
|
||||
/**
|
||||
* Operates on two numbers, returning the result of the operation.
|
||||
*
|
||||
* @param first the first number to operate on
|
||||
* @param second the second number to operate on
|
||||
* @return the result of the operation
|
||||
*/
|
||||
int apply(int first, int second);
|
||||
|
||||
/**
|
||||
* Operates on two numbers, returning the result of the operation.
|
||||
*
|
||||
* @param first the first number to operate on
|
||||
* @param second the second number to operate on
|
||||
* @return the result of the operation
|
||||
*/
|
||||
long apply(long first, long second);
|
||||
|
||||
/**
|
||||
* Operates on two numbers, returning the result of the operation.
|
||||
*
|
||||
* @param first the first number to operate on
|
||||
* @param second the second number to operate on
|
||||
* @return the result of the operation
|
||||
*/
|
||||
double apply(double first, double second);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,94 @@
|
||||
/*
|
||||
* This file is part of SpongeAPI, licensed under the MIT License (MIT).
|
||||
*
|
||||
* Copyright (c) SpongePowered <https://www.spongepowered.org>
|
||||
* 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 org.spongepowered.api.command.parameter.managed.operator;
|
||||
|
||||
import org.spongepowered.api.ResourceKey;
|
||||
import org.spongepowered.api.Sponge;
|
||||
import org.spongepowered.api.registry.DefaultedRegistryReference;
|
||||
import org.spongepowered.api.registry.RegistryKey;
|
||||
import org.spongepowered.api.registry.RegistryTypes;
|
||||
|
||||
public final class Operators {
|
||||
|
||||
// @formatter:off
|
||||
|
||||
// SORTFIELDS:ON
|
||||
|
||||
/**
|
||||
* Represents the addition operation, +=
|
||||
*/
|
||||
public static final DefaultedRegistryReference<Operator.Simple> ADDITION = Operators.key(ResourceKey.sponge("addition"));
|
||||
|
||||
/**
|
||||
* Represents the assignment operation, =
|
||||
*/
|
||||
public static final DefaultedRegistryReference<Operator> ASSIGN = Operators.key(ResourceKey.sponge("assign"));
|
||||
|
||||
/**
|
||||
* Represents the division operation, /=
|
||||
*/
|
||||
public static final DefaultedRegistryReference<Operator.Simple> DIVISION = Operators.key(ResourceKey.sponge("division"));
|
||||
|
||||
/**
|
||||
* Represents the max operation, >
|
||||
*/
|
||||
public static final DefaultedRegistryReference<Operator.Simple> MAX = Operators.key(ResourceKey.sponge("max"));
|
||||
|
||||
/**
|
||||
* Represents the min operation, <
|
||||
*/
|
||||
public static final DefaultedRegistryReference<Operator.Simple> MIN = Operators.key(ResourceKey.sponge("min"));
|
||||
|
||||
/**
|
||||
* Represents the modulus operation, %=
|
||||
*/
|
||||
public static final DefaultedRegistryReference<Operator.Simple> MODULUS = Operators.key(ResourceKey.sponge("modulus"));
|
||||
|
||||
/**
|
||||
* Represents the multiplication operation, *=
|
||||
*/
|
||||
public static final DefaultedRegistryReference<Operator.Simple> MULTIPLICATION = Operators.key(ResourceKey.sponge("multiplication"));
|
||||
|
||||
/**
|
||||
* Represents the subtraction operation, -=
|
||||
*/
|
||||
public static final DefaultedRegistryReference<Operator.Simple> SUBTRACTION = Operators.key(ResourceKey.sponge("subtraction"));
|
||||
|
||||
/**
|
||||
* Represents the swap operation, ><
|
||||
*/
|
||||
public static final DefaultedRegistryReference<Operator> SWAP = Operators.key(ResourceKey.sponge("swap"));
|
||||
|
||||
// SORTFIELDS:OFF
|
||||
|
||||
private Operators() {
|
||||
}
|
||||
|
||||
private static <T extends Operator> DefaultedRegistryReference<T> key(final ResourceKey location) {
|
||||
return RegistryKey.of(RegistryTypes.OPERATOR, location).asDefaultedReference(() -> Sponge.game().registries());
|
||||
}
|
||||
|
||||
// @formatter:off
|
||||
}
|
||||
+11
@@ -28,6 +28,8 @@ import net.kyori.adventure.text.Component;
|
||||
import org.spongepowered.api.ResourceKey;
|
||||
import org.spongepowered.api.Sponge;
|
||||
import org.spongepowered.api.block.BlockState;
|
||||
import org.spongepowered.api.command.parameter.managed.operator.Operator;
|
||||
import org.spongepowered.api.command.parameter.managed.operator.Operators;
|
||||
import org.spongepowered.api.data.persistence.DataContainer;
|
||||
import org.spongepowered.api.entity.Entity;
|
||||
import org.spongepowered.api.entity.living.player.Player;
|
||||
@@ -254,6 +256,15 @@ public final class ResourceKeyedValueParameters {
|
||||
*/
|
||||
public static final DefaultedRegistryReference<ResourceKeyedValueParameter<Void>> NONE = ResourceKeyedValueParameters.key(ResourceKey.sponge("none"));
|
||||
|
||||
/**
|
||||
* Expect an argument to represent an {@link Operator}
|
||||
*
|
||||
* <p>Valid operators are specified in {@link Operators}</p>
|
||||
*
|
||||
* <p>Returns an {@link Operator}</p>
|
||||
*/
|
||||
public static final DefaultedRegistryReference<ResourceKeyedValueParameter<Operator>> OPERATOR = ResourceKeyedValueParameters.key(ResourceKey.sponge("operator"));
|
||||
|
||||
/**
|
||||
* Expect an argument to represent an online player.
|
||||
*
|
||||
|
||||
@@ -34,6 +34,7 @@ import org.spongepowered.api.block.entity.BlockEntityType;
|
||||
import org.spongepowered.api.block.transaction.Operation;
|
||||
import org.spongepowered.api.command.parameter.managed.ValueParameter;
|
||||
import org.spongepowered.api.command.parameter.managed.clientcompletion.ClientCompletionType;
|
||||
import org.spongepowered.api.command.parameter.managed.operator.Operator;
|
||||
import org.spongepowered.api.command.registrar.CommandRegistrarType;
|
||||
import org.spongepowered.api.command.registrar.tree.ClientCompletionKey;
|
||||
import org.spongepowered.api.command.selector.SelectorSortAlgorithm;
|
||||
@@ -316,6 +317,8 @@ public final class RegistryTypes {
|
||||
|
||||
public static final DefaultedRegistryType<ObjectiveDisplayMode> OBJECTIVE_DISPLAY_MODE = RegistryTypes.spongeKeyInGame("objective_display_mode");
|
||||
|
||||
public static final DefaultedRegistryType<Operator> OPERATOR = RegistryTypes.spongeKeyInGame("operator");
|
||||
|
||||
public static final DefaultedRegistryType<Operation> OPERATION = RegistryTypes.spongeKeyInGame("operation");
|
||||
|
||||
public static final DefaultedRegistryType<Orientation> ORIENTATION = RegistryTypes.spongeKeyInGame("orientation");
|
||||
|
||||
Reference in new issue
Block a user