Skip to content

Commit

Permalink
Load all known templates when loading.
Browse files Browse the repository at this point in the history
  • Loading branch information
tastybento committed Mar 11, 2023
1 parent 4ea09ea commit c308414
Show file tree
Hide file tree
Showing 2 changed files with 1,053 additions and 20 deletions.
28 changes: 8 additions & 20 deletions src/main/java/world/bentobox/boxed/listeners/NewAreaListener.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import org.bukkit.loot.LootTables;
import org.bukkit.scheduler.BukkitTask;
import org.bukkit.structure.Structure;
import org.bukkit.util.BoundingBox;
import org.bukkit.util.Vector;
Expand Down Expand Up @@ -66,8 +65,6 @@ public class NewAreaListener implements Listener {
private record Item(String name, Structure structure, Location location, StructureRotation rot, Mirror mirror) {};
Pair<Integer, Integer> min = new Pair<Integer, Integer>(0,0);
Pair<Integer, Integer> max = new Pair<Integer, Integer>(0,0);
private BukkitTask task;
private int i;


/**
Expand All @@ -93,31 +90,22 @@ private void BuildItem() {
}

/**
* Workaround for https://hub.spigotmc.org/jira/browse/SPIGOT-7288
* Build a list of structures
* @param event event
*/
@EventHandler()
public void onBentoBoxReady(BentoBoxReadyEvent event) {
World seedBase = Bukkit.getWorld("seed_base");
if (seedBase == null) {
addon.logError("No seed base world!");
return;
}
addon.saveResource("templates.yml", false);
File templateFile = new File(addon.getDataFolder(), "templates.yml");
if (templateFile.exists()) {
YamlConfiguration loader = YamlConfiguration.loadConfiguration(templateFile);
List<String> list = loader.getStringList("templates");
task = Bukkit.getScheduler().runTaskTimer(addon.getPlugin(), () -> {
if (i == list.size()) {
task.cancel();
return;
}
String struct = list.get(i++);
Bukkit.getServer().dispatchCommand(Bukkit.getConsoleSender(), "execute in " + seedBase.getName() + " run place template " + struct + " 10000 120 10000");



}, 0, 10);
for (String struct : list) {
Structure s = Bukkit.getStructureManager().loadStructure(NamespacedKey.fromString(struct));
if (s == null) {
BentoBox.getInstance().log("Now loading group from: " + struct);
}
}
}

}
Expand Down

0 comments on commit c308414

Please sign in to comment.