Java Code Examples for org.bukkit.Material#HOPPER

The following examples show how to use org.bukkit.Material#HOPPER . 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: LockListener.java    From QuickShop-Reremake with GNU General Public License v3.0 6 votes vote down vote up
@EventHandler(priority = EventPriority.LOW, ignoreCancelled = true)
public void onPlace(BlockPlaceEvent e) {

    final Block b = e.getBlock();

    if (b.getType() != Material.HOPPER) {
        return;
    }

    final Player p = e.getPlayer();

    if (!Util.isOtherShopWithinHopperReach(b, p)) {
        return;
    }

    if (QuickShop.getPermissionManager().hasPermission(p, "quickshop.other.open")) {
        MsgUtil.sendMessage(p, MsgUtil.getMessage("bypassing-lock", p));
        return;
    }

    MsgUtil.sendMessage(p, MsgUtil.getMessage("that-is-locked", p));
    e.setCancelled(true);
}
 
Example 2
Source File: DispenserListener.java    From Slimefun4 with GNU General Public License v3.0 6 votes vote down vote up
@EventHandler
public void onBlockDispensing(BlockDispenseEvent e) {
    Block b = e.getBlock();

    if (b.getType() == Material.DISPENSER && b.getRelative(BlockFace.DOWN).getType() != Material.HOPPER) {
        SlimefunItem machine = BlockStorage.check(b);

        if (machine != null) {
            machine.callItemHandler(BlockDispenseHandler.class, handler -> {
                Dispenser dispenser = (Dispenser) b.getState();
                BlockFace face = ((Directional) b.getBlockData()).getFacing();
                Block block = b.getRelative(face);
                handler.onBlockDispense(e, dispenser, block, machine);
            });
        }
    }
}
 
Example 3
Source File: ProtectionFinder.java    From Modern-LWC with MIT License 5 votes vote down vote up
/**
 * Get the possible protection matchers that can match the protection
 *
 * @return
 */
public Matcher[] getProtectionMatchers() {
    Material material = baseBlock.getType();

    if (material == Material.HOPPER) {
        return new Matcher[0];
    }

    // Double chests
    if (DoubleChestMatcher.PROTECTABLES_CHESTS.contains(material)) {
        return new Matcher[]{
                new DoubleChestMatcher()
        };
    }

    // Gravity
    else if (GravityMatcher.PROTECTABLES_POSTS.contains(material)) {
        return new Matcher[]{
                new GravityMatcher()
        };
    }

    // Doors
    else if (DoorMatcher.PROTECTABLES_DOORS.contains(material)) {
        return new Matcher[]{
                new DoorMatcher()
        };
    }

    // Anything else
    else {
        return new Matcher[]{
                new DoorMatcher(),
                new GravityMatcher(),
                new WallMatcher()
        };
    }

}
 
Example 4
Source File: MapRatingsMatchModule.java    From ProjectAres with GNU Affero General Public License v3.0 5 votes vote down vote up
private ItemStack getOpenButton(MatchPlayer player) {
    ItemStack stack = new ItemStack(Material.HOPPER);
    ItemMeta meta = stack.getItemMeta();
    meta.addItemFlags(ItemFlag.values());
    meta.setDisplayName(BUTTON_PREFIX + ChatColor.BLUE.toString() + ChatColor.BOLD + PGMTranslations.t("rating.rateThisMap", player));
    stack.setItemMeta(meta);
    return stack;
}
 
Example 5
Source File: MapRatingsMatchModule.java    From ProjectAres with GNU Affero General Public License v3.0 5 votes vote down vote up
@EventHandler
public void onOpenButtonClick(PlayerInteractEvent event) {
    if(event.getAction() != Action.RIGHT_CLICK_AIR && event.getAction() != Action.RIGHT_CLICK_BLOCK) return;

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

    ItemStack stack = event.getPlayer().getItemInHand();
    if(stack == null) return;
    if(stack.getType() != Material.HOPPER) return;

    String name = stack.getItemMeta().getDisplayName();
    if(name == null || !name.startsWith(BUTTON_PREFIX)) return;
    this.showDialog(player);
}
 
Example 6
Source File: InfusedHopper.java    From Slimefun4 with GNU General Public License v3.0 5 votes vote down vote up
@Override
public BlockTicker getItemHandler() {
    return new BlockTicker() {

        @Override
        public void tick(Block b, SlimefunItem sfItem, Config data) {
            if (b.getType() != Material.HOPPER) {
                // we're no longer a hopper, we were probably destroyed. skipping this tick.
                BlockStorage.clearBlockInfo(b);
                return;
            }

            Location l = b.getLocation().add(0.5, 1.2, 0.5);
            boolean sound = false;
            double range = radius.getValue();

            for (Entity item : b.getWorld().getNearbyEntities(l, range, range, range, n -> isValidItem(l, n))) {
                item.setVelocity(new Vector(0, 0.1, 0));
                item.teleport(l);
                sound = true;
            }

            if (sound && !silent.getValue().booleanValue()) {
                b.getWorld().playSound(b.getLocation(), Sound.ENTITY_ENDERMAN_TELEPORT, 1F, 2F);
            }
        }

        @Override
        public boolean isSynchronized() {
            return true;
        }
    };
}
 
