예제 #1
0
 public static void writeItem(NetOutput out, ItemStack item) throws IOException {
   if (item == null) {
     out.writeShort(-1);
   } else {
     out.writeShort(item.getId());
     out.writeByte(item.getAmount());
     out.writeShort(item.getData());
     writeNBT(out, item.getNBT());
   }
 }
예제 #2
0
  private static void writeWatchableObject(
      DataOutputStream par0DataOutputStream, WatchableObject par1WatchableObject)
      throws IOException {
    int i =
        (par1WatchableObject.getObjectType() << 5 | par1WatchableObject.getDataValueId() & 0x1f)
            & 0xff;
    par0DataOutputStream.writeByte(i);

    switch (par1WatchableObject.getObjectType()) {
      case 0:
        par0DataOutputStream.writeByte(((Byte) par1WatchableObject.getObject()).byteValue());
        break;

      case 1:
        par0DataOutputStream.writeShort(((Short) par1WatchableObject.getObject()).shortValue());
        break;

      case 2:
        par0DataOutputStream.writeInt(((Integer) par1WatchableObject.getObject()).intValue());
        break;

      case 3:
        par0DataOutputStream.writeFloat(((Float) par1WatchableObject.getObject()).floatValue());
        break;

      case 4:
        Packet.writeString((String) par1WatchableObject.getObject(), par0DataOutputStream);
        break;

      case 5:
        ItemStack itemstack = (ItemStack) par1WatchableObject.getObject();
        par0DataOutputStream.writeShort(itemstack.getItem().shiftedIndex);
        par0DataOutputStream.writeByte(itemstack.stackSize);
        par0DataOutputStream.writeShort(itemstack.getItemDamage());
        break;

      case 6:
        ChunkCoordinates chunkcoordinates = (ChunkCoordinates) par1WatchableObject.getObject();
        par0DataOutputStream.writeInt(chunkcoordinates.posX);
        par0DataOutputStream.writeInt(chunkcoordinates.posY);
        par0DataOutputStream.writeInt(chunkcoordinates.posZ);
        break;
    }
  }
  /** Handle a creative slot packet. */
  public void handleCreativeSetSlot(Packet107CreativeSetSlot par1Packet107CreativeSetSlot) {
    if (playerEntity.theItemInWorldManager.isCreative()) {
      boolean flag = par1Packet107CreativeSetSlot.slot < 0;
      ItemStack itemstack = par1Packet107CreativeSetSlot.itemStack;
      boolean flag1 =
          par1Packet107CreativeSetSlot.slot >= 1
              && par1Packet107CreativeSetSlot.slot < 36 + InventoryPlayer.func_70451_h();
      boolean flag2 =
          itemstack == null
              || itemstack.itemID < Item.itemsList.length
                  && itemstack.itemID >= 0
                  && Item.itemsList[itemstack.itemID] != null;
      boolean flag3 =
          itemstack == null
              || itemstack.getItemDamage() >= 0
                  && itemstack.getItemDamage() >= 0
                  && itemstack.stackSize <= 64
                  && itemstack.stackSize > 0;

      if (flag1 && flag2 && flag3) {
        if (itemstack == null) {
          playerEntity.inventorySlots.putStackInSlot(par1Packet107CreativeSetSlot.slot, null);
        } else {
          playerEntity.inventorySlots.putStackInSlot(par1Packet107CreativeSetSlot.slot, itemstack);
        }

        playerEntity.inventorySlots.setPlayerIsPresent(playerEntity, true);
      } else if (flag && flag2 && flag3 && creativeItemCreationSpamThresholdTally < 200) {
        creativeItemCreationSpamThresholdTally += 20;
        EntityItem entityitem = playerEntity.dropPlayerItem(itemstack);

        if (entityitem != null) {
          entityitem.func_70288_d();
        }
      }
    }
  }
  public void handleWindowClick(Packet102WindowClick par1Packet102WindowClick) {
    if (playerEntity.craftingInventory.windowId == par1Packet102WindowClick.window_Id
        && playerEntity.craftingInventory.isPlayerNotUsingContainer(playerEntity)) {
      ItemStack itemstack =
          playerEntity.craftingInventory.slotClick(
              par1Packet102WindowClick.inventorySlot,
              par1Packet102WindowClick.mouseClick,
              par1Packet102WindowClick.holdingShift,
              playerEntity);

      if (ItemStack.areItemStacksEqual(par1Packet102WindowClick.itemStack, itemstack)) {
        playerEntity.serverForThisPlayer.sendPacketToPlayer(
            new Packet106Transaction(
                par1Packet102WindowClick.window_Id, par1Packet102WindowClick.action, true));
        playerEntity.playerInventoryBeingManipulated = true;
        playerEntity.craftingInventory.updateCraftingResults();
        playerEntity.sendInventoryToPlayer();
        playerEntity.playerInventoryBeingManipulated = false;
      } else {
        field_72586_s.addKey(
            playerEntity.craftingInventory.windowId,
            Short.valueOf(par1Packet102WindowClick.action));
        playerEntity.serverForThisPlayer.sendPacketToPlayer(
            new Packet106Transaction(
                par1Packet102WindowClick.window_Id, par1Packet102WindowClick.action, false));
        playerEntity.craftingInventory.setPlayerIsPresent(playerEntity, false);
        ArrayList arraylist = new ArrayList();

        for (int i = 0; i < playerEntity.craftingInventory.inventorySlots.size(); i++) {
          arraylist.add(((Slot) playerEntity.craftingInventory.inventorySlots.get(i)).getStack());
        }

        playerEntity.sendContainerAndContentsToPlayer(playerEntity.craftingInventory, arraylist);
      }
    }
  }
