org.bukkit.Material Java Examples

The following examples show how to use org.bukkit.Material. 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: WoodcutterAndroid.java    From Slimefun4 with GNU General Public License v3.0 6 votes vote down vote up
private void breakLog(Block log, Block android, BlockMenu menu, BlockFace face) {
    ItemStack drop = new ItemStack(log.getType());

    if (menu.fits(drop, getOutputSlots())) {
        menu.pushItem(drop, getOutputSlots());
        log.getWorld().playEffect(log.getLocation(), Effect.STEP_SOUND, log.getType());

        if (log.getY() == android.getRelative(face).getY()) {
            Optional<Material> sapling = MaterialConverter.getSaplingFromLog(log.getType());

            if (sapling.isPresent()) {
                log.setType(sapling.get());
            }
        }
        else {
            log.setType(Material.AIR);
        }
    }
}
 
Example #2
Source File: SimpleInventoryContainer.java    From Transport-Pipes with MIT License 6 votes vote down vote up
@Override
public int spaceForItem(TPDirection insertDirection, ItemStack insertion) {
    if (isInvLocked(cachedInvHolder)) {
        return 0;
    }

    int space = 0;

    for (int i = 0; i < cachedInv.getSize(); i++) {
        ItemStack item = cachedInv.getItem(i);
        if (item == null || item.getType() == Material.AIR) {
            space += insertion.getMaxStackSize();
        } else if (item.isSimilar(insertion) && item.getAmount() < item.getMaxStackSize()) {
            space += item.getMaxStackSize() - item.getAmount();
        }
    }

    return space;
}
 
Example #3
Source File: CustomItemStack.java    From AdditionsAPI with MIT License 6 votes vote down vote up
/**
 * Add all NBT Data from a Map. The String is the NBT Key, the Object is the
 * data you wish to store. Valid types are: Void, byte, short, int, long,
 * float, double, byte[], int[], String, List and Map.
 * 
 * @param nbtData
 */
public void addAllNBTData(Map<? extends String, ? extends Object> nbtData) {
	if (itemStack == null || itemStack.getType().equals(Material.AIR))
		return;
	ItemStack stack = NbtFactory.getCraftItemStack(itemStack);
	NbtCompound nbt = NbtFactory.fromItemTag(stack);
	nbt.putAll(nbtData);
	updateLore();
}
 
Example #4
Source File: TeamChestListener.java    From BedWars with GNU Lesser General Public License v3.0 6 votes vote down vote up
@EventHandler
public void onTeamChestBuilt(BedwarsPlayerBuildBlock event) {
    if (event.isCancelled()) {
        return;
    }

    Block block = event.getBlock();
    RunningTeam team = event.getTeam();

    if (block.getType() != Material.ENDER_CHEST) {
        return;
    }

    String unhidden = APIUtils.unhashFromInvisibleStringStartsWith(event.getItemInHand(), TEAM_CHEST_PREFIX);

    if (unhidden != null || Main.getConfigurator().config.getBoolean("specials.teamchest.turn-all-enderchests-to-teamchests")) {
        team.addTeamChest(block);
        String message = i18n("team_chest_placed");
        for (Player pl : team.getConnectedPlayers()) {
            pl.sendMessage(message);
        }
    }
}
 
Example #5
Source File: ItemListener.java    From HubBasics with GNU Lesser General Public License v3.0 6 votes vote down vote up
@EventHandler(ignoreCancelled = true)
public void onLeftClick(PlayerInteractEvent event) {
    if (!(event.getAction() == Action.LEFT_CLICK_AIR || event.getAction() == Action.LEFT_CLICK_BLOCK)) {
        return;
    }
    ItemStack itemStack = ReflectionUtils.invokeMethod(event.getPlayer(), this.getItemInHandMethod);
    if (itemStack != null && itemStack.getType() != Material.AIR) {
        NBTItem nbtItem = new NBTItem(itemStack);
        if (!nbtItem.hasKey("HubBasics")) return;
        event.setCancelled(true);
        CustomItem item = HubBasics.getInstance().getItemManager().get(nbtItem.getString("HubBasics"));
        if (item == null) {
            itemStack.setType(Material.AIR); // Destroy old item
            return;
        }
        if (!item.getRunOnLeftClick()) return;
        item.onCommand(event.getPlayer());
    }
}
 
Example #6
Source File: Game.java    From ZombieEscape with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Creates a door with a given time in seconds.
 *
 * @param player the player who is setting the arena up
 * @param input  the time, in seconds, the door will take to open
 */
