@EventHandler
  public void onPlayerInteractEvent(PlayerInteractEvent event) {
    if (!isEnabled()) return;
    try {
      if (event.hasBlock() && event.getClickedBlock().getType() == Material.SIGN) return;
      if (event.hasItem() && event.useItemInHand() != Event.Result.DENY) {
        ForgePermittor.log(
            "ItemType: " + getValidator().CheckItem(event.getItem()).toString(), true);
        if (!getProtectionManager()
            .CanUseItem(
                event.getPlayer(),
                event.getPlayer().getLocation(),
                getValidator().CheckItem(event.getItem()))) {
          event.setUseItemInHand(Event.Result.DENY);
          event.setUseInteractedBlock(Event.Result.DENY);

          return;
        }
      }
      if (event.hasBlock() && event.useInteractedBlock() != Event.Result.DENY) {
        ForgePermittor.log(
            "BlockType: " + getValidator().CheckBlock(event.getClickedBlock()).toString(), true);
        if (!getProtectionManager()
            .CanUseBlock(
                event.getPlayer(),
                event.getClickedBlock(),
                getValidator().CheckBlock(event.getClickedBlock()))) {
          event.setUseInteractedBlock(Event.Result.DENY);
        }
      }
    } catch (Exception e) {
      e.printStackTrace();
    }
  }
예제 #2
0
  @Override
  public void onRightClick(PlayerInteractEvent event) {

    LocalPlayer localPlayer = plugin.wrap(event.getPlayer());

    if (!plugin.getLocalConfiguration().cauldronSettings.enable) return;

    if (!localPlayer.hasPermission("craftbook.mech.cauldron")) return;

    if (!BukkitUtil.toWorldVector(event.getClickedBlock()).equals(pt)) return;
    if (event.getPlayer().getItemInHand().getTypeId() >= 255
        || event.getPlayer().getItemInHand().getType() == Material.AIR) {
      if (preCauldron(event.getPlayer(), event.getPlayer().getWorld(), pt)) {
        event.setUseInteractedBlock(Result.DENY);
        event.setUseItemInHand(Result.DENY);
        event.setCancelled(true);
      }
    }
  }
예제 #3
0
  @EventHandler(priority = EventPriority.HIGHEST)
  public void onPlayerInteract(PlayerInteractEvent event) {
    if (!event.hasBlock()) return;

    Action action = event.getAction();
    Player player = event.getPlayer();
    Block block = event.getClickedBlock();
    int type = block.getTypeId();
    BlockFace face = event.getBlockFace();

    if (action == Action.RIGHT_CLICK_BLOCK) {
      if (Lockette.protectTrapDoors)
        if (type == Material.TRAP_DOOR.getId()) {
          if (interactDoor(block, player)) return;

          event.setUseInteractedBlock(Result.DENY);
          event.setUseItemInHand(Result.DENY);
          return;
        }

      if (Lockette.protectDoors)
        if ((type == Material.WOODEN_DOOR.getId())
            || (type == Material.IRON_DOOR_BLOCK.getId())
            || (type == materialFenceGate)) {
          if (interactDoor(block, player)) return;

          event.setUseInteractedBlock(Result.DENY);
          event.setUseItemInHand(Result.DENY);
          return;
        }

      if (type == Material.WALL_SIGN.getId()) {
        interactSign(block, player);
        return;
      }

      if (type == Material.CHEST.getId()) {
        // Try at making a 1.7->1.8 chest fixer.
        Lockette.rotateChestOrientation(block, face);
      }

      if ((type == Material.CHEST.getId())
          || (type == Material.DISPENSER.getId())
          || (type == Material.FURNACE.getId())
          || (type == Material.BURNING_FURNACE.getId())
          || (type == Material.BREWING_STAND.getId())
          || Lockette.isInList(type, Lockette.customBlockList)) {

        // Trying something out....
        if (Lockette.directPlacement)
          if (event.hasItem())
            if ((face != BlockFace.UP) && (face != BlockFace.DOWN)) {
              ItemStack item = event.getItem();

              if (item.getTypeId() == Material.SIGN.getId()) {
                Block checkBlock = block.getRelative(face);

                type = checkBlock.getTypeId();

                if (type == Material.AIR.getId()) {
                  boolean place = false;

                  if (Lockette.isProtected(block)) {
                    // Add a users sign only if owner.
                    if (Lockette.isOwner(block, player.getName())) place = true;
                  } else place = true;
                  // if(Lockette.altPrivate == null){}//if(Lockette.altMoreUsers == null){}
                  if (place) {
                    // player.sendMessage(ChatColor.RED + "Lockette: Using a sign on a container");

                    event.setUseItemInHand(Result.ALLOW); // ? seems to work in 568
                    event.setUseInteractedBlock(Result.DENY);
                    return;
                  }
                }
              }
            }

        if (interactContainer(block, player)) return;

        event.setUseInteractedBlock(Result.DENY);
        event.setUseItemInHand(Result.DENY);
        return;
      }

      if (type == Material.DIRT.getId())
        if (event.hasItem()) {
          ItemStack item = event.getItem();

          type = item.getTypeId();

          if ((type == Material.DIAMOND_HOE.getId())
              || (type == Material.GOLD_HOE.getId())
              || (type == Material.IRON_HOE.getId())
              || (type == Material.STONE_HOE.getId())
              || (type == Material.WOOD_HOE.getId())) {
            Block checkBlock = block.getRelative(BlockFace.UP);

            type = checkBlock.getTypeId();

            if ((type == Material.WOODEN_DOOR.getId())
                || (type == Material.IRON_DOOR_BLOCK.getId())
                || (type == materialFenceGate)) {
              event.setUseInteractedBlock(Result.DENY);
              return;
            }
          }
        }
    } else if (action == Action.LEFT_CLICK_BLOCK) {
      if (Lockette.protectTrapDoors)
        if (type == Material.TRAP_DOOR.getId()) {
          if (interactDoor(block, player)) return;

          event.setUseInteractedBlock(Result.DENY);
          event.setUseItemInHand(Result.DENY);
          return;
        }

      if (Lockette.protectDoors)
        if ((type == Material.WOODEN_DOOR.getId())
            || (type == Material.IRON_DOOR_BLOCK.getId())
            || (type == materialFenceGate)) {
          if (interactDoor(block, player)) return;

          event.setUseInteractedBlock(Result.DENY);
          event.setUseItemInHand(Result.DENY);
          return;
        }
    }
  }
