Solved 20% more damage on hit.

Discussion in 'Plugin Development' started by Asgernohns, Oct 16, 2013.

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

    Asgernohns

    Hello all java programmers! :)

    I need some help to get started with this project. The plugin is about, if you had been given a permission, you are able to get 20% more damage in a hit (it could be with a sword, hand, axe, etc.)
    I no how to do the permission part but i need help with finding the right eventhandlers.

    Hope that someone can help :D
     
  2. Offline

    MiniDigger

    Asgernohns I would do something like this:
    Code:
    @EventHandler
    public onEntityDamageByEntity(EntityDamageByEntityEvent e){
    if(e.getDamager() instanceof Player){
    e.setDamage(e.getDamage() + e.getDamage()/5);
    }
    }
    
     
  3. Offline

    Asgernohns

    I will try it out :)

    I don't now why this isn't working.. the permission looks like it doesn't have any effect on the damage :confused:

    Here is the code:
    Code:java
    1. import java.util.logging.Logger;
    2.  
    3. import org.bukkit.ChatColor;
    4. import org.bukkit.command.Command;
    5. import org.bukkit.command.CommandSender;
    6. import org.bukkit.entity.Player;
    7. import org.bukkit.event.EventHandler;
    8. import org.bukkit.event.entity.EntityDamageByEntityEvent;
    9. import org.bukkit.plugin.PluginDescriptionFile;
    10. import org.bukkit.plugin.java.JavaPlugin;
    11.  
    12. public class CD extends JavaPlugin {
    13.  
    14. public final Logger logger = Logger.getLogger("Minecraft");
    15. public static CD plugin;
    16.  
    17. public void onEnable(){
    18. PluginDescriptionFile pdfFile = this.getDescription();
    19. this.logger.info(pdfFile.getName()+" v"+pdfFile.getVersion()+" Has been enabled!");
    20. }
    21.  
    22. @EventHandler
    23. public void onEntityDamageByEntity(EntityDamageByEntityEvent e){
    24. if(e.getDamager() instanceof Player){
    25. Player p = (Player) e.getDamager();
    26. if(p.hasPermission("20on.on")){
    27. e.setDamage(e.getDamage() + e.getDamage()/5);
    28. }
    29. }
    30. }
    31. public boolean onCommand(CommandSender sender, Command cmd, String[] args){
    32. Player p = (Player) sender;
    33. if(cmd.getName().equalsIgnoreCase("20on")){
    34. p.sendMessage(ChatColor.AQUA+"20on v1.0");
    35. }
    36.  
    37. return false;
    38. }
    39. }
    40.  


    here is the plugin.yml:
    PHP:
    name20on
    main
    me.AsgerNohns.ConfigDamge.CD
    description
    A plugin that allows you to hit a bit harder
    version
    1.0
    author
    AsgerNohns
    commands
    :
      
    20on:
        
    descriptionTells you the version of the plugin
    permissions
    :
      
    20on.on:
        
    descriptionAllows you to hit a bit harder
    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 4, 2016
  4. Offline

    metalhedd

    Your class must implement org.bukkit.event.Listener, and in your onEnable, you need to register it as an EventListener.

    Code:java
    1.  
    2. getServer().getPluginManager().registerEvents(this, this);
    3.  
     
  5. Offline

    sgavster

    Asgernohns You need to register your events.
    onEnable:
    Code:java
    1. Bukkit.getPluginManager().registerEvents(this, this);

    Edit: Ninja'd :(
     
  6. Offline

    Asgernohns

    aarrhhh..... YES! i forgot that thing xD thanks metalhedd and sgavster

    But the permission still dont work :( if i add the permission or delete the permission nothing happens with the damage :(
    can someone help :)

    here is the code:
    Code:java
    1. import java.util.logging.Logger;
    2.  
    3.  
    4. import org.bukkit.entity.Player;
    5. import org.bukkit.event.EventHandler;
    6. import org.bukkit.event.Listener;
    7. import org.bukkit.event.entity.EntityDamageByEntityEvent;
    8. import org.bukkit.plugin.PluginDescriptionFile;
    9. import org.bukkit.plugin.java.JavaPlugin;
    10.  
    11. public class CD extends JavaPlugin implements Listener {
    12.  
    13. public final Logger logger = Logger.getLogger("Minecraft");
    14. public static CD plugin;
    15.  
    16. public void onEnable(){
    17. PluginDescriptionFile pdfFile = this.getDescription();
    18. this.logger.info(pdfFile.getName()+" v"+pdfFile.getVersion()+" Has been enabled!");
    19. getServer().getPluginManager().registerEvents(this, this);
    20. }
    21.  
    22. @EventHandler
    23. public void onEntityDamageByEntity(EntityDamageByEntityEvent e){
    24. if(e.getDamager() instanceof Player){
    25. Player p = (Player) e.getDamager();
    26. if(p.hasPermission("20on.on")){
    27. e.setDamage(e.getDamage() + e.getDamage()/5);
    28. }else{
    29. e.setDamage(e.getDamage());
    30. }
    31. }
    32. }
    33.  
    34. }


    And here is the plugin.yml:
    PHP:
    name20on
    main
    me.AsgerNohns.ConfigDamge.CD
    description
    A plugin that allows you to hit a bit harder
    version
    1.0
    author
    AsgerNohns
    commands
    :
      
    20on:
        
    descriptionTells you the version of the plugin
    permissions
    :
      
    20on.on:
        
    descriptionAllows you to hit a bit harder
    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 4, 2016
  7. Offline

    Doodledew



    You do use a permission plugin to actually add the permissions to a player ingame? :3
     
  8. Offline

    metalhedd

    Just because there is no difference in the damage values doesn't mean the permission isn't working. it could be a problem with integer division as well (ie. getDamage()/5 rounds to 0) You should add some debug logging to veryify,.
     
Thread Status:
Not open for further replies.

Share This Page