Solved Fireball

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

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

    fireblast709

    sonicwolfsdutch you will still be using a 3rd party build after this. Quick switching is just a cheap shot to avoid the rules.
     
  2. still finding out i have school stuff also so this is not my #1 problem dho
     
  3. Offline

    mrgreen33gamer

    I would suggest using this event: ProjectileLaunchEvent
     
  4. mrgreen33gamer look at this step-by-step list
     
  5. Shmobi
    im doing something wrong there

    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())"

    oke untill here i came it to do but im stuck on 7

    Code:java
    1. @SuppressWarnings("deprecation")
    2. @EventHandler
    3. public void onEntitytrow(ProjectileLaunchEvent e) {
    4. if (e.getEntity() instanceof Snowball) {
    5. Snowball f = (Snowball) e.getEntity();
    6. if (f.getShooter() instanceof Player) {
    7. Player shooter = (Player) f.getShooter();
    8. if (shooter.getItemInHand().getItemMeta() != null)
    9. f.setMetadata("Snowball", new FixedMetadataValue(null, (ChatColor.RED + "Fireball")));
    10. if (shooter.getItemInHand().getType() == Material.SNOW_BALL) {
    11. if(shooter.getPlayer().getItemInHand().getItemMeta().getDisplayName().equalsIgnoreCase(ChatColor.RED + "Fireball"))
    12. e.getEntity().setFireTicks(60);
    13. }
    14. }
    15. }
    16. }
    17.  
    18. @SuppressWarnings("deprecation")
    19. @EventHandler
    20. public void trowing(EntityDamageByEntityEvent e) {
    21. if (e.getDamager() instanceof Snowball) {
    22. Snowball f = (Snowball) e.getDamager();
    23. if (f.getShooter() instanceof Player) {
    24. Player shooter = (Player) f.getShooter();
    25. e.getMetadata(null, (ChatColor.RED + "Fireball")).size()==1)
    26. e.getEntity().setFireTicks(60);
    27. }
    28. }
    29. }


    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 14, 2016
  6. Sorry for the spoonfeed everybody, but i'm tired of explaining
    sonicwolfsdutch
    Code:java
    1. @EventHandler
    2. public void onSnowballWillBeLaunched(final ProjectileLaunchEvent ple) {
    3. Projectile projectile = ple.getEntity();
    4. ProjectileSource source = projectile.getShooter();
    5. if (projectile instanceof Snowball && source instanceof Player) {
    6. Snowball snowball = (Snowball) projectile;
    7. Player shooter = (Player) source;
    8. ItemStack stackInHand = shooter.getItemInHand();
    9. if (stackInHand != null && stackInHand.getType() == Material.SNOW_BALL) {
    10. ItemMeta metaOfStackInHand = stackInHand.getItemMeta();
    11. if (metaOfStackInHand != null) {
    12. snowball.setMetadata("SnowballDisplayName", new FixedMetadataValue(this,
    13. metaOfStackInHand.getDisplayName())); // "this" will only work if the listener is also your pluginclass.
    14. //Else you must change it to your plugin
    15. }
    16. }
    17. }
    18. }
    19.  
    20. @EventHandler
    21. public void onSpezialSnowballDamagesPlayer(final EntityDamageByEntityEvent edbee) {
    22. Entity damager = edbee.getDamager();
    23. Entity damaged = edbee.getEntity();
    24. if (damager != null && damager instanceof Snowball && damaged != null) {
    25. Snowball snowball = (Snowball) damager;
    26. List<MetadataValue> values = snowball.getMetadata("SnowballDisplayName");
    27. if (values != null && values.size() == 1) {
    28. if (values.get(0).asString().equalsIgnoreCase("FireBall")) {
    29. damaged.setFireTicks(60);
    30. }
    31. }
    32. }
    33. }


    Edit it so it works for you. i hope the code explains itself
     
    sonicwolfsdutch likes this.
Thread Status:
Not open for further replies.

Share This Page