private void addDoor(Player player, String input) {
    Block block = player.getEyeLocation().getBlock();
    Material material = block.getType();
    if (material != Material.SIGN_POST && material != Material.WALL_SIGN) {
        Messages.BLOCK_NOT_SIGN.send(player);
        return;
    }

    int seconds = Utils.getNumber(player, input);

    if (seconds < 0) {
        Messages.BAD_SECONDS.send(player);
        return;
    }

    int signID = editedFile.createListLocation(player, block.getLocation(), "Doors");
    editedFile.getConfig().set("Doors." + signID + ".Timer", seconds);
    editedFile.saveFile();
    Messages.CREATED_SIGN.send(player, signID, seconds);
}
 
Example #7
Source File: GraphListener.java    From LagMonitor with MIT License 6 votes vote down vote up
@EventHandler(ignoreCancelled = true, priority = EventPriority.HIGH)
public void onInteract(PlayerInteractEvent clickEvent) {
    Player player = clickEvent.getPlayer();
    PlayerInventory inventory = player.getInventory();

    ItemStack mainHandItem;
    if (mainHandSupported) {
        mainHandItem = inventory.getItemInMainHand();
    } else {
        mainHandItem = inventory.getItemInHand();
    }

    if (isOurGraph(mainHandItem)) {
        inventory.setItemInMainHand(new ItemStack(Material.AIR));
    }
}
 
Example #8
Source File: EventFilterMatchModule.java    From ProjectAres with GNU Affero General Public License v3.0 6 votes vote down vote up
@EventHandler(priority = EventPriority.HIGHEST)
public void onInteract(final PlayerInteractEvent event) {
    if(cancelUnlessInteracting(event, event.getPlayer())) {
        // Allow the how-to book to be read
        if(event.getMaterial() == Material.WRITTEN_BOOK) {
            event.setUseItemInHand(Event.Result.ALLOW);
        } else {
            event.setUseItemInHand(Event.Result.DENY);
            event.setUseInteractedBlock(Event.Result.DENY);
        }

        MatchPlayer player = getMatch().getPlayer(event.getPlayer());
        if(player == null) return;

        if(!player.isSpawned()) {
            ClickType clickType = convertClick(event.getAction(), event.getPlayer());
            if(clickType == null) return;

            getMatch().callEvent(new ObserverInteractEvent(player, clickType, event.getClickedBlock(), null, event.getItem()));
        }

        // Right-clicking armor will put it on unless we do this
        event.getPlayer().updateInventory();
    }
}
 
Example #9
Source File: CommandCloudServer.java    From CloudNet with Apache License 2.0 6 votes vote down vote up
private boolean removeSign(CommandSender commandSender, Player player) {
    if (checkSignSelectorActive(commandSender)) {
        return true;
    }

    Block block = player.getTargetBlock((Set<Material>) null, 15);
    if (block.getState() instanceof org.bukkit.block.Sign) {
        if (SignSelector.getInstance().containsPosition(block.getLocation())) {
            Sign sign = SignSelector.getInstance().getSignByPosition(block.getLocation());

            if (sign != null) {
                CloudAPI.getInstance().getNetworkConnection().sendPacket(new PacketOutRemoveSign(sign));
                commandSender.sendMessage(CloudAPI.getInstance().getPrefix() + "The sign has been removed");
            }
        }
    }
    return false;
}
 
Example #10
Source File: ColorChanger.java    From BedWars with GNU Lesser General Public License v3.0 6 votes vote down vote up
public static Material changeMaterialColor(Material material, TeamColor teamColor) {
    String materialName = material.name();

    try {
        materialName = material.toString().substring(material.toString().indexOf("_") + 1);
    } catch (StringIndexOutOfBoundsException ignored) {
    }

    String teamMaterialColor = teamColor.material1_13;

    if (Main.autoColoredMaterials.contains(materialName)) {
        return Material.getMaterial(teamMaterialColor + "_" + materialName);
    } else if (material.toString().contains("GLASS")) {
        return Material.getMaterial(teamMaterialColor + "_STAINED_GLASS");
    } else if (material.toString().contains("GLASS_PANE")) {
        return Material.getMaterial(teamMaterialColor + "_STAINED_GLASS_PANE");
    }
    return material;

}
 
