Пример #1
0
  /** checks to make sure painting can be placed there */
  public boolean onValidSurface() {
    if (worldObj.getCollidingBoundingBoxes(this, boundingBox).size() > 0) {
      return false;
    }

    int i = art.sizeX / 16;
    int j = art.sizeY / 16;
    int k = xPosition;
    int l = yPosition;
    int i1 = zPosition;

    if (direction == 0) {
      k = MathHelper.floor_double(posX - (double) ((float) art.sizeX / 32F));
    }

    if (direction == 1) {
      i1 = MathHelper.floor_double(posZ - (double) ((float) art.sizeX / 32F));
    }

    if (direction == 2) {
      k = MathHelper.floor_double(posX - (double) ((float) art.sizeX / 32F));
    }

    if (direction == 3) {
      i1 = MathHelper.floor_double(posZ - (double) ((float) art.sizeX / 32F));
    }

    l = MathHelper.floor_double(posY - (double) ((float) art.sizeY / 32F));

    for (int j1 = 0; j1 < i; j1++) {
      for (int k1 = 0; k1 < j; k1++) {
        Material material;

        if (direction == 0 || direction == 2) {
          material = worldObj.getBlockMaterial(k + j1, l + k1, zPosition);
        } else {
          material = worldObj.getBlockMaterial(xPosition, l + k1, i1 + j1);
        }

        if (!material.isSolid()) {
          return false;
        }
      }
    }

    List list = worldObj.getEntitiesWithinAABBExcludingEntity(this, boundingBox);

    for (int l1 = 0; l1 < list.size(); l1++) {
      if (list.get(l1) instanceof EntityPainting) {
        return false;
      }
    }

    return true;
  }
Пример #2
0
  public ItemStack parseItemStack(String itemstr) {
    if (itemstr.isEmpty()) return null;

    String istr = itemstr;
    String enchant = "";
    String name = "";

    if (istr.contains("$")) {
      name = istr.substring(0, istr.indexOf("$"));
      istr = istr.substring(name.length() + 1);
    }
    if (istr.contains("@")) {
      enchant = istr.substring(istr.indexOf("@") + 1);
      istr = istr.substring(0, istr.indexOf("@"));
    }
    int id = -1;
    int amount = 1;
    short data = 0;
    String[] si = istr.split("\\*");

    if (si.length > 0) {
      if (si.length == 2) amount = Math.max(getMinMaxRandom(si[1]), 1);
      String ti[] = si[0].split(":");
      if (ti.length > 0) {
        if (ti[0].matches("[0-9]*")) id = Integer.parseInt(ti[0]);
        else {
          Material m = Material.getMaterial(ti[0].toUpperCase());
          if (m == null) {
            logOnce("wrongitem" + ti[0], "Could not parse item material name (id) " + ti[0]);
            return null;
          }
          id = m.getId();
        }
        if ((ti.length == 2) && (ti[1]).matches("[0-9]*")) data = Short.parseShort(ti[1]);
        ItemStack item = new ItemStack(id, amount, data);
        if (!enchant.isEmpty()) {
          item = setEnchantments(item, enchant);
        }
        if (!name.isEmpty()) {
          ItemMeta im = item.getItemMeta();
          im.setDisplayName(ChatColor.translateAlternateColorCodes('&', name.replace("_", " ")));
          item.setItemMeta(im);
        }
        return item;
      }
    }
    return null;
  }
Пример #3
0
  public void fuelRemove(Player player, Material block, Material single, int cost) {

    Inventory fuelInventory = getFuelInventory(player);

    for (ItemStack item : fuelInventory.getContents())
      if (item != null) if (item.getAmount() <= 0) item.setType(Material.AIR);

    if (!blockStacks.split(fuelInventory, block, single, cost, (9 - cost))) {
      commonString.messageSend(
          RocketInit.getPlugin(),
          player,
          true,
          RocketLanguage.FuelOutage(single.toString().toLowerCase()));
      disableRocketBoots(player, true, true, true, true, true);
    }

    try {

      Material jacketType = player.getInventory().getChestplate().getType();
      FileConfiguration fuelConfig = getFuelConfig(player);

      fuelConfig.set(getFuelJacketConfigString(jacketType), fuelInventory.getContents());
      fuelConfig.save(getFuelFile(player));

    } catch (IOException e) {
      commonString.messageSend(
          RocketInit.getPlugin(), player, true, RocketLanguage.RB_JACKET_SAVE_ERROR);
      e.printStackTrace();
    }
  }
Пример #4
0
 private void readAdditionalRenderState(List<Statement> renderStates) throws IOException {
   renderState = material.getAdditionalRenderState();
   for (Statement statement : renderStates) {
     readRenderStateStatement(statement);
   }
   renderState = null;
 }
Пример #5
0
 private void readTransparentStatement(String statement) throws IOException {
   String[] split = statement.split(whitespacePattern);
   if (split.length != 2) {
     throw new IOException("Transparent statement syntax incorrect");
   }
   material.setTransparent(parseBoolean(split[1]));
 }
Пример #6
0
  private List<TextureOptionValue> parseTextureOptions(final List<String> values) {
    final List<TextureOptionValue> matchList = new ArrayList<TextureOptionValue>();

    if (values.isEmpty() || values.size() == 1) {
      return matchList;
    }

    // Loop through all but the last value, the last one is going to be the path.
    for (int i = 0; i < values.size() - 1; i++) {
      final String value = values.get(i);
      final TextureOption textureOption = TextureOption.getTextureOption(value);

      if (textureOption == null
          && !value.contains("\\")
          && !value.contains("/")
          && !values.get(0).equals("Flip")
          && !values.get(0).equals("Repeat")) {
        logger.log(
            Level.WARNING,
            "Unknown texture option \"{0}\" encountered for \"{1}\" in material \"{2}\"",
            new Object[] {value, key, material.getKey().getName()});
      } else if (textureOption != null) {
        final String option = textureOption.getOptionValue(value);
        matchList.add(new TextureOptionValue(textureOption, option));
      }
    }

    return matchList;
  }
