Some misc refactoring / code cleanup

This commit is contained in:
Luck 2019-01-07 15:08:13 +00:00
parent c396323308
commit ec7a5321a6
No known key found for this signature in database
GPG Key ID: EFA9B3EC5FD90F8B
20 changed files with 29 additions and 41 deletions

View File

@ -91,7 +91,6 @@ public class MigrationPermissionsEx extends SubCommand<Object> {
super(CommandSpec.MIGRATION_COMMAND.localize(locale), "permissionsex", CommandPermission.MIGRATION, Predicates.alwaysFalse()); super(CommandSpec.MIGRATION_COMMAND.localize(locale), "permissionsex", CommandPermission.MIGRATION, Predicates.alwaysFalse());
} }
@SuppressWarnings("deprecation")
@Override @Override
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, Object o, List<String> args, String label) { public CommandResult execute(LuckPermsPlugin plugin, Sender sender, Object o, List<String> args, String label) {
ProgressLogger log = new ProgressLogger(Message.MIGRATION_LOG, Message.MIGRATION_LOG_PROGRESS, "PermissionsEx"); ProgressLogger log = new ProgressLogger(Message.MIGRATION_LOG, Message.MIGRATION_LOG_PROGRESS, "PermissionsEx");
@ -187,7 +186,6 @@ public class MigrationPermissionsEx extends SubCommand<Object> {
private static Map<String, List<String>> getPermanentPermissions(PermissionEntity entity) { private static Map<String, List<String>> getPermanentPermissions(PermissionEntity entity) {
try { try {
//noinspection unchecked
PermissionsData data = (PermissionsData) GET_DATA_METHOD.invoke(entity); PermissionsData data = (PermissionsData) GET_DATA_METHOD.invoke(entity);
return data.getPermissionsMap(); return data.getPermissionsMap();
} catch (IllegalAccessException | InvocationTargetException e) { } catch (IllegalAccessException | InvocationTargetException e) {

View File

@ -65,6 +65,8 @@ public class MetaAccumulator {
private enum State { private enum State {
/** Marks that the accumulator is still gaining (accumulating) new data. */ /** Marks that the accumulator is still gaining (accumulating) new data. */
ACCUMULATING, ACCUMULATING,
/** Marks that this accumulator is being completed. */
COMPLETING,
/** Marks that the process of gaining (accumulating) new data is complete. */ /** Marks that the process of gaining (accumulating) new data is complete. */
COMPLETE COMPLETE
} }
@ -102,7 +104,7 @@ public class MetaAccumulator {
* data is read. * data is read.
*/ */
public void complete() { public void complete() {
if (!this.state.compareAndSet(State.ACCUMULATING, State.COMPLETE)) { if (!this.state.compareAndSet(State.ACCUMULATING, State.COMPLETING)) {
return; return;
} }
@ -110,6 +112,8 @@ public class MetaAccumulator {
if (!this.meta.containsKey(NodeTypes.WEIGHT_KEY) && this.weight != 0) { if (!this.meta.containsKey(NodeTypes.WEIGHT_KEY) && this.weight != 0) {
this.meta.put(NodeTypes.WEIGHT_KEY, String.valueOf(this.weight)); this.meta.put(NodeTypes.WEIGHT_KEY, String.valueOf(this.weight));
} }
this.state.set(State.COMPLETE);
} }
// accumulate methods // accumulate methods

View File

@ -71,7 +71,7 @@ public class PermissionCheckInherits extends SharedSubCommand {
} }
String s = MessageUtils.formatTristate(result.getResult()); String s = MessageUtils.formatTristate(result.getResult());
Message.CHECK_INHERITS_PERMISSION.send(sender, holder.getFormattedDisplayName(), node, s, MessageUtils.contextSetToString(plugin.getLocaleManager(), context), String.valueOf(location)); Message.CHECK_INHERITS_PERMISSION.send(sender, holder.getFormattedDisplayName(), node, s, MessageUtils.contextSetToString(plugin.getLocaleManager(), context), location);
return CommandResult.SUCCESS; return CommandResult.SUCCESS;
} }

View File

@ -97,7 +97,7 @@ public class TreeCommand extends SingleCommand {
Message.TREE_URL.send(sender); Message.TREE_URL.send(sender);
Component message = TextComponent.builder(url).color(TextColor.AQUA) Component message = TextComponent.builder(url).color(TextColor.AQUA)
.clickEvent(new ClickEvent(ClickEvent.Action.OPEN_URL, String.valueOf(url))) .clickEvent(new ClickEvent(ClickEvent.Action.OPEN_URL, url))
.hoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, TextComponent.of("Click to open the tree view.").color(TextColor.GRAY))) .hoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, TextComponent.of("Click to open the tree view.").color(TextColor.GRAY)))
.build(); .build();

View File

@ -118,7 +118,7 @@ public class VerboseCommand extends SingleCommand {
Message.VERBOSE_RESULTS_URL.send(sender); Message.VERBOSE_RESULTS_URL.send(sender);
Component message = TextComponent.builder(url).color(TextColor.AQUA) Component message = TextComponent.builder(url).color(TextColor.AQUA)
.clickEvent(new ClickEvent(ClickEvent.Action.OPEN_URL, String.valueOf(url))) .clickEvent(new ClickEvent(ClickEvent.Action.OPEN_URL, url))
.hoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, TextComponent.of("Click to open the results page.").color(TextColor.GRAY))) .hoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, TextComponent.of("Click to open the results page.").color(TextColor.GRAY)))
.build(); .build();

View File

@ -54,7 +54,6 @@ public class UserInfo extends SubCommand<User> {
super(CommandSpec.USER_INFO.localize(locale), "info", CommandPermission.USER_INFO, Predicates.alwaysFalse()); super(CommandSpec.USER_INFO.localize(locale), "info", CommandPermission.USER_INFO, Predicates.alwaysFalse());
} }
@SuppressWarnings("unchecked")
@Override @Override
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, User user, List<String> args, String label) { public CommandResult execute(LuckPermsPlugin plugin, Sender sender, User user, List<String> args, String label) {
if (ArgumentPermissions.checkViewPerms(plugin, sender, getPermission().get(), user)) { if (ArgumentPermissions.checkViewPerms(plugin, sender, getPermission().get(), user)) {

View File

@ -196,7 +196,6 @@ public abstract class ContextManager<T> {
for (ContextCalculator<? super T> calculator : ContextManager.this.calculators) { for (ContextCalculator<? super T> calculator : ContextManager.this.calculators) {
try { try {
MutableContextSet ret = calculator.giveApplicableContext(subject, accumulator); MutableContextSet ret = calculator.giveApplicableContext(subject, accumulator);
//noinspection ConstantConditions
if (ret == null) { if (ret == null) {
throw new IllegalStateException(calculator.getClass() + " returned a null context set"); throw new IllegalStateException(calculator.getClass() + " returned a null context set");
} }
@ -216,7 +215,6 @@ public abstract class ContextManager<T> {
for (StaticContextCalculator calculator : this.staticCalculators) { for (StaticContextCalculator calculator : this.staticCalculators) {
try { try {
MutableContextSet ret = calculator.giveApplicableContext(accumulator); MutableContextSet ret = calculator.giveApplicableContext(accumulator);
//noinspection ConstantConditions
if (ret == null) { if (ret == null) {
throw new IllegalStateException(calculator.getClass() + " returned a null context set"); throw new IllegalStateException(calculator.getClass() + " returned a null context set");
} }

View File

@ -75,7 +75,7 @@ public class LocaleManager {
EnumMap<Message, String> messages = new EnumMap<>(Message.class); EnumMap<Message, String> messages = new EnumMap<>(Message.class);
EnumMap<CommandSpec, CommandSpecData> commands = new EnumMap<>(CommandSpec.class); EnumMap<CommandSpec, CommandSpecData> commands = new EnumMap<>(CommandSpec.class);
Map<String, Object> data = (Map<String, Object>) new Yaml().load(reader); Map<String, Object> data = new Yaml().load(reader);
for (Map.Entry<String, Object> entry : data.entrySet()) { for (Map.Entry<String, Object> entry : data.entrySet()) {
if (entry.getKey() == null || entry.getKey().isEmpty() || entry.getValue() == null) { if (entry.getKey() == null || entry.getKey().isEmpty() || entry.getValue() == null) {
continue; continue;

View File

@ -327,8 +327,8 @@ public final class ImmutableNode implements Node {
o1.permission == o2.permission && o1.permission == o2.permission &&
o1.value == o2.value && o1.value == o2.value &&
o1.override == o2.override && o1.override == o2.override &&
(o1.server == null ? o2.server == null : o1.server.equals(o2.server)) && Objects.equals(o1.server, o2.server) &&
(o1.world == null ? o2.world == null : o1.world.equals(o2.world)) && Objects.equals(o1.world, o2.world) &&
o1.expireAt == o2.expireAt && o1.expireAt == o2.expireAt &&
o1.getContexts().equals(o2.getContexts()); o1.getContexts().equals(o2.getContexts());
} }
@ -339,8 +339,8 @@ public final class ImmutableNode implements Node {
return o1 == o2 || return o1 == o2 ||
o1.permission == o2.permission && o1.permission == o2.permission &&
o1.override == o2.override && o1.override == o2.override &&
(o1.server == null ? o2.server == null : o1.server.equals(o2.server)) && Objects.equals(o1.server, o2.server) &&
(o1.world == null ? o2.world == null : o1.world.equals(o2.world)) && Objects.equals(o1.world, o2.world) &&
o1.expireAt == o2.expireAt && o1.expireAt == o2.expireAt &&
o1.getContexts().equals(o2.getContexts()); o1.getContexts().equals(o2.getContexts());
} }
@ -352,8 +352,8 @@ public final class ImmutableNode implements Node {
o1.permission == o2.permission && o1.permission == o2.permission &&
o1.value == o2.value && o1.value == o2.value &&
o1.override == o2.override && o1.override == o2.override &&
(o1.server == null ? o2.server == null : o1.server.equals(o2.server)) && Objects.equals(o1.server, o2.server) &&
(o1.world == null ? o2.world == null : o1.world.equals(o2.world)) && Objects.equals(o1.world, o2.world) &&
o1.isTemporary() == o2.isTemporary() && o1.isTemporary() == o2.isTemporary() &&
o1.getContexts().equals(o2.getContexts()); o1.getContexts().equals(o2.getContexts());
} }
@ -364,8 +364,8 @@ public final class ImmutableNode implements Node {
return o1 == o2 || return o1 == o2 ||
o1.permission == o2.permission && o1.permission == o2.permission &&
o1.override == o2.override && o1.override == o2.override &&
(o1.server == null ? o2.server == null : o1.server.equals(o2.server)) && Objects.equals(o1.server, o2.server) &&
(o1.world == null ? o2.world == null : o1.world.equals(o2.world)) && Objects.equals(o1.world, o2.world) &&
o1.isTemporary() == o2.isTemporary() && o1.isTemporary() == o2.isTemporary() &&
o1.getContexts().equals(o2.getContexts()); o1.getContexts().equals(o2.getContexts());
} }
@ -376,8 +376,8 @@ public final class ImmutableNode implements Node {
return o1 == o2 || return o1 == o2 ||
o1.permission == o2.permission && o1.permission == o2.permission &&
o1.override == o2.override && o1.override == o2.override &&
(o1.server == null ? o2.server == null : o1.server.equals(o2.server)) && Objects.equals(o1.server, o2.server) &&
(o1.world == null ? o2.world == null : o1.world.equals(o2.world)) && Objects.equals(o1.world, o2.world) &&
o1.getContexts().equals(o2.getContexts()); o1.getContexts().equals(o2.getContexts());
} }
}; };

View File

@ -71,15 +71,13 @@ public final class NodeHeldPermission<T extends Comparable<T>> implements HeldPe
return this.node.getWorld(); return this.node.getWorld();
} }
@NonNull
@Override @Override
public OptionalLong getExpiry() { public @NonNull OptionalLong getExpiry() {
return this.node.isTemporary() ? OptionalLong.of(this.node.getExpiryUnixTime()) : OptionalLong.empty(); return this.node.isTemporary() ? OptionalLong.of(this.node.getExpiryUnixTime()) : OptionalLong.empty();
} }
@NonNull
@Override @Override
public ContextSet getContexts() { public @NonNull ContextSet getContexts() {
return this.node.getContexts(); return this.node.getContexts();
} }

View File

@ -91,7 +91,6 @@ public final class AbstractSender<T> implements Sender {
} }
} }
@SuppressWarnings("deprecation")
@Override @Override
public void sendMessage(Component message) { public void sendMessage(Component message) {
if (isConsole()) { if (isConsole()) {

View File

@ -56,7 +56,6 @@ public abstract class DummySender implements Sender {
consumeMessage(message); consumeMessage(message);
} }
@SuppressWarnings("deprecation")
@Override @Override
public void sendMessage(Component message) { public void sendMessage(Component message) {
consumeMessage(TextUtils.toLegacy(message)); consumeMessage(TextUtils.toLegacy(message));

View File

@ -63,7 +63,6 @@ public final class ImmutableCollectors {
} }
public static <T extends Enum<T>> Collector<T, EnumSet<T>, ImmutableSet<T>> toEnumSet(Class<T> clazz) { public static <T extends Enum<T>> Collector<T, EnumSet<T>, ImmutableSet<T>> toEnumSet(Class<T> clazz) {
//noinspection unchecked
return Collector.of( return Collector.of(
() -> EnumSet.noneOf(clazz), () -> EnumSet.noneOf(clazz),
EnumSet::add, EnumSet::add,

View File

@ -63,6 +63,7 @@ public class LoadingMap<K, V> extends ForwardingMap<K, V> implements Map<K, V> {
if (value != null) { if (value != null) {
return value; return value;
} }
//noinspection unchecked
return this.map.computeIfAbsent((K) key, this.function); return this.map.computeIfAbsent((K) key, this.function);
} }
} }

View File

@ -79,7 +79,6 @@ public class VerboseHandler extends RepeatingTask {
return; return;
} }
//noinspection ThrowableNotThrown
StackTraceElement[] trace = new Exception().getStackTrace(); StackTraceElement[] trace = new Exception().getStackTrace();
// add the check data to a queue to be processed later. // add the check data to a queue to be processed later.
@ -104,7 +103,6 @@ public class VerboseHandler extends RepeatingTask {
return; return;
} }
//noinspection ThrowableNotThrown
StackTraceElement[] trace = new Exception().getStackTrace(); StackTraceElement[] trace = new Exception().getStackTrace();
// add the check data to a queue to be processed later. // add the check data to a queue to be processed later.

View File

@ -115,8 +115,8 @@ public final class DescriptionBuilder implements PermissionDescription.Builder,
return this.container.equals(other.container) && return this.container.equals(other.container) &&
this.roles.equals(other.roles) && this.roles.equals(other.roles) &&
(this.id == null ? other.id == null : this.id.equals(other.id)) && Objects.equals(this.id, other.id) &&
(this.description == null ? other.description == null : this.description.equals(other.description)); Objects.equals(this.description, other.description);
} }
@Override @Override

View File

@ -114,8 +114,8 @@ public final class DescriptionBuilder implements PermissionDescription.Builder,
return this.container.equals(other.container) && return this.container.equals(other.container) &&
this.roles.equals(other.roles) && this.roles.equals(other.roles) &&
(this.id == null ? other.id == null : this.id.equals(other.id)) && Objects.equals(this.id, other.id) &&
(this.description == null ? other.description == null : this.description.equals(other.description)); Objects.equals(this.description, other.description);
} }
@Override @Override

View File

@ -45,7 +45,6 @@ public final class ProxyFactory {
private static final boolean IS_API_7 = isApi7(); private static final boolean IS_API_7 = isApi7();
private static boolean isApi7() { private static boolean isApi7() {
try { try {
//noinspection JavaReflectionMemberAccess
Subject.class.getDeclaredMethod("asSubjectReference"); Subject.class.getDeclaredMethod("asSubjectReference");
return true; return true;
} catch (NoSuchMethodException e) { } catch (NoSuchMethodException e) {

View File

@ -240,11 +240,7 @@ public class CalculatedSubjectData implements LPSubjectData {
// flatten // flatten
Set<LPSubjectReference> result = new LinkedHashSet<>(); Set<LPSubjectReference> result = new LinkedHashSet<>();
for (Set<LPSubjectReference> set : sorted.values()) { for (Set<LPSubjectReference> set : sorted.values()) {
for (LPSubjectReference e : set) { result.addAll(set);
if (!result.contains(e)) {
result.add(e);
}
}
} }
return result; return result;
} }

View File

@ -51,7 +51,7 @@ public class VelocityCommandExecutor implements Command {
} }
@Override @Override
public void execute(@NonNull CommandSource source, String[] args) { public void execute(@NonNull CommandSource source, @NonNull String[] args) {
Sender lpSender = this.plugin.getSenderFactory().wrap(source); Sender lpSender = this.plugin.getSenderFactory().wrap(source);
List<String> arguments = CommandManager.stripQuotes(ARGUMENT_SPLITTER.splitToList(ARGUMENT_JOINER.join(args))); List<String> arguments = CommandManager.stripQuotes(ARGUMENT_SPLITTER.splitToList(ARGUMENT_JOINER.join(args)));
@ -59,7 +59,7 @@ public class VelocityCommandExecutor implements Command {
} }
@Override @Override
public List<String> suggest(@NonNull CommandSource source, String[] args) { public List<String> suggest(@NonNull CommandSource source, @NonNull String[] args) {
Sender lpSender = this.plugin.getSenderFactory().wrap(source); Sender lpSender = this.plugin.getSenderFactory().wrap(source);
List<String> arguments = CommandManager.stripQuotes(TAB_COMPLETE_ARGUMENT_SPLITTER.splitToList(ARGUMENT_JOINER.join(args))); List<String> arguments = CommandManager.stripQuotes(TAB_COMPLETE_ARGUMENT_SPLITTER.splitToList(ARGUMENT_JOINER.join(args)));