perf: 重写部分代码

This commit is contained in:
2023-05-30 04:46:01 +08:00
parent cfa382b71c
commit c485c29d5d
14 changed files with 36 additions and 37 deletions

View File

@@ -2,7 +2,7 @@ package cn.hamster3.mc.plugin.core.bukkit.command.core.sub;
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;
import cn.hamster3.mc.plugin.core.bukkit.util.BukkitUtils; import cn.hamster3.mc.plugin.core.bukkit.util.CoreBukkitUtils;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.command.Command; import org.bukkit.command.Command;
@@ -51,8 +51,8 @@ public class YamlCommand extends ChildCommand {
@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) {
YamlConfiguration config = new YamlConfiguration(); YamlConfiguration config = new YamlConfiguration();
config.set("mc-version", BukkitUtils.getMCVersion()); config.set("mc-version", CoreBukkitUtils.getMCVersion());
config.set("nms-version", BukkitUtils.getNMSVersion()); config.set("nms-version", CoreBukkitUtils.getNMSVersion());
config.set("server-version", Bukkit.getBukkitVersion()); config.set("server-version", Bukkit.getBukkitVersion());
config.set("bukkit-version", Bukkit.getVersion()); config.set("bukkit-version", Bukkit.getVersion());

View File

@@ -2,7 +2,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.command.ChildCommand;
import cn.hamster3.mc.plugin.core.bukkit.constant.CoreMessage; import cn.hamster3.mc.plugin.core.bukkit.constant.CoreMessage;
import cn.hamster3.mc.plugin.core.bukkit.util.BukkitUtils; import cn.hamster3.mc.plugin.core.bukkit.util.CoreBukkitUtils;
import org.bukkit.command.Command; import org.bukkit.command.Command;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
@@ -52,7 +52,7 @@ public class LoreAddCommand extends ChildCommand {
} }
Player player = (Player) sender; Player player = (Player) sender;
ItemStack stack = player.getItemInHand(); ItemStack stack = player.getItemInHand();
if (BukkitUtils.isEmptyItemStack(stack)) { if (CoreBukkitUtils.isEmptyItemStack(stack)) {
CoreMessage.COMMAND_LORE_HAND_EMPTY.show(player); CoreMessage.COMMAND_LORE_HAND_EMPTY.show(player);
return true; return true;
} }

View File

@@ -2,7 +2,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.command.ChildCommand;
import cn.hamster3.mc.plugin.core.bukkit.constant.CoreMessage; import cn.hamster3.mc.plugin.core.bukkit.constant.CoreMessage;
import cn.hamster3.mc.plugin.core.bukkit.util.BukkitUtils; import cn.hamster3.mc.plugin.core.bukkit.util.CoreBukkitUtils;
import org.bukkit.command.Command; import org.bukkit.command.Command;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
@@ -48,7 +48,7 @@ public class LoreClearCommand extends ChildCommand {
} }
Player player = (Player) sender; Player player = (Player) sender;
ItemStack stack = player.getItemInHand(); ItemStack stack = player.getItemInHand();
if (BukkitUtils.isEmptyItemStack(stack)) { if (CoreBukkitUtils.isEmptyItemStack(stack)) {
CoreMessage.COMMAND_LORE_HAND_EMPTY.show(player); CoreMessage.COMMAND_LORE_HAND_EMPTY.show(player);
return true; return true;
} }

View File

@@ -2,7 +2,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.command.ChildCommand;
import cn.hamster3.mc.plugin.core.bukkit.constant.CoreMessage; import cn.hamster3.mc.plugin.core.bukkit.constant.CoreMessage;
import cn.hamster3.mc.plugin.core.bukkit.util.BukkitUtils; import cn.hamster3.mc.plugin.core.bukkit.util.CoreBukkitUtils;
import net.kyori.adventure.text.TextReplacementConfig; import net.kyori.adventure.text.TextReplacementConfig;
import org.bukkit.command.Command; import org.bukkit.command.Command;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
@@ -48,7 +48,7 @@ public class LoreCustomModelDataCommand extends ChildCommand {
} }
Player player = (Player) sender; Player player = (Player) sender;
ItemStack stack = player.getItemInHand(); ItemStack stack = player.getItemInHand();
if (BukkitUtils.isEmptyItemStack(stack)) { if (CoreBukkitUtils.isEmptyItemStack(stack)) {
CoreMessage.COMMAND_LORE_HAND_EMPTY.show(player); CoreMessage.COMMAND_LORE_HAND_EMPTY.show(player);
return true; return true;
} }

