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;
}
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);
}
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));
}
}
}
}
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);
}
}
}
}
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;
}
}
Aggregations