Fix a couple of performance issues.
This commit is contained in:
parent
e29be0888f
commit
37000854be
@ -82,7 +82,7 @@ public abstract class ARSenderIdAbstract<T> extends ARAbstract<T>
|
||||
{
|
||||
// Allow names and uuid by format.
|
||||
if (MUtil.isValidPlayerName(arg)) return true;
|
||||
if (MUtil.isValidUUID(arg)) return true;
|
||||
if (MUtil.isUuid(arg)) return true;
|
||||
|
||||
// Check data presence. This handles specials like "@console".
|
||||
if (IdUtil.getIdToData().containsKey(arg)) return true;
|
||||
@ -98,12 +98,21 @@ public abstract class ARSenderIdAbstract<T> extends ARAbstract<T>
|
||||
Set<String> ret = new TreeSet<String>(String.CASE_INSENSITIVE_ORDER);
|
||||
|
||||
// Fill Ret
|
||||
Set<String> names = (online ? IdUtil.getOnlineNames() : IdUtil.getAllNames());
|
||||
Set<String> names;
|
||||
if (online)
|
||||
{
|
||||
names = IdUtil.getOnlineNames();
|
||||
for (String name : names)
|
||||
{
|
||||
if ( ! Mixin.canSee(sender, name)) continue;
|
||||
ret.add(name);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
names = IdUtil.getAllNames();
|
||||
ret.addAll(names);
|
||||
}
|
||||
|
||||
// Return Ret
|
||||
return ret;
|
||||
|
@ -70,7 +70,7 @@ public class Fetcher implements Callable<Set<IdAndName>>
|
||||
{
|
||||
names.add(string);
|
||||
}
|
||||
else if (MUtil.isValidUUID(string))
|
||||
else if (MUtil.isUuid(string))
|
||||
{
|
||||
ids.add(UUID.fromString(string));
|
||||
}
|
||||
|
@ -522,7 +522,7 @@ public class IdUtil implements Listener, Runnable
|
||||
{
|
||||
// Recurse as UUID
|
||||
String string = (String)senderObject;
|
||||
UUID uuid = uuidFromString(string);
|
||||
UUID uuid = MUtil.asUuid(string);
|
||||
if (uuid != null) return getSender(uuid);
|
||||
|
||||
// Registry
|
||||
@ -566,7 +566,7 @@ public class IdUtil implements Listener, Runnable
|
||||
{
|
||||
CommandSender sender = (CommandSender)senderObject;
|
||||
String id = sender.getName();
|
||||
return uuidFromString(id);
|
||||
return MUtil.asUuid(id);
|
||||
}
|
||||
|
||||
// UUID
|
||||
@ -577,7 +577,7 @@ public class IdUtil implements Listener, Runnable
|
||||
{
|
||||
// Is UUID
|
||||
String string = (String)senderObject;
|
||||
UUID uuid = uuidFromString(string);
|
||||
UUID uuid = MUtil.asUuid(string);
|
||||
if (uuid != null) return uuid;
|
||||
|
||||
// Is Name
|
||||
@ -590,7 +590,7 @@ public class IdUtil implements Listener, Runnable
|
||||
{
|
||||
String id = data.getId();
|
||||
if (id == null) return null;
|
||||
UUID uuid = uuidFromString(id);
|
||||
UUID uuid = MUtil.asUuid(id);
|
||||
return uuid;
|
||||
}
|
||||
|
||||
@ -605,7 +605,7 @@ public class IdUtil implements Listener, Runnable
|
||||
if (senderObject == null) return null;
|
||||
|
||||
// Already Done
|
||||
if (senderObject instanceof String && MUtil.isValidUUID((String)senderObject)) return (String)senderObject;
|
||||
if (senderObject instanceof String && MUtil.isUuid((String)senderObject)) return (String)senderObject;
|
||||
|
||||
// Console Type
|
||||
if (senderObject instanceof ConsoleCommandSender) return CONSOLE_ID;
|
||||
@ -721,7 +721,7 @@ public class IdUtil implements Listener, Runnable
|
||||
public static boolean isPlayerId(String string)
|
||||
{
|
||||
// NOTE: Assuming all custom ids look like "@shite".
|
||||
return MUtil.isValidPlayerName(string) || MUtil.isValidUUID(string);
|
||||
return MUtil.isValidPlayerName(string) || MUtil.isUuid(string);
|
||||
}
|
||||
|
||||
public static boolean isPlayer(Object senderObject)
|
||||
@ -964,20 +964,4 @@ public class IdUtil implements Listener, Runnable
|
||||
return ret;
|
||||
}
|
||||
|
||||
// -------------------------------------------- //
|
||||
// UTIL
|
||||
// -------------------------------------------- //
|
||||
|
||||
public static UUID uuidFromString(String string)
|
||||
{
|
||||
try
|
||||
{
|
||||
return UUID.fromString(string);
|
||||
}
|
||||
catch (IllegalArgumentException e)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -180,23 +180,33 @@ public class MUtil
|
||||
}
|
||||
|
||||
// -------------------------------------------- //
|
||||
// IS VALID UUID
|
||||
// UUID
|
||||
// -------------------------------------------- //
|
||||
|
||||
public static boolean isValidUUID(String string)
|
||||
public static UUID asUuid(String string)
|
||||
{
|
||||
if (string == null) return false;
|
||||
// Null
|
||||
if (string == null) return null;
|
||||
|
||||
// Avoid Exception
|
||||
if (string.length() != 36) return null;
|
||||
|
||||
// Try
|
||||
try
|
||||
{
|
||||
UUID.fromString(string);
|
||||
return true;
|
||||
return UUID.fromString(string);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
return false;
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean isUuid(String string)
|
||||
{
|
||||
return asUuid(string) != null;
|
||||
}
|
||||
|
||||
// -------------------------------------------- //
|
||||
// STACK TRACE: GET
|
||||
// -------------------------------------------- //
|
||||
|
@ -176,7 +176,7 @@ public class ExtractorLogic
|
||||
if (o instanceof String)
|
||||
{
|
||||
String string = (String)o;
|
||||
if (MUtil.isValidUUID(string))
|
||||
if (MUtil.isUuid(string))
|
||||
{
|
||||
String ret = worldNameViaPsMixin(string);
|
||||
if (ret != null) return ret;
|
||||
|
Loading…
Reference in New Issue
Block a user