Skip to content

Commit b188927

Browse files
committed
fix uuid stuff, remove HexaConsumer
1 parent 40a7a5a commit b188927

File tree

4 files changed

+33
-83
lines changed

4 files changed

+33
-83
lines changed

build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ sourceCompatibility = targetCompatibility = JavaVersion.VERSION_1_8
88
compileJava.options.encoding 'UTF-8'
99

1010
group 'me.dkim19375'
11-
version '2.6.0'
11+
version '2.6.1'
1212

1313
repositories {
1414
mavenCentral()

src/main/java/me/dkim19375/dkim19375core/PlayerUtils.java

Lines changed: 9 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -11,17 +11,16 @@ public class PlayerUtils {
1111
private PlayerUtils() {
1212
}
1313

14-
public enum InputTypes {
15-
VALID_USERNAME, VALID_UUID, INVALID_USERNAME, INVALID_UUID, INVALID
16-
}
17-
1814
@Nullable
1915
public static Player getFromAll(final String uuidOrPlayer) {
2016
if (uuidOrPlayer.matches("^\\w{3,16}$")) {
2117
return Bukkit.getPlayer(uuidOrPlayer);
2218
}
2319
if (uuidOrPlayer.matches("[0-9a-fA-F]{8}(?:-[0-9a-fA-F]{4}){3}-[0-9a-fA-F]{12}")) {
24-
final UUID uuid = UUID.fromString(uuidOrPlayer);
20+
final UUID uuid = UUIDUtils.getFromString(uuidOrPlayer);
21+
if (uuid == null) {
22+
return null;
23+
}
2524
return Bukkit.getPlayer(uuid);
2625
}
2726
return null;
@@ -32,28 +31,6 @@ public static Player getFromAll(final UUID uuid) {
3231
return Bukkit.getPlayer(uuid);
3332
}
3433

35-
@NotNull
36-
public static InputTypes getInputType(final String uuidOrPlayer) {
37-
if (uuidOrPlayer.matches("^\\w{3,16}$")) {
38-
final Player player = Bukkit.getPlayer(uuidOrPlayer);
39-
if (player != null) {
40-
return InputTypes.VALID_USERNAME;
41-
}
42-
return InputTypes.INVALID_USERNAME;
43-
}
44-
if (uuidOrPlayer.matches("[0-9a-fA-F]{8}(?:-[0-9a-fA-F]{4}){3}-[0-9a-fA-F]{12}")) {
45-
final UUID uuid = UUID.fromString(uuidOrPlayer);
46-
final Player player = Bukkit.getPlayer(uuid);
47-
if (player != null) {
48-
return InputTypes.VALID_UUID;
49-
}
50-
}
51-
if (uuidOrPlayer.matches("[0-9a-fA-F]{32}")) {
52-
return InputTypes.INVALID_UUID;
53-
}
54-
return InputTypes.INVALID;
55-
}
56-
5734
@Nullable
5835
public static Player getPlayerFromUsername(final String username) {
5936
if (username.matches("^\\w{3,16}$")) {
@@ -63,8 +40,11 @@ public static Player getPlayerFromUsername(final String username) {
6340
}
6441

6542
@Nullable
66-
public static Player getPlayerFromUUID(final String StringUUID) {
67-
final UUID uuid = UUID.fromString(StringUUID);
43+
public static Player getPlayerFromUUID(final String stringUUID) {
44+
final UUID uuid = UUIDUtils.getFromString(stringUUID);
45+
if (uuid == null) {
46+
return null;
47+
}
6848
return Bukkit.getPlayer(uuid);
6949
}
7050

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
package me.dkim19375.dkim19375core;
2+
3+
import org.jetbrains.annotations.Nullable;
4+
5+
import java.util.UUID;
6+
7+
public class UUIDUtils {
8+
@Nullable
9+
public static UUID getFromString(String name) {
10+
try {
11+
return UUID.fromString(name);
12+
} catch (IllegalArgumentException ignored) {}
13+
try {
14+
String uuid1 = name.substring(0, 8);
15+
String uuid2 = name.substring(8, 12);
16+
String uuid3 = name.substring(12, 16);
17+
String uuid4 = name.substring(16, 20);
18+
String uuid5 = name.substring(20);
19+
return UUID.fromString(uuid1 + "-" + uuid2 + "-" + uuid3 + "-" + uuid4 + "-" + uuid5);
20+
} catch (IndexOutOfBoundsException ignored) {}
21+
return null;
22+
}
23+
}

src/main/java/me/dkim19375/dkim19375core/function/HexaConsumer.java

Lines changed: 0 additions & 53 deletions
This file was deleted.

0 commit comments

Comments
 (0)