Solved Spawning Skeletons/WitherSkeletons

Discussion in 'Plugin Development' started by 97WaterPolo, Dec 28, 2014.

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

    97WaterPolo

    Hello!

    I am trying to prevent all normal skeletons from spawning, but allow the spawning of Wither Skeletons. Currently I am trying to use this, but not sure why it isn't working. I check the Skeleton's type before I cancel it, am I missing something obvious?

    Code:
        @EventHandler
        public void onCreatureSpawn(EntitySpawnEvent event){
            if (event.getEntityType() == EntityType.ZOMBIE ||
                    event.getEntityType() == EntityType.CREEPER ||
                    event.getEntityType() == EntityType.ENDERMAN ||
                    event.getEntityType() == EntityType.SPIDER ||
                    event.getEntityType() == EntityType.WITCH ||
                    event.getEntityType() == EntityType.SLIME ||
                    event.getEntityType() == EntityType.CAVE_SPIDER)
                event.setCancelled(true);
            if (event.getEntityType() == EntityType.SKELETON){//If it is a skeleton
                Skeleton s = (Skeleton) event.getEntity();//Cast it to a skeleton
                if (s.getSkeletonType() != SkeletonType.WITHER)//Check and see if it is a normal skeleton
                    event.setCancelled(true);//if it is, cancel the event
            }
        }
     
  2. Offline

    Vextricity

    Is the problem that both the wither skeleton and skeleton still spawn, or that neither spawn?
     
  3. did you register your events?
     
  4. Offline

    97WaterPolo

    @Datdenkikniet
    Yes, I did :p

    If I remove the code at the bottom, all skeletons spawn, if I add it, neither do.

    @Vextricity
    Its the fact that neither spawn. I want JUST wither skeletons to spawn.
     
  5. Offline

    Vextricity

    Isn't the event called CreatureSpawnEvent?
     
  6. Offline

    teej107

    @Vextricity They both can work and the CreatureSpawnEvent would be better since he is listening for creatures.
    @97WaterPolo What if you just set the type of the skeleton to a wither?
     
  7. Offline

    97WaterPolo

    @teej107
    It isn't that I am trying to make every single Skeleton a Wither, but prevent all normal skeletons except the ones that I spawn in VIA the plugin.

    Thought: Would setting the event cancelled based on the spawn reason work better? If I listened to Creature Spawn Event?
     
  8. Offline

    teej107

  9. Offline

    97WaterPolo

    @teej107
    Well I mean logically it should have worked, either way, I listened to CreatureSpawnEvent and checked the spawn reason. If it was not caused by my plugin, I cancelled the event.

    Thanks for the help!
     
Thread Status:
Not open for further replies.

Share This Page