View File

@@ -2,7 +2,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.command.ChildCommand;
import cn.hamster3.mc.plugin.core.bukkit.constant.CoreMessage; import cn.hamster3.mc.plugin.core.bukkit.constant.CoreMessage;
import cn.hamster3.mc.plugin.core.bukkit.util.BukkitUtils; import cn.hamster3.mc.plugin.core.bukkit.util.CoreBukkitUtils;
import org.bukkit.command.Command; import org.bukkit.command.Command;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
@@ -54,7 +54,7 @@ public class LoreFlagCommand extends ChildCommand {
} }
Player player = (Player) sender; Player player = (Player) sender;
ItemStack stack = player.getItemInHand(); ItemStack stack = player.getItemInHand();
if (BukkitUtils.isEmptyItemStack(stack)) { if (CoreBukkitUtils.isEmptyItemStack(stack)) {
CoreMessage.COMMAND_LORE_HAND_EMPTY.show(player); CoreMessage.COMMAND_LORE_HAND_EMPTY.show(player);
return true; return true;
} }

View File

@@ -2,7 +2,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.command.ChildCommand;
import cn.hamster3.mc.plugin.core.bukkit.constant.CoreMessage; import cn.hamster3.mc.plugin.core.bukkit.constant.CoreMessage;
import cn.hamster3.mc.plugin.core.bukkit.util.BukkitUtils; import cn.hamster3.mc.plugin.core.bukkit.util.CoreBukkitUtils;
import org.bukkit.command.Command; import org.bukkit.command.Command;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
@@ -51,7 +51,7 @@ public class LoreNameCommand extends ChildCommand {
} }
Player player = (Player) sender; Player player = (Player) sender;
ItemStack stack = player.getItemInHand(); ItemStack stack = player.getItemInHand();
if (BukkitUtils.isEmptyItemStack(stack)) { if (CoreBukkitUtils.isEmptyItemStack(stack)) {
CoreMessage.COMMAND_LORE_HAND_EMPTY.show(player); CoreMessage.COMMAND_LORE_HAND_EMPTY.show(player);
return true; return true;
} }

View File

@@ -2,7 +2,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.command.ChildCommand;
import cn.hamster3.mc.plugin.core.bukkit.constant.CoreMessage; import cn.hamster3.mc.plugin.core.bukkit.constant.CoreMessage;
import cn.hamster3.mc.plugin.core.bukkit.util.BukkitUtils; import cn.hamster3.mc.plugin.core.bukkit.util.CoreBukkitUtils;
import org.bukkit.command.Command; import org.bukkit.command.Command;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
@@ -57,7 +57,7 @@ public class LoreRemoveCommand extends ChildCommand {
} }
Player player = (Player) sender; Player player = (Player) sender;
ItemStack stack = player.getItemInHand(); ItemStack stack = player.getItemInHand();
if (BukkitUtils.isEmptyItemStack(stack)) { if (CoreBukkitUtils.isEmptyItemStack(stack)) {
CoreMessage.COMMAND_LORE_HAND_EMPTY.show(player); CoreMessage.COMMAND_LORE_HAND_EMPTY.show(player);
return true; return true;
} }

View File

@@ -2,7 +2,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.command.ChildCommand;
import cn.hamster3.mc.plugin.core.bukkit.constant.CoreMessage; import cn.hamster3.mc.plugin.core.bukkit.constant.CoreMessage;
import cn.hamster3.mc.plugin.core.bukkit.util.BukkitUtils; import cn.hamster3.mc.plugin.core.bukkit.util.CoreBukkitUtils;
import org.bukkit.command.Command; import org.bukkit.command.Command;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
@@ -62,7 +62,7 @@ public class LoreSetCommand extends ChildCommand {
} }
Player player = (Player) sender; Player player = (Player) sender;
ItemStack stack = player.getItemInHand(); ItemStack stack = player.getItemInHand();
if (BukkitUtils.isEmptyItemStack(stack)) { if (CoreBukkitUtils.isEmptyItemStack(stack)) {
CoreMessage.COMMAND_LORE_HAND_EMPTY.show(player); CoreMessage.COMMAND_LORE_HAND_EMPTY.show(player);
return true; return true;
} }

