Compare commits

..

23 Commits

Author SHA1 Message Date
Auxilor
7eb1b917dc Moved supported versions into ProxyConstants 2022-02-28 20:15:40 +00:00
Auxilor
fdba12082c Refactoring 2022-02-28 20:12:15 +00:00
Auxilor
516ecc1c3d Lookup cleanup 2022-02-28 20:10:53 +00:00
Auxilor
cfd545c735 Added ScheduledForRemoval inVersion 2022-02-28 20:04:02 +00:00
Auxilor
0ded1fe68b DummyEntity changes 2022-02-28 20:02:58 +00:00
Auxilor
4fce11b149 Fixed name and equipment arg parsers 2022-02-28 19:29:53 +00:00
Auxilor
2374e8fe03 Merge remote-tracking branch 'origin/develop' into develop 2022-02-28 18:52:18 +00:00
Auxilor
36ccf346d7 Codestyle 2022-02-28 18:51:49 +00:00
Auxilor
cb480bd88d Removed requirements from the backend, added warnings in static intializers. 2022-02-28 18:51:07 +00:00
Auxilor
8cc96cb30e Added StringUtils#toNiceString 2022-02-28 16:04:02 +00:00
Auxilor
736ba0f8b0 Janky CombatLogX fix 2022-02-28 15:55:21 +00:00
Auxilor
5b5fefee8e Fixed StringUtils#splitAround 2022-02-28 15:34:56 +00:00
Auxilor
8941e3179b Minor changes 2022-02-28 15:26:40 +00:00
Auxilor
19ce4c56a9 Fixed tests 2022-02-28 14:24:10 +00:00
Auxilor
337c5d2b84 Fixed missing lib jar 2022-02-28 14:17:24 +00:00
Auxilor
631c17aedc Build changes 2022-02-28 14:16:39 +00:00
Auxilor
0ff4ac92be Fixed SCore dependency 2022-02-28 14:15:01 +00:00
Auxilor
aa94094078 Moved SCore to jitpac 2022-02-28 14:11:45 +00:00
Auxilor
135ddcf331 Fixed ExecutableItems dependencies 2022-02-28 14:07:45 +00:00
Auxilor
e5d31e0b49 Updated to 6.26.0 2022-02-28 13:56:16 +00:00
Auxilor
448b2e4b3f Switched entity lookup off to new system 2022-02-28 13:53:44 +00:00
Auxilor
ebb30e3a70 Began rewriting lookups to reusable system 2022-02-28 13:18:58 +00:00
Auxilor
fb89415636 Dummy entities are now instances of the DummyEntityDelegate class 2022-02-28 12:17:33 +00:00
49 changed files with 886 additions and 265 deletions

View File

