[UNSOLVED] Snow Ball Slowdown

Discussion in 'Plugin Development' started by XxZHALO13Xx, May 11, 2014.

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

    XxZHALO13Xx

    Hi im trying to get a SnowBall Slowdown plugin.... Here's my code



    @EventHandler
    public void onProjectileHit(EntityDamageByEntityEvent e) {
    if (!(e.getEntity() instanceof Snowball)) return;
    Projectile p = (Projectile) e.getEntity();
    Snowball s = (Snowball) p;
    s.getWorld().createExplosion(s.getLocation(), 0);
    for (Entity en : s.getNearbyEntities(3, 3, 3)) {
    if (en instanceof Player) {
    Player pl = (Player) en;
    if (!(pl == ((Projectile) e.getEntity()).getShooter())) pl.addPotionEffect(new PotionEffect(PotionEffectType.SLOW, 400, 0));

    }
    }
    }

    }


    .getShooter())) has a line through it, it says "getShooter() is depreciated" what do i do? please help!

    what do i do
     
  2. Offline

    LilHambo

    It always is. It's ok it should still work. If there are errors put in a stack trace so we can see.
     
  3. Offline

    XxZHALO13Xx

    I fixed thaT... I dont get console errors but it doesnt slow me or mobs down when i hit them with it...
     
  4. Offline

    tryy3

    Dont use space in your name, use something like - or _ instead
     
  5. Offline

    XxZHALO13Xx

    that doesnt matter.. i dont get console errors but when i hit mobs or myself nothing happens
     
  6. Offline

    tryy3

    try adding debug lines
     
  7. Offline

    XxZHALO13Xx

    Whats that? im new to this
     
  8. Offline

    tryy3

    basically messages to print out to see if stuff working
    messages like, pl.getName() or just messages to see if a if statement actually did what it was supposed to do (in this case you can just send a message like "this statement worked"!
     
  9. Offline

    thecrystalflame

    you h ave the amplifier set to 0 ofcourse its not going to work. try changing this:
    Code:java
    1.  
    2. pl.addPotionEffect(new PotionEffect(PotionEffectType.SLOW, 400, 0));
    3.  


    to this:
    Code:java
    1.  
    2. pl.addPotionEffect(new PotionEffect(PotionEffectType.SLOW, 400, 1));
    3.  
     
  10. Offline

    DotDash

    Java starts counting at 0, so the effect you are describing is Slow II.
     
  11. Offline

    thecrystalflame

    incorrect again, arrays do start counting at 0 yes. but the method being used is written by the bukkit team and has nothind to do with how java counts. you "may" be correct but your reasoning behind it is wrong.
     
  12. Offline

    DotDash

    It does start at 0 because the third value is an amplifier. So you sir, are wrong.
     
  13. Offline

    d3v1n302418

    thecrystalflame you realize bukkit is an api for java? they are the same syntax-wise..
     
    Garris0n likes this.
  14. Offline

    Garris0n

    First of all, this will be called when a snowball hits an entity. If you want when a snowball hits the ground, use ProjectileHitEvent. Not sure which you're going far.

    Second, EntityDamageByEntityEvent#getEntity() will return the entity that is damaged. If you want the damager, it's EntityDamageByEntityEvent#getDamager().

    Third, it's deprecated because it was replaced by a new system. Use ProjectileSource.

    Also, use code tags.
     
  15. Offline

    thecrystalflame

    of course i reallise this, but a method from the api only starts at 0 if the programmer who wrote the method set it like so. the variable amplifier is an integer meaning its not set in stone if the program counts it from 0 or not.
     
  16. Offline

    15987632

    Code:java
    1. @EventHandler
    2. public void onPlayerDamageByPlayer(EntityDamageByEntityEvent event) {
    3. Entity damager = event.getDamager();
    4. if (damager instanceof Snowball) {
    5. Entity entity = event.getEntity();
    6. if (entity instanceof LivingEntity) {
    7. LivingEntity damaged = (LivingEntity) entity;
    8. PotionEffect potionEffect = new PotionEffect(PotionEffectType.SLOW, 60, 1);
    9. potionEffect.apply(damaged);
    10. }
    11.  
    12.  
    13. }
    14. }


    this code works
     
  17. Offline

    Aqua

    XxZHALO13Xx
    Did you register the Listener using:
    Bukkit.getPluginManager().registerEvents(Listener, Plugin) ?
     
  18. Offline

    thecrystalflame

    yes of course, this has nothing to do with syntax though. i can make a method that starts counting at 1 very easily in java. its not limited to it. yes arrays start counting at 0, that does not mean to say that 3rd party methods are limited to starting any type of count from 0. considering amplifier is an int nand does not call from any type of array.

    go on then, tell me why a value named amplifier HAS to start counting at 0. dont tell me this java starts with 0 logic because that has nothing to do with this. yes i was wrong in my previus post and amplifier does start at 0. but tell me what makes it impossible that it could of started at 1?

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

    Garris0n

    Everybody is expected to start at zero. And here is why.
     
  20. Offline

    thecrystalflame

    that explains it very well thank you.
    Expected is very different to Deffinate
     
  21. Offline

    Garris0n

    If you had to guess what it was, your guess should've been that it started at zero.
     
    thecrystalflame likes this.
  22. Offline

    XxZHALO13Xx

    How would i make it to where when the snowball hits the ground, it explodes, has particles, then disapears?
     
  23. Offline

    15987632

    XxZHALO13Xx

    Code:java
    1. public void onHit(ProjectileHitEvent event) {
    2. if (event.getEntity() instanceof Snowball) {
    3. event.getEnttity().getWorld().createExplosion(event.getEntity().getLocation(), 4.0)
    4. }
    5. }


    that is the explosion i dont know about the particles
     
  24. Offline

    XxZHALO13Xx


    Heres The Code i have... It doesnt work...
    package me.xxzhalo13xx.GreandePlugin;

    import org.bukkit.Bukkit;
    import org.bukkit.entity.*;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.Listener;
    import org.bukkit.event.entity.EntityDamageByEntityEvent;
    import org.bukkit.event.entity.ProjectileHitEvent;
    import org.bukkit.plugin.Plugin;
    import org.bukkit.plugin.java.JavaPlugin;
    import org.bukkit.potion.PotionEffect;
    import org.bukkit.potion.PotionEffectType;

    import javax.xml.bind.Marshaller;

    public class Core extends JavaPlugin implements Listener {




    public void onHit(ProjectileHitEvent event) {
    if (event.getEntity() instanceof Snowball) {
    event.getEntity().getWorld().createExplosion(event.getEntity().getLocation(), (float) 4.0);
    }
    }








    @EventHandler
    public void onPlayerDamageByPlayer(EntityDamageByEntityEvent event) {
    Entity damager = event.getDamager();
    if (damager instanceof Snowball) {
    Entity entity = event.getEntity();
    if (entity instanceof LivingEntity) {
    LivingEntity damaged = (LivingEntity) entity;
    PotionEffect potionEffect = new PotionEffect(PotionEffectType.SLOW, 5, 2);
    potionEffect.apply(damaged);
    }


    }
    }
    }
     
  25. Offline

    15987632

    XxZHALO13Xx you need to put the @eventhandler above the explosion code also
     
  26. Offline

    XxZHALO13Xx


    The Slowdown part still doesnt work though
     
  27. Offline

    15987632

    XxZHALO13Xx I literally copie and pasted that part from my code and it works. Put the whole class file in the code option this time and tell me which lines have errors
     
  28. Offline

    XxZHALO13Xx

    Code:
    package me.xxzhalo13xx.GreandePlugin;
     
    import org.bukkit.ChatColor;
    import org.bukkit.entity.Entity;
    import org.bukkit.entity.LivingEntity;
    import org.bukkit.entity.Snowball;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.Listener;
    import org.bukkit.event.entity.EntityDamageByEntityEvent;
    import org.bukkit.event.entity.ProjectileHitEvent;
    import org.bukkit.plugin.java.JavaPlugin;
    import org.bukkit.potion.PotionEffect;
    import org.bukkit.potion.PotionEffectType;
     
    public class Core extends JavaPlugin implements Listener {
     
     
    public void onEnable(){
        getLogger().info("Plugin Enabled");
    }
     
        @EventHandler
        public void onHit(ProjectileHitEvent event) {
            if (event.getEntity() instanceof Snowball) {
                event.getEntity().getWorld().createExplosion(event.getEntity().getLocation(), (float) 4.0);
            }
        }
     
     
     
     
     
     
     
     
        @EventHandler
        public void onPlayerDamageByPlayer(EntityDamageByEntityEvent event) {
            Entity damager = event.getDamager();
            if (damager instanceof Snowball) {
                Entity entity = event.getEntity();
                if (entity instanceof LivingEntity) {
                    LivingEntity damaged = (LivingEntity) entity;
                    PotionEffect potionEffect = new PotionEffect(PotionEffectType.SLOW, 5, 2);
                    potionEffect.apply(damaged);
                }
     
     
            }
        }
    }



    Plugin.yml
    name: Snow Ball Slowdown
    author: XxZHALO13XX
    version: 1.0
    main: me.xxzhalo13xx.GreandePlugin.Core



    there... onHit is gray and says its never used

    onPlayerDamageByPlayer is also gray and says its never used...

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 8, 2016
  29. XxZHALO13Xx So nice of your IDE to be able to tell the future so far that it even knows third-parties will never touch those 2 methods. And unused would hardly be an error, now, would it? To repeat the advice already offered:

    Try adding debug lines.
     
  30. Offline

    XxZHALO13Xx

    i forgot to register the listener XD... it works now... i put all my modues in one project in intellij... Only one runs.. why?
     
Thread Status:
Not open for further replies.

Share This Page