diff --git a/src/main/java/city/norain/slimefun4/compatibillty/VersionedAttribute.java b/src/main/java/city/norain/slimefun4/compatibillty/VersionedAttribute.java new file mode 100644 index 0000000000..c4f5ad7bcd --- /dev/null +++ b/src/main/java/city/norain/slimefun4/compatibillty/VersionedAttribute.java @@ -0,0 +1,16 @@ +package city.norain.slimefun4.compatibillty; + +import city.norain.slimefun4.SlimefunExtended; +import lombok.experimental.UtilityClass; +import org.bukkit.attribute.Attribute; + +@UtilityClass +public class VersionedAttribute { + public static Attribute getMaxHealth() { + if (SlimefunExtended.getMinecraftVersion().isAtLeast(1, 21, 3)) { + return Attribute.valueOf("MAX_HEALTH"); + } else { + return Attribute.valueOf("GENERIC_MAX_HEALTH"); + } + } +} diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/medical/Bandage.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/medical/Bandage.java index 38a68b5cd2..95b9d2b329 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/medical/Bandage.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/medical/Bandage.java @@ -1,5 +1,6 @@ package io.github.thebusybiscuit.slimefun4.implementation.items.medical; +import city.norain.slimefun4.compatibillty.VersionedAttribute; import io.github.bakedlibs.dough.items.ItemUtils; import io.github.thebusybiscuit.slimefun4.api.items.ItemGroup; import io.github.thebusybiscuit.slimefun4.api.items.SlimefunItemStack; @@ -11,7 +12,6 @@ import org.bukkit.Effect; import org.bukkit.GameMode; import org.bukkit.Material; -import org.bukkit.attribute.Attribute; import org.bukkit.entity.Player; import org.bukkit.inventory.ItemStack; import org.bukkit.potion.PotionEffect; @@ -45,7 +45,8 @@ public ItemUseHandler getItemHandler() { // Player is neither burning nor injured if (p.getFireTicks() <= 0 && p.getHealth() - >= p.getAttribute(Attribute.GENERIC_MAX_HEALTH).getValue()) { + >= p.getAttribute(VersionedAttribute.getMaxHealth()).getValue()) { + return; } diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/medical/MedicalSupply.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/medical/MedicalSupply.java index 347d82f01e..745f2774ea 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/medical/MedicalSupply.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/medical/MedicalSupply.java @@ -1,5 +1,6 @@ package io.github.thebusybiscuit.slimefun4.implementation.items.medical; +import city.norain.slimefun4.compatibillty.VersionedAttribute; import io.github.thebusybiscuit.slimefun4.api.items.ItemGroup; import io.github.thebusybiscuit.slimefun4.api.items.ItemHandler; import io.github.thebusybiscuit.slimefun4.api.items.SlimefunItemStack; @@ -11,7 +12,6 @@ import java.util.Set; import lombok.Getter; -import org.bukkit.attribute.Attribute; import org.bukkit.entity.LivingEntity; import org.bukkit.inventory.ItemStack; import org.bukkit.potion.PotionEffect; @@ -41,8 +41,7 @@ protected MedicalSupply( /** * This method clears any negative {@link PotionEffect} from the given {@link LivingEntity}. * - * @param n - * The {@link LivingEntity} to clear the effects from. + * @param n The {@link LivingEntity} to clear the effects from. */ public void clearNegativeEffects(LivingEntity n) { for (PotionEffectType effect : curedEffects) { @@ -55,12 +54,11 @@ public void clearNegativeEffects(LivingEntity n) { /** * This method heals the given {@link LivingEntity} by the amount provided via the constructor. * - * @param n - * The {@link LivingEntity} to heal + * @param n The {@link LivingEntity} to heal */ public void heal(LivingEntity n) { double health = n.getHealth() + healAmount; - double maxHealth = n.getAttribute(Attribute.GENERIC_MAX_HEALTH).getValue(); + double maxHealth = n.getAttribute(VersionedAttribute.getMaxHealth()).getValue(); n.setHealth(Math.min(health, maxHealth)); } } diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/medical/Splint.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/medical/Splint.java index e9a3b45d74..ba64892df6 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/medical/Splint.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/medical/Splint.java @@ -1,5 +1,6 @@ package io.github.thebusybiscuit.slimefun4.implementation.items.medical; +import city.norain.slimefun4.compatibillty.VersionedAttribute; import io.github.bakedlibs.dough.items.ItemUtils; import io.github.thebusybiscuit.slimefun4.api.items.ItemGroup; import io.github.thebusybiscuit.slimefun4.api.items.SlimefunItemStack; @@ -10,7 +11,6 @@ import io.github.thebusybiscuit.slimefun4.utils.compatibility.VersionedPotionEffectType; import org.bukkit.GameMode; -import org.bukkit.attribute.Attribute; import org.bukkit.entity.Player; import org.bukkit.inventory.ItemStack; import org.bukkit.potion.PotionEffect; @@ -33,7 +33,7 @@ public ItemUseHandler getItemHandler() { // Player is neither burning nor injured if (p.getFireTicks() <= 0 && p.getHealth() - >= p.getAttribute(Attribute.GENERIC_MAX_HEALTH).getValue()) { + >= p.getAttribute(VersionedAttribute.getMaxHealth()).getValue()) { return; } diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/weapons/VampireBlade.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/weapons/VampireBlade.java index 60c390e7b1..9d7b8e095d 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/weapons/VampireBlade.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/weapons/VampireBlade.java @@ -1,5 +1,6 @@ package io.github.thebusybiscuit.slimefun4.implementation.items.weapons; +import city.norain.slimefun4.compatibillty.VersionedAttribute; import io.github.thebusybiscuit.slimefun4.api.items.ItemGroup; import io.github.thebusybiscuit.slimefun4.api.items.ItemSetting; import io.github.thebusybiscuit.slimefun4.api.items.SlimefunItemStack; @@ -8,9 +9,9 @@ import io.github.thebusybiscuit.slimefun4.core.handlers.WeaponUseHandler; import io.github.thebusybiscuit.slimefun4.core.services.sounds.SoundEffect; import io.github.thebusybiscuit.slimefun4.implementation.items.SimpleSlimefunItem; + import java.util.concurrent.ThreadLocalRandom; -import org.bukkit.attribute.Attribute; import org.bukkit.entity.LivingEntity; import org.bukkit.entity.Player; import org.bukkit.inventory.ItemStack; @@ -20,7 +21,6 @@ * who damages another {@link LivingEntity} with this sword. * * @author TheBusyBiscuit - * */ public class VampireBlade extends SimpleSlimefunItem { private static final double HEALING_AMOUNT = 4.0; @@ -39,7 +39,8 @@ public WeaponUseHandler getItemHandler() { if (ThreadLocalRandom.current().nextInt(100) < getChance()) { SoundEffect.VAMPIRE_BLADE_HEALING_SOUND.playFor(p); double health = p.getHealth() + HEALING_AMOUNT; - double maxHealth = p.getAttribute(Attribute.GENERIC_MAX_HEALTH).getValue(); + double maxHealth = + p.getAttribute(VersionedAttribute.getMaxHealth()).getValue(); p.setHealth(Math.min(health, maxHealth)); } }; diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/utils/biomes/BiomeMap.java b/src/main/java/io/github/thebusybiscuit/slimefun4/utils/biomes/BiomeMap.java index 8c4b762653..bdb11193e9 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/utils/biomes/BiomeMap.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/utils/biomes/BiomeMap.java @@ -8,6 +8,7 @@ import java.io.InputStreamReader; import java.nio.charset.StandardCharsets; import java.util.EnumMap; +import java.util.HashMap; import java.util.Map; import java.util.stream.Collectors; import javax.annotation.Nullable; diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/utils/biomes/BiomeMapParser.java b/src/main/java/io/github/thebusybiscuit/slimefun4/utils/biomes/BiomeMapParser.java index 31bf85f2c9..299889627a 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/utils/biomes/BiomeMapParser.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/utils/biomes/BiomeMapParser.java @@ -8,11 +8,8 @@ import io.github.thebusybiscuit.slimefun4.api.exceptions.BiomeMapException; import io.github.thebusybiscuit.slimefun4.utils.JsonUtils; import io.github.thebusybiscuit.slimefun4.utils.PatternUtils; -import java.util.EnumMap; -import java.util.EnumSet; -import java.util.Locale; -import java.util.Map; -import java.util.Set; + +import java.util.*; import org.bukkit.NamespacedKey; import org.bukkit.block.Biome;