Solved How Do I Make Someone's XP Level Change Their Attack?

Discussion in 'Plugin Development' started by LegendaryStarX, Apr 25, 2014.

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

    LegendaryStarX

    For example, for every XP level someone gained, their attack would be raised by 0.1.
     
  2. Offline

    Glumpz

    LegendaryStarX On the event set the damage to the event.getDamage() + player.getLevel() / 10
     
  3. Offline

    LegendaryStarX

    Glumpz Thanks, do you have any example code for this?

    Can anyone help with this? I still need to figure out how to set a player's attack damage.

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 7, 2016
  4. Offline

    Wizehh

  5. Offline

    LegendaryStarX

    Thanks I think I figured it out, just have to test it now.

    Wizehh I spent some time fixing the add levels part of the plugin and when I finally tested it, the add levels works but the set damage doesn't. I have no idea what's wrong with it. I'm pretty new to this and just wanted to create something for fun. It doesn't show any errors. I've tested it on a pig. Would this work on players? Or does it not work at all? Either way what can I do to make it work on both mobs and players?

    Code:java
    1. package LegendaryStarX.PowerLevel;
    2.  
    3. import org.bukkit.Bukkit;
    4. import org.bukkit.entity.Player;
    5. import org.bukkit.event.EventHandler;
    6. import org.bukkit.plugin.java.JavaPlugin;
    7. import org.bukkit.scheduler.BukkitScheduler;
    8. import org.bukkit.event.entity.EntityDamageByEntityEvent;
    9.  
    10. public class Main extends JavaPlugin{
    11. Player player;
    12.  
    13. @Override
    14. public void onEnable(){
    15. BukkitScheduler scheduler = Bukkit.getServer().getScheduler();
    16. scheduler.scheduleSyncRepeatingTask(this, new Runnable() {
    17. @Override
    18. public void run() {
    19. for(Player player : Bukkit.getOnlinePlayers())
    20. player.giveExpLevels(1);
    21. }
    22. }, 0L, 200L);
    23. }
    24.  
    25. @Override
    26. public void onDisable(){
    27.  
    28. }
    29.  
    30. @EventHandler
    31. public void onEvent(EntityDamageByEntityEvent event){
    32. double attackDamage = event.getDamage()+player.getLevel()/1000;
    33. event.setDamage(attackDamage);
    34. }
    35. }
    36.  


    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 7, 2016
  6. Offline

    BillyGalbreath

    You didnt implement Listener
     
  7. Offline

    Gater12

    LegendaryStarX
    It would work for all entities (Hence EntityDamageByEntityEvent) and also you did not register your listeners or implement Listener interface.
     
  8. Offline

    LegendaryStarX

    BillyGalbreath I have added the implement Listener and it still does not work.
    Gater12 How would I register the listeners?
     
  9. Offline

    BillyGalbreath

    You dont have to register them since its the main class, afaik. Try doing some debug logs to see if its even firing.
     
  10. Offline

    LegendaryStarX

    I added getServer().getPluginManager().registerEvents(this, this); and now this shows up.
    Before when I hit a mob nothing showed up but whenever I hit a mob now this shows:

    Code:
    [00:47:42] [Server thread/ERROR]: Could not pass event EntityDamageByEntityEvent to PowerLevel v0.0.1
    org.bukkit.event.EventException
        at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:320) ~[craftbukkit.jar:git-Bukkit-1.7.2-R0.3-b3020jnks]
        at org.bukkit.plugin.RegisteredListener.callEvent(RegisteredListener.java:62) ~[craftbukkit.jar:git-Bukkit-1.7.2-R0.3-b3020jnks]
        at org.bukkit.plugin.SimplePluginManager.fireEvent(SimplePluginManager.java:486) [craftbukkit.jar:git-Bukkit-1.7.2-R0.3-b3020jnks]
        at org.bukkit.plugin.SimplePluginManager.callEvent(SimplePluginManager.java:471) [craftbukkit.jar:git-Bukkit-1.7.2-R0.3-b3020jnks]
        at org.bukkit.craftbukkit.v1_7_R1.event.CraftEventFactory.callEvent(CraftEventFactory.java:98) [craftbukkit.jar:git-Bukkit-1.7.2-R0.3-b3020jnks]
        at org.bukkit.craftbukkit.v1_7_R1.event.CraftEventFactory.callEntityDamageEvent(CraftEventFactory.java:386) [craftbukkit.jar:git-Bukkit-1.7.2-R0.3-b3020jnks]
        at org.bukkit.craftbukkit.v1_7_R1.event.CraftEventFactory.handleEntityDamageEvent(CraftEventFactory.java:414) [craftbukkit.jar:git-Bukkit-1.7.2-R0.3-b3020jnks]
        at net.minecraft.server.v1_7_R1.EntityLiving.damageEntity(EntityLiving.java:656) [craftbukkit.jar:git-Bukkit-1.7.2-R0.3-b3020jnks]
        at net.minecraft.server.v1_7_R1.EntityAnimal.damageEntity(SourceFile:145) [craftbukkit.jar:git-Bukkit-1.7.2-R0.3-b3020jnks]
        at net.minecraft.server.v1_7_R1.EntityHuman.attack(EntityHuman.java:918) [craftbukkit.jar:git-Bukkit-1.7.2-R0.3-b3020jnks]
        at net.minecraft.server.v1_7_R1.PlayerConnection.a(PlayerConnection.java:1102) [craftbukkit.jar:git-Bukkit-1.7.2-R0.3-b3020jnks]
        at net.minecraft.server.v1_7_R1.PacketPlayInUseEntity.a(SourceFile:55) [craftbukkit.jar:git-Bukkit-1.7.2-R0.3-b3020jnks]
        at net.minecraft.server.v1_7_R1.PacketPlayInUseEntity.handle(SourceFile:10) [craftbukkit.jar:git-Bukkit-1.7.2-R0.3-b3020jnks]
        at net.minecraft.server.v1_7_R1.NetworkManager.a(NetworkManager.java:146) [craftbukkit.jar:git-Bukkit-1.7.2-R0.3-b3020jnks]
        at net.minecraft.server.v1_7_R1.ServerConnection.c(SourceFile:134) [craftbukkit.jar:git-Bukkit-1.7.2-R0.3-b3020jnks]
        at net.minecraft.server.v1_7_R1.MinecraftServer.u(MinecraftServer.java:655) [craftbukkit.jar:git-Bukkit-1.7.2-R0.3-b3020jnks]
        at net.minecraft.server.v1_7_R1.DedicatedServer.u(DedicatedServer.java:250) [craftbukkit.jar:git-Bukkit-1.7.2-R0.3-b3020jnks]
        at net.minecraft.server.v1_7_R1.MinecraftServer.t(MinecraftServer.java:545) [craftbukkit.jar:git-Bukkit-1.7.2-R0.3-b3020jnks]
        at net.minecraft.server.v1_7_R1.MinecraftServer.run(MinecraftServer.java:457) [craftbukkit.jar:git-Bukkit-1.7.2-R0.3-b3020jnks]
        at net.minecraft.server.v1_7_R1.ThreadServerApplication.run(SourceFile:617) [craftbukkit.jar:git-Bukkit-1.7.2-R0.3-b3020jnks]
    Caused by: java.lang.NullPointerException
        at LegendaryStarX.PowerLevel.Main.onEvent(Main.java:34) ~[?:?]
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.7.0_25]
        at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) ~[?:1.7.0_25]
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) ~[?:1.7.0_25]
        at java.lang.reflect.Method.invoke(Unknown Source) ~[?:1.7.0_25]
    
     
  11. Offline

    BillyGalbreath

    Entity ent = event.getDamager();

    if (!(ent instanceof Player))
    return;

    double attackDamage = event.getDamage() + ((Player) ent).getLevel() / 1000;
     
  12. Offline

    Garris0n

    You can't just create a player variable in the class and magically have everything work. Please have at least a basic understanding of Java/programming in general before working with the Bukkit API.

    Also, that package name is in violation of the naming conventions in several different ways.
     
  13. Offline

    Deleted user

  14. Offline

    LegendaryStarX

    Thanks I figured everything out.
     
Thread Status:
Not open for further replies.

Share This Page