View File

@@ -1,7 +1,7 @@
package cn.hamster3.mc.plugin.core.bukkit.constant; package cn.hamster3.mc.plugin.core.bukkit.constant;
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.util.BukkitUtils; import cn.hamster3.mc.plugin.core.bukkit.util.CoreBukkitUtils;
import cn.hamster3.mc.plugin.core.common.data.DisplayMessage; import cn.hamster3.mc.plugin.core.common.data.DisplayMessage;
import net.kyori.adventure.audience.Audience; import net.kyori.adventure.audience.Audience;
import net.kyori.adventure.text.TextReplacementConfig; import net.kyori.adventure.text.TextReplacementConfig;
@@ -52,7 +52,7 @@ public enum CoreMessage {
continue; continue;
} }
try { try {
value.message = BukkitUtils.getDisplayMessage(section); value.message = CoreBukkitUtils.getDisplayMessage(section);
} catch (Exception e) { } catch (Exception e) {
plugin.getLogger().warning("加载消息设置 " + value.name() + " 时遇到了一个异常: "); plugin.getLogger().warning("加载消息设置 " + value.name() + " 时遇到了一个异常: ");
e.printStackTrace(); e.printStackTrace();

View File

@@ -33,8 +33,8 @@ import java.util.UUID;
import java.util.concurrent.CompletableFuture; import java.util.concurrent.CompletableFuture;
@SuppressWarnings("unused") @SuppressWarnings("unused")
public final class BukkitUtils { public final class CoreBukkitUtils {
private BukkitUtils() { private CoreBukkitUtils() {
} }
@NotNull @NotNull

View File

@@ -1,6 +1,6 @@
package cn.hamster3.mc.plugin.core.bukkit.util.serializer; package cn.hamster3.mc.plugin.core.bukkit.util.serializer;
import cn.hamster3.mc.plugin.core.bukkit.util.BukkitUtils; import cn.hamster3.mc.plugin.core.bukkit.util.CoreBukkitUtils;
import com.google.gson.*; import com.google.gson.*;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
@@ -17,7 +17,7 @@ public final class ItemStackAdapter implements JsonSerializer<ItemStack>, JsonDe
if (json.isJsonNull()) { if (json.isJsonNull()) {
return null; return null;
} }
return BukkitUtils.deserializeItemStack(json.getAsString()); return CoreBukkitUtils.deserializeItemStack(json.getAsString());
} }
@Override @Override
@@ -25,7 +25,7 @@ public final class ItemStackAdapter implements JsonSerializer<ItemStack>, JsonDe
if (src == null) { if (src == null) {
return JsonNull.INSTANCE; return JsonNull.INSTANCE;
} }
String s = BukkitUtils.serializeItemStack(src); String s = CoreBukkitUtils.serializeItemStack(src);
return new JsonPrimitive(s); return new JsonPrimitive(s);
} }
} }

View File

@@ -1,6 +1,6 @@
package cn.hamster3.mc.plugin.core.bukkit.util.serializer; package cn.hamster3.mc.plugin.core.bukkit.util.serializer;
import cn.hamster3.mc.plugin.core.bukkit.util.BukkitUtils; import cn.hamster3.mc.plugin.core.bukkit.util.CoreBukkitUtils;
import com.google.gson.*; import com.google.gson.*;
import org.bukkit.potion.PotionEffect; import org.bukkit.potion.PotionEffect;
@@ -17,7 +17,7 @@ public final class PotionEffectAdapter implements JsonSerializer<PotionEffect>,
if (json.isJsonNull()) { if (json.isJsonNull()) {
return null; return null;
} }
return BukkitUtils.deserializePotionEffect(json); return CoreBukkitUtils.deserializePotionEffect(json);
} }
@Override @Override
@@ -25,6 +25,6 @@ public final class PotionEffectAdapter implements JsonSerializer<PotionEffect>,
if (src == null) { if (src == null) {
return JsonNull.INSTANCE; return JsonNull.INSTANCE;
} }
return BukkitUtils.serializePotionEffect(src); return CoreBukkitUtils.serializePotionEffect(src);
} }
} }

