下面列出了org.bukkit.Material#getMaterial ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
@SuppressWarnings("deprecation")
private boolean matchBlock(Task task, Block block) {
Material material;
Object configBlock = task.getConfigValues().containsKey("block") ? task.getConfigValue("block") : task.getConfigValue("blocks");
Object configData = task.getConfigValue("data");
Object configSimilarBlocks = task.getConfigValue("use-similar-blocks");
List<String> checkBlocks = new ArrayList<>();
if (configBlock instanceof List) {
checkBlocks.addAll((List) configBlock);
} else {
checkBlocks.add(String.valueOf(configBlock));
}
for (String materialName : checkBlocks) {
// LOG:1 LOG:2 LOG should all be supported with this
String[] split = materialName.split(":");
int comparableData = (int) configData;
if (split.length > 1) {
comparableData = Integer.parseInt(split[1]);
}
material = Material.getMaterial(String.valueOf(split[0]));
Material blockType = block.getType();
short blockData = block.getData();
if (blockType.equals(material)) {
return configData == null || ((int) blockData) == comparableData;
}
}
return false;
}
/**
* Initializes the armorstand
*
* @param player player
* @param location location
* @param id id
* @param data data
* @param watchers watchers
*/
public DisplayArmorstand(Player player, Location location, int id, byte data, Set<Player> watchers) {
super();
this.watchers = watchers;
this.player = player;
this.armorStand = new EntityArmorStand(((CraftWorld) player.getWorld()).getHandle());
final NBTTagCompound compound = new NBTTagCompound();
compound.setBoolean("invulnerable", true);
compound.setBoolean("Invisible", true);
compound.setBoolean("PersistenceRequired", true);
compound.setBoolean("NoBasePlate", true);
this.armorStand.a(compound);
this.armorStand.setLocation(location.getX(), location.getY(), location.getZ(), 0, 0);
this.storedId = id;
this.storedData = data;
ItemStackBuilder stackBuilder = new ItemStackBuilder(Material.getMaterial(id), 1, data);
this.getCraftEntity().setHelmet(stackBuilder.build());
this.getCraftEntity().setBodyPose(new EulerAngle(3.15, 0, 0));
this.getCraftEntity().setLeftLegPose(new EulerAngle(3.15, 0, 0));
this.getCraftEntity().setRightLegPose(new EulerAngle(3.15, 0, 0));
if (((ArmorStand) this.armorStand.getBukkitEntity()).getHelmet().getType() == Material.AIR) {
stackBuilder = new ItemStackBuilder(Material.SKULL_ITEM, 1, (short) 3);
if (id == Material.WATER.getId() || id == Material.STATIONARY_WATER.getId()) {
stackBuilder.setSkin(NMSRegistry.WATER_HEAD);
} else if (id == Material.LAVA.getId() || id == Material.STATIONARY_LAVA.getId()) {
stackBuilder.setSkin(NMSRegistry.LAVA_HEAD);
} else {
stackBuilder.setSkin(NMSRegistry.NOT_FOUND);
}
((ArmorStand) this.armorStand.getBukkitEntity()).setHelmet(stackBuilder.build());
}
}
@SuppressWarnings("deprecation")
private Material parseMaterial() {
Material material = null;
String materialString = this.linkedSection.get("item").toString();
if (Utils.isNumber(materialString)) {
material = Material.getMaterial(Integer.parseInt(materialString));
} else {
material = Material.getMaterial(materialString);
}
return material;
}
@Override
public BlockBreakHandler getItemHandler() {
return new BlockBreakHandler() {
@Override
public boolean isPrivate() {
return false;
}
@Override
public boolean onBlockBreak(BlockBreakEvent e, ItemStack item, int fortune, List<ItemStack> drops) {
if (isItem(item)) {
damageItem(e.getPlayer(), item);
if (Tag.LEAVES.isTagged(e.getBlock().getType()) && ThreadLocalRandom.current().nextInt(100) < CHANCE) {
ItemStack sapling = new ItemStack(Material.getMaterial(e.getBlock().getType().toString().replace("LEAVES", "SAPLING")));
drops.add(sapling);
}
return true;
}
return false;
}
};
}
/**
* Gets material enum depending on the version
*
* @return material enum
*/
public Material get() {
if(ConfigManager.getServerVersion().isNewerThan(ConfigManager.ServerVersion.MINECRAFT_1_12_R1)) {
return Material.getMaterial("LEGACY_" + legacyName);
}
return Material.getMaterial(legacyName);
}
@Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
if (sender instanceof ConsoleCommandSender) {
HandleHelpPage(sender, 1);
return true;
}
Player player = (Player) sender;
if (RedProtect.get().config.getWorldClaimType(player.getWorld().getName()).equalsIgnoreCase("BLOCK") && !RedProtect.get().ph.hasPerm(player, "redprotect.command.admin.wand"))
return true;
if (args.length == 0) {
Inventory inv = player.getInventory();
Material mat = Material.getMaterial(RedProtect.get().config.configRoot().wands.adminWandID);
ItemStack item = new ItemStack(mat);
if (!inv.contains(mat) && inv.firstEmpty() != -1) {
inv.addItem(item);
RedProtect.get().lang.sendMessage(player, RedProtect.get().lang.get("cmdmanager.wand.given").replace("{item}", item.getType().name()));
} else {
RedProtect.get().lang.sendMessage(player, RedProtect.get().lang.get("cmdmanager.wand.nospace").replace("{item}", item.getType().name()));
}
return true;
}
RedProtect.get().lang.sendCommandHelp(sender, "wand", true);
return true;
}
/**
* Initializes the armorstand
*
* @param player player
* @param location location
* @param id id
* @param data data
* @param watchers watchers
*/
public DisplayArmorstand(Player player, Location location, int id, byte data, Set<Player> watchers) {
super();
this.watchers = watchers;
this.player = player;
this.armorStand = new EntityArmorStand(((CraftWorld) player.getWorld()).getHandle());
final NBTTagCompound compound = new NBTTagCompound();
compound.setBoolean("invulnerable", true);
compound.setBoolean("Invisible", true);
compound.setBoolean("PersistenceRequired", true);
compound.setBoolean("NoBasePlate", true);
this.armorStand.a(compound);
this.armorStand.setLocation(location.getX(), location.getY(), location.getZ(), 0, 0);
this.storedId = id;
this.storedData = data;
ItemStackBuilder stackBuilder = new ItemStackBuilder(Material.getMaterial(id), 1, data);
this.getCraftEntity().setHelmet(stackBuilder.build());
this.getCraftEntity().setBodyPose(new EulerAngle(3.15, 0, 0));
this.getCraftEntity().setLeftLegPose(new EulerAngle(3.15, 0, 0));
this.getCraftEntity().setRightLegPose(new EulerAngle(3.15, 0, 0));
if (((ArmorStand) this.armorStand.getBukkitEntity()).getHelmet().getType() == Material.AIR) {
stackBuilder = new ItemStackBuilder(Material.SKULL_ITEM, 1, (short) 3);
if (id == Material.WATER.getId() || id == Material.STATIONARY_WATER.getId()) {
stackBuilder.setSkin(NMSRegistry.WATER_HEAD);
} else if (id == Material.LAVA.getId() || id == Material.STATIONARY_LAVA.getId()) {
stackBuilder.setSkin(NMSRegistry.LAVA_HEAD);
} else {
stackBuilder.setSkin(NMSRegistry.NOT_FOUND);
}
((ArmorStand) this.armorStand.getBukkitEntity()).setHelmet(stackBuilder.build());
}
}
@Inject
public ItemService(GeneralConf generalConf) {
Material wrenchMaterial = Material.getMaterial(generalConf.getWrenchItem().toUpperCase(Locale.ENGLISH));
Objects.requireNonNull(wrenchMaterial, "The material for the wrench item set in the config file is not valid.");
wrench = generalConf.getWrenchGlowing() ? createGlowingItem(wrenchMaterial) : new ItemStack(wrenchMaterial);
wrench = changeDisplayNameAndLoreConfig(wrench, LangConf.Key.WRENCH.getLines());
tempConf = new YamlConfiguration();
}
public static Material parseMaterial(Configuration configuration, String previousPath) {
String path = automatedStringBuilder(previousPath, "Item Type");
return Material.getMaterial(configuration.getString(path));
}
/**
* Get material based on a sign material name.
* @param name Name of the sign material
* @return null if not a sign, otherwise the material matching the name (when the material is not available on the current minecraft version, it returns the base type)
*/
public static Material signNameToMaterial(String name) {
// Expected null case
if (!isSign(name)) {
return null;
}
Material result = null;
if (legacyMaterials) {
// 1.12 and lower just know SIGN_POST, WALL_SIGN and SIGN
if (FLOOR_SIGN_TYPES.contains(name)) {
result = Material.getMaterial("SIGN_POST");
} else if (WALL_SIGN_TYPES.contains(name)) {
result = Material.getMaterial("WALL_SIGN");
if (result == null) {
result = Material.getMaterial("SIGN");
}
}
} else {
// Try saved name (works for wood types on 1.14, regular types for below)
result = Material.getMaterial(name);
if (result == null) {
// Cases for 1.13, which don't know wood types, but need new materials
if (FLOOR_SIGN_TYPES.contains(name)) {
// SIGN -> OAK_SIGN for 1.14
result = Material.getMaterial("OAK_SIGN");
// Fallback for 1.13
if (result == null) {
result = Material.getMaterial("SIGN");
}
} else if (WALL_SIGN_TYPES.contains(name)) {
// WALL_SIGN -> OAK_WALL_SIGN for 1.14
result = Material.getMaterial("OAK_WALL_SIGN");
// Fallback for 1.13
if (result == null) {
result = Material.getMaterial("WALL_SIGN");
}
}
}
}
if (result == null) {
AreaShop.debug("Materials.get() null result:", name, "legacyMaterials:", legacyMaterials);
}
return result;
}
public FlagGui(String name, Player player, Region region, boolean editable, int maxSlots) {
this.editable = editable;
this.name = name;
this.player = player;
this.region = region;
if (maxSlots <= 9) {
this.size = 9;
} else if (maxSlots <= 18) {
this.size = 18;
} else if (maxSlots <= 27) {
this.size = 27;
} else if (maxSlots <= 36) {
this.size = 36;
} else if (maxSlots <= 45) {
this.size = 45;
} else if (maxSlots <= 54) {
this.size = 54;
} else {
throw new IllegalArgumentException("Parameter size is exceeding size limit (54)");
}
this.guiItems = new ItemStack[this.size];
allowEnchant = RedProtect.get().bukkitVersion >= 181;
for (String flag : RedProtect.get().config.getDefFlags()) {
try {
if (!RedProtect.get().config.guiRoot().gui_flags.containsKey(flag)) {
continue;
}
if (RedProtect.get().ph.hasFlagPerm(player, flag) && (RedProtect.get().config.configRoot().flags.containsKey(flag) || RedProtect.get().config.AdminFlags.contains(flag))) {
if (flag.equals("pvp") && !RedProtect.get().config.configRoot().flags.containsKey("pvp")) {
continue;
}
int i = RedProtect.get().config.getGuiSlot(flag);
Object flagValue = region.getFlags().get(flag);
String flagString;
if (flagValue instanceof Boolean) {
flagString = RedProtect.get().guiLang.getFlagString(flagValue.toString());
} else {
flagString = RedProtect.get().guiLang.getFlagString("list");
}
if (flag.equalsIgnoreCase("clan")) {
if (flagValue.toString().equals("")) {
flagString = RedProtect.get().guiLang.getFlagString("false");
} else {
flagString = RedProtect.get().guiLang.getFlagString("true");
}
}
this.guiItems[i] = new ItemStack(Material.getMaterial(RedProtect.get().config.guiRoot().gui_flags.get(flag).material));
ItemMeta guiMeta = this.guiItems[i].getItemMeta();
guiMeta.setDisplayName(translateAlternateColorCodes('&', RedProtect.get().guiLang.getFlagName(flag)));
List<String> lore = new ArrayList<>(Arrays.asList(
translateAlternateColorCodes('&', RedProtect.get().guiLang.getFlagString("value") + " " + flagString),
"§0" + flag));
lore.addAll(RedProtect.get().guiLang.getFlagDescription(flag));
guiMeta.setLore(lore);
if (allowEnchant) {
if (flagValue.toString().equalsIgnoreCase("true")) {
guiMeta.addEnchant(Enchantment.DURABILITY, 0, true);
} else {
guiMeta.removeEnchant(Enchantment.DURABILITY);
}
guiMeta.addItemFlags(ItemFlag.HIDE_ENCHANTS);
} else {
if (flagValue.toString().equalsIgnoreCase("true")) {
this.guiItems[i].setAmount(2);
} else {
this.guiItems[i].setAmount(1);
}
}
this.guiItems[i].setType(Material.getMaterial(RedProtect.get().config.guiRoot().gui_flags.get(flag).material));
this.guiItems[i].setItemMeta(guiMeta);
}
} catch (Exception e) {
this.player.sendMessage(ChatColor.RED + "Seems RedProtect have a wrong Item Gui or a problem on guiconfig for flag " + flag);
}
}
for (int slotc = 0; slotc < this.size; slotc++) {
if (this.guiItems[slotc] == null) {
this.guiItems[slotc] = RedProtect.get().config.getGuiSeparator();
}
}
}
@Override
public Material getEquipment() {
return Material.getMaterial(((IEntityHumanPet) this.getEntityPet()).getEquipmentId());
}
/**
* Returns true if the location is a safe one.
* @param chunk
* @param x
* @param y
* @param z
* @param worldHeight
* @return true if this is a safe spot, false if this is a portal scan
*/
@SuppressWarnings("deprecation")
private boolean checkBlock(ChunkSnapshot chunk, int x, int y, int z, int worldHeight) {
World world = location.getWorld();
Material type = Material.getMaterial(chunk.getBlockTypeId(x, y, z));
if (!type.equals(Material.AIR)) { // AIR
Material space1 = Material.getMaterial(chunk.getBlockTypeId(x, Math.min(y + 1, worldHeight), z));
Material space2 = Material.getMaterial(chunk.getBlockTypeId(x, Math.min(y + 2, worldHeight), z));
if ((space1.equals(Material.AIR) && space2.equals(Material.AIR)) || (space1.equals(Material.PORTAL) && space2.equals(Material.PORTAL))
&& (!type.toString().contains("FENCE") && !type.toString().contains("DOOR") && !type.toString().contains("GATE") && !type.toString().contains("PLATE"))) {
switch (type) {
// Unsafe
case ANVIL:
case BARRIER:
case BOAT:
case CACTUS:
case DOUBLE_PLANT:
case ENDER_PORTAL:
case FIRE:
case FLOWER_POT:
case LADDER:
case LAVA:
case LEVER:
case LONG_GRASS:
case PISTON_EXTENSION:
case PISTON_MOVING_PIECE:
case SIGN_POST:
case SKULL:
case STANDING_BANNER:
case STATIONARY_LAVA:
case STATIONARY_WATER:
case STONE_BUTTON:
case TORCH:
case TRIPWIRE:
case WATER:
case WEB:
case WOOD_BUTTON:
//Block is dangerous
break;
case PORTAL:
if (portal) {
// A portal has been found, switch to non-portal mode now
portal = false;
}
break;
default:
return safe(chunk, x, y, z, world);
}
}
}
return false;
}
@SuppressWarnings("deprecation")
private CraftItemStack(int typeId, int amount, short durability, ItemMeta itemMeta) {
this(Material.getMaterial(typeId), amount, durability, itemMeta);
}
public Material getType() {
return Material.getMaterial(getTypeId());
}
/**
* @deprecated will only work in versions lower than 1.13
*/
@Deprecated
public ItemStackBuilder(int material) {
this.itemStack = new ItemStack(Material.getMaterial(material));
this.itemMeta = itemStack.getItemMeta();
}
static Material getType(net.minecraft.item.ItemStack item) {
Material material = Material.getMaterial(item == null ? 0 : CraftMagicNumbers.getId(item.getItem()));
return material == null ? Material.AIR : material;
}
public Material getMaterial(int id)
{
return Material.getMaterial(id);
}
/**
* Gets the Material that we are trying to place.
*
* @return The Material that we are trying to place
*/
public Material getMaterial() {
return Material.getMaterial(material);
}
/**
* Gets a material from its name
*
* @param path config path
* @return the value
*/
public Material getMaterial(String path) {
String string = getString(path, null, false);
return Material.getMaterial((string.contains(":") ? org.apache.commons.lang.StringUtils.split(string, ':')[0] : string).toUpperCase());
}