How do you add custom damage to a sword

Discussion in 'Plugin Development' started by blakeaolson, Jan 14, 2015.

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

    blakeaolson

    Well currently I am wanting to make a plugin about custom swords/bows etc but I want the damage to be greater than a diamond sword and I have no idea how to do this. I do know how to make a simple plugin so I am not a complete noob but if someone could tell me or show me code on how this is done I would greatly appreciate it.
     
    GrandmaJam likes this.
  2. Offline

    teej107

    Use EntityDamageByEntityEvent
     
  3. Offline

    drpk

  4. Offline

    Konato_K

    @drpk Durability does not affect damage.

    Edit: Ahh, now that I see, it's a bit ambiguous what OP says, but I guess he is actually talking about damage dealt with the weapon than damage of the tool
     
  5. Offline

    blakeaolson

    Here is my code
    package me.Blake.GodSword;

    import java.util.Map;
    import java.util.logging.Logger;

    import org.bukkit.Bukkit;
    import org.bukkit.ChatColor;
    import org.bukkit.Material;
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandSender;
    import org.bukkit.enchantments.Enchantment;
    import org.bukkit.entity.Player;
    import org.bukkit.inventory.ItemStack;
    import org.bukkit.inventory.meta.ItemMeta;
    import org.bukkit.plugin.java.JavaPlugin;

    public class GodSword extends JavaPlugin{


    Logger myPluginLogger = Bukkit.getLogger();

    public void onEnable(){

    }

    public void onDisable(){

    }

    public void addEnchantments(Map<Enchantment, Integer> sharpness){


    }


    public boolean onCommand(CommandSender theSender, Command cmd, String commandLabel, String[] args)
    {
    Player player =(Player) theSender;

    if(commandLabel.equalsIgnoreCase("GodSword")){

    if(player.hasPermission("GodSword.GodSword")){
    String GodSword = ("TheGodOfSwords");
    ItemStack myItem = new ItemStack(Material.DIAMOND_SWORD);
    ItemMeta im = myItem.getItemMeta();
    im.setDisplayName(GodSword);
    myItem.setItemMeta(im);
    player.sendMessage(ChatColor.RED + "You have been given a GOD sword");
    getServer().broadcastMessage(ChatColor.GOLD + player.getName() + " has been given a God sword");
    player.getInventory().addItem(new ItemStack(Material.DIAMOND_SWORD));

    }

    else player.sendMessage(ChatColor.RED + "You dont have permission to use GodSword");
    }


    return true;
    }



    }


    Where do I put the public void?
     
  6. Offline

    Dsi_Mario

    Listen in on EntityDamageByEntityEvent, then set the damage value if the conditions are right.
     
  7. Offline

    blakeaolson

  8. Offline

    Konato_K

  9. Offline

    Skionz

    @blakeaolson I would suggest fixing your naming conventions and the unchecked casting.
     
  10. Offline

    Dsi_Mario

    Code:
        @EventHandler
        public void Something(EntityDamageByEntityEvent e){
            if(ConditionsAreMet){
                e.setDamage(DamageValueInDouble);
            }
        }
     
  11. //You should check if the entity damager is a player
    //You have to know the damage will be reduced by the entity armor, etc...
     
    Last edited: Jan 15, 2015
  12. Offline

    Avygeil

  13. Offline

    Konato_K

    @Avygeil The issue with this is that bukkit does not have an API for this, and as far I know, the attributes are not saved if you edit the item meta after adding them.
     
  14. Offline

    Avygeil

    @Konato_K Yes, they are saved if you do it right. And even with no API, it's much more convenient than using Bukkit events.
     
  15. Offline

    Bowan

    The way you posted the code is hard to read.
    here:
    Code:
    package me.Blake.GodSword;
    
    import java.util.Map;
    import java.util.logging.Logger;
    
    import org.bukkit.Bukkit;
    import org.bukkit.ChatColor;
    import org.bukkit.Material;
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandSender;
    import org.bukkit.enchantments.Enchantment;
    import org.bukkit.entity.Player;
    import org.bukkit.inventory.ItemStack;
    import org.bukkit.inventory.meta.ItemMeta;
    import org.bukkit.plugin.java.JavaPlugin;
    
    public class GodSword extends JavaPlugin{
    
    
    Logger myPluginLogger = Bukkit.getLogger();
    
    public void onEnable(){
    
    }
    
    public void onDisable(){
    
    }
    
    public void addEnchantments(Map<Enchantment, Integer> sharpness){
    
    
    }
    
    
    public boolean onCommand(CommandSender theSender, Command cmd, String commandLabel, String[] args)
    {
    Player player =(Player) theSender;
    
    if(commandLabel.equalsIgnoreCase("GodSword")){
    
    if(player.hasPermission("GodSword.GodSword")){
    String GodSword = ("TheGodOfSwords");
    ItemStack myItem = new ItemStack(Material.DIAMOND_SWORD);
    ItemMeta im = myItem.getItemMeta();
    im.setDisplayName(GodSword);
    myItem.setItemMeta(im);
    player.sendMessage(ChatColor.RED + "You have been given a GOD sword");
    getServer().broadcastMessage(ChatColor.GOLD + player.getName() + " has been given a God sword");
    player.getInventory().addItem(new ItemStack(Material.DIAMOND_SWORD));
    
    }
    
    else player.sendMessage(ChatColor.RED + "You dont have permission to use GodSword");
    }
    
    
    return true;
    }
    
    
    
    }
     
Thread Status:
Not open for further replies.

Share This Page