@EventHandler(priority = EventPriority.HIGH) // , ignoreCancelled = true public void onBlockPlace(final BlockPlaceEvent event) { Block b = event.getBlock(); if (PlotManager.isPlotWorld(b)) { Player p = event.getPlayer(); boolean canbuild = PlotMe.cPerms(p, "plotme.admin.buildanywhere"); String id = PlotManager.getPlotId(b.getLocation()); if (id.equalsIgnoreCase("")) { if (!canbuild) { p.sendMessage(PlotMe.caption("ErrCannotBuild")); event.setCancelled(true); } } else { Plot plot = PlotManager.getPlotById(p, id); if (plot == null) { if (!canbuild) { p.sendMessage(PlotMe.caption("ErrCannotBuild")); event.setCancelled(true); } } else if (!plot.isAllowed(p.getName())) { if (!canbuild) { p.sendMessage(PlotMe.caption("ErrCannotBuild")); event.setCancelled(true); } } else { plot.resetExpire(PlotManager.getMap(b).DaysToExpiration); } } } }
@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true) public void onPlayerInteractEntity(final PlayerInteractEntityEvent event) { Location l = event.getRightClicked().getLocation(); if (PlotManager.isPlotWorld(l)) { Player p = event.getPlayer(); boolean canbuild = PlotMe.cPerms(p, "plotme.admin.buildanywhere"); String id = PlotManager.getPlotId(l); if (id.equalsIgnoreCase("")) { if (!canbuild) { p.sendMessage(PlotMe.caption("ErrCannotBuild")); event.setCancelled(true); } } else { Plot plot = PlotManager.getPlotById(p, id); if (plot == null) { if (!canbuild) { p.sendMessage(PlotMe.caption("ErrCannotBuild")); event.setCancelled(true); } } else if (!plot.isAllowed(p.getName())) { if (!canbuild) { p.sendMessage(PlotMe.caption("ErrCannotBuild")); event.setCancelled(true); } } else { plot.resetExpire(PlotManager.getMap(l).DaysToExpiration); } } } }
@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true) public void onPlayerEggThrow(final PlayerEggThrowEvent event) { Location l = event.getEgg().getLocation(); if (PlotManager.isPlotWorld(l)) { Player p = event.getPlayer(); boolean canbuild = PlotMe.cPerms(p, "plotme.admin.buildanywhere"); String id = PlotManager.getPlotId(l); if (id.equalsIgnoreCase("")) { if (!canbuild) { p.sendMessage(PlotMe.caption("ErrCannotUseEggs")); event.setHatching(false); } } else { Plot plot = PlotManager.getPlotById(p, id); if (plot == null) { if (!canbuild) { p.sendMessage(PlotMe.caption("ErrCannotUseEggs")); event.setHatching(false); } } else if (!plot.isAllowed(p.getName())) { if (!canbuild) { p.sendMessage(PlotMe.caption("ErrCannotUseEggs")); event.setHatching(false); } } } } }
@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true) public void onPlayerBucketFill(final PlayerBucketFillEvent event) { if (!PlotMe.cPerms(event.getPlayer(), "plotme.admin.buildanywhere")) { Block b = event.getBlockClicked(); if (PlotManager.isPlotWorld(b)) { String id = PlotManager.getPlotId(b.getLocation()); Player p = event.getPlayer(); if (id.equalsIgnoreCase("")) { p.sendMessage(PlotMe.caption("ErrCannotBuild")); event.setCancelled(true); } else { Plot plot = PlotManager.getPlotById(p, id); if (plot == null) { p.sendMessage(PlotMe.caption("ErrCannotBuild")); event.setCancelled(true); } else if (!plot.isAllowed(p.getName())) { p.sendMessage(PlotMe.caption("ErrCannotBuild")); event.setCancelled(true); } } } } }
@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true) public void onBlockIgnite(final BlockIgniteEvent event) { Block b = event.getBlock(); if (b != null) { PlotMapInfo pmi = PlotManager.getMap(b); if (pmi != null) { if (pmi.DisableIgnition) { event.setCancelled(true); } else { String id = PlotManager.getPlotId(b.getLocation()); Player p = event.getPlayer(); if (id.equalsIgnoreCase("") || p == null) { event.setCancelled(true); } else { Plot plot = PlotManager.getPlotById(b, id); if (plot == null) { event.setCancelled(true); } else if (!plot.isAllowed(p.getName())) { event.setCancelled(true); } } } } } }
@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true) public void onBlockPistonRetract(final BlockPistonRetractEvent event) { Block b = event.getRetractLocation().getBlock(); if (PlotManager.isPlotWorld(b) && event.getBlock().getType() == Material.PISTON_STICKY_BASE) { String id = PlotManager.getPlotId(b.getLocation()); if (id.equalsIgnoreCase("")) { event.setCancelled(true); } } }
@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true) public void onBlockGrow(final BlockGrowEvent event) { Block b = event.getBlock(); if (PlotManager.isPlotWorld(b)) { String id = PlotManager.getPlotId(b.getLocation()); if (id.equalsIgnoreCase("")) { event.setCancelled(true); } } }
@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true) public void onStructureGrow(final StructureGrowEvent event) { List<BlockState> blocks = event.getBlocks(); boolean found = false; for (int i = 0; i < blocks.size(); i++) { if (found || PlotManager.isPlotWorld(blocks.get(i))) { found = true; String id = PlotManager.getPlotId(blocks.get(i).getLocation()); if (id.equalsIgnoreCase("")) { event.getBlocks().remove(i); i--; } } } }
@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true) public void onBlockPistonExtend(final BlockPistonExtendEvent event) { if (PlotManager.isPlotWorld(event.getBlock())) { BlockFace face = event.getDirection(); for (Block b : event.getBlocks()) { String id = PlotManager.getPlotId( b.getLocation().add(face.getModX(), face.getModY(), face.getModZ())); if (id.equalsIgnoreCase("")) { event.setCancelled(true); return; } } } }
public void setMask(Player p, Location l) { World w = p.getWorld(); String id = PlotManager.getPlotId(l); Location bottom = null; Location top = null; LocalSession session = PlotMe.worldeditplugin.getSession(p); if (!id.equalsIgnoreCase("")) { Plot plot = PlotManager.getPlotById(p, id); if (plot != null && plot.isAllowed(p.getUniqueId())) { bottom = PlotManager.getPlotBottomLoc(w, id); top = PlotManager.getPlotTopLoc(w, id); BukkitPlayer player = PlotMe.worldeditplugin.wrapPlayer(p); LocalWorld world = player.getWorld(); Vector pos1 = new Vector(bottom.getBlockX(), bottom.getBlockY(), bottom.getBlockZ()); Vector pos2 = new Vector(top.getBlockX(), top.getBlockY(), top.getBlockZ()); CuboidRegion cr = new CuboidRegion(world, pos1, pos2); RegionMask rm = new RegionMask(cr); session.setMask(rm); return; } } if (bottom == null || top == null) { bottom = new Location(w, 0, 0, 0); top = new Location(w, 0, 0, 0); } Object result = null; try { Class<? extends LocalSession> csession = session.getClass(); Method method = csession.getMethod("getMask", (Class<?>[]) null); result = method.invoke(session, (Object[]) null); } catch (NoSuchMethodException e) { e.printStackTrace(); } catch (SecurityException e) { e.printStackTrace(); } catch (IllegalAccessException e) { e.printStackTrace(); } catch (IllegalArgumentException e) { e.printStackTrace(); } catch (InvocationTargetException e) { e.printStackTrace(); } if (result == null) { BukkitPlayer player = PlotMe.worldeditplugin.wrapPlayer(p); LocalWorld world = player.getWorld(); Vector pos1 = new Vector(bottom.getBlockX(), bottom.getBlockY(), bottom.getBlockZ()); Vector pos2 = new Vector(top.getBlockX(), top.getBlockY(), top.getBlockZ()); CuboidRegion cr = new CuboidRegion(world, pos1, pos2); RegionMask rm = new RegionMask(cr); session.setMask(rm); } }
@SuppressWarnings("deprecation") @EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true) public void onPlayerInteract(final PlayerInteractEvent event) { Block b = event.getClickedBlock(); if (PlotManager.isPlotWorld(b)) { PlotMapInfo pmi = PlotManager.getMap(b); boolean blocked = false; Player player = event.getPlayer(); boolean canbuild = PlotMe.cPerms(player, "plotme.admin.buildanywhere"); if (event.isBlockInHand() && event.getAction() == Action.RIGHT_CLICK_BLOCK) { BlockFace face = event.getBlockFace(); Block builtblock = b.getWorld() .getBlockAt( b.getX() + face.getModX(), b.getY() + face.getModY(), b.getZ() + face.getModZ()); String id = PlotManager.getPlotId(builtblock.getLocation()); Player p = event.getPlayer(); if (id.equalsIgnoreCase("")) { if (!canbuild) { p.sendMessage(PlotMe.caption("ErrCannotBuild")); event.setCancelled(true); } } else { Plot plot = PlotManager.getPlotById(p, id); if (plot == null) { if (!canbuild) { p.sendMessage(PlotMe.caption("ErrCannotBuild")); event.setCancelled(true); } } else { if (!plot.isAllowed(p.getName())) { if (!canbuild) { p.sendMessage(PlotMe.caption("ErrCannotBuild")); event.setCancelled(true); } } else { plot.resetExpire(PlotManager.getMap(b).DaysToExpiration); } } } } else { /*for(int blockid : pmi.ProtectedBlocks) { if(blockid == b.getTypeId()) { if(!PlotMe.cPerms(player, "plotme.unblock." + blockid)) blocked = true; break; } }*/ if (pmi.ProtectedBlocks.contains(b.getTypeId())) { if (!PlotMe.cPerms(player, "plotme.unblock." + b.getTypeId())) blocked = true; } ItemStack is = event.getItem(); if (is != null && event.getAction() == Action.RIGHT_CLICK_BLOCK) { int itemid = is.getType().getId(); byte itemdata = is.getData().getData(); if (pmi.PreventedItems.contains("" + itemid) || pmi.PreventedItems.contains("" + itemid + ":" + itemdata)) { if (!PlotMe.cPerms(player, "plotme.unblock." + itemid)) blocked = true; } } if (blocked) { String id = PlotManager.getPlotId(b.getLocation()); Player p = event.getPlayer(); if (id.equalsIgnoreCase("")) { if (!canbuild) { if (event.getAction() == Action.RIGHT_CLICK_BLOCK) { p.sendMessage(PlotMe.caption("ErrCannotUse")); } event.setCancelled(true); } } else { Plot plot = PlotManager.getPlotById(p, id); if (plot == null) { if (!canbuild) { if (event.getAction() == Action.RIGHT_CLICK_BLOCK) { p.sendMessage(PlotMe.caption("ErrCannotUse")); } event.setCancelled(true); } } else if (!plot.isAllowed(p.getName())) { if (!canbuild) { if (event.getAction() == Action.RIGHT_CLICK_BLOCK) { p.sendMessage(PlotMe.caption("ErrCannotUse")); } event.setCancelled(true); } } } } } } }