style: 代码结构优化
This commit is contained in:
@@ -26,13 +26,15 @@ dependencies {
|
|||||||
// https://mvnrepository.com/artifact/net.kyori/adventure-platform-bukkit
|
// https://mvnrepository.com/artifact/net.kyori/adventure-platform-bukkit
|
||||||
api 'net.kyori:adventure-platform-bukkit:4.1.2'
|
api 'net.kyori:adventure-platform-bukkit:4.1.2'
|
||||||
oldJar 'net.kyori:adventure-platform-bukkit:4.1.2'
|
oldJar 'net.kyori:adventure-platform-bukkit:4.1.2'
|
||||||
// https://mvnrepository.com/artifact/com.squareup.okhttp3/okhttp
|
|
||||||
api 'com.squareup.okhttp3:okhttp:4.10.0'
|
// // https://mvnrepository.com/artifact/com.squareup.okhttp3/okhttp
|
||||||
oldJar 'com.squareup.okhttp3:okhttp:4.10.0'
|
// api 'com.squareup.okhttp3:okhttp:4.10.0'
|
||||||
|
// oldJar 'com.squareup.okhttp3:okhttp:4.10.0'
|
||||||
|
|
||||||
// https://mvnrepository.com/artifact/com.zaxxer/HikariCP
|
// https://mvnrepository.com/artifact/com.zaxxer/HikariCP
|
||||||
compileOnly 'com.zaxxer:HikariCP:5.0.1'
|
compileOnly 'com.zaxxer:HikariCP:5.0.1'
|
||||||
//noinspection GradlePackageUpdate
|
//noinspection GradlePackageUpdate
|
||||||
oldJar 'com.zaxxer:HikariCP:4.0.3'
|
oldJar('com.zaxxer:HikariCP:4.0.3') exclude group: "org.slf4j"
|
||||||
}
|
}
|
||||||
|
|
||||||
processResources {
|
processResources {
|
||||||
|
@@ -12,7 +12,7 @@ import cn.hamster3.mc.plugin.core.bukkit.page.listener.PageListener;
|
|||||||
import cn.hamster3.mc.plugin.core.bukkit.util.ItemStackAdapter;
|
import cn.hamster3.mc.plugin.core.bukkit.util.ItemStackAdapter;
|
||||||
import cn.hamster3.mc.plugin.core.common.constant.CoreConstantObjects;
|
import cn.hamster3.mc.plugin.core.common.constant.CoreConstantObjects;
|
||||||
import cn.hamster3.mc.plugin.core.common.data.DisplayMessage;
|
import cn.hamster3.mc.plugin.core.common.data.DisplayMessage;
|
||||||
import cn.hamster3.mc.plugin.core.common.util.MessageTypeAdapter;
|
import cn.hamster3.mc.plugin.core.common.misc.MessageTypeAdapter;
|
||||||
import com.google.gson.GsonBuilder;
|
import com.google.gson.GsonBuilder;
|
||||||
import net.kyori.adventure.platform.bukkit.BukkitAudiences;
|
import net.kyori.adventure.platform.bukkit.BukkitAudiences;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
|
@@ -44,10 +44,11 @@ public abstract class ParentCommand extends ChildCommand {
|
|||||||
@NotNull
|
@NotNull
|
||||||
@Override
|
@Override
|
||||||
public String getUsage() {
|
public String getUsage() {
|
||||||
if (getParent() == null) {
|
ParentCommand parent = getParent();
|
||||||
|
if (parent == null) {
|
||||||
return "/" + name;
|
return "/" + name;
|
||||||
}
|
}
|
||||||
return getParent().getUsage() + " " + name;
|
return parent.getUsage() + " " + name;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@@ -3,7 +3,7 @@ package cn.hamster3.mc.plugin.core.bukkit.command.lore;
|
|||||||
import cn.hamster3.mc.plugin.core.bukkit.HamsterCorePlugin;
|
import cn.hamster3.mc.plugin.core.bukkit.HamsterCorePlugin;
|
||||||
import cn.hamster3.mc.plugin.core.bukkit.command.ParentCommand;
|
import cn.hamster3.mc.plugin.core.bukkit.command.ParentCommand;
|
||||||
import cn.hamster3.mc.plugin.core.bukkit.command.lore.sub.*;
|
import cn.hamster3.mc.plugin.core.bukkit.command.lore.sub.*;
|
||||||
import cn.hamster3.mc.plugin.core.common.util.CommonUtils;
|
import cn.hamster3.mc.plugin.core.common.util.CoreUtils;
|
||||||
import org.bukkit.command.Command;
|
import org.bukkit.command.Command;
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
import org.bukkit.plugin.java.JavaPlugin;
|
import org.bukkit.plugin.java.JavaPlugin;
|
||||||
@@ -30,7 +30,7 @@ public final class ParentLoreCommand extends ParentCommand {
|
|||||||
|
|
||||||
@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) {
|
||||||
CommonUtils.replaceColorCode(args);
|
CoreUtils.replaceColorCode(args);
|
||||||
return super.onCommand(sender, command, label, args);
|
return super.onCommand(sender, command, label, args);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -17,15 +17,17 @@ dependencies {
|
|||||||
api 'net.kyori:adventure-platform-bungeecord:4.1.2'
|
api 'net.kyori:adventure-platform-bungeecord:4.1.2'
|
||||||
shade 'net.kyori:adventure-platform-bungeecord:4.1.2'
|
shade 'net.kyori:adventure-platform-bungeecord:4.1.2'
|
||||||
oldJar 'net.kyori:adventure-platform-bungeecord:4.1.2'
|
oldJar 'net.kyori:adventure-platform-bungeecord:4.1.2'
|
||||||
// https://mvnrepository.com/artifact/com.squareup.okhttp3/okhttp
|
|
||||||
api 'com.squareup.okhttp3:okhttp:4.10.0'
|
// // https://mvnrepository.com/artifact/com.squareup.okhttp3/okhttp
|
||||||
shade 'com.squareup.okhttp3:okhttp:4.10.0'
|
// api 'com.squareup.okhttp3:okhttp:4.10.0'
|
||||||
oldJar 'com.squareup.okhttp3:okhttp:4.10.0'
|
// shade 'com.squareup.okhttp3:okhttp:4.10.0'
|
||||||
|
// oldJar 'com.squareup.okhttp3:okhttp:4.10.0'
|
||||||
|
|
||||||
// https://mvnrepository.com/artifact/com.zaxxer/HikariCP
|
// https://mvnrepository.com/artifact/com.zaxxer/HikariCP
|
||||||
compileOnly 'com.zaxxer:HikariCP:5.0.1'
|
compileOnly 'com.zaxxer:HikariCP:5.0.1'
|
||||||
shade 'com.zaxxer:HikariCP:5.0.1'
|
shade 'com.zaxxer:HikariCP:5.0.1'
|
||||||
//noinspection GradlePackageUpdate
|
//noinspection GradlePackageUpdate
|
||||||
oldJar 'com.zaxxer:HikariCP:4.0.3'
|
oldJar 'com.zaxxer:HikariCP:4.0.3' exclude group: "org.slf4j"
|
||||||
}
|
}
|
||||||
|
|
||||||
processResources {
|
processResources {
|
||||||
|
@@ -1,56 +1,20 @@
|
|||||||
package cn.hamster3.mc.plugin.core.common.constant;
|
package cn.hamster3.mc.plugin.core.common.constant;
|
||||||
|
|
||||||
import cn.hamster3.mc.plugin.core.common.data.DisplayMessage;
|
import cn.hamster3.mc.plugin.core.common.util.CoreUtils;
|
||||||
import cn.hamster3.mc.plugin.core.common.util.MessageTypeAdapter;
|
|
||||||
import com.google.gson.Gson;
|
import com.google.gson.Gson;
|
||||||
import com.google.gson.GsonBuilder;
|
|
||||||
import org.jetbrains.annotations.NotNull;
|
|
||||||
|
|
||||||
import java.util.concurrent.ExecutorService;
|
import java.util.concurrent.ExecutorService;
|
||||||
import java.util.concurrent.Executors;
|
|
||||||
import java.util.concurrent.ScheduledExecutorService;
|
import java.util.concurrent.ScheduledExecutorService;
|
||||||
import java.util.concurrent.ThreadFactory;
|
|
||||||
|
|
||||||
@SuppressWarnings("unused")
|
@SuppressWarnings("unused")
|
||||||
public abstract class CoreConstantObjects {
|
public final class CoreConstantObjects {
|
||||||
/**
|
public static final ExecutorService WORKER_EXECUTOR = CoreUtils.WORKER_EXECUTOR;
|
||||||
* 异步线程
|
public static final ScheduledExecutorService SCHEDULED_EXECUTOR = CoreUtils.SCHEDULED_EXECUTOR;
|
||||||
*/
|
public static Gson GSON = CoreUtils.GSON;
|
||||||
public static final ExecutorService WORKER_EXECUTOR = Executors.newCachedThreadPool(new NamedThreadFactory("HamsterCore - Executor"));
|
public static Gson GSON_HUMAN = CoreUtils.GSON_HUMAN;
|
||||||
/**
|
|
||||||
* 调度器线程
|
|
||||||
*/
|
|
||||||
public static final ScheduledExecutorService SCHEDULED_EXECUTOR = Executors
|
|
||||||
.newScheduledThreadPool(1, new NamedThreadFactory("HamsterCore - Scheduler"));
|
|
||||||
/**
|
|
||||||
* GSON 工具
|
|
||||||
*/
|
|
||||||
public static Gson GSON = new GsonBuilder()
|
|
||||||
.registerTypeAdapter(DisplayMessage.class, MessageTypeAdapter.INSTANCE)
|
|
||||||
.create();
|
|
||||||
/**
|
|
||||||
* GSON 工具,会使用格式化输出、且解析中包含null参数
|
|
||||||
*/
|
|
||||||
public static Gson GSON_HUMAN = new GsonBuilder()
|
|
||||||
.registerTypeAdapter(DisplayMessage.class, MessageTypeAdapter.INSTANCE)
|
|
||||||
.serializeNulls()
|
|
||||||
.setPrettyPrinting()
|
|
||||||
.create();
|
|
||||||
}
|
|
||||||
|
|
||||||
class NamedThreadFactory implements ThreadFactory {
|
private CoreConstantObjects() {
|
||||||
private final String name;
|
|
||||||
private int threadID;
|
|
||||||
|
|
||||||
public NamedThreadFactory(String name) {
|
|
||||||
this.name = name;
|
|
||||||
threadID = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Thread newThread(@NotNull Runnable runnable) {
|
|
||||||
threadID++;
|
|
||||||
return new Thread(runnable, name + "#" + threadID);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@@ -1,4 +1,4 @@
|
|||||||
package cn.hamster3.mc.plugin.core.common.util;
|
package cn.hamster3.mc.plugin.core.common.misc;
|
||||||
|
|
||||||
import cn.hamster3.mc.plugin.core.common.data.DisplayMessage;
|
import cn.hamster3.mc.plugin.core.common.data.DisplayMessage;
|
||||||
import com.google.gson.*;
|
import com.google.gson.*;
|
@@ -0,0 +1,21 @@
|
|||||||
|
package cn.hamster3.mc.plugin.core.common.misc;
|
||||||
|
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
|
import java.util.concurrent.ThreadFactory;
|
||||||
|
|
||||||
|
public class NamedThreadFactory implements ThreadFactory {
|
||||||
|
private final String name;
|
||||||
|
private int threadID;
|
||||||
|
|
||||||
|
public NamedThreadFactory(String name) {
|
||||||
|
this.name = name;
|
||||||
|
threadID = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Thread newThread(@NotNull Runnable runnable) {
|
||||||
|
threadID++;
|
||||||
|
return new Thread(runnable, name + "#" + threadID);
|
||||||
|
}
|
||||||
|
}
|
@@ -11,10 +11,6 @@ import java.util.Stack;
|
|||||||
* 传入算数表达式,将返回一个浮点值结果
|
* 传入算数表达式,将返回一个浮点值结果
|
||||||
* <p>
|
* <p>
|
||||||
* 如果计算过程错误,将返回一个NaN
|
* 如果计算过程错误,将返回一个NaN
|
||||||
* <p>
|
|
||||||
* 我也忘了这个类是哪里抄来的
|
|
||||||
* <p>
|
|
||||||
* 反正它运行起来比直接用 JavaScript 引擎计算要快很多
|
|
||||||
*/
|
*/
|
||||||
@SuppressWarnings("unused")
|
@SuppressWarnings("unused")
|
||||||
public final class Calculator {
|
public final class Calculator {
|
||||||
|
@@ -1,5 +1,10 @@
|
|||||||
package cn.hamster3.mc.plugin.core.common.util;
|
package cn.hamster3.mc.plugin.core.common.util;
|
||||||
|
|
||||||
|
import cn.hamster3.mc.plugin.core.common.data.DisplayMessage;
|
||||||
|
import cn.hamster3.mc.plugin.core.common.misc.MessageTypeAdapter;
|
||||||
|
import cn.hamster3.mc.plugin.core.common.misc.NamedThreadFactory;
|
||||||
|
import com.google.gson.Gson;
|
||||||
|
import com.google.gson.GsonBuilder;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
@@ -8,12 +13,39 @@ import java.io.IOException;
|
|||||||
import java.nio.file.Files;
|
import java.nio.file.Files;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.concurrent.ExecutorService;
|
||||||
|
import java.util.concurrent.Executors;
|
||||||
|
import java.util.concurrent.ScheduledExecutorService;
|
||||||
import java.util.zip.ZipEntry;
|
import java.util.zip.ZipEntry;
|
||||||
import java.util.zip.ZipOutputStream;
|
import java.util.zip.ZipOutputStream;
|
||||||
|
|
||||||
@SuppressWarnings("unused")
|
@SuppressWarnings("unused")
|
||||||
public final class CommonUtils {
|
public final class CoreUtils {
|
||||||
private CommonUtils() {
|
/**
|
||||||
|
* 异步线程
|
||||||
|
*/
|
||||||
|
public static final ExecutorService WORKER_EXECUTOR = Executors.newCachedThreadPool(new NamedThreadFactory("HamsterCore - Executor"));
|
||||||
|
/**
|
||||||
|
* 调度器线程
|
||||||
|
*/
|
||||||
|
public static final ScheduledExecutorService SCHEDULED_EXECUTOR = Executors
|
||||||
|
.newScheduledThreadPool(1, new NamedThreadFactory("HamsterCore - Scheduler"));
|
||||||
|
/**
|
||||||
|
* GSON 工具
|
||||||
|
*/
|
||||||
|
public static Gson GSON = new GsonBuilder()
|
||||||
|
.registerTypeAdapter(DisplayMessage.class, MessageTypeAdapter.INSTANCE)
|
||||||
|
.create();
|
||||||
|
/**
|
||||||
|
* GSON 工具,会使用格式化输出、且解析中包含null参数
|
||||||
|
*/
|
||||||
|
public static Gson GSON_HUMAN = new GsonBuilder()
|
||||||
|
.registerTypeAdapter(DisplayMessage.class, MessageTypeAdapter.INSTANCE)
|
||||||
|
.serializeNulls()
|
||||||
|
.setPrettyPrinting()
|
||||||
|
.create();
|
||||||
|
|
||||||
|
private CoreUtils() {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void zipCompressionFolder(@NotNull File folder, @NotNull File zipFile) throws IOException {
|
public static void zipCompressionFolder(@NotNull File folder, @NotNull File zipFile) throws IOException {
|
||||||
@@ -175,5 +207,5 @@ public final class CommonUtils {
|
|||||||
public static <T> T caseObject(Object o) {
|
public static <T> T caseObject(Object o) {
|
||||||
return (T) o;
|
return (T) o;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Reference in New Issue
Block a user