Пример #7
0
 /*
  * Установка блока с проверкой на приват
  */
 public boolean placeBlock(Block block, Player p, Material newType, byte newData, boolean phys) {
   BlockState state = block.getState();
   block.setTypeIdAndData(newType.getId(), newData, phys);
   BlockPlaceEvent event =
       new BlockPlaceEvent(state.getBlock(), state, block, p.getItemInHand(), p, true);
   plg.getServer().getPluginManager().callEvent(event);
   if (event.isCancelled()) state.update(true);
   return event.isCancelled();
 }
Пример #8
0
  public int func_35840_c(int i, int j) {
    int k = i | j << 4;
    int l = field_35845_c[k];
    if (l == -999) {
      int i1 = field_1537_d.field_35472_c - 1;
      for (l = -1; i1 > 0 && l == -1; ) {
        int j1 = func_1008_a(i, i1, j);
        Material material = j1 != 0 ? Block.field_345_n[j1].field_356_bn : Material.field_1337_a;
        if (!material.func_880_c() && !material.func_879_d()) {
          i1--;
        } else {
          l = i1 + 1;
        }
      }

      field_35845_c[k] = l;
    }
    return l;
  }
Пример #9
0
  private void readValueParam(String statement) throws IOException {
    // Use limit=1 incase filename contains colons
    String[] split = statement.split(":", 2);
    if (split.length != 2) {
      throw new IOException("Value parameter statement syntax incorrect");
    }
    String name = split[0].trim();

    // parse value
    MatParam p = material.getMaterialDef().getMaterialParam(name);
    if (p == null) {
      throw new IOException("The material parameter: " + name + " is undefined.");
    }

    Object valueObj = readValue(p.getVarType(), split[1]);
    if (p.getVarType().isTextureType()) {
      material.setTextureParam(name, p.getVarType(), (Texture) valueObj);
    } else {
      material.setParam(name, p.getVarType(), valueObj);
    }
  }
Пример #10
0
  public static void newSpec() {
    List<Material> materials = Material.findAll();
    String username = session.get("username");
    if (username != null) {

      User user = User.getByUserName(username);
      if (user.role.name.equalsIgnoreCase("operator")) {
        materials = user.materials;
      }
    }
    render(materials);
  }
Пример #11
0
  public boolean fuelCheck(Player player, Material single, Material block) {

    Inventory fuelInventory = getFuelInventory(player);
    ItemStack rocketBoots = player.getInventory().getBoots();

    int fuelCost = 0;

    switch (rocketBoots.getType()) {
      case LEATHER_BOOTS:
        fuelCost = 1 + getBootPowerLevel(rocketBoots);
        break;

      case IRON_BOOTS:
        fuelCost = 2 + getBootPowerLevel(rocketBoots);
        break;

      case GOLD_BOOTS:
        fuelCost = 3 + getBootPowerLevel(rocketBoots);
        break;

      case DIAMOND_BOOTS:
        fuelCost = 4 + getBootPowerLevel(rocketBoots);
        break;
    }

    if (fuelInventory.containsAtLeast(new ItemStack(block), fuelCost)) return true;
    if (fuelInventory.containsAtLeast(new ItemStack(single), fuelCost)) return true;

    commonString.messageSend(
        RocketInit.getPlugin(),
        player,
        true,
        RocketLanguage.FuelRequired(single.name().toLowerCase()));
    RocketInit.rocketTimeout.add(player.getUniqueId());

    new BukkitRunnable() {
      int c = 5;

      @Override
      public void run() {
        if (c <= 0) {
          RocketInit.rocketTimeout.remove(player.getUniqueId());
          this.cancel();
          return;
        }
        player.setFlying(false);
        c--;
      }
    }.runTaskTimer(RocketInit.getPlugin(), 0, 20);

    return false;
  }
Пример #12
0
  /** Clones this material. The result is returned. */
  @Override
  public Material clone() {
    try {
      Material mat = (Material) super.clone();

      if (additionalState != null) {
        mat.additionalState = additionalState.clone();
      }
      mat.technique = null;
      mat.techniques = new HashMap<String, Technique>();

      mat.paramValues = new ListMap<String, MatParam>();
      for (int i = 0; i < paramValues.size(); i++) {
        Map.Entry<String, MatParam> entry = paramValues.getEntry(i);
        mat.paramValues.put(entry.getKey(), entry.getValue().clone());
      }

      return mat;
    } catch (CloneNotSupportedException ex) {
      throw new AssertionError(ex);
    }
  }
Пример #13
0
  public static void editSpec(Long id) {
    Specification spec = null;
    if (id != null) spec = Specification.findById(id);
    List<Material> materials = Material.findAll();
    String username = session.get("username");
    if (username != null) {

      User user = User.getByUserName(username);
      if (user.role.name.equalsIgnoreCase("operator")) {
        materials = user.materials;
      }
    }
    render(spec, materials);
  }
