use of org.bukkit.block.CreatureSpawner in project Prism-Bukkit by prism.
the class BlockAction method setBlock.
/**
*
* @param state
*/
public void setBlock(BlockState state) {
if (state != null) {
block_id = BlockUtils.blockIdMustRecordAs(state.getTypeId());
block_subid = state.getRawData();
// @todo clean this up
if (block_id == 144 || block_id == 397 || block_id == 52 || block_id == 63 || block_id == 68) {
actionData = new BlockActionData();
}
// spawner
if (state.getTypeId() == 52) {
final SpawnerActionData spawnerActionData = new SpawnerActionData();
final CreatureSpawner s = (CreatureSpawner) state;
spawnerActionData.entity_type = s.getSpawnedType().name().toLowerCase();
spawnerActionData.delay = s.getDelay();
actionData = spawnerActionData;
} else // skulls
if ((state.getTypeId() == 144 || state.getTypeId() == 397)) {
final SkullActionData skullActionData = new SkullActionData();
final Skull s = (Skull) state;
skullActionData.rotation = s.getRotation().name().toLowerCase();
skullActionData.owner = s.getOwner();
skullActionData.skull_type = s.getSkullType().name().toLowerCase();
actionData = skullActionData;
} else // signs
if ((state.getTypeId() == 63 || state.getTypeId() == 68)) {
final SignActionData signActionData = new SignActionData();
final Sign s = (Sign) state;
signActionData.lines = s.getLines();
actionData = signActionData;
} else // command block
if ((state.getTypeId() == 137)) {
final CommandBlock cmdblock = (CommandBlock) state;
data = cmdblock.getCommand();
}
this.world_name = state.getWorld().getName();
this.x = state.getLocation().getBlockX();
this.y = state.getLocation().getBlockY();
this.z = state.getLocation().getBlockZ();
}
}
use of org.bukkit.block.CreatureSpawner in project Prism-Bukkit by prism.
the class BlockAction method placeBlock.
/**
* Place a block unless something other than air occupies the spot, or if we
* detect a falling block now sits there. This resolves the issue of falling
* blocks taking up the space, preventing this rollback. However, it also
* means that a rollback *could* interfere with a player-placed block.
*/
protected ChangeResult placeBlock(Player player, QueryParameters parameters, boolean is_preview, Block block, boolean is_deferred) {
final Material m = Material.getMaterial(getBlockId());
BlockStateChange stateChange;
// (essentially liquid/air).
if (!getType().requiresHandler("BlockChangeAction") && !getType().requiresHandler("PrismRollbackAction")) {
if (!me.botsko.elixr.BlockUtils.isAcceptableForBlockPlace(block.getType()) && !parameters.hasFlag(Flag.OVERWRITE)) {
// System.out.print("Block skipped due to being unaccaptable for block place.");
return new ChangeResult(ChangeResultType.SKIPPED, null);
}
}
// On the blacklist (except an undo)
if (Prism.getIllegalBlocks().contains(getBlockId()) && !parameters.getProcessType().equals(PrismProcessType.UNDO)) {
// System.out.print("Block skipped because it's not allowed to be placed.");
return new ChangeResult(ChangeResultType.SKIPPED, null);
}
// If we're not in a preview, actually apply this block
if (!is_preview) {
// Capture the block before we change it
final BlockState originalBlock = block.getState();
// it's set to stationary water so the lilypad will sit
if (getBlockId() == 111) {
final Block below = block.getRelative(BlockFace.DOWN);
if (below.getType().equals(Material.WATER) || below.getType().equals(Material.AIR) || below.getType().equals(Material.STATIONARY_WATER)) {
below.setType(Material.STATIONARY_WATER);
} else {
// Prism.debug("Lilypad skipped because no water exists below.");
return new ChangeResult(ChangeResultType.SKIPPED, null);
}
}
// If portal, we need to light the portal. seems to be the only way.
if (getBlockId() == 90) {
final Block obsidian = me.botsko.elixr.BlockUtils.getFirstBlockOfMaterialBelow(Material.OBSIDIAN, block.getLocation());
if (obsidian != null) {
final Block above = obsidian.getRelative(BlockFace.UP);
if (!(above.getType() == Material.PORTAL)) {
above.setType(Material.FIRE);
return new ChangeResult(ChangeResultType.APPLIED, null);
}
}
}
// it becomes unplayable
if (getBlockId() == 84) {
block_subid = 0;
}
// Set the material
block.setTypeId(getBlockId());
block.setData((byte) getBlockSubId());
/**
* Skulls
*/
if ((getBlockId() == 144 || getBlockId() == 397) && getActionData() instanceof SkullActionData) {
final SkullActionData s = (SkullActionData) getActionData();
// Set skull data
final Skull skull = (Skull) block.getState();
skull.setRotation(s.getRotation());
skull.setSkullType(s.getSkullType());
if (!s.owner.isEmpty()) {
skull.setOwner(s.owner);
}
skull.update();
}
/**
* Spawner
*/
if (getBlockId() == 52) {
final SpawnerActionData s = (SpawnerActionData) getActionData();
// Set spawner data
final CreatureSpawner spawner = (CreatureSpawner) block.getState();
spawner.setDelay(s.getDelay());
spawner.setSpawnedType(s.getEntityType());
spawner.update();
}
/**
* Restoring command block
*/
if (getBlockId() == 137) {
final CommandBlock cmdblock = (CommandBlock) block.getState();
cmdblock.setCommand(data);
cmdblock.update();
}
/**
* Signs
*/
if (parameters.getProcessType().equals(PrismProcessType.ROLLBACK) && (getBlockId() == 63 || getBlockId() == 68) && getActionData() instanceof SignActionData) {
final SignActionData s = (SignActionData) getActionData();
// https://snowy-evening.com/botsko/prism/455/
if (block.getState() instanceof Sign) {
// Set sign data
final Sign sign = (Sign) block.getState();
int i = 0;
if (s.lines != null && s.lines.length > 0) {
for (final String line : s.lines) {
sign.setLine(i, line);
i++;
}
}
sign.update();
}
}
// logic to use materials.
if (me.botsko.elixr.BlockUtils.materialRequiresSoil(block.getType())) {
final Block below = block.getRelative(BlockFace.DOWN);
if (below.getType().equals(Material.DIRT) || below.getType().equals(Material.AIR) || below.getType().equals(Material.GRASS)) {
below.setType(Material.SOIL);
} else {
// System.out.print("Block skipped because there's no soil below.");
return new ChangeResult(ChangeResultType.SKIPPED, null);
}
}
// Capture the new state
final BlockState newBlock = block.getState();
// Store the state change
stateChange = new BlockStateChange(originalBlock, newBlock);
// If we're rolling back a door, we need to set it properly
if (BlockUtils.isDoor(m)) {
BlockUtils.properlySetDoor(block, getBlockId(), (byte) getBlockSubId());
} else // Or a bed
if (m.equals(Material.BED_BLOCK)) {
BlockUtils.properlySetBed(block, getBlockId(), (byte) getBlockSubId());
} else // Or double plants
if (m.equals(Material.DOUBLE_PLANT)) {
BlockUtils.properlySetDoublePlant(block, getBlockId(), (byte) getBlockSubId());
}
} else {
// Otherwise, save the state so we can cancel if needed
final BlockState originalBlock = block.getState();
// Note: we save the original state as both old/new so we can re-use
// blockStateChanges
stateChange = new BlockStateChange(originalBlock, originalBlock);
// Preview it
player.sendBlockChange(block.getLocation(), getBlockId(), (byte) getBlockSubId());
// Send preview to shared players
for (final CommandSender sharedPlayer : parameters.getSharedPlayers()) {
if (sharedPlayer instanceof Player) {
((Player) sharedPlayer).sendBlockChange(block.getLocation(), getBlockId(), (byte) getBlockSubId());
}
}
}
return new ChangeResult(ChangeResultType.APPLIED, stateChange);
}
use of org.bukkit.block.CreatureSpawner in project Towny by ElgarL.
the class ProtectionRegenTask method replaceProtections.
public void replaceProtections() {
try {
Block block = state.getBlock();
if (state.getData() instanceof Door) {
Door door = (Door) state.getData();
Block topHalf;
Block bottomHalf;
if (door.isTopHalf()) {
topHalf = block;
bottomHalf = block.getRelative(BlockFace.DOWN);
} else {
bottomHalf = block;
topHalf = block.getRelative(BlockFace.UP);
}
door.setTopHalf(true);
topHalf.setTypeIdAndData(state.getTypeId(), state.getData().getData(), false);
door.setTopHalf(false);
bottomHalf.setTypeIdAndData(state.getTypeId(), state.getData().getData(), false);
} else if (state instanceof Sign) {
block.setTypeIdAndData(state.getTypeId(), state.getData().getData(), false);
Sign sign = (Sign) block.getState();
int i = 0;
for (String line : ((Sign) state).getLines()) sign.setLine(i++, line);
sign.update(true);
} else if (state instanceof CreatureSpawner) {
block.setTypeIdAndData(state.getTypeId(), state.getData().getData(), false);
((CreatureSpawner) block.getState()).setSpawnedType(((CreatureSpawner) state).getSpawnedType());
} else if (state instanceof InventoryHolder) {
block.setTypeId(state.getTypeId(), false);
// Container to receive the inventory
Inventory container = ((InventoryHolder) block.getState()).getInventory();
container.setContents(contents.toArray(new ItemStack[0]));
block.setData(state.getData().getData(), false);
} else if (state.getData() instanceof PistonExtensionMaterial) {
PistonExtensionMaterial extension = (PistonExtensionMaterial) state.getData();
Block piston = block.getRelative(extension.getAttachedFace());
block.setTypeIdAndData(state.getTypeId(), state.getData().getData(), false);
if (altState != null) {
piston.setTypeIdAndData(altState.getTypeId(), altState.getData().getData(), false);
}
} else if (state.getData() instanceof Attachable) {
Block attachedBlock = block.getRelative(((Attachable) state.getData()).getAttachedFace());
if (attachedBlock.getTypeId() == 0) {
attachedBlock.setTypeId(placeholder.getId(), false);
TownyRegenAPI.addPlaceholder(attachedBlock);
}
block.setTypeIdAndData(state.getTypeId(), state.getData().getData(), false);
} else {
if (NeedsPlaceholder.contains(state.getType())) {
Block blockBelow = block.getRelative(BlockFace.DOWN);
if (blockBelow.getTypeId() == 0) {
if (state.getType().equals(Material.CROPS)) {
blockBelow.setTypeId(Material.SOIL.getId(), true);
} else {
blockBelow.setTypeId(placeholder.getId(), true);
}
TownyRegenAPI.addPlaceholder(blockBelow);
}
}
block.setTypeIdAndData(state.getTypeId(), state.getData().getData(), !NeedsPlaceholder.contains(state.getType()));
}
TownyRegenAPI.removePlaceholder(block);
} catch (Exception ex) {
ex.printStackTrace();
}
}
use of org.bukkit.block.CreatureSpawner in project Glowstone by GlowstoneMC.
the class StructureBuilder method createMobSpawner.
public void createMobSpawner(Vector pos, EntityType entityType) {
Vector vec = translate(pos);
if (boundingBox.isVectorInside(vec)) {
BlockState state = world.getBlockAt(vec.getBlockX(), vec.getBlockY(), vec.getBlockZ()).getState();
delegate.backupBlockState(state.getBlock());
state.setType(Material.MOB_SPAWNER);
state.update(true);
state = world.getBlockAt(vec.getBlockX(), vec.getBlockY(), vec.getBlockZ()).getState();
if (state instanceof CreatureSpawner) {
((CreatureSpawner) state).setSpawnedType(entityType);
}
}
}
use of org.bukkit.block.CreatureSpawner in project Essentials by drtshock.
the class EssentialsBlockListener method onBlockPlace.
@EventHandler(priority = EventPriority.LOW, ignoreCancelled = true)
public void onBlockPlace(final BlockPlaceEvent event) {
// Do not rely on getItemInHand();
// http://leaky.bukkit.org/issues/663
final ItemStack is = LocationUtil.convertBlockToItem(event.getBlockPlaced());
if (is == null) {
return;
}
if (is.getType() == Material.MOB_SPAWNER && event.getItemInHand() != null && event.getPlayer() != null && event.getItemInHand().getType() == Material.MOB_SPAWNER) {
final BlockState blockState = event.getBlockPlaced().getState();
if (blockState instanceof CreatureSpawner) {
final CreatureSpawner spawner = (CreatureSpawner) blockState;
final EntityType type = ess.getSpawnerProvider().getEntityType(event.getItemInHand());
if (type != null && Mob.fromBukkitType(type) != null) {
if (ess.getUser(event.getPlayer()).isAuthorized("essentials.spawnerconvert." + Mob.fromBukkitType(type).name().toLowerCase(Locale.ENGLISH))) {
spawner.setSpawnedType(type);
}
}
}
}
final User user = ess.getUser(event.getPlayer());
if (user.hasUnlimited(is) && user.getBase().getGameMode() == GameMode.SURVIVAL) {
class UnlimitedItemSpawnTask implements Runnable {
@Override
public void run() {
user.getBase().getInventory().addItem(is);
user.getBase().updateInventory();
}
}
ess.scheduleSyncDelayedTask(new UnlimitedItemSpawnTask());
}
}
Aggregations