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

JSON Value Providers & Operators #76

Merged
merged 21 commits into from
Mar 1, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
beb941e
First design of the ValueProviders & ValueComparators
WolfyScript Feb 10, 2022
5ac835f
Merge branch 'master' into value_providers
WolfyScript Feb 26, 2022
a39215f
Changed version to 3.16-SNAPSHOT
WolfyScript Feb 26, 2022
037e26f
Added Operators to use in Json and compare values.
WolfyScript Feb 26, 2022
bfd7d5a
Fixed ValueProviders and added String provider
WolfyScript Feb 26, 2022
1f1dd2d
Removed Statement class
WolfyScript Feb 26, 2022
69976ee
Added Registry for Operators and register the defaults.
WolfyScript Feb 26, 2022
0957bd7
Some Comparator changes (They will probably be removed anyway)
WolfyScript Feb 26, 2022
8844d3f
Added KeyedBaseType annotation to identify base type of the Keyed Obj…
WolfyScript Feb 27, 2022
53b9e9c
JsonIgnore the getValue in ValueProvider
WolfyScript Feb 27, 2022
1c9318e
Added ValueProviderVariable to use variables from the context inside …
WolfyScript Feb 27, 2022
3da9c0a
ComparisonOperators now use the context to get the values.
WolfyScript Feb 27, 2022
836f0f3
Register the new value provider types
WolfyScript Feb 27, 2022
e368422
Register the new value provider registries for the TypeIdResolver
WolfyScript Feb 27, 2022
5a825cb
Added LogicalOperators
WolfyScript Feb 27, 2022
b68de7d
Shorter keys for ComparisonOperators and ValueProviders
WolfyScript Feb 27, 2022
129e899
Created eval package
WolfyScript Feb 27, 2022
79f77cb
Removed ValueComparators
WolfyScript Feb 27, 2022
5f04829
Added PAPI value providers
WolfyScript Feb 28, 2022
2218c84
Merge branch 'master' into value_providers
WolfyScript Mar 1, 2022
5afccd4
Fixed merge issues
WolfyScript Mar 1, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
<parent>
<artifactId>wolfyutilities-parent</artifactId>
<groupId>com.wolfyscript.wolfyutilities</groupId>
<version>3.16.2.0</version>
<version>3.16-SNAPSHOT</version>
</parent>
<build>
<plugins>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,13 @@
import me.wolfyscript.utilities.api.inventory.tags.Tags;
import me.wolfyscript.utilities.util.Keyed;
import me.wolfyscript.utilities.util.NamespacedKey;
import me.wolfyscript.utilities.util.eval.operators.Operator;
import me.wolfyscript.utilities.util.particles.ParticleAnimation;
import me.wolfyscript.utilities.util.particles.ParticleEffect;
import me.wolfyscript.utilities.util.particles.animators.Animator;
import me.wolfyscript.utilities.util.particles.shapes.Shape;
import me.wolfyscript.utilities.util.particles.timer.Timer;
import me.wolfyscript.utilities.util.eval.value_providers.ValueProvider;

