Removed requirements from the backend, added warnings in static intializers.

This commit is contained in:
Auxilor
2022-02-28 18:51:07 +00:00
parent 13772002e8
commit cb480bd88d
10 changed files with 184 additions and 160 deletions

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

@@ -1,5 +1,6 @@
package com.willfp.eco.core.requirement;
import com.willfp.eco.core.Eco;
import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;
@@ -11,7 +12,6 @@ import java.util.List;
* @deprecated No typing, weak definitions, and not an API component. Shouldn't be in eco.
*/
@Deprecated(since = "6.24.0", forRemoval = true)
@SuppressWarnings("DeprecatedIsStillUsed")
public abstract class Requirement {
/**
* Create a new requirement.
@@ -29,4 +29,8 @@ 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,8 +1,11 @@
package com.willfp.eco.core.requirement;
import com.willfp.eco.core.Eco;
import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;
import java.util.List;
/**
* Contains methods and fields pertaining to requirements.
*
@@ -14,22 +17,22 @@ 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 +41,26 @@ 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,31 @@
package com.willfp.eco.core.requirement.impl;
import com.willfp.eco.core.Eco;
import org.bukkit.entity.Player;
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")
@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,32 @@
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.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")
@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,46 @@
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.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")
@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,46 @@
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.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")
@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!");
}
}