Java Code Examples for org.bukkit.Material#CHEST
The following examples show how to use
org.bukkit.Material#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: IslandGenerator.java From uSkyBlock with GNU General Public License v3.0 | 6 votes |
/** * Fill the {@link Inventory} of the given chest {@link Location} with the starter and {@link Perk} based items. * @param chestLocation Location of the chest block. * @param perk Perk containing extra perk-based items to add. * @return True if the chest is found and filled, false otherwise. */ public boolean setChest(@Nullable Location chestLocation, @NotNull Perk perk) { if (chestLocation == null || chestLocation.getWorld() == null) { return false; } final Block block = chestLocation.getWorld().getBlockAt(chestLocation); if (block.getType() == Material.CHEST) { final Chest chest = (Chest) block.getState(); final Inventory inventory = chest.getInventory(); inventory.addItem(Settings.island_chestItems); if (Settings.island_addExtraItems) { inventory.addItem(ItemStackUtil.createItemArray(perk.getExtraItems())); } return true; } return false; }
Example 2
Source File: Composter.java From Slimefun4 with GNU General Public License v3.0 | 6 votes |
private Optional<Inventory> findOutputChest(Block b, ItemStack output) { for (BlockFace face : outputFaces) { Block potentialOutput = b.getRelative(face); if (potentialOutput.getType() == Material.CHEST) { String id = BlockStorage.checkID(potentialOutput); if (id != null && id.equals("OUTPUT_CHEST")) { // Found the output chest! Now, let's check if we can fit the product in it. Inventory inv = ((Chest) potentialOutput.getState()).getInventory(); if (InvUtils.fits(inv, output)) { return Optional.of(inv); } } } } return Optional.empty(); }
Example 3
Source File: SignEvents.java From uSkyBlock with GNU General Public License v3.0 | 6 votes |
@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 4
Source File: ActiveMiner.java From Slimefun4 with GNU General Public License v3.0 | 6 votes |
/** * This consumes fuel from the given {@link Chest}. * * @return The gained fuel value */ private int consumeFuel() { if (chest.getType() == Material.CHEST) { Inventory inv = ((Chest) chest.getState()).getBlockInventory(); for (int i = 0; i < inv.getSize(); i++) { for (MachineFuel fuelType : miner.fuelTypes) { ItemStack item = inv.getContents()[i]; if (fuelType.test(item)) { ItemUtils.consumeItem(item, false); if (miner instanceof AdvancedIndustrialMiner) { inv.addItem(new ItemStack(Material.BUCKET)); } return fuelType.getTicks(); } } } } return 0; }
Example 5
Source File: RegionsTests.java From Civs with GNU General Public License v3.0 | 6 votes |
@Test public void regionShouldNotBeDestroyedCenter() { loadRegionTypeCobble(); HashMap<UUID, String> owners = new HashMap<>(); owners.put(TestUtil.player.getUniqueId(), Constants.OWNER); Location location1 = new Location(Bukkit.getWorld("world"), 4, 0, 0); RegionType regionType = (RegionType) ItemManager.getInstance().getItemType("cobble"); RegionManager.getInstance().addRegion(new Region("cobble", owners, location1, getRadii(), regionType.getEffects(),0)); Player player1 = mock(Player.class); when(player1.getUniqueId()).thenReturn(new UUID(1,8)); when(player1.getGameMode()).thenReturn(GameMode.SURVIVAL); BlockBreakEvent event = new BlockBreakEvent(TestUtil.blockUnique, player1); CVItem cvItem = new CVItem(Material.CHEST, 1); cvItem.getLore().add(TestUtil.player.getUniqueId().toString()); BlockLogger.getInstance().putBlock(location1, cvItem); CivilianListener civilianListener = new CivilianListener(); ProtectionHandler protectionHandler = new ProtectionHandler(); protectionHandler.onBlockBreak(event); if (!event.isCancelled()) { civilianListener.onCivilianBlockBreak(event); } assertNotNull(RegionManager.getInstance().getRegionAt(location1)); assertEquals(Material.CHEST, TestUtil.world.getBlockAt(location1).getType()); assertTrue(event.isCancelled()); }
Example 6
Source File: ActiveMiner.java From Slimefun4 with GNU General Public License v3.0 | 5 votes |
/** * This refuels the {@link IndustrialMiner} and pushes the given {@link ItemStack} to * its {@link Chest}. * * @param item * The {@link ItemStack} to push to the {@link Chest}. * * @return Whether the operation was successful */ private boolean push(ItemStack item) { if (fuel < 1) { // Restock fuel fuel = consumeFuel(); } // Check if there is enough fuel to run if (fuel > 0) { if (chest.getType() == Material.CHEST) { Inventory inv = ((Chest) chest.getState()).getBlockInventory(); if (InvUtils.fits(inv, item)) { inv.addItem(item); return true; } else { stop("machines.INDUSTRIAL_MINER.chest-full"); } } else { // The chest has been destroyed stop("machines.INDUSTRIAL_MINER.destroyed"); } } else { stop("machines.INDUSTRIAL_MINER.no-fuel"); } return false; }
Example 7
Source File: GuildManager.java From NovaGuilds with GNU General Public License v3.0 | 5 votes |
/** * Fixes vault hologram and vault location * if it has been disabled abnormally * * @param guild guild instance */ public static void checkVaultDestroyed(NovaGuild guild) { if(guild.getVaultLocation() != null) { if(guild.getVaultLocation().getBlock().getType() != Material.CHEST) { guild.setVaultLocation(null); Hologram hologram = guild.getVaultHologram(); if(hologram != null) { hologram.delete(); } guild.setVaultHologram(null); } } }
Example 8
Source File: ChestRefillEvent.java From SkyWarsReloaded with GNU General Public License v3.0 | 5 votes |
public ChestRefillEvent(GameMap map, boolean b) { this.gMap = map; this.enabled = b; File dataDirectory = SkyWarsReloaded.get().getDataFolder(); File mapDataDirectory = new File(dataDirectory, "mapsData"); if (!mapDataDirectory.exists() && !mapDataDirectory.mkdirs()) { return; } File mapFile = new File(mapDataDirectory, gMap.getName() + ".yml"); if (mapFile.exists()) { eventName = "ChestRefillEvent"; slot = 4; material = new ItemStack(Material.CHEST, 1); FileConfiguration fc = YamlConfiguration.loadConfiguration(mapFile); this.min = fc.getInt("events." + eventName + ".minStart"); this.max = fc.getInt("events." + eventName + ".maxStart"); this.length = fc.getInt("events." + eventName + ".length"); this.chance = fc.getInt("events." + eventName + ".chance"); this.title = fc.getString("events." + eventName + ".title"); this.subtitle = fc.getString("events." + eventName + ".subtitle"); this.startMessage = fc.getString("events." + eventName + ".startMessage"); this.endMessage = fc.getString("events." + eventName + ".endMessage"); this.announceEvent = fc.getBoolean("events." + eventName + ".announceTimer"); this.repeatable = fc.getBoolean("events." + eventName + ".repeatable"); } }
Example 9
Source File: MailboxListener.java From NyaaUtils with MIT License | 5 votes |
@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 10
Source File: TestBackpackListener.java From Slimefun4 with GNU General Public License v3.0 | 5 votes |
@Test public void testSetId() throws InterruptedException { Player player = server.addPlayer(); ItemStack item = new CustomItem(Material.CHEST, "&cA mocked Backpack", "", "&7Size: &e" + BACKPACK_SIZE, "&7ID: <ID>", "", "&7&eRight Click&7 to open"); PlayerProfile profile = TestUtilities.awaitProfile(player); int id = profile.createBackpack(BACKPACK_SIZE).getId(); listener.setBackpackId(player, item, 2, id); Assertions.assertEquals(ChatColor.GRAY + "ID: " + player.getUniqueId() + "#" + id, item.getItemMeta().getLore().get(2)); PlayerBackpack backpack = awaitBackpack(item); Assertions.assertEquals(player.getUniqueId(), backpack.getOwner().getUUID()); Assertions.assertEquals(id, backpack.getId()); }
Example 11
Source File: BlueprintsMenuTests.java From Civs with GNU General Public License v3.0 | 5 votes |
@Test public void itemShouldNotBeCivsItem() { RegionsTests.loadRegionTypeCobble(); ItemStackImpl itemStack = new ItemStackImpl(Material.CHEST, 1); ArrayList<String> lore = new ArrayList<>(); ItemMetaImpl itemMeta = new ItemMetaImpl("Civs Cobble", lore); itemStack.setItemMeta(itemMeta); assertFalse(CivItem.isCivsItem(itemStack)); }
Example 12
Source File: ChestImpl.java From Civs with GNU General Public License v3.0 | 4 votes |
@Override public Material getType() { return Material.CHEST; }
Example 13
Source File: Utils.java From Shopkeepers with GNU General Public License v3.0 | 4 votes |
public static boolean isChest(Material material) { return material == Material.CHEST || material == Material.TRAPPED_CHEST; }
Example 14
Source File: SignEvents.java From uSkyBlock with GNU General Public License v3.0 | 4 votes |
private boolean isChest(Block wallBlock) { return wallBlock != null && (wallBlock.getType() == Material.CHEST || wallBlock.getType() == Material.TRAPPED_CHEST) && wallBlock.getState() instanceof Chest; }
Example 15
Source File: BlockListener.java From MineTinker with GNU General Public License v3.0 | 4 votes |
@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 16
Source File: WarehouseEffect.java From Civs with GNU General Public License v3.0 | 4 votes |
@Override public void regionCreatedHandler(Region r) { if (!r.getEffects().containsKey(KEY)) { return; } ArrayList<CVInventory> chests = new ArrayList<>(); chests.add(UnloadedInventoryHandler.getInstance().getChestInventory(r.getLocation())); RegionType rt = (RegionType) ItemManager.getInstance().getItemType(r.getType()); double lx = Math.floor(r.getLocation().getX()) + 0.4; double ly = Math.floor(r.getLocation().getY()) + 0.4; double lz = Math.floor(r.getLocation().getZ()) + 0.4; double buildRadius = rt.getBuildRadius(); int x = (int) Math.round(lx - buildRadius); int y = (int) Math.round(ly - buildRadius); y = y < 0 ? 0 : y; int z = (int) Math.round(lz - buildRadius); int xMax = (int) Math.round(lx + buildRadius); int yMax = (int) Math.round(ly + buildRadius); World world = r.getLocation().getWorld(); if (world != null) { yMax = yMax > world.getMaxHeight() - 1 ? world.getMaxHeight() - 1 : yMax; int zMax = (int) Math.round(lz + buildRadius); for (int i = x; i < xMax; i++) { for (int j = y; j < yMax; j++) { for (int k = z; k < zMax; k++) { Block block = world.getBlockAt(i, j, k); if (block.getType() == Material.CHEST) { chests.add(UnloadedInventoryHandler.getInstance().getChestInventory(block.getLocation())); } } } } } File dataFolder = new File(Civs.dataLocation, Constants.REGIONS); if (!dataFolder.exists()) { return; } File dataFile = new File(dataFolder, r.getId() + ".yml"); if (!dataFile.exists()) { Civs.logger.log(Level.SEVERE, "Warehouse region file does not exist {0}.yml", r.getId()); return; } FileConfiguration config = new YamlConfiguration(); try { config.load(dataFile); ArrayList<String> locationList = new ArrayList<>(); for (CVInventory cvInventory : chests) { locationList.add(Region.blockLocationToString(cvInventory.getLocation())); } config.set(Constants.CHESTS, locationList); config.save(dataFile); } catch (Exception e) { e.printStackTrace(); Civs.logger.log(Level.WARNING, UNABLE_TO_SAVE_CHEST, r.getId()); return; } checkExcessChests(r); }
Example 17
Source File: WarehouseEffect.java From Civs with GNU General Public License v3.0 | 4 votes |
@EventHandler(ignoreCancelled = true) public void onChestPlace(BlockPlaceEvent event) { if (event.getBlock().getType() != Material.CHEST) { return; } Location l = Region.idToLocation(Region.blockLocationToString(event.getBlock().getLocation())); Region r = RegionManager.getInstance().getRegionAt(l); if (r == null) { return; } if (!r.getEffects().containsKey(KEY)) { return; } File dataFolder = new File(Civs.dataLocation, Constants.REGIONS); if (!dataFolder.exists()) { return; } File dataFile = new File(dataFolder, r.getId() + ".yml"); if (!dataFile.exists()) { return; } FileConfiguration config = new YamlConfiguration(); try { config.load(dataFile); List<String> locationList = config.getStringList(Constants.CHESTS); locationList.add(Region.locationToString(l)); config.set(Constants.CHESTS, locationList); config.save(dataFile); } catch (Exception e) { Civs.logger.log(Level.WARNING, UNABLE_TO_SAVE_CHEST, r.getId()); return; } if (!invs.containsKey(r)) { invs.put(r, new ArrayList<>()); } CVInventory cvInventory = UnloadedInventoryHandler.getInstance().getChestInventory(event.getBlockPlaced().getLocation()); invs.get(r).add(cvInventory); }
Example 18
Source File: Materials.java From ProjectAres with GNU Affero General Public License v3.0 | 4 votes |
public static boolean isChest(Material material) { return material == Material.CHEST || material == Material.TRAPPED_CHEST; }
Example 19
Source File: BlockListener.java From QuickShop-Reremake with GNU General Public License v3.0 | 4 votes |
@EventHandler(ignoreCancelled = true, priority = EventPriority.LOWEST) public void onPlace(BlockPlaceEvent e) { final Material type = e.getBlock().getType(); final Block placingBlock = e.getBlock(); final Player player = e.getPlayer(); if (type != Material.CHEST) { return; } Block chest = null; //Chest combine mechanic based checking if (player.isSneaking()) { Block blockAgainst = e.getBlockAgainst(); if (blockAgainst.getType() == Material.CHEST && placingBlock.getFace(blockAgainst) != BlockFace.UP && placingBlock.getFace(blockAgainst) != BlockFace.DOWN && !(((Chest) blockAgainst.getState()).getInventory() instanceof DoubleChestInventory)) { chest = e.getBlockAgainst(); } else { return; } } else { //Get all chest in vertical Location BlockFace placingChestFacing = ((Directional) (placingBlock.getState().getBlockData())).getFacing(); for (BlockFace face : Util.getVerticalFacing()) { //just check the right side and left side if (face != placingChestFacing && face != placingChestFacing.getOppositeFace()) { Block nearByBlock = placingBlock.getRelative(face); if (nearByBlock.getType() == Material.CHEST //non double chest && !(((Chest) nearByBlock.getState()).getInventory() instanceof DoubleChestInventory) //same facing && placingChestFacing == ((Directional) nearByBlock.getState().getBlockData()).getFacing()) { if (chest == null) { chest = nearByBlock; } else { //when multiply chests competed, minecraft will always combine with right side if (placingBlock.getFace(nearByBlock) == Util.getRightSide(placingChestFacing)) { chest = nearByBlock; } } } } } } if (chest == null) { return; } Shop shop = getShopPlayer(chest.getLocation(), false); if (shop != null) { if (!QuickShop.getPermissionManager().hasPermission(player, "quickshop.create.double")) { e.setCancelled(true); MsgUtil.sendMessage(player, MsgUtil.getMessage("no-double-chests", player)); } else if (!shop.getModerator().isModerator(player.getUniqueId())) { e.setCancelled(true); MsgUtil.sendMessage(player, MsgUtil.getMessage("not-managed-shop", player)); } } }
Example 20
Source File: ShopInteractListener.java From ShopChest with MIT License | 3 votes |
@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); }