mirror of
https://github.com/ChestShop-authors/ChestShop-3.git
synced 2024-06-23 12:54:45 +02:00
Update to WorldGuard 7.0.0 (for 1.13)
This commit is contained in:
parent
cf9e5bafde
commit
b972e79132
42
pom.xml
42
pom.xml
|
@ -201,20 +201,31 @@
|
|||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.sk89q</groupId>
|
||||
<artifactId>worldguard</artifactId>
|
||||
<version>6.1.1-SNAPSHOT</version>
|
||||
<groupId>javax.persistence</groupId>
|
||||
<artifactId>persistence-api</artifactId>
|
||||
<version>1.0</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.google.code.findbugs</groupId>
|
||||
<artifactId>jsr305</artifactId>
|
||||
<version>3.0.2</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.sk89q.worldedit</groupId>
|
||||
<artifactId>worldedit</artifactId>
|
||||
<version>7.0-SNAPSHOT</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.sk89q.worldguard</groupId>
|
||||
<artifactId>worldguard-legacy</artifactId>
|
||||
<version>7.0-SNAPSHOT</version>
|
||||
<scope>provided</scope>
|
||||
<exclusions>
|
||||
<exclusion>
|
||||
<groupId>org.bukkit</groupId>
|
||||
<artifactId>bukkit</artifactId>
|
||||
</exclusion>
|
||||
<exclusion>
|
||||
<groupId>org.bukkit</groupId>
|
||||
<artifactId>craftbukkit</artifactId>
|
||||
</exclusion>
|
||||
</exclusions>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
|
@ -312,6 +323,7 @@
|
|||
<include>net.gravitydevelopment.updater</include>
|
||||
<include>com.j256.ormlite</include>
|
||||
<include>org.apache.logging.log4j</include>
|
||||
<include>javax.persistence</include>
|
||||
</includes>
|
||||
</artifactSet>
|
||||
<relocations>
|
||||
|
@ -331,6 +343,10 @@
|
|||
<pattern>com.j256.ormlite</pattern>
|
||||
<shadedPattern>com.Acrobot.ChestShop.ORMlite</shadedPattern>
|
||||
</relocation>
|
||||
<relocation>
|
||||
<pattern>javax.persistence</pattern>
|
||||
<shadedPattern>com.Acrobot.ChestShop.javax.persistence</shadedPattern>
|
||||
</relocation>
|
||||
</relocations>
|
||||
</configuration>
|
||||
</execution>
|
||||
|
|
|
@ -86,6 +86,12 @@ public class ChestShop extends JavaPlugin {
|
|||
plugin = this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onLoad() {
|
||||
Dependencies.initializePlugins();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onEnable() {
|
||||
Configuration.pairFileAndClass(loadFile("config.yml"), Properties.class);
|
||||
Configuration.pairFileAndClass(loadFile("local.yml"), Messages.class);
|
||||
|
|
|
@ -6,7 +6,6 @@ import com.Acrobot.ChestShop.Listeners.Economy.Plugins.ReserveListener;
|
|||
import com.Acrobot.ChestShop.Listeners.Economy.Plugins.VaultListener;
|
||||
import com.Acrobot.ChestShop.Plugins.*;
|
||||
import com.sk89q.worldguard.bukkit.WorldGuardPlugin;
|
||||
import net.tnemc.core.Reserve;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
|
@ -17,7 +16,8 @@ import org.bukkit.plugin.PluginManager;
|
|||
* @author Acrobot
|
||||
*/
|
||||
public class Dependencies {
|
||||
public static boolean loadPlugins() {
|
||||
|
||||
public static void initializePlugins() {
|
||||
PluginManager pluginManager = Bukkit.getPluginManager();
|
||||
|
||||
for (String dependency : ChestShop.getDependencies()) {
|
||||
|
@ -27,6 +27,40 @@ public class Dependencies {
|
|||
initializePlugin(dependency, plugin);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static void initializePlugin(String name, Plugin plugin) { //Really messy, right? But it's short and fast :)
|
||||
Dependency dependency;
|
||||
|
||||
try {
|
||||
dependency = Dependency.valueOf(name);
|
||||
} catch (IllegalArgumentException exception) {
|
||||
return;
|
||||
}
|
||||
|
||||
switch (dependency) {
|
||||
//Terrain protection plugins
|
||||
case WorldGuard:
|
||||
if (Properties.WORLDGUARD_USE_FLAG) {
|
||||
WorldGuardFlags.ENABLE_SHOP.getName(); // force the static code to run
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
PluginDescriptionFile description = plugin.getDescription();
|
||||
ChestShop.getBukkitLogger().info(description.getName() + " version " + description.getVersion() + " loaded.");
|
||||
}
|
||||
|
||||
public static boolean loadPlugins() {
|
||||
PluginManager pluginManager = Bukkit.getPluginManager();
|
||||
|
||||
for (String dependency : ChestShop.getDependencies()) {
|
||||
Plugin plugin = pluginManager.getPlugin(dependency);
|
||||
|
||||
if (plugin != null) {
|
||||
loadPlugin(dependency, plugin);
|
||||
}
|
||||
}
|
||||
|
||||
return loadEconomy();
|
||||
}
|
||||
|
@ -56,7 +90,7 @@ public class Dependencies {
|
|||
return true;
|
||||
}
|
||||
|
||||
private static void initializePlugin(String name, Plugin plugin) { //Really messy, right? But it's short and fast :)
|
||||
private static void loadPlugin(String name, Plugin plugin) { //Really messy, right? But it's short and fast :)
|
||||
Dependency dependency;
|
||||
|
||||
try {
|
||||
|
|
|
@ -2,10 +2,13 @@ package com.Acrobot.ChestShop.Plugins;
|
|||
|
||||
import com.Acrobot.ChestShop.Configuration.Properties;
|
||||
import com.Acrobot.ChestShop.Events.Protection.BuildPermissionEvent;
|
||||
import com.sk89q.worldedit.bukkit.BukkitUtil;
|
||||
import com.sk89q.worldedit.bukkit.BukkitAdapter;
|
||||
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.DefaultFlag;
|
||||
import com.sk89q.worldguard.protection.flags.StateFlag;
|
||||
import com.sk89q.worldguard.protection.managers.RegionManager;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
|
@ -15,23 +18,29 @@ import org.bukkit.event.Listener;
|
|||
*/
|
||||
public class WorldGuardBuilding implements Listener {
|
||||
private WorldGuardPlugin worldGuard;
|
||||
private WorldGuardPlatform worldGuardPlatform;
|
||||
|
||||
public WorldGuardBuilding(WorldGuardPlugin plugin) {
|
||||
this.worldGuard = plugin;
|
||||
this.worldGuardPlatform = WorldGuard.getInstance().getPlatform();
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void canBuild(BuildPermissionEvent event) {
|
||||
ApplicableRegionSet regions = getApplicableRegions(event.getSign().getBlock().getLocation());
|
||||
|
||||
if (Properties.WORLDGUARD_USE_FLAG) {
|
||||
event.allow(regions.allows(DefaultFlag.ENABLE_SHOP));
|
||||
if (regions != null && Properties.WORLDGUARD_USE_FLAG) {
|
||||
event.allow(regions.queryState(worldGuard.wrapPlayer(event.getPlayer()), WorldGuardFlags.ENABLE_SHOP) == StateFlag.State.ALLOW);
|
||||
} else {
|
||||
event.allow(regions.size() != 0);
|
||||
event.allow(regions == null || regions.size() != 0);
|
||||
}
|
||||
}
|
||||
|
||||
private ApplicableRegionSet getApplicableRegions(Location location) {
|
||||
return worldGuard.getGlobalRegionManager().get(location.getWorld()).getApplicableRegions(BukkitUtil.toVector(location));
|
||||
RegionManager regionManager = worldGuardPlatform.getRegionContainer().get(BukkitAdapter.adapt(location.getWorld()));
|
||||
if (regionManager == null) {
|
||||
return null;
|
||||
}
|
||||
return regionManager.getApplicableRegions(BukkitAdapter.adapt(location).toVector());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,21 @@
|
|||
package com.Acrobot.ChestShop.Plugins;
|
||||
import com.sk89q.worldguard.protection.flags.Flags;
|
||||
import com.sk89q.worldguard.protection.flags.StateFlag;
|
||||
import com.sk89q.worldguard.protection.flags.registry.FlagConflictException;
|
||||
|
||||
/**
|
||||
* @author Brokkonaut
|
||||
*/
|
||||
public class WorldGuardFlags {
|
||||
public static final StateFlag ENABLE_SHOP;
|
||||
|
||||
static {
|
||||
StateFlag enableShop;
|
||||
try {
|
||||
enableShop = Flags.register(new StateFlag("allow-shop", false));
|
||||
} catch (FlagConflictException | IllegalStateException e) {
|
||||
enableShop = (StateFlag) Flags.get("allow-shop");
|
||||
}
|
||||
ENABLE_SHOP = enableShop;
|
||||
}
|
||||
}
|
|
@ -2,11 +2,14 @@ package com.Acrobot.ChestShop.Plugins;
|
|||
|
||||
import com.Acrobot.ChestShop.Events.Protection.ProtectionCheckEvent;
|
||||
import com.sk89q.worldedit.Vector;
|
||||
import com.sk89q.worldedit.bukkit.BukkitUtil;
|
||||
import com.sk89q.worldedit.bukkit.BukkitAdapter;
|
||||
import com.sk89q.worldguard.LocalPlayer;
|
||||
import com.sk89q.worldguard.WorldGuard;
|
||||
import com.sk89q.worldguard.bukkit.WorldGuardPlugin;
|
||||
import com.sk89q.worldguard.internal.permission.RegionPermissionModel;
|
||||
import com.sk89q.worldguard.internal.platform.WorldGuardPlatform;
|
||||
import com.sk89q.worldguard.protection.ApplicableRegionSet;
|
||||
import com.sk89q.worldguard.protection.flags.DefaultFlag;
|
||||
import com.sk89q.worldguard.protection.flags.Flags;
|
||||
import com.sk89q.worldguard.protection.managers.RegionManager;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.entity.Player;
|
||||
|
@ -19,9 +22,11 @@ import org.bukkit.event.Listener;
|
|||
*/
|
||||
public class WorldGuardProtection implements Listener {
|
||||
private WorldGuardPlugin worldGuard;
|
||||
private WorldGuardPlatform worldGuardPlatform;
|
||||
|
||||
public WorldGuardProtection(WorldGuardPlugin worldGuard) {
|
||||
this.worldGuard = worldGuard;
|
||||
this.worldGuardPlatform = WorldGuard.getInstance().getPlatform();
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
|
@ -33,8 +38,11 @@ public class WorldGuardProtection implements Listener {
|
|||
Block block = event.getBlock();
|
||||
Player player = event.getPlayer();
|
||||
|
||||
Vector blockPos = BukkitUtil.toVector(block);
|
||||
RegionManager manager = worldGuard.getRegionManager(block.getWorld());
|
||||
Vector blockPos = BukkitAdapter.adapt(block.getLocation()).toVector();
|
||||
RegionManager manager = worldGuardPlatform.getRegionContainer().get(BukkitAdapter.adapt(block.getWorld()));
|
||||
if (manager == null) {
|
||||
return;
|
||||
}
|
||||
ApplicableRegionSet set = manager.getApplicableRegions(blockPos);
|
||||
|
||||
LocalPlayer localPlayer = worldGuard.wrapPlayer(player);
|
||||
|
@ -45,8 +53,8 @@ public class WorldGuardProtection implements Listener {
|
|||
}
|
||||
|
||||
private boolean canAccess(LocalPlayer player, Block block, ApplicableRegionSet set) {
|
||||
return worldGuard.getGlobalRegionManager().hasBypass(player, block.getWorld())
|
||||
|| set.testState(player, DefaultFlag.BUILD)
|
||||
|| set.testState(player, DefaultFlag.CHEST_ACCESS);
|
||||
return new RegionPermissionModel(player).mayIgnoreRegionProtection(BukkitAdapter.adapt(block.getWorld()))
|
||||
|| set.testState(player, Flags.BUILD)
|
||||
|| set.testState(player, Flags.CHEST_ACCESS);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user