forked from PrismarineJS/flying-squid
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add gamerules support: basic data parsing, now possible to cont…
…rol/change them via /gamerule only these gamerules effect implemented: doDaylightCycle fix: better messaging from output commands (now green)
- Loading branch information
Showing
6 changed files
with
65 additions
and
12 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
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
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
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
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,41 @@ | ||
export const server = function (serv: Server, options: Options) { | ||
serv.gamerules ??= {} | ||
serv.on('asap', () => { | ||
for (const [key, val] of Object.entries(serv.levelData?.GameRules ?? {})) { | ||
serv.gamerules[key] = val === 'true' | ||
} | ||
}) | ||
|
||
const gameRules = { | ||
'doDayLightCycle': 'Wether to enable daylight cycle' | ||
} | ||
|
||
serv.commands.add({ | ||
base: 'gamerule', | ||
info: '', | ||
usage: '/gamerule <gamerule> <true|false>', | ||
op: true, | ||
parse (string, ctx) { | ||
return string.split(' ') | ||
}, | ||
action (data, ctx) { | ||
const [rule, newVal] = data | ||
if (!rule) { | ||
return `Available these gamerules: ${Object.entries(gameRules).map(([key, desc]) => `${key}: ${desc}`).join(', ')}` | ||
} | ||
if (newVal) { | ||
serv.gameMode[rule] = newVal === 'false' ? false : true | ||
return `set ${rule} to ${serv.gamerules[rule]}` | ||
} else { | ||
const gamerule = serv.gamerules[rule] | ||
return `${rule} is ${gamerule ? 'Enabled' : 'Disabled'} (${gamerule})` | ||
} | ||
} | ||
}) | ||
} | ||
|
||
declare global { | ||
interface Server { | ||
gamerules: Record<string, boolean> | ||
} | ||
} |
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