@@ -115,6 +115,10 @@ allprojects {
exclude(group = "com.github.cryptomorin", module = "XSeries")
}
configurations.testImplementation {
setExtendsFrom(listOf(configurations.compileOnly.get()))
}
tasks {
compileKotlin {
kotlinOptions {

View File

@@ -204,15 +204,6 @@ public interface Handler {
*/
void registerBStats(@NotNull EcoPlugin plugin);
/**
* Get the requirement factory.
*
* @return The factory.
*/
@NotNull
@Deprecated(forRemoval = true)
com.willfp.eco.core.requirement.RequirementFactory getRequirementFactory();
/**
* Get Adventure audiences.
*

View File

@@ -0,0 +1,10 @@
package com.willfp.eco.core.entities;
import org.bukkit.entity.Entity;
/**
* Interface for Dummy Entities in order to filter them using instanceof.
*/
public interface DummyEntity extends Entity {
}

View File

@@ -6,7 +6,6 @@ import com.willfp.eco.core.entities.impl.EmptyTestableEntity;
import com.willfp.eco.core.entities.impl.ModifiedTestableEntity;
import com.willfp.eco.core.entities.impl.SimpleTestableEntity;
import com.willfp.eco.util.NamespacedKeyUtils;
import com.willfp.eco.util.StringUtils;
import org.bukkit.Location;
import org.bukkit.NamespacedKey;
import org.bukkit.entity.Entity;
@@ -37,6 +36,11 @@ public final class Entities {
*/
private static final List<EntityArgParser> ARG_PARSERS = new ArrayList<>();
/**
* The lookup handler.
*/
private static final EntitiesLookupHandler ENTITIES_LOOKUP_HANDLER = new EntitiesLookupHandler(Entities::doParse);
/**
* Register a new custom item.
*
@@ -87,20 +91,11 @@ public final class Entities {
*/
@NotNull
public static TestableEntity lookup(@NotNull final String key) {
if (key.contains("?")) {
String[] options = key.split("\\?");
for (String option : options) {
TestableEntity lookup = lookup(option);
if (!(lookup instanceof EmptyTestableEntity)) {
return lookup;
}
}
return new EmptyTestableEntity();
}
String[] args = StringUtils.parseTokens(key);
return ENTITIES_LOOKUP_HANDLER.parseKey(key);
}
@NotNull
private static TestableEntity doParse(@NotNull final String[] args) {
if (args.length == 0) {
return new EmptyTestableEntity();
}
@@ -131,7 +126,6 @@ public final class Entities {
entity = part;
}
String[] modifierArgs = Arrays.copyOfRange(args, 1, args.length);
List<EntityArgParseResult> parseResults = new ArrayList<>();
@@ -172,7 +166,6 @@ public final class Entities {
return entity;
}
/**
* Get a Testable Entity from an ItemStack.
* <p>

View File

@@ -0,0 +1,48 @@
package com.willfp.eco.core.entities;
import com.willfp.eco.core.entities.impl.EmptyTestableEntity;
import com.willfp.eco.core.entities.impl.GroupedTestableEntities;
import com.willfp.eco.core.lookup.LookupHandler;
import org.jetbrains.annotations.NotNull;
import java.util.Collection;
import java.util.function.Function;
/**
* Handle item lookup strings.
*/
public class EntitiesLookupHandler implements LookupHandler<TestableEntity> {
/**
* The parser.
*/
private final Function<String[], @NotNull TestableEntity> parser;
/**
* Create new lookup handler.
*
* @param parser The parser.
*/
public EntitiesLookupHandler(@NotNull final Function<String[], @NotNull TestableEntity> parser) {
this.parser = parser;
}
@Override
public @NotNull TestableEntity parse(@NotNull final String[] args) {
return parser.apply(args);
}
@Override
public boolean validate(@NotNull final TestableEntity object) {
return !(object instanceof EmptyTestableEntity);
}
@Override
public @NotNull TestableEntity getFailsafe() {
return new EmptyTestableEntity();
}
@Override
public @NotNull TestableEntity join(@NotNull final Collection<TestableEntity> options) {
return new GroupedTestableEntities(options);
}
}

View File

@@ -1,5 +1,6 @@
package com.willfp.eco.core.entities;
import com.willfp.eco.core.lookup.Testable;
import org.bukkit.Location;
import org.bukkit.entity.Entity;
import org.jetbrains.annotations.NotNull;
@@ -8,13 +9,14 @@ import org.jetbrains.annotations.Nullable;
/**
* An item with a test to see if any item is that item.
*/
public interface TestableEntity {
public interface TestableEntity extends Testable<Entity> {
/**
* If an Entity matches the test.
*
* @param entity The entity to test.
* @return If the entity matches.
*/
@Override
boolean matches(@Nullable Entity entity);
/**

View File

@@ -0,0 +1,68 @@
package com.willfp.eco.core.entities.impl;
import com.willfp.eco.core.entities.TestableEntity;
import com.willfp.eco.util.NumberUtils;
import org.apache.commons.lang.Validate;
import org.bukkit.Location;
import org.bukkit.entity.Entity;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.util.ArrayList;
import java.util.Collection;
/**
* A group of testable entities.
*
* @see com.willfp.eco.core.entities.CustomEntity
*/
public class GroupedTestableEntities implements TestableEntity {
/**
* The children.
*/
private final Collection<TestableEntity> children;
/**
* Create a new group of testable entities.
*
* @param children The children.
*/
public GroupedTestableEntities(@NotNull final Collection<TestableEntity> children) {
Validate.isTrue(!children.isEmpty(), "Group must have at least one child!");
this.children = children;
}
/**
* If the item matches any children.
*
* @param entity The entity to test.
* @return If the entity matches the test of any children.
*/
@Override
public boolean matches(@Nullable final Entity entity) {
for (TestableEntity child : children) {
if (child.matches(entity)) {
return true;
}
}
return false;
}
@Override
public Entity spawn(@NotNull final Location location) {
return new ArrayList<>(children)
.get(NumberUtils.randInt(0, children.size() - 1))
.spawn(location);
}
/**
* Get the children.
*
* @return The children.
*/
public Collection<TestableEntity> getChildren() {
return new ArrayList<>(children);
}
}

View File

@@ -44,7 +44,8 @@ public final class AntigriefManager {
* @param location The location.
* @return If player can pick up item.
*/
public static boolean canPickupItem(@NotNull final Player player, @NotNull final Location location) {
public static boolean canPickupItem(@NotNull final Player player,
@NotNull final Location location) {
return REGISTERED.stream().allMatch(antigriefWrapper -> antigriefWrapper.canPickupItem(player, location));
}

View File

@@ -10,7 +10,6 @@ import com.willfp.eco.core.recipe.parts.ModifiedTestableItem;
import com.willfp.eco.core.recipe.parts.TestableStack;
import com.willfp.eco.util.NamespacedKeyUtils;
import com.willfp.eco.util.NumberUtils;
import com.willfp.eco.util.StringUtils;
import org.bukkit.Material;
import org.bukkit.NamespacedKey;
import org.bukkit.inventory.ItemStack;
@@ -68,6 +67,11 @@ public final class Items {
*/
private static final List<LookupArgParser> ARG_PARSERS = new ArrayList<>();
/**
* The handler.
*/
private static final ItemsLookupHandler ITEMS_LOOKUP_HANDLER = new ItemsLookupHandler(Items::doParse);
/**
* Register a new custom item.
*
@@ -131,20 +135,11 @@ public final class Items {
*/
@NotNull
public static TestableItem lookup(@NotNull final String key) {
if (key.contains("?")) {
String[] options = key.split("\\?");
for (String option : options) {
TestableItem lookup = lookup(option);
if (!(lookup instanceof EmptyTestableItem)) {
return lookup;
}
}
return new EmptyTestableItem();
}
String[] args = StringUtils.parseTokens(key);
return ITEMS_LOOKUP_HANDLER.parseKey(key);
}
@NotNull
private static TestableItem doParse(@NotNull final String[] args) {
if (args.length == 0) {
return new EmptyTestableItem();
}

View File

@@ -0,0 +1,48 @@
package com.willfp.eco.core.items;
import com.willfp.eco.core.lookup.LookupHandler;
import com.willfp.eco.core.recipe.parts.EmptyTestableItem;
import com.willfp.eco.core.recipe.parts.GroupedTestableItems;
import org.jetbrains.annotations.NotNull;
import java.util.Collection;
import java.util.function.Function;
/**
* Handle item lookup strings.
*/
public class ItemsLookupHandler implements LookupHandler<TestableItem> {
/**
* The parser.
*/
private final Function<String[], @NotNull TestableItem> parser;
/**
* Create new lookup handler.
*
* @param parser The parser.
*/
public ItemsLookupHandler(@NotNull final Function<String[], @NotNull TestableItem> parser) {
this.parser = parser;
}
@Override
public @NotNull TestableItem parse(@NotNull final String[] args) {
return parser.apply(args);
}
@Override
public boolean validate(@NotNull final TestableItem object) {
return !(object instanceof EmptyTestableItem);
}
@Override
public @NotNull TestableItem getFailsafe() {
return new EmptyTestableItem();
}
@Override
public @NotNull TestableItem join(@NotNull final Collection<TestableItem> options) {
return new GroupedTestableItems(options);
}
}

View File

@@ -1,18 +1,20 @@
package com.willfp.eco.core.items;
import com.willfp.eco.core.lookup.Testable;
import org.bukkit.inventory.ItemStack;
import org.jetbrains.annotations.Nullable;
/**
* An item with a test to see if any item is that item.
*/
public interface TestableItem {
public interface TestableItem extends Testable<ItemStack> {
/**
* If an ItemStack matches the recipe part.
*
* @param itemStack The item to test.
* @return If the item matches.
*/
@Override
boolean matches(@Nullable ItemStack itemStack);
/**

View File

@@ -0,0 +1,76 @@
package com.willfp.eco.core.lookup;
import com.willfp.eco.util.StringUtils;
import org.jetbrains.annotations.NotNull;
import java.util.Collection;
/**
* Handle lookups, used in {@link com.willfp.eco.core.entities.Entities} and {@link com.willfp.eco.core.items.Items}.
*
* @param <T> The type of testable object, eg {@link com.willfp.eco.core.items.TestableItem}.
*/
public interface LookupHandler<T extends Testable<?>> {
/**
* Parse lookup string completely.
* <p>
* You shouldn't override this method unless you're doing something
* technically interesting or weird. This is the entry point for all
* lookup parsers, {@link this#parse(String[])} is to specify implementation-specific
* parsing.
*
* @param key The key.
* @return The object.
*/
default T parseKey(@NotNull String key) {
for (SegmentParser parser : SegmentParser.values()) {
T generated = parser.parse(key, this);
if (generated != null) {
return generated;
}
}
String[] args = StringUtils.parseTokens(key);
return this.parse(args);
}
/**
* Parse arguments to an object.
*
* @param args The arguments.
* @return The object.
*/
@NotNull
T parse(@NotNull String[] args);
/**
* Validate an object.
*
* @param object The object.
* @return If validated.
*/
boolean validate(@NotNull T object);
/**
* Get the failsafe object.
* <p>
* A failsafe object should never pass {@link this#validate(Testable)}, as this will
* cause issues with segment parsers. See {@link com.willfp.eco.core.items.ItemsLookupHandler} and
* {@link com.willfp.eco.core.recipe.parts.EmptyTestableItem} for examples.
*
* @return The failsafe.
*/
@NotNull
T getFailsafe();
/**
* Join several options together.
*
* @param options The options.
* @return The joined object.
*/
@NotNull
T join(@NotNull Collection<T> options);
}

View File

@@ -0,0 +1,83 @@
package com.willfp.eco.core.lookup;
import com.willfp.eco.util.StringUtils;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
/**
* Parse a key into segments.
*/
public abstract class SegmentParser {
/**
* All segment parsers.
*/
private static final List<SegmentParser> REGISTERED = new ArrayList<>();
/**
* The pattern to split keys on.
*/
private final String pattern;
/**
* Create new lookup segment parser.
*
* @param pattern The pattern.
*/
protected SegmentParser(@NotNull final String pattern) {
this.pattern = pattern;
}
/**
* Register the parser.
*
* @return The parser.
*/
public SegmentParser register() {
REGISTERED.add(this);
return this;
}
/**
* Try parse segments from key.
*
* @param key The key.
* @param handler The handler.
* @param <T> The object type.
* @return Null if no segments were found, or the object generated from the segments.
*/
@Nullable
public <T extends Testable<?>> T parse(@NotNull final String key,
@NotNull final LookupHandler<T> handler) {
if (!key.contains(" " + pattern + " ")) {
return null;
}
String[] segments = StringUtils.splitAround(key, pattern);
return handleSegments(segments, handler);
}
/**
* Handle segments from key.
*
* @param segments The key segments.
* @param handler The handler.
* @param <T> The object type.
* @return The returned object.
*/
protected abstract <T extends Testable<?>> T handleSegments(@NotNull String[] segments,
@NotNull LookupHandler<T> handler);
/**
* Get all segment parsers.
*
* @return All parsers.
*/
public static Collection<SegmentParser> values() {
return new ArrayList<>(REGISTERED);
}
}

View File

@@ -0,0 +1,18 @@
package com.willfp.eco.core.lookup;
import org.jetbrains.annotations.Nullable;
/**
* Interface for testing if any object matches another object.
*
* @param <T> The type of object.
*/
public interface Testable<T> {
/**
* If object matches the test.
*
* @param other The other object.
* @return If matches.
*/
boolean matches(@Nullable T other);
}

View File

@@ -2,6 +2,9 @@ package com.willfp.eco.core.proxy;
import org.bukkit.Bukkit;
import java.util.Arrays;
import java.util.List;
/**
* Proxy / NMS constants.
*/
@@ -11,6 +14,14 @@ public final class ProxyConstants {
*/
public static final String NMS_VERSION = Bukkit.getServer().getClass().getPackage().getName().split("\\.")[3];
/**
* All supported NMS versions.
*/
public static final List<String> SUPPORTED_VERSIONS = Arrays.asList(
"v1_17_R1",
"v1_18_R1"
);
private ProxyConstants() {
throw new UnsupportedOperationException("This is a utility class and cannot be instantiated");
}

View File

@@ -0,0 +1,68 @@
package com.willfp.eco.core.recipe.parts;
import com.willfp.eco.core.items.TestableItem;
import org.apache.commons.lang.Validate;
import org.bukkit.inventory.ItemStack;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.util.ArrayList;
import java.util.Collection;
/**
* A group of testable items.
*
* @see com.willfp.eco.core.items.CustomItem
*/
public class GroupedTestableItems implements TestableItem {
/**
* The children.
*/
private final Collection<TestableItem> children;
/**
* Create a new group of testable items.
*
* @param children The children.
*/
public GroupedTestableItems(@NotNull final Collection<TestableItem> children) {
Validate.isTrue(!children.isEmpty(), "Group must have at least one child!");
this.children = children;
}
/**
* If the item matches any children.
*
* @param itemStack The item to test.
* @return If the item matches the test of any children..
*/
@Override
public boolean matches(@Nullable final ItemStack itemStack) {
for (TestableItem child : children) {
if (child.matches(itemStack)) {
return true;
}
}
return false;
}
@Override
public ItemStack getItem() {
for (TestableItem child : children) {
return child.getItem();
}
throw new IllegalStateException("Empty group of children!");
}
/**
* Get the children.
*
* @return The children.
*/
public Collection<TestableItem> getChildren() {
return new ArrayList<>(children);
}
}

View File

@@ -1,6 +1,8 @@
package com.willfp.eco.core.requirement;
import com.willfp.eco.core.Eco;
import org.bukkit.entity.Player;
import org.jetbrains.annotations.ApiStatus;
import org.jetbrains.annotations.NotNull;
import java.util.List;
@@ -10,8 +12,8 @@ import java.util.List;
*
* @deprecated No typing, weak definitions, and not an API component. Shouldn't be in eco.
*/
@ApiStatus.ScheduledForRemoval(inVersion = "6.27.0")
@Deprecated(since = "6.24.0", forRemoval = true)
@SuppressWarnings("DeprecatedIsStillUsed")
public abstract class Requirement {
/**
* Create a new requirement.
@@ -29,4 +31,9 @@ public abstract class Requirement {
*/
public abstract boolean doesPlayerMeet(@NotNull Player player,
@NotNull List<String> args);
static {
Eco.getHandler().getEcoPlugin().getLogger().severe("Loading for-removal Requirements system! This will throw an error once 6.27.0 is released."
+ "Make sure you're running the latest version of all your plugins!");
}
}

View File

@@ -1,25 +0,0 @@
package com.willfp.eco.core.requirement;
import com.willfp.eco.core.Eco;
import org.jetbrains.annotations.ApiStatus;
import org.jetbrains.annotations.NotNull;
/**
* Interface for internal requirement factory implementations.
*
* @deprecated See {@link Requirement}.
*/
@ApiStatus.Internal
@Eco.HandlerComponent
@Deprecated(since = "6.24.0", forRemoval = true)
@SuppressWarnings({"removal", "DeprecatedIsStillUsed"})
public interface RequirementFactory {
/**
* Create a requirement.
*
* @param name The name.
* @return The requirement returned for the name.
* Will return a requirement that is always true if not found.
*/
Requirement create(@NotNull String name);
}

View File

@@ -1,35 +1,40 @@
package com.willfp.eco.core.requirement;
import com.willfp.eco.core.Eco;
import org.bukkit.entity.Player;
import org.jetbrains.annotations.ApiStatus;
import org.jetbrains.annotations.NotNull;
import java.util.List;
/**
* Contains methods and fields pertaining to requirements.
*
* @deprecated See {@link Requirement}.
*/
@ApiStatus.ScheduledForRemoval(inVersion = "6.27.0")
@Deprecated(since = "6.24.0", forRemoval = true)
@SuppressWarnings("removal")
public final class Requirements {
/**
* Requires a player to have a permission.
*/
public static final Requirement HAS_PERMISSION = Eco.getHandler().getRequirementFactory().create("has-permission");
public static final Requirement HAS_PERMISSION = new com.willfp.eco.core.requirement.impl.RequirementHasPermission();
/**
* Placeholder equals value.
*/
public static final Requirement PLACEHOLDER_EQUALS = Eco.getHandler().getRequirementFactory().create("placeholder-equals");
public static final Requirement PLACEHOLDER_EQUALS = new com.willfp.eco.core.requirement.impl.RequirementPlaceholderEquals();
/**
* Numeric placeholder greater than value.
*/
public static final Requirement PLACEHOLDER_GREATER_THAN = Eco.getHandler().getRequirementFactory().create("placeholder-greater-than");
public static final Requirement PLACEHOLDER_GREATER_THAN = new com.willfp.eco.core.requirement.impl.RequirementPlaceholderGreaterThan();
/**
* Numeric placeholder less than value.
*/
public static final Requirement PLACEHOLDER_LESS_THAN = Eco.getHandler().getRequirementFactory().create("placeholder-less-than");
public static final Requirement PLACEHOLDER_LESS_THAN = new com.willfp.eco.core.requirement.impl.RequirementPlaceholderLessThan();
/**
* Get Requirements matching ID.
@@ -38,10 +43,27 @@ public final class Requirements {
* @return The matching Requirements.
*/
public static Requirement getByID(@NotNull final String name) {
return Eco.getHandler().getRequirementFactory().create(name);
return switch (name.toLowerCase()) {
case "has-permission" -> HAS_PERMISSION;
case "placeholder-equals" -> PLACEHOLDER_EQUALS;
case "placeholder-greater-than" -> PLACEHOLDER_GREATER_THAN;
case "placeholder-less-than" -> PLACEHOLDER_LESS_THAN;
default -> new Requirement() {
@Override
public boolean doesPlayerMeet(@NotNull final Player player,
@NotNull final List<String> args) {
return true;
}
};
};
}
private Requirements() {
throw new UnsupportedOperationException("This is a utility class and cannot be instantiated");
}
static {
Eco.getHandler().getEcoPlugin().getLogger().severe("Loading for-removal Requirements system! This will throw an error once 6.27.0 is released."
+ "Make sure you're running the latest version of all your plugins!");
}
}

View File

@@ -0,0 +1,34 @@
package com.willfp.eco.core.requirement.impl;
import com.willfp.eco.core.Eco;
import org.bukkit.entity.Player;
import org.jetbrains.annotations.ApiStatus;
import org.jetbrains.annotations.NotNull;
import java.util.List;
/**
* Moved to API in 6.26.0 after being marked for removal. This class should never be referenced, it
* was moved back to the API in order to remove backend components related to Requirements.
*
* @deprecated No typing, weak definitions, and not an API component. Shouldn't be in eco.
*/
@SuppressWarnings("removal")
@ApiStatus.ScheduledForRemoval(inVersion = "6.27.0")
@Deprecated(since = "6.26.0", forRemoval = true)
public class RequirementHasPermission extends com.willfp.eco.core.requirement.Requirement {
@Override
public boolean doesPlayerMeet(@NotNull final Player player,
@NotNull final List<String> args) {
if (args.isEmpty()) {
return false;
}
return player.hasPermission(args.get(0));
}
static {
Eco.getHandler().getEcoPlugin().getLogger().severe("Loading for-removal Requirements system! This will throw an error once 6.27.0 is released."
+ "Make sure you're running the latest version of all your plugins!");
}
}

View File

@@ -0,0 +1,35 @@
package com.willfp.eco.core.requirement.impl;
import com.willfp.eco.core.Eco;
import com.willfp.eco.core.integrations.placeholder.PlaceholderManager;
import org.bukkit.entity.Player;
import org.jetbrains.annotations.ApiStatus;
import org.jetbrains.annotations.NotNull;
import java.util.List;
/**
* Moved to API in 6.26.0 after being marked for removal. This class should never be referenced, it
* was moved back to the API in order to remove backend components related to Requirements.
*
* @deprecated No typing, weak definitions, and not an API component. Shouldn't be in eco.
*/
@SuppressWarnings("removal")
@ApiStatus.ScheduledForRemoval(inVersion = "6.27.0")
@Deprecated(since = "6.26.0", forRemoval = true)
public class RequirementPlaceholderEquals extends com.willfp.eco.core.requirement.Requirement {
@Override
public boolean doesPlayerMeet(@NotNull final Player player,
@NotNull final List<String> args) {
if (args.size() < 2) {
return false;
}
return PlaceholderManager.translatePlaceholders(args.get(0), player).equalsIgnoreCase(args.get(1));
}
static {
Eco.getHandler().getEcoPlugin().getLogger().severe("Loading for-removal Requirements system! This will throw an error once 6.27.0 is released."
+ "Make sure you're running the latest version of all your plugins!");
}
}

View File

@@ -0,0 +1,49 @@
package com.willfp.eco.core.requirement.impl;
import com.willfp.eco.core.Eco;
import com.willfp.eco.core.integrations.placeholder.PlaceholderManager;
import org.bukkit.entity.Player;
import org.jetbrains.annotations.ApiStatus;
import org.jetbrains.annotations.NotNull;
import java.util.List;
/**
* Moved to API in 6.26.0 after being marked for removal. This class should never be referenced, it
* was moved back to the API in order to remove backend components related to Requirements.
*
* @deprecated No typing, weak definitions, and not an API component. Shouldn't be in eco.
*/
@SuppressWarnings("removal")
@ApiStatus.ScheduledForRemoval(inVersion = "6.27.0")
@Deprecated(since = "6.26.0", forRemoval = true)
public class RequirementPlaceholderGreaterThan extends com.willfp.eco.core.requirement.Requirement {
@Override
public boolean doesPlayerMeet(@NotNull final Player player,
@NotNull final List<String> args) {
if (args.size() < 2) {
return false;
}
double actual;
try {
actual = Double.parseDouble(PlaceholderManager.translatePlaceholders(args.get(0), player));
} catch (NumberFormatException e) {
return false;
}
double expected;
try {
expected = Double.parseDouble(args.get(1));
} catch (NumberFormatException e) {
return false;
}
return actual >= expected;
}
static {
Eco.getHandler().getEcoPlugin().getLogger().severe("Loading for-removal Requirements system! This will throw an error once 6.27.0 is released."
+ "Make sure you're running the latest version of all your plugins!");
}
}

View File

@@ -0,0 +1,49 @@
package com.willfp.eco.core.requirement.impl;
import com.willfp.eco.core.Eco;
import com.willfp.eco.core.integrations.placeholder.PlaceholderManager;
import org.bukkit.entity.Player;
import org.jetbrains.annotations.ApiStatus;
import org.jetbrains.annotations.NotNull;
import java.util.List;
/**
* Moved to API in 6.26.0 after being marked for removal. This class should never be referenced, it
* was moved back to the API in order to remove backend components related to Requirements.
*
* @deprecated No typing, weak definitions, and not an API component. Shouldn't be in eco.
*/
@SuppressWarnings("removal")
@ApiStatus.ScheduledForRemoval(inVersion = "6.27.0")
@Deprecated(since = "6.26.0", forRemoval = true)
public class RequirementPlaceholderLessThan extends com.willfp.eco.core.requirement.Requirement {
@Override
public boolean doesPlayerMeet(@NotNull final Player player,
@NotNull final List<String> args) {
if (args.size() < 2) {
return false;
}
double actual;
try {
actual = Double.parseDouble(PlaceholderManager.translatePlaceholders(args.get(0), player));
} catch (NumberFormatException e) {
return false;
}
double expected;
try {
expected = Double.parseDouble(args.get(1));
} catch (NumberFormatException e) {
return false;
}
return actual < expected;
}
static {
Eco.getHandler().getEcoPlugin().getLogger().severe("Loading for-removal Requirements system! This will throw an error once 6.27.0 is released."
+ "Make sure you're running the latest version of all your plugins!");
}
}

View File

@@ -121,6 +121,14 @@ public final class StringUtils {
.put("§k", ChatColor.MAGIC)
.build();
/**
* Regex map for splitting values.
*/
private static final LoadingCache<String, Pattern> SPACE_AROUND_CHARACTER = Caffeine.newBuilder()
.build(
character -> Pattern.compile("( " + Pattern.quote(character) + " )")
);
/**
* Format a list of strings.
* <p>
@@ -419,9 +427,23 @@ public final class StringUtils {
*
* @param object The object to convert to string.
* @return The object stringified.
* @deprecated Poorly named method. Use {@link StringUtils#toNiceString(Object)} instead.
*/
@NotNull
@Deprecated(since = "6.26.0", forRemoval = true)
public static String internalToString(@Nullable final Object object) {
return toNiceString(object);
}
/**
* Internal implementation of {@link String#valueOf}.
* Formats collections and doubles better.
*
* @param object The object to convert to string.
* @return The object stringified.
*/
@NotNull
public static String toNiceString(@Nullable final Object object) {
if (object == null) {
return "null";
}
@@ -433,7 +455,7 @@ public final class StringUtils {
} else if (object instanceof Double) {
return NumberUtils.format((Double) object);
} else if (object instanceof Collection<?> c) {
return c.stream().map(StringUtils::internalToString).collect(Collectors.joining(", "));
return c.stream().map(StringUtils::toNiceString).collect(Collectors.joining(", "));
} else {
return String.valueOf(object);
}
@@ -560,6 +582,22 @@ public final class StringUtils {
return tokens.toArray(new String[0]);
}
/**
* Split input string around separator surrounded by spaces.
* <p>
* e.g. {@code splitAround("hello ? how are you", "?")} will split, but
* {@code splitAround("hello? how are you", "?")} will not.
*
* @param input Input string.
* @param separator Separator.
* @return The split string.
*/
@NotNull
public static String[] splitAround(@NotNull final String input,
@NotNull final String separator) {
return SPACE_AROUND_CHARACTER.get(separator).split(input);
}
/**
* Options for formatting.
*/

View File

@@ -40,3 +40,15 @@ fun List<String>.formatEco(
player,
if (formatPlaceholders) StringUtils.FormatOption.WITH_PLACEHOLDERS else StringUtils.FormatOption.WITHOUT_PLACEHOLDERS
)
/**
* @see StringUtils.splitAround
*/
fun String.splitAround(separator: String): Array<String> =
StringUtils.splitAround(this, separator)
/**
* @see StringUtils.toNiceString
*/
fun Any?.toNiceString(): String =
StringUtils.toNiceString(this)

View File

@@ -0,0 +1,29 @@
import com.willfp.eco.util.StringUtils;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
public class StringUtilsTest {
@Test
public void testSplitAround() {
Assertions.assertArrayEquals(
new String[]{"one", "two"},
StringUtils.splitAround("one ? two", "?")
);
Assertions.assertArrayEquals(
new String[]{"one? two"},
StringUtils.splitAround("one? two", "?")
);
Assertions.assertArrayEquals(
new String[]{"one", "two", "three"},
StringUtils.splitAround("one ? two ? three", "?")
);
Assertions.assertArrayEquals(
new String[]{"one", "two"},
StringUtils.splitAround("one || two", "||")
);
Assertions.assertArrayEquals(
new String[]{"one|| two"},
StringUtils.splitAround("one|| two", "||")
);
}
}

View File

@@ -0,0 +1,10 @@
package com.willfp.eco.internal.entities
import com.willfp.eco.core.entities.DummyEntity
import org.bukkit.entity.Entity
class EcoDummyEntity(private val handle: Entity) : DummyEntity, Entity by handle {
override fun toString(): String {
return "DummyEntity{id=${this.entityId}}"
}
}

View File

@@ -12,17 +12,11 @@ class EntityArgParserEquipment : EntityArgParser {
val equipment = mutableMapOf<EquipmentSlot, TestableItem>()
for (arg in args) {
val argSplit = arg.split(":")
for (slot in EquipmentSlot.values()) {
if (!argSplit[0].equals(slot.name, ignoreCase = true)) {
if (!arg.lowercase().startsWith("${slot.name.lowercase()}:")) {
continue
}
if (argSplit.size < 2) {
continue
}
equipment[slot] = Items.lookup(argSplit[1])
equipment[slot] = Items.lookup(arg.substring(slot.name.length + 1, arg.length))
}
}

View File

@@ -9,14 +9,10 @@ class EntityArgParserName : EntityArgParser {
var name: String? = null
for (arg in args) {
val argSplit = arg.split(":")
if (!argSplit[0].equals("name", ignoreCase = true)) {
if (!arg.lowercase().startsWith("name:")) {
continue
}
if (argSplit.size < 2) {
continue
}
name = argSplit[1]
name = arg.substring(5, arg.length)
}
name ?: return null

View File

@@ -11,20 +11,17 @@ class ArgParserName : LookupArgParser {
var name: String? = null
for (arg in args) {
val argSplit = arg.split(":")
if (!argSplit[0].equals("name", ignoreCase = true)) {
if (!arg.lowercase().startsWith("name:")) {
continue
}
if (argSplit.size < 2) {
continue
}
name = argSplit[1]
name = arg.substring(5, arg.length)
}
name ?: return null
val formatted = StringUtils.format(name)
@Suppress("UsePropertyAccessSyntax")
meta.setDisplayName(formatted)
return Predicate {

View File

@@ -0,0 +1,24 @@
package com.willfp.eco.internal.lookup
import com.willfp.eco.core.lookup.LookupHandler
import com.willfp.eco.core.lookup.SegmentParser
import com.willfp.eco.core.lookup.Testable
class SegmentParserGroup : SegmentParser("||") {
override fun <T : Testable<*>> handleSegments(segments: Array<out String>, handler: LookupHandler<T>): T {
val possibleOptions = mutableListOf<T>()
for (option in segments) {
val lookup = handler.parseKey(option)
if (handler.validate(lookup)) {
possibleOptions.add(lookup)
}
}
if (possibleOptions.isEmpty()) {
return handler.failsafe
}
return handler.join(possibleOptions)
}
}

View File

@@ -0,0 +1,18 @@
package com.willfp.eco.internal.lookup
import com.willfp.eco.core.lookup.LookupHandler
import com.willfp.eco.core.lookup.SegmentParser
import com.willfp.eco.core.lookup.Testable
class SegmentParserUseIfPresent : SegmentParser("?") {
override fun <T : Testable<*>> handleSegments(segments: Array<out String>, handler: LookupHandler<T>): T {
for (option in segments) {
val lookup = handler.parseKey(option)
if (handler.validate(lookup)) {
return lookup
}
}
return handler.failsafe
}
}

View File

@@ -43,7 +43,7 @@ class EcoProxyFactory(
private fun proxyErrorFrom(e: Exception): Throwable {
plugin.logger.severe("Fatal error with proxies! This plugin can't load.")
return if (!SUPPORTED_VERSIONS.contains(ProxyConstants.NMS_VERSION)) {
return if (!ProxyConstants.SUPPORTED_VERSIONS.contains(ProxyConstants.NMS_VERSION)) {
ProxyError(
"Could not initialize proxy.",
UnsupportedVersionError()
@@ -74,11 +74,4 @@ class EcoProxyFactory(
cache.clear()
}
companion object {
val SUPPORTED_VERSIONS = listOf(
"v1_17_R1",
"v1_18_R1"
)
}
}

View File

@@ -1,113 +0,0 @@
@file:Suppress("DEPRECATION")
package com.willfp.eco.internal.requirement
import com.willfp.eco.core.integrations.placeholder.PlaceholderManager
import com.willfp.eco.core.requirement.Requirement
import com.willfp.eco.core.requirement.RequirementFactory
import org.bukkit.entity.Player
@Deprecated(
"Requirement system is marked as for-removal from eco",
level = DeprecationLevel.WARNING
)
class EcoRequirementFactory : RequirementFactory {
override fun create(name: String): Requirement {
return when (name.lowercase()) {
"has-permission" -> RequirementHasPermission()
"placeholder-equals" -> RequirementPlaceholderEquals()
"placeholder-greater-than" -> RequirementPlaceholderGreaterThan()
"placeholder-less-than" -> RequirementPlaceholderLessThan()
else -> RequirementTrue()
}
}
}
@Deprecated(
"Requirement system is marked as for-removal from eco",
level = DeprecationLevel.WARNING
)
class RequirementHasPermission : Requirement() {
override fun doesPlayerMeet(
player: Player,
args: List<String>
): Boolean {
if (args.isEmpty()) {
return false
}
val permission = args[0]
return player.hasPermission(permission)
}
}
@Deprecated(
"Requirement system is marked as for-removal from eco",
level = DeprecationLevel.WARNING
)
class RequirementPlaceholderEquals : Requirement() {
override fun doesPlayerMeet(
player: Player,
args: List<String>
): Boolean {
if (args.size < 2) {
return false
}
val placeholder = args[0]
val equals = args[1]
return PlaceholderManager.translatePlaceholders(placeholder, player).equals(equals, ignoreCase = true)
}
}
@Deprecated(
"Requirement system is marked as for-removal from eco",
level = DeprecationLevel.WARNING
)
@SuppressWarnings("DEPRECATION")
class RequirementPlaceholderGreaterThan : Requirement() {
override fun doesPlayerMeet(
player: Player,
args: List<String>
): Boolean {
if (args.size < 2) {
return false
}
val placeholder = args[0]
val equals = args[1].toDoubleOrNull() ?: return false
return (PlaceholderManager.translatePlaceholders(placeholder, player).toDoubleOrNull() ?: 0.0) >= equals
}
}
@Deprecated(
"Requirement system is marked as for-removal from eco",
level = DeprecationLevel.WARNING
)
class RequirementPlaceholderLessThan : Requirement() {
override fun doesPlayerMeet(
player: Player,
args: List<String>
): Boolean {
if (args.size < 2) {
return false
}
val placeholder = args[0]
val equals = args[1].toDoubleOrNull() ?: return false
return (PlaceholderManager.translatePlaceholders(placeholder, player).toDoubleOrNull() ?: 0.0) < equals
}
}
@Deprecated(
"Requirement system is marked as for-removal from eco",
level = DeprecationLevel.WARNING
)
class RequirementTrue : Requirement() {
override fun doesPlayerMeet(
player: Player,
args: List<String>
): Boolean {
return true
}
}

View File

@@ -1,15 +1,16 @@
package com.willfp.eco.internal.spigot.proxy.v1_17_R1
import com.willfp.eco.internal.spigot.proxy.DummyEntityProxy
import com.willfp.eco.internal.entities.EcoDummyEntity
import com.willfp.eco.internal.spigot.proxy.DummyEntityFactoryProxy
import org.bukkit.Location
import org.bukkit.craftbukkit.v1_17_R1.CraftWorld
import org.bukkit.entity.Entity
import org.bukkit.entity.EntityType
class DummyEntity : DummyEntityProxy {
class DummyEntityFactory : DummyEntityFactoryProxy {
override fun createDummyEntity(location: Location): Entity {
val world = location.world as CraftWorld
@Suppress("UsePropertyAccessSyntax")
return world.createEntity(location, EntityType.ZOMBIE.entityClass).getBukkitEntity()
return EcoDummyEntity(world.createEntity(location, EntityType.ZOMBIE.entityClass).getBukkitEntity())
}
}
}

View File

@@ -1,15 +1,16 @@
package com.willfp.eco.internal.spigot.proxy.v1_18_R1
import com.willfp.eco.internal.spigot.proxy.DummyEntityProxy
import com.willfp.eco.internal.entities.EcoDummyEntity
import com.willfp.eco.internal.spigot.proxy.DummyEntityFactoryProxy
import org.bukkit.Location
import org.bukkit.craftbukkit.v1_18_R1.CraftWorld
import org.bukkit.entity.Entity
import org.bukkit.entity.EntityType
class DummyEntity : DummyEntityProxy {
class DummyEntityFactory : DummyEntityFactoryProxy {
override fun createDummyEntity(location: Location): Entity {
val world = location.world as CraftWorld
@Suppress("UsePropertyAccessSyntax")
return world.createEntity(location, EntityType.ZOMBIE.entityClass).getBukkitEntity()
return EcoDummyEntity(world.createEntity(location, EntityType.ZOMBIE.entityClass).getBukkitEntity())
}
}
}

View File

@@ -26,7 +26,6 @@ dependencies {
compileOnly 'com.gmail.nossr50.mcMMO:mcMMO:2.1.202'
compileOnly 'me.clip:placeholderapi:2.10.10'
compileOnly 'com.github.oraxen:oraxen:bd81ace154'
compileOnly 'com.github.Ssomar-Developement:ExecutableItems:master-SNAPSHOT'
compileOnly 'com.github.brcdev-minecraft:shopgui-api:2.2.0'
compileOnly 'com.github.LoneDev6:API-ItemsAdder:2.4.7'
compileOnly 'com.arcaniax:HeadDatabase-API:1.3.0'
@@ -36,7 +35,7 @@ dependencies {
compileOnly 'mysql:mysql-connector-java:8.0.25'
compileOnly 'com.zaxxer:HikariCP:5.0.0'
compileOnly 'com.gmail.filoghost.holographicdisplays:holographicdisplays-api:2.4.0'
compileOnly 'com.github.EssentialsX:Essentials:2.19.0'
compileOnly 'com.github.EssentialsX:Essentials:2.18.2'
compileOnly 'com.bgsoftware:SuperiorSkyblockAPI:1.8.3'
compileOnly 'com.github.MilkBowl:VaultAPI:1.7'
compileOnly 'world.bentobox:bentobox:1.17.3-SNAPSHOT'

View File

@@ -28,7 +28,7 @@ import com.willfp.eco.internal.spigot.data.DataYml
import com.willfp.eco.internal.spigot.data.EcoKeyRegistry
import com.willfp.eco.internal.spigot.data.EcoProfileHandler
import com.willfp.eco.internal.spigot.integrations.bstats.MetricHandler
import com.willfp.eco.internal.spigot.proxy.DummyEntityProxy
import com.willfp.eco.internal.spigot.proxy.DummyEntityFactoryProxy
import com.willfp.eco.internal.spigot.proxy.FastItemStackFactoryProxy
import net.kyori.adventure.platform.bukkit.BukkitAudiences
import org.bukkit.Location
@@ -43,8 +43,6 @@ class EcoHandler : EcoSpigotPlugin(), Handler {
private val cleaner = EcoCleaner()
@Suppress("DEPRECATION")
private val requirementFactory = com.willfp.eco.internal.requirement.EcoRequirementFactory()
private var adventure: BukkitAudiences? = null
private val keyRegistry = EcoKeyRegistry()
private val playerProfileHandler = EcoProfileHandler(this.configYml.getBool("mysql.enabled"), this)
@@ -134,11 +132,6 @@ class EcoHandler : EcoSpigotPlugin(), Handler {
MetricHandler.createMetrics(plugin)
}
@Suppress("DEPRECATION")
override fun getRequirementFactory(): com.willfp.eco.internal.requirement.EcoRequirementFactory {
return requirementFactory
}
override fun getAdventure(): BukkitAudiences? {
return adventure
}
@@ -156,7 +149,7 @@ class EcoHandler : EcoSpigotPlugin(), Handler {
}
override fun createDummyEntity(location: Location): Entity {
return getProxy(DummyEntityProxy::class.java).createDummyEntity(location)
return getProxy(DummyEntityFactoryProxy::class.java).createDummyEntity(location)
}
override fun createNamespacedKey(namespace: String, key: String): NamespacedKey {

View File

@@ -45,6 +45,8 @@ import com.willfp.eco.internal.items.ArgParserFlag
import com.willfp.eco.internal.items.ArgParserName
import com.willfp.eco.internal.items.ArgParserTexture
import com.willfp.eco.internal.items.ArgParserUnbreakable
import com.willfp.eco.internal.lookup.SegmentParserGroup
import com.willfp.eco.internal.lookup.SegmentParserUseIfPresent
import com.willfp.eco.internal.spigot.arrows.ArrowDataListener
import com.willfp.eco.internal.spigot.data.DataListener
import com.willfp.eco.internal.spigot.data.DataYml
@@ -159,6 +161,9 @@ abstract class EcoSpigotPlugin : EcoPlugin() {
ShapedRecipeListener.registerListener(ComplexInEco())
ShapedRecipeListener.registerListener(ComplexInVanilla())
SegmentParserGroup().register()
SegmentParserUseIfPresent().register()
val skullProxy = getProxy(SkullProxy::class.java)
SkullUtils.initialize(
{ meta, base64 -> skullProxy.setSkullTexture(meta, base64) },
@@ -332,4 +337,4 @@ abstract class EcoSpigotPlugin : EcoPlugin() {
return listeners
}
}
}

View File

@@ -13,6 +13,7 @@ import org.bukkit.entity.Player
class AntigriefCombatLogXV10 : AntigriefWrapper {
private val instance: ICombatLogX = Bukkit.getPluginManager().getPlugin("CombatLogX") as ICombatLogX
private var disabled = false
override fun canBreakBlock(
player: Player,
@@ -43,16 +44,23 @@ class AntigriefCombatLogXV10 : AntigriefWrapper {
return true
}
if (disabled) {
return true
}
// Only run checks if the NewbieHelper expansion is installed on the server.
val expansionManager = instance.expansionManager
val optionalExpansion = expansionManager.getExpansionByName<Expansion>("NewbieHelper")
if (optionalExpansion.isPresent) {
val expansion = optionalExpansion.get()
val expansion = runCatching { optionalExpansion.get() }
.onFailure { disabled = true }
.getOrNull() ?: return true
val newbieHelper: NewbieHelper = expansion as NewbieHelper
val pvpListener: ListenerPVP = newbieHelper.pvpListener
return pvpListener.isPVPEnabled(player) && pvpListener.isPVPEnabled(victim)
} else {
return true
}
return true
}
override fun canPickupItem(player: Player, location: Location): Boolean {

View File

@@ -13,6 +13,8 @@ import org.bukkit.entity.Player
class AntigriefCombatLogXV11 : AntigriefWrapper {
private val instance: ICombatLogX = Bukkit.getPluginManager().getPlugin("CombatLogX") as ICombatLogX
private var disabled = false
override fun canBreakBlock(
player: Player,
block: Block
@@ -42,12 +44,17 @@ class AntigriefCombatLogXV11 : AntigriefWrapper {
return true
}
if (disabled) {
return true
}
// Only run checks if the NewbieHelper expansion is installed on the server.
val expansionManager = instance.expansionManager
val optionalExpansion = expansionManager.getExpansion("NewbieHelper")
if (optionalExpansion.isPresent) {
val expansion = optionalExpansion.get()
val newbieHelperExpansion: NewbieHelperExpansion = expansion as NewbieHelperExpansion
val newbieHelperExpansion = runCatching {
optionalExpansion.get() as NewbieHelperExpansion
}.onFailure { disabled = true }.getOrNull() ?: return true
val protectionManager: ProtectionManager = newbieHelperExpansion.protectionManager
val pvpManager: PVPManager = newbieHelperExpansion.pvpManager
val victimProtected: Boolean = protectionManager.isProtected(victim)

View File

@@ -1,6 +1,6 @@
package com.willfp.eco.internal.spigot.integrations.customitems
import com.ssomar.score.api.ExecutableItemsAPI
import com.ssomar.executableitems.api.ExecutableItemsAPI
import com.willfp.eco.core.integrations.customitems.CustomItemsWrapper
import com.willfp.eco.core.items.CustomItem
import com.willfp.eco.core.items.Items
@@ -9,13 +9,16 @@ import com.willfp.eco.core.items.provider.ItemProvider
import com.willfp.eco.util.NamespacedKeyUtils
import org.bukkit.inventory.ItemStack
import java.util.function.Predicate
class CustomItemsExecutableItems: CustomItemsWrapper {
class CustomItemsExecutableItems : CustomItemsWrapper {
override fun registerAllItems() {
Items.registerItemProvider(ExecutableItemsProvider())
}
override fun getPluginName(): String {
return "ExecutableItems"
}
private class ExecutableItemsProvider : ItemProvider("executableitems") {
override fun provideForKey(key: String): TestableItem? {
val item = ExecutableItemsAPI.getExecutableItem(key) ?: return null
@@ -30,4 +33,4 @@ class CustomItemsExecutableItems: CustomItemsWrapper {
)
}
}
}
}

View File

@@ -1,7 +1,9 @@
package com.willfp.eco.internal.spigot.recipes.listeners
import com.willfp.eco.core.items.Items
import com.willfp.eco.core.items.TestableItem
import com.willfp.eco.core.recipe.Recipes
import com.willfp.eco.core.recipe.parts.GroupedTestableItems
import com.willfp.eco.core.recipe.parts.MaterialTestableItem
import com.willfp.eco.core.recipe.parts.ModifiedTestableItem
import com.willfp.eco.core.recipe.parts.TestableStack
@@ -9,6 +11,7 @@ import com.willfp.eco.core.recipe.recipes.ShapedCraftingRecipe
import com.willfp.eco.internal.spigot.recipes.GenericCraftEvent
import com.willfp.eco.internal.spigot.recipes.RecipeListener
import com.willfp.eco.internal.spigot.recipes.ShapedRecipeListener
import org.bukkit.inventory.ItemStack
class ComplexInEco : RecipeListener {
override fun handle(event: GenericCraftEvent) {
@@ -25,27 +28,41 @@ class ComplexInEco : RecipeListener {
for (i in 0..8) {
val itemStack = event.inventory.matrix[i]
val part = craftingRecipe.parts[i]
when (part) {
is MaterialTestableItem -> {
if (Items.isCustomItem(itemStack)) {
event.deny()
}
}
is ModifiedTestableItem -> {
if (part.handle is MaterialTestableItem) {
if (Items.isCustomItem(itemStack)) {
event.deny()
}
}
}
is TestableStack -> {
if (part.handle is MaterialTestableItem) {
if (Items.isCustomItem(itemStack)) {
event.deny()
}
}
}
if (part.isCustomWhenShouldNotBe(itemStack)) {
event.deny()
}
}
}
}
private fun TestableItem.isCustomWhenShouldNotBe(itemStack: ItemStack): Boolean {
when (this) {
is MaterialTestableItem -> {
if (Items.isCustomItem(itemStack)) {
return true
}
}
is ModifiedTestableItem -> {
if (this.handle is MaterialTestableItem) {
if (Items.isCustomItem(itemStack)) {
return true
}
}
}
is TestableStack -> {
if (this.handle is MaterialTestableItem) {
if (Items.isCustomItem(itemStack)) {
return true
}
}
}
is GroupedTestableItems -> {
// This will fail if and only if there is a complex item grouped with a simple item of the same type
if (this.children.any { it.isCustomWhenShouldNotBe(itemStack) && it.matches(itemStack) }) {
return true
}
}
}
return false
}

View File

@@ -58,4 +58,4 @@ libraries:
- 'com.google.guava:guava:31.0.1-jre'
- 'com.zaxxer:HikariCP:5.0.0'
- 'org.objenesis:objenesis:3.2'
- 'com.github.ben-manes.caffeine:caffeine:3.0.5'
- 'com.github.ben-manes.caffeine:caffeine:3.0.5'

View File

@@ -3,7 +3,7 @@ package com.willfp.eco.internal.spigot.proxy
import org.bukkit.Location
import org.bukkit.entity.Entity
interface DummyEntityProxy {
interface DummyEntityFactoryProxy {
fun createDummyEntity(
location: Location
): Entity

View File

@@ -1,3 +1,3 @@
version = 6.25.2
version = 6.26.0
plugin-name = eco
kotlin.code.style = official

Binary file not shown.

Binary file not shown.

BIN
lib/SCore-1.6.4.3.jar Normal file

Binary file not shown.