Java Code Examples for org.bukkit.block.Block#getX()

The following examples show how to use org.bukkit.block.Block#getX() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: HillObjective.java    From CardinalPGM with MIT License 6 votes vote down vote up
private void renderBlocks() {
    if (progress == null) return;
    byte color1 = capturingTeam != null ? MiscUtil.convertChatColorToDyeColor(capturingTeam.getColor()).getWoolData() : -1;
    byte color2 = team != null ? MiscUtil.convertChatColorToDyeColor(team.getColor()).getWoolData() : -1;
    Vector center = progress.getCenterBlock().getVector();
    double x = center.getX();
    double z = center.getZ();
    double percent = Math.toRadians(getPercent() * 3.6);
    for(Block block : progress.getBlocks()) {
        if (!visualMaterials.evaluate(block).equals(FilterState.ALLOW)) continue;
        double dx = block.getX() - x;
        double dz = block.getZ() - z;
        double angle = Math.atan2(dz, dx);
        if(angle < 0) angle += 2 * Math.PI;
        byte color = angle < percent ? color1 : color2;
        if (color == -1) {
            Pair<Material,Byte> oldBlock = oldProgress.getBlockAt(new BlockVector(block.getLocation().position()));
            if (oldBlock.getLeft().equals(block.getType())) color = oldBlock.getRight();
        }
        if (color != -1) block.setData(color);
    }
}
 
Example 2
Source File: GroupSign.java    From DungeonsXL with GNU General Public License v3.0 6 votes vote down vote up
/**
 * @param plugin the plugin instance
 * @param block  a block which is protected by the returned GroupSign
 * @return the group sign the block belongs to, null if it belongs to none
 */
public static GroupSign getByBlock(DungeonsXL plugin, Block block) {
    if (!Category.SIGNS.containsBlock(block)) {
        return null;
    }

    for (GlobalProtection protection : plugin.getGlobalProtectionCache().getProtections(GroupSign.class)) {
        GroupSign groupSign = (GroupSign) protection;
        Block start = groupSign.startSign;
        if (start == block || (start.getX() == block.getX() && start.getZ() == block.getZ() && (start.getY() >= block.getY() && start.getY() - groupSign.verticalSigns <= block.getY()))) {
            return groupSign;
        }
    }

    return null;
}
 
Example 3
Source File: CustomProjectileEntity.java    From Thermos with GNU General Public License v3.0 6 votes vote down vote up
@Override
public LivingEntity _INVALID_getShooter() {
    if (shooter instanceof LivingEntity) { return (LivingEntity)shooter; }
    if (shooter instanceof BlockProjectileSource)
    {
        Block block = ((BlockProjectileSource)shooter).getBlock();
        if(!(block.getWorld() instanceof WorldServer))return null;
        int x = block.getX(), y = block.getY(), z = block.getZ();
        WorldServer ws = (WorldServer)block.getWorld();
        EntityPlayerMP fake_dropper = new EntityPlayerMP(MinecraftServer.getServer(), ws, dropper, new ItemInWorldManager(MinecraftServer.getServer().worldServerForDimension(0)));
        fake_dropper.posX = x; fake_dropper.posY = y; fake_dropper.posZ = z;
        CraftEntity ce = org.bukkit.craftbukkit.entity.CraftEntity.getEntity(MinecraftServer.getServer().server, fake_dropper);
        if(ce instanceof LivingEntity) return (LivingEntity)ce;
        return null;
    } return null;
}
 
Example 4
Source File: CraftBlockState.java    From Thermos with GNU General Public License v3.0 6 votes vote down vote up
public CraftBlockState(final Block block) {
    this.world = (CraftWorld) block.getWorld();
    this.x = block.getX();
    this.y = block.getY();
    this.z = block.getZ();
    this.type = block.getTypeId();
    this.light = block.getLightLevel();
    this.chunk = (CraftChunk) block.getChunk();
    this.flag = 3;
    // Cauldron start - save TE data
    TileEntity te = world.getHandle().getTileEntity(x, y, z);
    if (te != null)
    {
        nbt = new NBTTagCompound();
        te.writeToNBT(nbt);
    }
    else nbt = null;
    // Cauldron end

    createData(block.getData());
}
 
