mirror of
https://github.com/LuckPerms/LuckPerms.git
synced 2025-01-01 05:57:51 +01:00
Fix parsing log entry types (#1438)
This commit is contained in:
parent
beeb4fa169
commit
287cc308d6
@ -102,6 +102,35 @@ public interface LogEntry extends Comparable<LogEntry> {
|
||||
enum Type {
|
||||
USER('U'), GROUP('G'), TRACK('T');
|
||||
|
||||
/**
|
||||
* Parses a {@link Type} from a string.
|
||||
*
|
||||
* @param type the string
|
||||
* @return a type
|
||||
* @throws IllegalArgumentException if a type could not be parsed
|
||||
* @since 4.4
|
||||
*/
|
||||
public static @NonNull Type parse(String type) {
|
||||
try {
|
||||
return valueOf(type);
|
||||
} catch (IllegalArgumentException e) {
|
||||
// ignore
|
||||
}
|
||||
try {
|
||||
return valueOf(type.charAt(0));
|
||||
} catch (IllegalArgumentException e) {
|
||||
// ignore
|
||||
}
|
||||
throw new IllegalArgumentException("Unknown type: " + type);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a {@link Type} by its code.
|
||||
*
|
||||
* @param code the code - see {@link Type#getCode()}.
|
||||
* @return a type
|
||||
* @throws IllegalArgumentException if a type could not be resolved
|
||||
*/
|
||||
public static @NonNull Type valueOf(char code) {
|
||||
switch (code) {
|
||||
case 'U':
|
||||
|
@ -58,7 +58,7 @@ public final class LogEntryJsonSerializer {
|
||||
|
||||
builder.actor(UUID.fromString(data.get("actor").getAsString()));
|
||||
builder.actorName(data.get("actorName").getAsString());
|
||||
builder.type(LogEntry.Type.valueOf(data.get("type").getAsString()));
|
||||
builder.type(LogEntry.Type.parse(data.get("type").getAsString()));
|
||||
if (data.has("acted")) {
|
||||
builder.actor(UUID.fromString(data.get("acted").getAsString()));
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user