Skip to content

Commit

Permalink
Add FastAsyncWorldEdit support
Browse files Browse the repository at this point in the history
  • Loading branch information
T14D3 committed Jan 9, 2025
1 parent b1b5362 commit ece6867
Show file tree
Hide file tree
Showing 3 changed files with 70 additions and 0 deletions.
3 changes: 3 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ dependencies {
compileOnly 'io.papermc.paper:paper-api:1.21.1-R0.1-SNAPSHOT'
compileOnly 'com.sk89q.worldedit:worldedit-bukkit:7.3.0'
//paperweight.paperDevBundle("1.21.1-R0.1-SNAPSHOT")
implementation(platform("com.intellectualsites.bom:bom-newest:1.52"))
compileOnly("com.fastasyncworldedit:FastAsyncWorldEdit-Core")
compileOnly("com.fastasyncworldedit:FastAsyncWorldEdit-Bukkit")
}

def targetJavaVersion = 21
Expand Down
6 changes: 6 additions & 0 deletions src/main/java/de/t14d3/zones/Zones.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package de.t14d3.zones;

import com.fastasyncworldedit.core.util.WEManager;
import com.sk89q.worldedit.WorldEdit;
import de.t14d3.zones.integrations.FAWEIntegration;
import de.t14d3.zones.integrations.WorldEditSession;
import de.t14d3.zones.listeners.CommandListener;
import de.t14d3.zones.listeners.PlayerInteractListener;
Expand Down Expand Up @@ -99,6 +101,10 @@ public void onEnable() {
WorldEdit.getInstance().getEventBus().register(new WorldEditSession(this));
getLogger().info("WorldEdit Integration enabled.");
}
if (getServer().getPluginManager().getPlugin("FastAsyncWorldEdit") != null) {
WEManager.weManager().addManager(new FAWEIntegration(this));
getLogger().info("FAWE Integration enabled.");
}

getLogger().info("Zones plugin has been enabled! Loaded " + regionManager.loadedRegions.size() + " regions.");
}
Expand Down
61 changes: 61 additions & 0 deletions src/main/java/de/t14d3/zones/integrations/FAWEIntegration.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
package de.t14d3.zones.integrations;

import com.fastasyncworldedit.bukkit.regions.BukkitMaskManager;
import com.fastasyncworldedit.core.regions.FaweMask;
import com.sk89q.worldedit.bukkit.BukkitAdapter;
import com.sk89q.worldedit.regions.CuboidRegion;
import de.t14d3.zones.Region;
import de.t14d3.zones.Zones;
import org.bukkit.Location;
import org.bukkit.entity.Player;

import java.util.List;

public class FAWEIntegration extends BukkitMaskManager {

private final Zones plugin;

public FAWEIntegration(final Zones plugin) {
super(plugin.getName());
this.plugin = plugin;
}

public boolean isAllowed(Player player, Region region, MaskType type) {
return region != null &&
(region.isAdmin(player.getUniqueId()) ||
type == MaskType.MEMBER && (
plugin.getPermissionManager().hasPermission(player.getUniqueId(), "PLACE", "true", region)
|| plugin.getPermissionManager().hasPermission(player.getUniqueId(), "BREAK", "true", region)));
}

@Override
public FaweMask getMask(final com.sk89q.worldedit.entity.Player wePlayer, final MaskType type, boolean isWhitelist) {
final Player player = BukkitAdapter.adapt(wePlayer);
final Location location = player.getLocation();
List<Region> regions = plugin.getRegionManager().getRegionsAt(location);
if (!regions.isEmpty()) {
boolean isAllowed = true;
for (Region region : regions) {
if (!isAllowed(player, region, type)) {
isAllowed = false;
break;
}
}
if (isAllowed) {
final Location pos1 = regions.get(0).getMin();
final Location pos2 = regions.get(0).getMax();
final Region region = regions.get(0);
return new FaweMask(new CuboidRegion(BukkitAdapter.asBlockVector(pos1), BukkitAdapter.asBlockVector(pos2))) {
@Override
public boolean isValid(com.sk89q.worldedit.entity.Player player, MaskType type) {
return isAllowed(BukkitAdapter.adapt(player), region, type);
}
};
}
}


return null;
}

}

0 comments on commit ece6867

Please sign in to comment.