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

The following examples show how to use org.bukkit.Material#valueOf() . 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: Config.java    From ArmorStandTools with MIT License 6 votes vote down vote up
private static ItemStack toItemStack(String s) {
    if(s == null || s.length() == 0) {
        return new ItemStack(Material.AIR);
    }
    String[] split = s.split(" ");
    if(split.length > 2) {
        plugin.getLogger().warning("Error in config.yml: Must use the format: MATERIAL_NAME dataValue. Continuing using AIR instead.");
        return new ItemStack(Material.AIR);
    }
    byte dataValue = (byte) 0;
    if(split.length == 2) {
        try {
            dataValue = Byte.parseByte(split[1]);
        } catch (NumberFormatException nfe) {
            plugin.getLogger().warning("Error in config.yml: Invalid data value specifed. Continuing using data value 0 instead.");
        }
    }
    Material m;
    try {
        m = Material.valueOf(split[0].toUpperCase());
    } catch(IllegalArgumentException iae) {
        plugin.getLogger().warning("Error in config.yml: Invalid material name specifed. Continuing using AIR instead.");
        return new ItemStack(Material.AIR);
    }
    return new ItemStack(m, 1, dataValue);
}
 
Example 2
Source File: RepairConfig.java    From NyaaUtils with MIT License 6 votes vote down vote up
@Override
public void deserialize(ConfigurationSection config) {
    repairMap.clear();
    for (String key : config.getKeys(false)) {
        Material m;
        try {
            m = Material.valueOf(key);
        } catch (IllegalArgumentException ex) {
            continue;
        }
        if (!config.isConfigurationSection(key)) continue;
        RepairConfigItem item = new RepairConfigItem();
        item.deserialize(config.getConfigurationSection(key));
        repairMap.put(m, item.normalize());
    }
}
 
Example 3
Source File: WrappedMaterial.java    From SonarPet with GNU General Public License v3.0 5 votes vote down vote up
public Material get() {
    try {
        return Material.valueOf(this.materialName);
    } catch (Exception exception) {
        return null;
    }
}
 
Example 4
Source File: SentinelItemHelper.java    From Sentinel with MIT License 5 votes vote down vote up
/**
 * Processes weapon redirection for an item, returning the redirected item (or an unchanged one).
 */
public ItemStack autoRedirect(ItemStack stack) {
    if (stack == null) {
        return null;
    }
    String redirect = sentinel.weaponRedirects.get(stack.getType().name().toLowerCase());
    if (redirect == null) {
        return stack;
    }
    Material mat = Material.valueOf(redirect.toUpperCase());
    ItemStack newStack = stack.clone();
    newStack.setType(mat);
    return newStack;
}
 
Example 5
Source File: SkullCreator.java    From Crazy-Crates with MIT License 5 votes vote down vote up
private static boolean newerApi() {
    try {
        Material.valueOf("PLAYER_HEAD");
        return true;
        
    } catch (IllegalArgumentException e) { // If PLAYER_HEAD doesn't exist
        return false;
    }
}
 
Example 6
Source File: MaterialHelper.java    From CS-CoreLib with GNU General Public License v3.0 5 votes vote down vote up
public static Material getSaplingFromLog(Material log) {
    if (!isLog(log))
        return Material.AIR;

    String type = log.name().substring(0, log.name().lastIndexOf('_'));
    type = type.replace("STRIPPED_", "");
    try {
        return Material.valueOf(type + "_SAPLING");
    }catch (IllegalArgumentException ignored) {
        return Material.AIR;
    }
}
 
Example 7
Source File: ConfigManager.java    From Civs with GNU General Public License v3.0 5 votes vote down vote up
private void getTownRingSettings(FileConfiguration config) {
    townRings = config.getBoolean("town-rings", true);
    try {
        townRingMat = Material.valueOf(config.getString("town-ring-material", "GLOWSTONE"));
    } catch (Exception e) {
        townRingMat = Material.GLOWSTONE;
        Civs.logger.severe("Unable to read town-ring-material");
    }
}
 
