2020-01-14 09:44:20 +00:00
|
|
|
import { server } from '@ms/api'
|
2020-02-26 02:15:33 +00:00
|
|
|
import { provideSingleton } from '@ms/container';
|
2020-01-14 09:44:20 +00:00
|
|
|
|
2020-02-29 14:28:43 +00:00
|
|
|
import * as fs from '@ms/common/dist/fs'
|
|
|
|
|
|
|
|
const Sponge = org.spongepowered.api.Sponge;
|
|
|
|
const TextSerializers = org.spongepowered.api.text.serializer.TextSerializers;
|
|
|
|
const URL = Java.type("java.net.URL");
|
|
|
|
const File = Java.type("java.io.File");
|
2020-01-14 09:44:20 +00:00
|
|
|
|
2020-02-26 02:15:33 +00:00
|
|
|
@provideSingleton(server.Server)
|
2020-01-14 09:44:20 +00:00
|
|
|
export class SpongeServer implements server.Server {
|
2020-03-01 07:19:43 +00:00
|
|
|
private pluginsFolder: string;
|
|
|
|
|
|
|
|
constructor() {
|
|
|
|
this.pluginsFolder = new File(base.getInstance().getClass().getProtectionDomain().getCodeSource().getLocation().getPath()).getParentFile().getCanonicalPath()
|
|
|
|
}
|
|
|
|
|
2020-01-14 09:44:20 +00:00
|
|
|
getPlayer(name: string) {
|
|
|
|
return Sponge.getServer().getPlayer(name).orElse(null)
|
|
|
|
}
|
|
|
|
getVersion(): string {
|
|
|
|
return `${Sponge.getPlatform().getImplementation().getName()} (${Sponge.getPlatform().getImplementation().getVersion()})`
|
|
|
|
}
|
|
|
|
getOnlinePlayers() {
|
|
|
|
return Sponge.getServer().getOnlinePlayers()
|
|
|
|
}
|
|
|
|
getConsoleSender() {
|
|
|
|
return Sponge.getServer().getConsole()
|
|
|
|
}
|
|
|
|
getService(service: string) {
|
|
|
|
return Sponge.getServiceManager().provide(base.getClass(service)).orElse(null)
|
|
|
|
}
|
|
|
|
dispatchCommand(sender: string | any, command: string): boolean {
|
|
|
|
if (typeof sender === 'string') {
|
|
|
|
sender = this.getPlayer(sender)
|
|
|
|
}
|
|
|
|
return Sponge.getCommandManager().process(sender, command).getQueryResult()
|
|
|
|
}
|
|
|
|
dispatchConsoleCommand(command: string): boolean {
|
|
|
|
return Sponge.getCommandManager().process(Sponge.getServer().getConsole(), command).getQueryResult()
|
|
|
|
}
|
2020-02-29 14:28:43 +00:00
|
|
|
getPluginsFolder(): string {
|
2020-03-01 07:19:43 +00:00
|
|
|
return this.pluginsFolder;
|
|
|
|
}
|
|
|
|
getNativePluginManager() {
|
|
|
|
throw new Error("Method not implemented.");
|
2020-02-29 14:28:43 +00:00
|
|
|
}
|
2020-01-14 09:44:20 +00:00
|
|
|
sendJson(sender: string | any, json: string): void {
|
|
|
|
if (typeof sender === "string") {
|
|
|
|
sender = this.getPlayer(sender)
|
|
|
|
}
|
|
|
|
sender.sendMessage(TextSerializers.JSON.deserialize(json))
|
|
|
|
}
|
|
|
|
}
|