mirror of
https://github.com/LuckPerms/LuckPerms.git
synced 2024-12-29 12:37:40 +01:00
Rename some classes
This commit is contained in:
parent
c98c60b120
commit
2028d65579
@ -36,6 +36,6 @@ public abstract class ApiAbstractManager<I, E, H> {
|
||||
this.handle = handle;
|
||||
}
|
||||
|
||||
protected abstract E getDelegateFor(I internal);
|
||||
protected abstract E proxy(I internal);
|
||||
|
||||
}
|
||||
|
@ -51,25 +51,21 @@ public class ApiGroupManager extends ApiAbstractManager<Group, net.luckperms.api
|
||||
}
|
||||
|
||||
@Override
|
||||
protected net.luckperms.api.model.group.Group getDelegateFor(me.lucko.luckperms.common.model.Group internal) {
|
||||
if (internal == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return internal.getApiDelegate();
|
||||
protected net.luckperms.api.model.group.Group proxy(me.lucko.luckperms.common.model.Group internal) {
|
||||
return internal == null ? null : internal.getApiProxy();
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NonNull CompletableFuture<net.luckperms.api.model.group.Group> createAndLoadGroup(@NonNull String name) {
|
||||
name = ApiUtils.checkName(Objects.requireNonNull(name, "name"));
|
||||
return this.plugin.getStorage().createAndLoadGroup(name, CreationCause.API)
|
||||
.thenApply(this::getDelegateFor);
|
||||
.thenApply(this::proxy);
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NonNull CompletableFuture<Optional<net.luckperms.api.model.group.Group>> loadGroup(@NonNull String 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
|
||||
@ -102,13 +98,13 @@ public class ApiGroupManager extends ApiAbstractManager<Group, net.luckperms.api
|
||||
@Override
|
||||
public net.luckperms.api.model.group.Group getGroup(@NonNull String name) {
|
||||
Objects.requireNonNull(name, "name");
|
||||
return getDelegateFor(this.handle.getIfLoaded(name));
|
||||
return proxy(this.handle.getIfLoaded(name));
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NonNull Set<net.luckperms.api.model.group.Group> getLoadedGroups() {
|
||||
return this.handle.getAll().values().stream()
|
||||
.map(this::getDelegateFor)
|
||||
.map(this::proxy)
|
||||
.collect(ImmutableCollectors.toSet());
|
||||
}
|
||||
|
||||
|
@ -47,25 +47,21 @@ public class ApiTrackManager extends ApiAbstractManager<Track, net.luckperms.api
|
||||
}
|
||||
|
||||
@Override
|
||||
protected net.luckperms.api.track.Track getDelegateFor(Track internal) {
|
||||
if (internal == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return internal.getApiDelegate();
|
||||
protected net.luckperms.api.track.Track proxy(Track internal) {
|
||||
return internal == null ? null : internal.getApiProxy();
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NonNull CompletableFuture<net.luckperms.api.track.Track> createAndLoadTrack(@NonNull String name) {
|
||||
name = ApiUtils.checkName(Objects.requireNonNull(name, "name"));
|
||||
return this.plugin.getStorage().createAndLoadTrack(name, CreationCause.API)
|
||||
.thenApply(this::getDelegateFor);
|
||||
.thenApply(this::proxy);
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NonNull CompletableFuture<Optional<net.luckperms.api.track.Track>> loadTrack(@NonNull String 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
|
||||
@ -88,13 +84,13 @@ public class ApiTrackManager extends ApiAbstractManager<Track, net.luckperms.api
|
||||
@Override
|
||||
public net.luckperms.api.track.Track getTrack(@NonNull String name) {
|
||||
Objects.requireNonNull(name, "name");
|
||||
return getDelegateFor(this.handle.getIfLoaded(name));
|
||||
return proxy(this.handle.getIfLoaded(name));
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NonNull Set<net.luckperms.api.track.Track> getLoadedTracks() {
|
||||
return this.handle.getAll().values().stream()
|
||||
.map(this::getDelegateFor)
|
||||
.map(this::proxy)
|
||||
.collect(ImmutableCollectors.toSet());
|
||||
}
|
||||
|
||||
|
@ -51,11 +51,8 @@ public class ApiUserManager extends ApiAbstractManager<User, net.luckperms.api.m
|
||||
}
|
||||
|
||||
@Override
|
||||
protected net.luckperms.api.model.user.User getDelegateFor(User internal) {
|
||||
if (internal == null) {
|
||||
return null;
|
||||
}
|
||||
return new ApiUser(internal);
|
||||
protected net.luckperms.api.model.user.User proxy(User internal) {
|
||||
return internal == null ? null : internal.getApiProxy();
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -68,7 +65,7 @@ public class ApiUserManager extends ApiAbstractManager<User, net.luckperms.api.m
|
||||
}
|
||||
|
||||
return this.plugin.getStorage().loadUser(uniqueId, username)
|
||||
.thenApply(this::getDelegateFor);
|
||||
.thenApply(this::proxy);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -110,19 +107,19 @@ public class ApiUserManager extends ApiAbstractManager<User, net.luckperms.api.m
|
||||
@Override
|
||||
public net.luckperms.api.model.user.User getUser(@NonNull UUID uniqueId) {
|
||||
Objects.requireNonNull(uniqueId, "uuid");
|
||||
return getDelegateFor(this.handle.getIfLoaded(uniqueId));
|
||||
return proxy(this.handle.getIfLoaded(uniqueId));
|
||||
}
|
||||
|
||||
@Override
|
||||
public net.luckperms.api.model.user.User getUser(@NonNull String username) {
|
||||
Objects.requireNonNull(username, "name");
|
||||
return getDelegateFor(this.handle.getByUsername(username));
|
||||
return proxy(this.handle.getByUsername(username));
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NonNull Set<net.luckperms.api.model.user.User> getLoadedUsers() {
|
||||
return this.handle.getAll().values().stream()
|
||||
.map(this::getDelegateFor)
|
||||
.map(this::proxy)
|
||||
.collect(ImmutableCollectors.toSet());
|
||||
}
|
||||
|
||||
|
@ -165,8 +165,8 @@ public abstract class ContextManager<T> {
|
||||
|
||||
private static String getCalculatorClass(ContextCalculator<?> calculator) {
|
||||
Class<?> calculatorClass;
|
||||
if (calculator instanceof ProxiedContextCalculator) {
|
||||
calculatorClass = ((ProxiedContextCalculator<?>) calculator).getDelegate().getClass();
|
||||
if (calculator instanceof ForwardingContextCalculator) {
|
||||
calculatorClass = ((ForwardingContextCalculator<?>) calculator).delegate().getClass();
|
||||
} else {
|
||||
calculatorClass = calculator.getClass();
|
||||
}
|
||||
|
@ -30,8 +30,8 @@ import net.luckperms.api.context.ContextCalculator;
|
||||
/**
|
||||
* 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();
|
||||
|
||||
}
|
@ -29,7 +29,6 @@ import com.google.common.collect.ImmutableList;
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
|
||||
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.UserCachedDataManager;
|
||||
import me.lucko.luckperms.common.event.gen.GeneratedEventClass;
|
||||
@ -144,11 +143,11 @@ public final class EventDispatcher {
|
||||
}
|
||||
|
||||
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) {
|
||||
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) {
|
||||
@ -160,7 +159,7 @@ public final class EventDispatcher {
|
||||
}
|
||||
|
||||
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) {
|
||||
@ -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) {
|
||||
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) {
|
||||
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) {
|
||||
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() {
|
||||
@ -248,7 +247,7 @@ public final class EventDispatcher {
|
||||
}
|
||||
|
||||
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) {
|
||||
@ -260,32 +259,32 @@ public final class EventDispatcher {
|
||||
}
|
||||
|
||||
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) {
|
||||
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) {
|
||||
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) {
|
||||
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) {
|
||||
post(UserCacheLoadEvent.class, () -> generate(UserCacheLoadEvent.class, new ApiUser(user), data));
|
||||
post(UserCacheLoadEvent.class, () -> generate(UserCacheLoadEvent.class, user.getApiProxy(), data));
|
||||
}
|
||||
|
||||
public void dispatchDataRecalculate(PermissionHolder holder) {
|
||||
if (holder.getType() == HolderType.USER) {
|
||||
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 {
|
||||
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;
|
||||
}
|
||||
|
||||
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) {
|
||||
@ -306,28 +305,28 @@ public final class EventDispatcher {
|
||||
}
|
||||
|
||||
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) {
|
||||
post(UserDemoteEvent.class, () -> {
|
||||
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) {
|
||||
post(UserPromoteEvent.class, () -> {
|
||||
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) {
|
||||
return ((Group) holder).getApiDelegate();
|
||||
return ((Group) holder).getApiProxy();
|
||||
} else if (holder instanceof User) {
|
||||
return new ApiUser(((User) holder));
|
||||
return ((User) holder).getApiProxy();
|
||||
} else {
|
||||
throw new AssertionError();
|
||||
}
|
||||
|
@ -41,7 +41,7 @@ import java.util.Optional;
|
||||
import java.util.OptionalInt;
|
||||
|
||||
public class Group extends PermissionHolder {
|
||||
private final ApiGroup apiDelegate = new ApiGroup(this);
|
||||
private final ApiGroup apiProxy = new ApiGroup(this);
|
||||
|
||||
/**
|
||||
* The name of the group
|
||||
@ -90,8 +90,8 @@ public class Group extends PermissionHolder {
|
||||
return this.name;
|
||||
}
|
||||
|
||||
public ApiGroup getApiDelegate() {
|
||||
return this.apiDelegate;
|
||||
public ApiGroup getApiProxy() {
|
||||
return this.apiProxy;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -68,7 +68,7 @@ public final class Track {
|
||||
*/
|
||||
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) {
|
||||
this.name = name;
|
||||
@ -83,8 +83,8 @@ public final class Track {
|
||||
return this.ioLock;
|
||||
}
|
||||
|
||||
public ApiTrack getApiDelegate() {
|
||||
return this.apiDelegate;
|
||||
public ApiTrack getApiProxy() {
|
||||
return this.apiProxy;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -36,7 +36,7 @@ import java.util.Optional;
|
||||
import java.util.UUID;
|
||||
|
||||
public class User extends PermissionHolder {
|
||||
private final ApiUser apiDelegate = new ApiUser(this);
|
||||
private final ApiUser apiProxy = new ApiUser(this);
|
||||
|
||||
/**
|
||||
* The users Mojang UUID
|
||||
@ -89,8 +89,8 @@ public class User extends PermissionHolder {
|
||||
return getFormattedDisplayName();
|
||||
}
|
||||
|
||||
public ApiUser getApiDelegate() {
|
||||
return this.apiDelegate;
|
||||
public ApiUser getApiProxy() {
|
||||
return this.apiProxy;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -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.ImmutableContextSetImpl;
|
||||
import me.lucko.luckperms.sponge.service.context.DelegatingContextSet;
|
||||
import me.lucko.luckperms.sponge.service.context.DelegatingImmutableContextSet;
|
||||
import me.lucko.luckperms.sponge.service.context.ForwardingContextSet;
|
||||
import me.lucko.luckperms.sponge.service.context.ForwardingImmutableContextSet;
|
||||
|
||||
import net.luckperms.api.context.ContextSet;
|
||||
import net.luckperms.api.context.ImmutableContextSet;
|
||||
@ -53,8 +53,8 @@ public final class CompatibilityUtil {
|
||||
public static ImmutableContextSet convertContexts(Set<Context> contexts) {
|
||||
Objects.requireNonNull(contexts, "contexts");
|
||||
|
||||
if (contexts instanceof DelegatingContextSet) {
|
||||
return ((DelegatingContextSet) contexts).getDelegate().immutableCopy();
|
||||
if (contexts instanceof ForwardingContextSet) {
|
||||
return ((ForwardingContextSet) contexts).delegate().immutableCopy();
|
||||
}
|
||||
|
||||
if (contexts.isEmpty()) {
|
||||
@ -75,7 +75,7 @@ public final class CompatibilityUtil {
|
||||
return EMPTY;
|
||||
}
|
||||
|
||||
return new DelegatingImmutableContextSet(contexts.immutableCopy());
|
||||
return new ForwardingImmutableContextSet(contexts.immutableCopy());
|
||||
}
|
||||
|
||||
public static org.spongepowered.api.util.Tristate convertTristate(Tristate tristate) {
|
||||
|
@ -30,30 +30,30 @@ import org.spongepowered.api.service.context.Context;
|
||||
import java.util.AbstractSet;
|
||||
import java.util.Set;
|
||||
|
||||
abstract class AbstractDelegatingContextSet extends AbstractSet<Context> implements DelegatingContextSet {
|
||||
abstract class AbstractForwardingContextSet extends AbstractSet<Context> implements ForwardingContextSet {
|
||||
|
||||
@Override
|
||||
public int size() {
|
||||
return getDelegate().size();
|
||||
return delegate().size();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isEmpty() {
|
||||
return getDelegate().isEmpty();
|
||||
return delegate().isEmpty();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean contains(Object o) {
|
||||
if (o instanceof Context) {
|
||||
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;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return getDelegate().hashCode();
|
||||
return delegate().hashCode();
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -62,8 +62,8 @@ abstract class AbstractDelegatingContextSet extends AbstractSet<Context> impleme
|
||||
return true;
|
||||
}
|
||||
|
||||
if (o instanceof DelegatingContextSet) {
|
||||
return getDelegate().equals(((DelegatingContextSet) o).getDelegate());
|
||||
if (o instanceof ForwardingContextSet) {
|
||||
return delegate().equals(((ForwardingContextSet) o).delegate());
|
||||
}
|
||||
|
||||
if (o instanceof Set) {
|
@ -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());
|
||||
}
|
||||
}
|
||||
}
|
@ -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}.
|
||||
*/
|
||||
public interface DelegatingContextSet extends Set<Context> {
|
||||
public interface ForwardingContextSet extends Set<Context> {
|
||||
|
||||
ContextSet getDelegate();
|
||||
ContextSet delegate();
|
||||
|
||||
}
|
@ -36,15 +36,15 @@ import java.util.Set;
|
||||
/**
|
||||
* 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;
|
||||
|
||||
public DelegatingImmutableContextSet(ImmutableContextSet delegate) {
|
||||
public ForwardingImmutableContextSet(ImmutableContextSet delegate) {
|
||||
this.delegate = delegate;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ImmutableContextSet getDelegate() {
|
||||
public ImmutableContextSet delegate() {
|
||||
return this.delegate;
|
||||
}
|
||||
|
||||
@ -70,11 +70,11 @@ public class DelegatingImmutableContextSet extends AbstractDelegatingContextSet
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "DelegatingImmutableContextSet(delegate=" + this.getDelegate() + ")";
|
||||
return "ForwardingImmutableContextSet(delegate=" + this.delegate() + ")";
|
||||
}
|
||||
|
||||
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
|
||||
public boolean hasNext() {
|
@ -32,9 +32,9 @@ import me.lucko.luckperms.common.cache.LoadingMap;
|
||||
import me.lucko.luckperms.common.context.ContextManager;
|
||||
import me.lucko.luckperms.common.util.Predicates;
|
||||
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.SpongeUserManager;
|
||||
import me.lucko.luckperms.sponge.service.model.ContextCalculatorProxy;
|
||||
import me.lucko.luckperms.sponge.service.model.LPPermissionDescription;
|
||||
import me.lucko.luckperms.sponge.service.model.LPPermissionService;
|
||||
import me.lucko.luckperms.sponge.service.model.LPSubject;
|
||||
@ -225,7 +225,7 @@ public class LuckPermsService implements LPPermissionService {
|
||||
@Override
|
||||
public void registerContextCalculator(ContextCalculator<Subject> calculator) {
|
||||
Objects.requireNonNull(calculator);
|
||||
this.plugin.getContextManager().registerCalculator(new SpongeProxiedContextCalculator(calculator));
|
||||
this.plugin.getContextManager().registerCalculator(new ContextCalculatorProxy(calculator));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -23,9 +23,9 @@
|
||||
* 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;
|
||||
|
||||
@ -38,27 +38,27 @@ import java.util.Collection;
|
||||
import java.util.Iterator;
|
||||
import java.util.Set;
|
||||
|
||||
public class SpongeProxiedContextCalculator implements ProxiedContextCalculator<Subject> {
|
||||
public class ContextCalculatorProxy implements ForwardingContextCalculator<Subject> {
|
||||
private final ContextCalculator<Subject> delegate;
|
||||
|
||||
public SpongeProxiedContextCalculator(ContextCalculator<Subject> delegate) {
|
||||
public ContextCalculatorProxy(ContextCalculator<Subject> delegate) {
|
||||
this.delegate = delegate;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void calculate(@NonNull Subject subject, @NonNull ContextConsumer consumer) {
|
||||
this.delegate.accumulateContexts(subject, new ProxiedContextSet(consumer));
|
||||
this.delegate.accumulateContexts(subject, new ForwardingContextSet(consumer));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getDelegate() {
|
||||
public Object 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 ProxiedContextSet(ContextConsumer consumer) {
|
||||
private ForwardingContextSet(ContextConsumer consumer) {
|
||||
this.consumer = consumer;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user