mirror of
https://github.com/RonanPlugins/BetterRTP.git
synced 2025-07-01 23:36:18 +00:00
fix: Support RegionPlugin UltimateClaims
v2 and v1
With v2 the package changed because Songoda renamed to Craftaro at one point in time. This fixes a `ClassNotFoundException` when using v2 of the plugin. The commit also refactors the code a bit as the `UltimateClaims#getInstance()` method is marked as deprecated and will be removed in the future.
This commit is contained in:
parent
dbde32d48d
commit
ea8231e4e0
@ -2,38 +2,39 @@ package me.SuperRonanCraft.BetterRTP.references.depends.regionPlugins;
|
|||||||
|
|
||||||
import org.bukkit.Chunk;
|
import org.bukkit.Chunk;
|
||||||
import org.bukkit.Location;
|
import org.bukkit.Location;
|
||||||
|
import org.bukkit.plugin.java.JavaPlugin;
|
||||||
|
|
||||||
import java.lang.reflect.Method;
|
import java.lang.reflect.Method;
|
||||||
|
|
||||||
public class RTP_UltimateClaims implements RegionPluginCheck {
|
public class RTP_UltimateClaims implements RegionPluginCheck {
|
||||||
|
|
||||||
// NOT TESTED (3.1.0)
|
// TESTED (v2.2.0)
|
||||||
// UltimateClaims (v1.6.1) - Abandoned
|
// UltimateClaims (v2.2.0 + v1.10.4)
|
||||||
// https://songoda.com/marketplace/product/ultimateclaims-the-ultimate-claiming-plugin.65
|
// https://craftaro.com/marketplace/product/65
|
||||||
public boolean check(Location loc) {
|
public boolean check(Location loc) {
|
||||||
boolean result = true;
|
boolean result = true;
|
||||||
if (REGIONPLUGINS.ULTIMATECLAIMS.isEnabled())
|
if (REGIONPLUGINS.ULTIMATECLAIMS.isEnabled())
|
||||||
try {
|
try {
|
||||||
Chunk chunk = loc.getChunk();
|
JavaPlugin ultimateClaimsInstance = JavaPlugin.getPlugin((Class<? extends JavaPlugin>) getPluginMainClass());
|
||||||
|
|
||||||
// Get instance of UltimateClaims
|
|
||||||
Class<?> ultimateClaimsClass = Class.forName("com.songoda.ultimateclaims.UltimateClaims");
|
|
||||||
Method getInstanceMethod = ultimateClaimsClass.getMethod("getInstance");
|
|
||||||
Object ultimateClaims = getInstanceMethod.invoke(null);
|
|
||||||
|
|
||||||
// Get the ClaimManager
|
// Get the ClaimManager
|
||||||
Method getClaimManagerMethod = ultimateClaimsClass.getMethod("getClaimManager");
|
Method getClaimManagerMethod = ultimateClaimsInstance.getClass().getMethod("getClaimManager");
|
||||||
Object claimManager = getClaimManagerMethod.invoke(ultimateClaims);
|
Object claimManager = getClaimManagerMethod.invoke(ultimateClaimsInstance);
|
||||||
|
|
||||||
// Get the claim based on the chunk
|
// Get the claim based on the chunk
|
||||||
Method getClaimMethod = claimManager.getClass().getMethod("getClaim", Chunk.class);
|
Method hasClaimMethod = claimManager.getClass().getMethod("hasClaim", Chunk.class);
|
||||||
Object claimObj = getClaimMethod.invoke(claimManager, chunk);
|
return Boolean.FALSE.equals(hasClaimMethod.invoke(claimManager, loc.getChunk()));
|
||||||
|
|
||||||
// Check if a claim exists
|
|
||||||
return claimObj == null;
|
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private Class<?> getPluginMainClass() throws ClassNotFoundException {
|
||||||
|
try {
|
||||||
|
return Class.forName("com.craftaro.ultimateclaims.UltimateClaims"); // v2
|
||||||
|
} catch (ClassNotFoundException ignore) {
|
||||||
|
return Class.forName("com.songoda.ultimateclaims.UltimateClaims"); // v1
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user