Example 8
Source File: GenerateVeinConfiguration.java    From UhcCore with GNU General Public License v3.0 5 votes vote down vote up
public boolean parseConfiguration(ConfigurationSection section){
	if (section == null){
		return false;
	}

	try{
		material = Material.valueOf(section.getName());
	}catch(IllegalArgumentException e){
		Bukkit.getLogger().warning("[UhcCore] Couldn't parse section '"+section.getName()+"' in generate-vein. This is not an existing block type.Ignoring it.");
		return false;
	}
	minVeinsPerChunk = section.getInt("min-veins-per-chunk",0);
	maxVeinsPerChunk = section.getInt("max-veins-per-chunk",5);
	if(minVeinsPerChunk < 0 || maxVeinsPerChunk < 0){
		Bukkit.getLogger().warning("[UhcCore] Couldn't parse section '"+section.getName()+"' in generate-vein. min and max-veins-per-chunk must be positive.");
		return false;
	}
	
	minBlocksPerVein = section.getInt("min-blocks-per-vein",5);
	maxBlocksPerVein = section.getInt("max-blocks-per-vein",10);
	if(minBlocksPerVein < 0 || maxBlocksPerVein < 0){
		Bukkit.getLogger().warning("[UhcCore] Couldn't parse section '"+section.getName()+"' in generate-vein. min and max-blocks-per-vein must be positive.");
		return false;
	}
	
	minY = section.getInt("min-y",0);
	maxY = section.getInt("max-y",65);
	if(minY < 0 || minY > 255 || maxY < 0 || maxY > 255){
		Bukkit.getLogger().warning("[UhcCore] Couldn't parse section '"+section.getName()+"' in generate-vein. The min and max Y must be between 0 and 255.");
		return false;
	}
	
	return true;
}
 
Example 9
Source File: ItemGetterLatest.java    From Quests with MIT License 5 votes vote down vote up
@Override
public ItemStack getItemStack(String material, Quests plugin) {
    Material type;
    try {
        type = Material.valueOf(material);
    } catch (Exception e) {
        plugin.getQuestsLogger().debug("Unrecognised material: " + material);
        type = Material.STONE;
    }
    return new ItemStack(type, 1);
}
 
Example 10
Source File: GuildHandler.java    From Guilds with MIT License 5 votes vote down vote up
/**
 * Create a guild upgrade ticket
 * @param settingsManager the settings manager
 * @param amount the amount of tickets to give
 * @return the guild upgrade ticket
 */
public ItemStack getUpgradeTicket(SettingsManager settingsManager, int amount) {
    ItemBuilder builder = new ItemBuilder(Material.valueOf(settingsManager.getProperty(TicketSettings.TICKET_MATERIAL)));
    builder.setAmount(amount);
    builder.setName(StringUtils.color(settingsManager.getProperty(TicketSettings.TICKET_NAME)));
    builder.setLore(settingsManager.getProperty(TicketSettings.TICKET_LORE).stream().map(StringUtils::color).collect(Collectors.toList()));
    return builder.build();
}
 
Example 11
Source File: NMSHandler.java    From SkyWarsReloaded with GNU General Public License v3.0 5 votes vote down vote up
@Override
public ItemStack getMaterial(String item) {
	if (item.equalsIgnoreCase("SKULL_ITEM")) {
		return new ItemStack(Material.SKULL_ITEM, 1, (short) 1);
	} else {
		return new ItemStack(Material.valueOf(item), 1);
	}
}
 