예제 #4
0
  @SuppressWarnings("deprecation")
  @EventHandler(priority = EventPriority.LOWEST)
  public void onPlayerInteract(PlayerInteractEvent event) {
    // ignore stepping onto or into a block
    if (event.getAction() == Action.PHYSICAL) {
      return;
    }

    final Player player = event.getPlayer();
    Block block = event.getClickedBlock();

    ItemStack item = event.getItem();
    if (item == null) {
      item = player.getItemInHand();
    }

    // ignore all vanilla items and edible items in vanilla blocks actions
    if (block != null
        && (item.getData().getItemType().isEdible() || isVanilla(item.getType()))
        && isVanilla(block.getType())) {
      return;
    }

    // whitelisted item check
    if (this.instance.config.matchWhitelistItem(
            item.getType(), item.getData().getData(), player.getWorld().getName())
        != null) {
      return;
    }

    // special aoe items list (needs to check a wide area...)
    ListedRangedItem rangeItem =
        this.instance.config.matchAoEItem(
            item.getType(), item.getData().getData(), player.getWorld().getName());
    if (rangeItem != null) {
      // check players location
      for (ProtectionHandler protection : ProtectionPlugins.getHandlers()) {
        if (!protection.canUseAoE(player, player.getLocation(), rangeItem.range)) {
          event.setUseInteractedBlock(Result.DENY);
          event.setUseItemInHand(Result.DENY);
          event.setCancelled(true);
          this.confiscateInventory(player);
          return;
        }
      }
      return;
    }

    if (block == null) {
      // check if the item in hand is a ranged item
      rangeItem =
          this.instance.config.matchRangedItem(
              item.getType(), item.getData().getData(), player.getWorld().getName());
      if (rangeItem != null) {
        block = getTargetBlock(player, rangeItem.range);
      }
    }

    Location targetLocation;
    if (block == null) {
      targetLocation = player.getLocation();
    } else {
      targetLocation = block.getLocation();
    }

    // check permissions on that location
    for (ProtectionHandler protection : ProtectionPlugins.getHandlers()) {
      if (!protection.canInteract(player, targetLocation)) {
        event.setUseInteractedBlock(Result.DENY);
        event.setUseItemInHand(Result.DENY);
        event.setCancelled(true);
        this.confiscateInventory(player);
        return;
      }
    }
  }
 @EventHandler
 public void onPlayerInteract(PlayerInteractEvent event) {
   if (event.getAction() == Action.RIGHT_CLICK_AIR && Editor.hasEditor(event.getPlayer()))
     event.setUseItemInHand(Result.DENY);
 }