use of dev.frankheijden.insights.api.annotations.AllowPriorityOverride in project Insights by InsightsPlugin.
the class BlockListener method onBlockPlace.
/**
* Handles the BlockPlaceEvent for players.
* Chunk limitations are applied in here on the lowest (first) event priority.
*/
@AllowPriorityOverride
@EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true)
public void onBlockPlace(BlockPlaceEvent event) {
var block = event.getBlock();
var location = block.getLocation();
var material = block.getType();
var player = event.getPlayer();
// In case of BlockMultiPlaceEvent, we may need to take a different delta.
// A closing tripwire hook triggers a BlockMultiPlaceEvent for all attached strings,
// but since they already exist in the world we do not need to count them.
var delta = 0;
if (event instanceof BlockMultiPlaceEvent && material != Material.TRIPWIRE_HOOK) {
List<BlockState> replacedBlockStates = ((BlockMultiPlaceEvent) event).getReplacedBlockStates();
for (BlockState state : replacedBlockStates) {
if (BlockUtils.isSameChunk(location.getBlockX(), location.getBlockZ(), state.getX(), state.getZ())) {
delta++;
}
}
} else {
delta = 1;
}
if (handleAddition(player, location, ScanObject.of(material), delta, false)) {
event.setCancelled(true);
}
}
Aggregations