Add allow_unicode_descriptions config option to allow unicode in descriptions (default on), Close #67

Split invalid description locales in two for more specific errors
Add defaults in Settings config reader

Signed-off-by: BuildTools <[email protected]>
This commit is contained in:
BuildTools committed 2021-07-13 00:44:08 +03:00
1 parent 85b51bc5ae
commit 3b5140f794
8 files changed
+118 -95

No files matched your search

@@ -133,10 +133,16 @@ public class EditHomeCommand extends CommandBase implements TabCompleter {
Bukkit.getScheduler().runTaskAsynchronously(plugin, () -> {
try {
// Check the description is valid
if (newDescriptionString.length() > 255 || !RegexUtil.DESCRIPTION_PATTERN.matcher(newDescriptionString).matches()) {
MessageManager.sendMessage(p, "error_edit_home_invalid_description");
if (newDescriptionString.length() > 255) {
MessageManager.sendMessage(p, "error_edit_home_description_length");
return;
}
if (!HuskHomes.getSettings().doUnicodeInDescriptions()) {
if (!RegexUtil.DESCRIPTION_PATTERN.matcher(newDescriptionString).matches()) {
MessageManager.sendMessage(p, "error_edit_home_description_characters");
return;
}
}
// Remove old marker if on the Dynmap
if (descriptionChangedHome.isPublic() && HuskHomes.getSettings().doMapIntegration() && HuskHomes.getSettings().showPublicHomesOnMap()) {
@@ -92,10 +92,16 @@ public class EditWarpCommand extends CommandBase implements TabCompleter {
// Check the description is valid
if (newDescriptionString.length() > 255 || !RegexUtil.DESCRIPTION_PATTERN.matcher(newDescriptionString).matches()) {
MessageManager.sendMessage(p, "error_edit_warp_invalid_description");
if (newDescriptionString.length() > 255) {
MessageManager.sendMessage(p, "error_edit_warp_description_length");
return;
}
if (!HuskHomes.getSettings().doUnicodeInDescriptions()) {
if (!RegexUtil.DESCRIPTION_PATTERN.matcher(newDescriptionString).matches()) {
MessageManager.sendMessage(p, "error_edit_warp_description_characters");
return;
}
}
if (HuskHomes.getSettings().doMapIntegration() && HuskHomes.getSettings().showWarpsOnMap()) {
HuskHomes.getMap().removeWarpMarker(warpName);
@@ -59,6 +59,9 @@ public class Settings {
private double rtpCost;
private double backCost;
// Allow UTF-8 (Unicode) characters in descriptions?
private boolean allowUnicodeInDescriptions;
// Vanished player checks
private boolean checkVanishedPlayers;
@@ -110,84 +113,82 @@ public class Settings {
public void reloadFromFile(FileConfiguration config) {
try {
this.language = config.getString("language");
this.language = config.getString("language", "en-gb");
this.updateReminders = config.getBoolean("check_for_updates");
this.updateReminders = config.getBoolean("check_for_updates", true);
this.doBungee = config.getBoolean("bungee_options.enable_bungee_mode");
this.server = config.getString("bungee_options.server_id");
this.clusterID = config.getInt("bungee_options.cluster_id");
this.doCrossServerTabCompletion = config.getBoolean("bungee_options.tab_complete_cross_server.enabled");
this.crossServerTabUpdateDelay = config.getInt("bungee_options.tab_complete_cross_server.delay");
this.doBungee = config.getBoolean("bungee_options.enable_bungee_mode", false);
this.server = config.getString("bungee_options.server_id", "server");
this.clusterID = config.getInt("bungee_options.cluster_id", 0);
this.doCrossServerTabCompletion = config.getBoolean("bungee_options.tab_complete_cross_server.enabled", true);
this.crossServerTabUpdateDelay = config.getInt("bungee_options.tab_complete_cross_server.delay", 60);
this.storageType = config.getString("data_storage_options.storage_type");
this.playerDataTable = config.getString("data_storage_options.table_names.player_data");
this.locationsDataTable = config.getString("data_storage_options.table_names.locations_data");
this.homesDataTable = config.getString("data_storage_options.table_names.homes_data");
this.warpsDataTable = config.getString("data_storage_options.table_names.warps_data");
this.storageType = config.getString("data_storage_options.storage_type", "SQLite");
this.playerDataTable = config.getString("data_storage_options.table_names.player_data", "huskhomes_player_data");
this.locationsDataTable = config.getString("data_storage_options.table_names.locations_data", "huskhomes_location_data");
this.homesDataTable = config.getString("data_storage_options.table_names.homes_data", "huskhomes_home_data");
this.warpsDataTable = config.getString("data_storage_options.table_names.warps_data", "huskhomes_warp_data");
// Resolve conflict between storage type and bungee mode
if (storageType.equalsIgnoreCase("sqlite") && doBungee) {
if (storageType.equalsIgnoreCase("SQLite") && doBungee) {
Bukkit.getLogger().warning("Bungee mode was set in config to be enabled but storage type was set to SQLite!");
Bukkit.getLogger().warning("A mySQL Database is required to utilise Bungee mode, so bungee mode has been disabled.");
Bukkit.getLogger().warning("To use Bungee mode and cross-server teleportation, please update your data storage settings to use \"mysql\" and update the connection credentials accordingly.");
this.doBungee = false;
}
this.mySQLhost = config.getString("data_storage_options.mysql_credentials.host");
this.mySQLdatabase = config.getString("data_storage_options.mysql_credentials.database");
this.mySQLusername = config.getString("data_storage_options.mysql_credentials.username");
this.mySQLpassword = config.getString("data_storage_options.mysql_credentials.password");
this.mySQLport = config.getInt("data_storage_options.mysql_credentials.port");
this.mySQLparams = config.getString("data_storage_options.mysql_credentials.params");
this.mySQLhost = config.getString("data_storage_options.mysql_credentials.host", "localhost");
this.mySQLdatabase = config.getString("data_storage_options.mysql_credentials.database", "HuskHomes");
this.mySQLusername = config.getString("data_storage_options.mysql_credentials.username", "root");
this.mySQLpassword = config.getString("data_storage_options.mysql_credentials.password", "pa55w0rd");
this.mySQLport = config.getInt("data_storage_options.mysql_credentials.port", 3306);
this.mySQLparams = config.getString("data_storage_options.mysql_credentials.params", "?autoReconnect=true&useSSL=false");
this.doMapIntegration = config.getBoolean("map_integration.enabled");
this.mapPlugin = config.getString("map_integration.plugin");
this.doMapIntegration = config.getBoolean("map_integration.enabled", false);
this.mapPlugin = config.getString("map_integration.plugin", "dynmap");
if (this.doMapIntegration) {
if (mapPlugin != null) {
PluginManager pluginManager = HuskHomes.getInstance().getServer().getPluginManager();
switch (mapPlugin.toLowerCase(Locale.ROOT)) {
case "dynmap" -> {
Plugin dynMap = pluginManager.getPlugin("dynmap");
if (dynMap == null) {
Bukkit.getLogger().warning("Dynmap integration was enabled in config, but the Dynmap plugin could not be found!");
Bukkit.getLogger().warning("The map integration setting has been disabled. Please ensure BlueMap is installed and restart the server.");
this.doMapIntegration = false;
plugin.getConfig().set("map_integration.enabled", false);
plugin.saveConfig();
}
}
case "bluemap" -> {
Plugin blueMap = pluginManager.getPlugin("BlueMap");
if (blueMap == null) {
Bukkit.getLogger().warning("BlueMap integration was enabled in config, but the BlueMap plugin could not be found!");
Bukkit.getLogger().warning("The map integration setting has been disabled. Please ensure BlueMap is installed and restart the server.");
this.doMapIntegration = false;
plugin.getConfig().set("map_integration.enabled", false);
plugin.saveConfig();
}
}
default -> {
Bukkit.getLogger().warning("Map integration was enabled in config, but the map plugin type was invalid.");
Bukkit.getLogger().warning("The map integration setting has been disabled. Please ensure you specify a valid map plugin type.");
PluginManager pluginManager = HuskHomes.getInstance().getServer().getPluginManager();
switch (mapPlugin.toLowerCase(Locale.ROOT)) {
case "dynmap" -> {
Plugin dynMap = pluginManager.getPlugin("dynmap");
if (dynMap == null) {
Bukkit.getLogger().warning("Dynmap integration was enabled in config, but the Dynmap plugin could not be found!");
Bukkit.getLogger().warning("The map integration setting has been disabled. Please ensure BlueMap is installed and restart the server.");
this.doMapIntegration = false;
plugin.getConfig().set("map_integration.enabled", false);
plugin.saveConfig();
}
}
case "bluemap" -> {
Plugin blueMap = pluginManager.getPlugin("BlueMap");
if (blueMap == null) {
Bukkit.getLogger().warning("BlueMap integration was enabled in config, but the BlueMap plugin could not be found!");
Bukkit.getLogger().warning("The map integration setting has been disabled. Please ensure BlueMap is installed and restart the server.");
this.doMapIntegration = false;
plugin.getConfig().set("map_integration.enabled", false);
plugin.saveConfig();
}
}
default -> {
Bukkit.getLogger().warning("Map integration was enabled in config, but the map plugin type was invalid.");
Bukkit.getLogger().warning("The map integration setting has been disabled. Please ensure you specify a valid map plugin type.");
this.doMapIntegration = false;
plugin.getConfig().set("map_integration.enabled", false);
plugin.saveConfig();
}
}
}
this.mapPublicHomes = config.getBoolean("map_integration.markers.public_homes.show");
this.mapWarps = config.getBoolean("map_integration.markers.warps.show");
this.mapPublicHomeMarkerIconID = config.getString("map_integration.markers.public_homes.icon_id");
this.mapWarpMarkerIconID = config.getString("map_integration.markers.warps.icon_id");
this.mapPublicHomeMarkerSet = config.getString("map_integration.markers.public_homes.set_name");
this.mapWarpMarkerSet = config.getString("map_integration.markers.warps.set_name");
this.mapPublicHomes = config.getBoolean("map_integration.markers.public_homes.show", true);
this.mapWarps = config.getBoolean("map_integration.markers.warps.show", true);
this.mapPublicHomeMarkerIconID = config.getString("map_integration.markers.public_homes.icon_id", "house");
this.mapWarpMarkerIconID = config.getString("map_integration.markers.warps.icon_id", "sign");
this.mapPublicHomeMarkerSet = config.getString("map_integration.markers.public_homes.set_name", "Public Homes");
this.mapWarpMarkerSet = config.getString("map_integration.markers.warps.set_name", "Warps");
this.doEconomy = config.getBoolean("economy_integration.enabled");
this.doEconomy = config.getBoolean("economy_integration.enabled", false);
if (this.doEconomy) {
PluginManager pluginManager = HuskHomes.getInstance().getServer().getPluginManager();
@@ -199,17 +200,17 @@ public class Settings {
}
}
this.freeHomeSlots = config.getInt("economy_integration.free_home_slots");
this.setHomeCost = config.getDouble("economy_integration.costs.additional_home_slot");
this.publicHomeCost = config.getDouble("economy_integration.costs.make_home_public");
this.rtpCost = config.getDouble("economy_integration.costs.random_teleport");
this.backCost = config.getDouble("economy_integration.costs.back");
this.freeHomeSlots = config.getInt("economy_integration.free_home_slots", 5);
this.setHomeCost = config.getDouble("economy_integration.costs.additional_home_slot", 100D);
this.publicHomeCost = config.getDouble("economy_integration.costs.make_home_public", 50D);
this.rtpCost = config.getDouble("economy_integration.costs.random_teleport", 20D);
this.backCost = config.getDouble("economy_integration.costs.back", 0D);
// Retrieve sounds used in plugin; if invalid, use defaults.
try {
this.teleportationCompleteSound = Sound.valueOf(config.getString("general.sounds.teleportation_complete"));
this.teleportWarmupSound = Sound.valueOf(config.getString("general.sounds.teleportation_warmup"));
this.teleportCancelledSound = Sound.valueOf(config.getString("general.sounds.teleportation_cancelled"));
this.teleportationCompleteSound = Sound.valueOf(config.getString("general.sounds.teleportation_complete", "ENTITY_ENDERMAN_TELEPORT"));
this.teleportWarmupSound = Sound.valueOf(config.getString("general.sounds.teleportation_warmup", "BLOCK_NOTE_BLOCK_BANJO"));
this.teleportCancelledSound = Sound.valueOf(config.getString("general.sounds.teleportation_cancelled", "ENTITY_ITEM_BREAK"));
} catch (IllegalArgumentException exception) {
Bukkit.getLogger().severe("Invalid sound specified in config.yml; using default sounds instead.");
this.teleportationCompleteSound = Sound.ENTITY_ENDERMAN_TELEPORT;
@@ -217,32 +218,34 @@ public class Settings {
this.teleportCancelledSound = Sound.ENTITY_ITEM_BREAK;
}
this.checkVanishedPlayers = config.getBoolean("handle_vanished_players");
this.allowUnicodeInDescriptions = config.getBoolean("allow_unicode_descriptions", true);
this.doSpawnCommand = config.getBoolean("spawn_command.enabled");
this.doCrossServerSpawn = config.getBoolean("spawn_command.bungee_network_spawn.enabled");
this.crossServerSpawnWarpName = config.getString("spawn_command.bungee_network_spawn.warp_name");
this.forceSpawnOnLogin = config.getBoolean("spawn_command.force_teleport_on_login");
this.checkVanishedPlayers = config.getBoolean("handle_vanished_players", true);
this.doWarpCommand = config.getBoolean("warp_command.enabled");
this.doPermissionRestrictedWarps = config.getBoolean("warp_command.permission_restrictions.require_permission");
this.warpRestrictionPermissionFormat = config.getString("warp_command.permission_restrictions.format");
this.hideRestrictedWarps = config.getBoolean("warp_command.permission_restrictions.hide_restricted_warps");
this.doSpawnCommand = config.getBoolean("spawn_command.enabled", true);
this.doCrossServerSpawn = config.getBoolean("spawn_command.bungee_network_spawn.enabled", false);
this.crossServerSpawnWarpName = config.getString("spawn_command.bungee_network_spawn.warp_name", "Spawn");
this.forceSpawnOnLogin = config.getBoolean("spawn_command.force_teleport_on_login", false);
this.doRtpCommand = config.getBoolean("random_teleport_command.enabled");
this.rtpRange = config.getInt("random_teleport_command.range");
this.rtpCooldown = config.getInt("random_teleport_command.cooldown");
this.doWarpCommand = config.getBoolean("warp_command.enabled", true);
this.doPermissionRestrictedWarps = config.getBoolean("warp_command.permission_restrictions.require_permission", false);
this.warpRestrictionPermissionFormat = config.getString("warp_command.permission_restrictions.format", "huskhomes.warp.");
this.hideRestrictedWarps = config.getBoolean("warp_command.permission_restrictions.hide_restricted_warps", true);
this.privateHomesPerPage = config.getInt("general.lists.private_homes_per_page");
this.publicHomesPerPage = config.getInt("general.lists.public_homes_per_page");
this.warpsPerPage = config.getInt("general.lists.warps_per_page");
this.doRtpCommand = config.getBoolean("random_teleport_command.enabled", true);
this.rtpRange = config.getInt("random_teleport_command.range", 5000);
this.rtpCooldown = config.getInt("random_teleport_command.cooldown", 30);
this.hideCommandsFromHelpMenuWithoutPermission = config.getBoolean("general.help_menu.hide_commands_without_permission");
this.hideHuskHomesCommandFromHelpMenu = config.getBoolean("general.help_menu.hide_huskhomes_command");
this.privateHomesPerPage = config.getInt("general.lists.private_homes_per_page", 10);
this.publicHomesPerPage = config.getInt("general.lists.public_homes_per_page", 10);
this.warpsPerPage = config.getInt("general.lists.warps_per_page", 10);
this.maximumHomes = config.getInt("general.max_sethomes");
this.teleportRequestExpiryTime = config.getInt("general.teleport_request_expiry_time");
this.teleportWarmupTime = config.getInt("general.teleport_warmup_time");
this.hideCommandsFromHelpMenuWithoutPermission = config.getBoolean("general.help_menu.hide_commands_without_permission", true);
this.hideHuskHomesCommandFromHelpMenu = config.getBoolean("general.help_menu.hide_huskhomes_command", false);
this.maximumHomes = config.getInt("general.max_sethomes", 10);
this.teleportRequestExpiryTime = config.getInt("general.teleport_request_expiry_time", 60);
this.teleportWarmupTime = config.getInt("general.teleport_warmup_time", 5);
} catch (Exception e) {
HuskHomes.disablePlugin("An error occurred loading the HuskHomes config (" + e.getCause() + ")");
@@ -438,7 +441,6 @@ public class Settings {
return doCrossServerTabCompletion;
}
// todo re-implement
public int getCrossServerTabUpdateDelay() {
return crossServerTabUpdateDelay;
}
@@ -466,4 +468,8 @@ public class Settings {
public boolean hideHuskHomesCommandFromHelpMenu() {
return hideHuskHomesCommandFromHelpMenu;
}
public boolean doUnicodeInDescriptions() {
return allowUnicodeInDescriptions;
}
}
@@ -14,6 +14,7 @@ public class SQLite extends Database {
final static String[] SQL_SETUP_STATEMENTS = {
"PRAGMA foreign_keys = ON;",
"PRAGMA encoding = 'UTF-8';",
"CREATE TABLE IF NOT EXISTS " + HuskHomes.getSettings().getLocationsDataTable() + " (" +
"`location_id` integer PRIMARY KEY," +