use of io.github.thebusybiscuit.slimefun4.api.events.BlockPlacerPlaceEvent in project Slimefun4 by Slimefun.
the class BlockPlacer method placeBlock.
@ParametersAreNonnullByDefault
private void placeBlock(ItemStack item, Block facedBlock, Dispenser dispenser) {
BlockPlacerPlaceEvent e = new BlockPlacerPlaceEvent(dispenser.getBlock(), item, facedBlock);
Bukkit.getPluginManager().callEvent(e);
if (!e.isCancelled()) {
schedulePlacement(facedBlock, dispenser.getInventory(), item, () -> {
facedBlock.setType(item.getType());
if (item.hasItemMeta()) {
ItemMeta meta = item.getItemMeta();
if (meta.hasDisplayName()) {
BlockStateSnapshotResult blockState = PaperLib.getBlockState(facedBlock, false);
if ((blockState.getState() instanceof Nameable)) {
Nameable nameable = ((Nameable) blockState.getState());
nameable.setCustomName(meta.getDisplayName());
if (blockState.isSnapshot()) {
// Update block state after changing name
blockState.getState().update(true, false);
}
}
}
}
});
}
}
use of io.github.thebusybiscuit.slimefun4.api.events.BlockPlacerPlaceEvent in project Slimefun4 by Slimefun.
the class BlockPlacer method placeSlimefunBlock.
@ParametersAreNonnullByDefault
private void placeSlimefunBlock(SlimefunItem sfItem, ItemStack item, Block block, Dispenser dispenser) {
BlockPlacerPlaceEvent e = new BlockPlacerPlaceEvent(dispenser.getBlock(), item, block);
Bukkit.getPluginManager().callEvent(e);
if (!e.isCancelled()) {
boolean hasItemHandler = sfItem.callItemHandler(BlockPlaceHandler.class, handler -> {
if (handler.isBlockPlacerAllowed()) {
schedulePlacement(block, dispenser.getInventory(), item, () -> {
block.setType(item.getType());
BlockStorage.store(block, sfItem.getId());
handler.onBlockPlacerPlace(e);
});
}
});
if (!hasItemHandler) {
schedulePlacement(block, dispenser.getInventory(), item, () -> {
block.setType(item.getType());
BlockStorage.store(block, sfItem.getId());
});
}
}
}
use of io.github.thebusybiscuit.slimefun4.api.events.BlockPlacerPlaceEvent in project Slimefun4 by Slimefun.
the class RepairedSpawner method onPlace.
@Nonnull
private BlockPlaceHandler onPlace() {
return new BlockPlaceHandler(true) {
@Override
public void onPlayerPlace(BlockPlaceEvent e) {
onPlace(e.getItemInHand(), e);
}
@Override
public void onBlockPlacerPlace(BlockPlacerPlaceEvent e) {
onPlace(e.getItemStack(), e);
}
@ParametersAreNonnullByDefault
private void onPlace(ItemStack item, BlockEvent e) {
/**
* This may no longer be needed at some point but for legacy items
* we still need to set the spawned EntityType manually
*/
if (e.getBlock().getType() == Material.SPAWNER) {
getEntityType(item).ifPresent(entity -> {
CreatureSpawner spawner = (CreatureSpawner) e.getBlock().getState();
spawner.setSpawnedType(entity);
spawner.update(true, false);
});
}
}
};
}
Aggregations