Pets Help

Discussion in 'Plugin Development' started by IIxUnderWorldxII, Feb 20, 2015.

Thread Status:
Not open for further replies.
  1. Code:
    package Pets;
    
    import java.util.HashMap;
    
    import net.minecraft.server.v1_7_R4.AttributeInstance;
    import net.minecraft.server.v1_7_R4.EntityInsentient;
    import net.minecraft.server.v1_7_R4.GenericAttributes;
    import net.minecraft.server.v1_7_R4.PathEntity;
    
    import org.bukkit.Bukkit;
    import org.bukkit.Location;
    import org.bukkit.craftbukkit.v1_7_R4.entity.CraftEntity;
    import org.bukkit.entity.Entity;
    import org.bukkit.entity.Player;
    import org.bukkit.scheduler.BukkitRunnable;
    
    public class PetHandler {
    
        public static HashMap <String, Entity> player_pet = new HashMap<String, Entity>();
    
        public static void createPet(final Player player, final Entity pet, final double speed) {
            if (player_pet.containsKey(player.getName())) {
                player_pet.get(player.getName()).remove();
                player_pet.remove(player.getName());
               }
    
    
                 player_pet.put(player.getName(), pet);
    
              new BukkitRunnable() {
    
               @SuppressWarnings("deprecation")
               public void run() {
                if (!pet.isValid() || (!player.isOnline())) {
                 this.cancel();
                }
    
                net.minecraft.server.v1_7_R4.Entity petentity = ((CraftEntity) pet).getHandle();
                ((EntityInsentient) petentity).getNavigation().a(2);
                Object petf = ((CraftEntity) pet).getHandle();
                Location targetLocation = player.getLocation();
    
                PathEntity path;
                path = ((EntityInsentient) petf).getNavigation().a(targetLocation.getX() + 1, targetLocation.getY(), targetLocation.getZ() + 1);
                if (path != null) {
                 ((EntityInsentient) petf).getNavigation().a(path, 1.0D);
                 ((EntityInsentient) petf).getNavigation().a(2.0D);
                }
    
                if (!player.isOnline()) {
                 pet.remove();
                }
            
                int distance = (int)
                        Bukkit.getPlayer(player.getName()).getLocation().distance(pet.getLocation());
                        if (distance > 10 && !pet.isDead() && player.isOnGround() && player.isOnline()) {
                        pet.teleport(player.getLocation());
    
                        }
    
                AttributeInstance attributes = ((EntityInsentient)((CraftEntity)pet).getHandle()).getAttributeInstance(GenericAttributes.d);
                attributes.setValue(speed);
               }
    
    
              }.runTaskTimer(PetHandler.i, 0L, 20L);
             }
    
    }
    
    It's the littler runTaskTimer(PetHandler."i"m oL, 20L); thats causing the error.
     
    Last edited by a moderator: Feb 20, 2015
Thread Status:
Not open for further replies.

Share This Page