Search in sources :

Example 96 with Material

use of org.bukkit.Material in project NoCheatPlus by NoCheatPlus.

the class BlockProperties method isPassableBox.

/**
 * Check passability with an arbitrary bounding box vs. a block.
 *
 * @param access
 *            the access
 * @param blockX
 *            the block x
 * @param blockY
 *            the block y
 * @param blockZ
 *            the block z
 * @param minX
 *            the min x
 * @param minY
 *            the min y
 * @param minZ
 *            the min z
 * @param maxX
 *            the max x
 * @param maxY
 *            the max y
 * @param maxZ
 *            the max z
 * @return true, if is passable box
 */
public static final boolean isPassableBox(final BlockCache access, final int blockX, final int blockY, final int blockZ, final double minX, final double minY, final double minZ, final double maxX, final double maxY, final double maxZ) {
    // TODO: This mostly is copy and paste from isPassableRay.
    final IBlockCacheNode node = access.getOrCreateBlockCacheNode(blockX, blockY, blockZ, false);
    final Material id = node.getType();
    if (BlockProperties.isPassable(id)) {
        return true;
    }
    double[] bounds = access.getBounds(blockX, blockY, blockZ);
    if (bounds == null) {
        return true;
    }
    // (Coordinates are already passed in an ordered form.)
    if (!collidesBlock(access, minX, minY, minZ, maxX, maxY, maxZ, blockX, blockY, blockZ, node, null, getBlockFlags(id) | F_COLLIDE_EDGES)) {
        return true;
    }
    // TODO: check f_itchy once exists.
    if (BlockProperties.isPassableWorkaround(access, blockX, blockY, blockZ, minX - blockX, minY - blockY, minZ - blockZ, node, maxX - minX, maxY - minY, maxZ - minZ, 1.0)) {
        return true;
    }
    // Does collide (most likely).
    return false;
}
Also used : IBlockCacheNode(fr.neatmonster.nocheatplus.utilities.map.BlockCache.IBlockCacheNode) Material(org.bukkit.Material)

Example 97 with Material

use of org.bukkit.Material in project NoCheatPlus by NoCheatPlus.

the class FakeBlockCache method toJava.

/**
 * Return a line of java code to construct a new FakeBlockCache with the
 * same content (no newlines).
 *
 * @param builder
 *            the builder
 * @param fbcName
 *            Variable name of the FakeBlockCache instance.
 * @param boundsPrefix
 *            A prefix for bounds variables for the case of repeated
 *            content. If set to null, no optimization will be performed.
 */
public void toJava(final StringBuilder builder, final String fbcName, final String boundsPrefix) {
    builder.append("FakeBlockCache " + fbcName + " = new FakeBlockCache();");
    final String fullBounds;
    if (boundsPrefix != null) {
        fullBounds = boundsPrefix + "_fb";
        builder.append(" double[] " + fullBounds + " = new double[]{0.0, 0.0, 0.0, 1.0, 1.0, 1.0};");
    } else {
        fullBounds = null;
    }
    // Assume id is always set.
    final Iterator<Entry<Material>> it = idMapStored.iterator();
    while (it.hasNext()) {
        Entry<Material> entry = it.next();
        final int x = entry.getX();
        final int y = entry.getY();
        final int z = entry.getZ();
        final Material id = entry.getValue();
        if (id == Material.AIR) {
            builder.append(fbcName + ".set(" + x + ", " + y + ", " + z + ", " + id + ");");
        } else {
            final Integer data = dataMapStored.get(x, y, z);
            final double[] bounds = boundsMapStored.get(x, y, z);
            if (bounds == null) {
                if (data == null) {
                    // Consider 0 too.
                    builder.append(fbcName + ".set(" + x + ", " + y + ", " + z + ", " + id + ");");
                } else {
                    builder.append(fbcName + ".set(" + x + ", " + y + ", " + z + ", " + id + ", " + data + ");");
                }
            } else if (boundsPrefix != null && MapUtil.isFullBounds(bounds)) {
                builder.append(fbcName + ".set(" + x + ", " + y + ", " + z + ", " + id + ", " + data + ", " + fullBounds + ");");
                ;
            } else {
                builder.append(fbcName + ".set(" + x + ", " + y + ", " + z + ", " + id + ", " + data + ", ");
                DebugUtil.toJava(bounds, builder);
                builder.append(");");
            }
        }
    }
}
Also used : Entry(fr.neatmonster.nocheatplus.utilities.ds.map.CoordMap.Entry) Material(org.bukkit.Material)

Example 98 with Material

use of org.bukkit.Material in project NoCheatPlus by NoCheatPlus.

the class InteractRayTracing method doesCollide.

/**
 * Simplistic collision check (can interact through this block).
 * @param blockX
 * @param blockY
 * @param blockZ
 * @return
 */
private boolean doesCollide(final int blockX, final int blockY, final int blockZ) {
    final Material id = blockCache.getType(blockX, blockY, blockZ);
    final long flags = BlockProperties.getBlockFlags(id);
    if ((flags & BlockProperties.F_SOLID) == 0) {
        // Ignore non solid blocks anyway.
        return false;
    }
    if ((flags & (BlockProperties.F_LIQUID | BlockProperties.F_IGN_PASSABLE | BlockProperties.F_STAIRS | BlockProperties.F_VARIABLE)) != 0) {
        // TODO: F_VARIABLE: Bounding boxes are roughly right ?
        return false;
    }
    if (!blockCache.isFullBounds(blockX, blockY, blockZ)) {
        return false;
    }
    return true;
}
Also used : Material(org.bukkit.Material)

