@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();
    }
  }
  @EventHandler
  public void onBlockPlaceEvent(BlockPlaceEvent event) {
    if (!isEnabled()) return;

    if (event.isCancelled()) return;
    try {

      BlockType type = BlockType.Unknown;
      Player player = event.getPlayer();
      Block block = event.getBlock();

      if (event.getBlock().getTypeId() == 0) {
        ForgePermittor.log("tile: " + getValidator().CheckItem(event.getItemInHand()), true);
        if (getValidator().CheckItem(event.getItemInHand()) == ItemType.Container)
          type = BlockType.Container;
      } else {
        ForgePermittor.log("tile: " + getValidator().CheckBlock(event.getBlock()), true);
        type = getValidator().CheckBlock(event.getBlock());
      }

      if (type == BlockType.Container) {
        if (CheckBlockPlaceforContainer(player, block.getRelative(BlockFace.NORTH))
            || CheckBlockPlaceforContainer(player, block.getRelative(BlockFace.SOUTH))
            || CheckBlockPlaceforContainer(player, block.getRelative(BlockFace.WEST))
            || CheckBlockPlaceforContainer(player, block.getRelative(BlockFace.EAST))) {
          event.setCancelled(true);
        }
      }
    } catch (Exception e) {
      ForgePermittor.log(e.toString(), true);
    }
  }
Exemplo n.º 3
0
 public ItemType CheckItem(ItemStack stack)
     throws InvocationTargetException, IllegalAccessException {
   int ItemID = stack.getTypeId();
   byte meta = stack.getData().getData();
   Object item = nmsResolver.getItemList().get(ItemID);
   ForgePermittor.log(item.toString(), true);
   if (item != null) {
     /*  if (this.getInformationManager().HasConnectableInferface(item))
     return ItemType.Connectable;*/
     if (this.getInformationManager().HasItemBlockContainerInterface(item))
       return ItemType.Container;
     if (this.getInformationManager().HasFoodInterface(item)) return ItemType.Food;
     if (this.getInformationManager().HasSwordInterface(item)) return ItemType.Weapon;
     if (this.getInformationManager().HasItemBlockInterface(item))
       return CheckItemBlock(item, ItemID, meta);
     if (this.getInformationManager().HasItemInterface(item)) {
       if (nmsResolver
           .getItemStackHandler()
           .HasTagCompound(nmsResolver.getCraftItemStackHandler().asNMSCopy(stack)))
         return ItemType.AdvItem;
       return ItemType.Item;
     }
   }
   return ItemType.Unknown;
 }
  private boolean CheckBlockPlaceforContainer(Player player, Block block) {
    try {
      if (block.getTypeId() != 0 && getValidator().CheckBlock(block) == BlockType.Container)
        if (!getProtectionManager().CanBreakBlock(player, block)) return true;

    } catch (Exception e) {
      ForgePermittor.log(Util.stackTraceToString(e), true);
    }
    return false;
  }
Exemplo n.º 5
0
 public BlockType CheckBlock(Block block)
     throws InvocationTargetException, IllegalAccessException {
   if (block.getTypeId() < 4096 && block.getTypeId() != 0) {
     Object object = nmsResolver.getBlockList().get(block.getTypeId());
     ForgePermittor.log(object.getClass().toString(), true);
     // todo Test if this doesn't break something
     if (
     /*this.getInformationManager().HasContainerInterface(object) || */ nmsResolver
         .getCraftWorldHandler()
         .HasTileEntity(block))
       if (this.getInformationManager()
           .HasTradeBlockInterface(nmsResolver.getCraftWorldHandler().getTileEntityFrom(block)))
         return BlockType.Trade;
       else return BlockType.Container; // CheckConnectable(block);
     if (this.getInformationManager().HasBlockInterface(object)) return BlockType.Block;
   }
   return BlockType.Unknown;
 }