AddPotionEffect not working

Discussion in 'Plugin Development' started by Smitty, Apr 1, 2016.

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

    Smitty

    Hey everyone,

    for some reason the addPotionEffect doesn't work. (Using spigot 1.9)

    Heres my code:
    https://codeshare.io/16nSv

    Error I'm getting:
    ... 26 more at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:306) ~[spigot.jar:git-Spigot-1a196e1-6f032cd] at java.lang.reflect.Method.invoke(Unknown Source) ~[?:1.8.0_73] at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) ~[?:1.8.0_73] at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) ~[?:1.8.0_73] at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.8.0_73] at me.dansmith.com.Main.lifeSteal(Main.java:46) ~[?:?]Caused by: java.lang.NullPointerException at java.lang.Thread.run(Unknown Source) [?:1.8.0_73] at net.minecraft.server.v1_9_R1.MinecraftServer.run(MinecraftServer.java:559) [spigot.jar:git-Spigot-1a196e1-6f032cd] at net.minecraft.server.v1_9_R1.MinecraftServer.C(MinecraftServer.java:660) [spigot.jar:git-Spigot-1a196e1-6f032cd] at net.minecraft.server.v1_9_R1.DedicatedServer.D(DedicatedServer.java:400) [spigot.jar:git-Spigot-1a196e1-6f032cd] at net.minecraft.server.v1_9_R1.MinecraftServer.D(MinecraftServer.java:721) [spigot.jar:git-Spigot-1a196e1-6f032cd] at net.minecraft.server.v1_9_R1.SystemUtils.a(SourceFile:45) [spigot.jar:git-Spigot-1a196e1-6f032cd] at java.util.concurrent.FutureTask.run(Unknown Source) [?:1.8.0_73] at java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source) [?:1.8.0_73] at net.minecraft.server.v1_9_R1.PlayerConnectionUtils$1.run(SourceFile:13) [spigot.jar:git-Spigot-1a196e1-6f032cd] at net.minecraft.server.v1_9_R1.PacketPlayInUseEntity.a(SourceFile:12) [spigot.jar:git-Spigot-1a196e1-6f032cd] at net.minecraft.server.v1_9_R1.PacketPlayInUseEntity.a(SourceFile:68) [spigot.jar:git-Spigot-1a196e1-6f032cd] at net.minecraft.server.v1_9_R1.PlayerConnection.a(PlayerConnection.java:1529) [spigot.jar:git-Spigot-1a196e1-6f032cd] at net.minecraft.server.v1_9_R1.EntityPlayer.attack(EntityPlayer.java:1141) [spigot.jar:git-Spigot-1a196e1-6f032cd] at net.minecraft.server.v1_9_R1.EntityHuman.attack(EntityHuman.java:999) [spigot.jar:git-Spigot-1a196e1-6f032cd] at net.minecraft.server.v1_9_R1.EntityPlayer.damageEntity(EntityPlayer.java:513) [spigot.jar:git-Spigot-1a196e1-6f032cd] at net.minecraft.server.v1_9_R1.EntityHuman.damageEntity(EntityHuman.java:762) [spigot.jar:git-Spigot-1a196e1-6f032cd] at net.minecraft.server.v1_9_R1.EntityLiving.damageEntity(EntityLiving.java:814) [spigot.jar:git-Spigot-1a196e1-6f032cd] at net.minecraft.server.v1_9_R1.EntityHuman.damageEntity0(EntityHuman.java:838) [spigot.jar:git-Spigot-1a196e1-6f032cd] at net.minecraft.server.v1_9_R1.EntityLiving.damageEntity0(EntityLiving.java:1206) [spigot.jar:git-Spigot-1a196e1-6f032cd] at org.bukkit.craftbukkit.v1_9_R1.event.CraftEventFactory.handleLivingEntityDamageEvent(CraftEventFactory.java:588) [spigot.jar:git-Spigot-1a196e1-6f032cd] at org.bukkit.craftbukkit.v1_9_R1.event.CraftEventFactory.handleEntityDamageEvent(CraftEventFactory.java:465) [spigot.jar:git-Spigot-1a196e1-6f032cd] at org.bukkit.craftbukkit.v1_9_R1.event.CraftEventFactory.callEntityDamageEvent(CraftEventFactory.java:556) [spigot.jar:git-Spigot-1a196e1-6f032cd] at org.bukkit.craftbukkit.v1_9_R1.event.CraftEventFactory.callEvent(CraftEventFactory.java:87) [spigot.jar:git-Spigot-1a196e1-6f032cd] at org.bukkit.plugin.SimplePluginManager.callEvent(SimplePluginManager.java:487) [spigot.jar:git-Spigot-1a196e1-6f032cd] at org.bukkit.plugin.SimplePluginManager.fireEvent(SimplePluginManager.java:502) [spigot.jar:git-Spigot-1a196e1-6f032cd] at org.bukkit.plugin.RegisteredListener.callEvent(RegisteredListener.java:62) ~[spigot.jar:git-Spigot-1a196e1-6f032cd] at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:310) ~[spigot.jar:git-Spigot-1a196e1-6f032cd]org.bukkit.event.EventExceptionCould not pass event EntityDamageByEntityEvent to CustomEnchants v1.0


    If Someone could please help, it would be appreciated.
     
  2. Offline

    Zombie_Striker

  3. Offline

    Smitty

  4. Offline

    Dynamus

    public void dizzy(EntityDamageByEntityEvent e) {
    Player p = (Player) e.getEntity();


    How do you know if the entity is actually a Player?
    Don't blind cast, check if the entity is a player before casting
     
  5. Offline

    Smitty

  6. Offline

    Dynamus


    If(Entity(From the event) instaceof Player)...
     
  7. By learning Java. ¯\_(ツ)_/¯

    Sorry to break it to you, but it's a bit obvious you don't know much about Java.
    Please, please, please, learn Java before trying to code with the Bukkit API. Chances are you probably just looked up a tutorial on YouTube. This is one of the worst ways to do it because it could teach bad habits, or just give you misleading information. The main reason we keep telling this to users is not because we're a bunch of mini-mods getting after users because we feel like it, but because if you aren't knowledgable of at least the basics of Java, problems that would be easy to solve for a person that knew Java, would stump a user that had no Java knowledge. Here's a link that could help a bit: http://docs.oracle.com/javase/tutorial/
     
  8. Offline

    Smitty

    @CodePlaysMinecraft Please don't make assumptions like this, I do know java, just a beginner.
     
  9. @Smitty I'm just assuming because there's an easy solution to your problem. Anyway, did you understand what was said in @Dynamus' post or is there a problem? If so, please post updated code.
     
  10. Offline

    Smitty

    @CodePlaysMinecraft
    Please take into consideration, I know the basics of java code, and expanding my knowledge. And to answer your question, no. When i put if(Entity instanceof Player) { Entity is underlined in red

    EDIT: Got the if statement figured out: if(e.getEntity() instanceof Player) {

    but now, the addPotionEffect still doesn't work.

    Updated code share in thread
     
    Last edited by a moderator: Apr 2, 2016
  11. Offline

    Dynamus

    @Smitty
    Of course is underlined red, do you really did this way? if(Entity instaceof Player)?
    That was a example. You need to specify what entity, in this case check if the entity that is receiving damage is a instance of a player. Sorry for my bad english. I'm always trying to learn. :p

    https://hub.spigotmc.org/javadocs/spigot/org/bukkit/event/entity/EntityDamageByEntityEvent.html
     
    Last edited: Apr 1, 2016
  12. Offline

    mcdorli

    You shouldn't learn java while learning bukkit, and you need at least intermediate java to handle bukkit.

    Because you don't know, how to check, if an object extends something, then sorry, but you don't even know the basics.
     
Thread Status:
Not open for further replies.

Share This Page