-
Notifications
You must be signed in to change notification settings - Fork 30
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
55 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
This folder contains example macros that can be used as a starting point for creating your own macros. | ||
|
||
Note: make sure your macro is in the correct format. The macro should be a folder with the `index.ts` or `index.js` file at the root of the folder as the entry point. | ||
|
||
PRs are welcome! If you have a macro you'd like to share, feel free to create a PR to add it to this folder. | ||
|
||
Read more about creating macros [here](https://github.com/Lodestone-Team/lodestone/wiki/Intro-to-Macro-and-Task) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
import { format } from "https://deno.land/std@0.177.1/datetime/format.ts"; | ||
import { copy } from "https://deno.land/std@0.191.0/fs/copy.ts"; | ||
import { sleep } from "https://deno.land/x/sleep@v1.2.1/mod.ts"; | ||
import { EventStream } from "https://raw.githubusercontent.com/Lodestone-Team/lodestone-macro-lib/main/events.ts"; | ||
import { lodestoneVersion } from "https://raw.githubusercontent.com/Lodestone-Team/lodestone-macro-lib/main/prelude.ts"; | ||
import { MinecraftJavaInstance } from "https://raw.githubusercontent.com/Lodestone-Team/lodestone-macro-lib/main/instance.ts"; | ||
|
||
const currentInstance = await MinecraftJavaInstance.current(); | ||
|
||
const eventStream = new EventStream( | ||
currentInstance.getUUID(), | ||
await currentInstance.name() | ||
); | ||
|
||
// Lodestone will parse the configuration class and inject the configuration into the macro | ||
class LodestoneConfig { | ||
// Where to store the backups relative to the instance path | ||
backupFolderRelative: string = "backups"; | ||
// How long to wait between backups in seconds | ||
delaySec: number = 3600; | ||
} | ||
|
||
// not technically necessary, but it's a good practice to appease the linter | ||
declare const config: LodestoneConfig; | ||
|
||
// make sure the config is injected properly | ||
console.log(config); | ||
|
||
const instancePath = await currentInstance.path(); | ||
const backupFolder = `${instancePath}/${config.backupFolderRelative}`; | ||
EventStream.emitDetach(); | ||
while (true) { | ||
eventStream.emitConsoleOut("[Backup Macro] Backing up world..."); | ||
if ((await currentInstance.state()) == "Stopped") { | ||
eventStream.emitConsoleOut("[Backup Macro] Instance stopped, exiting..."); | ||
break; | ||
} | ||
|
||
const now = new Date(); | ||
const now_str = format(now, "yy-MM-dd_HH"); | ||
try { | ||
await copy(`${instancePath}/world`, `${backupFolder}/backup_${now_str}`); | ||
} catch (e) { | ||
console.log(e); | ||
} | ||
|
||
await sleep(config.delaySec); | ||
} |