.setSitting on a wolf doesn't make a wolf stand up

Discussion in 'Plugin Development' started by Zethariel, Apr 6, 2015.

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

    Zethariel

    Hello,

    The following code does not work as expected:
    Code:
    dog.setSitting(false);
    plugin.logger.info("dog is sitting: "+dog.isSitting());
    
    The info claims that the dog is sitting. Dog is an instance of Wolf. Am I missing something that resets the entity's state?
     
  2. Offline

    dlange

    does setSitting(true) work?
     
  3. Offline

    Zethariel

    @bwfcwalshy

    Code:
    public class DogsCommand extends EQCommand {
    
       int range = 20;
      
       public static HashMap<UUID, ArrayList<Wolf>> playerDogs = new HashMap<UUID, ArrayList<Wolf>>();
      
       public DogsCommand(Equestrianeers plugin) {
         super(plugin);
        
         minArgCount = 1;
        
         //get all the dogs in all the worlds
         for (World world : Bukkit.getWorlds()){
           List<Wolf> allDogs = (ArrayList<Wolf>) world.getEntitiesByClass(Wolf.class);
           plugin.logger.info(allDogs.size()+" dogs detected");
           for (Wolf dog : allDogs){
             plugin.logger.info(dog.isTamed()+"");
             plugin.logger.info(plugin.playerManager.eqPlayerExists(dog.getOwner().getUniqueId()) + "");
             if (dog.isTamed() && plugin.playerManager.eqPlayerExists(dog.getOwner().getUniqueId())){
               UUID playerID = dog.getOwner().getUniqueId();
               if (playerDogs.containsKey(playerID))
                 playerDogs.get(playerID).add(dog);
               else{
                 playerDogs.put(playerID, new ArrayList<Wolf>(Arrays.asList(dog)));
                 plugin.logger.info("Added dog for" + playerID);
               }
             }
           }
         }
       }
    
       @Override
       protected boolean ProcessCommand(CommandSender sender, Command cmd,
           String label, String[] args) throws Exception {
        
         Player player = (Player) sender;
         UUID playerID = player.getUniqueId();
    
         //find all wolves that belong to the player within the radius
         if (playerDogs.containsKey(playerID) && playerDogs.get(playerID).size() > 0){
           ArrayList<Wolf> affectedDogs = new ArrayList<Wolf>();
           for (Wolf dog : playerDogs.get(playerID)){
             if (dog.getLocation().distance(player.getLocation()) <= range){
               affectedDogs.add(dog);
               plugin.logger.info("found affected dog");
             }
           }
          
           //apply command to these puppies
           switch(args[0]){
           case "sit":
             for (Wolf dog : affectedDogs){
               dog.setSitting(true);
               plugin.logger.info("dog is sitting: "+dog.isSitting());
             }
             break;
           case "stand":
             for (Wolf dog : affectedDogs){
               dog.setSitting(false);
               plugin.logger.info("dog is sitting: "+dog.isSitting());
             }
             break;
           case "come":
           case "heel":
             for (Wolf dog : affectedDogs){
               dog.setSitting(false);
               dog.setTarget(player);
             }
             break;
           }
         }else
           plugin.messageSender.sendCommandResponse(player, "You do not own any dogs :C");
        
        
        
         return true;
       }
    
    Apparently the dogs detected during the constructor 'don't work'. I also have a litener that dynamically adds dogs to the list, and those seem to work. A server restart makes those not work again.

    bump

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

    Tecno_Wizard

    @Zethariel that's an odd one. What build are you using?
     
Thread Status:
Not open for further replies.

Share This Page