mirror of
https://github.com/MassiveCraft/Factions.git
synced 2024-11-30 06:03:59 +01:00
Support WorldGuard 6 and 7.
This commit is contained in:
parent
760a5f4e78
commit
6c8f6b5f97
40
pom.xml
40
pom.xml
@ -159,6 +159,46 @@
|
||||
</exclusion>
|
||||
</exclusions>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.sk89q</groupId>
|
||||
<artifactId>worldguard</artifactId>
|
||||
<version>6.1.1-SNAPSHOT</version>
|
||||
<scope>provided</scope>
|
||||
<exclusions>
|
||||
<exclusion>
|
||||
<artifactId>bukkit</artifactId>
|
||||
<groupId>org.bukkit</groupId>
|
||||
</exclusion>
|
||||
<exclusion>
|
||||
<artifactId>bukkit-classloader-check</artifactId>
|
||||
<groupId>com.sk89q.spigot</groupId>
|
||||
</exclusion>
|
||||
<exclusion>
|
||||
<artifactId>commandbook</artifactId>
|
||||
<groupId>com.sk89q</groupId>
|
||||
</exclusion>
|
||||
<exclusion>
|
||||
<artifactId>jsr305</artifactId>
|
||||
<groupId>com.google.code.findbugs</groupId>
|
||||
</exclusion>
|
||||
<exclusion>
|
||||
<artifactId>js</artifactId>
|
||||
<groupId>rhino</groupId>
|
||||
</exclusion>
|
||||
<exclusion>
|
||||
<artifactId>truezip</artifactId>
|
||||
<groupId>de.schlichtherle</groupId>
|
||||
</exclusion>
|
||||
<exclusion>
|
||||
<artifactId>jchronic</artifactId>
|
||||
<groupId>com.sk89q</groupId>
|
||||
</exclusion>
|
||||
<exclusion>
|
||||
<artifactId>worldedit</artifactId>
|
||||
<groupId>com.sk89q</groupId>
|
||||
</exclusion>
|
||||
</exclusions>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.sk89q.worldguard</groupId>
|
||||
<artifactId>worldguard-legacy</artifactId>
|
||||
|
@ -5,9 +5,7 @@ import com.google.gson.GsonBuilder;
|
||||
import com.google.gson.reflect.TypeToken;
|
||||
import com.massivecraft.factions.cmd.CmdAutoHelp;
|
||||
import com.massivecraft.factions.cmd.FCmdRoot;
|
||||
import com.massivecraft.factions.integration.Econ;
|
||||
import com.massivecraft.factions.integration.Essentials;
|
||||
import com.massivecraft.factions.integration.Worldguard;
|
||||
import com.massivecraft.factions.integration.*;
|
||||
import com.massivecraft.factions.integration.dynmap.EngineDynmap;
|
||||
import com.massivecraft.factions.listeners.*;
|
||||
import com.massivecraft.factions.struct.ChatMode;
|
||||
@ -23,13 +21,10 @@ import com.massivecraft.factions.zcore.MPlugin;
|
||||
import com.massivecraft.factions.zcore.fperms.Access;
|
||||
import com.massivecraft.factions.zcore.fperms.Permissable;
|
||||
import com.massivecraft.factions.zcore.fperms.PermissableAction;
|
||||
import com.massivecraft.factions.zcore.util.TextUtil;
|
||||
import net.milkbowl.vault.permission.Permission;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.player.AsyncPlayerChatEvent;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
@ -37,7 +32,9 @@ import org.bukkit.plugin.RegisteredServiceProvider;
|
||||
|
||||
import java.lang.reflect.Modifier;
|
||||
import java.lang.reflect.Type;
|
||||
import java.util.*;
|
||||
import java.util.HashSet;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.logging.Level;
|
||||
|
||||
public class P extends MPlugin {
|
||||
@ -71,6 +68,7 @@ public class P extends MPlugin {
|
||||
|
||||
public SeeChunkUtil seeChunkUtil;
|
||||
public ParticleProvider particleProvider;
|
||||
public IWorldguard worldguard;
|
||||
|
||||
public P() {
|
||||
p = this;
|
||||
@ -125,9 +123,7 @@ public class P extends MPlugin {
|
||||
Econ.setup();
|
||||
setupPermissions();
|
||||
|
||||
if (Conf.worldGuardChecking || Conf.worldGuardBuildPriority) {
|
||||
Worldguard.init(this);
|
||||
}
|
||||
loadWorldguard();
|
||||
|
||||
EngineDynmap.getInstance().init();
|
||||
|
||||
@ -174,6 +170,33 @@ public class P extends MPlugin {
|
||||
this.loadSuccessful = true;
|
||||
}
|
||||
|
||||
private void loadWorldguard() {
|
||||
if (!Conf.worldGuardChecking && !Conf.worldGuardBuildPriority) {
|
||||
log(Level.INFO, "Not enabling WorldGuard check since no options for it are enabled.");
|
||||
return;
|
||||
}
|
||||
|
||||
Plugin plugin = getServer().getPluginManager().getPlugin("WorldGuard");
|
||||
if (plugin != null) {
|
||||
String version = plugin.getDescription().getVersion();
|
||||
if (version.startsWith("6")) {
|
||||
this.worldguard = new Worldguard6();
|
||||
log(Level.INFO, "Found support for WorldGuard version " + version);
|
||||
} else if (version.startsWith("7")) {
|
||||
this.worldguard = new Worldguard7();
|
||||
log(Level.INFO, "Found support for WorldGuard version " + version);
|
||||
} else {
|
||||
P.p.log(Level.WARNING, "Loaded WorldGuard but couldn't support this version: " + version);
|
||||
}
|
||||
} else {
|
||||
P.p.log(Level.WARNING, "WorldGuard checks were turned in on conf.json, but WorldGuard isn't present on the server.");
|
||||
}
|
||||
}
|
||||
|
||||
public IWorldguard getWorldguard() {
|
||||
return this.worldguard;
|
||||
}
|
||||
|
||||
private void setupPlaceholderAPI() {
|
||||
Plugin clip = getServer().getPluginManager().getPlugin("PlaceholderAPI");
|
||||
if (clip != null && clip.isEnabled()) {
|
||||
@ -223,10 +246,10 @@ public class P extends MPlugin {
|
||||
Type accessTypeAdatper = new TypeToken<Map<Permissable, Map<PermissableAction, Access>>>() {
|
||||
}.getType();
|
||||
|
||||
Type factionMaterialType = new TypeToken<FactionMaterial>(){
|
||||
Type factionMaterialType = new TypeToken<FactionMaterial>() {
|
||||
}.getType();
|
||||
|
||||
Type materialType = new TypeToken<Material>(){
|
||||
Type materialType = new TypeToken<Material>() {
|
||||
}.getType();
|
||||
|
||||
return new GsonBuilder()
|
||||
|
@ -0,0 +1,15 @@
|
||||
package com.massivecraft.factions.integration;
|
||||
|
||||
import com.massivecraft.factions.FLocation;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
public interface IWorldguard {
|
||||
|
||||
public boolean isPVP(Player player);
|
||||
|
||||
public boolean playerCanBuild(Player player, Location loc);
|
||||
|
||||
public boolean checkForRegionsInChunk(FLocation flocation);
|
||||
|
||||
}
|
@ -0,0 +1,71 @@
|
||||
package com.massivecraft.factions.integration;
|
||||
|
||||
import com.massivecraft.factions.FLocation;
|
||||
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.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.Chunk;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
public class Worldguard6 implements IWorldguard {
|
||||
|
||||
// PVP Flag check
|
||||
// Returns:
|
||||
// True: PVP is allowed
|
||||
// False: PVP is disallowed
|
||||
public boolean isPVP(Player player) {
|
||||
LocalPlayer localPlayer = WorldGuardPlugin.inst().wrapPlayer(player);
|
||||
RegionContainer container = WorldGuard.getInstance().getPlatform().getRegionContainer();
|
||||
RegionQuery query = container.createQuery();
|
||||
|
||||
return query.testState(localPlayer.getLocation(), localPlayer, Flags.PVP);
|
||||
}
|
||||
|
||||
// Check if player can build at location by worldguards rules.
|
||||
// Returns:
|
||||
// True: Player can build in the region.
|
||||
// False: Player can not build in the region.
|
||||
public boolean playerCanBuild(Player player, Location loc) {
|
||||
LocalPlayer localPlayer = WorldGuardPlugin.inst().wrapPlayer(player);
|
||||
RegionContainer container = WorldGuard.getInstance().getPlatform().getRegionContainer();
|
||||
RegionQuery query = container.createQuery();
|
||||
|
||||
return query.testBuild(localPlayer.getLocation(), localPlayer);
|
||||
}
|
||||
|
||||
public boolean checkForRegionsInChunk(FLocation flocation) {
|
||||
Chunk chunk = flocation.getChunk();
|
||||
|
||||
RegionContainer container = WorldGuard.getInstance().getPlatform().getRegionContainer();
|
||||
RegionManager regions = container.get(BukkitAdapter.adapt(chunk.getWorld()));
|
||||
if (regions == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
World world = chunk.getWorld();
|
||||
int minChunkX = chunk.getX() << 4;
|
||||
int minChunkZ = chunk.getZ() << 4;
|
||||
int maxChunkX = minChunkX + 15;
|
||||
int maxChunkZ = minChunkZ + 15;
|
||||
|
||||
int worldHeight = world.getMaxHeight(); // Allow for heights other than default
|
||||
|
||||
BlockVector3 min = BlockVector3.at(minChunkX, 0, minChunkZ);
|
||||
BlockVector3 max = BlockVector3.at(maxChunkX, worldHeight, maxChunkZ);
|
||||
ProtectedRegion region = new ProtectedCuboidRegion("wgregionflagcheckforfactions", min, max);
|
||||
ApplicableRegionSet set = regions.getApplicableRegions(region);
|
||||
|
||||
return set.size() > 1;
|
||||
}
|
||||
}
|
@ -1,7 +1,6 @@
|
||||
package com.massivecraft.factions.integration;
|
||||
|
||||
import com.massivecraft.factions.FLocation;
|
||||
import com.massivecraft.factions.P;
|
||||
import com.sk89q.worldedit.bukkit.BukkitAdapter;
|
||||
import com.sk89q.worldedit.math.BlockVector3;
|
||||
import com.sk89q.worldguard.LocalPlayer;
|
||||
@ -18,37 +17,14 @@ import org.bukkit.Chunk;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
|
||||
public class Worldguard {
|
||||
|
||||
private static boolean enabled = false;
|
||||
|
||||
public static void init(Plugin plugin) {
|
||||
Plugin wgplug = plugin.getServer().getPluginManager().getPlugin("WorldGuard");
|
||||
if (wgplug == null) {
|
||||
enabled = false;
|
||||
P.p.log("Could not hook to WorldGuard. WorldGuard checks are disabled.");
|
||||
} else {
|
||||
enabled = true;
|
||||
P.p.log("Successfully hooked to WorldGuard.");
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean isEnabled() {
|
||||
return enabled;
|
||||
}
|
||||
public class Worldguard7 implements IWorldguard {
|
||||
|
||||
// PVP Flag check
|
||||
// Returns:
|
||||
// True: PVP is allowed
|
||||
// False: PVP is disallowed
|
||||
public static boolean isPVP(Player player) {
|
||||
if (!enabled) {
|
||||
// No WG hooks so we'll always bypass this check.
|
||||
return true;
|
||||
}
|
||||
|
||||
public boolean isPVP(Player player) {
|
||||
LocalPlayer localPlayer = WorldGuardPlugin.inst().wrapPlayer(player);
|
||||
RegionContainer container = WorldGuard.getInstance().getPlatform().getRegionContainer();
|
||||
RegionQuery query = container.createQuery();
|
||||
@ -60,12 +36,7 @@ public class Worldguard {
|
||||
// Returns:
|
||||
// True: Player can build in the region.
|
||||
// False: Player can not build in the region.
|
||||
public static boolean playerCanBuild(Player player, Location loc) {
|
||||
if (!enabled) {
|
||||
// No WG hooks so we'll always bypass this check.
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean playerCanBuild(Player player, Location loc) {
|
||||
LocalPlayer localPlayer = WorldGuardPlugin.inst().wrapPlayer(player);
|
||||
RegionContainer container = WorldGuard.getInstance().getPlatform().getRegionContainer();
|
||||
RegionQuery query = container.createQuery();
|
||||
@ -73,17 +44,12 @@ public class Worldguard {
|
||||
return query.testBuild(localPlayer.getLocation(), localPlayer);
|
||||
}
|
||||
|
||||
public static boolean checkForRegionsInChunk(FLocation flocation) {
|
||||
if (!enabled) {
|
||||
// No WG hooks so we'll always bypass this check.
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean checkForRegionsInChunk(FLocation flocation) {
|
||||
Chunk chunk = flocation.getChunk();
|
||||
|
||||
RegionContainer container = WorldGuard.getInstance().getPlatform().getRegionContainer();
|
||||
RegionManager regions = container.get(BukkitAdapter.adapt(chunk.getWorld()));
|
||||
if (regions == null){
|
||||
if (regions == null) {
|
||||
return false;
|
||||
}
|
||||
|
@ -1,12 +1,11 @@
|
||||
package com.massivecraft.factions.listeners;
|
||||
|
||||
import com.massivecraft.factions.*;
|
||||
import com.massivecraft.factions.integration.Worldguard;
|
||||
import com.massivecraft.factions.integration.Worldguard7;
|
||||
import com.massivecraft.factions.struct.Permission;
|
||||
import com.massivecraft.factions.struct.Relation;
|
||||
import com.massivecraft.factions.zcore.fperms.Access;
|
||||
import com.massivecraft.factions.zcore.fperms.PermissableAction;
|
||||
import com.massivecraft.factions.zcore.util.TL;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.block.Block;
|
||||
@ -192,7 +191,7 @@ public class FactionsBlockListener implements Listener {
|
||||
Faction otherFaction = Board.getInstance().getFactionAt(loc);
|
||||
|
||||
if (otherFaction.isWilderness()) {
|
||||
if (Conf.worldGuardBuildPriority && Worldguard.playerCanBuild(player, location)) {
|
||||
if (Conf.worldGuardBuildPriority && P.p.getWorldguard() != null && P.p.getWorldguard().playerCanBuild(player, location)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -206,7 +205,7 @@ public class FactionsBlockListener implements Listener {
|
||||
|
||||
return false;
|
||||
} else if (otherFaction.isSafeZone()) {
|
||||
if (Conf.worldGuardBuildPriority && Worldguard.playerCanBuild(player, location)) {
|
||||
if (Conf.worldGuardBuildPriority && P.p.getWorldguard() != null && P.p.getWorldguard().playerCanBuild(player, location)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -220,7 +219,7 @@ public class FactionsBlockListener implements Listener {
|
||||
|
||||
return false;
|
||||
} else if (otherFaction.isWarZone()) {
|
||||
if (Conf.worldGuardBuildPriority && Worldguard.playerCanBuild(player, location)) {
|
||||
if (Conf.worldGuardBuildPriority && P.p.getWorldguard() != null && P.p.getWorldguard().playerCanBuild(player, location)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -7,7 +7,7 @@ import com.massivecraft.factions.iface.EconomyParticipator;
|
||||
import com.massivecraft.factions.iface.RelationParticipator;
|
||||
import com.massivecraft.factions.integration.Econ;
|
||||
import com.massivecraft.factions.integration.Essentials;
|
||||
import com.massivecraft.factions.integration.Worldguard;
|
||||
import com.massivecraft.factions.integration.Worldguard7;
|
||||
import com.massivecraft.factions.scoreboards.FScoreboard;
|
||||
import com.massivecraft.factions.scoreboards.sidebar.FInfoSidebar;
|
||||
import com.massivecraft.factions.struct.ChatMode;
|
||||
@ -731,7 +731,7 @@ public abstract class MemoryFPlayer implements FPlayer {
|
||||
int factionBuffer = P.p.getConfig().getInt("hcf.buffer-zone", 0);
|
||||
int worldBuffer = P.p.getConfig().getInt("world-border.buffer", 0);
|
||||
|
||||
if (Conf.worldGuardChecking && Worldguard.checkForRegionsInChunk(flocation)) {
|
||||
if (Conf.worldGuardChecking && P.p.getWorldguard() != null && P.p.getWorldguard().checkForRegionsInChunk(flocation)) {
|
||||
// Checks for WorldGuard regions in the chunk attempting to be claimed
|
||||
error = P.p.txt.parse(TL.CLAIM_PROTECTED.toString());
|
||||
} else if (Conf.worldsNoClaiming.contains(flocation.getWorldName())) {
|
||||
|
Loading…
Reference in New Issue
Block a user