Skip to content

Commit 904f23f

Browse files
committed
Update for Minecraft 1.21.3
1 parent 9f007ed commit 904f23f

6 files changed

Lines changed: 93 additions & 19 deletions

File tree

build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
plugins {
22
id 'com.github.johnrengelman.shadow' version '8.1.1'
33
id 'kr.entree.spigradle' version '2.4.3'
4-
id 'io.freefair.lombok' version '8.6'
4+
id 'io.freefair.lombok' version '8.10.2'
55
id 'java'
66
id 'jacoco'
77
}

gradle.properties

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
11
group = de.butzlabben
22
pluginName = WorldSystem
3-
author = Trainerlord, Butzlabben & CrazyCloudCraft
4-
mcVersion = 1.20.2
5-
apiVersion = 1.20
6-
version = 2.4.37
3+
author = Trainerlord, Butzlabben & N1klasse
4+
mcVersion = 1.21.3
5+
apiVersion = 1.21
6+
version = 2.4.38
77
Vault = Vault
88
WorldEdit = WorldEdit
9-
FAWE = FAWE
10-
11-
9+
FAWE = FAWE

gradle/wrapper/gradle-wrapper.jar

-19.3 KB
Binary file not shown.

src/main/java/de/butzlabben/world/GameProfileBuilder.java

Lines changed: 38 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,17 @@
77
import com.mojang.util.UUIDTypeAdapter;
88
import org.yaml.snakeyaml.external.biz.base64Coder.Base64Coder;
99

10+
/* DEPRECATED
1011
import java.io.BufferedReader;
11-
import java.io.IOException;
1212
import java.io.InputStreamReader;
13-
import java.lang.reflect.Type;
14-
import java.net.HttpURLConnection;
1513
import java.net.URL;
14+
import java.net.HttpURLConnection; */
15+
import java.io.IOException;
16+
import java.lang.reflect.Type;
17+
import java.net.URI;
18+
import java.net.http.HttpClient;
19+
import java.net.http.HttpRequest;
20+
import java.net.http.HttpResponse;
1621
import java.util.*;
1722

1823
/**
@@ -29,6 +34,8 @@ public class GameProfileBuilder {
2934
private static final Object sync = new Object();
3035
private static long cacheTime = -1L;
3136

37+
private static final HttpClient client = HttpClient.newHttpClient();
38+
3239
public static GameProfile fetch(UUID uuid) throws IOException {
3340
return fetch(uuid, false);
3441
}
@@ -38,11 +45,33 @@ public static GameProfile fetch(UUID uuid, boolean forceNew) throws IOException
3845
return cache.get(uuid).profile;
3946
}
4047

41-
HttpURLConnection connection;
48+
String url = String.format("https://sessionserver.mojang.com/session/minecraft/profile/%s?unsigned=false", UUIDTypeAdapter.fromUUID(uuid));
49+
HttpRequest request = HttpRequest.newBuilder()
50+
.uri(URI.create(url))
51+
.GET()
52+
.timeout(java.time.Duration.ofSeconds(5)) // Set timeout for request
53+
.build();
54+
55+
synchronized (sync) {
56+
try {
57+
HttpResponse<String> response = client.send(request, HttpResponse.BodyHandlers.ofString());
58+
if (response.statusCode() == 200) {
59+
String json = response.body();
60+
GameProfile result = gson.fromJson(json, GameProfile.class);
61+
cache.put(uuid, new CachedProfile(result));
62+
return result;
63+
}
64+
} catch (InterruptedException e) {
65+
Thread.currentThread().interrupt();
66+
throw new IOException("Request interrupted", e);
67+
}
68+
}
69+
70+
//DEPRECATED
71+
/*HttpURLConnection connection;
4272
synchronized (sync) {
4373
connection = (HttpURLConnection) new URL(
44-
String.format("https://sessionserver.mojang.com/session/minecraft/profile/%s?unsigned=false",
45-
UUIDTypeAdapter.fromUUID(uuid))).openConnection();
74+
String.format("https://sessionserver.mojang.com/session/minecraft/profile/%s?unsigned=false", UUIDTypeAdapter.fromUUID(uuid))).openConnection();
4675
connection.setReadTimeout(5000);
4776
}
4877
if (connection.getResponseCode() == 200) {
@@ -52,11 +81,12 @@ public static GameProfile fetch(UUID uuid, boolean forceNew) throws IOException
5281
GameProfile result = gson.fromJson(json, GameProfile.class);
5382
cache.put(uuid, new CachedProfile(result));
5483
return result;
55-
}
84+
}*/
85+
5686
if ((!forceNew) && (cache.containsKey(uuid))) {
5787
return cache.get(uuid).profile;
5888
}
59-
throw new IOException("Could not connect to mojang servers for unknown player: " + uuid.toString());
89+
throw new IOException("Could not connect to mojang servers for unknown player: "+ uuid); //+ uuid.toString());
6090
}
6191

