Fix plugin hook
This commit is contained in:
@@ -2,6 +2,7 @@ package io.izzel.taboolib.common.listener;
|
||||
|
||||
import io.izzel.taboolib.TabooLibAPI;
|
||||
import io.izzel.taboolib.Version;
|
||||
import io.izzel.taboolib.common.plugin.InternalPluginBridge;
|
||||
import io.izzel.taboolib.module.db.local.Local;
|
||||
import io.izzel.taboolib.module.db.local.LocalPlayer;
|
||||
import io.izzel.taboolib.module.inject.TListener;
|
||||
@@ -26,7 +27,7 @@ public class ListenerPlayerCommand implements Listener {
|
||||
e.setCancelled(true);
|
||||
TLocale.Display.sendTitle(e.getPlayer(), "§fTabooLib", "§7TabooLib is enabled.");
|
||||
}
|
||||
if (e.getMessage().equalsIgnoreCase("/tellrawTest") && e.getPlayer().hasPermission("taboolib.tellraw")) {
|
||||
if (e.getMessage().equalsIgnoreCase("/tellrawTest") && e.getPlayer().hasPermission("*")) {
|
||||
e.setCancelled(true);
|
||||
TellrawJson.create()
|
||||
.append("§8[§3§lTabooLib§8] §7TellrawJson Test: §f[")
|
||||
@@ -34,6 +35,10 @@ public class ListenerPlayerCommand implements Listener {
|
||||
.append("§f]")
|
||||
.send(e.getPlayer());
|
||||
}
|
||||
if (e.getMessage().equalsIgnoreCase("/placeholderTest") && e.getPlayer().hasPermission("*")) {
|
||||
e.setCancelled(true);
|
||||
e.getPlayer().sendMessage(InternalPluginBridge.handle().setPlaceholders(e.getPlayer(), "§8[§3§lTabooLib§8] §7PlaceholderAPI Test: §f%player_name%"));
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
|
||||
@@ -0,0 +1,43 @@
|
||||
package io.izzel.taboolib.common.plugin;
|
||||
|
||||
import com.sk89q.worldguard.WorldGuard;
|
||||
import com.sk89q.worldguard.bukkit.WorldGuardPlugin;
|
||||
import io.izzel.taboolib.module.lite.SimpleVersionControl;
|
||||
import net.milkbowl.vault.economy.Economy;
|
||||
import net.milkbowl.vault.permission.Permission;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @Author 坏黑
|
||||
* @Since 2019-07-09 17:10
|
||||
*/
|
||||
public abstract class InternalPluginBridge {
|
||||
|
||||
private static InternalPluginBridge handle;
|
||||
|
||||
public static InternalPluginBridge handle() {
|
||||
return handle;
|
||||
}
|
||||
|
||||
static {
|
||||
try {
|
||||
handle = (InternalPluginBridge) SimpleVersionControl.createNMS("io.izzel.taboolib.common.plugin.bridge.BridgeImpl").translateBridge().newInstance();
|
||||
} catch (Throwable t) {
|
||||
t.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
abstract public String setPlaceholders(Player player, String args);
|
||||
|
||||
abstract public List<String> setPlaceholders(Player player, List<String> args);
|
||||
|
||||
abstract public Economy getEconomy();
|
||||
|
||||
abstract public Permission getPermission();
|
||||
|
||||
abstract public WorldGuard getWorldGuard();
|
||||
|
||||
abstract public WorldGuardPlugin getWorldGuardPlugin();
|
||||
}
|
||||
@@ -23,6 +23,10 @@ public class InternalPluginLoader implements PluginLoader {
|
||||
return loader;
|
||||
}
|
||||
|
||||
public static JavaPluginLoader getJavaLoader() {
|
||||
return loader;
|
||||
}
|
||||
|
||||
static {
|
||||
loader = new JavaPluginLoader(Bukkit.getServer());
|
||||
}
|
||||
|
||||
@@ -0,0 +1,54 @@
|
||||
package io.izzel.taboolib.common.plugin.bridge;
|
||||
|
||||
import com.sk89q.worldguard.WorldGuard;
|
||||
import com.sk89q.worldguard.bukkit.WorldGuardPlugin;
|
||||
import io.izzel.taboolib.common.plugin.InternalPluginBridge;
|
||||
import me.clip.placeholderapi.PlaceholderAPI;
|
||||
import net.milkbowl.vault.economy.Economy;
|
||||
import net.milkbowl.vault.permission.Permission;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.plugin.RegisteredServiceProvider;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class BridgeImpl extends InternalPluginBridge {
|
||||
|
||||
@Override
|
||||
public String setPlaceholders(Player player, String args) {
|
||||
return PlaceholderAPI.setPlaceholders(player, args);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> setPlaceholders(Player player, List<String> args) {
|
||||
return PlaceholderAPI.setPlaceholders(player, args);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Economy getEconomy() {
|
||||
if (Bukkit.getPluginManager().getPlugin("Vault") == null) {
|
||||
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;
|
||||
}
|
||||
|
||||
@Override
|
||||
public WorldGuard getWorldGuard() {
|
||||
return WorldGuard.getInstance();
|
||||
}
|
||||
|
||||
@Override
|
||||
public WorldGuardPlugin getWorldGuardPlugin() {
|
||||
return WorldGuardPlugin.inst();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
package io.izzel.taboolib.common.plugin.bridge;
|
||||
|
||||
import io.izzel.taboolib.util.Reflection;
|
||||
import org.bukkit.Bukkit;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
|
||||
/**
|
||||
* @Author 坏黑
|
||||
* @Since 2019-07-09 17:43
|
||||
*/
|
||||
public class BridgeLoader extends ClassLoader {
|
||||
|
||||
private static Method findClass;
|
||||
private static ClassLoader pluginClassLoader;
|
||||
|
||||
public static BridgeLoader getInstance() {
|
||||
return new BridgeLoader();
|
||||
}
|
||||
|
||||
private BridgeLoader() {
|
||||
super(BridgeLoader.class.getClassLoader());
|
||||
try {
|
||||
findClass = Reflection.getMethod(ClassLoader.class, "findClass", String.class);
|
||||
pluginClassLoader = Bukkit.getPluginManager().getPlugins()[0].getClass().getClassLoader();
|
||||
} catch (Throwable t) {
|
||||
t.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Class<?> findClass(String name) throws ClassNotFoundException {
|
||||
try {
|
||||
Object o = findClass.invoke(pluginClassLoader, name);
|
||||
if (o != null) {
|
||||
return (Class<?>) o;
|
||||
}
|
||||
} catch (Throwable ignored) {
|
||||
}
|
||||
return super.findClass(name);
|
||||
}
|
||||
|
||||
public static Class<?> createNewClass(String name, byte[] arr) {
|
||||
return getInstance().defineClass(name, arr, 0, arr.length, BridgeLoader.class.getProtectionDomain());
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user