From b60d6bf52d9310a85870d27789f2e6726729637c Mon Sep 17 00:00:00 2001 From: Maxlego08 Date: Thu, 22 Feb 2024 12:53:51 +0100 Subject: [PATCH] :construction: Add scoreboard load --- src/fr/maxlego08/koth/KothPlugin.java | 19 ++++++- .../maxlego08/koth/hook/ScoreboardPlugin.java | 51 +++++++++++++++++++ .../koth/hook/scoreboard/DefaultHook.java | 21 ++++++++ .../hook/scoreboard/FeatherBoardHook.java | 5 ++ .../hook/scoreboard/SternalBoardHook.java | 3 +- .../koth/hook/scoreboard/TabHook.java | 5 +- .../hook/scoreboard/TitleManagerHook.java | 5 ++ src/main/resources/config.yml | 6 +++ src/main/resources/plugin.yml | 17 +++++++ 9 files changed, 128 insertions(+), 4 deletions(-) create mode 100644 src/fr/maxlego08/koth/hook/ScoreboardPlugin.java create mode 100644 src/fr/maxlego08/koth/hook/scoreboard/DefaultHook.java diff --git a/src/fr/maxlego08/koth/KothPlugin.java b/src/fr/maxlego08/koth/KothPlugin.java index 327868d..f0b17db 100644 --- a/src/fr/maxlego08/koth/KothPlugin.java +++ b/src/fr/maxlego08/koth/KothPlugin.java @@ -1,9 +1,13 @@ package fr.maxlego08.koth; +import fr.maxlego08.koth.api.KothScoreboard; import fr.maxlego08.koth.command.commands.CommandKoth; +import fr.maxlego08.koth.hook.ScoreboardPlugin; +import fr.maxlego08.koth.hook.scoreboard.DefaultHook; import fr.maxlego08.koth.placeholder.LocalPlaceholder; import fr.maxlego08.koth.save.MessageLoader; import fr.maxlego08.koth.zcore.ZPlugin; +import fr.maxlego08.koth.zcore.logger.Logger; /** * System to create your plugins very simply Projet: @@ -14,6 +18,7 @@ import fr.maxlego08.koth.zcore.ZPlugin; public class KothPlugin extends ZPlugin { private KothManager kothManager; + private KothScoreboard kothScoreboard = new DefaultHook(); @Override public void onEnable() { @@ -36,6 +41,14 @@ public class KothPlugin extends ZPlugin { this.loadFiles(); + for (ScoreboardPlugin value : ScoreboardPlugin.values()) { + if (value.isEnable()) { + kothScoreboard = value.init(this); + Logger.info("Register " + value.getPluginName() + " scoreboard implementation.", Logger.LogType.INFO); + break; + } + } + this.postEnable(); } @@ -50,6 +63,10 @@ public class KothPlugin extends ZPlugin { } public KothManager getKothManager() { - return kothManager; + return this.kothManager; + } + + public KothScoreboard getKothScoreboard() { + return this.kothScoreboard; } } diff --git a/src/fr/maxlego08/koth/hook/ScoreboardPlugin.java b/src/fr/maxlego08/koth/hook/ScoreboardPlugin.java new file mode 100644 index 0000000..857d5e7 --- /dev/null +++ b/src/fr/maxlego08/koth/hook/ScoreboardPlugin.java @@ -0,0 +1,51 @@ +package fr.maxlego08.koth.hook; + +import fr.maxlego08.koth.KothPlugin; +import fr.maxlego08.koth.api.KothScoreboard; +import fr.maxlego08.koth.hook.scoreboard.FeatherBoardHook; +import fr.maxlego08.koth.hook.scoreboard.SternalBoardHook; +import fr.maxlego08.koth.hook.scoreboard.TabHook; +import fr.maxlego08.koth.hook.scoreboard.TitleManagerHook; +import org.bukkit.Bukkit; +import org.bukkit.plugin.Plugin; + +import java.lang.reflect.InvocationTargetException; + +public enum ScoreboardPlugin { + + FEATHERBOARD("FeatherBoard", FeatherBoardHook.class), + TAB("TAB", TabHook.class), + STERNALBOARD("SternalBoard", SternalBoardHook.class), + TITLEMANAGER("TitleManager", TitleManagerHook.class), + + ; + + private final String pluginName; + private final Class scoreboardClass; + + private static KothScoreboard kothScoreboard; + + ScoreboardPlugin(String pluginName, Class scoreboardClass) { + this.pluginName = pluginName; + this.scoreboardClass = scoreboardClass; + } + + public String getPluginName() { + return pluginName; + } + + public boolean isEnable() { + Plugin plugin = Bukkit.getPluginManager().getPlugin(this.pluginName); + return plugin != null && plugin.isEnabled(); + } + + public KothScoreboard init(KothPlugin plugin) { + try { + return scoreboardClass.getConstructor(KothPlugin.class).newInstance(plugin); + } catch (InstantiationException | IllegalAccessException | InvocationTargetException | + NoSuchMethodException exception) { + exception.printStackTrace(); + } + return null; + } +} diff --git a/src/fr/maxlego08/koth/hook/scoreboard/DefaultHook.java b/src/fr/maxlego08/koth/hook/scoreboard/DefaultHook.java new file mode 100644 index 0000000..865a39d --- /dev/null +++ b/src/fr/maxlego08/koth/hook/scoreboard/DefaultHook.java @@ -0,0 +1,21 @@ +package fr.maxlego08.koth.hook.scoreboard; + +import fr.maxlego08.koth.KothPlugin; +import fr.maxlego08.koth.api.KothScoreboard; +import org.bukkit.entity.Player; + +import java.util.function.Consumer; + +public class DefaultHook implements KothScoreboard { + + + @Override + public void toggle(Player player, Consumer after) { + + } + + @Override + public void hide(Player player, Consumer after) { + + } +} diff --git a/src/fr/maxlego08/koth/hook/scoreboard/FeatherBoardHook.java b/src/fr/maxlego08/koth/hook/scoreboard/FeatherBoardHook.java index a95f1b8..a31395d 100644 --- a/src/fr/maxlego08/koth/hook/scoreboard/FeatherBoardHook.java +++ b/src/fr/maxlego08/koth/hook/scoreboard/FeatherBoardHook.java @@ -1,6 +1,7 @@ package fr.maxlego08.koth.hook.scoreboard; import be.maximvdw.featherboard.api.FeatherBoardAPI; +import fr.maxlego08.koth.KothPlugin; import fr.maxlego08.koth.api.KothScoreboard; import org.bukkit.entity.Player; @@ -8,6 +9,10 @@ import java.util.function.Consumer; public class FeatherBoardHook implements KothScoreboard { + public FeatherBoardHook(KothPlugin plugin){ + + } + @Override public void toggle(Player player, Consumer after) { if (!FeatherBoardAPI.isToggled(player)) { diff --git a/src/fr/maxlego08/koth/hook/scoreboard/SternalBoardHook.java b/src/fr/maxlego08/koth/hook/scoreboard/SternalBoardHook.java index ad45312..9ac5028 100644 --- a/src/fr/maxlego08/koth/hook/scoreboard/SternalBoardHook.java +++ b/src/fr/maxlego08/koth/hook/scoreboard/SternalBoardHook.java @@ -2,6 +2,7 @@ package fr.maxlego08.koth.hook.scoreboard; import com.xism4.sternalboard.SternalBoardPlugin; import com.xism4.sternalboard.managers.ScoreboardManager; +import fr.maxlego08.koth.KothPlugin; import fr.maxlego08.koth.api.KothScoreboard; import org.bukkit.Bukkit; import org.bukkit.entity.Player; @@ -13,7 +14,7 @@ public class SternalBoardHook implements KothScoreboard { private final ScoreboardManager manager; - public SternalBoardHook(Plugin plugin) { + public SternalBoardHook(KothPlugin plugin) { super(); this.manager = ((SternalBoardPlugin) Bukkit.getPluginManager().getPlugin("SternalBoard")).getScoreboardManager(); } diff --git a/src/fr/maxlego08/koth/hook/scoreboard/TabHook.java b/src/fr/maxlego08/koth/hook/scoreboard/TabHook.java index 83ccd8b..98e27b4 100644 --- a/src/fr/maxlego08/koth/hook/scoreboard/TabHook.java +++ b/src/fr/maxlego08/koth/hook/scoreboard/TabHook.java @@ -1,5 +1,6 @@ package fr.maxlego08.koth.hook.scoreboard; +import fr.maxlego08.koth.KothPlugin; import fr.maxlego08.koth.api.KothScoreboard; import me.neznamy.tab.api.TabAPI; import me.neznamy.tab.api.TabPlayer; @@ -11,9 +12,9 @@ import org.bukkit.plugin.Plugin; import java.util.function.Consumer; public class TabHook implements KothScoreboard { - private final Plugin plugin; + private final KothPlugin plugin; - public TabHook(Plugin plugin) { + public TabHook(KothPlugin plugin) { super(); this.plugin = plugin; } diff --git a/src/fr/maxlego08/koth/hook/scoreboard/TitleManagerHook.java b/src/fr/maxlego08/koth/hook/scoreboard/TitleManagerHook.java index eb8ea0d..fcba3fa 100644 --- a/src/fr/maxlego08/koth/hook/scoreboard/TitleManagerHook.java +++ b/src/fr/maxlego08/koth/hook/scoreboard/TitleManagerHook.java @@ -1,5 +1,6 @@ package fr.maxlego08.koth.hook.scoreboard; +import fr.maxlego08.koth.KothPlugin; import fr.maxlego08.koth.api.KothScoreboard; import io.puharesource.mc.titlemanager.api.v2.TitleManagerAPI; import org.bukkit.Bukkit; @@ -11,6 +12,10 @@ public class TitleManagerHook implements KothScoreboard { private TitleManagerAPI api; + public TitleManagerHook(KothPlugin plugin){ + + } + @Override public void toggle(Player player, Consumer after) { if (api == null) diff --git a/src/main/resources/config.yml b/src/main/resources/config.yml index 1d3d868..8b0d848 100644 --- a/src/main/resources/config.yml +++ b/src/main/resources/config.yml @@ -11,9 +11,15 @@ # /zkoth - zkoth.use - Displays the list of commands # /zkoth reload - zkoth.reload - Reload configuration files # /zkoth axe - zkoth.axe - Getting the selection axe +# /zkoth create [] [