当前位置: 首页>>代码示例>>Java>>正文


Java EntityBlockChangeEvent类代码示例

本文整理汇总了Java中cn.nukkit.event.entity.EntityBlockChangeEvent的典型用法代码示例。如果您正苦于以下问题:Java EntityBlockChangeEvent类的具体用法?Java EntityBlockChangeEvent怎么用?Java EntityBlockChangeEvent使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


EntityBlockChangeEvent类属于cn.nukkit.event.entity包,在下文中一共展示了EntityBlockChangeEvent类的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: onEntityFall

import cn.nukkit.event.entity.EntityBlockChangeEvent; //导入依赖的package包/类
@EventHandler(ignoreCancelled = true, priority = EventPriority.HIGHEST)
public void onEntityFall(EntityBlockChangeEvent event) {
    Entity entity = event.getEntity();
    Location location = NukkitUtil.getLocation(entity);
    if (!PS.get().hasPlotArea(location.getWorld())) {
        return;
    }
    PlotArea area = location.getPlotArea();
    if (area == null) {
        return;
    }
    Block from = event.getFrom();
    Block to = event.getTo();
    final Plot finalPlot = area.getOwnedPlotAbs(location);
    boolean toBlock = from == null || from.getId() == 0;
    if (toBlock) {
        List<MetadataValue> meta = entity.getMetadata("plot");
        if (meta.isEmpty()) {
            return;
        }
        Plot origin = (Plot) meta.get(0).value();
        if (origin != null && !origin.equals(finalPlot)) {
            kill(entity, event);
        }
    } else {
        entity.setMetadata("plot", new MetadataValue((Plugin) PS.get().IMP) {
            private Plot plot = finalPlot;
            @Override
            public Object value() {
                return plot;
            }
            @Override
            public void invalidate() {
                plot = null;
            }
        });
    }
}
 
开发者ID:IntellectualSites,项目名称:PlotSquared,代码行数:39,代码来源:PlayerEvents.java

示例2: onUpdate

import cn.nukkit.event.entity.EntityBlockChangeEvent; //导入依赖的package包/类
@Override
public boolean onUpdate(int currentTick) {

    if (closed) {
        return false;
    }

    this.timing.startTiming();

    int tickDiff = currentTick - lastUpdate;
    if (tickDiff <= 0 && !justCreated) {
        return true;
    }

    lastUpdate = currentTick;

    boolean hasUpdate = entityBaseTick(tickDiff);

    if (isAlive()) {
        motionY -= getGravity();

        move(motionX, motionY, motionZ);

        float friction = 1 - getDrag();

        motionX *= friction;
        motionY *= 1 - getDrag();
        motionZ *= friction;

        Vector3 pos = (new Vector3(x - 0.5, y, z - 0.5)).round();

        if (onGround) {
            kill();
            Block block = level.getBlock(pos);
            if (block.getId() > 0 && block.isTransparent() && !block.canBeReplaced()) {
                if (this.level.getGameRules().getBoolean("doEntityDrops")) {
                    getLevel().dropItem(this, Item.get(this.getBlock(), this.getDamage(), 1));
                }
            } else {
                EntityBlockChangeEvent event = new EntityBlockChangeEvent(this, block, Block.get(getBlock(), getDamage()));
                server.getPluginManager().callEvent(event);
                if (!event.isCancelled()) {
                    getLevel().setBlock(pos, event.getTo(), true);

                    if (event.getTo().getId() == Item.ANVIL) {
                        getLevel().addSound(new AnvilFallSound(pos));
                    }
                }
            }
            hasUpdate = true;
        }

        updateMovement();
    }

    this.timing.stopTiming();

    return hasUpdate || !onGround || Math.abs(motionX) > 0.00001 || Math.abs(motionY) > 0.00001 || Math.abs(motionZ) > 0.00001;
}
 
开发者ID:Rsplwe,项目名称:Nukkit-Java9,代码行数:60,代码来源:EntityFallingBlock.java


注:本文中的cn.nukkit.event.entity.EntityBlockChangeEvent类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。