use of org.bukkit.block.BlockState in project Towny by ElgarL.
the class TownyRegenAPI method regenChunk.
/**
* Regenerate the chunk the player is stood in and store the block data so it can be undone later.
*
* @param player
*/
public static void regenChunk(Player player) {
try {
Coord coord = Coord.parseCoord(player);
World world = player.getWorld();
Chunk chunk = world.getChunkAt(player.getLocation());
int maxHeight = world.getMaxHeight();
Object[][][] snapshot = new Object[16][maxHeight][16];
for (int x = 0; x < 16; x++) {
for (int z = 0; z < 16; z++) {
for (int y = 0; y < maxHeight; y++) {
//Current block to save
BlockState state = chunk.getBlock(x, y, z).getState();
if (state instanceof org.bukkit.block.Sign) {
BlockSign sign = new BlockSign(BukkitTools.getTypeId(state), BukkitTools.getDataData(state), ((org.bukkit.block.Sign) state).getLines());
sign.setLocation(state.getLocation());
snapshot[x][y][z] = sign;
} else if (state instanceof CreatureSpawner) {
BlockMobSpawner spawner = new BlockMobSpawner(((CreatureSpawner) state).getSpawnedType());
spawner.setLocation(state.getLocation());
spawner.setDelay(((CreatureSpawner) state).getDelay());
snapshot[x][y][z] = spawner;
} else if ((state instanceof InventoryHolder) && !(state instanceof Player)) {
BlockInventoryHolder holder = new BlockInventoryHolder(BukkitTools.getTypeId(state), BukkitTools.getDataData(state), ((InventoryHolder) state).getInventory().getContents());
holder.setLocation(state.getLocation());
snapshot[x][y][z] = holder;
} else {
snapshot[x][y][z] = new BlockObject(BukkitTools.getTypeId(state), BukkitTools.getDataData(state), state.getLocation());
}
}
}
}
TownyUniverse.getDataSource().getResident(player.getName()).addUndo(snapshot);
Bukkit.getWorld(player.getWorld().getName()).regenerateChunk(coord.getX(), coord.getZ());
} catch (NotRegisteredException e) {
// Failed to get resident
}
}
use of org.bukkit.block.BlockState in project Denizen-For-Bukkit by DenizenScript.
the class StructureGrowsScriptEvent method onStructureGrow.
@EventHandler
public void onStructureGrow(StructureGrowEvent event) {
world = new dWorld(event.getWorld());
location = new dLocation(event.getLocation());
structure = new Element(event.getSpecies().name());
blocks = new dList();
new_materials = new dList();
for (BlockState block : event.getBlocks()) {
blocks.add(new dLocation(block.getLocation()).identify());
new_materials.add(dMaterial.getMaterialFrom(block.getType(), block.getRawData()).identify());
}
this.event = event;
cancelled = event.isCancelled();
fire();
event.setCancelled(cancelled);
}
use of org.bukkit.block.BlockState in project Minigames by AddstarMC.
the class RecorderData method restoreBlockData.
@SuppressWarnings("deprecation")
public boolean restoreBlockData() {
File f = new File(plugin.getDataFolder() + "/minigames/" + minigame.getName(false) + "/backup.dat");
if (!f.exists()) {
Bukkit.getLogger().info("No backup file found for " + minigame.getName(false));
return false;
}
try {
BufferedReader br = new BufferedReader(new FileReader(f));
Map<String, String> args = new HashMap<String, String>();
String line;
String[] blocks;
String[] block;
World w;
BlockData bd;
BlockState state;
ItemStack[] items;
String[] sitems;
ItemStack item;
Map<String, String> iargs = new HashMap<String, String>();
while (br.ready()) {
line = br.readLine();
blocks = line.split("\\}\\{");
for (String bl : blocks) {
args.clear();
bl = bl.replace("{", "");
bl = bl.replace("}", "");
block = bl.split(";");
for (String b : block) {
String[] spl = b.split(":");
if (spl.length > 1) {
args.put(spl[0], spl[1]);
}
}
w = Bukkit.getWorld(args.get("world"));
state = w.getBlockAt(Integer.valueOf(args.get("x")), Integer.valueOf(args.get("y")), Integer.valueOf(args.get("z"))).getState();
state.setType(Material.getMaterial(args.get("mat")));
state.setRawData(Byte.valueOf(args.get("data")));
bd = new BlockData(state, null);
if (args.containsKey("items")) {
if (state.getType() == Material.DISPENSER || state.getType() == Material.DROPPER) {
items = new ItemStack[InventoryType.DISPENSER.getDefaultSize()];
} else if (state.getType() == Material.HOPPER) {
items = new ItemStack[InventoryType.HOPPER.getDefaultSize()];
} else if (state.getType() == Material.FURNACE) {
items = new ItemStack[InventoryType.FURNACE.getDefaultSize()];
} else if (state.getType() == Material.BREWING_STAND) {
items = new ItemStack[InventoryType.BREWING.getDefaultSize()];
} else {
items = new ItemStack[InventoryType.CHEST.getDefaultSize()];
}
sitems = args.get("items").split("\\)\\(");
for (String i : sitems) {
i = i.replace("(", "");
i = i.replace(")", "");
for (String s : i.split("\\|")) {
String[] spl = s.split("-");
if (spl.length > 1) {
iargs.put(s.split("-")[0], s.split("-")[1]);
}
}
item = new ItemStack(Material.getMaterial(iargs.get("item")), Integer.valueOf(iargs.get("c")), Short.valueOf(iargs.get("dur")));
if (iargs.containsKey("enc")) {
for (String s : iargs.get("enc").split("\\]\\[")) {
item.addUnsafeEnchantment(Enchantment.getByName(s.split(",")[0].replace("[", "")), Integer.valueOf(s.split(",")[1].replace("]", "")));
}
}
items[Integer.valueOf(iargs.get("slot"))] = item;
iargs.clear();
}
bd.setItems(items);
}
blockdata.put(MinigameUtils.createLocationID(bd.getLocation()), bd);
}
}
br.close();
} catch (FileNotFoundException e) {
Bukkit.getLogger().severe("File not found!!!");
e.printStackTrace();
} catch (IOException e) {
Bukkit.getLogger().severe("IO Error!");
e.printStackTrace();
}
return true;
}
use of org.bukkit.block.BlockState in project Minigames by AddstarMC.
the class PulseRedstoneAction method executeNodeAction.
@Override
public void executeNodeAction(MinigamePlayer player, Node node) {
Material block = Material.REDSTONE_BLOCK;
if (torch.getFlag())
block = Material.REDSTONE_TORCH_ON;
final BlockState last = node.getLocation().getBlock().getState();
node.getLocation().getBlock().setType(block);
Bukkit.getScheduler().scheduleSyncDelayedTask(Minigames.plugin, new Runnable() {
@Override
public void run() {
last.update(true);
}
}, 20 * time.getFlag());
}
use of org.bukkit.block.BlockState in project Prism-Bukkit by prism.
the class PrismWorldEvents method onStructureGrow.
/**
*
* @param event
*/
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onStructureGrow(final StructureGrowEvent event) {
String type = "tree-grow";
final TreeType species = event.getSpecies();
if (species != null && species.name().toLowerCase().contains("mushroom"))
type = "mushroom-grow";
if (!Prism.getIgnore().event(type, event.getWorld()))
return;
for (final BlockState block : event.getBlocks()) {
if (me.botsko.elixr.BlockUtils.isGrowableStructure(block.getType())) {
String player = "Environment";
if (event.getPlayer() != null) {
player = event.getPlayer().getName();
}
RecordingQueue.addToQueue(ActionFactory.createGrow(type, block, player));
}
}
}
Aggregations