Exemplo n.º 1
0
  @Override
  public IMessage onMessage(PacketGuiId message, MessageContext ctx) {

    EntityPlayerMP p = ctx.getServerHandler().playerEntity;

    int i = message.getData().getInteger("gui");

    p.openGui(MCEconomy2.instance, i, p.worldObj, (int) p.posX, (int) p.posY, (int) p.posZ);

    return null;
  }
  /**
   * method to handle packets that were sent to the server. mostly the same as above but with
   * different handling.
   *
   * @param manager
   * @param packet
   * @param player
   * @param dat
   * @param ID
   */
  public void handleServerPacket(
      Packet packet, EntityPlayer player, ByteArrayDataInput dat, short ID) {
    EntityPlayerMP thePlayer = (EntityPlayerMP) player;
    World world = thePlayer.worldObj;

    if (ID == 1) {
      int coords[] = new int[3];

      for (int var1 = 0; var1 < 3; var1++) {
        coords[var1] = dat.readInt();
      }

      TileEntityPressurePlate tpp =
          (TileEntityPressurePlate) world.getTileEntity(coords[0], coords[1], coords[2]);
      short var3 = dat.readShort();
      StringBuilder var4 = new StringBuilder();

      for (int var5 = 0; var5 < var3; var5++) {
        var4.append(dat.readChar());
      }

      String var6 = var4.toString();
      tpp.switchMob(var6, world);
      return;
    }

    if (ID == 2) {
      int coords[] = new int[3];

      for (int var1 = 0; var1 < 3; var1++) {
        coords[var1] = dat.readInt();
      }

      TileEntityPressurePlate tpp =
          (TileEntityPressurePlate) world.getTileEntity(coords[0], coords[1], coords[2]);
      short var3 = dat.readShort();
      StringBuilder var4 = new StringBuilder();

      for (int var5 = 0; var5 < var3; var5++) {
        var4.append(dat.readChar());
      }

      String var6 = var4.toString();
      tpp.switchPlayer(var6, world);
      return;
    }

    if (ID == 3) {
      int coords[] = new int[3];

      for (int var1 = 0; var1 < 3; var1++) {
        coords[var1] = dat.readInt();
      }

      if (world.getTileEntity(coords[0], coords[1], coords[2]) instanceof TileEntityPressurePlate) {
        TileEntityPressurePlate tpp =
            (TileEntityPressurePlate) world.getTileEntity(coords[0], coords[1], coords[2]);
        int usernameLength = dat.readInt();
        String username = "";

        for (int var2 = 0; var2 < usernameLength; var2++) {
          char c = dat.readChar();
          username = new StringBuilder().append(username).append(c).toString();
        }

        int playerUsernameLength = dat.readInt();
        String playerUsername = "";

        for (int var2 = 0; var2 < playerUsernameLength; var2++) {
          char c = dat.readChar();
          playerUsername = new StringBuilder().append(playerUsername).append(c).toString();
        }

        boolean bool = tpp.addPlayer(username);
        PacketSendManager.sendAddBooleanToClient(
            bool, coords[0], coords[1], coords[2], playerUsername);
        PacketSendManager.sendPressurePlatePlayerDataToClient(tpp);
      }

      return;
    }

    if (ID == 4) {
      int coords[] = new int[3];

      for (int var1 = 0; var1 < 3; var1++) {
        coords[var1] = dat.readInt();
      }

      if (world.getTileEntity(coords[0], coords[1], coords[2]) instanceof TileEntityPressurePlate) {
        TileEntityPressurePlate tpp =
            (TileEntityPressurePlate) world.getTileEntity(coords[0], coords[1], coords[2]);
        int usernameLength = dat.readInt();
        String username = "";

        for (int var2 = 0; var2 < usernameLength; var2++) {
          char c = dat.readChar();
          username = new StringBuilder().append(username).append(c).toString();
        }

        String playerUsername = "";
        int playerUsernameLength = dat.readInt();

        for (int var3 = 0; var3 < playerUsernameLength; var3++) {
          char c = dat.readChar();
          playerUsername = new StringBuilder().append(playerUsername).append(c).toString();
        }

        boolean bool = tpp.removePlayer(username);
        PacketSendManager.sendRemoveBooleanToClient(
            bool, coords[0], coords[1], coords[2], playerUsername);
        PacketSendManager.sendPressurePlatePlayerDataToClient(tpp);
      }

      return;
    }

    if (ID == 5) {
      int coords[] = new int[3];

      for (int var1 = 0; var1 < 3; var1++) {
        coords[var1] = dat.readInt();
      }

      if (world.getTileEntity(coords[0], coords[1], coords[2]) instanceof TileEntityPressurePlate) {
        TileEntityPressurePlate tpp =
            (TileEntityPressurePlate) world.getTileEntity(coords[0], coords[1], coords[2]);
        PacketSendManager.sendPressurePlatePlayerDataToClient(tpp);
      }

      return;
    }

    if (ID == 6) {
      int[] coords = new int[3];

      for (int var2 = 0; var2 < 3; var2++) {
        coords[var2] = dat.readInt();
      }

      TileEntityPressurePlate tpp = null;

      if (world.getTileEntity(coords[0], coords[1], coords[2]) instanceof TileEntityPressurePlate) {
        tpp = (TileEntityPressurePlate) world.getTileEntity(coords[0], coords[1], coords[2]);
      }

      if (tpp != null) {
        PacketSendManager.sendPressurePlateMobDataToClient(tpp);
        PacketSendManager.sendPressurePlatePlayerDataToClient(tpp);
        PacketSendManager.sendSettingsDataToClient(tpp);
        PacketSendManager.sendChangedDataToClient(tpp);
      }

      return;
    }

    if (ID == 7) {
      PPRegistry.loggedIn = true;
    }

    if (ID == 8) {
      int coords[] = new int[3];

      for (int var1 = 0; var1 < 3; var1++) {
        coords[var1] = dat.readInt();
      }

      TileEntityPressurePlate tpp = null;

      if (world.getTileEntity(coords[0], coords[1], coords[2]) instanceof TileEntityPressurePlate) {
        tpp = (TileEntityPressurePlate) world.getTileEntity(coords[0], coords[1], coords[2]);
      }

      if (tpp != null) {
        int index = dat.readInt();
        tpp.switchSetting(index);
      }

      return;
    }

    if (ID == 9) {
      int coords[] = new int[3];

      for (int var1 = 0; var1 < 3; var1++) {
        coords[var1] = dat.readInt();
      }

      TileEntityPressurePlate tpp = null;

      if (world.getTileEntity(coords[0], coords[1], coords[2]) instanceof TileEntityPressurePlate) {
        tpp = (TileEntityPressurePlate) world.getTileEntity(coords[0], coords[1], coords[2]);
      }

      if (tpp != null) {
        int length = dat.readInt();
        StringBuilder sb = new StringBuilder();

        for (int var1 = 0; var1 < length; var1++) {
          sb.append(dat.readChar());
        }

        String s = sb.toString();
        tpp.password = s;
        PacketSendManager.sendPasswordSetToClient(tpp, player);
      }

      return;
    }

    if (ID == 10) {
      int coords[] = new int[3];

      for (int var1 = 0; var1 < 3; var1++) {
        coords[var1] = dat.readInt();
      }

      TileEntityPressurePlate tpp = null;

      if (world.getTileEntity(coords[0], coords[1], coords[2]) instanceof TileEntityPressurePlate) {
        tpp = (TileEntityPressurePlate) world.getTileEntity(coords[0], coords[1], coords[2]);
      }

      if (tpp != null) {
        int length = dat.readInt();
        StringBuilder sb = new StringBuilder();

        for (int var1 = 0; var1 < length; var1++) {
          sb.append(dat.readChar());
        }

        String s = sb.toString();
        boolean b = tpp.password.matches(s);
        PacketSendManager.sendPasswordResponseToClient(tpp, b, thePlayer);
      }

      return;
    }

    if (ID == 11) {
      int coords[] = new int[3];

      for (int var1 = 0; var1 < 3; var1++) {
        coords[var1] = dat.readInt();
      }

      TileEntityPressurePlate tpp = null;

      if (world.getTileEntity(coords[0], coords[1], coords[2]) instanceof TileEntityPressurePlate) {
        tpp = (TileEntityPressurePlate) world.getTileEntity(coords[0], coords[1], coords[2]);
      }

      if (tpp != null) {
        PacketSendManager.sendPasswordToClient(tpp, thePlayer);
      }

      return;
    }

    if (ID == 12) {
      int coords[] = new int[3];

      for (int var1 = 0; var1 < 3; var1++) {
        coords[var1] = dat.readInt();
      }

      int GuiID = dat.readInt();
      TileEntityPressurePlate tpp = null;

      if (world.getTileEntity(coords[0], coords[1], coords[2]) instanceof TileEntityPressurePlate) {
        tpp = (TileEntityPressurePlate) world.getTileEntity(coords[0], coords[1], coords[2]);
      }

      if (tpp != null) {
        thePlayer.openGui(IronPP.instance, GuiID, world, tpp.xCoord, tpp.yCoord, tpp.zCoord);
      }

      return;
    }

    if (ID == 13) {
      int coords[] = new int[3];

      for (int var1 = 0; var1 < 3; var1++) {
        coords[var1] = dat.readInt();
      }

      world.setBlockToAir(coords[0], coords[1], coords[2]);
    }
    if (ID == 14) {
      int coords[] = new int[3];

      for (int var1 = 0; var1 < 3; var1++) {
        coords[var1] = dat.readInt();
      }
      TileEntity te = world.getTileEntity(coords[0], coords[1], coords[2]);
      if (te instanceof TileEntityPressurePlate) {
        ((TileEntityPressurePlate) te).maxOutput = dat.readInt();
        ((TileEntityPressurePlate) te).itemsForMax = dat.readInt();
        PacketSendManager.sendChangedDataToClient((TileEntityPressurePlate) te);
      }
    }
  }
