Skip to content

Commit

Permalink
adapt: adapt GMLIB v0.12. 6
Browse files Browse the repository at this point in the history
Update v0.12.1
  • Loading branch information
KobeBryant114514 authored May 25, 2024
2 parents 532858f + 7b997f6 commit 4468c23
Show file tree
Hide file tree
Showing 10 changed files with 59 additions and 55 deletions.
2 changes: 1 addition & 1 deletion SDK-GMLIB
Submodule SDK-GMLIB updated 51 files
+4 −4 GMLIB/Event/Entity/ActorChangeDImensionEvent.h
+3 −3 GMLIB/Event/Entity/DeathMessageEvent.h
+2 −2 GMLIB/Event/Entity/DragonRespawnEvent.h
+2 −2 GMLIB/Event/Entity/EconomyTradeEvent.h
+1 −1 GMLIB/Event/Entity/EndermanTakeBlockEvent.h
+1 −1 GMLIB/Event/Entity/ItemActorEvent.h
+21 −21 GMLIB/Event/Entity/ItemActorSpawnEvent.h
+2 −2 GMLIB/Event/Entity/MobHurtEvent.h
+2 −2 GMLIB/Event/Entity/MobPickupItemEvent.h
+2 −2 GMLIB/Event/Entity/ProjectileCreateEvent.h
+16 −16 GMLIB/Event/Level/ExplodeEvent.h
+8 −8 GMLIB/Event/Level/WeatherUpdateEvent.h
+12 −12 GMLIB/Event/Player/PlayerChangeDimensionEvent.h
+7 −7 GMLIB/Event/Player/PlayerSleepEvent.h
+2 −2 GMLIB/Event/RedStone/BlockMovedByPistonEvent.h
+8 −8 GMLIB/Event/RedStone/PistonPushEvent.h
+1 −1 GMLIB/Event/Registries/CreativeItemsInitEvent.h
+4 −4 GMLIB/Event/Registries/JsonItemInitEvent.h
+1 −1 GMLIB/Event/Registries/ResourcePackInitEvent.h
+0 −88 GMLIB/Files/Config/JsonConfig.h
+3 −3 GMLIB/Files/FileUtils.h
+19 −18 GMLIB/Files/JsonFile.h
+15 −15 GMLIB/Files/Language/I18n/JsonI18n.h
+15 −15 GMLIB/Files/Language/I18n/LangI18n.h
+13 −53 GMLIB/Files/Language/JsonLanguage.h
+9 −2 GMLIB/Files/Language/LangLanguage.h
+25 −14 GMLIB/Files/Language/McLang.h
+7 −7 GMLIB/Files/Language/ResourceLanguage.h
+20 −20 GMLIB/GMLIB.h
+6 −2 GMLIB/Macros.h
+1 −1 GMLIB/Mod/Addons/CustomDamageCause.h
+3 −2 GMLIB/Mod/Addons/CustomPacks.h
+1 −1 GMLIB/Mod/Addons/VanillaFix.h
+3 −3 GMLIB/Mod/CustomRecipe/CustomRecipe.h
+37 −32 GMLIB/Server/ActorAPI.h
+1 −37 GMLIB/Server/BinaryStreamAPI.h
+11 −11 GMLIB/Server/CompoundTagAPI.h
+1 −1 GMLIB/Server/FakeListAPI.h
+69 −53 GMLIB/Server/FloatingTextAPI.h
+2 −2 GMLIB/Server/FormAPI/NpcDialogueForm.h
+19 −11 GMLIB/Server/I18nAPI.h
+13 −13 GMLIB/Server/ItemStackAPI.h
+95 −52 GMLIB/Server/LevelAPI.h
+8 −8 GMLIB/Server/PlaceholderAPI.h
+85 −46 GMLIB/Server/PlayerAPI.h
+41 −41 GMLIB/Server/ScoreboardAPI.h
+24 −20 GMLIB/Server/SpawnerAPI.h
+35 −0 GMLIB/Server/StorageAPI.h
+30 −12 GMLIB/Server/UserCache.h
+1 −1 GMLIB/include_lib.h
+ Lib/GMLIB.lib
2 changes: 1 addition & 1 deletion manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"type": "native",
"author": "GroupMountain",
"description": "Free Camera",
"version": "0.12.0",
"version": "0.12.1",
"dependencies": [
{
"name": "GMLIB"
Expand Down
11 changes: 7 additions & 4 deletions src/Config.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
#pragma once
#include "Global.h"
#include <iostream>

std::string defaultConfig = R"({
"language": "en_US"
})";
struct Config {
int version = 1;

std::string language = "zh_CN";

};
22 changes: 20 additions & 2 deletions src/Entry.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include "Entry.h"
#include "Global.h"
#include "Language.h"
ll::Logger logger(PLUGIN_NAME);

namespace FreeCamera {
Expand All @@ -10,7 +11,6 @@ std::unique_ptr<Entry>& Entry::getInstance() {
}

bool Entry::load() {
initLanguage();
if (Version::getProtocolVersion() != TARGET_PROTOCOL) {
logger.error(tr("error.protocolMismatch.info"));
logger.error(
Expand All @@ -23,11 +23,21 @@ bool Entry::load() {
}

bool Entry::enable() {
mConfig.emplace();
if (!ll::config::loadConfig(*mConfig, getSelf().getConfigDir() / u8"config.json")) {
ll::config::saveConfig(*mConfig, getSelf().getConfigDir() / u8"config.json");
}
mI18n.emplace(getSelf().getLangDir(), mConfig->language);
mI18n->updateOrCreateLanguage("en_US", en_US);
mI18n->updateOrCreateLanguage("zh_CN", zh_CN);
mI18n->loadAllLanguages();
mI18n->chooseLanguage(mConfig->language);
RegisterCommand();
return true;
}

bool Entry::disable() {
mConfig.reset();
FreeCamList.clear();
ll::service::getLevel().get().forEachPlayer([](Player& pl) -> bool {
FreeCamera::DisableFreeCamera(&pl);
Expand All @@ -36,6 +46,14 @@ bool Entry::disable() {
return true;
}

Config& Entry::getConfig() { return mConfig.value(); }

LangI18n& Entry::getI18n() { return *mI18n; }

} // namespace FreeCamera

LL_REGISTER_PLUGIN(FreeCamera::Entry, FreeCamera::Entry::getInstance());
LL_REGISTER_PLUGIN(FreeCamera::Entry, FreeCamera::Entry::getInstance());

std::string tr(std::string const& key, std::vector<std::string> const& data) {
return FreeCamera::Entry::getInstance()->getI18n().get(key, data);
}
13 changes: 9 additions & 4 deletions src/Entry.h
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
#pragma once
#include <ll/api/plugin/NativePlugin.h>
#include "Config.h"
#include "Global.h"

namespace FreeCamera {

using namespace GMLIB::Files::I18n;

class Entry {

public:
Expand All @@ -21,12 +24,14 @@ class Entry {
/// @return True if the plugin is disabled successfully.
bool disable();

// TODO: Implement this method if you need to unload the plugin.
// /// @return True if the plugin is unloaded successfully.
// bool unload();
Config& getConfig();

LangI18n& getI18n();

private:
ll::plugin::NativePlugin& mSelf;
std::optional<Config> mConfig;
std::optional<LangI18n> mI18n;
};

} // namespace FreeCamera
5 changes: 2 additions & 3 deletions src/FreeCamera.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,13 @@ void SendFakePlayerPacket(Player* pl) {
// Update Skin
auto skin = pl->getSkin();
GMLIB_BinaryStream bs;
bs.writePacketHeader(MinecraftPacketIds::PlayerSkin);
bs.writeUuid(randomUuid);
bs.writeSkin(skin);
bs.writeString("");
bs.writeString("");
bs.writeBool(true);
auto pkt2 = MinecraftPackets::createPacket(MinecraftPacketIds::PlayerSkin);
pkt2->read(bs);
pl->sendNetworkPacket(*pkt2);
bs.sendTo(*pl);
}

void DisableFreeCameraPacket(Player* pl) {
Expand Down
3 changes: 1 addition & 2 deletions src/Global.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,8 @@ using namespace GMLIB;
extern ll::Logger logger;
extern std::unordered_set<uint64> FreeCamList;
extern void RegisterCommand();
extern void initLanguage();

extern std::string tr(std::string key, std::vector<std::string> data = {});
extern std::string tr(std::string const& key, std::vector<std::string> const& data = {});

namespace FreeCamera {
extern void DisableFreeCamera(Player* pl);
Expand Down
20 changes: 0 additions & 20 deletions src/Initialization.cpp

This file was deleted.

32 changes: 16 additions & 16 deletions src/Language.h
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
#pragma once
#include "Global.h"

std::string defaultLanguage_en_US = R"({
"freecamera.command.desc": "Enable or disable freecamera mode.",
"freecamera.command.enabled": "Freecamera mode enabled",
"freecamera.command.disabled": "Freecamera mode disabled",
"freecamera.command.console": "This command can only execute by players.",
"error.protocolMismatch.info":"You are running on an unsupport protocol version! This may result in crash!",
"error.protocolMismatch.version":"Support protocol %1$s, current protocol %2$s."
})";
std::string en_US = R"(
freecamera.command.desc=Enable or disable freecamera mode.
freecamera.command.enabled=Freecamera mode enabled.
freecamera.command.disabled=Freecamera mode disabled.
freecamera.command.console=This command can only execute by players.
error.protocolMismatch.info=You are running on an unsupport protocol version! This may result in crash!
error.protocolMismatch.version=Support protocol %1$s, current protocol %2$s.
)";

std::string defaultLanguage_zh_CN = R"({
"freecamera.command.desc": "开启或关闭自由视角模式",
"freecamera.command.enabled": "自由视角模式已启用",
"freecamera.command.disabled": "自由视角模式已禁用",
"freecamera.command.console": "该命令只能由玩家执行",
"error.protocolMismatch.info":"此插件正在不兼容的版本协议上运行!这可能造成服务器崩溃。",
"error.protocolMismatch.version":"此插件支持版本协议 %1$s,服务器版本协议 %2$s。"
})";
std::string zh_CN = R"(
freecamera.command.desc=开启或关闭自由视角模式
freecamera.command.enabled=自由视角模式已启用
freecamera.command.disabled=自由视角模式已禁用
freecamera.command.console=该命令只能由玩家执行
error.protocolMismatch.info=此插件正在不兼容的版本协议上运行!这可能造成服务器崩溃。
error.protocolMismatch.version=此插件支持版本协议 %1$s,服务器版本协议 %2$s。
)";
4 changes: 2 additions & 2 deletions tooth.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"format_version": 2,
"tooth": "github.com/GroupMountain/FreeCamera",
"version": "0.12.0",
"version": "0.12.1",
"info": {
"name": "FreeCamera",
"description": "Free Camera Plugin on Bedrock Dedicated Server",
Expand All @@ -11,7 +11,7 @@
"freecamera"
]
},
"asset_url": "https://github.com/GroupMountain/FreeCamera/releases/download/v0.12.0/FreeCamera-windows-x64.zip",
"asset_url": "https://github.com/GroupMountain/FreeCamera/releases/download/v0.12.1/FreeCamera-windows-x64.zip",
"dependencies": {
"github.com/GroupMountain/GMLIB": ">=0.12.1"
},
Expand Down

0 comments on commit 4468c23

Please sign in to comment.