Java 类org.bukkit.entity.LeashHitch 实例源码

项目:Skellett    文件:EffLeashBlock.java   
@Override
protected void execute(Event e) {
    Entity hitch = null;
    if (block.getSingle(e) == null) return;
    if (block.getSingle(e).getType() != Material.FENCE) {
        Material type = block.getSingle(e).getType();
        block.getSingle(e).setType(Material.FENCE);
        hitch = block.getSingle(e).getLocation().getWorld().spawn(block.getSingle(e).getLocation(), LeashHitch.class);
        block.getSingle(e).setType(type);
    } else {
        hitch = block.getSingle(e).getLocation().getWorld().spawn(block.getSingle(e).getLocation(), LeashHitch.class);
    }
    if (hitch != null && entities.getAll(e) != null ) {
        for (LivingEntity entity : entities.getAll(e)) {
            entity.setLeashHolder(hitch);
        }
    }
}
项目:beaconz    文件:BeaconProtectionListener.java   
/**
 * Protects animals on a beacon from damage
 * @param event
 */
@EventHandler(priority = EventPriority.LOW, ignoreCancelled = true)
public void onEntityDamage(final EntityDamageEvent event) {
    World world = event.getEntity().getWorld();
    if (!world.equals(getBeaconzWorld())) {
        return;
    }
    //getLogger().info("DEBUG: " + event.getEntityType());
    if (!(event.getEntity() instanceof Animals || event.getEntity() instanceof LeashHitch)) {
        return;
    }
    // Check beacon defense            
    BeaconObj beacon = getRegister().getBeaconAt(event.getEntity().getLocation());
    if (beacon != null) {                
        event.setCancelled(true);
    }
}
项目:NovaGuilds    文件:RegionInteractListener.java   
/**
 * Handles breaking paintings, item frames, leashes
 *
 * @param event The event
 */
@EventHandler
public void onHangingEntityBreak(HangingBreakByEntityEvent event) {
    if(!(event.getRemover() instanceof Player)) {
        return;
    }

    Player player = (Player) event.getRemover();
    NovaPlayer nPlayer = PlayerManager.getPlayer(player);
    boolean isLeash = event.getEntity() instanceof LeashHitch;

    if(RegionManager.get(event.getEntity()) != null
            && (!plugin.getRegionManager().canInteract(player, event.getEntity()) || (!nPlayer.getPreferences().getBypass() && !nPlayer.hasPermission(isLeash ? GuildPermission.MOB_LEASH : GuildPermission.BLOCK_BREAK)))) {
        event.setCancelled(true);
        (isLeash ? Message.CHAT_REGION_DENY_UNLEASH : Message.CHAT_REGION_DENY_INTERACT).send(player);
    }
}
项目:NucleusFramework    文件:LeashUtils.java   
/**
 * Get the {@link org.bukkit.entity.LeashHitch} of a leashed entity.
 *
 * @param entity  The {@link org.bukkit.entity.Entity} to check.
 *
 * @return  The {@link org.bukkit.entity.LeashHitch} or null if the entity
 * is not leashed or is leashed to a player.
 */
@Nullable
public static LeashHitch getHitch(Entity entity) {
    PreCon.notNull(entity);

    if (!(entity instanceof LivingEntity))
        return null;

    LivingEntity living = (LivingEntity) entity;

    if (!living.isLeashed())
        return null;

    Entity leash = living.getLeashHolder();

    if (leash instanceof LeashHitch)
        return (LeashHitch) leash;

    return null;
}
项目:ProjectAres    文件:EventRuleMatchModule.java   
private static Material getHangingType(Hanging hanging) {
    if(hanging instanceof Painting) {
        return Material.PAINTING;
    } else if(hanging instanceof ItemFrame) {
        return Material.ITEM_FRAME;
    } else if(hanging instanceof LeashHitch) {
        return Material.LEASH;
    } else {
        return null;
    }
}
项目:PlotMe-Core    文件:SchematicUtil.java   
private org.bukkit.entity.Entity getLeash(IWorld world1, Leash leash, com.worldcretornica.plotme_core.api.Vector loc, int originX, int originY,
        int originZ) {
    org.bukkit.entity.Entity ent = null;
    World world = ((BukkitWorld) world1).getWorld();

    int x = leash.getX() - originX;
    int y = leash.getY() - originY;
    int z = leash.getZ() - originZ;

    org.bukkit.Location etloc = new org.bukkit.Location(world, x + loc.getBlockX(), y + loc.getBlockY(), z + loc.getBlockZ());

    Block block = world.getBlockAt(etloc);

    if (block.getType() == Material.FENCE || block.getType() == Material.NETHER_FENCE) {
        etloc.setX(Math.floor(etloc.getX()));
        etloc.setY(Math.floor(etloc.getY()));
        etloc.setZ(Math.floor(etloc.getZ()));

        ent = world.spawnEntity(etloc, EntityType.LEASH_HITCH);

        List<org.bukkit.entity.Entity> nearbyentities = ent.getNearbyEntities(1, 1, 1);

        for (org.bukkit.entity.Entity nearby : nearbyentities) {
            if (nearby instanceof LeashHitch) {
                if (nearby.getLocation().distance(ent.getLocation()) == 0) {
                    ent.remove();
                    return nearby;
                }
            }
        }
    }

    return ent;
}