Compare commits
27 Commits
@@ -29,4 +29,10 @@ jobs:
|
||||
with:
|
||||
name: ${{ github.event.repository.name }}-windows-x64-${{ github.sha }}
|
||||
path: |
|
||||
bin/
|
||||
bin/DLL/
|
||||
|
||||
- uses: actions/upload-artifact@v3
|
||||
with:
|
||||
name: PDB
|
||||
path: |
|
||||
bin/PDB/
|
||||
|
||||
@@ -11,7 +11,7 @@ jobs:
|
||||
uses: actions/checkout@v2
|
||||
with:
|
||||
submodules: recursive
|
||||
|
||||
|
||||
- uses: actions/checkout@v4
|
||||
|
||||
- uses: xmake-io/github-action-setup-xmake@v1
|
||||
@@ -29,7 +29,13 @@ jobs:
|
||||
with:
|
||||
name: ${{ github.event.repository.name }}-windows-x64-${{ github.sha }}
|
||||
path: |
|
||||
bin/
|
||||
bin/DLL/
|
||||
|
||||
- uses: actions/upload-artifact@v3
|
||||
with:
|
||||
name: PDB
|
||||
path: |
|
||||
bin/PDB/
|
||||
|
||||
upload-to-release:
|
||||
needs:
|
||||
@@ -38,24 +44,35 @@ jobs:
|
||||
contents: write
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
- name: Checkout code
|
||||
uses: actions/checkout@v4
|
||||
|
||||
- uses: actions/download-artifact@v3
|
||||
- name: Download Plugin
|
||||
uses: actions/download-artifact@v3
|
||||
with:
|
||||
name: ${{ github.event.repository.name }}-windows-x64-${{ github.sha }}
|
||||
path: release/
|
||||
path: release/Plugin/
|
||||
|
||||
- run: |
|
||||
cp LICENSE README.md release/
|
||||
- name: Download PDB
|
||||
uses: actions/download-artifact@v3
|
||||
with:
|
||||
name: PDB
|
||||
path: release/PDB/
|
||||
|
||||
- name: Copy additional files
|
||||
run: |
|
||||
cp LICENSE README.md release/Plugin/
|
||||
|
||||
- name: Archive release
|
||||
run: |
|
||||
cd release
|
||||
cd release/Plugin
|
||||
zip -r ../${{ github.event.repository.name }}-windows-x64.zip *
|
||||
cd ..
|
||||
|
||||
- uses: softprops/action-gh-release@v1
|
||||
- name: Create GitHub Release
|
||||
id: create_release
|
||||
uses: softprops/action-gh-release@v1
|
||||
with:
|
||||
append_body: true
|
||||
files: |
|
||||
${{ github.event.repository.name }}-windows-x64.zip
|
||||
release/${{ github.event.repository.name }}-windows-x64.zip
|
||||
release/PDB/${{ github.event.repository.name }}.pdb
|
||||
|
||||
+1
-1
Submodule SDK-GMLIB updated: fa3ec71bdc...37d92200bd
+27
-21
@@ -1,11 +1,14 @@
|
||||
const PAPIgetValueAPI = ll.import("BEPlaceholderAPI", "GetValue")
|
||||
const PAPIgetValueByPlayerAPI = ll.import("BEPlaceholderAPI", "GetValueWithPlayer")
|
||||
const PAPIregisterPlayerPlaceholderAPI = ll.import("BEPlaceholderAPI", "registerPlayerPlaceholder")
|
||||
const PAPIregisterServerPlaceholderAPI = ll.import("BEPlaceholderAPI", "registerServerPlaceholder")
|
||||
const PAPIregisterStaticPlaceholderAPI = ll.import("BEPlaceholderAPI", "registerStaticPlaceholder")
|
||||
const PAPItranslateStringAPI = ll.import("BEPlaceholderAPI", "translateString")
|
||||
const PAPIunRegisterPlaceholderAPI = ll.import("BEPlaceholderAPI", "unRegisterPlaceholder")
|
||||
const PAPIgetAllPAPI = ll.import("BEPlaceholderAPI", "getAllPAPI")
|
||||
const PlaceholderAPI = {
|
||||
getValueAPI: ll.import("BEPlaceholderAPI", "GetValue"),
|
||||
getValueByPlayerAPI: ll.import("BEPlaceholderAPI", "GetValueWithPlayer"),
|
||||
registerPlayerPlaceholderAPI: ll.import("BEPlaceholderAPI", "registerPlayerPlaceholder"),
|
||||
registerServerPlaceholderAPI: ll.import("BEPlaceholderAPI", "registerServerPlaceholder"),
|
||||
registerStaticPlaceholderAPI: ll.import("BEPlaceholderAPI", "registerStaticPlaceholder"),
|
||||
translateStringAPI: ll.import("BEPlaceholderAPI", "translateString"),
|
||||
translateStringWithPlayerAPI: ll.import("BEPlaceholderAPI", "translateStringWithPlayer"),
|
||||
unRegisterPlaceholderAPI: ll.import("BEPlaceholderAPI", "unRegisterPlaceholder"),
|
||||
getAllPAPI: ll.import("BEPlaceholderAPI", "getAllPAPI")
|
||||
}
|
||||
|
||||
Function.prototype.getName = function () {
|
||||
return this.name || this.toString().match(/function\s*([^(]*)\(/)[1]
|
||||
@@ -17,38 +20,41 @@ class PAPI {
|
||||
}
|
||||
|
||||
static registerPlayerPlaceholder(func, PluginName, PAPIName) {
|
||||
ll.export(func, PluginName, func.getName())
|
||||
PAPIregisterPlayerPlaceholderAPI(PluginName, func.getName(), PAPIName)
|
||||
ll.export(func, PluginName, func.getName());
|
||||
return PlaceholderAPI.registerPlayerPlaceholderAPI(PluginName, func.getName(), PAPIName);
|
||||
}
|
||||
|
||||
static registerServerPlaceholder(func, PluginName, PAPIName) {
|
||||
ll.export(func, PluginName, func.getName())
|
||||
PAPIregisterServerPlaceholderAPI(PluginName, func.getName(), PAPIName)
|
||||
ll.export(func, PluginName, func.getName());
|
||||
return PlaceholderAPI.registerServerPlaceholderAPI(PluginName, func.getName(), PAPIName);
|
||||
}
|
||||
|
||||
static registerStaticPlaceholder(func, PluginName, PAPIName, UpdateInterval = 50) {
|
||||
ll.export(func, PluginName, func.getName())
|
||||
PAPIregisterStaticPlaceholderAPI(PluginName, func.getName(), PAPIName, UpdateInterval)
|
||||
ll.export(func, PluginName, func.getName());
|
||||
return PlaceholderAPI.registerStaticPlaceholderAPI(PluginName, func.getName(), PAPIName, UpdateInterval);
|
||||
}
|
||||
|
||||
static getValue(key) {
|
||||
return PAPIgetValueAPI(key)
|
||||
return PlaceholderAPI.getValueAPI(key);
|
||||
}
|
||||
|
||||
static getValueByPlayer(key, xuid) {
|
||||
return PAPIgetValueByPlayerAPI(key, xuid)
|
||||
static getValueByPlayer(key, pl) {
|
||||
return PlaceholderAPI.getValueByPlayerAPI(key, pl);
|
||||
}
|
||||
|
||||
static translateString(str, xuid = "") {
|
||||
return PAPItranslateStringAPI(str, xuid)
|
||||
static translateString(str, pl = null) {
|
||||
if (pl) {
|
||||
return PlaceholderAPI.translateStringWithPlayerAPI(str, pl);
|
||||
}
|
||||
return PlaceholderAPI.translateStringAPI(str);
|
||||
}
|
||||
|
||||
static unRegisterPlaceholder(str) {
|
||||
return PAPIunRegisterPlaceholderAPI(str)
|
||||
return PlaceholderAPI.unRegisterPlaceholderAPI(str);
|
||||
}
|
||||
|
||||
static getAllPAPI() {
|
||||
return PAPIgetAllPAPI();
|
||||
return PlaceholderAPI.getAllPAPI();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,29 @@
|
||||
const CallEvent = ll.import("GMLIB_API", "callCustomEvent");
|
||||
|
||||
let NextEventId = 0;
|
||||
|
||||
function getNextEventId() {
|
||||
NextEventId++;
|
||||
return "GMLIB_Event_" + NextEventId;
|
||||
}
|
||||
|
||||
class Event {
|
||||
constructor() {
|
||||
throw new Error("Static class cannot be instantiated");
|
||||
}
|
||||
|
||||
static listen(event, callback) {
|
||||
let eventId = getNextEventId();
|
||||
ll.export(callback, event, eventId);
|
||||
let result = CallEvent(event, eventId);
|
||||
if (!result) {
|
||||
logger.error(`Cannot listen event "${event}"!`);
|
||||
logger.error(`Event "${event}" No Found!`);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
Event
|
||||
};
|
||||
+439
-4
@@ -15,6 +15,9 @@ const GMLIB_API = {
|
||||
getPlayerNbt: ll.import("GMLIB_API", "getPlayerNbt"),
|
||||
setPlayerNbt: ll.import("GMLIB_API", "setPlayerNbt"),
|
||||
setPlayerNbtTags: ll.import("GMLIB_API", "setPlayerNbtTags"),
|
||||
resourcePackTranslate: ll.import("GMLIB_API", "resourcePackTranslate"),
|
||||
getResourcePackI18nLanguage: ll.import("GMLIB_API", "getResourcePackI18nLanguage"),
|
||||
chooseResourcePackI18nLanguage: ll.import("GMLIB_API", "chooseResourcePackI18nLanguage"),
|
||||
setEducationFeatureEnabled: ll.import("GMLib_ServerAPI", "setEducationFeatureEnabled"),
|
||||
registerAbilityCommand: ll.import("GMLib_ServerAPI", "registerAbilityCommand"),
|
||||
setEnableAchievement: ll.import("GMLib_ServerAPI", "setEnableAchievement"),
|
||||
@@ -32,6 +35,7 @@ const GMLIB_API = {
|
||||
getExperimentTranslatedName: ll.import("GMLIB_API", "getExperimentTranslatedName"),
|
||||
getExperimentEnabled: ll.import("GMLib_ModAPI", "getExperimentEnabled"),
|
||||
setExperimentEnabled: ll.import("GMLib_ModAPI", "setExperimentEnabled"),
|
||||
unregisterRecipe: ll.import("GMLIB_API", "unregisterRecipe"),
|
||||
registerExperimentsRequire: ll.import("GMLib_ModAPI", "registerExperimentsRequire"),
|
||||
registerStoneCutterRecipe: ll.import("GMLib_ModAPI", "registerStoneCutterRecipe"),
|
||||
registerSmithingTrimRecipe: ll.import("GMLib_ModAPI", "registerSmithingTrimRecipe"),
|
||||
@@ -43,7 +47,50 @@ const GMLIB_API = {
|
||||
registerShapelessRecipe: ll.import("GMLib_ModAPI", "registerShapelessRecipe"),
|
||||
isVersionMatched: ll.import("GMLIB_API", "isVersionMatched"),
|
||||
getVersion_LRCA: ll.import("GMLIB_API", "getVersion_LRCA"),
|
||||
getVersion_GMLIB: ll.import("GMLIB_API", "getVersion_GMLIB")
|
||||
getVersion_GMLIB: ll.import("GMLIB_API", "getVersion_GMLIB"),
|
||||
getPlayerPosition: ll.import("GMLIB_API", "getPlayerPosition"),
|
||||
setPlayerPosition: ll.import("GMLIB_API", "setPlayerPosition"),
|
||||
playerHasScore: ll.import("GMLIB_API", "playerHasScore"),
|
||||
getPlayerScore: ll.import("GMLIB_API", "getPlayerScore"),
|
||||
addPlayerScore: ll.import("GMLIB_API", "addPlayerScore"),
|
||||
reducePlayerScore: ll.import("GMLIB_API", "reducePlayerScore"),
|
||||
setPlayerScore: ll.import("GMLIB_API", "setPlayerScore"),
|
||||
resetPlayerScore: ll.import("GMLIB_API", "resetPlayerScore"),
|
||||
resetPlayerScores: ll.import("GMLIB_API", "resetPlayerScores"),
|
||||
entityHasScore: ll.import("GMLIB_API", "entityHasScore"),
|
||||
getEntityScore: ll.import("GMLIB_API", "getEntityScore"),
|
||||
addEntityScore: ll.import("GMLIB_API", "addEntityScore"),
|
||||
reduceEntityScore: ll.import("GMLIB_API", "reduceEntityScore"),
|
||||
setEntityScore: ll.import("GMLIB_API", "setEntityScore"),
|
||||
resetEntityScore: ll.import("GMLIB_API", "resetEntityScore"),
|
||||
resetEntityScores: ll.import("GMLIB_API", "resetEntityScores"),
|
||||
fakePlayerHasScore: ll.import("GMLIB_API", "fakePlayerHasScore"),
|
||||
getFakePlayerScore: ll.import("GMLIB_API", "getFakePlayerScore"),
|
||||
addFakePlayerScore: ll.import("GMLIB_API", "addFakePlayerScore"),
|
||||
reduceFakePlayerScore: ll.import("GMLIB_API", "reduceFakePlayerScore"),
|
||||
setFakePlayerScore: ll.import("GMLIB_API", "setFakePlayerScore"),
|
||||
resetFakePlayerScore: ll.import("GMLIB_API", "resetFakePlayerScore"),
|
||||
resetFakePlayerScores: ll.import("GMLIB_API", "resetFakePlayerScores"),
|
||||
addObjective: ll.import("GMLIB_API", "addObjective"),
|
||||
addObjectiveWithDisplayName: ll.import("GMLIB_API", "addObjectiveWithDisplayName"),
|
||||
getDisplayName: ll.import("GMLIB_API", "getDisplayName"),
|
||||
setDisplayName: ll.import("GMLIB_API", "setDisplayName"),
|
||||
removeObjective: ll.import("GMLIB_API", "removeObjective"),
|
||||
setDisplayObjective: ll.import("GMLIB_API", "setDisplayObjective"),
|
||||
clearDisplayObjective: ll.import("GMLIB_API", "clearDisplayObjective"),
|
||||
getAllObjectives: ll.import("GMLIB_API", "getAllObjectives"),
|
||||
getAllScoreboardPlayers: ll.import("GMLIB_API", "getAllScoreboardPlayers"),
|
||||
getAllScoreboardFakePlayers: ll.import("GMLIB_API", "getAllScoreboardFakePlayers"),
|
||||
getAllScoreboardEntities: ll.import("GMLIB_API", "getAllScoreboardEntities"),
|
||||
getPlayerFromUuid: ll.import("GMLIB_API", "getPlayerFromUuid"),
|
||||
getPlayerFromUniqueId: ll.import("GMLIB_API", "getPlayerFromUniqueId"),
|
||||
getEntityFromUniqueId: ll.import("GMLIB_API", "getEntityFromUniqueId"),
|
||||
getWorldSpawn: ll.import("GMLIB_API", "getWorldSpawn"),
|
||||
setWorldSpawn: ll.import("GMLIB_API", "setWorldSpawn"),
|
||||
getPlayerSpawnPoint: ll.import("GMLIB_API", "getPlayerSpawnPoint"),
|
||||
setPlayerSpawnPoint: ll.import("GMLIB_API", "setPlayerSpawnPoint"),
|
||||
clearPlayerSpawnPoint: ll.import("GMLIB_API", "clearPlayerSpawnPoint"),
|
||||
setCustomPackPath: ll.import("GMLIB_API", "setCustomPackPath")
|
||||
}
|
||||
|
||||
const FloatingTextList = [];
|
||||
@@ -235,13 +282,16 @@ class Minecraft {
|
||||
|
||||
static getPlayerNbt(uuid) {
|
||||
let snbt = GMLIB_API.getPlayerNbt(uuid);
|
||||
if (snbt == "null") {
|
||||
return null;
|
||||
}
|
||||
let nbt = NBT.parseSNBT(snbt);
|
||||
return nbt;
|
||||
}
|
||||
|
||||
static setPlayerNbt(uuid, nbt) {
|
||||
static setPlayerNbt(uuid, nbt, forceCreate = true) {
|
||||
let snbt = nbt.toSNBT();
|
||||
return GMLIB_API.setPlayerNbt(uuid, snbt);
|
||||
return GMLIB_API.setPlayerNbt(uuid, snbt, forceCreate);
|
||||
}
|
||||
|
||||
static setPlayerNbtTags(uuid, nbt, tags) {
|
||||
@@ -249,6 +299,38 @@ class Minecraft {
|
||||
return GMLIB_API.setPlayerNbtTags(uuid, snbt, tags);
|
||||
}
|
||||
|
||||
static getPlayerPosition(uuid) {
|
||||
let pos = GMLIB_API.getPlayerPosition(uuid);
|
||||
if (pos.dimid == -1) {
|
||||
return null;
|
||||
}
|
||||
return pos;
|
||||
}
|
||||
|
||||
static setPlayerPosition(uuid, pos) {
|
||||
return GMLIB_API.setPlayerPosition(uuid, pos);
|
||||
}
|
||||
|
||||
static getWorldSpawn() {
|
||||
return GMLIB_API.getWorldSpawn();
|
||||
}
|
||||
|
||||
static setWorldSpawn(pos) {
|
||||
return GMLIB_API.setWorldSpawn(pos);
|
||||
}
|
||||
|
||||
static getPlayerSpawnPoint() {
|
||||
return GMLIB_API.getPlayerSpawnPoint();
|
||||
}
|
||||
|
||||
static setPlayerSpawnPoint(pos) {
|
||||
GMLIB_API.setPlayerSpawnPoint(pos);
|
||||
}
|
||||
|
||||
static clearPlayerSpawnPoint() {
|
||||
GMLIB_API.clearPlayerSpawnPoint();
|
||||
}
|
||||
|
||||
static setEducationFeatureEnabled() {
|
||||
return GMLIB_API.setEducationFeatureEnabled();
|
||||
}
|
||||
@@ -300,6 +382,22 @@ class Minecraft {
|
||||
static throwEntity(entity, proj, speed = 2, offset = 3) {
|
||||
return GMLIB_API.throwEntity(entity, proj, speed = 2, offset = 3);
|
||||
}
|
||||
|
||||
static getServerLanguage() {
|
||||
return GMLIB_API.getResourcePackI18nLanguage(language);
|
||||
}
|
||||
|
||||
static setServerLanguage(language) {
|
||||
return GMLIB_API.chooseResourcePackI18nLanguage(language);
|
||||
}
|
||||
|
||||
static setCustomPackPath(path) {
|
||||
GMLIB_API.setCustomPackPath(path);
|
||||
}
|
||||
|
||||
static resourcePackTranslate(key, params = []) {
|
||||
return GMLIB_API.resourcePackTranslate(key, params);
|
||||
}
|
||||
}
|
||||
|
||||
class Recipes {
|
||||
@@ -307,6 +405,10 @@ class Recipes {
|
||||
throw new Error("Static class cannot be instantiated");
|
||||
}
|
||||
|
||||
static unregisterRecipe(recipeId) {
|
||||
return GMLIB_API.unregisterRecipe(recipeId);
|
||||
}
|
||||
|
||||
static registerStoneCutterRecipe(recipeId, inputName, inputAux, outputName, outputAux, outputCount) {
|
||||
return GMLIB_API.registerStoneCutterRecipe(recipeId, inputName, inputAux, outputName, outputAux, outputCount);
|
||||
}
|
||||
@@ -378,6 +480,53 @@ class Experiments {
|
||||
}
|
||||
}
|
||||
|
||||
class Version {
|
||||
constructor(major, minor, patch) {
|
||||
this.mMajor = major;
|
||||
this.mMinor = minor;
|
||||
this.mPatch = patch;
|
||||
}
|
||||
|
||||
toString(prefix = true) {
|
||||
let result = `${this.mMajor}.${this.mMinor}.${this.mPatch}`;
|
||||
if (prefix) {
|
||||
result = "v" + result;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
toArray() {
|
||||
return [this.mMajor, this.mMinor, this.mPatch];
|
||||
}
|
||||
|
||||
valueOf() {
|
||||
return 100000000 * this.mMajor + 10000 * this.mMinor + this.mPatch;
|
||||
}
|
||||
|
||||
static fromString(string) {
|
||||
if (typeof string === 'string' || string instanceof String) {
|
||||
let pattern = /^v?\d+\.\d+\.\d+$/;
|
||||
if (pattern.test(string)) {
|
||||
let regex = /\d+/g;
|
||||
let numbers = string.match(regex);
|
||||
let array = numbers.slice(0, 3).map(Number);
|
||||
return new Version(array[0], array[1], array[2]);
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
static fromArray(array) {
|
||||
if (Array.isArray(array) && array.length == 3) {
|
||||
let isNumber = array.every(element => typeof element == "number");
|
||||
if (isNumber) {
|
||||
return new Version(array[0], array[1], array[2])
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
class GMLIB {
|
||||
constructor() {
|
||||
throw new Error("Static class cannot be instantiated");
|
||||
@@ -396,4 +545,290 @@ class GMLIB {
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = { StaticFloatingText, DynamicFloatingText, Minecraft, Recipes, Experiments, GMLIB };
|
||||
class Scoreboard {
|
||||
constructor() {
|
||||
throw new Error("Static class cannot be instantiated");
|
||||
}
|
||||
|
||||
// Targets
|
||||
static getAllTrackedEntities() {
|
||||
return GMLIB_API.getAllScoreboardEntities();
|
||||
}
|
||||
|
||||
static getAllTrackedPlayers() {
|
||||
return GMLIB_API.getAllScoreboardPlayers();
|
||||
}
|
||||
|
||||
static getAllTrackedFakePlayers() {
|
||||
return GMLIB_API.getAllScoreboardFakePlayers();
|
||||
}
|
||||
|
||||
static getAllTrackedTargets() {
|
||||
let result = [];
|
||||
GMLIB_API.getAllScoreboardPlayers().forEach((uuid) => {
|
||||
let key = {
|
||||
"Type": "Player",
|
||||
"Uuid": uuid
|
||||
};
|
||||
result.push(key);
|
||||
});
|
||||
GMLIB_API.getAllScoreboardEntities().forEach((uniqueId) => {
|
||||
let key = {
|
||||
"Type": "Entity",
|
||||
"UniqueId": uniqueId
|
||||
};
|
||||
result.push(key);
|
||||
});
|
||||
GMLIB_API.getAllScoreboardFakePlayers().forEach((name) => {
|
||||
let key = {
|
||||
"Type": "FakePlayer",
|
||||
"Name": name
|
||||
};
|
||||
result.push(key);
|
||||
});
|
||||
return result;
|
||||
}
|
||||
|
||||
// Objectives
|
||||
static addObjective(name, displayName = "") {
|
||||
if (displayName == "") {
|
||||
return GMLIB_API.addObjective(name);
|
||||
}
|
||||
return GMLIB_API.addObjectiveWithDisplayName(name, displayName);
|
||||
}
|
||||
|
||||
static removeObjective(name) {
|
||||
return GMLIB_API.removeObjective(name);
|
||||
}
|
||||
|
||||
static getAllObjectives() {
|
||||
return GMLIB_API.getAllObjectives();
|
||||
}
|
||||
|
||||
static getDisplayName(objective) {
|
||||
return GMLIB_API.getDisplayName(objective);
|
||||
}
|
||||
|
||||
static setDisplayName(objective, displayName) {
|
||||
return GMLIB_API.setDisplayName(objective, displayName);
|
||||
}
|
||||
|
||||
static setDisplay(objective, slot, order = 0) {
|
||||
GMLIB_API.setDisplayObjective(objective, slot, order);
|
||||
}
|
||||
|
||||
static clearDisplay(slot) {
|
||||
GMLIB_API.clearDisplayObjective(slot);
|
||||
}
|
||||
|
||||
// Player Score
|
||||
static getPlayerScore(uuid, objective) {
|
||||
if (GMLIB_API.playerHasScore(uuid, objective)) {
|
||||
return GMLIB_API.getPlayerScore(uuid, objective);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
static addPlayerScore(uuid, objective, value) {
|
||||
return GMLIB_API.addPlayerScore(uuid, objective, value);
|
||||
}
|
||||
|
||||
static reducePlayerScore(uuid, objective, value) {
|
||||
return GMLIB_API.reducePlayerScore(uuid, objective, value);
|
||||
}
|
||||
|
||||
static setPlayerScore(uuid, objective, value) {
|
||||
return GMLIB_API.setPlayerScore(uuid, objective, value);
|
||||
}
|
||||
|
||||
static resetPlayerScore(uuid, objective) {
|
||||
return GMLIB_API.resetPlayerScore(uuid, objective);
|
||||
}
|
||||
|
||||
static resetPlayerScores(uuid) {
|
||||
return GMLIB_API.resetPlayerScores(uuid);
|
||||
}
|
||||
|
||||
// FakePlayer Score
|
||||
static getFakePlayerScore(name, objective) {
|
||||
if (GMLIB_API.fakePlayerHasScore(name, objective)) {
|
||||
return GMLIB_API.getFakePlayerScore(name, objective);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
static addFakePlayerScore(name, objective, value) {
|
||||
return GMLIB_API.addFakePlayerScore(name, objective, value);
|
||||
}
|
||||
|
||||
static reduceFakePlayerScore(name, objective, value) {
|
||||
return GMLIB_API.reduceFakePlayerScore(name, objective, value);
|
||||
}
|
||||
|
||||
static setFakePlayerScore(name, objective, value) {
|
||||
return GMLIB_API.setFakePlayerScore(name, objective, value);
|
||||
}
|
||||
|
||||
static resetFakePlayerScore(name, objective) {
|
||||
return GMLIB_API.resetFakePlayerScore(name, objective);
|
||||
}
|
||||
|
||||
static resetFakePlayerScores(name) {
|
||||
return GMLIB_API.resetFakePlayerScores(name);
|
||||
}
|
||||
|
||||
// Entity Score
|
||||
static getEntityScore(uniqueId, objective) {
|
||||
if (GMLIB_API.entityHasScore(uniqueId, objective)) {
|
||||
return GMLIB_API.getEntityScore(uniqueId, objective);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
static addEntityScore(uniqueId, objective, value) {
|
||||
return GMLIB_API.addEntityScore(uniqueId, objective, value);
|
||||
}
|
||||
|
||||
static reduceEntityScore(uniqueId, objective, value) {
|
||||
return GMLIB_API.reduceEntityScore(uniqueId, objective, value);
|
||||
}
|
||||
|
||||
static setEntityScore(uniqueId, objective, value) {
|
||||
return GMLIB_API.setEntityScore(uniqueId, objective, value);
|
||||
}
|
||||
|
||||
static resetEntityScore(uniqueId, objective) {
|
||||
return GMLIB_API.resetEntityScore(uniqueId, objective);
|
||||
}
|
||||
|
||||
static resetEntityScores(uniqueId) {
|
||||
return GMLIB_API.resetEntityScores(uniqueId);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
class JsonConfig {
|
||||
constructor(path, defultValue = {}) {
|
||||
this.mData = defultValue;
|
||||
this.mPath = path;
|
||||
this.init();
|
||||
}
|
||||
|
||||
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();
|
||||
}
|
||||
}
|
||||
|
||||
class JsonLanguage extends JsonConfig {
|
||||
constructor(path, defultValue = {}) {
|
||||
super(path, defultValue);
|
||||
}
|
||||
|
||||
translate(key, data = []) {
|
||||
let result = this.get(key);
|
||||
if (result == null) {
|
||||
return key;
|
||||
}
|
||||
data.forEach((val, index) => {
|
||||
let old = `{${index + 1}}`;
|
||||
result = result.split(old).join(val);
|
||||
});
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
class JsonI18n {
|
||||
constructor(path, localLangCode = "en_US") {
|
||||
if (!path.endsWith("/") && !path.endsWith("\\")) {
|
||||
path = path + "/";
|
||||
}
|
||||
this.mPath = path;
|
||||
this.mLangCode = localLangCode;
|
||||
this.mAllLanguages = {};
|
||||
this.mDefaultLangCode = "en_US";
|
||||
this.loadAllLanguages();
|
||||
}
|
||||
|
||||
loadAllLanguages() {
|
||||
let exist_list = File.getFilesList(this.mPath);
|
||||
exist_list.forEach((name) => {
|
||||
let code = name.replace(".json", "");
|
||||
let path = this.mPath + name;
|
||||
let language = new JsonLanguage(path);
|
||||
this.mAllLanguages[code] = language;
|
||||
});
|
||||
}
|
||||
|
||||
loadLanguage(langCode, defaultData = {}) {
|
||||
let langPath = this.mPath;
|
||||
langPath = langPath + langCode + ".json";
|
||||
let language = new JsonLanguage(langPath, defaultData);
|
||||
this.mAllLanguages[langCode] = language;
|
||||
}
|
||||
|
||||
chooseLanguage(langCode) {
|
||||
this.mLangCode = langCode;
|
||||
}
|
||||
|
||||
setDefaultLanguage(langCode) {
|
||||
this.mDefaultLangCode = langCode;
|
||||
}
|
||||
|
||||
translate(key, data = [], langCode = this.mLangCode) {
|
||||
let language = this.mAllLanguages[langCode];
|
||||
let result = language.translate(key, data);
|
||||
if (result == key) {
|
||||
let language = this.mAllLanguages[this.mDefaultLangCode];
|
||||
if (language) {
|
||||
result = language.translate(key, data);
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
};
|
||||
|
||||
module.exports = {
|
||||
StaticFloatingText,
|
||||
DynamicFloatingText,
|
||||
Minecraft,
|
||||
Recipes,
|
||||
Experiments,
|
||||
GMLIB,
|
||||
Scoreboard,
|
||||
JsonConfig,
|
||||
JsonLanguage,
|
||||
JsonI18n,
|
||||
Version
|
||||
};
|
||||
@@ -1,6 +1,8 @@
|
||||
{
|
||||
"name": "${pluginName}",
|
||||
"entry": "${pluginFile}",
|
||||
"version": "0.10.0",
|
||||
"author": "GroupMountain",
|
||||
"type": "native",
|
||||
"dependencies": [
|
||||
{
|
||||
|
||||
@@ -88,10 +88,11 @@ function pack_plugin(target,plugin_define)
|
||||
local manifest_path = find_file("manifest.json", os.projectdir())
|
||||
if manifest_path then
|
||||
local manifest = io.readfile(manifest_path)
|
||||
local bindir = path.join(os.projectdir(), "bin")
|
||||
local bindir = path.join(os.projectdir(), "bin/DLL")
|
||||
local pdbdir = path.join(os.projectdir(), "bin/PDB")
|
||||
local outputdir = path.join(bindir, plugin_define.pluginName)
|
||||
local targetfile = path.join(outputdir, plugin_define.pluginFile)
|
||||
local pdbfile = path.join(outputdir, path.basename(plugin_define.pluginFile) .. ".pdb")
|
||||
local pdbfile = path.join(pdbdir, path.basename(plugin_define.pluginFile) .. ".pdb")
|
||||
local libfile = path.join(os.projectdir(), "lib")
|
||||
local manifestfile = path.join(outputdir, "manifest.json")
|
||||
local oritargetfile = target:targetfile()
|
||||
|
||||
+304
-9
@@ -1,38 +1,70 @@
|
||||
#include "Global.h"
|
||||
#include <regex>
|
||||
|
||||
bool isInteger(const std::string& str) {
|
||||
std::regex pattern("^[+-]?\\d+$");
|
||||
return std::regex_match(str, pattern);
|
||||
}
|
||||
|
||||
ActorUniqueID parseScriptUniqueID(std::string uniqueId) {
|
||||
if (!isInteger(uniqueId)) {
|
||||
return ActorUniqueID::INVALID_ID;
|
||||
}
|
||||
return ActorUniqueID(std::stoll(uniqueId));
|
||||
}
|
||||
|
||||
void Export_Compatibility_API() {
|
||||
RemoteCall::exportAs("GMLIB_API", "unregisterRecipe", [](std::string id) -> bool {
|
||||
auto level = GMLIB_Level::getInstance();
|
||||
if (!level) {
|
||||
return false;
|
||||
}
|
||||
return GMLIB::Mod::CustomRecipe::unregisterRecipe(id);
|
||||
});
|
||||
RemoteCall::exportAs("GMLIB_API", "setCustomPackPath", [](std::string path) -> void {
|
||||
GMLIB::Mod::CustomPacks::addCustomPackPath(path);
|
||||
});
|
||||
RemoteCall::exportAs("GMLIB_API", "getServerMspt", []() -> float {
|
||||
auto level = GMLIB_Level::getLevel();
|
||||
auto level = GMLIB_Level::getInstance();
|
||||
if (!level) {
|
||||
return 0.0f;
|
||||
}
|
||||
return level->getServerMspt();
|
||||
});
|
||||
RemoteCall::exportAs("GMLIB_API", "getServerCurrentTps", []() -> float {
|
||||
auto level = GMLIB_Level::getLevel();
|
||||
auto level = GMLIB_Level::getInstance();
|
||||
if (!level) {
|
||||
return 0.0f;
|
||||
}
|
||||
return level->getServerCurrentTps();
|
||||
});
|
||||
RemoteCall::exportAs("GMLIB_API", "getServerAverageTps", []() -> float {
|
||||
auto level = GMLIB_Level::getLevel();
|
||||
auto level = GMLIB_Level::getInstance();
|
||||
if (!level) {
|
||||
return 0.0f;
|
||||
}
|
||||
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);
|
||||
return GMLIB_Player::getPlayerNbt(uid)->toSnbt();
|
||||
auto nbt = GMLIB_Player::getPlayerNbt(uid);
|
||||
if (nbt) {
|
||||
return nbt->toSnbt();
|
||||
}
|
||||
return "null";
|
||||
});
|
||||
RemoteCall::exportAs("GMLIB_API", "setPlayerNbt", [](std::string uuid, std::string snbt) -> bool {
|
||||
RemoteCall::exportAs("GMLIB_API", "setPlayerNbt", [](std::string uuid, std::string snbt, bool forceCreate) -> bool {
|
||||
auto uid = mce::UUID::fromString(uuid);
|
||||
auto nbt = CompoundTag::fromSnbt(snbt);
|
||||
return GMLIB_Player::setPlayerNbt(uid, *nbt);
|
||||
return GMLIB_Player::setPlayerNbt(uid, *nbt, forceCreate);
|
||||
});
|
||||
RemoteCall::exportAs(
|
||||
"GMLIB_API",
|
||||
@@ -126,11 +158,274 @@ void Export_Compatibility_API() {
|
||||
return false;
|
||||
});
|
||||
RemoteCall::exportAs("GMLIB_API", "isVersionMatched", [](int a, int b, int c) -> bool {
|
||||
auto version = SemVersion(a, b, c, "", "");
|
||||
return LIB_VERSION.satisfies(version);
|
||||
auto version = GMLIB::Version(a, b, c, "", "");
|
||||
return version >= LIB_VERSION;
|
||||
});
|
||||
RemoteCall::exportAs("GMLIB_API", "getVersion_LRCA", []() -> std::string { return LIB_VERSION.asString(); });
|
||||
RemoteCall::exportAs("GMLIB_API", "getVersion_GMLIB", []() -> std::string {
|
||||
return GMLIB::Version::getLibVersionString();
|
||||
});
|
||||
RemoteCall::exportAs(
|
||||
"GMLIB_API",
|
||||
"resourcePackTranslate",
|
||||
[](std::string key, std::vector<std::string> params) -> std::string { return I18n::get(key, params); }
|
||||
);
|
||||
RemoteCall::exportAs("GMLIB_API", "chooseResourcePackI18nLanguage", [](std::string code) -> void {
|
||||
I18n::chooseLanguage(code);
|
||||
});
|
||||
RemoteCall::exportAs("GMLIB_API", "getResourcePackI18nLanguage", []() -> std::string {
|
||||
return I18n::getCurrentLanguage()->getFullLanguageCode();
|
||||
});
|
||||
RemoteCall::exportAs("GMLIB_API", "getPlayerPosition", [](std::string uuid) -> std::pair<BlockPos, int> {
|
||||
auto uid = mce::UUID::fromString(uuid);
|
||||
auto pos = GMLIB_Player::getPlayerPosition(uid);
|
||||
if (pos.has_value()) {
|
||||
return pos.value();
|
||||
}
|
||||
return {
|
||||
{0, 0, 0},
|
||||
-1
|
||||
};
|
||||
});
|
||||
RemoteCall::exportAs("GMLIB_API", "setPlayerPosition", [](std::string uuid, std::pair<BlockPos, int> pos) -> bool {
|
||||
auto uid = mce::UUID::fromString(uuid);
|
||||
return GMLIB_Player::setPlayerPosition(uid, pos.first, pos.second);
|
||||
});
|
||||
RemoteCall::exportAs("GMLIB_API", "playerHasScore", [](std::string uuid, std::string obj) -> bool {
|
||||
auto uid = mce::UUID::fromString(uuid);
|
||||
if (auto result = GMLIB_Player::getPlayerScore(uid, obj)) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
});
|
||||
RemoteCall::exportAs("GMLIB_API", "getPlayerScore", [](std::string uuid, std::string obj) -> int {
|
||||
auto uid = mce::UUID::fromString(uuid);
|
||||
if (auto result = GMLIB_Player::getPlayerScore(uid, obj)) {
|
||||
return result.value();
|
||||
}
|
||||
return 0;
|
||||
});
|
||||
RemoteCall::exportAs("GMLIB_API", "addPlayerScore", [](std::string uuid, std::string obj, int value) -> bool {
|
||||
auto uid = mce::UUID::fromString(uuid);
|
||||
if (auto res = GMLIB_Player::setPlayerScore(uid, obj, value, PlayerScoreSetFunction::Add)) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
});
|
||||
RemoteCall::exportAs("GMLIB_API", "reducePlayerScore", [](std::string uuid, std::string obj, int value) -> bool {
|
||||
auto uid = mce::UUID::fromString(uuid);
|
||||
if (auto res = GMLIB_Player::setPlayerScore(uid, obj, value, PlayerScoreSetFunction::Subtract)) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
});
|
||||
RemoteCall::exportAs("GMLIB_API", "setPlayerScore", [](std::string uuid, std::string obj, int value) -> bool {
|
||||
auto uid = mce::UUID::fromString(uuid);
|
||||
if (auto res = GMLIB_Player::setPlayerScore(uid, obj, value)) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
});
|
||||
RemoteCall::exportAs("GMLIB_API", "resetPlayerScore", [](std::string uuid, std::string obj) -> bool {
|
||||
auto uid = mce::UUID::fromString(uuid);
|
||||
return GMLIB_Player::resetPlayerScore(uid, obj);
|
||||
});
|
||||
RemoteCall::exportAs("GMLIB_API", "resetPlayerScores", [](std::string uuid) -> bool {
|
||||
auto uid = mce::UUID::fromString(uuid);
|
||||
return GMLIB_Player::resetPlayerScore(uid);
|
||||
});
|
||||
RemoteCall::exportAs("GMLIB_API", "entityHasScore", [](std::string uniqueId, std::string obj) -> bool {
|
||||
auto auid = parseScriptUniqueID(uniqueId);
|
||||
if (auto result = GMLIB_Scoreboard::getInstance()->getScore(obj, auid)) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
});
|
||||
RemoteCall::exportAs("GMLIB_API", "getEntityScore", [](std::string uniqueId, std::string obj) -> int {
|
||||
auto auid = parseScriptUniqueID(uniqueId);
|
||||
if (auto result = GMLIB_Scoreboard::getInstance()->getScore(obj, auid)) {
|
||||
return result.value();
|
||||
}
|
||||
return 0;
|
||||
});
|
||||
RemoteCall::exportAs("GMLIB_API", "addEntityScore", [](std::string uniqueId, std::string obj, int value) -> bool {
|
||||
auto auid = parseScriptUniqueID(uniqueId);
|
||||
if (auto res = GMLIB_Scoreboard::getInstance()->setScore(obj, auid, value, PlayerScoreSetFunction::Add)) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
});
|
||||
RemoteCall::exportAs(
|
||||
"GMLIB_API",
|
||||
"reduceEntityScore",
|
||||
[](std::string uniqueId, std::string obj, int value) -> bool {
|
||||
auto auid = parseScriptUniqueID(uniqueId);
|
||||
if (auto res =
|
||||
GMLIB_Scoreboard::getInstance()->setScore(obj, auid, value, PlayerScoreSetFunction::Subtract)) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
);
|
||||
RemoteCall::exportAs("GMLIB_API", "setEntityScore", [](std::string uniqueId, std::string obj, int value) -> bool {
|
||||
auto auid = parseScriptUniqueID(uniqueId);
|
||||
if (auto res = GMLIB_Scoreboard::getInstance()->setScore(obj, auid, value)) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
});
|
||||
RemoteCall::exportAs("GMLIB_API", "resetEntityScore", [](std::string uniqueId, std::string obj) -> bool {
|
||||
auto auid = parseScriptUniqueID(uniqueId);
|
||||
return GMLIB_Scoreboard::getInstance()->resetScore(obj, auid);
|
||||
});
|
||||
RemoteCall::exportAs("GMLIB_API", "resetEntityScores", [](std::string uniqueId) -> bool {
|
||||
auto auid = parseScriptUniqueID(uniqueId);
|
||||
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)) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
});
|
||||
RemoteCall::exportAs("GMLIB_API", "getFakePlayerScore", [](std::string name, std::string obj) -> int {
|
||||
if (auto result = GMLIB_Scoreboard::getInstance()->getScore(obj, name)) {
|
||||
return result.value();
|
||||
}
|
||||
return 0;
|
||||
});
|
||||
RemoteCall::exportAs("GMLIB_API", "addFakePlayerScore", [](std::string name, std::string obj, int value) -> bool {
|
||||
if (auto res = GMLIB_Scoreboard::getInstance()->setScore(obj, name, value, PlayerScoreSetFunction::Add)) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
});
|
||||
RemoteCall::exportAs(
|
||||
"GMLIB_API",
|
||||
"reduceFakePlayerScore",
|
||||
[](std::string name, std::string obj, int value) -> bool {
|
||||
if (auto res =
|
||||
GMLIB_Scoreboard::getInstance()->setScore(obj, name, value, PlayerScoreSetFunction::Subtract)) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
);
|
||||
RemoteCall::exportAs("GMLIB_API", "setFakePlayerScore", [](std::string name, std::string obj, int value) -> bool {
|
||||
if (auto res = GMLIB_Scoreboard::getInstance()->setScore(obj, name, value)) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
});
|
||||
RemoteCall::exportAs("GMLIB_API", "resetFakePlayerScore", [](std::string name, std::string obj) -> bool {
|
||||
return GMLIB_Scoreboard::getInstance()->resetScore(obj, name);
|
||||
});
|
||||
RemoteCall::exportAs("GMLIB_API", "resetFakePlayerScores", [](std::string name) -> bool {
|
||||
return GMLIB_Scoreboard::getInstance()->resetScore(name);
|
||||
});
|
||||
RemoteCall::exportAs("GMLIB_API", "addObjective", [](std::string obj) -> bool {
|
||||
if (auto res = GMLIB_Scoreboard::getInstance()->getInstance()->addObjective(obj)) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
});
|
||||
RemoteCall::exportAs(
|
||||
"GMLIB_API",
|
||||
"addObjectiveWithDisplayName",
|
||||
[](std::string obj, std::string displayName) -> bool {
|
||||
if (auto res = GMLIB_Scoreboard::getInstance()->getInstance()->addObjective(obj, displayName)) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
);
|
||||
RemoteCall::exportAs("GMLIB_API", "getDisplayName", [](std::string obj) -> std::string {
|
||||
if (auto result = GMLIB_Scoreboard::getInstance()->getInstance()->getObjectiveDisplayName(obj)) {
|
||||
return result.value();
|
||||
}
|
||||
return "";
|
||||
});
|
||||
RemoteCall::exportAs("GMLIB_API", "setDisplayName", [](std::string obj, std::string displayName) -> bool {
|
||||
return GMLIB_Scoreboard::getInstance()->getInstance()->setObjectiveDisplayName(obj, displayName);
|
||||
});
|
||||
RemoteCall::exportAs("GMLIB_API", "removeObjective", [](std::string obj) -> bool {
|
||||
return GMLIB_Scoreboard::getInstance()->getInstance()->removeObjective(obj);
|
||||
});
|
||||
RemoteCall::exportAs("GMLIB_API", "setDisplayObjective", [](std::string obj, std::string slot, int order) -> void {
|
||||
return GMLIB_Scoreboard::getInstance()->getInstance()->setObjectiveDisplay(
|
||||
obj,
|
||||
slot,
|
||||
(ObjectiveSortOrder)order
|
||||
);
|
||||
});
|
||||
RemoteCall::exportAs("GMLIB_API", "clearDisplayObjective", [](std::string slot) -> void {
|
||||
return GMLIB_Scoreboard::getInstance()->getInstance()->clearObjectiveDisplay(slot);
|
||||
});
|
||||
RemoteCall::exportAs("GMLIB_API", "getAllObjectives", []() -> std::vector<std::string> {
|
||||
auto objs = GMLIB_Scoreboard::getInstance()->getInstance()->getObjectives();
|
||||
std::vector<std::string> result;
|
||||
for (auto obj : objs) {
|
||||
result.push_back(obj->getName());
|
||||
}
|
||||
return result;
|
||||
});
|
||||
RemoteCall::exportAs("GMLIB_API", "getAllScoreboardPlayers", []() -> std::vector<std::string> {
|
||||
auto uuids = GMLIB_Scoreboard::getInstance()->getInstance()->getAllPlayerUuids();
|
||||
std::vector<std::string> result;
|
||||
for (auto& uuid : uuids) {
|
||||
result.push_back(uuid.asString());
|
||||
}
|
||||
return result;
|
||||
});
|
||||
RemoteCall::exportAs("GMLIB_API", "getAllScoreboardFakePlayers", []() -> std::vector<std::string> {
|
||||
auto names = GMLIB_Scoreboard::getInstance()->getInstance()->getAllFakePlayers();
|
||||
std::vector<std::string> result;
|
||||
for (auto name : names) {
|
||||
result.push_back(name);
|
||||
}
|
||||
return result;
|
||||
});
|
||||
RemoteCall::exportAs("GMLIB_API", "getAllScoreboardEntities", []() -> std::vector<std::string> {
|
||||
auto auids = GMLIB_Scoreboard::getInstance()->getInstance()->getAllEntities();
|
||||
std::vector<std::string> result;
|
||||
for (auto auid : auids) {
|
||||
result.push_back(std::to_string(auid.get()));
|
||||
}
|
||||
return result;
|
||||
});
|
||||
RemoteCall::exportAs("GMLIB_API", "getPlayerFromUuid", [](std::string uuid) -> Player* {
|
||||
auto uid = mce::UUID::fromString(uuid);
|
||||
return ll::service::getLevel()->getPlayer(uuid);
|
||||
});
|
||||
RemoteCall::exportAs("GMLIB_API", "getPlayerFromUniqueId", [](std::string uniqueId) -> Actor* {
|
||||
auto auid = parseScriptUniqueID(uniqueId);
|
||||
return ll::service::getLevel()->getPlayer(auid);
|
||||
});
|
||||
RemoteCall::exportAs("GMLIB_API", "getEntityFromUniqueId", [](std::string uniqueId) -> Actor* {
|
||||
auto auid = parseScriptUniqueID(uniqueId);
|
||||
return ll::service::getLevel()->fetchEntity(auid);
|
||||
});
|
||||
RemoteCall::exportAs("GMLIB_API", "getWorldSpawn", []() -> std::pair<BlockPos, int> {
|
||||
return {GMLIB_Level::getInstance()->getWorldSpawn(), 0};
|
||||
});
|
||||
RemoteCall::exportAs("GMLIB_API", "setWorldSpawn", [](std::pair<BlockPos, int> pos) -> bool {
|
||||
if (pos.second != 0) {
|
||||
return false;
|
||||
}
|
||||
GMLIB_Level::getInstance()->setWorldSpawn(pos.first);
|
||||
return true;
|
||||
});
|
||||
RemoteCall::exportAs("GMLIB_API", "getPlayerSpawnPoint", [](Player* pl) -> std::pair<BlockPos, int> {
|
||||
auto player = (GMLIB_Player*)pl;
|
||||
auto res = player->getSpawnPoint();
|
||||
return {res.first, res.second};
|
||||
});
|
||||
RemoteCall::exportAs("GMLIB_API", "setPlayerSpawnPoint", [](Player* pl, std::pair<BlockPos, int> pos) -> void {
|
||||
auto player = (GMLIB_Player*)pl;
|
||||
player->setSpawnPoint(pos.first, pos.second);
|
||||
});
|
||||
RemoteCall::exportAs("GMLIB_API", "clearPlayerSpawnPoint", [](Player* pl) -> void {
|
||||
auto player = (GMLIB_Player*)pl;
|
||||
player->clearSpawnPoint();
|
||||
});
|
||||
}
|
||||
+9
-34
@@ -5,21 +5,17 @@ ll::Logger logger(PLUGIN_NAME);
|
||||
|
||||
namespace GMLIB_LegacyRemoteCallApi {
|
||||
|
||||
namespace {
|
||||
std::unique_ptr<LRCA>& LRCA::getInstance() {
|
||||
static std::unique_ptr<LRCA> instance;
|
||||
return instance;
|
||||
}
|
||||
|
||||
std::unique_ptr<std::reference_wrapper<ll::plugin::NativePlugin>>
|
||||
selfPluginInstance; // NOLINT(cppcoreguidelines-avoid-non-const-global-variables)
|
||||
|
||||
auto disable(ll::plugin::NativePlugin& /*self*/) -> bool { return false; }
|
||||
|
||||
auto enable(ll::plugin::NativePlugin& /*self*/) -> bool { return true; }
|
||||
|
||||
auto load(ll::plugin::NativePlugin& self) -> bool {
|
||||
selfPluginInstance = std::make_unique<std::reference_wrapper<ll::plugin::NativePlugin>>(self);
|
||||
bool LRCA::load() {
|
||||
Export_Legacy_GMLib_ModAPI();
|
||||
Export_Legacy_GMLib_ServerAPI();
|
||||
Export_Compatibility_API();
|
||||
ExportPAPI();
|
||||
Export_Event_API();
|
||||
logger.info("GMLIB-LegacyRemoteCallApi Loaded!");
|
||||
logger.info("Version: {}", LIB_VERSION.asString());
|
||||
logger.info("Author: GroupMountain");
|
||||
@@ -27,31 +23,10 @@ auto load(ll::plugin::NativePlugin& self) -> bool {
|
||||
return true;
|
||||
}
|
||||
|
||||
auto unload(ll::plugin::NativePlugin& self) -> bool { return false; }
|
||||
bool LRCA::enable() { return true; }
|
||||
|
||||
} // namespace
|
||||
|
||||
auto getSelfPluginInstance() -> ll::plugin::NativePlugin& {
|
||||
if (!selfPluginInstance) {
|
||||
throw std::runtime_error("selfPluginInstance is null");
|
||||
}
|
||||
|
||||
return *selfPluginInstance;
|
||||
}
|
||||
bool LRCA::disable() { return true; }
|
||||
|
||||
} // namespace GMLIB_LegacyRemoteCallApi
|
||||
|
||||
extern "C" {
|
||||
_declspec(dllexport) auto ll_plugin_disable(ll::plugin::NativePlugin& self) -> bool {
|
||||
return GMLIB_LegacyRemoteCallApi::disable(self);
|
||||
}
|
||||
_declspec(dllexport) auto ll_plugin_enable(ll::plugin::NativePlugin& self) -> bool {
|
||||
return GMLIB_LegacyRemoteCallApi::enable(self);
|
||||
}
|
||||
_declspec(dllexport) auto ll_plugin_load(ll::plugin::NativePlugin& self) -> bool {
|
||||
return GMLIB_LegacyRemoteCallApi::load(self);
|
||||
}
|
||||
_declspec(dllexport) auto ll_plugin_unload(ll::plugin::NativePlugin& self) -> bool {
|
||||
return GMLIB_LegacyRemoteCallApi::unload(self);
|
||||
}
|
||||
}
|
||||
LL_REGISTER_PLUGIN(GMLIB_LegacyRemoteCallApi::LRCA, GMLIB_LegacyRemoteCallApi::LRCA::getInstance());
|
||||
|
||||
+26
-2
@@ -1,9 +1,33 @@
|
||||
#pragma once
|
||||
|
||||
#include <ll/api/plugin/NativePlugin.h>
|
||||
#include <ll/api/plugin/RegisterHelper.h>
|
||||
|
||||
namespace GMLIB_LegacyRemoteCallApi {
|
||||
|
||||
[[nodiscard]] auto getSelfPluginInstance() -> ll::plugin::NativePlugin&;
|
||||
class LRCA {
|
||||
|
||||
public:
|
||||
static std::unique_ptr<LRCA>& getInstance();
|
||||
|
||||
LRCA(ll::plugin::NativePlugin& self) : mSelf(self) {}
|
||||
|
||||
[[nodiscard]] ll::plugin::NativePlugin& getSelf() const { return mSelf; }
|
||||
|
||||
/// @return True if the plugin is loaded successfully.
|
||||
bool load();
|
||||
|
||||
/// @return True if the plugin is enabled successfully.
|
||||
bool enable();
|
||||
|
||||
/// @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();
|
||||
|
||||
private:
|
||||
ll::plugin::NativePlugin& mSelf;
|
||||
};
|
||||
|
||||
} // namespace GMLIB_LegacyRemoteCallApi
|
||||
|
||||
@@ -0,0 +1,184 @@
|
||||
#include "Global.h"
|
||||
using namespace ll::hash_utils;
|
||||
|
||||
void Export_Event_API() {
|
||||
auto eventBus = &ll::event::EventBus::getInstance();
|
||||
RemoteCall::exportAs(
|
||||
"GMLIB_API",
|
||||
"callCustomEvent",
|
||||
[eventBus](std::string eventName, std::string eventId) -> bool {
|
||||
if (RemoteCall::hasFunc(eventName, eventId)) {
|
||||
switch (doHash(eventName)) {
|
||||
case doHash("onClientLogin"): {
|
||||
auto Call = RemoteCall::importAs<
|
||||
bool(std::string realName, std::string uuid, std::string serverXuid, std::string clientXuid)>(
|
||||
eventName,
|
||||
eventId
|
||||
);
|
||||
eventBus->emplaceListener<GMLIB::Event::PacketEvent::ClientLoginAfterEvent>(
|
||||
[Call](GMLIB::Event::PacketEvent::ClientLoginAfterEvent& ev) {
|
||||
try {
|
||||
Call(
|
||||
ev.getRealName(),
|
||||
ev.getUuid().asString(),
|
||||
ev.getServerAuthXuid(),
|
||||
ev.getClientAuthXuid()
|
||||
);
|
||||
} catch (...) {}
|
||||
}
|
||||
);
|
||||
return true;
|
||||
}
|
||||
case doHash("onWeatherChange"): {
|
||||
auto Call =
|
||||
RemoteCall::importAs<bool(int lightningLevel, int rainLevel, int lightningLast, int rainLast)>(
|
||||
eventName,
|
||||
eventId
|
||||
);
|
||||
eventBus->emplaceListener<GMLIB::Event::LevelEvent::WeatherUpdateBeforeEvent>(
|
||||
[Call](GMLIB::Event::LevelEvent::WeatherUpdateBeforeEvent& ev) {
|
||||
bool result = true;
|
||||
try {
|
||||
result = Call(
|
||||
ev.getLightningLevel(),
|
||||
ev.getRainLevel(),
|
||||
ev.getLightningLastTick(),
|
||||
ev.getRainingLastTick()
|
||||
);
|
||||
} catch (...) {}
|
||||
if (!result) {
|
||||
ev.cancel();
|
||||
}
|
||||
}
|
||||
);
|
||||
return true;
|
||||
}
|
||||
case doHash("onMobPick"): {
|
||||
auto Call = RemoteCall::importAs<bool(Actor * mob, Actor * item)>(eventName, eventId);
|
||||
eventBus->emplaceListener<GMLIB::Event::EntityEvent::MobPickupItemBeforeEvent>(
|
||||
[Call](GMLIB::Event::EntityEvent::MobPickupItemBeforeEvent& ev) {
|
||||
bool result = true;
|
||||
try {
|
||||
result = Call(&ev.self(), (Actor*)&ev.getItemActor());
|
||||
} catch (...) {}
|
||||
if (!result) {
|
||||
ev.cancel();
|
||||
}
|
||||
}
|
||||
);
|
||||
return true;
|
||||
}
|
||||
case doHash("onItemTrySpawn"): {
|
||||
auto Call = RemoteCall::importAs<
|
||||
bool(const ItemStack* item, std::pair<Vec3, int> position, Actor* spawner)>(eventName, eventId);
|
||||
eventBus->emplaceListener<GMLIB::Event::EntityEvent::ItemActorSpawnBeforeEvent>(
|
||||
[Call](GMLIB::Event::EntityEvent::ItemActorSpawnBeforeEvent& ev) {
|
||||
auto pos = ev.getPosition();
|
||||
auto dimid = ev.getBlockSource().getDimensionId().id;
|
||||
std::pair<Vec3, int> lsePos = {pos, dimid};
|
||||
bool result = true;
|
||||
try {
|
||||
result = Call(&ev.getItem(), lsePos, ev.getSpawner());
|
||||
} catch (...) {}
|
||||
if (!result) {
|
||||
ev.cancel();
|
||||
}
|
||||
}
|
||||
);
|
||||
return true;
|
||||
}
|
||||
case doHash("onItemSpawned"): {
|
||||
auto Call = RemoteCall::importAs<
|
||||
bool(const ItemStack* item, Actor* itemActor, std::pair<Vec3, int> position, Actor* spawner)>(
|
||||
eventName,
|
||||
eventId
|
||||
);
|
||||
eventBus->emplaceListener<GMLIB::Event::EntityEvent::ItemActorSpawnAfterEvent>(
|
||||
[Call](GMLIB::Event::EntityEvent::ItemActorSpawnAfterEvent& ev) {
|
||||
auto pos = ev.getPosition();
|
||||
auto dimid = ev.getBlockSource().getDimensionId().id;
|
||||
std::pair<Vec3, int> lsePos = {pos, dimid};
|
||||
try {
|
||||
Call(&ev.getItem(), (Actor*)&ev.getItemActor(), lsePos, ev.getSpawner());
|
||||
} catch (...) {}
|
||||
}
|
||||
);
|
||||
return true;
|
||||
}
|
||||
case doHash("onEntityChangeDim"): {
|
||||
auto Call = RemoteCall::importAs<bool(Actor * entity, int toDimId)>(eventName, eventId);
|
||||
eventBus->emplaceListener<GMLIB::Event::EntityEvent::ActorChangeDimensionBeforeEvent>(
|
||||
[Call](GMLIB::Event::EntityEvent::ActorChangeDimensionBeforeEvent& ev) {
|
||||
bool result = true;
|
||||
try {
|
||||
result = Call(&ev.self(), ev.getToDimensionId());
|
||||
} catch (...) {}
|
||||
if (!result) {
|
||||
ev.cancel();
|
||||
}
|
||||
}
|
||||
);
|
||||
return true;
|
||||
}
|
||||
case doHash("onLeaveBed"): {
|
||||
auto Call = RemoteCall::importAs<bool(Player * pl)>(eventName, eventId);
|
||||
eventBus->emplaceListener<GMLIB::Event::PlayerEvent::PlayerStopSleepBeforeEvent>(
|
||||
[Call](GMLIB::Event::PlayerEvent::PlayerStopSleepBeforeEvent& ev) {
|
||||
bool result = true;
|
||||
try {
|
||||
result = Call(&ev.self());
|
||||
} catch (...) {}
|
||||
if (!result) {
|
||||
ev.cancel();
|
||||
}
|
||||
}
|
||||
);
|
||||
return true;
|
||||
}
|
||||
case doHash("onDeathMessage"): {
|
||||
auto Call = RemoteCall::importAs<bool(std::string message, std::vector<std::string>, Actor * dead)>(
|
||||
eventName,
|
||||
eventId
|
||||
);
|
||||
eventBus->emplaceListener<GMLIB::Event::EntityEvent::DeathMessageAfterEvent>(
|
||||
[Call](GMLIB::Event::EntityEvent::DeathMessageAfterEvent& ev) {
|
||||
auto msg = ev.getDeathMessage();
|
||||
auto source = ev.getDamageSource();
|
||||
try {
|
||||
Call(msg.first, msg.second, &ev.self());
|
||||
} catch (...) {}
|
||||
}
|
||||
);
|
||||
return true;
|
||||
}
|
||||
case doHash("onMobHurted"): {
|
||||
auto Call = RemoteCall::importAs<bool(Actor * mob, Actor * source, float damage, int cause)>(
|
||||
eventName,
|
||||
eventId
|
||||
);
|
||||
eventBus->emplaceListener<GMLIB::Event::EntityEvent::MobHurtAfterEvent>(
|
||||
[Call](GMLIB::Event::EntityEvent::MobHurtAfterEvent& ev) {
|
||||
auto& damageSource = ev.getSource();
|
||||
Actor* source = nullptr;
|
||||
if (damageSource.isEntitySource()) {
|
||||
auto uniqueId = damageSource.getDamagingEntityUniqueID();
|
||||
source = ll::service::getLevel()->fetchEntity(uniqueId);
|
||||
if (source->getOwner()) {
|
||||
source = source->getOwner();
|
||||
}
|
||||
}
|
||||
try {
|
||||
Call(&ev.self(), source, ev.getDamage(), (int)damageSource.getCause());
|
||||
} catch (...) {}
|
||||
}
|
||||
);
|
||||
return true;
|
||||
}
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
);
|
||||
}
|
||||
+4
-2
@@ -1,13 +1,15 @@
|
||||
#pragma once
|
||||
#include <include_all.h>
|
||||
|
||||
#include <RemoteCallAPI.h>
|
||||
|
||||
#define PLUGIN_NAME "GMLIB-LRCA"
|
||||
#define LIB_VERSION SemVersion(0, 9, 0, "", "")
|
||||
#define LIB_VERSION GMLIB::Version(0, 10, 0)
|
||||
|
||||
extern ll::Logger logger;
|
||||
|
||||
extern void Export_Legacy_GMLib_ModAPI();
|
||||
extern void Export_Legacy_GMLib_ServerAPI();
|
||||
extern void Export_Compatibility_API();
|
||||
extern void ExportPAPI();
|
||||
extern void ExportPAPI();
|
||||
extern void Export_Event_API();
|
||||
+20
-20
@@ -22,7 +22,7 @@ void Export_Legacy_GMLib_ModAPI() {
|
||||
std::string result,
|
||||
int count,
|
||||
std::string unlock) -> void {
|
||||
auto level = GMLIB_Level::getLevel();
|
||||
auto level = GMLIB_Level::getInstance();
|
||||
if (!level) {
|
||||
return;
|
||||
}
|
||||
@@ -33,7 +33,7 @@ void Export_Legacy_GMLib_ModAPI() {
|
||||
}
|
||||
auto res = RecipeIngredient(result, 0, count);
|
||||
auto unl = makeRecipeUnlockingKey(unlock);
|
||||
GMLIB::Mod::CustomRecipe::registerShapelessCraftingTableRecipe(recipe_id, types, res, unl);
|
||||
GMLIB::Mod::JsonRecipe::registerShapelessCraftingTableRecipe(recipe_id, types, res, unl);
|
||||
}
|
||||
);
|
||||
RemoteCall::exportAs(
|
||||
@@ -45,7 +45,7 @@ void Export_Legacy_GMLib_ModAPI() {
|
||||
std::string result,
|
||||
int count,
|
||||
std::string unlock) -> void {
|
||||
auto level = GMLIB_Level::getLevel();
|
||||
auto level = GMLIB_Level::getInstance();
|
||||
if (!level) {
|
||||
return;
|
||||
}
|
||||
@@ -56,46 +56,46 @@ void Export_Legacy_GMLib_ModAPI() {
|
||||
}
|
||||
auto res = RecipeIngredient(result, 0, count);
|
||||
auto unl = makeRecipeUnlockingKey(unlock);
|
||||
GMLIB::Mod::CustomRecipe::registerShapedCraftingTableRecipe(recipe_id, shape, types, res, unl);
|
||||
GMLIB::Mod::JsonRecipe::registerShapedCraftingTableRecipe(recipe_id, shape, types, res, unl);
|
||||
}
|
||||
);
|
||||
RemoteCall::exportAs(
|
||||
"GMLib_ModAPI",
|
||||
"registerFurnaceRecipe",
|
||||
[](std::string recipe_id, std::string input, std::string output, std::vector<std::string> tags) -> void {
|
||||
auto level = GMLIB_Level::getLevel();
|
||||
auto level = GMLIB_Level::getInstance();
|
||||
if (!level) {
|
||||
return;
|
||||
}
|
||||
auto inp = RecipeIngredient(input, 0, 1);
|
||||
auto outp = RecipeIngredient(output, 0, 1);
|
||||
GMLIB::Mod::CustomRecipe::registerFurnaceRecipe(recipe_id, inp, outp, tags);
|
||||
GMLIB::Mod::JsonRecipe::registerFurnaceRecipe(recipe_id, inp, outp, tags);
|
||||
}
|
||||
);
|
||||
RemoteCall::exportAs(
|
||||
"GMLib_ModAPI",
|
||||
"registerBrewingMixRecipe",
|
||||
[](std::string recipe_id, std::string input, std::string output, std::string reagent) -> void {
|
||||
auto level = GMLIB_Level::getLevel();
|
||||
auto level = GMLIB_Level::getInstance();
|
||||
if (!level) {
|
||||
return;
|
||||
}
|
||||
auto rea = RecipeIngredient(reagent, 0, 1);
|
||||
GMLIB::Mod::CustomRecipe::registerBrewingMixRecipe(recipe_id, input, output, rea);
|
||||
GMLIB::Mod::JsonRecipe::registerBrewingMixRecipe(recipe_id, input, output, rea);
|
||||
}
|
||||
);
|
||||
RemoteCall::exportAs(
|
||||
"GMLib_ModAPI",
|
||||
"registerBrewingContainerRecipe",
|
||||
[](std::string recipe_id, std::string input, std::string output, std::string reagent) -> void {
|
||||
auto level = GMLIB_Level::getLevel();
|
||||
auto level = GMLIB_Level::getInstance();
|
||||
if (!level) {
|
||||
return;
|
||||
}
|
||||
auto inp = RecipeIngredient(input, 0, 1);
|
||||
auto outp = RecipeIngredient(output, 0, 1);
|
||||
auto rea = RecipeIngredient(reagent, 0, 1);
|
||||
GMLIB::Mod::CustomRecipe::registerBrewingContainerRecipe(recipe_id, inp, outp, rea);
|
||||
GMLIB::Mod::JsonRecipe::registerBrewingContainerRecipe(recipe_id, inp, outp, rea);
|
||||
}
|
||||
);
|
||||
RemoteCall::exportAs(
|
||||
@@ -106,11 +106,11 @@ void Export_Legacy_GMLib_ModAPI() {
|
||||
std::string base,
|
||||
std::string addition,
|
||||
std::string result) -> void {
|
||||
auto level = GMLIB_Level::getLevel();
|
||||
auto level = GMLIB_Level::getInstance();
|
||||
if (!level) {
|
||||
return;
|
||||
}
|
||||
GMLIB::Mod::CustomRecipe::registerSmithingTransformRecipe(
|
||||
GMLIB::Mod::JsonRecipe::registerSmithingTransformRecipe(
|
||||
recipe_id,
|
||||
smithing_template,
|
||||
base,
|
||||
@@ -123,11 +123,11 @@ void Export_Legacy_GMLib_ModAPI() {
|
||||
"GMLib_ModAPI",
|
||||
"registerSmithingTrimRecipe",
|
||||
[](std::string recipe_id, std::string smithing_template, std::string base, std::string addition) -> void {
|
||||
auto level = GMLIB_Level::getLevel();
|
||||
auto level = GMLIB_Level::getInstance();
|
||||
if (!level) {
|
||||
return;
|
||||
}
|
||||
GMLIB::Mod::CustomRecipe::registerSmithingTrimRecipe(recipe_id, smithing_template, base, addition);
|
||||
GMLIB::Mod::JsonRecipe::registerSmithingTrimRecipe(recipe_id, smithing_template, base, addition);
|
||||
}
|
||||
);
|
||||
RemoteCall::exportAs(
|
||||
@@ -139,13 +139,13 @@ void Export_Legacy_GMLib_ModAPI() {
|
||||
std::string output,
|
||||
int output_data,
|
||||
int output_count) -> void {
|
||||
auto level = GMLIB_Level::getLevel();
|
||||
auto level = GMLIB_Level::getInstance();
|
||||
if (!level) {
|
||||
return;
|
||||
}
|
||||
auto inp = RecipeIngredient(input, 0, 1);
|
||||
auto outp = RecipeIngredient(output, 0, 1);
|
||||
GMLIB::Mod::CustomRecipe::registerStoneCutterRecipe(recipe_id, inp, outp);
|
||||
GMLIB::Mod::JsonRecipe::registerStoneCutterRecipe(recipe_id, inp, outp);
|
||||
}
|
||||
);
|
||||
// 错误方块清理
|
||||
@@ -162,23 +162,23 @@ void Export_Legacy_GMLib_ModAPI() {
|
||||
}
|
||||
});
|
||||
RemoteCall::exportAs("GMLib_ModAPI", "setExperimentEnabled", [](int experiment_id, bool value) -> void {
|
||||
auto level = GMLIB_Level::getLevel();
|
||||
auto level = GMLIB_Level::getInstance();
|
||||
if (!level) {
|
||||
return;
|
||||
}
|
||||
auto map = GMLIB_Level::getAllExperiments();
|
||||
if (map.count(experiment_id)) {
|
||||
GMLIB_Level::getLevel()->setExperimentEnabled(((AllExperiments)experiment_id), value);
|
||||
GMLIB_Level::getInstance()->setExperimentEnabled(((AllExperiments)experiment_id), value);
|
||||
} else ll::Logger("Server").error("Experiment ID '{}' does not exist!", experiment_id);
|
||||
});
|
||||
RemoteCall::exportAs("GMLib_ModAPI", "getExperimentEnabled", [](int experiment_id) -> bool {
|
||||
auto level = GMLIB_Level::getLevel();
|
||||
auto level = GMLIB_Level::getInstance();
|
||||
if (!level) {
|
||||
return false;
|
||||
}
|
||||
auto map = GMLIB_Level::getAllExperiments();
|
||||
if (map.count(experiment_id)) {
|
||||
return GMLIB_Level::getLevel()->getExperimentEnabled(((AllExperiments)experiment_id));
|
||||
return GMLIB_Level::getInstance()->getExperimentEnabled(((AllExperiments)experiment_id));
|
||||
} else {
|
||||
ll::Logger("Server").error("Experiment ID '{}' does not exist!", experiment_id);
|
||||
return false;
|
||||
|
||||
@@ -13,14 +13,14 @@ void Export_Legacy_GMLib_ServerAPI() {
|
||||
RemoteCall::exportAs("GMLib_ServerAPI", "setForceTrustSkins", []() -> void { GMLIB_Level::setForceTrustSkin(); });
|
||||
RemoteCall::exportAs("GMLib_ServerAPI", "enableCoResourcePack", []() -> void { GMLIB_Level::setCoResourcePack(); });
|
||||
RemoteCall::exportAs("GMLib_ServerAPI", "getLevelName", []() -> std::string {
|
||||
auto level = GMLIB_Level::getLevel();
|
||||
auto level = GMLIB_Level::getInstance();
|
||||
if (!level) {
|
||||
return "";
|
||||
}
|
||||
return level->getLevelName();
|
||||
});
|
||||
RemoteCall::exportAs("GMLib_ServerAPI", "setLevelName", [](std::string name) -> void {
|
||||
auto level = GMLIB_Level::getLevel();
|
||||
auto level = GMLIB_Level::getInstance();
|
||||
if (!level) {
|
||||
return;
|
||||
}
|
||||
|
||||
+48
-82
@@ -3,114 +3,79 @@
|
||||
|
||||
namespace PAPIRemoteCall {
|
||||
|
||||
std::string removeBrackets(std::string a1) {
|
||||
a1.erase(a1.find_last_not_of("%") + 1);
|
||||
return a1;
|
||||
}
|
||||
|
||||
bool isParameters(std::string str) {
|
||||
std::regex reg("[<]([^<>]+)[>]");
|
||||
return std::regex_search(removeBrackets(str), reg);
|
||||
}
|
||||
|
||||
std::string GetValue(std::string const& from) { return GMLIB::Server::PlaceholderAPI::getValue(from); }
|
||||
|
||||
std::string GetValueWithPlayer(std::string const& a1, std::string const& a2) {
|
||||
return GMLIB::Server::PlaceholderAPI::getValue(a1, ll::service::bedrock::getLevel()->getPlayer(a2));
|
||||
}
|
||||
|
||||
std::string
|
||||
registerPlayerPlaceholder(std::string const& PluginName, std::string const& FuncName, std::string const& PAPIName) {
|
||||
bool registerPlayerPlaceholder(
|
||||
std::string const& PluginName,
|
||||
std::string const& FuncName,
|
||||
std::string const& PAPIName
|
||||
) {
|
||||
if (RemoteCall::hasFunc(PluginName, FuncName)) {
|
||||
if (isParameters(PAPIName)) {
|
||||
auto Call =
|
||||
RemoteCall::importAs<std::string(std::string const& arg, std::unordered_map<std::string, std::string>)>(
|
||||
PluginName,
|
||||
FuncName
|
||||
);
|
||||
GMLIB::Server::PlaceholderAPI::registerPlayerPlaceholder(
|
||||
PAPIName,
|
||||
[Call](Player* sp, std::unordered_map<std::string, std::string> map) {
|
||||
return Call(sp->getXuid(), map);
|
||||
},
|
||||
PluginName
|
||||
);
|
||||
} else {
|
||||
auto Call = RemoteCall::importAs<std::string(std::string const& arg)>(PluginName, FuncName);
|
||||
GMLIB::Server::PlaceholderAPI::registerPlayerPlaceholder(
|
||||
PAPIName,
|
||||
[Call](Player* sp) { return Call(sp->getXuid()); },
|
||||
PluginName
|
||||
);
|
||||
}
|
||||
} else {
|
||||
// logger.error("Function no find({}:{})", PluginName, FuncName);
|
||||
return "Function no find";
|
||||
auto Call = RemoteCall::importAs<std::string(Player * pl)>(PluginName, FuncName);
|
||||
GMLIB::Server::PlaceholderAPI::registerPlayerPlaceholder(
|
||||
PAPIName,
|
||||
[Call](Player* sp) { return Call(sp); },
|
||||
PluginName
|
||||
);
|
||||
return true;
|
||||
}
|
||||
return "Register Success";
|
||||
return false;
|
||||
}
|
||||
|
||||
std::string
|
||||
registerServerPlaceholder(std::string const& PluginName, std::string const& FuncName, std::string const& PAPIName) {
|
||||
bool registerServerPlaceholder(
|
||||
std::string const& PluginName,
|
||||
std::string const& FuncName,
|
||||
std::string const& PAPIName
|
||||
) {
|
||||
if (RemoteCall::hasFunc(PluginName, FuncName)) {
|
||||
if (isParameters(PAPIName)) {
|
||||
auto Call =
|
||||
RemoteCall::importAs<std::string(std::unordered_map<std::string, std::string>)>(PluginName, FuncName);
|
||||
GMLIB::Server::PlaceholderAPI::registerServerPlaceholder(
|
||||
PAPIName,
|
||||
[Call](std::unordered_map<std::string, std::string> map) { return Call(map); },
|
||||
PluginName
|
||||
);
|
||||
} else {
|
||||
auto Call = RemoteCall::importAs<std::string()>(PluginName, FuncName);
|
||||
GMLIB::Server::PlaceholderAPI::registerServerPlaceholder(
|
||||
PAPIName,
|
||||
[Call]() { return Call(); },
|
||||
PluginName
|
||||
);
|
||||
}
|
||||
} else {
|
||||
// logger.error("Function no find({}:{})", PluginName, FuncName);
|
||||
return "Function no find";
|
||||
auto Call = RemoteCall::importAs<std::string()>(PluginName, FuncName);
|
||||
GMLIB::Server::PlaceholderAPI::registerServerPlaceholder(
|
||||
PAPIName,
|
||||
[Call]() { return Call(); },
|
||||
PluginName
|
||||
);
|
||||
return true;
|
||||
}
|
||||
return "Register Success";
|
||||
return false;
|
||||
}
|
||||
|
||||
std::string registerStaticPlaceholder(
|
||||
bool registerStaticPlaceholder(
|
||||
std::string const& PluginName,
|
||||
std::string const& FuncName,
|
||||
std::string const& PAPIName,
|
||||
int num
|
||||
) {
|
||||
if (RemoteCall::hasFunc(PluginName, FuncName)) {
|
||||
if (isParameters(PAPIName)) {
|
||||
auto Call = RemoteCall::importAs<std::string()>(PluginName, FuncName);
|
||||
if (num == -1) {
|
||||
GMLIB::Server::PlaceholderAPI::registerStaticPlaceholder(
|
||||
PAPIName,
|
||||
[Call] { return Call(); },
|
||||
PluginName
|
||||
);
|
||||
} else {
|
||||
GMLIB::Server::PlaceholderAPI::registerStaticPlaceholder(
|
||||
PAPIName,
|
||||
num,
|
||||
[Call] { return Call(); },
|
||||
PluginName
|
||||
);
|
||||
}
|
||||
auto Call = RemoteCall::importAs<std::string()>(PluginName, FuncName);
|
||||
if (num == -1) {
|
||||
GMLIB::Server::PlaceholderAPI::registerStaticPlaceholder(
|
||||
PAPIName,
|
||||
[Call] { return Call(); },
|
||||
PluginName
|
||||
);
|
||||
} else {
|
||||
GMLIB::Server::PlaceholderAPI::registerStaticPlaceholder(
|
||||
PAPIName,
|
||||
num,
|
||||
[Call] { return Call(); },
|
||||
PluginName
|
||||
);
|
||||
}
|
||||
} else {
|
||||
// logger.error("Function no find({}:{})", PluginName, FuncName);
|
||||
return "Function no find";
|
||||
return true;
|
||||
}
|
||||
return "Register Success";
|
||||
return false;
|
||||
}
|
||||
|
||||
std::string translateString(std::string const& str, std::string const& xuid) {
|
||||
return GMLIB::Server::PlaceholderAPI::translate(str, ll::service::bedrock::getLevel()->getPlayerByXuid(xuid));
|
||||
std::string translateStringWithPlayer(std::string const& str, Player* pl) {
|
||||
return GMLIB::Server::PlaceholderAPI::translateString(str, pl);
|
||||
}
|
||||
|
||||
std::string translateString(std::string const& str) { return GMLIB::Server::PlaceholderAPI::translateString(str); }
|
||||
|
||||
bool unRegisterPlaceholder(std::string const& str) { return GMLIB::Server::PlaceholderAPI::unRegisterPlaceholder(str); }
|
||||
|
||||
std::vector<std::string> getAllPAPI() { return GMLIB::Server::PlaceholderAPI::getAllPAPI(); }
|
||||
@@ -127,6 +92,7 @@ void ExportPAPI() {
|
||||
EXPORTAPI(PAPIRemoteCall::GetValue);
|
||||
EXPORTAPI(PAPIRemoteCall::GetValueWithPlayer);
|
||||
EXPORTAPI(PAPIRemoteCall::translateString);
|
||||
EXPORTAPI(PAPIRemoteCall::translateStringWithPlayer);
|
||||
EXPORTAPI(PAPIRemoteCall::unRegisterPlaceholder);
|
||||
EXPORTAPI(PAPIRemoteCall::getAllPAPI);
|
||||
}
|
||||
@@ -0,0 +1,53 @@
|
||||
/**
|
||||
*
|
||||
* @name GMLIB_LRCA-Plugin-Template
|
||||
* @brief plugin template for GMLIB-LegacyRemoteCallApi
|
||||
*
|
||||
* @copyright Copyright (c) 2024 GroupMountain
|
||||
* GMLIB-LegacyRemoteCallApi <https://github.com/GroupMountain/GMLIB-LegacyRemoteCallApi/>
|
||||
*
|
||||
*/
|
||||
|
||||
const PluginInfo = {
|
||||
Name: "GMLIB_LRCA-Plugin-Template",
|
||||
Author: "your name",
|
||||
Version: "0.0.1"
|
||||
}
|
||||
|
||||
// 导入 API
|
||||
const { JsonConfig, JsonI18n } = require('./GMLIB-LegacyRemoteCallApi/lib/GMLIB_API-JS');
|
||||
|
||||
// 默认配置文件
|
||||
const defaultConfig = {
|
||||
"language": "zh_CN"
|
||||
};
|
||||
|
||||
// 默认语言文件
|
||||
const zh_CN = {
|
||||
"consolelog.loaded": "加载成功!",
|
||||
"consolelog.info": "插件作者: {1}, 当前版本: v{2}"
|
||||
};
|
||||
|
||||
// 初始化配置文件
|
||||
const config = new JsonConfig(`./plugins/${PluginInfo.Name}/config/config.json`, defaultConfig);
|
||||
|
||||
// 初始化 I18n
|
||||
const I18n = new JsonI18n(`./plugins/${PluginInfo.Name}/language/`, config.get("language"));
|
||||
I18n.loadLanguage("zh_CN", zh_CN); // 升级语言文件
|
||||
I18n.setDefaultLanguage("zh_CN"); // 设置I18n无法翻译时采用的默认语言
|
||||
|
||||
// I18n快捷翻译函数
|
||||
function tr(key, data = []) {
|
||||
return I18n.translate(key, data);
|
||||
}
|
||||
|
||||
// 监听服务器启动
|
||||
// 在无特殊说明的情况下,一切 MCAPI 都应该在服务器启动后访问。
|
||||
mc.listen("onServerStarted", () => {
|
||||
// 你的代码
|
||||
|
||||
|
||||
// 打印插件信息
|
||||
logger.info(tr("consolelog.loaded"));
|
||||
logger.info(tr("consolelog.info", [PluginInfo.Author, PluginInfo.Version]));
|
||||
});
|
||||
@@ -0,0 +1,3 @@
|
||||
{
|
||||
"language": "zh_CN"
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
{
|
||||
"consolelog.loaded": "加载成功!",
|
||||
"consolelog.info": "插件作者: {1}, 当前版本: v{2}"
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
{
|
||||
"entry": "GMLIB_LRCA-Plugin-Template.js",
|
||||
"name": "GMLIB_LRCA-Plugin-Template",
|
||||
"type": "lse-quickjs",
|
||||
"version": "0.0.1",
|
||||
"author": "Your Name",
|
||||
"description": "plugin description",
|
||||
"dependencies": [
|
||||
{
|
||||
"name": "legacy-script-engine-quickjs"
|
||||
},
|
||||
{
|
||||
"name": "GMLIB-LegacyRemoteCallApi"
|
||||
}
|
||||
]
|
||||
}
|
||||
+3
-3
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"format_version": 2,
|
||||
"tooth": "github.com/GroupMountain/GMLIB-LegacyRemoteCallApi",
|
||||
"version": "0.9.0",
|
||||
"version": "0.10.0",
|
||||
"info": {
|
||||
"name": "GMLIB-LegacyRemoteCallApi",
|
||||
"description": "Legacy RemoteCall API for GMLIB",
|
||||
@@ -14,9 +14,9 @@
|
||||
"library"
|
||||
]
|
||||
},
|
||||
"asset_url": "https://github.com/GroupMountain/GMLIB-LegacyRemoteCallApi/releases/download/v0.9.0/GMLIB-LegacyRemoteCallApi-windows-x64.zip",
|
||||
"asset_url": "https://github.com/GroupMountain/GMLIB-LegacyRemoteCallApi/releases/download/v0.10.0/GMLIB-LegacyRemoteCallApi-windows-x64.zip",
|
||||
"dependencies": {
|
||||
"github.com/GroupMountain/GMLIB": ">=0.9.0"
|
||||
"github.com/GroupMountain/GMLIB": ">=0.10.0"
|
||||
},
|
||||
"files": {
|
||||
"place": [
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
add_rules("mode.debug", "mode.release", "mode.releasedbg")
|
||||
add_rules("mode.debug", "mode.release")
|
||||
|
||||
add_repositories("liteldev-repo https://github.com/LiteLDev/xmake-repo.git")
|
||||
|
||||
@@ -47,7 +47,8 @@ target("GMLIB-LegacyRemoteCallApi") -- Change this to your plugin name.
|
||||
"/utf-8"
|
||||
)
|
||||
add_defines(
|
||||
"_HAS_CXX23=1" -- To enable C++23 features
|
||||
"NOMINMAX",
|
||||
"UNICODE"
|
||||
)
|
||||
add_files(
|
||||
"src/**.cpp"
|
||||
@@ -68,7 +69,8 @@ target("GMLIB-LegacyRemoteCallApi") -- Change this to your plugin name.
|
||||
)
|
||||
set_exceptions("none") -- To avoid conflicts with /EHa
|
||||
set_kind("shared")
|
||||
set_languages("cxx23")
|
||||
set_languages("c++23")
|
||||
set_symbols("debug")
|
||||
|
||||
after_build(function (target)
|
||||
local plugin_packer = import("scripts.after_build")
|
||||
|
||||
Reference in New Issue
Block a user