From 84afbf26f86a4334c96b60782171919f4ac6d55c Mon Sep 17 00:00:00 2001 From: Luck Date: Thu, 18 Aug 2016 00:07:56 +0100 Subject: [PATCH] refactor LogEntry & cleanup stream formatting --- .../java/me/lucko/luckperms/api/LogEntry.java | 178 ++++++++++++++---- .../luckperms/commands/CommandManager.java | 20 +- .../lucko/luckperms/commands/MainCommand.java | 37 +++- .../luckperms/commands/group/CreateGroup.java | 4 +- .../luckperms/commands/group/DeleteGroup.java | 7 +- .../group/subcommands/GroupClear.java | 4 +- .../group/subcommands/GroupSetInherit.java | 14 +- .../group/subcommands/GroupSetPermission.java | 14 +- .../subcommands/GroupSetTempInherit.java | 14 +- .../subcommands/GroupSetTempPermission.java | 14 +- .../subcommands/GroupUnSetPermission.java | 14 +- .../group/subcommands/GroupUnsetInherit.java | 14 +- .../subcommands/GroupUnsetTempInherit.java | 14 +- .../subcommands/GroupUnsetTempPermission.java | 14 +- .../commands/log/LogMainCommand.java | 21 ++- .../luckperms/commands/track/CreateTrack.java | 4 +- .../luckperms/commands/track/DeleteTrack.java | 8 +- .../track/subcommands/TrackAppend.java | 6 +- .../track/subcommands/TrackClear.java | 4 +- .../track/subcommands/TrackInsert.java | 6 +- .../track/subcommands/TrackRemove.java | 6 +- .../user/subcommands/UserAddGroup.java | 14 +- .../user/subcommands/UserAddTempGroup.java | 14 +- .../commands/user/subcommands/UserClear.java | 4 +- .../commands/user/subcommands/UserDemote.java | 6 +- .../user/subcommands/UserPromote.java | 6 +- .../user/subcommands/UserRemoveGroup.java | 14 +- .../user/subcommands/UserRemoveTempGroup.java | 14 +- .../user/subcommands/UserSetPermission.java | 14 +- .../user/subcommands/UserSetPrimaryGroup.java | 6 +- .../subcommands/UserSetTempPermission.java | 14 +- .../user/subcommands/UserUnSetPermission.java | 14 +- .../subcommands/UserUnsetTempPermission.java | 14 +- .../luckperms/core/PermissionHolder.java | 3 +- .../me/lucko/luckperms/core/UuidCache.java | 6 +- .../me/lucko/luckperms/data/LogEntry.java | 118 ++++++++++++ .../lucko/luckperms/data/LogEntryBuilder.java | 173 ----------------- .../java/me/lucko/luckperms/groups/Group.java | 10 +- .../lucko/luckperms/runnables/UpdateTask.java | 4 +- .../storage/methods/FlatfileDatastore.java | 8 +- .../storage/methods/MySQLDatastore.java | 2 +- .../storage/methods/SQLiteDatastore.java | 2 +- .../java/me/lucko/luckperms/tracks/Track.java | 10 +- .../lucko/luckperms/tracks/TrackManager.java | 4 +- .../java/me/lucko/luckperms/users/User.java | 10 +- .../me/lucko/luckperms/users/UserManager.java | 4 +- .../me/lucko/luckperms/SpongeListener.java | 4 +- .../me/lucko/luckperms/users/SpongeUser.java | 4 +- .../me/lucko/luckperms/utils/VersionUtil.java | 2 +- 49 files changed, 506 insertions(+), 409 deletions(-) create mode 100644 common/src/main/java/me/lucko/luckperms/data/LogEntry.java delete mode 100644 common/src/main/java/me/lucko/luckperms/data/LogEntryBuilder.java diff --git a/api/src/main/java/me/lucko/luckperms/api/LogEntry.java b/api/src/main/java/me/lucko/luckperms/api/LogEntry.java index 6585913b..691dc660 100644 --- a/api/src/main/java/me/lucko/luckperms/api/LogEntry.java +++ b/api/src/main/java/me/lucko/luckperms/api/LogEntry.java @@ -24,19 +24,20 @@ package me.lucko.luckperms.api; import java.util.UUID; -public final class LogEntry implements Comparable { +public class LogEntry implements Comparable { public static LogEntryBuilder builder() { return new LogEntryBuilder(); } + private static final String FORMAT = "&8(&e%s&8) [&a%s&8] (&b%s&8) &7--> &f%s"; - private final long timestamp; - private final UUID actor; - private final String actorName; - private final char type; - private final UUID acted; - private final String actedName; - private final String action; + private long timestamp; + private UUID actor; + private String actorName; + private char type; + private UUID acted; + private String actedName; + private String action; public LogEntry(long timestamp, UUID actor, String actorName, char type, UUID acted, String actedName, String action) { if (actor == null) { @@ -61,6 +62,16 @@ public final class LogEntry implements Comparable { this.action = action; } + protected LogEntry() { + this.timestamp = 0L; + this.actor = null; + this.actorName = null; + this.type = Character.MIN_VALUE; + this.acted = null; + this.actedName = null; + this.action = null; + } + @Override public int compareTo(LogEntry o) { return Long.compare(timestamp, o.getTimestamp()); @@ -109,6 +120,34 @@ public final class LogEntry implements Comparable { return action; } + void setTimestamp(long timestamp) { + this.timestamp = timestamp; + } + + void setActor(UUID actor) { + this.actor = actor; + } + + void setActorName(String actorName) { + this.actorName = actorName; + } + + void setType(char type) { + this.type = type; + } + + void setActed(UUID acted) { + this.acted = acted; + } + + void setActedName(String actedName) { + this.actedName = actedName; + } + + void setAction(String action) { + this.action = action; + } + @Override public String toString() { return "LogEntry(timestamp=" + this.getTimestamp() + ", actor=" + this.getActor() + ", actorName=" + @@ -160,59 +199,116 @@ public final class LogEntry implements Comparable { return result; } - public static class LogEntryBuilder { - private long timestamp; - private UUID actor; - private String actorName; - private char type; - private UUID acted; - private String actedName; - private String action; + public static class LogEntryBuilder extends AbstractLogEntryBuilder { - public LogEntryBuilder timestamp(long timestamp) { - this.timestamp = timestamp; - return this; + @Override + protected LogEntry createObj() { + return new LogEntry(); } - public LogEntryBuilder actor(UUID actor) { - this.actor = actor; + @Override + protected LogEntryBuilder getThis() { return this; } + } - public LogEntryBuilder actorName(String actorName) { - this.actorName = actorName; - return this; + public static abstract class AbstractLogEntryBuilder> { + private T obj; + private B thisObj; + + public AbstractLogEntryBuilder() { + obj = createObj(); + thisObj = getThis(); } - public LogEntryBuilder type(char type) { - this.type = type; - return this; + protected abstract T createObj(); + protected abstract B getThis(); + + public long getTimestamp() { + return obj.getTimestamp(); } - public LogEntryBuilder acted(UUID acted) { - this.acted = acted; - return this; + public UUID getActor() { + return obj.getActor(); } - public LogEntryBuilder actedName(String actedName) { - this.actedName = actedName; - return this; + public String getActorName() { + return obj.getActorName(); } - public LogEntryBuilder action(String action) { - this.action = action; - return this; + public char getType() { + return obj.getType(); } - public LogEntry build() { - return new LogEntry(timestamp, actor, actorName, type, acted, actedName, action); + public UUID getActed() { + return obj.getActed(); + } + + public String getActedName() { + return obj.getActedName(); + } + + public String getAction() { + return obj.getAction(); + } + + public B timestamp(long timestamp) { + obj.setTimestamp(timestamp); + return thisObj; + } + + public B actor(UUID actor) { + obj.setActor(actor); + return thisObj; + } + + public B actorName(String actorName) { + obj.setActorName(actorName); + return thisObj; + } + + public B type(char type) { + obj.setType(type); + return thisObj; + } + + public B acted(UUID acted) { + obj.setActed(acted); + return thisObj; + } + + public B actedName(String actedName) { + obj.setActedName(actedName); + return thisObj; + } + + public B action(String action) { + obj.setAction(action); + return thisObj; + } + + public T build() { + if (getActor() == null) { + throw new NullPointerException("actor"); + } + if (getActorName() == null) { + throw new NullPointerException("actorName"); + } + if (getActedName() == null) { + throw new NullPointerException("actedName"); + } + if (getAction() == null) { + throw new NullPointerException("action"); + } + + return obj; } @Override public String toString() { - return "LogEntry.LogEntryBuilder(timestamp=" + this.timestamp + ", actor=" + this.actor + ", actorName=" + - this.actorName + ", type=" + this.type + ", acted=" + this.acted + ", actedName=" + this.actedName + - ", action=" + this.action + ")"; + return "LogEntry.LogEntryBuilder(timestamp=" + getTimestamp() + ", actor=" + getActor() + ", actorName=" + + getActorName() + ", type=" + getType() + ", acted=" + getActed() + ", actedName=" + getActedName() + + ", action=" + getAction() + ")"; } } diff --git a/common/src/main/java/me/lucko/luckperms/commands/CommandManager.java b/common/src/main/java/me/lucko/luckperms/commands/CommandManager.java index f29efe6b..7c1447c5 100644 --- a/common/src/main/java/me/lucko/luckperms/commands/CommandManager.java +++ b/common/src/main/java/me/lucko/luckperms/commands/CommandManager.java @@ -144,18 +144,28 @@ public class CommandManager { */ @SuppressWarnings("unchecked") public List onTabComplete(Sender sender, List args) { - final List mains = mainCommands.stream().filter(m -> m.isAuthorized(sender)).collect(Collectors.toList()); + final List mains = mainCommands.stream() + .filter(m -> m.isAuthorized(sender)) + .collect(Collectors.toList()); if (args.size() <= 1) { if (args.isEmpty() || args.get(0).equalsIgnoreCase("")) { - return mains.stream().map(MainCommand::getName).map(String::toLowerCase).collect(Collectors.toList()); + return mains.stream() + .map(m -> m.getName().toLowerCase()) + .collect(Collectors.toList()); } - return mains.stream().map(MainCommand::getName).map(String::toLowerCase) - .filter(s -> s.startsWith(args.get(0).toLowerCase())).collect(Collectors.toList()); + return mains.stream() + .map(m -> m.getName().toLowerCase()) + .filter(s -> s.startsWith(args.get(0).toLowerCase())) + .collect(Collectors.toList()); } - Optional o = mains.stream().filter(m -> m.getName().equalsIgnoreCase(args.get(0))).limit(1).findAny(); + Optional o = mains.stream() + .filter(m -> m.getName().equalsIgnoreCase(args.get(0))) + .limit(1) + .findAny(); + if (!o.isPresent()) { return Collections.emptyList(); } diff --git a/common/src/main/java/me/lucko/luckperms/commands/MainCommand.java b/common/src/main/java/me/lucko/luckperms/commands/MainCommand.java index 86d9491b..885f852d 100644 --- a/common/src/main/java/me/lucko/luckperms/commands/MainCommand.java +++ b/common/src/main/java/me/lucko/luckperms/commands/MainCommand.java @@ -76,7 +76,10 @@ public abstract class MainCommand { return CommandResult.INVALID_ARGS; } - Optional> o = subCommands.stream().filter(s -> s.getName().equalsIgnoreCase(args.get(requiredArgsLength - 1))).limit(1).findAny(); + Optional> o = subCommands.stream() + .filter(s -> s.getName().equalsIgnoreCase(args.get(requiredArgsLength - 1))) + .limit(1) + .findAny(); if (!o.isPresent()) { Message.COMMAND_NOT_RECOGNISED.send(sender); @@ -121,7 +124,7 @@ public abstract class MainCommand { protected abstract void cleanup(T t, LuckPermsPlugin plugin); /** - * Get a list of objects for tab completion + * Get a list of {@link T} objects for tab completion * @param plugin a link to the main plugin instance * @return a list of strings */ @@ -138,7 +141,10 @@ public abstract class MainCommand { return; } - List subs = getSubCommands().stream().filter(s -> s.isAuthorized(sender)).collect(Collectors.toList()); + List subs = getSubCommands().stream() + .filter(s -> s.isAuthorized(sender)) + .collect(Collectors.toList()); + if (subs.size() > 0) { Util.sendPluginMessage(sender, "&e" + getName() + " Sub Commands:"); @@ -168,20 +174,33 @@ public abstract class MainCommand { return objects; } - return objects.stream().filter(s -> s.toLowerCase().startsWith(args.get(0).toLowerCase())).collect(Collectors.toList()); + return objects.stream() + .filter(s -> s.toLowerCase().startsWith(args.get(0).toLowerCase())) + .collect(Collectors.toList()); } - final List> subs = getSubCommands().stream().filter(s -> s.isAuthorized(sender)).collect(Collectors.toList()); + final List> subs = getSubCommands().stream() + .filter(s -> s.isAuthorized(sender)) + .collect(Collectors.toList()); + if (args.size() == 2) { if (args.get(1).equalsIgnoreCase("")) { - return subs.stream().map(SubCommand::getName).map(String::toLowerCase).collect(Collectors.toList()); + return subs.stream() + .map(m -> m.getName().toLowerCase()) + .collect(Collectors.toList()); } - return subs.stream().map(SubCommand::getName).map(String::toLowerCase) - .filter(s -> s.toLowerCase().startsWith(args.get(1).toLowerCase())).collect(Collectors.toList()); + return subs.stream() + .map(m -> m.getName().toLowerCase()) + .filter(s -> s.toLowerCase().startsWith(args.get(1).toLowerCase())) + .collect(Collectors.toList()); } - Optional> o = subs.stream().filter(s -> s.getName().equalsIgnoreCase(args.get(1))).limit(1).findAny(); + Optional> o = subs.stream() + .filter(s -> s.getName().equalsIgnoreCase(args.get(1))) + .limit(1) + .findAny(); + if (!o.isPresent()) { return Collections.emptyList(); } diff --git a/common/src/main/java/me/lucko/luckperms/commands/group/CreateGroup.java b/common/src/main/java/me/lucko/luckperms/commands/group/CreateGroup.java index 3c20b57c..8c43c0de 100644 --- a/common/src/main/java/me/lucko/luckperms/commands/group/CreateGroup.java +++ b/common/src/main/java/me/lucko/luckperms/commands/group/CreateGroup.java @@ -28,7 +28,7 @@ import me.lucko.luckperms.commands.Sender; import me.lucko.luckperms.commands.SingleMainCommand; import me.lucko.luckperms.constants.Message; import me.lucko.luckperms.constants.Permission; -import me.lucko.luckperms.data.LogEntryBuilder; +import me.lucko.luckperms.data.LogEntry; import me.lucko.luckperms.utils.ArgumentChecker; import java.util.List; @@ -62,7 +62,7 @@ public class CreateGroup extends SingleMainCommand { } Message.CREATE_SUCCESS.send(sender, groupName); - LogEntryBuilder.get().actor(sender).actedName(groupName).type('G').action("create").submit(plugin); + LogEntry.build().actor(sender).actedName(groupName).type('G').action("create").build().submit(plugin); plugin.runUpdateTask(); return CommandResult.SUCCESS; } diff --git a/common/src/main/java/me/lucko/luckperms/commands/group/DeleteGroup.java b/common/src/main/java/me/lucko/luckperms/commands/group/DeleteGroup.java index 61307e71..4c10e505 100644 --- a/common/src/main/java/me/lucko/luckperms/commands/group/DeleteGroup.java +++ b/common/src/main/java/me/lucko/luckperms/commands/group/DeleteGroup.java @@ -28,7 +28,7 @@ import me.lucko.luckperms.commands.Sender; import me.lucko.luckperms.commands.SingleMainCommand; import me.lucko.luckperms.constants.Message; import me.lucko.luckperms.constants.Permission; -import me.lucko.luckperms.data.LogEntryBuilder; +import me.lucko.luckperms.data.LogEntry; import me.lucko.luckperms.groups.Group; import me.lucko.luckperms.utils.ArgumentChecker; @@ -78,7 +78,7 @@ public class DeleteGroup extends SingleMainCommand { } Message.DELETE_SUCCESS.send(sender, groupName); - LogEntryBuilder.get().actor(sender).actedName(groupName).type('G').action("delete").submit(plugin); + LogEntry.build().actor(sender).actedName(groupName).type('G').action("delete").build().submit(plugin); plugin.runUpdateTask(); return CommandResult.SUCCESS; } @@ -92,7 +92,8 @@ public class DeleteGroup extends SingleMainCommand { return groups; } - return groups.stream().filter(s -> s.toLowerCase().startsWith(args.get(0).toLowerCase())).collect(Collectors.toList()); + return groups.stream().filter(s -> s.toLowerCase().startsWith(args.get(0).toLowerCase())) + .collect(Collectors.toList()); } return Collections.emptyList(); diff --git a/common/src/main/java/me/lucko/luckperms/commands/group/subcommands/GroupClear.java b/common/src/main/java/me/lucko/luckperms/commands/group/subcommands/GroupClear.java index 29df3c5c..8f1b0297 100644 --- a/common/src/main/java/me/lucko/luckperms/commands/group/subcommands/GroupClear.java +++ b/common/src/main/java/me/lucko/luckperms/commands/group/subcommands/GroupClear.java @@ -29,7 +29,7 @@ import me.lucko.luckperms.commands.Sender; import me.lucko.luckperms.commands.SubCommand; import me.lucko.luckperms.constants.Message; import me.lucko.luckperms.constants.Permission; -import me.lucko.luckperms.data.LogEntryBuilder; +import me.lucko.luckperms.data.LogEntry; import me.lucko.luckperms.groups.Group; import java.util.List; @@ -44,7 +44,7 @@ public class GroupClear extends SubCommand { public CommandResult execute(LuckPermsPlugin plugin, Sender sender, Group group, List args, String label) { group.clearNodes(); Message.CLEAR_SUCCESS.send(sender, group.getName()); - LogEntryBuilder.get().actor(sender).acted(group).action("clear").submit(plugin); + LogEntry.build().actor(sender).acted(group).action("clear").build().submit(plugin); save(group, sender, plugin); return CommandResult.SUCCESS; } diff --git a/common/src/main/java/me/lucko/luckperms/commands/group/subcommands/GroupSetInherit.java b/common/src/main/java/me/lucko/luckperms/commands/group/subcommands/GroupSetInherit.java index e7f60b1e..3b695563 100644 --- a/common/src/main/java/me/lucko/luckperms/commands/group/subcommands/GroupSetInherit.java +++ b/common/src/main/java/me/lucko/luckperms/commands/group/subcommands/GroupSetInherit.java @@ -29,7 +29,7 @@ import me.lucko.luckperms.commands.Sender; import me.lucko.luckperms.commands.SubCommand; import me.lucko.luckperms.constants.Message; import me.lucko.luckperms.constants.Permission; -import me.lucko.luckperms.data.LogEntryBuilder; +import me.lucko.luckperms.data.LogEntry; import me.lucko.luckperms.exceptions.ObjectAlreadyHasException; import me.lucko.luckperms.groups.Group; import me.lucko.luckperms.utils.ArgumentChecker; @@ -74,24 +74,24 @@ public class GroupSetInherit extends SubCommand { if (args.size() == 2) { group.setInheritGroup(group1, server); Message.GROUP_SETINHERIT_SERVER_SUCCESS.send(sender, group.getName(), group1.getName(), server); - LogEntryBuilder.get().actor(sender).acted(group) + LogEntry.build().actor(sender).acted(group) .action("setinherit " + group1.getName() + " " + server) - .submit(plugin); + .build().submit(plugin); } else { final String world = args.get(2).toLowerCase(); group.setInheritGroup(group1, server, world); Message.GROUP_SETINHERIT_SERVER_WORLD_SUCCESS.send(sender, group.getName(), group1.getName(), server, world); - LogEntryBuilder.get().actor(sender).acted(group) + LogEntry.build().actor(sender).acted(group) .action("setinherit " + group1.getName() + " " + server + " " + world) - .submit(plugin); + .build().submit(plugin); } } else { group.setInheritGroup(group1); Message.GROUP_SETINHERIT_SUCCESS.send(sender, group.getName(), group1.getName()); - LogEntryBuilder.get().actor(sender).acted(group) + LogEntry.build().actor(sender).acted(group) .action("setinherit " + group1.getName()) - .submit(plugin); + .build().submit(plugin); } save(group, sender, plugin); diff --git a/common/src/main/java/me/lucko/luckperms/commands/group/subcommands/GroupSetPermission.java b/common/src/main/java/me/lucko/luckperms/commands/group/subcommands/GroupSetPermission.java index 5cf51d86..a456a851 100644 --- a/common/src/main/java/me/lucko/luckperms/commands/group/subcommands/GroupSetPermission.java +++ b/common/src/main/java/me/lucko/luckperms/commands/group/subcommands/GroupSetPermission.java @@ -30,7 +30,7 @@ import me.lucko.luckperms.commands.SubCommand; import me.lucko.luckperms.constants.Message; import me.lucko.luckperms.constants.Patterns; import me.lucko.luckperms.constants.Permission; -import me.lucko.luckperms.data.LogEntryBuilder; +import me.lucko.luckperms.data.LogEntry; import me.lucko.luckperms.exceptions.ObjectAlreadyHasException; import me.lucko.luckperms.groups.Group; import me.lucko.luckperms.utils.ArgumentChecker; @@ -76,24 +76,24 @@ public class GroupSetPermission extends SubCommand { if (args.size() == 3) { group.setPermission(node, b, server); Message.SETPERMISSION_SERVER_SUCCESS.send(sender, node, bool, group.getName(), server); - LogEntryBuilder.get().actor(sender).acted(group) + LogEntry.build().actor(sender).acted(group) .action("set " + node + " " + b + " " + server) - .submit(plugin); + .build().submit(plugin); } else { final String world = args.get(3).toLowerCase(); group.setPermission(node, b, server, world); Message.SETPERMISSION_SERVER_WORLD_SUCCESS.send(sender, node, bool, group.getName(), server, world); - LogEntryBuilder.get().actor(sender).acted(group) + LogEntry.build().actor(sender).acted(group) .action("set " + node + " " + b + " " + server + " " + world) - .submit(plugin); + .build().submit(plugin); } } else { group.setPermission(node, b); Message.SETPERMISSION_SUCCESS.send(sender, node, bool, group.getName()); - LogEntryBuilder.get().actor(sender).acted(group) + LogEntry.build().actor(sender).acted(group) .action("set " + node + " " + b) - .submit(plugin); + .build().submit(plugin); } save(group, sender, plugin); diff --git a/common/src/main/java/me/lucko/luckperms/commands/group/subcommands/GroupSetTempInherit.java b/common/src/main/java/me/lucko/luckperms/commands/group/subcommands/GroupSetTempInherit.java index 2da2517c..47a08602 100644 --- a/common/src/main/java/me/lucko/luckperms/commands/group/subcommands/GroupSetTempInherit.java +++ b/common/src/main/java/me/lucko/luckperms/commands/group/subcommands/GroupSetTempInherit.java @@ -29,7 +29,7 @@ import me.lucko.luckperms.commands.Sender; import me.lucko.luckperms.commands.SubCommand; import me.lucko.luckperms.constants.Message; import me.lucko.luckperms.constants.Permission; -import me.lucko.luckperms.data.LogEntryBuilder; +import me.lucko.luckperms.data.LogEntry; import me.lucko.luckperms.exceptions.ObjectAlreadyHasException; import me.lucko.luckperms.groups.Group; import me.lucko.luckperms.utils.ArgumentChecker; @@ -89,25 +89,25 @@ public class GroupSetTempInherit extends SubCommand { group.setInheritGroup(group1, server, duration); Message.GROUP_SET_TEMP_INHERIT_SERVER_SUCCESS.send(sender, group.getName(), group1.getName(), server, DateUtil.formatDateDiff(duration)); - LogEntryBuilder.get().actor(sender).acted(group) + LogEntry.build().actor(sender).acted(group) .action("settempinherit " + group1.getName() + " " + duration + " " + server) - .submit(plugin); + .build().submit(plugin); } else { final String world = args.get(3).toLowerCase(); group.setInheritGroup(group1, server, world, duration); Message.GROUP_SET_TEMP_INHERIT_SERVER_WORLD_SUCCESS.send(sender, group.getName(), group1.getName(), server, world, DateUtil.formatDateDiff(duration)); - LogEntryBuilder.get().actor(sender).acted(group) + LogEntry.build().actor(sender).acted(group) .action("settempinherit " + group1.getName() + " " + duration + " " + server + " " + world) - .submit(plugin); + .build().submit(plugin); } } else { group.setInheritGroup(group1, duration); Message.GROUP_SET_TEMP_INHERIT_SUCCESS.send(sender, group.getName(), group1.getName(), DateUtil.formatDateDiff(duration)); - LogEntryBuilder.get().actor(sender).acted(group) + LogEntry.build().actor(sender).acted(group) .action("settempinherit " + group1.getName() + " " + duration) - .submit(plugin); + .build().submit(plugin); } save(group, sender, plugin); diff --git a/common/src/main/java/me/lucko/luckperms/commands/group/subcommands/GroupSetTempPermission.java b/common/src/main/java/me/lucko/luckperms/commands/group/subcommands/GroupSetTempPermission.java index 39d41570..112b2f7b 100644 --- a/common/src/main/java/me/lucko/luckperms/commands/group/subcommands/GroupSetTempPermission.java +++ b/common/src/main/java/me/lucko/luckperms/commands/group/subcommands/GroupSetTempPermission.java @@ -30,7 +30,7 @@ import me.lucko.luckperms.commands.SubCommand; import me.lucko.luckperms.constants.Message; import me.lucko.luckperms.constants.Patterns; import me.lucko.luckperms.constants.Permission; -import me.lucko.luckperms.data.LogEntryBuilder; +import me.lucko.luckperms.data.LogEntry; import me.lucko.luckperms.exceptions.ObjectAlreadyHasException; import me.lucko.luckperms.groups.Group; import me.lucko.luckperms.utils.ArgumentChecker; @@ -92,25 +92,25 @@ public class GroupSetTempPermission extends SubCommand { group.setPermission(node, b, server, duration); Message.SETPERMISSION_TEMP_SERVER_SUCCESS.send(sender, node, bool, group.getName(), server, DateUtil.formatDateDiff(duration)); - LogEntryBuilder.get().actor(sender).acted(group) + LogEntry.build().actor(sender).acted(group) .action("settemp " + node + " " + b + " " + duration + " " + server) - .submit(plugin); + .build().submit(plugin); } else { final String world = args.get(4).toLowerCase(); group.setPermission(node, b, server, world, duration); Message.SETPERMISSION_TEMP_SERVER_WORLD_SUCCESS.send(sender, node, bool, group.getName(), server, world, DateUtil.formatDateDiff(duration)); - LogEntryBuilder.get().actor(sender).acted(group) + LogEntry.build().actor(sender).acted(group) .action("settemp " + node + " " + b + " " + duration + " " + server + " " + world) - .submit(plugin); + .build().submit(plugin); } } else { group.setPermission(node, b, duration); Message.SETPERMISSION_TEMP_SUCCESS.send(sender, node, bool, group.getName(), DateUtil.formatDateDiff(duration)); - LogEntryBuilder.get().actor(sender).acted(group) + LogEntry.build().actor(sender).acted(group) .action("settemp " + node + " " + b + " " + duration) - .submit(plugin); + .build().submit(plugin); } save(group, sender, plugin); diff --git a/common/src/main/java/me/lucko/luckperms/commands/group/subcommands/GroupUnSetPermission.java b/common/src/main/java/me/lucko/luckperms/commands/group/subcommands/GroupUnSetPermission.java index 638e12cd..7604f6ef 100644 --- a/common/src/main/java/me/lucko/luckperms/commands/group/subcommands/GroupUnSetPermission.java +++ b/common/src/main/java/me/lucko/luckperms/commands/group/subcommands/GroupUnSetPermission.java @@ -30,7 +30,7 @@ import me.lucko.luckperms.commands.SubCommand; import me.lucko.luckperms.constants.Message; import me.lucko.luckperms.constants.Patterns; import me.lucko.luckperms.constants.Permission; -import me.lucko.luckperms.data.LogEntryBuilder; +import me.lucko.luckperms.data.LogEntry; import me.lucko.luckperms.exceptions.ObjectLacksException; import me.lucko.luckperms.groups.Group; import me.lucko.luckperms.utils.ArgumentChecker; @@ -68,24 +68,24 @@ public class GroupUnSetPermission extends SubCommand { if (args.size() == 2) { group.unsetPermission(node, server); Message.UNSETPERMISSION_SERVER_SUCCESS.send(sender, node, group.getName(), server); - LogEntryBuilder.get().actor(sender).acted(group) + LogEntry.build().actor(sender).acted(group) .action("unset " + node + " " + server) - .submit(plugin); + .build().submit(plugin); } else { final String world = args.get(2).toLowerCase(); group.unsetPermission(node, server, world); Message.UNSETPERMISSION_SERVER_WORLD_SUCCESS.send(sender, node, group.getName(), server, world); - LogEntryBuilder.get().actor(sender).acted(group) + LogEntry.build().actor(sender).acted(group) .action("unset " + node + " " + server + " " + world) - .submit(plugin); + .build().submit(plugin); } } else { group.unsetPermission(node); Message.UNSETPERMISSION_SUCCESS.send(sender, node, group.getName()); - LogEntryBuilder.get().actor(sender).acted(group) + LogEntry.build().actor(sender).acted(group) .action("unset " + node) - .submit(plugin); + .build().submit(plugin); } save(group, sender, plugin); diff --git a/common/src/main/java/me/lucko/luckperms/commands/group/subcommands/GroupUnsetInherit.java b/common/src/main/java/me/lucko/luckperms/commands/group/subcommands/GroupUnsetInherit.java index 2fff7647..a433701f 100644 --- a/common/src/main/java/me/lucko/luckperms/commands/group/subcommands/GroupUnsetInherit.java +++ b/common/src/main/java/me/lucko/luckperms/commands/group/subcommands/GroupUnsetInherit.java @@ -29,7 +29,7 @@ import me.lucko.luckperms.commands.Sender; import me.lucko.luckperms.commands.SubCommand; import me.lucko.luckperms.constants.Message; import me.lucko.luckperms.constants.Permission; -import me.lucko.luckperms.data.LogEntryBuilder; +import me.lucko.luckperms.data.LogEntry; import me.lucko.luckperms.exceptions.ObjectLacksException; import me.lucko.luckperms.groups.Group; import me.lucko.luckperms.utils.ArgumentChecker; @@ -63,24 +63,24 @@ public class GroupUnsetInherit extends SubCommand { if (args.size() == 2) { group.unsetPermission("group." + groupName, server); Message.GROUP_UNSETINHERIT_SERVER_SUCCESS.send(sender, group.getName(), groupName, server); - LogEntryBuilder.get().actor(sender).acted(group) + LogEntry.build().actor(sender).acted(group) .action("unsetinherit " + groupName + " " + server) - .submit(plugin); + .build().submit(plugin); } else { final String world = args.get(2).toLowerCase(); group.unsetPermission("group." + groupName, server, world); Message.GROUP_UNSETINHERIT_SERVER_WORLD_SUCCESS.send(sender, group.getName(), groupName, server, world); - LogEntryBuilder.get().actor(sender).acted(group) + LogEntry.build().actor(sender).acted(group) .action("unsetinherit " + groupName + " " + server + " " + world) - .submit(plugin); + .build().submit(plugin); } } else { group.unsetPermission("group." + groupName); Message.GROUP_UNSETINHERIT_SUCCESS.send(sender, group.getName(), groupName); - LogEntryBuilder.get().actor(sender).acted(group) + LogEntry.build().actor(sender).acted(group) .action("unsetinherit " + groupName) - .submit(plugin); + .build().submit(plugin); } save(group, sender, plugin); diff --git a/common/src/main/java/me/lucko/luckperms/commands/group/subcommands/GroupUnsetTempInherit.java b/common/src/main/java/me/lucko/luckperms/commands/group/subcommands/GroupUnsetTempInherit.java index d3ff21de..841ada64 100644 --- a/common/src/main/java/me/lucko/luckperms/commands/group/subcommands/GroupUnsetTempInherit.java +++ b/common/src/main/java/me/lucko/luckperms/commands/group/subcommands/GroupUnsetTempInherit.java @@ -29,7 +29,7 @@ import me.lucko.luckperms.commands.Sender; import me.lucko.luckperms.commands.SubCommand; import me.lucko.luckperms.constants.Message; import me.lucko.luckperms.constants.Permission; -import me.lucko.luckperms.data.LogEntryBuilder; +import me.lucko.luckperms.data.LogEntry; import me.lucko.luckperms.exceptions.ObjectLacksException; import me.lucko.luckperms.groups.Group; import me.lucko.luckperms.utils.ArgumentChecker; @@ -63,24 +63,24 @@ public class GroupUnsetTempInherit extends SubCommand { if (args.size() == 2) { group.unsetPermission("group." + groupName, server, true); Message.GROUP_UNSET_TEMP_INHERIT_SERVER_SUCCESS.send(sender, group.getName(), groupName, server); - LogEntryBuilder.get().actor(sender).acted(group) + LogEntry.build().actor(sender).acted(group) .action("unsettempinherit " + groupName + " " + server) - .submit(plugin); + .build().submit(plugin); } else { final String world = args.get(2).toLowerCase(); group.unsetPermission("group." + groupName, server, world, true); Message.GROUP_UNSET_TEMP_INHERIT_SERVER_WORLD_SUCCESS.send(sender, group.getName(), groupName, server, world); - LogEntryBuilder.get().actor(sender).acted(group) + LogEntry.build().actor(sender).acted(group) .action("unsettempinherit " + groupName + " " + server + " " + world) - .submit(plugin); + .build().submit(plugin); } } else { group.unsetPermission("group." + groupName, true); Message.GROUP_UNSET_TEMP_INHERIT_SUCCESS.send(sender, group.getName(), groupName); - LogEntryBuilder.get().actor(sender).acted(group) + LogEntry.build().actor(sender).acted(group) .action("unsettempinherit " + groupName) - .submit(plugin); + .build().submit(plugin); } save(group, sender, plugin); diff --git a/common/src/main/java/me/lucko/luckperms/commands/group/subcommands/GroupUnsetTempPermission.java b/common/src/main/java/me/lucko/luckperms/commands/group/subcommands/GroupUnsetTempPermission.java index 4761b806..23e612b7 100644 --- a/common/src/main/java/me/lucko/luckperms/commands/group/subcommands/GroupUnsetTempPermission.java +++ b/common/src/main/java/me/lucko/luckperms/commands/group/subcommands/GroupUnsetTempPermission.java @@ -30,7 +30,7 @@ import me.lucko.luckperms.commands.SubCommand; import me.lucko.luckperms.constants.Message; import me.lucko.luckperms.constants.Patterns; import me.lucko.luckperms.constants.Permission; -import me.lucko.luckperms.data.LogEntryBuilder; +import me.lucko.luckperms.data.LogEntry; import me.lucko.luckperms.exceptions.ObjectLacksException; import me.lucko.luckperms.groups.Group; import me.lucko.luckperms.utils.ArgumentChecker; @@ -69,24 +69,24 @@ public class GroupUnsetTempPermission extends SubCommand { if (args.size() == 2) { group.unsetPermission(node, server); Message.UNSET_TEMP_PERMISSION_SERVER_SUCCESS.send(sender, node, group.getName(), server); - LogEntryBuilder.get().actor(sender).acted(group) + LogEntry.build().actor(sender).acted(group) .action("unsettemp " + node + " " + server) - .submit(plugin); + .build().submit(plugin); } else { final String world = args.get(2).toLowerCase(); group.unsetPermission(node, server, world); Message.UNSET_TEMP_PERMISSION_SERVER_WORLD_SUCCESS.send(sender, node, group.getName(), server, world); - LogEntryBuilder.get().actor(sender).acted(group) + LogEntry.build().actor(sender).acted(group) .action("unsettemp " + node + " " + server + " " + world) - .submit(plugin); + .build().submit(plugin); } } else { group.unsetPermission(node, true); Message.UNSET_TEMP_PERMISSION_SUCCESS.send(sender, node, group.getName()); - LogEntryBuilder.get().actor(sender).acted(group) + LogEntry.build().actor(sender).acted(group) .action("unsettemp " + node) - .submit(plugin); + .build().submit(plugin); } save(group, sender, plugin); diff --git a/common/src/main/java/me/lucko/luckperms/commands/log/LogMainCommand.java b/common/src/main/java/me/lucko/luckperms/commands/log/LogMainCommand.java index 875e9727..89bb7324 100644 --- a/common/src/main/java/me/lucko/luckperms/commands/log/LogMainCommand.java +++ b/common/src/main/java/me/lucko/luckperms/commands/log/LogMainCommand.java @@ -73,17 +73,28 @@ public class LogMainCommand extends MainCommand { @Override protected List onTabComplete(Sender sender, List args, LuckPermsPlugin plugin) { - final List> subs = getSubCommands().stream().filter(s -> s.isAuthorized(sender)).collect(Collectors.toList()); + final List> subs = getSubCommands().stream() + .filter(s -> s.isAuthorized(sender)) + .collect(Collectors.toList()); + if (args.size() <= 1) { if (args.isEmpty() || args.get(0).equalsIgnoreCase("")) { - return subs.stream().map(SubCommand::getName).map(String::toLowerCase).collect(Collectors.toList()); + return subs.stream() + .map(m -> m.getName().toLowerCase()) + .collect(Collectors.toList()); } - return subs.stream().map(SubCommand::getName).map(String::toLowerCase) - .filter(s -> s.toLowerCase().startsWith(args.get(0).toLowerCase())).collect(Collectors.toList()); + return subs.stream() + .map(m -> m.getName().toLowerCase()) + .filter(s -> s.toLowerCase().startsWith(args.get(0).toLowerCase())) + .collect(Collectors.toList()); } - Optional> o = subs.stream().filter(s -> s.getName().equalsIgnoreCase(args.get(0))).limit(1).findAny(); + Optional> o = subs.stream() + .filter(s -> s.getName().equalsIgnoreCase(args.get(0))) + .limit(1) + .findAny(); + if (!o.isPresent()) { return Collections.emptyList(); } diff --git a/common/src/main/java/me/lucko/luckperms/commands/track/CreateTrack.java b/common/src/main/java/me/lucko/luckperms/commands/track/CreateTrack.java index d8290fb8..a261edb5 100644 --- a/common/src/main/java/me/lucko/luckperms/commands/track/CreateTrack.java +++ b/common/src/main/java/me/lucko/luckperms/commands/track/CreateTrack.java @@ -28,7 +28,7 @@ import me.lucko.luckperms.commands.Sender; import me.lucko.luckperms.commands.SingleMainCommand; import me.lucko.luckperms.constants.Message; import me.lucko.luckperms.constants.Permission; -import me.lucko.luckperms.data.LogEntryBuilder; +import me.lucko.luckperms.data.LogEntry; import me.lucko.luckperms.utils.ArgumentChecker; import java.util.List; @@ -62,7 +62,7 @@ public class CreateTrack extends SingleMainCommand { } Message.CREATE_SUCCESS.send(sender, trackName); - LogEntryBuilder.get().actor(sender).actedName(trackName).type('T').action("create").submit(plugin); + LogEntry.build().actor(sender).actedName(trackName).type('T').action("create").build().submit(plugin); plugin.runUpdateTask(); return CommandResult.SUCCESS; } diff --git a/common/src/main/java/me/lucko/luckperms/commands/track/DeleteTrack.java b/common/src/main/java/me/lucko/luckperms/commands/track/DeleteTrack.java index bebc433d..b9f61760 100644 --- a/common/src/main/java/me/lucko/luckperms/commands/track/DeleteTrack.java +++ b/common/src/main/java/me/lucko/luckperms/commands/track/DeleteTrack.java @@ -28,7 +28,7 @@ import me.lucko.luckperms.commands.Sender; import me.lucko.luckperms.commands.SingleMainCommand; import me.lucko.luckperms.constants.Message; import me.lucko.luckperms.constants.Permission; -import me.lucko.luckperms.data.LogEntryBuilder; +import me.lucko.luckperms.data.LogEntry; import me.lucko.luckperms.tracks.Track; import me.lucko.luckperms.utils.ArgumentChecker; @@ -72,7 +72,7 @@ public class DeleteTrack extends SingleMainCommand { } Message.DELETE_SUCCESS.send(sender, trackName); - LogEntryBuilder.get().actor(sender).actedName(trackName).type('T').action("delete").submit(plugin); + LogEntry.build().actor(sender).actedName(trackName).type('T').action("delete").build().submit(plugin); plugin.runUpdateTask(); return CommandResult.SUCCESS; } @@ -86,7 +86,9 @@ public class DeleteTrack extends SingleMainCommand { return tracks; } - return tracks.stream().filter(s -> s.toLowerCase().startsWith(args.get(0).toLowerCase())).collect(Collectors.toList()); + return tracks.stream() + .filter(s -> s.toLowerCase().startsWith(args.get(0).toLowerCase())) + .collect(Collectors.toList()); } return Collections.emptyList(); diff --git a/common/src/main/java/me/lucko/luckperms/commands/track/subcommands/TrackAppend.java b/common/src/main/java/me/lucko/luckperms/commands/track/subcommands/TrackAppend.java index bb32c623..a5b119d5 100644 --- a/common/src/main/java/me/lucko/luckperms/commands/track/subcommands/TrackAppend.java +++ b/common/src/main/java/me/lucko/luckperms/commands/track/subcommands/TrackAppend.java @@ -26,7 +26,7 @@ import me.lucko.luckperms.LuckPermsPlugin; import me.lucko.luckperms.commands.*; import me.lucko.luckperms.constants.Message; import me.lucko.luckperms.constants.Permission; -import me.lucko.luckperms.data.LogEntryBuilder; +import me.lucko.luckperms.data.LogEntry; import me.lucko.luckperms.exceptions.ObjectAlreadyHasException; import me.lucko.luckperms.groups.Group; import me.lucko.luckperms.tracks.Track; @@ -64,9 +64,9 @@ public class TrackAppend extends SubCommand { track.appendGroup(group); Message.TRACK_APPEND_SUCCESS.send(sender, group.getName(), track.getName()); Message.EMPTY.send(sender, Util.listToArrowSep(track.getGroups(), group.getName())); - LogEntryBuilder.get().actor(sender).acted(track) + LogEntry.build().actor(sender).acted(track) .action("append " + group.getName()) - .submit(plugin); + .build().submit(plugin); save(track, sender, plugin); return CommandResult.SUCCESS; } catch (ObjectAlreadyHasException e) { diff --git a/common/src/main/java/me/lucko/luckperms/commands/track/subcommands/TrackClear.java b/common/src/main/java/me/lucko/luckperms/commands/track/subcommands/TrackClear.java index d8634c9e..d0c1ff4c 100644 --- a/common/src/main/java/me/lucko/luckperms/commands/track/subcommands/TrackClear.java +++ b/common/src/main/java/me/lucko/luckperms/commands/track/subcommands/TrackClear.java @@ -29,7 +29,7 @@ import me.lucko.luckperms.commands.Sender; import me.lucko.luckperms.commands.SubCommand; import me.lucko.luckperms.constants.Message; import me.lucko.luckperms.constants.Permission; -import me.lucko.luckperms.data.LogEntryBuilder; +import me.lucko.luckperms.data.LogEntry; import me.lucko.luckperms.tracks.Track; import java.util.List; @@ -44,7 +44,7 @@ public class TrackClear extends SubCommand { public CommandResult execute(LuckPermsPlugin plugin, Sender sender, Track track, List args, String label) { track.clearGroups(); Message.TRACK_CLEAR.send(sender, track.getName()); - LogEntryBuilder.get().actor(sender).acted(track).action("clear").submit(plugin); + LogEntry.build().actor(sender).acted(track).action("clear").build().submit(plugin); save(track, sender, plugin); return CommandResult.SUCCESS; } diff --git a/common/src/main/java/me/lucko/luckperms/commands/track/subcommands/TrackInsert.java b/common/src/main/java/me/lucko/luckperms/commands/track/subcommands/TrackInsert.java index 4243c3c5..9a772105 100644 --- a/common/src/main/java/me/lucko/luckperms/commands/track/subcommands/TrackInsert.java +++ b/common/src/main/java/me/lucko/luckperms/commands/track/subcommands/TrackInsert.java @@ -26,7 +26,7 @@ import me.lucko.luckperms.LuckPermsPlugin; import me.lucko.luckperms.commands.*; import me.lucko.luckperms.constants.Message; import me.lucko.luckperms.constants.Permission; -import me.lucko.luckperms.data.LogEntryBuilder; +import me.lucko.luckperms.data.LogEntry; import me.lucko.luckperms.exceptions.ObjectAlreadyHasException; import me.lucko.luckperms.groups.Group; import me.lucko.luckperms.tracks.Track; @@ -72,9 +72,9 @@ public class TrackInsert extends SubCommand { track.insertGroup(group, pos - 1); Message.TRACK_INSERT_SUCCESS.send(sender, group.getName(), track.getName(), pos); Message.EMPTY.send(sender, Util.listToArrowSep(track.getGroups(), group.getName())); - LogEntryBuilder.get().actor(sender).acted(track) + LogEntry.build().actor(sender).acted(track) .action("insert " + group.getName() + " " + pos) - .submit(plugin); + .build().submit(plugin); save(track, sender, plugin); return CommandResult.SUCCESS; } catch (ObjectAlreadyHasException e) { diff --git a/common/src/main/java/me/lucko/luckperms/commands/track/subcommands/TrackRemove.java b/common/src/main/java/me/lucko/luckperms/commands/track/subcommands/TrackRemove.java index a228444a..c90c9f13 100644 --- a/common/src/main/java/me/lucko/luckperms/commands/track/subcommands/TrackRemove.java +++ b/common/src/main/java/me/lucko/luckperms/commands/track/subcommands/TrackRemove.java @@ -26,7 +26,7 @@ import me.lucko.luckperms.LuckPermsPlugin; import me.lucko.luckperms.commands.*; import me.lucko.luckperms.constants.Message; import me.lucko.luckperms.constants.Permission; -import me.lucko.luckperms.data.LogEntryBuilder; +import me.lucko.luckperms.data.LogEntry; import me.lucko.luckperms.exceptions.ObjectLacksException; import me.lucko.luckperms.tracks.Track; import me.lucko.luckperms.utils.ArgumentChecker; @@ -52,9 +52,9 @@ public class TrackRemove extends SubCommand { track.removeGroup(groupName); Message.TRACK_REMOVE_SUCCESS.send(sender, groupName, track.getName()); Message.EMPTY.send(sender, Util.listToArrowSep(track.getGroups())); - LogEntryBuilder.get().actor(sender).acted(track) + LogEntry.build().actor(sender).acted(track) .action("remove " + groupName) - .submit(plugin); + .build().submit(plugin); save(track, sender, plugin); return CommandResult.SUCCESS; } catch (ObjectLacksException e) { diff --git a/common/src/main/java/me/lucko/luckperms/commands/user/subcommands/UserAddGroup.java b/common/src/main/java/me/lucko/luckperms/commands/user/subcommands/UserAddGroup.java index 3726914e..86ec1996 100644 --- a/common/src/main/java/me/lucko/luckperms/commands/user/subcommands/UserAddGroup.java +++ b/common/src/main/java/me/lucko/luckperms/commands/user/subcommands/UserAddGroup.java @@ -29,7 +29,7 @@ import me.lucko.luckperms.commands.Sender; import me.lucko.luckperms.commands.SubCommand; import me.lucko.luckperms.constants.Message; import me.lucko.luckperms.constants.Permission; -import me.lucko.luckperms.data.LogEntryBuilder; +import me.lucko.luckperms.data.LogEntry; import me.lucko.luckperms.exceptions.ObjectAlreadyHasException; import me.lucko.luckperms.groups.Group; import me.lucko.luckperms.users.User; @@ -74,24 +74,24 @@ public class UserAddGroup extends SubCommand { if (args.size() == 2) { user.addGroup(group, server); Message.USER_ADDGROUP_SERVER_SUCCESS.send(sender, user.getName(), groupName, server); - LogEntryBuilder.get().actor(sender).acted(user) + LogEntry.build().actor(sender).acted(user) .action("addgroup " + group.getName() + " " + server) - .submit(plugin); + .build().submit(plugin); } else { final String world = args.get(2).toLowerCase(); user.addGroup(group, server, world); Message.USER_ADDGROUP_SERVER_WORLD_SUCCESS.send(sender, user.getName(), groupName, server, world); - LogEntryBuilder.get().actor(sender).acted(user) + LogEntry.build().actor(sender).acted(user) .action("addgroup " + group.getName() + " " + server + " " + world) - .submit(plugin); + .build().submit(plugin); } } else { user.addGroup(group); Message.USER_ADDGROUP_SUCCESS.send(sender, user.getName(), groupName); - LogEntryBuilder.get().actor(sender).acted(user) + LogEntry.build().actor(sender).acted(user) .action("addgroup " + group.getName()) - .submit(plugin); + .build().submit(plugin); } save(user, sender, plugin); diff --git a/common/src/main/java/me/lucko/luckperms/commands/user/subcommands/UserAddTempGroup.java b/common/src/main/java/me/lucko/luckperms/commands/user/subcommands/UserAddTempGroup.java index 785cd671..25136a77 100644 --- a/common/src/main/java/me/lucko/luckperms/commands/user/subcommands/UserAddTempGroup.java +++ b/common/src/main/java/me/lucko/luckperms/commands/user/subcommands/UserAddTempGroup.java @@ -29,7 +29,7 @@ import me.lucko.luckperms.commands.Sender; import me.lucko.luckperms.commands.SubCommand; import me.lucko.luckperms.constants.Message; import me.lucko.luckperms.constants.Permission; -import me.lucko.luckperms.data.LogEntryBuilder; +import me.lucko.luckperms.data.LogEntry; import me.lucko.luckperms.exceptions.ObjectAlreadyHasException; import me.lucko.luckperms.groups.Group; import me.lucko.luckperms.users.User; @@ -90,25 +90,25 @@ public class UserAddTempGroup extends SubCommand { user.addGroup(group, server, duration); Message.USER_ADDTEMPGROUP_SERVER_SUCCESS.send(sender, user.getName(), groupName, server, DateUtil.formatDateDiff(duration)); - LogEntryBuilder.get().actor(sender).acted(user) + LogEntry.build().actor(sender).acted(user) .action("addtempgroup " + group.getName() + " " + duration + " " + server) - .submit(plugin); + .build().submit(plugin); } else { final String world = args.get(3).toLowerCase(); user.addGroup(group, server, world, duration); Message.USER_ADDTEMPGROUP_SERVER_WORLD_SUCCESS.send(sender, user.getName(), groupName, server, world, DateUtil.formatDateDiff(duration)); - LogEntryBuilder.get().actor(sender).acted(user) + LogEntry.build().actor(sender).acted(user) .action("addtempgroup " + group.getName() + " " + duration + " " + server + " " + world) - .submit(plugin); + .build().submit(plugin); } } else { user.addGroup(group, duration); Message.USER_ADDTEMPGROUP_SUCCESS.send(sender, user.getName(), groupName, DateUtil.formatDateDiff(duration)); - LogEntryBuilder.get().actor(sender).acted(user) + LogEntry.build().actor(sender).acted(user) .action("addtempgroup " + group.getName() + " " + duration) - .submit(plugin); + .build().submit(plugin); } save(user, sender, plugin); diff --git a/common/src/main/java/me/lucko/luckperms/commands/user/subcommands/UserClear.java b/common/src/main/java/me/lucko/luckperms/commands/user/subcommands/UserClear.java index 85f52936..038a70a8 100644 --- a/common/src/main/java/me/lucko/luckperms/commands/user/subcommands/UserClear.java +++ b/common/src/main/java/me/lucko/luckperms/commands/user/subcommands/UserClear.java @@ -29,7 +29,7 @@ import me.lucko.luckperms.commands.Sender; import me.lucko.luckperms.commands.SubCommand; import me.lucko.luckperms.constants.Message; import me.lucko.luckperms.constants.Permission; -import me.lucko.luckperms.data.LogEntryBuilder; +import me.lucko.luckperms.data.LogEntry; import me.lucko.luckperms.users.User; import java.util.List; @@ -45,7 +45,7 @@ public class UserClear extends SubCommand { user.clearNodes(); plugin.getUserManager().giveDefaults(user); Message.CLEAR_SUCCESS.send(sender, user.getName()); - LogEntryBuilder.get().actor(sender).acted(user).action("clear").submit(plugin); + LogEntry.build().actor(sender).acted(user).action("clear").build().submit(plugin); save(user, sender, plugin); return CommandResult.SUCCESS; diff --git a/common/src/main/java/me/lucko/luckperms/commands/user/subcommands/UserDemote.java b/common/src/main/java/me/lucko/luckperms/commands/user/subcommands/UserDemote.java index ab98fd81..f24cf716 100644 --- a/common/src/main/java/me/lucko/luckperms/commands/user/subcommands/UserDemote.java +++ b/common/src/main/java/me/lucko/luckperms/commands/user/subcommands/UserDemote.java @@ -26,7 +26,7 @@ import me.lucko.luckperms.LuckPermsPlugin; import me.lucko.luckperms.commands.*; import me.lucko.luckperms.constants.Message; import me.lucko.luckperms.constants.Permission; -import me.lucko.luckperms.data.LogEntryBuilder; +import me.lucko.luckperms.data.LogEntry; import me.lucko.luckperms.exceptions.ObjectAlreadyHasException; import me.lucko.luckperms.exceptions.ObjectLacksException; import me.lucko.luckperms.groups.Group; @@ -103,9 +103,9 @@ public class UserDemote extends SubCommand { Message.USER_DEMOTE_SUCCESS_PROMOTE.send(sender, track.getName(), old, previousGroup.getName()); Message.USER_DEMOTE_SUCCESS_REMOVE.send(sender, user.getName(), old, previousGroup.getName(), previousGroup.getName()); Message.EMPTY.send(sender, Util.listToArrowSep(track.getGroups(), previousGroup.getName(), old, true)); - LogEntryBuilder.get().actor(sender).acted(user) + LogEntry.build().actor(sender).acted(user) .action("demote " + track.getName() + "(from " + old + " to " + previousGroup.getName() + ")") - .submit(plugin); + .build().submit(plugin); save(user, sender, plugin); return CommandResult.SUCCESS; } diff --git a/common/src/main/java/me/lucko/luckperms/commands/user/subcommands/UserPromote.java b/common/src/main/java/me/lucko/luckperms/commands/user/subcommands/UserPromote.java index a8929271..1f07b68b 100644 --- a/common/src/main/java/me/lucko/luckperms/commands/user/subcommands/UserPromote.java +++ b/common/src/main/java/me/lucko/luckperms/commands/user/subcommands/UserPromote.java @@ -26,7 +26,7 @@ import me.lucko.luckperms.LuckPermsPlugin; import me.lucko.luckperms.commands.*; import me.lucko.luckperms.constants.Message; import me.lucko.luckperms.constants.Permission; -import me.lucko.luckperms.data.LogEntryBuilder; +import me.lucko.luckperms.data.LogEntry; import me.lucko.luckperms.exceptions.ObjectAlreadyHasException; import me.lucko.luckperms.exceptions.ObjectLacksException; import me.lucko.luckperms.groups.Group; @@ -103,9 +103,9 @@ public class UserPromote extends SubCommand { Message.USER_PROMOTE_SUCCESS_PROMOTE.send(sender, track.getName(), old, nextGroup.getName()); Message.USER_PROMOTE_SUCCESS_REMOVE.send(sender, user.getName(), old, nextGroup.getName(), nextGroup.getName()); Message.EMPTY.send(sender, Util.listToArrowSep(track.getGroups(), old, nextGroup.getName(), false)); - LogEntryBuilder.get().actor(sender).acted(user) + LogEntry.build().actor(sender).acted(user) .action("promote " + track.getName() + "(from " + old + " to " + nextGroup.getName() + ")") - .submit(plugin); + .build().submit(plugin); save(user, sender, plugin); return CommandResult.SUCCESS; } diff --git a/common/src/main/java/me/lucko/luckperms/commands/user/subcommands/UserRemoveGroup.java b/common/src/main/java/me/lucko/luckperms/commands/user/subcommands/UserRemoveGroup.java index 9b35f818..c38eec29 100644 --- a/common/src/main/java/me/lucko/luckperms/commands/user/subcommands/UserRemoveGroup.java +++ b/common/src/main/java/me/lucko/luckperms/commands/user/subcommands/UserRemoveGroup.java @@ -29,7 +29,7 @@ import me.lucko.luckperms.commands.Sender; import me.lucko.luckperms.commands.SubCommand; import me.lucko.luckperms.constants.Message; import me.lucko.luckperms.constants.Permission; -import me.lucko.luckperms.data.LogEntryBuilder; +import me.lucko.luckperms.data.LogEntry; import me.lucko.luckperms.exceptions.ObjectLacksException; import me.lucko.luckperms.users.User; import me.lucko.luckperms.utils.ArgumentChecker; @@ -68,24 +68,24 @@ public class UserRemoveGroup extends SubCommand { if (args.size() == 2) { user.unsetPermission("group." + groupName, server); Message.USER_REMOVEGROUP_SERVER_SUCCESS.send(sender, user.getName(), groupName, server); - LogEntryBuilder.get().actor(sender).acted(user) + LogEntry.build().actor(sender).acted(user) .action("removegroup " + groupName + " " + server) - .submit(plugin); + .build().submit(plugin); } else { final String world = args.get(2).toLowerCase(); user.unsetPermission("group." + groupName, server, world); Message.USER_REMOVEGROUP_SERVER_WORLD_SUCCESS.send(sender, user.getName(), groupName, server, world); - LogEntryBuilder.get().actor(sender).acted(user) + LogEntry.build().actor(sender).acted(user) .action("removegroup " + groupName + " " + server + " " + world) - .submit(plugin); + .build().submit(plugin); } } else { user.unsetPermission("group." + groupName); Message.USER_REMOVEGROUP_SUCCESS.send(sender, user.getName(), groupName); - LogEntryBuilder.get().actor(sender).acted(user) + LogEntry.build().actor(sender).acted(user) .action("removegroup " + groupName) - .submit(plugin); + .build().submit(plugin); } save(user, sender, plugin); diff --git a/common/src/main/java/me/lucko/luckperms/commands/user/subcommands/UserRemoveTempGroup.java b/common/src/main/java/me/lucko/luckperms/commands/user/subcommands/UserRemoveTempGroup.java index 8c239859..e0e7b876 100644 --- a/common/src/main/java/me/lucko/luckperms/commands/user/subcommands/UserRemoveTempGroup.java +++ b/common/src/main/java/me/lucko/luckperms/commands/user/subcommands/UserRemoveTempGroup.java @@ -29,7 +29,7 @@ import me.lucko.luckperms.commands.Sender; import me.lucko.luckperms.commands.SubCommand; import me.lucko.luckperms.constants.Message; import me.lucko.luckperms.constants.Permission; -import me.lucko.luckperms.data.LogEntryBuilder; +import me.lucko.luckperms.data.LogEntry; import me.lucko.luckperms.exceptions.ObjectLacksException; import me.lucko.luckperms.users.User; import me.lucko.luckperms.utils.ArgumentChecker; @@ -63,24 +63,24 @@ public class UserRemoveTempGroup extends SubCommand { if (args.size() == 2) { user.unsetPermission("group." + groupName, server, true); Message.USER_REMOVETEMPGROUP_SERVER_SUCCESS.send(sender, user.getName(), groupName, server); - LogEntryBuilder.get().actor(sender).acted(user) + LogEntry.build().actor(sender).acted(user) .action("removetempgroup " + groupName + " " + server) - .submit(plugin); + .build().submit(plugin); } else { final String world = args.get(2).toLowerCase(); user.unsetPermission("group." + groupName, server, world, true); Message.USER_REMOVETEMPGROUP_SERVER_WORLD_SUCCESS.send(sender, user.getName(), groupName, server, world); - LogEntryBuilder.get().actor(sender).acted(user) + LogEntry.build().actor(sender).acted(user) .action("removetempgroup " + groupName + " " + server + " " + world) - .submit(plugin); + .build().submit(plugin); } } else { user.unsetPermission("group." + groupName, true); Message.USER_REMOVETEMPGROUP_SUCCESS.send(sender, user.getName(), groupName); - LogEntryBuilder.get().actor(sender).acted(user) + LogEntry.build().actor(sender).acted(user) .action("removetempgroup " + groupName) - .submit(plugin); + .build().submit(plugin); } save(user, sender, plugin); diff --git a/common/src/main/java/me/lucko/luckperms/commands/user/subcommands/UserSetPermission.java b/common/src/main/java/me/lucko/luckperms/commands/user/subcommands/UserSetPermission.java index af12ddde..7a274928 100644 --- a/common/src/main/java/me/lucko/luckperms/commands/user/subcommands/UserSetPermission.java +++ b/common/src/main/java/me/lucko/luckperms/commands/user/subcommands/UserSetPermission.java @@ -30,7 +30,7 @@ import me.lucko.luckperms.commands.SubCommand; import me.lucko.luckperms.constants.Message; import me.lucko.luckperms.constants.Patterns; import me.lucko.luckperms.constants.Permission; -import me.lucko.luckperms.data.LogEntryBuilder; +import me.lucko.luckperms.data.LogEntry; import me.lucko.luckperms.exceptions.ObjectAlreadyHasException; import me.lucko.luckperms.users.User; import me.lucko.luckperms.utils.ArgumentChecker; @@ -77,24 +77,24 @@ public class UserSetPermission extends SubCommand { if (args.size() == 3) { user.setPermission(node, b, server); Message.SETPERMISSION_SERVER_SUCCESS.send(sender, node, bool, user.getName(), server); - LogEntryBuilder.get().actor(sender).acted(user) + LogEntry.build().actor(sender).acted(user) .action("set " + node + " " + b + " " + server) - .submit(plugin); + .build().submit(plugin); } else { final String world = args.get(3).toLowerCase(); user.setPermission(node, b, server, world); Message.SETPERMISSION_SERVER_WORLD_SUCCESS.send(sender, node, bool, user.getName(), server, world); - LogEntryBuilder.get().actor(sender).acted(user) + LogEntry.build().actor(sender).acted(user) .action("set " + node + " " + b + " " + server + " " + world) - .submit(plugin); + .build().submit(plugin); } } else { user.setPermission(node, b); Message.SETPERMISSION_SUCCESS.send(sender, node, bool, user.getName()); - LogEntryBuilder.get().actor(sender).acted(user) + LogEntry.build().actor(sender).acted(user) .action("set " + node + " " + b) - .submit(plugin); + .build().submit(plugin); } save(user, sender, plugin); diff --git a/common/src/main/java/me/lucko/luckperms/commands/user/subcommands/UserSetPrimaryGroup.java b/common/src/main/java/me/lucko/luckperms/commands/user/subcommands/UserSetPrimaryGroup.java index 742fcfe1..ff0168ba 100644 --- a/common/src/main/java/me/lucko/luckperms/commands/user/subcommands/UserSetPrimaryGroup.java +++ b/common/src/main/java/me/lucko/luckperms/commands/user/subcommands/UserSetPrimaryGroup.java @@ -29,7 +29,7 @@ import me.lucko.luckperms.commands.Sender; import me.lucko.luckperms.commands.SubCommand; import me.lucko.luckperms.constants.Message; import me.lucko.luckperms.constants.Permission; -import me.lucko.luckperms.data.LogEntryBuilder; +import me.lucko.luckperms.data.LogEntry; import me.lucko.luckperms.groups.Group; import me.lucko.luckperms.users.User; @@ -61,9 +61,9 @@ public class UserSetPrimaryGroup extends SubCommand { user.setPrimaryGroup(group.getName()); Message.USER_PRIMARYGROUP_SUCCESS.send(sender, user.getName(), group.getName()); - LogEntryBuilder.get().actor(sender).acted(user) + LogEntry.build().actor(sender).acted(user) .action("setprimarygroup " + group.getName()) - .submit(plugin); + .build().submit(plugin); save(user, sender, plugin); return CommandResult.SUCCESS; diff --git a/common/src/main/java/me/lucko/luckperms/commands/user/subcommands/UserSetTempPermission.java b/common/src/main/java/me/lucko/luckperms/commands/user/subcommands/UserSetTempPermission.java index f3c580a3..6364da96 100644 --- a/common/src/main/java/me/lucko/luckperms/commands/user/subcommands/UserSetTempPermission.java +++ b/common/src/main/java/me/lucko/luckperms/commands/user/subcommands/UserSetTempPermission.java @@ -30,7 +30,7 @@ import me.lucko.luckperms.commands.SubCommand; import me.lucko.luckperms.constants.Message; import me.lucko.luckperms.constants.Patterns; import me.lucko.luckperms.constants.Permission; -import me.lucko.luckperms.data.LogEntryBuilder; +import me.lucko.luckperms.data.LogEntry; import me.lucko.luckperms.exceptions.ObjectAlreadyHasException; import me.lucko.luckperms.users.User; import me.lucko.luckperms.utils.ArgumentChecker; @@ -91,24 +91,24 @@ public class UserSetTempPermission extends SubCommand { if (args.size() == 4) { user.setPermission(node, b, server, duration); Message.SETPERMISSION_TEMP_SERVER_SUCCESS.send(sender, node, bool, user.getName(), server, DateUtil.formatDateDiff(duration)); - LogEntryBuilder.get().actor(sender).acted(user) + LogEntry.build().actor(sender).acted(user) .action("settemp " + node + " " + b + " " + duration + " " + server) - .submit(plugin); + .build().submit(plugin); } else { final String world = args.get(4).toLowerCase(); user.setPermission(node, b, server, world, duration); Message.SETPERMISSION_TEMP_SERVER_WORLD_SUCCESS.send(sender, node, bool, user.getName(), server, world, DateUtil.formatDateDiff(duration)); - LogEntryBuilder.get().actor(sender).acted(user) + LogEntry.build().actor(sender).acted(user) .action("settemp " + node + " " + b + " " + duration + " " + server + " " + world) - .submit(plugin); + .build().submit(plugin); } } else { user.setPermission(node, b, duration); Message.SETPERMISSION_TEMP_SUCCESS.send(sender, node, bool, user.getName(), DateUtil.formatDateDiff(duration)); - LogEntryBuilder.get().actor(sender).acted(user) + LogEntry.build().actor(sender).acted(user) .action("settemp " + node + " " + b + " " + duration) - .submit(plugin); + .build().submit(plugin); } save(user, sender, plugin); diff --git a/common/src/main/java/me/lucko/luckperms/commands/user/subcommands/UserUnSetPermission.java b/common/src/main/java/me/lucko/luckperms/commands/user/subcommands/UserUnSetPermission.java index a9125d68..7bd10d7a 100644 --- a/common/src/main/java/me/lucko/luckperms/commands/user/subcommands/UserUnSetPermission.java +++ b/common/src/main/java/me/lucko/luckperms/commands/user/subcommands/UserUnSetPermission.java @@ -30,7 +30,7 @@ import me.lucko.luckperms.commands.SubCommand; import me.lucko.luckperms.constants.Message; import me.lucko.luckperms.constants.Patterns; import me.lucko.luckperms.constants.Permission; -import me.lucko.luckperms.data.LogEntryBuilder; +import me.lucko.luckperms.data.LogEntry; import me.lucko.luckperms.exceptions.ObjectLacksException; import me.lucko.luckperms.users.User; import me.lucko.luckperms.utils.ArgumentChecker; @@ -68,24 +68,24 @@ public class UserUnSetPermission extends SubCommand { if (args.size() == 2) { user.unsetPermission(node, server); Message.UNSETPERMISSION_SERVER_SUCCESS.send(sender, node, user.getName(), server); - LogEntryBuilder.get().actor(sender).acted(user) + LogEntry.build().actor(sender).acted(user) .action("unset " + node + " " + server) - .submit(plugin); + .build().submit(plugin); } else { final String world = args.get(2).toLowerCase(); user.unsetPermission(node, server, world); Message.UNSETPERMISSION_SERVER_WORLD_SUCCESS.send(sender, node, user.getName(), server, world); - LogEntryBuilder.get().actor(sender).acted(user) + LogEntry.build().actor(sender).acted(user) .action("unset " + node + " " + server + " " + world) - .submit(plugin); + .build().submit(plugin); } } else { user.unsetPermission(node); Message.UNSETPERMISSION_SUCCESS.send(sender, node, user.getName()); - LogEntryBuilder.get().actor(sender).acted(user) + LogEntry.build().actor(sender).acted(user) .action("unset " + node) - .submit(plugin); + .build().submit(plugin); } save(user, sender, plugin); diff --git a/common/src/main/java/me/lucko/luckperms/commands/user/subcommands/UserUnsetTempPermission.java b/common/src/main/java/me/lucko/luckperms/commands/user/subcommands/UserUnsetTempPermission.java index 2e5bc4ff..fd1f046b 100644 --- a/common/src/main/java/me/lucko/luckperms/commands/user/subcommands/UserUnsetTempPermission.java +++ b/common/src/main/java/me/lucko/luckperms/commands/user/subcommands/UserUnsetTempPermission.java @@ -30,7 +30,7 @@ import me.lucko.luckperms.commands.SubCommand; import me.lucko.luckperms.constants.Message; import me.lucko.luckperms.constants.Patterns; import me.lucko.luckperms.constants.Permission; -import me.lucko.luckperms.data.LogEntryBuilder; +import me.lucko.luckperms.data.LogEntry; import me.lucko.luckperms.exceptions.ObjectLacksException; import me.lucko.luckperms.users.User; import me.lucko.luckperms.utils.ArgumentChecker; @@ -69,24 +69,24 @@ public class UserUnsetTempPermission extends SubCommand { if (args.size() == 2) { user.unsetPermission(node, server, true); Message.UNSET_TEMP_PERMISSION_SERVER_SUCCESS.send(sender, node, user.getName(), server); - LogEntryBuilder.get().actor(sender).acted(user) + LogEntry.build().actor(sender).acted(user) .action("unsettemp " + node + " " + server) - .submit(plugin); + .build().submit(plugin); } else { final String world = args.get(2).toLowerCase(); user.unsetPermission(node, server, world, true); Message.UNSET_TEMP_PERMISSION_SERVER_WORLD_SUCCESS.send(sender, node, user.getName(), server, world); - LogEntryBuilder.get().actor(sender).acted(user) + LogEntry.build().actor(sender).acted(user) .action("unsettemp " + node + " " + server + " " + world) - .submit(plugin); + .build().submit(plugin); } } else { user.unsetPermission(node, true); Message.UNSET_TEMP_PERMISSION_SUCCESS.send(sender, node, user.getName()); - LogEntryBuilder.get().actor(sender).acted(user) + LogEntry.build().actor(sender).acted(user) .action("unsettemp " + node) - .submit(plugin); + .build().submit(plugin); } save(user, sender, plugin); diff --git a/common/src/main/java/me/lucko/luckperms/core/PermissionHolder.java b/common/src/main/java/me/lucko/luckperms/core/PermissionHolder.java index a66e9b74..4888b6b3 100644 --- a/common/src/main/java/me/lucko/luckperms/core/PermissionHolder.java +++ b/common/src/main/java/me/lucko/luckperms/core/PermissionHolder.java @@ -331,7 +331,8 @@ public abstract class PermissionHolder { if (temporary) { match = this.nodes.keySet().stream() - .filter(n -> n.contains("$")).filter(n -> Patterns.TEMP_DELIMITER.split(n)[0].equalsIgnoreCase(fNode)) + .filter(n -> n.contains("$")) + .filter(n -> Patterns.TEMP_DELIMITER.split(n)[0].equalsIgnoreCase(fNode)) .findFirst(); } else { if (this.nodes.containsKey(fNode)) { diff --git a/common/src/main/java/me/lucko/luckperms/core/UuidCache.java b/common/src/main/java/me/lucko/luckperms/core/UuidCache.java index 94c044bb..8af279f1 100644 --- a/common/src/main/java/me/lucko/luckperms/core/UuidCache.java +++ b/common/src/main/java/me/lucko/luckperms/core/UuidCache.java @@ -55,7 +55,11 @@ public class UuidCache { public UUID getExternalUUID(UUID internal) { if (onlineMode) return internal; - Optional external = cache.entrySet().stream().filter(e -> e.getValue().equals(internal)).map(Map.Entry::getKey).findFirst(); + Optional external = cache.entrySet().stream() + .filter(e -> e.getValue().equals(internal)) + .map(Map.Entry::getKey) + .findFirst(); + return external.isPresent() ? external.get() : internal; } diff --git a/common/src/main/java/me/lucko/luckperms/data/LogEntry.java b/common/src/main/java/me/lucko/luckperms/data/LogEntry.java new file mode 100644 index 00000000..5c635b5a --- /dev/null +++ b/common/src/main/java/me/lucko/luckperms/data/LogEntry.java @@ -0,0 +1,118 @@ +/* + * Copyright (c) 2016 Lucko (Luck) + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +package me.lucko.luckperms.data; + +import me.lucko.luckperms.LuckPermsPlugin; +import me.lucko.luckperms.api.data.Callback; +import me.lucko.luckperms.commands.Sender; +import me.lucko.luckperms.constants.Message; +import me.lucko.luckperms.constants.Permission; +import me.lucko.luckperms.core.PermissionHolder; +import me.lucko.luckperms.groups.Group; +import me.lucko.luckperms.tracks.Track; +import me.lucko.luckperms.users.User; + +public class LogEntry extends me.lucko.luckperms.api.LogEntry { + public static LogEntryBuilder build() { + return new LogEntryBuilder(); + } + + private LogEntry() { + super(); + } + + public void submit(LuckPermsPlugin plugin) { + plugin.getDatastore().logAction(this, Callback.empty()); + + final String msg = super.getFormatted(); + + plugin.getSenders().stream() + .filter(Permission.LOG_NOTIFY::isAuthorized) + .filter(s -> !plugin.getIgnoringLogs().contains(s.getUuid())) + .forEach(s -> Message.LOG.send(s, msg)); + } + + public static class LogEntryBuilder extends AbstractLogEntryBuilder { + + @Override + protected LogEntry createObj() { + return new LogEntry(); + } + + @Override + protected LogEntryBuilder getThis() { + return this; + } + + public LogEntryBuilder actor(Sender actor) { + super.actorName(actor.getName()); + super.actor(actor.getUuid()); + return this; + } + + public LogEntryBuilder type(String type) { + super.type(type.toCharArray()[0]); + return this; + } + + public LogEntryBuilder type(Object object) { + if (object instanceof User) { + super.type('U'); + } else if (object instanceof Group) { + super.type('G'); + } else if (object instanceof Track) { + super.type('T'); + } else { + throw new IllegalArgumentException(); + } + return this; + } + + public LogEntryBuilder acted(PermissionHolder acted) { + if (acted instanceof User) { + super.actedName(((User) acted).getName()); + super.acted(((User) acted).getUuid()); + super.type('U'); + } else if (acted instanceof Group) { + super.actedName(((Group) acted).getName()); + super.type('G'); + } + return this; + } + + public LogEntryBuilder acted(Track track) { + super.actedName(track.getName()); + super.type('T'); + return this; + } + + @Override + public LogEntry build() { + if (getTimestamp() == 0L) { + super.timestamp(System.currentTimeMillis() / 1000L); + } + + return super.build(); + } + } +} diff --git a/common/src/main/java/me/lucko/luckperms/data/LogEntryBuilder.java b/common/src/main/java/me/lucko/luckperms/data/LogEntryBuilder.java deleted file mode 100644 index 1d92c027..00000000 --- a/common/src/main/java/me/lucko/luckperms/data/LogEntryBuilder.java +++ /dev/null @@ -1,173 +0,0 @@ -/* - * Copyright (c) 2016 Lucko (Luck) - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -package me.lucko.luckperms.data; - -import me.lucko.luckperms.LuckPermsPlugin; -import me.lucko.luckperms.api.LogEntry; -import me.lucko.luckperms.api.data.Callback; -import me.lucko.luckperms.commands.Sender; -import me.lucko.luckperms.constants.Message; -import me.lucko.luckperms.constants.Permission; -import me.lucko.luckperms.core.PermissionHolder; -import me.lucko.luckperms.groups.Group; -import me.lucko.luckperms.tracks.Track; -import me.lucko.luckperms.users.User; - -import java.util.HashSet; -import java.util.Set; -import java.util.UUID; - -public class LogEntryBuilder { - private long timestamp = 0L; - private UUID actor = null; - private String actorName = null; - private char type = Character.MIN_VALUE; - private UUID acted = null; - private String actedName = null; - private String action = null; - - public static LogEntryBuilder get() { - return new LogEntryBuilder(); - } - - public LogEntryBuilder timestamp(long timestamp) { - this.timestamp = timestamp; - return this; - } - - public LogEntryBuilder actor(UUID actor) { - this.actor = actor; - return this; - } - - public LogEntryBuilder actorName(String actorName) { - this.actorName = actorName; - return this; - } - - public LogEntryBuilder actor(Sender actor) { - this.actorName = actor.getName(); - this.actor = actor.getUuid(); - return this; - } - - public LogEntryBuilder type(char type) { - this.type = type; - return this; - } - - public LogEntryBuilder type(String type) { - this.type = type.toCharArray()[0]; - return this; - } - - public LogEntryBuilder type(Object object) { - if (object instanceof User) { - this.type = 'U'; - } else if (object instanceof Group) { - this.type = 'G'; - } else if (object instanceof Track) { - this.type = 'T'; - } else { - throw new IllegalArgumentException(); - } - return this; - } - - public LogEntryBuilder acted(UUID acted) { - this.acted = acted; - return this; - } - - public LogEntryBuilder actedName(String actedName) { - this.actedName = actedName; - return this; - } - - public LogEntryBuilder acted(PermissionHolder acted) { - if (acted instanceof User) { - this.actedName = ((User) acted).getName(); - this.acted = ((User) acted).getUuid(); - this.type = 'U'; - } else if (acted instanceof Group) { - this.actedName = ((Group) acted).getName(); - this.type = 'G'; - } - return this; - } - - public LogEntryBuilder acted(Track track) { - this.actedName = track.getName(); - this.type = 'T'; - return this; - } - - public LogEntryBuilder action(String action) { - this.action = action; - return this; - } - - private Set getEmpty() { - Set s = new HashSet<>(); - if (actor == null) { - s.add("actor"); - } - if (actorName == null) { - s.add("actorname"); - } - if (type == Character.MIN_VALUE) { - s.add("type"); - } - if (actedName == null) { - s.add("actedname"); - } - if (action == null) { - s.add("action"); - } - return s; - } - - public void submit(LuckPermsPlugin plugin) { - final LogEntry entry = build(); - plugin.getDatastore().logAction(entry, Callback.empty()); - - final String msg = entry.getFormatted(); - - plugin.getSenders().stream() - .filter(Permission.LOG_NOTIFY::isAuthorized) - .filter(s -> !plugin.getIgnoringLogs().contains(s.getUuid())) - .forEach(s -> Message.LOG.send(s, msg)); - } - - public LogEntry build() { - if (timestamp == 0L) { - timestamp = System.currentTimeMillis() / 1000; - } - - if (!getEmpty().isEmpty()) { - throw new IllegalStateException("Missing values: " + getEmpty().toString()); - } - - return new LogEntry(timestamp, actor, actorName, type, acted, actedName, action); - } -} diff --git a/common/src/main/java/me/lucko/luckperms/groups/Group.java b/common/src/main/java/me/lucko/luckperms/groups/Group.java index d2cfc1e0..48b82485 100644 --- a/common/src/main/java/me/lucko/luckperms/groups/Group.java +++ b/common/src/main/java/me/lucko/luckperms/groups/Group.java @@ -51,6 +51,11 @@ public class Group extends PermissionHolder implements Identifiable { this.name = name; } + @Override + public String getId() { + return name; + } + /** * check to see if a group inherits a group * @param group The group to check membership of @@ -309,9 +314,4 @@ public class Group extends PermissionHolder implements Identifiable { .map(s -> Patterns.DOT.split(s, 2)[1]) .collect(Collectors.toList()); } - - @Override - public String getId() { - return name; - } } diff --git a/common/src/main/java/me/lucko/luckperms/runnables/UpdateTask.java b/common/src/main/java/me/lucko/luckperms/runnables/UpdateTask.java index 4b924759..51539f80 100644 --- a/common/src/main/java/me/lucko/luckperms/runnables/UpdateTask.java +++ b/common/src/main/java/me/lucko/luckperms/runnables/UpdateTask.java @@ -31,14 +31,14 @@ public class UpdateTask implements Runnable { @Override public void run() { - // Reload all of the groups + // Reload all groups plugin.getDatastore().loadAllGroups(); String defaultGroup = plugin.getConfiguration().getDefaultGroupName(); if (!plugin.getGroupManager().isLoaded(defaultGroup)) { plugin.getDatastore().createAndLoadGroup(defaultGroup); } - // Reload all of the tracks + // Reload all tracks plugin.getDatastore().loadAllTracks(); // Refresh all online users. diff --git a/common/src/main/java/me/lucko/luckperms/storage/methods/FlatfileDatastore.java b/common/src/main/java/me/lucko/luckperms/storage/methods/FlatfileDatastore.java index 8427be67..926084af 100644 --- a/common/src/main/java/me/lucko/luckperms/storage/methods/FlatfileDatastore.java +++ b/common/src/main/java/me/lucko/luckperms/storage/methods/FlatfileDatastore.java @@ -385,7 +385,9 @@ public class FlatfileDatastore extends Datastore { public boolean loadAllGroups() { String[] fileNames = groupsDir.list((dir, name) -> name.endsWith(".json")); if (fileNames == null) return false; - List groups = Arrays.stream(fileNames).map(s -> s.substring(0, s.length() - 5)).collect(Collectors.toList()); + List groups = Arrays.stream(fileNames) + .map(s -> s.substring(0, s.length() - 5)) + .collect(Collectors.toList()); plugin.getGroupManager().unloadAll(); groups.forEach(this::loadGroup); @@ -511,7 +513,9 @@ public class FlatfileDatastore extends Datastore { public boolean loadAllTracks() { String[] fileNames = tracksDir.list((dir, name) -> name.endsWith(".json")); if (fileNames == null) return false; - List tracks = Arrays.stream(fileNames).map(s -> s.substring(0, s.length() - 5)).collect(Collectors.toList()); + List tracks = Arrays.stream(fileNames) + .map(s -> s.substring(0, s.length() - 5)) + .collect(Collectors.toList()); plugin.getTrackManager().unloadAll(); tracks.forEach(this::loadTrack); diff --git a/common/src/main/java/me/lucko/luckperms/storage/methods/MySQLDatastore.java b/common/src/main/java/me/lucko/luckperms/storage/methods/MySQLDatastore.java index 7c527959..37bc18fb 100644 --- a/common/src/main/java/me/lucko/luckperms/storage/methods/MySQLDatastore.java +++ b/common/src/main/java/me/lucko/luckperms/storage/methods/MySQLDatastore.java @@ -66,7 +66,7 @@ public class MySQLDatastore extends SQLDatastore { hikari.addDataSourceProperty("password", password); if (!setupTables(CREATETABLE_UUID, CREATETABLE_USERS, CREATETABLE_GROUPS, CREATETABLE_TRACKS, CREATETABLE_ACTION)) { - plugin.getLog().severe("Error occurred whilst initialising the database. All connections are disallowed."); + plugin.getLog().severe("Error occurred whilst initialising the database."); shutdown(); } else { setAcceptingLogins(true); diff --git a/common/src/main/java/me/lucko/luckperms/storage/methods/SQLiteDatastore.java b/common/src/main/java/me/lucko/luckperms/storage/methods/SQLiteDatastore.java index 1642ebc7..f3f543ff 100644 --- a/common/src/main/java/me/lucko/luckperms/storage/methods/SQLiteDatastore.java +++ b/common/src/main/java/me/lucko/luckperms/storage/methods/SQLiteDatastore.java @@ -47,7 +47,7 @@ public class SQLiteDatastore extends SQLDatastore { @Override public void init() { if (!setupTables(CREATETABLE_UUID, CREATETABLE_USERS, CREATETABLE_GROUPS, CREATETABLE_TRACKS, CREATETABLE_ACTION)) { - plugin.getLog().severe("Error occurred whilst initialising the database. All connections are disallowed."); + plugin.getLog().severe("Error occurred whilst initialising the database."); shutdown(); } else { setAcceptingLogins(true); diff --git a/common/src/main/java/me/lucko/luckperms/tracks/Track.java b/common/src/main/java/me/lucko/luckperms/tracks/Track.java index f167cb93..92517c13 100644 --- a/common/src/main/java/me/lucko/luckperms/tracks/Track.java +++ b/common/src/main/java/me/lucko/luckperms/tracks/Track.java @@ -51,6 +51,11 @@ public class Track implements Identifiable { */ private List groups = Collections.synchronizedList(new ArrayList<>()); + @Override + public String getId() { + return name; + } + /** * Gets an ordered list of the groups on this track * @return am ordered {@link List} of the groups on this track @@ -201,9 +206,4 @@ public class Track implements Identifiable { throw new ObjectLacksException(); } } - - @Override - public String getId() { - return name; - } } diff --git a/common/src/main/java/me/lucko/luckperms/tracks/TrackManager.java b/common/src/main/java/me/lucko/luckperms/tracks/TrackManager.java index 525a98d5..5c118c57 100644 --- a/common/src/main/java/me/lucko/luckperms/tracks/TrackManager.java +++ b/common/src/main/java/me/lucko/luckperms/tracks/TrackManager.java @@ -35,7 +35,9 @@ public class TrackManager extends AbstractManager { * @return a set of tracks that the groups could be a member of */ public Set getApplicableTracks(String group) { - return objects.values().stream().filter(t -> t.containsGroup(group)).collect(Collectors.toSet()); + return objects.values().stream() + .filter(t -> t.containsGroup(group)) + .collect(Collectors.toSet()); } @Override diff --git a/common/src/main/java/me/lucko/luckperms/users/User.java b/common/src/main/java/me/lucko/luckperms/users/User.java index 5fd8c4ee..8b707dd4 100644 --- a/common/src/main/java/me/lucko/luckperms/users/User.java +++ b/common/src/main/java/me/lucko/luckperms/users/User.java @@ -75,6 +75,11 @@ public abstract class User extends PermissionHolder implements Identifiable Patterns.DOT.split(s, 2)[1]) .collect(Collectors.toList()); } - - @Override - public UUID getId() { - return uuid; - } } diff --git a/common/src/main/java/me/lucko/luckperms/users/UserManager.java b/common/src/main/java/me/lucko/luckperms/users/UserManager.java index a7031a67..57d6ebda 100644 --- a/common/src/main/java/me/lucko/luckperms/users/UserManager.java +++ b/common/src/main/java/me/lucko/luckperms/users/UserManager.java @@ -43,7 +43,9 @@ public abstract class UserManager extends AbstractManager { @SuppressWarnings("OptionalGetWithoutIsPresent") public User get(String name) { try { - return objects.values().stream().filter(u -> u.getName().equalsIgnoreCase(name)).limit(1).findAny().get(); + return objects.values().stream() + .filter(u -> u.getName().equalsIgnoreCase(name)) + .limit(1).findAny().get(); } catch (NoSuchElementException e) { return null; } diff --git a/sponge/src/main/java/me/lucko/luckperms/SpongeListener.java b/sponge/src/main/java/me/lucko/luckperms/SpongeListener.java index 3cdee7f9..361f432a 100644 --- a/sponge/src/main/java/me/lucko/luckperms/SpongeListener.java +++ b/sponge/src/main/java/me/lucko/luckperms/SpongeListener.java @@ -45,8 +45,8 @@ public class SpongeListener extends AbstractListener { @Listener public void onClientAuth(ClientConnectionEvent.Auth e) { if (!plugin.getDatastore().isAcceptingLogins()) { - // Datastore is disabled, prevent players from joining the server - // Just don't load their data, they will be kicked at login + /* Datastore is disabled, prevent players from joining the server + Just don't load their data, they will be kicked at login */ return; } diff --git a/sponge/src/main/java/me/lucko/luckperms/users/SpongeUser.java b/sponge/src/main/java/me/lucko/luckperms/users/SpongeUser.java index a5fbecd4..50ae9d83 100644 --- a/sponge/src/main/java/me/lucko/luckperms/users/SpongeUser.java +++ b/sponge/src/main/java/me/lucko/luckperms/users/SpongeUser.java @@ -26,7 +26,7 @@ import me.lucko.luckperms.LPSpongePlugin; import org.spongepowered.api.entity.living.player.Player; import org.spongepowered.api.util.Tristate; -import java.util.HashSet; +import java.util.Collections; import java.util.Map; import java.util.Optional; import java.util.UUID; @@ -58,6 +58,6 @@ class SpongeUser extends User { // Re-add all defined permissions for the user final String world = player.getWorld().getName(); Map local = getLocalPermissions(getPlugin().getConfiguration().getServer(), world, null); - local.entrySet().forEach(e -> player.getSubjectData().setPermission(new HashSet<>(), e.getKey(), Tristate.fromBoolean(e.getValue()))); + local.entrySet().forEach(e -> player.getSubjectData().setPermission(Collections.emptySet(), e.getKey(), Tristate.fromBoolean(e.getValue()))); } } diff --git a/sponge/src/main/java/me/lucko/luckperms/utils/VersionUtil.java b/sponge/src/main/java/me/lucko/luckperms/utils/VersionUtil.java index aa1bf4d1..fe42ef2b 100644 --- a/sponge/src/main/java/me/lucko/luckperms/utils/VersionUtil.java +++ b/sponge/src/main/java/me/lucko/luckperms/utils/VersionUtil.java @@ -60,7 +60,7 @@ public class VersionUtil extends ClassTransformer { } @Override - public void configure(final Properties properties) { + public void configure(Properties properties) { assert properties != null; version = properties.getProperty("version"); }