Rename some classes

This commit is contained in:
Luck 2020-03-31 13:38:28 +01:00
parent c98c60b120
commit 2028d65579
No known key found for this signature in database
GPG Key ID: EFA9B3EC5FD90F8B
17 changed files with 82 additions and 222 deletions

View File

@ -36,6 +36,6 @@ public abstract class ApiAbstractManager<I, E, H> {
this.handle = handle; this.handle = handle;
} }
protected abstract E getDelegateFor(I internal); protected abstract E proxy(I internal);
} }

View File

@ -51,25 +51,21 @@ public class ApiGroupManager extends ApiAbstractManager<Group, net.luckperms.api
} }
@Override @Override
protected net.luckperms.api.model.group.Group getDelegateFor(me.lucko.luckperms.common.model.Group internal) { protected net.luckperms.api.model.group.Group proxy(me.lucko.luckperms.common.model.Group internal) {
if (internal == null) { return internal == null ? null : internal.getApiProxy();
return null;
}
return internal.getApiDelegate();
} }
@Override @Override
public @NonNull CompletableFuture<net.luckperms.api.model.group.Group> createAndLoadGroup(@NonNull String name) { public @NonNull CompletableFuture<net.luckperms.api.model.group.Group> createAndLoadGroup(@NonNull String name) {
name = ApiUtils.checkName(Objects.requireNonNull(name, "name")); name = ApiUtils.checkName(Objects.requireNonNull(name, "name"));
return this.plugin.getStorage().createAndLoadGroup(name, CreationCause.API) return this.plugin.getStorage().createAndLoadGroup(name, CreationCause.API)
.thenApply(this::getDelegateFor); .thenApply(this::proxy);
} }
@Override @Override
public @NonNull CompletableFuture<Optional<net.luckperms.api.model.group.Group>> loadGroup(@NonNull String name) { public @NonNull CompletableFuture<Optional<net.luckperms.api.model.group.Group>> loadGroup(@NonNull String name) {
name = ApiUtils.checkName(Objects.requireNonNull(name, "name")); name = ApiUtils.checkName(Objects.requireNonNull(name, "name"));
return this.plugin.getStorage().loadGroup(name).thenApply(opt -> opt.map(this::getDelegateFor)); return this.plugin.getStorage().loadGroup(name).thenApply(opt -> opt.map(this::proxy));
} }
@Override @Override
@ -102,13 +98,13 @@ public class ApiGroupManager extends ApiAbstractManager<Group, net.luckperms.api
@Override @Override
public net.luckperms.api.model.group.Group getGroup(@NonNull String name) { public net.luckperms.api.model.group.Group getGroup(@NonNull String name) {
Objects.requireNonNull(name, "name"); Objects.requireNonNull(name, "name");
return getDelegateFor(this.handle.getIfLoaded(name)); return proxy(this.handle.getIfLoaded(name));
} }
@Override @Override
public @NonNull Set<net.luckperms.api.model.group.Group> getLoadedGroups() { public @NonNull Set<net.luckperms.api.model.group.Group> getLoadedGroups() {
return this.handle.getAll().values().stream() return this.handle.getAll().values().stream()
.map(this::getDelegateFor) .map(this::proxy)
.collect(ImmutableCollectors.toSet()); .collect(ImmutableCollectors.toSet());
} }

View File

