Exemplo n.º 1
0
 /*
 @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
 public void onPlayerUseBukkit(PlayerBucketEvent event) {
     ZoneManager manager = m_plugin.getZoneManager();
     Zone zone = manager.getZone(event.getBlockClicked().getLocation());
     if (zone != null) {
         if (!zone.canPlayerUse(event.getPlayer(), event.getBlockClicked())) {
             event.setCancelled(true);
             sendMessageNoSpam(event.getPlayer(), UI.getMessage("NoBuild"));
         }
     }
 }
 */
 @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
 public void onPlayerInteractEvent(PlayerInteractEvent event) {
   ZoneManager manager = m_plugin.getZoneManager();
   Zone zone = manager.getZone(event.getClickedBlock().getLocation());
   if (zone != null) {
     if (!zone.canPlayerUse(event.getPlayer(), event.getClickedBlock())) {
       if (event.getAction() == Action.PHYSICAL
           || (event.getAction() == Action.RIGHT_CLICK_BLOCK && !event.isBlockInHand())) {
         if (event.getAction() == Action.PHYSICAL) {
           return;
         }
         event.setUseInteractedBlock(Event.Result.DENY);
         sendMessageNoSpam(event.getPlayer(), UI.getMessage("NoBuild"));
       }
     }
   }
 }
Exemplo n.º 2
0
  @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);
              }
            }
          }
        }
      }
    }
  }