-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
162 additions
and
30 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
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
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
58 changes: 58 additions & 0 deletions
58
src/main/java/de/t14d3/zones/integrations/WorldGuardImporter.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,58 @@ | ||
package de.t14d3.zones.integrations; | ||
|
||
import com.sk89q.worldedit.bukkit.BukkitAdapter; | ||
import com.sk89q.worldguard.WorldGuard; | ||
import com.sk89q.worldguard.protection.regions.ProtectedRegion; | ||
import com.sk89q.worldguard.protection.regions.RegionContainer; | ||
import com.sk89q.worldguard.protection.regions.RegionType; | ||
import de.t14d3.zones.Region; | ||
import de.t14d3.zones.Zones; | ||
import org.bukkit.Location; | ||
import org.bukkit.World; | ||
|
||
import java.util.HashMap; | ||
import java.util.Map; | ||
import java.util.UUID; | ||
|
||
public class WorldGuardImporter { | ||
|
||
private final Zones plugin; | ||
|
||
public WorldGuardImporter(Zones plugin) { | ||
this.plugin = plugin; | ||
} | ||
|
||
public void importRegions() { | ||
final int[] count = {0}; | ||
new Thread(() -> { | ||
RegionContainer container = WorldGuard.getInstance().getPlatform().getRegionContainer(); | ||
|
||
for (World world : plugin.getServer().getWorlds()) { | ||
for (Map.Entry<String, ProtectedRegion> entry : container.get(BukkitAdapter.adapt(world)).getRegions().entrySet()) { | ||
ProtectedRegion region = entry.getValue(); | ||
if (!region.getType().equals(RegionType.CUBOID)) { | ||
continue; | ||
} | ||
String key; | ||
do { | ||
key = UUID.randomUUID().toString().substring(0, 8); | ||
} while (plugin.getRegionManager().regions().containsKey(key)); | ||
String name = entry.getKey(); | ||
Location min = BukkitAdapter.adapt(world, region.getMinimumPoint()); | ||
Location max = BukkitAdapter.adapt(world, region.getMaximumPoint()); | ||
Map<UUID, Map<String, String>> members = new HashMap<>(); | ||
Map<String, String> tempPerms = Map.of("role", "member"); | ||
|
||
region.getMembers().getUniqueIds().forEach(uuid -> members.put(uuid, tempPerms)); | ||
|
||
Region newRegion = plugin.getRegionManager().createNewRegion(key, name, min, max, members); | ||
plugin.getRegionManager().addRegion(newRegion); | ||
count[0]++; | ||
} | ||
|
||
} | ||
|
||
plugin.getLogger().info("Imported " + count[0] + " regions from WorldGuard."); | ||
}).start(); | ||
} | ||
} |
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
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