Example #11
Source File: CraftHumanEntity.java    From Thermos with GNU General Public License v3.0 6 votes vote down vote up
public InventoryView openEnchanting(Location location, boolean force) {
    if (!force) {
        Block block = location.getBlock();
        if (block.getType() != Material.ENCHANTMENT_TABLE) {
            return null;
        }
    }
    if (location == null) {
        location = getLocation();
    }
    getHandle().displayGUIEnchantment(location.getBlockX(), location.getBlockY(), location.getBlockZ(), null);
    if (force) {
        getHandle().openContainer.checkReachable = false;
    }
    return getHandle().openContainer.getBukkitView();
}
 
Example #12
Source File: DataUpdaterEvents.java    From AACAdditionPro with GNU General Public License v3.0 6 votes vote down vote up
@EventHandler(priority = EventPriority.LOW)
public void onInventoryClick(final InventoryClickEvent event)
{
    final User user = UserManager.getUser(event.getWhoClicked().getUniqueId());

    if (user != null &&
        // Quickbar actions can be performed outside the inventory.
        event.getSlotType() != InventoryType.SlotType.QUICKBAR)
    {
        // Only update if the inventory is currently closed to not interfere with opening time checks.
        if (!user.hasOpenInventory()) {
            user.getTimestampMap().updateTimeStamp(TimestampKey.INVENTORY_OPENED);
        }

        user.getTimestampMap().updateTimeStamp(TimestampKey.LAST_INVENTORY_CLICK);
        if (event.getCurrentItem() != null) {
            user.getTimestampMap().updateTimeStamp(TimestampKey.LAST_INVENTORY_CLICK_ON_ITEM);
        }

        user.getDataMap().setValue(DataKey.LAST_RAW_SLOT_CLICKED, event.getRawSlot());
        user.getDataMap().setValue(DataKey.LAST_MATERIAL_CLICKED, event.getCurrentItem() == null ?
                                                                  Material.AIR :
                                                                  event.getCurrentItem().getType());
    }
}
 
Example #13
Source File: DoubleGoldListener.java    From UhcCore with GNU General Public License v3.0 6 votes vote down vote up
@EventHandler
public void onBlockBreak(BlockBreakEvent e) {

    if (isActivated(Scenario.CUTCLEAN) || isActivated(Scenario.TRIPLEORES) || isActivated(Scenario.VEINMINER)){
        return;
    }

    Block block = e.getBlock();
    Location loc = e.getBlock().getLocation().add(0.5, 0, 0.5);

    if (block.getType() == Material.GOLD_ORE){
        block.setType(Material.AIR);
        loc.getWorld().dropItem(loc,new ItemStack(Material.GOLD_INGOT, 2));
        UhcItems.spawnExtraXp(loc,6);
    }
}
 
Example #14
Source File: ItemConvertionTest.java    From Item-NBT-API with MIT License 6 votes vote down vote up
@Override
public void test() throws Exception {
	ItemStack item = new ItemStack(Material.STONE, 1);
	ItemMeta meta = item.getItemMeta();
	meta.setLore(Lists.newArrayList("Firest Line", "Second Line"));
	item.setItemMeta(meta);
	String nbt = NBTItem.convertItemtoNBT(item).toString();
	if (!nbt.contains("Firest Line") || !nbt.contains("Second Line"))
		throw new NbtApiException("The Item nbt '" + nbt + "' didn't contain the lore");
	ItemStack rebuild = NBTItem.convertNBTtoItem(new NBTContainer(nbt));
	if (!item.isSimilar(rebuild))
		throw new NbtApiException("Rebuilt item did not match the original!");
	
	NBTContainer cont = new NBTContainer();
	cont.setItemStack("testItem", item);
	if(!cont.getItemStack("testItem").isSimilar(item))
		throw new NbtApiException("Rebuilt item did not match the original!");
}
 
Example #15
Source File: Fiery.java    From MineTinker with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void reload() {
	FileConfiguration config = getConfig();
	config.options().copyDefaults(true);

	config.addDefault("Allowed", true);
	config.addDefault("Color", "%YELLOW%");
	config.addDefault("MaxLevel", 2);
	config.addDefault("SlotCost", 1);

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

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

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

	init(Material.BLAZE_ROD);
}
 
Example #16
Source File: NMSHandler.java    From SkyWarsReloaded with GNU General Public License v3.0 5 votes vote down vote up
@Override
public ItemStack getColorItem(String mat, byte color) {
	if (mat.equalsIgnoreCase("wool")) {
		return new ItemStack(Material.WOOL, 1, (short) color);
	} else if (mat.equalsIgnoreCase("glass")) {
		return new ItemStack(Material.STAINED_GLASS, 1, (short) color);
	} else if (mat.equalsIgnoreCase("banner")) {
		return new ItemStack(Material.BANNER, 1, (short) color);
	} else {
		return new ItemStack(Material.STAINED_GLASS, 1, (short) color);
	}
}
 
