Skip to content

Commit

Permalink
Release
Browse files Browse the repository at this point in the history
  • Loading branch information
LordBombardir committed Aug 22, 2024
1 parent b208da2 commit 2e166ff
Show file tree
Hide file tree
Showing 26 changed files with 984 additions and 107 deletions.
55 changes: 43 additions & 12 deletions assets/data/languages/en_US.json
Original file line number Diff line number Diff line change
@@ -1,18 +1,49 @@
{
"languageName": "English (United Kingdom)",
"undefinedError": "§r(Ranks) Sorry, an unknown error has occurred..",
"undefinedRank": "§r(Ranks) Unknown rank {rankName}! Available ranks: {ranks}.",
"dropdownDontPoint": "Don't point",
"commandAddRankDescription": "Create a new rank.",
"commandSetRankDescription": "Set a new rank for the player.",
"commandSetRankDescription": "Set a new rank for a player.",
"commandRemoveRankDescription": "Remove rank.",
"commandEditRankDescription": "Change rank.",
"commandEditRankDescription": "Edit rank.",
"commandAddRankUsing": "§r(Ranks) Usage: /addrank <rankName: string> <prefix: string> <chatFormat: string> <scoreTagFormat: string> [inheritanceRank: string]",
"addRankAlreadyExists": "§r(Ranks) A rank with this name already exists!",
"addRankSuccess": "§r(Ranks) You have successfully created a rank called {rankName}!",
"commandSetRankUsing": "§r(Ranks) Usage: /setrank <player: target> <rankName: string>",
"commandSetRankUndefinedPlayer": "§r(Ranks) Failed to get a player!",
"commandSetRankUndefinedRank": "§r(Ranks) Unknown rank {rankName}! Available ranks: {ranks}.",
"commandSetRankSuperRank": "§r(Ranks) This rank can only be set from the console!",
"commandSetRankSuperPlayer": "§r(Ranks) Player {playerName} can only be set from the console!",
"commandSetRankUndefinedError": "§r(Ranks) Unfortunately, an unknown error has occurred..",
"commandSetRankSuccess": "§r(Ranks) You have successfully set the {playerName} player's {rankName} rank!",
"commandSetRankSuccessMultiply": "§r(Ranks) You have successfully set the players {playerNames} rank {rankName}!",
"formSetRankTitle": "Setting a new rank for the player",
"formSetRankDropdownPlayers": "Select the player from the list to whom you want to set a new rank:",
"formSetRankDropdownRanks": "Select the rank from the list that you want to set for the player:"
"commandSetRankUndefinedPlayer": "§r(Ranks) Failed to get player!",
"setRankSuperRank": "§r(Ranks) This rank can only be set from console!",
"setRankSuperPlayer": "§r(Ranks) Player {playerName} can only be set to rank from console!",
"setRankSuccess": "§r(Ranks) You have successfully set player {playerName} to rank {rankName}!",
"commandSetRankSuccessMultiply": "§r(Ranks) You have successfully set the rank of {playerNames} to {rankName}!",
"commandRemoveRankUsing": "§r(Ranks) Usage: /removerank <rankName: string>",
"commandRemoveRankSuccess": "§r(Ranks) You have successfully removed the rank of {rankName}.",
"commandEditRankUsing": "§r(Ranks) Usage: /editrank <rankName: string> <prefix: string> <chatFormat: string> <scoreTagFormat: string> <inheritanceRank: string> <availableCommands: string>",
"editRankSuperRank": "§r(Ranks) This rank can only be edited from the console!",
"editRankInvalidFormatAvailableCommands": "§r(Ranks) Please enter available commands this rank separated by a semicolon («;», without quotes).",
"editRankSuccess": "§r(Ranks) You have successfully edited the rank {rankName}.",
"formAddRankTitle": "Creating a new rank",
"formAddRankInputRankName": "Enter the name of the future rank:",
"formAddRankInputRankNamePlaceholder": "Name of the future rank",
"formAddRankInputPrefix": "Enter the prefix of the future rank:",
"formAddRankInputPrefixPlaceholder": "Prefix of the future rank",
"formAddRankInputChatFormat": "Enter the format for displaying messages of the player who will have this rank (the following variables are supported: {prefix} - rank prefix, {playerName} - player name, {message} - message sent by the player):",
"formAddRankInputChatFormatPlaceholder": "Player message display format",
"formAddRankInputScoreTagFormat": "Enter the player's scoreTag format (the {prefix} variable is supported - rank prefix):",
"formAddRankInputScoreTagFormatPlaceholder": "Player scoreTag format",
"formAddRankDropdownRanks": "Select a rank from the list from which the future rank will be inherited:",
"formSetRankTitle": "Setting a new rank for a player",
"formSetRankDropdownPlayers": "Select a player from the list to whom you want to set a new rank:",
"formSetRankDropdownRanks": "Select a rank from the list that you want to set for the player:",
"formEditRankTitle": "Editing a rank",
"formEditRankDropdownRanks": "Select a rank from the list that you want to edit:",
"formEditRankInputPrefix": "Enter the new prefix of the selected rank:",
"formEditRankInputPrefixPlaceholder": "New rank prefix",
"formEditRankInputChatFormat": "Enter the new format for displaying player messages that will have the selected rank (supported variables {prefix} - rank prefix, {playerName} - player name, {message} - message sent by the player):",
"formEditRankInputChatFormatPlaceholder": "New format for displaying player messages",
"formEditRankInputScoreTagFormat": "Enter the new format for the player's scoreTag (supported variable {prefix} - rank prefix):",
"formEditRankInputScoreTagFormatPlaceholder": "New format for the player's scoreTag",
"formEditRankDropdownInheritanceRanks": "Select a rank from the list, from which the selected rank will inherit:",
"formEditRankInputAvailableCommands": "Enter new commands for the selected rank separated by semicolons («;», without quotes; enter the value «null» (without quotes) if you want to remove commands specifically available to this rank):",
"formEditRankInputAvailableCommandsPlaceholder": "New rank commands"
}
45 changes: 38 additions & 7 deletions assets/data/languages/ru_RU.json
Original file line number Diff line number Diff line change
@@ -1,18 +1,49 @@
{
"languageName": "Русский (Россия)",
"undefinedError": "§r(Ранги) К сожалению, произошла неизвестная ошибка..",
"undefinedRank": "§r(Ранги) Неизвестный ранг {rankName}! Доступные ранги: {ranks}.",
"dropdownDontPoint": "Не указывать",
"commandAddRankDescription": "Создать новый ранг.",
"commandSetRankDescription": "Установить игроку новый ранг.",
"commandRemoveRankDescription": "Удалить ранг.",
"commandEditRankDescription": "Изменить ранг.",
"commandEditRankDescription": "Отредактировать ранг.",
"commandAddRankUsing": "§r(Ранги) Использование: /addrank <rankName: string> <prefix: string> <chatFormat: string> <scoreTagFormat: string> [inheritanceRank: string]",
"addRankAlreadyExists": "§r(Ранги) Ранг с таким названием уже существует!",
"addRankSuccess": "§r(Ранги) Вы успешно создали ранг под названием {rankName}!",
"commandSetRankUsing": "§r(Ранги) Использование: /setrank <player: target> <rankName: string>",
"commandSetRankUndefinedPlayer": "§r(Ранги) Не удалось получить игрока!",
"commandSetRankUndefinedRank": "§r(Ранги) Неизвестный ранг {rankName}! Доступные ранги: {ranks}.",
"commandSetRankSuperRank": "§r(Ранги) Данный ранг можно устанавливать только с консоли!",
"commandSetRankSuperPlayer": "§r(Ранги) Игроку {playerName} можно устанавливать ранг только с консоли!",
"commandSetRankUndefinedError": "§r(Ранги) К сожалению, произошла неизвестная ошибка..",
"commandSetRankSuccess": "§r(Ранги) Вы успешно установили игроку {playerName} ранг {rankName}!",
"setRankSuperRank": "§r(Ранги) Данный ранг можно устанавливать только с консоли!",
"setRankSuperPlayer": "§r(Ранги) Игроку {playerName} можно устанавливать ранг только с консоли!",
"setRankSuccess": "§r(Ранги) Вы успешно установили игроку {playerName} ранг {rankName}!",
"commandSetRankSuccessMultiply": "§r(Ранги) Вы успешно установили игрокам {playerNames} ранг {rankName}!",
"commandRemoveRankUsing": "§r(Ранги) Использование: /removerank <rankName: string>",
"commandRemoveRankSuccess": "§r(Ранги) Вы успешно удалили ранг {rankName}.",
"commandEditRankUsing": "§r(Ранги) Использование: /editrank <rankName: string> <prefix: string> <chatFormat: string> <scoreTagFormat: string> <inheritanceRank: string> <availableCommands: string>",
"editRankSuperRank": "§r(Ранги) Данный ранг можно редактировать только с консоли!",
"editRankInvalidFormatAvailableCommands": "§r(Ранги) Пожалуйста, вводите доступные команды этому рангу через точку с запятой («;», без кавычек).",
"editRankSuccess": "§r(Ранги) Вы успешно отредактировали ранг {rankName}.",
"formAddRankTitle": "Создание нового ранга",
"formAddRankInputRankName": "Введите название будущего ранга:",
"formAddRankInputRankNamePlaceholder": "Название будущего ранга",
"formAddRankInputPrefix": "Введите префикс будущего ранга:",
"formAddRankInputPrefixPlaceholder": "Префикс будущего ранга",
"formAddRankInputChatFormat": "Введите формат отображения сообщений игрока, который будет иметь этот ранг (поддерживаются переменные {prefix} - префикс ранга, {playerName} - имя игрока, {message} - сообщение, отправленное игроком):",
"formAddRankInputChatFormatPlaceholder": "Формат отображения сообщений игрока",
"formAddRankInputScoreTagFormat": "Введите формат scoreTag'а игрока (поддерживается переменная {prefix} - префикс ранга):",
"formAddRankInputScoreTagFormatPlaceholder": "Формат scoreTag'а игрока",
"formAddRankDropdownRanks": "Выберите ранг из списка, от которого будет наследоваться будущий ранг:",
"formSetRankTitle": "Установка игроку нового ранга",
"formSetRankDropdownPlayers": "Выберите игрока из списка, которому хотите установить новый ранг:",
"formSetRankDropdownRanks": "Выберите ранг из списка, который хотите установить игроку:"
"formSetRankDropdownRanks": "Выберите ранг из списка, который хотите установить игроку:",
"formEditRankTitle": "Редактирование ранга",
"formEditRankDropdownRanks": "Выберите ранг из списка, который хотите редактировать:",
"formEditRankInputPrefix": "Введите новый префикс выбранного ранга:",
"formEditRankInputPrefixPlaceholder": "Новый префикс ранга",
"formEditRankInputChatFormat": "Введите новый формат отображения сообщений игрока, который будет иметь выбранный ранг (поддерживаются переменные {prefix} - префикс ранга, {playerName} - имя игрока, {message} - сообщение, отправленное игроком):",
"formEditRankInputChatFormatPlaceholder": "Новый формат отображения сообщений игрока",
"formEditRankInputScoreTagFormat": "Введите новый формат scoreTag'а игрока (поддерживается переменная {prefix} - префикс ранга):",
"formEditRankInputScoreTagFormatPlaceholder": "Новый формат scoreTag'а игрока",
"formEditRankDropdownInheritanceRanks": "Выберите ранг из списка, от которого будет наследоваться выбранный ранг:",
"formEditRankInputAvailableCommands": "Введите новые команды для выбранного ранга через точку с запятой («;», без кавычек; введите значение «null» (без кавычек), если хотите убрать команды, специально доступные этому рангу):",
"formEditRankInputAvailableCommandsPlaceholder": "Новые команды ранга"
}
1 change: 0 additions & 1 deletion src/mod/Api.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
#include <stdexcept>
#include <utility>


