Exemplo n.º 1
0
  public static void applyShape(
      IShape shape,
      EntityPlayer player,
      ArrayList<NBTTagCompound> blockDataNbtList,
      byte baseRotation) {
    try {
      ArrayList<BlockData> blockDataList = new ArrayList<>();
      for (NBTTagCompound compound : blockDataNbtList) {
        BlockData blockData = new BlockData(compound);
        for (int i = 0; i <= blockData.weight; i++) blockDataList.add(blockData);
      }

      int x = Helper.round(player.posX),
          y = Helper.round(player.posY + 1),
          z = Helper.round(player.posZ);
      Collection<PointI> points =
          shape
              .rotate(baseRotation)
              .rotate(baseRotation == -1 ? -1 : Helper.getHeading(player))
              .move(x, y, z)
              .getPoints();
      for (PointI p : points) {
        if (!shape.getReplaceableOnly()
            || player
                .worldObj
                .getBlock(p.getX(), p.getY(), p.getZ())
                .isReplaceable(player.worldObj, p.getX(), p.getY(), p.getZ())) {
          BlockData block =
              blockDataList.size() == 1
                  ? blockDataList.get(0)
                  : Helper.getRandomFromSet(blockDataList);
          Block block1 = Block.getBlockById(block.id);
          player.worldObj.setBlock(p.getX(), p.getY(), p.getZ(), block1, block.meta, 2);
          if (block.te != null) {
            TileEntity tileEntity = TileEntity.createAndLoadEntity(block.te);
            tileEntity.setWorldObj(player.worldObj);
            tileEntity.xCoord = p.getX();
            tileEntity.yCoord = p.getY();
            tileEntity.zCoord = p.getZ();
            player.worldObj.setTileEntity(p.getX(), p.getY(), p.getZ(), tileEntity);
          }
        }
      }
    } catch (BlockData.BannedBlockException e) {
      ((EntityPlayerMP) player).playerNetServerHandler.kickPlayerFromServer(e.getMessage());
    } catch (Exception e) {
      e.printStackTrace();
      Pay2Spawn.getLogger().warn("Error spawning in shape.");
      Pay2Spawn.getLogger().warn("Shape: " + shape.toString());
      Pay2Spawn.getLogger().warn("Player: " + player);
      Pay2Spawn.getLogger()
          .warn("BlockData array: " + Arrays.deepToString(blockDataNbtList.toArray()));
    }
  }
Exemplo n.º 2
0
  /**
   * Connects to the API and attempt to process any donations
   *
   * @param firstRun <code>boolean</code> used to identify previous donations that should not be
   *     processed.
   */
  private void processDonationAPI(boolean firstRun) {
    try {
      JsonArray donations =
          JSON_PARSER
              .parse(
                  Helper.readUrl(
                      new URL(firstRun ? URL + "?sort=amount" : URL),
                      new String[] {"authorization", String.format(HEADER, APIKey)}))
              .getAsJsonArray();
      for (JsonElement jsonElement : donations) {
        Donation donation = getDonation(jsonElement.getAsJsonObject());

        // Make sure we have a donation to work with and see if this is a first run
        if (donation != null && firstRun) {
          // This is a first run so add to current list/done ids
          topDonationsBasedHudEntry.add(donation);
          doneIDs.add(donation.id);
        } else if (donation != null) {
          // We have a donation and this is a loop check so process the donation
          process(donation, true, this);
        }
      }
    } catch (IOException e) {
      e.printStackTrace();
    }
  }