Fix broken usage of LogEntry#getActed

This commit is contained in:
Luck 2017-11-09 21:05:06 +00:00
parent 14005563a3
commit 22fba0c172
No known key found for this signature in database
GPG Key ID: EFA9B3EC5FD90F8B
13 changed files with 37 additions and 29 deletions

View File

@ -33,6 +33,8 @@ import javax.annotation.Nullable;
/** /**
* Represents a logged action. * Represents a logged action.
*
* @see LuckPermsApi#newLogEntryBuilder() for creating an instance
*/ */
public interface LogEntry extends Comparable<LogEntry> { public interface LogEntry extends Comparable<LogEntry> {
@ -50,6 +52,7 @@ public interface LogEntry extends Comparable<LogEntry> {
* *
* @return the actor id * @return the actor id
*/ */
@Nonnull
UUID getActor(); UUID getActor();
/** /**
@ -57,6 +60,7 @@ public interface LogEntry extends Comparable<LogEntry> {
* *
* @return the name of the actor * @return the name of the actor
*/ */
@Nonnull
String getActorName(); String getActorName();
/** /**
@ -64,6 +68,7 @@ public interface LogEntry extends Comparable<LogEntry> {
* *
* @return the action type * @return the action type
*/ */
@Nonnull
Type getType(); Type getType();
/** /**
@ -73,6 +78,7 @@ public interface LogEntry extends Comparable<LogEntry> {
* *
* @return the uuid of acted object * @return the uuid of acted object
*/ */
@Nonnull
Optional<UUID> getActed(); Optional<UUID> getActed();
/** /**
@ -80,6 +86,7 @@ public interface LogEntry extends Comparable<LogEntry> {
* *
* @return the name of the acted object * @return the name of the acted object
*/ */
@Nonnull
String getActedName(); String getActedName();
/** /**
@ -90,6 +97,7 @@ public interface LogEntry extends Comparable<LogEntry> {
* *
* @return the action * @return the action
*/ */
@Nonnull
String getAction(); String getAction();
/** /**
@ -112,6 +120,7 @@ public interface LogEntry extends Comparable<LogEntry> {
return this.code; return this.code;
} }
@Nonnull
public static Type valueOf(char code) { public static Type valueOf(char code) {
switch (code) { switch (code) {
case 'U': case 'U':

View File

@ -349,6 +349,7 @@ public interface LuckPermsApi {
* @return a new builder * @return a new builder
* @since 4.0 * @since 4.0
*/ */
@Nonnull
LogEntry.Builder newLogEntryBuilder(); LogEntry.Builder newLogEntryBuilder();
/** /**

View File

@ -45,10 +45,10 @@ import org.bukkit.plugin.Plugin;
import java.util.Collection; import java.util.Collection;
import java.util.HashSet; import java.util.HashSet;
import java.util.Map;
import java.util.Set; import java.util.Set;
import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.atomic.AtomicBoolean; import java.util.concurrent.atomic.AtomicBoolean;
import java.util.stream.Collectors;
/** /**
* PermissibleBase for LuckPerms. * PermissibleBase for LuckPerms.
@ -162,13 +162,14 @@ public class LPPermissible extends PermissibleBase {
@Override @Override
public Set<PermissionAttachmentInfo> getEffectivePermissions() { public Set<PermissionAttachmentInfo> getEffectivePermissions() {
Set<PermissionAttachmentInfo> perms = new HashSet<>(); Set<Map.Entry<String, Boolean>> permissions = user.getCachedData().getPermissionData(calculateContexts()).getImmutableBacking().entrySet();
perms.addAll( Set<PermissionAttachmentInfo> ret = new HashSet<>(permissions.size());
user.getCachedData().getPermissionData(calculateContexts()).getImmutableBacking().entrySet().stream()
.map(e -> new PermissionAttachmentInfo(player, e.getKey(), null, e.getValue())) for (Map.Entry<String, Boolean> entry : permissions) {
.collect(Collectors.toList()) ret.add(new PermissionAttachmentInfo(player, entry.getKey(), null, entry.getValue()));
); }
return perms;
return ret;
} }
@Override @Override

View File

@ -72,10 +72,7 @@ public class ExtendedLogEntry implements LogEntry {
.thenComparing(LogEntry::getActor) .thenComparing(LogEntry::getActor)
.thenComparing(LogEntry::getActorName, String.CASE_INSENSITIVE_ORDER) .thenComparing(LogEntry::getActorName, String.CASE_INSENSITIVE_ORDER)
.thenComparing(LogEntry::getType) .thenComparing(LogEntry::getType)
.thenComparing(e -> { .thenComparing(e -> e.getActed().map(UUID::toString).orElse(""))
UUID u = e.getActed().orElse(null);
return u == null ? "" : u.toString();
})
.thenComparing(LogEntry::getActedName, String.CASE_INSENSITIVE_ORDER) .thenComparing(LogEntry::getActedName, String.CASE_INSENSITIVE_ORDER)
.thenComparing(LogEntry::getAction); .thenComparing(LogEntry::getAction);
@ -187,7 +184,7 @@ public class ExtendedLogEntry implements LogEntry {
this.getActor().equals(other.getActor()) && this.getActor().equals(other.getActor()) &&
this.getActorName().equals(other.getActorName()) && this.getActorName().equals(other.getActorName()) &&
this.getType() == other.getType() && 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.getActedName().equals(other.getActedName()) &&
this.getAction().equals(other.getAction()); this.getAction().equals(other.getAction());
} }
@ -200,7 +197,7 @@ public class ExtendedLogEntry implements LogEntry {
result = result * PRIME + this.getActor().hashCode(); result = result * PRIME + this.getActor().hashCode();
result = result * PRIME + this.getActorName().hashCode(); result = result * PRIME + this.getActorName().hashCode();
result = result * PRIME + this.getType().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.getActedName().hashCode();
result = result * PRIME + this.getAction().hashCode(); result = result * PRIME + this.getAction().hashCode();
return result; return result;
@ -365,8 +362,8 @@ public class ExtendedLogEntry implements LogEntry {
data.add("actor", new JsonPrimitive(entry.getActor().toString())); data.add("actor", new JsonPrimitive(entry.getActor().toString()));
data.add("actorName", new JsonPrimitive(entry.getActorName())); data.add("actorName", new JsonPrimitive(entry.getActorName()));
data.add("type", new JsonPrimitive(entry.getType().name())); data.add("type", new JsonPrimitive(entry.getType().name()));
if (entry.getActed() != null) { if (entry.getActed().isPresent()) {
data.add("acted", new JsonPrimitive(entry.getActed().toString())); data.add("acted", new JsonPrimitive(entry.getActed().get().toString()));
} }
data.add("actedName", new JsonPrimitive(entry.getActedName())); data.add("actedName", new JsonPrimitive(entry.getActedName()));
data.add("action", new JsonPrimitive(entry.getAction())); data.add("action", new JsonPrimitive(entry.getAction()));

View File

@ -120,8 +120,8 @@ public class Log {
public SortedSet<ExtendedLogEntry> getUserHistory(UUID uuid) { public SortedSet<ExtendedLogEntry> getUserHistory(UUID uuid) {
return content.stream() return content.stream()
.filter(e -> e.getType() == LogEntry.Type.USER) .filter(e -> e.getType() == LogEntry.Type.USER)
.filter(e -> e.getActed() != null) .filter(e -> e.getActed().isPresent())
.filter(e -> e.getActed().equals(uuid)) .filter(e -> e.getActed().get().equals(uuid))
.collect(Collectors.toCollection(TreeSet::new)); .collect(Collectors.toCollection(TreeSet::new));
} }
@ -132,8 +132,8 @@ public class Log {
public int getUserHistoryMaxPages(UUID uuid) { public int getUserHistoryMaxPages(UUID uuid) {
return getMaxPages(content.stream() return getMaxPages(content.stream()
.filter(e -> e.getType() == LogEntry.Type.USER) .filter(e -> e.getType() == LogEntry.Type.USER)
.filter(e -> e.getActed() != null) .filter(e -> e.getActed().isPresent())
.filter(e -> e.getActed().equals(uuid)) .filter(e -> e.getActed().get().equals(uuid))
.count(), PAGE_ENTRIES); .count(), PAGE_ENTRIES);
} }

View File

@ -291,7 +291,7 @@ public abstract class ConfigurateDao extends AbstractDao {
(entry.getActor().equals(Constants.CONSOLE_UUID) ? "" : entry.getActor() + " "), (entry.getActor().equals(Constants.CONSOLE_UUID) ? "" : entry.getActor() + " "),
entry.getActorName(), entry.getActorName(),
Character.toString(entry.getType().getCode()), Character.toString(entry.getType().getCode()),
(entry.getActed() == null ? "" : entry.getActed().toString() + " "), entry.getActed().map(e -> e.toString() + " ").orElse(""),
entry.getActedName(), entry.getActedName(),
entry.getAction()) entry.getAction())
); );

View File

@ -170,8 +170,8 @@ public class MongoDao extends AbstractDao {
.append("actedName", entry.getActedName()) .append("actedName", entry.getActedName())
.append("action", entry.getAction()); .append("action", entry.getAction());
if (entry.getActed() != null) { if (entry.getActed().isPresent()) {
doc.append("acted", entry.getActed()); doc.append("acted", entry.getActed().get());
} }
c.insertOne(doc, new InsertOneOptions()); c.insertOne(doc, new InsertOneOptions());

View File

@ -234,7 +234,7 @@ public class SqlDao extends AbstractDao {
ps.setString(2, entry.getActor().toString()); ps.setString(2, entry.getActor().toString());
ps.setString(3, entry.getActorName()); ps.setString(3, entry.getActorName());
ps.setString(4, Character.toString(entry.getType().getCode())); 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(6, entry.getActedName());
ps.setString(7, entry.getAction()); ps.setString(7, entry.getAction());
ps.execute(); ps.execute();

View File

@ -45,7 +45,7 @@ CREATE TABLE `{prefix}actions` (
`id` INT AUTO_INCREMENT NOT NULL, `id` INT AUTO_INCREMENT NOT NULL,
`time` BIGINT NOT NULL, `time` BIGINT NOT NULL,
`actor_uuid` VARCHAR(36) 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, `type` CHAR(1) NOT NULL,
`acted_uuid` VARCHAR(36) NOT NULL, `acted_uuid` VARCHAR(36) NOT NULL,
`acted_name` VARCHAR(36) NOT NULL, `acted_name` VARCHAR(36) NOT NULL,

View File

@ -45,7 +45,7 @@ CREATE TABLE `{prefix}actions` (
`id` INT AUTO_INCREMENT NOT NULL, `id` INT AUTO_INCREMENT NOT NULL,
`time` BIGINT NOT NULL, `time` BIGINT NOT NULL,
`actor_uuid` VARCHAR(36) 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, `type` CHAR(1) NOT NULL,
`acted_uuid` VARCHAR(36) NOT NULL, `acted_uuid` VARCHAR(36) NOT NULL,
`acted_name` VARCHAR(36) NOT NULL, `acted_name` VARCHAR(36) NOT NULL,

View File

@ -45,7 +45,7 @@ CREATE TABLE `{prefix}actions` (
`id` INT AUTO_INCREMENT NOT NULL, `id` INT AUTO_INCREMENT NOT NULL,
`time` BIGINT NOT NULL, `time` BIGINT NOT NULL,
`actor_uuid` VARCHAR(36) 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, `type` CHAR(1) NOT NULL,
`acted_uuid` VARCHAR(36) NOT NULL, `acted_uuid` VARCHAR(36) NOT NULL,
`acted_name` VARCHAR(36) NOT NULL, `acted_name` VARCHAR(36) NOT NULL,

View File

@ -41,7 +41,7 @@ CREATE TABLE "{prefix}actions" (
"id" SERIAL PRIMARY KEY NOT NULL, "id" SERIAL PRIMARY KEY NOT NULL,
"time" BIGINT NOT NULL, "time" BIGINT NOT NULL,
"actor_uuid" VARCHAR(36) 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, "type" CHAR(1) NOT NULL,
"acted_uuid" VARCHAR(36) NOT NULL, "acted_uuid" VARCHAR(36) NOT NULL,
"acted_name" VARCHAR(36) NOT NULL, "acted_name" VARCHAR(36) NOT NULL,

View File

@ -43,7 +43,7 @@ CREATE TABLE `{prefix}actions` (
`id` INTEGER PRIMARY KEY NOT NULL, `id` INTEGER PRIMARY KEY NOT NULL,
`time` BIGINT NOT NULL, `time` BIGINT NOT NULL,
`actor_uuid` VARCHAR(36) 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, `type` CHAR(1) NOT NULL,
`acted_uuid` VARCHAR(36) NOT NULL, `acted_uuid` VARCHAR(36) NOT NULL,
`acted_name` VARCHAR(36) NOT NULL, `acted_name` VARCHAR(36) NOT NULL,