feat(hamster-core-bukkit): 添加指令
This commit is contained in:
@@ -16,7 +16,8 @@ public class ParentCoreCommand extends ParentCommand {
|
|||||||
addChildCommand(YamlCommand.INSTANCE);
|
addChildCommand(YamlCommand.INSTANCE);
|
||||||
addChildCommand(InfoModeCommand.INSTANCE);
|
addChildCommand(InfoModeCommand.INSTANCE);
|
||||||
addChildCommand(ReloadCommand.INSTANCE);
|
addChildCommand(ReloadCommand.INSTANCE);
|
||||||
addChildCommand(RuntimeCommand.INSTANCE);
|
addChildCommand(MemoryCommand.INSTANCE);
|
||||||
|
addChildCommand(SystemCommand.INSTANCE);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@@ -7,6 +7,7 @@ import org.jetbrains.annotations.NotNull;
|
|||||||
|
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
public class EnvCommand extends ChildCommand {
|
public class EnvCommand extends ChildCommand {
|
||||||
public static final EnvCommand INSTANCE = new EnvCommand();
|
public static final EnvCommand INSTANCE = new EnvCommand();
|
||||||
@@ -46,6 +47,13 @@ public class EnvCommand extends ChildCommand {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<String> onTabComplete(@NotNull CommandSender sender, @NotNull Command command, @NotNull String alias, String[] args) {
|
public List<String> onTabComplete(@NotNull CommandSender sender, @NotNull Command command, @NotNull String alias, String[] args) {
|
||||||
|
if (args.length == 1) {
|
||||||
|
String lowerCase = args[0].toLowerCase();
|
||||||
|
return System.getenv().keySet()
|
||||||
|
.stream()
|
||||||
|
.filter(o -> o.startsWith(lowerCase))
|
||||||
|
.collect(Collectors.toList());
|
||||||
|
}
|
||||||
return Collections.emptyList();
|
return Collections.emptyList();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -31,7 +31,7 @@ public class GCCommand extends ChildCommand {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public @NotNull String getDescription() {
|
public @NotNull String getDescription() {
|
||||||
return "通知JVM进行一次垃圾回收";
|
return "通知 JVM 进行一次垃圾回收";
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@@ -8,20 +8,20 @@ import org.jetbrains.annotations.NotNull;
|
|||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public class RuntimeCommand extends ChildCommand {
|
public class MemoryCommand extends ChildCommand {
|
||||||
public static final RuntimeCommand INSTANCE = new RuntimeCommand();
|
public static final MemoryCommand INSTANCE = new MemoryCommand();
|
||||||
|
|
||||||
private RuntimeCommand() {
|
private MemoryCommand() {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public @NotNull String getName() {
|
public @NotNull String getName() {
|
||||||
return "runtime";
|
return "memory";
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public @NotNull String getUsage() {
|
public @NotNull String getUsage() {
|
||||||
return "runtime";
|
return "memory";
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -31,15 +31,16 @@ public class RuntimeCommand extends ChildCommand {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public @NotNull String getDescription() {
|
public @NotNull String getDescription() {
|
||||||
return "查看JVM信息";
|
return "查看内存信息";
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, String[] args) {
|
public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, String[] args) {
|
||||||
Runtime runtime = Runtime.getRuntime();
|
Runtime runtime = Runtime.getRuntime();
|
||||||
sender.sendMessage("空闲内存:" + runtime.freeMemory() / 1024.0);
|
sender.sendMessage(String.format("活跃内存:%.2f MB", (runtime.totalMemory() - runtime.freeMemory()) / 1024.0 / 1024.0));
|
||||||
sender.sendMessage("已用内存:" + runtime.totalMemory() / 1024.0);
|
sender.sendMessage(String.format("空闲内存:%.2f MB", runtime.freeMemory() / 1024.0 / 1024.0));
|
||||||
sender.sendMessage("最大可用内存:" + runtime.maxMemory() / 1024.0);
|
sender.sendMessage(String.format("占用系统内存:%.2f MB", runtime.totalMemory() / 1024.0 / 1024.0));
|
||||||
|
sender.sendMessage(String.format("最大可用内存:%.2f MB", runtime.maxMemory() / 1024.0 / 1024.0));
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
@@ -0,0 +1,60 @@
|
|||||||
|
package cn.hamster3.mc.plugin.core.bukkit.command.core.sub;
|
||||||
|
|
||||||
|
import cn.hamster3.mc.plugin.core.bukkit.command.ChildCommand;
|
||||||
|
import org.bukkit.command.Command;
|
||||||
|
import org.bukkit.command.CommandSender;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
|
import java.util.Collections;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
|
public class SystemCommand extends ChildCommand {
|
||||||
|
public static final SystemCommand INSTANCE = new SystemCommand();
|
||||||
|
|
||||||
|
private SystemCommand() {
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public @NotNull String getName() {
|
||||||
|
return "system";
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public @NotNull String getUsage() {
|
||||||
|
return "system";
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean hasPermission(@NotNull CommandSender sender) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public @NotNull String getDescription() {
|
||||||
|
return "查看系统属性";
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, String[] args) {
|
||||||
|
if (args.length < 1) {
|
||||||
|
sender.sendMessage(System.getProperties().toString());
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
sender.sendMessage(args[0] + "=" + System.getProperty(args[0], ""));
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<String> onTabComplete(@NotNull CommandSender sender, @NotNull Command command, @NotNull String alias, String[] args) {
|
||||||
|
if (args.length == 1) {
|
||||||
|
String lowerCase = args[0].toLowerCase();
|
||||||
|
return System.getProperties().keySet()
|
||||||
|
.stream()
|
||||||
|
.map(Object::toString)
|
||||||
|
.filter(o -> o.startsWith(lowerCase))
|
||||||
|
.collect(Collectors.toList());
|
||||||
|
}
|
||||||
|
return Collections.emptyList();
|
||||||
|
}
|
||||||
|
}
|
Reference in New Issue
Block a user