Example 5
Source File: HologramProjector.java    From Slimefun4 with GNU General Public License v3.0 6 votes vote down vote up
private static ArmorStand getArmorStand(Block projector, boolean createIfNoneExists) {
    String nametag = BlockStorage.getLocationInfo(projector.getLocation(), "text");
    double offset = Double.parseDouble(BlockStorage.getLocationInfo(projector.getLocation(), "offset"));
    Location l = new Location(projector.getWorld(), projector.getX() + 0.5, projector.getY() + offset, projector.getZ() + 0.5);

    for (Entity n : l.getChunk().getEntities()) {
        if (n instanceof ArmorStand && n.getCustomName() != null && n.getCustomName().equals(nametag) && l.distanceSquared(n.getLocation()) < 0.4D) {
            return (ArmorStand) n;
        }
    }

    if (!createIfNoneExists) {
        return null;
    }

    ArmorStand hologram = SimpleHologram.create(l);
    hologram.setCustomName(nametag);
    return hologram;
}
 
Example 6
Source File: NMSHandler.java    From askyblock with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void setBlockSuperFast(Block b, int blockId, byte data, boolean applyPhysics) {
    net.minecraft.server.v1_12_R1.World w = ((CraftWorld) b.getWorld()).getHandle();
    net.minecraft.server.v1_12_R1.Chunk chunk = w.getChunkAt(b.getX() >> 4, b.getZ() >> 4);
    BlockPosition bp = new BlockPosition(b.getX(), b.getY(), b.getZ());
    int combined = blockId + (data << 12);
    IBlockData ibd = net.minecraft.server.v1_12_R1.Block.getByCombinedId(combined);
    if (applyPhysics) {
        w.setTypeAndData(bp, ibd, 3); 
    } else {
        w.setTypeAndData(bp, ibd, 2); 
    }
    chunk.a(bp, ibd);
}
 
Example 7
Source File: NMSImpl.java    From TabooLib with MIT License 5 votes vote down vote up
@Override
public void recalculate(Block block, Type lightType) {
    Object world = ((CraftWorld) block.getWorld()).getHandle();
    Object position = new net.minecraft.server.v1_15_R1.BlockPosition(block.getX(), block.getY(), block.getZ());
    if (is11400) {
        Object lightEngine = ((net.minecraft.server.v1_14_R1.WorldServer) world).getChunkProvider().getLightEngine();
        if (((net.minecraft.server.v1_14_R1.LightEngineThreaded) lightEngine).a()) {
            sync(lightEngine, e -> {
                Object[] lightEngineLayers;
                if (lightType == Type.BLOCK) {
                    ((LightEngineLayer) ((net.minecraft.server.v1_14_R1.LightEngineThreaded) lightEngine).a(net.minecraft.server.v1_14_R1.EnumSkyBlock.BLOCK)).a(Integer.MAX_VALUE, true, true);
                } else if (lightType == Type.SKY) {
                    ((LightEngineLayer) ((net.minecraft.server.v1_14_R1.LightEngineThreaded) lightEngine).a(net.minecraft.server.v1_14_R1.EnumSkyBlock.SKY)).a(Integer.MAX_VALUE, true, true);
                } else {
                    Object b = ((net.minecraft.server.v1_14_R1.LightEngineThreaded) lightEngine).a(net.minecraft.server.v1_14_R1.EnumSkyBlock.BLOCK);
                    Object s = ((net.minecraft.server.v1_14_R1.LightEngineThreaded) lightEngine).a(net.minecraft.server.v1_14_R1.EnumSkyBlock.SKY);
                    int maxUpdateCount = Integer.MAX_VALUE;
                    int integer4 = maxUpdateCount / 2;
                    int integer5 = ((LightEngineLayer) b).a(integer4, true, true);
                    int integer6 = maxUpdateCount - integer4 + integer5;
                    int integer7 = ((LightEngineLayer) s).a(integer6, true, true);
                    if (integer5 == 0 && integer7 > 0) {
                        ((LightEngineLayer) b).a(integer7, true, true);
                    }
                }
            });
        }
    } else {
        if (lightType == Type.SKY) {
            ((net.minecraft.server.v1_13_R2.WorldServer) world).c(net.minecraft.server.v1_13_R2.EnumSkyBlock.SKY, (net.minecraft.server.v1_13_R2.BlockPosition) position);
        } else if (lightType == Type.BLOCK) {
            ((net.minecraft.server.v1_13_R2.WorldServer) world).c(net.minecraft.server.v1_13_R2.EnumSkyBlock.BLOCK, (net.minecraft.server.v1_13_R2.BlockPosition) position);
        } else {
            ((net.minecraft.server.v1_13_R2.WorldServer) world).c(net.minecraft.server.v1_13_R2.EnumSkyBlock.SKY, (net.minecraft.server.v1_13_R2.BlockPosition) position);
            ((net.minecraft.server.v1_13_R2.WorldServer) world).c(net.minecraft.server.v1_13_R2.EnumSkyBlock.BLOCK, (net.minecraft.server.v1_13_R2.BlockPosition) position);
        }
    }
}
 
