Search in sources :

Example 26 with EntityType

use of org.bukkit.entity.EntityType in project NoCheatPlus by NoCheatPlus.

the class BlockCacheBukkit method standsOnEntity.

@Override
public boolean standsOnEntity(final Entity entity, final double minX, final double minY, final double minZ, final double maxX, final double maxY, final double maxZ) {
    try {
        // TODO: Probably check other ids too before doing this ?
        for (final Entity other : entity.getNearbyEntities(2.0, 2.0, 2.0)) {
            final EntityType type = other.getType();
            if (type != EntityType.BOAT) {
                // && !(other instanceof Minecart))
                continue;
            }
            final double locY = entity.getLocation(useLoc).getY();
            useLoc.setWorld(null);
            if (Math.abs(locY - minY) < 0.7) {
                // TODO: A "better" estimate is possible, though some more tolerance would be good.
                return true;
            } else
                return false;
        }
    } catch (Throwable t) {
    // Ignore exceptions (Context: DisguiseCraft).
    }
    return false;
}
Also used : EntityType(org.bukkit.entity.EntityType) Entity(org.bukkit.entity.Entity)

Example 27 with EntityType

use of org.bukkit.entity.EntityType in project NoCheatPlus by NoCheatPlus.

the class BlockPlaceListener method onProjectileLaunch.

/**
 * We listen to ProjectileLaunch events to prevent players from launching projectiles too quickly.
 *
 * @param event
 *            the event
 */
@EventHandler(ignoreCancelled = true, priority = EventPriority.LOWEST)
public void onProjectileLaunch(final ProjectileLaunchEvent event) {
    // The shooter needs to be a player.
    final Projectile projectile = event.getEntity();
    final Player player = BridgeMisc.getShooterPlayer(projectile);
    if (player == null) {
        return;
    }
    if (MovingUtil.hasScheduledPlayerSetBack(player)) {
        // TODO: Should log.
        event.setCancelled(true);
        return;
    }
    // And the projectile must be one the following:
    EntityType type = event.getEntityType();
    switch(type) {
        case ENDER_PEARL:
            break;
        case ENDER_SIGNAL:
            break;
        case EGG:
            break;
        case SNOWBALL:
            break;
        case THROWN_EXP_BOTTLE:
            break;
        case SPLASH_POTION:
            break;
        default:
            return;
    }
    // Do the actual check...
    final IPlayerData pData = DataManager.getPlayerData(player);
    final BlockPlaceConfig cc = pData.getGenericInstance(BlockPlaceConfig.class);
    boolean cancel = false;
    if (speed.isEnabled(player, pData)) {
        final long now = System.currentTimeMillis();
        final Location loc = player.getLocation(useLoc);
        if (Combined.checkYawRate(player, loc.getYaw(), now, loc.getWorld().getName(), pData)) {
            // Yawrate (checked extra).
            cancel = true;
        }
        if (speed.check(player, cc, pData)) {
            // If the check was positive, cancel the event.
            cancel = true;
        } else if (Improbable.check(player, 0.6f, now, "blockplace.speed", pData)) {
            // Combined fighting speed.
            cancel = true;
        }
    }
    // Ender pearl glitch (ab-) use.
    if (!cancel && type == EntityType.ENDER_PEARL) {
        if (!pData.getGenericInstance(CombinedConfig.class).enderPearlCheck) {
        // Do nothing !
        // TODO: Might have further flags?
        } else if (!BlockProperties.isPassable(projectile.getLocation(useLoc))) {
            // Launch into a block.
            // TODO: This might be a general check later.
            cancel = true;
        } else {
            if (!BlockProperties.isPassable(player.getEyeLocation(), projectile.getLocation(useLoc))) {
                // (Spare a useLoc2, for this is seldom rather.)
                // Something between player
                // TODO: This might be a general check later.
                cancel = true;
            } else {
                final Material mat = player.getLocation(useLoc).getBlock().getType();
                final long flags = BlockProperties.F_CLIMBABLE | BlockProperties.F_LIQUID | BlockProperties.F_IGN_PASSABLE;
                if (!BlockProperties.isAir(mat) && (BlockProperties.getBlockFlags(mat) & flags) == 0 && !mcAccess.getHandle().hasGravity(mat)) {
                    // Still fails on piston traps etc.
                    if (!BlockProperties.isPassable(player.getLocation(), projectile.getLocation()) && !BlockProperties.isOnGroundOrResetCond(player, player.getLocation(), pData.getGenericInstance(MovingConfig.class).yOnGround)) {
                        cancel = true;
                    }
                }
            }
        }
        if (cancel) {
            counters.addPrimaryThread(idEnderPearl, 1);
        }
    }
    // Cancelled ?
    if (cancel) {
        event.setCancelled(true);
    }
    // Cleanup.
    useLoc.setWorld(null);
}
Also used : EntityType(org.bukkit.entity.EntityType) Player(org.bukkit.entity.Player) IPlayerData(fr.neatmonster.nocheatplus.players.IPlayerData) Material(org.bukkit.Material) MovingConfig(fr.neatmonster.nocheatplus.checks.moving.MovingConfig) Projectile(org.bukkit.entity.Projectile) Location(org.bukkit.Location) EventHandler(org.bukkit.event.EventHandler)

