org.bukkit.event.block.BlockPhysicsEvent Java Examples

The following examples show how to use org.bukkit.event.block.BlockPhysicsEvent. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: WorldNativeAccess_v1_13_R2_2.java    From worldedit-adapters with GNU Lesser General Public License v3.0 6 votes vote down vote up
@Override
public void updateNeighbors(BlockPosition pos, IBlockData oldState, IBlockData newState, int recursionLimit) {
    World world = getWorld();
    // a == updateNeighbors
    // b == updateDiagonalNeighbors
    oldState.b(world, pos, NOTIFY);
    if (sideEffectSet.shouldApply(SideEffect.EVENTS)) {
        CraftWorld craftWorld = world.getWorld();
        if (craftWorld != null) {
            BlockPhysicsEvent event = new BlockPhysicsEvent(
                craftWorld.getBlockAt(pos.getX(), pos.getY(), pos.getZ()),
                CraftBlockData.fromData(newState));
            world.getServer().getPluginManager().callEvent(event);
            if (event.isCancelled()) {
                return;
            }
        }
    }
    newState.a(world, pos, NOTIFY);
    newState.b(world, pos, NOTIFY);
}
 
Example #2
Source File: WorldNativeAccess_v1_14_R4.java    From worldedit-adapters with GNU Lesser General Public License v3.0 6 votes vote down vote up
@Override
public void updateNeighbors(BlockPosition pos, IBlockData oldState, IBlockData newState, int recursionLimit) {
    World world = getWorld();
    // a == updateNeighbors
    // b == updateDiagonalNeighbors
    oldState.b(world, pos, NOTIFY);
    if (sideEffectSet.shouldApply(SideEffect.EVENTS)) {
        CraftWorld craftWorld = world.getWorld();
        if (craftWorld != null) {
            BlockPhysicsEvent event = new BlockPhysicsEvent(
                craftWorld.getBlockAt(pos.getX(), pos.getY(), pos.getZ()),
                CraftBlockData.fromData(newState));
            world.getServer().getPluginManager().callEvent(event);
            if (event.isCancelled()) {
                return;
            }
        }
    }
    newState.a(world, pos, NOTIFY);
    newState.b(world, pos, NOTIFY);
}
 
Example #3
Source File: WorldNativeAccess_v1_15_R2.java    From worldedit-adapters with GNU Lesser General Public License v3.0 6 votes vote down vote up
@Override
public void updateNeighbors(BlockPosition pos, IBlockData oldState, IBlockData newState, int recursionLimit) {
    World world = getWorld();
    // a == updateNeighbors
    // b == updateDiagonalNeighbors
    oldState.b(world, pos, NOTIFY);
    if (sideEffectSet.shouldApply(SideEffect.EVENTS)) {
        CraftWorld craftWorld = world.getWorld();
        if (craftWorld != null) {
            BlockPhysicsEvent event = new BlockPhysicsEvent(craftWorld.getBlockAt(pos.getX(), pos.getY(), pos.getZ()), CraftBlockData.fromData(newState));
            world.getServer().getPluginManager().callEvent(event);
            if (event.isCancelled()) {
                return;
            }
        }
    }
    newState.a(world, pos, NOTIFY);
    newState.b(world, pos, NOTIFY);
}
 
Example #4
Source File: WorldNativeAccess_v1_16_R1.java    From worldedit-adapters with GNU Lesser General Public License v3.0 6 votes vote down vote up
@Override
public void updateNeighbors(BlockPosition pos, IBlockData oldState, IBlockData newState, int recursionLimit) {
    World world = getWorld();
    // a == updateNeighbors
    // b == updateDiagonalNeighbors
    oldState.b(world, pos, NOTIFY, recursionLimit);
    if (sideEffectSet.shouldApply(SideEffect.EVENTS)) {
        CraftWorld craftWorld = world.getWorld();
        if (craftWorld != null) {
            BlockPhysicsEvent event = new BlockPhysicsEvent(craftWorld.getBlockAt(pos.getX(), pos.getY(), pos.getZ()), CraftBlockData.fromData(newState));
            world.getServer().getPluginManager().callEvent(event);
            if (event.isCancelled()) {
                return;
            }
        }
    }
    newState.a(world, pos, NOTIFY, recursionLimit);
    newState.b(world, pos, NOTIFY, recursionLimit);
}
 
