Java Code Examples for org.bukkit.Material#matchMaterial()
The following examples show how to use
org.bukkit.Material#matchMaterial() .
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: ItemKeepBuilder.java From CardinalPGM with MIT License | 6 votes |
@Override public ModuleCollection<ItemKeep> load(Match match) { ModuleCollection<ItemKeep> results = new ModuleCollection<>(); for (Element itemKeep : match.getDocument().getRootElement().getChildren("itemkeep")) { for (Element item : itemKeep.getChildren("item")) { Material material; int damageValue = 0; if (item.getText().contains(":")) { material = Material.matchMaterial(item.getText().split(":")[0]); damageValue = Numbers.parseInt(item.getText().split(":")[1]); } else { material = Material.matchMaterial(item.getText()); } if (item.getAttributeValue("damage") != null) { damageValue = Numbers.parseInt(item.getAttributeValue("damage")); } results.add(new ItemKeep(material, damageValue)); } } return results; }
Example 2
Source File: TagFormatter.java From HoloAPI with GNU General Public License v3.0 | 6 votes |
public ItemStack matchItem(String content) { Matcher matcher = Pattern.compile("%item:([0-9]+)(?:,([0-9]+))?%").matcher(content); while (matcher.find()) { try { int id = Integer.parseInt(matcher.group(1)); int durability = matcher.group(2) == null ? 0 : Integer.parseInt(matcher.group(2)); return new ItemStack(id, 1, (short) durability); } catch (NumberFormatException ignored) { } } Matcher matcherStr = Pattern.compile("%item:([^0-9%]+)%").matcher(content); while (matcherStr.find()) { Material m = Material.matchMaterial(matcherStr.group(1)); if (m != null) { return new ItemStack(m); } } return null; }
Example 3
Source File: NoEntryHandler.java From CombatLogX with GNU General Public License v3.0 | 6 votes |
public Material getForceFieldMaterial() { String materialString = getForceFieldMaterialString(); int minorVersion = VersionUtil.getMinorVersion(); if(minorVersion >= 13) { try { Class<?> classMaterial = Class.forName("org.bukkit.Material"); Method method_matchMaterial = classMaterial.getDeclaredMethod("matchMaterial", String.class, Boolean.TYPE); return (Material) method_matchMaterial.invoke(null, materialString, false); } catch(ReflectiveOperationException ex) { return Material.matchMaterial(materialString); } } if(materialString.contains(":")) { String[] split = materialString.split(Pattern.quote(":")); materialString = split[0]; } return Material.matchMaterial(materialString); }
Example 4
Source File: ItemDisguise.java From iDisguise with Creative Commons Attribution Share Alike 4.0 International | 6 votes |
public void setMaterial(String paramMaterial) { Material material = Material.matchMaterial(paramMaterial.replace('-', '_')); if(material != null) { setMaterial(material); return; } else if(paramMaterial.contains(":")) { String[] s = paramMaterial.split(":", 2); material = Material.matchMaterial(s[0].replace('-', '_')); if(material != null) { try { short durability = Short.parseShort(s[1]); setMaterial(material); setDurability(durability); return; } catch(NumberFormatException e) { throw new IllegalArgumentException("Invalid data value!"); } } } throw new IllegalArgumentException("Unknown argument!"); }
Example 5
Source File: MsgUtil.java From QuickShop-Reremake with GNU General Public License v3.0 | 5 votes |
/** * Get item's i18n name, If you want get item name, use Util.getItemStackName * * @param itemBukkitName ItemBukkitName(e.g. Material.STONE.name()) * @return String Item's i18n name. */ public static String getItemi18n(@NotNull String itemBukkitName) { if (itemBukkitName.isEmpty()) { return "Item is empty"; } String itemnameI18n = itemi18n.getString("itemi18n." + itemBukkitName); if (itemnameI18n != null && !itemnameI18n.isEmpty()) { return itemnameI18n; } Material material = Material.matchMaterial(itemBukkitName); if (material == null) { return "Material not exist"; } return Util.prettifyText(material.name()); }
Example 6
Source File: MultiVersionLookup.java From QualityArmory with GNU General Public License v3.0 | 5 votes |
public static Material getCarrotOnAStick() { if (carrotstick == null) { try { carrotstick = Material.matchMaterial("CARROT_STICK"); } catch (Error | Exception e) { } if (carrotstick == null) carrotstick = Material.CARROT_ON_A_STICK; } return carrotstick; }
Example 7
Source File: MultiVersionLookup.java From QualityArmory with GNU General Public License v3.0 | 5 votes |
public static Material getIronShovel() { if (ironshovel == null) { try { ironshovel = Material.matchMaterial("IRON_SPADE"); } catch (Error | Exception e) { } if (ironshovel == null) ironshovel = Material.IRON_SHOVEL; } return ironshovel; }
Example 8
Source File: XMLUtils.java From ProjectAres with GNU Affero General Public License v3.0 | 5 votes |
public static Material parseMaterial(Node node, String text) throws InvalidXMLException { Material material = Material.matchMaterial(text); if(material == null) { throw new InvalidXMLException("Unknown material '" + text + "'", node); } return material; }
Example 9
Source File: MultiVersionLookup.java From QualityArmory with GNU General Public License v3.0 | 5 votes |
public static Material getGlass() { if (glasspane == null) { try { glasspane = Material.matchMaterial("STAINED_GLASS_PANE"); } catch (Error | Exception e) { } if (glasspane == null) glasspane = Material.YELLOW_STAINED_GLASS_PANE; } return glasspane; }
Example 10
Source File: BlockCache.java From Modern-LWC with MIT License | 5 votes |
/** * Get a block's id, or try to add it if it doesn't exist. * * @param blockName * @return */ public int getBlockId(String blockName) { Material material = Material.matchMaterial(blockName); if (material != null) { return getBlockId(material); } return addBlock(blockName); }
Example 11
Source File: BlockCache.java From Modern-LWC with MIT License | 5 votes |
/** * Adds a block to the block cache by its Block name, and tries to add it if it doesn't exist. * * @param block */ public int addBlock(String block) { Material material = Material.matchMaterial(block); if (material != null) { return addBlock(material); } return -1; }
Example 12
Source File: VoxelVoxelCommand.java From FastAsyncWorldedit with GNU General Public License v3.0 | 5 votes |
public boolean onCommand(Player player, String[] args) { Sniper sniper = this.plugin.getSniperManager().getSniperForPlayer(player); SnipeData snipeData = sniper.getSnipeData(sniper.getCurrentToolId()); if(args.length == 0) { Block material1 = (new RangeBlockHelper(player, player.getWorld())).getTargetBlock(); if(material1 != null) { if(!player.hasPermission("voxelsniper.ignorelimitations") && this.plugin.getVoxelSniperConfiguration().getLiteSniperRestrictedItems().contains(Integer.valueOf(material1.getTypeId()))) { player.sendMessage("You are not allowed to use " + material1.getType().name() + "."); return true; } snipeData.setVoxelId(material1.getTypeId()); snipeData.getVoxelMessage().voxel(); snipeData.setPattern(null, null); } return true; } else { Material material = Material.matchMaterial(args[0]); if(material != null && material.isBlock()) { if(!player.hasPermission("voxelsniper.ignorelimitations") && this.plugin.getVoxelSniperConfiguration().getLiteSniperRestrictedItems().contains(Integer.valueOf(material.getId()))) { player.sendMessage("You are not allowed to use " + material.name() + "."); return true; } else { snipeData.setVoxelId(material.getId()); snipeData.getVoxelMessage().voxel(); snipeData.setPattern(null, null); return true; } } else { PatternUtil.parsePattern(player, snipeData, args[0]); return true; } } }
Example 13
Source File: ItemBuilder.java From Crazy-Crates with MIT License | 4 votes |
/** * Set the type of item the builder is set to. * @param material The material you wish to set. * @return The ItemBuilder with updated info. */ public ItemBuilder setMaterial(Material material) { this.material = material; this.isHead = material == (cc.useNewMaterial() ? Material.matchMaterial("PLAYER_HEAD") : Material.matchMaterial("SKULL_ITEM")); return this; }
Example 14
Source File: Parser.java From CardinalPGM with MIT License | 4 votes |
public static Pair<Material, Integer> parseMaterial(String material) { String type = material.split(":")[0].trim(); Integer damageValue = material.contains(":") ? Numbers.parseInt(material.split(":")[1].trim()) : -1; return new ImmutablePair<>(NumberUtils.isNumber(type) ? Material.getMaterial(Integer.parseInt(type)) : Material.matchMaterial(type), damageValue); }
Example 15
Source File: GunYMLLoader.java From QualityArmory with GNU General Public License v3.0 | 4 votes |
public static void loadAmmo(QAMain main) { if (new File(main.getDataFolder(), "ammo").exists()) { int items = 0; for (File f : new File(main.getDataFolder(), "ammo").listFiles()) { try { if (f.getName().contains("yml")) { FileConfiguration f2 = YamlConfiguration.loadConfiguration(f); if ((!f2.contains("invalid")) || !f2.getBoolean("invalid")) { Material m = f2.contains("material") ? Material.matchMaterial(f2.getString("material")) : Material.DIAMOND_AXE; int variant = f2.contains("variant") ? f2.getInt("variant") : 0; final String name = f2.getString("name"); if(QAMain.verboseLoadingLogging) main.getLogger().info("-Loading AmmoType: " + name); String extraData = null; if (f2.contains("skull_owner")) { extraData = f2.getString("skull_owner"); } String ed2 = null; if (f2.contains("skull_owner_custom_url") && !f2.getString("skull_owner_custom_url").equals(Ammo.NO_SKIN_STRING)) { ed2 = f2.getString("skull_owner_custom_url"); } final MaterialStorage ms = MaterialStorage.getMS(m, f2.getInt("id"), variant, extraData, ed2); final ItemStack[] materails = main .convertIngredients(f2.getStringList("craftingRequirements")); final String displayname = f2.contains("displayname") ? ChatColor.translateAlternateColorCodes('&', f2.getString("displayname")) : (ChatColor.WHITE + name); final List<String> extraLore2 = f2.contains("lore") ? f2.getStringList("lore") : null; final List<String> extraLore = new ArrayList<String>(); try { for (String lore : extraLore2) { extraLore.add(ChatColor.translateAlternateColorCodes('&', lore)); } } catch (Error | Exception re52) { } final double price = f2.contains("price") ? f2.getDouble("price") : 100; int amountA = f2.getInt("maxAmount"); double piercing = f2.getDouble("piercingSeverity"); Ammo da = new Ammo(name, displayname, extraLore, ms, amountA, false, 1, price, materails, piercing); da.setCustomLore(extraLore); QAMain.ammoRegister.put(ms, da); items++; if (extraData != null) { da.setSkullOwner(extraData); } if (ed2 != null) { da.setCustomSkin(ed2); } if (f2.contains("craftingReturnAmount")) { da.setCraftingReturn(f2.getInt("craftingReturnAmount")); } } } } catch (Exception e) { e.printStackTrace(); } } if(!QAMain.verboseLoadingLogging) main.getLogger().info("-Loaded "+items+" Ammo types."); } }
Example 16
Source File: ConfigManager.java From ObsidianDestroyer with GNU General Public License v3.0 | 4 votes |
/** * Translates the materials.yml from memory into a map for quick access * * @return map of materials keys and material durability data */ public Map<String, DurabilityMaterial> getDurabilityMaterials() { final long time = System.currentTimeMillis(); final ConfigurationSection section = materials.getConfigurationSection("HandledMaterials"); int errorDuraCount = 0; int invalidDuraCount = 0; int disabledDuraCount = 0; Map<String, DurabilityMaterial> durabilityMaterials = new HashMap<>(); for (String durabilityMaterial : section.getKeys(false)) { try { final ConfigurationSection materialSection = section.getConfigurationSection(durabilityMaterial); Material material = Material.matchMaterial(durabilityMaterial); if (material == null) { material = Material.matchMaterial(durabilityMaterial, true); if (material == null) { if (DurabilityMaterial.isEnabled(materialSection)) { ObsidianDestroyer.LOG.log(Level.WARNING, "Invalid Material Type: Unable to load ''{0}''", durabilityMaterial); } invalidDuraCount++; continue; } else { ObsidianDestroyer.LOG.log(Level.WARNING, "Semi-Valid Material Type: Loaded as ''{0}''", material.name()); } } if (!Util.isSolid(material) && !materialSection.contains("HandleNonSolid") && !materialSection.getBoolean("HandleNonSolid")) { ObsidianDestroyer.LOG.log(Level.WARNING, "Non-Solid Material Type: Did not load ''{0}''", durabilityMaterial); invalidDuraCount++; continue; } final DurabilityMaterial durablock; if (materialSection.contains("MetaData")) { durablock = new DurabilityMaterial(material, materialSection.getInt("MetaData"), materialSection); } else { durablock = new DurabilityMaterial(material, materialSection); } if (durablock.getEnabled()) { if (getVerbose() || getDebug()) { ObsidianDestroyer.LOG.log(Level.INFO, "Loaded durability of ''{0}'' for ''{1}''", new Object[]{durablock.getDurability(), durablock.toString()}); } durabilityMaterials.put(durablock.toString(), durablock); } else if (getDebug()) { ObsidianDestroyer.debug("Disabled durability of '" + durablock.getDurability() + "' for '" + durablock.toString() + "'"); disabledDuraCount++; } } catch (Exception e) { ObsidianDestroyer.LOG.log(Level.SEVERE, "Failed loading material ''{0}''", durabilityMaterial); errorDuraCount++; } } ObsidianDestroyer.LOG.log(Level.INFO, "Loaded and enabled ''{0}'' material durabilities from config in ''{1}'' ms.", new Object[]{durabilityMaterials.size(), (System.currentTimeMillis() - time)}); ObsidianDestroyer.LOG.log(Level.INFO, "Material in Error: ''{0}'' Invalid: ''{1}'' Disabled: ''{2}''", new Object[]{errorDuraCount, invalidDuraCount, disabledDuraCount}); return durabilityMaterials; }
Example 17
Source File: GunYMLLoader.java From QualityArmory with GNU General Public License v3.0 | 4 votes |
public static void loadArmor(QAMain main) { if (new File(main.getDataFolder(), "armor").exists()) { int items = 0; for (File f : new File(main.getDataFolder(), "armor").listFiles()) { try { if (f.getName().contains("yml")) { FileConfiguration f2 = YamlConfiguration.loadConfiguration(f); if ((!f2.contains("invalid")) || !f2.getBoolean("invalid")) { final String name = f2.getString("name"); if(QAMain.verboseLoadingLogging) main.getLogger().info("-Loading Armor: " + name); Material m = f2.contains("material") ? Material.matchMaterial(f2.getString("material")) : Material.DIAMOND_AXE; int variant = f2.contains("variant") ? f2.getInt("variant") : 0; final MaterialStorage ms = MaterialStorage.getMS(m, f2.getInt("id"), variant); final ItemStack[] materails = main .convertIngredients(f2.getStringList("craftingRequirements")); final String displayname = f2.contains("displayname") ? ChatColor.translateAlternateColorCodes('&', f2.getString("displayname")) : (ChatColor.WHITE + name); final List<String> rawLore = f2.contains("lore") ? f2.getStringList("lore") : null; final List<String> lore = new ArrayList<String>(); try { for (String lore2 : rawLore) { lore.add(ChatColor.translateAlternateColorCodes('&', lore2)); } } catch (Error | Exception re52) { } final int price = f2.contains("price") ? f2.getInt("price") : 100; WeaponType wt = WeaponType.getByName(f2.getString("MiscType")); if (wt == WeaponType.HELMET) { QAMain.armorRegister.put(ms, new Helmet(name, displayname, lore, materails, ms, price)); items++; } } } } catch (Exception e) { e.printStackTrace(); } } if(!QAMain.verboseLoadingLogging) main.getLogger().info("-Loaded "+items+" Armor types."); } }
Example 18
Source File: LevelManager.java From SkyWarsReloaded with GNU General Public License v3.0 | 4 votes |
public void loadParticleEffects() { particleList.clear(); File particleFile = new File(SkyWarsReloaded.get().getDataFolder(), "particleeffects.yml"); if (!particleFile.exists()) { SkyWarsReloaded.get().saveResource("particleeffects.yml", false); } if (particleFile.exists()) { FileConfiguration storage = YamlConfiguration.loadConfiguration(particleFile); if (storage.getConfigurationSection("effects") != null) { for (String key: storage.getConfigurationSection("effects").getKeys(false)) { String name = storage.getString("effects." + key + ".displayname"); String material = storage.getString("effects." + key + ".icon"); int level = storage.getInt("effects." + key + ".level"); int cost = storage.getInt("effects." + key + ".cost"); List<String> particles = storage.getStringList("effects." + key + ".particles"); List<ParticleEffect> effects = new ArrayList<ParticleEffect>(); if (particles != null) { for (String part: particles) { final String[] parts = part.split(":"); if (parts.length == 6 && SkyWarsReloaded.getNMS().isValueParticle(parts[0].toUpperCase()) && Util.get().isFloat(parts[1]) && Util.get().isFloat(parts[2]) && Util.get().isFloat(parts[3]) && Util.get().isInteger(parts[4]) && Util.get().isInteger(parts[5])) { effects.add(new ParticleEffect(parts[0].toUpperCase(), Float.valueOf(parts[1]), Float.valueOf(parts[2]), Float.valueOf(parts[3]), Integer.valueOf(parts[4]), Integer.valueOf(parts[5]))); } else { SkyWarsReloaded.get().getLogger().info("The particle effect " + key + " has an invalid particle effect"); } } } Material mat = Material.matchMaterial(material); if (mat != null) { particleList.add(new ParticleItem(key, effects, name, mat, level, cost)); } } } } Collections.<ParticleItem>sort(particleList); }
Example 19
Source File: SkyBlockMenu.java From uSkyBlock with GNU General Public License v3.0 | 4 votes |
private void addExtraMenus(Player player, Inventory menu) { ConfigurationSection extras = plugin.getConfig().getConfigurationSection("options.extra-menus"); if (extras == null) { return; } for (String sIndex : extras.getKeys(false)) { ConfigurationSection menuSection = extras.getConfigurationSection(sIndex); if (menuSection == null) { continue; } try { int index = Integer.parseInt(sIndex, 10); String title = menuSection.getString("title", "\u00a9Unknown"); String icon = menuSection.getString("displayItem", "CHEST"); List<String> lores = new ArrayList<>(); for (String l : menuSection.getStringList("lore")) { Matcher matcher = PERM_VALUE_PATTERN.matcher(l); if (matcher.matches()) { String perm = matcher.group("perm"); String lore = matcher.group("value"); boolean not = matcher.group("not") != null; if (perm != null) { boolean hasPerm = player.hasPermission(perm); if ((hasPerm && !not) || (!hasPerm && not)) { lores.add(lore); } } else { lores.add(lore); } } } // Only SIMPLE icons supported... ItemStack item = new ItemStack(Material.matchMaterial(icon), 1); ItemMeta meta = item.getItemMeta(); meta.setDisplayName(title); meta.setLore(lores); item.setItemMeta(meta); menu.setItem(index, item); } catch (Exception e) { log(Level.INFO, "\u00a79[uSkyBlock]\u00a7r Unable to add extra-menu " + sIndex + ": " + e); } } }
Example 20
Source File: SkyBlockMenu.java From uSkyBlock with GNU General Public License v3.0 | 4 votes |
private boolean isExtraMenuAction(Player player, ItemStack currentItem) { ConfigurationSection extras = plugin.getConfig().getConfigurationSection("options.extra-menus"); if (extras == null || currentItem == null || currentItem.getItemMeta() == null) { return false; } Material itemType = currentItem.getType(); String itemTitle = currentItem.getItemMeta().getDisplayName(); for (String sIndex : extras.getKeys(false)) { ConfigurationSection menuSection = extras.getConfigurationSection(sIndex); if (menuSection == null) { continue; } try { String title = menuSection.getString("title", "\u00a9Unknown"); String icon = menuSection.getString("displayItem", "CHEST"); Material material = Material.matchMaterial(icon); if (title.equals(itemTitle) && material == itemType) { for (String command : menuSection.getStringList("commands")) { Matcher matcher = PERM_VALUE_PATTERN.matcher(command); if (matcher.matches()) { String perm = matcher.group("perm"); String cmd = matcher.group("value"); boolean not = matcher.group("not") != null; if (perm != null) { boolean hasPerm = player.hasPermission(perm); if ((hasPerm && !not) || (!hasPerm && not)) { plugin.execCommand(player, cmd, false); } } else { plugin.execCommand(player, cmd, false); } } else { log(Level.INFO, "\u00a7a[uSkyBlock] Malformed menu " + title + ", invalid command : " + command); } } return true; } } catch (Exception e) { log(Level.INFO, "\u00a79[uSkyBlock]\u00a7r Unable to execute commands for extra-menu " + sIndex + ": " + e); } } return false; }