std::unordered_map<std::string, const power_ranks::object::Rank*> getRanks() {
std::unordered_map<std::string, power_ranks::object::Rank*> originalMap =
power_ranks::manager::RanksManager::getRanks();
Expand Down
3 changes: 2 additions & 1 deletion src/mod/Main.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include "Main.h"
#include "hooks/Hooks.h"
#include "manager/MainManager.h"
#include "manager/command/CommandManager.h"
#include "manager/lang/LanguageManager.h"
#include <ll/api/mod/RegisterHelper.h>
#include <memory>
Expand Down Expand Up @@ -28,7 +29,7 @@ bool Main::load() {
bool Main::enable() {
getSelf().getLogger().info("The mod is enabling...");

if (!manager::MainManager::registerCommands()) {
if (!manager::CommandManager::registerCommands()) {
getSelf().getLogger().info("Failed to enable the mod!");
return false;
}
Expand Down
44 changes: 44 additions & 0 deletions src/mod/Utils.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,50 @@ class Utils final {
auto iterator = std::find(vector.begin(), vector.end(), value);
return iterator != vector.end();
}

static std::vector<std::string> strSplit(const std::string& str, const std::string& separator) {
if (separator == "") {
return {};
}

std::vector<std::string> strings;
size_t start = 0;
size_t end = 0;

while ((end = str.find(separator, start)) != std::string::npos) {
strings.push_back(trim_copy(str.substr(start, end - start)));
start = end + separator.length();
}

strings.push_back(trim_copy(str.substr(start)));
return strings;
}

private:
// Оригинал кода, написанного ниже: https://stackoverflow.com/questions/216823/how-to-trim-a-stdstring

static inline void ltrim(std::string& str) {
str.erase(str.begin(), std::find_if(str.begin(), str.end(), [](unsigned char ch) {
return !std::isspace(ch);
}));
}

static inline void rtrim(std::string& str) {
str.erase(
std::find_if(str.rbegin(), str.rend(), [](unsigned char ch) { return !std::isspace(ch); }).base(),
str.end()
);
}

static inline void trim(std::string& str) {
rtrim(str);
ltrim(str);
}

static inline std::string trim_copy(std::string str) {
trim(str);
return str;
}
};

} // namespace power_ranks
67 changes: 67 additions & 0 deletions src/mod/commands/AddRankCommand.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
#include "AddRankCommand.h"
#include "../Utils.hpp"
#include "../forms/AddRankForm.h"
#include "../manager/ranks/RanksManager.h"
#include <mc/server/ServerPlayer.h>

namespace power_ranks::commands {

void AddRankCommand::execute(
const CommandOrigin& origin,
CommandOutput& output,
const Parameter& parameter,
const Command& _
) {
std::string localeName = origin.getEntity() == nullptr || !origin.getEntity()->isType(ActorType::Player)
? manager::ConfigManager::getConfig().defaultLocaleName
: static_cast<ServerPlayer&>(*origin.getEntity()).getLocaleName();

if (manager::RanksManager::getRank(parameter.rankName).has_value()) {
output.error(manager::LanguageManager::getInstance()->getTranslate("addRankAlreadyExists", localeName));
return;
}

std::optional<object::Rank*> inheritanceRank = manager::RanksManager::getRank(parameter.inheritanceRank);
if (parameter.inheritanceRank != "null" && !inheritanceRank.has_value()) {
std::string ranks = "";
for (std::pair<std::string, object::Rank*> pair : manager::RanksManager::getRanks()) {
if (ranks.empty()) {
ranks = pair.first;
continue;
}

ranks += ", " + pair.first;
}

output.error(Utils::strReplace(
manager::LanguageManager::getInstance()->getTranslate("undefinedRank", localeName),
{"{rankName}", "{ranks}"},
{parameter.rankName, ranks}
));
return;
}

manager::RanksManager::addRank(
parameter.rankName,
parameter.prefix,
parameter.chatFormat,
parameter.scoreTagFormat,
inheritanceRank
);
output.success(Utils::strReplace(
manager::LanguageManager::getInstance()->getTranslate("addRankSuccess", localeName),
"{rankName}",
parameter.rankName
));
}

void AddRankCommand::executeWithoutParameter(const CommandOrigin& origin, CommandOutput& output) {
if (origin.getEntity() == nullptr || !origin.getEntity()->isType(ActorType::Player)) {
output.error(manager::LanguageManager::getInstance()->getTranslate("commandAddRankUsing"));
return;
}

forms::AddRankForm::init(static_cast<ServerPlayer&>(*origin.getEntity()));
}

} // namespace power_ranks::commands
39 changes: 39 additions & 0 deletions src/mod/commands/AddRankCommand.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
#pragma once

#include "../manager/command/CommandManager.h"
#include "../manager/lang/LanguageManager.h"
#include <fmt/std.h>
#include <ll/api/command/SoftEnum.h>
#include <mc/server/commands/CommandFlag.h>
#include <mc/server/commands/CommandOrigin.h>
#include <mc/server/commands/CommandOutput.h>
#include <mc/server/commands/CommandPermissionLevel.h>
#include <mc/world/level/Command.h>

namespace power_ranks::commands {

class AddRankCommand {
public:
struct Parameter {
std::string rankName;
std::string prefix;
std::string chatFormat;
std::string scoreTagFormat;
ll::command::SoftEnum<manager::CommandManager::RankNames> inheritanceRank = "null";
};

static std::string getName() { return "addrank"; };
static std::string getDescription() {
return manager::LanguageManager::getInstance()->getTranslate("commandAddRankDescription");
};
static CommandPermissionLevel getRequirement() { return CommandPermissionLevel::GameDirectors; };
static CommandFlag getFlag() { return CommandFlagValue::NotCheat; };

static std::vector<std::string> getAliases() { return {"add-rank"}; };

static void
execute(const CommandOrigin& origin, CommandOutput& output, const Parameter& parameter, const Command& command);
static void executeWithoutParameter(const CommandOrigin& origin, CommandOutput& output);
};

} // namespace power_ranks::commands
Loading

0 comments on commit 2e166ff

Please sign in to comment.