Пример #14
0
  public int removeItemInInventory(Inventory inv, String istr) {
    String itemstr = istr;
    int left = 1;
    if (left <= 0) return -1;
    int id = -1;
    int data = -1;
    String name = "";

    if (itemstr.contains("$")) {
      name = itemstr.substring(0, itemstr.indexOf("$"));
      itemstr = itemstr.substring(name.length() + 1);
    }

    String[] si = itemstr.split("\\*");
    if (si.length == 0) return left;
    if ((si.length == 2) && si[1].matches("[1-9]+[0-9]*")) left = Integer.parseInt(si[1]);
    String ti[] = si[0].split(":");

    if (ti.length > 0) {
      if (ti[0].matches("[0-9]*")) id = Integer.parseInt(ti[0]);
      else id = Material.getMaterial(ti[0]).getId();
      if ((ti.length == 2) && (ti[1]).matches("[0-9]*")) data = Integer.parseInt(ti[1]);
    }
    if (id <= 0) return left;
    for (int i = 0; i < inv.getContents().length; i++) {
      ItemStack slot = inv.getItem(i);
      if (slot == null) continue;
      if (!compareItemName(slot, name)) continue;
      if (id != slot.getTypeId()) continue;
      if ((data > 0) && (data != slot.getDurability())) continue;
      int slotamount = slot.getAmount();
      if (slotamount == 0) continue;
      if (slotamount <= left) {
        left = left - slotamount;
        inv.setItem(i, null);
      } else {
        slot.setAmount(slotamount - left);
        left = 0;
      }
      if (left == 0) return 0;
    }
    return left;
  }
Пример #15
0
 public boolean removeItemInHand(Player p, String itemstr) {
   if (!itemstr.isEmpty()) {
     int id = -1;
     int amount = 1;
     int data = -1;
     String[] si = itemstr.split("\\*");
     if (si.length > 0) {
       if ((si.length == 2) && si[1].matches("[1-9]+[0-9]*")) amount = Integer.parseInt(si[1]);
       String ti[] = si[0].split(":");
       if (ti.length > 0) {
         if (ti[0].matches("[0-9]*")) id = Integer.parseInt(ti[0]);
         else id = Material.getMaterial(ti[0]).getId();
         if ((ti.length == 2) && (ti[1]).matches("[0-9]*")) data = Integer.parseInt(ti[1]);
         return removeItemInHand(p, id, data, amount);
       }
     }
   }
   return false;
 }
Пример #16
0
 public boolean compareItemStrIgnoreName(
     int item_id, int item_data, int item_amount, String itemstr) {
   if (!itemstr.isEmpty()) {
     int id = -1;
     int amount = 1;
     int data = -1;
     String[] si = itemstr.split("\\*");
     if (si.length > 0) {
       if ((si.length == 2) && si[1].matches("[1-9]+[0-9]*")) amount = Integer.parseInt(si[1]);
       String ti[] = si[0].split(":");
       if (ti.length > 0) {
         if (ti[0].matches("[0-9]*")) id = Integer.parseInt(ti[0]);
         else id = Material.getMaterial(ti[0]).getId();
         if ((ti.length == 2) && (ti[1]).matches("[0-9]*")) data = Integer.parseInt(ti[1]);
         return ((item_id == id)
             && ((data < 0) || (item_data == data))
             && (item_amount >= amount));
       }
     }
   }
   return false;
 }
Пример #17
0
 @Override
 public ItemStack getItemStack(final String path) {
   final ItemStack stack =
       new ItemStack(
           Material.valueOf(getString(path + ".type", "AIR")),
           getInt(path + ".amount", 1),
           (short) getInt(path + ".damage", 0));
   final ConfigurationSection enchants = getConfigurationSection(path + ".enchant");
   if (enchants != null) {
     for (String enchant : enchants.getKeys(false)) {
       final Enchantment enchantment = Enchantment.getByName(enchant.toUpperCase(Locale.ENGLISH));
       if (enchantment == null) {
         continue;
       }
       final int level = getInt(path + ".enchant." + enchant, enchantment.getStartLevel());
       stack.addUnsafeEnchantment(enchantment, level);
     }
   }
   return stack;
   /*
    * ,
    * (byte)getInt(path + ".data", 0)
    */
 }
Пример #18
0
  public int countItemInInventory(Inventory inv, String istr) {
    String itemstr = istr;
    int count = 0;
    int id = -1;
    int data = -1;
    String name = "";
    if (itemstr.contains("$")) {
      name = itemstr.substring(0, itemstr.indexOf("$"));
      itemstr = itemstr.substring(name.length() + 1);
    }

    String[] si = itemstr.split("\\*");
    if (si.length == 0) return 0;

    String ti[] = si[0].split(":");
    if (ti.length > 0) {
      try {
        if (ti[0].matches("[0-9]*")) id = Integer.parseInt(ti[0]);
        else id = Material.getMaterial(ti[0].toUpperCase()).getId();
      } catch (Exception e) {
        logOnce(istr, "Wrong material type/id " + ti[0] + " at line " + istr);
        return 0;
      }
      if ((ti.length == 2) && (ti[1]).matches("[0-9]*")) data = Integer.parseInt(ti[1]);
    }
    if (id <= 0) return 0;

    for (ItemStack slot : inv.getContents()) {
      if (slot == null) continue;
      if (!compareItemName(slot, name)) continue;
      if (id == slot.getTypeId()) {
        if ((data < 0) || (data == slot.getDurability())) count += slot.getAmount();
      }
    }
    return count;
  }
Пример #19
0
  public static void register() {

    List<Material> materialList = Material.findAll();
    render(materialList);
  }
Пример #20
0
 public void setDiffuseColor(int diffuseColor) {
   material.diffuseColor = diffuseColor;
 }
Пример #21
0
  public static void imp(File file) {
    String result = "";
    String profiles = "";
    int imported = 0;
    int missed = 0;

    if (file != null) {

      Config config = Config.find("1=1").first();

      FileInputStream fileInputStream = null;
      HSSFWorkbook workbook = null;
      try {
        fileInputStream = new FileInputStream(file);
        workbook = new HSSFWorkbook(fileInputStream);
      } catch (FileNotFoundException e) {
        e.printStackTrace();
      } catch (IOException e) {
        e.printStackTrace();
      }

      Profile profile = null;
      User user = null;
      String value = "";
      Material material = null;

      SendMessage m = new SendMessage();
      for (int x = 0; x < workbook.getNumberOfSheets(); x++) {

        HSSFSheet worksheet = workbook.getSheetAt(x);
        HSSFRow row = null;
        HSSFCell cell = null;
        DecimalFormat df = new DecimalFormat("#");
        df.setMaximumFractionDigits(0);

        for (int i = 1; i < worksheet.getLastRowNum(); i++) {
          String unit = "万元";
          String business = "0";
          try {
            row = worksheet.getRow(i);
            if (row.getLastCellNum() < 22) {
              continue;
            }
            cell = row.getCell(0);
            value = cell.getStringCellValue();
            user = User.find("username=?", value).first();
            if (user == null) {
              user = new User(value, getRandomPwd(), ApplicationRole.getByName("user"));
              user.save();
            }

            profile = Profile.find("user.id=?", user.id).first();
            if (profile == null) {
              profile = new Profile();
              profile.user = user;
            }

            profile.is_audit = 1;
            cell = row.getCell(1);
            value = cell.getStringCellValue();
            profile.name = value;

            cell = row.getCell(2);
            value = cell.getStringCellValue();
            material = Material.find("name=?", value).first();
            if (material == null) {
              material = new Material();
              material.name = value;
              material.save();
            }
            if (!profile.materials.contains(material)) profile.materials.add(material);

            cell = row.getCell(3);
            if (cell.getCellType() == Cell.CELL_TYPE_NUMERIC) {
              value = String.valueOf(cell.getNumericCellValue());
            } else {
              value = cell.getStringCellValue();
            }

            cell = row.getCell(4);
            if (cell.getCellType() == Cell.CELL_TYPE_NUMERIC) {
              value = String.valueOf(cell.getNumericCellValue());
            } else {
              value = cell.getStringCellValue();
            }

            cell = row.getCell(5);
            if (cell.getCellType() == Cell.CELL_TYPE_NUMERIC) {
              value = String.valueOf(cell.getNumericCellValue());
            } else {
              value = cell.getStringCellValue();
            }
            profile.registration_number = value;

            cell = row.getCell(6);
            if (cell.getCellType() == Cell.CELL_TYPE_NUMERIC) {
              df.setMaximumFractionDigits(2);
              value = String.valueOf(df.format(cell.getNumericCellValue()));
            } else {
              value = cell.getStringCellValue();
            }
            if (value.contains("美元")) {
              value = value.replace("(美元)", "").trim();
              unit = "万美元";
            }
            profile.registration_assets = value;
            profile.registration_assets_unit = unit;

            df.setMaximumFractionDigits(0);
            cell = row.getCell(7);
            if (cell.getCellType() == Cell.CELL_TYPE_NUMERIC) {
              value = String.valueOf(cell.getNumericCellValue());
            } else {
              value = cell.getStringCellValue();
            }
            profile.registration_address = value;

            cell = row.getCell(8);
            if (cell.getCellType() == Cell.CELL_TYPE_NUMERIC) {
              value = String.valueOf(cell.getNumericCellValue());
            } else {
              value = cell.getStringCellValue();
            }
            profile.bank_name = value;

            cell = row.getCell(9);
            if (cell.getCellType() == Cell.CELL_TYPE_NUMERIC) {
              value = String.valueOf(cell.getNumericCellValue());
            } else {
              value = cell.getStringCellValue();
            }
            profile.account_name = value;

            cell = row.getCell(10);
            if (cell.getCellType() == Cell.CELL_TYPE_NUMERIC) {
              value = String.valueOf(cell.getNumericCellValue());
            } else {
              value = cell.getStringCellValue();
            }
            profile.tfn = value;

            cell = row.getCell(11);
            if (cell.getCellType() == Cell.CELL_TYPE_NUMERIC) {
              value = String.valueOf(cell.getNumericCellValue());
            } else {
              value = cell.getStringCellValue();
            }
            profile.factory_name = value;

            cell = row.getCell(12);
            if (cell.getCellType() == Cell.CELL_TYPE_NUMERIC) {
              value = String.valueOf(cell.getNumericCellValue());
            } else {
              value = cell.getStringCellValue();
            }
            profile.factory_address = value;

            cell = row.getCell(13);
            if (cell.getCellType() == Cell.CELL_TYPE_NUMERIC) {
              value = String.valueOf(df.format(cell.getNumericCellValue()));
            } else {
              value = cell.getStringCellValue();
            }
            profile.first_supply = value.replaceAll("年", "");

            cell = row.getCell(14);
            if (cell.getCellType() == Cell.CELL_TYPE_NUMERIC) {
              value = String.valueOf(cell.getNumericCellValue());
            } else {
              value = cell.getStringCellValue();
            }
            profile.legal_person = value;

            cell = row.getCell(15);
            if (cell.getCellType() == Cell.CELL_TYPE_NUMERIC) {
              value = String.valueOf(cell.getNumericCellValue());
            } else {
              value = cell.getStringCellValue();
            }
            profile.contact_name = value;

            cell = row.getCell(16);
            if (cell.getCellType() == Cell.CELL_TYPE_NUMERIC) {
              value = String.valueOf(cell.getNumericCellValue());
            } else {
              value = cell.getStringCellValue();
            }
            profile.contact_job = value;

            cell = row.getCell(17);
            if (cell.getCellType() == Cell.CELL_TYPE_NUMERIC) {
              value = String.valueOf(df.format(cell.getNumericCellValue()));
            } else {
              value = cell.getStringCellValue();
            }
            profile.contact_phone = value;

            cell = row.getCell(18);
            if (cell.getCellType() == Cell.CELL_TYPE_NUMERIC) {
              value = String.valueOf(cell.getNumericCellValue());
            } else {
              value = cell.getStringCellValue();
            }
            profile.sales_name = value;

            cell = row.getCell(19);
            if (cell.getCellType() == Cell.CELL_TYPE_NUMERIC) {
              value = String.valueOf(cell.getNumericCellValue());
            } else {
              value = cell.getStringCellValue();
            }
            profile.sales_job = value;

            cell = row.getCell(20);
            if (cell.getCellType() == Cell.CELL_TYPE_NUMERIC) {
              value = String.valueOf(df.format(cell.getNumericCellValue()));
            } else {
              value = cell.getStringCellValue();
            }
            profile.sales_phone = value;

            cell = row.getCell(21);
            if (cell.getCellType() == Cell.CELL_TYPE_NUMERIC) {
              value = String.valueOf(cell.getNumericCellValue());
            } else {
              value = cell.getStringCellValue();
            }
            if (value.equals("自营")) {
              business = "1";
            } else if (value.equals("经销")) {
              business = "2";
            } else if (value.equals("挂靠")) {
              business = "3";
            } else {
              business = "0";
            }
            profile.business_model = business;
            profile.save();
            imported += 1;

            if (profile.contact_phone != null) {
              String message =
                  "您的信息已导入,用户名:" + user.username + ",密码:" + user.password + ",请登录比价平台上传资质文件";
              if (config.msg_import != null && !"".equals(config.msg_import)) {
                message =
                    config
                        .msg_import
                        .replace("{username}", user.username)
                        .replace("{passowrd}", user.password);
              }
              m.sendSms(profile.contact_phone, message, "0000001");
              if (profile.contact_email != null && !"".equals(profile.contact_phone)) {
                m.sendMail(
                    profile.contact_email,
                    "[" + Messages.get("application.name") + "]信息导入",
                    message);
              }
            }
          } catch (Exception e) {
            missed += 1;
            if (!"".equals(profiles)) {
              profiles += "," + profile.name;
            } else {
              profiles += profile.name;
            }
            e.printStackTrace();
          }
        }
      }

      result = "成功导入" + imported + "条记录,丢失" + missed + "条记录。";
      if (!"".equals(profiles)) {
        result += "丢失导入的供应商为:" + profiles;
      }
    }
    redirect("/admin/profiles?result=" + URLEncoder.encode(result));
  }
Пример #22
0
  private void loadFromRoot(List<Statement> roots) throws IOException {
    if (roots.size() == 2) {
      Statement exception = roots.get(0);
      String line = exception.getLine();
      if (line.startsWith("Exception")) {
        throw new AssetLoadException(line.substring("Exception ".length()));
      } else {
        throw new IOException("In multiroot material, expected first statement to be 'Exception'");
      }
    } else if (roots.size() != 1) {
      throw new IOException("Too many roots in J3M/J3MD file");
    }

    boolean extending = false;
    Statement materialStat = roots.get(0);
    String materialName = materialStat.getLine();
    if (materialName.startsWith("MaterialDef")) {
      materialName = materialName.substring("MaterialDef ".length()).trim();
      extending = false;
    } else if (materialName.startsWith("Material")) {
      materialName = materialName.substring("Material ".length()).trim();
      extending = true;
    } else {
      throw new IOException("Specified file is not a Material file");
    }

    String[] split = materialName.split(":", 2);

    if (materialName.equals("")) {
      throw new MatParseException("Material name cannot be empty", materialStat);
    }

    if (split.length == 2) {
      if (!extending) {
        throw new MatParseException("Must use 'Material' when extending.", materialStat);
      }

      String extendedMat = split[1].trim();

      MaterialDef def = (MaterialDef) assetManager.loadAsset(new AssetKey(extendedMat));
      if (def == null) {
        throw new MatParseException(
            "Extended material " + extendedMat + " cannot be found.", materialStat);
      }

      material = new Material(def);
      material.setKey(key);
      material.setName(split[0].trim());
      //            material.setAssetName(fileName);
    } else if (split.length == 1) {
      if (extending) {
        throw new MatParseException("Expected ':', got '{'", materialStat);
      }
      materialDef = new MaterialDef(assetManager, materialName);
      // NOTE: pass file name for defs so they can be loaded later
      materialDef.setAssetName(key.getName());
    } else {
      throw new MatParseException("Cannot use colon in material name/path", materialStat);
    }

    for (Statement statement : materialStat.getContents()) {
      split = statement.getLine().split("[ \\{]");
      String statType = split[0];
      if (extending) {
        if (statType.equals("MaterialParameters")) {
          readExtendingMaterialParams(statement.getContents());
        } else if (statType.equals("AdditionalRenderState")) {
          readAdditionalRenderState(statement.getContents());
        } else if (statType.equals("Transparent")) {
          readTransparentStatement(statement.getLine());
        }
      } else {
        if (statType.equals("Technique")) {
          readTechnique(statement);
        } else if (statType.equals("MaterialParameters")) {
          readMaterialParams(statement.getContents());
        } else {
          throw new MatParseException(
              "Expected material statement, got '" + statType + "'", statement);
        }
      }
    }
  }
