Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // workload interface
- public interface Workload {
- void compute();
- }
- // workload runnable
- public class WorkloadRunnable implements Runnable {
- private static final double MAX_MILIS_PER_TICK = 2.5;
- private static final int MAX_NANOS_PER_TICK = (int) (MAX_MILIS_PER_TICK * 1E6);
- private final Deque<Workload> workloadDeque = new ArrayDeque<>();
- public void addWorkLoad(Workload workload) {
- this.workloadDeque.add(workload);
- }
- @Override
- public void run() {
- long stopTime = System.nanoTime() + MAX_NANOS_PER_TICK;
- Workload nextLoad;
- while (System.nanoTime() <= stopTime && (nextLoad = this.workloadDeque.poll()) != null) {
- nextLoad.compute();
- }
- }
- }
- // Placeable block
- @AllArgsConstructor
- public class PlaceableBlock implements Workload {
- private final UUID worldID;
- private final int blockX;
- private final int blockY;
- private final int blockZ;
- private final Material material;
- @Override
- public void compute() {
- World world = Bukkit.getWorld(worldID);
- world.getBlockAt(blockX, blockY, blockZ).setType(material);
- }
- }
- // my code
- FileUtil util = new FileUtil(FileUtil.getDataFile("test.yml", "mines"));
- YamlConfiguration configuration = util.getConfiguration();
- Location center = new Location(player.getWorld(), 600, 50, 600);
- for (String key : configuration.getKeys(false)) {
- if (!key.equalsIgnoreCase("data")) {
- ConfigurationSection section = configuration.getConfigurationSection(key);
- double x = section.getDouble("x") + center.getX();
- double y = section.getDouble("y") + center.getY();
- double z = section.getDouble("z") + center.getZ();
- runnable.addWorkLoad(new PlaceableBlock(player.getWorld().getUID(), (int) (x), (int) (y), (int) (z), Material.valueOf(section.getString("material"))));
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment