Improve settings methods

This commit is contained in:
William278 committed 2023-03-23 13:02:07 +00:00
1 parent d158973450
commit db4758b960
1 file changed
+15 -23
@@ -146,13 +146,6 @@ public class Settings {
SoundEffectAction.TELEPORTATION_CANCELLED.name().toLowerCase(), SoundEffectAction.TELEPORTATION_CANCELLED.defaultSoundEffect SoundEffectAction.TELEPORTATION_CANCELLED.name().toLowerCase(), SoundEffectAction.TELEPORTATION_CANCELLED.defaultSoundEffect
); );
public Optional<String> getSoundEffect(@NotNull SoundEffectAction action) {
if (!isPlaySoundEffects()) {
return Optional.empty();
}
return Optional.ofNullable(getSoundEffects().get(action.name().toLowerCase()));
}
@YamlKey("general.brigadier_tab_completion") @YamlKey("general.brigadier_tab_completion")
private boolean brigadierTabCompletion = true; private boolean brigadierTabCompletion = true;
@@ -231,17 +224,6 @@ public class Settings {
EconomyHook.Action.BACK_COMMAND.name().toLowerCase(), EconomyHook.Action.BACK_COMMAND.getDefaultCost() EconomyHook.Action.BACK_COMMAND.name().toLowerCase(), EconomyHook.Action.BACK_COMMAND.getDefaultCost()
); );
public Optional<Double> getEconomyCost(@NotNull EconomyHook.Action action) {
if (!doEconomy()) {
return Optional.empty();
}
final Double cost = getEconomyCosts().get(action.name().toLowerCase());
if (cost != null && cost > 0d) {
return Optional.of(cost);
}
return Optional.empty();
}
// Mapping plugins // Mapping plugins
@YamlComment("Display public homes/warps on your web map (supports Dynmap and BlueMap)") @YamlComment("Display public homes/warps on your web map (supports Dynmap and BlueMap)")
@YamlKey("map_hook.enabled") @YamlKey("map_hook.enabled")
@@ -387,8 +369,11 @@ public class Settings {
return playSoundEffects; return playSoundEffects;
} }
public Map<String, String> getSoundEffects() { public Optional<String> getSoundEffect(@NotNull SoundEffectAction action) {
return soundEffects; if (!isPlaySoundEffects()) {
return Optional.empty();
}
return Optional.ofNullable(soundEffects.get(action.name().toLowerCase()));
} }
public boolean isCrossServer() { public boolean isCrossServer() {
@@ -467,8 +452,15 @@ public class Settings {
return freeHomeSlots; return freeHomeSlots;
} }
public Map<String, Double> getEconomyCosts() { public Optional<Double> getEconomyCost(@NotNull EconomyHook.Action action) {
return economyCosts; if (!doEconomy()) {
return Optional.empty();
}
final Double cost = economyCosts.get(action.name().toLowerCase());
if (cost != null && cost > 0d) {
return Optional.of(cost);
}
return Optional.empty();
} }
public boolean doMapHook() { public boolean doMapHook() {
@@ -487,7 +479,7 @@ public class Settings {
return disabledCommands.stream().anyMatch(disabled -> { return disabledCommands.stream().anyMatch(disabled -> {
final String command = (disabled.startsWith("/") ? disabled.substring(1) : disabled); final String command = (disabled.startsWith("/") ? disabled.substring(1) : disabled);
return command.equalsIgnoreCase(type.getName()) return command.equalsIgnoreCase(type.getName())
|| type.getAliases().stream().anyMatch(alias -> alias.equalsIgnoreCase(command)); || type.getAliases().stream().anyMatch(alias -> alias.equalsIgnoreCase(command));
}); });
} }