mirror of
https://github.com/Auxilor/EcoEnchants.git
synced 2024-11-22 15:05:18 +01:00
Deprecated EcoEnchants.getFromEnchantment and replaced with typecasts
This commit is contained in:
parent
4c8f9f07eb
commit
5881903706
@ -1,6 +1,6 @@
|
||||
package com.willfp.ecoenchants.proxy.v1_16_R1.enchants;
|
||||
|
||||
import com.willfp.ecoenchants.enchantments.EcoEnchants;
|
||||
import com.willfp.ecoenchants.enchantments.EcoEnchant;
|
||||
import com.willfp.ecoenchants.enchantments.support.vanilla.VanillaEnchantmentMetadata;
|
||||
import com.willfp.ecoenchants.enchantments.util.EnchantmentUtils;
|
||||
import net.minecraft.server.v1_16_R1.Enchantment;
|
||||
@ -23,7 +23,7 @@ public class EcoCraftEnchantment extends CraftEnchantment {
|
||||
|
||||
@Override
|
||||
public boolean conflictsWith(@NotNull final org.bukkit.enchantments.Enchantment other) {
|
||||
return EcoEnchants.getFromEnchantment(other) == null ? super.conflictsWith(other) : other.conflictsWith(this);
|
||||
return other instanceof EcoEnchant ? other.conflictsWith(this) : super.conflictsWith(other);
|
||||
}
|
||||
|
||||
public void register() {
|
||||
|
@ -1,6 +1,6 @@
|
||||
package com.willfp.ecoenchants.proxy.v1_16_R2.enchants;
|
||||
|
||||
import com.willfp.ecoenchants.enchantments.EcoEnchants;
|
||||
import com.willfp.ecoenchants.enchantments.EcoEnchant;
|
||||
import com.willfp.ecoenchants.enchantments.support.vanilla.VanillaEnchantmentMetadata;
|
||||
import com.willfp.ecoenchants.enchantments.util.EnchantmentUtils;
|
||||
import net.minecraft.server.v1_16_R2.Enchantment;
|
||||
@ -23,7 +23,7 @@ public class EcoCraftEnchantment extends CraftEnchantment {
|
||||
|
||||
@Override
|
||||
public boolean conflictsWith(@NotNull final org.bukkit.enchantments.Enchantment other) {
|
||||
return EcoEnchants.getFromEnchantment(other) == null ? super.conflictsWith(other) : other.conflictsWith(this);
|
||||
return other instanceof EcoEnchant ? other.conflictsWith(this) : super.conflictsWith(other);
|
||||
}
|
||||
|
||||
public void register() {
|
||||
|
@ -1,6 +1,6 @@
|
||||
package com.willfp.ecoenchants.proxy.v1_16_R3.enchants;
|
||||
|
||||
import com.willfp.ecoenchants.enchantments.EcoEnchants;
|
||||
import com.willfp.ecoenchants.enchantments.EcoEnchant;
|
||||
import com.willfp.ecoenchants.enchantments.support.vanilla.VanillaEnchantmentMetadata;
|
||||
import com.willfp.ecoenchants.enchantments.util.EnchantmentUtils;
|
||||
import net.minecraft.server.v1_16_R3.Enchantment;
|
||||
@ -23,7 +23,7 @@ public class EcoCraftEnchantment extends CraftEnchantment {
|
||||
|
||||
@Override
|
||||
public boolean conflictsWith(@NotNull final org.bukkit.enchantments.Enchantment other) {
|
||||
return EcoEnchants.getFromEnchantment(other) == null ? super.conflictsWith(other) : other.conflictsWith(this);
|
||||
return other instanceof EcoEnchant ? other.conflictsWith(this) : super.conflictsWith(other);
|
||||
}
|
||||
|
||||
public void register() {
|
||||
|
@ -1,6 +1,6 @@
|
||||
package com.willfp.ecoenchants.proxy.v1_17_R1.enchants;
|
||||
|
||||
import com.willfp.ecoenchants.enchantments.EcoEnchants;
|
||||
import com.willfp.ecoenchants.enchantments.EcoEnchant;
|
||||
import com.willfp.ecoenchants.enchantments.support.vanilla.VanillaEnchantmentMetadata;
|
||||
import com.willfp.ecoenchants.enchantments.util.EnchantmentUtils;
|
||||
import net.minecraft.world.item.enchantment.Enchantment;
|
||||
@ -23,7 +23,7 @@ public class EcoCraftEnchantment extends CraftEnchantment {
|
||||
|
||||
@Override
|
||||
public boolean conflictsWith(@NotNull final org.bukkit.enchantments.Enchantment other) {
|
||||
return EcoEnchants.getFromEnchantment(other) == null ? super.conflictsWith(other) : other.conflictsWith(this);
|
||||
return other instanceof EcoEnchant ? other.conflictsWith(this) : super.conflictsWith(other);
|
||||
}
|
||||
|
||||
public void register() {
|
||||
|
@ -80,15 +80,16 @@ public class CommandEnchantinfo extends PluginCommand {
|
||||
Set<Enchantment> conflicts = enchantment.getConflicts();
|
||||
|
||||
new HashSet<>(conflicts).forEach(enchantment1 -> {
|
||||
EcoEnchant ecoEnchant = EcoEnchants.getFromEnchantment(enchantment1);
|
||||
if (ecoEnchant != null && !ecoEnchant.isEnabled()) {
|
||||
if (enchantment1 instanceof EcoEnchant ecoEnchant) {
|
||||
if (!ecoEnchant.isEnabled()) {
|
||||
conflicts.remove(enchantment1);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
conflicts.forEach((enchantment1 -> {
|
||||
if (EcoEnchants.getFromEnchantment(enchantment1) != null) {
|
||||
conflictNames.add(EcoEnchants.getFromEnchantment(enchantment1).getDisplayName());
|
||||
if (enchantment1 instanceof EcoEnchant enchant) {
|
||||
conflictNames.add(enchant.getDisplayName());
|
||||
} else {
|
||||
conflictNames.add(this.getPlugin().getLangYml().getString("enchantments." + enchantment1.getKey().getKey() + ".name"));
|
||||
}
|
||||
|
@ -81,8 +81,7 @@ public class CommandRandomenchant extends Subcommand {
|
||||
if (!onItem.contains(ecoEnchant)) {
|
||||
boolean conflicts = false;
|
||||
for (Enchantment enchantment : onItem) {
|
||||
if (EcoEnchants.getFromEnchantment(enchantment) != null) {
|
||||
EcoEnchant ecoEnchantOnItem = EcoEnchants.getFromEnchantment(enchantment);
|
||||
if (enchantment instanceof EcoEnchant ecoEnchantOnItem) {
|
||||
if (ecoEnchantOnItem.getType().equals(ecoEnchant.getType()) && ecoEnchantOnItem.getType().isSingular()) {
|
||||
conflicts = true;
|
||||
}
|
||||
|
@ -8,7 +8,6 @@ import com.willfp.eco.core.display.DisplayPriority;
|
||||
import com.willfp.eco.util.NumberUtils;
|
||||
import com.willfp.ecoenchants.display.options.DisplayOptions;
|
||||
import com.willfp.ecoenchants.enchantments.EcoEnchant;
|
||||
import com.willfp.ecoenchants.enchantments.EcoEnchants;
|
||||
import com.willfp.ecoenchants.enchantments.meta.EnchantmentTarget;
|
||||
import com.willfp.ecoenchants.proxy.proxies.FastGetEnchantsProxy;
|
||||
import com.willfp.ecoenchants.util.ProxyUtils;
|
||||
@ -129,12 +128,10 @@ public class EnchantDisplay extends DisplayModule {
|
||||
unsorted.forEach(enchantment -> enchantments.put(enchantment, tempEnchantments.get(enchantment)));
|
||||
|
||||
enchantments.forEach((enchantment, level) -> {
|
||||
if (EcoEnchants.getFromEnchantment(enchantment) == null) {
|
||||
if (!(enchantment instanceof EcoEnchant ecoEnchant)) {
|
||||
return;
|
||||
}
|
||||
|
||||
EcoEnchant ecoEnchant = EcoEnchants.getFromEnchantment(enchantment);
|
||||
|
||||
if (!ecoEnchant.isEnabled()) {
|
||||
forRemoval.add(enchantment);
|
||||
}
|
||||
|
@ -5,7 +5,6 @@ import com.willfp.eco.core.config.ConfigUpdater;
|
||||
import com.willfp.eco.core.display.Display;
|
||||
import com.willfp.ecoenchants.EcoEnchantsPlugin;
|
||||
import com.willfp.ecoenchants.enchantments.EcoEnchant;
|
||||
import com.willfp.ecoenchants.enchantments.EcoEnchants;
|
||||
import com.willfp.ecoenchants.enchantments.meta.EnchantmentRarity;
|
||||
import com.willfp.ecoenchants.enchantments.meta.EnchantmentType;
|
||||
import lombok.Getter;
|
||||
@ -100,8 +99,7 @@ public class EnchantmentCache {
|
||||
EnchantmentType type;
|
||||
EnchantmentRarity rarity;
|
||||
List<String> description;
|
||||
if (EcoEnchants.getFromEnchantment(enchantment) != null) {
|
||||
EcoEnchant ecoEnchant = EcoEnchants.getFromEnchantment(enchantment);
|
||||
if (enchantment instanceof EcoEnchant ecoEnchant) {
|
||||
description = ecoEnchant.getWrappedDescription();
|
||||
name = ecoEnchant.getDisplayName();
|
||||
type = ecoEnchant.getType();
|
||||
|
@ -524,9 +524,11 @@ public class EcoEnchants {
|
||||
*
|
||||
* @param enchantment The enchantment.
|
||||
* @return The matching {@link EcoEnchant}, or null if not found.
|
||||
* @deprecated Use a typecast.
|
||||
*/
|
||||
@Deprecated
|
||||
public static EcoEnchant getFromEnchantment(@NotNull final Enchantment enchantment) {
|
||||
return getByKey(enchantment.getKey());
|
||||
return enchantment instanceof EcoEnchant ? (EcoEnchant) enchantment : null;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -573,13 +575,13 @@ public class EcoEnchants {
|
||||
|
||||
if (item.getItemMeta() instanceof EnchantmentStorageMeta) {
|
||||
((EnchantmentStorageMeta) item.getItemMeta()).getStoredEnchants().forEach(((enchantment, integer) -> {
|
||||
if (getFromEnchantment(enchantment) != null && getFromEnchantment(enchantment).getType().equals(type)) {
|
||||
if (enchantment instanceof EcoEnchant ecoEnchant && ecoEnchant.getType().equals(type)) {
|
||||
hasOfType.set(true);
|
||||
}
|
||||
}));
|
||||
} else {
|
||||
item.getEnchantments().forEach((enchantment, integer) -> {
|
||||
if (getFromEnchantment(enchantment) != null && (getFromEnchantment(enchantment).getType().equals(type))) {
|
||||
if (enchantment instanceof EcoEnchant ecoEnchant && ecoEnchant.getType().equals(type)) {
|
||||
hasOfType.set(true);
|
||||
}
|
||||
});
|
||||
|
@ -165,7 +165,7 @@ public class AnvilMerge {
|
||||
AtomicBoolean doesConflict = new AtomicBoolean(false);
|
||||
|
||||
EnchantmentType.values().forEach(enchantmentType -> {
|
||||
EcoEnchant enchant = EcoEnchants.getFromEnchantment(enchantment);
|
||||
EcoEnchant enchant = (EcoEnchant) enchantment;
|
||||
if (enchant == null) {
|
||||
return;
|
||||
}
|
||||
@ -258,12 +258,12 @@ public class AnvilMerge {
|
||||
AtomicInteger inEnchantLevels = new AtomicInteger();
|
||||
|
||||
outEnchants.forEach(((enchantment, integer) -> {
|
||||
if (EcoEnchants.getFromEnchantment(enchantment) != null) {
|
||||
if (enchantment instanceof EcoEnchant) {
|
||||
outEnchantLevels.addAndGet(integer);
|
||||
}
|
||||
}));
|
||||
leftEnchants.forEach(((enchantment, integer) -> {
|
||||
if (EcoEnchants.getFromEnchantment(enchantment) != null) {
|
||||
if (enchantment instanceof EcoEnchant) {
|
||||
outEnchantLevels.addAndGet(integer);
|
||||
}
|
||||
}));
|
||||
|
@ -1,7 +1,6 @@
|
||||
package com.willfp.ecoenchants.enchantments.support.merging.grindstone;
|
||||
|
||||
import com.willfp.ecoenchants.enchantments.EcoEnchant;
|
||||
import com.willfp.ecoenchants.enchantments.EcoEnchants;
|
||||
import lombok.experimental.UtilityClass;
|
||||
import org.bukkit.enchantments.Enchantment;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
@ -46,8 +45,7 @@ public class GrindstoneMerge {
|
||||
}
|
||||
|
||||
bottomEnchants.forEach(((enchantment, integer) -> {
|
||||
if (EcoEnchants.getFromEnchantment(enchantment) != null) {
|
||||
EcoEnchant ecoEnchant = EcoEnchants.getFromEnchantment(enchantment);
|
||||
if (enchantment instanceof EcoEnchant ecoEnchant) {
|
||||
if (!ecoEnchant.isGrindstoneable()) {
|
||||
toKeep.putIfAbsent(enchantment, integer);
|
||||
}
|
||||
@ -58,8 +56,7 @@ public class GrindstoneMerge {
|
||||
}
|
||||
}));
|
||||
topEnchants.forEach(((enchantment, integer) -> {
|
||||
if (EcoEnchants.getFromEnchantment(enchantment) != null) {
|
||||
EcoEnchant ecoEnchant = EcoEnchants.getFromEnchantment(enchantment);
|
||||
if (enchantment instanceof EcoEnchant ecoEnchant) {
|
||||
if (!ecoEnchant.isGrindstoneable()) {
|
||||
toKeep.putIfAbsent(enchantment, integer);
|
||||
}
|
||||
|
@ -147,8 +147,7 @@ public class EnchantingListeners extends PluginDependent<EcoPlugin> implements L
|
||||
anyConflicts.set(true);
|
||||
}
|
||||
|
||||
if (EcoEnchants.getFromEnchantment(enchant) != null) {
|
||||
EcoEnchant ecoEnchant = EcoEnchants.getFromEnchantment(enchant);
|
||||
if (enchant instanceof EcoEnchant ecoEnchant) {
|
||||
if (enchantment.getType().equals(ecoEnchant.getType()) && ecoEnchant.getType().isSingular()) {
|
||||
anyConflicts.set(true);
|
||||
}
|
||||
|
@ -120,7 +120,7 @@ public class LootPopulator extends BlockPopulator {
|
||||
anyConflicts.set(true);
|
||||
}
|
||||
|
||||
EcoEnchant ecoEnchant = EcoEnchants.getFromEnchantment(enchant);
|
||||
EcoEnchant ecoEnchant = (EcoEnchant) enchant;
|
||||
if (enchantment.getType().equals(ecoEnchant.getType()) && ecoEnchant.getType().isSingular()) {
|
||||
anyConflicts.set(true);
|
||||
}
|
||||
|
@ -179,7 +179,7 @@ public class VillagerListeners extends PluginDependent<EcoPlugin> implements Lis
|
||||
anyConflicts.set(true);
|
||||
}
|
||||
|
||||
EcoEnchant ecoEnchant = EcoEnchants.getFromEnchantment(enchant);
|
||||
EcoEnchant ecoEnchant = enchant;
|
||||
|
||||
if (enchantment.getType().equals(ecoEnchant.getType()) && ecoEnchant.getType().isSingular()) {
|
||||
anyConflicts.set(true);
|
||||
|
@ -3,7 +3,6 @@ package com.willfp.ecoenchants.enchantments.util;
|
||||
|
||||
import com.willfp.eco.util.DurabilityUtils;
|
||||
import com.willfp.ecoenchants.enchantments.EcoEnchant;
|
||||
import com.willfp.ecoenchants.enchantments.EcoEnchants;
|
||||
import com.willfp.ecoenchants.proxy.proxies.FastGetEnchantsProxy;
|
||||
import com.willfp.ecoenchants.util.ProxyUtils;
|
||||
import lombok.experimental.UtilityClass;
|
||||
@ -77,8 +76,7 @@ public class EnchantChecks {
|
||||
|
||||
Map<EcoEnchant, Integer> ecoEnchants = new HashMap<>();
|
||||
for (Map.Entry<Enchantment, Integer> enchantmentIntegerEntry : PROXY.getEnchantmentsOnItem(item).entrySet()) {
|
||||
EcoEnchant enchant = EcoEnchants.getFromEnchantment(enchantmentIntegerEntry.getKey());
|
||||
if (enchant != null) {
|
||||
if (enchantmentIntegerEntry.getKey() instanceof EcoEnchant enchant) {
|
||||
ecoEnchants.put(enchant, enchantmentIntegerEntry.getValue());
|
||||
}
|
||||
}
|
||||
|
@ -347,9 +347,7 @@ public class ItemConversions extends PluginDependent<EcoPlugin> implements Liste
|
||||
EcoEnchant illegalEnchant = null;
|
||||
|
||||
for (Enchantment enchantment : meta.getEnchants().keySet()) {
|
||||
if (EcoEnchants.getFromEnchantment(enchantment) != null) {
|
||||
EcoEnchant enchant = EcoEnchants.getFromEnchantment(enchantment);
|
||||
|
||||
if (enchantment instanceof EcoEnchant enchant) {
|
||||
if (!enchant.getTargetMaterials().contains(itemStack.getType())) {
|
||||
illegal = true;
|
||||
illegalEnchant = enchant;
|
||||
|
@ -1,7 +1,6 @@
|
||||
package com.willfp.ecoenchants.sprintartifacts;
|
||||
|
||||
import com.willfp.ecoenchants.enchantments.EcoEnchant;
|
||||
import com.willfp.ecoenchants.enchantments.EcoEnchants;
|
||||
import com.willfp.ecoenchants.enchantments.itemtypes.Artifact;
|
||||
import com.willfp.ecoenchants.enchantments.meta.EnchantmentType;
|
||||
import com.willfp.ecoenchants.enchantments.util.EnchantChecks;
|
||||
@ -40,7 +39,7 @@ public class SprintArtifactsListener implements Listener {
|
||||
}
|
||||
|
||||
Optional<EcoEnchant> matching = bootsMeta.getEnchants().keySet().stream()
|
||||
.map(EcoEnchants::getFromEnchantment)
|
||||
.map(enchant -> (EcoEnchant) enchant)
|
||||
.filter(Objects::nonNull)
|
||||
.filter(enchantment -> enchantment.getType().equals(EnchantmentType.ARTIFACT))
|
||||
.findFirst();
|
||||
|
Loading…
Reference in New Issue
Block a user