Java Code Examples for org.bukkit.Material#ENCHANTING_TABLE

The following examples show how to use org.bukkit.Material#ENCHANTING_TABLE . 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: CivilianListener.java    From Civs with GNU General Public License v3.0 6 votes vote down vote up
@EventHandler(ignoreCancelled = true)
public void onCivilianUseExp(PlayerInteractEvent event) {
    if (event.getClickedBlock() == null || event.getAction() != Action.RIGHT_CLICK_BLOCK) {
        return;
    }
    Civilian civilian = CivilianManager.getInstance().getCivilian(event.getPlayer().getUniqueId());
    if (civilian.getMana() < 1 || civilian.getMana() > 99) {
        return;
    }
    Material mat = event.getClickedBlock().getType();
    if (mat == Material.ANVIL ||
            mat == Material.ENCHANTING_TABLE) {
        event.setCancelled(true);
        event.getPlayer().sendMessage(Civs.getPrefix() + LocaleManager.getInstance().getTranslationWithPlaceholders(
                event.getPlayer(), "mana-use-exp"));
    }
}
 
Example 2
Source File: MagicSugar.java    From Slimefun4 with GNU General Public License v3.0 6 votes vote down vote up
@Override
public ItemUseHandler getItemHandler() {
    return e -> {
        // Check if it is being placed into an ancient altar.
        if (e.getClickedBlock().isPresent()) {
            Material block = e.getClickedBlock().get().getType();

            if (block == Material.DISPENSER || block == Material.ENCHANTING_TABLE) {
                return;
            }
        }

        Player p = e.getPlayer();
        if (p.getGameMode() != GameMode.CREATIVE) {
            ItemUtils.consumeItem(e.getItem(), false);
        }

        p.playSound(p.getLocation(), Sound.ENTITY_GENERIC_EAT, 1, 1);
        p.addPotionEffect(new PotionEffect(PotionEffectType.SPEED, 600, 3));
    };
}
 
Example 3
Source File: AncientAltarListener.java    From Slimefun4 with GNU General Public License v3.0 5 votes vote down vote up
@EventHandler
public void onInteract(PlayerRightClickEvent e) {
    if (altar == null || altar.isDisabled() || e.useBlock() == Result.DENY) {
        return;
    }

    Optional<Block> blockOptional = e.getClickedBlock();
    if (!blockOptional.isPresent()) {
        return;
    }

    Block b = blockOptional.get();
    if (b.getType() != Material.ENCHANTING_TABLE && b.getType() != Material.DISPENSER) {
        return;
    }

    Optional<SlimefunItem> slimefunBlock = e.getSlimefunBlock();
    if (!slimefunBlock.isPresent()) {
        return;
    }

    String id = slimefunBlock.get().getID();

    if (id.equals(SlimefunItems.ANCIENT_PEDESTAL.getItemId())) {
        e.cancel();
        usePedestal(b, e.getPlayer());
    }
    else if (id.equals(SlimefunItems.ANCIENT_ALTAR.getItemId())) {
        if (!Slimefun.hasUnlocked(e.getPlayer(), SlimefunItems.ANCIENT_ALTAR.getItem(), true) || altarsInUse.contains(b.getLocation())) {
            e.cancel();
            return;
        }

        // Make altarinuse simply because that was the last block clicked.
        altarsInUse.add(b.getLocation());
        e.cancel();

        useAltar(b, e.getPlayer());
    }
}
 
Example 4
Source File: SignListener.java    From PlayerVaults with GNU General Public License v3.0 5 votes vote down vote up
private boolean isInvalidBlock(Material material) {
    if (PlayerVaults.getInstance().getVersion().contains("v1_13")) {
        PlayerVaults.debug("[PlayerVaults] [Debug/SignListener] Block material checked for >= 1.13");
        return material == Material.CHEST || material == Material.TRAPPED_CHEST
                || material == Material.ENDER_CHEST || material == Material.FURNACE
                || material == Material.BREWING_STAND || material == Material.ENCHANTING_TABLE
                || material == Material.BEACON;
    }
    PlayerVaults.debug("[PlayerVaults] [Debug/SignListener] Block material checked for < 1.13");
    return material == Material.CHEST || material == Material.TRAPPED_CHEST
            || material == Material.ENDER_CHEST || material == Material.FURNACE
            || material == Material.valueOf("BURNING_FURNACE") || material == Material.BREWING_STAND
            || material == Material.valueOf("ENCHANTMENT_TABLE") || material == Material.BEACON;
}
 
Example 5
Source File: BlockListener.java    From MineTinker with GNU General Public License v3.0 4 votes vote down vote up
@EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true)
public void onClick(PlayerInteractEvent event) {
	Player player = event.getPlayer();

	ItemStack norm = null;
	if (event.getHand() == EquipmentSlot.HAND) {
		norm = player.getInventory().getItemInMainHand();
	} else if (event.getHand() == EquipmentSlot.OFF_HAND) {
		norm = player.getInventory().getItemInOffHand();
	}

	if (norm == null) return;

	if (event.getAction() == Action.RIGHT_CLICK_AIR) {
		if (modManager.isModifierItem(norm)) {
			event.setCancelled(true);
		}
	} else if (event.getAction() == Action.RIGHT_CLICK_BLOCK) {
		Block block = event.getClickedBlock();

		if (block == null) {
			return;
		}
		if (!player.isSneaking()) {
			Material type = block.getType();

			if (type == Material.ANVIL || type == Material.CRAFTING_TABLE
					|| type == Material.CHEST || type == Material.ENDER_CHEST
					|| type == Material.DROPPER || type == Material.HOPPER
					|| type == Material.DISPENSER || type == Material.TRAPPED_CHEST
					|| type == Material.FURNACE || type == Material.ENCHANTING_TABLE) {

				return;
			}
		}

		if (modManager.isModifierItem(norm)) {
			event.setCancelled(true);
			return;
		}

		if (block.getType() == Material.getMaterial(MineTinker.getPlugin().getConfig().getString("BlockToEnchantModifiers", Material.BOOKSHELF.name()))) {
			ItemStack item = player.getInventory().getItemInMainHand();

			for (Modifier m : modManager.getAllMods()) {
				if (m.getModItem().getType().equals(item.getType())) {
					if (!m.isEnchantable()) continue;
					m.enchantItem(player);
					event.setCancelled(true);
					break;
				}
			}
		}
	}
}