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());
}
@SuppressWarnings("deprecation")
@Override
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");
@ -187,7 +186,6 @@ public class MigrationPermissionsEx extends SubCommand<Object> {
private static Map<String, List<String>> getPermanentPermissions(PermissionEntity entity) {
try {
//noinspection unchecked
PermissionsData data = (PermissionsData) GET_DATA_METHOD.invoke(entity);
return data.getPermissionsMap();
} catch (IllegalAccessException | InvocationTargetException e) {

View File

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

View File

@ -71,7 +71,7 @@ public class PermissionCheckInherits extends SharedSubCommand {
}
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;
}

View File

@ -97,7 +97,7 @@ public class TreeCommand extends SingleCommand {
Message.TREE_URL.send(sender);
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)))
.build();

View File

@ -118,7 +118,7 @@ public class VerboseCommand extends SingleCommand {
Message.VERBOSE_RESULTS_URL.send(sender);
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)))
.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());
}
@SuppressWarnings("unchecked")
@Override
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, User user, List<String> args, String label) {
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) {
try {
MutableContextSet ret = calculator.giveApplicableContext(subject, accumulator);
//noinspection ConstantConditions
if (ret == null) {
throw new IllegalStateException(calculator.getClass() + " returned a null context set");
}
@ -216,7 +215,6 @@ public abstract class ContextManager<T> {
for (StaticContextCalculator calculator : this.staticCalculators) {
try {
MutableContextSet ret = calculator.giveApplicableContext(accumulator);
//noinspection ConstantConditions
if (ret == null) {
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<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()) {
if (entry.getKey() == null || entry.getKey().isEmpty() || entry.getValue() == null) {
continue;

View File

@ -327,8 +327,8 @@ public final class ImmutableNode implements Node {
o1.permission == o2.permission &&
o1.value == o2.value &&
o1.override == o2.override &&
(o1.server == null ? o2.server == null : o1.server.equals(o2.server)) &&
(o1.world == null ? o2.world == null : o1.world.equals(o2.world)) &&
Objects.equals(o1.server, o2.server) &&
Objects.equals(o1.world, o2.world) &&
o1.expireAt == o2.expireAt &&
o1.getContexts().equals(o2.getContexts());
}
@ -339,8 +339,8 @@ public final class ImmutableNode implements Node {
return o1 == o2 ||
o1.permission == o2.permission &&
o1.override == o2.override &&
(o1.server == null ? o2.server == null : o1.server.equals(o2.server)) &&
(o1.world == null ? o2.world == null : o1.world.equals(o2.world)) &&
Objects.equals(o1.server, o2.server) &&
Objects.equals(o1.world, o2.world) &&
o1.expireAt == o2.expireAt &&
o1.getContexts().equals(o2.getContexts());
}
@ -352,8 +352,8 @@ public final class ImmutableNode implements Node {
o1.permission == o2.permission &&
o1.value == o2.value &&
o1.override == o2.override &&
(o1.server == null ? o2.server == null : o1.server.equals(o2.server)) &&
(o1.world == null ? o2.world == null : o1.world.equals(o2.world)) &&
Objects.equals(o1.server, o2.server) &&
Objects.equals(o1.world, o2.world) &&
o1.isTemporary() == o2.isTemporary() &&
o1.getContexts().equals(o2.getContexts());
}
@ -364,8 +364,8 @@ public final class ImmutableNode implements Node {
return o1 == o2 ||
o1.permission == o2.permission &&
o1.override == o2.override &&
(o1.server == null ? o2.server == null : o1.server.equals(o2.server)) &&
(o1.world == null ? o2.world == null : o1.world.equals(o2.world)) &&
Objects.equals(o1.server, o2.server) &&
Objects.equals(o1.world, o2.world) &&
o1.isTemporary() == o2.isTemporary() &&
o1.getContexts().equals(o2.getContexts());
}
@ -376,8 +376,8 @@ public final class ImmutableNode implements Node {
return o1 == o2 ||
o1.permission == o2.permission &&
o1.override == o2.override &&
(o1.server == null ? o2.server == null : o1.server.equals(o2.server)) &&
(o1.world == null ? o2.world == null : o1.world.equals(o2.world)) &&
Objects.equals(o1.server, o2.server) &&
Objects.equals(o1.world, o2.world) &&
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();
}
@NonNull
@Override
public OptionalLong getExpiry() {
public @NonNull OptionalLong getExpiry() {
return this.node.isTemporary() ? OptionalLong.of(this.node.getExpiryUnixTime()) : OptionalLong.empty();
}
@NonNull
@Override
public ContextSet getContexts() {
public @NonNull ContextSet getContexts() {
return this.node.getContexts();
}

View File

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

View File

@ -56,7 +56,6 @@ public abstract class DummySender implements Sender {
consumeMessage(message);
}
@SuppressWarnings("deprecation")
@Override
public void sendMessage(Component 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) {
//noinspection unchecked
return Collector.of(
() -> EnumSet.noneOf(clazz),
EnumSet::add,

View File

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

View File

@ -79,7 +79,6 @@ public class VerboseHandler extends RepeatingTask {
return;
}
//noinspection ThrowableNotThrown
StackTraceElement[] trace = new Exception().getStackTrace();
// add the check data to a queue to be processed later.
@ -104,7 +103,6 @@ public class VerboseHandler extends RepeatingTask {
return;
}
//noinspection ThrowableNotThrown
StackTraceElement[] trace = new Exception().getStackTrace();
// 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) &&
this.roles.equals(other.roles) &&
(this.id == null ? other.id == null : this.id.equals(other.id)) &&
(this.description == null ? other.description == null : this.description.equals(other.description));
Objects.equals(this.id, other.id) &&
Objects.equals(this.description, other.description);
}
@Override

View File

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

View File

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

View File

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

View File

@ -51,7 +51,7 @@ public class VelocityCommandExecutor implements Command {
}
@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);
List<String> arguments = CommandManager.stripQuotes(ARGUMENT_SPLITTER.splitToList(ARGUMENT_JOINER.join(args)));
@ -59,7 +59,7 @@ public class VelocityCommandExecutor implements Command {
}
@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);
List<String> arguments = CommandManager.stripQuotes(TAB_COMPLETE_ARGUMENT_SPLITTER.splitToList(ARGUMENT_JOINER.join(args)));