mirror of
https://github.com/PikaMug/Quests.git
synced 2025-02-11 10:01:19 +01:00
Update WorldGuard integration for 7.0.0-beta-03+, fixes #889
This commit is contained in:
parent
07e124cd9a
commit
a272b6f694
12
main/pom.xml
12
main/pom.xml
@ -82,15 +82,15 @@
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.sk89q</groupId>
|
||||
<artifactId>worldedit</artifactId>
|
||||
<version>LATEST</version>
|
||||
<groupId>com.sk89q.worldedit</groupId>
|
||||
<artifactId>worldedit-bukkit</artifactId>
|
||||
<version>7.0.1-SNAPSHOT</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.sk89q</groupId>
|
||||
<artifactId>worldguard</artifactId>
|
||||
<version>LATEST</version>
|
||||
<groupId>com.sk89q.worldguard</groupId>
|
||||
<artifactId>worldguard-bukkit</artifactId>
|
||||
<version>7.0.1-SNAPSHOT</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
|
@ -12,7 +12,6 @@
|
||||
|
||||
package me.blackvein.quests;
|
||||
|
||||
import java.util.Iterator;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
@ -33,8 +32,6 @@ import com.codisimus.plugins.phatloots.loot.LootBundle;
|
||||
import com.gmail.nossr50.datatypes.skills.SkillType;
|
||||
import com.gmail.nossr50.util.player.UserManager;
|
||||
import com.herocraftonline.heroes.characters.Hero;
|
||||
import com.sk89q.worldguard.protection.ApplicableRegionSet;
|
||||
import com.sk89q.worldguard.protection.regions.ProtectedRegion;
|
||||
|
||||
import me.blackvein.quests.actions.Action;
|
||||
import me.blackvein.quests.events.quester.QuesterPostChangeStageEvent;
|
||||
@ -749,17 +746,11 @@ public class Quest {
|
||||
*/
|
||||
private boolean isInRegion(Player player) {
|
||||
if (region == null) {
|
||||
return true;
|
||||
} else {
|
||||
ApplicableRegionSet ars = plugin.getDependencies().getWorldGuardApi().getRegionManager(player.getWorld()).getApplicableRegions(player.getLocation());
|
||||
Iterator<ProtectedRegion> i = ars.iterator();
|
||||
while (i.hasNext()) {
|
||||
ProtectedRegion pr = i.next();
|
||||
if (pr.getId().equalsIgnoreCase(region)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
if (plugin.getDependencies().getWorldGuardApi().getApplicableRegionsIDs(player.getWorld(), player.getLocation()).contains(region)) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
@ -17,7 +17,6 @@ import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
@ -49,8 +48,6 @@ import org.bukkit.inventory.meta.BookMeta;
|
||||
import org.bukkit.inventory.meta.ItemMeta;
|
||||
|
||||
import com.alessiodp.parties.api.interfaces.Party;
|
||||
import com.sk89q.worldguard.protection.managers.RegionManager;
|
||||
import com.sk89q.worldguard.protection.regions.ProtectedRegion;
|
||||
|
||||
import de.erethon.dungeonsxl.player.DGroup;
|
||||
import me.blackvein.quests.events.quest.QuestTakeEvent;
|
||||
@ -61,7 +58,6 @@ import me.blackvein.quests.util.ItemUtil;
|
||||
import me.blackvein.quests.util.Lang;
|
||||
import me.blackvein.quests.util.LocaleQuery;
|
||||
import me.blackvein.quests.util.MiscUtil;
|
||||
import me.blackvein.quests.util.WorldGuardAPI;
|
||||
import net.citizensnpcs.api.npc.NPC;
|
||||
|
||||
public class Quester {
|
||||
@ -3182,18 +3178,7 @@ public class Quester {
|
||||
}
|
||||
if (canAcceptOffer(quest, giveReason)) {
|
||||
if (quest.getRegion() != null) {
|
||||
boolean inRegion = false;
|
||||
WorldGuardAPI api = plugin.getDependencies().getWorldGuardApi();
|
||||
RegionManager rm = api.getRegionManager(getPlayer().getWorld());
|
||||
Iterator<ProtectedRegion> it = rm.getApplicableRegions(getPlayer().getLocation()).iterator();
|
||||
while (it.hasNext()) {
|
||||
ProtectedRegion pr = it.next();
|
||||
if (pr.getId().equalsIgnoreCase(quest.getRegion())) {
|
||||
inRegion = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (inRegion == false) {
|
||||
if (!quest.isInRegion(this)) {
|
||||
if (giveReason) {
|
||||
String msg = Lang.get(getPlayer(), "questInvalidLocation");
|
||||
msg = msg.replace("<quest>", ChatColor.AQUA + quest.getName() + ChatColor.YELLOW);
|
||||
|
@ -80,8 +80,6 @@ import com.gmail.nossr50.datatypes.skills.SkillType;
|
||||
import com.gmail.nossr50.util.player.UserManager;
|
||||
import com.herocraftonline.heroes.characters.Hero;
|
||||
import com.herocraftonline.heroes.characters.classes.HeroClass;
|
||||
import com.sk89q.worldguard.protection.managers.RegionManager;
|
||||
import com.sk89q.worldguard.protection.regions.ProtectedRegion;
|
||||
|
||||
import me.blackvein.quests.actions.Action;
|
||||
import me.blackvein.quests.actions.ActionFactory;
|
||||
@ -1519,7 +1517,16 @@ public class Quests extends JavaPlugin implements ConversationAbandonedListener
|
||||
}
|
||||
if (config.contains("quests." + questKey + ".region")) {
|
||||
String region = config.getString("quests." + questKey + ".region");
|
||||
boolean exists = regionFound(quest, region);
|
||||
boolean exists = false;
|
||||
for (World world : getServer().getWorlds()) {
|
||||
if (getDependencies().getWorldGuardApi().getRegionManager(world) != null) {
|
||||
if (getDependencies().getWorldGuardApi().getRegionManager(world).hasRegion(region)) {
|
||||
quest.region = region;
|
||||
exists = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!exists) {
|
||||
skipQuestProcess("region: for Quest " + quest.getName() + " is not a valid WorldGuard region!");
|
||||
}
|
||||
@ -1983,24 +1990,6 @@ public class Quests extends JavaPlugin implements ConversationAbandonedListener
|
||||
skipQuestProcess(new String[] { msg });
|
||||
}
|
||||
|
||||
|
||||
|
||||
private boolean regionFound(Quest quest, String region) {
|
||||
boolean exists = false;
|
||||
for (World world : getServer().getWorlds()) {
|
||||
RegionManager rm = depends.getWorldGuardApi().getRegionManager(world);
|
||||
if (rm != null) {
|
||||
ProtectedRegion pr = rm.getRegion(region);
|
||||
if (pr != null) {
|
||||
quest.region = region;
|
||||
exists = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
return exists;
|
||||
}
|
||||
|
||||
@SuppressWarnings({ "unchecked", "unused" })
|
||||
private void processStages(Quest quest, FileConfiguration config, String questKey) throws StageFailedException {
|
||||
ConfigurationSection questStages = config.getConfigurationSection("quests." + questKey + ".stages.ordered");
|
||||
|
@ -67,16 +67,12 @@ import org.bukkit.inventory.EquipmentSlot;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.scheduler.BukkitRunnable;
|
||||
|
||||
import com.sk89q.worldguard.protection.managers.RegionManager;
|
||||
import com.sk89q.worldguard.protection.regions.ProtectedRegion;
|
||||
|
||||
import me.blackvein.quests.Quest;
|
||||
import me.blackvein.quests.Quester;
|
||||
import me.blackvein.quests.Quests;
|
||||
import me.blackvein.quests.Stage;
|
||||
import me.blackvein.quests.util.ItemUtil;
|
||||
import me.blackvein.quests.util.Lang;
|
||||
import me.blackvein.quests.util.WorldGuardAPI;
|
||||
import net.citizensnpcs.api.CitizensAPI;
|
||||
|
||||
public class PlayerListener implements Listener {
|
||||
@ -140,19 +136,7 @@ public class PlayerListener implements Listener {
|
||||
}
|
||||
}
|
||||
if (quest.getRegion() != null) {
|
||||
boolean inRegion = false;
|
||||
Player p = quester.getPlayer();
|
||||
WorldGuardAPI api = plugin.getDependencies().getWorldGuardApi();
|
||||
RegionManager rm = api.getRegionManager(p.getWorld());
|
||||
Iterator<ProtectedRegion> it = rm.getApplicableRegions(p.getLocation()).iterator();
|
||||
while (it.hasNext()) {
|
||||
ProtectedRegion pr = it.next();
|
||||
if (pr.getId().equalsIgnoreCase(quest.getRegion())) {
|
||||
inRegion = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (inRegion == false) {
|
||||
if (!quest.isInRegion(quester)) {
|
||||
String invalidLoc = Lang.get(player, "questInvalidLocation");
|
||||
invalidLoc = invalidLoc.replace("<quest>", ChatColor.AQUA + quest.getName() + ChatColor.YELLOW);
|
||||
player.sendMessage(ChatColor.YELLOW + invalidLoc);
|
||||
|
@ -30,17 +30,18 @@ import net.citizensnpcs.api.npc.NPC;
|
||||
public class DenizenAPI {
|
||||
private Class<?> denizen = null;
|
||||
private Class<?> scriptRegistry = null;
|
||||
private Method containsScriptGetMethod = null;
|
||||
private Method _getScriptNamesGetMethod = null;
|
||||
private Method containsScriptMethod = null;
|
||||
private Method getScriptNamesMethod = null;
|
||||
private Class<?> scriptContainer = null;
|
||||
private Class<?> taskScriptContainer = null;
|
||||
private Method getScriptContainerAsGetMethod = null;
|
||||
private Method getScriptContainerAsMethod = null;
|
||||
private Class<?> dPlayer = null;
|
||||
private Class<?> dNPC = null;
|
||||
private Method mirrorBukkitPlayerGetMethod = null;
|
||||
private Method mirrorCitizensNPCGetMethod = null;
|
||||
private Method mirrorBukkitPlayerMethod = null;
|
||||
private Method mirrorCitizensNPCMethod = null;
|
||||
private Class<?> scriptEntryData = null;
|
||||
private Class<?> bukkitScriptEntryData = null;
|
||||
private boolean initialized = false;
|
||||
|
||||
public boolean isEnabled() {
|
||||
return denizen != null;
|
||||
@ -71,16 +72,20 @@ public class DenizenAPI {
|
||||
* Initialize Denizen <1.1.0 methods
|
||||
*/
|
||||
private void initialize() {
|
||||
try {
|
||||
containsScriptGetMethod = scriptRegistry.getMethod("containsScript", String.class);
|
||||
_getScriptNamesGetMethod = scriptRegistry.getMethod("_getScriptNames");
|
||||
getScriptContainerAsGetMethod = scriptRegistry.getMethod("getScriptContainerAs", String.class, taskScriptContainer.getClass());
|
||||
mirrorBukkitPlayerGetMethod = dPlayer.getMethod("mirrorBukkitPlayer", OfflinePlayer.class);
|
||||
mirrorCitizensNPCGetMethod = dNPC.getMethod("mirrorCitizensNPC", NPC.class);
|
||||
} catch (Exception e) {
|
||||
Bukkit.getLogger().log(Level.WARNING, "Quests failed to bind to Denizen, integration will not work!", e);
|
||||
return;
|
||||
}
|
||||
if (!initialized) {
|
||||
initialized = true;
|
||||
|
||||
try {
|
||||
containsScriptMethod = scriptRegistry.getMethod("containsScript", String.class);
|
||||
getScriptNamesMethod = scriptRegistry.getMethod("_getScriptNames");
|
||||
getScriptContainerAsMethod = scriptRegistry.getMethod("getScriptContainerAs", String.class, taskScriptContainer.getClass());
|
||||
mirrorBukkitPlayerMethod = dPlayer.getMethod("mirrorBukkitPlayer", OfflinePlayer.class);
|
||||
mirrorCitizensNPCMethod = dNPC.getMethod("mirrorCitizensNPC", NPC.class);
|
||||
} catch (Exception e) {
|
||||
Bukkit.getLogger().log(Level.WARNING, "Quests failed to bind to Denizen, integration will not work!", e);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public Class<?> getDenizenClass() {
|
||||
@ -93,10 +98,10 @@ public class DenizenAPI {
|
||||
return DenizenAPI_1_1_0.containsScript(input);
|
||||
} else {
|
||||
initialize();
|
||||
if (scriptRegistry == null || containsScriptGetMethod == null) return false;
|
||||
if (scriptRegistry == null || containsScriptMethod == null) return false;
|
||||
boolean script = false;
|
||||
try {
|
||||
script = (boolean)containsScriptGetMethod.invoke(scriptRegistry, input);
|
||||
script = (boolean)containsScriptMethod.invoke(scriptRegistry, input);
|
||||
} catch (Exception e) {
|
||||
Bukkit.getLogger().log(Level.WARNING, "Quests encountered an error invoking Denizen ScriptRegistry#containsScript", e);
|
||||
}
|
||||
@ -131,10 +136,10 @@ public class DenizenAPI {
|
||||
return DenizenAPI_1_1_0._getScriptNames();
|
||||
} else {
|
||||
initialize();
|
||||
if (scriptRegistry == null || _getScriptNamesGetMethod == null) return null;
|
||||
if (scriptRegistry == null || getScriptNamesMethod == null) return null;
|
||||
Set<String> names = null;
|
||||
try {
|
||||
names = (Set<String>)_getScriptNamesGetMethod.invoke(scriptRegistry);
|
||||
names = (Set<String>)getScriptNamesMethod.invoke(scriptRegistry);
|
||||
} catch (Exception e) {
|
||||
Bukkit.getLogger().log(Level.WARNING, "Quests encountered an error invoking Denizen ScriptRegistry#_getScriptNames", e);
|
||||
}
|
||||
@ -151,7 +156,7 @@ public class DenizenAPI {
|
||||
if (scriptRegistry == null || taskScriptContainer == null) return null;
|
||||
Object container = null;
|
||||
try {
|
||||
container = getScriptContainerAsGetMethod.invoke(scriptRegistry, scriptName, taskScriptContainer);
|
||||
container = getScriptContainerAsMethod.invoke(scriptRegistry, scriptName, taskScriptContainer);
|
||||
} catch (Exception e) {
|
||||
Bukkit.getLogger().log(Level.WARNING, "Quests encountered an error invoking Denizen #getScriptContainerAs", e);
|
||||
}
|
||||
@ -165,10 +170,10 @@ public class DenizenAPI {
|
||||
return DenizenAPI_1_1_0.mirrorBukkitPlayer(player);
|
||||
} else {
|
||||
initialize();
|
||||
if (dPlayer == null || mirrorBukkitPlayerGetMethod == null) return null;
|
||||
if (dPlayer == null || mirrorBukkitPlayerMethod == null) return null;
|
||||
Object dp = null;
|
||||
try {
|
||||
dp = mirrorBukkitPlayerGetMethod.invoke(dPlayer, player);
|
||||
dp = mirrorBukkitPlayerMethod.invoke(dPlayer, player);
|
||||
} catch (Exception e) {
|
||||
Bukkit.getLogger().log(Level.WARNING, "Quests encountered an error invoking Denizen dPlayer#mirrorBukkitPlayer", e);
|
||||
}
|
||||
@ -182,10 +187,10 @@ public class DenizenAPI {
|
||||
return DenizenAPI_1_1_0.mirrorCitizensNPC(npc);
|
||||
} else {
|
||||
initialize();
|
||||
if (dNPC == null || mirrorCitizensNPCGetMethod == null) return null;
|
||||
if (dNPC == null || mirrorCitizensNPCMethod == null) return null;
|
||||
Object dp = null;
|
||||
try {
|
||||
dp = mirrorCitizensNPCGetMethod.invoke(dNPC, npc);
|
||||
dp = mirrorCitizensNPCMethod.invoke(dNPC, npc);
|
||||
} catch (Exception e) {
|
||||
Bukkit.getLogger().log(Level.WARNING, "Quests encountered an error invoking Denizen dNPC#mirrorCitizensNPC", e);
|
||||
}
|
||||
|
@ -12,31 +12,33 @@
|
||||
|
||||
package me.blackvein.quests.util;
|
||||
|
||||
import java.lang.reflect.Constructor;
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.List;
|
||||
import java.util.logging.Level;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
|
||||
import com.sk89q.worldguard.bukkit.WorldGuardPlugin;
|
||||
import com.sk89q.worldguard.domains.Association;
|
||||
import com.sk89q.worldguard.protection.ApplicableRegionSet;
|
||||
import com.sk89q.worldguard.protection.association.Associables;
|
||||
import com.sk89q.worldguard.protection.association.RegionAssociable;
|
||||
import com.sk89q.worldguard.protection.managers.RegionManager;
|
||||
|
||||
/**
|
||||
* @author NathanWolf
|
||||
*/
|
||||
public class WorldGuardAPI {
|
||||
private Object worldGuard = null;
|
||||
private Object worldGuard7 = null;
|
||||
private WorldGuardPlugin worldGuardPlugin = null;
|
||||
private Object regionContainer = null;
|
||||
private Method regionContainerGetMethod = null;
|
||||
private Method worldAdaptMethod = null;
|
||||
private Class<?> vector = null;
|
||||
private Constructor<?> vectorConstructor = null;
|
||||
private boolean initialized = false;
|
||||
|
||||
public boolean isEnabled() {
|
||||
@ -48,9 +50,8 @@ public class WorldGuardAPI {
|
||||
worldGuardPlugin = (WorldGuardPlugin)wg;
|
||||
|
||||
try {
|
||||
Class<?> worldGuardClass = Class.forName("com.sk89q.worldguard.WorldGuard");
|
||||
Method getInstanceMethod = worldGuardClass.getMethod("getInstance");
|
||||
worldGuard = getInstanceMethod.invoke(null);
|
||||
Class.forName("com.sk89q.worldguard.WorldGuard");
|
||||
worldGuard7 = WorldGuardAPI_7_0_0.getInstance();
|
||||
// WorldGuard 7+
|
||||
} catch (Exception ex) {
|
||||
// WorldGuard <7
|
||||
@ -72,27 +73,14 @@ public class WorldGuardAPI {
|
||||
private void initialize() {
|
||||
if (!initialized) {
|
||||
initialized = true;
|
||||
if (worldGuard != null) {
|
||||
// WorldGuard 7+
|
||||
try {
|
||||
Method getPlatFormMethod = worldGuard.getClass().getMethod("getPlatform");
|
||||
Object platform = getPlatFormMethod.invoke(worldGuard);
|
||||
Method getRegionContainerMethod = platform.getClass().getMethod("getRegionContainer");
|
||||
regionContainer = getRegionContainerMethod.invoke(platform);
|
||||
Class<?> worldEditWorldClass = Class.forName("com.sk89q.worldedit.world.World");
|
||||
Class<?> worldEditAdapterClass = Class.forName("com.sk89q.worldedit.bukkit.BukkitAdapter");
|
||||
worldAdaptMethod = worldEditAdapterClass.getMethod("adapt", World.class);
|
||||
regionContainerGetMethod = regionContainer.getClass().getMethod("get", worldEditWorldClass);
|
||||
} catch (Exception e) {
|
||||
Bukkit.getLogger().log(Level.WARNING, "Quests failed to bind to WorldGuard, integration will not work!", e);
|
||||
regionContainer = null;
|
||||
return;
|
||||
}
|
||||
} else {
|
||||
if (worldGuard7 == null) {
|
||||
// WorldGuard <7
|
||||
regionContainer = worldGuardPlugin.getRegionContainer();
|
||||
try {
|
||||
Method getRegionContainerMethod = worldGuardPlugin.getClass().getMethod("getRegionContainer");
|
||||
regionContainer = getRegionContainerMethod.invoke(worldGuardPlugin);
|
||||
regionContainerGetMethod = regionContainer.getClass().getMethod("get", World.class);
|
||||
vector = Class.forName("com.sk89q.worldedit.Vector");
|
||||
vectorConstructor = vector.getConstructor(double.class, double.class, double.class);
|
||||
} catch (Exception e) {
|
||||
Bukkit.getLogger().log(Level.WARNING, "Quests failed to bind to WorldGuard, integration will not work!", e);
|
||||
regionContainer = null;
|
||||
@ -108,21 +96,56 @@ public class WorldGuardAPI {
|
||||
|
||||
@Nullable
|
||||
public RegionManager getRegionManager(World world) {
|
||||
initialize();
|
||||
if (regionContainer == null || regionContainerGetMethod == null) return null;
|
||||
RegionManager regionManager = null;
|
||||
try {
|
||||
if (worldAdaptMethod != null) {
|
||||
// WorldGuard 7+
|
||||
Object worldEditWorld = worldAdaptMethod.invoke(null, world);
|
||||
regionManager = (RegionManager)regionContainerGetMethod.invoke(regionContainer, worldEditWorld);
|
||||
} else {
|
||||
// WorldGuard <7
|
||||
if (worldGuard7 != null) {
|
||||
return WorldGuardAPI_7_0_0.getRegionManager(world);
|
||||
} else {
|
||||
initialize();
|
||||
if (regionContainer == null || regionContainerGetMethod == null) return null;
|
||||
RegionManager regionManager = null;
|
||||
try {
|
||||
regionManager = (RegionManager)regionContainerGetMethod.invoke(regionContainer, world);
|
||||
} catch (Exception e) {
|
||||
Bukkit.getLogger().log(Level.WARNING, "Quests encountered an error getting WorldGuard RegionManager", e);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
Bukkit.getLogger().log(Level.WARNING, "Quests encountered an error getting WorldGuard RegionManager", e);
|
||||
}
|
||||
return regionManager;
|
||||
return regionManager;
|
||||
}
|
||||
}
|
||||
|
||||
public ApplicableRegionSet getApplicableRegions(World world, Location location) {
|
||||
if (worldGuard7 != null) {
|
||||
return WorldGuardAPI_7_0_0.getApplicableRegions(world, location);
|
||||
} else {
|
||||
initialize();
|
||||
RegionManager regionManager = getRegionManager(world);
|
||||
ApplicableRegionSet ars = null;
|
||||
if (regionManager == null) return null;
|
||||
try {
|
||||
Method getApplicableRegionsMethod = regionManager.getClass().getMethod("getApplicableRegions", Location.class);
|
||||
ars = (ApplicableRegionSet)getApplicableRegionsMethod.invoke(regionManager, location);
|
||||
} catch (Exception e) {
|
||||
Bukkit.getLogger().log(Level.WARNING, "Quests encountered an error getting RegionManager#getApplicableRegions", e);
|
||||
}
|
||||
return ars;
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public List<String> getApplicableRegionsIDs(World world, Location location) {
|
||||
if (worldGuard7 != null) {
|
||||
return WorldGuardAPI_7_0_0.getApplicableRegionsIDs(world, location);
|
||||
} else {
|
||||
initialize();
|
||||
RegionManager regionManager = getRegionManager(world);
|
||||
List<String> ari = null;
|
||||
if (regionManager == null) return null;
|
||||
try {
|
||||
Method getApplicableRegionsMethod = regionManager.getClass().getMethod("getApplicableRegionsIDs", vector);
|
||||
ari = (List<String>)getApplicableRegionsMethod.invoke(regionManager,
|
||||
vectorConstructor.newInstance(location.getX(), location.getY(), location.getZ()));
|
||||
} catch (Exception e) {
|
||||
Bukkit.getLogger().log(Level.WARNING, "Quests encountered an error getting RegionManager#getApplicableRegionsIDs", e);
|
||||
}
|
||||
return ari;
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,51 @@
|
||||
/*******************************************************************************************************
|
||||
* Continued by PikaMug (formerly HappyPikachu) with permission from _Blackvein_. All rights reserved.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
|
||||
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN
|
||||
* NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
|
||||
* OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*******************************************************************************************************/
|
||||
|
||||
package me.blackvein.quests.util;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.World;
|
||||
|
||||
import com.sk89q.worldedit.bukkit.BukkitAdapter;
|
||||
import com.sk89q.worldguard.WorldGuard;
|
||||
import com.sk89q.worldguard.protection.ApplicableRegionSet;
|
||||
import com.sk89q.worldguard.protection.managers.RegionManager;
|
||||
|
||||
/**
|
||||
* This class's imports must exist separately from WorldGuardAPI.java in order to not crash from NoClassDefFoundError at runtime
|
||||
*/
|
||||
public class WorldGuardAPI_7_0_0 {
|
||||
|
||||
@Nullable
|
||||
public static WorldGuard getInstance() {
|
||||
return WorldGuard.getInstance();
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public static RegionManager getRegionManager(World world) {
|
||||
return WorldGuard.getInstance().getPlatform().getRegionContainer().get(BukkitAdapter.adapt(world));
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public static ApplicableRegionSet getApplicableRegions(World world, Location location) {
|
||||
return getRegionManager(world).getApplicableRegions(BukkitAdapter.asBlockVector(location));
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public static List<String> getApplicableRegionsIDs(World world, Location location) {
|
||||
return getRegionManager(world).getApplicableRegionsIDs(BukkitAdapter.asBlockVector(location));
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user