View File

@@ -1,7 +1,7 @@
package cn.hamster3.mc.plugin.core.bungee.api; package cn.hamster3.mc.plugin.core.bungee.api;
import cn.hamster3.mc.plugin.core.bungee.HamsterCorePlugin; import cn.hamster3.mc.plugin.core.bungee.HamsterCorePlugin;
import cn.hamster3.mc.plugin.core.bungee.util.BungeeCordUtils; import cn.hamster3.mc.plugin.core.bungee.util.CoreBungeeCordUtils;
import cn.hamster3.mc.plugin.core.common.api.CoreAPI; import cn.hamster3.mc.plugin.core.common.api.CoreAPI;
import com.zaxxer.hikari.HikariConfig; import com.zaxxer.hikari.HikariConfig;
import com.zaxxer.hikari.HikariDataSource; import com.zaxxer.hikari.HikariDataSource;
@@ -16,8 +16,7 @@ public final class CoreBungeeAPI extends CoreAPI {
private CoreBungeeAPI() { private CoreBungeeAPI() {
HamsterCorePlugin plugin = HamsterCorePlugin.getInstance(); HamsterCorePlugin plugin = HamsterCorePlugin.getInstance();
Configuration config = BungeeCordUtils.getPluginConfig(plugin); Configuration config = CoreBungeeCordUtils.getPluginConfig(plugin);
Configuration datasourceConfig = config.getSection("datasource"); Configuration datasourceConfig = config.getSection("datasource");
if (datasourceConfig == null) { if (datasourceConfig == null) {
throw new IllegalArgumentException("配置文件中未找到 datasource 节点!"); throw new IllegalArgumentException("配置文件中未找到 datasource 节点!");

View File

@@ -12,10 +12,11 @@ import java.io.InputStream;
import java.nio.file.Files; import java.nio.file.Files;
@SuppressWarnings("unused") @SuppressWarnings("unused")
public final class BungeeCordUtils { public final class CoreBungeeCordUtils {
private BungeeCordUtils() { private CoreBungeeCordUtils() {
} }
@NotNull
public static Configuration getConfig(@NotNull File file) { public static Configuration getConfig(@NotNull File file) {
if (!file.exists()) { if (!file.exists()) {
throw new IllegalArgumentException("文件不存在!"); throw new IllegalArgumentException("文件不存在!");
@@ -27,20 +28,20 @@ public final class BungeeCordUtils {
} }
} }
@NotNull
public static Configuration getPluginConfig(@NotNull Plugin plugin) { public static Configuration getPluginConfig(@NotNull Plugin plugin) {
File configFile = new File(plugin.getDataFolder(), "config.yml"); File configFile = new File(plugin.getDataFolder(), "config.yml");
if (!configFile.exists()) { if (!configFile.exists()) {
return saveDefaultConfig(plugin); return saveDefaultConfig(plugin);
} }
try { try {
return ConfigurationProvider.getProvider(YamlConfiguration.class).load(configFile); return ConfigurationProvider.getProvider(YamlConfiguration.class).load(configFile);
} catch (IOException e) { } catch (IOException e) {
e.printStackTrace(); throw new RuntimeException(e);
return null;
} }
} }
@NotNull
public static Configuration saveDefaultConfig(@NotNull Plugin plugin) { public static Configuration saveDefaultConfig(@NotNull Plugin plugin) {
if (plugin.getDataFolder().mkdir()) { if (plugin.getDataFolder().mkdir()) {
plugin.getLogger().info("创建插件文件夹..."); plugin.getLogger().info("创建插件文件夹...");
@@ -51,8 +52,7 @@ public final class BungeeCordUtils {
Files.copy(in, configFile.toPath()); Files.copy(in, configFile.toPath());
return ConfigurationProvider.getProvider(YamlConfiguration.class).load(configFile); return ConfigurationProvider.getProvider(YamlConfiguration.class).load(configFile);
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); throw new RuntimeException(e);
} }
return null;
} }
} }