use of org.bukkit.Material in project NoCheatPlus by NoCheatPlus.
the class InventoryListener method onPlayerInteract.
/**
* We listen to PlayerInteract events for the InstantEat and InstantBow checks.
*
* @param event
* the event
*/
@EventHandler(ignoreCancelled = false, priority = EventPriority.LOWEST)
public final void onPlayerInteract(final PlayerInteractEvent event) {
// Only interested in right-clicks while holding an item.
if (event.getAction() != Action.RIGHT_CLICK_AIR && event.getAction() != Action.RIGHT_CLICK_BLOCK)
return;
final Player player = event.getPlayer();
final IPlayerData pData = DataManager.getPlayerData(player);
final InventoryData data = pData.getGenericInstance(InventoryData.class);
boolean resetAll = false;
if (event.hasItem()) {
final ItemStack item = event.getItem();
final Material type = item.getType();
// TODO: Cancelled / deny use item -> reset all?
if (type == Material.BOW) {
final long now = System.currentTimeMillis();
// It was a bow, the player starts to pull the string, remember this time.
data.instantBowInteract = (data.instantBowInteract > 0 && now - data.instantBowInteract < 800) ? Math.min(System.currentTimeMillis(), data.instantBowInteract) : System.currentTimeMillis();
} else if (InventoryUtil.isConsumable(type)) {
final long now = System.currentTimeMillis();
// It was food, the player starts to eat some food, remember this time and the type of food.
data.instantEatFood = type;
data.instantEatInteract = (data.instantEatInteract > 0 && now - data.instantEatInteract < 800) ? Math.min(System.currentTimeMillis(), data.instantEatInteract) : System.currentTimeMillis();
// Who's monitoring this indentation code?
data.instantBowInteract = 0;
} else
resetAll = true;
// Illegal enchantments hotfix check.
if (Items.checkIllegalEnchantments(player, item, pData)) {
event.setCancelled(true);
counters.addPrimaryThread(idIllegalItem, 1);
}
} else {
resetAll = true;
}
if (resetAll) {
// Nothing that we are interested in, reset data.
if (pData.isDebugActive(CheckType.INVENTORY_INSTANTEAT) && data.instantEatFood != null) {
debug(player, "PlayerInteractEvent, reset fastconsume (legacy: instanteat).");
}
data.instantBowInteract = 0;
data.instantEatInteract = 0;
data.instantEatFood = null;
}
}
use of org.bukkit.Material in project NoCheatPlus by NoCheatPlus.
the class BlockCacheCBDev method fetchBounds.
@Override
public double[] fetchBounds(final int x, final int y, final int z) {
final Material id = getType(x, y, z);
@SuppressWarnings("deprecation") final net.minecraft.server.v1_12_R1.Block block = net.minecraft.server.v1_12_R1.Block.getById(id.getId());
if (block == null) {
// TODO: Convention for null blocks -> full ?
return null;
}
final BlockPosition pos = new BlockPosition(x, y, z);
// TODO: Deprecation warning below (reason / substitute?).
@SuppressWarnings("deprecation") final AxisAlignedBB bb = block.b(iBlockAccess.getType(pos), iBlockAccess, pos);
if (bb == null) {
// Special case.
return new double[] { 0.0, 0.0, 0.0, 1.0, 1.0, 1.0 };
// return null;
}
// minX, minY, minZ, maxX, maxY, maxZ
return new double[] { bb.a, bb.b, bb.c, bb.d, bb.e, bb.f };
}
use of org.bukkit.Material in project NoCheatPlus by NoCheatPlus.
the class Against method check.
public boolean check(final Player player, final Block block, final Material placedMat, final Block blockAgainst, final boolean isInteractBlock, final BlockPlaceData data, final BlockPlaceConfig cc, final IPlayerData pData) {
boolean violation = false;
// TODO: Make more precise (workarounds like WATER_LILY, general points, such as action?).
// Workaround for signs on cactus and similar.
// TODO: pass as argument.
final BlockInteractData bdata = pData.getGenericInstance(BlockInteractData.class);
final Material againstType = blockAgainst.getType();
if (bdata.isConsumedCheck(this.type) && !bdata.isPassedCheck(this.type)) {
// TODO: Awareness of repeated violation probably is to be implemented below somewhere.
violation = true;
if (pData.isDebugActive(type)) {
debug(player, "Cancel due to block having been consumed by this check.");
}
} else if (BlockProperties.isAir(againstType)) {
// Attempt to workaround blocks like cactus.
final Material matAgainst = bdata.getLastType();
if (isInteractBlock && !BlockProperties.isAir(matAgainst) && !BlockProperties.isLiquid(matAgainst)) {
// Block was placed against something (e.g. cactus), allow it.
} else if (!pData.hasPermission(Permissions.BLOCKPLACE_AGAINST_AIR, player)) {
violation = true;
}
} else if (BlockProperties.isLiquid(againstType)) {
// TODO: F_PLACE_AGAINST_WATER|LIQUID...
if ((placedMat != Material.WATER_LILY || !BlockProperties.isLiquid(block.getRelative(BlockFace.DOWN).getType())) && !pData.hasPermission(Permissions.BLOCKPLACE_AGAINST_LIQUIDS, player)) {
violation = true;
}
}
// Handle violation and return.
bdata.addConsumedCheck(this.type);
if (violation) {
data.againstVL += 1.0;
final ViolationData vd = new ViolationData(this, player, data.againstVL, 1, cc.againstActions);
vd.setParameter(ParameterName.BLOCK_TYPE, placedMat.toString());
return executeActions(vd).willCancel();
} else {
// Assume one false positive every 100 blocks.
data.againstVL *= 0.99;
bdata.addPassedCheck(this.type);
return false;
}
}
use of org.bukkit.Material 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.Material in project NoCheatPlus by NoCheatPlus.
the class BlockPlaceListener method onBlockPlace.
/**
* We listen to BlockPlace events for obvious reasons.
*
* @param event
* the event
*/
@EventHandler(ignoreCancelled = true, priority = EventPriority.LOWEST)
public void onBlockPlace(final BlockPlaceEvent event) {
final Block block = event.getBlockPlaced();
final Block blockAgainst = event.getBlockAgainst();
// Skip any null blocks.
if (block == null || blockAgainst == null) {
return;
}
// TODO: What if same block?
// TODO: Revise material use (not block.get... ?)
// final Material mat = block.getType();
final Player player = event.getPlayer();
final Material placedMat;
if (hasGetReplacedState) {
placedMat = event.getBlockPlaced().getType();
} else if (Bridge1_9.hasGetItemInOffHand()) {
final ItemStack stack = event.getItemInHand();
placedMat = BlockProperties.isAir(stack) ? Material.AIR : stack.getType();
} else {
// Safety first.
placedMat = Bridge1_9.getItemInMainHand(player).getType();
}
boolean cancelled = false;
// TODO: Use for data + config getting etc.
final IPlayerData pData = DataManager.getPlayerData(player);
final BlockPlaceData data = pData.getGenericInstance(BlockPlaceData.class);
final BlockPlaceConfig cc = pData.getGenericInstance(BlockPlaceConfig.class);
final BlockInteractData bdata = pData.getGenericInstance(BlockInteractData.class);
final int tick = TickTask.getTick();
// isInteractBlock - the block placed against is the block last interacted with.
final boolean isInteractBlock = !bdata.getLastIsCancelled() && bdata.matchesLastBlock(tick, blockAgainst);
int skippedRedundantChecks = 0;
final boolean debug = pData.isDebugActive(CheckType.BLOCKPLACE);
final boolean shouldSkipSome;
if (blockMultiPlaceEvent != null && event.getClass() == blockMultiPlaceEvent) {
if (placedMat == Material.BEDROCK || Bridge1_9.hasEndCrystalItem() && placedMat == Bridge1_9.END_CRYSTAL_ITEM) {
shouldSkipSome = true;
} else {
if (debug) {
debug(player, "Block place " + event.getClass().getName() + " " + placedMat);
}
shouldSkipSome = false;
}
} else {
shouldSkipSome = false;
}
if (placedMat == Material.SIGN) {
// Might move to MONITOR priority.
data.autoSignPlacedTime = System.currentTimeMillis();
// Always hash as sign post for improved compatibility with Lockette etc.
data.autoSignPlacedHash = getBlockPlaceHash(block, Material.SIGN);
}
// Don't run checks, if a set back is scheduled.
if (!cancelled && pData.isPlayerSetBackScheduled()) {
cancelled = true;
}
// Fast place check.
if (!cancelled && fastPlace.isEnabled(player, pData)) {
if (fastPlace.check(player, block, tick, data, cc, pData)) {
cancelled = true;
} else {
// Feed the improbable.
Improbable.feed(player, 0.5f, System.currentTimeMillis(), pData);
}
}
// No swing check (player doesn't swing their arm when placing a lily pad).
if (!cancelled && !cc.noSwingExceptions.contains(placedMat) && noSwing.isEnabled(player, pData) && noSwing.check(player, data, cc)) {
// Consider skipping all insta placables or using simplified version (true or true within time frame).
cancelled = true;
}
final FlyingQueueHandle flyingHandle;
final boolean reachCheck = pData.isCheckActive(CheckType.BLOCKPLACE_REACH, player);
final boolean directionCheck = pData.isCheckActive(CheckType.BLOCKPLACE_DIRECTION, player);
if (reachCheck || directionCheck) {
flyingHandle = new FlyingQueueHandle(pData);
final Location loc = player.getLocation(useLoc);
final double eyeHeight = MovingUtil.getEyeHeight(player);
// Reach check (distance).
if (!cancelled && !shouldSkipSome) {
if (isInteractBlock && bdata.isPassedCheck(CheckType.BLOCKINTERACT_REACH)) {
skippedRedundantChecks++;
} else if (reachCheck && reach.check(player, eyeHeight, block, data, cc)) {
cancelled = true;
}
}
// Direction check.
if (!cancelled && !shouldSkipSome) {
if (isInteractBlock && bdata.isPassedCheck(CheckType.BLOCKINTERACT_DIRECTION)) {
skippedRedundantChecks++;
} else if (directionCheck && direction.check(player, loc, eyeHeight, block, flyingHandle, data, cc, pData)) {
cancelled = true;
}
}
useLoc.setWorld(null);
} else {
flyingHandle = null;
}
// Surrounding material.
if (!cancelled && against.isEnabled(player, pData) && against.check(player, block, placedMat, blockAgainst, isInteractBlock, data, cc, pData)) {
cancelled = true;
}
// If one of the checks requested to cancel the event, do so.
if (cancelled) {
event.setCancelled(cancelled);
} else {
// Debug log (only if not cancelled, to avoid spam).
if (debug) {
debugBlockPlace(player, placedMat, block, blockAgainst, skippedRedundantChecks, flyingHandle, pData);
}
}
// Cleanup
// Reminder(currently unused): useLoc.setWorld(null);
}
Aggregations