misc refactor for PermissionHolder & DummySender

This commit is contained in:
Luck 2018-01-12 23:51:59 +00:00
parent 3201d10bdd
commit 22006617d0
No known key found for this signature in database
GPG Key ID: EFA9B3EC5FD90F8B
5 changed files with 43 additions and 27 deletions

View File

@ -30,6 +30,7 @@ import com.google.common.collect.ImmutableSet;
import me.lucko.luckperms.common.commands.CommandManager;
import me.lucko.luckperms.common.commands.CommandResult;
import me.lucko.luckperms.common.commands.sender.DummySender;
import me.lucko.luckperms.common.commands.sender.Sender;
import me.lucko.luckperms.common.commands.utils.CommandUtils;
import me.lucko.luckperms.common.locale.Message;

View File

@ -23,11 +23,10 @@
* SOFTWARE.
*/
package me.lucko.luckperms.common.backup;
package me.lucko.luckperms.common.commands.sender;
import me.lucko.luckperms.api.Tristate;
import me.lucko.luckperms.common.commands.CommandManager;
import me.lucko.luckperms.common.commands.sender.Sender;
import me.lucko.luckperms.common.plugin.LuckPermsPlugin;
import me.lucko.luckperms.common.utils.TextUtils;

View File

@ -747,9 +747,11 @@ public abstract class PermissionHolder {
if (perms.putIfAbsent(perm, node.getValuePrimitive()) == null) {
if (applyShorthand) {
List<String> sh = node.resolveShorthand();
if (!sh.isEmpty()) {
sh.stream().map(s -> lowerCase ? s.toLowerCase() : s).forEach(s -> perms.putIfAbsent(s, node.getValuePrimitive()));
List<String> shorthand = node.resolveShorthand();
if (!shorthand.isEmpty()) {
for (String s : shorthand) {
perms.putIfAbsent(lowerCase ? s.toLowerCase() : s, node.getValuePrimitive());
}
}
}
}

View File

@ -28,6 +28,7 @@ package me.lucko.luckperms.common.utils;
import com.google.common.collect.ImmutableList;
import java.util.List;
import java.util.concurrent.atomic.AtomicInteger;
/**
* A cycle of elements, backed by a list. All operations are thread safe.
@ -35,45 +36,58 @@ import java.util.List;
* @param <E> the element type
*/
public class Cycle<E> {
protected final List<E> objects;
protected int index = 0;
/**
* The list that backs this instance
*/
private final List<E> objects;
/**
* The number of elements in the cycle
*/
private final int size;
/**
* The current position of the cursor
*/
private AtomicInteger cursor = new AtomicInteger(0);
public Cycle(List<E> objects) {
if (objects == null || objects.isEmpty()) {
throw new IllegalArgumentException("List of objects cannot be null/empty.");
}
this.objects = ImmutableList.copyOf(objects);
this.size = this.objects.size();
}
public int getIndex() {
return this.index;
public int cursor() {
return this.cursor.get();
}
public E current() {
synchronized (this) {
return this.objects.get(this.index);
}
return this.objects.get(cursor());
}
public E next() {
synchronized (this) {
this.index++;
this.index = this.index > this.objects.size() - 1 ? 0 : this.index;
return this.objects.get(this.index);
}
return this.objects.get(this.cursor.updateAndGet(i -> {
int n = i + 1;
if (n >= this.size) {
return 0;
}
return n;
}));
}
public E back() {
synchronized (this) {
this.index--;
this.index = this.index == -1 ? this.objects.size() - 1 : this.index;
return this.objects.get(this.index);
}
public E previous() {
return this.objects.get(this.cursor.updateAndGet(i -> {
if (i == 0) {
return this.size - 1;
}
return i - 1;
}));
}
public List<E> getBacking() {
return this.objects;
}
}
}

View File

@ -33,13 +33,13 @@ import me.lucko.luckperms.api.platform.PlatformType;
import me.lucko.luckperms.common.actionlog.LogDispatcher;
import me.lucko.luckperms.common.api.ApiRegistrationUtil;
import me.lucko.luckperms.common.api.LuckPermsApiProvider;
import me.lucko.luckperms.common.backup.DummySender;
import me.lucko.luckperms.common.buffers.BufferedRequest;
import me.lucko.luckperms.common.buffers.UpdateTaskBuffer;
import me.lucko.luckperms.common.caching.handlers.CachedStateManager;
import me.lucko.luckperms.common.calculators.CalculatorFactory;
import me.lucko.luckperms.common.commands.CommandPermission;
import me.lucko.luckperms.common.commands.abstraction.Command;
import me.lucko.luckperms.common.commands.sender.DummySender;
import me.lucko.luckperms.common.commands.sender.Sender;
import me.lucko.luckperms.common.config.AbstractConfiguration;
import me.lucko.luckperms.common.config.ConfigKeys;