コード例 #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);
  }
コード例 #2
0
  public void b(EntityHuman entityhuman) {
    PlayerInventory playerinventory = entityhuman.inventory;

    if (playerinventory.getCarried() != null) {
      entityhuman.drop(playerinventory.getCarried());
      playerinventory.setCarried((ItemStack) null);
    }
  }
コード例 #3
0
 public boolean switchHeldItems(int newSlot) {
   if (inventory.getCurrentHeldSlot() == newSlot) return true;
   if (newSlot > 8) {
     int hotbarSpace = 9;
     for (int hotbarIndex = 0; hotbarIndex < 9; hotbarIndex++) {
       ItemStack item = inventory.getItemAt(hotbarIndex);
       if (item == null) {
         hotbarSpace = hotbarIndex;
         break;
       } else if (ToolType.getById(item.getId()) == null && hotbarIndex < hotbarSpace)
         hotbarSpace = hotbarIndex;
     }
     if (hotbarSpace == 9) hotbarSpace = 0;
     inventory.selectItemAt(newSlot);
     inventory.selectItemAt(hotbarSpace);
     if (inventory.getSelectedItem() != null) inventory.selectItemAt(newSlot);
     inventory.close();
     newSlot = hotbarSpace;
   }
   inventory.setCurrentHeldSlot(newSlot);
   return true;
 }
コード例 #4
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;
   }
 }