Example #5
Source File: BlockPlant.java    From Carbon-2 with GNU Lesser General Public License v3.0 6 votes vote down vote up
protected void e(World world, BlockPosition blockposition, IBlockData iblockdata) {
    if (!f(world, blockposition, iblockdata)) {
        // CraftBukkit Start
        org.bukkit.block.Block block = world.getWorld().getBlockAt(blockposition.getX(), blockposition.getY(), blockposition.getZ());
        @SuppressWarnings("deprecation")
        BlockPhysicsEvent event = new BlockPhysicsEvent(block, block.getTypeId());
        world.getServer().getPluginManager().callEvent(event);

        if (event.isCancelled()) {
            return;
        }
        // CraftBukkit end
        this.b(world, blockposition, iblockdata, 0);
        world.setTypeAndData(blockposition, Blocks.AIR.getBlockData(), 3);
    }

}
 
Example #6
Source File: SignsFeature.java    From AreaShop with GNU General Public License v3.0 6 votes vote down vote up
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
public void onIndirectSignBreak(BlockPhysicsEvent event) {
	// Check if the block is a sign
	if(!Materials.isSign(event.getBlock().getType())) {
		return;
	}

	// Check if still attached to a block
	Block attachedBlock = plugin.getBukkitHandler().getSignAttachedTo(event.getBlock());
	// TODO: signs cannot be placed on all blocks, improve this check to isSolid()?
	if (attachedBlock.getType() != Material.AIR) {
		return;
	}

	// Check if the sign is really the same as a saved rent
	RegionSign regionSign = SignsFeature.getSignByLocation(event.getBlock().getLocation());
	if(regionSign == null) {
		return;
	}

	// Remove the sign so that it does not fall on the floor as an item (next region update will place it back when possible)
	AreaShop.debug("onIndirectSignBreak: Removed block of sign for", regionSign.getRegion().getName(), "at", regionSign.getStringLocation());
	event.getBlock().setType(Material.AIR);
	event.setCancelled(true);
}
 
Example #7
Source File: BlockPlant.java    From Carbon-2 with GNU Lesser General Public License v3.0 6 votes vote down vote up
protected void e(World world, BlockPosition blockposition, IBlockData iblockdata) {
    if (!f(world, blockposition, iblockdata)) {
        // CraftBukkit Start
        org.bukkit.block.Block block = world.getWorld().getBlockAt(blockposition.getX(), blockposition.getY(), blockposition.getZ());
        @SuppressWarnings("deprecation")
        BlockPhysicsEvent event = new BlockPhysicsEvent(block, block.getTypeId());
        world.getServer().getPluginManager().callEvent(event);

        if (event.isCancelled()) {
            return;
        }
        // CraftBukkit end
        this.b(world, blockposition, iblockdata, 0);
        world.setTypeAndData(blockposition, Blocks.AIR.getBlockData(), 3);
    }

}
 
Example #8
Source File: SignShopListener.java    From Shopkeepers with GNU General Public License v3.0 5 votes vote down vote up
@EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true)
void onBlockPhysics(BlockPhysicsEvent event) {
	Block block = event.getBlock();
	if (cancelNextBlockPhysicsLoc != null && cancelNextBlockPhysicsLoc.equals(block.getLocation())) {
		event.setCancelled(true);
	} else {
		if (Utils.isSign(block.getType()) && plugin.getShopkeeperByBlock(block) != null) {
			event.setCancelled(true);
		}
	}
}
 