Пример #23
0
  public static void impSpec(File file) {
    if (file != null) {
      List<Specification> specifications = new ArrayList<Specification>();
      Specification spec = null;
      Material material = null;
      try {
        FileInputStream fileInputStream = new FileInputStream(file);
        HSSFWorkbook workbook = new HSSFWorkbook(fileInputStream);
        HSSFSheet worksheet = workbook.getSheetAt(0);
        HSSFRow row = null;
        HSSFCell cell = null;
        Map<Integer, String> headerMap = new HashMap<Integer, String>();
        Prop prop = null;
        if (worksheet.getLastRowNum() > 0) {
          row = worksheet.getRow(0);
          for (int i = 0; i < row.getLastCellNum(); i++) {
            headerMap.put(Integer.valueOf(i), row.getCell(i).getStringCellValue());
          }
        }
        for (int i = 1; i < worksheet.getLastRowNum(); i++) {
          row = worksheet.getRow(i);
          cell = row.getCell(0);
          String materialName = cell.getStringCellValue();

          cell = row.getCell(1);
          String specification = cell.getStringCellValue();

          cell = row.getCell(2);
          Double number = cell.getNumericCellValue();

          cell = row.getCell(3);
          String unit = cell.getStringCellValue();

          cell = row.getCell(4);
          String company = cell.getStringCellValue();

          cell = row.getCell(5);
          Date date = cell.getDateCellValue();

          cell = row.getCell(6);
          String description = cell.getStringCellValue();

          spec = new Specification();

          for (int x = 7; x < row.getLastCellNum(); x++) {
            cell = row.getCell(x);
            String value = "";
            if (cell.getCellType() == Cell.CELL_TYPE_NUMERIC) {
              value = String.valueOf(cell.getNumericCellValue());
            } else {
              value = cell.getStringCellValue();
            }
            prop = new Prop();
            prop.name = headerMap.get(x);
            prop.value = value;
            prop.save();
            spec.properties.add(prop);
          }

          spec.name = specification;
          spec.specification = specification;
          if (number != null && !"".equals(number)) spec.amount = number;
          spec.unit = unit;
          spec.company = company;
          if (materialName != null && !"".equals(materialName)) {
            material = Material.find("name=?", materialName.trim()).first();
            spec.material = material;
          }
          spec.arrival_time = date;
          spec.description = description;
          spec.save();
          specifications.add(spec);
        }

        renderJSON(specifications);
      } catch (Exception e) {
        e.printStackTrace();
      }
    }
  }
Пример #24
0
  public static void save() throws Throwable {
    String username = params.get("username");
    String name = params.get("name");
    String password = params.get("password");
    String[] materials = params.getAll("material");
    String registration_number = params.get("registration_number");
    String registration_assets = params.get("registration_assets");
    String registration_assets_unit = params.get("registration_assets_unit");
    String registration_address = params.get("registration_address");
    String bank_name = params.get("bank_name");
    String account_name = params.get("account_name");
    String tfn = params.get("tfn");
    String legal_person = params.get("legal_person");
    String factory_name = params.get("factory_name");
    String factory_address = params.get("factory_address");
    String first_supply = params.get("first_supply");
    String business_model = params.get("business_model");
    String contact_name = params.get("contact_name");
    String contact_job = params.get("contact_job");
    String contact_phone = params.get("contact_phone");
    String contact_email = params.get("contact_email");
    String sales_name = params.get("sales_name");
    String sales_job = params.get("sales_job");
    String sales_phone = params.get("sales_phone");
    String[] files = params.getAll("files");

    User user = null;
    Material m = null;
    Files file = null;
    if (username != null && password != null && !"".equals(username) && !"".equals(password)) {
      user = User.find("username=?", username).first();
      if (user == null) {
        user = new User(username, password, ApplicationRole.getByName("user"));
        user.save();
      }

      Profile profile = Profile.find("user.id=?", user.id).first();
      if (profile == null) {
        profile = new Profile();
        profile.user = user;
      }

      if (materials != null) {
        for (String material_id : materials) {
          m = Material.find("id=?", Long.valueOf(material_id.trim())).first();
          if (m != null) profile.materials.add(m);
        }
      }
      profile.name = name;
      profile.registration_number = registration_number;
      profile.registration_assets = registration_assets;
      profile.registration_address = registration_address;
      profile.registration_assets_unit = registration_assets_unit;
      profile.bank_name = bank_name;
      profile.account_name = account_name;
      profile.tfn = tfn;
      profile.legal_person = legal_person;
      profile.factory_name = factory_name;
      profile.factory_address = factory_address;
      profile.first_supply = first_supply;
      profile.business_model = business_model;
      profile.contact_name = contact_name;
      profile.contact_job = contact_job;
      profile.contact_phone = contact_phone;
      profile.contact_email = contact_email;
      profile.sales_name = sales_name;
      profile.sales_job = sales_job;
      profile.sales_phone = sales_phone;

      if (files != null) {
        for (String f : files) {
          file = Files.find("id=?", Long.valueOf(f)).first();
          if (file != null) {
            profile.files.add(file);
          }
        }
      }

      profile.save();
    }

    session.put("username", username);

    Secure.redirectToOriginalURL();
  }