コード例 #5
0
  public ItemStack clickItem(int i, int j, int k, EntityHuman entityhuman) {
    ItemStack itemstack = null;
    PlayerInventory playerinventory = entityhuman.inventory;
    Slot slot;
    ItemStack itemstack1;
    int l;
    ItemStack itemstack2;

    if ((k == 0 || k == 1) && (j == 0 || j == 1)) {
      if (i == -999) {
        if (playerinventory.getCarried() != null && i == -999) {
          if (j == 0) {
            entityhuman.drop(playerinventory.getCarried());
            playerinventory.setCarried((ItemStack) null);
          }

          if (j == 1) {
            // CraftBukkit start - store a reference
            ItemStack itemstack3 = playerinventory.getCarried();
            if (itemstack3.count > 0) {
              entityhuman.drop(itemstack3.a(1));
            }

            if (itemstack3.count == 0) {
              // CraftBukkit end
              playerinventory.setCarried((ItemStack) null);
            }
          }
        }
      } else if (k == 1) {
        slot = (Slot) this.c.get(i);
        if (slot != null && slot.a(entityhuman)) {
          itemstack1 = this.b(entityhuman, i);
          if (itemstack1 != null) {
            int i1 = itemstack1.id;

            itemstack = itemstack1.cloneItemStack();
            if (slot != null && slot.getItem() != null && slot.getItem().id == i1) {
              this.a(i, j, true, entityhuman);
            }
          }
        }
      } else {
        if (i < 0) {
          return null;
        }

        slot = (Slot) this.c.get(i);
        if (slot != null) {
          itemstack1 = slot.getItem();
          ItemStack itemstack3 = playerinventory.getCarried();

          if (itemstack1 != null) {
            itemstack = itemstack1.cloneItemStack();
          }

          if (itemstack1 == null) {
            if (itemstack3 != null && slot.isAllowed(itemstack3)) {
              l = j == 0 ? itemstack3.count : 1;
              if (l > slot.a()) {
                l = slot.a();
              }

              // CraftBukkit start
              if (itemstack3.count >= l) {
                slot.set(itemstack3.a(l));
              }
              // CraftBukkit end

              if (itemstack3.count == 0) {
                playerinventory.setCarried((ItemStack) null);
              }
            }
          } else if (slot.a(entityhuman)) {
            if (itemstack3 == null) {
              l = j == 0 ? itemstack1.count : (itemstack1.count + 1) / 2;
              itemstack2 = slot.a(l);
              playerinventory.setCarried(itemstack2);
              if (itemstack1.count == 0) {
                slot.set((ItemStack) null);
              }

              slot.a(entityhuman, playerinventory.getCarried());
            } else if (slot.isAllowed(itemstack3)) {
              if (itemstack1.id == itemstack3.id
                  && (!itemstack1.usesData() || itemstack1.getData() == itemstack3.getData())
                  && ItemStack.equals(itemstack1, itemstack3)) {
                l = j == 0 ? itemstack3.count : 1;
                if (l > slot.a() - itemstack1.count) {
                  l = slot.a() - itemstack1.count;
                }

                if (l > itemstack3.getMaxStackSize() - itemstack1.count) {
                  l = itemstack3.getMaxStackSize() - itemstack1.count;
                }

                itemstack3.a(l);
                if (itemstack3.count == 0) {
                  playerinventory.setCarried((ItemStack) null);
                }

                itemstack1.count += l;
              } else if (itemstack3.count <= slot.a()) {
                slot.set(itemstack3);
                playerinventory.setCarried(itemstack1);
              }
            } else if (itemstack1.id == itemstack3.id
                && itemstack3.getMaxStackSize() > 1
                && (!itemstack1.usesData() || itemstack1.getData() == itemstack3.getData())
                && ItemStack.equals(itemstack1, itemstack3)) {
              l = itemstack1.count;
              if (l > 0 && l + itemstack3.count <= itemstack3.getMaxStackSize()) {
                itemstack3.count += l;
                itemstack1 = slot.a(l);
                if (itemstack1.count == 0) {
                  slot.set((ItemStack) null);
                }

                slot.a(entityhuman, playerinventory.getCarried());
              }
            }
          }

          slot.e();
        }
      }
    } else if (k == 2 && j >= 0 && j < 9) {
      slot = (Slot) this.c.get(i);
      if (slot.a(entityhuman)) {
        itemstack1 = playerinventory.getItem(j);
        boolean flag =
            itemstack1 == null || slot.inventory == playerinventory && slot.isAllowed(itemstack1);

        l = -1;
        if (!flag) {
          l = playerinventory.i();
          flag |= l > -1;
        }

        if (slot.d() && flag) {
          itemstack2 = slot.getItem();
          playerinventory.setItem(j, itemstack2);
          if ((slot.inventory != playerinventory || !slot.isAllowed(itemstack1))
              && itemstack1 != null) {
            if (l > -1) {
              playerinventory.pickup(itemstack1);
              slot.set((ItemStack) null);
              slot.a(entityhuman, itemstack2);
            }
          } else {
            slot.set(itemstack1);
            slot.a(entityhuman, itemstack2);
          }
        } else if (!slot.d() && itemstack1 != null && slot.isAllowed(itemstack1)) {
          playerinventory.setItem(j, (ItemStack) null);
          slot.set(itemstack1);
        }
      }
    } else if (k == 3
        && entityhuman.abilities.canInstantlyBuild
        && playerinventory.getCarried() == null
        && i >= 0) {
      slot = (Slot) this.c.get(i);
      if (slot != null && slot.d()) {
        itemstack1 = slot.getItem().cloneItemStack();
        itemstack1.count = itemstack1.getMaxStackSize();
        playerinventory.setCarried(itemstack1);
      }
    }

    return itemstack;
  }
コード例 #6
0
 @Override
 public void setWornItemAt(int slot, ItemStack item) {
   if (slot == 0) inventory.setItemAt(inventory.getCurrentHeldSlot(), item);
   else if (slot > 0 && slot <= 4) inventory.setArmorAt(slot - 1, item);
 }
コード例 #7
0
 @Override
 public ItemStack getWornItemAt(int slot) {
   return slot == 0
       ? inventory.getCurrentHeldItem()
       : slot > 0 && slot <= 4 ? inventory.getArmorAt(slot - 1) : null;
 }
コード例 #8
0
  public MainPlayerEntity(World world, MainPlayerEntity player) {
    this(world, player.getId(), player.getName(), player.getGameMode());

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