Refactor RegionProtection
Alle Prüfungen waren erfolgreich
SteamWarCI Build successful

Dieser Commit ist enthalten in:
Lixfel 2023-09-07 16:21:13 +02:00
Ursprung 35c4443996
Commit 7d82fed462
4 geänderte Dateien mit 26 neuen und 31 gelöschten Zeilen

Datei anzeigen

@ -4,24 +4,20 @@ import org.bukkit.Bukkit;
import org.bukkit.World; import org.bukkit.World;
import org.bukkit.entity.Player; 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) { BiFunction<Player, World, RegionProtection> getProtection = Bukkit.getPluginManager().isPluginEnabled("WorldGuard") ? WorldGuardProtection::create : (player, world) -> new Dummy();
if (Bukkit.getPluginManager().isPluginEnabled("WorldGuard")) {
this.worldGuard = RegionProtectionWorldGuard.tryCreate(player, world); boolean canBuildInSection(int cx, int cy, int cz);
} else {
this.worldGuard = null; 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;
}
} }

Datei anzeigen

@ -7,7 +7,7 @@ import java.util.function.IntFunction;
public interface VersionTranslator { 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); IntFunction<Integer> blockStateMapper(Player player);

Datei anzeigen

@ -15,37 +15,36 @@ import com.sk89q.worldguard.protection.regions.RegionContainer;
import com.sk89q.worldguard.protection.regions.RegionQuery; import com.sk89q.worldguard.protection.regions.RegionQuery;
import org.bukkit.World; import org.bukkit.World;
import org.bukkit.entity.Player; 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 LocalPlayer player;
private final RegionManager regionManager; private final RegionManager regionManager;
public RegionProtectionWorldGuard(LocalPlayer player, RegionManager regionManager) { public WorldGuardProtection(LocalPlayer player, RegionManager regionManager) {
this.player = player; this.player = player;
this.regionManager = regionManager; this.regionManager = regionManager;
} }
@Nullable public static RegionProtection create(Player player, World world) {
public static RegionProtectionWorldGuard tryCreate(Player player, World world) { com.sk89q.worldedit.world.World worldGuardWorld = BukkitAdapter.adapt(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); LocalPlayer worldGuardPlayer = WorldGuardPlugin.inst().wrapPlayer(player);
// Don't do any protection if player has bypass // Don't do any protection if player has bypass
if (platform.getSessionManager().hasBypass(worldGuardPlayer, worldEditWorld)) { if (platform.getSessionManager().hasBypass(worldGuardPlayer, worldGuardWorld)) {
return null; return new RegionProtection.Dummy();
} }
RegionManager regionManager = regionContainer.get(worldEditWorld); RegionManager regionManager = regionContainer.get(worldGuardWorld);
if (regionManager == null) return null; 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) { public boolean canBuildInSection(int cx, int cy, int cz) {
BlockVector3 min = BlockVector3.at(cx*16, cy*16, cz*16); BlockVector3 min = BlockVector3.at(cx*16, cy*16, cz*16);
BlockVector3 max = BlockVector3.at(cx*16+15, cy*16+15, cz*16+15); BlockVector3 max = BlockVector3.at(cx*16+15, cy*16+15, cz*16+15);

Datei anzeigen

@ -93,7 +93,7 @@ public class SetBlockBufferPacketListener implements AxiomPacketListener {
Bukkit.getPluginManager().callEvent(modifyWorldEvent); Bukkit.getPluginManager().callEvent(modifyWorldEvent);
if (modifyWorldEvent.isCancelled()) return; if (modifyWorldEvent.isCancelled()) return;
RegionProtection regionProtection = new RegionProtection(player, world.getWorld()); RegionProtection regionProtection = RegionProtection.getProtection.apply(player, world.getWorld());
// Allowed, apply buffer // Allowed, apply buffer
BlockPos.MutableBlockPos blockPos = new BlockPos.MutableBlockPos(); BlockPos.MutableBlockPos blockPos = new BlockPos.MutableBlockPos();