Start refactor work

This commit is contained in:
William278 committed 2023-03-01 16:23:01 +00:00
1 parent 6a8851a446
commit 3e1ec09487
51 files changed
+2397 -2474

No files matched your search

@@ -25,56 +25,57 @@ import java.util.Optional;
public class Settings {
// Top-level settings
public String language = "en-gb";
@YamlKey("language")
private String language = "en-gb";
@YamlKey("check_for_updates")
public boolean checkForUpdates = true;
private boolean checkForUpdates = true;
@YamlKey("debug_logging")
public boolean debugLogging = false;
private boolean debugLogging = false;
// Database settings
@YamlComment("Database connection settings")
@YamlKey("database.type")
public DatabaseType databaseType = DatabaseType.SQLITE;
private DatabaseType databaseType = DatabaseType.SQLITE;
@YamlKey("database.mysql.credentials.host")
public String mySqlHost = "localhost";
private String mySqlHost = "localhost";
@YamlKey("database.mysql.credentials.port")
public int mySqlPort = 3306;
private int mySqlPort = 3306;
@YamlKey("database.mysql.credentials.database")
public String mySqlDatabase = "HuskHomes";
private String mySqlDatabase = "HuskHomes";
@YamlKey("database.mysql.credentials.username")
public String mySqlUsername = "root";
private String mySqlUsername = "root";
@YamlKey("database.mysql.credentials.password")
public String mySqlPassword = "pa55w0rd";
private String mySqlPassword = "pa55w0rd";
@YamlKey("database.mysql.credentials.parameters")
public String mySqlConnectionParameters = "?autoReconnect=true&useSSL=false&useUnicode=true&characterEncoding=UTF-8";
private String mySqlConnectionParameters = "?autoReconnect=true&useSSL=false&useUnicode=true&characterEncoding=UTF-8";
@YamlComment("MySQL connection pool properties")
@YamlKey("database.mysql.connection_pool.size")
public int mySqlConnectionPoolSize = 12;
private int mySqlConnectionPoolSize = 12;
@YamlKey("database.mysql.connection_pool.idle")
public int mySqlConnectionPoolIdle = 12;
private int mySqlConnectionPoolIdle = 12;
@YamlKey("database.mysql.connection_pool.lifetime")
public long mySqlConnectionPoolLifetime = 1800000;
private long mySqlConnectionPoolLifetime = 1800000;
@YamlKey("database.mysql.connection_pool.keepalive")
public long mySqlConnectionPoolKeepAlive = 30000;
private long mySqlConnectionPoolKeepAlive = 30000;
@YamlKey("database.mysql.connection_pool.timeout")
public long mySqlConnectionPoolTimeout = 20000;
private long mySqlConnectionPoolTimeout = 20000;
@YamlKey("database.table_names")
public Map<String, String> tableNames = Map.of(
private Map<String, String> tableNames = Map.of(
TableName.PLAYER_DATA.name().toLowerCase(), TableName.PLAYER_DATA.defaultName,
TableName.POSITION_DATA.name().toLowerCase(), TableName.POSITION_DATA.defaultName,
TableName.SAVED_POSITION_DATA.name().toLowerCase(), TableName.SAVED_POSITION_DATA.defaultName,
@@ -85,142 +86,142 @@ public class Settings {
@NotNull
public String getTableName(@NotNull TableName tableName) {
return Optional.ofNullable(tableNames.get(tableName.name().toLowerCase())).orElse(tableName.defaultName);
return Optional.ofNullable(getTableNames().get(tableName.name().toLowerCase())).orElse(tableName.defaultName);
}
// General settings
@YamlComment("General plugin settings")
@YamlKey("general.max_homes")
public int maxHomes = 10;
private int maxHomes = 10;
@YamlKey("general.max_public_homes")
public int maxPublicHomes = 10;
private int maxPublicHomes = 10;
@YamlKey("general.stack_permission_limits")
public boolean stackPermissionLimits = true;
private boolean stackPermissionLimits = true;
@YamlKey("general.permission_restrict_warps")
public boolean permissionRestrictWarps = false;
private boolean permissionRestrictWarps = false;
@YamlKey("general.overwrite_existing_homes_warps")
public boolean overwriteExistingHomesWarps = true;
private boolean overwriteExistingHomesWarps = true;
@YamlKey("general.teleport_warmup_time")
public int teleportWarmupTime = 5;
private int teleportWarmupTime = 5;
@YamlKey("general.teleport_warmup_display")
public MessageDisplayType teleportWarmupDisplay = MessageDisplayType.ACTION_BAR;
private MessageDisplayType teleportWarmupDisplay = MessageDisplayType.ACTION_BAR;
@YamlKey("general.teleport_request_expiry_time")
public int teleportRequestExpiryTime = 60;
private int teleportRequestExpiryTime = 60;
@YamlKey("general.strict_tpa_here_requests")
public boolean strictTpaHereRequests = true;
private boolean strictTpaHereRequests = true;
@YamlKey("general.allow_unicode_names")
public boolean allowUnicodeNames = false;
private boolean allowUnicodeNames = false;
@YamlKey("general.allow_unicode_descriptions")
public boolean allowUnicodeDescriptions = true;
private boolean allowUnicodeDescriptions = true;
@YamlKey("general.back_command_return_by_death")
public boolean backCommandReturnByDeath = true;
private boolean backCommandReturnByDeath = true;
@YamlKey("general.back_command_save_teleport_event")
public boolean backCommandSaveOnTeleportEvent = false;
private boolean backCommandSaveOnTeleportEvent = false;
@YamlKey("general.list_items_per_page")
public int listItemsPerPage = 12;
private int listItemsPerPage = 12;
@YamlKey("general.asynchronous_teleports")
public boolean asynchronousTeleports = true;
private boolean asynchronousTeleports = true;
@YamlKey("general.play_sound_effects")
public boolean playSoundEffects = true;
private boolean playSoundEffects = true;
@YamlKey("general.sound_effects")
public Map<String, String> soundEffects = Map.of(
private Map<String, String> soundEffects = Map.of(
SoundEffectAction.TELEPORTATION_COMPLETE.name().toLowerCase(), SoundEffectAction.TELEPORTATION_COMPLETE.defaultSoundEffect,
SoundEffectAction.TELEPORTATION_WARMUP.name().toLowerCase(), SoundEffectAction.TELEPORTATION_WARMUP.defaultSoundEffect,
SoundEffectAction.TELEPORTATION_CANCELLED.name().toLowerCase(), SoundEffectAction.TELEPORTATION_CANCELLED.defaultSoundEffect
);
public Optional<String> getSoundEffect(@NotNull SoundEffectAction action) {
if (!playSoundEffects) {
if (!isPlaySoundEffects()) {
return Optional.empty();
}
return Optional.ofNullable(soundEffects.get(action.name().toLowerCase()));
return Optional.ofNullable(getSoundEffects().get(action.name().toLowerCase()));
}
// Cross-server settings
@YamlComment("Enable teleporting across proxied servers. Requires MySQL")
@YamlKey("cross_server.enabled")
public boolean crossServer = false;
private boolean crossServer = false;
@YamlKey("cross_server.messenger_type")
public MessengerType messengerType = MessengerType.PLUGIN_MESSAGE;
private MessengerType messengerType = MessengerType.PLUGIN_MESSAGE;
@YamlKey("cross_server.cluster_id")
public String clusterId = "";
private String clusterId = "";
@YamlKey("cross_server.global_spawn.enabled")
public boolean globalSpawn = false;
private boolean globalSpawn = false;
@YamlKey("cross_server.global_spawn.warp_name")
public String globalSpawnName = "Spawn";
private String globalSpawnName = "Spawn";
@YamlKey("cross_server.global_respawning")
public boolean globalRespawning = false;
private boolean globalRespawning = false;
@YamlKey("cross_server.redis_credentials.host")
public String redisHost = "localhost";
private String redisHost = "localhost";
@YamlKey("cross_server.redis_credentials.port")
public int redisPort = 6379;
private int redisPort = 6379;
@YamlKey("cross_server.redis_credentials.password")
public String redisPassword = "";
private String redisPassword = "";
@YamlKey("cross_server.redis_credentials.use_ssl")
public boolean redisUseSsl = false;
private boolean redisUseSsl = false;
// Rtp command settings
@YamlComment("Random teleport (/rtp) command settings")
@YamlKey("rtp.cooldown_length")
public int rtpCooldownLength = 10;
private int rtpCooldownLength = 10;
@YamlKey("rtp.radius")
public int rtpRadius = 5000;
private int rtpRadius = 5000;
@YamlKey("rtp.spawn_radius")
public int rtpSpawnRadius = 500;
private int rtpSpawnRadius = 500;
@YamlKey("rtp.distribution_mean")
public float rtpDistributionMean = 0.75f;
private float rtpDistributionMean = 0.75f;
@YamlKey("rtp.distribution_deviation")
public float rtpDistributionStandardDeviation = 2f;
private float rtpDistributionStandardDeviation = 2f;
@YamlKey("rtp.restricted_worlds")
public List<String> rtpRestrictedWorlds = List.of("world_nether", "world_the_end");
private List<String> rtpRestrictedWorlds = List.of("world_nether", "world_the_end");
// Economy settings
@YamlComment("Charge for certain actions (requires Vault)")
@YamlKey("economy.enabled")
public boolean economy = false;
private boolean economy = false;
@YamlComment("Use this currency for payments (works only with RedisEconomy), defaults to Vault currency")
@YamlKey("economy.redis_economy_name")
public String redisEconomyName = "vault";
private String redisEconomyName = "vault";
@YamlKey("economy.free_home_slots")
public int freeHomeSlots = 5;
private int freeHomeSlots = 5;
@YamlKey("economy.costs")
public Map<String, Double> economyCosts = Map.of(
private Map<String, Double> economyCosts = Map.of(
EconomyAction.ADDITIONAL_HOME_SLOT.name().toLowerCase(), EconomyAction.ADDITIONAL_HOME_SLOT.defaultCost,
EconomyAction.MAKE_HOME_PUBLIC.name().toLowerCase(), EconomyAction.MAKE_HOME_PUBLIC.defaultCost,
EconomyAction.RANDOM_TELEPORT.name().toLowerCase(), EconomyAction.RANDOM_TELEPORT.defaultCost,
@@ -228,10 +229,10 @@ public class Settings {
);
public Optional<Double> getEconomyCost(@NotNull EconomyAction action) {
if (!economy) {
if (!isEconomy()) {
return Optional.empty();
}
final Double cost = economyCosts.get(action.name().toLowerCase());
final Double cost = getEconomyCosts().get(action.name().toLowerCase());
if (cost != null && cost > 0d) {
return Optional.of(cost);
}
@@ -241,25 +242,257 @@ public class Settings {
// Mapping plugins
@YamlComment("Display public homes/warps on web maps (DYNMAP, BLUEMAP)")
@YamlKey("map_hook.enabled")
public boolean doMapHook = false;
private boolean doMapHook = false;
@YamlKey("map_hook.map_plugin")
public MappingPlugin mappingPlugin = MappingPlugin.DYNMAP;
private MappingPlugin mappingPlugin = MappingPlugin.DYNMAP;
@YamlKey("map_hook.show_public_homes")
public boolean publicHomesOnMap = true;
private boolean publicHomesOnMap = true;
@YamlKey("map_hook.show_warps")
public boolean warpsOnMap = true;
private boolean warpsOnMap = true;
// Disabled commands
@YamlComment("Disabled commands (e.g. ['/home', '/warp'] to disable /home and /warp)")
@YamlKey("disabled_commands")
public List<String> disabledCommands = Collections.emptyList();
private List<String> disabledCommands = Collections.emptyList();
@SuppressWarnings("unused")
public Settings() {
private Settings() {
}
public String getLanguage() {
return language;
}
public boolean doCheckForUpdates() {
return checkForUpdates;
}
public boolean doDebugLogging() {
return debugLogging;
}
public DatabaseType getDatabaseType() {
return databaseType;
}
public String getMySqlHost() {
return mySqlHost;
}
public int getMySqlPort() {
return mySqlPort;
}
public String getMySqlDatabase() {
return mySqlDatabase;
}
public String getMySqlUsername() {
return mySqlUsername;
}
public String getMySqlPassword() {
return mySqlPassword;
}
public String getMySqlConnectionParameters() {
return mySqlConnectionParameters;
}
public int getMySqlConnectionPoolSize() {
return mySqlConnectionPoolSize;
}
public int getMySqlConnectionPoolIdle() {
return mySqlConnectionPoolIdle;
}
public long getMySqlConnectionPoolLifetime() {
return mySqlConnectionPoolLifetime;
}
public long getMySqlConnectionPoolKeepAlive() {
return mySqlConnectionPoolKeepAlive;
}
public long getMySqlConnectionPoolTimeout() {
return mySqlConnectionPoolTimeout;
}
public Map<String, String> getTableNames() {
return tableNames;
}
public int getMaxHomes() {
return maxHomes;
}
public int getMaxPublicHomes() {
return maxPublicHomes;
}
public boolean doStackPermissionLimits() {
return stackPermissionLimits;
}
public boolean isPermissionRestrictWarps() {
return permissionRestrictWarps;
}
public boolean isOverwriteExistingHomesWarps() {
return overwriteExistingHomesWarps;
}
public int getTeleportWarmupTime() {
return teleportWarmupTime;
}
public MessageDisplayType getTeleportWarmupDisplay() {
return teleportWarmupDisplay;
}
public int getTeleportRequestExpiryTime() {
return teleportRequestExpiryTime;
}
public boolean isStrictTpaHereRequests() {
return strictTpaHereRequests;
}
public boolean isAllowUnicodeNames() {
return allowUnicodeNames;
}
public boolean isAllowUnicodeDescriptions() {
return allowUnicodeDescriptions;
}
public boolean isBackCommandReturnByDeath() {
return backCommandReturnByDeath;
}
public boolean isBackCommandSaveOnTeleportEvent() {
return backCommandSaveOnTeleportEvent;
}
public int getListItemsPerPage() {
return listItemsPerPage;
}
public boolean isAsynchronousTeleports() {
return asynchronousTeleports;
}
public boolean isPlaySoundEffects() {
return playSoundEffects;
}
public Map<String, String> getSoundEffects() {
return soundEffects;
}
public boolean isCrossServer() {
return crossServer;
}
public MessengerType getMessengerType() {
return messengerType;
}
public String getClusterId() {
return clusterId;
}
public boolean isGlobalSpawn() {
return globalSpawn;
}
public String getGlobalSpawnName() {
return globalSpawnName;
}
public boolean isGlobalRespawning() {
return globalRespawning;
}
public String getRedisHost() {
return redisHost;
}
public int getRedisPort() {
return redisPort;
}
public String getRedisPassword() {
return redisPassword;
}
public boolean isRedisUseSsl() {
return redisUseSsl;
}
public int getRtpCooldownLength() {
return rtpCooldownLength;
}
public int getRtpRadius() {
return rtpRadius;
}
public int getRtpSpawnRadius() {
return rtpSpawnRadius;
}
public float getRtpDistributionMean() {
return rtpDistributionMean;
}
public float getRtpDistributionStandardDeviation() {
return rtpDistributionStandardDeviation;
}
public List<String> getRtpRestrictedWorlds() {
return rtpRestrictedWorlds;
}
public boolean isEconomy() {
return economy;
}
public String getRedisEconomyName() {
return redisEconomyName;
}
public int getFreeHomeSlots() {
return freeHomeSlots;
}
public Map<String, Double> getEconomyCosts() {
return economyCosts;
}
public boolean isDoMapHook() {
return doMapHook;
}
public MappingPlugin getMappingPlugin() {
return mappingPlugin;
}
public boolean isPublicHomesOnMap() {
return publicHomesOnMap;
}
public boolean isWarpsOnMap() {
return warpsOnMap;
}
public List<String> getDisabledCommands() {
return disabledCommands;
}
/**