mirror of
https://github.com/Winds-Studio/Leaf.git
synced 2025-12-22 16:39:22 +00:00
Upstream has released updates that appear to apply and compile correctly Leaves Changes: LeavesMC/Leaves@88819fe8 Add mc-old hopper suck-in behavior (#395) LeavesMC/Leaves@7394e8dd Fix papermc repo LeavesMC/Leaves@85c7bf11 Remove cache-world-generator-sea-level (#392) LeavesMC/Leaves@00798036 init 1.21.4, and boom! LeavesMC/Leaves@91fc24da build change, but weight not work LeavesMC/Leaves@4ccdf459 just work LeavesMC/Leaves@05ee2e36 Build changes, and delete timings LeavesMC/Leaves@fcc859dc Fix API patches (#406) LeavesMC/Leaves@6a1259df 0006/0129 LeavesMC/Leaves@3e3b05df 0009/0129 LeavesMC/Leaves@c3255c4f 0011/0129 LeavesMC/Leaves@6284c7b6 0018/0129 LeavesMC/Leaves@7abdc88c 0030/0129 LeavesMC/Leaves@4d119ff9 0035/0129 LeavesMC/Leaves@60baed99 0043/0129 LeavesMC/Leaves@dc319d5b 0048/0129 LeavesMC/Leaves@73a505d5 0049/0129 LeavesMC/Leaves@016b29dd 0057/0129 LeavesMC/Leaves@c9cf5af8 0065/0129 LeavesMC/Leaves@330b79ff 0086/0129 (#408) LeavesMC/Leaves@06c1d946 0087/0129 LeavesMC/Leaves@bf4bc284 0091/0129 LeavesMC/Leaves@102a3b70 0097/0129 LeavesMC/Leaves@53b43fed 0101/0129 LeavesMC/Leaves@892f3925 102/129 LeavesMC/Leaves@08c3043a 0107/0129 LeavesMC/Leaves@48764d8e 0112/0129 LeavesMC/Leaves@8380feff 0118/0129 LeavesMC/Leaves@e51603db 0129/0129, 100% patched LeavesMC/Leaves@ef851152 fix some LeavesMC/Leaves@9b7c6e88 server work LeavesMC/Leaves@272b7dcb Protocol... (#409) LeavesMC/Leaves@7be1bc97 Make jade better LeavesMC/Leaves@5350f6ea Make action work LeavesMC/Leaves@f07c26c8 fix action jar
127 lines
6.6 KiB
Diff
127 lines
6.6 KiB
Diff
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
|
From: Dreeam <61569423+Dreeam-qwq@users.noreply.github.com>
|
|
Date: Mon, 11 Nov 2024 02:46:39 -0500
|
|
Subject: [PATCH] Use faster and thread-safe ban list date format parsing
|
|
|
|
Dreeam TODO: check is there need to use more accurate benchmark using jmh?
|
|
|
|
Use DateTimeFormatter since the original java SimpleDateFormat is not thread-safe
|
|
If calls DateTimeFormatter asynchronously, one data format may pollute another
|
|
|
|
This can fix the server crash on loading according to the user report.
|
|
The server crashed during initing the IP ban list, probably caused by calls in off-main.
|
|
|
|
Some performance test **only for reference**
|
|
Single thread, 10,000,000 times loop, java 21 (graalvm / zulu)
|
|
|
|
SimpleDateFormat: ~29,446ms
|
|
DateTimeFormatter: ~13,128ms
|
|
apache commons-lang's FastDateFormat: ~23,514ms
|
|
|
|
In the end, DateTimeFormatter is also fastest in three implementations in any ways,
|
|
Wether there is a high frequnently calls or not. And also thread-safe. So there is
|
|
a better solution, why not using it?
|
|
|
|
diff --git a/net/minecraft/server/players/BanListEntry.java b/net/minecraft/server/players/BanListEntry.java
|
|
index e111adec2116f922fe67ee434635e50c60dad15c..72f64d5812411be0f0bc5456caff87d63a4cbbb9 100644
|
|
--- a/net/minecraft/server/players/BanListEntry.java
|
|
+++ b/net/minecraft/server/players/BanListEntry.java
|
|
@@ -9,7 +9,11 @@ import javax.annotation.Nullable;
|
|
import net.minecraft.network.chat.Component;
|
|
|
|
public abstract class BanListEntry<T> extends StoredUserEntry<T> {
|
|
- public static final SimpleDateFormat DATE_FORMAT = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss Z", Locale.ROOT);
|
|
+ // Leaf start - Use faster and thread-safe ban list date format parsing
|
|
+ //public static final SimpleDateFormat DATE_FORMAT = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss Z", Locale.ROOT); // Leaf - I assume no one will use this, if yes, why?
|
|
+ private static final java.time.ZoneId ZONE_ID = java.time.ZoneId.systemDefault();
|
|
+ public static final java.time.format.DateTimeFormatter DATE_TIME_FORMATTER = java.time.format.DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss Z");
|
|
+ // Leaf end - Use faster and thread-safe ban list date format parsing
|
|
public static final String EXPIRES_NEVER = "forever";
|
|
protected final Date created;
|
|
protected final String source;
|
|
@@ -30,8 +34,10 @@ public abstract class BanListEntry<T> extends StoredUserEntry<T> {
|
|
|
|
Date date;
|
|
try {
|
|
- date = entryData.has("created") ? DATE_FORMAT.parse(entryData.get("created").getAsString()) : new Date();
|
|
- } catch (ParseException var7) {
|
|
+ // Leaf start - Use faster and thread-safe ban list date format parsing
|
|
+ date = entryData.has("created") ? parseToDate(entryData.get("created").getAsString()) : new Date();
|
|
+ } catch (java.time.format.DateTimeParseException var7) {
|
|
+ // Leaf end - Use faster and thread-safe ban list date format parsing
|
|
date = new Date();
|
|
}
|
|
|
|
@@ -40,8 +46,10 @@ public abstract class BanListEntry<T> extends StoredUserEntry<T> {
|
|
|
|
Date date1;
|
|
try {
|
|
- date1 = entryData.has("expires") ? DATE_FORMAT.parse(entryData.get("expires").getAsString()) : null;
|
|
- } catch (ParseException var6) {
|
|
+ // Leaf start - Use faster and thread-safe ban list date format parsing
|
|
+ date1 = entryData.has("expires") ? parseToDate(entryData.get("expires").getAsString()) : null;
|
|
+ } catch (java.time.format.DateTimeParseException var6) {
|
|
+ // Leaf end - Use faster and thread-safe ban list date format parsing
|
|
date1 = null;
|
|
}
|
|
|
|
@@ -75,9 +83,9 @@ public abstract class BanListEntry<T> extends StoredUserEntry<T> {
|
|
|
|
@Override
|
|
protected void serialize(JsonObject data) {
|
|
- data.addProperty("created", DATE_FORMAT.format(this.created));
|
|
+ data.addProperty("created", formateToString(this.created)); // Leaf - Use faster and thread-safe ban list date format parsing
|
|
data.addProperty("source", this.source);
|
|
- data.addProperty("expires", this.expires == null ? "forever" : DATE_FORMAT.format(this.expires));
|
|
+ data.addProperty("expires", this.expires == null ? "forever" : formateToString(this.expires)); // Leaf - Use faster and thread-safe ban list date format parsing
|
|
data.addProperty("reason", this.reason);
|
|
}
|
|
|
|
@@ -86,9 +94,11 @@ public abstract class BanListEntry<T> extends StoredUserEntry<T> {
|
|
Date expires = null;
|
|
|
|
try {
|
|
- expires = jsonobject.has("expires") ? BanListEntry.DATE_FORMAT.parse(jsonobject.get("expires").getAsString()) : null;
|
|
- } catch (ParseException ex) {
|
|
+ // Leaf start - Use faster and thread-safe ban list date format parsing
|
|
+ expires = jsonobject.has("expires") ? parseToDate(jsonobject.get("expires").getAsString()) : null;
|
|
+ } catch (java.time.format.DateTimeParseException ex) {
|
|
// Guess we don't have a date
|
|
+ // Leaf end - Use faster and thread-safe ban list date format parsing
|
|
}
|
|
|
|
if (expires == null || expires.after(new Date())) {
|
|
@@ -98,4 +108,15 @@ public abstract class BanListEntry<T> extends StoredUserEntry<T> {
|
|
}
|
|
}
|
|
// CraftBukkit end
|
|
+
|
|
+ // Leaf start - Use faster and thread-safe ban list date format parsing
|
|
+ public static Date parseToDate(String string) {
|
|
+ java.time.ZonedDateTime parsedDateTime = java.time.ZonedDateTime.parse(string, DATE_TIME_FORMATTER);
|
|
+ return Date.from(parsedDateTime.toInstant());
|
|
+ }
|
|
+
|
|
+ private static String formateToString(Date date) {
|
|
+ return DATE_TIME_FORMATTER.format(date.toInstant().atZone(ZONE_ID));
|
|
+ }
|
|
+ // Leaf end - Use faster and thread-safe ban list date format parsing
|
|
}
|
|
diff --git a/net/minecraft/server/players/OldUsersConverter.java b/net/minecraft/server/players/OldUsersConverter.java
|
|
index 7dbcd9d96f052bb10127ad2b061154c23cc9ffd4..0a3b159a8629fad1a240b9be3e6025bfa1183a00 100644
|
|
--- a/net/minecraft/server/players/OldUsersConverter.java
|
|
+++ b/net/minecraft/server/players/OldUsersConverter.java
|
|
@@ -469,8 +469,10 @@ public class OldUsersConverter {
|
|
static Date parseDate(String input, Date defaultValue) {
|
|
Date date;
|
|
try {
|
|
- date = BanListEntry.DATE_FORMAT.parse(input);
|
|
- } catch (ParseException var4) {
|
|
+ // Leaf start - Use faster and thread-safe ban list date format parsing
|
|
+ date = BanListEntry.parseToDate(input);
|
|
+ } catch (java.time.format.DateTimeParseException var4) {
|
|
+ // Leaf end - Use faster and thread-safe ban list date format parsing
|
|
date = defaultValue;
|
|
}
|
|
|