From 083c3dcbb94a1d873560f665f638637be7f907fb Mon Sep 17 00:00:00 2001 From: iquelli Date: Wed, 27 Mar 2024 21:47:53 +0000 Subject: [PATCH 1/5] Add title --- .../bukkit/BukkitMessageSender.java | 6 ++++- .../prisonescape/game/PrisonEscapeGame.java | 18 ++++++++++++-- .../managers/MessageLanguageManager.java | 24 +++++++++++++++++++ src/main/resources/languages/english.yml | 4 ++++ 4 files changed, 49 insertions(+), 3 deletions(-) diff --git a/src/main/java/net/tiagofar78/prisonescape/bukkit/BukkitMessageSender.java b/src/main/java/net/tiagofar78/prisonescape/bukkit/BukkitMessageSender.java index a5c13eb7..47688965 100644 --- a/src/main/java/net/tiagofar78/prisonescape/bukkit/BukkitMessageSender.java +++ b/src/main/java/net/tiagofar78/prisonescape/bukkit/BukkitMessageSender.java @@ -8,6 +8,9 @@ import net.tiagofar78.prisonescape.game.PrisonEscapePlayer; public class BukkitMessageSender { + + private static final int FADE = 20; + private static final int STAY = 70; public static List getOnlinePlayersNames() { return Bukkit.getOnlinePlayers().stream().map(p -> p.getName()).toList(); @@ -50,7 +53,8 @@ public static void sendChatMessage(String playerName, List message) { } public static void sendTitleMessage(String playerName, String titleMessage, String subtitleMessage) { - // TODO + Player bukkitPlayer = Bukkit.getPlayer(playerName); + bukkitPlayer.sendTitle(titleMessage, subtitleMessage, FADE, STAY, FADE); } } diff --git a/src/main/java/net/tiagofar78/prisonescape/game/PrisonEscapeGame.java b/src/main/java/net/tiagofar78/prisonescape/game/PrisonEscapeGame.java index b7e61125..533f91bf 100644 --- a/src/main/java/net/tiagofar78/prisonescape/game/PrisonEscapeGame.java +++ b/src/main/java/net/tiagofar78/prisonescape/game/PrisonEscapeGame.java @@ -330,9 +330,16 @@ private void startDay() { _dayPeriod = DayPeriod.DAY; _currentDay++; - + _prison.reloadChests(); - + + for (PrisonEscapePlayer player : _playersOnLobby) { + MessageLanguageManager messages = MessageLanguageManager.getInstanceByPlayer(player.getName()); + String title = messages.getNewDayTitleMessage(_currentDay); + String subtitle = messages.getNewDaySubtitleMessage(); + BukkitMessageSender.sendTitleMessage(player.getName(), title, subtitle); + } + BukkitScheduler.runSchedulerLater(new Runnable() { @Override @@ -348,6 +355,13 @@ private void startNight() { } _dayPeriod = DayPeriod.NIGHT; + + for (PrisonEscapePlayer player : _playersOnLobby) { + MessageLanguageManager messages = MessageLanguageManager.getInstanceByPlayer(player.getName()); + String title = messages.getNightTitleMessage(); + String subtitle = messages.getNightSubtitleMessage(); + BukkitMessageSender.sendTitleMessage(player.getName(), title, subtitle); + } BukkitScheduler.runSchedulerLater(new Runnable() { diff --git a/src/main/java/net/tiagofar78/prisonescape/managers/MessageLanguageManager.java b/src/main/java/net/tiagofar78/prisonescape/managers/MessageLanguageManager.java index 8c022e89..4fc64b23 100644 --- a/src/main/java/net/tiagofar78/prisonescape/managers/MessageLanguageManager.java +++ b/src/main/java/net/tiagofar78/prisonescape/managers/MessageLanguageManager.java @@ -99,6 +99,10 @@ private static String getPlayerLanguage(String playerName) { private List _gameResultMessage; private String _playerEscapedMessage; private String _gameCancelledNotEnoughPlayers; + private String _newDayTitleMessage; + private String _newDaySubtitleMessage; + private String _nightTitleMessage; + private String _nightSubtitleMessage; // ######################################## // # Errors # @@ -170,6 +174,10 @@ private MessageLanguageManager(String language) { _gameResultMessage = createMessage(messages.getStringList(announcementPath + "GameResult")); _playerEscapedMessage = createMessage(messages.getString(announcementPath + "PlayerEscaped")); _gameCancelledNotEnoughPlayers = createMessage(messages.getString(announcementPath + "GameCancelledFewPlayers")); + _newDayTitleMessage = createMessage(messages.getString(announcementPath + "NewDayTitle")); + _newDaySubtitleMessage = createMessage(messages.getString(announcementPath + "NewDaySubtitle")); + _nightTitleMessage = createMessage(messages.getString(announcementPath + "NightTitle")); + _nightSubtitleMessage = createMessage(messages.getString(announcementPath + "NightSubtitle")); String errorPath = messagePath + "Errors."; _notAllowedMessage = createMessage(messages.getString(errorPath + "NotAllowed")); @@ -343,6 +351,22 @@ public String getPlayerEscapedMessage(String playerName) { public String getGameCancelledFewPlayersMessage() { return _gameCancelledNotEnoughPlayers; } + + public String getNewDayTitleMessage(int day) { + return _newDayTitleMessage.replace("{DAYNUMBER}", String.valueOf(day)); + } + + public String getNewDaySubtitleMessage() { + return _newDaySubtitleMessage; + } + + public String getNightTitleMessage() { + return _nightTitleMessage; + } + + public String getNightSubtitleMessage() { + return _nightSubtitleMessage; + } // ######################################## // # Errors # diff --git a/src/main/resources/languages/english.yml b/src/main/resources/languages/english.yml index 892871af..127521a3 100644 --- a/src/main/resources/languages/english.yml +++ b/src/main/resources/languages/english.yml @@ -49,6 +49,10 @@ Messages: - "&6===================================" PlayerEscaped: "&ePlayer &f{PLAYER} &eescaped the prison." GameCancelledFewPlayers: "&cThe game was cancelled because there were not enough players." + NewDayTitle: "&aDay &a{DAYNUMBER}" + NewDaySubtitle: "&fThe sun has risen" + NightTitle: "&4Nightfall approaches" + NightSubtitle: "&fPlan your escape" Errors: NotAllowed: "&cYou don't have permission to do that." CommandForPlayers: "&cOnly players have permission to use this command." From fddbfab5c4a901e60a32e980fd73c12157bc1724 Mon Sep 17 00:00:00 2001 From: iquelli Date: Wed, 27 Mar 2024 21:51:38 +0000 Subject: [PATCH 2/5] Fix identation --- .../bukkit/BukkitMessageSender.java | 2 +- .../managers/MessageLanguageManager.java | 840 +++++++++--------- 2 files changed, 421 insertions(+), 421 deletions(-) diff --git a/src/main/java/net/tiagofar78/prisonescape/bukkit/BukkitMessageSender.java b/src/main/java/net/tiagofar78/prisonescape/bukkit/BukkitMessageSender.java index 47688965..613def4a 100644 --- a/src/main/java/net/tiagofar78/prisonescape/bukkit/BukkitMessageSender.java +++ b/src/main/java/net/tiagofar78/prisonescape/bukkit/BukkitMessageSender.java @@ -53,7 +53,7 @@ public static void sendChatMessage(String playerName, List message) { } public static void sendTitleMessage(String playerName, String titleMessage, String subtitleMessage) { - Player bukkitPlayer = Bukkit.getPlayer(playerName); + Player bukkitPlayer = Bukkit.getPlayer(playerName); bukkitPlayer.sendTitle(titleMessage, subtitleMessage, FADE, STAY, FADE); } diff --git a/src/main/java/net/tiagofar78/prisonescape/managers/MessageLanguageManager.java b/src/main/java/net/tiagofar78/prisonescape/managers/MessageLanguageManager.java index 4fc64b23..2f619833 100644 --- a/src/main/java/net/tiagofar78/prisonescape/managers/MessageLanguageManager.java +++ b/src/main/java/net/tiagofar78/prisonescape/managers/MessageLanguageManager.java @@ -9,351 +9,351 @@ import net.tiagofar78.prisonescape.PrisonEscapeResources; public class MessageLanguageManager { - - private static Hashtable instance = initializeLanguageMessages(); - - private static Hashtable initializeLanguageMessages() { - ConfigManager config = ConfigManager.getInstance(); - - Hashtable languagesMessages = new Hashtable<>(); - - List availableLanguages = config.getAvailableLanguages(); - String defaultLanguage = config.getDefaultLanguage(); - - if (availableLanguages.size() == 0) { - availableLanguages.add(defaultLanguage); - } - - for (String language : availableLanguages) { - languagesMessages.put(language, new MessageLanguageManager(language)); - } - - return languagesMessages; - } - - public static MessageLanguageManager getInstance(String language) { - if (language == null) { - language = ConfigManager.getInstance().getDefaultLanguage(); - } - - return instance.get(language); - } - - public static MessageLanguageManager getInstanceByPlayer(String playerName) { - String language = MessageLanguageManager.getPlayerLanguage(playerName); - if (language == null) { - language = ConfigManager.getInstance().getDefaultLanguage(); - } - - return MessageLanguageManager.getInstance(language); - } - - private static String getPlayerLanguage(String playerName) { - return ConfigManager.getInstance().getDefaultLanguage(); - } - -// ####################################### -// # Kit # -// ####################################### - - private String _selectPrisionerTeamItemName; - private String _selectPoliceTeamItemName; - private String _selectNoneTeamItemName; - -// ####################################### -// # Inventory # -// ####################################### - - private String _containerName; - -// ######################################## -// # Warnings # -// ######################################## - - private String _successfullyStartedGameMessage; - private String _successfullyForceStartedGameMessage; - private String _successfullyJoinedGameMessage; - private String _successfullyLeftGameMessage; - private String _successfullyForceStoppedGameMessage; - private String _successfullyRejoinedGameMessage; - private String _successfullyStoppedGameMessage; - private String _selectedPrisionersTeamMessage; - private String _selectedPoliceTeamMessage; - private String _removedTeamPreferenceMessage; - private String _prisionerGameStartedMessage; - private String _policeGameStartedMessage; - -// ######################################## -// # Announcements # -// ######################################## - - private List _gameStartingAnnouncementMessage; - private String _prisionerArrested; - private String _prisionerFreedOfSolitary; - private String _prisionersWonTitle; - private String _prisionersWonSubtitle; - private String _policeWonTitle; - private String _policeWonSubtitle; - private String _victoryWord; - private String _defeatWord; - private List _gameResultMessage; - private String _playerEscapedMessage; - private String _gameCancelledNotEnoughPlayers; + + private static Hashtable instance = initializeLanguageMessages(); + + private static Hashtable initializeLanguageMessages() { + ConfigManager config = ConfigManager.getInstance(); + + Hashtable languagesMessages = new Hashtable<>(); + + List availableLanguages = config.getAvailableLanguages(); + String defaultLanguage = config.getDefaultLanguage(); + + if (availableLanguages.size() == 0) { + availableLanguages.add(defaultLanguage); + } + + for (String language : availableLanguages) { + languagesMessages.put(language, new MessageLanguageManager(language)); + } + + return languagesMessages; + } + + public static MessageLanguageManager getInstance(String language) { + if (language == null) { + language = ConfigManager.getInstance().getDefaultLanguage(); + } + + return instance.get(language); + } + + public static MessageLanguageManager getInstanceByPlayer(String playerName) { + String language = MessageLanguageManager.getPlayerLanguage(playerName); + if (language == null) { + language = ConfigManager.getInstance().getDefaultLanguage(); + } + + return MessageLanguageManager.getInstance(language); + } + + private static String getPlayerLanguage(String playerName) { + return ConfigManager.getInstance().getDefaultLanguage(); + } + + // ####################################### + // # Kit # + // ####################################### + + private String _selectPrisionerTeamItemName; + private String _selectPoliceTeamItemName; + private String _selectNoneTeamItemName; + + // ####################################### + // # Inventory # + // ####################################### + + private String _containerName; + + // ######################################## + // # Warnings # + // ######################################## + + private String _successfullyStartedGameMessage; + private String _successfullyForceStartedGameMessage; + private String _successfullyJoinedGameMessage; + private String _successfullyLeftGameMessage; + private String _successfullyForceStoppedGameMessage; + private String _successfullyRejoinedGameMessage; + private String _successfullyStoppedGameMessage; + private String _selectedPrisionersTeamMessage; + private String _selectedPoliceTeamMessage; + private String _removedTeamPreferenceMessage; + private String _prisionerGameStartedMessage; + private String _policeGameStartedMessage; + + // ######################################## + // # Announcements # + // ######################################## + + private List _gameStartingAnnouncementMessage; + private String _prisionerArrested; + private String _prisionerFreedOfSolitary; + private String _prisionersWonTitle; + private String _prisionersWonSubtitle; + private String _policeWonTitle; + private String _policeWonSubtitle; + private String _victoryWord; + private String _defeatWord; + private List _gameResultMessage; + private String _playerEscapedMessage; + private String _gameCancelledNotEnoughPlayers; private String _newDayTitleMessage; private String _newDaySubtitleMessage; private String _nightTitleMessage; private String _nightSubtitleMessage; - -// ######################################## -// # Errors # -// ######################################## - - private String _notAllowedMessage; - private String _onlyPlayersCanUseThisCommandMessage; - - private String _gameAlreadyStartedMessage; - private String _gameNotStartedYetMessage; - private String _gameAlreadyOngoingMessage; - private String _gameHasNotStartedUseJoinInsteadMessage; - private String _gameIsNotInFinishedPhaseMessage; - private String _lobbyIsFullMessage; - - private String _playerAlreadyJoinedMessage; - private String _playerNotOnLobbyMessage; - private String _playerWasNeverInGameMessage; - -// ######################################## -// # Usages # -// ######################################## - - private List _usageMessage; - private String _startCommandUsage; - private String _forceStartCommandUsage; - private String _joinCommandUsage; - private String _leaveCommandUsage; - private String _forceStopCommandUsage; - private String _rejoinCommandUsage; - private String _stopCommandUsage; - - private MessageLanguageManager(String language) { - YamlConfiguration messages = PrisonEscapeResources.getYamlLanguage(language); - - String kitPath = "Kits."; - String teamSelector = kitPath + "TeamSelector."; - _selectPrisionerTeamItemName = createMessage(messages.getString(teamSelector + "SelectPrisioners.Name")); - _selectPoliceTeamItemName = createMessage(messages.getString(teamSelector + "SelectPolice.Name")); - _selectNoneTeamItemName = createMessage(messages.getString(teamSelector + "SelectNone.Name"));; - - _containerName = createMessage(messages.getString("Inventory.Chest.Title")); - - String messagePath = "Messages."; - String warningPath = messagePath + "Warnings."; - _successfullyStartedGameMessage = createMessage(messages.getString(warningPath + "StartedGame")); - _successfullyForceStartedGameMessage = createMessage(messages.getString(warningPath + "ForceStartedGame")); - _successfullyJoinedGameMessage = createMessage(messages.getString(warningPath + "JoinedGame")); - _successfullyLeftGameMessage = createMessage(messages.getString(warningPath + "LeftGame")); - _successfullyForceStoppedGameMessage = createMessage(messages.getString(warningPath + "ForceStoppedGame")); - _successfullyRejoinedGameMessage = createMessage(messages.getString(warningPath + "RejoinedGame")); - _successfullyStoppedGameMessage = createMessage(messages.getString(warningPath + "StoppedGame")); - _selectedPrisionersTeamMessage = createMessage(messages.getString(warningPath + "SelectedPrisionersTeam")); - _selectedPoliceTeamMessage = createMessage(messages.getString(warningPath + "SelectedPoliceTeam")); - _removedTeamPreferenceMessage = createMessage(messages.getString(warningPath + "SelectedRandomTeam")); - _prisionerGameStartedMessage = createMessage(messages.getString(warningPath + "PrisionerGameStart")); - _policeGameStartedMessage = createMessage(messages.getString(warningPath + "PoliceGameStart")); - - String announcementPath = messagePath + "Announcements."; - _gameStartingAnnouncementMessage = createMessage(messages.getStringList(announcementPath + "GameStarting")); - _prisionerArrested = createMessage(messages.getString(announcementPath + "PrisionerArrested")); - _prisionerFreedOfSolitary = createMessage(messages.getString(announcementPath + "PrisionerFreedOfSolitary")); - _prisionersWonTitle = createMessage(messages.getString(announcementPath + "PrisionersWonTitle")); - _prisionersWonSubtitle = createMessage(messages.getString(announcementPath + "PrisionersWonSubtitle")); - _policeWonTitle = createMessage(messages.getString(announcementPath + "PoliceWonTitle")); - _policeWonSubtitle = createMessage(messages.getString(announcementPath + "PoliceWonSubtitle")); - _victoryWord = messages.getString(announcementPath + "VictoryWord"); - _defeatWord = messages.getString(announcementPath + "DefeatWord"); - _gameResultMessage = createMessage(messages.getStringList(announcementPath + "GameResult")); - _playerEscapedMessage = createMessage(messages.getString(announcementPath + "PlayerEscaped")); - _gameCancelledNotEnoughPlayers = createMessage(messages.getString(announcementPath + "GameCancelledFewPlayers")); + + // ######################################## + // # Errors # + // ######################################## + + private String _notAllowedMessage; + private String _onlyPlayersCanUseThisCommandMessage; + + private String _gameAlreadyStartedMessage; + private String _gameNotStartedYetMessage; + private String _gameAlreadyOngoingMessage; + private String _gameHasNotStartedUseJoinInsteadMessage; + private String _gameIsNotInFinishedPhaseMessage; + private String _lobbyIsFullMessage; + + private String _playerAlreadyJoinedMessage; + private String _playerNotOnLobbyMessage; + private String _playerWasNeverInGameMessage; + + // ######################################## + // # Usages # + // ######################################## + + private List _usageMessage; + private String _startCommandUsage; + private String _forceStartCommandUsage; + private String _joinCommandUsage; + private String _leaveCommandUsage; + private String _forceStopCommandUsage; + private String _rejoinCommandUsage; + private String _stopCommandUsage; + + private MessageLanguageManager(String language) { + YamlConfiguration messages = PrisonEscapeResources.getYamlLanguage(language); + + String kitPath = "Kits."; + String teamSelector = kitPath + "TeamSelector."; + _selectPrisionerTeamItemName = createMessage(messages.getString(teamSelector + "SelectPrisioners.Name")); + _selectPoliceTeamItemName = createMessage(messages.getString(teamSelector + "SelectPolice.Name")); + _selectNoneTeamItemName = createMessage(messages.getString(teamSelector + "SelectNone.Name"));; + + _containerName = createMessage(messages.getString("Inventory.Chest.Title")); + + String messagePath = "Messages."; + String warningPath = messagePath + "Warnings."; + _successfullyStartedGameMessage = createMessage(messages.getString(warningPath + "StartedGame")); + _successfullyForceStartedGameMessage = createMessage(messages.getString(warningPath + "ForceStartedGame")); + _successfullyJoinedGameMessage = createMessage(messages.getString(warningPath + "JoinedGame")); + _successfullyLeftGameMessage = createMessage(messages.getString(warningPath + "LeftGame")); + _successfullyForceStoppedGameMessage = createMessage(messages.getString(warningPath + "ForceStoppedGame")); + _successfullyRejoinedGameMessage = createMessage(messages.getString(warningPath + "RejoinedGame")); + _successfullyStoppedGameMessage = createMessage(messages.getString(warningPath + "StoppedGame")); + _selectedPrisionersTeamMessage = createMessage(messages.getString(warningPath + "SelectedPrisionersTeam")); + _selectedPoliceTeamMessage = createMessage(messages.getString(warningPath + "SelectedPoliceTeam")); + _removedTeamPreferenceMessage = createMessage(messages.getString(warningPath + "SelectedRandomTeam")); + _prisionerGameStartedMessage = createMessage(messages.getString(warningPath + "PrisionerGameStart")); + _policeGameStartedMessage = createMessage(messages.getString(warningPath + "PoliceGameStart")); + + String announcementPath = messagePath + "Announcements."; + _gameStartingAnnouncementMessage = createMessage(messages.getStringList(announcementPath + "GameStarting")); + _prisionerArrested = createMessage(messages.getString(announcementPath + "PrisionerArrested")); + _prisionerFreedOfSolitary = createMessage(messages.getString(announcementPath + "PrisionerFreedOfSolitary")); + _prisionersWonTitle = createMessage(messages.getString(announcementPath + "PrisionersWonTitle")); + _prisionersWonSubtitle = createMessage(messages.getString(announcementPath + "PrisionersWonSubtitle")); + _policeWonTitle = createMessage(messages.getString(announcementPath + "PoliceWonTitle")); + _policeWonSubtitle = createMessage(messages.getString(announcementPath + "PoliceWonSubtitle")); + _victoryWord = messages.getString(announcementPath + "VictoryWord"); + _defeatWord = messages.getString(announcementPath + "DefeatWord"); + _gameResultMessage = createMessage(messages.getStringList(announcementPath + "GameResult")); + _playerEscapedMessage = createMessage(messages.getString(announcementPath + "PlayerEscaped")); + _gameCancelledNotEnoughPlayers = createMessage(messages.getString(announcementPath + "GameCancelledFewPlayers")); _newDayTitleMessage = createMessage(messages.getString(announcementPath + "NewDayTitle")); _newDaySubtitleMessage = createMessage(messages.getString(announcementPath + "NewDaySubtitle")); _nightTitleMessage = createMessage(messages.getString(announcementPath + "NightTitle")); _nightSubtitleMessage = createMessage(messages.getString(announcementPath + "NightSubtitle")); - - String errorPath = messagePath + "Errors."; - _notAllowedMessage = createMessage(messages.getString(errorPath + "NotAllowed")); - _onlyPlayersCanUseThisCommandMessage = createMessage(messages.getString(errorPath + "CommandForPlayers")); - _gameAlreadyStartedMessage = createMessage(messages.getString(errorPath + "GameAlreadyStarted")); - _gameNotStartedYetMessage = createMessage(messages.getString(errorPath + "GameNotStartedYet")); - _gameAlreadyOngoingMessage = createMessage(messages.getString(errorPath + "GameAlreadyOngoing")); - _gameHasNotStartedUseJoinInsteadMessage = createMessage(messages.getString(errorPath + "GameIsStillWaiting")); - _gameIsNotInFinishedPhaseMessage = createMessage(messages.getString(errorPath + "GameIsNotFinished")); - _lobbyIsFullMessage = createMessage(messages.getString(errorPath + "LobbyIsFull")); - _playerAlreadyJoinedMessage = createMessage(messages.getString(errorPath + "AlreadyJoined")); - _playerNotOnLobbyMessage = createMessage(messages.getString(errorPath + "NotOnLobby")); - _playerWasNeverInGameMessage = createMessage(messages.getString(errorPath + "NeverInGame")); - - String usagePath = messagePath + "Usages."; - _usageMessage = createMessage(messages.getStringList(usagePath + "General")); - _startCommandUsage = createMessage(messages.getString(usagePath + "Start")); - _forceStartCommandUsage = createMessage(messages.getString(usagePath + "ForceStart")); - _forceStopCommandUsage = createMessage(messages.getString(usagePath + "ForceStop")); - _joinCommandUsage = createMessage(messages.getString(usagePath + "Join")); - _leaveCommandUsage = createMessage(messages.getString(usagePath + "Leave")); - _rejoinCommandUsage = createMessage(messages.getString(usagePath + "Rejoin")); - _stopCommandUsage = createMessage(messages.getString(usagePath + "Stop")); - } - - private String createMessage(String rawMessage) { - return rawMessage.replace("&", "§"); - } - - private List createMessage(List rawMessage) { - List message = new ArrayList<>(rawMessage); - - for (int i = 0; i < message.size(); i++) { - message.set(i, message.get(i).replace("&", "§")); - } - - return message; - } - -// ####################################### -// # Kit # -// ####################################### - - public String getSelectPrisionerTeamItemName() { - return _selectPrisionerTeamItemName; - } - - public String getSelectPoliceTeamItemName() { - return _selectPoliceTeamItemName; - } - - public String getSelectNoneTeamItemName() { - return _selectNoneTeamItemName; - } - -// ####################################### -// # Inventory # -// ####################################### - - public String getContainerName() { - return _containerName; - } - -// ######################################## -// # Warnings # -// ######################################## - - public String getSuccessfullyStartedGameMessage() { - return _successfullyStartedGameMessage; - } - - public String getSuccessfullyForceStartedGameMessage() { - return _successfullyForceStartedGameMessage; - } - - public String getSuccessfullyJoinedGameMessage() { - return _successfullyJoinedGameMessage; - } - - public String getSuccessfullyLeftGameMessage() { - return _successfullyLeftGameMessage; - } - - public String getSuccessfullyForceStoppedGameMessage() { - return _successfullyForceStoppedGameMessage; - } - - public String getSuccessfullyRejoinedGameMessage() { - return _successfullyRejoinedGameMessage; - } - - public String getSuccessfullyStoppedGameMessage() { - return _successfullyStoppedGameMessage; - } - - public String getSelectedPrisionersTeamMessage() { - return _selectedPrisionersTeamMessage; - } - - public String getSelectedPoliceTeamMessage() { - return _selectedPoliceTeamMessage; - } - - public String getRemovedTeamPreferenceMessage() { - return _removedTeamPreferenceMessage; - } - - public String getPrisionerGameStartedMessage() { - return _prisionerGameStartedMessage; - } - - public String getPoliceGameStartedMessage() { - return _policeGameStartedMessage; - } - -// ######################################## -// # Announcements # -// ######################################## - - public List getGameStartingAnnouncementMessage(int remainingTime, int playersOnLobby) { - List message = new ArrayList<>(_gameStartingAnnouncementMessage); - - for (int i = 0; i < message.size(); i++) { - message.set(i, message.get(i) - .replace("{SECONDS}", Integer.toString(remainingTime)) - .replace("{PLAYERS}", Integer.toString(playersOnLobby))); - } - - return message; - } - - public String getPrisionerArrested(String playerName) { - return _prisionerArrested.replace("{PLAYER}", playerName); - } - - public String getPrisionerFreedOfSolitary() { - return _prisionerFreedOfSolitary; - } - - public String getPrisionersWonTitle() { - return _prisionersWonTitle; - } - - public String getPrisionersWonSubtitle() { - return _prisionersWonSubtitle; - } - - public String getPoliceWonTitle() { - return _policeWonTitle; - } - - public String getPoliceWonSubtitle(int playersInPrison) { - return _policeWonSubtitle; - } - - public List getGameResultMessage(boolean isWinner) { - String result = isWinner ? _victoryWord : _defeatWord; - - List message = new ArrayList<>(_gameResultMessage); - for (int i = 0; i < message.size(); i++) { - message.set(i, message.get(i).replace("{RESULT}", result)); - } - - return message; - } - - public String getPlayerEscapedMessage(String playerName) { - return _playerEscapedMessage.replace("{PLAYER}", playerName); - } - - public String getGameCancelledFewPlayersMessage() { - return _gameCancelledNotEnoughPlayers; - } + + String errorPath = messagePath + "Errors."; + _notAllowedMessage = createMessage(messages.getString(errorPath + "NotAllowed")); + _onlyPlayersCanUseThisCommandMessage = createMessage(messages.getString(errorPath + "CommandForPlayers")); + _gameAlreadyStartedMessage = createMessage(messages.getString(errorPath + "GameAlreadyStarted")); + _gameNotStartedYetMessage = createMessage(messages.getString(errorPath + "GameNotStartedYet")); + _gameAlreadyOngoingMessage = createMessage(messages.getString(errorPath + "GameAlreadyOngoing")); + _gameHasNotStartedUseJoinInsteadMessage = createMessage(messages.getString(errorPath + "GameIsStillWaiting")); + _gameIsNotInFinishedPhaseMessage = createMessage(messages.getString(errorPath + "GameIsNotFinished")); + _lobbyIsFullMessage = createMessage(messages.getString(errorPath + "LobbyIsFull")); + _playerAlreadyJoinedMessage = createMessage(messages.getString(errorPath + "AlreadyJoined")); + _playerNotOnLobbyMessage = createMessage(messages.getString(errorPath + "NotOnLobby")); + _playerWasNeverInGameMessage = createMessage(messages.getString(errorPath + "NeverInGame")); + + String usagePath = messagePath + "Usages."; + _usageMessage = createMessage(messages.getStringList(usagePath + "General")); + _startCommandUsage = createMessage(messages.getString(usagePath + "Start")); + _forceStartCommandUsage = createMessage(messages.getString(usagePath + "ForceStart")); + _forceStopCommandUsage = createMessage(messages.getString(usagePath + "ForceStop")); + _joinCommandUsage = createMessage(messages.getString(usagePath + "Join")); + _leaveCommandUsage = createMessage(messages.getString(usagePath + "Leave")); + _rejoinCommandUsage = createMessage(messages.getString(usagePath + "Rejoin")); + _stopCommandUsage = createMessage(messages.getString(usagePath + "Stop")); + } + + private String createMessage(String rawMessage) { + return rawMessage.replace("&", "§"); + } + + private List createMessage(List rawMessage) { + List message = new ArrayList<>(rawMessage); + + for (int i = 0; i < message.size(); i++) { + message.set(i, message.get(i).replace("&", "§")); + } + + return message; + } + + // ####################################### + // # Kit # + // ####################################### + + public String getSelectPrisionerTeamItemName() { + return _selectPrisionerTeamItemName; + } + + public String getSelectPoliceTeamItemName() { + return _selectPoliceTeamItemName; + } + + public String getSelectNoneTeamItemName() { + return _selectNoneTeamItemName; + } + + // ####################################### + // # Inventory # + // ####################################### + + public String getContainerName() { + return _containerName; + } + + // ######################################## + // # Warnings # + // ######################################## + + public String getSuccessfullyStartedGameMessage() { + return _successfullyStartedGameMessage; + } + + public String getSuccessfullyForceStartedGameMessage() { + return _successfullyForceStartedGameMessage; + } + + public String getSuccessfullyJoinedGameMessage() { + return _successfullyJoinedGameMessage; + } + + public String getSuccessfullyLeftGameMessage() { + return _successfullyLeftGameMessage; + } + + public String getSuccessfullyForceStoppedGameMessage() { + return _successfullyForceStoppedGameMessage; + } + + public String getSuccessfullyRejoinedGameMessage() { + return _successfullyRejoinedGameMessage; + } + + public String getSuccessfullyStoppedGameMessage() { + return _successfullyStoppedGameMessage; + } + + public String getSelectedPrisionersTeamMessage() { + return _selectedPrisionersTeamMessage; + } + + public String getSelectedPoliceTeamMessage() { + return _selectedPoliceTeamMessage; + } + + public String getRemovedTeamPreferenceMessage() { + return _removedTeamPreferenceMessage; + } + + public String getPrisionerGameStartedMessage() { + return _prisionerGameStartedMessage; + } + + public String getPoliceGameStartedMessage() { + return _policeGameStartedMessage; + } + + // ######################################## + // # Announcements # + // ######################################## + + public List getGameStartingAnnouncementMessage(int remainingTime, int playersOnLobby) { + List message = new ArrayList<>(_gameStartingAnnouncementMessage); + + for (int i = 0; i < message.size(); i++) { + message.set(i, message.get(i) + .replace("{SECONDS}", Integer.toString(remainingTime)) + .replace("{PLAYERS}", Integer.toString(playersOnLobby))); + } + + return message; + } + + public String getPrisionerArrested(String playerName) { + return _prisionerArrested.replace("{PLAYER}", playerName); + } + + public String getPrisionerFreedOfSolitary() { + return _prisionerFreedOfSolitary; + } + + public String getPrisionersWonTitle() { + return _prisionersWonTitle; + } + + public String getPrisionersWonSubtitle() { + return _prisionersWonSubtitle; + } + + public String getPoliceWonTitle() { + return _policeWonTitle; + } + + public String getPoliceWonSubtitle(int playersInPrison) { + return _policeWonSubtitle; + } + + public List getGameResultMessage(boolean isWinner) { + String result = isWinner ? _victoryWord : _defeatWord; + + List message = new ArrayList<>(_gameResultMessage); + for (int i = 0; i < message.size(); i++) { + message.set(i, message.get(i).replace("{RESULT}", result)); + } + + return message; + } + + public String getPlayerEscapedMessage(String playerName) { + return _playerEscapedMessage.replace("{PLAYER}", playerName); + } + + public String getGameCancelledFewPlayersMessage() { + return _gameCancelledNotEnoughPlayers; + } public String getNewDayTitleMessage(int day) { - return _newDayTitleMessage.replace("{DAYNUMBER}", String.valueOf(day)); + return _newDayTitleMessage.replace("{DAYNUMBER}", String.valueOf(day)); } public String getNewDaySubtitleMessage() { @@ -363,92 +363,92 @@ public String getNewDaySubtitleMessage() { public String getNightTitleMessage() { return _nightTitleMessage; } - + public String getNightSubtitleMessage() { return _nightSubtitleMessage; } - -// ######################################## -// # Errors # -// ######################################## - - public String getNotAllowedMessage() { - return _notAllowedMessage; - } - - public String getOnlyPlayersCanUseThisCommandMessage() { - return _onlyPlayersCanUseThisCommandMessage; - } - - public String getGameAlreadyStartedMessage() { - return _gameAlreadyStartedMessage; - } - - public String getGameNotStartedYetMessage() { - return _gameNotStartedYetMessage; - } - - public String getGameAlreadyOngoingMessage() { - return _gameAlreadyOngoingMessage; - } - - public String getGameHasNotStartedUseJoinInsteadMessage() { - return _gameHasNotStartedUseJoinInsteadMessage; - } - - public String getGameHasNotFinishedMessage() { - return _gameIsNotInFinishedPhaseMessage; - } - - public String getLobbyIsFullMessage() { - return _lobbyIsFullMessage; - } - - public String getPlayerAlreadyJoinedMessage() { - return _playerAlreadyJoinedMessage; - } - - public String getPlayerNotOnLobbyMessage() { - return _playerNotOnLobbyMessage; - } - - public String getPlayerWasNeverInGameMessage() { - return _playerWasNeverInGameMessage; - } - -// ######################################## -// # Usages # -// ######################################## - - public List getUsage() { - return _usageMessage; - } - - public String getStartCommandUsage() { - return _startCommandUsage; - } - - public String getForceStartCommandUsage() { - return _forceStartCommandUsage; - } - - public String getJoinCommandUsage() { - return _joinCommandUsage; - } - - public String getLeaveCommandUsage() { - return _leaveCommandUsage; - } - - public String getForceStopCommandUsage() { - return _forceStopCommandUsage; - } - - public String getRejoinCommandUsage() { - return _rejoinCommandUsage; - } - - public String getStopCommandUsage() { - return _stopCommandUsage; - } + + // ######################################## + // # Errors # + // ######################################## + + public String getNotAllowedMessage() { + return _notAllowedMessage; + } + + public String getOnlyPlayersCanUseThisCommandMessage() { + return _onlyPlayersCanUseThisCommandMessage; + } + + public String getGameAlreadyStartedMessage() { + return _gameAlreadyStartedMessage; + } + + public String getGameNotStartedYetMessage() { + return _gameNotStartedYetMessage; + } + + public String getGameAlreadyOngoingMessage() { + return _gameAlreadyOngoingMessage; + } + + public String getGameHasNotStartedUseJoinInsteadMessage() { + return _gameHasNotStartedUseJoinInsteadMessage; + } + + public String getGameHasNotFinishedMessage() { + return _gameIsNotInFinishedPhaseMessage; + } + + public String getLobbyIsFullMessage() { + return _lobbyIsFullMessage; + } + + public String getPlayerAlreadyJoinedMessage() { + return _playerAlreadyJoinedMessage; + } + + public String getPlayerNotOnLobbyMessage() { + return _playerNotOnLobbyMessage; + } + + public String getPlayerWasNeverInGameMessage() { + return _playerWasNeverInGameMessage; + } + + // ######################################## + // # Usages # + // ######################################## + + public List getUsage() { + return _usageMessage; + } + + public String getStartCommandUsage() { + return _startCommandUsage; + } + + public String getForceStartCommandUsage() { + return _forceStartCommandUsage; + } + + public String getJoinCommandUsage() { + return _joinCommandUsage; + } + + public String getLeaveCommandUsage() { + return _leaveCommandUsage; + } + + public String getForceStopCommandUsage() { + return _forceStopCommandUsage; + } + + public String getRejoinCommandUsage() { + return _rejoinCommandUsage; + } + + public String getStopCommandUsage() { + return _stopCommandUsage; + } } From 2bb376516a69c3ad3276be9a609eab8f9a75eefb Mon Sep 17 00:00:00 2001 From: iquelli Date: Wed, 27 Mar 2024 21:53:21 +0000 Subject: [PATCH 3/5] Check if player exists --- .../tiagofar78/prisonescape/bukkit/BukkitMessageSender.java | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/main/java/net/tiagofar78/prisonescape/bukkit/BukkitMessageSender.java b/src/main/java/net/tiagofar78/prisonescape/bukkit/BukkitMessageSender.java index 613def4a..989a9d7d 100644 --- a/src/main/java/net/tiagofar78/prisonescape/bukkit/BukkitMessageSender.java +++ b/src/main/java/net/tiagofar78/prisonescape/bukkit/BukkitMessageSender.java @@ -54,6 +54,10 @@ public static void sendChatMessage(String playerName, List message) { public static void sendTitleMessage(String playerName, String titleMessage, String subtitleMessage) { Player bukkitPlayer = Bukkit.getPlayer(playerName); + if (bukkitPlayer == null || !bukkitPlayer.isOnline()) { + return; + } + bukkitPlayer.sendTitle(titleMessage, subtitleMessage, FADE, STAY, FADE); } From 6b2412fcef7a4589eb6bfbbe8d6f2ff1db5fccdf Mon Sep 17 00:00:00 2001 From: iquelli Date: Wed, 27 Mar 2024 22:01:44 +0000 Subject: [PATCH 4/5] Add white space --- .../managers/MessageLanguageManager.java | 804 +++++++++--------- 1 file changed, 402 insertions(+), 402 deletions(-) diff --git a/src/main/java/net/tiagofar78/prisonescape/managers/MessageLanguageManager.java b/src/main/java/net/tiagofar78/prisonescape/managers/MessageLanguageManager.java index 2f619833..3e6ee4ba 100644 --- a/src/main/java/net/tiagofar78/prisonescape/managers/MessageLanguageManager.java +++ b/src/main/java/net/tiagofar78/prisonescape/managers/MessageLanguageManager.java @@ -10,445 +10,445 @@ public class MessageLanguageManager { - private static Hashtable instance = initializeLanguageMessages(); - - private static Hashtable initializeLanguageMessages() { - ConfigManager config = ConfigManager.getInstance(); - - Hashtable languagesMessages = new Hashtable<>(); - - List availableLanguages = config.getAvailableLanguages(); - String defaultLanguage = config.getDefaultLanguage(); - - if (availableLanguages.size() == 0) { - availableLanguages.add(defaultLanguage); - } - - for (String language : availableLanguages) { - languagesMessages.put(language, new MessageLanguageManager(language)); - } - - return languagesMessages; - } - - public static MessageLanguageManager getInstance(String language) { - if (language == null) { - language = ConfigManager.getInstance().getDefaultLanguage(); - } - - return instance.get(language); - } - - public static MessageLanguageManager getInstanceByPlayer(String playerName) { - String language = MessageLanguageManager.getPlayerLanguage(playerName); - if (language == null) { - language = ConfigManager.getInstance().getDefaultLanguage(); - } - - return MessageLanguageManager.getInstance(language); - } - - private static String getPlayerLanguage(String playerName) { - return ConfigManager.getInstance().getDefaultLanguage(); - } - - // ####################################### - // # Kit # - // ####################################### - - private String _selectPrisionerTeamItemName; - private String _selectPoliceTeamItemName; - private String _selectNoneTeamItemName; - - // ####################################### - // # Inventory # - // ####################################### - - private String _containerName; - - // ######################################## - // # Warnings # - // ######################################## - - private String _successfullyStartedGameMessage; - private String _successfullyForceStartedGameMessage; - private String _successfullyJoinedGameMessage; - private String _successfullyLeftGameMessage; - private String _successfullyForceStoppedGameMessage; - private String _successfullyRejoinedGameMessage; - private String _successfullyStoppedGameMessage; - private String _selectedPrisionersTeamMessage; - private String _selectedPoliceTeamMessage; - private String _removedTeamPreferenceMessage; - private String _prisionerGameStartedMessage; - private String _policeGameStartedMessage; - - // ######################################## - // # Announcements # - // ######################################## - - private List _gameStartingAnnouncementMessage; - private String _prisionerArrested; - private String _prisionerFreedOfSolitary; - private String _prisionersWonTitle; - private String _prisionersWonSubtitle; - private String _policeWonTitle; - private String _policeWonSubtitle; - private String _victoryWord; - private String _defeatWord; - private List _gameResultMessage; - private String _playerEscapedMessage; - private String _gameCancelledNotEnoughPlayers; - private String _newDayTitleMessage; - private String _newDaySubtitleMessage; - private String _nightTitleMessage; - private String _nightSubtitleMessage; - - // ######################################## - // # Errors # - // ######################################## - - private String _notAllowedMessage; - private String _onlyPlayersCanUseThisCommandMessage; - - private String _gameAlreadyStartedMessage; - private String _gameNotStartedYetMessage; - private String _gameAlreadyOngoingMessage; - private String _gameHasNotStartedUseJoinInsteadMessage; - private String _gameIsNotInFinishedPhaseMessage; - private String _lobbyIsFullMessage; - - private String _playerAlreadyJoinedMessage; - private String _playerNotOnLobbyMessage; - private String _playerWasNeverInGameMessage; - - // ######################################## - // # Usages # - // ######################################## - - private List _usageMessage; - private String _startCommandUsage; - private String _forceStartCommandUsage; - private String _joinCommandUsage; - private String _leaveCommandUsage; - private String _forceStopCommandUsage; - private String _rejoinCommandUsage; - private String _stopCommandUsage; - - private MessageLanguageManager(String language) { - YamlConfiguration messages = PrisonEscapeResources.getYamlLanguage(language); - - String kitPath = "Kits."; - String teamSelector = kitPath + "TeamSelector."; - _selectPrisionerTeamItemName = createMessage(messages.getString(teamSelector + "SelectPrisioners.Name")); - _selectPoliceTeamItemName = createMessage(messages.getString(teamSelector + "SelectPolice.Name")); - _selectNoneTeamItemName = createMessage(messages.getString(teamSelector + "SelectNone.Name"));; - - _containerName = createMessage(messages.getString("Inventory.Chest.Title")); - - String messagePath = "Messages."; - String warningPath = messagePath + "Warnings."; - _successfullyStartedGameMessage = createMessage(messages.getString(warningPath + "StartedGame")); - _successfullyForceStartedGameMessage = createMessage(messages.getString(warningPath + "ForceStartedGame")); - _successfullyJoinedGameMessage = createMessage(messages.getString(warningPath + "JoinedGame")); - _successfullyLeftGameMessage = createMessage(messages.getString(warningPath + "LeftGame")); - _successfullyForceStoppedGameMessage = createMessage(messages.getString(warningPath + "ForceStoppedGame")); - _successfullyRejoinedGameMessage = createMessage(messages.getString(warningPath + "RejoinedGame")); - _successfullyStoppedGameMessage = createMessage(messages.getString(warningPath + "StoppedGame")); - _selectedPrisionersTeamMessage = createMessage(messages.getString(warningPath + "SelectedPrisionersTeam")); - _selectedPoliceTeamMessage = createMessage(messages.getString(warningPath + "SelectedPoliceTeam")); - _removedTeamPreferenceMessage = createMessage(messages.getString(warningPath + "SelectedRandomTeam")); - _prisionerGameStartedMessage = createMessage(messages.getString(warningPath + "PrisionerGameStart")); - _policeGameStartedMessage = createMessage(messages.getString(warningPath + "PoliceGameStart")); - - String announcementPath = messagePath + "Announcements."; - _gameStartingAnnouncementMessage = createMessage(messages.getStringList(announcementPath + "GameStarting")); - _prisionerArrested = createMessage(messages.getString(announcementPath + "PrisionerArrested")); - _prisionerFreedOfSolitary = createMessage(messages.getString(announcementPath + "PrisionerFreedOfSolitary")); - _prisionersWonTitle = createMessage(messages.getString(announcementPath + "PrisionersWonTitle")); - _prisionersWonSubtitle = createMessage(messages.getString(announcementPath + "PrisionersWonSubtitle")); - _policeWonTitle = createMessage(messages.getString(announcementPath + "PoliceWonTitle")); - _policeWonSubtitle = createMessage(messages.getString(announcementPath + "PoliceWonSubtitle")); - _victoryWord = messages.getString(announcementPath + "VictoryWord"); - _defeatWord = messages.getString(announcementPath + "DefeatWord"); - _gameResultMessage = createMessage(messages.getStringList(announcementPath + "GameResult")); - _playerEscapedMessage = createMessage(messages.getString(announcementPath + "PlayerEscaped")); - _gameCancelledNotEnoughPlayers = createMessage(messages.getString(announcementPath + "GameCancelledFewPlayers")); - _newDayTitleMessage = createMessage(messages.getString(announcementPath + "NewDayTitle")); - _newDaySubtitleMessage = createMessage(messages.getString(announcementPath + "NewDaySubtitle")); - _nightTitleMessage = createMessage(messages.getString(announcementPath + "NightTitle")); - _nightSubtitleMessage = createMessage(messages.getString(announcementPath + "NightSubtitle")); - - String errorPath = messagePath + "Errors."; - _notAllowedMessage = createMessage(messages.getString(errorPath + "NotAllowed")); - _onlyPlayersCanUseThisCommandMessage = createMessage(messages.getString(errorPath + "CommandForPlayers")); - _gameAlreadyStartedMessage = createMessage(messages.getString(errorPath + "GameAlreadyStarted")); - _gameNotStartedYetMessage = createMessage(messages.getString(errorPath + "GameNotStartedYet")); - _gameAlreadyOngoingMessage = createMessage(messages.getString(errorPath + "GameAlreadyOngoing")); - _gameHasNotStartedUseJoinInsteadMessage = createMessage(messages.getString(errorPath + "GameIsStillWaiting")); - _gameIsNotInFinishedPhaseMessage = createMessage(messages.getString(errorPath + "GameIsNotFinished")); - _lobbyIsFullMessage = createMessage(messages.getString(errorPath + "LobbyIsFull")); - _playerAlreadyJoinedMessage = createMessage(messages.getString(errorPath + "AlreadyJoined")); - _playerNotOnLobbyMessage = createMessage(messages.getString(errorPath + "NotOnLobby")); - _playerWasNeverInGameMessage = createMessage(messages.getString(errorPath + "NeverInGame")); - - String usagePath = messagePath + "Usages."; - _usageMessage = createMessage(messages.getStringList(usagePath + "General")); - _startCommandUsage = createMessage(messages.getString(usagePath + "Start")); - _forceStartCommandUsage = createMessage(messages.getString(usagePath + "ForceStart")); - _forceStopCommandUsage = createMessage(messages.getString(usagePath + "ForceStop")); - _joinCommandUsage = createMessage(messages.getString(usagePath + "Join")); - _leaveCommandUsage = createMessage(messages.getString(usagePath + "Leave")); - _rejoinCommandUsage = createMessage(messages.getString(usagePath + "Rejoin")); - _stopCommandUsage = createMessage(messages.getString(usagePath + "Stop")); - } - - private String createMessage(String rawMessage) { - return rawMessage.replace("&", "§"); - } - - private List createMessage(List rawMessage) { - List message = new ArrayList<>(rawMessage); - - for (int i = 0; i < message.size(); i++) { - message.set(i, message.get(i).replace("&", "§")); - } - - return message; - } - - // ####################################### - // # Kit # - // ####################################### - - public String getSelectPrisionerTeamItemName() { - return _selectPrisionerTeamItemName; - } - - public String getSelectPoliceTeamItemName() { - return _selectPoliceTeamItemName; - } - - public String getSelectNoneTeamItemName() { - return _selectNoneTeamItemName; - } - - // ####################################### - // # Inventory # - // ####################################### - - public String getContainerName() { - return _containerName; - } - - // ######################################## - // # Warnings # - // ######################################## - - public String getSuccessfullyStartedGameMessage() { - return _successfullyStartedGameMessage; - } - - public String getSuccessfullyForceStartedGameMessage() { - return _successfullyForceStartedGameMessage; - } - - public String getSuccessfullyJoinedGameMessage() { - return _successfullyJoinedGameMessage; - } - - public String getSuccessfullyLeftGameMessage() { - return _successfullyLeftGameMessage; - } - - public String getSuccessfullyForceStoppedGameMessage() { - return _successfullyForceStoppedGameMessage; - } - - public String getSuccessfullyRejoinedGameMessage() { - return _successfullyRejoinedGameMessage; - } - - public String getSuccessfullyStoppedGameMessage() { - return _successfullyStoppedGameMessage; - } - - public String getSelectedPrisionersTeamMessage() { - return _selectedPrisionersTeamMessage; - } - - public String getSelectedPoliceTeamMessage() { - return _selectedPoliceTeamMessage; - } - - public String getRemovedTeamPreferenceMessage() { - return _removedTeamPreferenceMessage; - } - - public String getPrisionerGameStartedMessage() { - return _prisionerGameStartedMessage; - } - - public String getPoliceGameStartedMessage() { - return _policeGameStartedMessage; - } - - // ######################################## - // # Announcements # - // ######################################## + private static Hashtable instance = initializeLanguageMessages(); + + private static Hashtable initializeLanguageMessages() { + ConfigManager config = ConfigManager.getInstance(); + + Hashtable languagesMessages = new Hashtable<>(); + + List availableLanguages = config.getAvailableLanguages(); + String defaultLanguage = config.getDefaultLanguage(); + + if (availableLanguages.size() == 0) { + availableLanguages.add(defaultLanguage); + } + + for (String language : availableLanguages) { + languagesMessages.put(language, new MessageLanguageManager(language)); + } + + return languagesMessages; + } + + public static MessageLanguageManager getInstance(String language) { + if (language == null) { + language = ConfigManager.getInstance().getDefaultLanguage(); + } + + return instance.get(language); + } + + public static MessageLanguageManager getInstanceByPlayer(String playerName) { + String language = MessageLanguageManager.getPlayerLanguage(playerName); + if (language == null) { + language = ConfigManager.getInstance().getDefaultLanguage(); + } + + return MessageLanguageManager.getInstance(language); + } + + private static String getPlayerLanguage(String playerName) { + return ConfigManager.getInstance().getDefaultLanguage(); + } + + // ####################################### + // # Kit # + // ####################################### + + private String _selectPrisionerTeamItemName; + private String _selectPoliceTeamItemName; + private String _selectNoneTeamItemName; + + // ####################################### + // # Inventory # + // ####################################### + + private String _containerName; + + // ######################################## + // # Warnings # + // ######################################## + + private String _successfullyStartedGameMessage; + private String _successfullyForceStartedGameMessage; + private String _successfullyJoinedGameMessage; + private String _successfullyLeftGameMessage; + private String _successfullyForceStoppedGameMessage; + private String _successfullyRejoinedGameMessage; + private String _successfullyStoppedGameMessage; + private String _selectedPrisionersTeamMessage; + private String _selectedPoliceTeamMessage; + private String _removedTeamPreferenceMessage; + private String _prisionerGameStartedMessage; + private String _policeGameStartedMessage; + + // ######################################## + // # Announcements # + // ######################################## + + private List _gameStartingAnnouncementMessage; + private String _prisionerArrested; + private String _prisionerFreedOfSolitary; + private String _prisionersWonTitle; + private String _prisionersWonSubtitle; + private String _policeWonTitle; + private String _policeWonSubtitle; + private String _victoryWord; + private String _defeatWord; + private List _gameResultMessage; + private String _playerEscapedMessage; + private String _gameCancelledNotEnoughPlayers; + private String _newDayTitleMessage; + private String _newDaySubtitleMessage; + private String _nightTitleMessage; + private String _nightSubtitleMessage; + + // ######################################## + // # Errors # + // ######################################## + + private String _notAllowedMessage; + private String _onlyPlayersCanUseThisCommandMessage; + + private String _gameAlreadyStartedMessage; + private String _gameNotStartedYetMessage; + private String _gameAlreadyOngoingMessage; + private String _gameHasNotStartedUseJoinInsteadMessage; + private String _gameIsNotInFinishedPhaseMessage; + private String _lobbyIsFullMessage; + + private String _playerAlreadyJoinedMessage; + private String _playerNotOnLobbyMessage; + private String _playerWasNeverInGameMessage; + + // ######################################## + // # Usages # + // ######################################## + + private List _usageMessage; + private String _startCommandUsage; + private String _forceStartCommandUsage; + private String _joinCommandUsage; + private String _leaveCommandUsage; + private String _forceStopCommandUsage; + private String _rejoinCommandUsage; + private String _stopCommandUsage; + + private MessageLanguageManager(String language) { + YamlConfiguration messages = PrisonEscapeResources.getYamlLanguage(language); + + String kitPath = "Kits."; + String teamSelector = kitPath + "TeamSelector."; + _selectPrisionerTeamItemName = createMessage(messages.getString(teamSelector + "SelectPrisioners.Name")); + _selectPoliceTeamItemName = createMessage(messages.getString(teamSelector + "SelectPolice.Name")); + _selectNoneTeamItemName = createMessage(messages.getString(teamSelector + "SelectNone.Name"));; + + _containerName = createMessage(messages.getString("Inventory.Chest.Title")); + + String messagePath = "Messages."; + String warningPath = messagePath + "Warnings."; + _successfullyStartedGameMessage = createMessage(messages.getString(warningPath + "StartedGame")); + _successfullyForceStartedGameMessage = createMessage(messages.getString(warningPath + "ForceStartedGame")); + _successfullyJoinedGameMessage = createMessage(messages.getString(warningPath + "JoinedGame")); + _successfullyLeftGameMessage = createMessage(messages.getString(warningPath + "LeftGame")); + _successfullyForceStoppedGameMessage = createMessage(messages.getString(warningPath + "ForceStoppedGame")); + _successfullyRejoinedGameMessage = createMessage(messages.getString(warningPath + "RejoinedGame")); + _successfullyStoppedGameMessage = createMessage(messages.getString(warningPath + "StoppedGame")); + _selectedPrisionersTeamMessage = createMessage(messages.getString(warningPath + "SelectedPrisionersTeam")); + _selectedPoliceTeamMessage = createMessage(messages.getString(warningPath + "SelectedPoliceTeam")); + _removedTeamPreferenceMessage = createMessage(messages.getString(warningPath + "SelectedRandomTeam")); + _prisionerGameStartedMessage = createMessage(messages.getString(warningPath + "PrisionerGameStart")); + _policeGameStartedMessage = createMessage(messages.getString(warningPath + "PoliceGameStart")); + + String announcementPath = messagePath + "Announcements."; + _gameStartingAnnouncementMessage = createMessage(messages.getStringList(announcementPath + "GameStarting")); + _prisionerArrested = createMessage(messages.getString(announcementPath + "PrisionerArrested")); + _prisionerFreedOfSolitary = createMessage(messages.getString(announcementPath + "PrisionerFreedOfSolitary")); + _prisionersWonTitle = createMessage(messages.getString(announcementPath + "PrisionersWonTitle")); + _prisionersWonSubtitle = createMessage(messages.getString(announcementPath + "PrisionersWonSubtitle")); + _policeWonTitle = createMessage(messages.getString(announcementPath + "PoliceWonTitle")); + _policeWonSubtitle = createMessage(messages.getString(announcementPath + "PoliceWonSubtitle")); + _victoryWord = messages.getString(announcementPath + "VictoryWord"); + _defeatWord = messages.getString(announcementPath + "DefeatWord"); + _gameResultMessage = createMessage(messages.getStringList(announcementPath + "GameResult")); + _playerEscapedMessage = createMessage(messages.getString(announcementPath + "PlayerEscaped")); + _gameCancelledNotEnoughPlayers = createMessage(messages.getString(announcementPath + "GameCancelledFewPlayers")); + _newDayTitleMessage = createMessage(messages.getString(announcementPath + "NewDayTitle")); + _newDaySubtitleMessage = createMessage(messages.getString(announcementPath + "NewDaySubtitle")); + _nightTitleMessage = createMessage(messages.getString(announcementPath + "NightTitle")); + _nightSubtitleMessage = createMessage(messages.getString(announcementPath + "NightSubtitle")); + + String errorPath = messagePath + "Errors."; + _notAllowedMessage = createMessage(messages.getString(errorPath + "NotAllowed")); + _onlyPlayersCanUseThisCommandMessage = createMessage(messages.getString(errorPath + "CommandForPlayers")); + _gameAlreadyStartedMessage = createMessage(messages.getString(errorPath + "GameAlreadyStarted")); + _gameNotStartedYetMessage = createMessage(messages.getString(errorPath + "GameNotStartedYet")); + _gameAlreadyOngoingMessage = createMessage(messages.getString(errorPath + "GameAlreadyOngoing")); + _gameHasNotStartedUseJoinInsteadMessage = createMessage(messages.getString(errorPath + "GameIsStillWaiting")); + _gameIsNotInFinishedPhaseMessage = createMessage(messages.getString(errorPath + "GameIsNotFinished")); + _lobbyIsFullMessage = createMessage(messages.getString(errorPath + "LobbyIsFull")); + _playerAlreadyJoinedMessage = createMessage(messages.getString(errorPath + "AlreadyJoined")); + _playerNotOnLobbyMessage = createMessage(messages.getString(errorPath + "NotOnLobby")); + _playerWasNeverInGameMessage = createMessage(messages.getString(errorPath + "NeverInGame")); + + String usagePath = messagePath + "Usages."; + _usageMessage = createMessage(messages.getStringList(usagePath + "General")); + _startCommandUsage = createMessage(messages.getString(usagePath + "Start")); + _forceStartCommandUsage = createMessage(messages.getString(usagePath + "ForceStart")); + _forceStopCommandUsage = createMessage(messages.getString(usagePath + "ForceStop")); + _joinCommandUsage = createMessage(messages.getString(usagePath + "Join")); + _leaveCommandUsage = createMessage(messages.getString(usagePath + "Leave")); + _rejoinCommandUsage = createMessage(messages.getString(usagePath + "Rejoin")); + _stopCommandUsage = createMessage(messages.getString(usagePath + "Stop")); + } + + private String createMessage(String rawMessage) { + return rawMessage.replace("&", "§"); + } + + private List createMessage(List rawMessage) { + List message = new ArrayList<>(rawMessage); + + for (int i = 0; i < message.size(); i++) { + message.set(i, message.get(i).replace("&", "§")); + } + + return message; + } + + // ####################################### + // # Kit # + // ####################################### + + public String getSelectPrisionerTeamItemName() { + return _selectPrisionerTeamItemName; + } + + public String getSelectPoliceTeamItemName() { + return _selectPoliceTeamItemName; + } + + public String getSelectNoneTeamItemName() { + return _selectNoneTeamItemName; + } + + // ####################################### + // # Inventory # + // ####################################### + + public String getContainerName() { + return _containerName; + } + + // ######################################## + // # Warnings # + // ######################################## + + public String getSuccessfullyStartedGameMessage() { + return _successfullyStartedGameMessage; + } + + public String getSuccessfullyForceStartedGameMessage() { + return _successfullyForceStartedGameMessage; + } + + public String getSuccessfullyJoinedGameMessage() { + return _successfullyJoinedGameMessage; + } + + public String getSuccessfullyLeftGameMessage() { + return _successfullyLeftGameMessage; + } + + public String getSuccessfullyForceStoppedGameMessage() { + return _successfullyForceStoppedGameMessage; + } + + public String getSuccessfullyRejoinedGameMessage() { + return _successfullyRejoinedGameMessage; + } + + public String getSuccessfullyStoppedGameMessage() { + return _successfullyStoppedGameMessage; + } + + public String getSelectedPrisionersTeamMessage() { + return _selectedPrisionersTeamMessage; + } + + public String getSelectedPoliceTeamMessage() { + return _selectedPoliceTeamMessage; + } + + public String getRemovedTeamPreferenceMessage() { + return _removedTeamPreferenceMessage; + } + + public String getPrisionerGameStartedMessage() { + return _prisionerGameStartedMessage; + } + + public String getPoliceGameStartedMessage() { + return _policeGameStartedMessage; + } + + // ######################################## + // # Announcements # + // ######################################## - public List getGameStartingAnnouncementMessage(int remainingTime, int playersOnLobby) { - List message = new ArrayList<>(_gameStartingAnnouncementMessage); + public List getGameStartingAnnouncementMessage(int remainingTime, int playersOnLobby) { + List message = new ArrayList<>(_gameStartingAnnouncementMessage); - for (int i = 0; i < message.size(); i++) { - message.set(i, message.get(i) - .replace("{SECONDS}", Integer.toString(remainingTime)) - .replace("{PLAYERS}", Integer.toString(playersOnLobby))); - } + for (int i = 0; i < message.size(); i++) { + message.set(i, message.get(i) + .replace("{SECONDS}", Integer.toString(remainingTime)) + .replace("{PLAYERS}", Integer.toString(playersOnLobby))); + } - return message; - } + return message; + } - public String getPrisionerArrested(String playerName) { - return _prisionerArrested.replace("{PLAYER}", playerName); - } + public String getPrisionerArrested(String playerName) { + return _prisionerArrested.replace("{PLAYER}", playerName); + } - public String getPrisionerFreedOfSolitary() { - return _prisionerFreedOfSolitary; - } + public String getPrisionerFreedOfSolitary() { + return _prisionerFreedOfSolitary; + } - public String getPrisionersWonTitle() { - return _prisionersWonTitle; - } + public String getPrisionersWonTitle() { + return _prisionersWonTitle; + } - public String getPrisionersWonSubtitle() { - return _prisionersWonSubtitle; - } + public String getPrisionersWonSubtitle() { + return _prisionersWonSubtitle; + } - public String getPoliceWonTitle() { - return _policeWonTitle; - } + public String getPoliceWonTitle() { + return _policeWonTitle; + } - public String getPoliceWonSubtitle(int playersInPrison) { - return _policeWonSubtitle; - } + public String getPoliceWonSubtitle(int playersInPrison) { + return _policeWonSubtitle; + } - public List getGameResultMessage(boolean isWinner) { - String result = isWinner ? _victoryWord : _defeatWord; + public List getGameResultMessage(boolean isWinner) { + String result = isWinner ? _victoryWord : _defeatWord; - List message = new ArrayList<>(_gameResultMessage); - for (int i = 0; i < message.size(); i++) { - message.set(i, message.get(i).replace("{RESULT}", result)); - } + List message = new ArrayList<>(_gameResultMessage); + for (int i = 0; i < message.size(); i++) { + message.set(i, message.get(i).replace("{RESULT}", result)); + } - return message; - } + return message; + } - public String getPlayerEscapedMessage(String playerName) { - return _playerEscapedMessage.replace("{PLAYER}", playerName); - } + public String getPlayerEscapedMessage(String playerName) { + return _playerEscapedMessage.replace("{PLAYER}", playerName); + } - public String getGameCancelledFewPlayersMessage() { - return _gameCancelledNotEnoughPlayers; - } + public String getGameCancelledFewPlayersMessage() { + return _gameCancelledNotEnoughPlayers; + } - public String getNewDayTitleMessage(int day) { - return _newDayTitleMessage.replace("{DAYNUMBER}", String.valueOf(day)); - } + public String getNewDayTitleMessage(int day) { + return _newDayTitleMessage.replace("{DAYNUMBER}", String.valueOf(day)); + } - public String getNewDaySubtitleMessage() { - return _newDaySubtitleMessage; - } + public String getNewDaySubtitleMessage() { + return _newDaySubtitleMessage; + } - public String getNightTitleMessage() { - return _nightTitleMessage; - } + public String getNightTitleMessage() { + return _nightTitleMessage; + } - public String getNightSubtitleMessage() { - return _nightSubtitleMessage; - } + public String getNightSubtitleMessage() { + return _nightSubtitleMessage; + } - // ######################################## - // # Errors # - // ######################################## + // ######################################## + // # Errors # + // ######################################## - public String getNotAllowedMessage() { - return _notAllowedMessage; - } + public String getNotAllowedMessage() { + return _notAllowedMessage; + } - public String getOnlyPlayersCanUseThisCommandMessage() { - return _onlyPlayersCanUseThisCommandMessage; - } + public String getOnlyPlayersCanUseThisCommandMessage() { + return _onlyPlayersCanUseThisCommandMessage; + } - public String getGameAlreadyStartedMessage() { - return _gameAlreadyStartedMessage; - } + public String getGameAlreadyStartedMessage() { + return _gameAlreadyStartedMessage; + } - public String getGameNotStartedYetMessage() { - return _gameNotStartedYetMessage; - } + public String getGameNotStartedYetMessage() { + return _gameNotStartedYetMessage; + } - public String getGameAlreadyOngoingMessage() { - return _gameAlreadyOngoingMessage; - } + public String getGameAlreadyOngoingMessage() { + return _gameAlreadyOngoingMessage; + } - public String getGameHasNotStartedUseJoinInsteadMessage() { - return _gameHasNotStartedUseJoinInsteadMessage; - } + public String getGameHasNotStartedUseJoinInsteadMessage() { + return _gameHasNotStartedUseJoinInsteadMessage; + } - public String getGameHasNotFinishedMessage() { - return _gameIsNotInFinishedPhaseMessage; - } + public String getGameHasNotFinishedMessage() { + return _gameIsNotInFinishedPhaseMessage; + } - public String getLobbyIsFullMessage() { - return _lobbyIsFullMessage; - } + public String getLobbyIsFullMessage() { + return _lobbyIsFullMessage; + } - public String getPlayerAlreadyJoinedMessage() { - return _playerAlreadyJoinedMessage; - } + public String getPlayerAlreadyJoinedMessage() { + return _playerAlreadyJoinedMessage; + } - public String getPlayerNotOnLobbyMessage() { - return _playerNotOnLobbyMessage; - } + public String getPlayerNotOnLobbyMessage() { + return _playerNotOnLobbyMessage; + } - public String getPlayerWasNeverInGameMessage() { - return _playerWasNeverInGameMessage; - } + public String getPlayerWasNeverInGameMessage() { + return _playerWasNeverInGameMessage; + } - // ######################################## - // # Usages # - // ######################################## + // ######################################## + // # Usages # + // ######################################## - public List getUsage() { - return _usageMessage; - } + public List getUsage() { + return _usageMessage; + } - public String getStartCommandUsage() { - return _startCommandUsage; - } + public String getStartCommandUsage() { + return _startCommandUsage; + } - public String getForceStartCommandUsage() { - return _forceStartCommandUsage; - } + public String getForceStartCommandUsage() { + return _forceStartCommandUsage; + } - public String getJoinCommandUsage() { - return _joinCommandUsage; - } + public String getJoinCommandUsage() { + return _joinCommandUsage; + } - public String getLeaveCommandUsage() { - return _leaveCommandUsage; - } + public String getLeaveCommandUsage() { + return _leaveCommandUsage; + } - public String getForceStopCommandUsage() { - return _forceStopCommandUsage; - } + public String getForceStopCommandUsage() { + return _forceStopCommandUsage; + } - public String getRejoinCommandUsage() { - return _rejoinCommandUsage; - } + public String getRejoinCommandUsage() { + return _rejoinCommandUsage; + } - public String getStopCommandUsage() { - return _stopCommandUsage; - } + public String getStopCommandUsage() { + return _stopCommandUsage; + } } From bd9ea81e0483540cc9b2c22cf17f1cf5038053ce Mon Sep 17 00:00:00 2001 From: iquelli Date: Wed, 27 Mar 2024 22:13:22 +0000 Subject: [PATCH 5/5] Refactor code --- .../bukkit/BukkitMessageSender.java | 5 +- .../managers/MessageLanguageManager.java | 72 +++++++++---------- 2 files changed, 39 insertions(+), 38 deletions(-) diff --git a/src/main/java/net/tiagofar78/prisonescape/bukkit/BukkitMessageSender.java b/src/main/java/net/tiagofar78/prisonescape/bukkit/BukkitMessageSender.java index 989a9d7d..e6a1745a 100644 --- a/src/main/java/net/tiagofar78/prisonescape/bukkit/BukkitMessageSender.java +++ b/src/main/java/net/tiagofar78/prisonescape/bukkit/BukkitMessageSender.java @@ -9,8 +9,9 @@ public class BukkitMessageSender { - private static final int FADE = 20; - private static final int STAY = 70; + private static final int TICKS_PER_SECOND = 20; + private static final int FADE = (int) (1 * TICKS_PER_SECOND); + private static final int STAY = (int) (3.5 * TICKS_PER_SECOND); public static List getOnlinePlayersNames() { return Bukkit.getOnlinePlayers().stream().map(p -> p.getName()).toList(); diff --git a/src/main/java/net/tiagofar78/prisonescape/managers/MessageLanguageManager.java b/src/main/java/net/tiagofar78/prisonescape/managers/MessageLanguageManager.java index 3e6ee4ba..bc66042b 100644 --- a/src/main/java/net/tiagofar78/prisonescape/managers/MessageLanguageManager.java +++ b/src/main/java/net/tiagofar78/prisonescape/managers/MessageLanguageManager.java @@ -52,23 +52,23 @@ private static String getPlayerLanguage(String playerName) { return ConfigManager.getInstance().getDefaultLanguage(); } - // ####################################### - // # Kit # - // ####################################### +// ####################################### +// # Kit # +// ####################################### private String _selectPrisionerTeamItemName; private String _selectPoliceTeamItemName; private String _selectNoneTeamItemName; - // ####################################### - // # Inventory # - // ####################################### +// ####################################### +// # Inventory # +// ####################################### private String _containerName; - // ######################################## - // # Warnings # - // ######################################## +// ######################################## +// # Warnings # +// ######################################## private String _successfullyStartedGameMessage; private String _successfullyForceStartedGameMessage; @@ -83,9 +83,9 @@ private static String getPlayerLanguage(String playerName) { private String _prisionerGameStartedMessage; private String _policeGameStartedMessage; - // ######################################## - // # Announcements # - // ######################################## +// ######################################## +// # Announcements # +// ######################################## private List _gameStartingAnnouncementMessage; private String _prisionerArrested; @@ -104,9 +104,9 @@ private static String getPlayerLanguage(String playerName) { private String _nightTitleMessage; private String _nightSubtitleMessage; - // ######################################## - // # Errors # - // ######################################## +// ######################################## +// # Errors # +// ######################################## private String _notAllowedMessage; private String _onlyPlayersCanUseThisCommandMessage; @@ -122,9 +122,9 @@ private static String getPlayerLanguage(String playerName) { private String _playerNotOnLobbyMessage; private String _playerWasNeverInGameMessage; - // ######################################## - // # Usages # - // ######################################## +// ######################################## +// # Usages # +// ######################################## private List _usageMessage; private String _startCommandUsage; @@ -217,9 +217,9 @@ private List createMessage(List rawMessage) { return message; } - // ####################################### - // # Kit # - // ####################################### +// ####################################### +// # Kit # +// ####################################### public String getSelectPrisionerTeamItemName() { return _selectPrisionerTeamItemName; @@ -233,17 +233,17 @@ public String getSelectNoneTeamItemName() { return _selectNoneTeamItemName; } - // ####################################### - // # Inventory # - // ####################################### +// ####################################### +// # Inventory # +// ####################################### public String getContainerName() { return _containerName; } - // ######################################## - // # Warnings # - // ######################################## +// ######################################## +// # Warnings # +// ######################################## public String getSuccessfullyStartedGameMessage() { return _successfullyStartedGameMessage; @@ -293,9 +293,9 @@ public String getPoliceGameStartedMessage() { return _policeGameStartedMessage; } - // ######################################## - // # Announcements # - // ######################################## +// ######################################## +// # Announcements # +// ######################################## public List getGameStartingAnnouncementMessage(int remainingTime, int playersOnLobby) { List message = new ArrayList<>(_gameStartingAnnouncementMessage); @@ -368,9 +368,9 @@ public String getNightSubtitleMessage() { return _nightSubtitleMessage; } - // ######################################## - // # Errors # - // ######################################## +// ######################################## +// # Errors # +// ######################################## public String getNotAllowedMessage() { return _notAllowedMessage; @@ -416,9 +416,9 @@ public String getPlayerWasNeverInGameMessage() { return _playerWasNeverInGameMessage; } - // ######################################## - // # Usages # - // ######################################## +// ######################################## +// # Usages # +// ######################################## public List getUsage() { return _usageMessage;