Solved Fireball

Discussion in 'Plugin Development' started by sonicwolfsdutch, Sep 14, 2014.

Thread Status:
Not open for further replies.
  1. so what i want is that the snowball that has the name Fireball in red it will put the player in fire oke i did that

    Code:java
    1. @SuppressWarnings("deprecation")
    2. @EventHandler
    3. public void onEntityDamage(EntityDamageByEntityEvent e) {
    4. if (e.getDamager() instanceof Snowball) {
    5. Snowball f = (Snowball) e.getDamager();
    6. if (f.getShooter() instanceof Player) {
    7. Player shooter = (Player) f.getShooter();
    8. if (shooter.getItemInHand().getType() == Material.SNOW_BALL) {
    9. if(shooter.getPlayer().getItemInHand().getItemMeta().getDisplayName().equalsIgnoreCase(ChatColor.RED + "Fireball"))
    10. e.getEntity().setFireTicks(60);
    11. }
    12. }
    13. }
    14. }




    but if its a normal snowball i get a big console crash
    Code:
    [14:32:36] [Server thread/ERROR]: Could not pass event EntityDamageByEntityEvent to fireballtest
    org.bukkit.event.EventException
    at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:302) ~[spigot.jar:git-Spigot-1.7.9-R0.2-205-g6a8d903]
    at org.bukkit.plugin.RegisteredListener.callEvent(RegisteredListener.java:62) ~[spigot.jar:git-Spigot-1.7.9-R0.2-205-g6a8d903]
    at org.bukkit.plugin.SimplePluginManager.fireEvent(SimplePluginManager.java:509) [spigot.jar:git-Spigot-1.7.9-R0.2-205-g6a8d903]
    at org.bukkit.plugin.SimplePluginManager.callEvent(SimplePluginManager.java:494) [spigot.jar:git-Spigot-1.7.9-R0.2-205-g6a8d903]
    at org.bukkit.craftbukkit.v1_7_R4.event.CraftEventFactory.callEvent(CraftEventFactory.java:108) [spigot.jar:git-Spigot-1.7.9-R0.2-205-g6a8d903]
    at org.bukkit.craftbukkit.v1_7_R4.event.CraftEventFactory.callEntityDamageEvent(CraftEventFactory.java:554) [spigot.jar:git-Spigot-1.7.9-R0.2-205-g6a8d903]
    at org.bukkit.craftbukkit.v1_7_R4.event.CraftEventFactory.handleEntityDamageEvent(CraftEventFactory.java:467) [spigot.jar:git-Spigot-1.7.9-R0.2-205-g6a8d903]
    at org.bukkit.craftbukkit.v1_7_R4.event.CraftEventFactory.handleLivingEntityDamageEvent(CraftEventFactory.java:586) [spigot.jar:git-Spigot-1.7.9-R0.2-205-g6a8d903]
    at net.minecraft.server.v1_7_R4.EntityLiving.d(EntityLiving.java:1040) [spigot.jar:git-Spigot-1.7.9-R0.2-205-g6a8d903]
    at net.minecraft.server.v1_7_R4.EntityLiving.damageEntity(EntityLiving.java:684) [spigot.jar:git-Spigot-1.7.9-R0.2-205-g6a8d903]
    at net.minecraft.server.v1_7_R4.EntityAnimal.damageEntity(SourceFile:145) [spigot.jar:git-Spigot-1.7.9-R0.2-205-g6a8d903]
    at net.minecraft.server.v1_7_R4.EntitySnowball.a(SourceFile:30) [spigot.jar:git-Spigot-1.7.9-R0.2-205-g6a8d903]
    at net.minecraft.server.v1_7_R4.EntityProjectile.h(EntityProjectile.java:155) [spigot.jar:git-Spigot-1.7.9-R0.2-205-g6a8d903]
    at net.minecraft.server.v1_7_R4.World.entityJoinedWorld(World.java:1620) [spigot.jar:git-Spigot-1.7.9-R0.2-205-g6a8d903]
    at net.minecraft.server.v1_7_R4.World.playerJoinedWorld(World.java:1595) [spigot.jar:git-Spigot-1.7.9-R0.2-205-g6a8d903]
    at net.minecraft.server.v1_7_R4.World.tickEntities(World.java:1460) [spigot.jar:git-Spigot-1.7.9-R0.2-205-g6a8d903]
    at net.minecraft.server.v1_7_R4.WorldServer.tickEntities(WorldServer.java:516) [spigot.jar:git-Spigot-1.7.9-R0.2-205-g6a8d903]
    at net.minecraft.server.v1_7_R4.MinecraftServer.v(MinecraftServer.java:706) [spigot.jar:git-Spigot-1.7.9-R0.2-205-g6a8d903]
    at net.minecraft.server.v1_7_R4.DedicatedServer.v(DedicatedServer.java:289) [spigot.jar:git-Spigot-1.7.9-R0.2-205-g6a8d903]
    at net.minecraft.server.v1_7_R4.MinecraftServer.u(MinecraftServer.java:584) [spigot.jar:git-Spigot-1.7.9-R0.2-205-g6a8d903]
    at net.minecraft.server.v1_7_R4.MinecraftServer.run(MinecraftServer.java:490) [spigot.jar:git-Spigot-1.7.9-R0.2-205-g6a8d903]
    at net.minecraft.server.v1_7_R4.ThreadServerApplication.run(SourceFile:628) [spigot.jar:git-Spigot-1.7.9-R0.2-205-g6a8d903]
    Caused by: java.lang.NullPointerException
    at me.sonicwolfsdutch.apple.Main.onEntityDamage(Main.java:95) ~[?:?]
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.8.0_20]
    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) ~[?:1.8.0_20]
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) ~[?:1.8.0_20]
    at java.lang.reflect.Method.invoke(Unknown Source) ~[?:1.8.0_20]
    at org.bukkit.plugin.java.JaPluginLoader$1.execute(JavaPluginLoader.java:298) ~[spigot.jar:git-Spigot-1.7.9-R0.2-205-g6a8d903]
     
    ... 21 more
    
    it says at me.sonicwolfsdutch.apple.Main.onEntityDamage(Main.java:95) ~[?:?]
    and that line is

    Code:java
    1. if(shooter.getPlayer().getItemInHand().getItemMeta().getDisplayName().equalsIgnoreCase(ChatColor.RED + "Fireball"))
    2. e.getEntity().setFireTicks(60);



    how can i fix this? im trying like 4h now
     
  2. Offline

    4thegame3

    Because when you launch a snowball you no longer have it on hands..
     
  3. Offline

    Jimfutsu

    Use some checks before you check that, because not every snowball has item meta, and if it dosnt then that line cannot be initiated. Just simply do if(p.getItemInHand.hasItemMeta){ or something like that
     
  4. well it is only for if the snowball is called Snowball u get the error if its called (ChatColor.RED+"Fireball") than u dont get the error
     
  5. Offline

    Bobit

    sonicwolfsdutch
    Normal snowballs don't have item meta, according to Jimfutsu.

    Also, your logic isn't what you want.

    You're saying "If a snowball hits the enemy and the shooter of the snowball is holding a snowball called 'fireball' set the enemy on fire."

    What you want to say is "If a snowball called 'fireball' hits the enemy, set them on fire."
     

  6. yep
     
  7. Offline

    Bobit

    sonicwolfsdutch

    Um...okay...good to know you get it. Now go do that. I gtg.
     
    sonicwolfsdutch likes this.
  8. ohh look at that found something else to its doing it if i have in my inventory if i don't have it in my inventory it doesnt work god darn it
     
  9. Offline

    4thegame3

    use this and check if the snowball is the same
     
  10. the amount of magic bukkit has pfff
     
  11. Offline

    4thegame3

    eh? :eek:
     
  12. Offline

    4thegame3

    @sonicwolfsdutch Its easy, how do you suppose to get if the snoball had a colored name if the event is after launching it?​
     
  13. using this my friend

    Code:java
    1. private void fireball() {
    2. ItemStack helmet = new ItemStack(Material.SNOW_BALL);
    3. ItemMeta meta = helmet.getItemMeta();
    4. meta.setDisplayName(ChatColor.RED + "Fireball");
    5. meta.setLore(Arrays.asList(ChatColor.GRAY + "this snow ball puts the player on fire for 3 seconds"));
    6. helmet.setItemMeta(meta);
    7.  
    8. ShapedRecipe hrecipe = new ShapedRecipe(helmet);
    9. hrecipe.shape(
    10. "OOO",
    11. "OOO");
    12. hrecipe.setIngredient('@', Material.SNOW_BALL);
    13. hrecipe.setIngredient('O', Material.BLAZE_POWDER);
    14. Bukkit.getServer().addRecipe(hrecipe);
    15. }
     
  14. Offline

    4thegame3

    so? a launched snowball is a entity
     
  15. yes
     
  16. Offline

    ChipDev

    sonicwolfsdutch
    your original code must have 1+ snowballs named "Fireball" in their hands.
     
  17. yep i just found that out :/
     
  18. Offline

    ChipDev

    K, So exactly what do you want?
     
  19. Offline

    4thegame3

    @ChipDevhe needs to check if the original itemstack of a launched projectile is a fireball named Fireball
     
  20. a snowball called Fireball that's done
    if it hits the player it does a ping sound like if u hit some one whit the bow
    an puts the guy on fire for 3 seconds
     
  21. Offline

    Bobit

    When a snowball hits an entity
    IF that snowball has meta and
    IF that snowball has the display name "fireball" then set the target on fire.

    The second line of that is so that you don't get a null exception because you check for an item meta's display name when the item meta is nothing.
    We're probably not going to tell you exactly what the code is for this because you need to learn how to read API if you're going to code anything else.
     
  22. Offline

    Jimfutsu

    Bobit
    There is no need to put the itemmeta, as the snowbal cointains the same itemmeta when launched/in inventory.
    The 2nd step is correct though.
     
  23. Offline

    Bobit

    Jimfutsu

    Display name is item meta? Cool. I never understood item meta.
     
  24. sonicwolfsdutch i tried arround and searched for some ways and found one! this are the steps i did:
    1. listen to ProjectileLaunchEvent
    2. check if the Projectile is a snowball and check if the ProjectileSource (shooter) is a Player
    3. get the ItemStack in the hand of the Player
    4. check if the ItemMeta of the stack != null
    5. set new metadata for the Snowball (snowball.setMetaData(see 5.1, see 5.2))
    5.1 The first parameter is the key which you can choose free. i used "SnowballDisplayName"
    5.2 The second parameter is the value you want to set. use "new FixedMetadataValue(YOURPLUGIN, ItemMetaOfStackInHand.getDisplayName())"
    6. listen to EntityDamageByEntityEvent
    7. check if the damagerentity is a Snowball
    8. check if snowball.getMetadata(see 5.1 (i used "SnowballDisplayName")).size()==1
    9. get the entry with index 0 and use the "asString()" method of it. That's the name of your snowball
    10. check if the name of the snowball is equal to your spezialname, in your case 'ChatColor.Red+"FireBall"'
    11. set fireticks of target

    i hope i could help :) i also got a codeexample, but i'll only show you after you tried it on your own and showed me your code :p
     
  25. what do u mean Third party builds are not supported here? this is a Plugin that's getting Developt im getting error im asking here for a fix


    ima look in to it wish me luck!
     
  26. just for u
    Code:
    [20:16:58] [Server thread/INFO]: This server is running CraftBukkit version git-Bukkit-1.7.9-R0.2-24-g07d4558-b3116jnks (MC: 1.7.10) (Implementing API version 1.7.10-R0.1-SNAPSHOT)
    [20:17:06] [Server thread/INFO]: sonicwolfsdutch has just earned the achievement [Taking Inventory]
    [20:17:47] [Server thread/ERROR]: Could not pass event EntityDamageByEntityEvent to fireballtest
    org.bukkit.event.EventException
        at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:294) ~[craftbukkit_dev.jar:git-Bukkit-1.7.9-R0.2-24-g07d4558-b3116jnks]
        at org.bukkit.plugin.RegisteredListener.callEvent(RegisteredListener.java:62) ~[craftbukkit_dev.jar:git-Bukkit-1.7.9-R0.2-24-g07d4558-b3116jnks]
        at org.bukkit.plugin.SimplePluginManager.fireEvent(SimplePluginManager.java:501) [craftbukkit_dev.jar:git-Bukkit-1.7.9-R0.2-24-g07d4558-b3116jnks]
        at org.bukkit.plugin.SimplePluginManager.callEvent(SimplePluginManager.java:486) [craftbukkit_dev.jar:git-Bukkit-1.7.9-R0.2-24-g07d4558-b3116jnks]
        at org.bukkit.craftbukkit.v1_7_R4.event.CraftEventFactory.callEvent(CraftEventFactory.java:107) [craftbukkit_dev.jar:git-Bukkit-1.7.9-R0.2-24-g07d4558-b3116jnks]
        at org.bukkit.craftbukkit.v1_7_R4.event.CraftEventFactory.callEntityDamageEvent(CraftEventFactory.java:537) [craftbukkit_dev.jar:git-Bukkit-1.7.9-R0.2-24-g07d4558-b3116jnks]
        at org.bukkit.craftbukkit.v1_7_R4.event.CraftEventFactory.handleEntityDamageEvent(CraftEventFactory.java:450) [craftbukkit_dev.jar:git-Bukkit-1.7.9-R0.2-24-g07d4558-b3116jnks]
        at org.bukkit.craftbukkit.v1_7_R4.event.CraftEventFactory.handleLivingEntityDamageEvent(CraftEventFactory.java:569) [craftbukkit_dev.jar:git-Bukkit-1.7.9-R0.2-24-g07d4558-b3116jnks]
        at net.minecraft.server.v1_7_R4.EntityLiving.d(EntityLiving.java:1031) [craftbukkit_dev.jar:git-Bukkit-1.7.9-R0.2-24-g07d4558-b3116jnks]
        at net.minecraft.server.v1_7_R4.EntityLiving.damageEntity(EntityLiving.java:675) [craftbukkit_dev.jar:git-Bukkit-1.7.9-R0.2-24-g07d4558-b3116jnks]
        at net.minecraft.server.v1_7_R4.EntityAnimal.damageEntity(SourceFile:145) [craftbukkit_dev.jar:git-Bukkit-1.7.9-R0.2-24-g07d4558-b3116jnks]
        at net.minecraft.server.v1_7_R4.EntitySnowball.a(SourceFile:30) [craftbukkit_dev.jar:git-Bukkit-1.7.9-R0.2-24-g07d4558-b3116jnks]
        at net.minecraft.server.v1_7_R4.EntityProjectile.h(EntityProjectile.java:155) [craftbukkit_dev.jar:git-Bukkit-1.7.9-R0.2-24-g07d4558-b3116jnks]
        at net.minecraft.server.v1_7_R4.World.entityJoinedWorld(World.java:1418) [craftbukkit_dev.jar:git-Bukkit-1.7.9-R0.2-24-g07d4558-b3116jnks]
        at net.minecraft.server.v1_7_R4.World.playerJoinedWorld(World.java:1396) [craftbukkit_dev.jar:git-Bukkit-1.7.9-R0.2-24-g07d4558-b3116jnks]
        at net.minecraft.server.v1_7_R4.World.tickEntities(World.java:1281) [craftbukkit_dev.jar:git-Bukkit-1.7.9-R0.2-24-g07d4558-b3116jnks]
        at net.minecraft.server.v1_7_R4.WorldServer.tickEntities(WorldServer.java:481) [craftbukkit_dev.jar:git-Bukkit-1.7.9-R0.2-24-g07d4558-b3116jnks]
        at net.minecraft.server.v1_7_R4.MinecraftServer.v(MinecraftServer.java:649) [craftbukkit_dev.jar:git-Bukkit-1.7.9-R0.2-24-g07d4558-b3116jnks]
        at net.minecraft.server.v1_7_R4.DedicatedServer.v(DedicatedServer.java:258) [craftbukkit_dev.jar:git-Bukkit-1.7.9-R0.2-24-g07d4558-b3116jnks]
        at net.minecraft.server.v1_7_R4.MinecraftServer.u(MinecraftServer.java:558) [craftbukkit_dev.jar:git-Bukkit-1.7.9-R0.2-24-g07d4558-b3116jnks]
        at net.minecraft.server.v1_7_R4.MinecraftServer.run(MinecraftServer.java:469) [craftbukkit_dev.jar:git-Bukkit-1.7.9-R0.2-24-g07d4558-b3116jnks]
        at net.minecraft.server.v1_7_R4.ThreadServerApplication.run(SourceFile:628) [craftbukkit_dev.jar:git-Bukkit-1.7.9-R0.2-24-g07d4558-b3116jnks]
    Caused by: java.lang.NullPointerException
        at me.sonicwolfsdutch.apple.Main.onEntityDamage(Main.java:95) ~[?:?]
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.8.0_20]
        at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) ~[?:1.8.0_20]
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) ~[?:1.8.0_20]
        at java.lang.reflect.Method.invoke(Unknown Source) ~[?:1.8.0_20]
        at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:292) ~[craftbukkit_dev.jar:git-Bukkit-1.7.9-R0.2-24-g07d4558-b3116jnks]
        ... 21 more
     
    Bobit likes this.
Thread Status:
Not open for further replies.

Share This Page