perf: 优化代码
This commit is contained in:
@@ -1,8 +1,9 @@
|
||||
package cn.hamster3.mc.plugin.core.bukkit;
|
||||
|
||||
import cn.hamster3.mc.plugin.core.bukkit.api.CoreBukkitAPI;
|
||||
import cn.hamster3.mc.plugin.core.bukkit.command.core.ParentCoreCommand;
|
||||
import cn.hamster3.mc.plugin.core.bukkit.command.lore.ParentLoreCommand;
|
||||
import cn.hamster3.mc.plugin.core.bukkit.command.core.CoreCommand;
|
||||
import cn.hamster3.mc.plugin.core.bukkit.command.lore.LoreCommand;
|
||||
import cn.hamster3.mc.plugin.core.bukkit.command.nbt.NBTCommand;
|
||||
import cn.hamster3.mc.plugin.core.bukkit.constant.CoreMessage;
|
||||
import cn.hamster3.mc.plugin.core.bukkit.hook.PointAPI;
|
||||
import cn.hamster3.mc.plugin.core.bukkit.hook.VaultAPI;
|
||||
@@ -40,7 +41,7 @@ public class HamsterCorePlugin extends JavaPlugin {
|
||||
logger.info("已读取配置文件.");
|
||||
CoreBukkitAPI.init();
|
||||
logger.info("已初始化 CoreAPI.");
|
||||
CoreMessage.init(getLogger(), getConfig().getConfigurationSection("messages"));
|
||||
CoreMessage.init(this);
|
||||
logger.info("已初始化语言文本.");
|
||||
long time = System.currentTimeMillis() - start;
|
||||
logger.info("仓鼠核心初始化完成,总计耗时 " + time + " ms.");
|
||||
@@ -59,8 +60,9 @@ public class HamsterCorePlugin extends JavaPlugin {
|
||||
logger.info("已注册 CallbackListener.");
|
||||
Bukkit.getPluginManager().registerEvents(DebugListener.INSTANCE, this);
|
||||
logger.info("已注册 DebugListener.");
|
||||
ParentCoreCommand.INSTANCE.register();
|
||||
ParentLoreCommand.INSTANCE.register();
|
||||
CoreCommand.INSTANCE.register();
|
||||
LoreCommand.INSTANCE.register();
|
||||
NBTCommand.INSTANCE.register();
|
||||
long time = System.currentTimeMillis() - start;
|
||||
Bukkit.getScheduler().runTaskLater(this, () -> {
|
||||
PointAPI.reloadPlayerPointAPIHook();
|
||||
|
@@ -31,7 +31,7 @@ public final class CoreBukkitAPI extends CoreAPI {
|
||||
|
||||
ConfigurationSection datasourceConfig = config.getConfigurationSection("datasource");
|
||||
if (datasourceConfig == null) {
|
||||
throw new IllegalArgumentException("配置文件中未找到 datasource 节点!");
|
||||
throw new IllegalArgumentException("配置文件中未找到 datasource 节点");
|
||||
}
|
||||
|
||||
HikariConfig hikariConfig = new HikariConfig();
|
||||
|
@@ -6,10 +6,10 @@ import cn.hamster3.mc.plugin.core.bukkit.command.core.sub.*;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class ParentCoreCommand extends ParentCommand {
|
||||
public static final ParentCoreCommand INSTANCE = new ParentCoreCommand();
|
||||
public class CoreCommand extends ParentCommand {
|
||||
public static final CoreCommand INSTANCE = new CoreCommand();
|
||||
|
||||
private ParentCoreCommand() {
|
||||
private CoreCommand() {
|
||||
addChildCommand(EnvCommand.INSTANCE);
|
||||
addChildCommand(GCCommand.INSTANCE);
|
||||
addChildCommand(YamlCommand.INSTANCE);
|
@@ -52,23 +52,25 @@ public class InfoModeCommand extends ChildCommand {
|
||||
case "1":
|
||||
case "on": {
|
||||
DebugListener.INFO_MODE_PLAYERS.add(uuid);
|
||||
CoreMessage.COMMAND_DEBUG_INFO_MODE_ON.show(player);
|
||||
return true;
|
||||
break;
|
||||
}
|
||||
case "0":
|
||||
case "off": {
|
||||
DebugListener.INFO_MODE_PLAYERS.remove(uuid);
|
||||
CoreMessage.COMMAND_DEBUG_INFO_MODE_OFF.show(player);
|
||||
return true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (DebugListener.INFO_MODE_PLAYERS.contains(uuid)) {
|
||||
DebugListener.INFO_MODE_PLAYERS.remove(uuid);
|
||||
} else {
|
||||
DebugListener.INFO_MODE_PLAYERS.add(uuid);
|
||||
}
|
||||
}
|
||||
|
||||
if (DebugListener.INFO_MODE_PLAYERS.contains(uuid)) {
|
||||
DebugListener.INFO_MODE_PLAYERS.remove(uuid);
|
||||
CoreMessage.COMMAND_DEBUG_INFO_MODE_OFF.show(player);
|
||||
} else {
|
||||
DebugListener.INFO_MODE_PLAYERS.add(uuid);
|
||||
CoreMessage.COMMAND_DEBUG_INFO_MODE_ON.show(player);
|
||||
}
|
||||
return true;
|
||||
|
@@ -8,10 +8,10 @@ import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public final class ParentLoreCommand extends ParentCommand {
|
||||
public static final ParentLoreCommand INSTANCE = new ParentLoreCommand();
|
||||
public final class LoreCommand extends ParentCommand {
|
||||
public static final LoreCommand INSTANCE = new LoreCommand();
|
||||
|
||||
public ParentLoreCommand() {
|
||||
public LoreCommand() {
|
||||
addChildCommand(LoreAddCommand.INSTANCE);
|
||||
addChildCommand(LoreRemoveCommand.INSTANCE);
|
||||
addChildCommand(LoreSetCommand.INSTANCE);
|
||||
@@ -23,7 +23,7 @@ public final class ParentLoreCommand extends ParentCommand {
|
||||
|
||||
@Override
|
||||
public @NotNull String getName() {
|
||||
return "lore";
|
||||
return "hamster-lore";
|
||||
}
|
||||
|
||||
@Override
|
@@ -43,7 +43,7 @@ public class LoreAddCommand extends ChildCommand {
|
||||
@Override
|
||||
public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, String[] args) {
|
||||
if (args.length < 1) {
|
||||
CoreMessage.COMMAND_LORE_EMPTY_INPUT.show(sender);
|
||||
CoreMessage.COMMAND_LORE_ADD_NOT_INPUT.show(sender);
|
||||
return true;
|
||||
}
|
||||
if (!(sender instanceof Player)) {
|
||||
|
@@ -3,6 +3,7 @@ package cn.hamster3.mc.plugin.core.bukkit.command.lore.sub;
|
||||
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.util.CoreBukkitUtils;
|
||||
import net.kyori.adventure.text.TextReplacementConfig;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
@@ -38,14 +39,14 @@ public class LoreFlagCommand extends ChildCommand {
|
||||
|
||||
@Override
|
||||
public @NotNull String getDescription() {
|
||||
return "为手持物品添加一条 lore";
|
||||
return "为手持物品设置 flag";
|
||||
}
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
@Override
|
||||
public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, String[] args) {
|
||||
if (args.length < 1) {
|
||||
CoreMessage.COMMAND_LORE_EMPTY_INPUT.show(sender);
|
||||
CoreMessage.COMMAND_LORE_ADD_NOT_INPUT.show(sender);
|
||||
return true;
|
||||
}
|
||||
if (!(sender instanceof Player)) {
|
||||
@@ -62,7 +63,7 @@ public class LoreFlagCommand extends ChildCommand {
|
||||
try {
|
||||
flag = ItemFlag.valueOf(args[0]);
|
||||
} catch (IllegalArgumentException e) {
|
||||
CoreMessage.COMMAND_LORE_FLAG_SET_INPUT_ERROR.show(player);
|
||||
CoreMessage.COMMAND_LORE_FLAG_SET_ERROR_INPUT.show(player);
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -70,10 +71,16 @@ public class LoreFlagCommand extends ChildCommand {
|
||||
if (meta != null) {
|
||||
if (meta.hasItemFlag(flag)) {
|
||||
meta.removeItemFlags(flag);
|
||||
CoreMessage.COMMAND_LORE_FLAG_REMOVE_SUCCESS.show(player);
|
||||
CoreMessage.COMMAND_LORE_FLAG_REMOVE_SUCCESS.show(player, TextReplacementConfig.builder()
|
||||
.replacement("%flag%")
|
||||
.matchLiteral(flag.name())
|
||||
.build());
|
||||
} else {
|
||||
meta.addItemFlags(flag);
|
||||
CoreMessage.COMMAND_LORE_FLAG_SET_SUCCESS.show(player);
|
||||
CoreMessage.COMMAND_LORE_FLAG_SET_SUCCESS.show(player, TextReplacementConfig.builder()
|
||||
.replacement("%flag%")
|
||||
.matchLiteral(flag.name())
|
||||
.build());
|
||||
}
|
||||
}
|
||||
stack.setItemMeta(meta);
|
||||
|
@@ -42,7 +42,7 @@ public class LoreNameCommand extends ChildCommand {
|
||||
@Override
|
||||
public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, String[] args) {
|
||||
if (args.length < 1) {
|
||||
CoreMessage.COMMAND_LORE_EMPTY_INPUT.show(sender);
|
||||
CoreMessage.COMMAND_LORE_NAME_NOT_INPUT.show(sender);
|
||||
return true;
|
||||
}
|
||||
if (!(sender instanceof Player)) {
|
||||
|
@@ -10,7 +10,6 @@ import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.ItemMeta;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class LoreRemoveCommand extends ChildCommand {
|
||||
@@ -42,19 +41,10 @@ public class LoreRemoveCommand extends ChildCommand {
|
||||
@SuppressWarnings("deprecation")
|
||||
@Override
|
||||
public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, String[] args) {
|
||||
if (args.length < 1) {
|
||||
CoreMessage.COMMAND_LORE_REMOVE_NOT_INPUT_NUMBER.show(sender);
|
||||
return true;
|
||||
}
|
||||
if (!(sender instanceof Player)) {
|
||||
CoreMessage.COMMAND_MUST_USED_BY_PLAYER.show(sender);
|
||||
return true;
|
||||
}
|
||||
int i = Integer.parseInt(args[0]);
|
||||
if (i <= 0) {
|
||||
CoreMessage.COMMAND_LORE_REMOVE_INPUT_NUMBER_ERROR.show(sender);
|
||||
return true;
|
||||
}
|
||||
Player player = (Player) sender;
|
||||
ItemStack stack = player.getItemInHand();
|
||||
if (CoreBukkitUtils.isEmptyItemStack(stack)) {
|
||||
@@ -62,18 +52,30 @@ public class LoreRemoveCommand extends ChildCommand {
|
||||
return true;
|
||||
}
|
||||
ItemMeta meta = stack.getItemMeta();
|
||||
if (meta != null) {
|
||||
if (meta == null) {
|
||||
CoreMessage.COMMAND_LORE_REMOVE_NOTHING.show(player);
|
||||
return true;
|
||||
}
|
||||
List<String> lore = meta.getLore();
|
||||
if (lore == null) {
|
||||
lore = new ArrayList<>();
|
||||
CoreMessage.COMMAND_LORE_REMOVE_NOTHING.show(player);
|
||||
return true;
|
||||
}
|
||||
if (args.length < 1) {
|
||||
lore.remove(lore.size() - 1);
|
||||
} else {
|
||||
int i = Integer.parseInt(args[0]);
|
||||
if (i <= 0) {
|
||||
CoreMessage.COMMAND_LORE_REMOVE_INPUT_NUMBER_ERROR.show(sender);
|
||||
return true;
|
||||
}
|
||||
if (lore.size() < i) {
|
||||
CoreMessage.COMMAND_LORE_REMOVE_INDEX_OUT_OF_RANGE.show(player);
|
||||
return true;
|
||||
}
|
||||
lore.remove(i - 1);
|
||||
meta.setLore(lore);
|
||||
}
|
||||
meta.setLore(lore);
|
||||
stack.setItemMeta(meta);
|
||||
CoreMessage.COMMAND_LORE_REMOVE_SUCCESS.show(player);
|
||||
return true;
|
||||
|
@@ -0,0 +1,23 @@
|
||||
package cn.hamster3.mc.plugin.core.bukkit.command.nbt;
|
||||
|
||||
import cn.hamster3.mc.plugin.core.bukkit.HamsterCorePlugin;
|
||||
import cn.hamster3.mc.plugin.core.bukkit.command.ParentCommand;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class NBTCommand extends ParentCommand {
|
||||
public static final NBTCommand INSTANCE = new NBTCommand();
|
||||
|
||||
private NBTCommand() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull JavaPlugin getPlugin() {
|
||||
return HamsterCorePlugin.getInstance();
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull String getName() {
|
||||
return "hamster-nbt";
|
||||
}
|
||||
}
|
@@ -7,59 +7,94 @@ import net.kyori.adventure.audience.Audience;
|
||||
import net.kyori.adventure.text.TextReplacementConfig;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.configuration.ConfigurationSection;
|
||||
import org.bukkit.configuration.file.YamlConfiguration;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.logging.Logger;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
|
||||
public enum CoreMessage {
|
||||
COMMAND_NOT_FOUND,
|
||||
COMMAND_NOT_HAS_PERMISSION,
|
||||
COMMAND_MUST_USED_BY_PLAYER,
|
||||
COMMAND_DEBUG_INFO_MODE_ON,
|
||||
COMMAND_DEBUG_INFO_MODE_OFF,
|
||||
COMMAND_LORE_HAND_EMPTY,
|
||||
COMMAND_LORE_EMPTY_INPUT,
|
||||
COMMAND_LORE_ADD_SUCCESS,
|
||||
COMMAND_LORE_CLEAR_NOTHING,
|
||||
COMMAND_LORE_CLEAR_SUCCESS,
|
||||
COMMAND_LORE_CMD_CLEAR_SUCCESS,
|
||||
COMMAND_LORE_CMD_SET_SUCCESS,
|
||||
COMMAND_LORE_CMD_SET_INPUT_ERROR,
|
||||
COMMAND_LORE_FLAG_SET_SUCCESS,
|
||||
COMMAND_LORE_FLAG_REMOVE_SUCCESS,
|
||||
COMMAND_LORE_FLAG_SET_INPUT_ERROR,
|
||||
COMMAND_LORE_NAME_SUCCESS,
|
||||
COMMAND_LORE_REMOVE_NOT_INPUT_NUMBER,
|
||||
COMMAND_LORE_REMOVE_INPUT_NUMBER_ERROR,
|
||||
COMMAND_LORE_REMOVE_INDEX_OUT_OF_RANGE,
|
||||
COMMAND_LORE_REMOVE_SUCCESS,
|
||||
COMMAND_LORE_SET_NOT_INPUT_NUMBER,
|
||||
COMMAND_LORE_SET_INPUT_NUMBER_ERROR,
|
||||
COMMAND_LORE_SET_NOT_INPUT_TEXT,
|
||||
COMMAND_LORE_SET_INDEX_OUT_OF_RANGE,
|
||||
COMMAND_LORE_SET_SUCCESS;
|
||||
COMMAND_NOT_FOUND("§c未找到该指令"),
|
||||
COMMAND_NOT_HAS_PERMISSION("§c你没有这个权限"),
|
||||
COMMAND_MUST_USED_BY_PLAYER("§c这个命令只能由玩家执行"),
|
||||
COMMAND_DEBUG_INFO_MODE_ON("§a信息查询模式: 已开启"),
|
||||
COMMAND_DEBUG_INFO_MODE_OFF("§a信息查询模式: 已关闭"),
|
||||
|
||||
COMMAND_LORE_HAND_EMPTY("§c你必须手持一个物品才能使用这个命令"),
|
||||
|
||||
COMMAND_LORE_ADD_NOT_INPUT("§c你没有输入 lore 文本"),
|
||||
COMMAND_LORE_ADD_SUCCESS("§a已成功添加 lore 文本"),
|
||||
|
||||
COMMAND_LORE_CLEAR_NOTHING("§c这个物品没有 lore 文本"),
|
||||
COMMAND_LORE_CLEAR_SUCCESS("§a已清理该物品的全部 lore 文本"),
|
||||
|
||||
COMMAND_LORE_CMD_CLEAR_SUCCESS("§a已清理物品的自定义模型"),
|
||||
COMMAND_LORE_CMD_SET_INPUT_ERROR("§c设置物品的自定义模型失败: 模型 ID 必须是一个数字"),
|
||||
COMMAND_LORE_CMD_SET_SUCCESS("§a已设置物品的自定义模型为: %data%"),
|
||||
|
||||
COMMAND_LORE_FLAG_SET_ERROR_INPUT("§c设置物品 flag 失败: 输入的 flag 有误"),
|
||||
COMMAND_LORE_FLAG_REMOVE_SUCCESS("§a已移除物品的 flag: %flag%"),
|
||||
COMMAND_LORE_FLAG_SET_SUCCESS("§a已设置物品的 flag: %flag%"),
|
||||
|
||||
COMMAND_LORE_NAME_NOT_INPUT("§c请输入物品名称"),
|
||||
COMMAND_LORE_NAME_SUCCESS("§a已成功设置物品名称"),
|
||||
|
||||
COMMAND_LORE_REMOVE_INPUT_NUMBER_ERROR("§c行号必须是一个大于0的整数"),
|
||||
COMMAND_LORE_REMOVE_INDEX_OUT_OF_RANGE("§c你的手持物品没有这么多行 lore 文本"),
|
||||
|
||||
COMMAND_LORE_REMOVE_NOTHING("§c这个物品没有 lore"),
|
||||
COMMAND_LORE_REMOVE_SUCCESS("§a已成功删除一行 lore 文本"),
|
||||
|
||||
COMMAND_LORE_SET_NOT_INPUT_NUMBER("§c请输入要设置的行号"),
|
||||
COMMAND_LORE_SET_INPUT_NUMBER_ERROR("§c行号必须是一个大于 0 的整数"),
|
||||
COMMAND_LORE_SET_NOT_INPUT_TEXT("§c请输入要设置的 lore 文本"),
|
||||
COMMAND_LORE_SET_INDEX_OUT_OF_RANGE("§c你的手持物品没有这么多行 lore 文本"),
|
||||
COMMAND_LORE_SET_SUCCESS("§a已成功设置 lore 文本"),
|
||||
;
|
||||
|
||||
private DisplayMessage message;
|
||||
|
||||
public static void init(@NotNull Logger logger, @Nullable ConfigurationSection config) {
|
||||
if (config == null) {
|
||||
logger.warning("加载消息失败: 配置文件中未找到 messages 节点!");
|
||||
return;
|
||||
CoreMessage(@NotNull String message) {
|
||||
this.message = new DisplayMessage().setMessage(message);
|
||||
}
|
||||
|
||||
@SuppressWarnings("CallToPrintStackTrace")
|
||||
public static void init(@NotNull Plugin plugin) {
|
||||
File dataFolder = plugin.getDataFolder();
|
||||
if (dataFolder.mkdirs()) {
|
||||
plugin.getLogger().info("已生成插件存档文件夹 " + dataFolder.getName());
|
||||
}
|
||||
File file = new File(dataFolder, "messages.yml");
|
||||
YamlConfiguration config = new YamlConfiguration();
|
||||
if (file.exists()) {
|
||||
try {
|
||||
config.load(file);
|
||||
} catch (Exception e) {
|
||||
plugin.getLogger().warning("加载消息配置文件时出现了一个异常:");
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
for (CoreMessage value : values()) {
|
||||
ConfigurationSection section = config.getConfigurationSection(value.name());
|
||||
if (section == null) {
|
||||
logger.warning("未找到消息设置: " + value.name());
|
||||
plugin.getLogger().info("生成消息设置: " + value.name());
|
||||
config.set(value.name(), CoreBukkitUtils.toDisplayMessage(value.message));
|
||||
continue;
|
||||
}
|
||||
try {
|
||||
value.message = CoreBukkitUtils.getDisplayMessage(section);
|
||||
} catch (Exception e) {
|
||||
logger.warning("加载消息设置 " + value.name() + " 时遇到了一个异常: ");
|
||||
plugin.getLogger().warning("加载消息设置 " + value.name() + " 时遇到了一个异常: ");
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
try {
|
||||
config.save(file);
|
||||
} catch (IOException e) {
|
||||
plugin.getLogger().warning("保存消息配置文件时出现了一个异常:");
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public void show(@NotNull CommandSender sender, TextReplacementConfig... replacement) {
|
||||
|
@@ -25,11 +25,11 @@ public class PointAPI {
|
||||
public static void reloadPlayerPointAPIHook() {
|
||||
Plugin plugin = Bukkit.getPluginManager().getPlugin("PlayerPoints");
|
||||
if (plugin == null) {
|
||||
HamsterCorePlugin.getInstance().getLogger().warning("未检测到 PlayerPointAPI 插件!");
|
||||
HamsterCorePlugin.getInstance().getLogger().warning("未检测到 PlayerPointAPI 插件");
|
||||
return;
|
||||
}
|
||||
playerPointsAPI = ((PlayerPoints) plugin).getAPI();
|
||||
HamsterCorePlugin.getInstance().getLogger().info("PlayerPointAPI 挂接成功!");
|
||||
HamsterCorePlugin.getInstance().getLogger().info("PlayerPointAPI 挂接成功");
|
||||
}
|
||||
|
||||
/**
|
||||
|
@@ -29,10 +29,10 @@ public class VaultAPI {
|
||||
vaultEnabled = Bukkit.getPluginManager().isPluginEnabled("Vault");
|
||||
Logger logger = HamsterCorePlugin.getInstance().getLogger();
|
||||
if (!vaultEnabled) {
|
||||
logger.warning("未检测到 Vault 插件!");
|
||||
logger.warning("未检测到 Vault 插件");
|
||||
return;
|
||||
}
|
||||
logger.info("已连接 Vault!");
|
||||
logger.info("已连接 Vault");
|
||||
|
||||
RegisteredServiceProvider<Chat> chatProvider = Bukkit.getServer().getServicesManager().getRegistration(Chat.class);
|
||||
|
||||
@@ -40,7 +40,7 @@ public class VaultAPI {
|
||||
chat = chatProvider.getProvider();
|
||||
logger.info("聊天系统挂接成功.");
|
||||
} else {
|
||||
logger.warning("未检测到聊天系统!");
|
||||
logger.warning("未检测到聊天系统");
|
||||
}
|
||||
|
||||
RegisteredServiceProvider<Economy> economyProvider = Bukkit.getServer().getServicesManager().getRegistration(Economy.class);
|
||||
@@ -48,7 +48,7 @@ public class VaultAPI {
|
||||
economy = economyProvider.getProvider();
|
||||
logger.info("经济系统挂接成功.");
|
||||
} else {
|
||||
logger.warning("未检测到经济系统!");
|
||||
logger.warning("未检测到经济系统");
|
||||
}
|
||||
|
||||
RegisteredServiceProvider<Permission> permissionProvider = Bukkit.getServer().getServicesManager().getRegistration(Permission.class);
|
||||
@@ -56,7 +56,7 @@ public class VaultAPI {
|
||||
permission = permissionProvider.getProvider();
|
||||
logger.info("权限系统挂接成功.");
|
||||
} else {
|
||||
logger.warning("未检测到权限插件!");
|
||||
logger.warning("未检测到权限插件");
|
||||
}
|
||||
logger.info("已完成 VaultAPI 挂载.");
|
||||
}
|
||||
|
@@ -160,7 +160,7 @@ public class PageConfig implements InventoryHolder {
|
||||
return group;
|
||||
}
|
||||
}
|
||||
throw new IllegalArgumentException("未找到名称为 " + groupName + " 的按钮编组!");
|
||||
throw new IllegalArgumentException("未找到名称为 " + groupName + " 的按钮编组");
|
||||
}
|
||||
|
||||
@NotNull
|
||||
|
@@ -22,13 +22,13 @@ public class PageManager {
|
||||
return pageConfig;
|
||||
}
|
||||
if (!clazz.isAnnotationPresent(PluginPage.class)) {
|
||||
throw new IllegalArgumentException(clazz.getName() + " 未被 @PluginPage 注解修饰!");
|
||||
throw new IllegalArgumentException(clazz.getName() + " 未被 @PluginPage 注解修饰");
|
||||
}
|
||||
PluginPage annotation = clazz.getAnnotation(PluginPage.class);
|
||||
String pluginName = annotation.value();
|
||||
Plugin plugin = Bukkit.getPluginManager().getPlugin(pluginName);
|
||||
if (plugin == null) {
|
||||
throw new IllegalArgumentException("未找到插件 " + pluginName + " !");
|
||||
throw new IllegalArgumentException("未找到插件 " + pluginName + " ");
|
||||
}
|
||||
pageConfig = getPageConfig(plugin, clazz.getSimpleName());
|
||||
PAGE_CONFIG.put(clazz.getName(), pageConfig);
|
||||
@@ -50,13 +50,13 @@ public class PageManager {
|
||||
}
|
||||
try (InputStream resource = plugin.getResource("pages/" + filename)) {
|
||||
if (resource == null) {
|
||||
throw new IllegalArgumentException("在插件 " + plugin.getName() + " 的 Jar 文件内部未找到 /pages/" + filename + " !");
|
||||
throw new IllegalArgumentException("在插件 " + plugin.getName() + " 的 Jar 文件内部未找到 /pages/" + filename + " ");
|
||||
}
|
||||
Files.copy(resource, pageConfigFile.toPath(), StandardCopyOption.REPLACE_EXISTING);
|
||||
YamlConfiguration config = YamlConfiguration.loadConfiguration(pageConfigFile);
|
||||
return new PageConfig(plugin, config);
|
||||
} catch (IOException e) {
|
||||
throw new IllegalArgumentException("为插件 " + pluginName + " 加载页面配置文件 " + filename + " 时出错!", e);
|
||||
throw new IllegalArgumentException("为插件 " + pluginName + " 加载页面配置文件 " + filename + " 时出错", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -5,6 +5,8 @@ import cn.hamster3.mc.plugin.core.common.data.DisplayMessage;
|
||||
import com.google.gson.JsonObject;
|
||||
import de.tr7zw.changeme.nbtapi.NBTContainer;
|
||||
import de.tr7zw.changeme.nbtapi.NBTItem;
|
||||
import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer;
|
||||
import net.kyori.adventure.title.Title;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
@@ -215,6 +217,33 @@ public final class CoreBukkitUtils {
|
||||
return displayMessage;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static ConfigurationSection toDisplayMessage(@NotNull DisplayMessage message) {
|
||||
YamlConfiguration config = new YamlConfiguration();
|
||||
if (message.getMessage() != null) {
|
||||
config.set("message", LegacyComponentSerializer.legacySection().serialize(message.getMessage()));
|
||||
}
|
||||
if (message.getActionbar() != null) {
|
||||
config.set("actionbar", LegacyComponentSerializer.legacySection().serialize(message.getActionbar()));
|
||||
}
|
||||
if (message.getTitle() != null) {
|
||||
config.set("title", LegacyComponentSerializer.legacySection().serialize(message.getTitle().title()));
|
||||
config.set("subtitle", LegacyComponentSerializer.legacySection().serialize(message.getTitle().subtitle()));
|
||||
Title.Times times = message.getTitle().times();
|
||||
if (times != null) {
|
||||
config.set("fade-in", times.fadeIn().getSeconds() / 20 + times.fadeIn().getNano() / 1000_000);
|
||||
config.set("stay", times.fadeIn().getSeconds() / 20 + times.stay().getNano() / 1000_000);
|
||||
config.set("fade-out", times.fadeIn().getSeconds() / 20 + times.fadeOut().getNano() / 1000_000);
|
||||
}
|
||||
}
|
||||
if (message.getSound() != null) {
|
||||
config.set("sound", message.getSound().name().asString());
|
||||
config.set("volume", message.getSound().volume());
|
||||
config.set("pitch", message.getSound().pitch());
|
||||
}
|
||||
return config;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static YamlConfiguration getPluginConfig(@NotNull Plugin plugin, @NotNull String filename) {
|
||||
File file = new File(plugin.getDataFolder(), filename);
|
||||
@@ -225,11 +254,11 @@ public final class CoreBukkitUtils {
|
||||
if (!file.exists()) {
|
||||
try (InputStream stream = plugin.getResource(filename)) {
|
||||
if (stream == null) {
|
||||
throw new NullPointerException("在插件 " + plugin.getName() + " 的文件内部未找到 " + filename + " !");
|
||||
throw new NullPointerException("在插件 " + plugin.getName() + " 的文件内部未找到 " + filename + " ");
|
||||
}
|
||||
Files.copy(stream, file.toPath(), StandardCopyOption.REPLACE_EXISTING);
|
||||
} catch (IOException e) {
|
||||
throw new IllegalArgumentException("在插件 " + plugin.getName() + " 内部读取文件 " + filename + " 时发生错误!");
|
||||
throw new IllegalArgumentException("在插件 " + plugin.getName() + " 内部读取文件 " + filename + " 时发生错误");
|
||||
}
|
||||
}
|
||||
return YamlConfiguration.loadConfiguration(file);
|
||||
|
@@ -35,45 +35,3 @@ datasource:
|
||||
# 验证连接存活的超时时间
|
||||
# 单位:毫秒
|
||||
validation-timeout: 5000
|
||||
|
||||
messages:
|
||||
COMMAND_NOT_FOUND:
|
||||
message: "§c未找到该指令!"
|
||||
COMMAND_NOT_HAS_PERMISSION:
|
||||
message: "§c你没有这个权限!"
|
||||
COMMAND_MUST_USED_BY_PLAYER:
|
||||
message: "§c这个命令只能由玩家执行!"
|
||||
COMMAND_DEBUG_INFO_MODE_ON:
|
||||
message: "§a已开启信息查询模式!"
|
||||
COMMAND_DEBUG_INFO_MODE_OFF:
|
||||
message: "§a已关闭信息查询模式!"
|
||||
COMMAND_LORE_HAND_EMPTY:
|
||||
message: "§c你必须手持一个物品才能使用这个命令!"
|
||||
COMMAND_LORE_EMPTY_INPUT:
|
||||
message: "§c你没有输入lore文本!"
|
||||
COMMAND_LORE_ADD_SUCCESS:
|
||||
message: "§a已成功添加lore文本!"
|
||||
COMMAND_LORE_CLEAR_NOTHING:
|
||||
message: "§c这个物品没有lore文本!"
|
||||
COMMAND_LORE_CLEAR_SUCCESS:
|
||||
message: "§c已清理该物品的全部lore文本!"
|
||||
COMMAND_LORE_NAME_SUCCESS:
|
||||
message: "§a已成功设置物品名称!"
|
||||
COMMAND_LORE_REMOVE_NOT_INPUT_NUMBER:
|
||||
message: "§c请输入要删除的行号!"
|
||||
COMMAND_LORE_REMOVE_INPUT_NUMBER_ERROR:
|
||||
message: "§c行号必须是一个大于0的整数!"
|
||||
COMMAND_LORE_REMOVE_INDEX_OUT_OF_RANGE:
|
||||
message: "§c你的手持物品没有这么多行lore文本!"
|
||||
COMMAND_LORE_REMOVE_SUCCESS:
|
||||
message: "§a已成功删除lore文本!"
|
||||
COMMAND_LORE_SET_NOT_INPUT_NUMBER:
|
||||
message: "§c请输入要设置的行号!"
|
||||
COMMAND_LORE_SET_INPUT_NUMBER_ERROR:
|
||||
message: "§c行号必须是一个大于0的整数!"
|
||||
COMMAND_LORE_SET_NOT_INPUT_TEXT:
|
||||
message: "§c请输入要设置的lore文本!"
|
||||
COMMAND_LORE_SET_INDEX_OUT_OF_RANGE:
|
||||
message: "§c你的手持物品没有这么多行lore文本!"
|
||||
COMMAND_LORE_SET_SUCCESS:
|
||||
message: "§a已成功设置lore文本!"
|
||||
|
@@ -18,14 +18,20 @@ loadbefore:
|
||||
|
||||
commands:
|
||||
hamster-core:
|
||||
aliases: [ hcore, hc, core ]
|
||||
aliases: [ hcore, core ]
|
||||
description: 仓鼠核心调试指令
|
||||
permission: hamster.core.admin
|
||||
permission-message: §c你没有这个权限!
|
||||
lore:
|
||||
permission-message: §c你没有这个权限
|
||||
hamster-lore:
|
||||
aliases: [ hlore, lore ]
|
||||
description: 仓鼠核心的 lore 修改指令
|
||||
permission: hamster.lore.admin
|
||||
permission-message: §c你没有这个权限!
|
||||
permission: hamster.core.admin
|
||||
permission-message: §c你没有这个权限
|
||||
hamster-nbt:
|
||||
aliases: [ hnbt, nbt ]
|
||||
description: 仓鼠核心的 nbt 修改指令
|
||||
permission: hamster.core.admin
|
||||
permission-message: §c你没有这个权限
|
||||
|
||||
permissions:
|
||||
hamster.core.admin:
|
||||
|
@@ -27,7 +27,7 @@ public final class CoreBungeeAPI extends CoreAPI {
|
||||
Configuration config = CoreBungeeCordUtils.getPluginConfig(plugin);
|
||||
Configuration datasourceConfig = config.getSection("datasource");
|
||||
if (datasourceConfig == null) {
|
||||
throw new IllegalArgumentException("配置文件中未找到 datasource 节点!");
|
||||
throw new IllegalArgumentException("配置文件中未找到 datasource 节点");
|
||||
}
|
||||
|
||||
HikariConfig hikariConfig = new HikariConfig();
|
||||
|
@@ -19,7 +19,7 @@ public final class CoreBungeeCordUtils {
|
||||
@NotNull
|
||||
public static Configuration getConfig(@NotNull File file) {
|
||||
if (!file.exists()) {
|
||||
throw new IllegalArgumentException("文件不存在!");
|
||||
throw new IllegalArgumentException("文件不存在");
|
||||
}
|
||||
try {
|
||||
return ConfigurationProvider.getProvider(YamlConfiguration.class).load(file);
|
||||
@@ -57,7 +57,7 @@ public final class CoreBungeeCordUtils {
|
||||
@NotNull
|
||||
public static Configuration saveDefaultConfig(@NotNull Plugin plugin) {
|
||||
if (plugin.getDataFolder().mkdir()) {
|
||||
plugin.getLogger().info("已生成插件存档文件夹...");
|
||||
plugin.getLogger().info("已生成插件存档文件夹");
|
||||
}
|
||||
File configFile = new File(plugin.getDataFolder(), "config.yml");
|
||||
try {
|
||||
@@ -72,7 +72,7 @@ public final class CoreBungeeCordUtils {
|
||||
@NotNull
|
||||
public static Configuration saveDefaultConfig(@NotNull Plugin plugin, @NotNull String filename) {
|
||||
if (plugin.getDataFolder().mkdir()) {
|
||||
plugin.getLogger().info("已生成插件存档文件夹...");
|
||||
plugin.getLogger().info("已生成插件存档文件夹");
|
||||
}
|
||||
File configFile = new File(plugin.getDataFolder(), filename);
|
||||
try {
|
||||
|
Reference in New Issue
Block a user