Skip to content
This repository has been archived by the owner on Jan 28, 2023. It is now read-only.

Commit

Permalink
Add Console Command Example
Browse files Browse the repository at this point in the history
  • Loading branch information
xiaoshen committed May 18, 2020
1 parent 6765867 commit 46fe097
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 0 deletions.
Binary file modified .DS_Store
Binary file not shown.
63 changes: 63 additions & 0 deletions markdown/Console Command.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
# Console Command

## Java

## 新的Console Command

```java
import cc.moecraft.icq.pluginmanager.console.ConsoleCommand;

public class MyConsoleCommand implements ConsoleCommand {
@Override
//传入 args
//如果输入为 /print a b c
// args = ["a", "b", "c"]
public void onCommand(String[] args) {
if (args.length == 0) {
MyPlugin.logger.log("没有参数");
} else {
// 打印第一个参数
MyPlugin.logger.log("Print " + args[0]);
}
}
}

```

## 主类注册

```java
import cc.moecraft.icq.command.interfaces.IcqCommand;
import cc.moecraft.icq.event.IcqListener;
import cc.moecraft.icq.pluginmanager.plugin.IcqPlugin;
import cc.moecraft.logger.HyLogger;
import jdk.nashorn.internal.objects.annotations.Getter;

public class MyPlugin extends IcqPlugin {

public static HyLogger logger;

@Override
public IcqCommand[] commands() {
return new IcqCommand[0];
}

@Override
public IcqListener[] listeners() {
return new IcqListener[0];
}

@Override
public void onEnable() {
logger = this.getLogger();
//"print" 为指令的名字, MyConsoleCommand() 为我们刚刚创建的
this.getConsoleCommandManager().addCommand("print", new MyConsoleCommand());
}

@Override
public void onDisable() {

}
}
```

0 comments on commit 46fe097

Please sign in to comment.