Example 28 with EntityType

use of org.bukkit.entity.EntityType in project NoCheatPlus by NoCheatPlus.

the class RawConfigFile method readDoubleValuesForEntityTypes.

/**
 * Read double for entity type, ignoring case. Uses bukkit names for
 * EntityType.
 *
 * @param path
 * @param map
 * @param defaultValue
 * @param allowDefault
 *            If set to true, the default value will be added for the null
 *            key, unless present, and it will be set/overridden if a
 *            section key equals 'default', ignoring case.
 */
public void readDoubleValuesForEntityTypes(final String sectionPath, final Map<EntityType, Double> map, double defaultValue, final boolean allowDefault) {
    final ConfigurationSection section = getConfigurationSection(sectionPath);
    if (section == null) {
        if (allowDefault && !map.containsKey(null)) {
            map.put(null, defaultValue);
        }
        return;
    }
    if (allowDefault) {
        for (final String key : section.getKeys(false)) {
            final String ucKey = key.trim().toUpperCase();
            final String path = sectionPath + "." + key;
            if (ucKey.equals("DEFAULT")) {
                defaultValue = getDouble(path, defaultValue);
                map.put(null, defaultValue);
            }
        }
        if (!map.containsKey(null)) {
            map.put(null, defaultValue);
        }
    }
    for (final String key : section.getKeys(false)) {
        final String ucKey = key.trim().toUpperCase();
        final String path = sectionPath + "." + key;
        if (allowDefault && ucKey.equals("DEFAULT")) {
        // Ignore.
        } else {
            // TODO: Validate values further.
            EntityType type = null;
            try {
                type = EntityType.valueOf(ucKey);
            } catch (IllegalArgumentException e) {
            }
            if (type == null) {
                // TODO: Log once per file only (needs new framework)?
                NCPAPIProvider.getNoCheatPlusAPI().getLogManager().warning(Streams.STATUS, "Bad entity type at '" + path + "': " + key);
            } else {
                map.put(type, getDouble(path, defaultValue));
            }
        }
    }
}
Also used : EntityType(org.bukkit.entity.EntityType) ConfigurationSection(org.bukkit.configuration.ConfigurationSection)

Example 29 with EntityType

use of org.bukkit.entity.EntityType in project Essentials by EssentialsX.

the class EssentialsAntiBuildListener method onHangingBreak.

@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
public void onHangingBreak(final HangingBreakByEntityEvent event) {
    final Entity entity = event.getRemover();
    if (entity instanceof Player) {
        final User user = ess.getUser((Player) entity);
        final EntityType type = event.getEntity().getType();
        final boolean warn = ess.getSettings().warnOnBuildDisallow();
        if (prot.getSettingBool(AntiBuildConfig.disable_build) && !user.canBuild() && !user.isAuthorized("essentials.build")) {
            if (type == EntityType.PAINTING && !metaPermCheck(user, "break", Material.PAINTING.getId())) {
                if (warn) {
                    user.sendMessage(tl("antiBuildBreak", Material.PAINTING.toString()));
                }
                event.setCancelled(true);
            } else if (type == EntityType.ITEM_FRAME && !metaPermCheck(user, "break", Material.ITEM_FRAME.getId())) {
                if (warn) {
                    user.sendMessage(tl("antiBuildBreak", Material.ITEM_FRAME.toString()));
                }
                event.setCancelled(true);
            }
        }
    }
}
Also used : EntityType(org.bukkit.entity.EntityType) HumanEntity(org.bukkit.entity.HumanEntity) Entity(org.bukkit.entity.Entity) Player(org.bukkit.entity.Player) User(com.earth2me.essentials.User) EventHandler(org.bukkit.event.EventHandler)

Example 30 with EntityType

use of org.bukkit.entity.EntityType in project Essentials by EssentialsX.

the class SpawnEggProvider method tryProvider.

@Override
public boolean tryProvider() {
    try {
        EntityType type = EntityType.CREEPER;
        ItemStack is = createEggItem(type);
        EntityType readType = getSpawnedType(is);
        return type == readType;
    } catch (Throwable t) {
        return false;
    }
}
Also used : EntityType(org.bukkit.entity.EntityType) ItemStack(org.bukkit.inventory.ItemStack)

Aggregations

EntityType (org.bukkit.entity.EntityType)109 ArrayList (java.util.ArrayList)29 ItemStack (org.bukkit.inventory.ItemStack)28 Material (org.bukkit.Material)23 Player (org.bukkit.entity.Player)23 Entity (org.bukkit.entity.Entity)19 Location (org.bukkit.Location)17 IOException (java.io.IOException)16 File (java.io.File)13 LivingEntity (org.bukkit.entity.LivingEntity)13 EventHandler (org.bukkit.event.EventHandler)12 PotionType (org.bukkit.potion.PotionType)12 HashMap (java.util.HashMap)10 ConfigurationSection (org.bukkit.configuration.ConfigurationSection)9 Block (org.bukkit.block.Block)8 YamlConfiguration (org.bukkit.configuration.file.YamlConfiguration)8 World (org.bukkit.World)7 SpawnEgg (org.bukkit.material.SpawnEgg)7 UUID (java.util.UUID)5 Biome (org.bukkit.block.Biome)5