Example 12
Source File: LevelManager.java    From SkyWarsReloaded with GNU General Public License v3.0 5 votes vote down vote up
private void loadTaunts() {
	tauntList.clear();
       File tauntFile = new File(SkyWarsReloaded.get().getDataFolder(), "taunts.yml");

       if (!tauntFile.exists()) {
       	if (SkyWarsReloaded.getNMS().getVersion() < 9) {
               	SkyWarsReloaded.get().saveResource("taunts18.yml", false);
               	File sf = new File(SkyWarsReloaded.get().getDataFolder(), "taunts18.yml");
               	if (sf.exists()) {
               		sf.renameTo(new File(SkyWarsReloaded.get().getDataFolder(), "taunts.yml"));
               	}
       	} else {
           	SkyWarsReloaded.get().saveResource("taunts.yml", false);
       	}
       }
       
       if (tauntFile.exists()) {
           FileConfiguration storage = YamlConfiguration.loadConfiguration(tauntFile);

           if (storage.getConfigurationSection("taunts") != null) {
           	for (String key: storage.getConfigurationSection("taunts").getKeys(false)) {
               	String name = storage.getString("taunts." + key + ".name");
               	List<String> lore = storage.getStringList("taunts." + key + ".lore");
               	int level = storage.getInt("taunts." + key + ".level");
               	int cost = storage.getInt("taunts." + key + ".cost");
               	String message = storage.getString("taunts." + key + ".message");
               	String sound = storage.getString("taunts." + key + ".sound");
               	boolean useCustomSound = storage.getBoolean("taunts." + key + ".useCustomSound", false);
               	double volume = storage.getDouble("taunts." + key + ".volume");
               	double pitch = storage.getDouble("taunts." + key + ".pitch");
               	double speed = storage.getDouble("taunts." + key + ".particleSpeed");
               	int density = storage.getInt("taunts." + key + ".particleDensity");
               	List<String> particles = storage.getStringList("taunts." + key + ".particles");
               	Material icon = Material.valueOf(storage.getString("taunts." + key + ".icon", "DIAMOND"));
               	tauntList.add(new Taunt(key, name, lore, message, sound, useCustomSound, volume, pitch, speed, density, particles, icon, level, cost));
               }
           } 
       }
       Collections.<Taunt>sort(tauntList);
}
 
Example 13
Source File: ItemStackReader.java    From helper with MIT License 5 votes vote down vote up
protected Material parseMaterial(String name) {
    try {
        return Material.valueOf(name.toUpperCase());
    } catch (IllegalArgumentException e) {
        throw new IllegalArgumentException("Unable to parse material '" + name + "'");
    }
}
 
Example 14
Source File: LegacyBedUtils.java    From BedWars with GNU Lesser General Public License v3.0 5 votes vote down vote up
public static boolean isBedBlock(Block isBed) {
    if (isBed == null) {
        return false;
    }

    return (isBed.getType() == Material.valueOf("BED") || isBed.getType() == Material.valueOf("BED_BLOCK"));
}
 
Example 15
Source File: MessageGui.java    From WildernessTp with MIT License 5 votes vote down vote up
private static ItemStack makeItem(String name, String lore) {
    ItemStack stack = new ItemStack(Material.valueOf(MainGui.getMaterials().get("Book")));
    ItemMeta meta = stack.getItemMeta();
    ArrayList<String> loreArray = new ArrayList<>();
    loreArray.add(lore);
    meta.setLore(loreArray);
    meta.setDisplayName(name);
    stack.setItemMeta(meta);
    return stack;
}
 
Example 16
Source File: MaterialHook.java    From CS-CoreLib with GNU General Public License v3.0 5 votes vote down vote up
public static Material parse(String name, String legacy) {
	if (ReflectionUtils.isVersion("v1_12_", "v1_11_", "v1_10_", "v1_9_")) {
		return Material.valueOf(legacy);
	}
	else {
		return Material.valueOf(name);
	}
}
 
Example 17
Source File: NMSHandler.java    From SkyWarsReloaded with GNU General Public License v3.0 5 votes vote down vote up
@Override
public ItemStack getMaterial(String item) {
	if (item.equalsIgnoreCase("SKULL_ITEM")) {
		return new ItemStack(Material.SKULL_ITEM, 1, (short) 1);
	} else {
		return new ItemStack(Material.valueOf(item), 1);
	}
}
 
Example 18
Source File: Config.java    From SkyWarsReloaded with GNU General Public License v3.0 4 votes vote down vote up
public Material getRandMat() {
	return Material.valueOf(randMat);
}
 
