Guest User

Untitled

a guest
Dec 23rd, 2022
14
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.04 KB | None | 0 0
  1. // workload interface
  2.  
  3. public interface Workload {
  4.  
  5. void compute();
  6. }
  7.  
  8. // workload runnable
  9.  
  10. public class WorkloadRunnable implements Runnable {
  11. private static final double MAX_MILIS_PER_TICK = 2.5;
  12. private static final int MAX_NANOS_PER_TICK = (int) (MAX_MILIS_PER_TICK * 1E6);
  13.  
  14. private final Deque<Workload> workloadDeque = new ArrayDeque<>();
  15.  
  16. public void addWorkLoad(Workload workload) {
  17. this.workloadDeque.add(workload);
  18. }
  19.  
  20. @Override
  21. public void run() {
  22. long stopTime = System.nanoTime() + MAX_NANOS_PER_TICK;
  23.  
  24. Workload nextLoad;
  25.  
  26. while (System.nanoTime() <= stopTime && (nextLoad = this.workloadDeque.poll()) != null) {
  27. nextLoad.compute();
  28. }
  29. }
  30. }
  31.  
  32. // Placeable block
  33.  
  34. @AllArgsConstructor
  35. public class PlaceableBlock implements Workload {
  36. private final UUID worldID;
  37. private final int blockX;
  38. private final int blockY;
  39. private final int blockZ;
  40. private final Material material;
  41.  
  42. @Override
  43. public void compute() {
  44. World world = Bukkit.getWorld(worldID);
  45. world.getBlockAt(blockX, blockY, blockZ).setType(material);
  46. }
  47. }
  48.  
  49. // my code
  50.  
  51. FileUtil util = new FileUtil(FileUtil.getDataFile("test.yml", "mines"));
  52. YamlConfiguration configuration = util.getConfiguration();
  53. Location center = new Location(player.getWorld(), 600, 50, 600);
  54.  
  55. for (String key : configuration.getKeys(false)) {
  56. if (!key.equalsIgnoreCase("data")) {
  57. ConfigurationSection section = configuration.getConfigurationSection(key);
  58. double x = section.getDouble("x") + center.getX();
  59. double y = section.getDouble("y") + center.getY();
  60. double z = section.getDouble("z") + center.getZ();
  61.  
  62. runnable.addWorkLoad(new PlaceableBlock(player.getWorld().getUID(), (int) (x), (int) (y), (int) (z), Material.valueOf(section.getString("material"))));
  63. }
  64. }
Advertisement
Add Comment
Please, Sign In to add comment