Пример #25
0
 public static void load() {
   final FileConfiguration config = UDSPlugin.getPlugin().getConfig();
   BLOCK_CREEPERS = config.getBoolean("block.creeper");
   BLOCK_ENDERMEN = config.getBoolean("block.endermen");
   BLOCK_SILVERFISH = config.getBoolean("block.silverfish");
   BLOCK_TNT = config.getBoolean("block.tnt");
   BLOCK_WITHER = config.getBoolean("block.wither");
   MAP_DATA = (byte) config.getInt("map-data");
   BASE_COST = config.getInt("cost.base");
   BUILD_COST = config.getInt("cost.build");
   CITY_COST = config.getInt("cost.city");
   CLAN_COST = config.getInt("cost.clan");
   EXPAND_COST = config.getInt("cost.expand");
   HOME_COST = config.getInt("cost.home");
   MAP_COST = config.getInt("cost.map");
   SHOP_COST = config.getInt("cost.shop");
   VIP_COST = config.getInt("cost.vip");
   UNDO_COUNT = config.getInt("range.undo");
   DRAIN_RANGE = config.getInt("range.drain");
   MOVE_RANGE = config.getInt("range.move");
   EDIT_RANGE = config.getInt("range.edit");
   COMPASS_RANGE = config.getInt("range.compass");
   BUTCHER_RANGE = config.getInt("range.butcher");
   VIP_SPAWNS = config.getInt("vip.spawns");
   WORLD_BORDER = config.getInt("range.world");
   WORLD_BORDER_SQRD = WORLD_BORDER * WORLD_BORDER;
   SPAWNER_EXP = config.getInt("exp.spawner");
   REQUEST_TTL = config.getLong("request-timeout") * TimeUtils.SECOND;
   MINECART_TTL = config.getLong("minecart.life") * TimeUtils.SECOND;
   PVP_TIME = config.getLong("pvp-time") * TimeUtils.SECOND;
   SLOW_TIME = config.getLong("auto-save") * TimeUtils.MINUTE;
   DRAGON_RESPAWN = config.getLong("respawn-dragon") * TimeUtils.MINUTE;
   VIP_TIME = config.getLong("vip.time") * TimeUtils.DAY;
   CURRENCIES = config.getString("currency.plural");
   WELCOME_MSG = config.getString("welcome.message");
   WELCOME_ADMIN = config.getString("welcome.admin");
   SERVER_OWNER = config.getString("server-owner");
   CURRENCY = config.getString("currency.singular");
   MAIN_WORLD = config.getString("world-name");
   WELCOME_GIFT = Material.getMaterial(config.getString("welcome.gift"));
   if (WELCOME_GIFT == null) WELCOME_GIFT = Material.EMERALD;
   SERVER_RULES = config.getStringList("server-rules");
   PISTON_POWER = config.getDouble("piston-power");
   SHARES = config.getStringList("inventory-shares");
   GMAIL_ADDRESS = config.getString("gmail.email");
   SKULL = config.getDouble("head-drop-chance");
   GMAIL_PASSWORD = config.getString("gmail.password");
   VIP_WHITELIST.clear();
   for (int typeId : config.getIntegerList("item-whitelist")) {
     VIP_WHITELIST.add(Material.getMaterial(typeId));
   }
   KITS.clear();
   for (String kit : config.getStringList("kits")) {
     final String[] kitSplit = kit.split(",");
     final List<ItemStack> items =
         new ArrayList<ItemStack>(ArrayUtils.subarray(kitSplit, 3, kitSplit.length - 1).length);
     for (Object item : ArrayUtils.subarray(kitSplit, 3, kitSplit.length - 1)) {
       items.add(new ItemStack(Material.getMaterial(Integer.parseInt((String) item))));
     }
     KITS.add(
         new Kit(
             kitSplit[0],
             Integer.parseInt(kitSplit[1]),
             items,
             PlayerRank.getByName(kitSplit[2])));
   }
   MOB_REWARDS.clear();
   for (EntityType entityType : EntityType.values()) {
     String entityName = "mob-rewards." + entityType.getName();
     if (entityName != null) {
       entityName = entityName.toLowerCase();
       MOB_REWARDS.put(entityType, config.getInt(entityName));
     }
   }
   GLOBAL_FLAGS.clear();
   for (RegionFlag flag : RegionFlag.values()) {
     final String flagname = "global-flags." + flag.toString().toLowerCase();
     GLOBAL_FLAGS.put(flag, config.getBoolean(flagname));
   }
 }
  private static Map<String, List<Material>> initSynonyms() {

    Map<String, List<Material>> result = new HashMap<String, List<Material>>();
    // Blocks
    result.put("ANY_FURNACE", Arrays.asList(Material.FURNACE, Material.BURNING_FURNACE));
    result.put("ANY_SIGN", Arrays.asList(Material.SIGN, Material.SIGN_POST, Material.WALL_SIGN));
    result.put(
        "ANY_REDSTONE_ORE", Arrays.asList(Material.REDSTONE_ORE, Material.GLOWING_REDSTONE_ORE));
    result.put(
        "ANY_REDSTONE_TORCH",
        Arrays.asList(Material.REDSTONE_TORCH_OFF, Material.REDSTONE_TORCH_ON));
    result.put("ANY_DIODE_BLOCK", Arrays.asList(Material.DIODE_BLOCK_OFF, Material.DIODE_BLOCK_ON));
    // Tools
    result.put(
        "ANY_SPADE",
        Arrays.asList(
            Material.WOOD_SPADE,
            Material.STONE_SPADE,
            Material.GOLD_SPADE,
            Material.IRON_SPADE,
            Material.DIAMOND_SPADE));
    result.put(
        "ANY_AXE",
        Arrays.asList(
            Material.WOOD_AXE,
            Material.STONE_AXE,
            Material.GOLD_AXE,
            Material.IRON_AXE,
            Material.DIAMOND_AXE));
    result.put(
        "ANY_HOE",
        Arrays.asList(
            Material.WOOD_HOE,
            Material.STONE_HOE,
            Material.GOLD_HOE,
            Material.IRON_HOE,
            Material.DIAMOND_HOE));
    result.put(
        "ANY_PICKAXE",
        Arrays.asList(
            Material.WOOD_PICKAXE,
            Material.STONE_PICKAXE,
            Material.GOLD_PICKAXE,
            Material.IRON_PICKAXE,
            Material.DIAMOND_PICKAXE));
    result.put(
        "ANY_SWORD",
        Arrays.asList(
            Material.WOOD_SWORD,
            Material.STONE_SWORD,
            Material.GOLD_SWORD,
            Material.IRON_SWORD,
            Material.DIAMOND_SWORD));
    result.put(
        "ANY_BUCKET",
        Arrays.asList(
            Material.BUCKET, Material.LAVA_BUCKET, Material.WATER_BUCKET, Material.MILK_BUCKET));
    // Armour
    result.put(
        "ANY_HELMET",
        Arrays.asList(
            Material.LEATHER_HELMET,
            Material.CHAINMAIL_HELMET,
            Material.GOLD_HELMET,
            Material.IRON_HELMET,
            Material.DIAMOND_HELMET));
    result.put(
        "ANY_CHESTPLATE",
        Arrays.asList(
            Material.LEATHER_CHESTPLATE,
            Material.CHAINMAIL_CHESTPLATE,
            Material.GOLD_CHESTPLATE,
            Material.IRON_CHESTPLATE,
            Material.DIAMOND_CHESTPLATE));
    result.put(
        "ANY_LEGGINGS",
        Arrays.asList(
            Material.LEATHER_LEGGINGS,
            Material.CHAINMAIL_LEGGINGS,
            Material.GOLD_LEGGINGS,
            Material.IRON_LEGGINGS,
            Material.DIAMOND_LEGGINGS));
    result.put(
        "ANY_BOOTS",
        Arrays.asList(
            Material.LEATHER_BOOTS,
            Material.CHAINMAIL_BOOTS,
            Material.GOLD_BOOTS,
            Material.IRON_BOOTS,
            Material.DIAMOND_BOOTS));
    // Minecarts
    result.put(
        "ANY_MINECART",
        Arrays.asList(Material.MINECART, Material.POWERED_MINECART, Material.STORAGE_MINECART));
    result.put(
        "ANY_RAIL", Arrays.asList(Material.RAILS, Material.POWERED_RAIL, Material.DETECTOR_RAIL));
    // Wildcards
    List<Material> merger;

    merger = new ArrayList<Material>();
    merger.addAll(result.get("ANY_SPADE"));
    merger.addAll(result.get("ANY_AXE"));
    merger.addAll(result.get("ANY_HOE"));
    merger.addAll(result.get("ANY_PICKAXE"));
    merger.addAll(result.get("ANY_SWORD"));
    merger.addAll(result.get("ANY_BUCKET"));
    merger.addAll(
        Arrays.asList(
            Material.FLINT_AND_STEEL, Material.FISHING_ROD, Material.SADDLE, Material.BOW));
    result.put("ANY_TOOL", merger);

    merger = new ArrayList<Material>();
    merger.addAll(result.get("ANY_SWORD"));
    merger.addAll(Arrays.asList(Material.BOW, Material.ARROW));
    result.put("ANY_WEAPON", merger);

    merger = new ArrayList<Material>();
    merger.addAll(result.get("ANY_HELMET"));
    merger.addAll(result.get("ANY_CHESTPLATE"));
    merger.addAll(result.get("ANY_LEGGINGS"));
    merger.addAll(result.get("ANY_BOOTS"));
    result.put("ANY_ARMOR", merger);

    merger = new ArrayList<Material>();
    merger.addAll(Arrays.asList(Material.values()));
    result.put("ANY_OBJECT", merger);

    merger = new ArrayList<Material>();
    merger.addAll(Arrays.asList(Material.values()));
    for (int i = 0; i < merger.size(); i++) {
      if (!merger.get(i).isBlock()) merger.set(i, null);
    }
    while (merger.indexOf(null) >= 0) merger.remove(null);
    result.put("ANY_BLOCK", merger);

    merger = new ArrayList<Material>();
    merger.addAll(Arrays.asList(Material.values()));
    for (int i = 0; i < merger.size(); i++) {
      if (merger.get(i).isBlock()) merger.set(i, null);
    }
    while (merger.indexOf(null) >= 0) merger.remove(null);
    result.put("ANY_ITEM", merger);

    return Collections.unmodifiableMap(result);
  }
