Files
fantasysmp/src/main/java/dev/zxq5/fantasysmp/items/Witherite.java
T
FantasyPvP b8f9b7749b initial
2025-01-05 18:42:39 +00:00

88 lines
3.3 KiB
Java

package dev.zxq5.fantasysmp.items;
import org.bukkit.command.CommandExecutor;
import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.potion.PotionEffect;
public class Witherite extends GenericGearSet implements Listener, CommandExecutor {
@Override
public boolean onCommand(org.bukkit.command.CommandSender sender, org.bukkit.command.Command command, String label, String[] args) {
if (!(args[0].equals("witherite"))) {
return false;
}
Player player = (Player) sender;
player.getInventory().addItem(new Witherite().getSword());
player.getInventory().addItem(new Witherite().getHelmet());
player.getInventory().addItem(new Witherite().getChestplate());
player.getInventory().addItem(new Witherite().getLeggings());
player.getInventory().addItem(new Witherite().getBoots());
return true;
}
@EventHandler
public void onEntityDamageByEntity(org.bukkit.event.entity.EntityDamageByEntityEvent event) {
// checks that it is a player that is performing the attack.
if (!(event.getDamager() instanceof org.bukkit.entity.Player player)) {
return;
}
try {
if (!player.getInventory().getItemInMainHand().getItemMeta().getLore().toString().contains(this.swordLore)) {
return;
}
} catch (Exception e) {
e.printStackTrace();
return;
}
PotionEffect effect = new PotionEffect(
org.bukkit.potion.PotionEffectType.WITHER,
20 * 5,
1
);
effect.apply((LivingEntity) event.getEntity());
}
@EventHandler
public void onEntityPotionEffectEvent(org.bukkit.event.entity.EntityPotionEffectEvent event) {
if (event.getEntity() instanceof Player player) {
try {
if (player.getInventory().getHelmet().getItemMeta().getLore().toString().contains(this.helmetLore)
&& player.getInventory().getChestplate().getItemMeta().getLore().toString().contains(this.chestplateLore)
&& player.getInventory().getLeggings().getItemMeta().getLore().toString().contains(this.leggingsLore)
&& player.getInventory().getBoots().getItemMeta().getLore().toString().contains(this.bootsLore)) {
event.setCancelled(true);
}
} catch (Exception e) {
e.printStackTrace();
}
}
}
public static void init() {}
public Witherite() {
this.setTier5();
this.swordName = "Witherite Sword";
this.helmetName = "Witherite Helmet";
this.chestplateName = "Witherite Chestplate";
this.leggingsName = "Witherite Leggings";
this.bootsName = "Witherite Boots";
this.swordLore = "A sword forged with the skulls of wither skeletons.";
this.helmetLore = "A helmet forged with the skulls of wither skeletons.";
this.chestplateLore = "A chestplate forged with the skulls of wither skeletons.";
this.leggingsLore = "A leggings forged with the skulls of wither skeletons.";
this.bootsLore = "A boots forged with the skulls of wither skeletons.";
}
}