Files
src
build.gradle
manifest.kod
Code
4 139
src/main/java/com/netharmor/NetheriteArmorEffects.java
package com.netharmor;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import org.bukkit.plugin.java.JavaPlugin;
import org.bukkit.potion.PotionEffect;
import com.cryptomorin.xseries.XMaterial;
import com.cryptomorin.xseries.XPotion;
import java.util.Optional;
public class NetheriteArmorEffects extends JavaPlugin {
@Override
public void onEnable() {
Bukkit.getScheduler().runTaskTimer(this, this::checkAllPlayers, 20L, 20L);
getLogger().info("NetheriteArmorEffects enabled!");
}
private void checkAllPlayers() {
for (Player player : Bukkit.getOnlinePlayers()) {
handlePlayerArmor(player);
}
}
private void handlePlayerArmor(Player player) {
ItemStack helmet = player.getInventory().getHelmet();
ItemStack chestplate = player.getInventory().getChestplate();
ItemStack leggings = player.getInventory().getLeggings();
ItemStack boots = player.getInventory().getBoots();
handleHelmet(player, helmet);
handleChestplate(player, chestplate);
handleLeggings(player, leggings);
handleBoots(player, boots);
}
private void handleHelmet(Player player, ItemStack helmet) {
Optional<XMaterial> material = helmet != null
? XMaterial.matchXMaterial(helmet.getType())
: Optional.empty();
if (material.isPresent() && material.get() == XMaterial.NETHERITE_HELMET) {
XPotion.matchXPotion("WATER_BREATHING")
.map(xp -> xp.buildPotionEffect(Integer.MAX_VALUE, 0))
.ifPresent(player::addPotionEffect);
} else {
XPotion.matchXPotion("WATER_BREATHING").ifPresent(xp -> {
player.removePotionEffect(xp.getPotionEffectType());
});
}
}
private void handleChestplate(Player player, ItemStack chestplate) {
Optional<XMaterial> material = chestplate != null
? XMaterial.matchXMaterial(chestplate.getType())
: Optional.empty();
if (material.isPresent() && material.get() == XMaterial.NETHERITE_CHESTPLATE) {
XPotion.matchXPotion("STRENGTH")
.map(xp -> xp.buildPotionEffect(Integer.MAX_VALUE, 1))
.ifPresent(player::addPotionEffect);
} else {
XPotion.matchXPotion("STRENGTH").ifPresent(xp -> {
player.removePotionEffect(xp.getPotionEffectType());
});
}
}
private void handleLeggings(Player player, ItemStack leggings) {
Optional<XMaterial> material = leggings != null
? XMaterial.matchXMaterial(leggings.getType())
: Optional.empty();
if (material.isPresent() && material.get() == XMaterial.NETHERITE_LEGGINGS) {
XPotion.matchXPotion("RESISTANCE")
.map(xp -> xp.buildPotionEffect(Integer.MAX_VALUE, 1))
.ifPresent(player::addPotionEffect);
} else {
XPotion.matchXPotion("RESISTANCE").ifPresent(xp -> {
player.removePotionEffect(xp.getPotionEffectType());
});
}
}
private void handleBoots(Player player, ItemStack boots) {
Optional<XMaterial> material = boots != null
? XMaterial.matchXMaterial(boots.getType())
: Optional.empty();
if (material.isPresent() && material.get() == XMaterial.NETHERITE_BOOTS) {
XPotion.matchXPotion("SPEED")
.map(xp -> xp.buildPotionEffect(Integer.MAX_VALUE, 1))
.ifPresent(player::addPotionEffect);
} else {
XPotion.matchXPotion("SPEED").ifPresent(xp -> {
player.removePotionEffect(xp.getPotionEffectType());
});
}
}
}