From 7e9229cc1a8eed20d88a6c3ea29c28d8e306d08e Mon Sep 17 00:00:00 2001 From: William Date: Sun, 25 Sep 2022 18:03:57 +0100 Subject: [PATCH] Remove formatting from `error_in_game_only`, tweaks to OnlinePlayer --- bukkit/build.gradle | 2 +- .../net/william278/huskhomes/BukkitHuskHomes.java | 2 +- .../william278/huskhomes/command/BukkitCommand.java | 8 ++++---- .../william278/huskhomes/player/BukkitPlayer.java | 13 +++++++++---- common/src/main/resources/locales/bg-bg.yml | 2 +- common/src/main/resources/locales/de-de.yml | 2 +- common/src/main/resources/locales/en-gb.yml | 2 +- common/src/main/resources/locales/es-es.yml | 2 +- common/src/main/resources/locales/it-it.yml | 2 +- common/src/main/resources/locales/pl.yml | 2 +- common/src/main/resources/locales/uk-ua.yml | 2 +- common/src/main/resources/locales/zh-cn.yml | 2 +- common/src/main/resources/locales/zh-tw.yml | 2 +- 13 files changed, 24 insertions(+), 19 deletions(-) diff --git a/bukkit/build.gradle b/bukkit/build.gradle index b60993db..c92e8d10 100644 --- a/bukkit/build.gradle +++ b/bukkit/build.gradle @@ -5,8 +5,8 @@ dependencies { implementation 'io.papermc:paperlib:1.0.7' implementation 'me.lucko:commodore:2.2' - compileOnly 'org.jetbrains:annotations:23.0.0' compileOnly 'org.spigotmc:spigot-api:1.16.5-R0.1-SNAPSHOT' + compileOnly 'org.jetbrains:annotations:23.0.0' compileOnly 'de.themoep:minedown-adventure:1.7.2-SNAPSHOT' compileOnly 'net.kyori:adventure-api:' + adventure_api_version compileOnly 'net.kyori:adventure-platform-bukkit:' + adventure_bukkit_platform_version diff --git a/bukkit/src/main/java/net/william278/huskhomes/BukkitHuskHomes.java b/bukkit/src/main/java/net/william278/huskhomes/BukkitHuskHomes.java index f6e71aa5..2be819dc 100644 --- a/bukkit/src/main/java/net/william278/huskhomes/BukkitHuskHomes.java +++ b/bukkit/src/main/java/net/william278/huskhomes/BukkitHuskHomes.java @@ -9,9 +9,9 @@ import net.william278.huskhomes.command.BukkitCommandType; import net.william278.huskhomes.command.CommandBase; import net.william278.huskhomes.command.DisabledCommand; import net.william278.huskhomes.config.CachedServer; +import net.william278.huskhomes.config.CachedSpawn; import net.william278.huskhomes.config.Locales; import net.william278.huskhomes.config.Settings; -import net.william278.huskhomes.config.CachedSpawn; import net.william278.huskhomes.database.Database; import net.william278.huskhomes.database.MySqlDatabase; import net.william278.huskhomes.database.SqLiteDatabase; diff --git a/bukkit/src/main/java/net/william278/huskhomes/command/BukkitCommand.java b/bukkit/src/main/java/net/william278/huskhomes/command/BukkitCommand.java index cc9bd373..4c84b6d8 100644 --- a/bukkit/src/main/java/net/william278/huskhomes/command/BukkitCommand.java +++ b/bukkit/src/main/java/net/william278/huskhomes/command/BukkitCommand.java @@ -3,7 +3,6 @@ package net.william278.huskhomes.command; import me.lucko.commodore.CommodoreProvider; import net.william278.huskhomes.BukkitHuskHomes; import net.william278.huskhomes.player.BukkitPlayer; -import org.bukkit.Bukkit; import org.bukkit.command.*; import org.bukkit.entity.Player; import org.jetbrains.annotations.NotNull; @@ -11,7 +10,7 @@ import org.jetbrains.annotations.Nullable; import java.util.Collections; import java.util.List; -import java.util.concurrent.CompletableFuture; +import java.util.logging.Level; /** * Bukkit executor that implements and executes {@link CommandBase}s @@ -58,8 +57,9 @@ public class BukkitCommand implements CommandExecutor, TabExecutor { if (this.command instanceof ConsoleExecutable consoleExecutable) { consoleExecutable.onConsoleExecute(args); } else { - plugin.getLocales().getLocale("error_in_game_only") - .ifPresent(locale -> plugin.getAudiences().sender(sender).sendMessage(locale.toComponent())); + plugin.getLoggingAdapter().log(Level.WARNING, plugin.getLocales() + .getRawLocale("error_in_game_only") + .orElse("Error: That command can only be run in-game.")); } } return true; diff --git a/bukkit/src/main/java/net/william278/huskhomes/player/BukkitPlayer.java b/bukkit/src/main/java/net/william278/huskhomes/player/BukkitPlayer.java index d4efd2ad..101f80dc 100644 --- a/bukkit/src/main/java/net/william278/huskhomes/player/BukkitPlayer.java +++ b/bukkit/src/main/java/net/william278/huskhomes/player/BukkitPlayer.java @@ -26,10 +26,15 @@ import java.util.stream.Collectors; */ public class BukkitPlayer extends OnlineUser { + // Instance of the implementing plugin + private final BukkitHuskHomes plugin; + + // The Bukkit player private final Player player; private BukkitPlayer(@NotNull Player player) { super(player.getUniqueId(), player.getName()); + this.plugin = BukkitHuskHomes.getInstance(); this.player = player; } @@ -62,14 +67,14 @@ public class BukkitPlayer extends OnlineUser { public Position getPosition() { return new Position(BukkitAdapter.adaptLocation(player.getLocation()) .orElseThrow(() -> new HuskHomesException("Failed to get the position of a BukkitPlayer (null)")), - BukkitHuskHomes.getInstance().getPluginServer()); + plugin.getPluginServer()); } @Override public Optional getBedSpawnPosition() { return Optional.ofNullable(player.getBedSpawnLocation()).flatMap(BukkitAdapter::adaptLocation) - .map(location -> new Position(location, BukkitHuskHomes.getInstance().getPluginServer())); + .map(location -> new Position(location, plugin.getPluginServer())); } @Override @@ -91,7 +96,7 @@ public class BukkitPlayer extends OnlineUser { @Override protected @NotNull Audience getAudience() { - return BukkitHuskHomes.getInstance().getAudiences().player(player); + return plugin.getAudiences().player(player); } @Override @@ -105,7 +110,7 @@ public class BukkitPlayer extends OnlineUser { return CompletableFuture.completedFuture(TeleportResult.FAILED_ILLEGAL_COORDINATES); } final CompletableFuture resultCompletableFuture = new CompletableFuture<>(); - Bukkit.getScheduler().runTask(BukkitHuskHomes.getInstance(), () -> { + Bukkit.getScheduler().runTask(plugin, () -> { if (asynchronous) { PaperLib.teleportAsync(player, bukkitLocation.get(), PlayerTeleportEvent.TeleportCause.PLUGIN) .thenAccept(result -> resultCompletableFuture.complete( diff --git a/common/src/main/resources/locales/bg-bg.yml b/common/src/main/resources/locales/bg-bg.yml index 95e83447..657341cc 100644 --- a/common/src/main/resources/locales/bg-bg.yml +++ b/common/src/main/resources/locales/bg-bg.yml @@ -107,7 +107,7 @@ error_no_permission: '[Грешка:](#ff3300) [Нямате право да и error_invalid_syntax: '[Грешка:](#ff3300) [Неправилен синтаксис. Използвайте: %1%](#ff7e5e)' error_already_teleporting: '[Error:](#ff3300) [Please wait for the current teleport to finish!](#ff7e5e)' error_no_last_position: '[Грешка:](#ff3300) [Нямате последна локация, на която да се върнете!](#ff7e5e)' -error_in_game_only: '[Error:](#ff3300) [That command can only be run in-game.](#ff7e5e)' +error_in_game_only: 'Error: That command can only be run in-game.' error_invalid_server: '[Error:](#ff3300) [Failed to finish teleportation as the target server could not be found or was offline.](#ff7e5e)' error_home_invalid: '[Грешка:](#ff3300) [Нямате дом на име "%1%"](#ff7e5e)' error_warp_invalid: '[Грешка:](#ff3300) [Няма поставен уарп с името "%1%"](#ff7e5e)' diff --git a/common/src/main/resources/locales/de-de.yml b/common/src/main/resources/locales/de-de.yml index aaede2e9..7455ab7d 100644 --- a/common/src/main/resources/locales/de-de.yml +++ b/common/src/main/resources/locales/de-de.yml @@ -107,7 +107,7 @@ error_no_permission: '[Fehler:](#ff3300) [Du hast nicht die benötigten Berechti error_invalid_syntax: '[Fehler:](#ff3300) [Falsche Syntax. Nutze: %1%](#ff7e5e)' error_already_teleporting: '[Fehler:](#ff3300) [Bitte warte, bis der aktuelle Teleport beendet ist!](#ff7e5e)' error_no_last_position: '[Fehler:](#ff3300) [Du hast keine letzte Position, zu der du zurückkehren kannst!](#ff7e5e)' -error_in_game_only: '[Fehler:](#ff3300) [Dieser Befehl kann nur im Spiel ausgeführt werden.](#ff7e5e)' +error_in_game_only: 'Fehler: Dieser Befehl kann nur im Spiel ausgeführt werden.' error_invalid_server: '[Fehler:](#ff3300) [Die Teleportation konnte nicht beendet werden, da der Zielserver nicht gefunden werden konnte oder offline war.](#ff7e5e)' error_home_invalid: '[Fehler:](#ff3300) [Du hast kein Home namens "%1%"](#ff7e5e)' error_warp_invalid: '[Fehler:](#ff3300) [Es existiert kein Warp namens "%1%"](#ff7e5e)' diff --git a/common/src/main/resources/locales/en-gb.yml b/common/src/main/resources/locales/en-gb.yml index c178d249..f70d76f4 100644 --- a/common/src/main/resources/locales/en-gb.yml +++ b/common/src/main/resources/locales/en-gb.yml @@ -107,7 +107,7 @@ error_no_permission: '[Error:](#ff3300) [You do not have permission to execute t error_invalid_syntax: '[Error:](#ff3300) [Incorrect syntax. Usage: %1%](#ff7e5e)' error_already_teleporting: '[Error:](#ff3300) [Please wait for the current teleport to finish!](#ff7e5e)' error_no_last_position: '[Error:](#ff3300) [You have no last position to return to!](#ff7e5e)' -error_in_game_only: '[Error:](#ff3300) [That command can only be run in-game.](#ff7e5e)' +error_in_game_only: 'Error: That command can only be run in-game.' error_invalid_server: '[Error:](#ff3300) [Failed to finish teleportation as the target server could not be found or was offline.](#ff7e5e)' error_home_invalid: '[Error:](#ff3300) [You do not have a home named "%1%"](#ff7e5e)' error_warp_invalid: '[Error:](#ff3300) [There is no warp set named "%1%"](#ff7e5e)' diff --git a/common/src/main/resources/locales/es-es.yml b/common/src/main/resources/locales/es-es.yml index d5ee9ed3..7e011c0d 100644 --- a/common/src/main/resources/locales/es-es.yml +++ b/common/src/main/resources/locales/es-es.yml @@ -107,7 +107,7 @@ error_no_permission: '[Error:](#ff3300) [No tiene permiso para ejecutar ese coma error_invalid_syntax: '[Error:](#ff3300) [Sintaxis incorrecta. Usa: %1%](#ff7e5e)' error_already_teleporting: '[Error:](#ff3300) [Por favor, espere a que el teletransporte actual termine!](#ff7e5e)' error_no_last_position: '[Error:](#ff3300) [¡No tienes una última posición a la que volver!](#ff7e5e)' -error_in_game_only: '[Error:](#ff3300) [Ese comando sólo se puede ejecutar en el juego.](#ff7e5e)' +error_in_game_only: 'Error: Ese comando sólo se puede ejecutar en el juego.' error_invalid_server: '[Error:](#ff3300) [No se ha podido finalizar el teletransporte porque el servidor de destino no se pudo encontrar o estaba desconectado.](#ff7e5e)' error_home_invalid: '[Error:](#ff3300) [Usted no tiene una casa llamada "%1%"](#ff7e5e)' error_warp_invalid: '[Error:](#ff3300) [No hay ningún warp llamado "%1%"](#ff7e5e)' diff --git a/common/src/main/resources/locales/it-it.yml b/common/src/main/resources/locales/it-it.yml index 4a3775c1..1914a8c8 100644 --- a/common/src/main/resources/locales/it-it.yml +++ b/common/src/main/resources/locales/it-it.yml @@ -107,7 +107,7 @@ error_no_permission: '[Errore:](#ff3300) [Non hai il permesso di eseguire questo error_invalid_syntax: '[Errore:](#ff3300) [Comando non riconosciuto. Utilizza: %1%](#ff7e5e)' error_already_teleporting: '[Errore:](#ff3300) [Attendi che il teletrasporto finisca!](#ff7e5e)' error_no_last_position: '[Errore:](#ff3300) [Non hai nessuna posizione precedente salvata!](#ff7e5e)' -error_in_game_only: '[Errore:](#ff3300) [Questo comando può essere utilizzato solo in game.](#ff7e5e)' +error_in_game_only: 'Errore: Questo comando può essere utilizzato solo in game.' error_invalid_server: '[Errore:](#ff3300) [Teletrasporto fallito! Il server potrebbe essere inesistente o offline.](#ff7e5e)' error_home_invalid: '[Errore:](#ff3300) [Non hai nessuna home chiamata "%1%"](#ff7e5e)' error_warp_invalid: '[Errore:](#ff3300) [Non esiste nessun warp chiamato "%1%"](#ff7e5e)' diff --git a/common/src/main/resources/locales/pl.yml b/common/src/main/resources/locales/pl.yml index 53c9fc18..a53100bf 100644 --- a/common/src/main/resources/locales/pl.yml +++ b/common/src/main/resources/locales/pl.yml @@ -107,7 +107,7 @@ error_no_permission: '[Błąd:](#ff3300) [Nie masz uprawnień do tego polecenia. error_invalid_syntax: '[Błąd:](#ff3300) [Niepoprawna składnia. Wpisz: %1%](#ff7e5e)' error_already_teleporting: '[Error:](#ff3300) [Please wait for the current teleport to finish!](#ff7e5e)' error_no_last_position: '[Błąd:](#ff3300) [Nie masz żadnej wcześniejszej lokalizacji aby powrócić!](#ff7e5e)' -error_in_game_only: '[Error:](#ff3300) [That command can only be run in-game.](#ff7e5e)' +error_in_game_only: 'Error: That command can only be run in-game.' error_invalid_server: '[Error:](#ff3300) [Failed to finish teleportation as the target server could not be found or was offline.](#ff7e5e)' error_home_invalid: '[Błądr:](#ff3300) [Nie masz domu o nazwie "%1%"](#ff7e5e)' error_warp_invalid: '[Błąd:](#ff3300) [Nie ma warpu o nazwie "%1%"](#ff7e5e)' diff --git a/common/src/main/resources/locales/uk-ua.yml b/common/src/main/resources/locales/uk-ua.yml index cd6b8bf7..2f738a39 100644 --- a/common/src/main/resources/locales/uk-ua.yml +++ b/common/src/main/resources/locales/uk-ua.yml @@ -107,7 +107,7 @@ error_no_permission: '[Помилка:](#ff3300) [У тебе немає пра error_invalid_syntax: '[Помилка:](#ff3300) [Неккоректне використання. Треба: %1%](#ff7e5e)' error_already_teleporting: '[Error:](#ff3300) [Please wait for the current teleport to finish!](#ff7e5e)' error_no_last_position: '[Помилка:](#ff3300) [Немає куди тебе повертати!](#ff7e5e)' -error_in_game_only: '[Error:](#ff3300) [That command can only be run in-game.](#ff7e5e)' +error_in_game_only: 'Error: That command can only be run in-game.' error_invalid_server: '[Error:](#ff3300) [Failed to finish teleportation as the target server could not be found or was offline.](#ff7e5e)' error_home_invalid: '[Помилка:](#ff3300) [У тебе немає домівки "%1%"](#ff7e5e)' error_warp_invalid: '[Помилка:](#ff3300) [Немає варпу "%1%"](#ff7e5e)' diff --git a/common/src/main/resources/locales/zh-cn.yml b/common/src/main/resources/locales/zh-cn.yml index 01e43dbd..43c99bac 100644 --- a/common/src/main/resources/locales/zh-cn.yml +++ b/common/src/main/resources/locales/zh-cn.yml @@ -107,7 +107,7 @@ error_no_permission: '[错误:](#ff3300) [没有权限](#ff7e5e)' error_invalid_syntax: '[错误:](#ff3300) [语法错误, 使用: %1%](#ff7e5e)' error_already_teleporting: '错误:](#ff3300) [请等待当前传送完成!](#ff7e5e)' error_no_last_position: '[错误:](#ff3300) [没有上一个位置](#ff7e5e)' -error_in_game_only: '[错误:](#ff3300) [该命令只能在游戏中使用.](#ff7e5e)' +error_in_game_only: '错误: 该命令只能在游戏中使用.' error_invalid_server: '[错误:](#ff3300) [无法传送, 目标服务器不存在或离线.](#ff7e5e)' error_home_invalid: '[错误:](#ff3300) [家 %1% 不存在](#ff7e5e)' error_warp_invalid: '[错误:](#ff3300) [地标 %1% 不存在](#ff7e5e)' diff --git a/common/src/main/resources/locales/zh-tw.yml b/common/src/main/resources/locales/zh-tw.yml index 55ed99ef..d3d68aef 100644 --- a/common/src/main/resources/locales/zh-tw.yml +++ b/common/src/main/resources/locales/zh-tw.yml @@ -107,7 +107,7 @@ error_no_permission: '[錯誤:](#ff3300) [沒有權限](#ff7e5e)' error_invalid_syntax: '[錯誤:](#ff3300) [語法錯誤, 使用: %1%](#ff7e5e)' error_already_teleporting: '錯誤:](#ff3300) [請等待當前傳送完成!](#ff7e5e)' error_no_last_position: '[錯誤:](#ff3300) [沒有上一個位置](#ff7e5e)' -error_in_game_only: '[錯誤:](#ff3300) [該命令只能在遊戲中使用.](#ff7e5e)' +error_in_game_only: '錯誤: 該命令只能在遊戲中使用.' error_invalid_server: '[錯誤:](#ff3300) [無法傳送, 目標伺服器不存在或離線.](#ff7e5e)' error_home_invalid: '[錯誤:](#ff3300) [家 %1% 不存在](#ff7e5e)' error_warp_invalid: '[錯誤:](#ff3300) [地標 %1% 不存在](#ff7e5e)'