-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patheconomyListener.h
54 lines (46 loc) · 1.45 KB
/
economyListener.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
//
// Created by admin on 2024/7/29.
//
#pragma once
#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 {
public:
explicit economyListener(endstone::Plugin &plugin): plugin_(plugin){
}
void onPlayerJoin(endstone::PlayerJoinEvent &event)
{
std::string uuid = event.getPlayer().getUniqueId().str();
const std::string playerName = event.getPlayer().getName();
if(!hasAccount(uuid)){
creatAccount(event.getPlayer().getName(),uuid);
plugin_.getLogger().info("玩家: "+ playerName +" 账户创建成功");
}
plugin_.getLogger().info(playerName);
}
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;
}
}
bool hasAccount(const std::string& uuid) {
try{
jsonHelper_.hasEconomyData(uuid);
return true;
}catch (const std::runtime_error& e){
return false;
}
}
private:
endstone::Plugin &plugin_;
jsonHelper jsonHelper_;
};