import java.util.HashMap;
import java.util.Map;
Expand Down Expand Up @@ -81,6 +83,9 @@ public class Registries {
private final TypeRegistry<Action<?>> customItemActions;
private final TypeRegistry<Event<?>> customItemEvents;

private final TypeRegistry<ValueProvider<?>> valueProviders;
private final TypeRegistry<Operator> operators;

public Registries(WolfyUtilCore core) {
this.core = core;

Expand All @@ -99,6 +104,8 @@ public Registries(WolfyUtilCore core) {
customItemNbtChecks = new TypeRegistrySimple<>(new NamespacedKey(core, "custom_item_nbt_checks"), this);
customItemActions = new TypeRegistrySimple<>(ITEM_ACTION_TYPES, this);
customItemEvents = new TypeRegistrySimple<>(ITEM_EVENT_TYPES, this);
valueProviders = new TypeRegistrySimple<>(new NamespacedKey(core, "value_providers"), this);
operators = new TypeRegistrySimple<>(new NamespacedKey(core, "operators"), this);
}

void indexTypedRegistry(IRegistry<?> registry) {
Expand Down Expand Up @@ -170,10 +177,6 @@ public RegistryParticleAnimation getParticleAnimations() {
return particleAnimations;
}

public TypeRegistry<Shape> getParticleShapes() {
return particleShapes;
}

/**
* Gets the registry containing all the available {@link ParticleEffect}s.
*
Expand All @@ -187,6 +190,18 @@ public Tags<CustomItem> getItemTags() {
return itemTags;
}

public Registry<Action<?>> getCustomItemActionValues() {
return customItemActionValues;
}

public Registry<Event<?>> getCustomItemEventValues() {
return customItemEventValues;
}

public TypeRegistry<Shape> getParticleShapes() {
return particleShapes;
}

/**
* Gets the registry containing all the available NBTChecks for CustomItems.
*
Expand Down Expand Up @@ -222,11 +237,11 @@ public TypeRegistry<Event<?>> getCustomItemEvents() {
return customItemEvents;
}

public Registry<Action<?>> getCustomItemActionValues() {
return customItemActionValues;
public TypeRegistry<ValueProvider<?>> getValueProviders() {
return valueProviders;
}

public Registry<Event<?>> getCustomItemEventValues() {
return customItemEventValues;
public TypeRegistry<Operator> getOperators() {
return operators;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/*
* WolfyUtilities, APIs and Utilities for Minecraft Spigot plugins
* Copyright (C) 2021 WolfyScript
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/

package me.wolfyscript.utilities.util.eval.context;

import java.util.HashMap;
import java.util.Map;

public class EvalContext {

private final Map<String, Object> variables;

public EvalContext() {
this.variables = new HashMap<>();
}

public Object getVariable(String variableName) {
return variables.get(variableName);
}

public void setVariable(String name, Object value) {
variables.put(name, value);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/*
* WolfyUtilities, APIs and Utilities for Minecraft Spigot plugins
* Copyright (C) 2021 WolfyScript
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/

package me.wolfyscript.utilities.util.eval.context;

import org.bukkit.entity.Player;

public class EvalContextPlayer extends EvalContext {

private final Player player;

public EvalContextPlayer(Player player) {
super();
this.player = player;
}

public Player getPlayer() {
return player;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/*
* WolfyUtilities, APIs and Utilities for Minecraft Spigot plugins
* Copyright (C) 2021 WolfyScript
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/

package me.wolfyscript.utilities.util.eval.operators;

import me.wolfyscript.utilities.util.NamespacedKey;
import me.wolfyscript.utilities.util.eval.context.EvalContext;
import me.wolfyscript.utilities.util.json.jackson.annotations.KeyedBaseType;

/**
* An Operator that evaluates into a booleanish value.
*/
@KeyedBaseType(baseType = Operator.class)
public abstract class BoolOperator extends Operator {

public BoolOperator(NamespacedKey namespacedKey) {
super(namespacedKey);
}

public abstract boolean evaluate(EvalContext context);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
/*
* WolfyUtilities, APIs and Utilities for Minecraft Spigot plugins
* Copyright (C) 2021 WolfyScript
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/

package me.wolfyscript.utilities.util.eval.operators;

import me.wolfyscript.utilities.util.NamespacedKey;
import me.wolfyscript.utilities.util.eval.context.EvalContext;
import me.wolfyscript.utilities.util.eval.value_providers.ValueProvider;

/**
* Represents comparison operators that compare values.<br>
* <ul>
* <li>equal (==) {@link ComparisonOperatorEqual}</li>
* <li>not equal (!=) {@link ComparisonOperatorNotEqual}</li>
* <li>less (<) {@link ComparisonOperatorLess}</li>
* <li>less or equal(<=) {@link ComparisonOperatorLessEqual}</li>
* <li>greater (>) {@link ComparisonOperatorGreater}</li>
* <li>greater or equal (>=) {@link ComparisonOperatorGreaterEqual}</li>
* </ul>
*
* @param <V> The type of the objects to compare. Must be the same for both objects.
*/
public abstract class ComparisonOperator<V extends Comparable<V>> extends BoolOperator {

protected ValueProvider<V> thisValue;
protected ValueProvider<V> thatValue;

protected ComparisonOperator(NamespacedKey namespacedKey, ValueProvider<V> thisValue, ValueProvider<V> thatValue) {
super(namespacedKey);
this.thisValue = thisValue;
this.thatValue = thatValue;
}

@Override
public abstract boolean evaluate(EvalContext context);

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/*
* WolfyUtilities, APIs and Utilities for Minecraft Spigot plugins
* Copyright (C) 2021 WolfyScript
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/

package me.wolfyscript.utilities.util.eval.operators;

import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonProperty;
import me.wolfyscript.utilities.util.NamespacedKey;
import me.wolfyscript.utilities.util.eval.context.EvalContext;
import me.wolfyscript.utilities.util.eval.value_providers.ValueProvider;

public class ComparisonOperatorEqual<V extends Comparable<V>> extends ComparisonOperator<V> {

public static final NamespacedKey KEY = NamespacedKey.wolfyutilties("equal");

@JsonCreator
protected ComparisonOperatorEqual(@JsonProperty("this") ValueProvider<V> thisValue, @JsonProperty("that") ValueProvider<V> thatValue) {
super(KEY, thisValue, thatValue);
}

@Override
public boolean evaluate(EvalContext context) {
return this.thisValue.getValue(context).compareTo(this.thatValue.getValue(context)) == 0;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/*
* WolfyUtilities, APIs and Utilities for Minecraft Spigot plugins
* Copyright (C) 2021 WolfyScript
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/

package me.wolfyscript.utilities.util.eval.operators;

import me.wolfyscript.utilities.util.NamespacedKey;
import me.wolfyscript.utilities.util.eval.context.EvalContext;
import me.wolfyscript.utilities.util.eval.value_providers.ValueProvider;

public class ComparisonOperatorGreater<V extends Comparable<V>> extends ComparisonOperator<V> {

public static final NamespacedKey KEY = NamespacedKey.wolfyutilties("greater");

protected ComparisonOperatorGreater(ValueProvider<V> thisValue, ValueProvider<V> thatValue) {
super(KEY, thisValue, thatValue);
}

@Override
public boolean evaluate(EvalContext context) {
return this.thisValue.getValue(context).compareTo(this.thatValue.getValue(context)) > 0;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/*
* WolfyUtilities, APIs and Utilities for Minecraft Spigot plugins
* Copyright (C) 2021 WolfyScript
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/

package me.wolfyscript.utilities.util.eval.operators;

import me.wolfyscript.utilities.util.NamespacedKey;
import me.wolfyscript.utilities.util.eval.context.EvalContext;
import me.wolfyscript.utilities.util.eval.value_providers.ValueProvider;

public class ComparisonOperatorGreaterEqual<V extends Comparable<V>> extends ComparisonOperator<V> {

public static final NamespacedKey KEY = NamespacedKey.wolfyutilties("greater_equal");

protected ComparisonOperatorGreaterEqual(ValueProvider<V> thisValue, ValueProvider<V> thatValue) {
super(KEY, thisValue, thatValue);
}

@Override
public boolean evaluate(EvalContext context) {
return this.thisValue.getValue(context).compareTo(this.thatValue.getValue(context)) >= 0;
}
}