Java Code Examples for br.net.fabiozumbi12.RedProtect.Bukkit.Region#canBuild()
The following examples show how to use
br.net.fabiozumbi12.RedProtect.Bukkit.Region#canBuild() .
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: Compat18.java From RedProtect with GNU General Public License v3.0 | 6 votes |
@EventHandler(ignoreCancelled = true) public void onAttemptInteractAS(PlayerInteractAtEntityEvent e) { Entity ent = e.getRightClicked(); Location l = ent.getLocation(); Region r = RedProtect.get().rm.getTopRegion(l); Player p = e.getPlayer(); if (r == null) { //global flags if (ent instanceof ArmorStand) { if (!RedProtect.get().config.globalFlagsRoot().worlds.get(l.getWorld().getName()).build) { e.setCancelled(true); return; } } return; } if (ent instanceof ArmorStand) { if (!r.canBuild(p)) { RedProtect.get().lang.sendMessage(p, "playerlistener.region.cantedit"); e.setCancelled(true); } } }
Example 2
Source File: Compat18.java From RedProtect with GNU General Public License v3.0 | 6 votes |
@EventHandler(ignoreCancelled = true) public void onInteractAS(PlayerInteractEvent e) { if (e.getClickedBlock() == null) { return; } if (RedProtect.get().bukkitVersion <= 180) { return; } Player p = e.getPlayer(); Location l = e.getClickedBlock().getLocation(); Region r = RedProtect.get().rm.getTopRegion(l); Material m = p.getItemInHand().getType(); if (RedProtect.get().bukkitVersion >= 190 && e.getItem() != null) { m = e.getItem().getType(); } if (m.equals(Material.ARMOR_STAND) || m.equals(Material.END_CRYSTAL)) { if (r != null && !r.canBuild(p) && !r.canPlace(m) && !r.canBreak(m)) { e.setCancelled(true); RedProtect.get().lang.sendMessage(p, "blocklistener.region.cantbuild"); } } }
Example 3
Source File: GlobalListener.java From RedProtect with GNU General Public License v3.0 | 6 votes |
@EventHandler(ignoreCancelled = true) public void onConsume(PlayerItemConsumeEvent e) { if (e.getItem() == null) { return; } Player p = e.getPlayer(); Location l = p.getLocation(); Region r = RedProtect.get().rm.getTopRegion(l); //deny item usage List<String> items = RedProtect.get().config.globalFlagsRoot().worlds.get(p.getWorld().getName()).deny_item_usage.items; if (e.getItem() != null && items.stream().anyMatch(e.getItem().getType().name()::matches)) { if (r != null && ((!RedProtect.get().config.globalFlagsRoot().worlds.get(p.getWorld().getName()).deny_item_usage.allow_on_claimed_rps && r.canBuild(p)) || (RedProtect.get().config.globalFlagsRoot().worlds.get(p.getWorld().getName()).deny_item_usage.allow_on_claimed_rps && !r.canBuild(p)))) { RedProtect.get().lang.sendMessage(p, "playerlistener.region.cantuse"); e.setCancelled(true); return; } if (r == null && !RedProtect.get().config.globalFlagsRoot().worlds.get(p.getWorld().getName()).deny_item_usage.allow_on_wilderness && !RedProtect.get().ph.hasPerm(p, "redprotect.bypass.world")) { RedProtect.get().lang.sendMessage(p, "playerlistener.region.cantuse"); e.setCancelled(true); } } }
Example 4
Source File: PlayerListener.java From RedProtect with GNU General Public License v3.0 | 6 votes |
private boolean checkMaxPlayer(Player p, Region r) { if (r.canBuild(p)) { return true; } int ttl = 0; for (Player onp : p.getWorld().getPlayers()) { if (onp == p) { continue; } Region reg = RedProtect.get().rm.getTopRegion(onp.getLocation()); if (reg != null && reg == r) { ttl++; } } return ttl < r.getMaxPlayers(); }
Example 5
Source File: RedProtectUtil.java From RedProtect with GNU General Public License v3.0 | 6 votes |
public boolean canBuildNear(Player p, Location loc) { if (RedProtect.get().config.configRoot().region_settings.deny_build_near <= 0) { return true; } int x = loc.getBlockX(); int y = loc.getBlockY(); int z = loc.getBlockZ(); int radius = RedProtect.get().config.configRoot().region_settings.deny_build_near; for (int ix = x - radius; ix <= x + radius; ++ix) { for (int iy = y - radius; iy <= y + radius; ++iy) { for (int iz = z - radius; iz <= z + radius; ++iz) { Region reg = RedProtect.get().rm.getTopRegion(new Location(p.getWorld(), ix, iy, iz)); if (reg != null && !reg.canBuild(p)) { RedProtect.get().lang.sendMessage(p, RedProtect.get().lang.get("blocklistener.cantbuild.nearrp").replace("{distance}", "" + radius)); return false; } } } } return true; }
Example 6
Source File: PlayerListener.java From RedProtect with GNU General Public License v3.0 | 6 votes |
@EventHandler public void onHangingDamaged(HangingBreakByEntityEvent e) { if (e.isCancelled()) { return; } RedProtect.get().logger.debug(LogLevel.PLAYER, "Is PlayerListener - HangingBreakByEntityEvent event"); Entity ent = e.getRemover(); Location loc = e.getEntity().getLocation(); Region r = RedProtect.get().rm.getTopRegion(loc); if (ent instanceof Player) { Player player = (Player) ent; if (r != null && !r.canBuild(player) && !r.canBreak(e.getEntity().getType())) { RedProtect.get().lang.sendMessage(player, "blocklistener.region.cantbuild"); e.setCancelled(true); } } if (ent instanceof Monster) { if (r != null && !r.canMobLoot()) { e.setCancelled(true); } } }
Example 7
Source File: PlayerListener.java From RedProtect with GNU General Public License v3.0 | 5 votes |
@EventHandler public void PlayerTrownEgg(PlayerEggThrowEvent e) { Location l = e.getEgg().getLocation(); Player p = e.getPlayer(); Region r = RedProtect.get().rm.getTopRegion(l); if (r != null && !r.canBuild(p)) { e.setHatching(false); RedProtect.get().lang.sendMessage(p, "playerlistener.region.canthatch"); } }
Example 8
Source File: RedProtectHook.java From RandomTeleport with GNU General Public License v3.0 | 5 votes |
@Override public boolean canBuild(Player player, World world, int chunkX, int chunkZ) { for (Region region : inst.getAPI().getChunkRegions(world.getChunkAt(chunkX, chunkZ))) { if (!region.canBuild(player)) { return false; } } return true; }
Example 9
Source File: BlockListener.java From RedProtect with GNU General Public License v3.0 | 5 votes |
@EventHandler(ignoreCancelled = true) public void onBlockStartBurn(BlockIgniteEvent e) { RedProtect.get().logger.debug(LogLevel.BLOCKS, "BlockListener - Is BlockIgniteEvent event"); Block b = e.getBlock(); Block bignit = e.getIgnitingBlock(); if (b == null) { return; } Region r = RedProtect.get().rm.getTopRegion(b.getLocation()); if (r != null && !r.canFire()) { if (e.getIgnitingEntity() != null) { if (e.getIgnitingEntity() instanceof Player) { Player p = (Player) e.getIgnitingEntity(); if (!r.canBuild(p)) { RedProtect.get().lang.sendMessage(p, "blocklistener.region.cantplace"); e.setCancelled(true); return; } } else { e.setCancelled(true); return; } } if (bignit != null && (bignit.getType().equals(Material.FIRE) || bignit.getType().name().contains("LAVA"))) { e.setCancelled(true); return; } if (e.getCause().equals(IgniteCause.LIGHTNING) || e.getCause().equals(IgniteCause.EXPLOSION) || e.getCause().equals(IgniteCause.FIREBALL)) { e.setCancelled(true); } } }
Example 10
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 11
Source File: BlockListener.java From RedProtect with GNU General Public License v3.0 | 5 votes |
@EventHandler(ignoreCancelled = true, priority = EventPriority.LOWEST) public void onBlockBreak(BlockBreakEvent e) { RedProtect.get().logger.debug(LogLevel.BLOCKS, "BlockListener - Is BlockBreakEvent event!"); Player p = e.getPlayer(); Block b = e.getBlock(); boolean antih = RedProtect.get().config.configRoot().region_settings.anti_hopper; Region r = RedProtect.get().rm.getTopRegion(b.getLocation()); if (!RedProtect.get().ph.hasPerm(p, "redprotect.bypass")) { Block ib = b.getRelative(BlockFace.UP); if ((antih && !cont.canBreak(p, ib)) || !cont.canBreak(p, b)) { RedProtect.get().lang.sendMessage(p, "blocklistener.container.breakinside"); e.setCancelled(true); return; } } if (r == null && canBreakList(p.getWorld(), b.getType().name())) { return; } if (r != null && (b.getType().name().equals("MOB_SPAWNER") || b.getType().name().equals("SPAWNER")) && r.canPlaceSpawner(p)) { return; } if (r != null && r.canBuild(p) && b.getType().name().endsWith("_SIGN")) { Sign s = (Sign) b.getState(); if (s.getLine(0).equalsIgnoreCase("[flag]")) { RedProtect.get().config.removeSign(r.getID(), b.getLocation()); return; } } if (r != null && !r.canBuild(p) && !r.canTree(b) && !r.canMining(b) && !r.canCrops(b) && !r.canBreak(b.getType())) { RedProtect.get().lang.sendMessage(p, "blocklistener.region.cantbuild"); e.setCancelled(true); } }
Example 12
Source File: PlayerListener.java From RedProtect with GNU General Public License v3.0 | 5 votes |
@EventHandler public void onBucketFill(PlayerBucketFillEvent e) { if (e.isCancelled()) { return; } Player p = e.getPlayer(); Location l = e.getBlockClicked().getLocation(); Region r = RedProtect.get().rm.getTopRegion(l); if (r != null && !r.canBuild(p) && (p.getItemInHand().getType().name().contains("BUCKET"))) { e.setCancelled(true); } }
Example 13
Source File: PlayerListener.java From RedProtect with GNU General Public License v3.0 | 5 votes |
@EventHandler public void onBucketUse(PlayerBucketEmptyEvent e) { if (e.isCancelled()) { return; } Player p = e.getPlayer(); Location l = e.getBlockClicked().getLocation(); Region r = RedProtect.get().rm.getTopRegion(l); if (r != null && !r.canBuild(p) && (p.getItemInHand().getType().name().contains("BUCKET"))) { e.setCancelled(true); } }
Example 14
Source File: Compat114.java From RedProtect with GNU General Public License v3.0 | 5 votes |
@EventHandler(ignoreCancelled = true) public void onTakeBookLectern(PlayerTakeLecternBookEvent event) { Player p = event.getPlayer(); Region r = RedProtect.get().rm.getTopRegion(event.getLectern().getLocation()); if (r != null) { if (!r.canBuild(p)) { RedProtect.get().lang.sendMessage(p, "playerlistener.region.cantremove"); event.setCancelled(true); } } else if (!RedProtect.get().config.globalFlagsRoot().worlds.get(p.getWorld().getName()).build && !p.hasPermission("redprotect.bypass.world")) { event.setCancelled(true); } }
Example 15
Source File: Compat111.java From RedProtect with GNU General Public License v3.0 | 5 votes |
@EventHandler private void onChorusBreak(ProjectileHitEvent event) { if (!(event.getEntity().getShooter() instanceof Player)) return; if (event.getHitBlock() != null && event.getHitBlock().getType() == Material.CHORUS_FLOWER) { Player p = (Player) event.getEntity().getShooter(); Region r = RedProtect.get().rm.getTopRegion(event.getHitBlock().getLocation()); if (r != null && !r.canBuild(p)) { event.getEntity().remove(); event.getHitBlock().setType(Material.AIR); Bukkit.getScheduler().runTask(RedProtect.get(), () -> event.getHitBlock().setType(Material.CHORUS_FLOWER)); RedProtect.get().lang.sendMessage(p, "blocklistener.region.cantbreak"); } } }
Example 16
Source File: Compat19.java From RedProtect with GNU General Public License v3.0 | 5 votes |
@EventHandler(ignoreCancelled = true) public void onChangeBlock(EntityChangeBlockEvent e) { if (e.getEntity() instanceof Player) { Player p = (Player) e.getEntity(); Block b = e.getBlock(); Region r = RedProtect.get().rm.getTopRegion(b.getLocation()); if (r != null && !r.canBuild(p)) { RedProtect.get().lang.sendMessage(p, "blocklistener.region.cantbreak"); e.setCancelled(true); } } }
Example 17
Source File: PlayerListener.java From RedProtect with GNU General Public License v3.0 | 4 votes |
@EventHandler public void onPlayerCommand(PlayerCommandPreprocessEvent e) { Player p = e.getPlayer(); if (RedProtect.get().tpWait.contains(p.getName())) { RedProtect.get().tpWait.remove(p.getName()); RedProtect.get().lang.sendMessage(p, "cmdmanager.region.tpcancelled"); } String msg = e.getMessage(); String cmds = msg.split(" ")[0].toLowerCase().replace("/", ""); //RedProtect.get().logger.severe("Command: "+msg); if (RedProtect.get().config.configRoot().server_protection.deny_commands_on_worlds.getOrDefault(p.getWorld().getName(), new ArrayList<>()).contains(cmds) && !p.hasPermission("redprotect.bypass")) { RedProtect.get().lang.sendMessage(p, "playerlistener.command-notallowed"); e.setCancelled(true); return; } if (RedProtect.get().config.globalFlagsRoot().worlds.get(p.getWorld().getName()).command_ranges.containsKey(cmds.toLowerCase().replace("/", "")) && !cmds.equals(".")) { double min = RedProtect.get().config.globalFlagsRoot().worlds.get(p.getWorld().getName()).command_ranges.get(cmds).min_range; double max = RedProtect.get().config.globalFlagsRoot().worlds.get(p.getWorld().getName()).command_ranges.get(cmds).max_range; String mesg = RedProtect.get().config.globalFlagsRoot().worlds.get(p.getWorld().getName()).command_ranges.get(cmds).message; double py = p.getLocation().getY(); if (py < min || py > max) { if (mesg != null && !mesg.equals("")) { RedProtect.get().lang.sendMessage(p, mesg); } e.setCancelled(true); return; } } if (cmds.equalsIgnoreCase("back") || cmds.equalsIgnoreCase("home")) { PlayerCmd.put(p.getName(), msg); } Region r = RedProtect.get().rm.getTopRegion(p.getLocation()); if (r != null) { if ((cmds.equalsIgnoreCase("petc") || cmds.equalsIgnoreCase("petcall")) && RedProtect.get().hooks.myPet && !r.canPet(p)) { RedProtect.get().lang.sendMessage(p, "playerlistener.region.cantpet"); e.setCancelled(true); return; } if (!r.isCmdAllowed(msg)) { if (cmds.equalsIgnoreCase("rp") || cmds.equalsIgnoreCase("redprotect")) { return; } RedProtect.get().lang.sendMessage(p, "playerlistener.region.cantcommand"); e.setCancelled(true); return; } if (!r.isCmdDenied(msg)) { for (String alias : RedProtect.get().getCommand("RedProtect").getAliases()) { if (cmds.equalsIgnoreCase(alias)) { return; } } RedProtect.get().lang.sendMessage(p, "playerlistener.region.cantcommand"); e.setCancelled(true); return; } if (cmds.equalsIgnoreCase("sethome") && !r.isHomeAllowed(p)) { RedProtect.get().lang.sendMessage(p, "playerlistener.region.canthome"); e.setCancelled(true); return; } //Pvp check if (cmds.equalsIgnoreCase("pvp") && RedProtect.get().hooks.pvpm) { if (r.isPvPArena() && !PvPlayer.get(p).hasPvPEnabled() && !r.canBuild(p)) { RedProtect.get().lang.sendMessage(p, "playerlistener.region.pvpenabled"); RedProtect.get().getServer().dispatchCommand(RedProtect.get().getServer().getConsoleSender(), RedProtect.get().config.configRoot().flags_configuration.pvparena_nopvp_kick_cmd.replace("{player}", p.getName())); } } } }
Example 18
Source File: BlockListener.java From RedProtect with GNU General Public License v3.0 | 4 votes |
@EventHandler(ignoreCancelled = true, priority = EventPriority.HIGH) public void onBlockPlace(BlockPlaceEvent e) { RedProtect.get().logger.debug(LogLevel.BLOCKS, "BlockListener - Is BlockPlaceEvent event!"); Player p = e.getPlayer(); Block b = e.getBlockPlaced(); World w = p.getWorld(); Material m = e.getItemInHand().getType(); boolean antih = RedProtect.get().config.configRoot().region_settings.anti_hopper; Region r = RedProtect.get().rm.getTopRegion(b.getLocation()); if (!RedProtect.get().ph.hasPerm(p, "redprotect.bypass") && antih && (m.equals(Material.HOPPER) || m.name().contains("RAIL"))) { int x = b.getX(); int y = b.getY(); int z = b.getZ(); Block ib = w.getBlockAt(x, y + 1, z); if (!cont.canBreak(p, ib) || !cont.canBreak(p, b)) { RedProtect.get().lang.sendMessage(p, "blocklistener.container.chestinside"); e.setCancelled(true); return; } } if (r == null && canPlaceList(p.getWorld(), b.getType().name())) { return; } if (r != null) { if (!r.canMinecart(p) && (m.name().contains("MINECART") || m.name().contains("BOAT"))) { RedProtect.get().lang.sendMessage(p, "blocklistener.region.cantplace"); e.setCancelled(true); return; } if ((b.getType().name().equals("MOB_SPAWNER") || b.getType().name().equals("SPAWNER")) && r.canPlaceSpawner(p)) { return; } if ((m.name().contains("_HOE") || r.canCrops(b)) && r.canCrops()) { return; } Material type = b.getType(); if (!r.blockTransform() && type.isBlock() && ( type.name().contains("SNOW") || type.name().contains("ICE") || type.name().contains("CORAL") || type.name().contains("POWDER"))) { b.setType(m); } if (!r.canBuild(p) && !r.canPlace(b.getType())) { RedProtect.get().lang.sendMessage(p, "blocklistener.region.cantbuild"); e.setCancelled(true); } } }
Example 19
Source File: PlayerListener.java From RedProtect with GNU General Public License v3.0 | 4 votes |
@EventHandler(priority = EventPriority.LOWEST) public void onEntityDamageByEntityEvent(EntityDamageByEntityEvent e) { Player p = null; RedProtect.get().logger.debug(LogLevel.PLAYER, "RPLayerListener: Is EntityDamageByEntityEvent event"); if (e.getDamager() instanceof Player) { p = (Player) e.getDamager(); } else if (e.getDamager() instanceof Projectile) { Projectile proj = (Projectile) e.getDamager(); if (proj.getShooter() instanceof Player) { p = (Player) proj.getShooter(); } } if (p != null) { RedProtect.get().logger.debug(LogLevel.PLAYER, "Player: " + p.getName()); } else { RedProtect.get().logger.debug(LogLevel.PLAYER, "Player: is null"); return; } RedProtect.get().logger.debug(LogLevel.PLAYER, "Damager: " + e.getDamager().getType().name()); Location l = e.getEntity().getLocation(); Region r = RedProtect.get().rm.getTopRegion(l); if (r == null) { return; } if (RedProtect.get().tpWait.contains(p.getName())) { RedProtect.get().tpWait.remove(p.getName()); RedProtect.get().lang.sendMessage(p, "cmdmanager.region.tpcancelled"); } if (e.getEntity() instanceof Player && !p.equals(e.getEntity()) && r.flagExists("pvp") && !r.canPVP((Player) e.getEntity(), p)) { RedProtect.get().lang.sendMessage(p, "entitylistener.region.cantpvp"); e.setCancelled(true); } if ((e.getEntity() instanceof Hanging || e.getEntity() instanceof EnderCrystal) && !r.canBuild(p) && !r.canBreak(e.getEntityType())) { RedProtect.get().lang.sendMessage(p, "playerlistener.region.cantremove"); e.setCancelled(true); } if ((e.getEntity() instanceof Boat || e.getEntity() instanceof Minecart) && !r.canMinecart(p)) { RedProtect.get().lang.sendMessage(p, "blocklistener.region.cantbreak"); e.setCancelled(true); } }
Example 20
Source File: RedProtectHook.java From RandomTeleport with GNU General Public License v3.0 | 4 votes |
@Override public boolean canBuild(Player player, Location location) { Region region = inst.getAPI().getRegion(location); return region == null || region.canBuild(player); }