@@ -5,6 +5,7 @@ import { DefaultContainer as container } from '@ms/container'
 | 
			
		||||
 | 
			
		||||
import { SpongeConsole } from './console';
 | 
			
		||||
import { SpongeEvent } from './event';
 | 
			
		||||
import { SpongeServer } from './server';
 | 
			
		||||
import { SpongeCommand } from './command';
 | 
			
		||||
import { SpongeTaskManager } from './task';
 | 
			
		||||
 | 
			
		||||
@@ -16,7 +17,6 @@ container.bind(server.ServerType).toConstantValue(SpongeServerType);
 | 
			
		||||
container.bind(plugin.PluginInstance).toConstantValue(Sponge.getPluginManager().getPlugin('MiaoScript').orElse(null));
 | 
			
		||||
 | 
			
		||||
container.bind(event.Event).to(SpongeEvent).inSingletonScope();
 | 
			
		||||
container.bind(server.Server).to(SpongeServer).inSingletonScope();
 | 
			
		||||
container.bind(command.Command).to(SpongeCommand).inSingletonScope();
 | 
			
		||||
container.bind(task.TaskManager).to(SpongeTaskManager).inSingletonScope();
 | 
			
		||||
 | 
			
		||||
console.debug(`Detect Sponge Compatible set ServerType to ${SpongeServerType} ...`)
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										39
									
								
								packages/sponge/src/server.ts
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										39
									
								
								packages/sponge/src/server.ts
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,39 @@
 | 
			
		||||
import { server } from '@ms/api'
 | 
			
		||||
import { injectable } from '@ms/container';
 | 
			
		||||
 | 
			
		||||
let Sponge = org.spongepowered.api.Sponge;
 | 
			
		||||
let TextSerializers = org.spongepowered.api.text.serializer.TextSerializers;
 | 
			
		||||
 | 
			
		||||
@injectable()
 | 
			
		||||
export class SpongeServer implements server.Server {
 | 
			
		||||
    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()
 | 
			
		||||
    }
 | 
			
		||||
    sendJson(sender: string | any, json: string): void {
 | 
			
		||||
        if (typeof sender === "string") {
 | 
			
		||||
            sender = this.getPlayer(sender)
 | 
			
		||||
        }
 | 
			
		||||
        sender.sendMessage(TextSerializers.JSON.deserialize(json))
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
		Reference in New Issue
	
	Block a user