Example #9
Source File: GDPermissionManager.java    From GriefDefender with MIT License 5 votes vote down vote up
public Tristate processResult(Claim claim, String permission, String trust, Tristate permissionValue, GDPermissionHolder permissionHolder) {
    if (GriefDefenderPlugin.debugActive) {
        // Use the event subject always if available
        // This prevents debug showing 'default' for users
        if (eventSubject != null) {
            permissionHolder = eventSubject;
        } else if (permissionHolder == null) {
            final Object source = GDCauseStackManager.getInstance().getCurrentCause().root();
            if (source instanceof GDPermissionUser) {
                permissionHolder = (GDPermissionUser) source;
            } else {
                permissionHolder = GriefDefenderPlugin.DEFAULT_HOLDER;
            }
        }

        if (this.currentEvent != null && (this.currentEvent instanceof BlockPhysicsEvent)) {
            if (((GDClaim) claim).getWorld().getTime() % 100 != 0L) {
                return permissionValue;
            }
        }

        GriefDefenderPlugin.addEventLogEntry(this.currentEvent, claim, this.eventLocation, this.eventSourceId, this.eventTargetId, this.eventSubject == null ? permissionHolder : this.eventSubject, permission, trust, permissionValue, this.eventContexts);
    }


    if (eventPlayerData != null && eventPlayerData.eventResultCache != null) {
        final Flag flag = FlagRegistryModule.getInstance().getById(permission).orElse(null);
        if (flag != null) {
            eventPlayerData.eventResultCache = new EventResultCache((GDClaim) claim, flag.getName().toLowerCase(), permissionValue);
        }
    }
    return permissionValue;
}
 
Example #10
Source File: SignListener.java    From PlayerVaults with GNU General Public License v3.0 5 votes vote down vote up
@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
public void onBlockPhysics(BlockPhysicsEvent event) {
    if (!PlayerVaults.getInstance().getConf().isSigns()) {
        return;
    }
    blockChangeCheck(event.getBlock().getLocation());
}
 
Example #11
Source File: ChunkListener.java    From FastAsyncWorldedit with GNU General Public License v3.0 5 votes vote down vote up
protected boolean containsSetAir(Exception e, BlockPhysicsEvent event) {
    for (int frame = 25; frame < 35; frame++) {
        StackTraceElement elem = getElement(e, frame);
        if (elem != null) {
            String methodName = elem.getMethodName();
            // setAir | setTypeAndData (hacky, but this needs to be efficient)
            if (methodName.charAt(0) == 's' && methodName.length() == 6 || methodName.length() == 14) {
                return true;
            }
        }
    }
    return false;
}
 
Example #12
Source File: EventRuleMatchModule.java    From ProjectAres with GNU Affero General Public License v3.0 5 votes vote down vote up
@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
public void checkBlockPhysics(final BlockPhysicsEvent event) {
    BlockEventQuery query = new BlockEventQuery(event, event.getBlock().getState());
    for(EventRule rule : this.ruleContext.get(EventRuleScope.BLOCK_PHYSICS)) {
        if(rule.region().contains(event.getBlock()) && processQuery(rule, query)) break;
    }
}
 
Example #13
Source File: RegionMatchModule.java    From PGM with GNU Affero General Public License v3.0 5 votes vote down vote up
@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
public void checkBlockPhysics(final BlockPhysicsEvent event) {
  tc.oc.pgm.filters.query.BlockQuery query =
      new tc.oc.pgm.filters.query.BlockQuery(event, event.getBlock().getState());
  for (RegionFilterApplication rfa : this.rfaContext.get(RFAScope.BLOCK_PHYSICS)) {
    if (rfa.region.contains(event.getBlock()) && processQuery(rfa, query)) break;
  }
}
 
Example #14
Source File: ThreadSafetyListener.java    From LagMonitor with MIT License 4 votes vote down vote up
@EventHandler
public void onBlockPhysics(BlockPhysicsEvent blockPhysicsEvent) {
    checkSafety(blockPhysicsEvent);
}
 
Example #15
Source File: GlobalProtectionListener.java    From DungeonsXL with GNU General Public License v3.0 4 votes vote down vote up
@EventHandler(ignoreCancelled = true, priority = EventPriority.HIGHEST)
public void onBlockPhysics(BlockPhysicsEvent event) {
    if (DPortal.getByBlock(plugin, event.getBlock()) != null) {
        event.setCancelled(true);
    }
}
 
Example #16
Source File: ThreadSafetyListener.java    From LagMonitor with MIT License 4 votes vote down vote up
@EventHandler
public void onBlockPhysics(BlockPhysicsEvent blockPhysicsEvent) {
    checkSafety(blockPhysicsEvent);
}
 
Example #17
Source File: EnvironmentControlListener.java    From ProjectAres with GNU Affero General Public License v3.0 4 votes vote down vote up
@EventHandler(priority = EventPriority.HIGH)
public void physics(final BlockPhysicsEvent event) {
    event.setCancelled(true);
}
 
