mirror of
https://github.com/Xiao-MoMi/craft-engine.git
synced 2025-12-19 15:09:15 +00:00
Merge branch 'Xiao-MoMi:dev' into dev
This commit is contained in:
@@ -52,6 +52,8 @@ info.resource_pack.upload: "Completed uploading resource pack"
|
||||
info.host.self.netty_server: "Netty HTTP server started on port: <arg:0>"
|
||||
info.host.cache.load: "[<arg:0>] Loaded cached resource pack metadata"
|
||||
info.compatibility: "[Compatibility] <arg:0> hooked"
|
||||
info.update.available: "New version <arg:0> is available: <arg:1>"
|
||||
info.update.latest: "You're running the latest version"
|
||||
command.reload.config.success: "<white>Configs reloaded in <green><arg:0></green> ms.</white> <gray>(Async: <arg:1>ms | Sync: <arg:2>ms)</gray>"
|
||||
command.reload.config.failure: "<red>Config reload failed. Check console logs.</red>"
|
||||
command.reload.pack.success: "<white>Resource pack reloaded in <green><arg:0></green> ms.</white>"
|
||||
|
||||
@@ -52,6 +52,8 @@ info.resource_pack.upload: "资源包上传完成"
|
||||
info.host.self.netty_server: "Netty HTTP 服务已在端口 <arg:0> 开启"
|
||||
info.host.cache.load: "[<arg:0>] 已加载缓存的资源包元数据"
|
||||
info.compatibility: "[兼容性] 已挂钩 <arg:0>"
|
||||
info.update.available: "新版本 <arg:0> 已可供下载: <arg:1>"
|
||||
info.update.latest: "插件已是最新版本"
|
||||
command.reload.config.success: "<white>重新加载配置完成. 耗时 <green><arg:0></green> 毫秒</white> <gray>(异步: <arg:1>ms | 同步: <arg:2>ms)</gray>"
|
||||
command.reload.config.failure: "<red>重新加载配置失败, 请检查控制台日志</red>"
|
||||
command.reload.pack.success: "<white>资源包重新加载完成. 耗时 <green><arg:0></green> 毫秒</white>"
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package net.momirealms.craftengine.core.plugin;
|
||||
|
||||
import com.google.gson.JsonObject;
|
||||
import net.momirealms.craftengine.core.advancement.AdvancementManager;
|
||||
import net.momirealms.craftengine.core.block.BlockManager;
|
||||
import net.momirealms.craftengine.core.entity.furniture.FurnitureManager;
|
||||
@@ -40,14 +41,23 @@ import net.momirealms.craftengine.core.plugin.network.NetworkManager;
|
||||
import net.momirealms.craftengine.core.plugin.scheduler.SchedulerAdapter;
|
||||
import net.momirealms.craftengine.core.sound.SoundManager;
|
||||
import net.momirealms.craftengine.core.util.CompletableFutures;
|
||||
import net.momirealms.craftengine.core.util.GsonHelper;
|
||||
import net.momirealms.craftengine.core.util.VersionHelper;
|
||||
import net.momirealms.craftengine.core.world.WorldManager;
|
||||
import net.momirealms.craftengine.core.world.score.TeamManager;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.core.Logger;
|
||||
import org.jetbrains.annotations.ApiStatus;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.InputStreamReader;
|
||||
import java.net.HttpURLConnection;
|
||||
import java.net.URI;
|
||||
import java.net.URL;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import java.util.concurrent.Executor;
|
||||
import java.util.function.Consumer;
|
||||
@@ -338,9 +348,87 @@ public abstract class CraftEngine implements Plugin {
|
||||
this.scheduler.executeAsync(() -> this.packManager.initCachedAssets());
|
||||
// 正式完成重载
|
||||
this.reloadEventDispatcher.accept(this);
|
||||
// 检查更新
|
||||
if (Config.checkUpdate()) {
|
||||
this.scheduler.executeAsync(this::checkUpdates);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void checkUpdates() {
|
||||
boolean downloadFromPolymart = this.polymart.equals("1");
|
||||
boolean downloadFromBBB = this.buildByBit.equals("true");
|
||||
String link;
|
||||
if (VersionHelper.PREMIUM) {
|
||||
if (downloadFromPolymart) {
|
||||
link = "https://polymart.org/product/7624/";
|
||||
} else if (downloadFromBBB) {
|
||||
link = "https://builtbybit.com/resources/82674/";
|
||||
} else {
|
||||
if (Locale.getDefault() == Locale.SIMPLIFIED_CHINESE) {
|
||||
link = "QQ群[1039968907]";
|
||||
} else {
|
||||
return;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
link = "https://modrinth.com/plugin/craftengine/";
|
||||
}
|
||||
try {
|
||||
String lv = getLatestVersion();
|
||||
if (lv == null) return;
|
||||
if (compareVer(lv, pluginVersion())) {
|
||||
this.logger.warn(TranslationManager.instance().translateLog("info.update.available", lv, link));
|
||||
} else {
|
||||
this.logger.info(TranslationManager.instance().translateLog("info.update.latest"));
|
||||
}
|
||||
} catch (Exception ignored) {
|
||||
}
|
||||
}
|
||||
|
||||
private boolean compareVer(String v1, String v2) {
|
||||
String[] parts1 = v1.split("\\.");
|
||||
String[] parts2 = v2.split("\\.");
|
||||
int maxLength = Math.max(parts1.length, parts2.length);
|
||||
for (int i = 0; i < maxLength; i++) {
|
||||
int num1 = i < parts1.length ? Integer.parseInt(parts1[i]) : 0;
|
||||
int num2 = i < parts2.length ? Integer.parseInt(parts2[i]) : 0;
|
||||
if (num1 != num2) {
|
||||
return num1 > num2;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private static String getLatestVersion() throws Exception {
|
||||
String apiUrl = "https://api.spiget.org/v2/resources/128871/versions/latest";
|
||||
URL url = new URI(apiUrl).toURL();
|
||||
// 创建HTTP连接
|
||||
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
|
||||
connection.setRequestMethod("GET");
|
||||
connection.setRequestProperty("User-Agent", "Mozilla/5.0");
|
||||
connection.setConnectTimeout(5000);
|
||||
connection.setReadTimeout(5000);
|
||||
// 获取响应代码
|
||||
int responseCode = connection.getResponseCode();
|
||||
if (responseCode == HttpURLConnection.HTTP_OK) {
|
||||
// 读取响应内容
|
||||
BufferedReader in = new BufferedReader(new InputStreamReader(connection.getInputStream()));
|
||||
StringBuilder response = new StringBuilder();
|
||||
String inputLine;
|
||||
while ((inputLine = in.readLine()) != null) {
|
||||
response.append(inputLine);
|
||||
}
|
||||
in.close();
|
||||
JsonObject jsonResponse = GsonHelper.get().fromJson(response.toString(), JsonObject.class);
|
||||
if (jsonResponse.has("name")) {
|
||||
return jsonResponse.get("name").getAsString();
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
protected void onPluginDisable() {
|
||||
if (this.networkManager != null) this.networkManager.disable();
|
||||
if (this.fontManager != null) this.fontManager.disable();
|
||||
|
||||
@@ -213,7 +213,6 @@ public class ConcurrentUUID2ReferenceChainedHashTable<V> implements Iterable<Con
|
||||
* Returns whether the specified value has a key mapped to it.
|
||||
*/
|
||||
public boolean containsValue(final V value) {
|
||||
Validate.notNull(value, "Value cannot be null");
|
||||
|
||||
final NodeIterator<V> iterator = new NodeIterator<>(this.table);
|
||||
|
||||
@@ -378,7 +377,6 @@ public class ConcurrentUUID2ReferenceChainedHashTable<V> implements Iterable<Con
|
||||
* Atomically updates the value associated with {@code key} to {@code value}, or inserts a new mapping.
|
||||
*/
|
||||
public V put(final UUID key, final V value) {
|
||||
Validate.notNull(value, "Value may not be null");
|
||||
|
||||
final int hash = getHash(key);
|
||||
|
||||
@@ -429,7 +427,6 @@ public class ConcurrentUUID2ReferenceChainedHashTable<V> implements Iterable<Con
|
||||
* Atomically inserts a new mapping if and only if {@code key} is not currently mapped.
|
||||
*/
|
||||
public V putIfAbsent(final UUID key, final V value) {
|
||||
Validate.notNull(value, "Value may not be null");
|
||||
|
||||
final int hash = getHash(key);
|
||||
|
||||
@@ -485,7 +482,6 @@ public class ConcurrentUUID2ReferenceChainedHashTable<V> implements Iterable<Con
|
||||
* Atomically updates the value associated with {@code key} to {@code value}, or does nothing if not mapped.
|
||||
*/
|
||||
public V replace(final UUID key, final V value) {
|
||||
Validate.notNull(value, "Value may not be null");
|
||||
|
||||
final int hash = getHash(key);
|
||||
|
||||
@@ -530,8 +526,6 @@ public class ConcurrentUUID2ReferenceChainedHashTable<V> implements Iterable<Con
|
||||
* Atomically updates the value if the currently associated value is reference equal to {@code expect}.
|
||||
*/
|
||||
public V replace(final UUID key, final V expect, final V update) {
|
||||
Validate.notNull(expect, "Expect may not be null");
|
||||
Validate.notNull(update, "Update may not be null");
|
||||
|
||||
final int hash = getHash(key);
|
||||
|
||||
@@ -757,7 +751,6 @@ public class ConcurrentUUID2ReferenceChainedHashTable<V> implements Iterable<Con
|
||||
* </p>
|
||||
*/
|
||||
public V computeIfAbsent(final UUID key, final Function<UUID, ? extends V> function) {
|
||||
Validate.notNull(function, "Function may not be null");
|
||||
|
||||
final int hash = getHash(key);
|
||||
|
||||
@@ -859,7 +852,6 @@ public class ConcurrentUUID2ReferenceChainedHashTable<V> implements Iterable<Con
|
||||
}
|
||||
@Override public TableEntry<V> next() { return this.nextNode(); }
|
||||
@Override public void forEachRemaining(final Consumer<? super TableEntry<V>> action) {
|
||||
Validate.notNull(action, "Action may not be null");
|
||||
while (this.hasNext()) { action.accept(this.next()); }
|
||||
}
|
||||
}
|
||||
@@ -868,7 +860,6 @@ public class ConcurrentUUID2ReferenceChainedHashTable<V> implements Iterable<Con
|
||||
public KeyIterator(final ConcurrentUUID2ReferenceChainedHashTable<V> map) { super(map); }
|
||||
@Override public UUID next() { return this.nextNode().key; }
|
||||
@Override public void forEachRemaining(final Consumer<? super UUID> action) {
|
||||
Validate.notNull(action, "Action may not be null");
|
||||
while (this.hasNext()) { action.accept(this.next()); }
|
||||
}
|
||||
}
|
||||
@@ -877,7 +868,6 @@ public class ConcurrentUUID2ReferenceChainedHashTable<V> implements Iterable<Con
|
||||
public ValueIterator(final ConcurrentUUID2ReferenceChainedHashTable<V> map) { super(map); }
|
||||
@Override public V next() { return this.nextNode().getValueVolatile(); }
|
||||
@Override public void forEachRemaining(final Consumer<? super V> action) {
|
||||
Validate.notNull(action, "Action may not be null");
|
||||
while (this.hasNext()) { action.accept(this.next()); }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
org.gradle.jvmargs=-Xmx4G
|
||||
|
||||
# Project settings
|
||||
project_version=0.0.66.3
|
||||
project_version=0.0.66.4
|
||||
config_version=61
|
||||
lang_version=43
|
||||
lang_version=44
|
||||
project_group=net.momirealms
|
||||
latest_supported_version=1.21.11
|
||||
|
||||
@@ -55,7 +55,7 @@ amazon_awssdk_version=2.38.7
|
||||
amazon_awssdk_eventstream_version=1.0.1
|
||||
jimfs_version=1.3.1
|
||||
authlib_version=7.0.60
|
||||
concurrent_util_version=0.0.3
|
||||
concurrent_util_version=0.0.8-SNAPSHOT
|
||||
bucket4j_version=8.15.0
|
||||
|
||||
# Proxy settings
|
||||
|
||||
Binary file not shown.
BIN
libs/concurrentutil-0.0.8-SNAPSHOT.jar
Normal file
BIN
libs/concurrentutil-0.0.8-SNAPSHOT.jar
Normal file
Binary file not shown.
Reference in New Issue
Block a user