Fix issues when enabling hooks with external classes
This commit is contained in:
parent
975eaa9cb6
commit
49c03c85d3
|
@ -3,6 +3,7 @@ package com.craftaro.core.hooks;
|
|||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
@ -29,15 +30,22 @@ public abstract class HookManager<T extends PluginHook> {
|
|||
return registeredHooks.values();
|
||||
}
|
||||
|
||||
public void registerHook(T hook) {
|
||||
public void registerHook(Class<? extends T> hook) {
|
||||
registerHook(null, hook);
|
||||
}
|
||||
|
||||
public void registerHook(String requiredPlugin, T hook) {
|
||||
public void registerHook(String requiredPlugin, Class<? extends T> hookClazz) {
|
||||
if (requiredPlugin != null && !Bukkit.getPluginManager().isPluginEnabled(requiredPlugin)) {
|
||||
return;
|
||||
}
|
||||
|
||||
T hook = null;
|
||||
try {
|
||||
hook = hookClazz.getConstructor(Plugin.class).newInstance(plugin);
|
||||
} catch (InstantiationException | InvocationTargetException | NoSuchMethodException | IllegalAccessException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
if (!hook.enableHook()) {
|
||||
return;
|
||||
}
|
||||
|
|
|
@ -13,7 +13,7 @@ public class EconomyManager extends HookManager<IEconomy> {
|
|||
|
||||
@Override
|
||||
protected void registerDefaultHooks() {
|
||||
registerHook("Vault", new VaultImplementation());
|
||||
registerHook("Vault", VaultImplementation.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -4,10 +4,13 @@ import com.craftaro.core.hooks.economy.IEconomy;
|
|||
import net.milkbowl.vault.economy.Economy;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
import org.bukkit.plugin.RegisteredServiceProvider;
|
||||
|
||||
public class VaultImplementation implements IEconomy {
|
||||
|
||||
public VaultImplementation(Plugin plugin) {}
|
||||
|
||||
private Economy economy;
|
||||
|
||||
@Override
|
||||
|
|
|
@ -14,8 +14,8 @@ public class HologramManager extends HookManager<AbstractHologram> {
|
|||
|
||||
@Override
|
||||
protected void registerDefaultHooks() {
|
||||
registerHook("HolographicDisplays", new HolographicDisplaysImplementation(plugin));
|
||||
registerHook("DecentHolograms", new DecentHologramsImplementation());
|
||||
registerHook("HolographicDisplays", HolographicDisplaysImplementation.class);
|
||||
registerHook("DecentHolograms", DecentHologramsImplementation.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -5,12 +5,15 @@ import eu.decentsoftware.holograms.api.DHAPI;
|
|||
import eu.decentsoftware.holograms.api.DecentHologramsAPI;
|
||||
import eu.decentsoftware.holograms.api.holograms.Hologram;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
public class DecentHologramsImplementation extends AbstractHologram {
|
||||
private final Map<String, Hologram> holograms = new HashMap<>();
|
||||
|
||||
public DecentHologramsImplementation(Plugin plugin) {}
|
||||
|
||||
@Override
|
||||
public String getHookName() {
|
||||
return "DecentHolograms";
|
||||
|
|
|
@ -2,11 +2,13 @@ package com.craftaro.core.hooks.holograms.impl;
|
|||
|
||||
import com.craftaro.core.hooks.holograms.AbstractHologram;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public class DummyHologramImplementation extends AbstractHologram {
|
||||
|
||||
@Override
|
||||
public String getHookName() {
|
||||
return "None";
|
||||
|
|
|
@ -17,15 +17,16 @@ public class ProtectionManager extends HookManager<IProtection> {
|
|||
|
||||
@Override
|
||||
protected void registerDefaultHooks() {
|
||||
registerHook("BentoBox", new BentoBoxImplementation());
|
||||
registerHook("GriefPrevention", new GriefPreventionImplementation());
|
||||
registerHook("WorldGuard", new WorldGuardImplementation());
|
||||
registerHook("BentoBox", BentoBoxImplementation.class);
|
||||
registerHook("GriefPrevention", GriefPreventionImplementation.class);
|
||||
registerHook("WorldGuard", WorldGuardImplementation.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected IProtection getDummyHook() {
|
||||
return new DummyProtectionImplementation();
|
||||
}
|
||||
|
||||
public ProtectionSet getHooksByName(List<String> names) {
|
||||
ProtectionSet hooks = new ProtectionSet();
|
||||
for (String name : names) {
|
||||
|
|
|
@ -3,6 +3,7 @@ package com.craftaro.core.hooks.protection.impl;
|
|||
import com.craftaro.core.hooks.protection.IProtection;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
import world.bentobox.bentobox.BentoBox;
|
||||
import world.bentobox.bentobox.api.flags.Flag;
|
||||
import world.bentobox.bentobox.api.user.User;
|
||||
|
@ -14,6 +15,8 @@ import java.util.Optional;
|
|||
|
||||
public class BentoBoxImplementation implements IProtection {
|
||||
|
||||
public BentoBoxImplementation(Plugin plugin) {}
|
||||
|
||||
private IslandsManager islandsManager;
|
||||
|
||||
@Override
|
||||
|
|
|
@ -3,8 +3,10 @@ package com.craftaro.core.hooks.protection.impl;
|
|||
import com.craftaro.core.hooks.protection.IProtection;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
|
||||
public class DummyProtectionImplementation implements IProtection {
|
||||
|
||||
@Override
|
||||
public String getHookName() {
|
||||
return "None";
|
||||
|
|
|
@ -6,10 +6,13 @@ import me.ryanhamshire.GriefPrevention.GriefPrevention;
|
|||
import me.ryanhamshire.GriefPrevention.DataStore;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
|
||||
public class GriefPreventionImplementation implements IProtection {
|
||||
|
||||
private DataStore dataStore;
|
||||
private DataStore dataStore;
|
||||
|
||||
public GriefPreventionImplementation(Plugin plugin) {}
|
||||
|
||||
@Override
|
||||
public String getHookName() {
|
||||
|
|
|
@ -10,6 +10,7 @@ import com.sk89q.worldguard.protection.managers.RegionManager;
|
|||
import com.sk89q.worldguard.protection.regions.RegionContainer;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
|
@ -17,6 +18,8 @@ public class WorldGuardImplementation implements IProtection {
|
|||
|
||||
private RegionContainer container;
|
||||
|
||||
public WorldGuardImplementation(Plugin plugin) {}
|
||||
|
||||
@Override
|
||||
public String getHookName() {
|
||||
return "WorldGuard";
|
||||
|
|
Loading…
Reference in New Issue