Skip to content

Commit

Permalink
Update Localization
Browse files Browse the repository at this point in the history
  • Loading branch information
wuliao697 committed Dec 14, 2024
1 parent 18f6358 commit bb1b342
Show file tree
Hide file tree
Showing 14 changed files with 270 additions and 178 deletions.
13 changes: 9 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ Economy plugin for EndStone.Theoretically supports multiple platforms (not teste
Welcome to the submission of issues!
Unless the endstone program is retired from history, I'll keep it updated!

I used some radical settings regarding file reading, but will refine them later.

## Command Introduction
```
- View your own money
Expand Down Expand Up @@ -48,8 +50,9 @@ economy.command.show.others
Note:I am waiting for a plugin like luckperms before you can configure these permissions. Otherwise, you can only change it from inside the plugin

## Interface Related
Waiting for endstone to update the interface...
```C++
extern "C" __declspec(dllexport) int getPlayerMoney(std::string& uuid){
extern "C" __declspec(dllexport) int getPlayerMoney(const char* uuid){
jsonHelper jsonHelper;
try {
return jsonHelper.getPlayerMoney(uuid);
Expand All @@ -58,7 +61,7 @@ extern "C" __declspec(dllexport) int getPlayerMoney(std::string& uuid){
}
}

extern "C" __declspec(dllexport) bool addPlayerMoney(std::string& uuid,int& money){
extern "C" __declspec(dllexport) bool addPlayerMoney(const char* uuid,int& money){
jsonHelper jsonHelper;
try {
jsonHelper.addPlayerMoney(uuid, money);
Expand All @@ -68,7 +71,7 @@ extern "C" __declspec(dllexport) bool addPlayerMoney(std::string& uuid,int& mone
}
}

extern "C" __declspec(dllexport) bool setPlayerMoney(const std::string& uuid,const int& money){
extern "C" __declspec(dllexport) bool setPlayerMoney(const char* uuid,const int& money){
jsonHelper jsonHelper;
try {
jsonHelper.setPlayerMoney(uuid, money);
Expand All @@ -81,7 +84,9 @@ extern "C" __declspec(dllexport) bool setPlayerMoney(const std::string& uuid,con
## TODO(Chinese)
- 实现配置文件里的功能
- 支持i18n
- 控制台操作命令
- 内存操作(很快)
- 试图再封装一次提供给py的接口并兼容部分py插件
- 使用持久层框架支持关系型数据库(看情况)
- 实现实体货币/支持多种货币共存(看情况)
Expand Down
147 changes: 74 additions & 73 deletions include/command/economyCommand.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include "endstone/color_format.h"

#include "util/data/poco/jsonHelper.h"
#include "util/files/filesInitialize.h"

/*
* sender.hasPermission待做
Expand All @@ -26,98 +27,98 @@ class economyCommand : public endstone::CommandExecutor{
for (const std::string& str:args) {
std::cout << str<<std::endl;
}*/
if(command.getName() != "economy"){
return false;
}

if (command.getName() == "economy") {
std::string uuid;
std::string targetUuid;
int amount;

endstone::Server& server= sender.getServer();
std::string uuid;
std::string targetUuid;
int amount;
endstone::Server& server= sender.getServer();

if (args.size()>=2){
if(!isOnlinePlayer(server,args[1])){
sender.sendMessage(endstone::ColorFormat::Red + "目标玩家账户并未找到"+ endstone::ColorFormat::Reset);
if (args.size()>=2){
if(!isOnlinePlayer(server,args[1])){
sender.sendMessage(endstone::ColorFormat::Red + lang["target-not-found"].GetString()+ endstone::ColorFormat::Reset);
return false;
}
targetUuid = server.getPlayer(args[1])->getUniqueId().str();
}
/*
* 匹配第一级参数
*/
uuid = server.getPlayer(sender.getName())->getUniqueId().str();
if (args[0] == "top") {
sender.sendMessage("todo功能老弟");
return true;
}
if (args[0] == "show") {
std::string money;
if (sender.isOp() && !targetUuid.empty()) {
if (!legalityCheck(targetUuid,sender)){
return false;
}
money = std::to_string(jsonHelper.getPlayerMoney(targetUuid));
sender.sendMessage(endstone::ColorFormat::Gold + "该玩家当前余额: " + money + endstone::ColorFormat::Reset);
return true;
}
/*
* 匹配第一级参数
*/
uuid = server.getPlayer(sender.getName())->getUniqueId().str();
if (args[0] == "top") {
sender.sendMessage("todo功能老弟");
return true;
}
if (args[0] == "show") {
std::string money;
if (sender.isOp() && !targetUuid.empty()) {
if (!legalityCheck(targetUuid,sender)){
return false;
}
money = std::to_string(jsonHelper.getPlayerMoney(uuid));
sender.sendMessage(endstone::ColorFormat::Gold + "您当前的余额为: " + money + endstone::ColorFormat::Reset);
money = std::to_string(jsonHelper.getPlayerMoney(targetUuid));
sender.sendMessage(endstone::ColorFormat::Gold + lang["player-balance"].GetString() + money + endstone::ColorFormat::Reset);
return true;
}
/*
* 匹配第一级参数
*/
if( args.size() == 3){
amount = stoi(args[2]);
money = std::to_string(jsonHelper.getPlayerMoney(uuid));
sender.sendMessage(endstone::ColorFormat::Gold + lang["player-balance"].GetString() + money + endstone::ColorFormat::Reset);
return true;
}
/*
* 匹配第一级参数
*/
if( args.size() == 3){
amount = stoi(args[2]);
}
if (args[0] == "pay") {
if (targetUuid.empty() || amount <= 0){
sender.sendMessage(endstone::ColorFormat::Red + lang["check-format"].GetString() + endstone::ColorFormat::Reset);
return false;
}
if (args[0] == "pay") {
if (targetUuid.empty() || amount <= 0){
sender.sendMessage(endstone::ColorFormat::Red + "请检查你输入的格式" + endstone::ColorFormat::Reset);
return false;
}
if(args[1] == sender.getName()){
sender.sendMessage(endstone::ColorFormat::Red + "不能给自己转账" + endstone::ColorFormat::Reset);
return false;
}
if (!payPlayerMoney(uuid,targetUuid,amount)){
sender.sendMessage(endstone::ColorFormat::Red + "转账时错误。" + endstone::ColorFormat::Reset);
return false;
}
sender.sendMessage(endstone::ColorFormat::Green + "您已成功转账" + endstone::ColorFormat::Reset);
server.getPlayer(args[1])->sendMessage(endstone::ColorFormat::Green + "您已成功到账"+ args[2] + "货币" + endstone::ColorFormat::Reset);
return true;
if(args[1] == sender.getName()){
sender.sendMessage(endstone::ColorFormat::Red + lang["transfer-error"].GetString() + endstone::ColorFormat::Reset);
return false;
}
if (!sender.isOp()){
sender.sendMessage(endstone::ColorFormat::Red + "你个人机" + endstone::ColorFormat::Reset);
if (!payPlayerMoney(uuid,targetUuid,amount)){
sender.sendMessage(endstone::ColorFormat::Red + lang["transfer-anomaly"].GetString() + endstone::ColorFormat::Reset);
return false;
}
//用的不是很安全
if (args[0] == "add"){
if(!legalityCheck(targetUuid,sender,amount)){
return false;
}
jsonHelper.addPlayerMoney(targetUuid,amount);
sender.sendMessage(endstone::ColorFormat::Green + "目标账户金额增加成功" + endstone::ColorFormat::Reset);
return true;
sender.sendMessage(endstone::ColorFormat::Green + lang["transfer-successful"].GetString() + endstone::ColorFormat::Reset);
server.getPlayer(args[1])->sendMessage(endstone::ColorFormat::Green + lang["successful-arrival"].GetString() + args[2] + cfg["money"]["monetary-unit"].GetString() + endstone::ColorFormat::Reset);
return true;
}
if (!sender.isOp()){
sender.sendMessage(endstone::ColorFormat::Red + lang["no-permission"].GetString() + endstone::ColorFormat::Reset);
return false;
}
//用的不是很安全
if (args[0] == "add"){
if(!legalityCheck(targetUuid,sender,amount)){
return false;
}
if (args[0] == "reduce"){
if(!legalityCheck(targetUuid,sender,amount)){
return true;
}
jsonHelper.addPlayerMoney(targetUuid,-amount);
sender.sendMessage(endstone::ColorFormat::Green + "目标账户金额减少成功" + endstone::ColorFormat::Reset);
jsonHelper.addPlayerMoney(targetUuid,amount);
sender.sendMessage(endstone::ColorFormat::Green + lang["money-add"].GetString() + endstone::ColorFormat::Reset);
return true;
}
if (args[0] == "reduce"){
if(!legalityCheck(targetUuid,sender,amount)){
return true;
}
if (args[0] == "set"){
if(!legalityCheck(targetUuid,sender,amount)){
return true;
}
jsonHelper.setPlayerMoney(targetUuid,amount);
sender.sendMessage(endstone::ColorFormat::Green + "目标账户金额设置成功" + endstone::ColorFormat::Reset);
jsonHelper.addPlayerMoney(targetUuid,-amount);
sender.sendMessage(endstone::ColorFormat::Green + lang["money-reduce"].GetString() + endstone::ColorFormat::Reset);
return true;
}
if (args[0] == "set"){
if(!legalityCheck(targetUuid,sender,amount)){
return true;
}
jsonHelper.setPlayerMoney(targetUuid,amount);
sender.sendMessage(endstone::ColorFormat::Green + lang["money-set"].GetString() + endstone::ColorFormat::Reset);
return true;
}
return false;
}
};

static bool payPlayerMoney(std::string& transferor,std::string& transferee,int& money){
jsonHelper jsonHelper;
Expand Down
10 changes: 5 additions & 5 deletions include/economyAPI.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@
#include "economyListener.h"
#include "command/economyCommand.h"
#include "util/data/poco/jsonHelper.h"
#include "util/config/jsonConfig.h"

#include <iostream>
#include "util/files/filesInitialize.h"

#include <iostream>

class economyAPI : public endstone::Plugin{

Expand All @@ -31,8 +31,9 @@ class economyAPI : public endstone::Plugin{
}

try{
jsonConfig::configInitialize();
jsonConfig::dataBaseInitialize();
filesInitialize::configInitialize();
filesInitialize::languageInitialize();
filesInitialize::dataBaseInitialize();
}catch (const std::runtime_error& e){
getLogger().error(e.what());
}
Expand All @@ -59,6 +60,5 @@ class economyAPI : public endstone::Plugin{

private:
std::unique_ptr<economyListener> listener_;
jsonHelper jsonHelper;
};

10 changes: 8 additions & 2 deletions include/economyListener.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@

#include "endstone/plugin/plugin.h"
#include "endstone/event/player/player_join_event.h"

#include "util/data/poco/jsonHelper.h"
#include "util/files/filesInitialize.h"


class economyListener {
Expand All @@ -18,17 +20,21 @@ class economyListener {
std::string uuid = event.getPlayer().getUniqueId().str();
const std::string playerName = event.getPlayer().getName();
if(!hasAccount(uuid)){
creatAccount(event.getPlayer().getName(),uuid,0);
creatAccount(event.getPlayer().getName(),uuid);
plugin_.getLogger().info("玩家: "+ playerName +" 账户创建成功");
}
plugin_.getLogger().info(playerName);
}

bool creatAccount(const std::string& playerName, std::string& uuid, int money){
bool creatAccount(const std::string& playerName, std::string& uuid){
int money;
try{
money = cfg["money"]["default"].GetInt();
jsonHelper_.addEconomyData(playerName,uuid,money);
return true;
}catch (const std::runtime_error& e){
money = 0;
jsonHelper_.addEconomyData(playerName,uuid,money);
return false;
}
}
Expand Down
9 changes: 5 additions & 4 deletions include/rapidjson/document.h
Original file line number Diff line number Diff line change
Expand Up @@ -2800,7 +2800,10 @@ class GenericDocument : public GenericValue<Encoding, Allocator> {
//! Get the capacity of stack in bytes.
size_t GetStackCapacity() const { return stack_.GetCapacity(); }

private:
//! Prohibit assignment
GenericDocument& operator=(const GenericDocument&);

private:
// clear stack on any exit from ParseStream, e.g. due to exception
struct ClearStackOnExit {
explicit ClearStackOnExit(GenericDocument& d) : d_(d) {}
Expand Down Expand Up @@ -2862,10 +2865,8 @@ class GenericDocument : public GenericValue<Encoding, Allocator> {
private:
//! Prohibit copying
GenericDocument(const GenericDocument&);
//! Prohibit assignment
GenericDocument& operator=(const GenericDocument&);

void ClearStack() {
void ClearStack() {
if (Allocator::kNeedFree)
while (stack_.GetSize() > 0) // Here assumes all elements in stack array are GenericValue (Member is actually 2 GenericValue objects)
(stack_.template Pop<ValueType>(1))->~ValueType();
Expand Down
2 changes: 2 additions & 0 deletions include/util/data/dao/jsonBase.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@

#include "util/files/filesManager.h"



class jsonBase{
public:
static void jsonWrite(const rapidjson::Document& file);
Expand Down
2 changes: 1 addition & 1 deletion include/util/data/poco/jsonHelper.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@
#include "rapidjson/stringbuffer.h"
#include "rapidjson/prettywriter.h"
#include "rapidjson/document.h"
#include "rapidjson/istreamwrapper.h"
#include "rapidjson/filereadstream.h"
#include "rapidjson/filewritestream.h"

#include "endstone/plugin/plugin.h"

#include "util/files/filesManager.h"
#include "util/data/poco/dataHelper.h"

#include "util/data/dao/jsonBase.h"

#include <iostream>
Expand Down
Loading

0 comments on commit bb1b342

Please sign in to comment.