Exemplo n.º 3
0
  @SubscribeEvent
  public void onServerPacket(ServerCustomPacketEvent event) {

    if (!event.packet.channel().equals(Telepads.channelName)) return;

    EntityPlayerMP p = ((NetHandlerPlayServer) event.handler).playerEntity;
    ByteBufInputStream dis = new ByteBufInputStream(event.packet.payload());
    ByteBuf buf = event.packet.payload();

    World world = p.worldObj;

    int x = (int) p.posX;
    int y = (int) p.posY;
    int z = (int) p.posZ;

    try {

      int packetID = dis.readInt();

      int x2 = dis.readInt();
      int y2 = dis.readInt();
      int z2 = dis.readInt();

      TETelepad pad = (TETelepad) p.worldObj.getTileEntity(x2, y2, z2);

      switch (packetID) {
        case IDENTIFIER_GUI:
          int id = dis.readInt();
          p.openGui(Telepads.instance, id, world, x2, y2, z2);
          break;

        case IDENTIFIER_NAMEPAD:
          String name = dis.readUTF();
          String channel = dis.readUTF();

          pad.telepadname = name;
          pad.TELEPORTCHANNEL = channel;

          TelepadWorldData.get(world).addPad(pad);
          pad.markDirty();
          TelepadWorldData.get(world).markDirty();

          ByteBuf buff = Unpooled.buffer();
          ByteBufOutputStream out = new ByteBufOutputStream(buff);
          try {

            out.writeInt(ServerPacketHandler.IDENTIFIER_NAMEPAD);
            out.writeInt(x2);
            out.writeInt(y2);
            out.writeInt(z2);
            out.writeUTF(name);
            out.writeUTF(channel);
            out.close();

            if (!p.worldObj.isRemote)
              Telepads.Channel.sendTo(new FMLProxyPacket(buf, Telepads.channelName), p);

          } catch (IOException e) {
            e.printStackTrace();
          }
          break;

        case IDENTIFIER_TELEPORTER:
          if (dis.readInt() == GuiTeleport.EXIT_BUTTON) {
            pad.resetTE();
            pad.getDescriptionPacket();
            break;
          } else {
            // reset pad BEFORE the player gets teleported, or else it might be out of range and
            // can't be reset
            pad.resetTE();
            pad.getDescriptionPacket();

            int otherPadX = dis.readInt();
            int otherPadY = dis.readInt();
            int otherPadZ = dis.readInt();

            int dimID = dis.readInt();

            // if the dimension id = the End, play endscreen and teleport to spawn point.
            // this is needed or game will act funny if you don't.
            if (dimID != p.worldObj.provider.dimensionId) {
              if (p.worldObj.provider.dimensionId == 1) {
                p.travelToDimension(1);
              } else {
                p.travelToDimension(dimID);
                p.setPositionAndUpdate(otherPadX + 2, otherPadY + 0.5d, otherPadZ);
              }

            } else {
              p.setPositionAndUpdate(otherPadX + 2, otherPadY + 0.5d, otherPadZ);
            }
          }

          break;

        case IDENTIFIER_PLATFORM:
          boolean b = dis.readBoolean();

          pad.isStandingOnPlatform = b;

          if (b == false) {
            pad.resetTE();
            pad.playerStandingOnPad = null;
          }

          break;

        case IDENTIFIER_RESETnNOTIFY:
          p.addChatMessage(new ChatComponentText(dis.readUTF()));
          pad.resetTE();
          break;
      }

      dis.close();
    } catch (Exception e) {
      e.printStackTrace();
    }
  }