feat: compatible brower behavior
Signed-off-by: MiaoWoo <admin@yumc.pw>
This commit is contained in:
@ -1,80 +1,80 @@
|
||||
import { command, plugin } from "@ccms/api";
|
||||
import { inject, provideSingleton } from "@ccms/container";
|
||||
import { command, plugin } from "@ccms/api"
|
||||
import { inject, provideSingleton } from "@ccms/container"
|
||||
|
||||
let Sponge = Java.type('org.spongepowered.api.Sponge');
|
||||
let Text = Java.type('org.spongepowered.api.text.Text');
|
||||
var CommandCallable = Java.type('org.spongepowered.api.command.CommandCallable');
|
||||
var CommandResult = Java.type('org.spongepowered.api.command.CommandResult');
|
||||
var Optional = Java.type('java.util.Optional');
|
||||
let Sponge = Java.type('org.spongepowered.api.Sponge')
|
||||
let Text = Java.type('org.spongepowered.api.text.Text')
|
||||
var CommandCallable = Java.type('org.spongepowered.api.command.CommandCallable')
|
||||
var CommandResult = Java.type('org.spongepowered.api.command.CommandResult')
|
||||
var Optional = Java.type('java.util.Optional')
|
||||
|
||||
@provideSingleton(command.Command)
|
||||
export class SpongeCommand extends command.Command {
|
||||
@inject(plugin.PluginInstance)
|
||||
private pluginInstance: any
|
||||
private commandMapping: any[] = [];
|
||||
private commandMapping: any[] = []
|
||||
|
||||
create(plugin: any, command: string) {
|
||||
let commandKey = this.getCommandKey(plugin, command);
|
||||
let commandCallable = new SimpleCommandCallable(command);
|
||||
this.commandMapping[commandKey] = Sponge.getCommandManager().register(this.pluginInstance, commandCallable.callable, command, commandKey).orElse(null);
|
||||
return commandCallable;
|
||||
let commandKey = this.getCommandKey(plugin, command)
|
||||
let commandCallable = new SimpleCommandCallable(command)
|
||||
this.commandMapping[commandKey] = Sponge.getCommandManager().register(this.pluginInstance, commandCallable.callable, command, commandKey).orElse(null)
|
||||
return commandCallable
|
||||
}
|
||||
remove(plugin: any, command: string) {
|
||||
var commandKey = this.getCommandKey(plugin, command);
|
||||
var commandKey = this.getCommandKey(plugin, command)
|
||||
if (this.commandMapping[commandKey]) {
|
||||
Sponge.getCommandManager().removeMapping(this.commandMapping[commandKey]);
|
||||
delete this.commandMapping[commandKey];
|
||||
Sponge.getCommandManager().removeMapping(this.commandMapping[commandKey])
|
||||
delete this.commandMapping[commandKey]
|
||||
}
|
||||
}
|
||||
onCommand(plugin: any, command: any, executor: Function) {
|
||||
command.setExecutor(super.setExecutor(plugin, command, executor));
|
||||
onCommand(plugin: plugin.Plugin, command: any, executor: Function) {
|
||||
command.setExecutor(super.setExecutor(plugin, command, executor))
|
||||
}
|
||||
onTabComplete(plugin: any, command: any, tabCompleter: Function) {
|
||||
command.setTabCompleter(super.setTabCompleter(plugin, command, tabCompleter));
|
||||
onTabComplete(plugin: plugin.Plugin, command: any, tabCompleter: Function) {
|
||||
command.setTabCompleter(super.setTabCompleter(plugin, command, tabCompleter))
|
||||
}
|
||||
|
||||
private getCommandKey(plugin: any, command: string) {
|
||||
return plugin.description.name.toLowerCase() + ":" + command;
|
||||
return plugin.description.name.toLowerCase() + ":" + command
|
||||
}
|
||||
}
|
||||
|
||||
class SimpleCommandCallable {
|
||||
public callable: any;
|
||||
private name: string;
|
||||
private executor: Function;
|
||||
private tabCompleter: Function;
|
||||
public callable: any
|
||||
private name: string
|
||||
private executor: Function
|
||||
private tabCompleter: Function
|
||||
|
||||
constructor(command: string, description: string = '暂无描述!') {
|
||||
this.name = command;
|
||||
this.name = command
|
||||
this.callable = new CommandCallable({
|
||||
//CommandResult process(CommandSource source, String arguments) throws CommandException;
|
||||
//CommandResult process(CommandSource source, String arguments) throws CommandException
|
||||
process: (sender: any, args) => {
|
||||
return this.executor(sender, '', command, Java.to(args.split(" ").filter(e => e))) ? CommandResult.success() : CommandResult.empty();
|
||||
return this.executor(sender, '', command, Java.to(args.split(" ").filter(e => e))) ? CommandResult.success() : CommandResult.empty()
|
||||
},
|
||||
//List<String> getSuggestions(CommandSource source, String arguments, @Nullable Location<World> targetPosition) throws CommandException;
|
||||
//List<String> getSuggestions(CommandSource source, String arguments, @Nullable Location<World> targetPosition) throws CommandException
|
||||
getSuggestions: (sender: any, args, target) => {
|
||||
return this.tabCompleter(sender, '', command, Java.to(args.split(" ").filter(e => e)));
|
||||
return this.tabCompleter(sender, '', command, Java.to(args.split(" ").filter(e => e)))
|
||||
},
|
||||
//boolean testPermission(CommandSource source);
|
||||
//boolean testPermission(CommandSource source)
|
||||
testPermission: () => {
|
||||
return true;
|
||||
return true
|
||||
},
|
||||
//Optional<Text> getShortDescription(CommandSource source);
|
||||
//Optional<Text> getShortDescription(CommandSource source)
|
||||
getShortDescription: () => {
|
||||
return Optional.of(Text.of(description));
|
||||
return Optional.of(Text.of(description))
|
||||
},
|
||||
//Optional<Text> getHelp(CommandSource source);
|
||||
//Optional<Text> getHelp(CommandSource source)
|
||||
getHelp: () => {
|
||||
return Optional.of(Text.of(""));
|
||||
return Optional.of(Text.of(""))
|
||||
},
|
||||
//Text getUsage(CommandSource source);
|
||||
//Text getUsage(CommandSource source)
|
||||
getUsage: () => {
|
||||
return Text.of('');
|
||||
return Text.of('')
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
setExecutor = (executor: Function) => this.executor = executor;
|
||||
setTabCompleter = (tabCompleter: Function) => this.tabCompleter = tabCompleter;
|
||||
setExecutor = (executor: Function) => this.executor = executor
|
||||
setTabCompleter = (tabCompleter: Function) => this.tabCompleter = tabCompleter
|
||||
toString = () => `Sponge SimpleCommandCallable(${this.name})`
|
||||
}
|
@ -1,17 +1,17 @@
|
||||
import { task, plugin } from '@ccms/api'
|
||||
import { inject, provideSingleton, postConstruct } from '@ccms/container';
|
||||
import { inject, provideSingleton, postConstruct } from '@ccms/container'
|
||||
|
||||
const Sponge = Java.type("org.spongepowered.api.Sponge");
|
||||
const Task = Java.type("org.spongepowered.api.scheduler.Task");
|
||||
const Consumer = Java.type('java.util.function.Consumer');
|
||||
const Callable = Java.type('java.util.concurrent.Callable');
|
||||
const TimeUnit = Java.type('java.util.concurrent.TimeUnit');
|
||||
const Sponge = Java.type("org.spongepowered.api.Sponge")
|
||||
const Task = Java.type("org.spongepowered.api.scheduler.Task")
|
||||
const Consumer = Java.type('java.util.function.Consumer')
|
||||
const Callable = Java.type('java.util.concurrent.Callable')
|
||||
const TimeUnit = Java.type('java.util.concurrent.TimeUnit')
|
||||
|
||||
@provideSingleton(task.TaskManager)
|
||||
export class SpongeTaskManager implements task.TaskManager {
|
||||
@inject(plugin.PluginInstance)
|
||||
private pluginInstance: any;
|
||||
private syncExecutor: any;
|
||||
private pluginInstance: any
|
||||
private syncExecutor: any
|
||||
|
||||
@postConstruct()
|
||||
initialize() {
|
||||
@ -19,8 +19,8 @@ export class SpongeTaskManager implements task.TaskManager {
|
||||
}
|
||||
|
||||
create(func: Function): task.Task {
|
||||
if (Object.prototype.toString.call(func) !== "[object Function]") { throw TypeError('第一个参数 Task 必须为 function !'); };
|
||||
return new SpongeTask(this.pluginInstance, func);
|
||||
if (Object.prototype.toString.call(func) !== "[object Function]") { throw TypeError('第一个参数 Task 必须为 function !') }
|
||||
return new SpongeTask(this.pluginInstance, func)
|
||||
}
|
||||
callSyncMethod(func: Function): any {
|
||||
// @ts-ignore
|
||||
@ -32,10 +32,8 @@ export class SpongeTaskManager implements task.TaskManager {
|
||||
}
|
||||
|
||||
export class SpongeTask extends task.Task {
|
||||
submit(): task.Cancelable {
|
||||
let run = Task.builder().execute(new Consumer({
|
||||
accept: () => this.run()
|
||||
}));
|
||||
submit(...args: any[]): task.Cancelable {
|
||||
let run = Task.builder().execute(new Consumer({ accept: () => this.run(...args) }))
|
||||
if (this.isAsync) { run.async() }
|
||||
if (this.laterTime) { run.delayTicks(this.laterTime) }
|
||||
if (this.interval) { run.intervalTicks(this.interval) }
|
||||
|
Reference in New Issue
Block a user