-
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Does not work if chunks around the paste point are not loaded.
- Loading branch information
1 parent
29121d6
commit 12e1568
Showing
3 changed files
with
99 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
91 changes: 91 additions & 0 deletions
91
src/main/java/world/bentobox/boxed/listeners/NewAreaListener.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
package world.bentobox.boxed.listeners; | ||
|
||
import java.io.File; | ||
|
||
import org.bukkit.Bukkit; | ||
import org.bukkit.Location; | ||
import org.bukkit.configuration.ConfigurationSection; | ||
import org.bukkit.configuration.file.YamlConfiguration; | ||
import org.bukkit.event.EventHandler; | ||
import org.bukkit.event.EventPriority; | ||
import org.bukkit.event.Listener; | ||
|
||
import world.bentobox.bentobox.api.events.island.IslandCreatedEvent; | ||
import world.bentobox.bentobox.database.objects.Island; | ||
import world.bentobox.bentobox.util.Util; | ||
import world.bentobox.boxed.Boxed; | ||
|
||
/** | ||
* @author tastybento | ||
* Place structures in areas after they are created | ||
*/ | ||
public class NewAreaListener implements Listener { | ||
|
||
private final Boxed addon; | ||
private final YamlConfiguration config; | ||
|
||
/** | ||
* @param addon addon | ||
*/ | ||
public NewAreaListener(Boxed addon) { | ||
this.addon = addon; | ||
// Load the config | ||
File structureFile = new File(addon.getDataFolder(), "structures.yml"); | ||
// Check if it exists and if not, save it from the jar | ||
if (!structureFile.exists()) { | ||
addon.saveResource("structures.yml", true); | ||
} | ||
config = YamlConfiguration.loadConfiguration(structureFile); | ||
|
||
} | ||
|
||
@EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true) | ||
public void onIslandCreated(IslandCreatedEvent e) { | ||
addon.log(e.getEventName()); | ||
Island island = e.getIsland(); | ||
addon.getPlugin().getIWM().getAddon(island.getWorld()).ifPresent(gma -> addon.log(gma.getDescription().getName())); | ||
// Check if this island is in this game | ||
/* | ||
if (!addon.getPlugin().getIWM().getAddon(island.getWorld()).map(gma -> gma.equals(addon)).orElse(false)) { | ||
// Not correct addon | ||
return; | ||
}*/ | ||
Location center = island.getProtectionCenter(); | ||
ConfigurationSection section = config.getConfigurationSection("structures.new"); | ||
if (section == null) { | ||
addon.logError("structures.new not found"); | ||
return; | ||
} | ||
for (String structure : section.getKeys(false)) { | ||
addon.log(structure); | ||
String value = section.getString(structure,""); | ||
// Extract coords | ||
String[] coords = value.split(","); | ||
if (coords.length == 3) { | ||
int x = Integer.valueOf(coords[0]) + center.getBlockX(); | ||
int y = Integer.valueOf(coords[1]) + center.getBlockY(); | ||
int z = Integer.valueOf(coords[2]) + center.getBlockZ(); | ||
Util.getChunkAtAsync(center.getWorld(), x >> 4, z >> 4, true).thenAccept(c -> { | ||
// Run command | ||
String cmd = "place structure minecraft:" + structure + " " | ||
+ x + " " | ||
+ y + " " | ||
+ z + " "; | ||
Bukkit.getScheduler().runTaskLater(addon.getPlugin(), () -> { | ||
addon.log("run command " + cmd); | ||
addon.getServer().dispatchCommand(Bukkit.getConsoleSender(), cmd); | ||
}, 1000); | ||
}); | ||
|
||
} else { | ||
addon.logError("Structure file syntax error: " + structure + " " + value); | ||
} | ||
|
||
} | ||
|
||
|
||
} | ||
|
||
|
||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
structures: | ||
new-island: | ||
"minecraft:village": 100,0,100 |