Exemplo n.º 1
0
  public boolean switchTools(ToolType tool) {
    MainPlayerEntity player = world.getBot().getPlayer();
    if (player == null) return false;
    PlayerInventory inventory = player.getInventory();

    ItemStack bestTool = null;
    int bestToolSlot = -1, bestToolValue = -1;
    for (int i = 0; i < 36; i++) {
      ItemStack item = inventory.getItemAt(i);
      if (tool == null) {
        if (i > 8) break;
        if (item == null || ToolType.getById(item.getId()) == null) {
          bestTool = item;
          bestToolSlot = i;
          break;
        }
        continue;
      }
      if (item == null) continue;
      ToolType toolType = ToolType.getById(item.getId());
      if (toolType == null || toolType != tool) continue;
      int toolValue = getToolPriority(item.getId());
      if (bestTool == null || toolValue > bestToolValue) {
        bestTool = item;
        bestToolSlot = i;
        bestToolValue = toolValue;
      }
    }
    if (bestToolSlot == -1) return false;
    return switchHeldItems(bestToolSlot);
  }
Exemplo n.º 2
0
 @Override
 public synchronized void run() {
   MainPlayerEntity player = bot.getPlayer();
   World world = bot.getWorld();
   if (player == null || world == null) return;
   double speed = 0.18 * 3;
   double x = player.getX(), z = player.getZ();
   int lowestY = (int) player.getY();
   while (!BlockType.getById(world.getBlockIdAt((int) (x - 0.5), (lowestY - 1), (int) (z - 0.5)))
           .isSolid()
       && lowestY > 0) lowestY--;
   player.setY(player.getY() + Math.max(-speed, lowestY - player.getY()));
 }
Exemplo n.º 3
0
 @EventHandler
 public void onPacketProcess(PacketProcessEvent event) {
   // System.out.println("Packet received: " + event.getPacket().getId()
   // + " (" + event.getPacket() + ")");
   Packet packet = event.getPacket();
   switch (packet.getId()) {
     case 0:
       connectionHandler.sendPacket(new Packet0KeepAlive(new Random().nextInt()));
       break;
     case 3:
       String message = ((Packet3Chat) packet).message;
       message = removeColors(message);
       System.out.println("[" + bot.getSession().getUsername() + "] " + message);
       String testMessage = "[MineCaptcha] To be unmuted answer this question: What is ";
       String testMessage2 = "Please type '";
       String testMessage3 = "' to continue sending messages/commands";
       if (message.contains(testMessage)) {
         try {
           String captcha = message.split(Pattern.quote(testMessage))[1].split("[ \\?]")[0];
           ScriptEngineManager mgr = new ScriptEngineManager();
           ScriptEngine engine = mgr.getEngineByName("JavaScript");
           String solved = engine.eval(captcha).toString();
           solved = solved.split("\\.")[0];
           connectionHandler.sendPacket(new Packet3Chat(solved));
         } catch (Exception exception) {
           exception.printStackTrace();
         }
       } else if (message.contains(testMessage2) && message.contains(testMessage3)) {
         try {
           String captcha =
               message.split(Pattern.quote(testMessage2))[1].split(Pattern.quote(testMessage3))[0];
           connectionHandler.sendPacket(new Packet3Chat(captcha));
         } catch (Exception exception) {
           exception.printStackTrace();
         }
       } else if (message.startsWith("Please register with \"/register")) {
         String password = "";
         for (int i = 0; i < 10 + random.nextInt(6); i++)
           password += alphas[random.nextInt(alphas.length)];
         bot.say("/register " + password + " " + password);
       } else if (message.startsWith("/uc ")) {
         connectionHandler.sendPacket(new Packet3Chat(message));
       } else if ((message.contains("do the crime") && message.contains("do the time"))
           || message.contains("You have been muted")) {
         connectionHandler.sendPacket(new Packet3Chat("\247Leaving!"));
       } else if (message.contains(owner + " has requested to teleport to you.")) {
         connectionHandler.sendPacket(new Packet3Chat("/tpaccept"));
       } else if (message.contains(owner)) {
         if (message.contains("Go ")) {
           spamMessage = message.substring(message.indexOf("Go ") + "Go ".length());
         } else if (message.contains("Stop")) {
           spamMessage = null;
           bot.getTaskManager().stopAll();
         } else if (message.contains("Die")) {
           die = true;
         } else if (message.contains("Say ")) {
           connectionHandler.sendPacket(
               new Packet3Chat(message.substring(message.indexOf("Say ") + "Say ".length())));
         } else if (message.contains("Leave")) {
           connectionHandler.sendPacket(new Packet255KickDisconnect("Quit"));
         } else if (message.contains("Tool")) {
           MainPlayerEntity player = bot.getPlayer();
           if (player == null) return;
           PlayerInventory inventory = player.getInventory();
           inventory.setCurrentHeldSlot(
               Integer.parseInt(
                   message.substring(message.indexOf("Tool ") + "Tool ".length()).split(" ")[0]));
         } else if (message.contains("DropId ")) {
           MainPlayerEntity player = bot.getPlayer();
           PlayerInventory inventory = player.getInventory();
           String substring =
               message.substring(message.indexOf("DropId ") + "DropId ".length()).split(" ")[0];
           int id = Integer.parseInt(substring);
           for (int slot = 0; slot < 40; slot++) {
             ItemStack item = inventory.getItemAt(slot);
             if (item != null && item.getId() == id) {
               inventory.selectItemAt(slot, true);
               inventory.dropSelectedItem();
             }
           }
           inventory.close();
         } else if (message.contains("Drop")) {
           MainPlayerEntity player = bot.getPlayer();
           PlayerInventory inventory = player.getInventory();
           if (message.contains("Drop ")) {
             String substring =
                 message.substring(message.indexOf("Drop ") + "Drop ".length()).split(" ")[0];
             try {
               int slot = Integer.parseInt(substring);
               if (slot < 0 || slot >= 40) return;
               if (inventory.getItemAt(slot) != null) {
                 inventory.selectItemAt(slot, true);
                 inventory.dropSelectedItem();
               }
               return;
             } catch (NumberFormatException e) {
             }
           }
           for (int slot = 0; slot < 40; slot++) {
             if (inventory.getItemAt(slot) != null) {
               inventory.selectItemAt(slot, true);
               inventory.dropSelectedItem();
             }
           }
           inventory.close();
         } else if (message.contains("Switch ")) {
           MainPlayerEntity player = bot.getPlayer();
           PlayerInventory inventory = player.getInventory();
           String substring = message.substring(message.indexOf("Switch ") + "Switch ".length());
           try {
             int slot1 = Integer.parseInt(substring.split(" ")[0]);
             int slot2 = Integer.parseInt(substring.split(" ")[1]);
             if (slot1 < 0 || slot1 >= 45 || slot2 < 0 || slot2 >= 45) return;
             inventory.selectItemAt(slot1);
             inventory.selectItemAt(slot2);
             inventory.selectItemAt(slot1);
           } catch (NumberFormatException e) {
           }
           // inventory.close();
         } else if (message.contains("Equip")) {
           MainPlayerEntity player = bot.getPlayer();
           PlayerInventory inventory = player.getInventory();
           boolean helmet = inventory.getArmorAt(0) != null;
           boolean chestplate = inventory.getArmorAt(1) != null;
           boolean leggings = inventory.getArmorAt(2) != null;
           boolean boots = inventory.getArmorAt(3) != null;
           boolean changed = false;
           for (int i = 0; i < 36; i++) {
             ItemStack item = inventory.getItemAt(i);
             if (item == null) continue;
             int armorSlot;
             int id = item.getId();
             if (!helmet
                 && (id == 86 || id == 298 || id == 302 || id == 306 || id == 310 || id == 314)) {
               armorSlot = 0;
               helmet = true;
             } else if (!chestplate
                 && (id == 299 || id == 303 || id == 307 || id == 311 || id == 315)) {
               armorSlot = 1;
               chestplate = true;
             } else if (!leggings
                 && (id == 300 || id == 304 || id == 308 || id == 312 || id == 316)) {
               armorSlot = 2;
               leggings = true;
             } else if (!boots
                 && (id == 301 || id == 305 || id == 309 || id == 313 || id == 317)) {
               armorSlot = 3;
               boots = true;
             } else if (helmet && chestplate && leggings && boots) break;
             else continue;
             inventory.selectItemAt(i);
             inventory.selectArmorAt(armorSlot);
             changed = true;
           }
           if (!changed) {
             for (int i = 0; i < 36; i++) {
               ItemStack item = inventory.getItemAt(i);
               if (item != null) continue;
               int armorSlot;
               if (helmet) {
                 armorSlot = 0;
                 helmet = false;
               } else if (chestplate) {
                 armorSlot = 1;
                 chestplate = false;
               } else if (leggings) {
                 armorSlot = 2;
                 leggings = false;
               } else if (boots) {
                 armorSlot = 3;
                 boots = false;
               } else if (!helmet && !chestplate && !leggings && !boots) break;
               else continue;
               inventory.selectArmorAt(armorSlot);
               inventory.selectItemAt(i);
             }
           }
           inventory.close();
           bot.say("Equipped armor.");
         } else if (message.contains("Owner ")) {
           String name =
               message.substring(message.indexOf("Owner ") + "Owner ".length()).split(" ")[0];
           owner = name;
           bot.say("Set owner to " + name);
         }
       } else if (message.contains("You are not member of any faction.")
           && spamMessage != null
           && createFaction) {
         String msg = "/f create ";
         for (int i = 0; i < 7 + random.nextInt(3); i++)
           msg += alphas[random.nextInt(alphas.length)];
         bot.say(msg);
       }
       if (message.matches("[\\*]*SPQR [\\w]{1,16} invited you to SPQR")) {
         bot.say("/f join SPQR");
         bot.say("\247asdf");
       }
       break;
     case 8:
       Packet8UpdateHealth updateHealth = (Packet8UpdateHealth) packet;
       if (updateHealth.healthMP <= 0) connectionHandler.sendPacket(new Packet205ClientCommand(1));
       break;
     case 9:
       TaskManager taskManager = bot.getTaskManager();
       taskManager.stopAll();
       break;
   }
 }
