From e860ff8a7f839a547d3e5ae8f33dd447ef82eb0d Mon Sep 17 00:00:00 2001 From: XPYEX Date: Mon, 22 Aug 2022 20:43:55 +0800 Subject: [PATCH] 2.0.0 --- .../flywithfood/bukkit/FlyWithFoodBukkit.java | 2 +- .../flywithfood/common/FlyWithFood.java | 16 +++++++++++--- .../common/command/FWFCmdExecutor.java | 2 +- .../flywithfood/common/config/FWFConfig.java | 2 +- .../common/implementation/FWFUser.java | 7 ++++++ .../sponge7/FlyWithFoodSponge7.java | 22 +++++++++++++------ .../sponge7/api/FlyWithFoodAPISponge7.java | 3 +-- 7 files changed, 39 insertions(+), 15 deletions(-) diff --git a/bukkit/src/main/java/me/xpyex/plugin/flywithfood/bukkit/FlyWithFoodBukkit.java b/bukkit/src/main/java/me/xpyex/plugin/flywithfood/bukkit/FlyWithFoodBukkit.java index f89f887..00a78a1 100644 --- a/bukkit/src/main/java/me/xpyex/plugin/flywithfood/bukkit/FlyWithFoodBukkit.java +++ b/bukkit/src/main/java/me/xpyex/plugin/flywithfood/bukkit/FlyWithFoodBukkit.java @@ -36,7 +36,7 @@ public void onDisable() { } public static FlyWithFoodBukkit getInstance() { - if (Util.checkNull(INSTANCE)) throw new IllegalStateException("插件尚未加载完成"); + if (Util.checkNull(INSTANCE)) throw new IllegalStateException(FlyWithFood.PLUGIN_NOT_LOADED_MSG); return INSTANCE; } diff --git a/common/src/main/java/me/xpyex/plugin/flywithfood/common/FlyWithFood.java b/common/src/main/java/me/xpyex/plugin/flywithfood/common/FlyWithFood.java index 8b5dafe..7eaf6d0 100644 --- a/common/src/main/java/me/xpyex/plugin/flywithfood/common/FlyWithFood.java +++ b/common/src/main/java/me/xpyex/plugin/flywithfood/common/FlyWithFood.java @@ -7,7 +7,7 @@ public class FlyWithFood { private static FlyWithFood INSTANCE; - private static final String PLUGIN_NOT_LOADED_MSG = "插件尚未加载完成 || Plugin is invalid"; + public static final String PLUGIN_NOT_LOADED_MSG = "插件尚未加载完成 || Plugin is invalid"; private final FlyWithFoodAPI API; public FlyWithFood(FlyWithFoodAPI API) { @@ -46,9 +46,19 @@ public void enable() { getLogger().info(" "); getAPI().registerEnergies(); - getAPI().runTaskAsync(getAPI()::register_bStats); - FWFConfig.reload(); + if (!FWFConfig.reload()) { + getLogger().severe("载入配置文件出错!插件加载已终止,请检查配置文件,如无法解决请查看后台报错并报告开发者. QQ:1723275529"); + getLogger().severe("若确认是由配置文件错误导致加载出错,可在修改完毕后使用 /fly reload 重载以恢复"); + getLogger().severe(" "); + getLogger().severe("ERROR!! The plugin loading has been terminated. Please check your config file."); + getLogger().severe("If you can not solve this problem, please check error messages in console and open a Issue to my GitHub."); + getLogger().severe("If you are sure that the config file has something wrong, you can use '/fly reload' after you fix that problem."); + getLogger().severe(" "); + return; + } + + getAPI().runTaskAsync(getAPI()::register_bStats); FlyWithFood.getInstance().getAPI().startCheck(); diff --git a/common/src/main/java/me/xpyex/plugin/flywithfood/common/command/FWFCmdExecutor.java b/common/src/main/java/me/xpyex/plugin/flywithfood/common/command/FWFCmdExecutor.java index 6ff896b..f94ac5b 100644 --- a/common/src/main/java/me/xpyex/plugin/flywithfood/common/command/FWFCmdExecutor.java +++ b/common/src/main/java/me/xpyex/plugin/flywithfood/common/command/FWFCmdExecutor.java @@ -75,7 +75,7 @@ public static void onCmd(FWFSender sender, String label, String... args) { sender.sendFWFMsg(FWFMsgType.NoPermission); return; } - if (FWFConfig.CONFIG.reload()) { + if (FWFConfig.reload()) { if (FWFConfig.CONFIG.isChinese) { sender.autoSendMsg("&a重载成功"); } else { diff --git a/common/src/main/java/me/xpyex/plugin/flywithfood/common/config/FWFConfig.java b/common/src/main/java/me/xpyex/plugin/flywithfood/common/config/FWFConfig.java index b858cbf..13d9385 100644 --- a/common/src/main/java/me/xpyex/plugin/flywithfood/common/config/FWFConfig.java +++ b/common/src/main/java/me/xpyex/plugin/flywithfood/common/config/FWFConfig.java @@ -19,7 +19,7 @@ public class FWFConfig { public static File ROOT; public static File CONFIG_FILE; public static File BAK_FOLDER; - public static final int CONFIG_VERSION = 6; + public static final int CONFIG_VERSION = 5; public static FWFConfig CONFIG; public static final Gson GSON = new GsonBuilder() .setPrettyPrinting() diff --git a/common/src/main/java/me/xpyex/plugin/flywithfood/common/implementation/FWFUser.java b/common/src/main/java/me/xpyex/plugin/flywithfood/common/implementation/FWFUser.java index efbc646..000520b 100644 --- a/common/src/main/java/me/xpyex/plugin/flywithfood/common/implementation/FWFUser.java +++ b/common/src/main/java/me/xpyex/plugin/flywithfood/common/implementation/FWFUser.java @@ -1,8 +1,10 @@ package me.xpyex.plugin.flywithfood.common.implementation; +import java.util.Arrays; import me.xpyex.plugin.flywithfood.common.FlyWithFood; import me.xpyex.plugin.flywithfood.common.config.FWFConfig; import me.xpyex.plugin.flywithfood.common.config.FWFInfo; +import me.xpyex.plugin.flywithfood.common.flyenergy.EnergyManager; import me.xpyex.plugin.flywithfood.common.utils.GsonUtil; public interface FWFUser extends FWFSender { @@ -28,6 +30,11 @@ public default FWFInfo getInfo() { break; } } + if (!EnergyManager.hasEnergy(mode)) { + FlyWithFood.getLogger().error("玩家 " + getName() + " 的CostMode错误!CostMode只应为 " + Arrays.toString(EnergyManager.getEnergies()) + " 中的一种. -> " + mode); + FlyWithFood.getLogger().error("ERROR!! CostMode does not exists! You can use these: " + Arrays.toString(EnergyManager.getEnergies()) + ". -> " + mode); + throw new IllegalStateException(); + } return new FWFInfo(cost, disable, mode); } diff --git a/sponge7/src/main/java/me/xpyex/plugin/flywithfood/sponge7/FlyWithFoodSponge7.java b/sponge7/src/main/java/me/xpyex/plugin/flywithfood/sponge7/FlyWithFoodSponge7.java index 88c6cbe..84c7adc 100644 --- a/sponge7/src/main/java/me/xpyex/plugin/flywithfood/sponge7/FlyWithFoodSponge7.java +++ b/sponge7/src/main/java/me/xpyex/plugin/flywithfood/sponge7/FlyWithFoodSponge7.java @@ -1,7 +1,7 @@ package me.xpyex.plugin.flywithfood.sponge7; import com.google.inject.Inject; -import java.util.ArrayList; +import java.util.Collections; import java.util.List; import java.util.Optional; import me.xpyex.plugin.flywithfood.common.FlyWithFood; @@ -9,7 +9,6 @@ import me.xpyex.plugin.flywithfood.common.utils.Util; import me.xpyex.plugin.flywithfood.sponge7.api.FlyWithFoodAPISponge7; import me.xpyex.plugin.flywithfood.sponge7.bstats.Metrics; -import me.xpyex.plugin.flywithfood.sponge7.energies.SpongeMoney; import me.xpyex.plugin.flywithfood.sponge7.implementation.SpongeSender; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -23,7 +22,6 @@ import org.spongepowered.api.event.game.state.GameStoppingServerEvent; import org.spongepowered.api.plugin.Plugin; import org.spongepowered.api.plugin.PluginContainer; -import org.spongepowered.api.service.economy.EconomyService; import org.spongepowered.api.text.Text; import org.spongepowered.api.world.Location; import org.spongepowered.api.world.World; @@ -59,40 +57,50 @@ public void onGameStart(GameStartedServerEvent event) { Sponge.getCommandManager().register(INSTANCE, new CommandCallable() { @Override public @NotNull CommandResult process(@NotNull CommandSource source, @NotNull String arguments) throws CommandException { - System.out.println(arguments); - FWFCmdExecutor.onCmd(new SpongeSender(source), "fly", arguments); + String[] args; + if (arguments.trim().isEmpty()) { + args = new String[0]; + } else { + args = arguments.split(" "); + } + FWFCmdExecutor.onCmd(new SpongeSender(source), "fly", args); return CommandResult.success(); } @Override public @NotNull List getSuggestions(@NotNull CommandSource source, @NotNull String arguments, @Nullable Location targetPosition) throws CommandException { - return new ArrayList<>(); + return Collections.emptyList(); + // } @Override public boolean testPermission(@NotNull CommandSource source) { return true; + // } @Override public @NotNull Optional getShortDescription(@NotNull CommandSource source) { return Optional.of(Text.of("FlyWithFood的基础命令")); + // } @Override public @NotNull Optional getHelp(@NotNull CommandSource source) { return Optional.of(Text.of("这是可以帮助的吗")); + // } @Override public @NotNull Text getUsage(@NotNull CommandSource source) { return Text.of("没有Usage"); + // } }, "flywithfood", "fly", "fwf"); } public static FlyWithFoodSponge7 getInstance() { - if (Util.checkNull(INSTANCE)) throw new IllegalStateException("插件尚未加载完成"); + if (Util.checkNull(INSTANCE)) throw new IllegalStateException(FlyWithFood.PLUGIN_NOT_LOADED_MSG); return INSTANCE; } diff --git a/sponge7/src/main/java/me/xpyex/plugin/flywithfood/sponge7/api/FlyWithFoodAPISponge7.java b/sponge7/src/main/java/me/xpyex/plugin/flywithfood/sponge7/api/FlyWithFoodAPISponge7.java index e1c9a4a..af9dc59 100644 --- a/sponge7/src/main/java/me/xpyex/plugin/flywithfood/sponge7/api/FlyWithFoodAPISponge7.java +++ b/sponge7/src/main/java/me/xpyex/plugin/flywithfood/sponge7/api/FlyWithFoodAPISponge7.java @@ -26,7 +26,6 @@ public class FlyWithFoodAPISponge7 implements FlyWithFoodAPI { private final FWFLogger logger; private static final String SERVER_SOFTWARE = "Sponge-1.12"; private static final int SERVER_MAIN_VERSION = 12; - private static final Task.Builder SCHEDULER = Task.builder(); public FlyWithFoodAPISponge7() { this.logger = new FWFLogger(new SpongeSender(Sponge.getServer().getConsole())); @@ -120,7 +119,7 @@ public void stopTasks() { } public Task.Builder getScheduler() { - return SCHEDULER; + return Task.builder(); // }