Fix plugin hook
This commit is contained in:
@@ -55,10 +55,10 @@ public class ListenerPlayerCommand implements Listener {
|
||||
e.setCancelled(true);
|
||||
}
|
||||
if (TabooLibAPI.isDebug()) {
|
||||
TabooLibAPI.setDebug(false);
|
||||
TabooLibAPI.debug(false);
|
||||
TLogger.getGlobalLogger().info("&cDisabled.");
|
||||
} else {
|
||||
TabooLibAPI.setDebug(true);
|
||||
TabooLibAPI.debug(true);
|
||||
TLogger.getGlobalLogger().info("&aEnabled.");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,12 +1,13 @@
|
||||
package io.izzel.taboolib.common.plugin;
|
||||
|
||||
import com.sk89q.worldguard.WorldGuard;
|
||||
import com.sk89q.worldguard.bukkit.WorldGuardPlugin;
|
||||
import com.sk89q.worldguard.protection.managers.RegionManager;
|
||||
import io.izzel.taboolib.module.lite.SimpleVersionControl;
|
||||
import net.milkbowl.vault.economy.Economy;
|
||||
import net.milkbowl.vault.permission.Permission;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
@@ -29,15 +30,37 @@ public abstract class InternalPluginBridge {
|
||||
}
|
||||
}
|
||||
|
||||
abstract public <T> T getRegisteredService(Class<? extends T> clazz);
|
||||
|
||||
abstract public String setPlaceholders(Player player, String args);
|
||||
|
||||
abstract public List<String> setPlaceholders(Player player, List<String> args);
|
||||
|
||||
abstract public Economy getEconomy();
|
||||
abstract public void economyCreate(OfflinePlayer p);
|
||||
|
||||
abstract public Permission getPermission();
|
||||
abstract public void economyTake(OfflinePlayer p, double d);
|
||||
|
||||
abstract public WorldGuard getWorldGuard();
|
||||
abstract public void economyGive(OfflinePlayer p, double d);
|
||||
|
||||
abstract public WorldGuardPlugin getWorldGuardPlugin();
|
||||
abstract public double economyLook(OfflinePlayer p);
|
||||
|
||||
abstract public void permissionAdd(Player player, String perm);
|
||||
|
||||
abstract public void permissionRemove(Player player, String perm);
|
||||
|
||||
abstract public boolean permissionHas(Player player, String perm);
|
||||
|
||||
abstract public RegionManager worldguardRegionManager(World world);
|
||||
|
||||
abstract public Collection<String> worldguardGetRegions(World world);
|
||||
|
||||
abstract public List<String> worldguardGetRegion(World world, Location location);
|
||||
|
||||
abstract public boolean economyHooked();
|
||||
|
||||
abstract public boolean permissionHooked();
|
||||
|
||||
abstract public boolean placeholderHooked();
|
||||
|
||||
abstract public boolean worldguardHooked();
|
||||
}
|
||||
|
||||
@@ -1,54 +1,156 @@
|
||||
package io.izzel.taboolib.common.plugin.bridge;
|
||||
|
||||
import com.sk89q.worldedit.bukkit.BukkitAdapter;
|
||||
import com.sk89q.worldguard.WorldGuard;
|
||||
import com.sk89q.worldguard.bukkit.WorldGuardPlugin;
|
||||
import com.sk89q.worldguard.protection.managers.RegionManager;
|
||||
import com.sk89q.worldguard.protection.regions.ProtectedRegion;
|
||||
import io.izzel.taboolib.common.plugin.InternalPluginBridge;
|
||||
import io.izzel.taboolib.util.Reflection;
|
||||
import me.clip.placeholderapi.PlaceholderAPI;
|
||||
import net.milkbowl.vault.economy.Economy;
|
||||
import net.milkbowl.vault.permission.Permission;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.plugin.RegisteredServiceProvider;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class BridgeImpl extends InternalPluginBridge {
|
||||
|
||||
private Object economy;
|
||||
private Object permission;
|
||||
private Method getRegionManager;
|
||||
private boolean placeholder;
|
||||
private boolean worldguard;
|
||||
|
||||
public BridgeImpl() {
|
||||
if (Bukkit.getPluginManager().getPlugin("Vault") != null) {
|
||||
economy = getRegisteredService(Economy.class);
|
||||
permission = getRegisteredService(Permission.class);
|
||||
}
|
||||
if (Bukkit.getPluginManager().getPlugin("WorldGuard") != null) {
|
||||
if (!WorldGuardPlugin.inst().getDescription().getVersion().startsWith("7")) {
|
||||
try {
|
||||
getRegionManager = Reflection.getMethod(WorldGuardPlugin.class, "worldguardRegionManager", World.class);
|
||||
} catch (NoSuchMethodException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
worldguard = true;
|
||||
}
|
||||
placeholder = Bukkit.getPluginManager().getPlugin("PlaceholderAPI") != null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> T getRegisteredService(Class<? extends T> clazz) {
|
||||
RegisteredServiceProvider registeredServiceProvider = Bukkit.getServer().getServicesManager().getRegistration(clazz);
|
||||
return (T) registeredServiceProvider.getProvider();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String setPlaceholders(Player player, String args) {
|
||||
return PlaceholderAPI.setPlaceholders(player, args);
|
||||
return placeholder ? PlaceholderAPI.setPlaceholders(player, args) : args;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> setPlaceholders(Player player, List<String> args) {
|
||||
return PlaceholderAPI.setPlaceholders(player, args);
|
||||
return placeholder ? PlaceholderAPI.setPlaceholders(player, args) : args;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Economy getEconomy() {
|
||||
if (Bukkit.getPluginManager().getPlugin("Vault") == null) {
|
||||
public void economyCreate(OfflinePlayer p) {
|
||||
if (economy instanceof Economy) {
|
||||
((Economy) economy).createPlayerAccount(p);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void economyTake(OfflinePlayer p, double d) {
|
||||
if (economy instanceof Economy) {
|
||||
((Economy) economy).withdrawPlayer(p, d);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void economyGive(OfflinePlayer p, double d) {
|
||||
if (economy instanceof Economy) {
|
||||
((Economy) economy).depositPlayer(p, d);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public double economyLook(OfflinePlayer p) {
|
||||
return economy instanceof Economy ? ((Economy) economy).getBalance(p) : 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void permissionAdd(Player player, String perm) {
|
||||
if (permission instanceof Permission) {
|
||||
((Permission) permission).playerAdd(player, perm);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void permissionRemove(Player player, String perm) {
|
||||
if (permission instanceof Permission) {
|
||||
((Permission) permission).playerRemove(player, perm);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean permissionHas(Player player, String perm) {
|
||||
return permission instanceof Permission && ((Permission) permission).playerHas(player, perm);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<String> worldguardGetRegions(World world) {
|
||||
return worldguardRegionManager(world).getRegions().keySet();
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> worldguardGetRegion(World world, Location location) {
|
||||
return worldguardRegionManager(world).getRegions().values().stream().filter(r -> r.contains(location.getBlockX(), location.getBlockY(), location.getBlockZ())).map(ProtectedRegion::getId).collect(Collectors.toList());
|
||||
}
|
||||
|
||||
@Override
|
||||
public RegionManager worldguardRegionManager(World world) {
|
||||
if (WorldGuardPlugin.inst().getDescription().getVersion().startsWith("7")) {
|
||||
return WorldGuard.getInstance().getPlatform().getRegionContainer().get(BukkitAdapter.adapt(world));
|
||||
} else {
|
||||
try {
|
||||
return (RegionManager) getRegionManager.invoke(WorldGuardPlugin.inst(), world);
|
||||
} catch (Throwable t) {
|
||||
t.printStackTrace();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
RegisteredServiceProvider<Economy> registration = Bukkit.getServer().getServicesManager().getRegistration(Economy.class);
|
||||
return registration != null ? registration.getProvider() : null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Permission getPermission() {
|
||||
if (Bukkit.getPluginManager().getPlugin("Vault") == null) {
|
||||
return null;
|
||||
}
|
||||
RegisteredServiceProvider<Permission> registration = Bukkit.getServer().getServicesManager().getRegistration(Permission.class);
|
||||
return registration != null ? registration.getProvider() : null;
|
||||
public boolean economyHooked() {
|
||||
return economy != null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public WorldGuard getWorldGuard() {
|
||||
return WorldGuard.getInstance();
|
||||
public boolean permissionHooked() {
|
||||
return permission != null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public WorldGuardPlugin getWorldGuardPlugin() {
|
||||
return WorldGuardPlugin.inst();
|
||||
public boolean placeholderHooked() {
|
||||
return placeholder;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean worldguardHooked() {
|
||||
return worldguard;
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user