Skip to content

Commit 0483f63

Browse files
committed
1.3.2
1 parent b0f6599 commit 0483f63

File tree

5 files changed

+136
-83
lines changed

5 files changed

+136
-83
lines changed

build.gradle.kts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ plugins {
99
}
1010

1111
group = "one.tranic"
12-
version = "1.3.1"
12+
version = "1.3.2"
1313

1414
repositories {
1515
mavenCentral()

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,5 +99,6 @@ public static <T> CompletableFuture<T> runAsync(Supplier<T> supplier) {
9999

100100
public static void close() {
101101
executor.shutdownNow();
102+
INSTANCE.disable();
102103
}
103104
}

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

Lines changed: 35 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -11,39 +11,59 @@
1111
import java.util.Objects;
1212
import java.util.UUID;
1313

14-
public interface TInterface {
14+
@SuppressWarnings("unused")
15+
public interface TInterface<S, P> {
16+
/**
17+
* Enables the functionality or state associated with this instance.
18+
*/
1519
void enable();
1620

21+
/**
22+
* Disables the current instance of the interface or system.
23+
*/
1724
void disable();
1825

26+
/**
27+
* Retrieves an array of supported platforms for the implementing service.
28+
*
29+
* @return an array of {@code Platform} objects representing the platforms supported by this service.
30+
* The returned array is guaranteed to be non-null but may be empty if no platforms are supported.
31+
*/
1932
Platform[] getSupportedPlatforms();
2033

21-
SystemCommandSource<?, ?> getConsoleSource();
34+
/**
35+
* Retrieves the console command source for the system.
36+
* The console source represents an abstract command execution entity
37+
* used for operations not tied to any specific player or client.
38+
*
39+
* @return a {@code SystemCommandSource<S, P>} instance representing the console command source.
40+
*/
41+
SystemCommandSource<S, P> getConsoleSource();
2242

2343
/**
2444
* Retrieves a player instance based on their player name.
2545
*
2646
* @param name the name of the player to search for; must not be null
2747
* @return the {@code Player} instance corresponding to the given name, or {@code null} if no player is found
2848
*/
29-
@Nullable Player<?> getPlayer(@NotNull String name);
49+
@Nullable Player<P> getPlayer(@NotNull String name);
3050

3151
/**
3252
* Retrieves a player using their unique identifier (UUID).
3353
*
3454
* @param uuid the UUID of the player to be retrieved; must not be null
35-
* @return a {@code Player<?>} instance if a player with the given UUID exists;
55+
* @return a {@code Player<P>} instance if a player with the given UUID exists;
3656
* otherwise, {@code null}
3757
*/
38-
@Nullable Player<?> getPlayer(@NotNull UUID uuid);
58+
@Nullable Player<P> getPlayer(@NotNull UUID uuid);
3959

4060
/**
4161
* Retrieves a list of all online players currently connected to the server.
4262
*
43-
* @return a {@code List} of {@code Player<?>} representing each online player;
63+
* @return a {@code List} of {@code Player<P>} representing each online player;
4464
* the list is guaranteed to be non-null.
4565
*/
46-
@NotNull List<Player<?>> getOnlinePlayers();
66+
@NotNull List<Player<P>> getOnlinePlayers();
4767

4868
/**
4969
* Retrieves a list of alternative players who are connected to the same host
@@ -55,17 +75,17 @@ public interface TInterface {
5575
* Players with a matching connected host are returned in the resulting list, ensuring that the specified player is
5676
* excluded from this list.
5777
*
58-
* @param player the {@code Player<?>} whose connected host is used for comparison;
78+
* @param player the {@code Player<P>} whose connected host is used for comparison;
5979
* must not be null
60-
* @return a {@code List<Player<?>>} containing all players who are connected
80+
* @return a {@code List<Player<P>>} containing all players who are connected
6181
* to the same host as the specified player, excluding the player itself;
6282
* the list is guaranteed to be non-null but may be empty if no other
6383
* players share the same connected host
6484
*/
65-
default @NotNull List<Player<?>> getAltPlayers(@NotNull Player<?> player) {
66-
final List<Player<?>> end = Collections.newArrayList();
67-
final List<Player<?>> players = getOnlinePlayers();
68-
for (Player<?> p : players) {
85+
default @NotNull List<Player<P>> getAltPlayers(@NotNull Player<P> player) {
86+
final List<Player<P>> end = Collections.newArrayList();
87+
final List<Player<P>> players = getOnlinePlayers();
88+
for (Player<P> p : players) {
6989
if (p.getUniqueId() != player.getUniqueId() && Objects.equals(p.getConnectedHost(), player.getConnectedHost()))
7090
end.add(p);
7191
}
@@ -77,10 +97,10 @@ public interface TInterface {
7797
* <p>
7898
* The specific type of player instances within this list may vary based on the platform implementation.
7999
*
80-
* @return a {@code List<?>} representing the platform-specific online players;
100+
* @return a {@code List<P>} representing the platform-specific online players;
81101
* the list is guaranteed to be non-null.
82102
*/
83-
@NotNull List<?> getPlatformOnlinePlayers();
103+
@NotNull List<P> getPlatformOnlinePlayers();
84104

85105
/**
86106
* Retrieves a list of the names of all online players currently connected to the server.

src/main/java/one/tranic/t/base/player/BedrockPlayer.java

Lines changed: 95 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import one.tranic.t.base.parse.uuid.UUIDParser;
44
import one.tranic.t.utils.Reflect;
5+
import org.apache.commons.lang.Validate;
56
import org.checkerframework.checker.nullness.qual.NonNull;
67
import org.checkerframework.checker.nullness.qual.Nullable;
78
import org.geysermc.cumulus.form.Form;
@@ -15,14 +16,15 @@
1516

1617
import java.util.UUID;
1718

18-
public class BedrockPlayer {
19+
@SuppressWarnings("all")
20+
public class BedrockPlayer<P> {
1921
private static final boolean geyser = Reflect.hasClass("org.geysermc.geyser.api.GeyserApi");
2022
private static final boolean floodgate = Reflect.hasClass("org.geysermc.floodgate.api.FloodgateApi");
2123

22-
private final Player player;
24+
private final Player<P> player;
2325
private final Object bedrockPlayer;
2426

25-
protected BedrockPlayer(@NotNull Player player) {
27+
public BedrockPlayer(@NotNull Player<P> player) {
2628
this.player = player;
2729
this.bedrockPlayer = getBedrockPlayer(player.getUniqueId());
2830
}
@@ -33,7 +35,7 @@ protected BedrockPlayer(@NotNull Player player) {
3335
* @param player the {@link Player} to convert to a {@link BedrockPlayer}; must not be null
3436
* @return a new {@link BedrockPlayer} instance associated with the given {@link Player}
3537
*/
36-
public static BedrockPlayer of(@NotNull Player player) {
38+
public static @NotNull BedrockPlayer of(@NotNull Player player) {
3739
return new BedrockPlayer(player);
3840
}
3941

@@ -50,14 +52,24 @@ public static boolean isBedrockPlayer(UUID uuid) {
5052
return isFloodgatePlayer(uuid);
5153
}
5254

55+
/**
56+
* Determines whether the specified player is a Bedrock player.
57+
*
58+
* @param player the player to check; must not be null
59+
* @return true if the specified player is a Bedrock player, otherwise false
60+
*/
61+
public static boolean isBedrockPlayer(@NotNull Player player) {
62+
return isBedrockPlayer(player.getUniqueId());
63+
}
64+
5365
/**
5466
* Checks if a given UUID string represents a Floodgate player by verifying
5567
* if it starts with the Floodgate UUID prefix.
5668
*
5769
* @param uuid the UUID string of the player, expected to contain dashes and not null
5870
* @return {@code true} if the UUID represents a Floodgate player, {@code false} otherwise
5971
*/
60-
public static boolean isFloodgatePlayer(String uuid) {
72+
public static boolean isFloodgatePlayer(@NotNull String uuid) {
6173
final String FLOODGATE_UUID_PREFIX = "0000000000000000";
6274

6375
String str = UUIDParser.removeDashes(uuid);
@@ -70,17 +82,37 @@ public static boolean isFloodgatePlayer(String uuid) {
7082
* @param uuid the universally unique identifier (UUID) of the player to check
7183
* @return true if the player is a Floodgate player, false otherwise
7284
*/
73-
public static boolean isFloodgatePlayer(UUID uuid) {
85+
public static boolean isFloodgatePlayer(@NotNull UUID uuid) {
7486
return isFloodgatePlayer(uuid.toString());
7587
}
7688

89+
/**
90+
* Determines if the specified Bedrock player is a Floodgate player.
91+
*
92+
* @param player the Bedrock player to check; must not be null
93+
* @return true if the specified player is a Floodgate player, false otherwise
94+
*/
95+
public static boolean isFloodgatePlayer(@NotNull BedrockPlayer player) {
96+
return isFloodgatePlayer(player.uuid());
97+
}
98+
99+
/**
100+
* Determines whether the specified player is a Floodgate player.
101+
*
102+
* @param player the player to check; must not be null
103+
* @return true if the player is a Floodgate player, false otherwise
104+
*/
105+
public static boolean isFloodgatePlayer(@NotNull Player player) {
106+
return isFloodgatePlayer(player.getUniqueId());
107+
}
108+
77109
/**
78110
* Retrieves the Bedrock player associated with the given UUID.
79111
*
80112
* @param uuid the unique identifier of the player to retrieve
81113
* @return the Bedrock player object if found, otherwise null
82114
*/
83-
private static @Nullable Object getBedrockPlayer(UUID uuid) {
115+
private static @Nullable Object getBedrockPlayer(@NotNull UUID uuid) {
84116
return floodgate ? FloodgateApi.getInstance().getPlayer(uuid) :
85117
geyser ? GeyserApi.api().connectionByUuid(uuid) : null;
86118
}
@@ -108,7 +140,7 @@ public static boolean hasFloodgate() {
108140
*
109141
* @return the {@link Player} instance associated with this object; never null
110142
*/
111-
public @NotNull Player player() {
143+
public @NotNull Player<P> player() {
112144
return player;
113145
}
114146

@@ -131,11 +163,8 @@ public boolean isFloodgatePlayer() {
131163
*/
132164
public @NonNull String platform() {
133165
if (bedrockPlayer != null) {
134-
if (floodgate) {
135-
return ((FloodgatePlayer) bedrockPlayer).getDeviceOs().toString();
136-
} else if (geyser) {
137-
return ((GeyserConnection) bedrockPlayer).platform().toString();
138-
}
166+
if (floodgate) return ((FloodgatePlayer) bedrockPlayer).getDeviceOs().toString();
167+
if (geyser) return ((GeyserConnection) bedrockPlayer).platform().toString();
139168
}
140169
return "Java Edition";
141170
}
@@ -150,9 +179,34 @@ public boolean isFloodgatePlayer() {
150179
* @return the subscription ID of the Floodgate player, or -1 if unavailable
151180
*/
152181
public int subscribeId() {
153-
if (bedrockPlayer != null && floodgate) {
182+
if (bedrockPlayer != null && floodgate)
154183
return ((FloodgatePlayerImpl) bedrockPlayer).getSubscribeId();
184+
return -1;
185+
}
186+
187+
/**
188+
* Retrieves the version of the Bedrock player, if applicable.
189+
*
190+
* @return the version of the Bedrock player as a {@code String}, or {@code null}
191+
* if the player is not a Bedrock player or the version could not be determined
192+
*/
193+
public @Nullable String version() {
194+
if (bedrockPlayer != null) {
195+
if (geyser) return ((GeyserConnection) bedrockPlayer).version();
196+
if (floodgate) return ((FloodgatePlayer) bedrockPlayer).getVersion();
155197
}
198+
return null;
199+
}
200+
201+
/**
202+
* Retrieves the protocol version of the Bedrock player if applicable.
203+
*
204+
* @return the protocol version as an integer if the player is a Geyser Bedrock player;
205+
* otherwise, returns -1 if the player is not a Bedrock player or Geyser is not available.
206+
*/
207+
public int protocolVersion() {
208+
if (bedrockPlayer != null && geyser)
209+
return ((GeyserConnection) bedrockPlayer).protocolVersion();
156210
return -1;
157211
}
158212

@@ -166,9 +220,8 @@ public int subscribeId() {
166220
* Bedrock player, Geyser is not enabled, or if the device ID is unavailable
167221
*/
168222
public @Nullable String deviceId() {
169-
if (bedrockPlayer != null && geyser) {
223+
if (bedrockPlayer != null && geyser)
170224
return ((GeyserSession) bedrockPlayer).getClientData().getDeviceId();
171-
}
172225
return null;
173226
}
174227

@@ -181,9 +234,8 @@ public int subscribeId() {
181234
* @return the device model of the Bedrock player as a string, or {@code null} if unavailable
182235
*/
183236
public @Nullable String deviceModel() {
184-
if (bedrockPlayer != null && geyser) {
237+
if (bedrockPlayer != null && geyser)
185238
return ((GeyserSession) bedrockPlayer).getClientData().getDeviceModel();
186-
}
187239
return null;
188240
}
189241

@@ -198,12 +250,8 @@ public int subscribeId() {
198250
*/
199251
public @Nullable String inputMode() {
200252
if (bedrockPlayer != null) {
201-
if (floodgate) {
202-
return ((FloodgatePlayer) bedrockPlayer).getInputMode().name();
203-
}
204-
if (geyser) {
205-
return ((GeyserConnection) bedrockPlayer).inputMode().name();
206-
}
253+
if (floodgate) return ((FloodgatePlayer) bedrockPlayer).getInputMode().name();
254+
if (geyser) return ((GeyserConnection) bedrockPlayer).inputMode().name();
207255
}
208256
return null;
209257
}
@@ -219,9 +267,8 @@ public int subscribeId() {
219267
* @return the client ID as a long if the player is a Geyser Bedrock player; -1 otherwise
220268
*/
221269
public long clientID() {
222-
if (bedrockPlayer != null && geyser) {
270+
if (bedrockPlayer != null && geyser)
223271
return ((GeyserSession) bedrockPlayer).getClientData().getClientRandomId();
224-
}
225272
return -1;
226273
}
227274

@@ -235,14 +282,27 @@ public long clientID() {
235282
*/
236283
public @Nullable String xuid() {
237284
if (bedrockPlayer != null) {
238-
if (floodgate) {
239-
return ((FloodgatePlayer) bedrockPlayer).getXuid();
240-
}
285+
if (floodgate) return ((FloodgatePlayer) bedrockPlayer).getXuid();
286+
if (geyser) return ((GeyserConnection) bedrockPlayer).xuid();
287+
}
288+
return null;
289+
}
290+
291+
/**
292+
* Retrieves the unique identifier (UUID) associated with this player.
293+
*
294+
* @return the UUID of the player; never null
295+
*/
296+
public @NotNull UUID uuid() {
297+
if (bedrockPlayer != null) {
298+
if (floodgate) return ((FloodgatePlayer) bedrockPlayer).getCorrectUniqueId();
241299
if (geyser) {
242-
return ((GeyserConnection) bedrockPlayer).xuid();
300+
var uuid = ((GeyserConnection) bedrockPlayer).playerUuid();
301+
if (uuid == null) uuid = player.getUniqueId();
302+
return uuid;
243303
}
244304
}
245-
return null;
305+
return player.getUniqueId();
246306
}
247307

248308
/**
@@ -256,29 +316,20 @@ public long clientID() {
256316
@SuppressWarnings("all")
257317
public boolean form(@NotNull Form form) {
258318
if (bedrockPlayer != null && form != null) {
259-
if (floodgate) {
260-
return ((FloodgatePlayer) bedrockPlayer).sendForm(form);
261-
}
262-
if (geyser) {
263-
return ((GeyserConnection) bedrockPlayer).sendForm(form);
264-
}
319+
if (floodgate) return ((FloodgatePlayer) bedrockPlayer).sendForm(form);
320+
if (geyser) return ((GeyserConnection) bedrockPlayer).sendForm(form);
265321
}
266322
return false;
267323
}
268324

269325
/**
270326
* Retrieves the ping value of a Bedrock player if applicable.
271-
* <p>
272-
* This method checks if the associated player is a Bedrock player and if
273-
* the Geyser integration is available.
274327
*
275328
* @return the ping value in milliseconds for a Bedrock player, or -1 if
276329
* the player is not a Bedrock player or Geyser is not available.
277330
*/
278331
public long ping() {
279-
if (bedrockPlayer != null && geyser) {
280-
return ((GeyserConnection) bedrockPlayer).ping();
281-
}
282-
return -1;
332+
if (bedrockPlayer != null && geyser) return ((GeyserConnection) bedrockPlayer).ping();
333+
return player.getPing();
283334
}
284335
}

0 commit comments

Comments
 (0)