mirror of
https://github.com/CarmJos/EasyPlugin.git
synced 2026-06-04 16:48:16 +08:00
[v1.1.0] 版本更新
- [U] 不再允许重写onLoad、onEnable与onDisable方法。 - [F] 修复GUI打开时的空指针异常。 - [A] 添加outputInfo方法,方便插件输出相关信息。 - [A] 添加 EasyPluginMessageProvider 用于实现多语言支持。
This commit is contained in:
@@ -5,7 +5,7 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<artifactId>easyplugin-parent</artifactId>
|
<artifactId>easyplugin-parent</artifactId>
|
||||||
<groupId>cc.carm.lib</groupId>
|
<groupId>cc.carm.lib</groupId>
|
||||||
<version>1.0.0-SNAPSHOT</version>
|
<version>1.1.0</version>
|
||||||
</parent>
|
</parent>
|
||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
|
||||||
|
|||||||
@@ -5,7 +5,7 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<artifactId>easyplugin-parent</artifactId>
|
<artifactId>easyplugin-parent</artifactId>
|
||||||
<groupId>cc.carm.lib</groupId>
|
<groupId>cc.carm.lib</groupId>
|
||||||
<version>1.0.0-SNAPSHOT</version>
|
<version>1.1.0</version>
|
||||||
</parent>
|
</parent>
|
||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
|
||||||
|
|||||||
@@ -5,7 +5,7 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<artifactId>easyplugin-parent</artifactId>
|
<artifactId>easyplugin-parent</artifactId>
|
||||||
<groupId>cc.carm.lib</groupId>
|
<groupId>cc.carm.lib</groupId>
|
||||||
<version>1.0.0-SNAPSHOT</version>
|
<version>1.1.0</version>
|
||||||
</parent>
|
</parent>
|
||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
|
||||||
|
|||||||
@@ -5,7 +5,7 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<artifactId>easyplugin-parent</artifactId>
|
<artifactId>easyplugin-parent</artifactId>
|
||||||
<groupId>cc.carm.lib</groupId>
|
<groupId>cc.carm.lib</groupId>
|
||||||
<version>1.0.0-SNAPSHOT</version>
|
<version>1.1.0</version>
|
||||||
</parent>
|
</parent>
|
||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
|
||||||
@@ -21,7 +21,7 @@
|
|||||||
|
|
||||||
|
|
||||||
<name>EasyPlugin-Configuration</name>
|
<name>EasyPlugin-Configuration</name>
|
||||||
<description>轻松插件配置,可以方便快捷的将配置文件作为静态参数使用。</description>
|
<description>轻松插件配置模块,可以方便快捷的将配置文件作为静态参数使用。</description>
|
||||||
<url>https://github.com/CarmJos/EasyPlugin</url>
|
<url>https://github.com/CarmJos/EasyPlugin</url>
|
||||||
|
|
||||||
<developers>
|
<developers>
|
||||||
|
|||||||
@@ -5,7 +5,7 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<artifactId>easyplugin-parent</artifactId>
|
<artifactId>easyplugin-parent</artifactId>
|
||||||
<groupId>cc.carm.lib</groupId>
|
<groupId>cc.carm.lib</groupId>
|
||||||
<version>1.0.0-SNAPSHOT</version>
|
<version>1.1.0</version>
|
||||||
</parent>
|
</parent>
|
||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
|
||||||
@@ -19,6 +19,35 @@
|
|||||||
<artifactId>easyplugin-database</artifactId>
|
<artifactId>easyplugin-database</artifactId>
|
||||||
<packaging>jar</packaging>
|
<packaging>jar</packaging>
|
||||||
|
|
||||||
|
<name>EasyPlugin-Database</name>
|
||||||
|
<description>轻松插件数据库模块,包含快速实现数据库功能的工具。</description>
|
||||||
|
<url>https://github.com/CarmJos/EasyPlugin</url>
|
||||||
|
|
||||||
|
<developers>
|
||||||
|
<developer>
|
||||||
|
<id>CarmJos</id>
|
||||||
|
<name>Carm Jos</name>
|
||||||
|
<email>carm@carm.cc</email>
|
||||||
|
<url>https://www.carm.cc</url>
|
||||||
|
</developer>
|
||||||
|
</developers>
|
||||||
|
|
||||||
|
<licenses>
|
||||||
|
<license>
|
||||||
|
<name>GNU General Public License v3.0</name>
|
||||||
|
<url>https://opensource.org/licenses/GPL-3.0</url>
|
||||||
|
</license>
|
||||||
|
</licenses>
|
||||||
|
|
||||||
|
<issueManagement>
|
||||||
|
<system>GitHub Issues</system>
|
||||||
|
<url>https://github.com/CarmJos/EasyPlugin/issues</url>
|
||||||
|
</issueManagement>
|
||||||
|
|
||||||
|
<ciManagement>
|
||||||
|
<system>GitHub Actions</system>
|
||||||
|
<url>https://github.com/CarmJos/EasyPlugin/actions/workflows/maven.yml</url>
|
||||||
|
</ciManagement>
|
||||||
|
|
||||||
<repositories>
|
<repositories>
|
||||||
<repository>
|
<repository>
|
||||||
@@ -32,10 +61,65 @@
|
|||||||
<dependency>
|
<dependency>
|
||||||
<groupId>cc.carm.lib</groupId>
|
<groupId>cc.carm.lib</groupId>
|
||||||
<artifactId>easysql-beecp</artifactId>
|
<artifactId>easysql-beecp</artifactId>
|
||||||
<version>0.2.3</version>
|
<version>0.2.4</version>
|
||||||
|
<optional>true</optional>
|
||||||
<scope>compile</scope>
|
<scope>compile</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
|
<build>
|
||||||
|
<plugins>
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
|
<artifactId>maven-javadoc-plugin</artifactId>
|
||||||
|
</plugin>
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
|
<artifactId>maven-compiler-plugin</artifactId>
|
||||||
|
</plugin>
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
|
<artifactId>maven-jar-plugin</artifactId>
|
||||||
|
</plugin>
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
|
<artifactId>maven-source-plugin</artifactId>
|
||||||
|
</plugin>
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
|
<artifactId>maven-shade-plugin</artifactId>
|
||||||
|
<version>3.2.3</version>
|
||||||
|
<executions>
|
||||||
|
<execution>
|
||||||
|
<phase>package</phase>
|
||||||
|
<goals>
|
||||||
|
<goal>shade</goal>
|
||||||
|
</goals>
|
||||||
|
<configuration>
|
||||||
|
<createDependencyReducedPom>false</createDependencyReducedPom>
|
||||||
|
</configuration>
|
||||||
|
</execution>
|
||||||
|
</executions>
|
||||||
|
<configuration>
|
||||||
|
<relocations>
|
||||||
|
<relocation>
|
||||||
|
<pattern>cc.carm.lib.easysql</pattern>
|
||||||
|
<shadedPattern>cc.carm.lib.easyplugin.database</shadedPattern>
|
||||||
|
</relocation>
|
||||||
|
</relocations>
|
||||||
|
<filters>
|
||||||
|
<filter>
|
||||||
|
<artifact>*:*</artifact>
|
||||||
|
<excludes>
|
||||||
|
<exclude>META-INF/MANIFEST.MF</exclude>
|
||||||
|
<exclude>META-INF/*.txt</exclude>
|
||||||
|
</excludes>
|
||||||
|
</filter>
|
||||||
|
</filters>
|
||||||
|
</configuration>
|
||||||
|
</plugin>
|
||||||
|
</plugins>
|
||||||
|
</build>
|
||||||
|
|
||||||
</project>
|
</project>
|
||||||
@@ -0,0 +1,51 @@
|
|||||||
|
package cc.carm.lib.easyplugin.database;
|
||||||
|
|
||||||
|
import cc.carm.lib.easysql.api.SQLManager;
|
||||||
|
import cc.carm.lib.easysql.api.builder.TableCreateBuilder;
|
||||||
|
import cc.carm.lib.easysql.api.builder.TableQueryBuilder;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
|
import java.sql.SQLException;
|
||||||
|
|
||||||
|
public class DatabaseTable {
|
||||||
|
|
||||||
|
private final @NotNull String tableName;
|
||||||
|
private final @NotNull String[] columns;
|
||||||
|
|
||||||
|
@Nullable String tableSettings;
|
||||||
|
|
||||||
|
public DatabaseTable(@NotNull String tableName, @NotNull String[] columns) {
|
||||||
|
this(tableName, columns, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
public DatabaseTable(@NotNull String tableName, @NotNull String[] columns, @Nullable String tableSettings) {
|
||||||
|
this.tableName = tableName;
|
||||||
|
this.columns = columns;
|
||||||
|
this.tableSettings = tableSettings;
|
||||||
|
}
|
||||||
|
|
||||||
|
public @NotNull String getTableName() {
|
||||||
|
return tableName;
|
||||||
|
}
|
||||||
|
|
||||||
|
public @NotNull String[] getColumns() {
|
||||||
|
return columns;
|
||||||
|
}
|
||||||
|
|
||||||
|
public @Nullable String getTableSettings() {
|
||||||
|
return tableSettings;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int createTable(SQLManager sqlManager) throws SQLException {
|
||||||
|
TableCreateBuilder createAction = sqlManager.createTable(getTableName());
|
||||||
|
createAction.setColumns(getColumns());
|
||||||
|
if (getTableSettings() != null) createAction.setTableSettings(getTableSettings());
|
||||||
|
return createAction.build().execute();
|
||||||
|
}
|
||||||
|
|
||||||
|
public TableQueryBuilder createQuery(SQLManager sqlManager) {
|
||||||
|
return sqlManager.createQuery().inTable(tableName);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -5,7 +5,7 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<artifactId>easyplugin-parent</artifactId>
|
<artifactId>easyplugin-parent</artifactId>
|
||||||
<groupId>cc.carm.lib</groupId>
|
<groupId>cc.carm.lib</groupId>
|
||||||
<version>1.0.0-SNAPSHOT</version>
|
<version>1.1.0</version>
|
||||||
</parent>
|
</parent>
|
||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
|
||||||
@@ -20,7 +20,7 @@
|
|||||||
<packaging>jar</packaging>
|
<packaging>jar</packaging>
|
||||||
|
|
||||||
<name>EasyPlugin-GUI</name>
|
<name>EasyPlugin-GUI</name>
|
||||||
<description>轻松插件界面相关接口,方便快捷的创建箱子GUI界面。</description>
|
<description>轻松插件GUI接口模块,方便快捷的创建箱子GUI界面。</description>
|
||||||
<url>https://github.com/CarmJos/EasyPlugin</url>
|
<url>https://github.com/CarmJos/EasyPlugin</url>
|
||||||
|
|
||||||
<developers>
|
<developers>
|
||||||
|
|||||||
@@ -159,7 +159,7 @@ public class GUI {
|
|||||||
if (this.type == GUIType.CANCEL) throw new NullPointerException("被取消或不存在的GUI");
|
if (this.type == GUIType.CANCEL) throw new NullPointerException("被取消或不存在的GUI");
|
||||||
|
|
||||||
Inventory inv = Bukkit.createInventory(null, this.type.getSize(), this.name);
|
Inventory inv = Bukkit.createInventory(null, this.type.getSize(), this.name);
|
||||||
IntStream.range(0, this.inv.getSize()).forEach(index -> inv.setItem(index, new ItemStack(Material.AIR)));
|
IntStream.range(0, inv.getSize()).forEach(index -> inv.setItem(index, new ItemStack(Material.AIR)));
|
||||||
getItems().forEach((index, item) -> inv.setItem(index, item.getDisplay()));
|
getItems().forEach((index, item) -> inv.setItem(index, item.getDisplay()));
|
||||||
|
|
||||||
setOpenedGUI(player, this);
|
setOpenedGUI(player, this);
|
||||||
|
|||||||
@@ -0,0 +1,52 @@
|
|||||||
|
|
||||||
|
import cc.carm.lib.easyplugin.gui.configuration.GUIActionType;
|
||||||
|
import cc.carm.lib.easyplugin.gui.configuration.GUIConfiguration;
|
||||||
|
import org.bukkit.event.inventory.ClickType;
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public class ActionReadTest {
|
||||||
|
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void test() {
|
||||||
|
|
||||||
|
List<String> actions = Arrays.asList(
|
||||||
|
"[CHAT] 123123",
|
||||||
|
"[SHIFT_LEFT:CHAT] /test qwq",
|
||||||
|
"[CONSOLE] say hello",
|
||||||
|
"[CLOSE]"
|
||||||
|
);
|
||||||
|
|
||||||
|
for (String actionString : actions) {
|
||||||
|
int prefixStart = actionString.indexOf("[");
|
||||||
|
int prefixEnd = actionString.indexOf("]");
|
||||||
|
if (prefixStart < 0 || prefixEnd < 0) continue;
|
||||||
|
|
||||||
|
String prefix = actionString.substring(prefixStart + 1, prefixEnd);
|
||||||
|
ClickType clickType = null;
|
||||||
|
GUIActionType actionType;
|
||||||
|
if (prefix.contains(":")) {
|
||||||
|
String[] args = prefix.split(":");
|
||||||
|
clickType = GUIConfiguration.readClickType(args[0]);
|
||||||
|
actionType = GUIActionType.readActionType(args[1]);
|
||||||
|
} else {
|
||||||
|
actionType = GUIActionType.readActionType(prefix);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (actionType == null) {
|
||||||
|
System.out.println("# " + actionString);
|
||||||
|
System.out.println("- actionType is Null");
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
System.out.println("# " + actionType.name() + " " + (clickType == null ? "" : clickType.name()));
|
||||||
|
System.out.println("- " + actionString.substring(prefixEnd + 1).trim());
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -5,7 +5,7 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<artifactId>easyplugin-parent</artifactId>
|
<artifactId>easyplugin-parent</artifactId>
|
||||||
<groupId>cc.carm.lib</groupId>
|
<groupId>cc.carm.lib</groupId>
|
||||||
<version>1.0.0-SNAPSHOT</version>
|
<version>1.1.0</version>
|
||||||
</parent>
|
</parent>
|
||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
|
||||||
|
|||||||
@@ -5,7 +5,7 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<artifactId>easyplugin-parent</artifactId>
|
<artifactId>easyplugin-parent</artifactId>
|
||||||
<groupId>cc.carm.lib</groupId>
|
<groupId>cc.carm.lib</groupId>
|
||||||
<version>1.0.0-SNAPSHOT</version>
|
<version>1.1.0</version>
|
||||||
</parent>
|
</parent>
|
||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
|
||||||
@@ -21,7 +21,7 @@
|
|||||||
<packaging>jar</packaging>
|
<packaging>jar</packaging>
|
||||||
|
|
||||||
<name>EasyPlugin-Main</name>
|
<name>EasyPlugin-Main</name>
|
||||||
<description>轻松插件主要接口集,包含方便的插件入口类与相关工具类。</description>
|
<description>轻松插件主要接口模块,包含方便的插件入口类与相关工具类。</description>
|
||||||
<url>https://github.com/CarmJos/EasyPlugin</url>
|
<url>https://github.com/CarmJos/EasyPlugin</url>
|
||||||
|
|
||||||
<developers>
|
<developers>
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
package cc.carm.lib.easyplugin;
|
package cc.carm.lib.easyplugin;
|
||||||
|
|
||||||
import cc.carm.lib.easyplugin.utils.ColorParser;
|
import cc.carm.lib.easyplugin.i18n.EasyPluginMessageProvider;
|
||||||
import cc.carm.lib.easyplugin.utils.SchedulerUtils;
|
import cc.carm.lib.easyplugin.utils.SchedulerUtils;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.command.CommandExecutor;
|
import org.bukkit.command.CommandExecutor;
|
||||||
@@ -18,47 +18,57 @@ import java.util.Map;
|
|||||||
|
|
||||||
public abstract class EasyPlugin extends JavaPlugin {
|
public abstract class EasyPlugin extends JavaPlugin {
|
||||||
|
|
||||||
|
protected EasyPluginMessageProvider messageProvider;
|
||||||
|
|
||||||
|
public EasyPlugin() {
|
||||||
|
this(new EasyPluginMessageProvider.en_US());
|
||||||
|
}
|
||||||
|
|
||||||
|
public EasyPlugin(EasyPluginMessageProvider messageProvider) {
|
||||||
|
this.messageProvider = messageProvider;
|
||||||
|
}
|
||||||
|
|
||||||
private SchedulerUtils scheduler;
|
private SchedulerUtils scheduler;
|
||||||
private boolean initialized = false;
|
private boolean initialized = false;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onLoad() {
|
public final void onLoad() {
|
||||||
scheduler = new SchedulerUtils(this);
|
scheduler = new SchedulerUtils(this);
|
||||||
|
if (!hasOverride("load")) return;
|
||||||
|
|
||||||
if (!isOverride("load")) return;
|
|
||||||
|
|
||||||
log(getName() + " " + getDescription().getVersion() + " &7开始加载...");
|
|
||||||
long startTime = System.currentTimeMillis();
|
long startTime = System.currentTimeMillis();
|
||||||
|
|
||||||
|
log(messageProvider.loading(this));
|
||||||
load();
|
load();
|
||||||
log("加载完成 ,共耗时 " + (System.currentTimeMillis() - startTime) + " ms 。");
|
log(messageProvider.loaded(this, startTime));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onEnable() {
|
public final void onEnable() {
|
||||||
|
outputInfo();
|
||||||
|
|
||||||
log(getName() + " " + getDescription().getVersion() + " &7开始启动...");
|
log(messageProvider.enabling(this));
|
||||||
long startTime = System.currentTimeMillis();
|
long startTime = System.currentTimeMillis();
|
||||||
|
|
||||||
this.initialized = initialize();
|
if (!(this.initialized = initialize())) {
|
||||||
|
|
||||||
if (!isInitialized()) {
|
|
||||||
setEnabled(false);
|
setEnabled(false);
|
||||||
|
log(messageProvider.enableFailure(this, startTime));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
log("启用完成 ,共耗时 " + (System.currentTimeMillis() - startTime) + " ms 。");
|
log(messageProvider.enableSuccess(this, startTime));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onDisable() {
|
public final void onDisable() {
|
||||||
if (!isOverride("shutdown")) return;
|
if (!hasOverride("shutdown") || !isInitialized()) return;
|
||||||
|
outputInfo();
|
||||||
|
|
||||||
log(getName() + " " + getDescription().getVersion() + " 开始卸载...");
|
log(messageProvider.disabling(this));
|
||||||
long startTime = System.currentTimeMillis();
|
long startTime = System.currentTimeMillis();
|
||||||
shutdown();
|
shutdown();
|
||||||
log("卸载完成 ,共耗时 " + (System.currentTimeMillis() - startTime) + " ms 。");
|
log(messageProvider.disabled(this, startTime));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void load() {
|
public void load() {
|
||||||
@@ -69,6 +79,12 @@ public abstract class EasyPlugin extends JavaPlugin {
|
|||||||
public void shutdown() {
|
public void shutdown() {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 重写以展示插件的相关信息,如插件横幅、下载地址等。
|
||||||
|
*/
|
||||||
|
public void outputInfo() {
|
||||||
|
}
|
||||||
|
|
||||||
public boolean isInitialized() {
|
public boolean isInitialized() {
|
||||||
return initialized;
|
return initialized;
|
||||||
}
|
}
|
||||||
@@ -99,28 +115,25 @@ public abstract class EasyPlugin extends JavaPlugin {
|
|||||||
if (tabCompleter != null) command.setTabCompleter(tabCompleter);
|
if (tabCompleter != null) command.setTabCompleter(tabCompleter);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void print(@Nullable String prefix, @Nullable String... messages) {
|
||||||
|
messageProvider.print(this, prefix, messages);
|
||||||
|
}
|
||||||
|
|
||||||
public void log(@Nullable String... messages) {
|
public void log(@Nullable String... messages) {
|
||||||
print(null, messages);
|
print(null, messages);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void print(@Nullable String prefix, @Nullable String... messages) {
|
|
||||||
Arrays.stream(messages)
|
|
||||||
.map(message -> "[" + getName() + "] " + (prefix == null ? "" : prefix) + message)
|
|
||||||
.map(ColorParser::parse)
|
|
||||||
.forEach(message -> Bukkit.getConsoleSender().sendMessage(message));
|
|
||||||
}
|
|
||||||
|
|
||||||
public void error(String... messages) {
|
public void error(String... messages) {
|
||||||
print("&c[ERROR] &r", messages);
|
print("&c[ERROR] &r", messages);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void debug(@Nullable String... messages) {
|
public void debug(@Nullable String... messages) {
|
||||||
if (isDebugging()) print("&7[DEBUG] &r", messages);
|
if (isDebugging()) print("&8[DEBUG] &r", messages);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private boolean isOverride(String methodName) {
|
@SuppressWarnings("BooleanMethodIsAlwaysInverted")
|
||||||
|
private boolean hasOverride(String methodName) {
|
||||||
Map<Method, Method> methodMap = new HashMap<>();
|
Map<Method, Method> methodMap = new HashMap<>();
|
||||||
Arrays.stream(EasyPlugin.class.getDeclaredMethods())
|
Arrays.stream(EasyPlugin.class.getDeclaredMethods())
|
||||||
.filter(method -> method.getName().equals(methodName))
|
.filter(method -> method.getName().equals(methodName))
|
||||||
@@ -132,4 +145,5 @@ public abstract class EasyPlugin extends JavaPlugin {
|
|||||||
);
|
);
|
||||||
return !methodMap.isEmpty();
|
return !methodMap.isEmpty();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
+110
@@ -0,0 +1,110 @@
|
|||||||
|
package cc.carm.lib.easyplugin.i18n;
|
||||||
|
|
||||||
|
import cc.carm.lib.easyplugin.utils.ColorParser;
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.plugin.Plugin;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
|
import java.util.Arrays;
|
||||||
|
|
||||||
|
public interface EasyPluginMessageProvider {
|
||||||
|
|
||||||
|
String loading(Plugin plugin);
|
||||||
|
|
||||||
|
String loaded(Plugin plugin, long startMillis);
|
||||||
|
|
||||||
|
String enabling(Plugin plugin);
|
||||||
|
|
||||||
|
String enableSuccess(Plugin plugin, long startMillis);
|
||||||
|
|
||||||
|
String enableFailure(Plugin plugin, long startMillis);
|
||||||
|
|
||||||
|
String disabling(Plugin plugin);
|
||||||
|
|
||||||
|
String disabled(Plugin plugin, long startMillis);
|
||||||
|
|
||||||
|
default void print(@NotNull Plugin plugin, @Nullable String prefix, @Nullable String... messages) {
|
||||||
|
Arrays.stream(messages)
|
||||||
|
.map(message -> "[" + plugin.getName() + "] " + (prefix == null ? "" : prefix) + message)
|
||||||
|
.map(ColorParser::parse)
|
||||||
|
.forEach(message -> Bukkit.getConsoleSender().sendMessage(message));
|
||||||
|
}
|
||||||
|
|
||||||
|
class zh_CN implements EasyPluginMessageProvider {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String loading(Plugin plugin) {
|
||||||
|
return "&f" + plugin.getName() + " " + plugin.getDescription().getVersion() + " 开始加载...";
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String loaded(Plugin plugin, long startMillis) {
|
||||||
|
return "&f加载完成 ,共耗时 " + (System.currentTimeMillis() - startMillis) + " ms 。";
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String enabling(Plugin plugin) {
|
||||||
|
return "&f" + plugin.getName() + " " + plugin.getDescription().getVersion() + " 开始启动...";
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String enableSuccess(Plugin plugin, long startMillis) {
|
||||||
|
return "&a启用完成! &f共耗时 " + (System.currentTimeMillis() - startMillis) + " ms 。";
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String enableFailure(Plugin plugin, long startMillis) {
|
||||||
|
return "&c启用失败! &f已耗时 " + (System.currentTimeMillis() - startMillis) + " ms 。";
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String disabling(Plugin plugin) {
|
||||||
|
return "&f" + plugin.getName() + " " + plugin.getDescription().getVersion() + " 开始卸载...";
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String disabled(Plugin plugin, long startMillis) {
|
||||||
|
return "&f卸载完成! 共耗时 " + (System.currentTimeMillis() - startMillis) + " ms 。";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class en_US implements EasyPluginMessageProvider {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String loading(Plugin plugin) {
|
||||||
|
return "&f" + plugin.getName() + " " + plugin.getDescription().getVersion() + " loading...";
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String loaded(Plugin plugin, long startMillis) {
|
||||||
|
return "&fLoaded after " + (System.currentTimeMillis() - startMillis) + " ms.";
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String enabling(Plugin plugin) {
|
||||||
|
return "&f" + plugin.getName() + " " + plugin.getDescription().getVersion() + " enabling...";
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String enableSuccess(Plugin plugin, long startMillis) {
|
||||||
|
return "&aEnabled successfully!&f Cost " + (System.currentTimeMillis() - startMillis) + " ms.";
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String enableFailure(Plugin plugin, long startMillis) {
|
||||||
|
return "&cEnabled failed after " + (System.currentTimeMillis() - startMillis) + " ms.";
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String disabling(Plugin plugin) {
|
||||||
|
return "&f" + plugin.getName() + " " + plugin.getDescription().getVersion() + " begin to shutdown...";
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String disabled(Plugin plugin, long startMillis) {
|
||||||
|
return "&fShutdown successfully, cost " + (System.currentTimeMillis() - startMillis) + " ms.";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -5,7 +5,7 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<artifactId>easyplugin-parent</artifactId>
|
<artifactId>easyplugin-parent</artifactId>
|
||||||
<groupId>cc.carm.lib</groupId>
|
<groupId>cc.carm.lib</groupId>
|
||||||
<version>1.0.0-SNAPSHOT</version>
|
<version>1.1.0</version>
|
||||||
</parent>
|
</parent>
|
||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
|
||||||
|
|||||||
@@ -5,7 +5,7 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<artifactId>easyplugin-parent</artifactId>
|
<artifactId>easyplugin-parent</artifactId>
|
||||||
<groupId>cc.carm.lib</groupId>
|
<groupId>cc.carm.lib</groupId>
|
||||||
<version>1.0.0-SNAPSHOT</version>
|
<version>1.1.0</version>
|
||||||
</parent>
|
</parent>
|
||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
|
||||||
|
|||||||
@@ -14,7 +14,7 @@
|
|||||||
<groupId>cc.carm.lib</groupId>
|
<groupId>cc.carm.lib</groupId>
|
||||||
<artifactId>easyplugin-parent</artifactId>
|
<artifactId>easyplugin-parent</artifactId>
|
||||||
<packaging>pom</packaging>
|
<packaging>pom</packaging>
|
||||||
<version>1.0.0-SNAPSHOT</version>
|
<version>1.1.0</version>
|
||||||
<modules>
|
<modules>
|
||||||
<module>easyplugin-main</module>
|
<module>easyplugin-main</module>
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user