예제 #5
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;
   }
 }
  public void handlePlace(Packet15Place par1Packet15Place) {
    WorldServer worldserver = mcServer.worldServerForDimension(playerEntity.dimension);
    ItemStack itemstack = playerEntity.inventory.getCurrentItem();
    boolean flag = false;
    int i = par1Packet15Place.getXPosition();
    int j = par1Packet15Place.getYPosition();
    int k = par1Packet15Place.getZPosition();
    int l = par1Packet15Place.getDirection();
    boolean flag1 =
        worldserver.actionsAllowed =
            worldserver.provider.worldType != 0
                || mcServer.getConfigurationManager().areCommandsAllowed(playerEntity.username)
                || mcServer.isSinglePlayer();

    if (par1Packet15Place.getDirection() == 255) {
      if (itemstack == null) {
        return;
      }

      playerEntity.theItemInWorldManager.tryUseItem(playerEntity, worldserver, itemstack);
    } else if (par1Packet15Place.getYPosition() < mcServer.getBuildLimit() - 1
        || par1Packet15Place.getDirection() != 1
            && par1Packet15Place.getYPosition() < mcServer.getBuildLimit()) {
      ChunkCoordinates chunkcoordinates = worldserver.getSpawnPoint();
      int i1 = MathHelper.abs_int(i - chunkcoordinates.posX);
      int j1 = MathHelper.abs_int(k - chunkcoordinates.posZ);

      if (i1 > j1) {
        j1 = i1;
      }

      if (field_72587_r
          && playerEntity.getDistanceSq((double) i + 0.5D, (double) j + 0.5D, (double) k + 0.5D)
              < 64D
          && (j1 > 16 || flag1)) {
        playerEntity.theItemInWorldManager.activateBlockOrUseItem(
            playerEntity,
            worldserver,
            itemstack,
            i,
            j,
            k,
            l,
            par1Packet15Place.getXOffset(),
            par1Packet15Place.getYOffset(),
            par1Packet15Place.getZOffset());
      }

      flag = true;
    } else {
      playerEntity.serverForThisPlayer.sendPacketToPlayer(
          new Packet3Chat(
              (new StringBuilder())
                  .append("\2477Height limit for building is ")
                  .append(mcServer.getBuildLimit())
                  .toString()));
      flag = true;
    }

    if (flag) {
      playerEntity.serverForThisPlayer.sendPacketToPlayer(
          new Packet53BlockChange(i, j, k, worldserver));

      if (l == 0) {
        j--;
      }

      if (l == 1) {
        j++;
      }

      if (l == 2) {
        k--;
      }

      if (l == 3) {
        k++;
      }

      if (l == 4) {
        i--;
      }

      if (l == 5) {
        i++;
      }

      playerEntity.serverForThisPlayer.sendPacketToPlayer(
          new Packet53BlockChange(i, j, k, worldserver));
    }

    itemstack = playerEntity.inventory.getCurrentItem();

    if (itemstack != null && itemstack.stackSize == 0) {
      playerEntity.inventory.mainInventory[playerEntity.inventory.currentItem] = null;
      itemstack = null;
    }

    if (itemstack == null || itemstack.getMaxItemUseDuration() == 0) {
      playerEntity.playerInventoryBeingManipulated = true;
      playerEntity.inventory.mainInventory[playerEntity.inventory.currentItem] =
          ItemStack.copyItemStack(
              playerEntity.inventory.mainInventory[playerEntity.inventory.currentItem]);
      Slot slot =
          playerEntity.craftingInventory.getSlotFromInventory(
              playerEntity.inventory, playerEntity.inventory.currentItem);
      playerEntity.craftingInventory.updateCraftingResults();
      playerEntity.playerInventoryBeingManipulated = false;

      if (!ItemStack.areItemStacksEqual(
          playerEntity.inventory.getCurrentItem(), par1Packet15Place.getItemStack())) {
        sendPacketToPlayer(
            new Packet103SetSlot(
                playerEntity.craftingInventory.windowId,
                slot.slotNumber,
                playerEntity.inventory.getCurrentItem()));
      }
    }

    worldserver.actionsAllowed = false;
  }
  public void handleCustomPayload(Packet250CustomPayload par1Packet250CustomPayload) {
    if ("MC|BEdit".equals(par1Packet250CustomPayload.channel)) {
      try {
        DataInputStream datainputstream =
            new DataInputStream(new ByteArrayInputStream(par1Packet250CustomPayload.data));
        ItemStack itemstack = Packet.readItemStack(datainputstream);

        if (!ItemWritableBook.validBookTagPages(itemstack.getTagCompound())) {
          throw new IOException("Invalid book tag!");
        }

        ItemStack itemstack2 = playerEntity.inventory.getCurrentItem();

        if (itemstack != null
            && itemstack.itemID == Item.writableBook.shiftedIndex
            && itemstack.itemID == itemstack2.itemID) {
          itemstack2.setTagCompound(itemstack.getTagCompound());
        }
      } catch (Exception exception) {
        exception.printStackTrace();
      }
    } else if ("MC|BSign".equals(par1Packet250CustomPayload.channel)) {
      try {
        DataInputStream datainputstream1 =
            new DataInputStream(new ByteArrayInputStream(par1Packet250CustomPayload.data));
        ItemStack itemstack1 = Packet.readItemStack(datainputstream1);

        if (!ItemEditableBook.validBookTagContents(itemstack1.getTagCompound())) {
          throw new IOException("Invalid book tag!");
        }

        ItemStack itemstack3 = playerEntity.inventory.getCurrentItem();

        if (itemstack1 != null
            && itemstack1.itemID == Item.writtenBook.shiftedIndex
            && itemstack3.itemID == Item.writableBook.shiftedIndex) {
          itemstack3.setTagCompound(itemstack1.getTagCompound());
          itemstack3.itemID = Item.writtenBook.shiftedIndex;
        }
      } catch (Exception exception1) {
        exception1.printStackTrace();
      }
    } else if ("MC|TrSel".equals(par1Packet250CustomPayload.channel)) {
      try {
        DataInputStream datainputstream2 =
            new DataInputStream(new ByteArrayInputStream(par1Packet250CustomPayload.data));
        int i = datainputstream2.readInt();
        Container container = playerEntity.craftingInventory;

        if (container instanceof ContainerMerchant) {
          ((ContainerMerchant) container).setCurrentRecipeIndex(i);
        }
      } catch (Exception exception2) {
        exception2.printStackTrace();
      }
    } else {
      ModLoader.serverCustomPayload(this, par1Packet250CustomPayload);
    }
  }