From fc76fd25b1314e33b6bfcfe96ff8585f3bc86cd3 Mon Sep 17 00:00:00 2001 From: tanyaofei Date: Sun, 28 Jul 2024 18:52:43 +0800 Subject: [PATCH] redesign configuration --- .../fakeplayer/core/FakeplayerModule.java | 15 +- .../github/hello09x/fakeplayer/core/Main.java | 4 +- .../core/command/CommandRegistry.java | 7 +- .../core/command/CommandSupports.java | 19 +- .../core/command/impl/AbstractCommand.java | 4 +- .../core/command/impl/ReloadCommand.java | 11 +- .../fakeplayer/core/config/Config.java | 121 +++++++++-- .../core/config/FakeplayerConfig.java | 202 ------------------ .../fakeplayer/core/entity/FakePlayer.java | 4 +- .../core/listener/FakeplayerListener.java | 6 +- .../core/manager/FakeplayerManager.java | 19 +- .../core/manager/WildFakeplayerManager.java | 6 +- .../core/manager/naming/NameManager.java | 6 +- .../main/resources/message/message.properties | 1 + .../resources/message/message_en.properties | 1 + .../resources/message/message_zh.properties | 1 + .../message/message_zh_cn.properties | 1 + .../message/message_zh_hk.properties | 3 +- .../message/message_zh_tw.properties | 3 +- 19 files changed, 162 insertions(+), 272 deletions(-) delete mode 100644 fakeplayer-core/src/main/java/io/github/hello09x/fakeplayer/core/config/FakeplayerConfig.java diff --git a/fakeplayer-core/src/main/java/io/github/hello09x/fakeplayer/core/FakeplayerModule.java b/fakeplayer-core/src/main/java/io/github/hello09x/fakeplayer/core/FakeplayerModule.java index 871b75c..08ff4d5 100644 --- a/fakeplayer-core/src/main/java/io/github/hello09x/fakeplayer/core/FakeplayerModule.java +++ b/fakeplayer-core/src/main/java/io/github/hello09x/fakeplayer/core/FakeplayerModule.java @@ -3,13 +3,11 @@ package io.github.hello09x.fakeplayer.core; import com.google.inject.AbstractModule; import com.zaxxer.hikari.HikariConfig; import com.zaxxer.hikari.HikariDataSource; -import io.github.hello09x.devtools.database.jdbc.JdbcTemplate; import io.github.hello09x.fakeplayer.api.spi.NMSBridge; -import io.github.hello09x.fakeplayer.core.config.FakeplayerConfig; import io.github.hello09x.fakeplayer.core.manager.invsee.DefaultInvseeImpl; import io.github.hello09x.fakeplayer.core.manager.invsee.Invsee; import org.bukkit.Bukkit; -import org.jetbrains.annotations.NotNull; +import org.bukkit.plugin.Plugin; import javax.sql.DataSource; import java.io.File; @@ -17,18 +15,13 @@ import java.util.ServiceLoader; public class FakeplayerModule extends AbstractModule { - @Override protected void configure() { - super.bind(FakeplayerConfig.class).toInstance(this.fakeplayerConfig()); + super.bind(Plugin.class).toInstance(Main.getInstance()); super.bind(NMSBridge.class).toInstance(this.nmsBridge()); super.bind(Invsee.class).to(DefaultInvseeImpl.class); } - private FakeplayerConfig fakeplayerConfig() { - return new FakeplayerConfig(Main.getInstance(), "13"); - } - private DataSource dataSource() { var config = new HikariConfig(); config.setDriverClassName("org.sqlite.JDBC"); @@ -38,10 +31,6 @@ public class FakeplayerModule extends AbstractModule { return new HikariDataSource(config); } - private JdbcTemplate jdbcTemplate(@NotNull DataSource dataSource) { - return new JdbcTemplate(Main.getInstance(), dataSource); - } - private NMSBridge nmsBridge() { var bridge = ServiceLoader .load(NMSBridge.class, NMSBridge.class.getClassLoader()) diff --git a/fakeplayer-core/src/main/java/io/github/hello09x/fakeplayer/core/Main.java b/fakeplayer-core/src/main/java/io/github/hello09x/fakeplayer/core/Main.java index 213a388..2f90aa8 100644 --- a/fakeplayer-core/src/main/java/io/github/hello09x/fakeplayer/core/Main.java +++ b/fakeplayer-core/src/main/java/io/github/hello09x/fakeplayer/core/Main.java @@ -11,7 +11,7 @@ import io.github.hello09x.devtools.core.transaction.TranslatorUtils; import io.github.hello09x.devtools.core.utils.Lambdas; import io.github.hello09x.devtools.database.DatabaseModule; import io.github.hello09x.fakeplayer.core.command.CommandRegistry; -import io.github.hello09x.fakeplayer.core.config.FakeplayerConfig; +import io.github.hello09x.fakeplayer.core.config.Config; import io.github.hello09x.fakeplayer.core.listener.FakeplayerListener; import io.github.hello09x.fakeplayer.core.listener.PlayerListener; import io.github.hello09x.fakeplayer.core.listener.ReplenishListener; @@ -69,7 +69,7 @@ public final class Main extends RegistrablePlugin { manager.registerEvents(injector.getInstance(ReplenishListener.class), this); } - if (injector.getInstance(FakeplayerConfig.class).isCheckForUpdates()) { + if (injector.getInstance(Config.class).isCheckForUpdates()) { checkForUpdatesAsync(); } diff --git a/fakeplayer-core/src/main/java/io/github/hello09x/fakeplayer/core/command/CommandRegistry.java b/fakeplayer-core/src/main/java/io/github/hello09x/fakeplayer/core/command/CommandRegistry.java index b3e3cac..21af7b4 100644 --- a/fakeplayer-core/src/main/java/io/github/hello09x/fakeplayer/core/command/CommandRegistry.java +++ b/fakeplayer-core/src/main/java/io/github/hello09x/fakeplayer/core/command/CommandRegistry.java @@ -7,9 +7,8 @@ import io.github.hello09x.bedrock.command.Usage; import io.github.hello09x.devtools.core.transaction.PluginTranslator; import io.github.hello09x.fakeplayer.api.spi.Action; import io.github.hello09x.fakeplayer.core.command.impl.*; -import io.github.hello09x.fakeplayer.core.config.FakeplayerConfig; +import io.github.hello09x.fakeplayer.core.config.Config; import io.github.hello09x.fakeplayer.core.constant.Direction; -import io.github.hello09x.fakeplayer.core.repository.model.Config; import org.bukkit.entity.Entity; import org.bukkit.entity.LivingEntity; @@ -75,7 +74,7 @@ public class CommandRegistry { private DebugCommand debugCommand; @Inject - private FakeplayerConfig config; + private Config config; @Inject private PluginTranslator translator; @@ -195,7 +194,7 @@ public class CommandRegistry { .withRequirement(CommandSupports::hasTarget) .withPermission(Permission.set) .withArguments( - config("config", Config::hasAccessor), + config("config", io.github.hello09x.fakeplayer.core.repository.model.Config::hasAccessor), configValue("config", "value") ) .withOptionalArguments(target("name")) diff --git a/fakeplayer-core/src/main/java/io/github/hello09x/fakeplayer/core/command/CommandSupports.java b/fakeplayer-core/src/main/java/io/github/hello09x/fakeplayer/core/command/CommandSupports.java index 5ebb5d0..d83129f 100644 --- a/fakeplayer-core/src/main/java/io/github/hello09x/fakeplayer/core/command/CommandSupports.java +++ b/fakeplayer-core/src/main/java/io/github/hello09x/fakeplayer/core/command/CommandSupports.java @@ -9,9 +9,8 @@ import io.github.hello09x.devtools.core.transaction.PluginTranslator; import io.github.hello09x.fakeplayer.api.spi.Action; import io.github.hello09x.fakeplayer.core.Main; import io.github.hello09x.fakeplayer.core.command.impl.ActionCommand; -import io.github.hello09x.fakeplayer.core.config.FakeplayerConfig; +import io.github.hello09x.fakeplayer.core.config.Config; import io.github.hello09x.fakeplayer.core.manager.FakeplayerManager; -import io.github.hello09x.fakeplayer.core.repository.model.Config; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; import org.jetbrains.annotations.NotNull; @@ -32,7 +31,7 @@ public abstract class CommandSupports { private final static FakeplayerManager manager = Main.getInjector().getInstance(FakeplayerManager.class); - private final static FakeplayerConfig config = Main.getInjector().getInstance(FakeplayerConfig.class); + private final static Config config = Main.getInjector().getInstance(Config.class); private static final PluginTranslator translator = Main.getInjector().getInstance(PluginTranslator.class); private static final ActionCommand actionCommand = Main.getInjector().getInstance(ActionCommand.class); @@ -122,16 +121,16 @@ public abstract class CommandSupports { })); } - public static @NotNull Argument> config(@NotNull String nodeName) { + public static @NotNull Argument> config(@NotNull String nodeName) { return config(nodeName, null); } - public static @NotNull Argument> config(@NotNull String nodeName, @Nullable Predicate> predicate) { + public static @NotNull Argument> config(@NotNull String nodeName, @Nullable Predicate> predicate) { return new CustomArgument<>(new StringArgument(nodeName), info -> { var arg = info.currentInput(); - Config config; + io.github.hello09x.fakeplayer.core.repository.model.Config config; try { - config = Config.valueOf(arg); + config = io.github.hello09x.fakeplayer.core.repository.model.Config.valueOf(arg); } catch (Exception e) { throw CustomArgument.CustomArgumentException.fromString(translator.asString("fakeplayer.command.config.set.error.invalid-option", null)); } @@ -139,20 +138,20 @@ public abstract class CommandSupports { throw CustomArgument.CustomArgumentException.fromString(translator.asString("fakeplayer.command.config.set.error.invalid-option", null)); } return config; - }).replaceSuggestions(ArgumentSuggestions.strings(Arrays.stream(Config.values()).map(Config::key).toList())); + }).replaceSuggestions(ArgumentSuggestions.strings(Arrays.stream(io.github.hello09x.fakeplayer.core.repository.model.Config.values()).map(io.github.hello09x.fakeplayer.core.repository.model.Config::key).toList())); } public static @NotNull Argument configValue(@NotNull String configNodeName, @NotNull String nodeName) { return new CustomArgument<>(new StringArgument(nodeName), info -> { @SuppressWarnings("unchecked") - var config = Objects.requireNonNull((Config) info.previousArgs().get(configNodeName)); + var config = Objects.requireNonNull((io.github.hello09x.fakeplayer.core.repository.model.Config) info.previousArgs().get(configNodeName)); var arg = info.currentInput(); if (!config.options().contains(arg)) { throw CustomArgument.CustomArgumentException.fromString(translator.asString("fakeplayer.command.config.set.error.invalid-value", null)); } return config.parser().apply(arg); }).replaceSuggestions(ArgumentSuggestions.stringsAsync(info -> CompletableFuture.supplyAsync(() -> { - var config = Objects.requireNonNull((Config) info.previousArgs().get(configNodeName)); + var config = Objects.requireNonNull((io.github.hello09x.fakeplayer.core.repository.model.Config) info.previousArgs().get(configNodeName)); var arg = info.currentArg().toLowerCase(); var options = config.options().stream(); if (!arg.isEmpty()) { diff --git a/fakeplayer-core/src/main/java/io/github/hello09x/fakeplayer/core/command/impl/AbstractCommand.java b/fakeplayer-core/src/main/java/io/github/hello09x/fakeplayer/core/command/impl/AbstractCommand.java index 6927c1e..8e7de70 100644 --- a/fakeplayer-core/src/main/java/io/github/hello09x/fakeplayer/core/command/impl/AbstractCommand.java +++ b/fakeplayer-core/src/main/java/io/github/hello09x/fakeplayer/core/command/impl/AbstractCommand.java @@ -8,7 +8,7 @@ import io.github.hello09x.devtools.core.transaction.PluginTranslator; import io.github.hello09x.devtools.core.transaction.TranslatorUtils; import io.github.hello09x.fakeplayer.api.spi.NMSBridge; import io.github.hello09x.fakeplayer.core.Main; -import io.github.hello09x.fakeplayer.core.config.FakeplayerConfig; +import io.github.hello09x.fakeplayer.core.config.Config; import io.github.hello09x.fakeplayer.core.manager.FakeplayerManager; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; @@ -31,7 +31,7 @@ public abstract class AbstractCommand { protected FakeplayerManager manager; @Inject - protected FakeplayerConfig config; + protected Config config; @Inject protected PluginTranslator translator; diff --git a/fakeplayer-core/src/main/java/io/github/hello09x/fakeplayer/core/command/impl/ReloadCommand.java b/fakeplayer-core/src/main/java/io/github/hello09x/fakeplayer/core/command/impl/ReloadCommand.java index 5868ba6..f96b976 100644 --- a/fakeplayer-core/src/main/java/io/github/hello09x/fakeplayer/core/command/impl/ReloadCommand.java +++ b/fakeplayer-core/src/main/java/io/github/hello09x/fakeplayer/core/command/impl/ReloadCommand.java @@ -4,7 +4,7 @@ import com.google.inject.Inject; import com.google.inject.Singleton; import dev.jorel.commandapi.executors.CommandArguments; import io.github.hello09x.devtools.core.transaction.TranslatorUtils; -import io.github.hello09x.fakeplayer.core.config.FakeplayerConfig; +import io.github.hello09x.fakeplayer.core.config.Config; import org.bukkit.command.CommandSender; import org.jetbrains.annotations.NotNull; @@ -13,17 +13,20 @@ import static net.kyori.adventure.text.format.NamedTextColor.GRAY; @Singleton public class ReloadCommand extends AbstractCommand { - private final FakeplayerConfig config; + private final Config config; @Inject - public ReloadCommand(FakeplayerConfig config) { + public ReloadCommand(Config config) { this.config = config; } public void reload(@NotNull CommandSender sender, @NotNull CommandArguments args) { var locale = TranslatorUtils.getLocale(sender); - config.reload(true); + config.reload(); sender.sendMessage(translator.translate("fakeplayer.command.reload.success", locale, GRAY)); + if (config.isFileConfigurationOutOfDate()) { + sender.sendMessage(translator.translate("fakeplayer.configuration.outofdate", locale, GRAY)); + } } } diff --git a/fakeplayer-core/src/main/java/io/github/hello09x/fakeplayer/core/config/Config.java b/fakeplayer-core/src/main/java/io/github/hello09x/fakeplayer/core/config/Config.java index 95543ab..9eb97b3 100644 --- a/fakeplayer-core/src/main/java/io/github/hello09x/fakeplayer/core/config/Config.java +++ b/fakeplayer-core/src/main/java/io/github/hello09x/fakeplayer/core/config/Config.java @@ -1,21 +1,35 @@ package io.github.hello09x.fakeplayer.core.config; + +import com.google.inject.Inject; import com.google.inject.Singleton; -import lombok.Data; +import io.github.hello09x.devtools.core.config.PluginConfig; +import io.github.hello09x.devtools.core.event.PluginEventRegistry; +import io.github.hello09x.devtools.core.transaction.PluginTranslator; +import io.github.hello09x.fakeplayer.core.Main; +import lombok.Getter; +import lombok.ToString; +import org.bukkit.Bukkit; +import org.bukkit.configuration.file.FileConfiguration; +import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import java.time.Duration; import java.util.List; import java.util.Set; +import java.util.logging.Logger; import java.util.regex.Pattern; +import java.util.regex.PatternSyntaxException; +import java.util.stream.Collectors; -/** - * @author tanyaofei - * @since 2024/7/27 - **/ -@Data +@Getter +@ToString @Singleton -public class Config { +public class Config extends PluginConfig { + + private final static Logger log = Main.getInstance().getLogger(); + + private final static String defaultNameChars = "^[a-zA-Z0-9_]+$"; /** * 每位玩家最多多少个假人 @@ -98,14 +112,97 @@ public class Config { @Nullable private Duration lifespan; - /** - * 防止踢出 - */ - private PreventKicking preventKicking; - /** * 开发者调试模式 */ private boolean debug; + /** + * 防止踢出 + */ + private PreventKicking preventKicking; + + private final PluginTranslator translator; + + @Inject + public Config(@NotNull PluginEventRegistry pluginEventRegistry, @NotNull PluginTranslator translator) { + super(Main.getInstance(), pluginEventRegistry); + this.translator = translator; + } + + private static int maxIfZero(int value) { + return value <= 0 ? Integer.MAX_VALUE : value; + } + + @Override + protected void reload(@NotNull FileConfiguration file) { + this.playerLimit = maxIfZero(file.getInt("player-limit", 1)); + this.serverLimit = maxIfZero(file.getInt("server-limit", 1000)); + this.followQuiting = file.getBoolean("follow-quiting", true); + this.detectIp = file.getBoolean("detect-ip", false); + this.kaleTps = file.getInt("kale-tps", 0); + this.selfCommands = file.getStringList("self-commands"); + this.preparingCommands = file.getStringList("preparing-commands"); + this.destroyCommands = file.getStringList("destroy-commands"); + this.nameTemplate = file.getString("name-template", ""); + this.dropInventoryOnQuiting = file.getBoolean("drop-inventory-on-quiting", true); + this.persistData = file.getBoolean("persist-data", true); + this.kickOnDead = file.getBoolean("kick-on-dead", true); + this.checkForUpdates = file.getBoolean("check-for-updates", true); + this.namePattern = getNamePattern(file); + this.preventKicking = this.getPreventKicking(file); + this.nameTemplate = getNameTemplate(file); + this.lifespan = getLifespan(file); + this.allowCommands = file.getStringList("allow-commands") + .stream() + .map(c -> c.startsWith("/") ? c.substring(1) : c) + .filter(c -> !c.isBlank()) + .collect(Collectors.toSet()); + this.debug = file.getBoolean("debug", false); + + if (this.isFileConfigurationOutOfDate()) { + Bukkit.getScheduler().runTaskLater(Main.getInstance(), () -> { + if (Main.getInstance().isEnabled()) { + log.info(translator.asString("fakeplayer.configuration.outofdate", null)); + } + }, 1); + } + } + + private @Nullable Duration getLifespan(@NotNull FileConfiguration file) { + var minutes = file.getLong("lifespan"); + if (minutes <= 0) { + return null; + } + return Duration.ofMinutes(minutes); + } + + + private @NotNull Pattern getNamePattern(@NotNull FileConfiguration file) { + try { + return Pattern.compile(file.getString("name-pattern", defaultNameChars)); + } catch (PatternSyntaxException e) { + log.warning("Invalid name-pattern: " + file.getString("name-chars")); + return Pattern.compile(defaultNameChars); + } + } + + private @NotNull String getNameTemplate(@NotNull FileConfiguration file) { + var tmpl = file.getString("name-template", ""); + if (tmpl.startsWith("-") || tmpl.startsWith("@")) { + log.warning("Invalid name template: " + this.nameTemplate); + return ""; + } + return tmpl; + } + + private @NotNull PreventKicking getPreventKicking(@NotNull FileConfiguration file) { + if (file.getBoolean("prevent-kicked-on-spawning", false)) { + log.warning("prevent-kicked-on-spawning is deprecated, use prevent-kick instead"); + return PreventKicking.ON_SPAWNING; + } + + return PreventKicking.valueOf(file.getString("prevent-kicking", PreventKicking.NEVER.toString())); + } + } diff --git a/fakeplayer-core/src/main/java/io/github/hello09x/fakeplayer/core/config/FakeplayerConfig.java b/fakeplayer-core/src/main/java/io/github/hello09x/fakeplayer/core/config/FakeplayerConfig.java deleted file mode 100644 index 814d69f..0000000 --- a/fakeplayer-core/src/main/java/io/github/hello09x/fakeplayer/core/config/FakeplayerConfig.java +++ /dev/null @@ -1,202 +0,0 @@ -package io.github.hello09x.fakeplayer.core.config; - - -import io.github.hello09x.bedrock.config.Config; -import io.github.hello09x.fakeplayer.core.Main; -import lombok.Getter; -import lombok.ToString; -import org.bukkit.configuration.file.FileConfiguration; -import org.bukkit.plugin.java.JavaPlugin; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; - -import java.time.Duration; -import java.util.List; -import java.util.Set; -import java.util.logging.Logger; -import java.util.regex.Pattern; -import java.util.regex.PatternSyntaxException; -import java.util.stream.Collectors; - -@Getter -@ToString -public class FakeplayerConfig extends Config { - - public final static FakeplayerConfig instance; - - private final static Logger log; - - private final static String defaultNameChars = "^[a-zA-Z0-9_]+$"; - - static { - log = Main.getInstance().getLogger(); - instance = new FakeplayerConfig( - Main.getInstance(), - "15" - ); - } - - /** - * 每位玩家最多多少个假人 - */ - private int playerLimit; - - /** - * 服务器最多多少个假人 - */ - private int serverLimit; - - /** - * 命名模版 - */ - private String nameTemplate; - - /** - * 创建者玩家下线时是否跟随下线 - */ - private boolean followQuiting; - - /** - * 是否探测 IP - */ - private boolean detectIp; - - /** - * 服务器 tps 低于这个值移除所有假人 - */ - private int kaleTps; - - /** - * 准备命令 - */ - private List preparingCommands; - - /** - * 自执行命令 - */ - private List selfCommands; - - /** - * 销毁命令 - */ - private List destroyCommands; - - /** - * 退出时是否丢弃背包物品 - */ - private boolean dropInventoryOnQuiting; - - /** - * 是否保存假人存档 - */ - private boolean persistData; - - /** - * 死亡时是否踢出游戏 - */ - private boolean kickOnDead; - - /** - * 自定义名称规则 - */ - private Pattern namePattern; - - /** - * 检测更新 - */ - private boolean checkForUpdates; - - /** - * 允许执行的命令 - */ - private Set allowCommands; - - /** - * 默认假人存活时间 - */ - @Nullable - private Duration lifespan; - - /** - * 开发者调试模式 - */ - private boolean debug; - - /** - * 防止踢出 - */ - private PreventKicking preventKicking; - - public FakeplayerConfig(@NotNull JavaPlugin plugin, @NotNull String version) { - super(plugin, version); - reload(false); - } - - private static int maxIfZero(int value) { - return value <= 0 ? Integer.MAX_VALUE : value; - } - - @Override - protected void reload(@NotNull FileConfiguration file) { - this.playerLimit = maxIfZero(file.getInt("player-limit", 1)); - this.serverLimit = maxIfZero(file.getInt("server-limit", 1000)); - this.followQuiting = file.getBoolean("follow-quiting", true); - this.detectIp = file.getBoolean("detect-ip", false); - this.kaleTps = file.getInt("kale-tps", 0); - this.selfCommands = file.getStringList("self-commands"); - this.preparingCommands = file.getStringList("preparing-commands"); - this.destroyCommands = file.getStringList("destroy-commands"); - this.nameTemplate = file.getString("name-template", ""); - this.dropInventoryOnQuiting = file.getBoolean("drop-inventory-on-quiting", true); - this.persistData = file.getBoolean("persist-data", true); - this.kickOnDead = file.getBoolean("kick-on-dead", true); - this.checkForUpdates = file.getBoolean("check-for-updates", true); - this.namePattern = getNamePattern(file); - this.preventKicking = this.getPreventKicking(file); - this.nameTemplate = getNameTemplate(file); - this.lifespan = getLifespan(file); - this.allowCommands = file.getStringList("allow-commands") - .stream() - .map(c -> c.startsWith("/") ? c.substring(1) : c) - .filter(c -> !c.isBlank()) - .collect(Collectors.toSet()); - this.debug = file.getBoolean("debug", false); - } - - private @Nullable Duration getLifespan(@NotNull FileConfiguration file) { - var minutes = file.getLong("lifespan"); - if (minutes <= 0) { - return null; - } - return Duration.ofMinutes(minutes); - } - - - private @NotNull Pattern getNamePattern(@NotNull FileConfiguration file) { - try { - return Pattern.compile(file.getString("name-pattern", defaultNameChars)); - } catch (PatternSyntaxException e) { - log.warning("Invalid name-pattern: " + file.getString("name-chars")); - return Pattern.compile(defaultNameChars); - } - } - - private @NotNull String getNameTemplate(@NotNull FileConfiguration file) { - var tmpl = file.getString("name-template", ""); - if (tmpl.startsWith("-") || tmpl.startsWith("@")) { - log.warning("Invalid name template: " + this.nameTemplate); - return ""; - } - return tmpl; - } - - private @NotNull PreventKicking getPreventKicking(@NotNull FileConfiguration file) { - if (file.getBoolean("prevent-kicked-on-spawning", false)) { - log.warning("prevent-kicked-on-spawning is deprecated, use prevent-kick instead"); - return PreventKicking.ON_SPAWNING; - } - - return PreventKicking.valueOf(file.getString("prevent-kicking", PreventKicking.NEVER.toString())); - } - -} diff --git a/fakeplayer-core/src/main/java/io/github/hello09x/fakeplayer/core/entity/FakePlayer.java b/fakeplayer-core/src/main/java/io/github/hello09x/fakeplayer/core/entity/FakePlayer.java index 78422a8..ed4cb32 100644 --- a/fakeplayer-core/src/main/java/io/github/hello09x/fakeplayer/core/entity/FakePlayer.java +++ b/fakeplayer-core/src/main/java/io/github/hello09x/fakeplayer/core/entity/FakePlayer.java @@ -12,7 +12,7 @@ import io.github.hello09x.fakeplayer.api.spi.NMSBridge; import io.github.hello09x.fakeplayer.api.spi.NMSNetwork; import io.github.hello09x.fakeplayer.api.spi.NMSServerPlayer; import io.github.hello09x.fakeplayer.core.Main; -import io.github.hello09x.fakeplayer.core.config.FakeplayerConfig; +import io.github.hello09x.fakeplayer.core.config.Config; import io.github.hello09x.fakeplayer.core.constant.FakePlayerStatus; import io.github.hello09x.fakeplayer.core.manager.FakeplayerManager; import io.github.hello09x.fakeplayer.core.manager.action.ActionManager; @@ -44,7 +44,7 @@ public class FakePlayer { private final static InternalAddressGenerator ipGen = new InternalAddressGenerator(); - private final static FakeplayerConfig config = Main.getInjector().getInstance(FakeplayerConfig.class); + private final static Config config = Main.getInjector().getInstance(Config.class); private final static PluginTranslator translator = Main.getInjector().getInstance(PluginTranslator.class); diff --git a/fakeplayer-core/src/main/java/io/github/hello09x/fakeplayer/core/listener/FakeplayerListener.java b/fakeplayer-core/src/main/java/io/github/hello09x/fakeplayer/core/listener/FakeplayerListener.java index e2bdcef..b8276fc 100644 --- a/fakeplayer-core/src/main/java/io/github/hello09x/fakeplayer/core/listener/FakeplayerListener.java +++ b/fakeplayer-core/src/main/java/io/github/hello09x/fakeplayer/core/listener/FakeplayerListener.java @@ -6,7 +6,7 @@ import com.google.inject.Singleton; import io.github.hello09x.devtools.core.transaction.PluginTranslator; import io.github.hello09x.devtools.core.utils.ComponentUtils; import io.github.hello09x.fakeplayer.core.Main; -import io.github.hello09x.fakeplayer.core.config.FakeplayerConfig; +import io.github.hello09x.fakeplayer.core.config.Config; import io.github.hello09x.fakeplayer.core.constant.FakePlayerStatus; import io.github.hello09x.fakeplayer.core.manager.FakeplayerManager; import io.github.hello09x.fakeplayer.core.repository.UsedIdRepository; @@ -38,11 +38,11 @@ public class FakeplayerListener implements Listener { private final FakeplayerManager manager; private final UsedIdRepository usedIdRepository; - private final FakeplayerConfig config; + private final Config config; private final PluginTranslator translator; @Inject - public FakeplayerListener(FakeplayerManager manager, UsedIdRepository usedIdRepository, FakeplayerConfig config, PluginTranslator translator) { + public FakeplayerListener(FakeplayerManager manager, UsedIdRepository usedIdRepository, Config config, PluginTranslator translator) { this.manager = manager; this.usedIdRepository = usedIdRepository; this.config = config; diff --git a/fakeplayer-core/src/main/java/io/github/hello09x/fakeplayer/core/manager/FakeplayerManager.java b/fakeplayer-core/src/main/java/io/github/hello09x/fakeplayer/core/manager/FakeplayerManager.java index 3bc5d67..32f9849 100644 --- a/fakeplayer-core/src/main/java/io/github/hello09x/fakeplayer/core/manager/FakeplayerManager.java +++ b/fakeplayer-core/src/main/java/io/github/hello09x/fakeplayer/core/manager/FakeplayerManager.java @@ -9,7 +9,7 @@ import io.github.hello09x.devtools.core.transaction.TranslatorUtils; import io.github.hello09x.fakeplayer.api.spi.Action; import io.github.hello09x.fakeplayer.api.spi.NMSBridge; import io.github.hello09x.fakeplayer.core.Main; -import io.github.hello09x.fakeplayer.core.config.FakeplayerConfig; +import io.github.hello09x.fakeplayer.core.config.Config; import io.github.hello09x.fakeplayer.core.constant.MetadataKeys; import io.github.hello09x.fakeplayer.core.entity.FakePlayer; import io.github.hello09x.fakeplayer.core.entity.SpawnOption; @@ -18,7 +18,6 @@ import io.github.hello09x.fakeplayer.core.manager.naming.NameManager; import io.github.hello09x.fakeplayer.core.manager.naming.SequenceName; import io.github.hello09x.fakeplayer.core.manager.naming.exception.IllegalCustomNameException; import io.github.hello09x.fakeplayer.core.repository.UsedIdRepository; -import io.github.hello09x.fakeplayer.core.repository.model.Config; import io.github.hello09x.fakeplayer.core.util.Commands; import net.kyori.adventure.text.Component; import org.bukkit.Bukkit; @@ -58,11 +57,11 @@ public class FakeplayerManager { private final FakeplayerList playerList; private final UserConfigManager configManager; private final NMSBridge nms; - private final FakeplayerConfig config; + private final Config config; private final PluginTranslator translator; @Inject - public FakeplayerManager(Invsee invsee, UsedIdRepository usedIdRepository, NameManager nameManager, FakeplayerList playerList, UserConfigManager configManager, NMSBridge nms, FakeplayerConfig config, PluginTranslator translator) { + public FakeplayerManager(Invsee invsee, UsedIdRepository usedIdRepository, NameManager nameManager, FakeplayerList playerList, UserConfigManager configManager, NMSBridge nms, Config config, PluginTranslator translator) { this.invsee = invsee; this.usedIdRepository = usedIdRepository; this.nameManager = nameManager; @@ -122,12 +121,12 @@ public class FakeplayerManager { var configs = configManager.getConfigs(creator); return new SpawnOption( spawnAt, - configs.getOrDefault(Config.invulnerable), - configs.getOrDefault(Config.collidable), - configs.getOrDefault(Config.look_at_entity), - configs.getOrDefault(Config.pickup_items), - configs.getOrDefault(Config.skin), - configs.getOrDefault(Config.replenish) + configs.getOrDefault(io.github.hello09x.fakeplayer.core.repository.model.Config.invulnerable), + configs.getOrDefault(io.github.hello09x.fakeplayer.core.repository.model.Config.collidable), + configs.getOrDefault(io.github.hello09x.fakeplayer.core.repository.model.Config.look_at_entity), + configs.getOrDefault(io.github.hello09x.fakeplayer.core.repository.model.Config.pickup_items), + configs.getOrDefault(io.github.hello09x.fakeplayer.core.repository.model.Config.skin), + configs.getOrDefault(io.github.hello09x.fakeplayer.core.repository.model.Config.replenish) ); }) .thenComposeAsync(options -> fp.spawnAsync(creator, options)) diff --git a/fakeplayer-core/src/main/java/io/github/hello09x/fakeplayer/core/manager/WildFakeplayerManager.java b/fakeplayer-core/src/main/java/io/github/hello09x/fakeplayer/core/manager/WildFakeplayerManager.java index c2cb2ac..40f38c2 100644 --- a/fakeplayer-core/src/main/java/io/github/hello09x/fakeplayer/core/manager/WildFakeplayerManager.java +++ b/fakeplayer-core/src/main/java/io/github/hello09x/fakeplayer/core/manager/WildFakeplayerManager.java @@ -4,7 +4,7 @@ import com.google.common.io.ByteStreams; import com.google.inject.Inject; import com.google.inject.Singleton; import io.github.hello09x.fakeplayer.core.Main; -import io.github.hello09x.fakeplayer.core.config.FakeplayerConfig; +import io.github.hello09x.fakeplayer.core.config.Config; import org.bukkit.Bukkit; import org.bukkit.entity.Player; import org.bukkit.plugin.messaging.PluginMessageListener; @@ -36,11 +36,11 @@ public class WildFakeplayerManager implements PluginMessageListener { private final static int CLEANUP_PERIOD = 6000; private final FakeplayerManager manager; - private final FakeplayerConfig config; + private final Config config; private final Map offline = new HashMap<>(); @Inject - public WildFakeplayerManager(FakeplayerManager manager, FakeplayerConfig config) { + public WildFakeplayerManager(FakeplayerManager manager, Config config) { this.manager = manager; this.config = config; Bukkit.getScheduler().runTaskTimer(Main.getInstance(), this::cleanup, 0, CLEANUP_PERIOD); diff --git a/fakeplayer-core/src/main/java/io/github/hello09x/fakeplayer/core/manager/naming/NameManager.java b/fakeplayer-core/src/main/java/io/github/hello09x/fakeplayer/core/manager/naming/NameManager.java index de0e28f..5372a9c 100644 --- a/fakeplayer-core/src/main/java/io/github/hello09x/fakeplayer/core/manager/naming/NameManager.java +++ b/fakeplayer-core/src/main/java/io/github/hello09x/fakeplayer/core/manager/naming/NameManager.java @@ -4,7 +4,7 @@ import com.google.inject.Inject; import com.google.inject.Singleton; import io.github.hello09x.devtools.core.transaction.PluginTranslator; import io.github.hello09x.fakeplayer.core.Main; -import io.github.hello09x.fakeplayer.core.config.FakeplayerConfig; +import io.github.hello09x.fakeplayer.core.config.Config; import io.github.hello09x.fakeplayer.core.manager.naming.exception.IllegalCustomNameException; import io.github.hello09x.fakeplayer.core.repository.UsedIdRepository; import net.kyori.adventure.text.minimessage.tag.resolver.Placeholder; @@ -36,14 +36,14 @@ public class NameManager { private final static String FALLBACK_NAME = "_fp_"; private final UsedIdRepository usedIdRepository; - private final FakeplayerConfig config; + private final Config config; private final PluginTranslator translator; private final Map nameSources = new HashMap<>(); private final String serverId; @Inject - public NameManager(UsedIdRepository usedIdRepository, FakeplayerConfig config, PluginTranslator translator) { + public NameManager(UsedIdRepository usedIdRepository, Config config, PluginTranslator translator) { this.usedIdRepository = usedIdRepository; this.config = config; this.translator = translator; diff --git a/fakeplayer-core/src/main/resources/message/message.properties b/fakeplayer-core/src/main/resources/message/message.properties index afbc1c8..7a465f9 100644 --- a/fakeplayer-core/src/main/resources/message/message.properties +++ b/fakeplayer-core/src/main/resources/message/message.properties @@ -134,5 +134,6 @@ fakeplayer.spawn.error.name.invalid=Invalid name fakeplayer.spawn.error.name.start-with-illegal-character=Name can not start with fakeplayer.spawn.error.name.too-long=Requires a name has less than characters fakeplayer.spawn.error.name.too-short=Requires a name has more than characters +fakeplayer.configuration.outofdate=Your configuration file is out of date, please rengenerate it after backup and delete config.yml diff --git a/fakeplayer-core/src/main/resources/message/message_en.properties b/fakeplayer-core/src/main/resources/message/message_en.properties index afbc1c8..7a465f9 100644 --- a/fakeplayer-core/src/main/resources/message/message_en.properties +++ b/fakeplayer-core/src/main/resources/message/message_en.properties @@ -134,5 +134,6 @@ fakeplayer.spawn.error.name.invalid=Invalid name fakeplayer.spawn.error.name.start-with-illegal-character=Name can not start with fakeplayer.spawn.error.name.too-long=Requires a name has less than characters fakeplayer.spawn.error.name.too-short=Requires a name has more than characters +fakeplayer.configuration.outofdate=Your configuration file is out of date, please rengenerate it after backup and delete config.yml diff --git a/fakeplayer-core/src/main/resources/message/message_zh.properties b/fakeplayer-core/src/main/resources/message/message_zh.properties index 8bfa3a0..56b4e5d 100644 --- a/fakeplayer-core/src/main/resources/message/message_zh.properties +++ b/fakeplayer-core/src/main/resources/message/message_zh.properties @@ -134,4 +134,5 @@ fakeplayer.spawn.error.name.invalid=\u540D\u79F0\u4E0D\u7B26\u5408\u683C\u5F0F\u fakeplayer.spawn.error.name.start-with-illegal-character=\u81EA\u5B9A\u4E49\u540D\u79F0\u4E0D\u80FD\u4EE5 \u5F00\u5934 fakeplayer.spawn.error.name.too-long=\u540D\u79F0\u6700\u591A \u4E2A\u5B57\u7B26 fakeplayer.spawn.error.name.too-short=\u540D\u79F0\u6700\u5C11 \u4E2A\u5B57\u7B26 +fakeplayer.configuration.outofdate=\u914D\u7F6E\u6587\u4EF6\u7248\u672C\u66F4\u65B0\u4E86\uFF0C\u8BF7\u5907\u4EFD\u5E76\u5220\u9664 config.yml \u540E\u91CD\u65B0\u751F\u6210 diff --git a/fakeplayer-core/src/main/resources/message/message_zh_cn.properties b/fakeplayer-core/src/main/resources/message/message_zh_cn.properties index 8bfa3a0..9aa50e9 100644 --- a/fakeplayer-core/src/main/resources/message/message_zh_cn.properties +++ b/fakeplayer-core/src/main/resources/message/message_zh_cn.properties @@ -134,4 +134,5 @@ fakeplayer.spawn.error.name.invalid=\u540D\u79F0\u4E0D\u7B26\u5408\u683C\u5F0F\u fakeplayer.spawn.error.name.start-with-illegal-character=\u81EA\u5B9A\u4E49\u540D\u79F0\u4E0D\u80FD\u4EE5 \u5F00\u5934 fakeplayer.spawn.error.name.too-long=\u540D\u79F0\u6700\u591A \u4E2A\u5B57\u7B26 fakeplayer.spawn.error.name.too-short=\u540D\u79F0\u6700\u5C11 \u4E2A\u5B57\u7B26 +fakeplayer.configuration.outofdate=\u914D\u7F6E\u6587\u4EF6\u7248\u672C\u5DF2\u66F4\u65B0\uFF0C\u8BF7\u5907\u4EFD\u5E76\u5220\u9664 config.yml \u540E\u91CD\u65B0\u751F\u6210 diff --git a/fakeplayer-core/src/main/resources/message/message_zh_hk.properties b/fakeplayer-core/src/main/resources/message/message_zh_hk.properties index 1557628..d4e7c90 100644 --- a/fakeplayer-core/src/main/resources/message/message_zh_hk.properties +++ b/fakeplayer-core/src/main/resources/message/message_zh_hk.properties @@ -133,4 +133,5 @@ fakeplayer.spawn.error.name.existed=\u540D\u7A31\u5DF2\u88AB\u4F7F\u7528 fakeplayer.spawn.error.name.invalid=\u540D\u7A31\u5514\u7B26\u5408\u683C\u5F0F\u8981\u6C42 fakeplayer.spawn.error.name.start-with-illegal-character=\u81EA\u5B9A\u7FA9\u540D\u7A31\u5514\u80FD\u4EE5 \u958B\u982D fakeplayer.spawn.error.name.too-long=\u540D\u7A31\u81F3\u591A \u500B\u5B57\u7B26 -fakeplayer.spawn.error.name.too-short=\u540D\u7A31\u6700\u5C11 \u500B\u5B57\u7B26 \ No newline at end of file +fakeplayer.spawn.error.name.too-short=\u540D\u7A31\u6700\u5C11 \u500B\u5B57\u7B26 +fakeplayer.configuration.outofdate=\u914D\u7F6E\u6A94\u6848\u7248\u672C\u5DF2\u66F4\u65B0\uFF0C\u8ACB\u5099\u4EFD\u4E26\u522A\u9664 config.yml \u4E4B\u5F8C\u91CD\u65B0\u751F\u6210 \ No newline at end of file diff --git a/fakeplayer-core/src/main/resources/message/message_zh_tw.properties b/fakeplayer-core/src/main/resources/message/message_zh_tw.properties index 897d09e..2392e43 100644 --- a/fakeplayer-core/src/main/resources/message/message_zh_tw.properties +++ b/fakeplayer-core/src/main/resources/message/message_zh_tw.properties @@ -133,4 +133,5 @@ fakeplayer.spawn.error.name.existed=\u540D\u7A31\u5DF2\u88AB\u4F7F\u7528 fakeplayer.spawn.error.name.invalid=\u540D\u7A31\u4E0D\u7B26\u5408\u683C\u5F0F\u8981\u6C42 fakeplayer.spawn.error.name.start-with-illegal-character=\u81EA\u5B9A\u7FA9\u540D\u7A31\u4E0D\u80FD\u4EE5 \u958B\u982D fakeplayer.spawn.error.name.too-long=\u540D\u7A31\u6700\u591A \u500B\u5B57\u7B26 -fakeplayer.spawn.error.name.too-short=\u540D\u7A31\u6700\u5C11 \u500B\u5B57\u7B26 \ No newline at end of file +fakeplayer.spawn.error.name.too-short=\u540D\u7A31\u6700\u5C11 \u500B\u5B57\u7B26 +fakeplayer.configuration.outofdate=\u914D\u7F6E\u6A94\u6848\u7248\u672C\u5DF2\u66F4\u65B0\uFF0C\u8ACB\u5099\u4EFD\u4E26\u522A\u9664 config.yml \u5F8C\u91CD\u65B0\u751F\u6210 \ No newline at end of file