Example 99 with Material

use of org.bukkit.Material in project NoCheatPlus by NoCheatPlus.

the class BlockCache method getOrCreateNode.

/**
 * If there is no node stored, create a new node only with the type id set.
 *
 * @param x
 * @param y
 * @param z
 * @return
 */
private BlockCacheNode getOrCreateNode(final int x, final int y, final int z) {
    BlockCacheNode node = nodeMap.get(x, y, z);
    if (node != null) {
        return node;
    }
    final Material id = (y < 0 || y > maxBlockY) ? Material.AIR : fetchTypeId(x, y, z);
    // (Later: Static id-node map from config.)
    if (id == Material.AIR) {
        return airNode;
    } else {
        node = new BlockCacheNode(id);
        nodeMap.put(x, y, z, node);
        return node;
    }
}
Also used : Material(org.bukkit.Material)

Example 100 with Material

use of org.bukkit.Material in project FunnyGuilds by FunnyGuilds.

the class EntityExplode method onExplode.

@EventHandler
public void onExplode(EntityExplodeEvent event) {
    List<Block> destroyedBlocks = event.blockList();
    Location explodeLocation = event.getLocation();
    PluginConfig pluginConfiguration = Settings.getConfig();
    List<Location> sphere = SpaceUtils.sphere(explodeLocation, pluginConfiguration.explodeRadius, pluginConfiguration.explodeRadius, false, true, 0);
    Map<Material, Double> materials = pluginConfiguration.explodeMaterials;
    destroyedBlocks.removeIf(blocks -> {
        Region region = RegionUtils.getAt(blocks.getLocation());
        return region != null && region.getGuild() != null && !region.getGuild().canBeAttacked();
    });
    Region region = RegionUtils.getAt(explodeLocation);
    if (region != null) {
        Guild guild = region.getGuild();
        if (pluginConfiguration.guildTNTProtectionEnabled) {
            LocalDateTime start = pluginConfiguration.guildTNTProtectionStartTime;
            LocalDateTime end = pluginConfiguration.guildTNTProtectionEndTime;
            LocalDateTime now = LocalDateTime.now();
            if ((now.isAfter(start) || now.equals(start)) && (now.isBefore(end) || now.equals(end))) {
                event.setCancelled(true);
                return;
            }
        }
        if (pluginConfiguration.warTntProtection & !guild.canBeAttacked()) {
            event.setCancelled(true);
            return;
        }
        Location protect = region.getCenter().getBlock().getRelative(BlockFace.DOWN).getLocation();
        destroyedBlocks.removeIf(block -> block.getLocation().equals(protect));
        guild.setBuild(System.currentTimeMillis() + Settings.getConfig().regionExplode * 1000L);
        for (User user : guild.getMembers()) {
            Player player = user.getPlayer();
            if (player != null) {
                if (informationMessageCooldowns.cooldown(player, TimeUnit.SECONDS, pluginConfiguration.infoPlayerCooldown)) {
                    player.sendMessage(Messages.getInstance().regionExplode.replace("{TIME}", Integer.toString(Settings.getConfig().regionExplode)));
                }
            }
        }
    }
    for (Location l : sphere) {
        Material material = l.getBlock().getType();
        if (!materials.containsKey(material)) {
            continue;
        }
        if (material == Material.WATER || material == Material.LAVA) {
            if (SpaceUtils.chance(materials.get(material))) {
                l.getBlock().setType(Material.AIR);
            }
        } else {
            if (SpaceUtils.chance(materials.get(material))) {
                l.getBlock().breakNaturally();
            }
        }
    }
}
Also used : LocalDateTime(java.time.LocalDateTime) Player(org.bukkit.entity.Player) User(net.dzikoysk.funnyguilds.basic.User) Material(org.bukkit.Material) Guild(net.dzikoysk.funnyguilds.basic.Guild) PluginConfig(net.dzikoysk.funnyguilds.data.configs.PluginConfig) Block(org.bukkit.block.Block) Region(net.dzikoysk.funnyguilds.basic.Region) Location(org.bukkit.Location) EventHandler(org.bukkit.event.EventHandler)

Aggregations

Material (org.bukkit.Material)427 ItemStack (org.bukkit.inventory.ItemStack)99 Block (org.bukkit.block.Block)87 EventHandler (org.bukkit.event.EventHandler)51 ArrayList (java.util.ArrayList)46 Player (org.bukkit.entity.Player)44 Location (org.bukkit.Location)42 Vector (org.bukkit.util.Vector)27 EntityType (org.bukkit.entity.EntityType)26 GlowBlock (net.glowstone.block.GlowBlock)24 Test (org.junit.Test)24 BlockFace (org.bukkit.block.BlockFace)23 Entity (org.bukkit.entity.Entity)22 MaterialData (org.bukkit.material.MaterialData)22 World (org.bukkit.World)20 HashMap (java.util.HashMap)19 IOException (java.io.IOException)17 ConfigurationSection (org.bukkit.configuration.ConfigurationSection)16 File (java.io.File)15 HashSet (java.util.HashSet)13