Example #18
Source File: BlockPhysicsListener.java    From ProjectAres with GNU Affero General Public License v3.0 4 votes vote down vote up
@EventHandler
public void onBlockPhysics(BlockPhysicsEvent event) {
    if(!allowPhysics()) {
        event.setCancelled(true);
    }
}
 
Example #19
Source File: BlockPhysics.java    From FunnyGuilds with Apache License 2.0 4 votes vote down vote up
@EventHandler
public void onPhysics(BlockPhysicsEvent event) {
    if (GuildHeartProtectionHandler.isGuildHeart(event.getBlock())) {
        event.setCancelled(true);
    }
}
 
Example #20
Source File: WorldFreeze.java    From CardinalPGM with MIT License 4 votes vote down vote up
@EventHandler
public void onBlockPysics(BlockPhysicsEvent event) {
    if (!match.isRunning()) {
        event.setCancelled(true);
    }
}
 
Example #21
Source File: BlockEventRegion.java    From CardinalPGM with MIT License 4 votes vote down vote up
@EventHandler
public void onBlockPhysics(BlockPhysicsEvent event) {
    if (region.contains(new BlockRegion(null, event.getBlock().getLocation().toVector())) && filter.evaluate(event.getBlock(), event).equals(FilterState.DENY)) {
        event.setCancelled(true);
    }
}
 
Example #22
Source File: FallingBlocksModule.java    From CardinalPGM with MIT License 4 votes vote down vote up
@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
public void onBlockUpdate(BlockPhysicsEvent event) {
    scheduleUpdate(event.getBlock());
}
 
Example #23
Source File: BlockEventHandler.java    From GriefDefender with MIT License 4 votes vote down vote up
@EventHandler(priority = EventPriority.HIGHEST)
public void onBlockNotify(BlockPhysicsEvent event) {
    final Block source = NMSUtil.getInstance().getSourceBlock(event);
    if (source == null) {
        return;
    }

    final Location sourceLocation = source.getLocation();
    if (sourceLocation != null && sourceLocation.equals(event.getBlock().getLocation())) {
        return;
    }

    final GDPermissionUser user = CauseContextHelper.getEventUser(sourceLocation);
    final Location location = event.getBlock().getLocation();
    if (user == null) {
        return;
    }

    final World world = event.getBlock().getWorld();
    if (!GriefDefenderPlugin.getInstance().claimsEnabledForWorld(world.getUID())) {
        return;
    }

    final GDPlayerData playerData =  GriefDefenderPlugin.getInstance().dataStore.getOrCreatePlayerData(world, user.getUniqueId());
    final GDClaim sourceClaim = this.storage.getClaimAt(sourceLocation);
    final Vector3i pos = VecHelper.toVector3i(location);
    final GDClaim targetClaim = this.storage.getClaimAt(location);
    if (sourceClaim.isWilderness() && targetClaim.isWilderness()) {
        if (playerData != null) {
            playerData.eventResultCache = new EventResultCache(targetClaim, "block-notify", Tristate.TRUE);
        }

        return;
    } else if (!sourceClaim.isWilderness() && targetClaim.isWilderness()) {
        if (playerData != null) {
            playerData.eventResultCache = new EventResultCache(targetClaim, "block-notify", Tristate.TRUE);
        }

        return;
    } // Redstone sources can end up in target
    else if (sourceClaim.getUniqueId().equals(targetClaim.getUniqueId())) {
        if (playerData != null) {
            playerData.eventResultCache = new EventResultCache(targetClaim, "block-notify", Tristate.TRUE);
        }

        return;
    } else {
        if (playerData.eventResultCache != null && playerData.eventResultCache.checkEventResultCache(targetClaim) == Tristate.TRUE) {
            return;
        }
        // Needed to handle levers notifying doors to open etc.
        if (targetClaim.isUserTrusted(user, TrustTypes.ACCESSOR)) {
            if (playerData != null) {
                playerData.eventResultCache = new EventResultCache(targetClaim, "block-notify", Tristate.TRUE);
            }
            return;
        }
    }

    event.setCancelled(true);
}