mirror of
https://github.com/mcMMO-Dev/mcMMO.git
synced 2024-11-22 13:16:45 +01:00
Improved WG compatibility + Tree Feller will now damage unbreaking
enchant tools again
This commit is contained in:
parent
214974e3a3
commit
a135e08e12
@ -1,5 +1,15 @@
|
|||||||
Version 2.1.89
|
Version 2.1.89
|
||||||
|
When using WG with mcMMO, mcMMO now examines WG during runtime to determine if its a compatible version or not, see the notes
|
||||||
Fixed a bug that could result in Tree Feller failing to remove parts of a tree
|
Fixed a bug that could result in Tree Feller failing to remove parts of a tree
|
||||||
|
Updated Japanese locale (thanks snake)
|
||||||
|
|
||||||
|
NOTES:
|
||||||
|
https://mcmmo.org/wiki/World_guard - A list of WG flags
|
||||||
|
It is not necessary to have WG installed, but if you do have WG installed mcMMO hooks into it to provide some additional features.
|
||||||
|
|
||||||
|
Previously mcMMO used to determine if WG was compatible just by checking to see if it was version 7 of WG, however version 7 of WG is not guaranteed to be compatible as necessary classes that mcMMO hooks into were added during its development and some users are still running early dev versions of WG7.
|
||||||
|
In order to decrease the chance of error, mcMMO now uses reflection when checking to see if WG is compatible in addition to checking its version number, if its not compatible mcMMO will print a message and refrain from hooking into WG.
|
||||||
|
WG is an optional dependency for mcMMO, and unfortunately before this change if mcMMO thought you were running a compatible version of WG and it turned out you weren't then mcMMO would not function correctly.
|
||||||
|
|
||||||
Version 2.1.88
|
Version 2.1.88
|
||||||
mcMMO is now more compatible with a plugin named Project Korra
|
mcMMO is now more compatible with a plugin named Project Korra
|
||||||
|
2
pom.xml
2
pom.xml
@ -173,7 +173,7 @@
|
|||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.sk89q.worldguard</groupId>
|
<groupId>com.sk89q.worldguard</groupId>
|
||||||
<artifactId>worldguard-core</artifactId>
|
<artifactId>worldguard-core</artifactId>
|
||||||
<version>7.0.0-SNAPSHOT</version>
|
<version>7.0.1-SNAPSHOT</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.sk89q.worldguard</groupId>
|
<groupId>com.sk89q.worldguard</groupId>
|
||||||
|
@ -0,0 +1,13 @@
|
|||||||
|
package com.gmail.nossr50.commands.admin;
|
||||||
|
|
||||||
|
import org.bukkit.command.Command;
|
||||||
|
import org.bukkit.command.CommandExecutor;
|
||||||
|
import org.bukkit.command.CommandSender;
|
||||||
|
|
||||||
|
public class PlayerDebug implements CommandExecutor {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
@ -45,6 +45,7 @@ import com.gmail.nossr50.util.scoreboards.ScoreboardManager;
|
|||||||
import com.gmail.nossr50.util.skills.RankUtils;
|
import com.gmail.nossr50.util.skills.RankUtils;
|
||||||
import com.gmail.nossr50.util.upgrade.UpgradeManager;
|
import com.gmail.nossr50.util.upgrade.UpgradeManager;
|
||||||
import com.gmail.nossr50.worldguard.WorldGuardManager;
|
import com.gmail.nossr50.worldguard.WorldGuardManager;
|
||||||
|
import com.gmail.nossr50.worldguard.WorldGuardUtils;
|
||||||
import com.google.common.base.Charsets;
|
import com.google.common.base.Charsets;
|
||||||
import net.shatteredlands.shatt.backup.ZipLibrary;
|
import net.shatteredlands.shatt.backup.ZipLibrary;
|
||||||
import org.bstats.bukkit.Metrics;
|
import org.bstats.bukkit.Metrics;
|
||||||
@ -309,8 +310,12 @@ public class mcMMO extends JavaPlugin {
|
|||||||
@Override
|
@Override
|
||||||
public void onLoad()
|
public void onLoad()
|
||||||
{
|
{
|
||||||
if(getServer().getPluginManager().getPlugin("WorldGuard") != null)
|
if(getServer().getPluginManager().getPlugin("WorldGuard") != null) {
|
||||||
WorldGuardManager.getInstance().registerFlags();
|
//Make sure WG is compatible before proceeding
|
||||||
|
if(WorldGuardUtils.isWorldGuardLoaded()) {
|
||||||
|
WorldGuardManager.getInstance().registerFlags();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -148,9 +148,8 @@ public final class Woodcutting {
|
|||||||
* @return True if the tool can sustain the durability loss
|
* @return True if the tool can sustain the durability loss
|
||||||
*/
|
*/
|
||||||
protected static boolean handleDurabilityLoss(Set<BlockState> treeFellerBlocks, ItemStack inHand) {
|
protected static boolean handleDurabilityLoss(Set<BlockState> treeFellerBlocks, ItemStack inHand) {
|
||||||
|
//Treat the NBT tag for unbreakable and the durability enchant differently
|
||||||
if((inHand.getItemMeta().getEnchants().get(Enchantment.DURABILITY) != null && inHand.getItemMeta().getEnchants().get(Enchantment.DURABILITY) >= 1)
|
if(inHand.getItemMeta() != null && inHand.getItemMeta().isUnbreakable()) {
|
||||||
|| (inHand.getItemMeta() != null && inHand.getItemMeta().isUnbreakable())) {
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -24,11 +24,6 @@ public class WorldGuardManager {
|
|||||||
return instance;
|
return instance;
|
||||||
}
|
}
|
||||||
|
|
||||||
public WorldGuardManager()
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean hasMainFlag(Player player)
|
public boolean hasMainFlag(Player player)
|
||||||
{
|
{
|
||||||
if(player == null)
|
if(player == null)
|
||||||
@ -37,7 +32,6 @@ public class WorldGuardManager {
|
|||||||
BukkitPlayer localPlayer = BukkitAdapter.adapt(player);
|
BukkitPlayer localPlayer = BukkitAdapter.adapt(player);
|
||||||
com.sk89q.worldedit.util.Location loc = localPlayer.getLocation();
|
com.sk89q.worldedit.util.Location loc = localPlayer.getLocation();
|
||||||
|
|
||||||
|
|
||||||
//WorldGuardPlugin worldGuard = getWorldGuard();
|
//WorldGuardPlugin worldGuard = getWorldGuard();
|
||||||
RegionContainer container = WorldGuard.getInstance().getPlatform().getRegionContainer();
|
RegionContainer container = WorldGuard.getInstance().getPlatform().getRegionContainer();
|
||||||
RegionQuery query = container.createQuery();
|
RegionQuery query = container.createQuery();
|
||||||
@ -101,8 +95,6 @@ public class WorldGuardManager {
|
|||||||
FlagRegistry registry = WorldGuard.getInstance().getFlagRegistry();
|
FlagRegistry registry = WorldGuard.getInstance().getFlagRegistry();
|
||||||
try {
|
try {
|
||||||
// register our flag with the registry
|
// register our flag with the registry
|
||||||
/*registry.register(WorldGuardFlags.MCMMO_ENABLE_WG_FLAG);
|
|
||||||
registry.register(WorldGuardFlags.MCMMO_XP_WG_FLAG);*/
|
|
||||||
registry.register(WorldGuardFlags.MCMMO_ENABLE_WG_FLAG);
|
registry.register(WorldGuardFlags.MCMMO_ENABLE_WG_FLAG);
|
||||||
registry.register(WorldGuardFlags.MCMMO_XP_WG_FLAG);
|
registry.register(WorldGuardFlags.MCMMO_XP_WG_FLAG);
|
||||||
registry.register(WorldGuardFlags.MCMMO_HARDCORE_WG_FLAG);
|
registry.register(WorldGuardFlags.MCMMO_HARDCORE_WG_FLAG);
|
||||||
|
@ -4,58 +4,122 @@ import com.gmail.nossr50.mcMMO;
|
|||||||
import com.sk89q.worldguard.bukkit.WorldGuardPlugin;
|
import com.sk89q.worldguard.bukkit.WorldGuardPlugin;
|
||||||
import org.bukkit.plugin.Plugin;
|
import org.bukkit.plugin.Plugin;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
|
||||||
import static org.bukkit.Bukkit.getServer;
|
import static org.bukkit.Bukkit.getServer;
|
||||||
|
|
||||||
public class WorldGuardUtils {
|
public class WorldGuardUtils {
|
||||||
private static WorldGuardPlugin worldGuardPluginRef;
|
private static WorldGuardPlugin worldGuardPluginRef;
|
||||||
private static boolean isLoaded = false;
|
private static boolean isLoaded = false;
|
||||||
private static boolean hasWarned = false;
|
private static boolean detectedIncompatibleWG = false;
|
||||||
|
private static final ArrayList<String> WGClassList;
|
||||||
|
|
||||||
|
static {
|
||||||
|
/*
|
||||||
|
These are the classes mcMMO tries to hook into for WG support, if any of them are missing it is safe to consider WG is not compatible
|
||||||
|
com.sk89q.worldedit.bukkit.BukkitAdapter
|
||||||
|
com.sk89q.worldedit.bukkit.BukkitPlayer
|
||||||
|
com.sk89q.worldguard.WorldGuard
|
||||||
|
com.sk89q.worldguard.bukkit.WorldGuardPlugin
|
||||||
|
com.sk89q.worldguard.protection.flags.registry.FlagConflictException
|
||||||
|
com.sk89q.worldguard.protection.flags.registry.FlagRegistry
|
||||||
|
com.sk89q.worldguard.protection.regions.RegionContainer
|
||||||
|
com.sk89q.worldguard.protection.regions.RegionQuery
|
||||||
|
*/
|
||||||
|
|
||||||
|
WGClassList = new ArrayList<>();
|
||||||
|
WGClassList.add("com.sk89q.worldedit.bukkit.BukkitAdapter");
|
||||||
|
WGClassList.add("com.sk89q.worldedit.bukkit.BukkitPlayer");
|
||||||
|
WGClassList.add("com.sk89q.worldguard.WorldGuard");
|
||||||
|
WGClassList.add("com.sk89q.worldguard.bukkit.WorldGuardPlugin");
|
||||||
|
WGClassList.add("com.sk89q.worldguard.protection.flags.registry.FlagConflictException");
|
||||||
|
WGClassList.add("com.sk89q.worldguard.protection.flags.registry.FlagRegistry");
|
||||||
|
WGClassList.add("com.sk89q.worldguard.protection.regions.RegionContainer");
|
||||||
|
WGClassList.add("com.sk89q.worldguard.protection.regions.RegionQuery");
|
||||||
|
}
|
||||||
|
|
||||||
public static boolean isWorldGuardLoaded()
|
public static boolean isWorldGuardLoaded()
|
||||||
{
|
{
|
||||||
|
if(detectedIncompatibleWG)
|
||||||
|
return false;
|
||||||
|
|
||||||
WorldGuardPlugin plugin = getWorldGuard();
|
WorldGuardPlugin plugin = getWorldGuard();
|
||||||
|
|
||||||
try {
|
return plugin == null;
|
||||||
// WorldGuard may not be loaded
|
|
||||||
if (plugin == null) {
|
|
||||||
return false; // Maybe you want throw an exception instead
|
|
||||||
}
|
|
||||||
} catch (Exception e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
//Silently Fail
|
|
||||||
//mcMMO.p.getLogger().severe("Failed to detect worldguard.");
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the instance of the WG plugin if its compatible
|
||||||
|
* Results are cached
|
||||||
|
* @return the instance of WG plugin, null if its not compatible or isn't present
|
||||||
|
*/
|
||||||
private static WorldGuardPlugin getWorldGuard()
|
private static WorldGuardPlugin getWorldGuard()
|
||||||
{
|
{
|
||||||
|
//WG plugin reference is already cached so just return it
|
||||||
if(isLoaded)
|
if(isLoaded)
|
||||||
return worldGuardPluginRef;
|
return worldGuardPluginRef;
|
||||||
|
|
||||||
|
//Grab WG if it exists
|
||||||
Plugin plugin = getServer().getPluginManager().getPlugin("WorldGuard");
|
Plugin plugin = getServer().getPluginManager().getPlugin("WorldGuard");
|
||||||
|
|
||||||
if(plugin instanceof WorldGuardPlugin)
|
if(plugin == null) {
|
||||||
{
|
//WG is not present
|
||||||
if(plugin.getDescription().getVersion().startsWith("7"))
|
detectedIncompatibleWG = true;
|
||||||
|
mcMMO.p.getLogger().info("WorldGuard was not detected.");
|
||||||
|
} else {
|
||||||
|
//Check that its actually of class WorldGuardPlugin
|
||||||
|
if(plugin instanceof WorldGuardPlugin)
|
||||||
{
|
{
|
||||||
worldGuardPluginRef = (WorldGuardPlugin) plugin;
|
if(isCompatibleVersion(plugin))
|
||||||
|
|
||||||
if(worldGuardPluginRef != null)
|
|
||||||
isLoaded = true;
|
|
||||||
|
|
||||||
} else {
|
|
||||||
if(!hasWarned)
|
|
||||||
{
|
{
|
||||||
mcMMO.p.getLogger().severe("mcMMO only supports WorldGuard version 7! Make sure you have WG 7! This warning will not appear again.");
|
worldGuardPluginRef = (WorldGuardPlugin) plugin;
|
||||||
hasWarned = true;
|
isLoaded = true;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
//Plugin is not of the expected type
|
||||||
|
markWGIncompatible();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
return worldGuardPluginRef;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Checks to make sure the version of WG installed is compatible
|
||||||
|
* Does this by checking for necessary WG classes via Reflection
|
||||||
|
* This does not guarantee compatibility, but it should help reduce the chance that mcMMO tries to hook into WG and its not compatible
|
||||||
|
* @return true if the version of WG appears to be compatible
|
||||||
|
*/
|
||||||
|
private static boolean isCompatibleVersion(Plugin plugin) {
|
||||||
|
//Check that the version of WG is at least version 7.xx
|
||||||
|
if(!plugin.getDescription().getVersion().startsWith("7")) {
|
||||||
|
markWGIncompatible();
|
||||||
|
} else {
|
||||||
|
//Use Reflection to check for a class not present in all versions of WG7
|
||||||
|
for(String classString : WGClassList) {
|
||||||
|
try {
|
||||||
|
Class<?> checkForClass = Class.forName(classString);
|
||||||
|
detectedIncompatibleWG = false; //In case this was set to true previously
|
||||||
|
} catch (ClassNotFoundException e) {
|
||||||
|
mcMMO.p.getLogger().severe("Missing WorldGuard class - "+classString);
|
||||||
|
markWGIncompatible();
|
||||||
|
break; //Break out of the loop
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return worldGuardPluginRef;
|
return detectedIncompatibleWG;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Mark WG as being incompatible to avoid unnecessary operations
|
||||||
|
*/
|
||||||
|
private static void markWGIncompatible() {
|
||||||
|
mcMMO.p.getLogger().severe("You are using a version of WG that is not compatible with mcMMO, " +
|
||||||
|
"WG features for mcMMO will be disabled. mcMMO requires you to be using a new version of WG7 " +
|
||||||
|
"in order for it to use WG features. Not all versions of WG7 are compatible.");
|
||||||
|
mcMMO.p.getLogger().severe("mcMMO will continue to function normally, but if you wish to use WG support you must use a compatible version.");
|
||||||
|
detectedIncompatibleWG = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user