Mix of Checkstyle and SonarLint.

This commit is contained in:
Andrew Steinborn
2018-10-28 03:18:15 -04:00
parent 9806d57a13
commit 1310cd2c53
15 changed files with 98 additions and 53 deletions

View File

@@ -2,7 +2,6 @@ package com.velocitypowered.api.plugin.ap;
import com.google.gson.Gson;
import com.velocitypowered.api.plugin.Plugin;
import com.velocitypowered.api.plugin.PluginDescription;
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.Writer;
@@ -66,7 +65,7 @@ public class PluginAnnotationProcessor extends AbstractProcessor {
}
Plugin plugin = element.getAnnotation(Plugin.class);
if (!PluginDescription.ID_PATTERN.matcher(plugin.id()).matches()) {
if (!SerializedPluginDescription.ID_PATTERN.matcher(plugin.id()).matches()) {
environment.getMessager().printMessage(Diagnostic.Kind.ERROR, "Invalid ID for plugin "
+ qualifiedName
+ ". IDs must start alphabetically, have alphanumeric characters, and can "

View File

@@ -8,11 +8,14 @@ import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Objects;
import java.util.regex.Pattern;
import java.util.stream.Collectors;
import org.checkerframework.checker.nullness.qual.Nullable;
public class SerializedPluginDescription {
public static final Pattern ID_PATTERN = Pattern.compile("[a-z][a-z0-9-_]{0,63}");
// @Nullable is used here to make GSON skip these in the serialized file
private final String id;
private final @Nullable String name;
@@ -26,7 +29,9 @@ public class SerializedPluginDescription {
private SerializedPluginDescription(String id, String name, String version, String description,
String url,
List<String> authors, List<Dependency> dependencies, String main) {
this.id = Preconditions.checkNotNull(id, "id");
Preconditions.checkNotNull(id, "id");
Preconditions.checkArgument(ID_PATTERN.matcher(id).matches(), "id is not valid");
this.id = id;
this.name = Strings.emptyToNull(name);
this.version = Strings.emptyToNull(version);
this.description = Strings.emptyToNull(description);

View File

@@ -4,7 +4,7 @@ import com.google.common.base.Preconditions;
import com.velocitypowered.api.proxy.InboundConnection;
/**
* This event is fired when a handshake is established between a client and Velocity.
* This event is fired when a handshake is established between a client and the proxy.
*/
public final class ConnectionHandshakeEvent {

View File

@@ -14,7 +14,8 @@ public @interface Plugin {
/**
* The ID of the plugin. This ID should be unique as to not conflict with other plugins. The
* plugin ID must match the {@link PluginDescription#ID_PATTERN}.
* plugin ID may contain alphanumeric characters, dashes, and underscores, and be a maximum
* of 64 characters long.
*
* @return the ID for this plugin
*/

View File

@@ -186,21 +186,23 @@ public final class TextTitle implements Title {
return this;
}
public Builder stay(int ticks) {
private int checkTicks(int ticks) {
Preconditions.checkArgument(ticks >= 0, "ticks value %s is negative", ticks);
this.stay = ticks;
return ticks;
}
public Builder stay(int ticks) {
this.stay = checkTicks(ticks);
return this;
}
public Builder fadeIn(int ticks) {
Preconditions.checkArgument(ticks >= 0, "ticks value %s is negative", ticks);
this.fadeIn = ticks;
this.fadeIn = checkTicks(ticks);
return this;
}
public Builder fadeOut(int ticks) {
Preconditions.checkArgument(ticks >= 0, "ticks value %s is negative", ticks);
this.fadeOut = ticks;
this.fadeOut = checkTicks(ticks);
return this;
}