Potion Effects not working

Discussion in 'Plugin Development' started by boynedmaster, Jul 30, 2013.

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

    boynedmaster

    I'm making a plugin that gives zombies certain effects based on their Y axis. My code:
    Code:
    package me.boynedmaster.DeepZombies;
     
    import org.bukkit.entity.Zombie;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.entity.CreatureSpawnEvent;
    import org.bukkit.plugin.java.JavaPlugin;
    import org.bukkit.potion.PotionEffect;
    import org.bukkit.potion.PotionEffectType;
     
    public class DeepZombies extends JavaPlugin {
    String version = "1.0";
     
    int lvl1 = 85;
    int lvl2 = 100;
    int lvl3 = 120;
     
    @Override
    public void onEnable(){
    getLogger().info("Deep Zombies "+version+" loaded!");
    }
     
    @Override
    public void onDisable(){
    getLogger().info("Deep Zombies "+version+" disabled!");
    }
     
    @EventHandler
    public void creatureSpawnEvent(CreatureSpawnEvent e){
    if(e.getEntity() instanceof Zombie){
    int y = e.getEntity().getLocation().getBlockY();
     
    if(lvl1 > y && y > 59)
    return;
     
    if(y < 59){
     
    return;
    }
     
    if(y == lvl1 || (y > lvl1 && y < lvl2)){
    e.getEntity().addPotionEffect(new PotionEffect(PotionEffectType.INCREASE_DAMAGE, 2147483647, 1));
    return;
    }
     
    if(y == lvl2 || (y > lvl2 && y < lvl3)){
    e.getEntity().addPotionEffect(new PotionEffect(PotionEffectType.INCREASE_DAMAGE, 2147483647, 2));
    return;
    }
     
    if(y >= lvl3){
    e.getEntity().addPotionEffect(new PotionEffect(PotionEffectType.INCREASE_DAMAGE, 2147483647, 2));
    e.getEntity().addPotionEffect(new PotionEffect(PotionEffectType.SPEED, 2147483647, 1));
    return;
    }
    }
    }
    }
    
    There's no error, and I'm on the right Y angle. Help!
     
  2. Offline

    chasechocolate

    You're not registering your events. Also, an alternative to 2147483647 is Integer.MAX_VALUE.
     
  3. Offline

    boynedmaster

    ?
    Same thing.
     
  4. Add this inside your onEnable()
    Code:java
    1. getServer().getPluginManager().registerEvents(this, this);
     
  5. boynedmaster
    I don't think any potions work on entities but I know for sure that Speed potions don't work on entities, only Players.
    I tried it so if I get this wrong, that's just weird.
     
  6. Offline

    sumusiko

    then what would be the best way for mosnters to get progressively stronger as they go up or down in Y axis?
     
  7. Offline

    xTrollxDudex

    sumusiko
    That will never work unless the zombie spawns directly on that Y block
     
    foodyling likes this.
  8. Offline

    sumusiko

    i know it works because I've seen a server with this system implemented...

    the lower you got (undeground) the stronger would the monsters get
     
  9. Offline

    xTrollxDudex

    sumusiko
    *facepalm* this works when they spawn, not when they move lower
    KingFaris11 *LivingEntity, not entity
     
  10. Offline

    sumusiko

    Yes thats what I'm saying when they spawn they get those not when they move lower lol...
     
  11. xTrollxDudex
    If you're trying to say it's not possible when they're lower, it is.

    In the EntityDamageByEntityEvent:
    Code:
    if (event.getDamage() == 0) return;
    if (event.getEntityType() == EntityType.PLAYER) {
        if (event.getDamager() instanceof Zombie) {
            Zombie zombie = (Zombie) event.getDamager();
            event.setDamage(event.getDamage() + (6 / zombie.getY());
        }
    }
    
    What this would do is add 6 divided by the Y of the zombie to the original damage. This isn't the best as if the Zombie's Y is 60, 6 / 60 = 0.1 which is originalDamage + 0.1 which is not really that strong, although at least it proves it's possible.

    You can make it so that if the Y is lower than a specific number, increase by x much.
    Code:
    if (event.getDamage() == 0) return;
    if (event.getEntityType() == EntityType.PLAYER) {
        if (event.getDamager() instanceof Zombie) {
            Zombie zombie = (Zombie) event.getDamager();
            double damageIncrease = 0;
            int zombieY = (int) zombie.getY();
            if (zombieY <= 128) damageIncrease = 1;
            if (zombieY <= 96) damageIncrease = 1.5;
            if (zombieY <= 64) damageIncrease = 2;
            if (zombieY <= 48) damageIncrease = 2.5;
            if (zombieY <= 32) damageIncrease = 3;
            if (zombieY <= 16) damageIncrease = 3.5;
            if (zombieY <= 1) damageIncrease = 4;
            event.setDamage(event.getDamage() + damageIncrease);
        }
    }
    
    If you mean where they spawn, you've gotta something a tiny bit more complicated. Have a Map of where LivingEntities spawn and then get the Entity/UUID from the Map in the EntityDamageByEntityEvent.
     
  12. Offline

    sumusiko


    Thats perfect, I'm not a plugin developer, the OP is actually making this plugin for me so I just wanted to know what could possibly be wrong because I had no error in console, but we will probably use this and test out the damages and such. Thanks !
     

  13. No problem. =)
     
  14. Offline

    boynedmaster

    "The method registerEvents(Listener, Plugin) in the type PluginManager is not applicable for the arguments (DeepZombies, DeepZombies)"
     
  15. Offline

    sumusiko

    so apparently we still need help!
     
  16. Offline

    Awesomeman2

    KingFaris11 Potion effects work on mobs thats how u use posion and things on them.
     
  17. Offline

    sumusiko

    any idea why its not working for OP?
     

  18. Speed potions don't work I mean. Thanks for correcting me though, I knew that some work.


    Are you serious? If DeepZombies is your main class, it should extend JavaPlugin and implement Listener if you're putting an event inside that class. If it isn't your main class, onEnable should be in your main class extending JavaPlugin. If you have a class just for listener, put this.getServer().getPluginManager().registerEvents(new PlayerListener(this), this) and PlayerListener should be the class you called it.


    What do you mean it's not working for OP? Are you saying that it works for non OPs?

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

    sumusiko

    I mean OP as in the thread maker
     
  20. Oh.
     
Thread Status:
Not open for further replies.

Share This Page