Skip to content

Commit e0b83f8

Browse files
committed
bump to 1.2.6
1 parent df02f47 commit e0b83f8

File tree

13 files changed

+194
-84
lines changed

13 files changed

+194
-84
lines changed

build.gradle.kts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,12 +37,12 @@ dependencies {
3737
compileOnly("it.unimi.dsi:fastutil:8.5.15")
3838
implementation("com.google.code.gson:gson:2.12.1")
3939

40-
implementation("one.tranic:t-thread:1.0.0")
40+
implementation("one.tranic:t-thread:1.0.1")
4141
implementation("one.tranic:t-proxy:1.0.0")
42-
implementation("one.tranic:t-utils:1.2.1")
42+
implementation("one.tranic:t-utils:1.2.2.1")
4343

44-
implementation("net.kyori:adventure-api:4.18.0")
45-
implementation("net.kyori:adventure-text-minimessage:4.18.0")
44+
implementation("net.kyori:adventure-api:4.19.0")
45+
implementation("net.kyori:adventure-text-minimessage:4.19.0")
4646
}
4747

4848
val targetJavaVersion = 17

src/main/java/one/tranic/t/base/TBase.java

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,14 @@
1212

1313
public class TBase {
1414
public final static ExecutorService executor = T2hread.getExecutor();
15-
//public final static List<String> EMPTY_LIST = Collections.newUnmodifiableList();
16-
public static final SystemCommandSource<?, ?> CONSOLE_SOURCE;
1715
private final static Operator operator = new Operator("Console", UUID.fromString("05b11eee-24db-4a21-ba9d-e12e8df9a92f"));
1816
private static final String packageName;
17+
//public final static List<String> EMPTY_LIST = Collections.newUnmodifiableList();
18+
private static SystemCommandSource<?, ?> CONSOLE_SOURCE;
1919
private static Supplier<SystemCommandSource<?, ?>> getConsoleSourceSupplier;
2020

2121
static {
2222
packageName = getRootPath();
23-
CONSOLE_SOURCE = getConsoleSource();
2423
}
2524

2625
/**
@@ -64,8 +63,12 @@ public static Operator console() {
6463
* for administrative or automated command execution.
6564
*/
6665
public static @Nullable SystemCommandSource<?, ?> getConsoleSource() {
67-
if (getConsoleSourceSupplier == null) return null;
68-
return getConsoleSourceSupplier.get();
66+
if (CONSOLE_SOURCE != null) return CONSOLE_SOURCE;
67+
if (getConsoleSourceSupplier != null) {
68+
CONSOLE_SOURCE = getConsoleSourceSupplier.get();
69+
return CONSOLE_SOURCE;
70+
}
71+
return null;
6972
}
7073

7174
/**
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
package one.tranic.t.base.cache;
2+
3+
/**
4+
* Represents a generic cache interface that provides access
5+
* to the underlying {@link CacheService} implementation.
6+
* <p>
7+
* Classes implementing this interface are responsible for
8+
* defining specific cache behaviors while encapsulating their
9+
* implementation details through the provided service.
10+
*/
11+
public interface Cache extends AutoCloseable {
12+
/**
13+
* Retrieves the underlying CacheService instance associated with the current Cache implementation.
14+
* This method provides access to the internal caching service used for managing cache operations.
15+
*
16+
* @return the CacheService instance backing the current Cache implementation.
17+
*/
18+
CacheService getService();
19+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
package one.tranic.t.base.cache;
2+
3+
import org.jetbrains.annotations.NotNull;
4+
import org.jetbrains.annotations.Range;
5+
6+
import java.util.Optional;
7+
8+
public interface CacheService extends AutoCloseable {
9+
<T> @NotNull Optional<T> get(@NotNull String key, @NotNull Class<T> type);
10+
11+
@NotNull String get(@NotNull String key);
12+
13+
void put(@NotNull String key, @NotNull Object value, @Range(from = 0, to = Long.MAX_VALUE) long ttl);
14+
15+
void invalidate(@NotNull String key);
16+
17+
void invalidateAll();
18+
}

src/main/java/one/tranic/t/base/command/simple/SimpleCommand.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ public void sendResult(C source, Component msg) {
4444
*/
4545
public void sendResult(C source, Component msg, boolean withConsole) {
4646
if (source.isPlayer()) source.sendMessage(msg);
47-
if (withConsole) TBase.CONSOLE_SOURCE.sendMessage(msg);
47+
if (withConsole) TBase.getConsoleSource().sendMessage(msg);
4848
}
4949

5050
/**
@@ -66,7 +66,7 @@ public void sendResult(C source, String msg) {
6666
*/
6767
public void sendResult(C source, String msg, boolean withConsole) {
6868
if (source.isPlayer()) source.sendMessage(msg);
69-
if (withConsole) TBase.CONSOLE_SOURCE.sendMessage(msg);
69+
if (withConsole) TBase.getConsoleSource().sendMessage(msg);
7070
}
7171

7272
/**

src/main/java/one/tranic/t/base/exception/CommandException.java

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,6 @@
33
/**
44
* A custom exception that represents errors occurring during the execution
55
* or processing of commands in the application.
6-
* <p>
7-
* This exception is a subclass of {@code RuntimeException} and is designed to signal command-specific failures
8-
* that developers or users need to be made aware of.
9-
* <p>
10-
* This exception can be used in scenarios where command validation, execution,
11-
* or configuration fails or encounters issues.
12-
* <p>
13-
* Developers can provide additional details about the failure by using the constructor that accepts a message.
146
*/
157
public class CommandException extends RuntimeException {
168
public CommandException(String message) {
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
package one.tranic.t.base.exception;
2+
3+
public class ConnectionTestFailedException extends RuntimeException {
4+
public ConnectionTestFailedException() {
5+
super();
6+
}
7+
8+
public ConnectionTestFailedException(String message) {
9+
super(message);
10+
}
11+
12+
public ConnectionTestFailedException(String message, Throwable cause) {
13+
super(message, cause);
14+
}
15+
}

src/main/java/one/tranic/t/base/exception/UnsupportedTypeException.java

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,6 @@
22

33
/**
44
* A custom exception that indicates an operation involving an unsupported or invalid type.
5-
* <p>
6-
* This exception is a subclass of {@code RuntimeException} and is typically used to signal
7-
* situations where a type provided to a method or operation is invalid or not supported.
8-
* <p>
9-
* This exception can be constructed with a custom message, an existing exception, or
10-
* automatically include the class name of the unsupported object to provide additional context.
115
*/
126
public class UnsupportedTypeException extends RuntimeException {
137
/**

src/main/java/one/tranic/t/base/parse/mojang/MojangAPIParser.java

Lines changed: 82 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
import java.io.OutputStream;
1111
import java.lang.reflect.Type;
1212
import java.net.HttpURLConnection;
13+
import java.net.Proxy;
14+
import java.net.URL;
1315
import java.nio.charset.StandardCharsets;
1416
import java.util.List;
1517
import java.util.UUID;
@@ -20,55 +22,114 @@
2022
* Connections are established using the RequestWithProxyParser class to support proxy configurations.
2123
*/
2224
public class MojangAPIParser {
23-
2425
private static final String BASE_URL = "https://api.minecraftservices.com/minecraft/profile/lookup";
26+
private static final String NAME_ENDPOINT = "/name/";
27+
private static final String BULK_ENDPOINT = "/bulk/byname";
28+
private static final String CONTENT_TYPE = "Content-Type";
29+
private static final String APPLICATION_JSON = "application/json";
30+
private static final String POST_METHOD = "POST";
2531

2632
/**
27-
* Looks up a Minecraft profile by its username using the Mojang API.
33+
* Retrieves the profile information for a user based on their username.
2834
*
29-
* @param name the username of the Minecraft profile to be looked up
30-
* @return a {@code ProfileLookup} object containing the profile's ID and username
31-
* @throws IOException if an I/O error occurs while connecting to the Mojang API or parsing the response
35+
* @param name the username for which profile information is to be looked up
36+
* @return a {@link ProfileLookup} object containing the profile information
37+
* @throws IOException if an I/O error occurs during the profile lookup
3238
*/
3339
public static ProfileLookup lookupProfile(String name) throws IOException {
34-
String url = BASE_URL + "/name/" + name;
35-
HttpURLConnection connection = RequestWithProxyParser.openConnection(url);
40+
return lookupProfile(true, name);
41+
}
42+
43+
/**
44+
* Looks up profile information for a given username from a remote server.
45+
*
46+
* @param useProxy whether to use a proxy connection for the request
47+
* @param name the username to look up
48+
* @return the {@link ProfileLookup} containing the profile ID and name
49+
* @throws IOException if an I/O error occurs while performing the request or reading the response
50+
*/
51+
public static ProfileLookup lookupProfile(boolean useProxy, String name) throws IOException {
52+
String url = BASE_URL + NAME_ENDPOINT + name;
53+
HttpURLConnection connection = createConnection(url, useProxy);
3654
return JsonParser.requestAndParse(connection, ProfileLookup.class);
3755
}
3856

3957
/**
40-
* Retrieves the Minecraft profile associated with the given UUID by performing a lookup request to the Mojang API.
58+
* Retrieves the profile information associated with the specified UUID.
4159
*
42-
* @param uuid the unique identifier of the Minecraft account to look up, must not be null
43-
* @return a {@link ProfileLookup} record containing the profile information, including the UUID and username
44-
* @throws IOException if an I/O error occurs while making the request or parsing the response
60+
* @param uuid the {@link UUID} of the profile to lookup; must not be null
61+
* @return a {@link ProfileLookup} containing the profile information corresponding to the given UUID
62+
* @throws IOException if an I/O error occurs while making the request or processing the response
4563
*/
4664
public static ProfileLookup lookupProfile(UUID uuid) throws IOException {
65+
return lookupProfile(true, uuid);
66+
}
67+
68+
/**
69+
* Looks up a profile from the Mojang API using the specified UUID.
70+
*
71+
* @param useProxy a boolean indicating whether a proxy should be used for the connection
72+
* @param uuid the UUID of the profile to lookup, must not be null
73+
* @return a {@link ProfileLookup} object containing the profile information
74+
* @throws IOException if an error occurs during the network request or while reading the response
75+
*/
76+
public static ProfileLookup lookupProfile(boolean useProxy, UUID uuid) throws IOException {
4777
String url = BASE_URL + "/" + UUIDParser.removeDashes(uuid);
48-
HttpURLConnection connection = RequestWithProxyParser.openConnection(url);
78+
HttpURLConnection connection = createConnection(url, useProxy);
4979
return JsonParser.requestAndParse(connection, ProfileLookup.class);
5080
}
5181

5282
/**
53-
* Retrieves a list of Minecraft profiles by performing a bulk lookup using an array of usernames.
83+
* Retrieves a list of profile lookups for the given player names.
84+
*
85+
* @param names the array of player names to look up profiles for; each name must be a valid string
86+
* @return a list of {@code ProfileLookup} records containing the ID and name of each requested profile
87+
* @throws IOException if an I/O error occurs during the HTTP request or response parsing
88+
*/
89+
public static List<ProfileLookup> lookupProfiles(String... names) throws IOException {
90+
return lookupProfiles(true, names);
91+
}
92+
93+
/**
94+
* Looks up profiles for the given list of names by sending an HTTP request to the Mojang API.
5495
*
55-
* @param names an array of usernames to be looked up; each name represents a Minecraft user's profile
56-
* @return a list of {@code ProfileLookup} records containing the id and name of the queried profiles
57-
* @throws IOException if an I/O error occurs during the HTTP request or response handling
96+
* @param useProxy a boolean indicating whether to use a proxy for the HTTP connection
97+
* @param names a variable-length list of usernames to look up profiles for
98+
* @return a list of {@link ProfileLookup} representing the fetched profile information for each provided name
99+
* @throws IOException if an I/O error occurs while making the request or processing the response
58100
*/
59-
public static List<ProfileLookup> lookupProfile(String... names) throws IOException {
60-
String url = BASE_URL + "/bulk/byname";
61-
HttpURLConnection connection = RequestWithProxyParser.openConnection(url);
62-
connection.setRequestMethod("POST");
63-
connection.setRequestProperty("Content-Type", "application/json");
101+
public static List<ProfileLookup> lookupProfiles(boolean useProxy, String... names) throws IOException {
102+
String url = BASE_URL + BULK_ENDPOINT;
103+
HttpURLConnection connection = createConnection(url, useProxy);
104+
105+
connection.setRequestMethod(POST_METHOD);
106+
connection.setRequestProperty(CONTENT_TYPE, APPLICATION_JSON);
64107
connection.setDoOutput(true);
108+
65109
String jsonBody = JsonParser.toJson(names);
66110
try (OutputStream outputStream = connection.getOutputStream()) {
67111
outputStream.write(jsonBody.getBytes(StandardCharsets.UTF_8));
68112
outputStream.flush();
69113
}
114+
70115
Type listType = new TypeToken<List<ProfileLookup>>() {
71116
}.getType();
72117
return JsonParser.requestAndParse(connection, listType);
73118
}
119+
120+
/**
121+
* Creates and returns an {@link HttpURLConnection} instance for the specified URL.
122+
* If the {@code useProxy} flag is set to {@code true}, a connection using a proxy is created.
123+
* Otherwise, a direct connection is instantiated.
124+
*
125+
* @param url the URL to which the connection is to be established
126+
* @param useProxy a boolean flag indicating whether a proxy should be used for the connection
127+
* @return an instance of {@link HttpURLConnection} configured based on the provided parameters
128+
* @throws IOException if an I/O error occurs while creating the connection
129+
*/
130+
private static HttpURLConnection createConnection(String url, boolean useProxy) throws IOException {
131+
return useProxy
132+
? RequestWithProxyParser.openConnection(url)
133+
: (HttpURLConnection) new URL(url).openConnection(Proxy.NO_PROXY);
134+
}
74135
}

src/main/java/one/tranic/t/base/parse/network/NetworkParser.java renamed to src/main/java/one/tranic/t/base/parse/resource/ResourceParser.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package one.tranic.t.base.parse.network;
1+
package one.tranic.t.base.parse.resource;
22

33
import com.google.common.io.Resources;
44
import org.jetbrains.annotations.NotNull;
@@ -8,7 +8,7 @@
88
import java.net.URL;
99
import java.net.URLConnection;
1010

11-
public class NetworkParser {
11+
public class ResourceParser {
1212
/**
1313
* Retrieves an InputStream for a specified resource file by its filename.
1414
*

0 commit comments

Comments
 (0)