Snowball damage

Discussion in 'Plugin Development' started by Wantsome909, Jun 8, 2013.

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

    Wantsome909

    how can i make it so two weapons have differnet damage's with a snowball?
     
  2. Offline

    JackProehl

    If you mean you're trying to detect when a snowball does damage simply create a listener for the EntityDamageByEntity event and check to see if the event damager is instanceof Snowball. Hope that helps.
     
  3. Offline

    Wantsome909

    im trying to say that i have two weapons and i want them to do different damages
     
  4. Offline

    Drkmaster83

    So, you're trying to make two snowballs have different damages?
     
  5. Offline

    Bancey

    well you can set the damage but I'm not sure how you are planning to differentiate between the two snowballs.

    Code:java
    1. event.setDamage(<amount of damage>);
     
  6. Offline

    JackProehl

    Well, he could check to see if the shooter has a certain permission, or come up with a system to check the name of the snowball before it is thrown.
     
  7. Offline

    Hedgehogs4Me

    I'd normally say to have two different lores on one item type to make it do two different things, but in the case of a snowball, that might be a bit harder. You might have to write your own snowball class if you really want to do that.

    Or, you could say that if they right click with a snowball that has a certain lore, it fires a fire charge or an egg, then check for damage caused by those.
     
  8. Offline

    Wantsome909

    no i mean i have to guns a sniper and a pistol the sniper well take 5 hearts and the pistol well take 1 heart but the EventHandler make ever snowball deal 5 damage!
     
  9. Offline

    TheJugger

    Retrieve the shooter, then check the item he had in his hands when he shot.
     
  10. Offline

    wuiyang

    you can try to code that when /somecommandhere join, then it give you a stick and named "Pistol", "Sniper", and snowball for "Pistol Bullet" and empty bottle for "Sniper Bullet", next create customList.yml , where you store the name of the player, then code when you right click with the stick, it fire the snowball or bottle, after that code the damage, cause you are now in the area, and there will be no other people can join when there is a fight, you can simply code the damage with the event.setDamage(<amount of damage>); , but you must set WHEN THEY JOINED, they get the damage, i will post the code when i was free
     
  11. Offline

    Bancey

    TheJugger Yes but he is trying to differentiate between two different snowballs.
     
  12. Offline

    JoTyler

    im also trying to do this but i can't figure out how to call the player in the EntityDamageByEntityEvent

    My code that doesn't work.

    Code:
        @EventHandler
        public void GunBulletD(EntityDamageByEntityEvent event){
         
         
            Player player = (Player) event.getDamager();
            ItemStack hand = player.getItemInHand();
            if(event.getCause().equals(Snowball.class)){
             
                ItemStack brod = new ItemStack(Material.BLAZE_ROD, 1);
                ItemMeta sMeta = brod.getItemMeta();
                sMeta.setDisplayName("Gun");
                brod.setItemMeta(sMeta);
         
                if(hand.getItemMeta().equals(sMeta)){
                event.setDamage(100);
             
             
             
            }else{
                return;
            }
         
         
        }else{
            return;
        }
     
     
        }



    the error

    Code:
    14:05:01 [SEVERE] Could not pass event EntityDamageByEntityEvent to HiddenPluginName v1.0
    org.bukkit.event.EventException
        at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:427)
        at org.bukkit.plugin.RegisteredListener.callEvent(RegisteredListener.java:62)
        at org.bukkit.plugin.SimplePluginManager.fireEvent(SimplePluginManager.java:477)
        at org.bukkit.plugin.SimplePluginManager.callEvent(SimplePluginManager.java:462)
        at org.bukkit.craftbukkit.v1_5_R3.event.CraftEventFactory.callEvent(CraftEventFactory.java:89)
        at org.bukkit.craftbukkit.v1_5_R3.event.CraftEventFactory.callEntityDamageEvent(CraftEventFactory.java:377)
        at org.bukkit.craftbukkit.v1_5_R3.event.CraftEventFactory.handleEntityDamageEvent(CraftEventFactory.java:402)
        at net.minecraft.server.v1_5_R3.EntityLiving.damageEntity(EntityLiving.java:677)
        at net.minecraft.server.v1_5_R3.EntityAnimal.damageEntity(SourceFile:119)
        at net.minecraft.server.v1_5_R3.EntitySnowball.a(SourceFile:30)
        at net.minecraft.server.v1_5_R3.EntityProjectile.l_(EntityProjectile.java:156)
        at net.minecraft.server.v1_5_R3.World.entityJoinedWorld(World.java:1355)
        at net.minecraft.server.v1_5_R3.WorldServer.entityJoinedWorld(WorldServer.java:614)
        at net.minecraft.server.v1_5_R3.World.playerJoinedWorld(World.java:1336)
        at net.minecraft.server.v1_5_R3.World.tickEntities(World.java:1224)
        at net.minecraft.server.v1_5_R3.WorldServer.tickEntities(WorldServer.java:480)
        at net.minecraft.server.v1_5_R3.MinecraftServer.r(MinecraftServer.java:563)
        at net.minecraft.server.v1_5_R3.DedicatedServer.r(DedicatedServer.java:226)
        at net.minecraft.server.v1_5_R3.MinecraftServer.q(MinecraftServer.java:477)
        at net.minecraft.server.v1_5_R3.MinecraftServer.run(MinecraftServer.java:410)
        at net.minecraft.server.v1_5_R3.ThreadServerApplication.run(SourceFile:573)
    Caused by: java.lang.ClassCastException: org.bukkit.craftbukkit.v1_5_R3.entity.CraftSnowball cannot be cast to org.bukkit.entity.Player
        at me.JoTyler.HiddenPluginName.Weapons.GunBulletD(Weapons.java:60)
        at sun.reflect.GeneratedMethodAccessor2.invoke(Unknown Source)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
        at java.lang.reflect.Method.invoke(Method.java:597)
        at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:425)
        ... 20 more
    14:05:01 [SEVERE] Could not pass event EntityDamageByEntityEvent to HiddenPluginName v1.0
    org.bukkit.event.EventException
        at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:427)
        at org.bukkit.plugin.RegisteredListener.callEvent(RegisteredListener.java:62)
        at org.bukkit.plugin.SimplePluginManager.fireEvent(SimplePluginManager.java:477)
        at org.bukkit.plugin.SimplePluginManager.callEvent(SimplePluginManager.java:462)
        at org.bukkit.craftbukkit.v1_5_R3.event.CraftEventFactory.callEvent(CraftEventFactory.java:89)
        at org.bukkit.craftbukkit.v1_5_R3.event.CraftEventFactory.callEntityDamageEvent(CraftEventFactory.java:377)
        at org.bukkit.craftbukkit.v1_5_R3.event.CraftEventFactory.handleEntityDamageEvent(CraftEventFactory.java:402)
        at net.minecraft.server.v1_5_R3.EntityLiving.damageEntity(EntityLiving.java:677)
        at net.minecraft.server.v1_5_R3.EntityAnimal.damageEntity(SourceFile:119)
        at net.minecraft.server.v1_5_R3.EntitySnowball.a(SourceFile:30)
        at net.minecraft.server.v1_5_R3.EntityProjectile.l_(EntityProjectile.java:156)
        at net.minecraft.server.v1_5_R3.World.entityJoinedWorld(World.java:1355)
        at net.minecraft.server.v1_5_R3.WorldServer.entityJoinedWorld(WorldServer.java:614)
        at net.minecraft.server.v1_5_R3.World.playerJoinedWorld(World.java:1336)
        at net.minecraft.server.v1_5_R3.World.tickEntities(World.java:1224)
        at net.minecraft.server.v1_5_R3.WorldServer.tickEntities(WorldServer.java:480)
        at net.minecraft.server.v1_5_R3.MinecraftServer.r(MinecraftServer.java:563)
        at net.minecraft.server.v1_5_R3.DedicatedServer.r(DedicatedServer.java:226)
        at net.minecraft.server.v1_5_R3.MinecraftServer.q(MinecraftServer.java:477)
        at net.minecraft.server.v1_5_R3.MinecraftServer.run(MinecraftServer.java:410)
        at net.minecraft.server.v1_5_R3.ThreadServerApplication.run(SourceFile:573)
    Caused by: java.lang.ClassCastException: org.bukkit.craftbukkit.v1_5_R3.entity.CraftSnowball cannot be cast to org.bukkit.entity.Player
        at me.JoTyler.HiddenPluginName.Weapons.GunBulletD(Weapons.java:60)
        at sun.reflect.GeneratedMethodAccessor2.invoke(Unknown Source)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
        at java.lang.reflect.Method.invoke(Method.java:597)
        at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:425)
        ... 20 more
    
    This is line 60 ..
    Code:
            Player player = (Player) event.getDamager();
    
     
  13. Offline

    Shinxs

    i've got this and it worked but don't just copy it!!
    Code:
    @EventHandler
      public void onEntityDamageByEntity(EntityDamageByEntityEvent e) {
        if (e.getDamager().getType() == EntityType.EGG) {
          if(e.getEntity() instanceof Player) {
          Player p = (Player) e.getEntity();
          Egg egg = (Egg) e.getDamager();
          Player pl = (Player) egg.getShooter();
          String name = pl.getItemInHand().getItemMeta().getDisplayName();
          if(name != null) {
            if(name.equalsIgnoreCase("P30")) {
                  p.damage(4);
            }
            else if(name.equalsIgnoreCase("SW1911")) {
                  p.damage(5);
            }
           else if(name.equalsIgnoreCase("AA-12")) {
                  p.damage(7);
            } else {
                   p.damage(0);
            }
          }
         }
      }
    and this is with eggs but i know you can figure out how to do it with snowballs
     
Thread Status:
Not open for further replies.

Share This Page