Skip to content

Commit

Permalink
adapt: adapt to GMLIB v0.12.0
Browse files Browse the repository at this point in the history
  • Loading branch information
KobeBryant114514 committed Apr 28, 2024
1 parent 7328199 commit 5f62fb6
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 37 deletions.
7 changes: 4 additions & 3 deletions src/Config.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,9 @@ struct Config {
};

std::unordered_map<std::string, DataInfo> sidebarInfo = {
{"1", DataInfo{{"§aConfig Example", "§bConfig Example", "§cConfig Example"}, 1}},
{"2", DataInfo{{"Player Name: %player_name%", "Player Ping: %player_ping%ms"}, 2} },
{"3", DataInfo{{"Server Mspt: %server_mspt%", "Server Tps: %server_tps%"}, 3} }
{"1", DataInfo{{"§aConfig Example", "§bConfig Example", "§cConfig Example"}, 1} },
{"2", DataInfo{{"Name: %player_name%", "Ping: %player_ping%ms"}, 2} },
{"3", DataInfo{{"Mspt: %server_mspt_colored_2%", "Tps: %server_tps_colored_2%"}, 3}},
{"4", DataInfo{{"Score1: %player_score_test1%", "Score2: %player_score_test2%"}, 3}}
};
};
21 changes: 12 additions & 9 deletions src/Entry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,19 @@

ll::Logger logger(PLUGIN_NAME);

namespace my_plugin {
namespace gmsidebar {

std::unique_ptr<MyPlugin>& MyPlugin::getInstance() {
static std::unique_ptr<MyPlugin> instance;
std::unique_ptr<Entry>& Entry::getInstance() {
static std::unique_ptr<Entry> instance;
return instance;
}

bool MyPlugin::load() {
bool Entry::load() {
// Code for loading the plugin goes here.
return true;
}

bool MyPlugin::enable() {
bool Entry::enable() {
// Code for enabling the plugin goes here.
mConfig.emplace();
ll::config::loadConfig(*mConfig, getSelf().getConfigDir() / u8"config.json");
Expand All @@ -30,10 +30,13 @@ bool MyPlugin::enable() {
loadSidebarStatus();
init();
registerCommand();
logger.info("GMSidebar Loaded!");
logger.info("Author: GroupMountain");
logger.info("Repository: https://github.com/GroupMountain/GMSidebar");
return true;
}

bool MyPlugin::disable() {
bool Entry::disable() {
// Code for disabling the plugin goes here.
saveSidebarStatus();
mConfig.reset();
Expand All @@ -42,11 +45,11 @@ bool MyPlugin::disable() {
return true;
}

bool MyPlugin::unload() {
bool Entry::unload() {
// Code for disabling the plugin goes here.
return true;
}

} // namespace my_plugin
} // namespace gmsidebar

LL_REGISTER_PLUGIN(my_plugin::MyPlugin, my_plugin::MyPlugin::getInstance());
LL_REGISTER_PLUGIN(gmsidebar::Entry, gmsidebar::Entry::getInstance());
10 changes: 5 additions & 5 deletions src/Entry.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@
#include <ll/api/plugin/NativePlugin.h>
#include <ll/api/plugin/RegisterHelper.h>

namespace my_plugin {
namespace gmsidebar {

class MyPlugin {
class Entry {

public:
static std::unique_ptr<MyPlugin>& getInstance();
static std::unique_ptr<Entry>& getInstance();

MyPlugin(ll::plugin::NativePlugin& self) : mSelf(self) {}
Entry(ll::plugin::NativePlugin& self) : mSelf(self) {}

[[nodiscard]] ll::plugin::NativePlugin& getSelf() const { return mSelf; }

Expand Down Expand Up @@ -41,4 +41,4 @@ class MyPlugin {
std::unique_ptr<GMLIB::Files::I18n::LangI18n> mI18n;
};

} // namespace my_plugin
} // namespace gmsidebar
22 changes: 3 additions & 19 deletions src/Sidebar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ std::optional<ll::schedule::SystemTimeScheduler> mAsyncScheduler;
std::optional<ll::schedule::ServerTimeScheduler> mScheduler;

std::string tr(std::string key, std::vector<std::string> data, std::string translateKey) {
return my_plugin::MyPlugin::getInstance()->translate(key, data, translateKey);
return gmsidebar::Entry::getInstance()->translate(key, data, translateKey);
}

void saveSidebarStatus() {
Expand All @@ -37,23 +37,7 @@ void sendSidebar(GMLIB_Player* pl) {
GMLIB::Server::PlaceholderAPI::translate(data, pl);
}
auto title = GMLIB::Server::PlaceholderAPI::translateString(mTitle, pl);
// pl->setClientSidebar(title, dataList, mOrder);
SetDisplayObjectivePacket("sidebar", "GMLIB_SIDEBAR_API", title, "dummy", mOrder).sendTo(*pl);

std::vector<ScorePacketInfo> info;
for (auto& key : dataList) {
const ScoreboardId& id = ScoreboardId(key.second);
auto text = key.first;
auto scoreInfo = ScorePacketInfo();
scoreInfo.mScoreboardId = id;
scoreInfo.mObjectiveName = "GMLIB_SIDEBAR_API";
scoreInfo.mIdentityType = IdentityDefinition::Type::FakePlayer;
scoreInfo.mScoreValue = key.second;
scoreInfo.mFakePlayerName = text;
info.emplace_back(scoreInfo);
}
auto pkt = SetScorePacket::change(info);
pkt.sendTo(*pl);
pl->setClientSidebar(title, dataList, mOrder);
}

void sendSidebarToClients() {
Expand All @@ -74,7 +58,7 @@ void sendSidebarToClients() {
void init() {
mAsyncScheduler.emplace();
mScheduler.emplace();
auto& config = my_plugin::MyPlugin::getInstance()->getConfig();
auto& config = gmsidebar::Entry::getInstance()->getConfig();
mOrder = config.sortType;
for (auto& [index, info] : config.sidebarInfo) {
try {
Expand Down

0 comments on commit 5f62fb6

Please sign in to comment.