org.bukkit.material.Crops Java Examples
The following examples show how to use
org.bukkit.material.Crops.
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: BlockGrowListener.java From IridiumSkyblock with GNU General Public License v2.0 | 6 votes |
@EventHandler public void onBlockGrow(BlockGrowEvent event) { try { final Block block = event.getBlock(); final Location location = block.getLocation(); final IslandManager islandManager = IridiumSkyblock.getIslandManager(); final Island island = islandManager.getIslandViaLocation(location); if (island == null) return; if (island.getFarmingBooster() == 0) return; final Material material = block.getType(); if (!XBlock.isCrops(material)) return; event.setCancelled(true); final Crops crops = new Crops(CropState.RIPE); final BlockState blockState = block.getState(); blockState.setData(crops); blockState.update(); } catch (Exception e) { IridiumSkyblock.getInstance().sendErrorMessage(e); } }
Example #2
Source File: Region.java From RedProtect with GNU General Public License v3.0 | 6 votes |
public boolean canCrops(Block b) { return flagExists("cropsfarm") && ( b instanceof Crops || b.getType().equals(Material.PUMPKIN_STEM) || b.getType().equals(Material.MELON_STEM) || b.getType().toString().contains("CARROTS") || b.getType().toString().contains("CROPS") || b.getType().toString().contains("_BERRIES") || b.getType().toString().contains("SOIL") || b.getType().toString().contains("CHORUS_") || b.getType().toString().contains("BEETROOT_") || b.getType().toString().contains("BEETROOTS") || b.getType().toString().contains("SUGAR_CANE") || b.getType().toString().contains("FARMLAND") || b.getType().toString().contains("WHEAT")) && getFlagBool("cropsfarm"); }
Example #3
Source File: BlockListener.java From RedProtect with GNU General Public License v3.0 | 5 votes |
@EventHandler(ignoreCancelled = true, priority = EventPriority.LOWEST) public void onPlayerInteract(PlayerInteractEvent e) { RedProtect.get().logger.debug(LogLevel.BLOCKS, "BlockListener - Is PlayerInteractEvent event!"); Player p = e.getPlayer(); Location l = e.getClickedBlock().getLocation(); Region r = RedProtect.get().rm.getTopRegion(l); Block b = p.getLocation().getBlock(); if (r != null && (b instanceof Crops || b.getType().equals(Material.PUMPKIN_STEM) || b.getType().equals(Material.MELON_STEM) || b.getType().toString().contains("CARROTS") || b.getType().toString().contains("_BERRIES") || b.getType().toString().contains("CROPS") || b.getType().toString().contains("SOIL") || b.getType().toString().contains("FARMLAND") || b.getType().toString().contains("CHORUS_") || b.getType().toString().contains("BEETROOT_") || b.getType().toString().contains("BEETROOTS") || b.getType().toString().contains("SUGAR_CANE") || p.getInventory().getItemInHand().getType().name().contains("_HOE")) && !r.canCrops() && !r.canBuild(p)) { RedProtect.get().lang.sendMessage(p, "blocklistener.region.cantbreak"); e.setCancelled(true); return; } Block relative = e.getClickedBlock().getRelative(e.getBlockFace()); if (relative.getType().equals(Material.FIRE)) { Region r1 = RedProtect.get().rm.getTopRegion(relative.getLocation()); if (r1 != null && !r1.canBuild(e.getPlayer())) { e.setCancelled(true); RedProtect.get().lang.sendMessage(e.getPlayer(), "playerlistener.region.cantinteract"); } } }
Example #4
Source File: BlockPlaceListener.java From IridiumSkyblock with GNU General Public License v2.0 | 4 votes |
@EventHandler public void onBlockPlace(BlockPlaceEvent event) { try { final Block block = event.getBlock(); final Location location = block.getLocation(); final IslandManager islandManager = IridiumSkyblock.getIslandManager(); final Island island = islandManager.getIslandViaLocation(location); if (island == null) return; final Player player = event.getPlayer(); final User user = User.getUser(player); final Material material = block.getType(); final XMaterial xmaterial = XMaterial.matchXMaterial(material); final Config config = IridiumSkyblock.getConfiguration(); final Integer max = config.limitedBlocks.get(xmaterial); if (max != null) { if (island.valuableBlocks.getOrDefault(xmaterial.name(), 0) >= max) { player.sendMessage(Utils.color(IridiumSkyblock.getMessages().blockLimitReached .replace("%prefix%", config.prefix))); event.setCancelled(true); return; } } if (user.islandID == island.getId()) { for (Mission mission : IridiumSkyblock.getMissions().missions) { final Map<String, Integer> levels = island.getMissionLevels(); levels.putIfAbsent(mission.name, 1); final MissionData level = mission.levels.get(levels.get(mission.name)); if (level == null) continue; if (level.type != MissionType.BLOCK_PLACE) continue; final List<String> conditions = level.conditions; if ( conditions.isEmpty() || conditions.contains(xmaterial.name()) || conditions.contains(((Crops) block.getState().getData()).getState().toString()) ) island.addMission(mission.name, 1); } } if (!island.getPermissions(user).placeBlocks) event.setCancelled(true); } catch (Exception e) { IridiumSkyblock.getInstance().sendErrorMessage(e); } }
Example #5
Source File: BlockBreakListener.java From IridiumSkyblock with GNU General Public License v2.0 | 4 votes |
@EventHandler public void onBlockBreak(BlockBreakEvent event) { try { if (event.isCancelled()) return; final Block block = event.getBlock(); final Location location = block.getLocation(); final IslandManager islandManager = IridiumSkyblock.getIslandManager(); final Island island = islandManager.getIslandViaLocation(location); if (island == null) return; final Player player = event.getPlayer(); final User user = User.getUser(player); if (user.islandID == island.getId()) { for (Missions.Mission mission : IridiumSkyblock.getMissions().missions) { final int key = island.getMissionLevels().computeIfAbsent(mission.name, (name) -> 1); final Map<Integer, Missions.MissionData> levels = mission.levels; final Missions.MissionData level = levels.get(key); if (level == null) continue; if (level.type != MissionType.BLOCK_BREAK) continue; final List<String> conditions = level.conditions; if ( conditions.isEmpty() || conditions.contains(XMaterial.matchXMaterial(block.getType()).name()) || ( block.getState().getData() instanceof Crops && conditions.contains(((Crops) block.getState().getData()).getState().toString()) ) ) island.addMission(mission.name, 1); } } if (!island.getPermissions(user).breakBlocks || (!island.getPermissions(user).breakSpawners && XMaterial.matchXMaterial(block.getType()).equals(XMaterial.SPAWNER))) { if (XMaterial.matchXMaterial(block.getType()).equals(XMaterial.SPAWNER)) { player.sendMessage(Utils.color(IridiumSkyblock.getMessages().noPermissionBreakSpawners.replace("%prefix%", IridiumSkyblock.getConfiguration().prefix))); } else { player.sendMessage(Utils.color(IridiumSkyblock.getMessages().noPermissionBuild.replace("%prefix%", IridiumSkyblock.getConfiguration().prefix))); } event.setCancelled(true); } } catch (Exception e) { IridiumSkyblock.getInstance().sendErrorMessage(e); } }
Example #6
Source File: FarmingTaskType.java From Quests with MIT License | 4 votes |
@SuppressWarnings("deprecation") @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true) public void onBlockBreak(BlockBreakEvent event) { //TODO: finish this if (!(event.getBlock().getState() instanceof Crops)) { return; } Crops crop = (Crops) event.getBlock().getState(); QPlayer qPlayer = QuestsAPI.getPlayerManager().getPlayer(event.getPlayer().getUniqueId(), true); QuestProgressFile questProgressFile = qPlayer.getQuestProgressFile(); for (Quest quest : super.getRegisteredQuests()) { if (questProgressFile.hasStartedQuest(quest)) { QuestProgress questProgress = questProgressFile.getQuestProgress(quest); for (Task task : quest.getTasksOfType(super.getType())) { TaskProgress taskProgress = questProgress.getTaskProgress(task.getId()); if (taskProgress.isCompleted()) { continue; } Material material; Object configBlock = task.getConfigValue("block"); Object configData = task.getConfigValue("data"); material = Material.matchMaterial(String.valueOf(configBlock)); if (material != null && event.getBlock().getType().equals(material)) { if (configData != null && (((int) event.getBlock().getData()) != ((int) configData))) { continue; } int brokenBlocksNeeded = (int) task.getConfigValue("amount"); int progressBlocksBroken; if (taskProgress.getProgress() == null) { progressBlocksBroken = 0; } else { progressBlocksBroken = (int) taskProgress.getProgress(); } taskProgress.setProgress(progressBlocksBroken + 1); if (((int) taskProgress.getProgress()) >= brokenBlocksNeeded) { taskProgress.setCompleted(true); } } } } } }