3
0
Mirror von https://github.com/Moulberry/AxiomPaperPlugin.git synchronisiert 2024-11-08 17:40:04 +01:00

Preliminary WorldGuard support

Dieser Commit ist enthalten in:
Moulberry 2023-09-06 13:31:10 +08:00
Ursprung 02c65bc807
Commit d4eb0a3721
4 geänderte Dateien mit 116 neuen und 1 gelöschten Zeilen

Datei anzeigen

@ -17,8 +17,11 @@ java {
}
repositories {
mavenCentral()
maven("https://s01.oss.sonatype.org/content/repositories/snapshots/")
maven("https://jitpack.io")
maven("https://maven.enginehub.org/repo/")
maven("https://repo.papermc.io/repository/maven-public/")
}
dependencies {
@ -27,6 +30,14 @@ dependencies {
// Zstd Compression Library
implementation("com.github.luben:zstd-jni:1.5.5-4")
// WorldGuard support
compileOnly("com.sk89q.worldguard:worldguard-bukkit:7.1.0-SNAPSHOT")
// PlotSquared support
implementation(platform("com.intellectualsites.bom:bom-newest:1.37"))
compileOnly("com.intellectualsites.plotsquared:plotsquared-core")
compileOnly("com.intellectualsites.plotsquared:plotsquared-bukkit") { isTransitive = false }
}
tasks {

Datei anzeigen

@ -0,0 +1,27 @@
package com.moulberry.axiom.integration;
import org.bukkit.Bukkit;
import org.bukkit.World;
import org.bukkit.entity.Player;
public class RegionProtection {
private final RegionProtectionWorldGuard worldGuard;
public RegionProtection(Player player, World world) {
if (Bukkit.getPluginManager().isPluginEnabled("WorldGuard")) {
this.worldGuard = RegionProtectionWorldGuard.tryCreate(player, world);
} else {
this.worldGuard = null;
}
}
public boolean canBuildInSection(int cx, int cy, int cz) {
if (this.worldGuard != null && !this.worldGuard.canBuildInSection(cx, cy, cz)) return false;
// todo: PlotSquared
return true;
}
}

Datei anzeigen

@ -0,0 +1,57 @@
package com.moulberry.axiom.integration;
import com.sk89q.worldedit.bukkit.BukkitAdapter;
import com.sk89q.worldedit.math.BlockVector3;
import com.sk89q.worldguard.LocalPlayer;
import com.sk89q.worldguard.WorldGuard;
import com.sk89q.worldguard.bukkit.WorldGuardPlugin;
import com.sk89q.worldguard.internal.platform.WorldGuardPlatform;
import com.sk89q.worldguard.protection.ApplicableRegionSet;
import com.sk89q.worldguard.protection.flags.Flags;
import com.sk89q.worldguard.protection.managers.RegionManager;
import com.sk89q.worldguard.protection.regions.ProtectedCuboidRegion;
import com.sk89q.worldguard.protection.regions.ProtectedRegion;
import com.sk89q.worldguard.protection.regions.RegionContainer;
import com.sk89q.worldguard.protection.regions.RegionQuery;
import org.bukkit.World;
import org.bukkit.entity.Player;
import org.jetbrains.annotations.Nullable;
public class RegionProtectionWorldGuard {
private final LocalPlayer player;
private final RegionManager regionManager;
public RegionProtectionWorldGuard(LocalPlayer player, RegionManager regionManager) {
this.player = player;
this.regionManager = regionManager;
}
@Nullable
public static RegionProtectionWorldGuard tryCreate(Player player, World world) {
WorldGuardPlatform platform = WorldGuard.getInstance().getPlatform();
RegionContainer regionContainer = platform.getRegionContainer();
com.sk89q.worldedit.world.World worldEditWorld = BukkitAdapter.adapt(world);
LocalPlayer worldGuardPlayer = WorldGuardPlugin.inst().wrapPlayer(player);
// Don't do any protection if player has bypass
if (platform.getSessionManager().hasBypass(worldGuardPlayer, worldEditWorld)) {
return null;
}
RegionManager regionManager = regionContainer.get(worldEditWorld);
if (regionManager == null) return null;
return new RegionProtectionWorldGuard(worldGuardPlayer, regionManager);
}
public boolean canBuildInSection(int cx, int cy, int cz) {
BlockVector3 min = BlockVector3.at(cx*16, cy*16, cz*16);
BlockVector3 max = BlockVector3.at(cx*16+15, cy*16+15, cz*16+15);
ProtectedRegion test = new ProtectedCuboidRegion("dummy", min, max);
ApplicableRegionSet regions = this.regionManager.getApplicableRegions(test, RegionQuery.QueryOption.COMPUTE_PARENTS);
return regions.testState(this.player, Flags.BUILD);
}
}

Datei anzeigen

@ -5,6 +5,21 @@ import com.moulberry.axiom.buffer.BiomeBuffer;
import com.moulberry.axiom.buffer.BlockBuffer;
import com.moulberry.axiom.buffer.CompressedBlockEntity;
import com.moulberry.axiom.event.AxiomModifyWorldEvent;
import com.moulberry.axiom.integration.RegionProtection;
import com.sk89q.worldedit.bukkit.BukkitAdapter;
import com.sk89q.worldedit.math.BlockVector3;
import com.sk89q.worldedit.world.World;
import com.sk89q.worldguard.LocalPlayer;
import com.sk89q.worldguard.WorldGuard;
import com.sk89q.worldguard.bukkit.WorldGuardPlugin;
import com.sk89q.worldguard.protection.ApplicableRegionSet;
import com.sk89q.worldguard.protection.flags.Flags;
import com.sk89q.worldguard.protection.flags.StateFlag;
import com.sk89q.worldguard.protection.managers.RegionManager;
import com.sk89q.worldguard.protection.regions.ProtectedCuboidRegion;
import com.sk89q.worldguard.protection.regions.ProtectedRegion;
import com.sk89q.worldguard.protection.regions.RegionContainer;
import com.sk89q.worldguard.protection.regions.RegionQuery;
import io.netty.buffer.Unpooled;
import it.unimi.dsi.fastutil.longs.Long2ObjectMap;
import it.unimi.dsi.fastutil.shorts.Short2ObjectMap;
@ -34,7 +49,6 @@ import net.minecraft.world.level.levelgen.Heightmap;
import net.minecraft.world.level.lighting.LightEngine;
import org.bukkit.Bukkit;
import org.bukkit.NamespacedKey;
import org.bukkit.World;
import org.bukkit.craftbukkit.v1_20_R1.CraftWorld;
import org.bukkit.craftbukkit.v1_20_R1.entity.CraftPlayer;
import org.bukkit.entity.Player;
@ -102,6 +116,8 @@ public class SetBlockBufferPacketListener {
Bukkit.getPluginManager().callEvent(modifyWorldEvent);
if (modifyWorldEvent.isCancelled()) return;
RegionProtection regionProtection = new RegionProtection(player.getBukkitEntity(), world.getWorld());
// Allowed, apply buffer
BlockPos.MutableBlockPos blockPos = new BlockPos.MutableBlockPos();
@ -119,6 +135,10 @@ public class SetBlockBufferPacketListener {
continue;
}
if (!regionProtection.canBuildInSection(cx, cy, cz)) {
continue;
}
LevelChunk chunk = world.getChunk(cx, cz);
chunk.setUnsaved(true);