Example 8
Source File: CraftHanging.java    From Thermos with GNU General Public License v3.0 5 votes vote down vote up
public boolean setFacingDirection(BlockFace face, boolean force) {
    Block block = getLocation().getBlock().getRelative(getAttachedFace()).getRelative(face.getOppositeFace()).getRelative(getFacing());
    net.minecraft.entity.EntityHanging hanging = getHandle();
    int x = hanging.field_146063_b, y = hanging.field_146064_c, z = hanging.field_146062_d, dir = hanging.hangingDirection;
    hanging.field_146063_b = block.getX();
    hanging.field_146064_c = block.getY();
    hanging.field_146062_d = block.getZ();
    switch (face) {
        case SOUTH:
        default:
            getHandle().setDirection(0);
            break;
        case WEST:
            getHandle().setDirection(1);
            break;
        case NORTH:
            getHandle().setDirection(2);
            break;
        case EAST:
            getHandle().setDirection(3);
            break;
    }
    if (!force && !hanging.onValidSurface()) {
        // Revert since it doesn't fit
        hanging.field_146063_b = x;
        hanging.field_146064_c = y;
        hanging.field_146062_d = z;
        hanging.setDirection(dir);
        return false;
    }
    return true;
}
 
Example 9
Source File: JoinSign.java    From DungeonsXL with GNU General Public License v3.0 5 votes vote down vote up
protected static void onCreation(DungeonsXL plugin, Block startSign, String identifier, int maxElements, int startIfElementsAtLeast) {
    World world = startSign.getWorld();
    BlockFace facing = DungeonsXL.BLOCK_ADAPTER.getFacing(startSign);
    int x = startSign.getX(), y = startSign.getY(), z = startSign.getZ();

    int verticalSigns = (int) Math.ceil((float) (1 + maxElements) / 4);
    while (verticalSigns > 1) {
        Block block = world.getBlockAt(x, y - verticalSigns + 1, z);
        block.setType(startSign.getType(), false);
        DungeonsXL.BLOCK_ADAPTER.setFacing(block, facing);
        verticalSigns--;
    }

    LWCUtil.removeProtection(startSign);
}
 
Example 10
Source File: NMSHandler.java    From askyblock with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void setBlockSuperFast(Block b, int blockId, byte data, boolean applyPhysics) {
    net.minecraft.server.v1_9_R2.World w = ((CraftWorld) b.getWorld()).getHandle();
    net.minecraft.server.v1_9_R2.Chunk chunk = w.getChunkAt(b.getX() >> 4, b.getZ() >> 4);
    BlockPosition bp = new BlockPosition(b.getX(), b.getY(), b.getZ());
    int combined = blockId + (data << 12);
    IBlockData ibd = net.minecraft.server.v1_9_R2.Block.getByCombinedId(combined);
    if (applyPhysics) {
        w.setTypeAndData(bp, ibd, 3); 
    } else {
        w.setTypeAndData(bp, ibd, 2); 
    }
    chunk.a(bp, ibd);
}
 
