use of org.bukkit.block.BlockState in project RedProtect by FabioZumbi12.
the class RPBlockListener method onBlockForm.
@EventHandler
public void onBlockForm(BlockFormEvent event) {
RedProtect.get().logger.debug("RPBlockListener - Is Blockform event!");
if (event.isCancelled()) {
return;
}
BlockState b = event.getNewState();
if (b == null) {
return;
}
RedProtect.get().logger.debug("Is Blockform event: " + b.getType().name());
if (b.getType().equals(Material.SNOW) || b.getType().equals(Material.ICE)) {
Region r = RedProtect.get().rm.getTopRegion(b.getLocation());
if (r != null && !r.canIceForm()) {
event.setCancelled(true);
}
}
}
use of org.bukkit.block.BlockState in project VoxelGamesLibv2 by VoxelGamesLib.
the class MapScanner method searchForMarkers.
/**
* Searches the map for "markers". Most of the time these are implemented as tile entities (skulls)
*
* @param map the map to scan
* @param center the center location
* @param range the range in where to scan
*/
public void searchForMarkers(@Nonnull Map map, @Nonnull Vector3D center, int range, @Nonnull UUID gameid) {
World world = Bukkit.getWorld(map.getLoadedName(gameid));
if (world == null) {
throw new MapException("Could not find world " + map.getLoadedName(gameid) + "(" + map.getInfo().getName() + ")" + ". Is it loaded?");
}
List<Marker> markers = new ArrayList<>();
List<ChestMarker> chestMarkers = new ArrayList<>();
int startX = (int) center.getX();
int startY = (int) center.getZ();
int minX = Math.min(startX - range, startX + range);
int minZ = Math.min(startY - range, startY + range);
int maxX = Math.max(startX - range, startX + range);
int maxZ = Math.max(startY - range, startY + range);
for (int x = minX; x <= maxX; x += 16) {
for (int z = minZ; z <= maxZ; z += 16) {
Chunk chunk = world.getChunkAt(x >> 4, z >> 4);
for (BlockState te : chunk.getTileEntities()) {
if (te.getType() == Material.SKULL) {
Skull skull = (Skull) te;
if (skull.getSkullType() == SkullType.PLAYER) {
String markerData = getMarkerData(skull);
if (markerData == null)
continue;
MarkerDefinition markerDefinition = mapHandler.createMarkerDefinition(markerData);
markers.add(new Marker(new Vector3D(skull.getX(), skull.getY(), skull.getZ()), DirectionUtil.directionToYaw(skull.getRotation()), markerData, markerDefinition));
}
} else if (te.getType() == Material.CHEST) {
Chest chest = (Chest) te;
String name = chest.getBlockInventory().getName();
ItemStack[] items = new ItemStack[chest.getBlockInventory().getStorageContents().length];
for (int i = 0; i < items.length; i++) {
ItemStack is = chest.getBlockInventory().getItem(i);
if (is == null) {
items[i] = new ItemStack(Material.AIR);
} else {
items[i] = is;
}
}
chestMarkers.add(new ChestMarker(new Vector3D(chest.getX(), chest.getY(), chest.getZ()), name, items));
}
}
}
}
map.setMarkers(markers);
map.setChestMarkers(chestMarkers);
}
use of org.bukkit.block.BlockState in project MagicPlugin by elBukkit.
the class SimulateSpell method onCast.
@Override
public SpellResult onCast(ConfigurationSection parameters) {
Target t = getTarget();
if (t == null) {
return SpellResult.NO_TARGET;
}
Block target = t.getBlock();
if (target == null) {
return SpellResult.NO_TARGET;
}
if (!hasBuildPermission(target)) {
return SpellResult.INSUFFICIENT_PERMISSION;
}
int radius = parameters.getInt("radius", DEFAULT_RADIUS);
radius = parameters.getInt("r", radius);
int yRadius = parameters.getInt("yradius", 0);
MaterialAndData birthMaterial = new MaterialAndData(target);
birthMaterial = ConfigurationUtils.getMaterialAndData(parameters, "material", birthMaterial);
birthMaterial = ConfigurationUtils.getMaterialAndData(parameters, "m", birthMaterial);
Double dmxValue = ConfigurationUtils.getDouble(parameters, "obx", null);
Double dmyValue = ConfigurationUtils.getDouble(parameters, "oby", null);
Double dmzValue = ConfigurationUtils.getDouble(parameters, "obz", null);
if (dmxValue != null || dmyValue != null || dmzValue != null) {
Vector offset = new Vector(dmxValue == null ? 0 : dmxValue, dmyValue == null ? 0 : dmyValue, dmzValue == null ? 0 : dmzValue);
Location targetLocation = target.getLocation().add(offset);
if (!targetLocation.getBlock().getChunk().isLoaded())
return SpellResult.FAIL;
birthMaterial = new MaterialAndData(targetLocation.getBlock());
}
Material deathMaterial = ConfigurationUtils.getMaterial(parameters, "death_material", Material.AIR);
// use the target location with the player's facing
Location location = getLocation();
Location targetLocation = target.getLocation();
targetLocation.setPitch(location.getPitch());
targetLocation.setYaw(location.getYaw());
// Look for relative-positioned chests that define the rulesets.
Set<Integer> birthCounts = new HashSet<>();
Set<Integer> liveCounts = new HashSet<>();
Double dlcxValue = ConfigurationUtils.getDouble(parameters, "olcx", null);
Double dlcyValue = ConfigurationUtils.getDouble(parameters, "olcy", null);
Double dlczValue = ConfigurationUtils.getDouble(parameters, "olcz", null);
if (dlcxValue != null || dlcyValue != null || dlczValue != null) {
Location liveChestLocation = targetLocation.clone().add(new Vector(dlcxValue == null ? 0 : dlcxValue, dlcyValue == null ? 0 : dlcyValue, dlczValue == null ? 0 : dlczValue));
Block chestBlock = liveChestLocation.getBlock();
BlockState chestState = chestBlock.getState();
if (chestState instanceof InventoryHolder) {
ItemStack[] items = ((InventoryHolder) chestState).getInventory().getContents();
for (int index = 0; index < items.length; index++) {
if (items[index] != null && items[index].getType() != Material.AIR) {
liveCounts.add(index + 1);
// controller.getLogger().info("SimulateSpell: Added live rules for index " + (index + 1) + " from chest at " + liveChestLocation.toVector());
}
}
} else {
controller.getLogger().warning("SimulateSpell: Chest for live rules not found at " + liveChestLocation.toVector());
}
} else if (parameters.contains("live_rules")) {
liveCounts.addAll(ConfigurationUtils.getIntegerList(parameters, "live_rules"));
} else {
liveCounts.add(2);
liveCounts.add(3);
}
Double dbcxValue = ConfigurationUtils.getDouble(parameters, "obcx", null);
Double dbcyValue = ConfigurationUtils.getDouble(parameters, "obcy", null);
Double dbczValue = ConfigurationUtils.getDouble(parameters, "obcz", null);
if (dbcxValue != null || dbcyValue != null || dbczValue != null) {
Location birthChestLocation = targetLocation.clone().add(new Vector(dbcxValue == null ? 0 : dbcxValue, dbcyValue == null ? 0 : dbcyValue, dbczValue == null ? 0 : dbczValue));
Block chestBlock = birthChestLocation.getBlock();
BlockState chestState = chestBlock.getState();
if (chestState instanceof InventoryHolder) {
ItemStack[] items = ((InventoryHolder) chestState).getInventory().getContents();
for (int index = 0; index < items.length; index++) {
if (items[index] != null && items[index].getType() != Material.AIR) {
birthCounts.add(index + 1);
// controller.getLogger().info("SimulateSpell: Added birth rules for index " + (index + 1) + " from chest at " + birthChestLocation.toVector());
}
}
} else {
controller.getLogger().warning("SimulateSpell: Chest for birth rules not found at " + birthChestLocation.toVector());
}
} else if (parameters.contains("birth_rules")) {
birthCounts.addAll(ConfigurationUtils.getIntegerList(parameters, "birth_rules"));
} else {
birthCounts.add(3);
}
if (liveCounts.size() == 0 || birthCounts.size() == 0) {
return SpellResult.FAIL;
}
String automataName = parameters.getString("animate", null);
boolean isAutomata = automataName != null;
final SimulateBatch batch = new SimulateBatch(this, targetLocation, radius, yRadius, birthMaterial, deathMaterial, liveCounts, birthCounts, automataName);
if (parameters.contains("diagonal_live_rules")) {
batch.setDiagonalLiveRules(ConfigurationUtils.getIntegerList(parameters, "diagonal_live_rules"));
}
if (parameters.contains("diagonal_birth_rules")) {
batch.setDiagonalBirthRules(ConfigurationUtils.getIntegerList(parameters, "diagonal_birth_rules"));
}
batch.setReflectChange(parameters.getDouble("reflect_chance", 0));
batch.setBirthRange(parameters.getInt("birth_range", 0));
batch.setLiveRange(parameters.getInt("live_range", 0));
batch.setConcurrent(parameters.getBoolean("concurrent", false));
batch.setCastRange(parameters.getInt("cast_range", 16));
int delay = parameters.getInt("delay", 0);
if (isAutomata) {
SimulateBatch.TargetMode targetMode = null;
String targetModeString = parameters.getString("target_mode", "");
if (targetModeString.length() > 0) {
try {
targetMode = SimulateBatch.TargetMode.valueOf(targetModeString.toUpperCase());
} catch (Exception ex) {
controller.getLogger().warning(ex.getMessage());
}
}
SimulateBatch.TargetMode backupTargetMode = null;
String backupTargetModeString = parameters.getString("backup_target_mode", "");
if (backupTargetModeString.length() > 0) {
try {
backupTargetMode = SimulateBatch.TargetMode.valueOf(backupTargetModeString.toUpperCase());
} catch (Exception ex) {
controller.getLogger().warning(ex.getMessage());
}
}
batch.setMoveRange(parameters.getInt("move", 3));
SimulateBatch.TargetType targetType = null;
String targetTypeString = parameters.getString("targets", "");
if (targetTypeString.length() > 0) {
try {
targetType = SimulateBatch.TargetType.valueOf(targetTypeString.toUpperCase());
} catch (Exception ex) {
controller.getLogger().warning(ex.getMessage());
}
}
batch.setTargetType(targetType);
batch.setMinHuntRange(parameters.getInt("target_min_range", 4));
batch.setMaxHuntRange(parameters.getInt("target_max_range", 128));
batch.setDrop(parameters.getString("drop"), parameters.getInt("drop_xp", 0), ConfigurationUtils.getStringList(parameters, "drops"));
int maxBlocks = parameters.getInt("max_blocks");
batch.setMaxBlocks(maxBlocks);
batch.setMinBlocks(parameters.getInt("min_blocks", maxBlocks));
int level = parameters.getInt("level", 1);
if (level < 1)
level = 1;
if (levelMap != null) {
AutomatonLevel automatonLevel = levelMap.get(level);
batch.setLevel(automatonLevel);
delay = automatonLevel.getDelay(delay);
}
batch.setDelay(delay);
if (targetMode != null) {
batch.setTargetMode(targetMode);
}
if (backupTargetMode != null) {
batch.setBackupTargetMode(backupTargetMode);
}
}
boolean success = mage.addBatch(batch);
return success ? SpellResult.CAST : SpellResult.FAIL;
}
use of org.bukkit.block.BlockState in project MagicPlugin by elBukkit.
the class PowerBlockAction method perform.
@SuppressWarnings("deprecation")
@Override
public SpellResult perform(CastContext context) {
Block block = context.getTargetBlock();
if (!context.hasBuildPermission(block)) {
return SpellResult.INSUFFICIENT_PERMISSION;
}
if (!context.isDestructible(block)) {
return SpellResult.NO_TARGET;
}
context.getUndoList().setApplyPhysics(true);
Material material = block.getType();
BlockState blockState = block.getState();
MaterialData data = blockState.getData();
MageController controller = context.getController();
boolean powerBlock = false;
if (data instanceof Button) {
Button powerData = (Button) data;
context.registerForUndo(block);
powerData.setPowered(!powerData.isPowered());
powerBlock = true;
} else if (data instanceof Lever) {
Lever powerData = (Lever) data;
context.registerForUndo(block);
powerData.setPowered(!powerData.isPowered());
powerBlock = true;
} else if (data instanceof PistonBaseMaterial) {
PistonBaseMaterial powerData = (PistonBaseMaterial) data;
context.registerForUndo(block);
powerData.setPowered(!powerData.isPowered());
powerBlock = true;
} else if (data instanceof PoweredRail) {
PoweredRail powerData = (PoweredRail) data;
context.registerForUndo(block);
powerData.setPowered(!powerData.isPowered());
powerBlock = true;
} else if (data instanceof RedstoneWire) {
RedstoneWire wireData = (RedstoneWire) data;
context.registerForUndo(block);
wireData.setData((byte) (15 - wireData.getData()));
powerBlock = true;
} else if (material == Material.REDSTONE_BLOCK) {
context.registerForUndo(block);
block.getWorld().playEffect(block.getLocation(), Effect.STEP_SOUND, material.getId());
controller.getRedstoneReplacement().modify(block, applyPhysics);
} else if (material == Material.REDSTONE_TORCH_OFF) {
context.registerForUndo(block);
block.setType(Material.REDSTONE_TORCH_ON);
} else if (material == Material.REDSTONE_TORCH_ON) {
context.registerForUndo(block);
block.setType(Material.REDSTONE_TORCH_OFF);
} else if (material == Material.TNT) {
context.registerForUndo(block);
block.setType(Material.AIR);
// Kaboomy time!
context.registerForUndo(block.getLocation().getWorld().spawnEntity(block.getLocation(), EntityType.PRIMED_TNT));
}
if (powerBlock) {
blockState.update();
}
return SpellResult.CAST;
}
use of org.bukkit.block.BlockState in project MagicPlugin by elBukkit.
the class MaterialAndData method modify.
@Override
@SuppressWarnings("deprecation")
public void modify(Block block, boolean applyPhysics) {
if (!isValid)
return;
try {
BlockState blockState = block.getState();
if (material != null) {
byte blockData = data != null ? (byte) (short) data : block.getData();
if (material == Material.AIR) {
// Clear chests and flower pots so they don't dump their contents.
clearItems(blockState);
}
block.setTypeIdAndData(material.getId(), blockData, applyPhysics);
blockState = block.getState();
}
// Command blocks still prefer internal data for parameterized commands
if (blockState != null && blockState instanceof CommandBlock && extraData != null && extraData instanceof BlockCommand) {
CommandBlock command = (CommandBlock) blockState;
BlockCommand commandData = (BlockCommand) extraData;
command.setCommand(commandData.command);
if (commandData.customName != null) {
command.setName(commandData.customName);
}
command.update();
} else if (extraData != null && extraData instanceof BlockTileEntity) {
// Tile entity data overrides everything else, and may replace all of this in the future.
NMSUtils.setTileEntityData(block.getLocation(), ((BlockTileEntity) extraData).data);
} else if (blockState != null && (material == Material.STANDING_BANNER || material == Material.WALL_BANNER) && extraData != null && extraData instanceof BlockBanner) {
if (blockState instanceof Banner) {
BlockBanner bannerData = (BlockBanner) extraData;
Banner banner = (Banner) blockState;
if (bannerData.patterns != null) {
banner.setPatterns(bannerData.patterns);
}
if (bannerData.baseColor != null) {
banner.setBaseColor(bannerData.baseColor);
}
}
blockState.update(true, false);
} else if (blockState != null && blockState instanceof Skull && extraData != null && extraData instanceof BlockSkull) {
Skull skull = (Skull) blockState;
BlockSkull skullData = (BlockSkull) extraData;
if (skullData.skullType != null) {
skull.setSkullType(skullData.skullType);
}
if (skullData.rotation != null) {
skull.setRotation(skullData.rotation);
}
if (skullData.profile != null) {
InventoryUtils.setSkullProfile(skull, skullData.profile);
} else if (skullData.playerName != null) {
skull.setOwner(skullData.playerName);
}
skull.update(true, false);
} else if (blockState != null && blockState instanceof CreatureSpawner && extraData != null && extraData instanceof BlockMobSpawner) {
BlockMobSpawner spawnerData = (BlockMobSpawner) extraData;
if (spawnerData.mobName != null && !spawnerData.mobName.isEmpty()) {
CreatureSpawner spawner = (CreatureSpawner) blockState;
spawner.setCreatureTypeByName(spawnerData.mobName);
spawner.update();
}
} else if (blockState != null && blockState instanceof Sign && extraData != null && extraData instanceof BlockSign) {
BlockSign signData = (BlockSign) extraData;
Sign sign = (Sign) blockState;
for (int i = 0; i < signData.lines.length; i++) {
sign.setLine(i, signData.lines[i]);
}
sign.update();
}
} catch (Exception ex) {
Bukkit.getLogger().warning("[Magic] Error updating block state");
ex.printStackTrace();
}
}
Aggregations