EventSimulator.java 文件源码

java
阅读 47 收藏 0 点赞 0 评论 0

项目:StarQuestCode 作者:
/**
    * Function for a moving machina to test whether it's allowed to move to a
    * new location by protection plugins. Returns true if the player could
    * build (and break) the new block.
    * 
    * This function will fire a blockplace event, collect the cancelled result
    * at the highest possible priority, then cancel its own event to prevent it
    * from being logged by any monitoring plugins.
    * 
    * @param target
    *            The target location to place at
    * @param typeId
    *            The typeId of the block to place
    * @param placedAgainst
    *            The block that it will be placed against
    * @param player
    *            The player to simulate for
    * @return True if the player may place a block at the location
    */
   @SuppressWarnings("deprecation")
public static boolean blockPlacePretend(BlockLocation target, int typeId, BlockLocation placedAgainst, Player player) {
       Block placedBlock = target.getBlock();
       BlockState replacedBlockState = placedBlock.getState();
       int oldType = replacedBlockState.getTypeId();
       byte oldData = replacedBlockState.getRawData();

       // Set the new state without physics.
       placedBlock.setTypeIdAndData(typeId, (byte) 0, false);

       pretendEvent = new ArtificialBlockPlaceEvent(placedBlock, replacedBlockState, placedAgainst.getBlock(), new ItemStack(Material.AIR), player, true, EquipmentSlot.HAND);
       pretendEventCancelled = true;
       MachinaCore.pluginManager.callEvent(pretendEvent);

       // Revert to the old state without physics.
       placedBlock.setTypeIdAndData(oldType, oldData, false);

       return !pretendEventCancelled;
   }
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号