use of org.bukkit.entity.FallingBlock in project MagicPlugin by elBukkit.
the class ThrowBlockAction method start.
@Override
public SpellResult start(CastContext context) {
Location location = context.getLocation();
if (!context.hasBuildPermission(location.getBlock())) {
return SpellResult.INSUFFICIENT_PERMISSION;
}
location.setY(location.getY() - 1);
MaterialBrush buildWith = context.getBrush();
buildWith.setTarget(location);
if (buildWith.isErase() || buildWith.getMaterial() == Material.AIR) {
return SpellResult.NO_TARGET;
}
if (consumeBlocks && !context.isConsumeFree()) {
Mage mage = context.getMage();
UndoList undoList = context.getUndoList();
if (undoList != null) {
undoList.setConsumed(true);
}
ItemStack requires = buildWith.getItemStack(1);
if (!mage.hasItem(requires, consumeVariants)) {
String requiresMessage = context.getMessage("insufficient_resources");
context.sendMessage(requiresMessage.replace("$cost", buildWith.getName()));
return SpellResult.STOP;
}
mage.removeItem(requires, consumeVariants);
}
Material material = buildWith.getMaterial();
byte data = buildWith.getBlockData();
location = sourceLocation.getLocation(context);
Vector direction = location.getDirection();
double speed = context.getRandom().nextDouble() * (speedMax - speedMin) + speedMin;
direction.normalize().multiply(speed);
Vector up = new Vector(0, 1, 0);
Vector perp = new Vector();
perp.copy(direction);
perp.crossProduct(up);
FallingBlock falling = DeprecatedUtils.spawnFallingBlock(location, material, data);
if (falling == null) {
return SpellResult.FAIL;
}
track(context, falling);
if (!consumeBlocks) {
falling.setDropItem(false);
}
SafetyUtils.setVelocity(falling, direction);
if (maxDamage > 0 && fallDamage > 0) {
CompatibilityUtils.setFallingBlockDamage(falling, fallDamage, maxDamage);
} else {
falling.setHurtEntities(hurts);
}
return checkTracking(context);
}
use of org.bukkit.entity.FallingBlock in project MagicPlugin by elBukkit.
the class ConstructBatch method modifyWith.
protected void modifyWith(Block block, MaterialAndData brush) {
Material previousMaterial = block.getType();
byte previousData = DeprecatedUtils.getData(block);
if (brush.isValid() && (brush.isDifferent(block) || commit)) {
if (consume && !context.isConsumeFree() && brush.getMaterial() != Material.AIR) {
ItemStack requires = brush.getItemStack(1);
if (!mage.hasItem(requires, consumeVariants)) {
String requiresMessage = context.getMessage("insufficient_resources");
context.sendMessage(requiresMessage.replace("$cost", brush.getName()));
finish();
return;
}
mage.removeItem(requires, consumeVariants);
}
if (!commit) {
registerForUndo(block);
}
// Check for command overrides
if (commandMap != null && brush.getMaterial() == Material.COMMAND) {
String commandKey = brush.getCommandLine();
if (commandKey != null && commandKey.length() > 0 && commandMap.containsKey(commandKey)) {
brush.setCommandLine(commandMap.get(commandKey));
}
}
brush.modify(block, applyPhysics);
if (breakable > 0) {
spell.getCurrentCast().registerBreakable(block, breakable);
}
if (backfireChance > 0) {
spell.getCurrentCast().registerReflective(block, backfireChance);
}
if (spawnFallingBlocks) {
FallingBlock falling = DeprecatedUtils.spawnFallingBlock(block.getLocation(), previousMaterial, previousData);
falling.setDropItem(false);
if (fallingBlockSpeed != 0) {
Vector direction = this.fallingDirection != null ? this.fallingDirection : falling.getLocation().subtract(center).toVector();
direction = direction.normalize().multiply(fallingBlockSpeed);
SafetyUtils.setVelocity(falling, direction);
}
registerForUndo(falling);
}
if (commit) {
com.elmakers.mine.bukkit.api.block.BlockData blockData = UndoList.register(block);
blockData.commit();
}
}
}
use of org.bukkit.entity.FallingBlock in project MagicPlugin by elBukkit.
the class FillBatch method process.
@Override
@SuppressWarnings("deprecation")
public int process(int maxBlocks) {
int processedBlocks = 0;
while (processedBlocks <= maxBlocks && ix < absx) {
Block block = world.getBlockAt(x + ix * dx, y + iy * dy, z + iz * dz);
brush.update(mage, block.getLocation());
if (!block.getChunk().isLoaded()) {
block.getChunk().load();
return processedBlocks;
}
if (!brush.isReady()) {
brush.prepare();
return processedBlocks;
}
processedBlocks++;
boolean hasPermission = brush.isErase() ? spell.hasBreakPermission(block) : spell.hasBuildPermission(block);
if (hasPermission && !spell.isIndestructible(block)) {
Material previousMaterial = block.getType();
byte previousData = block.getData();
if (brush.isDifferent(block)) {
if (consume && !context.isConsumeFree() && brush.getMaterial() != Material.AIR) {
ItemStack requires = brush.getItemStack(1);
if (!mage.hasItem(requires, consumeVariants)) {
String requiresMessage = context.getMessage("insufficient_resources");
context.sendMessage(requiresMessage.replace("$cost", brush.getName()));
finish();
return processedBlocks;
}
mage.removeItem(requires, consumeVariants);
}
registerForUndo(block);
brush.modify(block);
if (spawnFallingBlocks) {
FallingBlock falling = block.getWorld().spawnFallingBlock(block.getLocation(), previousMaterial, previousData);
falling.setDropItem(false);
}
}
}
iy++;
if (iy >= absy) {
iy = 0;
iz++;
if (iz >= absz) {
iz = 0;
ix++;
}
}
}
if (ix >= absx) {
finish();
}
return processedBlocks;
}
use of org.bukkit.entity.FallingBlock in project MagicPlugin by elBukkit.
the class BlockController method onEntityChangeBlockEvent.
@EventHandler
public void onEntityChangeBlockEvent(EntityChangeBlockEvent event) {
Entity entity = event.getEntity();
if (entity instanceof FallingBlock) {
if (event.getTo() == Material.AIR) {
// Block is falling, register it
controller.registerFallingBlock(entity, event.getBlock());
} else {
// Block is landing, convert it
UndoList blockList = com.elmakers.mine.bukkit.block.UndoList.getUndoList(entity);
if (blockList != null) {
com.elmakers.mine.bukkit.api.action.CastContext context = blockList.getContext();
if (context != null && !context.hasBuildPermission(entity.getLocation().getBlock())) {
event.setCancelled(true);
} else {
Block block = event.getBlock();
blockList.convert(entity, block);
if (!blockList.getApplyPhysics()) {
FallingBlock falling = (FallingBlock) entity;
DeprecatedUtils.setTypeIdAndData(block, DeprecatedUtils.getId(falling.getMaterial()), DeprecatedUtils.getBlockData(falling), false);
event.setCancelled(true);
}
}
}
}
}
}
use of org.bukkit.entity.FallingBlock in project NoCheatPlus by NoCheatPlus.
the class HotFixFallingBlockPortalEnter method onEntityPortalEnter.
@EventHandler(priority = EventPriority.MONITOR)
public void onEntityPortalEnter(EntityPortalEnterEvent event) {
final Entity entity = event.getEntity();
final Material mat;
if (entity instanceof FallingBlock) {
mat = ((FallingBlock) entity).getMaterial();
} else if (entity instanceof Item) {
// TODO: Not sure if needed.
if (((Item) entity).getItemStack().getType().hasGravity()) {
mat = ((Item) entity).getItemStack().getType();
} else {
mat = null;
}
} else {
mat = null;
}
if (mat != null) {
final Location loc = entity.getLocation(useLoc);
final World world = loc.getWorld();
final IWorldData worldData = NCPAPIProvider.getNoCheatPlusAPI().getWorldDataManager().getWorldData(world);
if (worldData.getGenericInstance(InventoryConfig.class).hotFixFallingBlockEndPortalActive) {
final BlockCache blockCache = wrapBlockCache.getBlockCache();
blockCache.setAccess(world);
final boolean nearbyPortal = BlockProperties.collidesId(blockCache, loc.getX() - 2.0, loc.getY() - 2.0, loc.getZ() - 2.0, loc.getX() + 3.0, loc.getY() + 3.0, loc.getZ() + 3.0, Material.ENDER_PORTAL);
blockCache.cleanup();
if (nearbyPortal) {
// Likely spigot currently removes entities entering portals anyway (cross-world teleport issues).
// On remove: Looks like setDropItem(false) wouldn't suffice.
entity.remove();
// TODO: STATUS: should have another stream for violations/protection.
final String message = "[INVENTORY_HOTFIX] Remove falling block entering a portal near an end portal: " + mat + " at " + world.getName() + "/" + LocUtil.simpleFormatPosition(loc);
NCPAPIProvider.getNoCheatPlusAPI().getLogManager().info(Streams.STATUS, message);
}
}
useLoc.setWorld(null);
}
}
Aggregations