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

The following examples show how to use org.bukkit.Material#getMaterial() . 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: ItemService.java    From Transport-Pipes with MIT License 5 votes vote down vote up
@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();
}
 
Example 2
Source File: DisplayArmorstand.java    From AstralEdit with Apache License 2.0 5 votes vote down vote up
/**
 * 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());
    }
}
 
Example 3
Source File: ItemStackParser.java    From BedwarsRel with GNU General Public License v3.0 5 votes vote down vote up
@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;
}
 
Example 4
Source File: Crook.java    From ExoticGarden with GNU General Public License v3.0 5 votes vote down vote up
@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;
        }

    };
}
 
Example 5
Source File: CompatibilityUtils.java    From NovaGuilds with GNU General Public License v3.0 5 votes vote down vote up
/**
 * 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);
}
 
Example 6
Source File: WandCommand.java    From RedProtect with GNU General Public License v3.0 5 votes vote down vote up
@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;
}
 
Example 7
Source File: MiningCertainTaskType.java    From Quests with MIT License 5 votes vote down vote up
@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;
}
 
Example 8
Source File: DisplayArmorstand.java    From AstralEdit with Apache License 2.0 5 votes vote down vote up
/**
 * 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());
    }
}
 
Example 9
Source File: SafeSpotTeleport.java    From askyblock with GNU General Public License v2.0 4 votes vote down vote up
/**
 * 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;
}
 
Example 10
Source File: FaweAdapter_1_11.java    From FastAsyncWorldedit with GNU General Public License v3.0 4 votes vote down vote up
public Material getMaterial(int id)
{
    return Material.getMaterial(id);
}
 
Example 11
Source File: CraftItemStack.java    From Kettle with GNU General Public License v3.0 4 votes vote down vote up
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;
}
 
Example 12
Source File: ItemStackBuilder.java    From CloudNet with Apache License 2.0 4 votes vote down vote up
/**
 * @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();
}
 
Example 13
Source File: CraftBlock.java    From Kettle with GNU General Public License v3.0 4 votes vote down vote up
public Material getType() {
    return Material.getMaterial(getTypeId());
}
 
Example 14
Source File: CraftItemStack.java    From Carbon with GNU Lesser General Public License v3.0 4 votes vote down vote up
@SuppressWarnings("deprecation")
private CraftItemStack(int typeId, int amount, short durability, ItemMeta itemMeta) {
	this(Material.getMaterial(typeId), amount, durability, itemMeta);
}
 
Example 15
Source File: HumanPet.java    From SonarPet with GNU General Public License v3.0 4 votes vote down vote up
@Override
public Material getEquipment() {
    return Material.getMaterial(((IEntityHumanPet) this.getEntityPet()).getEquipmentId());
}
 
Example 16
Source File: FlagGui.java    From RedProtect with GNU General Public License v3.0 4 votes vote down vote up
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();
        }
    }
}
 
Example 17
Source File: Materials.java    From AreaShop with GNU General Public License v3.0 4 votes vote down vote up
/**
 * 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;
}
 
Example 18
Source File: MaterialConfigParser.java    From EliteMobs with GNU General Public License v3.0 4 votes vote down vote up
public static Material parseMaterial(Configuration configuration, String previousPath) {
    String path = automatedStringBuilder(previousPath, "Item Type");
    return Material.getMaterial(configuration.getString(path));
}
 
Example 19
Source File: ConfigManager.java    From NovaGuilds with GNU General Public License v3.0 2 votes vote down vote up
/**
 * 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());
}
 
Example 20
Source File: BlockCanBuildEvent.java    From Kettle with GNU General Public License v3.0 2 votes vote down vote up
/**
 * 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);
}