Don't store API delegate instances for all users

This commit is contained in:
Luck 2018-01-28 00:26:58 +00:00
parent e28d15456c
commit 2bc56de1c3
No known key found for this signature in database
GPG Key ID: EFA9B3EC5FD90F8B
15 changed files with 40 additions and 57 deletions

View File

@ -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

View File

@ -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<Group> 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

View File

@ -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<Track> 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

View File

@ -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<User> 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

View File

@ -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");
}

View File

@ -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() {

View File

@ -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<String> before, List<String> 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<String> 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<String> before, List<String> 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);
}

View File

@ -46,7 +46,7 @@ public class Group extends PermissionHolder implements Identifiable<String> {
*/
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<String> {
return this.name;
}
@Override
public ApiGroup getDelegate() {
return this.delegate;
public ApiGroup getApiDelegate() {
return this.apiDelegate;
}
@Override

View File

@ -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:

View File

@ -54,7 +54,7 @@ public final class Track implements Identifiable<String> {
*/
private final List<String> 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<String> {
return this.ioLock;
}
public ApiTrack getDelegate() {
return this.delegate;
public ApiTrack getApiDelegate() {
return this.apiDelegate;
}
@Override

View File

@ -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<UserIdentifie
private final BufferedRequest<Void> 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<UserIdentifie
return this.refreshBuffer;
}
@Override
public ApiUser getDelegate() {
return this.delegate;
}
@Override
public UserIdentifier getId() {
return UserIdentifier.of(this.uuid, this.name);

View File

@ -64,12 +64,12 @@ public class AbstractStorage implements Storage {
private final LuckPermsPlugin plugin;
private final AbstractDao dao;
private final ApiStorage delegate;
private final ApiStorage apiDelegate;
private AbstractStorage(LuckPermsPlugin plugin, AbstractDao dao) {
this.plugin = plugin;
this.dao = dao;
this.delegate = new ApiStorage(plugin, this);
this.apiDelegate = new ApiStorage(plugin, this);
}
@Override
@ -100,8 +100,8 @@ public class AbstractStorage implements Storage {
}
@Override
public ApiStorage getDelegate() {
return this.delegate;
public ApiStorage getApiDelegate() {
return this.apiDelegate;
}
private interface ThrowingRunnable {

View File

@ -49,7 +49,7 @@ import java.util.concurrent.CompletableFuture;
*/
public interface Storage {
ApiStorage getDelegate();
ApiStorage getApiDelegate();
AbstractDao getDao();

View File

@ -178,8 +178,8 @@ public class BufferedOutputStorage implements Storage, Runnable {
}
@Override
public ApiStorage getDelegate() {
return this.delegate.getDelegate();
public ApiStorage getApiDelegate() {
return this.delegate.getApiDelegate();
}
@Override

View File

@ -69,8 +69,8 @@ public class PhasedStorage implements Storage {
}
@Override
public ApiStorage getDelegate() {
return this.delegate.getDelegate();
public ApiStorage getApiDelegate() {
return this.delegate.getApiDelegate();
}
@Override