Example 11
Source File: ChunkListener.java    From FastAsyncWorldedit with GNU General Public License v3.0 5 votes vote down vote up
@EventHandler(priority = EventPriority.LOWEST)
public void onBlockChange(EntityChangeBlockEvent event) {
    if (physicsFreeze) {
        event.setCancelled(true);
        return;
    }
    Block block = event.getBlock();
    int x = block.getX();
    int z = block.getZ();
    int cx = x >> 4;
    int cz = z >> 4;
    int[] count = getCount(cx, cz);
    if (count[1] >= Settings.IMP.TICK_LIMITER.FALLING) {
        event.setCancelled(true);
        return;
    }
    if (event.getEntityType() == EntityType.FALLING_BLOCK) {
        if (++count[1] >= Settings.IMP.TICK_LIMITER.FALLING) {

            // Only cancel falling blocks when it's lagging
            if (Fawe.get().getTimer().getTPS() < 18) {
                cancelNearby(cx, cz);
                if (rateLimit <= 0) {
                    rateLimit = 20;
                    Fawe.debug("[FAWE `tick-limiter`] Detected and cancelled falling block lag source at " + block.getLocation());
                }
                event.setCancelled(true);
                return;
            } else {
                count[1] = 0;
            }
        }
    }
}
 
Example 12
Source File: SimpleHologram.java    From Slimefun4 with GNU General Public License v3.0 5 votes vote down vote up
private static ArmorStand getArmorStand(Block b, boolean createIfNoneExists) {
    Location l = new Location(b.getWorld(), b.getX() + 0.5, b.getY() + 0.7F, b.getZ() + 0.5);

    for (Entity n : l.getChunk().getEntities()) {
        if (n instanceof ArmorStand && n.getCustomName() != null && l.distanceSquared(n.getLocation()) < 0.4D) {
            return (ArmorStand) n;
        }
    }

    if (!createIfNoneExists) return null;
    else return create(l);
}
 
Example 13
Source File: ContainerManager.java    From RedProtect with GNU General Public License v3.0 4 votes vote down vote up
public boolean canOpen(Block b, Player p) {
    if (!RedProtect.get().config.configRoot().private_cat.use || p.hasPermission("redprotect.bypass")) {
        return true;
    }

    String blocktype = b.getType().name();
    List<String> blocks = RedProtect.get().config.configRoot().private_cat.allowed_blocks;

    boolean deny = true;
    if (blocks.stream().anyMatch(blocktype::matches)) {
        int x = b.getX();
        int y = b.getY();
        int z = b.getZ();
        World w = p.getWorld();

        for (int sx = -1; sx <= 1; sx++) {
            for (int sz = -1; sz <= 1; sz++) {
                Block bs = w.getBlockAt(x + sx, y, z + sz);
                if (isSign(bs) && (validatePrivateSign(bs))) {
                    deny = false;
                    if (validateOpenBlock(bs, p)) {
                        return true;
                    }
                }

                int x2 = bs.getX();
                int y2 = bs.getY();
                int z2 = bs.getZ();

                String blocktype2 = b.getType().name();
                if (blocks.stream().anyMatch(blocktype2::matches)) {
                    for (int ux = -1; ux <= 1; ux++) {
                        for (int uz = -1; uz <= 1; uz++) {
                            Block bu = w.getBlockAt(x2 + ux, y2, z2 + uz);
                            if (isSign(bu) && (validatePrivateSign(bu))) {
                                deny = false;
                                if (validateOpenBlock(bu, p)) {
                                    return true;
                                }
                            }
                        }
                    }
                }
            }
        }
    }
    return deny;
}
 