@ -47,25 +47,21 @@ public class ApiTrackManager extends ApiAbstractManager<Track, net.luckperms.api
} }
@Override @Override
protected net.luckperms.api.track.Track getDelegateFor(Track internal) { protected net.luckperms.api.track.Track proxy(Track internal) {
if (internal == null) { return internal == null ? null : internal.getApiProxy();
return null;
}
return internal.getApiDelegate();
} }
@Override @Override
public @NonNull CompletableFuture<net.luckperms.api.track.Track> createAndLoadTrack(@NonNull String name) { public @NonNull CompletableFuture<net.luckperms.api.track.Track> createAndLoadTrack(@NonNull String name) {
name = ApiUtils.checkName(Objects.requireNonNull(name, "name")); name = ApiUtils.checkName(Objects.requireNonNull(name, "name"));
return this.plugin.getStorage().createAndLoadTrack(name, CreationCause.API) return this.plugin.getStorage().createAndLoadTrack(name, CreationCause.API)
.thenApply(this::getDelegateFor); .thenApply(this::proxy);
} }
@Override @Override
public @NonNull CompletableFuture<Optional<net.luckperms.api.track.Track>> loadTrack(@NonNull String name) { public @NonNull CompletableFuture<Optional<net.luckperms.api.track.Track>> loadTrack(@NonNull String name) {
name = ApiUtils.checkName(Objects.requireNonNull(name, "name")); name = ApiUtils.checkName(Objects.requireNonNull(name, "name"));
return this.plugin.getStorage().loadTrack(name).thenApply(opt -> opt.map(this::getDelegateFor)); return this.plugin.getStorage().loadTrack(name).thenApply(opt -> opt.map(this::proxy));
} }
@Override @Override
@ -88,13 +84,13 @@ public class ApiTrackManager extends ApiAbstractManager<Track, net.luckperms.api
@Override @Override
public net.luckperms.api.track.Track getTrack(@NonNull String name) { public net.luckperms.api.track.Track getTrack(@NonNull String name) {
Objects.requireNonNull(name, "name"); Objects.requireNonNull(name, "name");
return getDelegateFor(this.handle.getIfLoaded(name)); return proxy(this.handle.getIfLoaded(name));
} }
@Override @Override
public @NonNull Set<net.luckperms.api.track.Track> getLoadedTracks() { public @NonNull Set<net.luckperms.api.track.Track> getLoadedTracks() {
return this.handle.getAll().values().stream() return this.handle.getAll().values().stream()
.map(this::getDelegateFor) .map(this::proxy)
.collect(ImmutableCollectors.toSet()); .collect(ImmutableCollectors.toSet());
} }

View File

@ -51,11 +51,8 @@ public class ApiUserManager extends ApiAbstractManager<User, net.luckperms.api.m
} }
@Override @Override
protected net.luckperms.api.model.user.User getDelegateFor(User internal) { protected net.luckperms.api.model.user.User proxy(User internal) {
if (internal == null) { return internal == null ? null : internal.getApiProxy();
return null;
}
return new ApiUser(internal);
} }
@Override @Override
@ -68,7 +65,7 @@ public class ApiUserManager extends ApiAbstractManager<User, net.luckperms.api.m
} }
return this.plugin.getStorage().loadUser(uniqueId, username) return this.plugin.getStorage().loadUser(uniqueId, username)
.thenApply(this::getDelegateFor); .thenApply(this::proxy);
} }
@Override @Override
@ -110,19 +107,19 @@ public class ApiUserManager extends ApiAbstractManager<User, net.luckperms.api.m
@Override @Override
public net.luckperms.api.model.user.User getUser(@NonNull UUID uniqueId) { public net.luckperms.api.model.user.User getUser(@NonNull UUID uniqueId) {
Objects.requireNonNull(uniqueId, "uuid"); Objects.requireNonNull(uniqueId, "uuid");
return getDelegateFor(this.handle.getIfLoaded(uniqueId)); return proxy(this.handle.getIfLoaded(uniqueId));
} }
@Override @Override
public net.luckperms.api.model.user.User getUser(@NonNull String username) { public net.luckperms.api.model.user.User getUser(@NonNull String username) {
Objects.requireNonNull(username, "name"); Objects.requireNonNull(username, "name");
return getDelegateFor(this.handle.getByUsername(username)); return proxy(this.handle.getByUsername(username));
} }
@Override @Override
public @NonNull Set<net.luckperms.api.model.user.User> getLoadedUsers() { public @NonNull Set<net.luckperms.api.model.user.User> getLoadedUsers() {
return this.handle.getAll().values().stream() return this.handle.getAll().values().stream()
.map(this::getDelegateFor) .map(this::proxy)
.collect(ImmutableCollectors.toSet()); .collect(ImmutableCollectors.toSet());
} }

View File