Пример #27
0
  /**
   * Compares two materials and returns true if they are equal. This methods compare definition,
   * parameters, additional render states. Since materials are mutable objects, implementing
   * equals() properly is not possible, hence the name contentEquals().
   *
   * @param otherObj the material to compare to this material
   * @return true if the materials are equal.
   */
  public boolean contentEquals(Object otherObj) {
    if (!(otherObj instanceof Material)) {
      return false;
    }

    Material other = (Material) otherObj;

    // Early exit if the material are the same object
    if (this == other) {
      return true;
    }

    // Check material definition
    if (this.getMaterialDef() != other.getMaterialDef()) {
      return false;
    }

    // Early exit if the size of the params is different
    if (this.paramValues.size() != other.paramValues.size()) {
      return false;
    }

    // Checking technique
    if (this.technique != null || other.technique != null) {
      // Techniques are considered equal if their names are the same
      // E.g. if user chose custom technique for one material but
      // uses default technique for other material, the materials
      // are not equal.
      String thisDefName = this.technique != null ? this.technique.getDef().getName() : "Default";
      String otherDefName =
          other.technique != null ? other.technique.getDef().getName() : "Default";
      if (!thisDefName.equals(otherDefName)) {
        return false;
      }
    }

    // Comparing parameters
    for (String paramKey : paramValues.keySet()) {
      MatParam thisParam = this.getParam(paramKey);
      MatParam otherParam = other.getParam(paramKey);

      // This param does not exist in compared mat
      if (otherParam == null) {
        return false;
      }

      if (!otherParam.equals(thisParam)) {
        return false;
      }
    }

    // Comparing additional render states
    if (additionalState == null) {
      if (other.additionalState != null) {
        return false;
      }
    } else {
      if (!additionalState.equals(other.additionalState)) {
        return false;
      }
    }

    return true;
  }