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 bb74829..db8c01e 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 @@ -11,7 +11,7 @@ import io.github.hello09x.fakeplayer.api.spi.ActionType; import io.github.hello09x.fakeplayer.core.command.impl.*; import io.github.hello09x.fakeplayer.core.config.FakeplayerConfig; import io.github.hello09x.fakeplayer.core.constant.Direction; -import io.github.hello09x.fakeplayer.core.repository.model.FeatureKey; +import io.github.hello09x.fakeplayer.core.repository.model.Feature; import org.bukkit.entity.Entity; import org.bukkit.entity.LivingEntity; @@ -173,7 +173,7 @@ public class CommandRegistry { .withShortDescription("fakeplayer.command.set.description") .withPermission(Permission.set) .withArguments( - configKey("feature", FeatureKey::hasModifier), + configKey("feature", Feature::hasModifier), configValue("feature", "option") ) .withOptionalArguments(fakeplayer("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 214d4c9..57a7161 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 @@ -11,7 +11,7 @@ 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.manager.FakeplayerManager; -import io.github.hello09x.fakeplayer.core.repository.model.FeatureKey; +import io.github.hello09x.fakeplayer.core.repository.model.Feature; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; import org.jetbrains.annotations.NotNull; @@ -126,16 +126,16 @@ public abstract class CommandSupports { })); } - public static @NotNull Argument configKey(@NotNull String nodeName) { + public static @NotNull Argument configKey(@NotNull String nodeName) { return configKey(nodeName, ignored -> true); } - public static @NotNull Argument configKey(@NotNull String nodeName, @NotNull Predicate predicate) { + public static @NotNull Argument configKey(@NotNull String nodeName, @NotNull Predicate predicate) { return new CustomArgument<>(new StringArgument(nodeName), info -> { var arg = info.currentInput(); - FeatureKey key; + Feature key; try { - key = FeatureKey.valueOf(arg); + key = Feature.valueOf(arg); } catch (Exception e) { throw CustomArgument.CustomArgumentException.fromAdventureComponent(translatable("fakeplayer.command.config.set.error.invalid-key")); } @@ -148,13 +148,13 @@ public abstract class CommandSupports { throw CustomArgument.CustomArgumentException.fromAdventureComponent(translatable("fakeplayer.command.config.set.error.no-permission")); } return key; - }).replaceSuggestions(ArgumentSuggestions.strings(Arrays.stream(FeatureKey.values()).filter(predicate).map(Enum::name).toArray(String[]::new))); + }).replaceSuggestions(ArgumentSuggestions.strings(Arrays.stream(Feature.values()).filter(predicate).map(Enum::name).toArray(String[]::new))); } public static @NotNull Argument configValue(@NotNull String configKeyNodeName, @NotNull String nodeName) { return new CustomArgument(new StringArgument(nodeName), info -> { - var key = (FeatureKey) info.previousArgs().get(configKeyNodeName); + var key = (Feature) info.previousArgs().get(configKeyNodeName); if (key == null) { throw CustomArgument.CustomArgumentException.fromAdventureComponent(translatable("fakeplayer.command.config.set.error.invalid-key")); } @@ -165,7 +165,7 @@ public abstract class CommandSupports { return arg; }).replaceSuggestions(ArgumentSuggestions.stringCollectionAsync(info -> CompletableFuture.supplyAsync(() -> { - var key = (FeatureKey) info.previousArgs().get(configKeyNodeName); + var key = (Feature) info.previousArgs().get(configKeyNodeName); if (key == null) { return Collections.emptyList(); } diff --git a/fakeplayer-core/src/main/java/io/github/hello09x/fakeplayer/core/command/impl/ConfigCommand.java b/fakeplayer-core/src/main/java/io/github/hello09x/fakeplayer/core/command/impl/ConfigCommand.java index 0b19dd3..48a718f 100644 --- a/fakeplayer-core/src/main/java/io/github/hello09x/fakeplayer/core/command/impl/ConfigCommand.java +++ b/fakeplayer-core/src/main/java/io/github/hello09x/fakeplayer/core/command/impl/ConfigCommand.java @@ -9,7 +9,7 @@ import io.github.hello09x.devtools.core.translation.TranslatorUtils; import io.github.hello09x.devtools.core.utils.ComponentUtils; import io.github.hello09x.fakeplayer.core.Main; import io.github.hello09x.fakeplayer.core.manager.feature.FakeplayerFeatureManager; -import io.github.hello09x.fakeplayer.core.repository.model.FeatureKey; +import io.github.hello09x.fakeplayer.core.repository.model.Feature; import net.kyori.adventure.text.Component; import net.kyori.adventure.text.format.Style; import org.bukkit.Bukkit; @@ -39,8 +39,8 @@ public class ConfigCommand extends AbstractCommand { * 设置配置 */ public void setConfig(@NotNull Player sender, @NotNull CommandArguments args) throws WrapperCommandSyntaxException { - var key = (FeatureKey) Objects.requireNonNull(args.get("feature")); - if (!key.testPermissions(sender)) { + var feature = (Feature) Objects.requireNonNull(args.get("feature")); + if (!feature.testPermissions(sender)) { throw CommandAPI.failWithString(ComponentUtils.toString( translatable("fakeplayer.command.config.set.error.no-permission"), TranslatorUtils.getLocale(sender) @@ -48,10 +48,10 @@ public class ConfigCommand extends AbstractCommand { } var option = (String) Objects.requireNonNull(args.get("option")); - featureManager.setFeature(sender, key, option); + featureManager.setFeature(sender, feature, option); sender.sendMessage(translatable( "fakeplayer.command.config.set.success", - translatable(key.translationKey(), GOLD), + translatable(feature.translationKey(), GOLD), text(option, WHITE) ).color(GRAY)); } diff --git a/fakeplayer-core/src/main/java/io/github/hello09x/fakeplayer/core/command/impl/SetCommand.java b/fakeplayer-core/src/main/java/io/github/hello09x/fakeplayer/core/command/impl/SetCommand.java index 7623a7e..77af32a 100644 --- a/fakeplayer-core/src/main/java/io/github/hello09x/fakeplayer/core/command/impl/SetCommand.java +++ b/fakeplayer-core/src/main/java/io/github/hello09x/fakeplayer/core/command/impl/SetCommand.java @@ -3,7 +3,7 @@ package io.github.hello09x.fakeplayer.core.command.impl; import com.google.inject.Singleton; import dev.jorel.commandapi.exceptions.WrapperCommandSyntaxException; import dev.jorel.commandapi.executors.CommandArguments; -import io.github.hello09x.fakeplayer.core.repository.model.FeatureKey; +import io.github.hello09x.fakeplayer.core.repository.model.Feature; import org.bukkit.command.CommandSender; import org.jetbrains.annotations.NotNull; @@ -18,10 +18,10 @@ public class SetCommand extends AbstractCommand { public void set(@NotNull CommandSender sender, @NotNull CommandArguments args) throws WrapperCommandSyntaxException { var target = super.getFakeplayer(sender, args); - var key = (FeatureKey) Objects.requireNonNull(args.get("feature")); + var feature = (Feature) Objects.requireNonNull(args.get("feature")); var value = (String) Objects.requireNonNull(args.get("option")); - var modifier = key.getModifier(); + var modifier = feature.getModifier(); if (modifier == null) { sender.sendMessage(translatable("fakeplayer.command.config.set.error.invalid-key", RED)); return; @@ -31,7 +31,7 @@ public class SetCommand extends AbstractCommand { sender.sendMessage(translatable( "fakeplayer.command.set.success", text(target.getName(), WHITE), - translatable(key, GOLD), + translatable(feature, GOLD), text(value, WHITE) ).color(GRAY)); diff --git a/fakeplayer-core/src/main/java/io/github/hello09x/fakeplayer/core/command/impl/StatusCommand.java b/fakeplayer-core/src/main/java/io/github/hello09x/fakeplayer/core/command/impl/StatusCommand.java index 11f506d..84444da 100644 --- a/fakeplayer-core/src/main/java/io/github/hello09x/fakeplayer/core/command/impl/StatusCommand.java +++ b/fakeplayer-core/src/main/java/io/github/hello09x/fakeplayer/core/command/impl/StatusCommand.java @@ -5,7 +5,7 @@ import dev.jorel.commandapi.exceptions.WrapperCommandSyntaxException; import dev.jorel.commandapi.executors.CommandArguments; import io.github.hello09x.devtools.core.utils.ExperienceUtils; import io.github.hello09x.fakeplayer.core.command.Permission; -import io.github.hello09x.fakeplayer.core.repository.model.FeatureKey; +import io.github.hello09x.fakeplayer.core.repository.model.Feature; import io.github.hello09x.fakeplayer.core.util.Mth; import net.kyori.adventure.text.Component; import net.kyori.adventure.text.JoinConfiguration; @@ -118,13 +118,13 @@ public class StatusCommand extends AbstractCommand { private @NotNull Component getFeatureLine(@NotNull Player faker) { var messages = new ArrayList(); - for (var key : FeatureKey.values()) { - var detector = key.getDetector(); + for (var feature : Feature.values()) { + var detector = feature.getDetector(); if (detector == null) { continue; } - var name = translatable(key, WHITE); - var options = key.getOptions(); + var name = translatable(feature, WHITE); + var options = feature.getOptions(); var status = detector.apply(faker); messages.add(textOfChildren( @@ -133,7 +133,7 @@ public class StatusCommand extends AbstractCommand { join(separator(space()), options.stream().map(option -> { var style = option.equals(status) ? Style.style(GREEN, UNDERLINED) : Style.style(GRAY); return text("[" + option + "]").style(style).clickEvent( - runCommand("/fp set %s %s %s".formatted(key.name(), option, faker.getName())) + runCommand("/fp set %s %s %s".formatted(feature.name(), option, faker.getName())) ); }).toList()) )); 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 index 12be8a2..dfec7bf 100644 --- 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 @@ -7,7 +7,7 @@ import com.google.inject.Singleton; import io.github.hello09x.devtools.core.config.ConfigUtils; import io.github.hello09x.devtools.core.config.PluginConfig; import io.github.hello09x.fakeplayer.core.Main; -import io.github.hello09x.fakeplayer.core.repository.model.FeatureKey; +import io.github.hello09x.fakeplayer.core.repository.model.Feature; import lombok.Getter; import lombok.ToString; import org.bukkit.Bukkit; @@ -157,7 +157,7 @@ public class FakeplayerConfig extends PluginConfig { @Beta private boolean defaultOnlineSkin; - private Map defaultFeatures; + private Map defaultFeatures; @Inject public FakeplayerConfig() { @@ -197,7 +197,7 @@ public class FakeplayerConfig extends PluginConfig { .collect(Collectors.toSet()); this.defaultOnlineSkin = file.getBoolean("default-online-skin", false); - this.defaultFeatures = Arrays.stream(FeatureKey.values()) + this.defaultFeatures = Arrays.stream(Feature.values()) .collect(Collectors.toMap(Function.identity(), key -> file.getString("default-features." + key.name(), key.getDefaultOption()))); this.invseeImplement = ConfigUtils.getEnum(file, "invsee-implement", InvseeImplement.class, InvseeImplement.AUTO); this.debug = file.getBoolean("debug", false); 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 39bc7ff..e3c6798 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 @@ -15,7 +15,7 @@ import io.github.hello09x.fakeplayer.core.entity.Fakeplayer; import io.github.hello09x.fakeplayer.core.entity.SpawnOption; import io.github.hello09x.fakeplayer.core.manager.feature.FakeplayerFeatureManager; import io.github.hello09x.fakeplayer.core.manager.naming.NameManager; -import io.github.hello09x.fakeplayer.core.repository.model.FeatureKey; +import io.github.hello09x.fakeplayer.core.repository.model.Feature; import io.github.hello09x.fakeplayer.core.util.AddressUtils; import io.github.hello09x.fakeplayer.core.util.Commands; import net.kyori.adventure.text.Component; @@ -111,13 +111,13 @@ public class FakeplayerManager { var configs = featureManager.getFeatures(creator); return new SpawnOption( spawnAt, - configs.get(FeatureKey.invulnerable).asBoolean(), - configs.get(FeatureKey.collidable).asBoolean(), - configs.get(FeatureKey.look_at_entity).asBoolean(), - configs.get(FeatureKey.pickup_items).asBoolean(), - configs.get(FeatureKey.skin).asBoolean(), - configs.get(FeatureKey.replenish).asBoolean(), - configs.get(FeatureKey.autofish).asBoolean() + configs.get(Feature.invulnerable).asBoolean(), + configs.get(Feature.collidable).asBoolean(), + configs.get(Feature.look_at_entity).asBoolean(), + configs.get(Feature.pickup_items).asBoolean(), + configs.get(Feature.skin).asBoolean(), + configs.get(Feature.replenish).asBoolean(), + configs.get(Feature.autofish).asBoolean() ); }) .thenComposeAsync(fp::spawnAsync) diff --git a/fakeplayer-core/src/main/java/io/github/hello09x/fakeplayer/core/manager/feature/FakeplayerFeatureManager.java b/fakeplayer-core/src/main/java/io/github/hello09x/fakeplayer/core/manager/feature/FakeplayerFeatureManager.java index c47cff1..b3c0e6e 100644 --- a/fakeplayer-core/src/main/java/io/github/hello09x/fakeplayer/core/manager/feature/FakeplayerFeatureManager.java +++ b/fakeplayer-core/src/main/java/io/github/hello09x/fakeplayer/core/manager/feature/FakeplayerFeatureManager.java @@ -4,7 +4,7 @@ import com.google.inject.Inject; import com.google.inject.Singleton; import io.github.hello09x.fakeplayer.core.config.FakeplayerConfig; import io.github.hello09x.fakeplayer.core.repository.UserConfigRepository; -import io.github.hello09x.fakeplayer.core.repository.model.FeatureKey; +import io.github.hello09x.fakeplayer.core.repository.model.Feature; import io.github.hello09x.fakeplayer.core.repository.model.UserConfig; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; @@ -29,45 +29,45 @@ public class FakeplayerFeatureManager { this.config = config; } - private @NotNull String getDefaultOption(@NotNull FeatureKey key) { + private @NotNull String getDefaultOption(@NotNull Feature key) { return Optional.ofNullable(config.getDefaultFeatures().get(key)).filter(option -> key.getOptions().contains(option)).orElse(key.getDefaultOption()); } - public @NotNull Feature getFeature(@NotNull Player player, @NotNull FeatureKey key) { + public @NotNull FeatureInstance getFeature(@NotNull Player player, @NotNull Feature key) { if (!key.testPermissions(player)) { - return new Feature(key, this.getDefaultOption(key)); + return new FeatureInstance(key, this.getDefaultOption(key)); } String value = Optional.ofNullable(repository.selectByPlayerIdAndKey(player.getUniqueId(), key)) .map(UserConfig::value) .orElseGet(() -> this.getDefaultOption(key)); - return new Feature(key, value); + return new FeatureInstance(key, value); } - public @NotNull Map getFeatures(@NotNull CommandSender sender) { - Map userConfigs; + public @NotNull Map getFeatures(@NotNull CommandSender sender) { + Map userConfigs; if (sender instanceof Player player) { userConfigs = repository.selectByPlayerId(player.getUniqueId()).stream().collect(Collectors.toMap(UserConfig::key, Function.identity())); } else { userConfigs = Collections.emptyMap(); } - var configs = new LinkedHashMap(FeatureKey.values().length, 1.0F); - for (var key : FeatureKey.values()) { + var configs = new LinkedHashMap(Feature.values().length, 1.0F); + for (var key : Feature.values()) { String value; if (!key.testPermissions(sender)) { value = this.getDefaultOption(key); } else { value = Optional.ofNullable(userConfigs.get(key)).map(UserConfig::value).orElseGet(() -> this.getDefaultOption(key)); } - configs.put(key, new Feature(key, value)); + configs.put(key, new FeatureInstance(key, value)); } return configs; } - public void setFeature(@NotNull Player player, @NotNull FeatureKey key, @NotNull String value) { + public void setFeature(@NotNull Player player, @NotNull Feature key, @NotNull String value) { this.repository.saveOrUpdate(new UserConfig( null, player.getUniqueId(), diff --git a/fakeplayer-core/src/main/java/io/github/hello09x/fakeplayer/core/manager/feature/Feature.java b/fakeplayer-core/src/main/java/io/github/hello09x/fakeplayer/core/manager/feature/FeatureInstance.java similarity index 88% rename from fakeplayer-core/src/main/java/io/github/hello09x/fakeplayer/core/manager/feature/Feature.java rename to fakeplayer-core/src/main/java/io/github/hello09x/fakeplayer/core/manager/feature/FeatureInstance.java index 43d47d7..d7ac607 100644 --- a/fakeplayer-core/src/main/java/io/github/hello09x/fakeplayer/core/manager/feature/Feature.java +++ b/fakeplayer-core/src/main/java/io/github/hello09x/fakeplayer/core/manager/feature/FeatureInstance.java @@ -1,16 +1,16 @@ package io.github.hello09x.fakeplayer.core.manager.feature; -import io.github.hello09x.fakeplayer.core.repository.model.FeatureKey; +import io.github.hello09x.fakeplayer.core.repository.model.Feature; import org.jetbrains.annotations.NotNull; /** * @author tanyaofei * @since 2024/8/13 **/ -public record Feature( +public record FeatureInstance( @NotNull - FeatureKey key, + Feature key, @NotNull String value diff --git a/fakeplayer-core/src/main/java/io/github/hello09x/fakeplayer/core/repository/UserConfigRepository.java b/fakeplayer-core/src/main/java/io/github/hello09x/fakeplayer/core/repository/UserConfigRepository.java index 5f1934b..c24f3f2 100644 --- a/fakeplayer-core/src/main/java/io/github/hello09x/fakeplayer/core/repository/UserConfigRepository.java +++ b/fakeplayer-core/src/main/java/io/github/hello09x/fakeplayer/core/repository/UserConfigRepository.java @@ -3,7 +3,7 @@ package io.github.hello09x.fakeplayer.core.repository; import com.google.inject.Inject; import com.google.inject.Singleton; import io.github.hello09x.devtools.database.jdbc.JdbcTemplate; -import io.github.hello09x.fakeplayer.core.repository.model.FeatureKey; +import io.github.hello09x.fakeplayer.core.repository.model.Feature; import io.github.hello09x.fakeplayer.core.repository.model.UserConfig; import io.github.hello09x.fakeplayer.core.repository.model.UserConfigRowMapper; import org.jetbrains.annotations.NotNull; @@ -23,9 +23,9 @@ public class UserConfigRepository { this.initTables(); } - public @Nullable UserConfig selectByPlayerIdAndKey(@NotNull UUID playerId, @NotNull FeatureKey featureKey) { + public @Nullable UserConfig selectByPlayerIdAndKey(@NotNull UUID playerId, @NotNull Feature feature) { var sql = "select * from user_config where player_id = ? and `key` = ?"; - return jdbc.queryForObject(sql, UserConfigRowMapper.instance, playerId.toString(), featureKey.name()); + return jdbc.queryForObject(sql, UserConfigRowMapper.instance, playerId.toString(), feature.name()); } public int saveOrUpdate(@NotNull UserConfig config) { diff --git a/fakeplayer-core/src/main/java/io/github/hello09x/fakeplayer/core/repository/model/FeatureKey.java b/fakeplayer-core/src/main/java/io/github/hello09x/fakeplayer/core/repository/model/Feature.java similarity index 98% rename from fakeplayer-core/src/main/java/io/github/hello09x/fakeplayer/core/repository/model/FeatureKey.java rename to fakeplayer-core/src/main/java/io/github/hello09x/fakeplayer/core/repository/model/Feature.java index 83b9f97..6e62da6 100644 --- a/fakeplayer-core/src/main/java/io/github/hello09x/fakeplayer/core/repository/model/FeatureKey.java +++ b/fakeplayer-core/src/main/java/io/github/hello09x/fakeplayer/core/repository/model/Feature.java @@ -21,7 +21,7 @@ import java.util.function.Function; **/ @Getter @AllArgsConstructor -public enum FeatureKey implements Translatable, Singletons { +public enum Feature implements Translatable, Singletons { /** * 是否具有碰撞箱 diff --git a/fakeplayer-core/src/main/java/io/github/hello09x/fakeplayer/core/repository/model/UserConfig.java b/fakeplayer-core/src/main/java/io/github/hello09x/fakeplayer/core/repository/model/UserConfig.java index b2b1e09..6df2b5b 100644 --- a/fakeplayer-core/src/main/java/io/github/hello09x/fakeplayer/core/repository/model/UserConfig.java +++ b/fakeplayer-core/src/main/java/io/github/hello09x/fakeplayer/core/repository/model/UserConfig.java @@ -13,7 +13,7 @@ public record UserConfig( UUID playerId, @NotNull - FeatureKey key, + Feature key, @NotNull String value diff --git a/fakeplayer-core/src/main/java/io/github/hello09x/fakeplayer/core/repository/model/UserConfigRowMapper.java b/fakeplayer-core/src/main/java/io/github/hello09x/fakeplayer/core/repository/model/UserConfigRowMapper.java index 1f919f1..e6edf33 100644 --- a/fakeplayer-core/src/main/java/io/github/hello09x/fakeplayer/core/repository/model/UserConfigRowMapper.java +++ b/fakeplayer-core/src/main/java/io/github/hello09x/fakeplayer/core/repository/model/UserConfigRowMapper.java @@ -21,7 +21,7 @@ public class UserConfigRowMapper implements RowMapper { return new UserConfig( rs.getInt("id"), UUID.fromString(rs.getString("player_id")), - FeatureKey.valueOf(rs.getString("key")), + Feature.valueOf(rs.getString("key")), rs.getString("value") ); }