feat: 添加 GC 命令
This commit is contained in:
@@ -1,9 +1,7 @@
|
|||||||
package cn.hamster3.mc.plugin.core.bukkit;
|
package cn.hamster3.mc.plugin.core.bukkit;
|
||||||
|
|
||||||
import cn.hamster3.mc.plugin.core.bukkit.api.CoreBukkitAPI;
|
import cn.hamster3.mc.plugin.core.bukkit.api.CoreBukkitAPI;
|
||||||
import cn.hamster3.mc.plugin.core.bukkit.command.ParentCommand;
|
import cn.hamster3.mc.plugin.core.bukkit.command.core.ParentCoreCommand;
|
||||||
import cn.hamster3.mc.plugin.core.bukkit.command.debug.BlockInfoCommand;
|
|
||||||
import cn.hamster3.mc.plugin.core.bukkit.command.debug.YamlCommand;
|
|
||||||
import cn.hamster3.mc.plugin.core.bukkit.command.lore.ParentLoreCommand;
|
import cn.hamster3.mc.plugin.core.bukkit.command.lore.ParentLoreCommand;
|
||||||
import cn.hamster3.mc.plugin.core.bukkit.hook.PointAPI;
|
import cn.hamster3.mc.plugin.core.bukkit.hook.PointAPI;
|
||||||
import cn.hamster3.mc.plugin.core.bukkit.hook.VaultAPI;
|
import cn.hamster3.mc.plugin.core.bukkit.hook.VaultAPI;
|
||||||
@@ -13,15 +11,11 @@ import cn.hamster3.mc.plugin.core.bukkit.page.listener.PageListener;
|
|||||||
import cn.hamster3.mc.plugin.core.common.constant.CoreConstantObjects;
|
import cn.hamster3.mc.plugin.core.common.constant.CoreConstantObjects;
|
||||||
import net.kyori.adventure.platform.bukkit.BukkitAudiences;
|
import net.kyori.adventure.platform.bukkit.BukkitAudiences;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.command.Command;
|
|
||||||
import org.bukkit.command.CommandSender;
|
|
||||||
import org.bukkit.plugin.java.JavaPlugin;
|
import org.bukkit.plugin.java.JavaPlugin;
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.logging.Logger;
|
import java.util.logging.Logger;
|
||||||
|
|
||||||
public class HamsterCorePlugin extends JavaPlugin {
|
public class HamsterCorePlugin extends JavaPlugin {
|
||||||
public static final ParentCommand COMMAND_EXECUTOR = new ParentCommand("core");
|
|
||||||
private static HamsterCorePlugin instance;
|
private static HamsterCorePlugin instance;
|
||||||
|
|
||||||
private BukkitAudiences audienceProvider;
|
private BukkitAudiences audienceProvider;
|
||||||
@@ -42,12 +36,6 @@ public class HamsterCorePlugin extends JavaPlugin {
|
|||||||
logger.info("仓鼠核心正在初始化...");
|
logger.info("仓鼠核心正在初始化...");
|
||||||
CoreBukkitAPI.init();
|
CoreBukkitAPI.init();
|
||||||
logger.info("CoreBukkitAPI 已初始化.");
|
logger.info("CoreBukkitAPI 已初始化.");
|
||||||
COMMAND_EXECUTOR.addChildCommand(BlockInfoCommand.INSTANCE);
|
|
||||||
logger.info("已添加指令: " + BlockInfoCommand.INSTANCE.getName() + " .");
|
|
||||||
COMMAND_EXECUTOR.addChildCommand(YamlCommand.INSTANCE);
|
|
||||||
logger.info("已添加指令: " + YamlCommand.INSTANCE.getName() + " .");
|
|
||||||
COMMAND_EXECUTOR.addChildCommand(ParentLoreCommand.INSTANCE);
|
|
||||||
logger.info("已添加指令: " + ParentLoreCommand.INSTANCE.getName() + " .");
|
|
||||||
long time = System.currentTimeMillis() - start;
|
long time = System.currentTimeMillis() - start;
|
||||||
logger.info("仓鼠核心初始化完成,总计耗时 " + time + " ms.");
|
logger.info("仓鼠核心初始化完成,总计耗时 " + time + " ms.");
|
||||||
}
|
}
|
||||||
@@ -69,6 +57,9 @@ public class HamsterCorePlugin extends JavaPlugin {
|
|||||||
logger.info("已注册 CallbackListener.");
|
logger.info("已注册 CallbackListener.");
|
||||||
Bukkit.getPluginManager().registerEvents(DebugListener.INSTANCE, this);
|
Bukkit.getPluginManager().registerEvents(DebugListener.INSTANCE, this);
|
||||||
logger.info("已注册 DebugListener.");
|
logger.info("已注册 DebugListener.");
|
||||||
|
//noinspection SpellCheckingInspection
|
||||||
|
ParentCoreCommand.INSTANCE.hook(getCommand("hamstercore"));
|
||||||
|
ParentLoreCommand.INSTANCE.hook(getCommand("lore"));
|
||||||
long time = System.currentTimeMillis() - start;
|
long time = System.currentTimeMillis() - start;
|
||||||
logger.info("仓鼠核心启动完成,总计耗时 " + time + " ms.");
|
logger.info("仓鼠核心启动完成,总计耗时 " + time + " ms.");
|
||||||
}
|
}
|
||||||
@@ -86,16 +77,6 @@ public class HamsterCorePlugin extends JavaPlugin {
|
|||||||
logger.info("仓鼠核心已关闭,总计耗时 " + time + " ms.");
|
logger.info("仓鼠核心已关闭,总计耗时 " + time + " ms.");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
|
|
||||||
return COMMAND_EXECUTOR.onCommand(sender, command, label, args);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public List<String> onTabComplete(CommandSender sender, Command command, String alias, String[] args) {
|
|
||||||
return COMMAND_EXECUTOR.onTabComplete(sender, command, alias, args);
|
|
||||||
}
|
|
||||||
|
|
||||||
public BukkitAudiences getAudienceProvider() {
|
public BukkitAudiences getAudienceProvider() {
|
||||||
return audienceProvider;
|
return audienceProvider;
|
||||||
}
|
}
|
||||||
|
@@ -3,6 +3,8 @@ package cn.hamster3.mc.plugin.core.bukkit.command;
|
|||||||
import cn.hamster3.mc.plugin.core.bukkit.constant.CoreMessage;
|
import cn.hamster3.mc.plugin.core.bukkit.constant.CoreMessage;
|
||||||
import org.bukkit.command.Command;
|
import org.bukkit.command.Command;
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
|
import org.bukkit.command.PluginCommand;
|
||||||
|
import org.bukkit.plugin.Plugin;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
@@ -11,6 +13,8 @@ import java.util.stream.Collectors;
|
|||||||
|
|
||||||
@SuppressWarnings("unused")
|
@SuppressWarnings("unused")
|
||||||
public class ParentCommand extends ChildCommand {
|
public class ParentCommand extends ChildCommand {
|
||||||
|
@NotNull
|
||||||
|
private final Plugin plugin;
|
||||||
@NotNull
|
@NotNull
|
||||||
private final String name;
|
private final String name;
|
||||||
@Nullable
|
@Nullable
|
||||||
@@ -18,13 +22,15 @@ public class ParentCommand extends ChildCommand {
|
|||||||
@NotNull
|
@NotNull
|
||||||
private final List<ChildCommand> childCommands;
|
private final List<ChildCommand> childCommands;
|
||||||
|
|
||||||
public ParentCommand(@NotNull String name) {
|
public ParentCommand(@NotNull Plugin plugin, @NotNull String name) {
|
||||||
|
this.plugin = plugin;
|
||||||
this.name = name;
|
this.name = name;
|
||||||
parent = null;
|
parent = null;
|
||||||
childCommands = new ArrayList<>();
|
childCommands = new ArrayList<>();
|
||||||
}
|
}
|
||||||
|
|
||||||
public ParentCommand(@NotNull String name, @Nullable ParentCommand parent) {
|
public ParentCommand(@NotNull Plugin plugin, @NotNull String name, @Nullable ParentCommand parent) {
|
||||||
|
this.plugin = plugin;
|
||||||
this.name = name;
|
this.name = name;
|
||||||
this.parent = parent;
|
this.parent = parent;
|
||||||
childCommands = new ArrayList<>();
|
childCommands = new ArrayList<>();
|
||||||
@@ -73,8 +79,10 @@ public class ParentCommand extends ChildCommand {
|
|||||||
|
|
||||||
public void addChildCommand(@NotNull ChildCommand command) {
|
public void addChildCommand(@NotNull ChildCommand command) {
|
||||||
childCommands.add(command);
|
childCommands.add(command);
|
||||||
|
plugin.getLogger().info("已为 " + getUsage() + " 添加子命令: " + command.getName() + " .");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@NotNull
|
||||||
public Map<String, String> getCommandHelp(CommandSender sender) {
|
public Map<String, String> getCommandHelp(CommandSender sender) {
|
||||||
HashMap<String, String> map = new HashMap<>();
|
HashMap<String, String> map = new HashMap<>();
|
||||||
for (ChildCommand child : childCommands) {
|
for (ChildCommand child : childCommands) {
|
||||||
@@ -91,6 +99,12 @@ public class ParentCommand extends ChildCommand {
|
|||||||
return map;
|
return map;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void hook(@NotNull PluginCommand command) {
|
||||||
|
command.setExecutor(this);
|
||||||
|
command.setTabCompleter(this);
|
||||||
|
plugin.getLogger().info("已注册指令 " + getUsage() + ".");
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
|
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
|
||||||
if (args.length == 0) {
|
if (args.length == 0) {
|
||||||
|
@@ -1,4 +1,4 @@
|
|||||||
package cn.hamster3.mc.plugin.core.bukkit.command.debug;
|
package cn.hamster3.mc.plugin.core.bukkit.command.core;
|
||||||
|
|
||||||
import cn.hamster3.mc.plugin.core.bukkit.command.ChildCommand;
|
import cn.hamster3.mc.plugin.core.bukkit.command.ChildCommand;
|
||||||
import cn.hamster3.mc.plugin.core.bukkit.constant.CoreMessage;
|
import cn.hamster3.mc.plugin.core.bukkit.constant.CoreMessage;
|
@@ -0,0 +1,48 @@
|
|||||||
|
package cn.hamster3.mc.plugin.core.bukkit.command.core;
|
||||||
|
|
||||||
|
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;
|
||||||
|
|
||||||
|
public class GCCommand extends ChildCommand {
|
||||||
|
public static final GCCommand INSTANCE = new GCCommand();
|
||||||
|
|
||||||
|
private GCCommand() {
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public @NotNull String getName() {
|
||||||
|
return "gc";
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public @NotNull String getUsage() {
|
||||||
|
return "gc";
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean hasPermission(@NotNull CommandSender sender) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public @NotNull String getDescription() {
|
||||||
|
return "通知JVM进行一次垃圾回收";
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
|
||||||
|
System.gc();
|
||||||
|
sender.sendMessage("§a已发送 GC 信号.");
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<String> onTabComplete(CommandSender sender, Command command, String alias, String[] args) {
|
||||||
|
return Collections.emptyList();
|
||||||
|
}
|
||||||
|
}
|
@@ -0,0 +1,15 @@
|
|||||||
|
package cn.hamster3.mc.plugin.core.bukkit.command.core;
|
||||||
|
|
||||||
|
import cn.hamster3.mc.plugin.core.bukkit.HamsterCorePlugin;
|
||||||
|
import cn.hamster3.mc.plugin.core.bukkit.command.ParentCommand;
|
||||||
|
|
||||||
|
public class ParentCoreCommand extends ParentCommand {
|
||||||
|
public static final ParentCoreCommand INSTANCE = new ParentCoreCommand();
|
||||||
|
|
||||||
|
private ParentCoreCommand() {
|
||||||
|
super(HamsterCorePlugin.getInstance(), "core");
|
||||||
|
addChildCommand(YamlCommand.INSTANCE);
|
||||||
|
addChildCommand(GCCommand.INSTANCE);
|
||||||
|
addChildCommand(BlockInfoCommand.INSTANCE);
|
||||||
|
}
|
||||||
|
}
|
@@ -1,4 +1,4 @@
|
|||||||
package cn.hamster3.mc.plugin.core.bukkit.command.debug;
|
package cn.hamster3.mc.plugin.core.bukkit.command.core;
|
||||||
|
|
||||||
import cn.hamster3.mc.plugin.core.bukkit.HamsterCorePlugin;
|
import cn.hamster3.mc.plugin.core.bukkit.HamsterCorePlugin;
|
||||||
import cn.hamster3.mc.plugin.core.bukkit.command.ChildCommand;
|
import cn.hamster3.mc.plugin.core.bukkit.command.ChildCommand;
|
@@ -5,14 +5,12 @@ import cn.hamster3.mc.plugin.core.bukkit.command.ParentCommand;
|
|||||||
import cn.hamster3.mc.plugin.core.common.util.CommonUtils;
|
import cn.hamster3.mc.plugin.core.common.util.CommonUtils;
|
||||||
import org.bukkit.command.Command;
|
import org.bukkit.command.Command;
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
import org.jetbrains.annotations.NotNull;
|
|
||||||
import org.jetbrains.annotations.Nullable;
|
|
||||||
|
|
||||||
public final class ParentLoreCommand extends ParentCommand {
|
public final class ParentLoreCommand extends ParentCommand {
|
||||||
public static final ParentLoreCommand INSTANCE = new ParentLoreCommand("lore", HamsterCorePlugin.COMMAND_EXECUTOR);
|
public static final ParentLoreCommand INSTANCE = new ParentLoreCommand();
|
||||||
|
|
||||||
private ParentLoreCommand(@NotNull String name, @Nullable ParentCommand parent) {
|
public ParentLoreCommand() {
|
||||||
super(name, parent);
|
super(HamsterCorePlugin.getInstance(), "lore");
|
||||||
addChildCommand(LoreAddCommand.INSTANCE);
|
addChildCommand(LoreAddCommand.INSTANCE);
|
||||||
addChildCommand(LoreRemoveCommand.INSTANCE);
|
addChildCommand(LoreRemoveCommand.INSTANCE);
|
||||||
addChildCommand(LoreSetCommand.INSTANCE);
|
addChildCommand(LoreSetCommand.INSTANCE);
|
||||||
|
@@ -16,6 +16,10 @@ commands:
|
|||||||
description: 仓鼠核心调试指令
|
description: 仓鼠核心调试指令
|
||||||
permission: hamster.core.admin
|
permission: hamster.core.admin
|
||||||
permission-message: §c你没有这个权限!
|
permission-message: §c你没有这个权限!
|
||||||
|
lore:
|
||||||
|
description: 仓鼠核心的 lore 修改指令
|
||||||
|
permission: hamster.lore.admin
|
||||||
|
permission-message: §c你没有这个权限!
|
||||||
|
|
||||||
permissions:
|
permissions:
|
||||||
hamster.core.admin:
|
hamster.core.admin:
|
||||||
|
Reference in New Issue
Block a user