Solved how to set reach in which sheeps are sheared in

Discussion in 'Plugin Development' started by Leon0983X, Aug 27, 2015.

Thread Status:
Not open for further replies.
  1. Hi, i'll make a plugin which shears all sheeps in a reach of 10 blocks when a player shears one sheep. I started developing today >.< and I don't know how to do this, could you help me?
    I have done this:

    Code:
        @EventHandler
        public void playerShear(PlayerShearEntityEvent event){
            Player player = (Player)event.getPlayer();
          
        }
    xD

    Sorry for my bad englisch. I hope you can understand what i mean xD
     
  2. Offline

    finalblade1234

  3. how can i check if its an sheep?
     
  4. Offline

    finalblade1234

    @Leon0983X
    if(<entity> instanceof Sheep){ //do stuff }
     
  5. Code:
        @EventHandler
    
        public void playerShear(PlayerShearEntityEvent event){
            Player player = (Player)event.getPlayer();
            player.getNearbyEntities(10, 2, 10);
            if(player instanceof Sheep){
                System.out.println("lol you are a sheep");
            }
    what's wrong?
     
    Last edited: Aug 27, 2015
  6. Offline

    au2001

    @Leon0983X You have to loop through the entities using a for loop, not just get them.

    Then, you don't want to check if the player is a sheep (that would actually be weird) but the entity you're looping through.
     
  7. Offline

    Kyorax

    Code:
    Player player = (Player)event.getPlayer();
    for(Entity e: player.getNearbyEntities(10,2,10)) {
        if(e instanceof Sheep) {
            //Do stuff
        }
    }
    You are now looking at one individual entity and can do your checks.
     
    mrgreen33gamer likes this.
  8. Offline

    au2001

    @Kyorax
    Spoonfeed: To treat (another) in a way that discourages independent thought or action, as by over indulgence.
     
  9. Offline

    Kyorax

    @au2001 He probably doesn't know how iterating works, so I showed him so he can apply it in future problems.
     
    ferrybig likes this.
  10. Offline

    au2001

  11. Offline

    Kyorax

    @au2001 Okay, you made a point.
     
  12. Thanks, now i have:
    Code:
        public void playerShear(PlayerShearEntityEvent event){
            Player player = (Player)event.getPlayer();
            for(Entity e: player.getNearbyEntities(10,2,10)) {
               if(e instanceof Sheep) {
                   ((Sheep) e).setSheared(true);
                   final Inventory inventory = player.getInventory();
                   inventory.addItem(ItemStack(Material.WOOL, 1));
               }
            }
            }
    
    what's wrong now?
    It says: The method ItemStack(Material, int) is undefined for the type EventListener
     
  13. Offline

    timtower Administrator Administrator Moderator

    @Leon0983X Change ItemStack into new ItemStack
     
  14. Offline

    au2001

    @Leon0983X And no need to put the amount if it's just one.
     
Thread Status:
Not open for further replies.

Share This Page