From 2d77c2fecb2245281ad22ffb69315077abf4586b Mon Sep 17 00:00:00 2001 From: stevei5mc <2978383306@qq.com> Date: Mon, 26 Aug 2024 23:50:22 +0800 Subject: [PATCH] =?UTF-8?q?=E9=87=8D=E5=86=99=E6=8F=92=E4=BB=B6=E6=98=AF?= =?UTF-8?q?=E5=90=A6=E5=AD=98=E5=9C=A8=E7=9A=84=E5=88=A4=E6=96=AD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../NewTipsVariables/utils/GetConfigInfo.java | 3 +- .../NewTipsVariables/utils/PluginsState.java | 44 +++++++++-- .../variables/LoadSupportPlugins.java | 77 +++++-------------- .../supportPlugins/SmallasWaterPlugins.java | 10 +-- 4 files changed, 61 insertions(+), 73 deletions(-) diff --git a/src/main/java/cn/stevei5mc/NewTipsVariables/utils/GetConfigInfo.java b/src/main/java/cn/stevei5mc/NewTipsVariables/utils/GetConfigInfo.java index eaf2e5c..a877608 100644 --- a/src/main/java/cn/stevei5mc/NewTipsVariables/utils/GetConfigInfo.java +++ b/src/main/java/cn/stevei5mc/NewTipsVariables/utils/GetConfigInfo.java @@ -6,6 +6,7 @@ import healthapi.PlayerHealth; import cn.stevei5mc.NewTipsVariables.variables.LoadSupportPlugins; import cn.nukkit.utils.Config; +import cn.stevei5mc.NewTipsVariables.utils.PluginsState; public class GetConfigInfo { /** @@ -93,7 +94,7 @@ public static String getPlayerHealth(Player player) { double healthValue; String healthValue2; String healthMaxValue; - if (LoadSupportPlugins.pl5) { + if (PluginsState.getInstance().healthAPI) { PlayerHealth health = PlayerHealth.getPlayerHealth(player); healthValue = health.getHealth(); healthValue2 = String.valueOf(healthValue); diff --git a/src/main/java/cn/stevei5mc/NewTipsVariables/utils/PluginsState.java b/src/main/java/cn/stevei5mc/NewTipsVariables/utils/PluginsState.java index cf6feee..24b99c3 100644 --- a/src/main/java/cn/stevei5mc/NewTipsVariables/utils/PluginsState.java +++ b/src/main/java/cn/stevei5mc/NewTipsVariables/utils/PluginsState.java @@ -14,15 +14,43 @@ public static PluginsState getInstance() { // 插件的状态 public boolean playerPoints = false; - public boolean EconomyAPI = false; - public boolean OreArea = false; - public boolean RSTask = false; - public boolean HealthAPI = false; - public boolean LevelAwakenSystem = false; - public boolean RSWeapon = false; - public boolean LuckPerms = false; + public boolean economyAPI = false; + public boolean oreArea = false; + public boolean rSTask = false; + public boolean healthAPI = false; + public boolean levelAwakenSystem = false; + public boolean rSWeapon = false; + public boolean luckPerms = false; public void setPluginState(String pluginName) { - + switch (pluginName) { + case "playerPoints": + playerPoints = true; + break; + case "EconomyAPI": + economyAPI = true; + break; + case "OreArea": + oreArea = true; + break; + case "RSTask": + rSTask = true; + break; + case "HealthAPI": + healthAPI = true; + break; + case "LevelAwakenSystem": + levelAwakenSystem = true; + break; + case "RSWeapon": + rSWeapon = true; + break; + case "LuckPerms": + luckPerms = true; + break; + default: + // 对于其他插件,不做任何操作,因为没有必要 + break; + } } } \ No newline at end of file diff --git a/src/main/java/cn/stevei5mc/NewTipsVariables/variables/LoadSupportPlugins.java b/src/main/java/cn/stevei5mc/NewTipsVariables/variables/LoadSupportPlugins.java index c77f193..a3393a1 100644 --- a/src/main/java/cn/stevei5mc/NewTipsVariables/variables/LoadSupportPlugins.java +++ b/src/main/java/cn/stevei5mc/NewTipsVariables/variables/LoadSupportPlugins.java @@ -9,78 +9,37 @@ import cn.stevei5mc.NewTipsVariables.variables.supportPlugins.LuckPermsVar; import net.luckperms.api.LuckPerms; import net.luckperms.api.LuckPermsProvider; +import cn.stevei5mc.NewTipsVariables.utils.PluginsState; +import java.util.*; public class LoadSupportPlugins{ private static LuckPerms luckperms; public static LuckPerms getLP() { return luckperms; } - - //加载相关插件的变量时的提示 - public static String successMsg = Main.debugPrefix+"§a找到插件§e【§b{0}§e】§a相关变量已加载"; - public static String failureMsg = Main.debugPrefix+"§c无法找到插件§e【§b{0}§e】§c相关变量加载失败,请安装相关插件再试"; //需要加载的变量的插件 public static void loadSupportVariables(Player player) { - /* boolean debug = Main.debug; - String plugin; - plugin = "playerPoints"; - if (Server.getInstance().getPluginManager().getPlugin(plugin) != null) { - pl1 = true; - if (debug) {Main.getInstance().getLogger().info(successMsg.replace("{0}",plugin));} - } else if (debug) { - Main.getInstance().getLogger().info(failureMsg.replace("{0}",plugin)); + PluginsState ps = PluginsState.getInstance(); + String successMsg = Main.debugPrefix+"§a找到插件§e【§b{0}§e】§a相关变量已加载"; + String failureMsg = Main.debugPrefix+"§c无法找到插件§e【§b{0}§e】§c相关变量加载失败,请安装相关插件再试"; + boolean debug = Main.debug; + List pluginList = Arrays.asList("playerPoints","EconomyAPI","OreArea","RSTask","HealthAPI","LevelAwakenSystem","RSWeapon","LuckPerms"); + for(String plugin: pluginList){ + if (Server.getInstance().getPluginManager().getPlugin(plugin) != null) { + ps.setPluginState(plugin); + if (debug) {Main.getInstance().getLogger().info(successMsg.replace("{0}",plugin));} + } else if (debug) { + Main.getInstance().getLogger().info(failureMsg.replace("{0}",plugin)); + } } - plugin = "EconomyAPI"; - if (Server.getInstance().getPluginManager().getPlugin(plugin) != null) { + Api.registerVariables("SmallasWaterPlugins", SmallasWaterPlugins.class); + if (ps.economyAPI) { Api.registerVariables("economyApiVariable", economyApiVariable.class); - if (debug) {Main.getInstance().getLogger().info(successMsg.replace("{0}",plugin));} - } else if (debug) { - Main.getInstance().getLogger().info(failureMsg.replace("{0}",plugin)); - } - plugin = "OreArea"; - if (Server.getInstance().getPluginManager().getPlugin(plugin) != null) { - pl3 = true; - if (debug) {Main.getInstance().getLogger().info(successMsg.replace("{0}",plugin));} - } else if (debug) { - Main.getInstance().getLogger().info(failureMsg.replace("{0}",plugin)); - } - plugin = "RSTask"; - if (Server.getInstance().getPluginManager().getPlugin(plugin) != null) { - pl4 = true; - if (debug) {Main.getInstance().getLogger().info(successMsg.replace("{0}",plugin));} - } else if (debug) { - Main.getInstance().getLogger().info(failureMsg.replace("{0}",plugin)); - } - plugin = "HealthAPI"; - if (Server.getInstance().getPluginManager().getPlugin(plugin) != null) { - pl5 = true; - if (debug) {Main.getInstance().getLogger().info(successMsg.replace("{0}",plugin));} - } else if (debug) { - Main.getInstance().getLogger().info(failureMsg.replace("{0}",plugin)); } - plugin = "LevelAwakenSystem"; - if (Server.getInstance().getPluginManager().getPlugin(plugin) != null) { - pl6 = true; - if (debug) {Main.getInstance().getLogger().info(successMsg.replace("{0}",plugin));} - } else if (debug) { - Main.getInstance().getLogger().info(failureMsg.replace("{0}",plugin)); - } - plugin = "RSWeapon"; - if (Server.getInstance().getPluginManager().getPlugin(plugin) != null) { - pl7 = true; - if (debug) {Main.getInstance().getLogger().info(successMsg.replace("{0}",plugin));} - } else if (debug) { - Main.getInstance().getLogger().info(failureMsg.replace("{0}",plugin)); - } - Api.registerVariables("SmallasWaterPlugins", SmallasWaterPlugins.class); - plugin = "LuckPerms"; - if (Server.getInstance().getPluginManager().getPlugin(plugin) != null) { + if (ps.luckPerms) { luckperms = LuckPermsProvider.get(); Api.registerVariables("LuckPermsVar", LuckPermsVar.class); - if (debug) {Main.getInstance().getLogger().info(successMsg.replace("{0}",plugin));} - } else if (debug) { - Main.getInstance().getLogger().info(failureMsg.replace("{0}",plugin)); } - } */ + } } \ No newline at end of file diff --git a/src/main/java/cn/stevei5mc/NewTipsVariables/variables/supportPlugins/SmallasWaterPlugins.java b/src/main/java/cn/stevei5mc/NewTipsVariables/variables/supportPlugins/SmallasWaterPlugins.java index 8ce6590..ca6d8b2 100644 --- a/src/main/java/cn/stevei5mc/NewTipsVariables/variables/supportPlugins/SmallasWaterPlugins.java +++ b/src/main/java/cn/stevei5mc/NewTipsVariables/variables/supportPlugins/SmallasWaterPlugins.java @@ -34,19 +34,19 @@ public void strReplace() { if (ps.playerPoints) { playerPoint(); } - if (ps.RsTask) { + if (ps.rSTask) { RsTask(); } - if (ps.OreArea) { + if (ps.oreArea) { OreArea(); } - if (ps.HealthAPI) { + if (ps.healthAPI) { HealthAPI(); } - if (ps.RSWeapon) { + if (ps.rSWeapon) { RSWeapon(); } - if (ps.LevelAwakenSystem) { + if (ps.levelAwakenSystem) { LevelAwakenSystem(); } }