mirror of
https://github.com/tanyaofei/minecraft-fakeplayer.git
synced 2025-07-13 21:02:27 +08:00
Noting important
This commit is contained in:
parent
f788729420
commit
7be8b7c675
@ -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.command.impl.*;
|
||||||
import io.github.hello09x.fakeplayer.core.config.FakeplayerConfig;
|
import io.github.hello09x.fakeplayer.core.config.FakeplayerConfig;
|
||||||
import io.github.hello09x.fakeplayer.core.constant.Direction;
|
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.Entity;
|
||||||
import org.bukkit.entity.LivingEntity;
|
import org.bukkit.entity.LivingEntity;
|
||||||
|
|
||||||
@ -173,7 +173,7 @@ public class CommandRegistry {
|
|||||||
.withShortDescription("fakeplayer.command.set.description")
|
.withShortDescription("fakeplayer.command.set.description")
|
||||||
.withPermission(Permission.set)
|
.withPermission(Permission.set)
|
||||||
.withArguments(
|
.withArguments(
|
||||||
configKey("feature", FeatureKey::hasModifier),
|
configKey("feature", Feature::hasModifier),
|
||||||
configValue("feature", "option")
|
configValue("feature", "option")
|
||||||
)
|
)
|
||||||
.withOptionalArguments(fakeplayer("name"))
|
.withOptionalArguments(fakeplayer("name"))
|
||||||
|
@ -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.command.impl.ActionCommand;
|
||||||
import io.github.hello09x.fakeplayer.core.config.FakeplayerConfig;
|
import io.github.hello09x.fakeplayer.core.config.FakeplayerConfig;
|
||||||
import io.github.hello09x.fakeplayer.core.manager.FakeplayerManager;
|
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.command.CommandSender;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
@ -126,16 +126,16 @@ public abstract class CommandSupports {
|
|||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
|
|
||||||
public static @NotNull Argument<FeatureKey> configKey(@NotNull String nodeName) {
|
public static @NotNull Argument<Feature> configKey(@NotNull String nodeName) {
|
||||||
return configKey(nodeName, ignored -> true);
|
return configKey(nodeName, ignored -> true);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static @NotNull Argument<FeatureKey> configKey(@NotNull String nodeName, @NotNull Predicate<FeatureKey> predicate) {
|
public static @NotNull Argument<Feature> configKey(@NotNull String nodeName, @NotNull Predicate<Feature> predicate) {
|
||||||
return new CustomArgument<>(new StringArgument(nodeName), info -> {
|
return new CustomArgument<>(new StringArgument(nodeName), info -> {
|
||||||
var arg = info.currentInput();
|
var arg = info.currentInput();
|
||||||
FeatureKey key;
|
Feature key;
|
||||||
try {
|
try {
|
||||||
key = FeatureKey.valueOf(arg);
|
key = Feature.valueOf(arg);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
throw CustomArgument.CustomArgumentException.fromAdventureComponent(translatable("fakeplayer.command.config.set.error.invalid-key"));
|
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"));
|
throw CustomArgument.CustomArgumentException.fromAdventureComponent(translatable("fakeplayer.command.config.set.error.no-permission"));
|
||||||
}
|
}
|
||||||
return key;
|
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<String> configValue(@NotNull String configKeyNodeName, @NotNull String nodeName) {
|
public static @NotNull Argument<String> configValue(@NotNull String configKeyNodeName, @NotNull String nodeName) {
|
||||||
return new CustomArgument<String, String>(new StringArgument(nodeName), info -> {
|
return new CustomArgument<String, String>(new StringArgument(nodeName), info -> {
|
||||||
var key = (FeatureKey) info.previousArgs().get(configKeyNodeName);
|
var key = (Feature) info.previousArgs().get(configKeyNodeName);
|
||||||
if (key == null) {
|
if (key == null) {
|
||||||
throw CustomArgument.CustomArgumentException.fromAdventureComponent(translatable("fakeplayer.command.config.set.error.invalid-key"));
|
throw CustomArgument.CustomArgumentException.fromAdventureComponent(translatable("fakeplayer.command.config.set.error.invalid-key"));
|
||||||
}
|
}
|
||||||
@ -165,7 +165,7 @@ public abstract class CommandSupports {
|
|||||||
|
|
||||||
return arg;
|
return arg;
|
||||||
}).replaceSuggestions(ArgumentSuggestions.stringCollectionAsync(info -> CompletableFuture.supplyAsync(() -> {
|
}).replaceSuggestions(ArgumentSuggestions.stringCollectionAsync(info -> CompletableFuture.supplyAsync(() -> {
|
||||||
var key = (FeatureKey) info.previousArgs().get(configKeyNodeName);
|
var key = (Feature) info.previousArgs().get(configKeyNodeName);
|
||||||
if (key == null) {
|
if (key == null) {
|
||||||
return Collections.emptyList();
|
return Collections.emptyList();
|
||||||
}
|
}
|
||||||
|
@ -9,7 +9,7 @@ import io.github.hello09x.devtools.core.translation.TranslatorUtils;
|
|||||||
import io.github.hello09x.devtools.core.utils.ComponentUtils;
|
import io.github.hello09x.devtools.core.utils.ComponentUtils;
|
||||||
import io.github.hello09x.fakeplayer.core.Main;
|
import io.github.hello09x.fakeplayer.core.Main;
|
||||||
import io.github.hello09x.fakeplayer.core.manager.feature.FakeplayerFeatureManager;
|
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.Component;
|
||||||
import net.kyori.adventure.text.format.Style;
|
import net.kyori.adventure.text.format.Style;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
@ -39,8 +39,8 @@ public class ConfigCommand extends AbstractCommand {
|
|||||||
* 设置配置
|
* 设置配置
|
||||||
*/
|
*/
|
||||||
public void setConfig(@NotNull Player sender, @NotNull CommandArguments args) throws WrapperCommandSyntaxException {
|
public void setConfig(@NotNull Player sender, @NotNull CommandArguments args) throws WrapperCommandSyntaxException {
|
||||||
var key = (FeatureKey) Objects.requireNonNull(args.get("feature"));
|
var feature = (Feature) Objects.requireNonNull(args.get("feature"));
|
||||||
if (!key.testPermissions(sender)) {
|
if (!feature.testPermissions(sender)) {
|
||||||
throw CommandAPI.failWithString(ComponentUtils.toString(
|
throw CommandAPI.failWithString(ComponentUtils.toString(
|
||||||
translatable("fakeplayer.command.config.set.error.no-permission"),
|
translatable("fakeplayer.command.config.set.error.no-permission"),
|
||||||
TranslatorUtils.getLocale(sender)
|
TranslatorUtils.getLocale(sender)
|
||||||
@ -48,10 +48,10 @@ public class ConfigCommand extends AbstractCommand {
|
|||||||
}
|
}
|
||||||
|
|
||||||
var option = (String) Objects.requireNonNull(args.get("option"));
|
var option = (String) Objects.requireNonNull(args.get("option"));
|
||||||
featureManager.setFeature(sender, key, option);
|
featureManager.setFeature(sender, feature, option);
|
||||||
sender.sendMessage(translatable(
|
sender.sendMessage(translatable(
|
||||||
"fakeplayer.command.config.set.success",
|
"fakeplayer.command.config.set.success",
|
||||||
translatable(key.translationKey(), GOLD),
|
translatable(feature.translationKey(), GOLD),
|
||||||
text(option, WHITE)
|
text(option, WHITE)
|
||||||
).color(GRAY));
|
).color(GRAY));
|
||||||
}
|
}
|
||||||
|
@ -3,7 +3,7 @@ package io.github.hello09x.fakeplayer.core.command.impl;
|
|||||||
import com.google.inject.Singleton;
|
import com.google.inject.Singleton;
|
||||||
import dev.jorel.commandapi.exceptions.WrapperCommandSyntaxException;
|
import dev.jorel.commandapi.exceptions.WrapperCommandSyntaxException;
|
||||||
import dev.jorel.commandapi.executors.CommandArguments;
|
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.bukkit.command.CommandSender;
|
||||||
import org.jetbrains.annotations.NotNull;
|
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 {
|
public void set(@NotNull CommandSender sender, @NotNull CommandArguments args) throws WrapperCommandSyntaxException {
|
||||||
var target = super.getFakeplayer(sender, args);
|
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 value = (String) Objects.requireNonNull(args.get("option"));
|
||||||
|
|
||||||
var modifier = key.getModifier();
|
var modifier = feature.getModifier();
|
||||||
if (modifier == null) {
|
if (modifier == null) {
|
||||||
sender.sendMessage(translatable("fakeplayer.command.config.set.error.invalid-key", RED));
|
sender.sendMessage(translatable("fakeplayer.command.config.set.error.invalid-key", RED));
|
||||||
return;
|
return;
|
||||||
@ -31,7 +31,7 @@ public class SetCommand extends AbstractCommand {
|
|||||||
sender.sendMessage(translatable(
|
sender.sendMessage(translatable(
|
||||||
"fakeplayer.command.set.success",
|
"fakeplayer.command.set.success",
|
||||||
text(target.getName(), WHITE),
|
text(target.getName(), WHITE),
|
||||||
translatable(key, GOLD),
|
translatable(feature, GOLD),
|
||||||
text(value, WHITE)
|
text(value, WHITE)
|
||||||
).color(GRAY));
|
).color(GRAY));
|
||||||
|
|
||||||
|
@ -5,7 +5,7 @@ import dev.jorel.commandapi.exceptions.WrapperCommandSyntaxException;
|
|||||||
import dev.jorel.commandapi.executors.CommandArguments;
|
import dev.jorel.commandapi.executors.CommandArguments;
|
||||||
import io.github.hello09x.devtools.core.utils.ExperienceUtils;
|
import io.github.hello09x.devtools.core.utils.ExperienceUtils;
|
||||||
import io.github.hello09x.fakeplayer.core.command.Permission;
|
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 io.github.hello09x.fakeplayer.core.util.Mth;
|
||||||
import net.kyori.adventure.text.Component;
|
import net.kyori.adventure.text.Component;
|
||||||
import net.kyori.adventure.text.JoinConfiguration;
|
import net.kyori.adventure.text.JoinConfiguration;
|
||||||
@ -118,13 +118,13 @@ public class StatusCommand extends AbstractCommand {
|
|||||||
|
|
||||||
private @NotNull Component getFeatureLine(@NotNull Player faker) {
|
private @NotNull Component getFeatureLine(@NotNull Player faker) {
|
||||||
var messages = new ArrayList<Component>();
|
var messages = new ArrayList<Component>();
|
||||||
for (var key : FeatureKey.values()) {
|
for (var feature : Feature.values()) {
|
||||||
var detector = key.getDetector();
|
var detector = feature.getDetector();
|
||||||
if (detector == null) {
|
if (detector == null) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
var name = translatable(key, WHITE);
|
var name = translatable(feature, WHITE);
|
||||||
var options = key.getOptions();
|
var options = feature.getOptions();
|
||||||
var status = detector.apply(faker);
|
var status = detector.apply(faker);
|
||||||
|
|
||||||
messages.add(textOfChildren(
|
messages.add(textOfChildren(
|
||||||
@ -133,7 +133,7 @@ public class StatusCommand extends AbstractCommand {
|
|||||||
join(separator(space()), options.stream().map(option -> {
|
join(separator(space()), options.stream().map(option -> {
|
||||||
var style = option.equals(status) ? Style.style(GREEN, UNDERLINED) : Style.style(GRAY);
|
var style = option.equals(status) ? Style.style(GREEN, UNDERLINED) : Style.style(GRAY);
|
||||||
return text("[" + option + "]").style(style).clickEvent(
|
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())
|
}).toList())
|
||||||
));
|
));
|
||||||
|
@ -7,7 +7,7 @@ import com.google.inject.Singleton;
|
|||||||
import io.github.hello09x.devtools.core.config.ConfigUtils;
|
import io.github.hello09x.devtools.core.config.ConfigUtils;
|
||||||
import io.github.hello09x.devtools.core.config.PluginConfig;
|
import io.github.hello09x.devtools.core.config.PluginConfig;
|
||||||
import io.github.hello09x.fakeplayer.core.Main;
|
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.Getter;
|
||||||
import lombok.ToString;
|
import lombok.ToString;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
@ -157,7 +157,7 @@ public class FakeplayerConfig extends PluginConfig {
|
|||||||
@Beta
|
@Beta
|
||||||
private boolean defaultOnlineSkin;
|
private boolean defaultOnlineSkin;
|
||||||
|
|
||||||
private Map<FeatureKey, String> defaultFeatures;
|
private Map<Feature, String> defaultFeatures;
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
public FakeplayerConfig() {
|
public FakeplayerConfig() {
|
||||||
@ -197,7 +197,7 @@ public class FakeplayerConfig extends PluginConfig {
|
|||||||
.collect(Collectors.toSet());
|
.collect(Collectors.toSet());
|
||||||
|
|
||||||
this.defaultOnlineSkin = file.getBoolean("default-online-skin", false);
|
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())));
|
.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.invseeImplement = ConfigUtils.getEnum(file, "invsee-implement", InvseeImplement.class, InvseeImplement.AUTO);
|
||||||
this.debug = file.getBoolean("debug", false);
|
this.debug = file.getBoolean("debug", false);
|
||||||
|
@ -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.entity.SpawnOption;
|
||||||
import io.github.hello09x.fakeplayer.core.manager.feature.FakeplayerFeatureManager;
|
import io.github.hello09x.fakeplayer.core.manager.feature.FakeplayerFeatureManager;
|
||||||
import io.github.hello09x.fakeplayer.core.manager.naming.NameManager;
|
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.AddressUtils;
|
||||||
import io.github.hello09x.fakeplayer.core.util.Commands;
|
import io.github.hello09x.fakeplayer.core.util.Commands;
|
||||||
import net.kyori.adventure.text.Component;
|
import net.kyori.adventure.text.Component;
|
||||||
@ -111,13 +111,13 @@ public class FakeplayerManager {
|
|||||||
var configs = featureManager.getFeatures(creator);
|
var configs = featureManager.getFeatures(creator);
|
||||||
return new SpawnOption(
|
return new SpawnOption(
|
||||||
spawnAt,
|
spawnAt,
|
||||||
configs.get(FeatureKey.invulnerable).asBoolean(),
|
configs.get(Feature.invulnerable).asBoolean(),
|
||||||
configs.get(FeatureKey.collidable).asBoolean(),
|
configs.get(Feature.collidable).asBoolean(),
|
||||||
configs.get(FeatureKey.look_at_entity).asBoolean(),
|
configs.get(Feature.look_at_entity).asBoolean(),
|
||||||
configs.get(FeatureKey.pickup_items).asBoolean(),
|
configs.get(Feature.pickup_items).asBoolean(),
|
||||||
configs.get(FeatureKey.skin).asBoolean(),
|
configs.get(Feature.skin).asBoolean(),
|
||||||
configs.get(FeatureKey.replenish).asBoolean(),
|
configs.get(Feature.replenish).asBoolean(),
|
||||||
configs.get(FeatureKey.autofish).asBoolean()
|
configs.get(Feature.autofish).asBoolean()
|
||||||
);
|
);
|
||||||
})
|
})
|
||||||
.thenComposeAsync(fp::spawnAsync)
|
.thenComposeAsync(fp::spawnAsync)
|
||||||
|
@ -4,7 +4,7 @@ import com.google.inject.Inject;
|
|||||||
import com.google.inject.Singleton;
|
import com.google.inject.Singleton;
|
||||||
import io.github.hello09x.fakeplayer.core.config.FakeplayerConfig;
|
import io.github.hello09x.fakeplayer.core.config.FakeplayerConfig;
|
||||||
import io.github.hello09x.fakeplayer.core.repository.UserConfigRepository;
|
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 io.github.hello09x.fakeplayer.core.repository.model.UserConfig;
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
@ -29,45 +29,45 @@ public class FakeplayerFeatureManager {
|
|||||||
this.config = config;
|
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());
|
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)) {
|
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))
|
String value = Optional.ofNullable(repository.selectByPlayerIdAndKey(player.getUniqueId(), key))
|
||||||
.map(UserConfig::value)
|
.map(UserConfig::value)
|
||||||
.orElseGet(() -> this.getDefaultOption(key));
|
.orElseGet(() -> this.getDefaultOption(key));
|
||||||
|
|
||||||
return new Feature(key, value);
|
return new FeatureInstance(key, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
public @NotNull Map<FeatureKey, Feature> getFeatures(@NotNull CommandSender sender) {
|
public @NotNull Map<Feature, FeatureInstance> getFeatures(@NotNull CommandSender sender) {
|
||||||
Map<FeatureKey, UserConfig> userConfigs;
|
Map<Feature, UserConfig> userConfigs;
|
||||||
if (sender instanceof Player player) {
|
if (sender instanceof Player player) {
|
||||||
userConfigs = repository.selectByPlayerId(player.getUniqueId()).stream().collect(Collectors.toMap(UserConfig::key, Function.identity()));
|
userConfigs = repository.selectByPlayerId(player.getUniqueId()).stream().collect(Collectors.toMap(UserConfig::key, Function.identity()));
|
||||||
} else {
|
} else {
|
||||||
userConfigs = Collections.emptyMap();
|
userConfigs = Collections.emptyMap();
|
||||||
}
|
}
|
||||||
|
|
||||||
var configs = new LinkedHashMap<FeatureKey, Feature>(FeatureKey.values().length, 1.0F);
|
var configs = new LinkedHashMap<Feature, FeatureInstance>(Feature.values().length, 1.0F);
|
||||||
for (var key : FeatureKey.values()) {
|
for (var key : Feature.values()) {
|
||||||
String value;
|
String value;
|
||||||
if (!key.testPermissions(sender)) {
|
if (!key.testPermissions(sender)) {
|
||||||
value = this.getDefaultOption(key);
|
value = this.getDefaultOption(key);
|
||||||
} else {
|
} else {
|
||||||
value = Optional.ofNullable(userConfigs.get(key)).map(UserConfig::value).orElseGet(() -> this.getDefaultOption(key));
|
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;
|
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(
|
this.repository.saveOrUpdate(new UserConfig(
|
||||||
null,
|
null,
|
||||||
player.getUniqueId(),
|
player.getUniqueId(),
|
||||||
|
@ -1,16 +1,16 @@
|
|||||||
package io.github.hello09x.fakeplayer.core.manager.feature;
|
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;
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author tanyaofei
|
* @author tanyaofei
|
||||||
* @since 2024/8/13
|
* @since 2024/8/13
|
||||||
**/
|
**/
|
||||||
public record Feature(
|
public record FeatureInstance(
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
FeatureKey key,
|
Feature key,
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
String value
|
String value
|
@ -3,7 +3,7 @@ package io.github.hello09x.fakeplayer.core.repository;
|
|||||||
import com.google.inject.Inject;
|
import com.google.inject.Inject;
|
||||||
import com.google.inject.Singleton;
|
import com.google.inject.Singleton;
|
||||||
import io.github.hello09x.devtools.database.jdbc.JdbcTemplate;
|
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.UserConfig;
|
||||||
import io.github.hello09x.fakeplayer.core.repository.model.UserConfigRowMapper;
|
import io.github.hello09x.fakeplayer.core.repository.model.UserConfigRowMapper;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
@ -23,9 +23,9 @@ public class UserConfigRepository {
|
|||||||
this.initTables();
|
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` = ?";
|
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) {
|
public int saveOrUpdate(@NotNull UserConfig config) {
|
||||||
|
@ -21,7 +21,7 @@ import java.util.function.Function;
|
|||||||
**/
|
**/
|
||||||
@Getter
|
@Getter
|
||||||
@AllArgsConstructor
|
@AllArgsConstructor
|
||||||
public enum FeatureKey implements Translatable, Singletons {
|
public enum Feature implements Translatable, Singletons {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 是否具有碰撞箱
|
* 是否具有碰撞箱
|
@ -13,7 +13,7 @@ public record UserConfig(
|
|||||||
UUID playerId,
|
UUID playerId,
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
FeatureKey key,
|
Feature key,
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
String value
|
String value
|
||||||
|
@ -21,7 +21,7 @@ public class UserConfigRowMapper implements RowMapper<UserConfig> {
|
|||||||
return new UserConfig(
|
return new UserConfig(
|
||||||
rs.getInt("id"),
|
rs.getInt("id"),
|
||||||
UUID.fromString(rs.getString("player_id")),
|
UUID.fromString(rs.getString("player_id")),
|
||||||
FeatureKey.valueOf(rs.getString("key")),
|
Feature.valueOf(rs.getString("key")),
|
||||||
rs.getString("value")
|
rs.getString("value")
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user