From 2bc56de1c3041ac42405a9a32937a8d1f81f6157 Mon Sep 17 00:00:00 2001 From: Luck Date: Sun, 28 Jan 2018 00:26:58 +0000 Subject: [PATCH] Don't store API delegate instances for all users --- .../common/api/LuckPermsApiProvider.java | 2 +- .../delegates/manager/ApiGroupManager.java | 4 ++-- .../delegates/manager/ApiTrackManager.java | 4 ++-- .../api/delegates/manager/ApiUserManager.java | 6 ++--- .../delegates/model/ApiPermissionHolder.java | 2 +- .../common/api/delegates/model/ApiUser.java | 10 ++++----- .../luckperms/common/event/EventFactory.java | 22 +++++++++---------- .../lucko/luckperms/common/model/Group.java | 7 +++--- .../common/model/PermissionHolder.java | 8 ------- .../lucko/luckperms/common/model/Track.java | 6 ++--- .../me/lucko/luckperms/common/model/User.java | 8 ------- .../common/storage/AbstractStorage.java | 8 +++---- .../luckperms/common/storage/Storage.java | 2 +- .../wrappings/BufferedOutputStorage.java | 4 ++-- .../storage/wrappings/PhasedStorage.java | 4 ++-- 15 files changed, 40 insertions(+), 57 deletions(-) diff --git a/common/src/main/java/me/lucko/luckperms/common/api/LuckPermsApiProvider.java b/common/src/main/java/me/lucko/luckperms/common/api/LuckPermsApiProvider.java index 4872a5f9..d388f41b 100644 --- a/common/src/main/java/me/lucko/luckperms/common/api/LuckPermsApiProvider.java +++ b/common/src/main/java/me/lucko/luckperms/common/api/LuckPermsApiProvider.java @@ -131,7 +131,7 @@ public class LuckPermsApiProvider implements LuckPermsApi { @Nonnull @Override public Storage getStorage() { - return this.plugin.getStorage().getDelegate(); + return this.plugin.getStorage().getApiDelegate(); } @Nonnull diff --git a/common/src/main/java/me/lucko/luckperms/common/api/delegates/manager/ApiGroupManager.java b/common/src/main/java/me/lucko/luckperms/common/api/delegates/manager/ApiGroupManager.java index 063fa73f..7c21f8a1 100644 --- a/common/src/main/java/me/lucko/luckperms/common/api/delegates/manager/ApiGroupManager.java +++ b/common/src/main/java/me/lucko/luckperms/common/api/delegates/manager/ApiGroupManager.java @@ -45,13 +45,13 @@ public class ApiGroupManager implements GroupManager { public Group getGroup(@Nonnull String name) { Objects.requireNonNull(name, "name"); me.lucko.luckperms.common.model.Group group = this.handle.getIfLoaded(name); - return group == null ? null : group.getDelegate(); + return group == null ? null : group.getApiDelegate(); } @Nonnull @Override public Set getLoadedGroups() { - return this.handle.getAll().values().stream().map(me.lucko.luckperms.common.model.Group::getDelegate).collect(Collectors.toSet()); + return this.handle.getAll().values().stream().map(me.lucko.luckperms.common.model.Group::getApiDelegate).collect(Collectors.toSet()); } @Override diff --git a/common/src/main/java/me/lucko/luckperms/common/api/delegates/manager/ApiTrackManager.java b/common/src/main/java/me/lucko/luckperms/common/api/delegates/manager/ApiTrackManager.java index aa7406d9..3135f9e6 100644 --- a/common/src/main/java/me/lucko/luckperms/common/api/delegates/manager/ApiTrackManager.java +++ b/common/src/main/java/me/lucko/luckperms/common/api/delegates/manager/ApiTrackManager.java @@ -45,13 +45,13 @@ public class ApiTrackManager implements TrackManager { public Track getTrack(@Nonnull String name) { Objects.requireNonNull(name, "name"); me.lucko.luckperms.common.model.Track track = this.handle.getIfLoaded(name); - return track == null ? null : track.getDelegate(); + return track == null ? null : track.getApiDelegate(); } @Nonnull @Override public Set getLoadedTracks() { - return this.handle.getAll().values().stream().map(me.lucko.luckperms.common.model.Track::getDelegate).collect(Collectors.toSet()); + return this.handle.getAll().values().stream().map(me.lucko.luckperms.common.model.Track::getApiDelegate).collect(Collectors.toSet()); } @Override diff --git a/common/src/main/java/me/lucko/luckperms/common/api/delegates/manager/ApiUserManager.java b/common/src/main/java/me/lucko/luckperms/common/api/delegates/manager/ApiUserManager.java index 24d23a94..0bdd4154 100644 --- a/common/src/main/java/me/lucko/luckperms/common/api/delegates/manager/ApiUserManager.java +++ b/common/src/main/java/me/lucko/luckperms/common/api/delegates/manager/ApiUserManager.java @@ -48,20 +48,20 @@ public class ApiUserManager implements UserManager { public User getUser(@Nonnull UUID uuid) { Objects.requireNonNull(uuid, "uuid"); me.lucko.luckperms.common.model.User user = this.handle.getIfLoaded(uuid); - return user == null ? null : user.getDelegate(); + return user == null ? null : new ApiUser(user); } @Override public User getUser(@Nonnull String name) { Objects.requireNonNull(name, "name"); me.lucko.luckperms.common.model.User user = this.handle.getByUsername(name); - return user == null ? null : user.getDelegate(); + return user == null ? null : new ApiUser(user); } @Nonnull @Override public Set getLoadedUsers() { - return this.handle.getAll().values().stream().map(me.lucko.luckperms.common.model.User::getDelegate).collect(Collectors.toSet()); + return this.handle.getAll().values().stream().map(ApiUser::new).collect(Collectors.toSet()); } @Override diff --git a/common/src/main/java/me/lucko/luckperms/common/api/delegates/model/ApiPermissionHolder.java b/common/src/main/java/me/lucko/luckperms/common/api/delegates/model/ApiPermissionHolder.java index dc4d615e..652544c8 100644 --- a/common/src/main/java/me/lucko/luckperms/common/api/delegates/model/ApiPermissionHolder.java +++ b/common/src/main/java/me/lucko/luckperms/common/api/delegates/model/ApiPermissionHolder.java @@ -59,7 +59,7 @@ import javax.annotation.Nonnull; public class ApiPermissionHolder implements PermissionHolder { private final me.lucko.luckperms.common.model.PermissionHolder handle; - public ApiPermissionHolder(me.lucko.luckperms.common.model.PermissionHolder handle) { + ApiPermissionHolder(me.lucko.luckperms.common.model.PermissionHolder handle) { this.handle = Objects.requireNonNull(handle, "handle"); } diff --git a/common/src/main/java/me/lucko/luckperms/common/api/delegates/model/ApiUser.java b/common/src/main/java/me/lucko/luckperms/common/api/delegates/model/ApiUser.java index 53b96597..5641fdaf 100644 --- a/common/src/main/java/me/lucko/luckperms/common/api/delegates/model/ApiUser.java +++ b/common/src/main/java/me/lucko/luckperms/common/api/delegates/model/ApiUser.java @@ -45,16 +45,16 @@ public final class ApiUser extends ApiPermissionHolder implements User { private final me.lucko.luckperms.common.model.User handle; - @Override - me.lucko.luckperms.common.model.User getHandle() { - return this.handle; - } - public ApiUser(me.lucko.luckperms.common.model.User handle) { super(handle); this.handle = handle; } + @Override + me.lucko.luckperms.common.model.User getHandle() { + return this.handle; + } + @Nonnull @Override public UUID getUuid() { diff --git a/common/src/main/java/me/lucko/luckperms/common/event/EventFactory.java b/common/src/main/java/me/lucko/luckperms/common/event/EventFactory.java index c306a288..d19b637f 100644 --- a/common/src/main/java/me/lucko/luckperms/common/event/EventFactory.java +++ b/common/src/main/java/me/lucko/luckperms/common/event/EventFactory.java @@ -101,17 +101,17 @@ public final class EventFactory { } public void handleGroupCacheLoad(Group group, GroupData data) { - EventGroupCacheLoad event = new EventGroupCacheLoad(group.getDelegate(), data); + EventGroupCacheLoad event = new EventGroupCacheLoad(group.getApiDelegate(), data); fireEventAsync(event); } public void handleGroupCreate(Group group, CreationCause cause) { - EventGroupCreate event = new EventGroupCreate(group.getDelegate(), cause); + EventGroupCreate event = new EventGroupCreate(group.getApiDelegate(), cause); fireEventAsync(event); } public void handleGroupDataRecalculate(Group group, GroupData data) { - EventGroupDataRecalculate event = new EventGroupDataRecalculate(group.getDelegate(), data); + EventGroupDataRecalculate event = new EventGroupDataRecalculate(group.getApiDelegate(), data); fireEventAsync(event); } @@ -126,7 +126,7 @@ public final class EventFactory { } public void handleGroupLoad(Group group) { - EventGroupLoad event = new EventGroupLoad(group.getDelegate()); + EventGroupLoad event = new EventGroupLoad(group.getApiDelegate()); fireEventAsync(event); } @@ -203,7 +203,7 @@ public final class EventFactory { } public void handleTrackCreate(Track track, CreationCause cause) { - EventTrackCreate event = new EventTrackCreate(track.getDelegate(), cause); + EventTrackCreate event = new EventTrackCreate(track.getApiDelegate(), cause); fireEventAsync(event); } @@ -218,22 +218,22 @@ public final class EventFactory { } public void handleTrackLoad(Track track) { - EventTrackLoad event = new EventTrackLoad(track.getDelegate()); + EventTrackLoad event = new EventTrackLoad(track.getApiDelegate()); fireEventAsync(event); } public void handleTrackAddGroup(Track track, String group, List before, List after) { - EventTrackAddGroup event = new EventTrackAddGroup(group, track.getDelegate(), ImmutableList.copyOf(before), ImmutableList.copyOf(after)); + EventTrackAddGroup event = new EventTrackAddGroup(group, track.getApiDelegate(), ImmutableList.copyOf(before), ImmutableList.copyOf(after)); fireEventAsync(event); } public void handleTrackClear(Track track, List before) { - EventTrackClear event = new EventTrackClear(track.getDelegate(), ImmutableList.copyOf(before), ImmutableList.of()); + EventTrackClear event = new EventTrackClear(track.getApiDelegate(), ImmutableList.copyOf(before), ImmutableList.of()); fireEventAsync(event); } public void handleTrackRemoveGroup(Track track, String group, List before, List after) { - EventTrackRemoveGroup event = new EventTrackRemoveGroup(group, track.getDelegate(), ImmutableList.copyOf(before), ImmutableList.copyOf(after)); + EventTrackRemoveGroup event = new EventTrackRemoveGroup(group, track.getApiDelegate(), ImmutableList.copyOf(before), ImmutableList.copyOf(after)); fireEventAsync(event); } @@ -263,12 +263,12 @@ public final class EventFactory { } public void handleUserDemote(User user, Track track, String from, String to) { - EventUserDemote event = new EventUserDemote(track.getDelegate(), user.getDelegate(), from, to); + EventUserDemote event = new EventUserDemote(track.getApiDelegate(), user.getDelegate(), from, to); fireEventAsync(event); } public void handleUserPromote(User user, Track track, String from, String to) { - EventUserPromote event = new EventUserPromote(track.getDelegate(), user.getDelegate(), from, to); + EventUserPromote event = new EventUserPromote(track.getApiDelegate(), user.getDelegate(), from, to); fireEventAsync(event); } diff --git a/common/src/main/java/me/lucko/luckperms/common/model/Group.java b/common/src/main/java/me/lucko/luckperms/common/model/Group.java index 7dac7fd5..4ea9bd15 100644 --- a/common/src/main/java/me/lucko/luckperms/common/model/Group.java +++ b/common/src/main/java/me/lucko/luckperms/common/model/Group.java @@ -46,7 +46,7 @@ public class Group extends PermissionHolder implements Identifiable { */ private final String name; - private final ApiGroup delegate = new ApiGroup(this); + private final ApiGroup apiDelegate = new ApiGroup(this); /** * The groups data cache instance @@ -71,9 +71,8 @@ public class Group extends PermissionHolder implements Identifiable { return this.name; } - @Override - public ApiGroup getDelegate() { - return this.delegate; + public ApiGroup getApiDelegate() { + return this.apiDelegate; } @Override diff --git a/common/src/main/java/me/lucko/luckperms/common/model/PermissionHolder.java b/common/src/main/java/me/lucko/luckperms/common/model/PermissionHolder.java index 6cfdef7e..e3dcddf6 100644 --- a/common/src/main/java/me/lucko/luckperms/common/model/PermissionHolder.java +++ b/common/src/main/java/me/lucko/luckperms/common/model/PermissionHolder.java @@ -38,7 +38,6 @@ import me.lucko.luckperms.api.Node; import me.lucko.luckperms.api.Tristate; import me.lucko.luckperms.api.context.ContextSet; import me.lucko.luckperms.api.context.ImmutableContextSet; -import me.lucko.luckperms.common.api.delegates.model.ApiPermissionHolder; import me.lucko.luckperms.common.buffers.BufferedRequest; import me.lucko.luckperms.common.buffers.Cache; import me.lucko.luckperms.common.caching.HolderCachedData; @@ -227,13 +226,6 @@ public abstract class PermissionHolder { */ public abstract HolderType getType(); - /** - * Gets the API delegate for this instance - * - * @return the api delegate - */ - public abstract ApiPermissionHolder getDelegate(); - public NodeMap getData(NodeMapType type) { switch (type) { case ENDURING: diff --git a/common/src/main/java/me/lucko/luckperms/common/model/Track.java b/common/src/main/java/me/lucko/luckperms/common/model/Track.java index 6ff6f2c1..395cc5f2 100644 --- a/common/src/main/java/me/lucko/luckperms/common/model/Track.java +++ b/common/src/main/java/me/lucko/luckperms/common/model/Track.java @@ -54,7 +54,7 @@ public final class Track implements Identifiable { */ private final List groups = Collections.synchronizedList(new ArrayList<>()); - private final ApiTrack delegate = new ApiTrack(this); + private final ApiTrack apiDelegate = new ApiTrack(this); public Track(String name, LuckPermsPlugin plugin) { this.name = name; @@ -69,8 +69,8 @@ public final class Track implements Identifiable { return this.ioLock; } - public ApiTrack getDelegate() { - return this.delegate; + public ApiTrack getApiDelegate() { + return this.apiDelegate; } @Override diff --git a/common/src/main/java/me/lucko/luckperms/common/model/User.java b/common/src/main/java/me/lucko/luckperms/common/model/User.java index a6cc82cc..aad3cdfc 100644 --- a/common/src/main/java/me/lucko/luckperms/common/model/User.java +++ b/common/src/main/java/me/lucko/luckperms/common/model/User.java @@ -26,7 +26,6 @@ package me.lucko.luckperms.common.model; import me.lucko.luckperms.api.Contexts; -import me.lucko.luckperms.common.api.delegates.model.ApiUser; import me.lucko.luckperms.common.buffers.BufferedRequest; import me.lucko.luckperms.common.caching.UserCachedData; import me.lucko.luckperms.common.config.ConfigKeys; @@ -65,8 +64,6 @@ public class User extends PermissionHolder implements Identifiable refreshBuffer; - private final ApiUser delegate = new ApiUser(this); - public User(UUID uuid, LuckPermsPlugin plugin) { super(uuid.toString(), plugin); this.uuid = uuid; @@ -108,11 +105,6 @@ public class User extends PermissionHolder implements Identifiable