Fixup config map reading inconsistencies, close #471

This commit is contained in:
William committed 2023-07-24 11:42:09 +01:00
1 parent e7c95ee742
commit 6455f15d92
9 files changed
+114 -58

No files matched your search

+3 -3
View File
@@ -59,9 +59,9 @@ allprojects {
}
dependencies {
testImplementation 'org.junit.jupiter:junit-jupiter-api:5.9.3'
testImplementation 'org.junit.jupiter:junit-jupiter-params:5.9.3'
testImplementation 'org.junit.jupiter:junit-jupiter-engine:5.9.3'
testImplementation 'org.junit.jupiter:junit-jupiter-api:5.10.0'
testImplementation 'org.junit.jupiter:junit-jupiter-params:5.10.0'
testImplementation 'org.junit.jupiter:junit-jupiter-engine:5.10.0'
}
license {
+1 -1
View File
@@ -10,7 +10,7 @@ dependencies {
compileOnly 'org.spigotmc:spigot-api:1.16.5-R0.1-SNAPSHOT'
compileOnly 'org.jetbrains:annotations:24.0.1'
compileOnly 'de.themoep:minedown-adventure:1.7.2-SNAPSHOT'
compileOnly 'net.william278:annotaml:2.0.4'
compileOnly 'net.william278:annotaml:2.0.5'
compileOnly 'net.william278:DesertWell:2.0.4'
compileOnly 'com.github.MilkBowl:VaultAPI:1.7.1'
compileOnly 'me.clip:placeholderapi:2.11.3'
@@ -89,6 +89,13 @@ public class BukkitPluginTests {
Assertions.assertNotNull(BukkitUser.adapt(player, plugin));
}
@Test
@DisplayName("Config Reload & Read Test")
public void testConfigReload() {
plugin.reloadConfig();
Assertions.assertNotNull(plugin.getConfig());
}
}
@Nested
+1 -1
View File
@@ -7,7 +7,7 @@ dependencies {
api 'org.apache.commons:commons-text:1.10.0'
api 'de.themoep:minedown-adventure:1.7.2-SNAPSHOT'
api 'com.google.code.gson:gson:2.10.1'
api 'net.william278:annotaml:2.0.4'
api 'net.william278:annotaml:2.0.5'
api 'net.william278:PagineDown:1.1'
api 'net.william278:DesertWell:2.0.4'
api 'dev.dejvokep:boosted-yaml:1.3.1'
@@ -100,7 +100,7 @@ public class Settings {
@YamlComment("Names of tables to use on your database. Don't modify this unless you know what you're doing!")
@YamlKey("database.table_names")
private Map<String, String> tableNames = Database.Table.getConfigMap();
private TreeMap<String, String> tableNames = new TreeMap<>(Database.Table.getConfigMap());
// General settings
@@ -113,7 +113,7 @@ public class Settings {
@YamlKey("general.max_public_homes")
private int maxPublicHomes = 10;
@YamlComment("Whether permission limits (i.e. huskhomes.max_homes.<number>)"
@YamlComment("Whether permission limits (i.e. huskhomes.max_homes.<number>) "
+ "should stack if the user inherits multiple nodes.")
@YamlKey("general.stack_permission_limits")
private boolean stackPermissionLimits = false;
@@ -176,7 +176,7 @@ public class Settings {
@YamlComment("Which sound effects to play for various actions")
@YamlKey("general.sound_effects")
private Map<String, String> soundEffects = SoundEffectAction.getConfigMap();
private TreeMap<String, String> soundEffects = new TreeMap<>(SoundEffectAction.getConfigMap());
@YamlComment("Whether to provide modern, rich TAB suggestions for commands (if available)")
@YamlKey("general.brigadier_tab_completion")
@@ -252,12 +252,7 @@ public class Settings {
@YamlComment("Set a cooldown between performing actions (in seconds). Docs: https://william278.net/docs/huskhomes/cooldowns/")
@YamlKey("cooldowns.cooldown_times")
private Map<String, Integer> cooldownTimes = Arrays.stream(TransactionResolver.Action.values())
.filter(action -> action.getDefaultCooldown() > 0)
.collect(Collectors.toMap(
action -> action.name().toLowerCase(Locale.ENGLISH),
TransactionResolver.Action::getDefaultCooldown)
);
private TreeMap<String, Integer> cooldownTimes = new TreeMap<>(TransactionResolver.Action.getCooldownsConfigMap());
// Economy settings
@@ -271,12 +266,7 @@ public class Settings {
@YamlComment("Charge money for perform certain actions. Docs: https://william278.net/docs/huskhomes/economy-hook/")
@YamlKey("economy.costs")
private Map<String, Double> economyCosts = Arrays.stream(TransactionResolver.Action.values())
.filter(action -> action.getDefaultCost() > 0)
.collect(Collectors.toMap(
action -> action.name().toLowerCase(Locale.ENGLISH),
TransactionResolver.Action::getDefaultCost)
);
private TreeMap<String, Double> economyCosts = new TreeMap<>(TransactionResolver.Action.getEconomyCostsConfigMap());
// Mapping plugins
@YamlComment("Display public homes/warps on your Dynmap, BlueMap or Pl3xMap. Docs: https://william278.net/docs/huskhomes/map-hooks")
@@ -302,6 +292,7 @@ public class Settings {
private Settings() {
}
@NotNull
public String getLanguage() {
return language;
}
@@ -310,10 +301,12 @@ public class Settings {
return checkForUpdates;
}
@NotNull
public Database.Type getDatabaseType() {
return databaseType;
}
@NotNull
public String getMySqlHost() {
return mySqlHost;
}
@@ -322,18 +315,22 @@ public class Settings {
return mySqlPort;
}
@NotNull
public String getMySqlDatabase() {
return mySqlDatabase;
}
@NotNull
public String getMySqlUsername() {
return mySqlUsername;
}
@NotNull
public String getMySqlPassword() {
return mySqlPassword;
}
@NotNull
public String getMySqlConnectionParameters() {
return mySqlConnectionParameters;
}
@@ -358,13 +355,16 @@ public class Settings {
return mySqlConnectionPoolTimeout;
}
public Map<String, String> getTableNames() {
@NotNull
public TreeMap<String, String> getTableNames() {
final TreeMap<String, String> tableNames = new TreeMap<>(String.CASE_INSENSITIVE_ORDER);
tableNames.putAll(this.tableNames);
return tableNames;
}
@NotNull
public String getTableName(@NotNull Database.Table table) {
return Optional.ofNullable(getTableNames().get(table.name().toLowerCase())).orElse(table.getName());
return Optional.ofNullable(getTableNames().get(table.name())).orElse(table.getDefaultName());
}
public int getMaxHomes() {
@@ -391,6 +391,7 @@ public class Settings {
return teleportWarmupTime;
}
@NotNull
public Locales.DisplaySlot getTeleportWarmupDisplay() {
return teleportWarmupDisplay;
}
@@ -435,21 +436,30 @@ public class Settings {
return playSoundEffects;
}
@NotNull
public TreeMap<String, String> getSoundEffects() {
final TreeMap<String, String> soundEffects = new TreeMap<>(String.CASE_INSENSITIVE_ORDER);
soundEffects.putAll(this.soundEffects);
return soundEffects;
}
public Optional<String> getSoundEffect(@NotNull SoundEffectAction action) {
if (!doPlaySoundEffects()) {
return Optional.empty();
}
return Optional.ofNullable(soundEffects.get(action.name().toLowerCase()));
return Optional.ofNullable(getSoundEffects().get(action.name()));
}
public boolean doCrossServer() {
return crossServer;
}
@NotNull
public Broker.Type getBrokerType() {
return messageBrokerType;
}
@NotNull
public String getClusterId() {
return clusterId;
}
@@ -458,6 +468,7 @@ public class Settings {
return globalSpawn;
}
@NotNull
public String getGlobalSpawnName() {
return globalSpawnName;
}
@@ -466,6 +477,7 @@ public class Settings {
return globalRespawning;
}
@NotNull
public String getRedisHost() {
return redisHost;
}
@@ -474,6 +486,7 @@ public class Settings {
return redisPort;
}
@NotNull
public String getRedisPassword() {
return redisPassword;
}
@@ -511,11 +524,18 @@ public class Settings {
return cooldowns;
}
@NotNull
public TreeMap<String, Integer> getCooldownTimes() {
final TreeMap<String, Integer> cooldownTimes = new TreeMap<>(String.CASE_INSENSITIVE_ORDER);
cooldownTimes.putAll(this.cooldownTimes);
return cooldownTimes;
}
public long getCooldown(@NotNull TransactionResolver.Action action) {
if (!doCooldowns()) {
return 0;
}
final Integer cooldown = cooldownTimes.get(action.name().toLowerCase(Locale.ENGLISH));
final Integer cooldown = getCooldownTimes().get(action.name());
if (cooldown != null && cooldown > 0) {
return cooldown;
}
@@ -530,11 +550,18 @@ public class Settings {
return freeHomeSlots;
}
@NotNull
public TreeMap<String, Double> getEconomyCosts() {
final TreeMap<String, Double> economyCosts = new TreeMap<>(String.CASE_INSENSITIVE_ORDER);
economyCosts.putAll(this.economyCosts);
return economyCosts;
}
public Optional<Double> getEconomyCost(@NotNull TransactionResolver.Action action) {
if (!doEconomy()) {
return Optional.empty();
}
final Double cost = economyCosts.get(action.name().toLowerCase(Locale.ENGLISH));
final Double cost = getEconomyCosts().get(action.name());
if (cost != null && cost > 0d) {
return Optional.of(cost);
}
@@ -554,11 +581,12 @@ public class Settings {
}
public boolean isCommandDisabled(Command type) {
return disabledCommands.stream().anyMatch(disabled -> {
final String command = (disabled.startsWith("/") ? disabled.substring(1) : disabled);
return command.equalsIgnoreCase(type.getName())
|| type.getAliases().stream().anyMatch(alias -> alias.equalsIgnoreCase(command));
});
return disabledCommands.stream()
.anyMatch(disabled -> {
final String command = (disabled.startsWith("/") ? disabled.substring(1) : disabled);
return command.equalsIgnoreCase(type.getName())
|| type.getAliases().stream().anyMatch(alias -> alias.equalsIgnoreCase(command));
});
}
public boolean doBrigadierTabCompletion() {
@@ -573,6 +601,7 @@ public class Settings {
TELEPORTATION_WARMUP("block.note_block.banjo"),
TELEPORTATION_CANCELLED("entity.item.break"),
TELEPORT_REQUEST_RECEIVED("entity.experience_orb.pickup");
private final String defaultEffect;
SoundEffectAction(@NotNull String defaultEffect) {
@@ -581,11 +610,10 @@ public class Settings {
@NotNull
public static Map<String, String> getConfigMap() {
return Arrays.stream(values())
.collect(Collectors.toMap(
SoundEffectAction::name,
action -> action.defaultEffect)
);
return Arrays.stream(values()).collect(Collectors.toMap(
action -> action.name().toLowerCase(Locale.ENGLISH),
action -> action.defaultEffect
));
}
}
@@ -474,17 +474,16 @@ public abstract class Database {
}
@NotNull
public String getName() {
public String getDefaultName() {
return defaultName;
}
@NotNull
public static Map<String, String> getConfigMap() {
return Arrays.stream(values())
.collect(Collectors.toMap(
Table::name,
action -> action.defaultName
));
return Arrays.stream(values()).collect(Collectors.toMap(
table -> table.name().toLowerCase(Locale.ENGLISH),
Table::getDefaultName
));
}
}
@@ -26,8 +26,8 @@ import org.jetbrains.annotations.NotNull;
import java.time.Duration;
import java.time.Instant;
import java.util.Optional;
import java.util.StringJoiner;
import java.util.*;
import java.util.stream.Collectors;
/**
* Class for validating and performing economy and cooldown transactions involving {@link Action}s.
@@ -229,5 +229,27 @@ public interface TransactionResolver {
return defaultCooldown;
}
// Get the default economy action cost map for the config
@NotNull
public static Map<String, Double> getEconomyCostsConfigMap() {
return Arrays.stream(values())
.filter(action -> action.getDefaultCost() > 0)
.collect(Collectors.toMap(
action -> action.name().toLowerCase(Locale.ENGLISH),
Action::getDefaultCost
));
}
// Get the default cooldown action time map for the config
@NotNull
public static Map<String, Integer> getCooldownsConfigMap() {
return Arrays.stream(values())
.filter(action -> action.getDefaultCooldown() > 0)
.collect(Collectors.toMap(
action -> action.name().toLowerCase(Locale.ENGLISH),
Action::getDefaultCooldown
));
}
}
}
+14 -14
View File
@@ -44,13 +44,13 @@ database:
timeout: 20000
# Names of tables to use on your database. Don't modify this unless you know what you're doing!
table_names:
position_data: huskhomes_position_data
warp_data: huskhomes_warps
saved_position_data: huskhomes_saved_positions
player_cooldowns_data: huskhomes_user_cooldowns
home_data: huskhomes_homes
teleport_data: huskhomes_teleports
player_cooldowns_data: huskhomes_user_cooldowns
player_data: huskhomes_users
position_data: huskhomes_position_data
saved_position_data: huskhomes_saved_positions
teleport_data: huskhomes_teleports
warp_data: huskhomes_warps
general:
# The maximum homes a user can create. Override with the huskhomes.max_homes.<number> permission.
max_homes: 10
@@ -60,7 +60,7 @@ general:
stack_permission_limits: false
# Whether users require a permission (huskhomes.command.warp.<warp_name>) to use warps
permission_restrict_warps: false
# Whether running /sethome <name> or /setwarp <name> when a home/warp already exists should overwrite it.
# Whether running /sethome <name> or /setwarp <name> when a home/warp already exists should overwrite.
overwrite_existing_homes_warps: true
# How long a player has to stand still and not take damage for when teleporting (in seconds)
teleport_warmup_time: 5
@@ -78,7 +78,7 @@ general:
allow_unicode_descriptions: true
# Whether /back should work to teleport the user to where they died
back_command_return_by_death: true
# Whether /back should work with other plugins that use the PlayerTeleportEvent (this can cause conflicts)
# Whether /back should work with other plugins that use the PlayerTeleportEvent (can cause conflicts)
back_command_save_teleport_event: false
# How many items should be displayed per-page in chat menu lists
list_items_per_page: 12
@@ -88,10 +88,10 @@ general:
play_sound_effects: true
# Which sound effects to play for various actions
sound_effects:
teleportation_cancelled: entity.item.break
teleportation_warmup: block.note_block.banjo
teleportation_complete: entity.enderman.teleport
teleport_request_received: entity.experience_orb.pickup
teleportation_cancelled: entity.item.break
teleportation_complete: entity.enderman.teleport
teleportation_warmup: block.note_block.banjo
# Whether to provide modern, rich TAB suggestions for commands (if available)
brigadier_tab_completion: true
cross_server:
@@ -121,12 +121,12 @@ rtp:
spawn_radius: 500
# Mean of the normal distribution used to calculate the distance from the center of the world
distribution_mean: 0.75
# Standard deviation of the normal distribution used to calculate the distance from the center of the world
# Standard deviation of the normal distribution for distributing players randomly
distribution_deviation: 2.0
# List of worlds in which /rtp is disabled. Please note that /rtp does not work well in the nether.
restricted_worlds:
- world_nether
- world_the_end
- world_nether
- world_the_end
cooldowns:
# Whether to apply a cooldown between performing certain actions
enabled: true
@@ -140,8 +140,8 @@ economy:
free_home_slots: 5
# Charge money for perform certain actions. Docs: https://william278.net/docs/huskhomes/economy-hook/
costs:
make_home_public: 50.0
additional_home_slot: 100.0
make_home_public: 50.0
random_teleport: 25.0
map_hook:
# Display public homes/warps on your Dynmap, BlueMap or Pl3xMap. Docs: https://william278.net/docs/huskhomes/map-hooks
+1 -1
View File
@@ -11,7 +11,7 @@ dependencies {
compileOnly 'org.bstats:bstats-bukkit:3.0.2'
compileOnly 'org.jetbrains:annotations:24.0.1'
compileOnly 'de.themoep:minedown-adventure:1.7.2-SNAPSHOT'
compileOnly 'net.william278:annotaml:2.0.4'
compileOnly 'net.william278:annotaml:2.0.5'
compileOnly 'net.william278:DesertWell:2.0.4'
compileOnly 'me.lucko:commodore:2.2'
compileOnly 'com.github.MilkBowl:VaultAPI:1.7.1'