mirror of
https://github.com/Auxilor/EcoEnchants.git
synced 2024-11-28 16:05:14 +01:00
Updated to eco 6.8.0
This commit is contained in:
parent
c8e5913f5d
commit
0312915d33
@ -48,7 +48,7 @@ allprojects {
|
||||
}
|
||||
|
||||
dependencies {
|
||||
compileOnly 'com.willfp:eco:6.7.5'
|
||||
compileOnly 'com.willfp:eco:6.8.0'
|
||||
|
||||
compileOnly 'org.jetbrains:annotations:19.0.0'
|
||||
|
||||
|
@ -19,7 +19,6 @@
|
||||
|
||||
<!-- Fields don't need javadoc -->
|
||||
<suppress files="EcoEnchants.java" checks="JavadocVariable"/>
|
||||
<suppress files="EnchantmentRequirements.java" checks="JavadocVariable"/>
|
||||
|
||||
<!-- Modified version of library -->
|
||||
<suppress files="ArmorEquipEvent.java" checks="JavadocVariable"/>
|
||||
|
@ -1,13 +1,13 @@
|
||||
package com.willfp.ecoenchants.enchantments;
|
||||
|
||||
import com.willfp.eco.core.Prerequisite;
|
||||
import com.willfp.eco.core.requirement.Requirement;
|
||||
import com.willfp.eco.core.requirement.Requirements;
|
||||
import com.willfp.ecoenchants.EcoEnchantsPlugin;
|
||||
import com.willfp.ecoenchants.config.configs.EnchantmentConfig;
|
||||
import com.willfp.ecoenchants.enchantments.meta.EnchantmentRarity;
|
||||
import com.willfp.ecoenchants.enchantments.meta.EnchantmentTarget;
|
||||
import com.willfp.ecoenchants.enchantments.meta.EnchantmentType;
|
||||
import com.willfp.ecoenchants.enchantments.meta.requirements.EnchantmentRequirement;
|
||||
import com.willfp.ecoenchants.enchantments.meta.requirements.EnchantmentRequirements;
|
||||
import com.willfp.ecoenchants.enchantments.util.EnchantmentUtils;
|
||||
import com.willfp.ecoenchants.enchantments.util.Watcher;
|
||||
import lombok.AccessLevel;
|
||||
@ -156,7 +156,7 @@ public abstract class EcoEnchant extends Enchantment implements Listener, Watche
|
||||
/**
|
||||
* All the requirements needed in order to use the enchantment.
|
||||
*/
|
||||
private final Map<EnchantmentRequirement, List<String>> requirements = new HashMap<>();
|
||||
private final Map<Requirement, List<String>> requirements = new HashMap<>();
|
||||
|
||||
/**
|
||||
* Cached players to see if they meet requirements.
|
||||
@ -250,11 +250,7 @@ public abstract class EcoEnchant extends Enchantment implements Listener, Watche
|
||||
continue;
|
||||
}
|
||||
|
||||
EnchantmentRequirement requirement = EnchantmentRequirements.getByID(split.get(0).toLowerCase());
|
||||
|
||||
if (requirement == null) {
|
||||
continue;
|
||||
}
|
||||
Requirement requirement = Requirements.getByID(split.get(0).toLowerCase());
|
||||
|
||||
this.requirements.put(requirement, split.subList(1, split.size()));
|
||||
}
|
||||
@ -310,7 +306,7 @@ public abstract class EcoEnchant extends Enchantment implements Listener, Watche
|
||||
return cachedRequirements.get(player.getUniqueId());
|
||||
}
|
||||
|
||||
for (Map.Entry<EnchantmentRequirement, List<String>> entry : requirements.entrySet()) {
|
||||
for (Map.Entry<Requirement, List<String>> entry : requirements.entrySet()) {
|
||||
if (!entry.getKey().doesPlayerMeet(player, entry.getValue())) {
|
||||
cachedRequirements.put(player.getUniqueId(), false);
|
||||
return false;
|
||||
|
@ -1,31 +0,0 @@
|
||||
package com.willfp.ecoenchants.enchantments.meta.requirements;
|
||||
|
||||
import lombok.Getter;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public abstract class EnchantmentRequirement {
|
||||
/**
|
||||
* The ID of the requirement.
|
||||
*/
|
||||
@Getter
|
||||
private final String id;
|
||||
|
||||
protected EnchantmentRequirement(@NotNull final String id) {
|
||||
this.id = id;
|
||||
|
||||
EnchantmentRequirements.addNewRequirement(this);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test if the player meets the requirement.
|
||||
*
|
||||
* @param player The player.
|
||||
* @param args The arguments.
|
||||
* @return The requirement.
|
||||
*/
|
||||
public abstract boolean doesPlayerMeet(@NotNull Player player,
|
||||
@NotNull List<String> args);
|
||||
}
|
@ -1,68 +0,0 @@
|
||||
package com.willfp.ecoenchants.enchantments.meta.requirements;
|
||||
|
||||
import com.google.common.collect.BiMap;
|
||||
import com.google.common.collect.HashBiMap;
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import com.willfp.ecoenchants.enchantments.EcoEnchant;
|
||||
import com.willfp.ecoenchants.enchantments.meta.requirements.requirements.RequirementHasPermission;
|
||||
import com.willfp.ecoenchants.enchantments.meta.requirements.requirements.RequirementPlaceholderEquals;
|
||||
import com.willfp.ecoenchants.enchantments.meta.requirements.requirements.RequirementPlaceholderGreaterThan;
|
||||
import com.willfp.ecoenchants.enchantments.meta.requirements.requirements.RequirementPlaceholderLessThan;
|
||||
import lombok.experimental.UtilityClass;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@UtilityClass
|
||||
@SuppressWarnings({"unused", "checkstyle:JavadocVariable"})
|
||||
public class EnchantmentRequirements {
|
||||
/**
|
||||
* All registered requirements.
|
||||
*/
|
||||
private static final BiMap<String, EnchantmentRequirement> BY_ID = HashBiMap.create();
|
||||
|
||||
public static final EnchantmentRequirement HAS_PERMISSION = new RequirementHasPermission();
|
||||
public static final EnchantmentRequirement PLACEHOLDER_EQUALS = new RequirementPlaceholderEquals();
|
||||
public static final EnchantmentRequirement PLACEHOLDER_GREATER_THAN = new RequirementPlaceholderGreaterThan();
|
||||
public static final EnchantmentRequirement PLACEHOLDER_LESS_THAN = new RequirementPlaceholderLessThan();
|
||||
|
||||
/**
|
||||
* Get all registered {@link EcoEnchant}s.
|
||||
*
|
||||
* @return A list of all {@link EcoEnchant}s.
|
||||
*/
|
||||
public static List<EnchantmentRequirement> values() {
|
||||
return ImmutableList.copyOf(BY_ID.values());
|
||||
}
|
||||
|
||||
/**
|
||||
* Get {@link EnchantmentRequirement} matching ID.
|
||||
*
|
||||
* @param name The ID to search for.
|
||||
* @return The matching {@link EnchantmentRequirement}, or null if not found.
|
||||
*/
|
||||
public static EnchantmentRequirement getByID(@NotNull final String name) {
|
||||
return BY_ID.get(name);
|
||||
}
|
||||
|
||||
/**
|
||||
* Add new {@link EnchantmentRequirement} to EcoEnchants.
|
||||
* <p>
|
||||
* Only for internal use, requirements are automatically added in the constructor.
|
||||
*
|
||||
* @param req The {@link EnchantmentRequirement} to add.
|
||||
*/
|
||||
public static void addNewRequirement(@NotNull final EnchantmentRequirement req) {
|
||||
BY_ID.inverse().remove(req);
|
||||
BY_ID.put(req.getId(), req);
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove {@link EnchantmentRequirement} from EcoEnchants.
|
||||
*
|
||||
* @param req The {@link EnchantmentRequirement} to remove.
|
||||
*/
|
||||
public static void removeRequirement(@NotNull final EnchantmentRequirement req) {
|
||||
BY_ID.inverse().remove(req);
|
||||
}
|
||||
}
|
@ -1,23 +0,0 @@
|
||||
package com.willfp.ecoenchants.enchantments.meta.requirements.requirements;
|
||||
|
||||
import com.willfp.ecoenchants.enchantments.meta.requirements.EnchantmentRequirement;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class RequirementHasPermission extends EnchantmentRequirement {
|
||||
/**
|
||||
* Create new requirement.
|
||||
*/
|
||||
public RequirementHasPermission() {
|
||||
super("has-permission");
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean doesPlayerMeet(@NotNull final Player player,
|
||||
@NotNull final List<String> args) {
|
||||
String permission = args.get(0);
|
||||
return player.hasPermission(permission);
|
||||
}
|
||||
}
|
@ -1,26 +0,0 @@
|
||||
package com.willfp.ecoenchants.enchantments.meta.requirements.requirements;
|
||||
|
||||
import com.willfp.eco.core.integrations.placeholder.PlaceholderManager;
|
||||
import com.willfp.ecoenchants.enchantments.meta.requirements.EnchantmentRequirement;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class RequirementPlaceholderEquals extends EnchantmentRequirement {
|
||||
/**
|
||||
* Create new requirement.
|
||||
*/
|
||||
public RequirementPlaceholderEquals() {
|
||||
super("placeholder-equals");
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean doesPlayerMeet(@NotNull final Player player,
|
||||
@NotNull final List<String> args) {
|
||||
String placeholder = args.get(0);
|
||||
String equals = args.get(1);
|
||||
|
||||
return PlaceholderManager.translatePlaceholders(placeholder, player).equalsIgnoreCase(equals);
|
||||
}
|
||||
}
|
@ -1,30 +0,0 @@
|
||||
package com.willfp.ecoenchants.enchantments.meta.requirements.requirements;
|
||||
|
||||
import com.willfp.eco.core.integrations.placeholder.PlaceholderManager;
|
||||
import com.willfp.ecoenchants.enchantments.meta.requirements.EnchantmentRequirement;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class RequirementPlaceholderGreaterThan extends EnchantmentRequirement {
|
||||
/**
|
||||
* Create new requirement.
|
||||
*/
|
||||
public RequirementPlaceholderGreaterThan() {
|
||||
super("placeholder-greater-than");
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean doesPlayerMeet(@NotNull final Player player,
|
||||
@NotNull final List<String> args) {
|
||||
String placeholder = args.get(0);
|
||||
double equals = Double.parseDouble(args.get(1));
|
||||
|
||||
try {
|
||||
return Double.parseDouble(PlaceholderManager.translatePlaceholders(placeholder, player)) >= equals;
|
||||
} catch (NumberFormatException e) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
@ -1,30 +0,0 @@
|
||||
package com.willfp.ecoenchants.enchantments.meta.requirements.requirements;
|
||||
|
||||
import com.willfp.eco.core.integrations.placeholder.PlaceholderManager;
|
||||
import com.willfp.ecoenchants.enchantments.meta.requirements.EnchantmentRequirement;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class RequirementPlaceholderLessThan extends EnchantmentRequirement {
|
||||
/**
|
||||
* Create new requirement.
|
||||
*/
|
||||
public RequirementPlaceholderLessThan() {
|
||||
super("placeholder-less-than");
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean doesPlayerMeet(@NotNull final Player player,
|
||||
@NotNull final List<String> args) {
|
||||
String placeholder = args.get(0);
|
||||
double equals = Double.parseDouble(args.get(1));
|
||||
|
||||
try {
|
||||
return Double.parseDouble(PlaceholderManager.translatePlaceholders(placeholder, player)) < equals;
|
||||
} catch (NumberFormatException e) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user