Example 7
Source File: ChestProtectListener.java    From Shopkeepers with GNU General Public License v3.0 5 votes vote down vote up
@EventHandler(ignoreCancelled = true)
void onBlockPlace(BlockPlaceEvent event) {
	Block block = event.getBlock();
	Material type = block.getType();
	Player player = event.getPlayer();
	if (Utils.isChest(type)) {
		if (plugin.getProtectedChests().isChestProtected(block, player)) {
			Log.debug("Cancelled placing of chest block by '" + player.getName() + "' at '"
					+ Utils.getLocationString(block) + "': Protected chest nearby");
			event.setCancelled(true);
		}
	} else if (type == Material.HOPPER) {
		if (plugin.getProtectedChests().isProtectedChestAroundHopper(block, player)) {
			Log.debug("Cancelled placing of hopper block by '" + player.getName() + "' at '"
					+ Utils.getLocationString(block) + "': Protected chest nearby");
			event.setCancelled(true);
		}
	} else if (type == Material.RAILS || type == Material.POWERED_RAIL || type == Material.DETECTOR_RAIL || type == Material.ACTIVATOR_RAIL) {
		Block upperBlock = block.getRelative(BlockFace.UP);
		if (Utils.isChest(upperBlock.getType()) && plugin.getProtectedChests().isChestProtected(upperBlock, player)) {
			Log.debug("Cancelled placing of rail block by '" + player.getName() + "' at '"
					+ Utils.getLocationString(block) + "': Protected chest nearby");
			event.setCancelled(true);
			return;
		}
	}
}
 
Example 8
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 9
Source File: SkyBlockMenu.java    From uSkyBlock with GNU General Public License v3.0 4 votes vote down vote up
private void onClickMainMenu(InventoryClickEvent event, ItemStack currentItem, Player p, int slotIndex) {
    event.setCancelled(true);
    if (slotIndex < 0 || slotIndex > 35) {
        return;
    }
    PlayerInfo playerInfo = plugin.getPlayerInfo(p);
    IslandInfo islandInfo = plugin.getIslandInfo(playerInfo);
    if (currentItem.getType() == Material.JUNGLE_SAPLING) {
        p.closeInventory();
        p.performCommand("island biome");
    } else if (currentItem.getType() == Material.PLAYER_HEAD) {
        p.closeInventory();
        p.performCommand("island party");
    } else if (currentItem.getType() == Material.RED_BED) {
        p.closeInventory();
        p.performCommand("island sethome");
        p.performCommand("island");
    } else if (currentItem.getType() == Material.GRASS) {
        p.closeInventory();
        p.performCommand("island spawn");
    } else if (currentItem.getType() == Material.HOPPER) {
        p.closeInventory();
        p.performCommand("island setwarp");
        p.performCommand("island");
    } else if (currentItem.getType() == Material.WRITABLE_BOOK) {
        p.closeInventory();
        p.performCommand("island log");
    } else if (currentItem.getType() == Material.OAK_DOOR) {
        p.closeInventory();
        p.performCommand("island home");
    } else if (currentItem.getType() == Material.EXPERIENCE_BOTTLE) {
        p.closeInventory();
        p.performCommand("island level");
    } else if (currentItem.getType() == Material.DIAMOND_ORE) {
        p.closeInventory();
        p.performCommand("c");
    } else if (currentItem.getType() == Material.END_STONE || currentItem.getType() == Material.END_PORTAL_FRAME) {
        p.closeInventory();
        p.performCommand("island togglewarp");
        p.performCommand("island");
    } else if (currentItem.getType() == Material.IRON_BARS && islandInfo.isLocked()) {
        p.closeInventory();
        p.performCommand("island unlock");
        p.performCommand("island");
    } else if (currentItem.getType() == Material.IRON_BARS && !islandInfo.isLocked()) {
        p.closeInventory();
        p.performCommand("island lock");
        p.performCommand("island");
    } else if (slotIndex == 17) {
        if (islandInfo.isLeader(p) && plugin.getConfig().getBoolean("island-schemes-enabled", true)) {
            p.closeInventory();
            p.openInventory(createRestartGUI(p));
        } else {
            if (plugin.getConfirmHandler().millisLeft(p, "/is leave") > 0) {
                p.closeInventory();
                p.performCommand("island leave");
            } else {
                p.performCommand("island leave");
                updateLeaveMenuItemTimer(p, event.getInventory(), currentItem);
            }
        }
    } else {
        if (!isExtraMenuAction(p, currentItem)) {
            p.closeInventory();
            p.performCommand("island");
        }
    }
}
 
Example 10
Source File: Hopper.java    From Kettle with GNU General Public License v3.0 2 votes vote down vote up
/**
 * Constructs a hopper facing the specified direction and either active or
 * not.
 *
 * @param facingDirection the direction the hopper is facing
 * @param isActive        True if the hopper is initially active, false if
 *                        deactivated
 * @see BlockFace
 */
public Hopper(BlockFace facingDirection, boolean isActive) {
    super(Material.HOPPER);
    setFacingDirection(facingDirection);
    setActive(isActive);
}