Solved Is this the best way of doing adding damage?

Discussion in 'Plugin Development' started by RainingTNT123, May 4, 2020.

Thread Status:
Not open for further replies.
  1. Offline

    RainingTNT123

    I was wondering if there was a better way of dealing damage because when I put this on a weapon it makes it do a lot of damage but it's not doing it directly either.
    So if there is a better way of changing the damage of an item that would be great!
    By the way I'm using bukkit 1.8
    Thanks!

    What I'm using
    damaged.damage(8);

    My Code
    Code:
    package me.RainingTNT123.Ultimates.Events;
    
    
    
    import java.util.UUID;
    
    import org.bukkit.ChatColor;
    import org.bukkit.entity.LivingEntity;
    import org.bukkit.entity.Player;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.Listener;
    import org.bukkit.event.entity.EntityDamageByEntityEvent;
    import org.bukkit.inventory.ItemStack;
    import org.bukkit.potion.PotionEffect;
    import org.bukkit.potion.PotionEffectType;
    
    import me.RainingTNT123.Ultimates.Main;
    
    
    
    public class EventsClass implements Listener {
    
        private Main plugin = Main.getPlugin(Main.class);
      
      
        @EventHandler
        public void onHit(EntityDamageByEntityEvent event) {
            if(event.getDamager() instanceof Player) {
                Player player = (Player) event.getDamager();
                LivingEntity damaged = (LivingEntity) event.getEntity();
          
              
              
                ItemStack hand = player.getInventory().getItemInHand();
            if(hand.getItemMeta().getDisplayName().contains(ChatColor.DARK_PURPLE + "The Withered Sword")){
                damaged.addPotionEffect(new PotionEffect(PotionEffectType.WITHER, 60, 2));
                damaged.addPotionEffect(new PotionEffect(PotionEffectType.BLINDNESS, 60, 2));
                damaged.damage(8);
    
            }
            }
        }
            @EventHandler
            public void onHit2(EntityDamageByEntityEvent event) {
                if(event.getDamager() instanceof Player) {
                    Player player = (Player) event.getDamager();
                    LivingEntity damaged = (LivingEntity) event.getEntity();
                    UUID uuid = player.getUniqueId();
                  
            ItemStack hand2 = player.getInventory().getItemInHand();
            if(hand2.getItemMeta().getDisplayName().contains(ChatColor.DARK_AQUA + "The Hammer of The Storms")){
                damaged.damage(7);
                if(!plugin.cdtime.containsKey(uuid)) {
                  
                damaged.getWorld().strikeLightning(event.getEntity().getLocation());
                plugin.cdtime.put(uuid, plugin.smitecd);
                player.sendMessage(ChatColor.GREEN + "You used the" + ChatColor.GOLD + ChatColor.BOLD + " Smite" +  ChatColor.GREEN + " Ability!");
                }
                }else {
                    event.setCancelled(true);
                    if(hand2.getItemMeta().getDisplayName().contains(ChatColor.DARK_AQUA + "The Hammer of The Storms")){
                    player.sendMessage(ChatColor.RED + "You are on cooldown currently with" + ChatColor.GOLD + plugin.cdtime.get(uuid) + ChatColor.RED + " seconds");
            }
                }}}
            @EventHandler
            public void onHit3(EntityDamageByEntityEvent event) {
                if(event.getDamager() instanceof Player) {
                    Player player = (Player) event.getDamager();
                    LivingEntity damaged = (LivingEntity) event.getEntity();
                    UUID uuid = player.getUniqueId();
            ItemStack hand3 = player.getInventory().getItemInHand();
            if(hand3.getItemMeta().getDisplayName().contains(ChatColor.DARK_PURPLE + "Sword of Harming")){
                damaged.damage(2);
                if(!plugin.cdtime.containsKey(uuid)) {
                  
              
                damaged.addPotionEffect(new PotionEffect(PotionEffectType.HARM, 1, 2));
                plugin.cdtime.put(uuid, plugin.harmcd);
                player.sendMessage(ChatColor.GREEN + "You used the" + ChatColor.GOLD + ChatColor.BOLD + " Harming" +  ChatColor.GREEN + " Ability!");
                }
            }else{
                event.setCancelled(true);
                if(hand3.getItemMeta().getDisplayName().contains(ChatColor.DARK_PURPLE + "Sword of Harming")){
                player.sendMessage(ChatColor.RED + "You are on cooldown currently with" + ChatColor.GOLD + plugin.cdtime.get(uuid) + ChatColor.RED + " seconds");
            }
            }
            }}}
          
    
    
     
    Last edited: May 4, 2020
  2. Offline

    KarimAKL

    @RainingTNT123 I might be mistaken but, i think the damage taken from Damageable#damage(double) still gets reduced from armor, resistance, etc.
     
  3. Offline

    RainingTNT123

    Armor does work but it does do a little more than sharpness.
    Thanks for the help!
     
    KarimAKL likes this.
Thread Status:
Not open for further replies.

Share This Page