Example 19
Source File: Drilling.java    From MineTinker with GNU General Public License v3.0 4 votes vote down vote up
@Override
public void reload() {
	FileConfiguration config = getConfig();
	config.options().copyDefaults(true);

	config.addDefault("Allowed", true);
	config.addDefault("Color", "%GREEN%");
	config.addDefault("Toggleable", true);
	config.addDefault("MaxLevel", 4);
	config.addDefault("SlotCost", 1);

	config.addDefault("EnchantCost", 15);
	config.addDefault("Enchantable", false);

	config.addDefault("Recipe.Enabled", true);
	config.addDefault("Recipe.Top", " D ");
	config.addDefault("Recipe.Middle", "DGD");
	config.addDefault("Recipe.Bottom", "GHG");

	Map<String, String> recipeMaterials = new HashMap<>();
	recipeMaterials.put("D", Material.DIAMOND.name());
	recipeMaterials.put("G", Material.GOLD_BLOCK.name());
	recipeMaterials.put("H", Material.HOPPER.name());

	config.addDefault("Recipe.Materials", recipeMaterials);

	List<String> blacklistTemp = new ArrayList<>();

	blacklistTemp.add(Material.AIR.name());
	blacklistTemp.add(Material.BEDROCK.name());
	blacklistTemp.add(Material.WATER.name());
	blacklistTemp.add(Material.BUBBLE_COLUMN.name());
	blacklistTemp.add(Material.LAVA.name());
	blacklistTemp.add(Material.END_PORTAL.name());
	blacklistTemp.add(Material.END_CRYSTAL.name());
	blacklistTemp.add(Material.END_PORTAL_FRAME.name());
	blacklistTemp.add(Material.NETHER_PORTAL.name());

	config.addDefault("Blacklist", blacklistTemp);
	config.addDefault("TreatAsWhitelist", false);

	ConfigurationManager.saveConfig(config);
	ConfigurationManager.loadConfig("Modifiers" + File.separator, getFileName());

	init(Material.HOPPER);

	this.toggleable = config.getBoolean("Toggleable", true);
	this.treatAsWhitelist = config.getBoolean("TreatAsWhitelist", false);

	blacklist = new ArrayList<>();

	List<String> blacklistConfig = config.getStringList("Blacklist");

	for (String mat : blacklistConfig) {
		try {
			Material material = Material.valueOf(mat);

			if (blacklist == null) {
				continue;
			}

			blacklist.add(material);
		} catch (IllegalArgumentException e) {
			MineTinker.getPlugin().getLogger()
					.warning("Illegal material name found when loading Drilling blacklist: " + mat);
		}
	}
}
 
Example 20
Source File: Power.java    From MineTinker with GNU General Public License v3.0 4 votes vote down vote up
@Override
public void reload() {
	FileConfiguration config = getConfig();
	config.options().copyDefaults(true);

	config.addDefault("Allowed", true);
	config.addDefault("Color", "%GREEN%");
	config.addDefault("Lv1Vertical", false); // Should the 3x1 at level 1 be horizontal (false) or vertical (true)
	config.addDefault("Toggleable", true);
	config.addDefault("MaxLevel", 2); // Algorithm for area of effect (except for level 1): (level * 2) - 1 x
	config.addDefault("SlotCost", 2);

	config.addDefault("EnchantCost", 15);
	config.addDefault("Enchantable", true);

	config.addDefault("Recipe.Enabled", false);

	List<String> blacklistTemp = new ArrayList<>();

	blacklistTemp.add(Material.AIR.name());
	blacklistTemp.add(Material.BEDROCK.name());
	blacklistTemp.add(Material.WATER.name());
	blacklistTemp.add(Material.BUBBLE_COLUMN.name());
	blacklistTemp.add(Material.LAVA.name());
	blacklistTemp.add(Material.END_PORTAL.name());
	blacklistTemp.add(Material.END_CRYSTAL.name());
	blacklistTemp.add(Material.END_PORTAL_FRAME.name());
	blacklistTemp.add(Material.NETHER_PORTAL.name());

	config.addDefault("Blacklist", blacklistTemp);
	config.addDefault("TreatAsWhitelist", false);

	ConfigurationManager.saveConfig(config);
	ConfigurationManager.loadConfig("Modifiers" + File.separator, getFileName());

	init(Material.EMERALD);

	this.lv1_vertical = config.getBoolean("Lv1Vertical", false);
	this.toggleable = config.getBoolean("Toggleable", true);
	this.treatAsWhitelist = config.getBoolean("TreatAsWhitelist", false);

	blacklist = new ArrayList<>();

	List<String> blacklistConfig = config.getStringList("Blacklist");

	for (String mat : blacklistConfig) {
		try {
			Material material = Material.valueOf(mat);

			if (blacklist == null) {
				continue;
			}

			blacklist.add(material);
		} catch (IllegalArgumentException e) {
			MineTinker.getPlugin().getLogger()
					.warning("Illegal material name found when loading Power blacklist: " + mat);
		}
	}
}