geforkt von Mirrors/AxiomPaperPlugin
Dieser Commit ist enthalten in:
Ursprung
35c4443996
Commit
7d82fed462
|
@ -4,24 +4,20 @@ import org.bukkit.Bukkit;
|
|||
import org.bukkit.World;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
public class RegionProtection {
|
||||
import java.util.function.BiFunction;
|
||||
|
||||
private final RegionProtectionWorldGuard worldGuard;
|
||||
public interface RegionProtection {
|
||||
|
||||
public RegionProtection(Player player, World world) {
|
||||
if (Bukkit.getPluginManager().isPluginEnabled("WorldGuard")) {
|
||||
this.worldGuard = RegionProtectionWorldGuard.tryCreate(player, world);
|
||||
} else {
|
||||
this.worldGuard = null;
|
||||
BiFunction<Player, World, RegionProtection> getProtection = Bukkit.getPluginManager().isPluginEnabled("WorldGuard") ? WorldGuardProtection::create : (player, world) -> new Dummy();
|
||||
|
||||
boolean canBuildInSection(int cx, int cy, int cz);
|
||||
|
||||
class Dummy implements RegionProtection {
|
||||
|
||||
@Override
|
||||
public boolean canBuildInSection(int cx, int cy, int cz) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -7,7 +7,7 @@ import java.util.function.IntFunction;
|
|||
|
||||
public interface VersionTranslator {
|
||||
|
||||
VersionTranslator impl = Bukkit.getPluginManager().getPlugin("ViaVersion") != null ? new ViaVersionTranslator() : new Dummy();
|
||||
VersionTranslator impl = Bukkit.getPluginManager().isPluginEnabled("ViaVersion") ? new ViaVersionTranslator() : new Dummy();
|
||||
|
||||
IntFunction<Integer> blockStateMapper(Player player);
|
||||
|
||||
|
|
|
@ -15,37 +15,36 @@ 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 {
|
||||
public class WorldGuardProtection implements RegionProtection {
|
||||
|
||||
private static final WorldGuardPlatform platform = WorldGuard.getInstance().getPlatform();
|
||||
private static final RegionContainer regionContainer = platform.getRegionContainer();
|
||||
|
||||
private final LocalPlayer player;
|
||||
private final RegionManager regionManager;
|
||||
|
||||
public RegionProtectionWorldGuard(LocalPlayer player, RegionManager regionManager) {
|
||||
public WorldGuardProtection(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);
|
||||
public static RegionProtection create(Player player, World world) {
|
||||
com.sk89q.worldedit.world.World worldGuardWorld = 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;
|
||||
if (platform.getSessionManager().hasBypass(worldGuardPlayer, worldGuardWorld)) {
|
||||
return new RegionProtection.Dummy();
|
||||
}
|
||||
|
||||
RegionManager regionManager = regionContainer.get(worldEditWorld);
|
||||
if (regionManager == null) return null;
|
||||
RegionManager regionManager = regionContainer.get(worldGuardWorld);
|
||||
if (regionManager == null) return new RegionProtection.Dummy();
|
||||
|
||||
return new RegionProtectionWorldGuard(worldGuardPlayer, regionManager);
|
||||
return new WorldGuardProtection(worldGuardPlayer, regionManager);
|
||||
}
|
||||
|
||||
@Override
|
||||
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);
|
|
@ -93,7 +93,7 @@ public class SetBlockBufferPacketListener implements AxiomPacketListener {
|
|||
Bukkit.getPluginManager().callEvent(modifyWorldEvent);
|
||||
if (modifyWorldEvent.isCancelled()) return;
|
||||
|
||||
RegionProtection regionProtection = new RegionProtection(player, world.getWorld());
|
||||
RegionProtection regionProtection = RegionProtection.getProtection.apply(player, world.getWorld());
|
||||
|
||||
// Allowed, apply buffer
|
||||
BlockPos.MutableBlockPos blockPos = new BlockPos.MutableBlockPos();
|
||||
|
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren