bukkit-runtime icon indicating copy to clipboard operation
bukkit-runtime copied to clipboard

Add `server` global to JS runtime

Open connerdouglass opened this issue 4 years ago • 4 comments

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.

connerdouglass avatar Nov 24 '21 03:11 connerdouglass

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 to ServerCommands?)
  • getWorlds()
  • reload()
  • reloadData()
  • reloadWhitelist()
  • setWhitelist(boolean value)
  • setWhitelistEnforced(boolean value)
  • unbanIP(String address)

AL1L avatar Nov 24 '21 16:11 AL1L

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)

Ftsos avatar Nov 25 '21 02:11 Ftsos

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)

AL1L avatar Nov 25 '21 02:11 AL1L

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.

connerdouglass avatar Nov 25 '21 02:11 connerdouglass

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();

connerdouglass avatar Jun 20 '24 21:06 connerdouglass