Exemplo n.º 4
0
  @EventHandler
  public void onPacketProcess(PacketProcessEvent event) {
    Packet packet = event.getPacket();
    if (packet instanceof Packet5PlayerInventory) {
      Packet5PlayerInventory inventoryPacket = (Packet5PlayerInventory) packet;
      Entity entity = getEntityById(inventoryPacket.entityID);
      if (entity == null || !(entity instanceof LivingEntity)) return;
      LivingEntity livingEntity = (LivingEntity) entity;
      livingEntity.setWornItemAt(inventoryPacket.slot, inventoryPacket.item);
    } else if (packet instanceof Packet8UpdateHealth) {
      Packet8UpdateHealth updateHealthPacket = (Packet8UpdateHealth) packet;
      MainPlayerEntity player = bot.getPlayer();
      player.setHealth(updateHealthPacket.healthMP);
      player.setHunger(updateHealthPacket.food);
    } else if (packet instanceof Packet9Respawn) {
      synchronized (chunks) {
        chunks.clear();
      }
    } else if (packet instanceof Packet20NamedEntitySpawn) {
      Packet20NamedEntitySpawn spawnPacket = (Packet20NamedEntitySpawn) packet;
      PlayerEntity entity = new PlayerEntity(this, spawnPacket.entityId, spawnPacket.name);
      entity.setX(spawnPacket.xPosition / 32D);
      entity.setY(spawnPacket.yPosition / 32D);
      entity.setZ(spawnPacket.zPosition / 32D);
      entity.setYaw(spawnPacket.rotation);
      entity.setPitch(spawnPacket.pitch);
      entity.setWornItemAt(0, new BasicItemStack(spawnPacket.currentItem, 1, 0));
      spawnEntity(entity);
    } else if (packet instanceof Packet21PickupSpawn) {
      Packet21PickupSpawn spawnPacket = (Packet21PickupSpawn) packet;
      ItemEntity entity = new ItemEntity(this, spawnPacket.entityId, spawnPacket.item);
      entity.setX(spawnPacket.xPosition / 32D);
      entity.setY(spawnPacket.yPosition / 32D);
      entity.setZ(spawnPacket.zPosition / 32D);
      spawnEntity(entity);
    } else if (packet instanceof Packet22Collect) {
      Entity entity = getEntityById(((Packet22Collect) packet).collectedEntityId);
      if (entity != null) despawnEntity(entity);
    } else if (packet instanceof Packet23VehicleSpawn) {
      Packet23VehicleSpawn spawnPacket = (Packet23VehicleSpawn) packet;
      Entity entity = null;
      Class<? extends Entity> entityClass = EntityList.getObjectEntityClass(spawnPacket.type);
      if (entityClass == null) return;
      try {
        Constructor<? extends Entity> constructor =
            entityClass.getConstructor(World.class, Integer.TYPE);
        entity = constructor.newInstance(this, spawnPacket.entityId);
      } catch (Exception exception) {
        exception.printStackTrace();
        return;
      }
      entity.setX(spawnPacket.xPosition / 32D);
      entity.setY(spawnPacket.yPosition / 32D);
      entity.setZ(spawnPacket.zPosition / 32D);
      entity.setYaw(0);
      entity.setPitch(0);
      spawnEntity(entity);
    } else if (packet instanceof Packet24MobSpawn) {
      Packet24MobSpawn mobSpawnPacket = (Packet24MobSpawn) packet;
      LivingEntity entity = null;
      Class<? extends LivingEntity> entityClass =
          EntityList.getLivingEntityClass(mobSpawnPacket.type);
      if (entityClass == null) return;
      try {
        Constructor<? extends LivingEntity> constructor =
            entityClass.getConstructor(World.class, Integer.TYPE);
        entity = constructor.newInstance(this, mobSpawnPacket.entityId);
      } catch (Exception exception) {
        exception.printStackTrace();
        return;
      }
      entity.setX(mobSpawnPacket.xPosition / 32D);
      entity.setY(mobSpawnPacket.yPosition / 32D);
      entity.setZ(mobSpawnPacket.zPosition / 32D);
      entity.setYaw((mobSpawnPacket.yaw * 360) / 256F);
      entity.setPitch((mobSpawnPacket.pitch * 360) / 256F);
      entity.setHeadYaw((mobSpawnPacket.headYaw * 360) / 256F);

      if (mobSpawnPacket.getMetadata() != null) entity.updateMetadata(mobSpawnPacket.getMetadata());
      spawnEntity(entity);
    } else if (packet instanceof Packet25EntityPainting) {
      Packet25EntityPainting paintingPacket = (Packet25EntityPainting) packet;
      PaintingEntity entity =
          new PaintingEntity(
              this, paintingPacket.entityId, ArtType.getArtTypeByName(paintingPacket.title));
      entity.setX(paintingPacket.xPosition);
      entity.setY(paintingPacket.yPosition);
      entity.setZ(paintingPacket.zPosition);
      entity.setDirection(paintingPacket.direction);
      spawnEntity(entity);
    } else if (packet instanceof Packet26EntityExpOrb) {

    } else if (packet instanceof Packet29DestroyEntity) {
      Packet29DestroyEntity destroyEntityPacket = (Packet29DestroyEntity) packet;
      for (int id : destroyEntityPacket.entityIds) {
        Entity entity = getEntityById(id);
        if (entity != null) {
          despawnEntity(entity);
          entity.setDead(true);
        }
      }
    } else if (packet instanceof Packet30Entity) {
      Packet30Entity entityPacket = (Packet30Entity) packet;
      Entity entity = getEntityById(entityPacket.entityId);
      if (entity == null) return;
      entity.setX(entity.getX() + (entityPacket.xPosition / 32D));
      entity.setY(entity.getY() + (entityPacket.yPosition / 32D));
      entity.setZ(entity.getZ() + (entityPacket.zPosition / 32D));
      if (packet instanceof Packet31RelEntityMove || packet instanceof Packet33RelEntityMoveLook) {
        entity.setYaw((entityPacket.yaw * 360) / 256F);
        entity.setPitch((entityPacket.pitch * 360) / 256F);
      }
    } else if (packet instanceof Packet34EntityTeleport) {
      Packet34EntityTeleport teleportPacket = (Packet34EntityTeleport) packet;
      Entity entity = getEntityById(teleportPacket.entityId);
      if (entity == null) return;
      entity.setX(teleportPacket.xPosition / 32D);
      entity.setY(teleportPacket.yPosition / 32D);
      entity.setZ(teleportPacket.zPosition / 32D);
      entity.setYaw((teleportPacket.yaw * 360) / 256F);
      entity.setPitch((teleportPacket.pitch * 360) / 256F);
    } else if (packet instanceof Packet35EntityHeadRotation) {
      Packet35EntityHeadRotation headRotatePacket = (Packet35EntityHeadRotation) packet;
      Entity entity = getEntityById(headRotatePacket.entityId);
      if (entity == null || !(entity instanceof LivingEntity)) return;
      ((LivingEntity) entity).setHeadYaw((headRotatePacket.headRotationYaw * 360) / 256F);
    } else if (packet instanceof Packet39AttachEntity) {
      Packet39AttachEntity attachEntityPacket = (Packet39AttachEntity) packet;
      Entity rider = getEntityById(attachEntityPacket.entityId);
      if (rider == null) return;
      Entity riding = null;
      if (attachEntityPacket.vehicleEntityId == -1) {
        if (rider.getRiding() != null) {
          rider.getRiding().setRider(null);
          rider.setRiding(null);
        }
      } else {
        riding = getEntityById(attachEntityPacket.vehicleEntityId);
        if (riding == null) return;
        rider.setRiding(riding);
        riding.setRider(rider);
      }
    } else if (packet instanceof Packet40EntityMetadata) {
      Packet40EntityMetadata metadataPacket = (Packet40EntityMetadata) packet;
      Entity entity = getEntityById(metadataPacket.entityId);
      if (entity == null) return;
      entity.updateMetadata(metadataPacket.getMetadata());
    } else if (packet instanceof Packet43Experience) {
      Packet43Experience experiencePacket = (Packet43Experience) packet;
      MainPlayerEntity player = bot.getPlayer();
      player.setExperienceLevel(experiencePacket.experienceLevel);
      player.setExperienceTotal(experiencePacket.experienceTotal);
    } else if (packet instanceof Packet51MapChunk) {
      if (bot.isMovementDisabled()) return;
      Packet51MapChunk mapChunkPacket = (Packet51MapChunk) packet;
      processChunk(
          mapChunkPacket.x,
          mapChunkPacket.z,
          mapChunkPacket.chunkData,
          mapChunkPacket.bitmask,
          mapChunkPacket.additionalBitmask,
          true,
          mapChunkPacket.biomes);
    } else if (packet instanceof Packet52MultiBlockChange) {
      Packet52MultiBlockChange multiBlockChangePacket = (Packet52MultiBlockChange) packet;
      if (multiBlockChangePacket.metadataArray == null) return;
      DataInputStream datainputstream =
          new DataInputStream(new ByteArrayInputStream(multiBlockChangePacket.metadataArray));
      try {
        for (int i = 0; i < multiBlockChangePacket.size; i++) {
          short word0 = datainputstream.readShort();
          short word1 = datainputstream.readShort();
          int id = (word1 & 0xfff) >> 4;
          int metadata = word1 & 0xf;
          int x = word0 >> 12 & 0xf;
          int z = word0 >> 8 & 0xf;
          int y = word0 & 0xff;
          setBlockIdAt(
              id,
              (multiBlockChangePacket.xPosition * 16) + x,
              y,
              (multiBlockChangePacket.zPosition * 16) + z);
          setBlockMetadataAt(
              metadata,
              (multiBlockChangePacket.xPosition * 16) + x,
              y,
              (multiBlockChangePacket.zPosition * 16) + z);
        }
      } catch (IOException exception) {
        exception.printStackTrace();
      }
    } else if (packet instanceof Packet53BlockChange) {
      Packet53BlockChange blockChangePacket = (Packet53BlockChange) packet;
      setBlockIdAt(
          blockChangePacket.type,
          blockChangePacket.xPosition,
          blockChangePacket.yPosition,
          blockChangePacket.zPosition);
      setBlockMetadataAt(
          blockChangePacket.metadata,
          blockChangePacket.xPosition,
          blockChangePacket.yPosition,
          blockChangePacket.zPosition);
    } else if (packet instanceof Packet56MapChunks) {
      if (bot.isMovementDisabled()) return;
      Packet56MapChunks chunkPacket = (Packet56MapChunks) packet;
      for (int i = 0; i < chunkPacket.primaryBitmap.length; i++)
        processChunk(
            chunkPacket.chunkX[i],
            chunkPacket.chunkZ[i],
            chunkPacket.chunkData[i],
            chunkPacket.primaryBitmap[i],
            chunkPacket.secondaryBitmap[i],
            chunkPacket.skylight,
            true);
    }
  }
Exemplo n.º 5
0
 @Override
 public synchronized boolean isActive() {
   MainPlayerEntity player = bot.getPlayer();
   if (player == null) return false;
   return !player.isOnGround();
 }
 public PlayerMoveRotateEvent(
     MainPlayerEntity entity, double x, double y, double z, double yaw, double pitch) {
   super(entity, x, y, z, yaw, pitch, entity.isOnGround());
 }
Exemplo n.º 7
0
  public MainPlayerEntity(World world, MainPlayerEntity player) {
    this(world, player.getId(), player.getName(), player.getGameMode());

    inventory.setDelay(player.getInventory().getDelay());
  }