Java Code Examples for org.bukkit.Material#TRAPPED_CHEST

The following examples show how to use org.bukkit.Material#TRAPPED_CHEST . 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: WorldGuardListener.java    From ShopChest with MIT License 6 votes vote down vote up
@EventHandler(priority = EventPriority.LOW)
public void onUseBlock(WrappedUseBlockEvent event) {
    if (Config.enableWorldGuardIntegration) {
        Player player = event.getPlayer();

        if (event.getOriginalEvent() instanceof PlayerInteractEvent) {
            Block block = event.getBlocks().get(0);
            Material type = block.getType();
            
            if (type == Material.CHEST || type == Material.TRAPPED_CHEST) {
                if (isAllowed(player, block.getLocation())) {
                    event.setResult(Result.ALLOW);
                }
            }
        } else if (event.getOriginalEvent() instanceof InventoryOpenEvent) {
            InventoryOpenEvent orig = (InventoryOpenEvent) event.getOriginalEvent();

            if (orig.getInventory().getHolder() instanceof Chest) {
                if (isAllowed(player, ((Chest) orig.getInventory().getHolder()).getLocation())) {
                    event.setResult(Result.ALLOW);
                }
            }
        }
    }
}
 
Example 2
Source File: SignEvents.java    From uSkyBlock with GNU General Public License v3.0 6 votes vote down vote up
@EventHandler(priority = EventPriority.MONITOR)
public void onSignOrChestBreak(BlockBreakEvent e) {
    if (e.isCancelled()
            || e.getBlock() == null
            || (e.getBlock().getType() != SkyBlockMenu.WALL_SIGN_MATERIAL && !(e.getBlock().getType() == Material.CHEST || e.getBlock().getType() == Material.TRAPPED_CHEST))
            || e.getBlock().getLocation() == null
            || !plugin.getWorldManager().isSkyAssociatedWorld(e.getBlock().getLocation().getWorld())
            ) {
        return;
    }
    if (e.getBlock().getType() == SkyBlockMenu.WALL_SIGN_MATERIAL) {
        logic.removeSign(e.getBlock().getLocation());
    } else {
        logic.removeChest(e.getBlock().getLocation());
    }
}
 
Example 3
Source File: MailboxListener.java    From NyaaUtils with MIT License 5 votes vote down vote up
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
public void onRightClickChest(PlayerInteractEvent ev) {
    if (callbackMap.containsKey(ev.getPlayer()) && ev.hasBlock() && ev.getAction() == Action.RIGHT_CLICK_BLOCK) {
        Block b = ev.getClickedBlock();
        if (b.getType() == Material.CHEST || b.getType() == Material.TRAPPED_CHEST) {
            callbackMap.remove(ev.getPlayer()).accept(b.getLocation());
            if (timeoutListener.containsKey(ev.getPlayer()))
                timeoutListener.remove(ev.getPlayer()).cancel();
            ev.setCancelled(true);
        }
    }

}
 
Example 4
Source File: Shop.java    From ShopChest with MIT License 5 votes vote down vote up
/**
 * @return {@link InventoryHolder} of the shop or <b>null</b> if the shop has no chest.
 */
public InventoryHolder getInventoryHolder() {
    Block b = getLocation().getBlock();

    if (b.getType() == Material.CHEST || b.getType() == Material.TRAPPED_CHEST) {
        Chest chest = (Chest) b.getState();
        return chest.getInventory().getHolder();
    }

    return null;
}
 
Example 5
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 6
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;
				}
			}
		}
	}
}
 
Example 7
Source File: Materials.java    From ProjectAres with GNU Affero General Public License v3.0 4 votes vote down vote up
public static boolean isChest(Material material) {
    return material == Material.CHEST || material == Material.TRAPPED_CHEST;
}
 
Example 8
Source File: SignLogic.java    From uSkyBlock with GNU General Public License v3.0 4 votes vote down vote up
private boolean isChest(Block chestBlock) {
    return (chestBlock.getType() == Material.CHEST || chestBlock.getType() == Material.TRAPPED_CHEST) && chestBlock.getState() instanceof Chest;
}
 
Example 9
Source File: SignEvents.java    From uSkyBlock with GNU General Public License v3.0 4 votes vote down vote up
private boolean isChest(Block wallBlock) {
    return wallBlock != null
            && (wallBlock.getType() == Material.CHEST || wallBlock.getType() == Material.TRAPPED_CHEST)
            && wallBlock.getState() instanceof Chest;
}
 
Example 10
Source File: Utils.java    From Shopkeepers with GNU General Public License v3.0 4 votes vote down vote up
public static boolean isChest(Material material) {
	return material == Material.CHEST || material == Material.TRAPPED_CHEST;
}
 
Example 11
Source File: ShopInteractListener.java    From ShopChest with MIT License 3 votes vote down vote up
@EventHandler(priority = EventPriority.HIGH)
public void onPlayerInteractCreate(PlayerInteractEvent e) {
    Player p = e.getPlayer();
    Block b = e.getClickedBlock();

    if (e.getAction() != Action.RIGHT_CLICK_BLOCK)
        return;

    if (!(ClickType.getPlayerClickType(p) instanceof CreateClickType))
        return;

    if (b.getType() != Material.CHEST && b.getType() != Material.TRAPPED_CHEST)
        return;

    if (ClickType.getPlayerClickType(p).getClickType() != ClickType.EnumClickType.CREATE)
        return;

    if (Config.enableAuthMeIntegration && plugin.hasAuthMe() && !AuthMeApi.getInstance().isAuthenticated(p))
        return;

    if (e.isCancelled() && !p.hasPermission(Permissions.CREATE_PROTECTED)) {
        p.sendMessage(LanguageUtils.getMessage(Message.NO_PERMISSION_CREATE_PROTECTED));
        plugin.debug(p.getName() + " is not allowed to create a shop on the selected chest");
    } else if (shopUtils.isShop(b.getLocation())) {
        p.sendMessage(LanguageUtils.getMessage(Message.CHEST_ALREADY_SHOP));
        plugin.debug("Chest is already a shop");
    } else if (!ItemUtils.isAir(b.getRelative(BlockFace.UP).getType())) {
        p.sendMessage(LanguageUtils.getMessage(Message.CHEST_BLOCKED));
        plugin.debug("Chest is blocked");
    } else {
        CreateClickType clickType = (CreateClickType) ClickType.getPlayerClickType(p);
        ShopProduct product = clickType.getProduct();
        double buyPrice = clickType.getBuyPrice();
        double sellPrice = clickType.getSellPrice();
        ShopType shopType = clickType.getShopType();

        create(p, b.getLocation(), product, buyPrice, sellPrice, shopType);
    }

    e.setCancelled(true);
    ClickType.removePlayerClickType(p);
}