Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import com.sk89q.worldedit.bukkit.WorldEditPlugin;
- import com.sk89q.worldedit.bukkit.selections.Selection;
- import net.menoni.rd.Debugger;
- import net.menoni.rd.RuntimeDebugger;
- import org.bukkit.Bukkit;
- import org.bukkit.Location;
- import org.bukkit.Material;
- import org.bukkit.World;
- import org.bukkit.block.Block;
- import org.bukkit.block.BlockFace;
- import org.bukkit.command.CommandSender;
- import org.bukkit.entity.Player;
- import java.security.SecureRandom;
- import java.util.ArrayList;
- import java.util.List;
- import java.util.Random;
- public class FillFlowers implements Debugger {
- private static List<Blocky> flowerList;
- private static Random random;
- private static class Blocky {
- private Material material;
- private byte data;
- private int height;
- private int weight;
- public Blocky(Material material, int weight) {
- this(material, (byte) 0, weight);
- }
- public Blocky(Material material, int data, int weight) {
- this(material, data, 1, weight);
- }
- public Blocky(Material material, int data, int height, int weight) {
- this.material = material;
- this.height = height;
- this.data = (byte) data;
- this.weight = weight;
- }
- public int getHeight() {
- return height;
- }
- public Material getMaterial() {
- return material;
- }
- public byte getData() {
- return data;
- }
- public int getWeight() {
- return this.weight;
- }
- }
- static {
- random = new SecureRandom();
- flowerList = new ArrayList<>();
- flowerList.add(new Blocky(Material.YELLOW_FLOWER, 1));
- flowerList.add(new Blocky(Material.LONG_GRASS, 1, 5));
- flowerList.add(new Blocky(Material.LONG_GRASS, 2, 5));
- flowerList.add(new Blocky(Material.RED_ROSE, 0, 1));
- flowerList.add(new Blocky(Material.RED_ROSE, 1, 1));
- flowerList.add(new Blocky(Material.RED_ROSE, 2, 1));
- flowerList.add(new Blocky(Material.RED_ROSE, 3, 1));
- flowerList.add(new Blocky(Material.RED_ROSE, 4, 1));
- flowerList.add(new Blocky(Material.RED_ROSE, 5, 1));
- flowerList.add(new Blocky(Material.RED_ROSE, 6, 1));
- flowerList.add(new Blocky(Material.RED_ROSE, 7, 1));
- flowerList.add(new Blocky(Material.RED_ROSE, 8, 1));
- flowerList.add(new Blocky(Material.DOUBLE_PLANT, 0, 2, 1));
- flowerList.add(new Blocky(Material.DOUBLE_PLANT, 1, 2, 1));
- flowerList.add(new Blocky(Material.DOUBLE_PLANT, 4, 2, 1));
- flowerList.add(new Blocky(Material.DOUBLE_PLANT, 5, 2, 1));
- }
- @Override
- public void debug(RuntimeDebugger runtimeDebugger, CommandSender commandSender) {
- if (!(commandSender instanceof Player)) {
- commandSender.sendMessage("Only players can run this script.");
- return;
- }
- Player player = (Player) commandSender;
- WorldEditPlugin worldEdit = (WorldEditPlugin) Bukkit.getServer().getPluginManager().getPlugin("WorldEdit");
- if (worldEdit == null) {
- player.sendMessage("Unable to indicate WorldEdit plugin presence...");
- return;
- }
- Selection selection = worldEdit.getSelection(player);
- if (selection == null) {
- player.sendMessage("You need to make a selection with worldedit first");
- return;
- }
- World world = selection.getWorld();
- Location min = selection.getMinimumPoint();
- Location max = selection.getMaximumPoint();
- int placed = 0;
- player.sendMessage("Starting flower placement...");
- for (int x = min.getBlockX(); x <= max.getBlockX(); x++) {
- for (int y = min.getBlockY(); y <= max.getBlockY(); y++) {
- for (int z = min.getBlockZ(); z <= max.getBlockZ(); z++) {
- Block block = world.getBlockAt(x, y, z);
- if (block == null) {
- continue;
- }
- if (block.getType() != Material.GRASS) {
- continue;
- }
- Block oneUp = block.getRelative(BlockFace.UP, 1);
- Block twoUp = block.getRelative(BlockFace.UP, 2);
- if (!((oneUp == null || oneUp.getType() == Material.AIR) && (twoUp == null || twoUp.getType() == Material.AIR))) {
- continue;
- }
- placeRandomFlower(oneUp);
- placed++;
- }
- }
- }
- player.sendMessage("Placed " + placed + " flowers!");
- }
- public Blocky getRandomFlower() {
- Blocky res = null;
- int totalWeight = 0;
- for (Blocky blocky : flowerList) {
- totalWeight += blocky.getWeight();
- }
- while (res == null) {
- int index = random.nextInt(totalWeight);
- for (Blocky blocky : flowerList) {
- index -= blocky.getWeight();
- if (index <= 0) {
- res = blocky;
- break;
- }
- }
- }
- return res;
- }
- public void placeRandomFlower(Block airBlock) {
- if (random.nextBoolean()) {
- return;
- }
- Blocky flower = getRandomFlower();
- airBlock.setType(flower.getMaterial());
- airBlock.setData(flower.getData());
- if (flower.getHeight() > 1) {
- Block up = airBlock.getRelative(BlockFace.UP);
- up.setType(flower.getMaterial());
- up.setData((byte) 8);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment