adapt: adapt GMLIB v0.9.7
This commit is contained in:
+1
-1
Submodule SDK-GMLIB updated: b1e7ebd770...9935ed4063
+45
-1
@@ -620,6 +620,49 @@ class Scoreboard {
|
||||
|
||||
}
|
||||
|
||||
class JsonConfig {
|
||||
constructor(path, defultValue = {}) {
|
||||
this.mData = defultValue;
|
||||
this.mPath = path;
|
||||
}
|
||||
|
||||
init() {
|
||||
if (File.exists(this.mPath)) {
|
||||
let existDataStr = File.readFrom(this.mPath);
|
||||
this.mData = Object.assign({}, this.mData, JSON.parse(existDataStr));
|
||||
}
|
||||
this.save();
|
||||
}
|
||||
|
||||
save(format = 4) {
|
||||
let dataStr = JSON.stringify(this.mData, null, format);
|
||||
File.writeTo(this.mPath, dataStr);
|
||||
}
|
||||
|
||||
getData() {
|
||||
return this.mData;
|
||||
}
|
||||
|
||||
get(key, defultValue = null) {
|
||||
let result = this.getData()[key];
|
||||
if (!result && defultValue != null) {
|
||||
this.set(key, defultValue);
|
||||
return defultValue;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
set(key, value) {
|
||||
this.getData()[key] = value;
|
||||
this.save();
|
||||
}
|
||||
|
||||
delete(key) {
|
||||
delete this.getData()[key];
|
||||
this.save();
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
StaticFloatingText,
|
||||
DynamicFloatingText,
|
||||
@@ -627,5 +670,6 @@ module.exports = {
|
||||
Recipes,
|
||||
Experiments,
|
||||
GMLIB,
|
||||
Scoreboard
|
||||
Scoreboard,
|
||||
JsonConfig
|
||||
};
|
||||
@@ -1,13 +1,13 @@
|
||||
#include "Global.h"
|
||||
#include <regex>
|
||||
|
||||
bool isNumber(const std::string& str) {
|
||||
std::regex pattern("[-+]?[0-9]*\\.?[0-9]+");
|
||||
bool isInteger(const std::string& str) {
|
||||
std::regex pattern("^[+-]?\\d+$");
|
||||
return std::regex_match(str, pattern);
|
||||
}
|
||||
|
||||
ActorUniqueID parseScriptUniqueID(std::string uniqueId) {
|
||||
if (!isNumber(uniqueId)) {
|
||||
if (!isInteger(uniqueId)) {
|
||||
return ActorUniqueID::INVALID_ID;
|
||||
}
|
||||
return ActorUniqueID(std::stoll(uniqueId));
|
||||
@@ -36,7 +36,12 @@ void Export_Compatibility_API() {
|
||||
return level->getServerAverageTps();
|
||||
});
|
||||
RemoteCall::exportAs("GMLIB_API", "getAllPlayerUuids", []() -> std::vector<std::string> {
|
||||
return GMLIB_Player::getAllUuids();
|
||||
std::vector<std::string> result;
|
||||
std::vector<mce::UUID> uuids = GMLIB_Player::getAllUuids();
|
||||
for (auto& uuid : uuids) {
|
||||
result.push_back(uuid.asString());
|
||||
}
|
||||
return result;
|
||||
});
|
||||
RemoteCall::exportAs("GMLIB_API", "getPlayerNbt", [](std::string uuid) -> std::string {
|
||||
auto uid = mce::UUID::fromString(uuid);
|
||||
@@ -262,7 +267,7 @@ void Export_Compatibility_API() {
|
||||
});
|
||||
RemoteCall::exportAs("GMLIB_API", "resetEntityScores", [](std::string uniqueId) -> bool {
|
||||
auto auid = parseScriptUniqueID(uniqueId);
|
||||
return GMLIB_Scoreboard::getInstance()->resetAllScores(auid);
|
||||
return GMLIB_Scoreboard::getInstance()->resetScore(auid);
|
||||
});
|
||||
RemoteCall::exportAs("GMLIB_API", "fakePlayerHasScore", [](std::string name, std::string obj) -> bool {
|
||||
if (auto result = GMLIB_Scoreboard::getInstance()->getScore(obj, name)) {
|
||||
@@ -303,7 +308,7 @@ void Export_Compatibility_API() {
|
||||
return GMLIB_Scoreboard::getInstance()->resetScore(obj, name);
|
||||
});
|
||||
RemoteCall::exportAs("GMLIB_API", "resetFakePlayerScores", [](std::string name) -> bool {
|
||||
return GMLIB_Scoreboard::getInstance()->resetAllScores(name);
|
||||
return GMLIB_Scoreboard::getInstance()->resetScore(name);
|
||||
});
|
||||
RemoteCall::exportAs("GMLIB_API", "addObjective", [](std::string obj) -> bool {
|
||||
if (auto res = GMLIB_Scoreboard::getInstance()->getInstance()->addObjective(obj)) {
|
||||
|
||||
Reference in New Issue
Block a user