feat: update example plugin

Signed-off-by: MiaoWoo <admin@yumc.pw>
This commit is contained in:
MiaoWoo 2020-02-15 19:40:25 +08:00
parent 982e14953c
commit cc96519e80

View File

@ -2,18 +2,23 @@
/// <reference types="@ms/types/dist/typings/sponge" /> /// <reference types="@ms/types/dist/typings/sponge" />
/// <reference types="@ms/types/dist/typings/bungee" /> /// <reference types="@ms/types/dist/typings/bungee" />
import { server } from '@ms/api';
import { inject } from '@ms/container';
import { plugin, interfaces, cmd, listener, tab } from '@ms/plugin' import { plugin, interfaces, cmd, listener, tab } from '@ms/plugin'
@plugin({ name: 'HelloWorld', version: '1.0.0', author: 'MiaoWoo', source: __filename }) @plugin({ name: 'HelloWorld', version: '1.0.0', author: 'MiaoWoo', source: __filename })
export class HelloWorld extends interfaces.Plugin { export class HelloWorld extends interfaces.Plugin {
@inject(server.Server)
private Server: server.Server
load() { load() {
this.logger.log('Test Plugin load from MiaoScript Plugin System...'); this.logger.log('Plugin load from MiaoScript Plugin System...');
} }
enable() { enable() {
this.logger.log('Test Plugin enable from MiaoScript Plugin System...'); this.logger.log('Plugin enable from MiaoScript Plugin System...');
} }
disable() { disable() {
this.logger.log('Test Plugin disable from MiaoScript Plugin System...'); this.logger.log('Plugin disable from MiaoScript Plugin System...');
} }
bukkitload() { bukkitload() {
@ -61,13 +66,18 @@ export class HelloWorld extends interfaces.Plugin {
PlayerJoin(event: org.bukkit.event.player.PlayerJoinEvent) { PlayerJoin(event: org.bukkit.event.player.PlayerJoinEvent) {
let plyaer = event.getPlayer(); let plyaer = event.getPlayer();
this.logger.console(`§cBukkit §aPlayerJoinEvent: §b${plyaer.getName()}`) this.logger.console(`§cBukkit §aPlayerJoinEvent: §b${plyaer.getName()}`)
setTimeout(() => this.logger.sender(plyaer, `§a欢迎来到 §bMiaoScript §a的世界!`), 10); setTimeout(() => this.sendWelcome(plyaer), 10);
} }
@listener({ servers: ['sponge'] }) @listener({ servers: ['sponge'] })
ClientConnectionEvent$Join(event: org.spongepowered.api.event.network.ClientConnectionEvent.Join) { ClientConnectionEvent$Join(event: org.spongepowered.api.event.network.ClientConnectionEvent.Join) {
this.logger.console(`§cSponge §aClientConnectionEvent.Join: §b${event.getTargetEntity().getName()}`) this.logger.console(`§cSponge §aClientConnectionEvent.Join: §b${event.getTargetEntity().getName()}`)
setTimeout(() => this.logger.sender(event.getTargetEntity(), `§a欢迎来到 §bMiaoScript §a的世界!`), 10); setTimeout(() => this.sendWelcome(event.getTargetEntity()), 10);
}
private sendWelcome(player: any) {
this.logger.sender(player, `§a欢迎来到 §bMiaoScript §a的世界!`)
this.logger.sender(player, `§6当前版本: §c${this.Server.getVersion()}`)
} }
@listener({ servers: ['bungee'] }) @listener({ servers: ['bungee'] })
@ -76,10 +86,4 @@ export class HelloWorld extends interfaces.Plugin {
this.logger.console(`§cBungeeCord §aServerConnectedEvent: §b${event.getPlayer().getDisplayName()}`) this.logger.console(`§cBungeeCord §aServerConnectedEvent: §b${event.getPlayer().getDisplayName()}`)
setTimeout(() => this.logger.sender(event.getPlayer(), `§a欢迎来到 §bMiaoScript §a的世界 §6来自 §cBungeeCord §6的问候!`), 10); setTimeout(() => this.logger.sender(event.getPlayer(), `§a欢迎来到 §bMiaoScript §a的世界 §6来自 §cBungeeCord §6的问候!`), 10);
} }
@listener({ servers: ["bungee"] })
PluginMessage(e: any) {
let event = e as net.md_5.bungee.api.event.PluginMessageEvent
this.logger.console(`§cBungeeCord §aPluginMessageEvent: §b${event.getTag()}`)
}
} }