Fix plugin hook
This commit is contained in:
@@ -1,29 +1,20 @@
|
||||
package io.izzel.taboolib.module.compat;
|
||||
|
||||
import io.izzel.taboolib.common.plugin.InternalPluginBridge;
|
||||
import io.izzel.taboolib.module.inject.TFunction;
|
||||
import net.milkbowl.vault.economy.Economy;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
|
||||
/**
|
||||
* @Author 坏黑
|
||||
* @Since 2019-07-05 18:50
|
||||
*/
|
||||
@TFunction(enable = "init")
|
||||
public class EconomyHook {
|
||||
|
||||
private static Economy economy;
|
||||
|
||||
static void init() {
|
||||
economy = InternalPluginBridge.handle().getEconomy();
|
||||
public static void add(OfflinePlayer p, double d) {
|
||||
InternalPluginBridge.handle().economyGive(p, d);
|
||||
}
|
||||
|
||||
public static void remove(OfflinePlayer p, double d) {
|
||||
economy.withdrawPlayer(p, d);
|
||||
}
|
||||
|
||||
public static void add(OfflinePlayer p, double d) {
|
||||
economy.depositPlayer(p, d);
|
||||
InternalPluginBridge.handle().economyTake(p, d);
|
||||
}
|
||||
|
||||
public static void set(OfflinePlayer p, double d) {
|
||||
@@ -31,18 +22,14 @@ public class EconomyHook {
|
||||
}
|
||||
|
||||
public static double get(OfflinePlayer p) {
|
||||
return economy.getBalance(p);
|
||||
return InternalPluginBridge.handle().economyLook(p);
|
||||
}
|
||||
|
||||
public static void create(OfflinePlayer p) {
|
||||
economy.createPlayerAccount(p);
|
||||
InternalPluginBridge.handle().economyCreate(p);
|
||||
}
|
||||
|
||||
public static boolean exists() {
|
||||
return economy != null;
|
||||
}
|
||||
|
||||
public static net.milkbowl.vault.economy.Economy getEconomy() {
|
||||
return economy;
|
||||
return InternalPluginBridge.handle().economyHooked();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,34 +1,23 @@
|
||||
package io.izzel.taboolib.module.compat;
|
||||
|
||||
import io.izzel.taboolib.common.plugin.InternalPluginBridge;
|
||||
import io.izzel.taboolib.module.inject.TFunction;
|
||||
import net.milkbowl.vault.permission.Permission;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
@TFunction(enable = "init")
|
||||
public class PermissionHook {
|
||||
|
||||
private static Permission perms;
|
||||
|
||||
static void init() {
|
||||
perms = InternalPluginBridge.handle().getPermission();
|
||||
public static void add(Player player, String perm) {
|
||||
InternalPluginBridge.handle().permissionAdd(player, perm);
|
||||
}
|
||||
|
||||
public static Permission getPermission() {
|
||||
return perms;
|
||||
public static void remove(Player player, String perm) {
|
||||
InternalPluginBridge.handle().permissionAdd(player, perm);
|
||||
}
|
||||
|
||||
public static void addPermission(Player player, String perm) {
|
||||
perms.playerAdd(player, perm);
|
||||
public static boolean has(Player player, String perm) {
|
||||
return InternalPluginBridge.handle().permissionHas(player, perm);
|
||||
}
|
||||
|
||||
public static void removePermission(Player player, String perm) {
|
||||
perms.playerRemove(player, perm);
|
||||
}
|
||||
|
||||
public static boolean hasPermission(Player player, String perm) {
|
||||
return perms.playerHas(player, perm) || Arrays.stream(perms.getPlayerGroups(player)).anyMatch(group -> perms.groupHas(player.getWorld(), group, perm));
|
||||
public static boolean exists() {
|
||||
return InternalPluginBridge.handle().permissionHooked();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,25 +1,22 @@
|
||||
package io.izzel.taboolib.module.compat;
|
||||
|
||||
import io.izzel.taboolib.common.plugin.InternalPluginBridge;
|
||||
import io.izzel.taboolib.module.inject.TFunction;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
@TFunction(enable = "init")
|
||||
public abstract class PlaceholderHook {
|
||||
import java.util.List;
|
||||
|
||||
private static boolean hooked;
|
||||
|
||||
static void init() {
|
||||
hooked = Bukkit.getPluginManager().getPlugin("PlaceholderAPI") != null;
|
||||
}
|
||||
public class PlaceholderHook {
|
||||
|
||||
public static String replace(CommandSender sender, String text) {
|
||||
return sender instanceof Player && hooked ? InternalPluginBridge.handle().setPlaceholders((Player) sender, text) : text;
|
||||
return sender instanceof Player ? InternalPluginBridge.handle().setPlaceholders((Player) sender, text) : text;
|
||||
}
|
||||
|
||||
public static List<String> replace(CommandSender sender, List<String> text) {
|
||||
return sender instanceof Player ? InternalPluginBridge.handle().setPlaceholders((Player) sender, text) : text;
|
||||
}
|
||||
|
||||
public static boolean isHooked() {
|
||||
return hooked;
|
||||
return InternalPluginBridge.handle().placeholderHooked();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,84 +0,0 @@
|
||||
package io.izzel.taboolib.module.compat;
|
||||
|
||||
import com.sk89q.worldedit.bukkit.BukkitAdapter;
|
||||
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 org.bukkit.Location;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* @Author AgarthaLib
|
||||
*/
|
||||
public class WorldGuardHook {
|
||||
|
||||
public static final WorldGuardHook INSTANCE = new WorldGuardHook();
|
||||
private WorldGuardPlugin worldGuard;
|
||||
private Method getRegionManager;
|
||||
|
||||
public WorldGuardHook() {
|
||||
worldGuard = InternalPluginBridge.handle().getWorldGuardPlugin();
|
||||
if (!worldGuard.getDescription().getVersion().startsWith("7")) {
|
||||
try {
|
||||
getRegionManager = WorldGuardPlugin.class.getDeclaredMethod("getRegionManager", World.class);
|
||||
getRegionManager.setAccessible(true);
|
||||
} catch (NoSuchMethodException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public WorldGuardPlugin getWorldGuard() {
|
||||
return this.worldGuard;
|
||||
}
|
||||
|
||||
public RegionManager getRegionManager(World world) {
|
||||
if (worldGuard.getDescription().getVersion().startsWith("7")) {
|
||||
return InternalPluginBridge.handle().getWorldGuard().getPlatform().getRegionContainer().get(BukkitAdapter.adapt(world));
|
||||
} else {
|
||||
try {
|
||||
return (RegionManager) getRegionManager.invoke(worldGuard, world);
|
||||
} catch (Throwable t) {
|
||||
t.printStackTrace();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public boolean isRegionManagerExists(World world) {
|
||||
return this.getRegionManager(world) != null;
|
||||
}
|
||||
|
||||
public Collection<String> getRegionIDs(World world) {
|
||||
return getRegionManager(world).getRegions().keySet();
|
||||
}
|
||||
|
||||
public Collection<ProtectedRegion> getRegions(World world) {
|
||||
return getRegionManager(world).getRegions().values();
|
||||
}
|
||||
|
||||
public List<String> getRegionsAtLocation(World world, Location location) {
|
||||
return getRegions(world).stream().filter(protectedRegion -> protectedRegion.contains(location.getBlockX(), location.getBlockY(), location.getBlockZ())).map(ProtectedRegion::getId).collect(Collectors.toList());
|
||||
}
|
||||
|
||||
public ProtectedRegion getRegion(World world, String id) {
|
||||
RegionManager regionManager = this.getRegionManager(world);
|
||||
return regionManager != null ? regionManager.getRegions().keySet().stream().filter(key -> key.equalsIgnoreCase(id)).findFirst().map(regionManager::getRegion).orElse(null) : null;
|
||||
}
|
||||
|
||||
public boolean isRegionExists(World world, String id) {
|
||||
return this.getRegion(world, id) != null;
|
||||
}
|
||||
|
||||
public boolean isPlayerInsideRegion(ProtectedRegion region, Player player) {
|
||||
Location location = player.getLocation();
|
||||
return region.contains(location.getBlockX(), location.getBlockY(), location.getBlockZ());
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user