下面列出了org.bukkit.Material#valueOf ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
@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());
}
}
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);
}
/**
* 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;
}
@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);
}
}
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);
}
}
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;
}
public static boolean isBedBlock(Block isBed) {
if (isBed == null) {
return false;
}
return (isBed.getType() == Material.valueOf("BED") || isBed.getType() == Material.valueOf("BED_BLOCK"));
}
protected Material parseMaterial(String name) {
try {
return Material.valueOf(name.toUpperCase());
} catch (IllegalArgumentException e) {
throw new IllegalArgumentException("Unable to parse material '" + name + "'");
}
}
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);
}
@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);
}
}
/**
* 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();
}
@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);
}
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;
}
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");
}
}
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;
}
}
private static boolean newerApi() {
try {
Material.valueOf("PLAYER_HEAD");
return true;
} catch (IllegalArgumentException e) { // If PLAYER_HEAD doesn't exist
return false;
}
}
public Material get() {
try {
return Material.valueOf(this.materialName);
} catch (Exception exception) {
return null;
}
}
@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);
}
}
}
@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);
}
}
}
public Material getRandMat() {
return Material.valueOf(randMat);
}