Example 14
Source File: Wall.java    From civcraft with GNU General Public License v2.0 4 votes vote down vote up
private void validateBlockLocation(Player player, Location loc) throws CivException {
	Block b = loc.getBlock();
	
	if (ItemManager.getId(b) == CivData.CHEST) {
		throw new CivException("Cannot build here, would destroy chest.");
	}
						
	TownChunk tc = CivGlobal.getTownChunk(b.getLocation());
		
	if (tc != null && !tc.perms.hasPermission(PlotPermissions.Type.DESTROY, CivGlobal.getResident(player))) {
		// Make sure we have permission to destroy any block in this area.
		throw new CivException("Cannot build here, you need DESTROY permissions to the block at "+b.getX()+","+b.getY()+","+b.getZ());
	}

	BlockCoord coord = new BlockCoord(b);
	//not building a trade outpost, prevent protected blocks from being destroyed.
	if (CivGlobal.getProtectedBlock(coord) != null) {
		throw new CivException("Cannot build here, protected blocks in the way.");
	}

	
	if (CivGlobal.getStructureBlock(coord) != null) {
		throw new CivException("Cannot build here, structure blocks in the way at "+coord);
	}
	

	if (CivGlobal.getFarmChunk(new ChunkCoord(coord.getLocation())) != null) {
		throw new CivException("Cannot build here, in the same chunk as a farm improvement.");
	}
	
	if (loc.getBlockY() >= Wall.MAX_HEIGHT) {
		throw new CivException("Cannot build here, wall is too high.");
	}
	
	if (loc.getBlockY() <= 1) {
		throw new CivException("Cannot build here, too close to bedrock.");
	}
	
	BlockCoord bcoord = new BlockCoord(loc);
	for (int y = 0; y < 256; y++) {
		bcoord.setY(y);
		StructureBlock sb = CivGlobal.getStructureBlock(bcoord);
		if (sb != null) {
			throw new CivException("Cannot build here, this wall segment overlaps with a structure block belonging to a "+sb.getOwner().getName()+" structure.");
		}
	}
	
}
 
Example 15
Source File: DPortal.java    From DungeonsXL with GNU General Public License v3.0 4 votes vote down vote up
/**
 * @param plugin the plugin instance
 * @param block  a block covered by the returned portal
 * @return the portal that the block belongs to, null if it belongs to none
 */
public static DPortal getByBlock(DungeonsXL plugin, Block block) {
    for (GlobalProtection protection : plugin.getGlobalProtectionCache().getProtections(DPortal.class)) {
        DPortal portal = (DPortal) protection;
        if (portal.getBlock1() == null || portal.getBlock2() == null) {
            continue;
        }

        int x1 = portal.block1.getX(), y1 = portal.block1.getY(), z1 = portal.block1.getZ();
        int x2 = portal.block2.getX(), y2 = portal.block2.getY(), z2 = portal.block2.getZ();
        int x3 = block.getX(), y3 = block.getY(), z3 = block.getZ();

        if (x1 > x2) {
            if (x3 < x2 || x3 > x1) {
                continue;
            }

        } else if (x3 > x2 || x3 < x1) {
            continue;
        }

        if (y1 > y2) {
            if (y3 < y2 || y3 > y1) {
                continue;
            }

        } else if (y3 > y2 || y3 < y1) {
            continue;
        }

        if (z1 > z2) {
            if (z3 < z2 || z3 > z1) {
                continue;
            }
        } else if (z3 > z2 || z3 < z1) {
            continue;
        }

        return portal;
    }

    return null;
}
 
Example 16
Source File: BlockPos.java    From factions-top with MIT License 4 votes vote down vote up
public static BlockPos of(Block block) {
    return new BlockPos(block.getWorld().getName(), block.getX(), block.getY(), block.getZ());
}
 
Example 17
Source File: ResourceManager.java    From Slimefun4 with GNU General Public License v3.0 4 votes vote down vote up
/**
 * This method will start a geo-scan at the given {@link Block} and display the result
 * of that scan to the given {@link Player}.
 * 
 * Note that scans are always per {@link Chunk}, not per {@link Block}, the {@link Block}
 * parameter only determines the {@link Location} that was clicked but it will still scan
 * the entire {@link Chunk}.
 * 
 * @param p
 *            The {@link Player} who requested these results
 * @param block
 *            The {@link Block} which the scan starts at
 * @param page
 *            The page to display
 */
