Add `server` global to JS runtime
This PR adds a server global to the JavaScript runtime.
Currently it has these properties and methods:
-
port -
getMotd() -
shutdown()
I want to add a lot more before merging the PR. Please comment with whatever properties / methods should be added.
Well, there's a lot of methods, these I think are most important
-
banIp(String address) -
broadcast(String message, String permission) -
broadcastMessage(String message) -
createInventory(...) -
dispatchCommand(CommandSender, String commandLine)(maybe move this toServerCommands?) -
getWorlds() -
reload() -
reloadData() -
reloadWhitelist() -
setWhitelist(boolean value) -
setWhitelistEnforced(boolean value) -
unbanIP(String address)
I agree with most of the methods that AL1L proposed, however I think that i would be a good idea to also add this.
-
getPluginManager()(and it would be a great idea to add some of the methods of this class) -
createWorld() -
getWorld() -
getPlayer() -
getOfflinePlayer() -
getOfflinePlayers() -
getLogger()(and some of the basic methods of the class)
For create world and create inventory, what about moving those to static methods on their classes? Or even somehow letting you do new Inventory() and new World()
And for bans, maybe those should be static methods on the Players class.
I never really liked the way Bukkit designed their API, and I don't see a compelling enough reason to stick to exactly how they do things. It's just not JavaScript-like (what's the JS equivalent of Pythonic? lol)
I agree, I think we should add most of these, but the ones that involve Player or World or other types could cause confusion, since the @customrealms/core library has wrappers around those, and we can't assume those wrappers in the runtime.
Also all of these things can already be done, for example: Java.resolve('org.bukkit.Bukkit').reload(). So exposing them through a server global is just a convenience thing for those functions that are most likely to be needed.
I say we think about this a little longer and don't rush to add it. Or maybe change it to process and mirror some of the NodeJS functionality.
This is superseded by the new Bukkit variable that users have access to from https://github.com/customrealms/core
For example...
import { Bukkit } from '@customrealms/core';
Bukkit.getOnlinePlayers();
Bukkit.reload();