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 6b43cd56..1ac044ff 100644 --- a/api/src/main/java/me/lucko/luckperms/api/LogEntry.java +++ b/api/src/main/java/me/lucko/luckperms/api/LogEntry.java @@ -33,6 +33,8 @@ import javax.annotation.Nullable; /** * Represents a logged action. + * + * @see LuckPermsApi#newLogEntryBuilder() for creating an instance */ public interface LogEntry extends Comparable { @@ -50,6 +52,7 @@ public interface LogEntry extends Comparable { * * @return the actor id */ + @Nonnull UUID getActor(); /** @@ -57,6 +60,7 @@ public interface LogEntry extends Comparable { * * @return the name of the actor */ + @Nonnull String getActorName(); /** @@ -64,6 +68,7 @@ public interface LogEntry extends Comparable { * * @return the action type */ + @Nonnull Type getType(); /** @@ -73,6 +78,7 @@ public interface LogEntry extends Comparable { * * @return the uuid of acted object */ + @Nonnull Optional getActed(); /** @@ -80,6 +86,7 @@ public interface LogEntry extends Comparable { * * @return the name of the acted object */ + @Nonnull String getActedName(); /** @@ -90,6 +97,7 @@ public interface LogEntry extends Comparable { * * @return the action */ + @Nonnull String getAction(); /** @@ -112,6 +120,7 @@ public interface LogEntry extends Comparable { return this.code; } + @Nonnull public static Type valueOf(char code) { switch (code) { case 'U': diff --git a/api/src/main/java/me/lucko/luckperms/api/LuckPermsApi.java b/api/src/main/java/me/lucko/luckperms/api/LuckPermsApi.java index 4deb10c2..1dd91b4e 100644 --- a/api/src/main/java/me/lucko/luckperms/api/LuckPermsApi.java +++ b/api/src/main/java/me/lucko/luckperms/api/LuckPermsApi.java @@ -349,6 +349,7 @@ public interface LuckPermsApi { * @return a new builder * @since 4.0 */ + @Nonnull LogEntry.Builder newLogEntryBuilder(); /** diff --git a/bukkit/src/main/java/me/lucko/luckperms/bukkit/model/LPPermissible.java b/bukkit/src/main/java/me/lucko/luckperms/bukkit/model/LPPermissible.java index 652a59f3..9c507651 100644 --- a/bukkit/src/main/java/me/lucko/luckperms/bukkit/model/LPPermissible.java +++ b/bukkit/src/main/java/me/lucko/luckperms/bukkit/model/LPPermissible.java @@ -45,10 +45,10 @@ import org.bukkit.plugin.Plugin; import java.util.Collection; import java.util.HashSet; +import java.util.Map; import java.util.Set; import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.atomic.AtomicBoolean; -import java.util.stream.Collectors; /** * PermissibleBase for LuckPerms. @@ -162,13 +162,14 @@ public class LPPermissible extends PermissibleBase { @Override public Set getEffectivePermissions() { - Set perms = new HashSet<>(); - perms.addAll( - user.getCachedData().getPermissionData(calculateContexts()).getImmutableBacking().entrySet().stream() - .map(e -> new PermissionAttachmentInfo(player, e.getKey(), null, e.getValue())) - .collect(Collectors.toList()) - ); - return perms; + Set> permissions = user.getCachedData().getPermissionData(calculateContexts()).getImmutableBacking().entrySet(); + Set ret = new HashSet<>(permissions.size()); + + for (Map.Entry entry : permissions) { + ret.add(new PermissionAttachmentInfo(player, entry.getKey(), null, entry.getValue())); + } + + return ret; } @Override diff --git a/common/src/main/java/me/lucko/luckperms/common/actionlog/ExtendedLogEntry.java b/common/src/main/java/me/lucko/luckperms/common/actionlog/ExtendedLogEntry.java index 35aa7177..6d650c7b 100644 --- a/common/src/main/java/me/lucko/luckperms/common/actionlog/ExtendedLogEntry.java +++ b/common/src/main/java/me/lucko/luckperms/common/actionlog/ExtendedLogEntry.java @@ -72,10 +72,7 @@ public class ExtendedLogEntry implements LogEntry { .thenComparing(LogEntry::getActor) .thenComparing(LogEntry::getActorName, String.CASE_INSENSITIVE_ORDER) .thenComparing(LogEntry::getType) - .thenComparing(e -> { - UUID u = e.getActed().orElse(null); - return u == null ? "" : u.toString(); - }) + .thenComparing(e -> e.getActed().map(UUID::toString).orElse("")) .thenComparing(LogEntry::getActedName, String.CASE_INSENSITIVE_ORDER) .thenComparing(LogEntry::getAction); @@ -187,7 +184,7 @@ public class ExtendedLogEntry implements LogEntry { this.getActor().equals(other.getActor()) && this.getActorName().equals(other.getActorName()) && this.getType() == other.getType() && - (this.getActed() == null ? other.getActed() == null : this.getActed().equals(other.getActed())) && + this.getActed().equals(other.getActed()) && this.getActedName().equals(other.getActedName()) && this.getAction().equals(other.getAction()); } @@ -200,7 +197,7 @@ public class ExtendedLogEntry implements LogEntry { result = result * PRIME + this.getActor().hashCode(); result = result * PRIME + this.getActorName().hashCode(); result = result * PRIME + this.getType().hashCode(); - result = result * PRIME + (this.getActed() == null ? 43 : this.getActed().hashCode()); + result = result * PRIME + this.getActed().hashCode(); result = result * PRIME + this.getActedName().hashCode(); result = result * PRIME + this.getAction().hashCode(); return result; @@ -365,8 +362,8 @@ public class ExtendedLogEntry implements LogEntry { data.add("actor", new JsonPrimitive(entry.getActor().toString())); data.add("actorName", new JsonPrimitive(entry.getActorName())); data.add("type", new JsonPrimitive(entry.getType().name())); - if (entry.getActed() != null) { - data.add("acted", new JsonPrimitive(entry.getActed().toString())); + if (entry.getActed().isPresent()) { + data.add("acted", new JsonPrimitive(entry.getActed().get().toString())); } data.add("actedName", new JsonPrimitive(entry.getActedName())); data.add("action", new JsonPrimitive(entry.getAction())); diff --git a/common/src/main/java/me/lucko/luckperms/common/actionlog/Log.java b/common/src/main/java/me/lucko/luckperms/common/actionlog/Log.java index ca36d9b3..ec871f43 100644 --- a/common/src/main/java/me/lucko/luckperms/common/actionlog/Log.java +++ b/common/src/main/java/me/lucko/luckperms/common/actionlog/Log.java @@ -120,8 +120,8 @@ public class Log { public SortedSet getUserHistory(UUID uuid) { return content.stream() .filter(e -> e.getType() == LogEntry.Type.USER) - .filter(e -> e.getActed() != null) - .filter(e -> e.getActed().equals(uuid)) + .filter(e -> e.getActed().isPresent()) + .filter(e -> e.getActed().get().equals(uuid)) .collect(Collectors.toCollection(TreeSet::new)); } @@ -132,8 +132,8 @@ public class Log { public int getUserHistoryMaxPages(UUID uuid) { return getMaxPages(content.stream() .filter(e -> e.getType() == LogEntry.Type.USER) - .filter(e -> e.getActed() != null) - .filter(e -> e.getActed().equals(uuid)) + .filter(e -> e.getActed().isPresent()) + .filter(e -> e.getActed().get().equals(uuid)) .count(), PAGE_ENTRIES); } diff --git a/common/src/main/java/me/lucko/luckperms/common/storage/dao/file/ConfigurateDao.java b/common/src/main/java/me/lucko/luckperms/common/storage/dao/file/ConfigurateDao.java index 166f4302..fa416608 100644 --- a/common/src/main/java/me/lucko/luckperms/common/storage/dao/file/ConfigurateDao.java +++ b/common/src/main/java/me/lucko/luckperms/common/storage/dao/file/ConfigurateDao.java @@ -291,7 +291,7 @@ public abstract class ConfigurateDao extends AbstractDao { (entry.getActor().equals(Constants.CONSOLE_UUID) ? "" : entry.getActor() + " "), entry.getActorName(), Character.toString(entry.getType().getCode()), - (entry.getActed() == null ? "" : entry.getActed().toString() + " "), + entry.getActed().map(e -> e.toString() + " ").orElse(""), entry.getActedName(), entry.getAction()) ); diff --git a/common/src/main/java/me/lucko/luckperms/common/storage/dao/mongodb/MongoDao.java b/common/src/main/java/me/lucko/luckperms/common/storage/dao/mongodb/MongoDao.java index 0a71964d..f41bae3e 100644 --- a/common/src/main/java/me/lucko/luckperms/common/storage/dao/mongodb/MongoDao.java +++ b/common/src/main/java/me/lucko/luckperms/common/storage/dao/mongodb/MongoDao.java @@ -170,8 +170,8 @@ public class MongoDao extends AbstractDao { .append("actedName", entry.getActedName()) .append("action", entry.getAction()); - if (entry.getActed() != null) { - doc.append("acted", entry.getActed()); + if (entry.getActed().isPresent()) { + doc.append("acted", entry.getActed().get()); } c.insertOne(doc, new InsertOneOptions()); diff --git a/common/src/main/java/me/lucko/luckperms/common/storage/dao/sql/SqlDao.java b/common/src/main/java/me/lucko/luckperms/common/storage/dao/sql/SqlDao.java index edd122d9..3ab8c0f9 100644 --- a/common/src/main/java/me/lucko/luckperms/common/storage/dao/sql/SqlDao.java +++ b/common/src/main/java/me/lucko/luckperms/common/storage/dao/sql/SqlDao.java @@ -234,7 +234,7 @@ public class SqlDao extends AbstractDao { ps.setString(2, entry.getActor().toString()); ps.setString(3, entry.getActorName()); ps.setString(4, Character.toString(entry.getType().getCode())); - ps.setString(5, String.valueOf(entry.getActed())); + ps.setString(5, entry.getActed().map(UUID::toString).orElse("null")); ps.setString(6, entry.getActedName()); ps.setString(7, entry.getAction()); ps.execute(); diff --git a/common/src/main/resources/schema/h2.sql b/common/src/main/resources/schema/h2.sql index ba8fdf66..2f57da9c 100644 --- a/common/src/main/resources/schema/h2.sql +++ b/common/src/main/resources/schema/h2.sql @@ -45,7 +45,7 @@ CREATE TABLE `{prefix}actions` ( `id` INT AUTO_INCREMENT NOT NULL, `time` BIGINT NOT NULL, `actor_uuid` VARCHAR(36) NOT NULL, - `actor_name` VARCHAR(100) NOT NULL, + `actor_name` VARCHAR(100) NOT NULL, `type` CHAR(1) NOT NULL, `acted_uuid` VARCHAR(36) NOT NULL, `acted_name` VARCHAR(36) NOT NULL, diff --git a/common/src/main/resources/schema/mariadb.sql b/common/src/main/resources/schema/mariadb.sql index 9cfdf3cb..61206287 100644 --- a/common/src/main/resources/schema/mariadb.sql +++ b/common/src/main/resources/schema/mariadb.sql @@ -45,7 +45,7 @@ CREATE TABLE `{prefix}actions` ( `id` INT AUTO_INCREMENT NOT NULL, `time` BIGINT NOT NULL, `actor_uuid` VARCHAR(36) NOT NULL, - `actor_name` VARCHAR(100) NOT NULL, + `actor_name` VARCHAR(100) NOT NULL, `type` CHAR(1) NOT NULL, `acted_uuid` VARCHAR(36) NOT NULL, `acted_name` VARCHAR(36) NOT NULL, diff --git a/common/src/main/resources/schema/mysql.sql b/common/src/main/resources/schema/mysql.sql index a3b8a2ff..5bc22b05 100644 --- a/common/src/main/resources/schema/mysql.sql +++ b/common/src/main/resources/schema/mysql.sql @@ -45,7 +45,7 @@ CREATE TABLE `{prefix}actions` ( `id` INT AUTO_INCREMENT NOT NULL, `time` BIGINT NOT NULL, `actor_uuid` VARCHAR(36) NOT NULL, - `actor_name` VARCHAR(100) NOT NULL, + `actor_name` VARCHAR(100) NOT NULL, `type` CHAR(1) NOT NULL, `acted_uuid` VARCHAR(36) NOT NULL, `acted_name` VARCHAR(36) NOT NULL, diff --git a/common/src/main/resources/schema/postgresql.sql b/common/src/main/resources/schema/postgresql.sql index eff5a56d..58b1beb1 100644 --- a/common/src/main/resources/schema/postgresql.sql +++ b/common/src/main/resources/schema/postgresql.sql @@ -41,7 +41,7 @@ CREATE TABLE "{prefix}actions" ( "id" SERIAL PRIMARY KEY NOT NULL, "time" BIGINT NOT NULL, "actor_uuid" VARCHAR(36) NOT NULL, - "actor_name" VARCHAR(100) NOT NULL, + "actor_name" VARCHAR(100) NOT NULL, "type" CHAR(1) NOT NULL, "acted_uuid" VARCHAR(36) NOT NULL, "acted_name" VARCHAR(36) NOT NULL, diff --git a/common/src/main/resources/schema/sqlite.sql b/common/src/main/resources/schema/sqlite.sql index a887aaa5..8a24823a 100644 --- a/common/src/main/resources/schema/sqlite.sql +++ b/common/src/main/resources/schema/sqlite.sql @@ -43,7 +43,7 @@ CREATE TABLE `{prefix}actions` ( `id` INTEGER PRIMARY KEY NOT NULL, `time` BIGINT NOT NULL, `actor_uuid` VARCHAR(36) NOT NULL, - `actor_name` VARCHAR(100) NOT NULL, + `actor_name` VARCHAR(100) NOT NULL, `type` CHAR(1) NOT NULL, `acted_uuid` VARCHAR(36) NOT NULL, `acted_name` VARCHAR(36) NOT NULL,