public void scan(Player p, Block block, int page) {
    if (SlimefunPlugin.getGPSNetwork().getNetworkComplexity(p.getUniqueId()) < 600) {
        SlimefunPlugin.getLocalization().sendMessages(p, "gps.insufficient-complexity", true, msg -> msg.replace("%complexity%", "600"));
        return;
    }

    int x = block.getX() >> 4;
    int z = block.getZ() >> 4;

    ChestMenu menu = new ChestMenu("&4" + SlimefunPlugin.getLocalization().getResourceString(p, "tooltips.results"));

    for (int slot : backgroundSlots) {
        menu.addItem(slot, ChestMenuUtils.getBackground(), ChestMenuUtils.getEmptyClickHandler());
    }

    menu.addItem(4, new CustomItem(SlimefunUtils.getCustomHead(HeadTexture.MINECRAFT_CHUNK.getTexture()), ChatColor.YELLOW + SlimefunPlugin.getLocalization().getResourceString(p, "tooltips.chunk"), "", "&8\u21E8 &7" + SlimefunPlugin.getLocalization().getResourceString(p, "tooltips.world") + ": " + block.getWorld().getName(), "&8\u21E8 &7X: " + x + " Z: " + z), ChestMenuUtils.getEmptyClickHandler());
    List<GEOResource> resources = new ArrayList<>(SlimefunPlugin.getRegistry().getGEOResources().values());
    Collections.sort(resources, (a, b) -> a.getName(p).toLowerCase(Locale.ROOT).compareTo(b.getName(p).toLowerCase(Locale.ROOT)));

    int index = 10;
    int pages = (resources.size() - 1) / 36 + 1;

    for (int i = page * 28; i < resources.size() && i < (page + 1) * 28; i++) {
        GEOResource resource = resources.get(i);
        OptionalInt optional = getSupplies(resource, block.getWorld(), x, z);
        int supplies = optional.isPresent() ? optional.getAsInt() : generate(resource, block.getWorld(), x, z);
        String suffix = SlimefunPlugin.getLocalization().getResourceString(p, supplies == 1 ? "tooltips.unit" : "tooltips.units");

        ItemStack item = new CustomItem(resource.getItem(), "&f" + resource.getName(p), "&8\u21E8 &e" + supplies + ' ' + suffix);

        if (supplies > 1) {
            item.setAmount(supplies > item.getMaxStackSize() ? item.getMaxStackSize() : supplies);
        }

        menu.addItem(index, item, ChestMenuUtils.getEmptyClickHandler());
        index++;

        if (index % 9 == 8) {
            index += 2;
        }
    }

    menu.addItem(47, ChestMenuUtils.getPreviousButton(p, page + 1, pages));
    menu.addMenuClickHandler(47, (pl, slot, item, action) -> {
        if (page > 0) scan(pl, block, page - 1);
        return false;
    });

    menu.addItem(51, ChestMenuUtils.getNextButton(p, page + 1, pages));
    menu.addMenuClickHandler(51, (pl, slot, item, action) -> {
        if (page + 1 < pages) scan(pl, block, page + 1);
        return false;
    });

    menu.open(p);
}
 
