Java Code Examples for org.bukkit.Material#isItem()

The following examples show how to use org.bukkit.Material#isItem() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ImportManager.java    From Statz with GNU General Public License v3.0 6 votes vote down vote up
private void importToolsBroken(PlayerInfo playerInfo, String worldName) {
    Optional<JSONObject> object = getCustomSection(playerInfo.getUUID(), worldName);

    if (!object.isPresent()) {
        return;
    }

    Optional<JSONObject> brokenSection = getBrokenSection(playerInfo.getUUID(), worldName);

    if (!brokenSection.isPresent()) return;

    for (Material material : Material.values()) {
        if (material.isItem()) {

            long broken = (Long) getStatistic(brokenSection.get(), material.getKey().toString()).orElse(0L);

            if (broken <= 0) continue;

            playerInfo.addRow(PlayerStat.TOOLS_BROKEN,
                    StatzUtil.makeQuery(playerInfo.getUUID(), "value", broken, "world",
                            worldName, "item", material));
        }
    }
}
 
Example 2
Source File: ItemStackComplexRemapperRegistry.java    From ProtocolSupport with GNU Affero General Public License v3.0 5 votes vote down vote up
protected static void register(
	Int2ObjectOpenHashMap<EnumMap<ProtocolVersion, List<ItemStackComplexRemapper>>> registry,
	Material material, ItemStackComplexRemapper transformer, ProtocolVersion... versions
) {
	if (!material.isItem()) {
		throw new IllegalArgumentException(material + " is not an item");
	}
	EnumMap<ProtocolVersion, List<ItemStackComplexRemapper>> map = registry.computeIfAbsent(ItemMaterialLookup.getRuntimeId(material), k -> new EnumMap<>(ProtocolVersion.class));
	Arrays.stream(versions).forEach(version -> map.computeIfAbsent(version, k -> new ArrayList<>()).add(transformer));
}
 
Example 3
Source File: MaterialAPI.java    From ProtocolSupport with GNU Affero General Public License v3.0 5 votes vote down vote up
/**
 * Returns item network id
 * @param material item material
 * @return item network id
 */
@SuppressWarnings("deprecation")
public static int getItemNetworkId(Material material) {
	if (material.isLegacy()) {
		throw new IllegalArgumentException(MessageFormat.format("Material {0} is legacy", material));
	}
	if (!material.isItem()) {
		throw new IllegalArgumentException(MessageFormat.format("Material {0} is not an item", material));
	}
	return ItemMaterialLookup.getRuntimeId(material);
}
 
Example 4
Source File: ImportManager.java    From Statz with GNU General Public License v3.0 4 votes vote down vote up
private void importItemsCrafted(PlayerInfo playerInfo, String worldName) {

        Optional<JSONObject> object = getCustomSection(playerInfo.getUUID(), worldName);

        if (!object.isPresent()) {
            return;
        }

        Optional<JSONObject> craftedSection = getCraftedSection(playerInfo.getUUID(), worldName);

        if (!craftedSection.isPresent()) return;

        for (Material material : Material.values()) {
            if (material.isItem()) {

                long itemsCrafted = (Long) getStatistic(craftedSection.get(), material.getKey().toString()).orElse(0L);

                if (itemsCrafted <= 0) continue;

                playerInfo.addRow(PlayerStat.ITEMS_CRAFTED,
                        StatzUtil.makeQuery(playerInfo.getUUID(), "value", itemsCrafted, "world",
                                worldName, "item", material));
            }
        }
    }
 
Example 5
Source File: GUIManager.java    From Statz with GNU General Public License v3.0 4 votes vote down vote up
private Material getIconMaterialForSpecificStatistic(Query query, PlayerStat stat) {

        if (stat == PlayerStat.BLOCKS_BROKEN || stat == PlayerStat.BLOCKS_PLACED) {

            Material material = Material.getMaterial(query.getValue("block").toString());

            if (material != null && material.isItem()) {
                return material;
            }
        }

        if (stat == PlayerStat.VILLAGER_TRADES) {
            return Material.getMaterial(query.getValue("trade").toString());
        }

        if (stat == PlayerStat.KILLS_MOBS) {
            return Material.getMaterial(query.getValue("weapon").toString());
        }

        if (stat == PlayerStat.ITEMS_PICKED_UP || stat == PlayerStat.ITEMS_DROPPED || stat == PlayerStat.ITEMS_CRAFTED || stat == PlayerStat.TOOLS_BROKEN) {
            return Material.getMaterial(query.getValue("item").toString());
        }

        if (stat == PlayerStat.ITEMS_CAUGHT) {
            return Material.getMaterial(query.getValue("caught").toString());
        }

        if (stat == PlayerStat.FOOD_EATEN) {
            return Material.getMaterial(query.getValue("foodEaten").toString());
        }

        if (stat == PlayerStat.DISTANCE_TRAVELLED) {
            String movementType = query.getValue("moveType").toString();

            switch (movementType) {
                case "SWIM":
                    return Material.TROPICAL_FISH;
                case "FLY":
                    return Material.BLAZE_POWDER;
                case "BOAT":
                    return Material.OAK_BOAT;
                case "MINECART":
                case "HORSE IN MINECART":
                    return Material.MINECART;
                case "PIG IN MINECART":
                case "PIG":
                    return Material.COOKED_PORKCHOP;
                case "HORSE":
                    return Material.DIAMOND_HORSE_ARMOR;
                case "FLY WITH ELYTRA":
                    return Material.ELYTRA;
                case "WALK":
                    return Material.GOLDEN_BOOTS;
            }
        }


        return plugin.getStatisticDescriptionConfig().getIconMaterial(stat);
    }