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.
|
// Allow names and uuid by format.
|
||||||
if (MUtil.isValidPlayerName(arg)) return true;
|
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".
|
// Check data presence. This handles specials like "@console".
|
||||||
if (IdUtil.getIdToData().containsKey(arg)) return true;
|
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);
|
Set<String> ret = new TreeSet<String>(String.CASE_INSENSITIVE_ORDER);
|
||||||
|
|
||||||
// Fill Ret
|
// Fill Ret
|
||||||
Set<String> names = (online ? IdUtil.getOnlineNames() : IdUtil.getAllNames());
|
Set<String> names;
|
||||||
|
if (online)
|
||||||
|
{
|
||||||
|
names = IdUtil.getOnlineNames();
|
||||||
for (String name : names)
|
for (String name : names)
|
||||||
{
|
{
|
||||||
if ( ! Mixin.canSee(sender, name)) continue;
|
if ( ! Mixin.canSee(sender, name)) continue;
|
||||||
ret.add(name);
|
ret.add(name);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
names = IdUtil.getAllNames();
|
||||||
|
ret.addAll(names);
|
||||||
|
}
|
||||||
|
|
||||||
// Return Ret
|
// Return Ret
|
||||||
return ret;
|
return ret;
|
||||||
|
@ -70,7 +70,7 @@ public class Fetcher implements Callable<Set<IdAndName>>
|
|||||||
{
|
{
|
||||||
names.add(string);
|
names.add(string);
|
||||||
}
|
}
|
||||||
else if (MUtil.isValidUUID(string))
|
else if (MUtil.isUuid(string))
|
||||||
{
|
{
|
||||||
ids.add(UUID.fromString(string));
|
ids.add(UUID.fromString(string));
|
||||||
}
|
}
|
||||||
|
@ -522,7 +522,7 @@ public class IdUtil implements Listener, Runnable
|
|||||||
{
|
{
|
||||||
// Recurse as UUID
|
// Recurse as UUID
|
||||||
String string = (String)senderObject;
|
String string = (String)senderObject;
|
||||||
UUID uuid = uuidFromString(string);
|
UUID uuid = MUtil.asUuid(string);
|
||||||
if (uuid != null) return getSender(uuid);
|
if (uuid != null) return getSender(uuid);
|
||||||
|
|
||||||
// Registry
|
// Registry
|
||||||
@ -566,7 +566,7 @@ public class IdUtil implements Listener, Runnable
|
|||||||
{
|
{
|
||||||
CommandSender sender = (CommandSender)senderObject;
|
CommandSender sender = (CommandSender)senderObject;
|
||||||
String id = sender.getName();
|
String id = sender.getName();
|
||||||
return uuidFromString(id);
|
return MUtil.asUuid(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
// UUID
|
// UUID
|
||||||
@ -577,7 +577,7 @@ public class IdUtil implements Listener, Runnable
|
|||||||
{
|
{
|
||||||
// Is UUID
|
// Is UUID
|
||||||
String string = (String)senderObject;
|
String string = (String)senderObject;
|
||||||
UUID uuid = uuidFromString(string);
|
UUID uuid = MUtil.asUuid(string);
|
||||||
if (uuid != null) return uuid;
|
if (uuid != null) return uuid;
|
||||||
|
|
||||||
// Is Name
|
// Is Name
|
||||||
@ -590,7 +590,7 @@ public class IdUtil implements Listener, Runnable
|
|||||||
{
|
{
|
||||||
String id = data.getId();
|
String id = data.getId();
|
||||||
if (id == null) return null;
|
if (id == null) return null;
|
||||||
UUID uuid = uuidFromString(id);
|
UUID uuid = MUtil.asUuid(id);
|
||||||
return uuid;
|
return uuid;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -605,7 +605,7 @@ public class IdUtil implements Listener, Runnable
|
|||||||
if (senderObject == null) return null;
|
if (senderObject == null) return null;
|
||||||
|
|
||||||
// Already Done
|
// 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
|
// Console Type
|
||||||
if (senderObject instanceof ConsoleCommandSender) return CONSOLE_ID;
|
if (senderObject instanceof ConsoleCommandSender) return CONSOLE_ID;
|
||||||
@ -721,7 +721,7 @@ public class IdUtil implements Listener, Runnable
|
|||||||
public static boolean isPlayerId(String string)
|
public static boolean isPlayerId(String string)
|
||||||
{
|
{
|
||||||
// NOTE: Assuming all custom ids look like "@shite".
|
// 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)
|
public static boolean isPlayer(Object senderObject)
|
||||||
@ -964,20 +964,4 @@ public class IdUtil implements Listener, Runnable
|
|||||||
return ret;
|
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
|
try
|
||||||
{
|
{
|
||||||
UUID.fromString(string);
|
return UUID.fromString(string);
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
return false;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static boolean isUuid(String string)
|
||||||
|
{
|
||||||
|
return asUuid(string) != null;
|
||||||
|
}
|
||||||
|
|
||||||
// -------------------------------------------- //
|
// -------------------------------------------- //
|
||||||
// STACK TRACE: GET
|
// STACK TRACE: GET
|
||||||
// -------------------------------------------- //
|
// -------------------------------------------- //
|
||||||
|
@ -176,7 +176,7 @@ public class ExtractorLogic
|
|||||||
if (o instanceof String)
|
if (o instanceof String)
|
||||||
{
|
{
|
||||||
String string = (String)o;
|
String string = (String)o;
|
||||||
if (MUtil.isValidUUID(string))
|
if (MUtil.isUuid(string))
|
||||||
{
|
{
|
||||||
String ret = worldNameViaPsMixin(string);
|
String ret = worldNameViaPsMixin(string);
|
||||||
if (ret != null) return ret;
|
if (ret != null) return ret;
|
||||||
|
Loading…
Reference in New Issue
Block a user