Example 18
Source File: Util.java    From ObsidianDestroyer with GNU General Public License v3.0 4 votes vote down vote up
public static List<Location> getTargetsPathBlocked(Location tLoc, Location dLoc, boolean useOnlyMaterialListing, boolean ignoreFirstZone) {
    final ArrayList<Location> targetsInPath = new ArrayList<Location>();

    // check world
    if (!dLoc.getWorld().getName().equalsIgnoreCase(tLoc.getWorld().getName())) {
        return targetsInPath;
    }

    // if the distance is too close... the path is not blocked ;)
    if (dLoc.distance(tLoc) <= 0.9) {
        return targetsInPath;
    }

    // try to iterate through blocks between dLoc and tLoc
    try {
        // Create a vector block trace from the detonator location to damaged block's location
        final Location tarLoc = tLoc.clone().add(0, 0.25, 0);
        final BlockIterator blocksInPath = new BlockIterator(tarLoc.getWorld(), dLoc.toVector(), tarLoc.toVector().subtract(dLoc.toVector()).normalize(), 0.5, (int) dLoc.distance(tarLoc));

        // iterate through the blocks in the path
        int i = ConfigManager.getInstance().getRadius() + 1;
        int over = 0; // prevents rare case of infinite loop and server crash
        while (blocksInPath.hasNext() && over < 128) {
            if (i > 0) {
                i--;
            } else {
                break;
            }
            over++;

            // the next block
            final Block block = blocksInPath.next();
            if (block == null) {
                continue;
            }
            // check if next block is the target block
            if (tarLoc.getWorld().getName().equals(block.getWorld().getName()) &&
                    tarLoc.getBlockX() == block.getX() &&
                    tarLoc.getBlockY() == block.getY() &&
                    tarLoc.getBlockZ() == block.getZ()) {
                // ignore target block
                continue;
            }
            // Ignore first blocks next to explosion
            if (ignoreFirstZone && ((i >= ConfigManager.getInstance().getRadius() - 1) || (dLoc.distance(tarLoc) <= 1.5))) {
                if (i >= ConfigManager.getInstance().getRadius() - 1 && MaterialManager.getInstance().contains(block.getType().name(), block.getData())) {
                    targetsInPath.add(block.getLocation());
                }
                continue;
            }

            // check if the block material is being handled
            if (useOnlyMaterialListing) {
                // only handle for certain case as to not interfere with all explosions
                if (MaterialManager.getInstance().contains(block.getType().name(), block.getData())) {
                    targetsInPath.add(block.getLocation());
                    continue;
                } else {
                    continue;
                }
            }
            // check if the block material is a solid
            if (!isNonSolid(block.getType())) {
                targetsInPath.add(block.getLocation());
                if (targetsInPath.size() > 3) {
                    break;
                }
            }
        }
    } catch (Exception e) {
        // ignore the error and return no targets in path
    }
    return targetsInPath;
}
 
Example 19
Source File: DGameWorld.java    From DungeonsXL with GNU General Public License v3.0 4 votes vote down vote up
/**
 * Handles what happens when a player places a block.
 *
 * @param player
 * @param block
 * @param against
 * @param hand    the event parameters.
 * @return if the event is cancelled
 */
public boolean onPlace(Player player, Block block, Block against, ItemStack hand) {
    Game game = getGame();
    if (game == null) {
        return true;
    }

    PlaceableBlock placeableBlock = null;
    for (PlaceableBlock gamePlaceableBlock : placeableBlocks) {
        if (gamePlaceableBlock.canPlace(block, caliburn.getExItem(hand))) {
            placeableBlock = gamePlaceableBlock;
            break;
        }
    }
    if (!getRules().getState(GameRule.PLACE_BLOCKS) && placeableBlock == null) {
        // Workaround for a bug that would allow 3-Block-high jumping
        Location loc = player.getLocation();
        if (loc.getY() > block.getY() + 1.0 && loc.getY() <= block.getY() + 1.5) {
            if (loc.getX() >= block.getX() - 0.3 && loc.getX() <= block.getX() + 1.3) {
                if (loc.getZ() >= block.getZ() - 0.3 && loc.getZ() <= block.getZ() + 1.3) {
                    loc.setX(block.getX() + 0.5);
                    loc.setY(block.getY());
                    loc.setZ(block.getZ() + 0.5);
                    player.teleport(loc);
                }
            }
        }

        return true;
    }
    if (placeableBlock != null) {
        placeableBlock.onPlace();
    }

    Set<ExItem> whitelist = getRules().getState(GameRule.PLACE_WHITELIST);
    if (whitelist == null || whitelist.contains(VanillaItem.get(block.getType()))) {
        placedBlocks.add(block);
        return false;
    }

    return true;
}
 
Example 20
Source File: LWC.java    From Modern-LWC with MIT License 2 votes vote down vote up
/**
 * Compares two blocks if they are equal
 *
 * @param block
 * @param block2
 * @return
 */
@SuppressWarnings("deprecation")
public boolean blockEquals(Block block, Block block2) {
    return block.getType() == block2.getType() && block.getX() == block2.getX() && block.getY() == block2.getY()
            && block.getZ() == block2.getZ() && block.getData() == block2.getData();
}