Solved Giving effects and items to ALL mobs on the server!

Discussion in 'Plugin Development' started by SpongyBacon, Dec 30, 2013.

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

    SpongyBacon

    Hey Bukkit,
    So I need a bit of help giving effects and items to every mob on the server.

    Say I wanted to give every zombie on the server speed 1, and a diamond sword.
    Now I know how to spawn a zombie with speed 1, but I don't know how to modify the natural spawning system so it automatically gives all zombies speed 1 and a diamond sword.

    Thanks!
     
  2. Offline

    xTrollxDudex

    SpongyBacon likes this.
  3. Offline

    SpongyBacon

    Oh wow, didn't realise it was that simple! I'll give it a try and see what I can do!
     
  4. Offline

    xTrollxDudex

    SpongyBacon
    PHP:
    event.getEntity().getEquipment().setItemInHand(new ItemStack(Material.DIAMOND_SWORD));
    event.getEntity().addPotionEffect(new PotionEffect(PotionEffectType.SPEEDInteger.MAX_VALUE1));
     
  5. Offline

    SpongyBacon

    I love you. (No homo)

    xTrollxDudex

    EDIT: Doesn't work, no errors.

    So this is what i've done:
    Code:
    public class Main extends JavaPlugin{
     
        @Override
        public void onEnable() {
            getLogger().info("Enabled!");
        }
     
        @Override
        public void onDisable() {
            getLogger().info("Disabled!");
        }
     
        public boolean onCreatureSpawnEvent(CreatureSpawnEvent event){
          if(event.getEntityType() != EntityType.ZOMBIE){
            event.getEntity().getEquipment().setItemInHand(new ItemStack(Material.DIAMOND_SWORD));
            event.getEntity().addPotionEffect(new PotionEffect(PotionEffectType.SPEED, Integer.MAX_VALUE, 1));
          }
        return false;
        }
     
    }
    Is that how you would do it? I've got no errors in eclipse, but I haven't tested it yet.
    Thanks for the help so far, i'm pretty new to bukkit.

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 6, 2016
  6. SpongyBacon
    Forgot to register your listener, ill help you on skype
     
    SpongyBacon likes this.
  7. Offline

    SpongyBacon

    OneBillionAndOne
    Thanks a billion! (Get it?)

    Well, this problem has been solved. Here's the final thing for those people who'll google this in the future!
    Code:
    public class Main extends JavaPlugin implements Listener{
       
        @Override
        public void onEnable() {
            getLogger().info("Enabled!");
            getServer().getPluginManager().registerEvents(this, this);
        }
       
        @Override
        public void onDisable() {
            getLogger().info("Disabled!");
        }
       
        @EventHandler
        public void onCreatureSpawnEvent(CreatureSpawnEvent event){
          if(event.getEntityType() == EntityType.ZOMBIE){
            event.getEntity().getEquipment().setItemInHand(new ItemStack(Material.DIAMOND_SWORD));
            event.getEntity().addPotionEffect(new PotionEffect(PotionEffectType.SPEED, Integer.MAX_VALUE, 1));
          }
        }
     
    }
    /solved

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 6, 2016
    OneBillionAndOne likes this.
Thread Status:
Not open for further replies.

Share This Page