! Renames Hook Interface to OutdatedHookInterface for the new hooks

The interface is used/imported in two other Craftaro plugins (FabledSkyBlock and UltimateStacker).

I've worked on a new hook system which is easier to understand and maintain and hopefully also
allows for some more flexibility.

To introduce the new hooks without breaking changes (or as little as possible), this interface had to move.
This commit is contained in:
Christian Koop 2024-01-30 17:31:05 +01:00
parent 29f2d0b643
commit 50dfbf8dad
No known key found for this signature in database
GPG Key ID: 89A8181384E010A3
8 changed files with 20 additions and 16 deletions

View File

@ -9,7 +9,7 @@ import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.stream.Collectors; import java.util.stream.Collectors;
public class HookManager<T extends Hook> { public class HookManager<T extends OutdatedHookInterface> {
private final Class typeClass; private final Class typeClass;
private T defaultHook = null; private T defaultHook = null;
private boolean loaded = false; private boolean loaded = false;

View File

@ -1,6 +1,10 @@
package com.craftaro.core.hooks; package com.craftaro.core.hooks;
public interface Hook { /**
* This interface is part of the old hook system and is being replaced
*/
@Deprecated
public interface OutdatedHookInterface {
/** /**
* Get the name of the plugin being used * Get the name of the plugin being used
*/ */

View File

@ -63,7 +63,7 @@ public final class PluginHook<T extends Class> {
protected Constructor pluginConstructor; // for passing the plugin loading the hook to the plugin hook protected Constructor pluginConstructor; // for passing the plugin loading the hook to the plugin hook
private PluginHook(T type, String pluginName, Class handler) { private PluginHook(T type, String pluginName, Class handler) {
if (!Hook.class.isAssignableFrom(handler)) { if (!OutdatedHookInterface.class.isAssignableFrom(handler)) {
throw new RuntimeException("Tried to register a non-Hook plugin hook! " + pluginName + " -> " + handler.getName()); throw new RuntimeException("Tried to register a non-Hook plugin hook! " + pluginName + " -> " + handler.getName());
} }
@ -104,13 +104,13 @@ public final class PluginHook<T extends Class> {
return new PluginHook(type, pluginName, handler); return new PluginHook(type, pluginName, handler);
} }
protected static Map<PluginHook, Hook> loadHooks(Class type, Plugin plugin) { protected static Map<PluginHook, OutdatedHookInterface> loadHooks(Class type, Plugin plugin) {
Map<PluginHook, Hook> loaded = new LinkedHashMap<>(); Map<PluginHook, OutdatedHookInterface> loaded = new LinkedHashMap<>();
PluginManager pluginManager = Bukkit.getPluginManager(); PluginManager pluginManager = Bukkit.getPluginManager();
for (PluginHook hook : getHooks(type)) { for (PluginHook hook : getHooks(type)) {
if (pluginManager.isPluginEnabled(hook.plugin)) { if (pluginManager.isPluginEnabled(hook.plugin)) {
Hook handler = (Hook) (plugin != null ? hook.load(plugin) : hook.load()); OutdatedHookInterface handler = (OutdatedHookInterface) (plugin != null ? hook.load(plugin) : hook.load());
if (handler != null && handler.isEnabled()) { if (handler != null && handler.isEnabled()) {
loaded.put(hook, handler); loaded.put(hook, handler);

View File

@ -1,9 +1,9 @@
package com.craftaro.core.hooks.economies; package com.craftaro.core.hooks.economies;
import com.craftaro.core.hooks.Hook; import com.craftaro.core.hooks.OutdatedHookInterface;
import org.bukkit.OfflinePlayer; import org.bukkit.OfflinePlayer;
public abstract class Economy implements Hook { public abstract class Economy implements OutdatedHookInterface {
/** /**
* Get the players available balance * Get the players available balance
* *

View File

@ -1,6 +1,6 @@
package com.craftaro.core.hooks.holograms; package com.craftaro.core.hooks.holograms;
import com.craftaro.core.hooks.Hook; import com.craftaro.core.hooks.OutdatedHookInterface;
import org.bukkit.Location; import org.bukkit.Location;
import org.bukkit.plugin.Plugin; import org.bukkit.plugin.Plugin;
@ -8,7 +8,7 @@ import java.util.Collections;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
public abstract class Holograms implements Hook { public abstract class Holograms implements OutdatedHookInterface {
protected double xOffset = 0.5; protected double xOffset = 0.5;
protected double yOffset = 0.5; protected double yOffset = 0.5;
protected double zOffset = 0.5; protected double zOffset = 0.5;

View File

@ -1,11 +1,11 @@
package com.craftaro.core.hooks.log; package com.craftaro.core.hooks.log;
import com.craftaro.core.hooks.Hook; import com.craftaro.core.hooks.OutdatedHookInterface;
import org.bukkit.Location; import org.bukkit.Location;
import org.bukkit.OfflinePlayer; import org.bukkit.OfflinePlayer;
import org.bukkit.block.Block; import org.bukkit.block.Block;
public abstract class Log implements Hook { public abstract class Log implements OutdatedHookInterface {
public abstract void logPlacement(OfflinePlayer player, Block block); public abstract void logPlacement(OfflinePlayer player, Block block);
public abstract void logRemoval(OfflinePlayer player, Block block); public abstract void logRemoval(OfflinePlayer player, Block block);

View File

@ -1,11 +1,11 @@
package com.craftaro.core.hooks.protection; package com.craftaro.core.hooks.protection;
import com.craftaro.core.hooks.Hook; import com.craftaro.core.hooks.OutdatedHookInterface;
import org.bukkit.Location; import org.bukkit.Location;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.plugin.Plugin; import org.bukkit.plugin.Plugin;
public abstract class Protection implements Hook { public abstract class Protection implements OutdatedHookInterface {
protected final Plugin plugin; protected final Plugin plugin;
public Protection(Plugin plugin) { public Protection(Plugin plugin) {

View File

@ -1,11 +1,11 @@
package com.craftaro.core.hooks.stackers; package com.craftaro.core.hooks.stackers;
import com.craftaro.core.hooks.Hook; import com.craftaro.core.hooks.OutdatedHookInterface;
import org.bukkit.entity.EntityType; import org.bukkit.entity.EntityType;
import org.bukkit.entity.Item; import org.bukkit.entity.Item;
import org.bukkit.entity.LivingEntity; import org.bukkit.entity.LivingEntity;
public abstract class Stacker implements Hook { public abstract class Stacker implements OutdatedHookInterface {
public abstract boolean supportsItemStacking(); public abstract boolean supportsItemStacking();
public abstract boolean supportsEntityStacking(); public abstract boolean supportsEntityStacking();