mirror of
https://github.com/CarmJos/MoeTeleport.git
synced 2026-06-04 16:46:10 +08:00
Compare commits
11 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 4f232d35c4 | |||
| f2bfdf4635 | |||
| 3a016fb560 | |||
| 7cf0b9ed01 | |||
| 5f6a44d96f | |||
| d24278b81c | |||
| d1ff8a12d4 | |||
| 3c07da0e3f | |||
| 61d97c2df4 | |||
| 514f757fe8 | |||
| 33c2f9de78 |
@@ -15,7 +15,7 @@
|
||||
|
||||
项目代码符合开发规范,适合新手开发者学习Bukkit,制作属于自己的插件。
|
||||
|
||||
本插件由 [璎珞服务器](https://www.yingluo.world/) 请求本人开发,经过授权后开源。
|
||||
本插件由 [璎珞服务器](https://www.yingluo.world/) 委托本人开发,经过授权后开源。
|
||||
|
||||
## 功能与优势
|
||||
|
||||
@@ -107,6 +107,9 @@ homes:
|
||||
|
||||
```
|
||||
|
||||
## 使用统计
|
||||
[](https://bstats.org/plugin/bukkit/MoeTeleport/14459)
|
||||
|
||||
## 支持与捐赠
|
||||
|
||||
若您觉得本插件做的不错,您可以捐赠支持我!
|
||||
@@ -118,7 +121,9 @@ homes:
|
||||
## 开源协议
|
||||
|
||||
本项目源码采用 [GNU General Public License v3.0](https://opensource.org/licenses/GPL-3.0) 开源协议。
|
||||
> ### 关于 GPL 协议
|
||||
<details>
|
||||
<summary>关于 GPL 协议</summary>
|
||||
|
||||
> GNU General Public Licence (GPL) 有可能是开源界最常用的许可模式。GPL 保证了所有开发者的权利,同时为使用者提供了足够的复制,分发,修改的权利:
|
||||
>
|
||||
> #### 可自由复制
|
||||
@@ -133,3 +138,4 @@ homes:
|
||||
> 需要注意的是,分发的时候,需要明确提供源代码和二进制文件,另外,用于某些程序的某些协议有一些问题和限制,你可以看一下 @PierreJoye 写的 Practical Guide to GPL Compliance 一文。使用 GPL 协议,你必须在源代码代码中包含相应信息,以及协议本身。
|
||||
>
|
||||
> *以上文字来自 [五种开源协议GPL,LGPL,BSD,MIT,Apache](https://www.oschina.net/question/54100_9455) 。*
|
||||
</details>
|
||||
|
||||
@@ -15,7 +15,7 @@
|
||||
|
||||
<groupId>cc.carm.plugin</groupId>
|
||||
<artifactId>moeteleport</artifactId>
|
||||
<version>3.1.0</version>
|
||||
<version>3.1.2</version>
|
||||
|
||||
<name>MoeTeleport</name>
|
||||
<description>喵喵传送,简单的传送、设置家的插件。</description>
|
||||
@@ -179,7 +179,7 @@
|
||||
<dependency>
|
||||
<groupId>org.jetbrains</groupId>
|
||||
<artifactId>annotations</artifactId>
|
||||
<version>22.0.0</version>
|
||||
<version>23.0.0</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
|
||||
@@ -280,6 +280,10 @@
|
||||
</filter>
|
||||
</filters>
|
||||
<relocations>
|
||||
<relocation>
|
||||
<pattern>cc.carm.lib</pattern>
|
||||
<shadedPattern>cc.carm.plugin.moeteleport.lib</shadedPattern>
|
||||
</relocation>
|
||||
<relocation>
|
||||
<pattern>de.themoep.minedown</pattern>
|
||||
<shadedPattern>cc.carm.plugin.moeteleport.lib.minedown</shadedPattern>
|
||||
@@ -292,18 +296,6 @@
|
||||
<pattern>org.json</pattern>
|
||||
<shadedPattern>cc.carm.plugin.moeteleport.lib.json</shadedPattern>
|
||||
</relocation>
|
||||
<relocation>
|
||||
<pattern>cc.carm.lib.easyplugin</pattern>
|
||||
<shadedPattern>cc.carm.plugin.ultradepository.lib.easyplugin</shadedPattern>
|
||||
</relocation>
|
||||
<relocation>
|
||||
<pattern>cc.carm.lib.easysql</pattern>
|
||||
<shadedPattern>cc.carm.plugin.moeteleport.lib.easysql</shadedPattern>
|
||||
</relocation>
|
||||
<relocation>
|
||||
<pattern>cc.carm.lib.githubreleases4j</pattern>
|
||||
<shadedPattern>cc.carm.plugin.moeteleport.lib.github</shadedPattern>
|
||||
</relocation>
|
||||
</relocations>
|
||||
</configuration>
|
||||
</plugin>
|
||||
|
||||
@@ -34,10 +34,11 @@ import java.util.Arrays;
|
||||
|
||||
public class Main extends EasyPlugin {
|
||||
private static Main instance;
|
||||
private static DataStorage storage;
|
||||
private WarpManager warpManager;
|
||||
private UserManager userManager;
|
||||
private RequestManager requestManager;
|
||||
|
||||
protected DataStorage storage;
|
||||
protected WarpManager warpManager;
|
||||
protected UserManager userManager;
|
||||
protected RequestManager requestManager;
|
||||
|
||||
public Main() {
|
||||
super(new EasyPluginMessageProvider.zh_CN());
|
||||
@@ -57,7 +58,7 @@ public class Main extends EasyPlugin {
|
||||
getInstance().log(messages);
|
||||
}
|
||||
|
||||
public static void serve(String... messages) {
|
||||
public static void severe(String... messages) {
|
||||
getInstance().error(messages);
|
||||
}
|
||||
|
||||
@@ -74,23 +75,25 @@ public class Main extends EasyPlugin {
|
||||
|
||||
info("加载配置文件...");
|
||||
if (!ConfigManager.initConfig()) {
|
||||
serve("配置文件初始化失败,请检查。");
|
||||
severe("配置文件初始化失败,请检查。");
|
||||
setEnabled(false);
|
||||
return false;
|
||||
}
|
||||
|
||||
info("初始化存储方式...");
|
||||
StorageMethod storageMethod = StorageMethod.read(PluginConfig.STORAGE_METHOD.get());
|
||||
info(" 正在使用 " + storageMethod.name() + " 进行数据存储");
|
||||
|
||||
try {
|
||||
info(" 正在使用 " + storageMethod.name() + " 进行数据存储");
|
||||
storage = storageMethod.createStorage();
|
||||
if (!storage.initialize()) {
|
||||
serve("初始化存储失败,请检查配置文件。");
|
||||
storage.shutdown();
|
||||
storage.initialize();
|
||||
} catch (Exception ex) {
|
||||
severe("初始化存储失败,请检查配置文件。");
|
||||
setEnabled(false);
|
||||
return false; // 初始化失败,不再继续加载
|
||||
}
|
||||
|
||||
|
||||
info("加载地标管理器...");
|
||||
warpManager = new WarpManager();
|
||||
|
||||
@@ -98,7 +101,7 @@ public class Main extends EasyPlugin {
|
||||
this.userManager = new UserManager();
|
||||
if (Bukkit.getOnlinePlayers().size() > 0) {
|
||||
info(" 加载现有用户数据...");
|
||||
getUserManager().loadAll();
|
||||
this.userManager.loadAll();
|
||||
}
|
||||
|
||||
info("加载请求管理器...");
|
||||
@@ -147,16 +150,16 @@ public class Main extends EasyPlugin {
|
||||
@Override
|
||||
protected void shutdown() {
|
||||
info("关闭所有请求...");
|
||||
getRequestManager().shutdown();
|
||||
this.requestManager.shutdown();
|
||||
|
||||
info("保存用户数据...");
|
||||
getUserManager().unloadAll(true);
|
||||
this.userManager.unloadAll(true);
|
||||
|
||||
info("保存地标数据...");
|
||||
getWarpManager().saveWarps();
|
||||
this.warpManager.saveWarps();
|
||||
|
||||
info("终止存储源...");
|
||||
getStorage().shutdown();
|
||||
this.storage.shutdown();
|
||||
|
||||
info("卸载监听器...");
|
||||
Bukkit.getServicesManager().unregisterAll(this);
|
||||
@@ -174,21 +177,5 @@ public class Main extends EasyPlugin {
|
||||
}
|
||||
}
|
||||
|
||||
protected DataStorage getStorage() {
|
||||
return storage;
|
||||
}
|
||||
|
||||
protected WarpManager getWarpManager() {
|
||||
return getInstance().warpManager;
|
||||
}
|
||||
|
||||
protected UserManager getUserManager() {
|
||||
return getInstance().userManager;
|
||||
}
|
||||
|
||||
protected RequestManager getRequestManager() {
|
||||
return getInstance().requestManager;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -6,8 +6,6 @@ import cc.carm.plugin.moeteleport.manager.WarpManager;
|
||||
import cc.carm.plugin.moeteleport.storage.DataStorage;
|
||||
import cc.carm.plugin.moeteleport.storage.StorageMethod;
|
||||
|
||||
import java.util.function.Supplier;
|
||||
|
||||
public class MoeTeleport {
|
||||
|
||||
public static void outputInfo() {
|
||||
@@ -15,27 +13,27 @@ public class MoeTeleport {
|
||||
}
|
||||
|
||||
public static DataStorage getStorage() {
|
||||
return Main.getInstance().getStorage();
|
||||
return Main.getInstance().storage;
|
||||
}
|
||||
|
||||
public static WarpManager getWarpManager() {
|
||||
return Main.getInstance().getWarpManager();
|
||||
return Main.getInstance().warpManager;
|
||||
}
|
||||
|
||||
public static UserManager getUserManager() {
|
||||
return Main.getInstance().getUserManager();
|
||||
return Main.getInstance().userManager;
|
||||
}
|
||||
|
||||
public static RequestManager getRequestManager() {
|
||||
return Main.getInstance().getRequestManager();
|
||||
return Main.getInstance().requestManager;
|
||||
}
|
||||
|
||||
public void registerCustomStorage(DataStorage storage) {
|
||||
registerCustomStorage(() -> storage);
|
||||
public void setStorage(DataStorage storage) {
|
||||
Main.getInstance().storage = storage;
|
||||
}
|
||||
|
||||
public void registerCustomStorage(Supplier<DataStorage> storageSupplier) {
|
||||
StorageMethod.CUSTOM.setStorageSupplier(storageSupplier);
|
||||
public void registerCustomStorage(Class<? extends DataStorage> storageClazz) {
|
||||
StorageMethod.CUSTOM.setStorageClazz(storageClazz);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -17,7 +17,7 @@ public class PluginMessages extends MessagesRoot {
|
||||
).build();
|
||||
|
||||
public static final EasyMessageList DEATH_MESSAGE = MoeMessageList.builder().contents(
|
||||
"&f您可以输入 &5/back &f或 [&d&l点击这里](show_text=点击返回到死亡地点 run_command=/back) &f返回您的死亡地点。"
|
||||
"&f您可以输入 &5/back &f或 [&d&l点击这里](show_text=点击返回到死亡地点 run_command=/moeteleport:back) &f返回您的死亡地点。"
|
||||
).build();
|
||||
|
||||
}
|
||||
@@ -70,14 +70,14 @@ public class PluginMessages extends MessagesRoot {
|
||||
|
||||
public static final EasyMessageList RECEIVED_TP_HERE = MoeMessageList.builder().contents(
|
||||
"&d%(player) &f请求传送到您身边,您有 &5%(expire)秒 &f的时间回应。",
|
||||
" [&a&l[点击同意]](show_text=点击同意请求 run_command=/tpAccept %(player)) &f或输入 &5/tpAccept &f同意该请求。",
|
||||
" [&c&l[点击拒绝]](show_text=点击拒绝请求 run_command=/tpDeny %(player)) &f或输入 &5/tpDeny &f拒绝该请求。"
|
||||
" [&a&l[点击同意]](show_text=点击同意请求 run_command=/moeteleport:tpaccept %(player)) &f或输入 &5/tpAccept &f同意该请求。",
|
||||
" [&c&l[点击拒绝]](show_text=点击拒绝请求 run_command=/moeteleport:tpdeny %(player)) &f或输入 &5/tpDeny &f拒绝该请求。"
|
||||
).params("player", "expire").build();
|
||||
|
||||
public static final EasyMessageList RECEIVED_TP_TO = MoeMessageList.builder().contents(
|
||||
"&d%(player) &f请求传送您到Ta身边,您有 &5%(expire)秒 &f的时间回应。",
|
||||
" [&a&l[点击同意]](show_text=点击同意请求 run_command=/tpAccept %(player)) &f或输入 &5/tpAccept &f同意该请求。",
|
||||
" [&c&l[点击拒绝]](show_text=点击拒绝请求 run_command=/tpDeny %(player)) &f或输入 &5/tpDeny &f拒绝该请求。"
|
||||
" [&a&l[点击同意]](show_text=点击同意请求 run_command=/moeteleport:tpaccept %(player)) &f或输入 &5/tpAccept &f同意该请求。",
|
||||
" [&c&l[点击拒绝]](show_text=点击拒绝请求 run_command=/moeteleport:tpdeny %(player)) &f或输入 &5/tpDeny &f拒绝该请求。"
|
||||
).params("player", "expire").build();
|
||||
|
||||
|
||||
@@ -145,7 +145,7 @@ public class PluginMessages extends MessagesRoot {
|
||||
).build();
|
||||
|
||||
public static final EasyMessageList OBJECT = MoeMessageList.builder().contents(
|
||||
"&8# &f%(id) &d%(location) [&7✈](show_text=点击返回家 %(id) run_command=/home %(id))"
|
||||
"&8# &f%(id) &d%(location) [&7✈](show_text=点击返回家 %(id) run_command=/moeteleport:home %(id))"
|
||||
).params("id", "location").build();
|
||||
|
||||
}
|
||||
@@ -177,11 +177,11 @@ public class PluginMessages extends MessagesRoot {
|
||||
).params("max").build();
|
||||
|
||||
public static final EasyMessageList INFO_LOCATION = MoeMessageList.builder().contents(
|
||||
"&f地标点 &d%(name) &f所在位置为 &5%(location) &f。[&7✈](show_text=点击前往&d %(name) run_command=/warp %(name))"
|
||||
"&f地标点 &d%(name) &f所在位置为 &5%(location) &f。[&7✈](show_text=点击前往&d %(name) run_command=/moeteleport:warp %(name))"
|
||||
).params("name", "location").build();
|
||||
|
||||
public static final EasyMessageList INFO_FULL = MoeMessageList.builder().contents(
|
||||
"&f地标点 &d%(name) &f由 &5%(owner) &f创建,所在位置为 &d%(location) &f。[&7✈](show_text=点击前往&d %(name) run_command=/warp %(name))"
|
||||
"&f地标点 &d%(name) &f由 &5%(owner) &f创建,所在位置为 &d%(location) &f。[&7✈](show_text=点击前往&d %(name) run_command=/moeteleport:warp %(name))"
|
||||
).params("name", "owner", "location").build();
|
||||
|
||||
public static final EasyMessageList SET = MoeMessageList.builder().contents(
|
||||
@@ -207,12 +207,12 @@ public class PluginMessages extends MessagesRoot {
|
||||
|
||||
public static final EasyMessageList OBJECT = MoeMessageList.builder().contents(
|
||||
"&8# &f%(id) &7[由%(owner)创建]",
|
||||
"&8- &d%(location) [&7✈](show_text=点击前往&d %(id) run_command=/warp %(id))"
|
||||
"&8- &d%(location) [&7✈](show_text=点击前往&d %(id) run_command=/moeteleport:warp %(id))"
|
||||
).params("id", "owner", "location").build();
|
||||
|
||||
public static final EasyMessageList OBJECT_NO_OWNER = MoeMessageList.builder().contents(
|
||||
"&8# &f%(id)",
|
||||
"&8- &d%(location) [&7✈](show_text=点击前往&d %(id) run_command=/warp %(id))"
|
||||
"&8- &d%(location) [&7✈](show_text=点击前往&d %(id) run_command=/moeteleport:warp %(id))"
|
||||
).params("id", "location").build();
|
||||
|
||||
}
|
||||
|
||||
@@ -58,8 +58,8 @@ public class UserManager {
|
||||
|
||||
return data;
|
||||
} catch (Exception e) {
|
||||
Main.serve("无法正常读取玩家数据,玩家操作将不会被保存,请检查数据配置!");
|
||||
Main.serve("Could not load user's data, please check the data configuration!");
|
||||
Main.severe("无法正常读取玩家数据,玩家操作将不会被保存,请检查数据配置!");
|
||||
Main.severe("Could not load user's data, please check the data configuration!");
|
||||
e.printStackTrace();
|
||||
return new UserData(userUUID);
|
||||
}
|
||||
@@ -77,8 +77,8 @@ public class UserManager {
|
||||
"耗时 " + (System.currentTimeMillis() - start) + "ms。");
|
||||
|
||||
} catch (Exception e) {
|
||||
Main.serve("无法正常保存玩家数据,请检查数据配置!");
|
||||
Main.serve("Could not save user's data, please check the data configuration!");
|
||||
Main.severe("无法正常保存玩家数据,请检查数据配置!");
|
||||
Main.severe("Could not save user's data, please check the data configuration!");
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
@@ -143,8 +143,8 @@ public class UserManager {
|
||||
try {
|
||||
task.run(MoeTeleport.getStorage());
|
||||
} catch (Exception exception) {
|
||||
Main.serve("无法正常更改玩家数据,请检查数据配置!");
|
||||
Main.serve("Could not edit user's data, please check the data configuration!");
|
||||
Main.severe("无法正常更改玩家数据,请检查数据配置!");
|
||||
Main.severe("Could not edit user's data, please check the data configuration!");
|
||||
exception.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,7 +19,7 @@ public class WarpManager {
|
||||
try {
|
||||
MoeTeleport.getStorage().saveWarps();
|
||||
} catch (Exception exception) {
|
||||
Main.serve("保存地标数据失败,请检查配置文件。");
|
||||
Main.severe("保存地标数据失败,请检查配置文件。");
|
||||
exception.printStackTrace();
|
||||
}
|
||||
}
|
||||
@@ -33,7 +33,7 @@ public class WarpManager {
|
||||
try {
|
||||
MoeTeleport.getStorage().setWarp(name, new WarpInfo(name,owner, location));
|
||||
} catch (Exception exception) {
|
||||
Main.serve("保存地标数据 " + name + " 失败,请检查配置文件。");
|
||||
Main.severe("保存地标数据 " + name + " 失败,请检查配置文件。");
|
||||
exception.printStackTrace();
|
||||
}
|
||||
|
||||
@@ -51,7 +51,7 @@ public class WarpManager {
|
||||
try {
|
||||
MoeTeleport.getStorage().delWarp(name);
|
||||
} catch (Exception exception) {
|
||||
Main.serve("删除地标数据 " + name + " 失败,请检查配置文件。");
|
||||
Main.severe("删除地标数据 " + name + " 失败,请检查配置文件。");
|
||||
exception.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -15,9 +15,9 @@ public interface DataStorage {
|
||||
/**
|
||||
* 在插件加载存储源时执行。
|
||||
*
|
||||
* @return 是否初始化成功
|
||||
* @throws Exception 当出现任何错误时抛出
|
||||
*/
|
||||
boolean initialize();
|
||||
void initialize() throws Exception;
|
||||
|
||||
/**
|
||||
* 在插件被卸载时执行。
|
||||
|
||||
@@ -10,25 +10,24 @@ import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Optional;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
public enum StorageMethod {
|
||||
|
||||
CUSTOM(0, new String[]{}, CustomStorage::new),
|
||||
YAML(1, new String[]{"yml"}, YAMLStorage::new),
|
||||
JSON(2, new String[]{}, JSONStorage::new),
|
||||
MYSQL(3, new String[]{"my-sql", "mariadb", "sql", "database"}, MySQLStorage::new),
|
||||
CUSTOM(0, new String[]{}, CustomStorage.class),
|
||||
YAML(1, new String[]{"yml"}, YAMLStorage.class),
|
||||
JSON(2, new String[]{}, JSONStorage.class),
|
||||
MYSQL(3, new String[]{"my-sql", "mariadb", "sql", "database"}, MySQLStorage.class),
|
||||
|
||||
ESSENTIALS(11, new String[]{"essential", "ess", "EssentialsX", "essX"}, EssentialStorage::new);
|
||||
ESSENTIALS(11, new String[]{"essential", "ess", "EssentialsX", "essX"}, EssentialStorage.class);
|
||||
|
||||
private final int id;
|
||||
private final String[] alias;
|
||||
private @NotNull Supplier<@NotNull DataStorage> storageSupplier;
|
||||
private @NotNull Class<? extends DataStorage> storageClazz;
|
||||
|
||||
StorageMethod(int id, String[] alias, @NotNull Supplier<@NotNull DataStorage> storageSupplier) {
|
||||
StorageMethod(int id, String[] alias, @NotNull Class<? extends DataStorage> storageClazz) {
|
||||
this.id = id;
|
||||
this.alias = alias;
|
||||
this.storageSupplier = storageSupplier;
|
||||
this.storageClazz = storageClazz;
|
||||
}
|
||||
|
||||
public static @NotNull StorageMethod read(String s) {
|
||||
@@ -65,15 +64,15 @@ public enum StorageMethod {
|
||||
return alias;
|
||||
}
|
||||
|
||||
public @NotNull Supplier<@NotNull DataStorage> getStorageSupplier() {
|
||||
return storageSupplier;
|
||||
public @NotNull Class<? extends DataStorage> getStorageClazz() {
|
||||
return storageClazz;
|
||||
}
|
||||
|
||||
public void setStorageSupplier(@NotNull Supplier<@NotNull DataStorage> storageSupplier) {
|
||||
this.storageSupplier = storageSupplier;
|
||||
public void setStorageClazz(@NotNull Class<? extends DataStorage> storageClazz) {
|
||||
this.storageClazz = storageClazz;
|
||||
}
|
||||
|
||||
public @NotNull DataStorage createStorage() {
|
||||
return getStorageSupplier().get();
|
||||
public @NotNull DataStorage createStorage() throws Exception {
|
||||
return getStorageClazz().newInstance();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,10 +17,10 @@ public class CustomStorage implements DataStorage {
|
||||
|
||||
@Override
|
||||
@TestOnly
|
||||
public boolean initialize() {
|
||||
Main.serve("您选择使用自定义存储,但并没有应用成功。");
|
||||
Main.serve("You are using CustomStorage, but not overwrite the methods.");
|
||||
return false;
|
||||
public void initialize() throws UnsupportedOperationException {
|
||||
Main.severe("您选择使用自定义存储,但并没有应用成功。");
|
||||
Main.severe("You are using CustomStorage, but not overwrite the methods.");
|
||||
throw new UnsupportedOperationException("您选择使用自定义存储,但并没有应用成功。");
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -31,14 +31,14 @@ public class CustomStorage implements DataStorage {
|
||||
|
||||
@Override
|
||||
@TestOnly
|
||||
public @Nullable UserData loadData(@NotNull UUID uuid) {
|
||||
return null;
|
||||
public @Nullable UserData loadData(@NotNull UUID uuid) throws UnsupportedOperationException {
|
||||
throw new UnsupportedOperationException("您选择使用自定义存储,但并没有应用成功。");
|
||||
}
|
||||
|
||||
@Override
|
||||
@TestOnly
|
||||
public void saveUserData(@NotNull UserData data) {
|
||||
|
||||
public void saveUserData(@NotNull UserData data) throws UnsupportedOperationException {
|
||||
throw new UnsupportedOperationException("您选择使用自定义存储,但并没有应用成功。");
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -26,7 +26,7 @@ public class MySQLStorage implements DataStorage {
|
||||
Map<String, WarpInfo> warpsMap = new HashMap<>();
|
||||
|
||||
@Override
|
||||
public boolean initialize() {
|
||||
public void initialize() throws Exception {
|
||||
try {
|
||||
Main.info(" 尝试连接到数据库...");
|
||||
String url = String.format("jdbc:mysql://%s:%s/%s?useSSL=false",
|
||||
@@ -38,9 +38,7 @@ public class MySQLStorage implements DataStorage {
|
||||
);
|
||||
this.sqlManager.setDebugMode(() -> Main.getInstance().isDebugging());
|
||||
} catch (Exception exception) {
|
||||
Main.serve("无法连接到数据库,请检查配置文件。");
|
||||
exception.printStackTrace();
|
||||
return false;
|
||||
throw new Exception("无法连接到数据库,请检查配置文件", exception);
|
||||
}
|
||||
|
||||
try {
|
||||
@@ -58,20 +56,15 @@ public class MySQLStorage implements DataStorage {
|
||||
.build().execute();
|
||||
|
||||
} catch (SQLException exception) {
|
||||
Main.serve("无法创建插件所需的表,请检查数据库权限。");
|
||||
exception.printStackTrace();
|
||||
return false;
|
||||
throw new Exception("无法创建插件所需的表,请检查数据库权限。", exception);
|
||||
}
|
||||
|
||||
Main.info(" 加载地标数据...");
|
||||
try {
|
||||
this.warpsMap = loadWarps();
|
||||
} catch (Exception e) {
|
||||
Main.serve("无法加载地标数据,请检查数据库权限和相关表。");
|
||||
e.printStackTrace();
|
||||
throw new Exception("无法加载地标数据,请检查数据库权限和相关表。", e);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -16,17 +16,10 @@ import java.util.UUID;
|
||||
|
||||
public class EssentialStorage extends PluginBasedStorage {
|
||||
|
||||
private Essentials essentials;
|
||||
|
||||
public EssentialStorage() {
|
||||
super("Essentials");
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean initialize() {
|
||||
return super.initialize() && (this.essentials = (Essentials) getDependPlugin()) != null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public @Nullable UserData loadData(@NotNull UUID uuid) {
|
||||
return new EssentialUserData(uuid, getEssentials());
|
||||
@@ -40,7 +33,7 @@ public class EssentialStorage extends PluginBasedStorage {
|
||||
try {
|
||||
Location warpLocation = getEssentials().getWarps().getWarp(warpName);
|
||||
UUID owner = getEssentials().getWarps().getLastOwner(warpName);
|
||||
warps.put(warpName, new WarpInfo(warpName,owner, new DataLocation(warpLocation)));
|
||||
warps.put(warpName, new WarpInfo(warpName, owner, new DataLocation(warpLocation)));
|
||||
} catch (Exception ignore) {
|
||||
}
|
||||
}
|
||||
@@ -74,7 +67,7 @@ public class EssentialStorage extends PluginBasedStorage {
|
||||
}
|
||||
|
||||
public Essentials getEssentials() {
|
||||
return essentials;
|
||||
return (Essentials) getDependPlugin();
|
||||
}
|
||||
|
||||
public static class EssentialUserData extends UserData {
|
||||
|
||||
@@ -30,17 +30,9 @@ public class JSONStorage extends FileBasedStorage {
|
||||
Map<String, WarpInfo> warpsMap = new HashMap<>();
|
||||
|
||||
@Override
|
||||
public boolean initialize() {
|
||||
if (super.initialize()) {
|
||||
try {
|
||||
public void initialize() throws Exception {
|
||||
super.initialize();
|
||||
this.warpsMap = loadWarps();
|
||||
return true;
|
||||
} catch (Exception e) {
|
||||
Main.serve("无法加载地标数据,请检查文件权限和相关配置。");
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -26,22 +26,14 @@ public class YAMLStorage extends FileBasedStorage {
|
||||
FileConfiguration warpsConfiguration;
|
||||
|
||||
@Override
|
||||
public boolean initialize() {
|
||||
if (super.initialize()) {
|
||||
try {
|
||||
public void initialize() throws Exception {
|
||||
super.initialize();
|
||||
this.warpsDataFile = new File(getDataFolder(), "warps.yml");
|
||||
if (!this.warpsDataFile.exists()) {
|
||||
boolean success = warpsDataFile.createNewFile();
|
||||
if (!this.warpsDataFile.exists() && !warpsDataFile.createNewFile()) {
|
||||
throw new Exception("无法创建 warps.yml 文件。");
|
||||
}
|
||||
this.warpsConfiguration = YamlConfiguration.loadConfiguration(warpsDataFile);
|
||||
this.warpsMap = loadWarps();
|
||||
return true;
|
||||
} catch (Exception e) {
|
||||
Main.serve("无法加载地标数据,请检查文件权限和相关配置。");
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -20,16 +20,14 @@ public abstract class FileBasedStorage implements DataStorage {
|
||||
protected @Nullable File dataFolder;
|
||||
|
||||
@Override
|
||||
public boolean initialize() {
|
||||
try {
|
||||
public void initialize() throws Exception {
|
||||
this.dataFolder = new File(Main.getInstance().getDataFolder(), FILE_PATH.get());
|
||||
if (!dataFolder.exists()) {
|
||||
return dataFolder.mkdir();
|
||||
} else {
|
||||
return dataFolder.isDirectory();
|
||||
if (!dataFolder.mkdir()) {
|
||||
throw new Exception("无法创建数据文件夹!");
|
||||
}
|
||||
} catch (Exception ex) {
|
||||
return false;
|
||||
} else if (!dataFolder.isDirectory()) {
|
||||
throw new Exception("数据文件夹路径对应的不是一个文件夹!");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -20,8 +20,10 @@ public abstract class PluginBasedStorage implements DataStorage {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean initialize() {
|
||||
return dependPlugin != null;
|
||||
public void initialize() throws NullPointerException {
|
||||
if (dependPlugin == null) {
|
||||
throw new NullPointerException("该存储类型依赖的插件不存在,请检查配置文件");
|
||||
}
|
||||
}
|
||||
|
||||
public Plugin getDependPlugin() {
|
||||
|
||||
@@ -18,16 +18,16 @@ public class UpdateChecker {
|
||||
|
||||
MoeTeleport.outputInfo();
|
||||
if (behindVersions == null) {
|
||||
Main.serve("检查更新失败,请您定期查看插件是否更新,避免安全问题。");
|
||||
Main.serve("下载地址 " + downloadURL);
|
||||
Main.severe("检查更新失败,请您定期查看插件是否更新,避免安全问题。");
|
||||
Main.severe("下载地址 " + downloadURL);
|
||||
} else if (behindVersions == 0) {
|
||||
Main.info("检查完成,当前已是最新版本。");
|
||||
} else if (behindVersions > 0) {
|
||||
Main.info("发现新版本! 目前已落后 " + behindVersions + " 个版本。");
|
||||
Main.info("最新版下载地址 " + downloadURL);
|
||||
} else {
|
||||
Main.serve("检查更新失败! 当前版本未知,请您使用原生版本以避免安全问题。");
|
||||
Main.serve("最新版下载地址 " + downloadURL);
|
||||
Main.severe("检查更新失败! 当前版本未知,请您使用原生版本以避免安全问题。");
|
||||
Main.severe("最新版下载地址 " + downloadURL);
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user