mirror of
https://github.com/CarmJos/UltraDepository.git
synced 2026-06-05 00:58:22 +08:00
Compare commits
2 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| a427db36e9 | |||
| afd62a493d |
@@ -15,7 +15,7 @@
|
||||
<groupId>cc.carm.plugin</groupId>
|
||||
<artifactId>ultradepository</artifactId>
|
||||
<packaging>jar</packaging>
|
||||
<version>1.3.2</version>
|
||||
<version>1.3.4</version>
|
||||
|
||||
<name>UltraDepository</name>
|
||||
<description>超级仓库插件,支持设定不同物品的存储仓库。</description>
|
||||
@@ -116,6 +116,13 @@
|
||||
<optional>true</optional>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>cc.carm.lib</groupId>
|
||||
<artifactId>githubreleases4j</artifactId>
|
||||
<version>1.2.0</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.spigotmc</groupId>
|
||||
<artifactId>spigot-api</artifactId>
|
||||
@@ -252,10 +259,18 @@
|
||||
<pattern>org.bstats</pattern>
|
||||
<shadedPattern>cc.carm.plugin.ultradepository.lib.bstats</shadedPattern>
|
||||
</relocation>
|
||||
<relocation>
|
||||
<pattern>org.json</pattern>
|
||||
<shadedPattern>cc.carm.plugin.ultradepository.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.githubreleases4j</pattern>
|
||||
<shadedPattern>cc.carm.plugin.ultradepository.lib.github</shadedPattern>
|
||||
</relocation>
|
||||
</relocations>
|
||||
<filters>
|
||||
<filter>
|
||||
|
||||
@@ -7,6 +7,7 @@ import cc.carm.lib.easyplugin.utils.MessageUtils;
|
||||
import cc.carm.plugin.ultradepository.command.DepositoryCommand;
|
||||
import cc.carm.plugin.ultradepository.configuration.PluginConfig;
|
||||
import cc.carm.plugin.ultradepository.hooker.PAPIExpansion;
|
||||
import cc.carm.plugin.ultradepository.hooker.UpdateChecker;
|
||||
import cc.carm.plugin.ultradepository.listener.CollectListener;
|
||||
import cc.carm.plugin.ultradepository.listener.UserListener;
|
||||
import cc.carm.plugin.ultradepository.manager.ConfigManager;
|
||||
@@ -60,9 +61,6 @@ public class UltraDepository extends EasyPlugin {
|
||||
return false;
|
||||
}
|
||||
|
||||
log("加载用户系统...");
|
||||
userManager = new UserManager();
|
||||
|
||||
log("加载经济系统...");
|
||||
if (Bukkit.getPluginManager().getPlugin("Vault") != null) {
|
||||
economyManager = new EconomyManager();
|
||||
@@ -76,11 +74,15 @@ public class UltraDepository extends EasyPlugin {
|
||||
log("加载仓库管理器...");
|
||||
depositoryManager = new DepositoryManager();
|
||||
getDepositoryManager().loadDepositories();
|
||||
GUI.initialize(this);
|
||||
|
||||
log("加载用户系统...");
|
||||
userManager = new UserManager();
|
||||
|
||||
|
||||
log("注册监听器...");
|
||||
regListener(new UserListener());
|
||||
regListener(new CollectListener());
|
||||
GUI.initialize(this);
|
||||
|
||||
log("注册指令...");
|
||||
registerCommand("UltraDepository", new DepositoryCommand());
|
||||
@@ -107,6 +109,16 @@ public class UltraDepository extends EasyPlugin {
|
||||
else return plugin.getDescription().getVersion();
|
||||
}));
|
||||
}
|
||||
|
||||
if (PluginConfig.CHECK_UPDATE.get()) {
|
||||
log("开始检查更新...");
|
||||
UpdateChecker.checkUpdate(this);
|
||||
} else {
|
||||
log("已禁用检查更新,跳过。");
|
||||
}
|
||||
|
||||
getUserManager().loadPlayersData();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -123,6 +135,7 @@ public class UltraDepository extends EasyPlugin {
|
||||
|
||||
log("卸载监听器...");
|
||||
Bukkit.getServicesManager().unregisterAll(this);
|
||||
|
||||
}
|
||||
|
||||
public static DataStorage getStorage() {
|
||||
|
||||
@@ -21,6 +21,10 @@ public class PluginConfig {
|
||||
"metrics", Boolean.class, true
|
||||
);
|
||||
|
||||
public static final ConfigValue<Boolean> CHECK_UPDATE = new ConfigValue<>(
|
||||
"check-update", Boolean.class, true
|
||||
);
|
||||
|
||||
public static final ConfigStringCast<StorageMethod> STORAGE_METHOD = new ConfigStringCast<>(
|
||||
"storage.method", StorageMethod::read, StorageMethod.YAML
|
||||
);
|
||||
|
||||
@@ -0,0 +1,46 @@
|
||||
package cc.carm.plugin.ultradepository.hooker;
|
||||
|
||||
import cc.carm.lib.githubreleases4j.GithubRelease;
|
||||
import cc.carm.lib.githubreleases4j.GithubReleases4J;
|
||||
import cc.carm.plugin.ultradepository.UltraDepository;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class UpdateChecker {
|
||||
|
||||
public static void checkUpdate(UltraDepository plugin) {
|
||||
plugin.getScheduler().runAsync(() -> {
|
||||
|
||||
try {
|
||||
|
||||
List<GithubRelease> releases = GithubReleases4J.listReleases("CarmJos", "UltraDepository");
|
||||
if (releases.isEmpty()) throw new NullPointerException(); // 无法获取更新
|
||||
|
||||
String currentVersion = plugin.getDescription().getVersion();
|
||||
int i = 0;
|
||||
|
||||
for (GithubRelease release : releases) {
|
||||
if (release.getTagName().equalsIgnoreCase(currentVersion)) {
|
||||
break;
|
||||
}
|
||||
i++;
|
||||
}
|
||||
|
||||
if (i > 0) {
|
||||
GithubRelease latestRelease = releases.get(0);
|
||||
plugin.log("检查更新完成,当前已落后 " + i + " 个版本,最新版本为 &6&l" + latestRelease.getTagName() + " &r。");
|
||||
plugin.log("最新版本下载地址&e " + latestRelease.getHTMLUrl());
|
||||
} else {
|
||||
plugin.log("检查更新完成,当前已是最新版本。");
|
||||
}
|
||||
|
||||
} catch (Exception exception) {
|
||||
plugin.error("检查更新失败,请您定期查看插件是否更新,避免安全问题。");
|
||||
plugin.error("插件下载地址&e https://github.com/CarmJos/UltraDepository/releases");
|
||||
}
|
||||
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -20,15 +20,13 @@ public class UserListener implements Listener {
|
||||
if (event.getLoginResult() != AsyncPlayerPreLoginEvent.Result.ALLOWED) {
|
||||
return;
|
||||
}
|
||||
UUID uuid = event.getUniqueId();
|
||||
UltraDepository.getUserManager().getDataCache()
|
||||
.put(uuid, UltraDepository.getUserManager().loadData(uuid));
|
||||
UltraDepository.getUserManager().loadDataCache(event.getUniqueId());
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.MONITOR)
|
||||
public void onPreLoginMonitor(AsyncPlayerPreLoginEvent event) {
|
||||
if (event.getLoginResult() != AsyncPlayerPreLoginEvent.Result.ALLOWED) {
|
||||
UltraDepository.getUserManager().getDataCache().remove(event.getUniqueId());
|
||||
UltraDepository.getUserManager().removeDataCache(event.getUniqueId());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -4,6 +4,7 @@ import cc.carm.plugin.ultradepository.UltraDepository;
|
||||
import cc.carm.plugin.ultradepository.data.UserData;
|
||||
import cc.carm.plugin.ultradepository.storage.DataStorage;
|
||||
import cc.carm.plugin.ultradepository.util.DateIntUtil;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
@@ -20,6 +21,27 @@ public class UserManager {
|
||||
return dataCache;
|
||||
}
|
||||
|
||||
public void loadPlayersData() {
|
||||
if (Bukkit.getOnlinePlayers().size() < 1) return;
|
||||
|
||||
UltraDepository.getInstance().log("加载当前在线玩家数据...");
|
||||
// 用于热加载时重载玩家数据。
|
||||
Bukkit.getOnlinePlayers().forEach(player -> loadDataCache(player.getUniqueId()));
|
||||
}
|
||||
|
||||
public @NotNull UserData loadDataCache(@NotNull UUID userUUID) {
|
||||
UserData data = loadData(userUUID);
|
||||
UltraDepository.getUserManager().getDataCache().put(userUUID, data);
|
||||
return data;
|
||||
}
|
||||
|
||||
|
||||
public boolean removeDataCache(@NotNull UUID userUUID) {
|
||||
boolean contains = getDataCache().containsKey(userUUID);
|
||||
getDataCache().remove(userUUID);
|
||||
return contains;
|
||||
}
|
||||
|
||||
public @Nullable UserData getData(@NotNull UUID userUUID) {
|
||||
return getDataCache().get(userUUID);
|
||||
}
|
||||
@@ -56,7 +78,7 @@ public class UserManager {
|
||||
UserData data = getData(uuid);
|
||||
if (data == null) return;
|
||||
if (save) saveData(data);
|
||||
dataCache.remove(uuid);
|
||||
removeDataCache(uuid);
|
||||
}
|
||||
|
||||
public void saveData(UserData data) {
|
||||
|
||||
@@ -11,6 +11,11 @@ debug: false
|
||||
# 当然,您也可以选择在这里关闭,或在plugins/bStats下的配置文件中关闭。
|
||||
metrics: true
|
||||
|
||||
# 检查更新设定
|
||||
# 该选项用于插件判断是否要检查更新,若您不希望插件检查更新并提示您,可以选择关闭。
|
||||
# 检查更新为异步操作,绝不会影响性能与使用体验。
|
||||
check-update: true
|
||||
|
||||
# 存储相关配置
|
||||
# 注意:存储配置不会通过重载指令生效,如有修改请重新启动服务器。
|
||||
storage:
|
||||
|
||||
@@ -0,0 +1,20 @@
|
||||
import cc.carm.lib.githubreleases4j.GithubRelease;
|
||||
import cc.carm.lib.githubreleases4j.GithubReleases4J;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class ReleasesTest {
|
||||
|
||||
@Test
|
||||
public void onTest() {
|
||||
|
||||
List<GithubRelease> releases = GithubReleases4J.listReleases("CarmJos", "UltraDepository");
|
||||
|
||||
for (GithubRelease release : releases) {
|
||||
System.out.println("#" + release.getID() + " (:" + release.getTagName() + ")" + " " + release.getName());
|
||||
System.out.println("- " + release.getHTMLUrl());
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user