@ -165,8 +165,8 @@ public abstract class ContextManager<T> {
private static String getCalculatorClass(ContextCalculator<?> calculator) { private static String getCalculatorClass(ContextCalculator<?> calculator) {
Class<?> calculatorClass; Class<?> calculatorClass;
if (calculator instanceof ProxiedContextCalculator) { if (calculator instanceof ForwardingContextCalculator) {
calculatorClass = ((ProxiedContextCalculator<?>) calculator).getDelegate().getClass(); calculatorClass = ((ForwardingContextCalculator<?>) calculator).delegate().getClass();
} else { } else {
calculatorClass = calculator.getClass(); calculatorClass = calculator.getClass();
} }

View File

@ -30,8 +30,8 @@ import net.luckperms.api.context.ContextCalculator;
/** /**
* Represents a {@link ContextCalculator} which delegates calls to another object. * Represents a {@link ContextCalculator} which delegates calls to another object.
*/ */
public interface ProxiedContextCalculator<T> extends ContextCalculator<T> { public interface ForwardingContextCalculator<T> extends ContextCalculator<T> {
Object getDelegate(); Object delegate();
} }

View File

@ -29,7 +29,6 @@ import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableSet; import com.google.common.collect.ImmutableSet;
import me.lucko.luckperms.common.api.implementation.ApiPermissionHolder; import me.lucko.luckperms.common.api.implementation.ApiPermissionHolder;
import me.lucko.luckperms.common.api.implementation.ApiUser;
import me.lucko.luckperms.common.cacheddata.GroupCachedDataManager; import me.lucko.luckperms.common.cacheddata.GroupCachedDataManager;
import me.lucko.luckperms.common.cacheddata.UserCachedDataManager; import me.lucko.luckperms.common.cacheddata.UserCachedDataManager;
import me.lucko.luckperms.common.event.gen.GeneratedEventClass; import me.lucko.luckperms.common.event.gen.GeneratedEventClass;
@ -144,11 +143,11 @@ public final class EventDispatcher {
} }
public void dispatchGroupCacheLoad(Group group, GroupCachedDataManager data) { public void dispatchGroupCacheLoad(Group group, GroupCachedDataManager data) {
post(GroupCacheLoadEvent.class, () -> generate(GroupCacheLoadEvent.class, group.getApiDelegate(), data)); post(GroupCacheLoadEvent.class, () -> generate(GroupCacheLoadEvent.class, group.getApiProxy(), data));
} }
public void dispatchGroupCreate(Group group, CreationCause cause) { public void dispatchGroupCreate(Group group, CreationCause cause) {
post(GroupCreateEvent.class, () -> generate(GroupCreateEvent.class, group.getApiDelegate(), cause)); post(GroupCreateEvent.class, () -> generate(GroupCreateEvent.class, group.getApiProxy(), cause));
} }
public void dispatchGroupDelete(Group group, DeletionCause cause) { public void dispatchGroupDelete(Group group, DeletionCause cause) {
@ -160,7 +159,7 @@ public final class EventDispatcher {
} }
public void dispatchGroupLoad(Group group) { public void dispatchGroupLoad(Group group) {
post(GroupLoadEvent.class, () -> generate(GroupLoadEvent.class, group.getApiDelegate())); post(GroupLoadEvent.class, () -> generate(GroupLoadEvent.class, group.getApiProxy()));
} }
public boolean dispatchLogBroadcast(boolean initialState, Action entry, LogBroadcastEvent.Origin origin) { public boolean dispatchLogBroadcast(boolean initialState, Action entry, LogBroadcastEvent.Origin origin) {
@ -208,15 +207,15 @@ public final class EventDispatcher {
} }
public void dispatchNodeAdd(Node node, PermissionHolder target, DataType dataType, Collection<? extends Node> before, Collection<? extends Node> after) { public void dispatchNodeAdd(Node node, PermissionHolder target, DataType dataType, Collection<? extends Node> before, Collection<? extends Node> after) {
post(NodeAddEvent.class, () -> generate(NodeAddEvent.class, getDelegate(target), dataType, ImmutableSet.copyOf(before), ImmutableSet.copyOf(after), node)); post(NodeAddEvent.class, () -> generate(NodeAddEvent.class, proxy(target), dataType, ImmutableSet.copyOf(before), ImmutableSet.copyOf(after), node));
} }
public void dispatchNodeClear(PermissionHolder target, DataType dataType, Collection<? extends Node> before, Collection<? extends Node> after) { public void dispatchNodeClear(PermissionHolder target, DataType dataType, Collection<? extends Node> before, Collection<? extends Node> after) {
post(NodeClearEvent.class, () -> generate(NodeClearEvent.class, getDelegate(target), dataType, ImmutableSet.copyOf(before), ImmutableSet.copyOf(after))); post(NodeClearEvent.class, () -> generate(NodeClearEvent.class, proxy(target), dataType, ImmutableSet.copyOf(before), ImmutableSet.copyOf(after)));
} }
public void dispatchNodeRemove(Node node, PermissionHolder target, DataType dataType, Collection<? extends Node> before, Collection<? extends Node> after) { public void dispatchNodeRemove(Node node, PermissionHolder target, DataType dataType, Collection<? extends Node> before, Collection<? extends Node> after) {
post(NodeRemoveEvent.class, () -> generate(NodeRemoveEvent.class, getDelegate(target), dataType, ImmutableSet.copyOf(before), ImmutableSet.copyOf(after), node)); post(NodeRemoveEvent.class, () -> generate(NodeRemoveEvent.class, proxy(target), dataType, ImmutableSet.copyOf(before), ImmutableSet.copyOf(after), node));
} }
public void dispatchConfigReload() { public void dispatchConfigReload() {
@ -248,7 +247,7 @@ public final class EventDispatcher {
} }
public void dispatchTrackCreate(Track track, CreationCause cause) { public void dispatchTrackCreate(Track track, CreationCause cause) {
post(TrackCreateEvent.class, () -> generate(TrackCreateEvent.class, track.getApiDelegate(), cause)); post(TrackCreateEvent.class, () -> generate(TrackCreateEvent.class, track.getApiProxy(), cause));
} }
public void dispatchTrackDelete(Track track, DeletionCause cause) { public void dispatchTrackDelete(Track track, DeletionCause cause) {
@ -260,32 +259,32 @@ public final class EventDispatcher {
} }
public void dispatchTrackLoad(Track track) { public void dispatchTrackLoad(Track track) {
post(TrackLoadEvent.class, () -> generate(TrackLoadEvent.class, track.getApiDelegate())); post(TrackLoadEvent.class, () -> generate(TrackLoadEvent.class, track.getApiProxy()));
} }
public void dispatchTrackAddGroup(Track track, String group, List<String> before, List<String> after) { public void dispatchTrackAddGroup(Track track, String group, List<String> before, List<String> after) {
post(TrackAddGroupEvent.class, () -> generate(TrackAddGroupEvent.class, track.getApiDelegate(), ImmutableList.copyOf(before), ImmutableList.copyOf(after), group)); post(TrackAddGroupEvent.class, () -> generate(TrackAddGroupEvent.class, track.getApiProxy(), ImmutableList.copyOf(before), ImmutableList.copyOf(after), group));
} }
public void dispatchTrackClear(Track track, List<String> before) { public void dispatchTrackClear(Track track, List<String> before) {
post(TrackClearEvent.class, () -> generate(TrackClearEvent.class, track.getApiDelegate(), ImmutableList.copyOf(before), ImmutableList.of())); post(TrackClearEvent.class, () -> generate(TrackClearEvent.class, track.getApiProxy(), ImmutableList.copyOf(before), ImmutableList.of()));
} }
public void dispatchTrackRemoveGroup(Track track, String group, List<String> before, List<String> after) { public void dispatchTrackRemoveGroup(Track track, String group, List<String> before, List<String> after) {
post(TrackRemoveGroupEvent.class, () -> generate(TrackRemoveGroupEvent.class, track.getApiDelegate(), ImmutableList.copyOf(before), ImmutableList.copyOf(after), group)); post(TrackRemoveGroupEvent.class, () -> generate(TrackRemoveGroupEvent.class, track.getApiProxy(), ImmutableList.copyOf(before), ImmutableList.copyOf(after), group));
} }
public void dispatchUserCacheLoad(User user, UserCachedDataManager data) { public void dispatchUserCacheLoad(User user, UserCachedDataManager data) {
post(UserCacheLoadEvent.class, () -> generate(UserCacheLoadEvent.class, new ApiUser(user), data)); post(UserCacheLoadEvent.class, () -> generate(UserCacheLoadEvent.class, user.getApiProxy(), data));
} }
public void dispatchDataRecalculate(PermissionHolder holder) { public void dispatchDataRecalculate(PermissionHolder holder) {
if (holder.getType() == HolderType.USER) { if (holder.getType() == HolderType.USER) {
User user = (User) holder; User user = (User) holder;
post(UserDataRecalculateEvent.class, () -> generate(UserDataRecalculateEvent.class, user.getApiDelegate(), user.getCachedData())); post(UserDataRecalculateEvent.class, () -> generate(UserDataRecalculateEvent.class, user.getApiProxy(), user.getCachedData()));
} else { } else {
Group group = (Group) holder; Group group = (Group) holder;
post(GroupDataRecalculateEvent.class, () -> generate(GroupDataRecalculateEvent.class, group.getApiDelegate(), group.getCachedData())); post(GroupDataRecalculateEvent.class, () -> generate(GroupDataRecalculateEvent.class, group.getApiProxy(), group.getCachedData()));
} }
} }
@ -298,7 +297,7 @@ public final class EventDispatcher {
return; return;
} }
post(generate(PlayerLoginProcessEvent.class, uniqueId, username, new ApiUser(user))); post(generate(PlayerLoginProcessEvent.class, uniqueId, username, user.getApiProxy()));
} }
public void dispatchPlayerDataSave(UUID uniqueId, String username, PlayerSaveResult result) { public void dispatchPlayerDataSave(UUID uniqueId, String username, PlayerSaveResult result) {
@ -306,28 +305,28 @@ public final class EventDispatcher {
} }
public void dispatchUserLoad(User user) { public void dispatchUserLoad(User user) {
post(UserLoadEvent.class, () -> generate(UserLoadEvent.class, new ApiUser(user))); post(UserLoadEvent.class, () -> generate(UserLoadEvent.class, user.getApiProxy()));
} }
public void dispatchUserDemote(User user, Track track, String from, String to, @Nullable Sender source) { public void dispatchUserDemote(User user, Track track, String from, String to, @Nullable Sender source) {
post(UserDemoteEvent.class, () -> { post(UserDemoteEvent.class, () -> {
Source s = source == null ? UnknownSource.INSTANCE : new EntitySourceImpl(new SenderPlatformEntity(source)); Source s = source == null ? UnknownSource.INSTANCE : new EntitySourceImpl(new SenderPlatformEntity(source));
return generate(UserDemoteEvent.class, s, track.getApiDelegate(), new ApiUser(user), Optional.ofNullable(from), Optional.ofNullable(to)); return generate(UserDemoteEvent.class, s, track.getApiProxy(), user.getApiProxy(), Optional.ofNullable(from), Optional.ofNullable(to));
}); });
} }
public void dispatchUserPromote(User user, Track track, String from, String to, @Nullable Sender source) { public void dispatchUserPromote(User user, Track track, String from, String to, @Nullable Sender source) {
post(UserPromoteEvent.class, () -> { post(UserPromoteEvent.class, () -> {
Source s = source == null ? UnknownSource.INSTANCE : new EntitySourceImpl(new SenderPlatformEntity(source)); Source s = source == null ? UnknownSource.INSTANCE : new EntitySourceImpl(new SenderPlatformEntity(source));
return generate(UserPromoteEvent.class, s, track.getApiDelegate(), new ApiUser(user), Optional.ofNullable(from), Optional.ofNullable(to)); return generate(UserPromoteEvent.class, s, track.getApiProxy(), user.getApiProxy(), Optional.ofNullable(from), Optional.ofNullable(to));
}); });
} }
private static ApiPermissionHolder getDelegate(PermissionHolder holder) { private static ApiPermissionHolder proxy(PermissionHolder holder) {
if (holder instanceof Group) { if (holder instanceof Group) {
return ((Group) holder).getApiDelegate(); return ((Group) holder).getApiProxy();
} else if (holder instanceof User) { } else if (holder instanceof User) {
return new ApiUser(((User) holder)); return ((User) holder).getApiProxy();
} else { } else {
throw new AssertionError(); throw new AssertionError();
} }

View File

@ -41,7 +41,7 @@ import java.util.Optional;
import java.util.OptionalInt; import java.util.OptionalInt;
public class Group extends PermissionHolder { public class Group extends PermissionHolder {
private final ApiGroup apiDelegate = new ApiGroup(this); private final ApiGroup apiProxy = new ApiGroup(this);
/** /**
* The name of the group * The name of the group
@ -90,8 +90,8 @@ public class Group extends PermissionHolder {
return this.name; return this.name;
} }
public ApiGroup getApiDelegate() { public ApiGroup getApiProxy() {
return this.apiDelegate; return this.apiProxy;
} }
@Override @Override

View File

@ -68,7 +68,7 @@ public final class Track {
*/ */
private final List<String> groups = Collections.synchronizedList(new ArrayList<>()); private final List<String> groups = Collections.synchronizedList(new ArrayList<>());
private final ApiTrack apiDelegate = new ApiTrack(this); private final ApiTrack apiProxy = new ApiTrack(this);
public Track(String name, LuckPermsPlugin plugin) { public Track(String name, LuckPermsPlugin plugin) {
this.name = name; this.name = name;
@ -83,8 +83,8 @@ public final class Track {
return this.ioLock; return this.ioLock;
} }
public ApiTrack getApiDelegate() { public ApiTrack getApiProxy() {
return this.apiDelegate; return this.apiProxy;
} }
/** /**

View File

@ -36,7 +36,7 @@ import java.util.Optional;
import java.util.UUID; import java.util.UUID;
public class User extends PermissionHolder { public class User extends PermissionHolder {
private final ApiUser apiDelegate = new ApiUser(this); private final ApiUser apiProxy = new ApiUser(this);
/** /**
* The users Mojang UUID * The users Mojang UUID
@ -89,8 +89,8 @@ public class User extends PermissionHolder {
return getFormattedDisplayName(); return getFormattedDisplayName();
} }
public ApiUser getApiDelegate() { public ApiUser getApiProxy() {
return this.apiDelegate; return this.apiProxy;
} }
@Override @Override

View File

@ -29,8 +29,8 @@ import com.google.common.collect.ImmutableSet;
import me.lucko.luckperms.common.context.contextset.ContextImpl; import me.lucko.luckperms.common.context.contextset.ContextImpl;
import me.lucko.luckperms.common.context.contextset.ImmutableContextSetImpl; import me.lucko.luckperms.common.context.contextset.ImmutableContextSetImpl;
import me.lucko.luckperms.sponge.service.context.DelegatingContextSet; import me.lucko.luckperms.sponge.service.context.ForwardingContextSet;
import me.lucko.luckperms.sponge.service.context.DelegatingImmutableContextSet; import me.lucko.luckperms.sponge.service.context.ForwardingImmutableContextSet;
import net.luckperms.api.context.ContextSet; import net.luckperms.api.context.ContextSet;
import net.luckperms.api.context.ImmutableContextSet; import net.luckperms.api.context.ImmutableContextSet;
@ -53,8 +53,8 @@ public final class CompatibilityUtil {
public static ImmutableContextSet convertContexts(Set<Context> contexts) { public static ImmutableContextSet convertContexts(Set<Context> contexts) {
Objects.requireNonNull(contexts, "contexts"); Objects.requireNonNull(contexts, "contexts");
if (contexts instanceof DelegatingContextSet) { if (contexts instanceof ForwardingContextSet) {
return ((DelegatingContextSet) contexts).getDelegate().immutableCopy(); return ((ForwardingContextSet) contexts).delegate().immutableCopy();
} }
if (contexts.isEmpty()) { if (contexts.isEmpty()) {
@ -75,7 +75,7 @@ public final class CompatibilityUtil {
return EMPTY; return EMPTY;
} }
return new DelegatingImmutableContextSet(contexts.immutableCopy()); return new ForwardingImmutableContextSet(contexts.immutableCopy());
} }
public static org.spongepowered.api.util.Tristate convertTristate(Tristate tristate) { public static org.spongepowered.api.util.Tristate convertTristate(Tristate tristate) {

View File

@ -30,30 +30,30 @@ import org.spongepowered.api.service.context.Context;
import java.util.AbstractSet; import java.util.AbstractSet;
import java.util.Set; import java.util.Set;
abstract class AbstractDelegatingContextSet extends AbstractSet<Context> implements DelegatingContextSet { abstract class AbstractForwardingContextSet extends AbstractSet<Context> implements ForwardingContextSet {
@Override @Override
public int size() { public int size() {
return getDelegate().size(); return delegate().size();
} }
@Override @Override
public boolean isEmpty() { public boolean isEmpty() {
return getDelegate().isEmpty(); return delegate().isEmpty();
} }
@Override @Override
public boolean contains(Object o) { public boolean contains(Object o) {
if (o instanceof Context) { if (o instanceof Context) {
Context context = (Context) o; Context context = (Context) o;
return !context.getKey().isEmpty() && !context.getValue().isEmpty() && getDelegate().contains(context.getKey(), context.getValue()); return !context.getKey().isEmpty() && !context.getValue().isEmpty() && delegate().contains(context.getKey(), context.getValue());
} }
return false; return false;
} }
@Override @Override
public int hashCode() { public int hashCode() {
return getDelegate().hashCode(); return delegate().hashCode();
} }
@Override @Override
@ -62,8 +62,8 @@ abstract class AbstractDelegatingContextSet extends AbstractSet<Context> impleme
return true; return true;
} }
if (o instanceof DelegatingContextSet) { if (o instanceof ForwardingContextSet) {
return getDelegate().equals(((DelegatingContextSet) o).getDelegate()); return delegate().equals(((ForwardingContextSet) o).delegate());
} }
if (o instanceof Set) { if (o instanceof Set) {

View File

@ -1,128 +0,0 @@
/*
* This file is part of LuckPerms, licensed under the MIT License.
*
* Copyright (c) lucko (Luck) <luck@lucko.me>
* Copyright (c) contributors
*
* 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.sponge.service.context;
import me.lucko.luckperms.common.context.contextset.ContextImpl;
import net.luckperms.api.context.MutableContextSet;
import org.checkerframework.checker.nullness.qual.NonNull;
import org.spongepowered.api.service.context.Context;
import java.util.Iterator;
import java.util.Set;
/**
* Implements a {@link Set} of {@link Context}s, delegating all calls to a {@link MutableContextSet}.
*/
public class DelegatingMutableContextSet extends AbstractDelegatingContextSet {
private final MutableContextSet delegate;
public DelegatingMutableContextSet(MutableContextSet delegate) {
this.delegate = delegate;
}
@Override
public MutableContextSet getDelegate() {
return this.delegate;
}
@Override
public @NonNull Iterator<Context> iterator() {
return new ContextSetIterator();
}
@Override
public boolean add(Context context) {
if (context == null) {
throw new NullPointerException("context");
}
if (context.getKey().isEmpty() || context.getValue().isEmpty()) {
return false;
}
boolean has = this.delegate.contains(context.getKey(), context.getValue());
this.delegate.add(new ContextImpl(context.getKey(), context.getValue()));
return !has;
}
@Override
public boolean remove(Object o) {
if (o instanceof Context) {
Context context = (Context) o;
if (context.getKey().isEmpty() || context.getValue().isEmpty()) {
return false;
}
boolean had = this.delegate.contains(context.getKey(), context.getValue());
this.delegate.remove(context.getKey(), context.getValue());
return had;
}
return false;
}
@Override
public void clear() {
this.delegate.clear();
}
@Override
public String toString() {
return "DelegatingMutableContextSet(delegate=" + this.getDelegate() + ")";
}
private final class ContextSetIterator implements Iterator<Context> {
private final Iterator<net.luckperms.api.context.Context> it = DelegatingMutableContextSet.this.delegate.iterator();
private Context current;
@Override
public boolean hasNext() {
return this.it.hasNext();
}
@Override
public Context next() {
net.luckperms.api.context.Context next = this.it.next();
// track the iterators cursor to handle #remove calls
this.current = new Context(next.getKey(), next.getValue());
return this.current;
}
@Override
public void remove() {
Context c = this.current;
if (c == null) {
throw new IllegalStateException();
}
this.current = null;
// delegate the removal call to the MutableContextSet, as the iterator returned by
// toSet().iterator() is immutable
DelegatingMutableContextSet.this.delegate.remove(c.getKey(), c.getValue());
}
}
}

View File

@ -34,8 +34,8 @@ import java.util.Set;
/** /**
* Represents an object which is a {@link Set} of {@link Context}s, delegating all calls to a {@link ContextSet}. * Represents an object which is a {@link Set} of {@link Context}s, delegating all calls to a {@link ContextSet}.
*/ */
public interface DelegatingContextSet extends Set<Context> { public interface ForwardingContextSet extends Set<Context> {
ContextSet getDelegate(); ContextSet delegate();
} }

View File

@ -36,15 +36,15 @@ import java.util.Set;
/** /**
* Implements a {@link Set} of {@link Context}s, delegating all calls to a {@link ImmutableContextSet}. * Implements a {@link Set} of {@link Context}s, delegating all calls to a {@link ImmutableContextSet}.
*/ */
public class DelegatingImmutableContextSet extends AbstractDelegatingContextSet { public class ForwardingImmutableContextSet extends AbstractForwardingContextSet {
private final ImmutableContextSet delegate; private final ImmutableContextSet delegate;
public DelegatingImmutableContextSet(ImmutableContextSet delegate) { public ForwardingImmutableContextSet(ImmutableContextSet delegate) {
this.delegate = delegate; this.delegate = delegate;
} }
@Override @Override
public ImmutableContextSet getDelegate() { public ImmutableContextSet delegate() {
return this.delegate; return this.delegate;
} }
@ -70,11 +70,11 @@ public class DelegatingImmutableContextSet extends AbstractDelegatingContextSet
@Override @Override
public String toString() { public String toString() {
return "DelegatingImmutableContextSet(delegate=" + this.getDelegate() + ")"; return "ForwardingImmutableContextSet(delegate=" + this.delegate() + ")";
} }
private final class ContextSetIterator implements Iterator<Context> { private final class ContextSetIterator implements Iterator<Context> {
private final Iterator<net.luckperms.api.context.Context> it = DelegatingImmutableContextSet.this.delegate.iterator(); private final Iterator<net.luckperms.api.context.Context> it = ForwardingImmutableContextSet.this.delegate.iterator();
@Override @Override
public boolean hasNext() { public boolean hasNext() {

View File

@ -32,9 +32,9 @@ import me.lucko.luckperms.common.cache.LoadingMap;
import me.lucko.luckperms.common.context.ContextManager; import me.lucko.luckperms.common.context.ContextManager;
import me.lucko.luckperms.common.util.Predicates; import me.lucko.luckperms.common.util.Predicates;
import me.lucko.luckperms.sponge.LPSpongePlugin; import me.lucko.luckperms.sponge.LPSpongePlugin;
import me.lucko.luckperms.sponge.context.SpongeProxiedContextCalculator;
import me.lucko.luckperms.sponge.model.manager.SpongeGroupManager; import me.lucko.luckperms.sponge.model.manager.SpongeGroupManager;
import me.lucko.luckperms.sponge.model.manager.SpongeUserManager; import me.lucko.luckperms.sponge.model.manager.SpongeUserManager;
import me.lucko.luckperms.sponge.service.model.ContextCalculatorProxy;
import me.lucko.luckperms.sponge.service.model.LPPermissionDescription; import me.lucko.luckperms.sponge.service.model.LPPermissionDescription;
import me.lucko.luckperms.sponge.service.model.LPPermissionService; import me.lucko.luckperms.sponge.service.model.LPPermissionService;
import me.lucko.luckperms.sponge.service.model.LPSubject; import me.lucko.luckperms.sponge.service.model.LPSubject;
@ -225,7 +225,7 @@ public class LuckPermsService implements LPPermissionService {
@Override @Override
public void registerContextCalculator(ContextCalculator<Subject> calculator) { public void registerContextCalculator(ContextCalculator<Subject> calculator) {
Objects.requireNonNull(calculator); Objects.requireNonNull(calculator);
this.plugin.getContextManager().registerCalculator(new SpongeProxiedContextCalculator(calculator)); this.plugin.getContextManager().registerCalculator(new ContextCalculatorProxy(calculator));
} }
@Override @Override

View File

@ -23,9 +23,9 @@
* SOFTWARE. * SOFTWARE.
*/ */
package me.lucko.luckperms.sponge.context; package me.lucko.luckperms.sponge.service.model;
import me.lucko.luckperms.common.context.ProxiedContextCalculator; import me.lucko.luckperms.common.context.ForwardingContextCalculator;
import net.luckperms.api.context.ContextConsumer; import net.luckperms.api.context.ContextConsumer;
@ -38,27 +38,27 @@ import java.util.Collection;
import java.util.Iterator; import java.util.Iterator;
import java.util.Set; import java.util.Set;
public class SpongeProxiedContextCalculator implements ProxiedContextCalculator<Subject> { public class ContextCalculatorProxy implements ForwardingContextCalculator<Subject> {
private final ContextCalculator<Subject> delegate; private final ContextCalculator<Subject> delegate;
public SpongeProxiedContextCalculator(ContextCalculator<Subject> delegate) { public ContextCalculatorProxy(ContextCalculator<Subject> delegate) {
this.delegate = delegate; this.delegate = delegate;
} }
@Override @Override
public void calculate(@NonNull Subject subject, @NonNull ContextConsumer consumer) { public void calculate(@NonNull Subject subject, @NonNull ContextConsumer consumer) {
this.delegate.accumulateContexts(subject, new ProxiedContextSet(consumer)); this.delegate.accumulateContexts(subject, new ForwardingContextSet(consumer));
} }
@Override @Override
public Object getDelegate() { public Object delegate() {
return this.delegate; return this.delegate;
} }
private static final class ProxiedContextSet implements Set<Context> { private static final class ForwardingContextSet implements Set<Context> {
private final ContextConsumer consumer; private final ContextConsumer consumer;
private ProxiedContextSet(ContextConsumer consumer) { private ForwardingContextSet(ContextConsumer consumer) {
this.consumer = consumer; this.consumer = consumer;
} }