mirror of
https://github.com/tanyaofei/minecraft-fakeplayer.git
synced 2025-09-14 11:16:46 +08:00
redesign configuration
This commit is contained in:
parent
5b7b85df1c
commit
fc76fd25b1
@ -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())
|
||||
|
@ -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();
|
||||
}
|
||||
|
||||
|
@ -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"))
|
||||
|
@ -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<Object>> config(@NotNull String nodeName) {
|
||||
public static @NotNull Argument<io.github.hello09x.fakeplayer.core.repository.model.Config<Object>> config(@NotNull String nodeName) {
|
||||
return config(nodeName, null);
|
||||
}
|
||||
|
||||
public static @NotNull Argument<Config<Object>> config(@NotNull String nodeName, @Nullable Predicate<Config<Object>> predicate) {
|
||||
public static @NotNull Argument<io.github.hello09x.fakeplayer.core.repository.model.Config<Object>> config(@NotNull String nodeName, @Nullable Predicate<io.github.hello09x.fakeplayer.core.repository.model.Config<Object>> predicate) {
|
||||
return new CustomArgument<>(new StringArgument(nodeName), info -> {
|
||||
var arg = info.currentInput();
|
||||
Config<Object> config;
|
||||
io.github.hello09x.fakeplayer.core.repository.model.Config<Object> 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<Object> configValue(@NotNull String configNodeName, @NotNull String nodeName) {
|
||||
return new CustomArgument<>(new StringArgument(nodeName), info -> {
|
||||
@SuppressWarnings("unchecked")
|
||||
var config = Objects.requireNonNull((Config<Object>) info.previousArgs().get(configNodeName));
|
||||
var config = Objects.requireNonNull((io.github.hello09x.fakeplayer.core.repository.model.Config<Object>) 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()) {
|
||||
|
@ -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;
|
||||
|
@ -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));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -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()));
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -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<FakeplayerConfig> {
|
||||
|
||||
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<String> preparingCommands;
|
||||
|
||||
/**
|
||||
* 自执行命令
|
||||
*/
|
||||
private List<String> selfCommands;
|
||||
|
||||
/**
|
||||
* 销毁命令
|
||||
*/
|
||||
private List<String> destroyCommands;
|
||||
|
||||
/**
|
||||
* 退出时是否丢弃背包物品
|
||||
*/
|
||||
private boolean dropInventoryOnQuiting;
|
||||
|
||||
/**
|
||||
* 是否保存假人存档
|
||||
*/
|
||||
private boolean persistData;
|
||||
|
||||
/**
|
||||
* 死亡时是否踢出游戏
|
||||
*/
|
||||
private boolean kickOnDead;
|
||||
|
||||
/**
|
||||
* 自定义名称规则
|
||||
*/
|
||||
private Pattern namePattern;
|
||||
|
||||
/**
|
||||
* 检测更新
|
||||
*/
|
||||
private boolean checkForUpdates;
|
||||
|
||||
/**
|
||||
* 允许执行的命令
|
||||
*/
|
||||
private Set<String> 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()));
|
||||
}
|
||||
|
||||
}
|
@ -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);
|
||||
|
||||
|
@ -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;
|
||||
|
@ -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))
|
||||
|
@ -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<String, AtomicInteger> 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);
|
||||
|
@ -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<String, NameSource> 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;
|
||||
|
@ -134,5 +134,6 @@ fakeplayer.spawn.error.name.invalid=Invalid name
|
||||
fakeplayer.spawn.error.name.start-with-illegal-character=Name can not start with <character>
|
||||
fakeplayer.spawn.error.name.too-long=Requires a name has less than <length> characters
|
||||
fakeplayer.spawn.error.name.too-short=Requires a name has more than <length> characters
|
||||
fakeplayer.configuration.outofdate=Your configuration file is out of date, please rengenerate it after backup and delete config.yml
|
||||
|
||||
|
||||
|
@ -134,5 +134,6 @@ fakeplayer.spawn.error.name.invalid=Invalid name
|
||||
fakeplayer.spawn.error.name.start-with-illegal-character=Name can not start with <character>
|
||||
fakeplayer.spawn.error.name.too-long=Requires a name has less than <length> characters
|
||||
fakeplayer.spawn.error.name.too-short=Requires a name has more than <length> characters
|
||||
fakeplayer.configuration.outofdate=Your configuration file is out of date, please rengenerate it after backup and delete config.yml
|
||||
|
||||
|
||||
|
@ -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 <character> \u5F00\u5934
|
||||
fakeplayer.spawn.error.name.too-long=\u540D\u79F0\u6700\u591A <length> \u4E2A\u5B57\u7B26
|
||||
fakeplayer.spawn.error.name.too-short=\u540D\u79F0\u6700\u5C11 <length> \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
|
||||
|
||||
|
@ -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 <character> \u5F00\u5934
|
||||
fakeplayer.spawn.error.name.too-long=\u540D\u79F0\u6700\u591A <length> \u4E2A\u5B57\u7B26
|
||||
fakeplayer.spawn.error.name.too-short=\u540D\u79F0\u6700\u5C11 <length> \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
|
||||
|
||||
|
@ -134,3 +134,4 @@ fakeplayer.spawn.error.name.invalid=\u540D\u7A31\u5514\u7B26\u5408\u683C\u5F0F\u
|
||||
fakeplayer.spawn.error.name.start-with-illegal-character=\u81EA\u5B9A\u7FA9\u540D\u7A31\u5514\u80FD\u4EE5 <character> \u958B\u982D
|
||||
fakeplayer.spawn.error.name.too-long=\u540D\u7A31\u81F3\u591A <length> \u500B\u5B57\u7B26
|
||||
fakeplayer.spawn.error.name.too-short=\u540D\u7A31\u6700\u5C11 <length> \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
|
@ -134,3 +134,4 @@ fakeplayer.spawn.error.name.invalid=\u540D\u7A31\u4E0D\u7B26\u5408\u683C\u5F0F\u
|
||||
fakeplayer.spawn.error.name.start-with-illegal-character=\u81EA\u5B9A\u7FA9\u540D\u7A31\u4E0D\u80FD\u4EE5 <character> \u958B\u982D
|
||||
fakeplayer.spawn.error.name.too-long=\u540D\u7A31\u6700\u591A <length> \u500B\u5B57\u7B26
|
||||
fakeplayer.spawn.error.name.too-short=\u540D\u7A31\u6700\u5C11 <length> \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
|
Loading…
Reference in New Issue
Block a user