6292
public static GameProfile getProfile(UUID uuid, String name, String skin) {

src/main/java/de/butzlabben/world/util/PlayerWrapper.java

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
import de.butzlabben.world.config.PluginConfig;
66
import de.butzlabben.world.util.database.DatabaseProvider;
77
import de.butzlabben.world.util.database.DatabaseUtil;
8+
9+
import org.apache.commons.lang3.ObjectUtils.Null;
810
import org.bukkit.Bukkit;
911
import org.bukkit.OfflinePlayer;
1012
import org.bukkit.entity.Player;
@@ -78,6 +80,24 @@ private static UUID getUUID(String name) {
7880
return null;
7981
}
8082

83+
public static OfflinePlayer getOfflinePlayer(String name) {
84+
Player player = Bukkit.getPlayer(name); // Check if the player is currently online
85+
if (player != null) {
86+
// Return the OfflinePlayer using the online player's UUID
87+
return Bukkit.getOfflinePlayer(player.getUniqueId());
88+
}
89+
90+
// If the player is not online, attempt to get the UUID from the database
91+
UUID uuid = PlayerWrapper.getUUID(name);
92+
if (uuid != null) {
93+
return Bukkit.getOfflinePlayer(uuid);
94+
}
95+
96+
// If the UUID is not in the database, return null or handle accordingly
97+
return null;
98+
}
99+
100+
/*
81101
public static OfflinePlayer getOfflinePlayer(String name) {
82102
Player player = Bukkit.getPlayer(name);
83103
if(player != null)
@@ -88,7 +108,7 @@ public static OfflinePlayer getOfflinePlayer(String name) {
88108
return Bukkit.getOfflinePlayer(uuid);
89109
90110
return Bukkit.getOfflinePlayer(name);
91-
}
111+
}*/
92112

93113
public static OfflinePlayer getOfflinePlayer(UUID uuid) {
94114
return Bukkit.getOfflinePlayer(uuid);

src/main/java/de/butzlabben/world/util/VersionUtil.java

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ public class VersionUtil {
1515
private VersionUtil() {
1616
}
1717

18-
public static int getVersion() {
18+
/*public static int getVersion() {
1919
if (version == 0) {
2020
// Detect version
2121
String v = Bukkit.getVersion();
@@ -44,7 +44,33 @@ public static int getVersion() {
4444
version = 12;
4545
}
4646
return version;
47-
}
47+
}*/
48+
49+
public static int getVersion() {
50+
if (version == 0) {
51+
// Detect version
52+
String v = Bukkit.getVersion();
53+
54+
// Extract minor version number
55+
int minorVersion = 0;
56+
if (v.matches(".*1\\.(\\d+).*")) {
57+
minorVersion = Integer.parseInt(v.replaceAll(".*1\\.(\\d+).*", "$1"));
58+
}
59+
60+
// Set version based on minor version number
61+
switch (minorVersion) {
62+
case 21 -> version = 21;
63+
case 20 -> version = 20;
64+
case 19, 18, 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3 -> version = minorVersion;
65+
default -> {
66+
System.err.println("[WorldSystem] Unknown version: " + v);
67+
System.err.println("[WorldSystem] Choosing version 1.12.2");
68+
version = 12; // Default to 1.12 if version is unrecognized
69+
}
70+
}
71+
}
72+
return version;
73+
}
4874

4975
public static boolean isCancelled(BukkitTask task) {
5076
if (getVersion() <= 12)

0 commit comments

Comments
 (0)