diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 079884ce..2ff59349 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -70,3 +70,4 @@ jobs: with: name: failed-javadocs-options-file path: build/tmp/javadoc/javadoc.options + diff --git a/.gitignore b/.gitignore index 5459b6f0..2d5ec7c6 100644 --- a/.gitignore +++ b/.gitignore @@ -25,6 +25,7 @@ hs_err_pid* .gradle **/build/ !src/**/build/ +**/resources/generated/ # Ignore Gradle GUI config gradle-app.setting diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 99f50ca6..49799c61 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -6,7 +6,7 @@ This project is open for all developers for contribution, so it's important we e - No pushing to master without opening a pull request (The only exceptions are small hotfixes, any new features or such MUST go in a new branch) - Must be backwards compatible down to Java 11 -- Javadoc your code according to google's [Javadoc guidlines](https://google.github.io/styleguide/javaguide.html#s7-javadoc) +- Javadoc your code according to Google's [Javadoc guidlines](https://google.github.io/styleguide/javaguide.html#s7-javadoc) ## Pull Requests diff --git a/build.gradle b/build.gradle index 05b250c1..5b22d8a7 100644 --- a/build.gradle +++ b/build.gradle @@ -14,19 +14,21 @@ jacoco { } group = 'com.dumbdogdiner' - -version = '2.1.0' +version = '2.3.0' // License Plugin Options license { header = project.file('LICENSE_HEADER') ext.year = Calendar.getInstance().get(Calendar.YEAR) mapping("java", "SLASHSTAR_STYLE") + exclude("**/*.json") } tasks.withType(JavaCompile) { options.compilerArgs << "-Xlint:unchecked" << "-Xlint:deprecation" << "-XDignore.symbol.file" + options.encoding = "UTF-8" } + // Run the license formatter before compiling the source code. tasks.compileJava.dependsOn licenseFormatMain, licenseFormatTest @@ -39,6 +41,7 @@ configurations { repositories { mavenCentral() jcenter() + google() maven { url 'https://oss.sonatype.org/content/repositories/snapshots' } maven { url 'https://papermc.io/repo/repository/maven-public/' } @@ -50,10 +53,14 @@ dependencies { compileOnly 'com.destroystokyo.paper:paper-api:1.16.5-R0.1-SNAPSHOT' compileOnly 'net.md-5:bungeecord-api:1.16-R0.5-SNAPSHOT' + implementation 'org.jetbrains:annotations:20.1.0' implementation 'com.google.code.gson:gson:2.8.6' implementation 'io.github.classgraph:classgraph:4.8.100' implementation 'com.github.seancfoley:ipaddress:5.3.3' + implementation 'com.squareup.okhttp3:okhttp:4.9.0' + implementation 'commons-validator:commons-validator:1.7' + implementation 'com.google.guava:guava:30.1-jre' // Tests - JUnit 5 testImplementation("org.junit.jupiter:junit-jupiter-api:5.7.0") @@ -61,6 +68,19 @@ dependencies { // Tests - Mocking Suite (eg. mocking Bukkit for tests) testImplementation("org.mockito:mockito-core:3.7.7") + + // Tests - Mocked Bukkit Project (Has some additional features) + testImplementation 'com.github.seeseemelk:MockBukkit-v1.16:0.5.0' + testImplementation 'it.unimi.dsi:fastutil:8.4.4' +} + +task downloadTextures(type: Download) { + sourceUrl = 'https://dumbdogdiner.github.io/mc-heads-resource/textures.json' + target = new File('src/main/resources/generated/textures.json') +} + +task cleanGenerated(type: Delete){ + delete('src/main/resources/generated') } test { @@ -70,6 +90,7 @@ test { // Show System.out for code ran by tests showStandardStreams = true } + //ignoreFailures = true finalizedBy jacocoTestReport // report is always generated after tests run } @@ -86,15 +107,22 @@ task sources(type: Jar, dependsOn: classes) { from sourceSets.main.allSource } +tasks.delombok.shouldRunAfter(sources) +tasks.publish.dependsOn build +tasks.build.shouldRunAfter(clean) +tasks.javadoc.shouldRunAfter(clean) +tasks.build.finalizedBy(sources) +tasks.clean.dependsOn(cleanGenerated) +tasks.processResources.dependsOn(downloadTextures) // Javadoc Fixes // Some environments (such as the builder image) do not use UTF-8 as the default encoding! -// This sets UTF-8 as the encoding for the following tasks: delombok, compileJava, compileTestJava and javadoc. -delombok.encoding = "UTF-8" - -compileJava.options.encoding = "UTF-8" -compileTestJava.options.encoding = "UTF-8" -javadoc.options.encoding = "UTF-8" +delombok { + finalizedBy(javadoc) + print(true) + encoding = "UTF-8" + //verbose(true) +} // Build Info @@ -127,10 +155,35 @@ task processSourceTokens(type: Sync) { } // Use the filter task as the input for compileJava compileJava.source = processSourceTokens.outputs +tasks.publish.dependsOn build, sources + +tasks.withType(JavaCompile) { + options.encoding = "UTF-8" +} +tasks.withType(Test) { + systemProperty "file.encoding", "UTF-8" +} +javadoc { + options.addBooleanOption('XDignore.symbol.file', true) + options.addBooleanOption('-frames', true) + options.addBooleanOption('private', true) + test.ignoreFailures true; + options.encoding = 'UTF-8' + dependsOn delombok +} -tasks.publish.dependsOn build, sources +task browseJavadoc { + dependsOn javadoc + doLast { + java.awt.Desktop.desktop.browse new URI(("file:///" << System.getProperty("user.dir").replace('\\','/') << "/build/docs/javadoc/index.html").toString()) + } +} +task rebuild { + dependsOn clean + finalizedBy build +} @@ -152,3 +205,16 @@ publishing { } } } + +class Download extends DefaultTask { + @Input + String sourceUrl + + @OutputFile + File target + + @TaskAction + void download() { + ant.get(src: sourceUrl, dest: target) + } +} \ No newline at end of file diff --git a/gradle.properties b/gradle.properties new file mode 100644 index 00000000..b8e93595 --- /dev/null +++ b/gradle.properties @@ -0,0 +1 @@ +systemProp.file.encoding=utf-8 \ No newline at end of file diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 8988d1ba..2a563242 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,6 +1,5 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-6.7-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-6.8.2-bin.zip zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists -compileJava.options.encoding=UTF-8 \ No newline at end of file diff --git a/src/main/java/com/dumbdogdiner/stickyapi/StickyAPI.java b/src/main/java/com/dumbdogdiner/stickyapi/StickyAPI.java index dd98ddce..dc9ef778 100644 --- a/src/main/java/com/dumbdogdiner/stickyapi/StickyAPI.java +++ b/src/main/java/com/dumbdogdiner/stickyapi/StickyAPI.java @@ -4,6 +4,11 @@ */ package com.dumbdogdiner.stickyapi; +import lombok.Getter; +import lombok.Setter; +import org.jetbrains.annotations.NotNull; + +import java.io.InputStream; import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.Date; @@ -11,9 +16,6 @@ import java.util.concurrent.Executors; import java.util.logging.Logger; -import lombok.Getter; -import lombok.Setter; - /** *
+ * You can specify a group and name from the embedded texture file, or simply set a name and a texture, + * and generate player heads with ease! + *
+ */ + +@SuppressWarnings("UnusedReturnValue") +public class SkullBuilder { + @Getter + @NotNull + @VisibleForTesting + private String category = "*"; + @Getter + @VisibleForTesting + protected int quantity = 1; + @Getter + private String head; + + + @SuppressWarnings("DanglingJavadoc") // For lombok + @Accessors(fluent = true, chain = true) + @Setter + @Getter + /** + * @param name The displayed name of the head + * @return The displayed name of the head + */ + protected String name; + @Getter + protected String texture; + + /** + * Sets the category of the head type (Defaults to *, which is first match) + * + * @param category The category to set + * @throws IllegalArgumentException if the category is not valid + * @see TextureHelper#getCategories() + */ + public @NotNull SkullBuilder category(@NotNull String category) { + Preconditions.checkArgument(TextureHelper.getCategories().contains(category.toUpperCase()), + "The specified group %s is not a valid category", category); + this.category = category.toUpperCase(); + return this; + } + + /** + * Sets the specific head (fromtextures.yml)
+ *
+ * @param head The head to set
+ * @throws IllegalArgumentException if the head does not exist
+ * @see TextureHelper#getTexture(String, String)
+ */
+ public @NotNull SkullBuilder head(@NotNull String head) {
+ head = head.toUpperCase();
+ Preconditions.checkNotNull(TextureHelper.getTexture(category, head),
+ "The specified head %s is not a valid head", head);
+ this.head = head;
+ this.texture = TextureHelper.getTexture(category, head);
+ return this;
+ }
+
+
+ /**
+ * Sets the quantity of items in the final item stack
+ *
+ * @param i the requested quantity
+ * @throws IllegalArgumentException if the stack size is invalid
+ */
+ public @NotNull SkullBuilder quantity(int i) {
+ Preconditions.checkArgument(i >= 0 && i <= 64,
+ "Invalid stack size of %s specified (must be between 0 and 64, inclusive)", i);
+ this.quantity = i;
+ return this;
+ }
+
+
+ /**
+ * @param textureURL A {@link URL} where a valid PNG minecraft texture can be found
+ * @return The current {@link SkullBuilder} instance
+ * @throws IllegalArgumentException if the URL is invalid
+ */
+ public @NotNull SkullBuilder texture(@NotNull URL textureURL) {
+ TextureValidator.validateTextureUrl(textureURL.toExternalForm());
+
+ texture(TextureHelper.encodeTextureString(textureURL));
+ return this;
+ }
+
+ /**
+ * Set the texture with a pre-encoded string
+ *
+ * @param texture Base64 string of the json of texture location
+ * @throws IllegalArgumentException if the texture string is invalid
+ */
+ public @NotNull SkullBuilder texture(@NotNull String texture) {
+ TextureValidator.validateTextureString(texture);
+ this.texture = texture;
+ return this;
+ }
+
+ /**
+ * Builds the final {@link ItemStack} of {@link Material#PLAYER_HEAD} as long as
+ *
+ * @return The constructed head
+ */
+ public @NotNull ItemStack build() {
+ Preconditions.checkNotNull(texture);
+ Preconditions.checkArgument(name != null || head != null);
+
+ @NotNull SkullMeta meta = (SkullMeta) (new ItemStack(Material.PLAYER_HEAD, 1)).getItemMeta();
+ @NotNull PlayerProfile profile = Bukkit.createProfile(new UUID(0, 0), head);
+
+ profile.setName(TextureHelper.toQualifiedName(category, head == null ? name : head));
+ if (name != null) {
+ meta.setDisplayName(name);
+ } else {
+ meta.setDisplayName(StringUtil.capitalize(head));
+ }
+
+ profile.setProperty(new ProfileProperty("textures", texture));
+ meta.setPlayerProfile(profile);
+ @NotNull ItemStack head = new ItemStack(Material.PLAYER_HEAD, quantity);
+ head.setItemMeta(meta);
+ return head;
+ }
+
+ public SkullBuilder qualified(String qualifiedName) {
+ String [] qn = qualifiedName.toUpperCase().split("\\.");
+ category(qn[0]);
+ return head(qn[1]);
+ }
+}
diff --git a/src/main/java/com/dumbdogdiner/stickyapi/bukkit/particle/ParticleSystem.java b/src/main/java/com/dumbdogdiner/stickyapi/bukkit/particle/ParticleSystem.java
index 28e7180e..36852e52 100644
--- a/src/main/java/com/dumbdogdiner/stickyapi/bukkit/particle/ParticleSystem.java
+++ b/src/main/java/com/dumbdogdiner/stickyapi/bukkit/particle/ParticleSystem.java
@@ -166,7 +166,7 @@ public ParticleSystem spawn(@NotNull Particle particle, double x, double y, doub
* @param count The number of particles to spawn
* @return {@link ParticleSystem}
*/
- public ParticleSystem spawn(double x, double y, double z, int count) {
+ public @NotNull ParticleSystem spawn(double x, double y, double z, int count) {
this.ensureDefaultParticle();
return this.spawn(this.particle, x, y, z, count, this.data);
}
@@ -214,7 +214,7 @@ public ParticleSystem spawnAbsolute(@NotNull Particle particle, double x, double
* @param count The number of particles to spawn
* @return {@link ParticleSystem}
*/
- public ParticleSystem spawnAbsolute(double x, double y, double z, int count) {
+ public @NotNull ParticleSystem spawnAbsolute(double x, double y, double z, int count) {
this.ensureDefaultParticle();
return this.spawnAbsolute(this.particle, x, y, z, count, this.data);
}
@@ -527,7 +527,7 @@ public ParticleSystem lineAbsolute(Location a, Location b, double steps, int cou
* @param data Data of the particles to spawn
* @return {@link ParticleSystem}
*/
- public ParticleSystem shape(@NotNull Particle particle, @NotNull Shape shape, @Nullable Particle.DustOptions data) {
+ public @NotNull ParticleSystem shape(@NotNull Particle particle, @NotNull Shape shape, @Nullable Particle.DustOptions data) {
this.ensureRelative();
shape.draw(this, particle, data);
return this;
@@ -540,7 +540,7 @@ public ParticleSystem shape(@NotNull Particle particle, @NotNull Shape shape, @N
* @param shape The shape
* @return {@link ParticleSystem}
*/
- public ParticleSystem shape(@NotNull Particle particle, @NotNull Shape shape) {
+ public @NotNull ParticleSystem shape(@NotNull Particle particle, @NotNull Shape shape) {
return this.shape(particle, shape, null);
}
@@ -550,7 +550,7 @@ public ParticleSystem shape(@NotNull Particle particle, @NotNull Shape shape) {
* @param shape The shape
* @return {@link ParticleSystem}
*/
- public ParticleSystem shape(Shape shape) {
+ public @NotNull ParticleSystem shape(@NotNull Shape shape) {
this.ensureDefaultParticle();
return this.shape(this.particle, shape, this.data);
}
@@ -577,7 +577,7 @@ public ParticleSystem shapeAbsolute(@NotNull Particle particle, @NotNull Shape s
* @param shape The shape
* @return {@link ParticleSystem}
*/
- public ParticleSystem shapeAbsolute(@NotNull Particle particle, @NotNull Shape shape) {
+ public @NotNull ParticleSystem shapeAbsolute(@NotNull Particle particle, @NotNull Shape shape) {
return this.shapeAbsolute(particle, shape, null);
}
@@ -587,7 +587,7 @@ public ParticleSystem shapeAbsolute(@NotNull Particle particle, @NotNull Shape s
* @param shape The shape
* @return {@link ParticleSystem}
*/
- public ParticleSystem shapeAbsolute(@NotNull Shape shape) {
+ public @NotNull ParticleSystem shapeAbsolute(@NotNull Shape shape) {
this.ensureDefaultParticle();
return this.shapeAbsolute(this.particle, shape, this.data);
}
diff --git a/src/main/java/com/dumbdogdiner/stickyapi/bukkit/particle/shapes/Circle.java b/src/main/java/com/dumbdogdiner/stickyapi/bukkit/particle/shapes/Circle.java
index 9ff214da..f2eec4eb 100644
--- a/src/main/java/com/dumbdogdiner/stickyapi/bukkit/particle/shapes/Circle.java
+++ b/src/main/java/com/dumbdogdiner/stickyapi/bukkit/particle/shapes/Circle.java
@@ -11,6 +11,7 @@
import org.bukkit.Particle;
import org.bukkit.Particle.DustOptions;
+import org.jetbrains.annotations.NotNull;
/**
* Draws a circle.
@@ -37,7 +38,7 @@ public class Circle implements Shape {
* @param r Size of the circle's radius.
* @param orientation Orientation of the circle.
*/
- public Circle(double x, double y, double z, double r, Orientation orientation) {
+ public Circle(double x, double y, double z, double r, @NotNull Orientation orientation) {
if (r > MAX_RADIUS) {
throw new IllegalArgumentException("Tried to draw circle with absurd radius (>250)!");
}
@@ -107,12 +108,12 @@ public double z(double t) {
}
@Override
- public void draw(ParticleSystem system, Particle particle, DustOptions data) {
+ public void draw(@NotNull ParticleSystem system, @NotNull Particle particle, DustOptions data) {
system.parametric(particle, this.parametric, 0, Math.PI * 2, Math.PI / (16 * r), 1, data);
}
@Override
- public void drawAbsolute(ParticleSystem system, Particle particle, DustOptions data) {
+ public void drawAbsolute(@NotNull ParticleSystem system, @NotNull Particle particle, DustOptions data) {
system.parametricAbsolute(particle, this.parametric, 0, Math.PI * 2, Math.PI / (16 * r), 1, data);
}
}
diff --git a/src/main/java/com/dumbdogdiner/stickyapi/bukkit/player/PlayerSnapshot.java b/src/main/java/com/dumbdogdiner/stickyapi/bukkit/player/PlayerSnapshot.java
index 7fdc3d6c..7e6be4cb 100644
--- a/src/main/java/com/dumbdogdiner/stickyapi/bukkit/player/PlayerSnapshot.java
+++ b/src/main/java/com/dumbdogdiner/stickyapi/bukkit/player/PlayerSnapshot.java
@@ -4,23 +4,29 @@
*/
package com.dumbdogdiner.stickyapi.bukkit.player;
+import lombok.Getter;
import org.bukkit.Location;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import org.bukkit.util.Vector;
import org.jetbrains.annotations.NotNull;
-public class PlayerSnapshot {
+import java.io.Serializable;
+import java.time.Instant;
- private Location location;
- private ItemStack[] armor;
- private ItemStack[] items;
- private double health;
- private int foodLevel;
- private float saturation;
- private float exhaustion;
- private float exp;
- private Vector velocity;
+public class PlayerSnapshot implements Serializable {
+
+ private final @NotNull Location location;
+ private final ItemStack[] armor;
+ private final ItemStack[] items;
+ private final double health;
+ private final int foodLevel;
+ private final float saturation;
+ private final float exhaustion;
+ private final float exp;
+ private final @NotNull Vector velocity;
+ @Getter
+ private final Instant savedAt;
/**
* Create a new {@link PlayerSnapshot}.
@@ -34,16 +40,16 @@ public class PlayerSnapshot {
* @param player the Player to snapshot
*/
public PlayerSnapshot(@NotNull Player player) {
- location = player.getLocation();
- armor = player.getInventory().getArmorContents();
- items = player.getInventory().getContents();
- health = player.getHealth();
- foodLevel = player.getFoodLevel();
- saturation = player.getSaturation();
- exhaustion = player.getExhaustion();
- exp = player.getExp();
- velocity = player.getVelocity();
-
+ this.savedAt = Instant.now();
+ this.location = player.getLocation();
+ this.armor = player.getInventory().getArmorContents();
+ this.items = player.getInventory().getContents();
+ this.health = player.getHealth();
+ this.foodLevel = player.getFoodLevel();
+ this.saturation = player.getSaturation();
+ this.exhaustion = player.getExhaustion();
+ this.exp = player.getExp();
+ this.velocity = player.getVelocity();
}
/**
diff --git a/src/main/java/com/dumbdogdiner/stickyapi/bukkit/util/ServerUtil.java b/src/main/java/com/dumbdogdiner/stickyapi/bukkit/util/ServerUtil.java
index a309dc58..5248b822 100644
--- a/src/main/java/com/dumbdogdiner/stickyapi/bukkit/util/ServerUtil.java
+++ b/src/main/java/com/dumbdogdiner/stickyapi/bukkit/util/ServerUtil.java
@@ -4,19 +4,17 @@
*/
package com.dumbdogdiner.stickyapi.bukkit.util;
-import javax.annotation.Nullable;
-
import com.destroystokyo.paper.Title;
-
import com.dumbdogdiner.stickyapi.common.translation.Translation;
import com.dumbdogdiner.stickyapi.common.util.reflection.ReflectionUtil;
+import net.md_5.bungee.api.chat.TextComponent;
import org.bukkit.Bukkit;
import org.bukkit.Server;
import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;
-import net.md_5.bungee.api.chat.TextComponent;
+import javax.annotation.Nullable;
public class ServerUtil {
private ServerUtil() {
@@ -42,7 +40,7 @@ public static double[] getRecentTps() {
* @param args The format arguments, if any
*/
public static void broadcastMessage(@NotNull String message, @Nullable String... args) {
- for (Player player : Bukkit.getServer().getOnlinePlayers()) {
+ for (@NotNull Player player : Bukkit.getServer().getOnlinePlayers()) {
player.sendMessage(
new TextComponent(Translation.translateColors("&", String.format(message, (Object) args))));
}
@@ -54,7 +52,7 @@ public static void broadcastMessage(@NotNull String message, @Nullable String...
* @param title The {@link com.destroystokyo.paper.Title} to send
*/
public static void broadcastTitle(@NotNull Title title) {
- for (Player player : Bukkit.getServer().getOnlinePlayers()) {
+ for (@NotNull Player player : Bukkit.getServer().getOnlinePlayers()) {
player.sendTitle(title);
}
}
diff --git a/src/main/java/com/dumbdogdiner/stickyapi/bukkit/util/SoundUtil.java b/src/main/java/com/dumbdogdiner/stickyapi/bukkit/util/SoundUtil.java
index 03257dcc..991aeca7 100644
--- a/src/main/java/com/dumbdogdiner/stickyapi/bukkit/util/SoundUtil.java
+++ b/src/main/java/com/dumbdogdiner/stickyapi/bukkit/util/SoundUtil.java
@@ -25,7 +25,7 @@ private SoundUtil() {
* @param sender {@link org.bukkit.command.CommandSender} The sender to validate
* @return {@link java.lang.Boolean}
*/
- private static Boolean validate(CommandSender sender) {
+ private static @NotNull Boolean validate(CommandSender sender) {
return sender instanceof Player;
}
@@ -100,11 +100,11 @@ public static void sendSuccess(@NotNull Player player) {
* @param type {@link NotificationType} The type of sound
* @return {@link java.lang.Boolean}
*/
- public static Boolean send(@NotNull CommandSender sender, @NotNull NotificationType type) {
+ public static @NotNull Boolean send(@NotNull CommandSender sender, @NotNull NotificationType type) {
if (!validate(sender)) {
return false;
}
- var player = (Player) sender;
+ @NotNull var player = (Player) sender;
switch (type) {
case ERROR:
sendError(player);
diff --git a/src/main/java/com/dumbdogdiner/stickyapi/bukkit/util/StartupUtil.java b/src/main/java/com/dumbdogdiner/stickyapi/bukkit/util/StartupUtil.java
index beb5505b..902b8d10 100644
--- a/src/main/java/com/dumbdogdiner/stickyapi/bukkit/util/StartupUtil.java
+++ b/src/main/java/com/dumbdogdiner/stickyapi/bukkit/util/StartupUtil.java
@@ -52,7 +52,7 @@ public static boolean setupConfig(@NotNull JavaPlugin plugin) {
* @param localeProvider The plugin's locale provider
* @return False if something went wrong
*/
- public static LocaleProvider setupLocale(@NotNull JavaPlugin plugin, @Nullable LocaleProvider localeProvider) {
+ public static @org.jetbrains.annotations.Nullable LocaleProvider setupLocale(@NotNull JavaPlugin plugin, @Nullable LocaleProvider localeProvider) {
localeProvider = new LocaleProvider(new File(plugin.getDataFolder(), "locale"));
int loadedLocales = localeProvider.loadAllLocales();
boolean localeEnabled = localeProvider.setDefaultLocale("messages.en_us");
diff --git a/src/main/java/com/dumbdogdiner/stickyapi/bungeecord/command/BungeeCommandBuilder.java b/src/main/java/com/dumbdogdiner/stickyapi/bungeecord/command/BungeeCommandBuilder.java
index 4cbf15dc..16692305 100644
--- a/src/main/java/com/dumbdogdiner/stickyapi/bungeecord/command/BungeeCommandBuilder.java
+++ b/src/main/java/com/dumbdogdiner/stickyapi/bungeecord/command/BungeeCommandBuilder.java
@@ -4,51 +4,45 @@
*/
package com.dumbdogdiner.stickyapi.bungeecord.command;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.List;
-import java.util.TreeMap;
-import java.util.concurrent.FutureTask;
-
import com.dumbdogdiner.stickyapi.StickyAPI;
import com.dumbdogdiner.stickyapi.bungeecord.packet.PacketRegistration;
import com.dumbdogdiner.stickyapi.bungeecord.util.SoundUtil;
import com.dumbdogdiner.stickyapi.common.arguments.Arguments;
-import com.dumbdogdiner.stickyapi.common.command.ExitCode;
import com.dumbdogdiner.stickyapi.common.command.CommandBuilder;
+import com.dumbdogdiner.stickyapi.common.command.ExitCode;
import com.dumbdogdiner.stickyapi.common.util.NotificationType;
import com.dumbdogdiner.stickyapi.common.util.StringUtil;
import com.google.common.collect.ImmutableList;
-
-import org.jetbrains.annotations.NotNull;
-
import net.md_5.bungee.api.CommandSender;
import net.md_5.bungee.api.ProxyServer;
import net.md_5.bungee.api.connection.ProxiedPlayer;
import net.md_5.bungee.api.plugin.Command;
import net.md_5.bungee.api.plugin.Plugin;
+import org.jetbrains.annotations.NotNull;
+import org.jetbrains.annotations.Nullable;
+
+import java.util.*;
+import java.util.concurrent.FutureTask;
@SuppressWarnings("deprecation") // PacketRegistration is deprecated
public class BungeeCommandBuilder extends CommandBuilder
- * Returns the argument, if it exists
*
* @param name The name of the argument to check for
- * @return {@link java.lang.Boolean}
*/
- public Boolean exists(@NotNull String name) {
+ public boolean exists(@NotNull String name) {
return parsedArgs.get(name) != null;
}
@@ -570,7 +563,7 @@ public Boolean exists(@NotNull String name) {
* @param name The name of the flag to fetch
* @return {@link java.lang.Boolean}
*/
- public Boolean getFlag(@NotNull String name) {
+ public @Nullable Boolean getFlag(@NotNull String name) {
return exists(name);
}
@@ -582,7 +575,7 @@ public Boolean getFlag(@NotNull String name) {
* @param name The name of the boolean to fetch
* @return {@link java.lang.Boolean}
*/
- public Boolean getBoolean(@NotNull String name) {
+ public @NotNull Boolean getBoolean(@NotNull String name) {
return Boolean.valueOf(parsedArgs.get(name));
}
@@ -594,7 +587,7 @@ public Boolean getBoolean(@NotNull String name) {
* @param name The name of the duration to fetch
* @return {@link java.lang.Long}
*/
- public Long getDuration(@NotNull String name) {
+ public @Nullable Long getDuration(@NotNull String name) {
return TimeUtil.duration(parsedArgs.get(name)).isPresent() ? TimeUtil.duration(parsedArgs.get(name)).get()
: null;
}
diff --git a/src/main/java/com/dumbdogdiner/stickyapi/common/cache/Cache.java b/src/main/java/com/dumbdogdiner/stickyapi/common/cache/Cache.java
index 0e95d9d2..b9c7d024 100644
--- a/src/main/java/com/dumbdogdiner/stickyapi/common/cache/Cache.java
+++ b/src/main/java/com/dumbdogdiner/stickyapi/common/cache/Cache.java
@@ -15,6 +15,7 @@
import lombok.Getter;
import lombok.Setter;
+import org.jetbrains.annotations.Nullable;
/**
* General purpose cache for caching things that should be cached.
@@ -31,12 +32,12 @@ public interface PredicategetKey()
* method to allow for key retrieval.
*/
public interface Cacheable {
- String getKey();
+ @NotNull String getKey();
}
diff --git a/src/main/java/com/dumbdogdiner/stickyapi/common/chat/ChatMessage.java b/src/main/java/com/dumbdogdiner/stickyapi/common/chat/ChatMessage.java
index b75f2588..cf37bf8d 100644
--- a/src/main/java/com/dumbdogdiner/stickyapi/common/chat/ChatMessage.java
+++ b/src/main/java/com/dumbdogdiner/stickyapi/common/chat/ChatMessage.java
@@ -57,7 +57,7 @@ public ChatMessage(@NotNull String content) {
* @param content The new content this ChatMessage object should contain
* @return {@link ChatMessage}
*/
- public ChatMessage setContent(@NotNull String content) {
+ public @NotNull ChatMessage setContent(@NotNull String content) {
this.component = new TextComponent(content);
this.rawContent = content;
return this;
@@ -70,7 +70,7 @@ public ChatMessage setContent(@NotNull String content) {
* @param apply Whether URLs should be formatted.
* @return {@link ChatMessage}
*/
- public ChatMessage applyURLs(@NotNull boolean apply) {
+ public @NotNull ChatMessage applyURLs(@NotNull boolean apply) {
if (apply) {
String original = this.component.getText();
component = URLUtil.convertURLs(original);
@@ -86,7 +86,7 @@ public ChatMessage applyURLs(@NotNull boolean apply) {
* @param chatMessage The ChatMessage that should be added.
* @return {@link ChatMessage}
*/
- public ChatMessage appendMessage(@NotNull ChatMessage chatMessage) {
+ public @NotNull ChatMessage appendMessage(@NotNull ChatMessage chatMessage) {
if (chatMessage != null) {
this.component.addExtra(chatMessage.getComponent());
this.rawContent = rawContent + chatMessage.getRawContent();
@@ -103,8 +103,8 @@ public ChatMessage appendMessage(@NotNull ChatMessage chatMessage) {
*
* @return {@link ChatMessage}
*/
- public ChatMessage setHoverMessage(@NotNull String... text) {
- StringBuilder tooltip = new StringBuilder();
+ public @NotNull ChatMessage setHoverMessage(@NotNull String @NotNull ... text) {
+ @NotNull StringBuilder tooltip = new StringBuilder();
int i = 0;
for (String s : text) {
tooltip.append(s);
@@ -127,7 +127,7 @@ public ChatMessage setHoverMessage(@NotNull String... text) {
* @param url The URL this message should suggest when clicked.
* @return {@link ChatMessage}
*/
- public ChatMessage setLink(@NotNull String url) {
+ public @NotNull ChatMessage setLink(@NotNull String url) {
this.component.setClickEvent(new ClickEvent(ClickEvent.Action.OPEN_URL, url));
return this;
}
@@ -139,7 +139,7 @@ public ChatMessage setLink(@NotNull String url) {
* @param command The command that should run when message is clicked.
* @return {@link ChatMessage}
*/
- public ChatMessage setCommand(@NotNull String command) {
+ public @NotNull ChatMessage setCommand(@NotNull String command) {
this.component.setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, command));
return this;
}
diff --git a/src/main/java/com/dumbdogdiner/stickyapi/common/command/CommandBuilder.java b/src/main/java/com/dumbdogdiner/stickyapi/common/command/CommandBuilder.java
index ae4104a5..0ae573dd 100644
--- a/src/main/java/com/dumbdogdiner/stickyapi/common/command/CommandBuilder.java
+++ b/src/main/java/com/dumbdogdiner/stickyapi/common/command/CommandBuilder.java
@@ -4,6 +4,9 @@
*/
package com.dumbdogdiner.stickyapi.common.command;
+import lombok.Getter;
+import org.jetbrains.annotations.NotNull;
+
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
@@ -18,6 +21,7 @@ public abstract class CommandBuilder