21
21
import ch .njol .skript .util .BlockUtils ;
22
22
import ch .njol .skript .util .PotionEffectUtils ;
23
23
import ch .njol .skript .util .StringMode ;
24
+ import ch .njol .skript .util .Utils ;
24
25
import ch .njol .util .StringUtils ;
25
26
import ch .njol .yggdrasil .Fields ;
26
27
import io .papermc .paper .world .MoonPhase ;
@@ -71,10 +72,7 @@ public class BukkitClasses {
71
72
72
73
public BukkitClasses () {}
73
74
74
- public static final Pattern UUID_PATTERN = Pattern .compile ("(?i)[0-9a-f]{8}(-[0-9a-f]{4}){3}-[0-9a-f]{12}" );
75
-
76
75
static {
77
- final boolean GET_ENTITY_METHOD_EXISTS = Skript .methodExists (Bukkit .class , "getEntity" , UUID .class );
78
76
Classes .registerClass (new ClassInfo <>(Entity .class , "entity" )
79
77
.user ("entit(y|ies)" )
80
78
.name ("Entity" )
@@ -91,25 +89,10 @@ public BukkitClasses() {}
91
89
.defaultExpression (new EventValueExpression <>(Entity .class ))
92
90
.parser (new Parser <Entity >() {
93
91
@ Override
94
- @ Nullable
95
- public Entity parse (final String s , final ParseContext context ) {
96
- UUID uuid ;
97
- try {
98
- uuid = UUID .fromString (s );
99
- } catch (IllegalArgumentException iae ) {
100
- return null ;
101
- }
102
- if (GET_ENTITY_METHOD_EXISTS ) {
103
- return Bukkit .getEntity (uuid );
104
- } else {
105
- for (World world : Bukkit .getWorlds ()) {
106
- for (Entity entity : world .getEntities ()) {
107
- if (entity .getUniqueId ().equals (uuid )) {
108
- return entity ;
109
- }
110
- }
111
- }
112
- }
92
+ public @ Nullable Entity parse (final String s , final ParseContext context ) {
93
+ if (Utils .isValidUUID (s ))
94
+ return Bukkit .getEntity (UUID .fromString (s ));
95
+
113
96
return null ;
114
97
}
115
98
@@ -643,8 +626,10 @@ public Player parse(String string, ParseContext context) {
643
626
if (context == ParseContext .COMMAND || context == ParseContext .PARSE ) {
644
627
if (string .isEmpty ())
645
628
return null ;
646
- if (UUID_PATTERN .matcher (string ).matches ())
629
+
630
+ if (Utils .isValidUUID (string ))
647
631
return Bukkit .getPlayer (UUID .fromString (string ));
632
+
648
633
String name = string .toLowerCase (Locale .ENGLISH );
649
634
int nameLength = name .length (); // caching
650
635
List <Player > players = new ArrayList <>();
@@ -709,16 +694,11 @@ public String getDebugMessage(final Player p) {
709
694
.after ("string" , "world" )
710
695
.parser (new Parser <OfflinePlayer >() {
711
696
@ Override
712
- @ Nullable
713
- public OfflinePlayer parse (final String s , final ParseContext context ) {
714
- if (context == ParseContext .COMMAND || context == ParseContext .PARSE ) {
715
- if (UUID_PATTERN .matcher (s ).matches ())
716
- return Bukkit .getOfflinePlayer (UUID .fromString (s ));
717
- else if (!SkriptConfig .playerNameRegexPattern .value ().matcher (s ).matches ())
718
- return null ;
697
+ public @ Nullable OfflinePlayer parse (final String s , final ParseContext context ) {
698
+ if (Utils .isValidUUID (s ))
699
+ return Bukkit .getOfflinePlayer (UUID .fromString (s ));
700
+ else if (SkriptConfig .playerNameRegexPattern .value ().matcher (s ).matches ())
719
701
return Bukkit .getOfflinePlayer (s );
720
- }
721
- assert false ;
722
702
return null ;
723
703
}
724
704
0 commit comments