Example #1
0
	private String getFriendlyFlagInfo(Game game) {
		Map<Flag<?>, Object> flags = game.getFlags();
		String[] info = new String[flags.size()];
		
		int i = 0;
		for (Flag<?> flag : flags.keySet()) {
			info[i] = flag.toInfo(flags.get(flag));
			i++;
		}
		
		return Util.toFriendlyString(info, ", ");
	}
  @Override
  public void putElement(Player player, String input, List<SerializeableItemStack> existing) {
    String[] inputParts = splitStringSafely(input, " ");

    Material material;
    byte data = 0;
    int amount = 1;
    String displayName = null;
    List<String> lore = null;

    if (inputParts.length < 1) {
      return;
    }

    String[] itemData = inputParts[0].split(":");

    if (Util.isNumber(itemData[0])) {
      material = Material.getMaterial(Integer.parseInt(itemData[0]));
    } else {
      try {
        material = Material.valueOf(itemData[0].toUpperCase());
      } catch (Exception e) {
        player.sendMessage(getHelp());
        return;
      }
    }

    if (itemData.length > 1) {
      if (Util.isNumber(itemData[1])) {
        data = Byte.parseByte(itemData[1]);
      } else {
        player.sendMessage(getHelp());
        return;
      }
    }

    if (inputParts.length > 1) {
      if (Util.isNumber(inputParts[1])) {
        amount = Integer.parseInt(inputParts[1]);
      } else {
        player.sendMessage(getHelp());
        return;
      }
    }

    if (inputParts.length > 2) {
      // DisplayName
      displayName = ChatColor.translateAlternateColorCodes('&', inputParts[2]);
    }

    if (inputParts.length > 3) {
      // Lore
      String[] lines = inputParts[3].split("//");
      for (int i = 0; i < lines.length; i++) {
        lines[i] = ChatColor.translateAlternateColorCodes('&', lines[i]);
      }

      lore = Arrays.asList(lines);
    }

    SerializeableItemStack itemstack = new SerializeableItemStack(material, amount);
    itemstack.setData(data);
    itemstack.setDisplayName(displayName);
    itemstack.setLore(lore);

    existing.add(itemstack);
  }