Example #17
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 #18
Source File: InventoryForSpecialVariable.java    From NBTEditor with GNU General Public License v3.0 5 votes vote down vote up
protected static ItemStack createPlaceholder(Material material, String name, String lore) {
	ArrayList<String> loreList = new ArrayList<String>(2);
	if (lore != null) {
		loreList.add(lore);
	}
	loreList.add("§oThis is a placeholder item.");
	loreList.add("§oClick to remove.");
	return UtilsMc.newSingleItemStack(material, name, loreList);
}
 
Example #19
Source File: SlimefunUtils.java    From Slimefun4 with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Toggles an {@link ItemStack} to be Soulbound.<br>
 * If true is passed, this will add the {@link #SOULBOUND_LORE} and
 * add a {@link NamespacedKey} to the item so it can be quickly identified
 * by {@link #isSoulbound(ItemStack)}.<br>
 * If false is passed, this property will be removed.
 *
 * @param item
 *            The {@link ItemStack} you want to add/remove Soulbound from.
 * @param makeSoulbound
 *            If they item should be soulbound.
 * 
 * @see #isSoulbound(ItemStack)
 */
public static void setSoulbound(ItemStack item, boolean makeSoulbound) {
    if (item == null || item.getType() == Material.AIR) {
        throw new IllegalArgumentException("A soulbound item cannot be null or air!");
    }

    boolean isSoulbound = isSoulbound(item);
    ItemMeta meta = item.getItemMeta();

    if (SlimefunPlugin.getMinecraftVersion().isAtLeast(MinecraftVersion.MINECRAFT_1_14)) {
        PersistentDataContainer container = meta.getPersistentDataContainer();

        if (makeSoulbound && !isSoulbound) {
            container.set(SOULBOUND_KEY, PersistentDataType.BYTE, (byte) 1);
        }

        if (!makeSoulbound && isSoulbound) {
            container.remove(SOULBOUND_KEY);
        }
    }

    List<String> lore = meta.hasLore() ? meta.getLore() : new ArrayList<>();

    if (makeSoulbound && !isSoulbound) {
        lore.add(SOULBOUND_LORE);
    }

    if (!makeSoulbound && isSoulbound) {
        lore.remove(SOULBOUND_LORE);
    }

    meta.setLore(lore);
    item.setItemMeta(meta);
}
 
Example #20
Source File: UMaterial.java    From TradePlus with GNU General Public License v3.0 5 votes vote down vote up
public static ItemStack getEnchantmentBook(LinkedHashMap<Enchantment, Integer> enchants, int amount) {
  final ItemStack s = new ItemStack(Material.ENCHANTED_BOOK, amount);
  final EnchantmentStorageMeta sm = (EnchantmentStorageMeta) s;
  for(Enchantment enchant : enchants.keySet()) {
    sm.addStoredEnchant(enchant, enchants.get(enchant), true);
  }
  s.setItemMeta(sm);
  return s;
}
 
Example #21
Source File: IndustrialMiner.java    From Slimefun4 with GNU General Public License v3.0 5 votes vote down vote up
public IndustrialMiner(Category category, SlimefunItemStack item, Material baseMaterial, boolean silkTouch, int range) {
    super(category, item, new ItemStack[] { null, null, null, new CustomItem(Material.PISTON, "Piston (facing up)"), new ItemStack(Material.CHEST), new CustomItem(Material.PISTON, "Piston (facing up)"), new ItemStack(baseMaterial), new ItemStack(SlimefunPlugin.getMinecraftVersion().isAtLeast(MinecraftVersion.MINECRAFT_1_14) ? Material.BLAST_FURNACE : Material.FURNACE), new ItemStack(baseMaterial) }, new ItemStack[0], BlockFace.UP);

    this.range = range;
    this.silkTouch = silkTouch;

    registerDefaultFuelTypes();
}
 
Example #22
Source File: PlayerShopkeeper.java    From Shopkeepers with GNU General Public License v3.0 5 votes vote down vote up
protected int getPriceFromColumn(Inventory inventory, int column) {
	ItemStack lowCostItem = inventory.getItem(column + 18);
	ItemStack highCostItem = inventory.getItem(column + 9);
	int cost = 0;
	if (lowCostItem != null && lowCostItem.getType() == Settings.currencyItem && lowCostItem.getAmount() > 0) {
		cost += lowCostItem.getAmount();
	}
	if (Settings.highCurrencyItem != Material.AIR && highCostItem != null && highCostItem.getType() == Settings.highCurrencyItem && highCostItem.getAmount() > 0) {
		cost += highCostItem.getAmount() * Settings.highCurrencyValue;
	}
	return cost;
}
 
Example #23
Source File: AbstractConfigMenu.java    From uSkyBlock with GNU General Public License v3.0 5 votes vote down vote up
protected ItemStack createItem(Material icon, int subType, String title, List<String> lore) {
    ItemStack itemStack = new ItemStack(icon, 1, (short) (subType & 0xff));
    ItemMeta meta = itemStack.getItemMeta();
    meta.setDisplayName(title);
    meta.setLore(lore);
    itemStack.setItemMeta(meta);
    return itemStack;
}
 
Example #24
Source File: CompatibilityUtils.java    From NovaGuilds with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Gets material by id
 *
 * @param id id
 * @return material enum
 */
public static Material getMaterial(int id) {
	for(Material material : Material.values()) {
		if(material.getId() == id) {
			return material;
		}
	}

	return null;
}
 
Example #25
Source File: TestSoulboundItem.java    From Slimefun4 with GNU General Public License v3.0 5 votes vote down vote up
@Test
public void testSetSoulbound() {
    ItemStack item = new CustomItem(Material.DIAMOND, "&cI wanna be soulbound!");

    Assertions.assertFalse(SlimefunUtils.isSoulbound(item));

    SlimefunUtils.setSoulbound(item, true);
    Assertions.assertTrue(SlimefunUtils.isSoulbound(item));
    Assertions.assertEquals(1, item.getItemMeta().getLore().size());

    SlimefunUtils.setSoulbound(item, false);
    Assertions.assertFalse(SlimefunUtils.isSoulbound(item));
    Assertions.assertEquals(0, item.getItemMeta().getLore().size());
}
 
Example #26
Source File: Crate.java    From SkyWarsReloaded with GNU General Public License v3.0 5 votes vote down vote up
private void checkSuccess() {
	new BukkitRunnable() {
		@Override
		public void run() {
			if (ent.getLocation().getBlockY() == prevY && !success) {
				ent.getWorld().getBlockAt(ent.getLocation()).setType(Material.ENDER_CHEST);
				setLocation(ent.getWorld().getBlockAt(ent.getLocation()));
				ent.remove();
			} else {
				prevY = ent.getLocation().getY();
				checkSuccess();
			}
		}
	}.runTaskLater(SkyWarsReloaded.get(), 10L);
}
 
Example #27
Source File: SentinelItemHelper.java    From Sentinel with MIT License 5 votes vote down vote up
/**
 * Returns whether the NPC can take durability from the held item.
 */
public boolean shouldTakeDura() {
    ItemStack it = getHeldItem();
    if (it == null) {
        return false;
    }
    Material type = it.getType();
    return SentinelVersionCompat.BOW_MATERIALS.contains(type) || SentinelVersionCompat.SWORD_MATERIALS.contains(type)
            || SentinelVersionCompat.PICKAXE_MATERIALS.contains(type) || SentinelVersionCompat.AXE_MATERIALS.contains(type);
}
 
Example #28
Source File: NMSHandler.java    From SkyWarsReloaded with GNU General Public License v3.0 5 votes vote down vote up
@Override
public boolean checkMaterial(FallingBlock fb, Material mat) {
	if (fb.getMaterial().equals(mat)) {
		return true;
	}
	return false;
}
 
Example #29
Source File: SlimefunItemStack.java    From Slimefun4 with GNU General Public License v3.0 5 votes vote down vote up
private static ItemStack getSkull(String id, String texture) {
    if (SlimefunPlugin.getMinecraftVersion() == MinecraftVersion.UNIT_TEST) {
        return new ItemStack(Material.PLAYER_HEAD);
    }

    return SkullItem.fromBase64(getTexture(id, texture));
}
 
Example #30
Source File: BlockTransformListener.java    From PGM with GNU Affero General Public License v3.0 5 votes vote down vote up
@EventWrapper
public void onBlockSpread(final BlockSpreadEvent event) {
  // This fires for: fire, grass, mycelium, mushrooms, and vines
  // Fire is already handled by BlockIgniteEvent
  if (event.getNewState().getType() != Material.FIRE) {
    this.callEvent(
        new BlockTransformEvent(event, event.getBlock().getState(), event.getNewState()));
  }
}