diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/api/network/Network.java b/src/main/java/io/github/thebusybiscuit/slimefun4/api/network/Network.java index 9cc30d2d0..21872a875 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/api/network/Network.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/api/network/Network.java @@ -5,6 +5,9 @@ import java.util.HashSet; import java.util.Queue; import java.util.Set; +import javax.annotation.Nonnull; +import javax.annotation.Nullable; + import org.apache.commons.lang.Validate; import org.bukkit.Color; import org.bukkit.Location; @@ -44,7 +47,7 @@ public abstract class Network { * @param regulator * The {@link Location} marking the regulator of this {@link Network}. */ - protected Network(NetworkManager manager, Location regulator) { + protected Network(@Nonnull NetworkManager manager, @Nonnull Location regulator) { Validate.notNull(manager, "A NetworkManager must be provided"); Validate.notNull(regulator, "No regulator was specified"); @@ -74,7 +77,8 @@ public abstract class Network { * The {@link Location} to classify * @return The assigned type of {@link NetworkComponent} for this {@link Location} */ - public abstract NetworkComponent classifyLocation(Location l); + @Nullable + public abstract NetworkComponent classifyLocation(@Nonnull Location l); /** * This method is called whenever a {@link Location} in this {@link Network} changes @@ -99,7 +103,7 @@ public abstract class Network { return regulatorNodes.size() + connectorNodes.size() + terminusNodes.size(); } - protected void addLocationToNetwork(Location l) { + protected void addLocationToNetwork(@Nonnull Location l) { if (connectedLocations.contains(l)) { return; } @@ -115,7 +119,7 @@ public abstract class Network { * @param l * The {@link Location} to update */ - public void markDirty(Location l) { + public void markDirty(@Nonnull Location l) { if (regulator.equals(l)) { manager.unregisterNetwork(this); } @@ -131,11 +135,12 @@ public abstract class Network { * The {@link Location} to check for * @return Whether the given {@link Location} is part of this {@link Network} */ - public boolean connectsTo(Location l) { + public boolean connectsTo(@Nonnull Location l) { return connectedLocations.contains(l); } - private NetworkComponent getCurrentClassification(Location l) { + @Nullable + private NetworkComponent getCurrentClassification(@Nonnull Location l) { if (regulatorNodes.contains(l)) { return NetworkComponent.REGULATOR; } @@ -191,14 +196,14 @@ public abstract class Network { } } - private void discoverNeighbors(Location l, double xDiff, double yDiff, double zDiff) { + private void discoverNeighbors(@Nonnull Location l, double xDiff, double yDiff, double zDiff) { for (int i = getRange() + 1; i > 0; i--) { Location newLocation = l.clone().add(i * xDiff, i * yDiff, i * zDiff); addLocationToNetwork(newLocation); } } - private void discoverNeighbors(Location l) { + private void discoverNeighbors(@Nonnull Location l) { discoverNeighbors(l, 1.0, 0.0, 0.0); discoverNeighbors(l, -1.0, 0.0, 0.0); discoverNeighbors(l, 0.0, 1.0, 0.0); @@ -230,6 +235,7 @@ public abstract class Network { * * @return The {@link Location} of our regulator */ + @Nonnull public Location getRegulator() { return regulator; } diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/core/attributes/EnergyNetComponent.java b/src/main/java/io/github/thebusybiscuit/slimefun4/core/attributes/EnergyNetComponent.java index 44b6c9caf..91262da84 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/core/attributes/EnergyNetComponent.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/core/attributes/EnergyNetComponent.java @@ -1,5 +1,7 @@ package io.github.thebusybiscuit.slimefun4.core.attributes; +import javax.annotation.Nonnull; + import org.apache.commons.lang.Validate; import org.bukkit.Location; @@ -33,6 +35,7 @@ public interface EnergyNetComponent extends ItemAttribute { * * @return The {@link EnergyNetComponentType} this {@link SlimefunItem} represents. */ + @Nonnull EnergyNetComponentType getEnergyComponentType(); /** @@ -61,7 +64,7 @@ public interface EnergyNetComponent extends ItemAttribute { * * @return The charge stored at that {@link Location} */ - default int getCharge(Location l) { + default int getCharge(@Nonnull Location l) { Validate.notNull(l, "Location was null!"); String charge = BlockStorage.getLocationInfo(l, "energy-charge"); @@ -83,7 +86,7 @@ public interface EnergyNetComponent extends ItemAttribute { * @param charge * The new charge */ - default void setCharge(Location l, int charge) { + default void setCharge(@Nonnull Location l, int charge) { Validate.notNull(l, "Location was null!"); Validate.isTrue(charge >= 0, "You can only set a charge of zero or more!"); int capacity = getCapacity(); @@ -104,7 +107,7 @@ public interface EnergyNetComponent extends ItemAttribute { } } - default void addCharge(Location l, int charge) { + default void addCharge(@Nonnull Location l, int charge) { Validate.notNull(l, "Location was null!"); Validate.isTrue(charge > 0, "You can only add a positive charge!"); int capacity = getCapacity(); @@ -126,7 +129,7 @@ public interface EnergyNetComponent extends ItemAttribute { } } - default void removeCharge(Location l, int charge) { + default void removeCharge(@Nonnull Location l, int charge) { Validate.notNull(l, "Location was null!"); Validate.isTrue(charge > 0, "The charge to remove must be greater than zero!"); int capacity = getCapacity(); diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/core/attributes/EnergyNetProvider.java b/src/main/java/io/github/thebusybiscuit/slimefun4/core/attributes/EnergyNetProvider.java index 9a4e7e2e2..6e2c7f0eb 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/core/attributes/EnergyNetProvider.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/core/attributes/EnergyNetProvider.java @@ -1,5 +1,7 @@ package io.github.thebusybiscuit.slimefun4.core.attributes; +import javax.annotation.Nonnull; + import org.bukkit.Location; import io.github.thebusybiscuit.slimefun4.core.networks.energy.EnergyNet; @@ -42,7 +44,7 @@ public interface EnergyNetProvider extends EnergyNetComponent { * * @return The generated output energy of this {@link EnergyNetProvider}. */ - int getGeneratedOutput(Location l, Config data); + int getGeneratedOutput(@Nonnull Location l, @Nonnull Config data); /** * This method returns whether the given {@link Location} is going to explode on the @@ -55,7 +57,7 @@ public interface EnergyNetProvider extends EnergyNetComponent { * * @return Whether or not this {@link Location} will explode. */ - default boolean willExplode(Location l, Config data) { + default boolean willExplode(@Nonnull Location l, @Nonnull Config data) { return false; } diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/core/attributes/MachineTier.java b/src/main/java/io/github/thebusybiscuit/slimefun4/core/attributes/MachineTier.java index 5d1cd6aba..eb01529ec 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/core/attributes/MachineTier.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/core/attributes/MachineTier.java @@ -1,17 +1,19 @@ package io.github.thebusybiscuit.slimefun4.core.attributes; +import javax.annotation.Nonnull; + public enum MachineTier { - BASIC("&eBasic"), - AVERAGE("&6Average"), - MEDIUM("&aMedium"), - GOOD("&2Good"), - ADVANCED("&6Advanced"), + BASIC("&eBasic"), + AVERAGE("&6Average"), + MEDIUM("&aMedium"), + GOOD("&2Good"), + ADVANCED("&6Advanced"), END_GAME("&4End-Game"); private final String prefix; - MachineTier(String prefix) { + MachineTier(@Nonnull String prefix) { this.prefix = prefix; } diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/core/attributes/MachineType.java b/src/main/java/io/github/thebusybiscuit/slimefun4/core/attributes/MachineType.java index 6eaa22301..119b9f693 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/core/attributes/MachineType.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/core/attributes/MachineType.java @@ -1,5 +1,7 @@ package io.github.thebusybiscuit.slimefun4.core.attributes; +import javax.annotation.Nonnull; + public enum MachineType { CAPACITOR("Capacitor"), @@ -8,7 +10,7 @@ public enum MachineType { private final String suffix; - MachineType(String suffix) { + MachineType(@Nonnull String suffix) { this.suffix = suffix; } diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/core/attributes/Radioactive.java b/src/main/java/io/github/thebusybiscuit/slimefun4/core/attributes/Radioactive.java index 85b7afac9..246d31c9e 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/core/attributes/Radioactive.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/core/attributes/Radioactive.java @@ -1,5 +1,7 @@ package io.github.thebusybiscuit.slimefun4.core.attributes; +import javax.annotation.Nonnull; + import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.SlimefunItem; /** @@ -12,6 +14,7 @@ import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.SlimefunItem; * @author TheBusyBiscuit * */ +@FunctionalInterface public interface Radioactive extends ItemAttribute { /** @@ -20,6 +23,7 @@ public interface Radioactive extends ItemAttribute { * * @return The level of {@link Radioactivity} of this item. */ + @Nonnull Radioactivity getRadioactivity(); } diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/core/attributes/Radioactivity.java b/src/main/java/io/github/thebusybiscuit/slimefun4/core/attributes/Radioactivity.java index 4c25a67f8..3e4bd9f12 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/core/attributes/Radioactivity.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/core/attributes/Radioactivity.java @@ -1,5 +1,7 @@ package io.github.thebusybiscuit.slimefun4.core.attributes; +import javax.annotation.Nonnull; + import org.bukkit.ChatColor; import org.bukkit.entity.Player; @@ -47,10 +49,11 @@ public enum Radioactivity { private final ChatColor color; - Radioactivity(ChatColor color) { + Radioactivity(@Nonnull ChatColor color) { this.color = color; } + @Nonnull public String getLore() { return ChatColor.GREEN + "\u2622" + ChatColor.GRAY + " Radiation level: " + color + toString().replace('_', ' '); } diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/core/attributes/RechargeableHelper.java b/src/main/java/io/github/thebusybiscuit/slimefun4/core/attributes/RechargeableHelper.java index 97aa0dc8a..f19af55a5 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/core/attributes/RechargeableHelper.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/core/attributes/RechargeableHelper.java @@ -6,6 +6,8 @@ import java.util.ArrayList; import java.util.List; import java.util.regex.Pattern; +import javax.annotation.Nonnull; + import org.bukkit.NamespacedKey; import org.bukkit.inventory.meta.ItemMeta; import org.bukkit.persistence.PersistentDataType; @@ -33,7 +35,7 @@ final class RechargeableHelper { private RechargeableHelper() {} - static void setCharge(ItemMeta meta, float charge, float capacity) { + static void setCharge(@Nonnull ItemMeta meta, float charge, float capacity) { BigDecimal decimal = BigDecimal.valueOf(charge).setScale(2, RoundingMode.HALF_UP); float value = decimal.floatValue(); @@ -56,7 +58,7 @@ final class RechargeableHelper { meta.setLore(lore); } - static float getCharge(ItemMeta meta) { + static float getCharge(@Nonnull ItemMeta meta) { if (SlimefunPlugin.getMinecraftVersion().isAtLeast(MinecraftVersion.MINECRAFT_1_14)) { Float value = meta.getPersistentDataContainer().get(CHARGE_KEY, PersistentDataType.FLOAT); diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/core/attributes/RecipeDisplayItem.java b/src/main/java/io/github/thebusybiscuit/slimefun4/core/attributes/RecipeDisplayItem.java index 09bb199d6..e48801c01 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/core/attributes/RecipeDisplayItem.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/core/attributes/RecipeDisplayItem.java @@ -2,6 +2,8 @@ package io.github.thebusybiscuit.slimefun4.core.attributes; import java.util.List; +import javax.annotation.Nonnull; + import org.bukkit.entity.Player; import org.bukkit.inventory.ItemStack; @@ -38,13 +40,16 @@ public interface RecipeDisplayItem extends ItemAttribute { * * @return The recipes to display in the {@link SlimefunGuide} */ + @Nonnull List getDisplayRecipes(); + @Nonnull default String getLabelLocalPath() { return "guide.tooltips.recipes.machine"; } - default String getRecipeSectionLabel(Player p) { + @Nonnull + default String getRecipeSectionLabel(@Nonnull Player p) { return "&7\u21E9 " + SlimefunPlugin.getLocalization().getMessage(p, getLabelLocalPath()) + " \u21E9"; } } diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/core/attributes/WitherProof.java b/src/main/java/io/github/thebusybiscuit/slimefun4/core/attributes/WitherProof.java index 315336974..e08c14ceb 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/core/attributes/WitherProof.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/core/attributes/WitherProof.java @@ -1,5 +1,7 @@ package io.github.thebusybiscuit.slimefun4.core.attributes; +import javax.annotation.Nonnull; + import org.bukkit.block.Block; import org.bukkit.entity.Wither; @@ -28,6 +30,6 @@ public interface WitherProof extends ItemAttribute { * @param wither * The {@link Wither} who attacked. */ - void onAttack(Block block, Wither wither); + void onAttack(@Nonnull Block block, @Nonnull Wither wither); } diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/core/commands/SlimefunCommand.java b/src/main/java/io/github/thebusybiscuit/slimefun4/core/commands/SlimefunCommand.java index 632e61ecb..8fd253456 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/core/commands/SlimefunCommand.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/core/commands/SlimefunCommand.java @@ -6,6 +6,8 @@ import java.util.List; import java.util.Map; import java.util.stream.Collectors; +import javax.annotation.Nonnull; + import org.apache.commons.lang.Validate; import org.bukkit.command.Command; import org.bukkit.command.CommandExecutor; @@ -37,7 +39,7 @@ public class SlimefunCommand implements CommandExecutor, Listener { * @param plugin * The instance of our {@link SlimefunPlugin} */ - public SlimefunCommand(SlimefunPlugin plugin) { + public SlimefunCommand(@Nonnull SlimefunPlugin plugin) { this.plugin = plugin; } @@ -52,6 +54,7 @@ public class SlimefunCommand implements CommandExecutor, Listener { commands.addAll(SlimefunSubCommands.getAllCommands(this)); } + @Nonnull public SlimefunPlugin getPlugin() { return plugin; } @@ -61,6 +64,7 @@ public class SlimefunCommand implements CommandExecutor, Listener { * * @return A {@link Map} holding the amount of times each command was run */ + @Nonnull public Map getCommandUsage() { return commandUsage; } @@ -82,7 +86,7 @@ public class SlimefunCommand implements CommandExecutor, Listener { return true; } - public void sendHelp(CommandSender sender) { + public void sendHelp(@Nonnull CommandSender sender) { sender.sendMessage(""); sender.sendMessage(ChatColors.color("&aSlimefun &2v" + SlimefunPlugin.getVersion())); sender.sendMessage(""); @@ -107,6 +111,7 @@ public class SlimefunCommand implements CommandExecutor, Listener { * * @return A {@link List} containing every {@link SubCommand} */ + @Nonnull public List getSubCommandNames() { return commands.stream().map(SubCommand::getName).collect(Collectors.toList()); } diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/core/commands/SlimefunTabCompleter.java b/src/main/java/io/github/thebusybiscuit/slimefun4/core/commands/SlimefunTabCompleter.java index 1a4adad1b..13cc27ebf 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/core/commands/SlimefunTabCompleter.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/core/commands/SlimefunTabCompleter.java @@ -7,6 +7,8 @@ import java.util.LinkedList; import java.util.List; import java.util.Locale; +import javax.annotation.Nonnull; + import org.bukkit.command.Command; import org.bukkit.command.CommandSender; import org.bukkit.command.TabCompleter; @@ -21,7 +23,7 @@ class SlimefunTabCompleter implements TabCompleter { private final SlimefunCommand command; - public SlimefunTabCompleter(SlimefunCommand command) { + public SlimefunTabCompleter(@Nonnull SlimefunCommand command) { this.command = command; } @@ -70,7 +72,8 @@ class SlimefunTabCompleter implements TabCompleter { * The typed string * @return Sublist if string is not empty */ - private List createReturnList(List list, String string) { + @Nonnull + private List createReturnList(@Nonnull List list, @Nonnull String string) { if (string.length() == 0) { return list; } @@ -94,6 +97,7 @@ class SlimefunTabCompleter implements TabCompleter { return returnList; } + @Nonnull private List getSlimefunItems() { List items = SlimefunPlugin.getRegistry().getEnabledSlimefunItems(); List list = new ArrayList<>(items.size()); diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/core/commands/SubCommand.java b/src/main/java/io/github/thebusybiscuit/slimefun4/core/commands/SubCommand.java index 4edbd09c4..f3c2f044b 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/core/commands/SubCommand.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/core/commands/SubCommand.java @@ -2,6 +2,9 @@ package io.github.thebusybiscuit.slimefun4.core.commands; import java.util.Map; +import javax.annotation.Nonnull; +import javax.annotation.ParametersAreNonnullByDefault; + import org.bukkit.command.Command; import org.bukkit.command.CommandSender; import org.bukkit.command.defaults.HelpCommand; @@ -27,6 +30,7 @@ public abstract class SubCommand { private final String name; private final boolean hidden; + @ParametersAreNonnullByDefault protected SubCommand(SlimefunPlugin plugin, SlimefunCommand cmd, String name, boolean hidden) { this.plugin = plugin; this.cmd = cmd; @@ -41,6 +45,7 @@ public abstract class SubCommand { * * @return The name of this {@link SubCommand} */ + @Nonnull public final String getName() { return name; } @@ -54,12 +59,13 @@ public abstract class SubCommand { return hidden; } - protected void recordUsage(Map commandUsage) { + protected void recordUsage(@Nonnull Map commandUsage) { commandUsage.merge(this, 1, Integer::sum); } - public abstract void onExecute(CommandSender sender, String[] args); + public abstract void onExecute(@Nonnull CommandSender sender, @Nonnull String[] args); + @Nonnull protected String getDescription() { return "commands." + getName(); } @@ -73,7 +79,8 @@ public abstract class SubCommand { * The {@link CommandSender} who requested the description * @return A possibly localized description of this {@link SubCommand} */ - public String getDescription(CommandSender sender) { + @Nonnull + public String getDescription(@Nonnull CommandSender sender) { if (sender instanceof Player) { return SlimefunPlugin.getLocalization().getMessage((Player) sender, getDescription()); } diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/core/guide/GuideEntry.java b/src/main/java/io/github/thebusybiscuit/slimefun4/core/guide/GuideEntry.java index b521e8680..14f65fd07 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/core/guide/GuideEntry.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/core/guide/GuideEntry.java @@ -1,15 +1,18 @@ package io.github.thebusybiscuit.slimefun4.core.guide; +import javax.annotation.Nonnull; + class GuideEntry { private final T object; private int page; - GuideEntry(T object, int page) { + GuideEntry(@Nonnull T object, int page) { this.object = object; this.page = page; } + @Nonnull public T getIndexedObject() { return object; } diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/core/guide/GuideHistory.java b/src/main/java/io/github/thebusybiscuit/slimefun4/core/guide/GuideHistory.java index 83b36be28..a2c0b1ebc 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/core/guide/GuideHistory.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/core/guide/GuideHistory.java @@ -3,6 +3,9 @@ package io.github.thebusybiscuit.slimefun4.core.guide; import java.util.Deque; import java.util.LinkedList; +import javax.annotation.Nonnull; +import javax.annotation.Nullable; + import org.apache.commons.lang.Validate; import org.bukkit.entity.Player; import org.bukkit.inventory.ItemStack; @@ -32,7 +35,7 @@ public class GuideHistory { * @param profile * The {@link PlayerProfile} this {@link GuideHistory} was made for */ - public GuideHistory(PlayerProfile profile) { + public GuideHistory(@Nonnull PlayerProfile profile) { Validate.notNull(profile, "Cannot create a GuideHistory without a PlayerProfile!"); this.profile = profile; } @@ -54,7 +57,7 @@ public class GuideHistory { * @param page * The current page of the {@link Category} that should be stored */ - public void add(Category category, int page) { + public void add(@Nonnull Category category, int page) { refresh(category, page); } @@ -68,7 +71,7 @@ public class GuideHistory { * @param page * The current page of the recipes of this {@link ItemStack} */ - public void add(ItemStack item, int page) { + public void add(@Nonnull ItemStack item, int page) { refresh(item, page); } @@ -78,8 +81,8 @@ public class GuideHistory { * @param item * The {@link SlimefunItem} that should be added to this {@link GuideHistory} */ - public void add(SlimefunItem item) { - Validate.notNull(item, "Cannot add a nonexisting SlimefunItem to the GuideHistory!"); + public void add(@Nonnull SlimefunItem item) { + Validate.notNull(item, "Cannot add a non-existing SlimefunItem to the GuideHistory!"); queue.add(new GuideEntry<>(item, 0)); } @@ -89,12 +92,12 @@ public class GuideHistory { * @param searchTerm * The term that the {@link Player} searched for */ - public void add(String searchTerm) { + public void add(@Nonnull String searchTerm) { Validate.notNull(searchTerm, "Cannot add an empty Search Term to the GuideHistory!"); queue.add(new GuideEntry<>(searchTerm, 0)); } - private void refresh(T object, int page) { + private void refresh(@Nonnull T object, int page) { Validate.notNull(object, "Cannot add a null Entry to the GuideHistory!"); Validate.isTrue(page >= 0, "page must not be negative!"); @@ -125,6 +128,7 @@ public class GuideHistory { * Whether to remove the current entry so it moves back to the entry returned. * @return The last Guide Entry that was saved to the given Players guide history. */ + @Nullable private GuideEntry getLastEntry(boolean remove) { if (remove && !queue.isEmpty()) { queue.removeLast(); @@ -140,7 +144,7 @@ public class GuideHistory { * @param guide * The {@link SlimefunGuideImplementation} to use */ - public void openLastEntry(SlimefunGuideImplementation guide) { + public void openLastEntry(@Nonnull SlimefunGuideImplementation guide) { GuideEntry entry = getLastEntry(false); open(guide, entry); } @@ -155,12 +159,12 @@ public class GuideHistory { * @param guide * The {@link SlimefunGuideImplementation} to use */ - public void goBack(SlimefunGuideImplementation guide) { + public void goBack(@Nonnull SlimefunGuideImplementation guide) { GuideEntry entry = getLastEntry(true); open(guide, entry); } - private void open(SlimefunGuideImplementation guide, GuideEntry entry) { + private void open(@Nonnull SlimefunGuideImplementation guide, @Nullable GuideEntry entry) { if (entry == null) { guide.openMainMenu(profile, 1); } diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/core/guide/SlimefunGuide.java b/src/main/java/io/github/thebusybiscuit/slimefun4/core/guide/SlimefunGuide.java index 6760baae1..cc15b1d1b 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/core/guide/SlimefunGuide.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/core/guide/SlimefunGuide.java @@ -2,6 +2,8 @@ package io.github.thebusybiscuit.slimefun4.core.guide; import java.util.Optional; +import javax.annotation.Nonnull; + import org.bukkit.entity.Player; import org.bukkit.inventory.ItemStack; @@ -29,7 +31,7 @@ public final class SlimefunGuide { private SlimefunGuide() {} - public static ItemStack getItem(SlimefunGuideLayout design) { + public static ItemStack getItem(@Nonnull SlimefunGuideLayout design) { return SlimefunPlugin.getRegistry().getGuideLayout(design).getItem(); } diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/core/guide/SlimefunGuideImplementation.java b/src/main/java/io/github/thebusybiscuit/slimefun4/core/guide/SlimefunGuideImplementation.java index 7ef81acfc..61f1a92f9 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/core/guide/SlimefunGuideImplementation.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/core/guide/SlimefunGuideImplementation.java @@ -2,6 +2,8 @@ package io.github.thebusybiscuit.slimefun4.core.guide; import java.util.function.Consumer; +import javax.annotation.Nonnull; + import org.bukkit.GameMode; import org.bukkit.entity.Player; import org.bukkit.inventory.ItemStack; @@ -33,6 +35,7 @@ public interface SlimefunGuideImplementation { * * @return The layout this {@link SlimefunGuideImplementation} represents */ + @Nonnull SlimefunGuideLayout getLayout(); /** @@ -42,6 +45,7 @@ public interface SlimefunGuideImplementation { * * @return The {@link ItemStack} representation for this {@link SlimefunGuideImplementation} */ + @Nonnull ItemStack getItem(); /** diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/core/networks/NetworkManager.java b/src/main/java/io/github/thebusybiscuit/slimefun4/core/networks/NetworkManager.java index e8b26fb20..0d0b80f0a 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/core/networks/NetworkManager.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/core/networks/NetworkManager.java @@ -5,6 +5,9 @@ import java.util.LinkedList; import java.util.List; import java.util.Optional; +import javax.annotation.Nonnull; +import javax.annotation.Nullable; + import org.apache.commons.lang.Validate; import org.bukkit.Location; import org.bukkit.Server; @@ -54,11 +57,13 @@ public class NetworkManager { * * @return A {@link List} containing every {@link Network} on the {@link Server} */ + @Nonnull public List getNetworkList() { return networks; } - public Optional getNetworkFromLocation(Location l, Class type) { + @Nonnull + public Optional getNetworkFromLocation(@Nullable Location l, @Nonnull Class type) { if (l == null) { return Optional.empty(); } @@ -73,7 +78,8 @@ public class NetworkManager { return Optional.empty(); } - public List getNetworksFromLocation(Location l, Class type) { + @Nonnull + public List getNetworksFromLocation(@Nullable Location l, @Nonnull Class type) { if (l == null) { // No networks here, if the location does not even exist return new ArrayList<>(); @@ -97,7 +103,7 @@ public class NetworkManager { * @param network * The {@link Network} to register */ - public void registerNetwork(Network network) { + public void registerNetwork(@Nonnull Network network) { Validate.notNull(network, "Cannot register a null Network"); networks.add(network); } @@ -108,7 +114,7 @@ public class NetworkManager { * @param network * The {@link Network} to remove */ - public void unregisterNetwork(Network network) { + public void unregisterNetwork(@Nonnull Network network) { Validate.notNull(network, "Cannot unregister a null Network"); networks.remove(network); } @@ -120,7 +126,9 @@ public class NetworkManager { * @param l * The {@link Location} to update */ - public void updateAllNetworks(Location l) { + public void updateAllNetworks(@Nonnull Location l) { + Validate.notNull(l, "The Location cannot be null"); + for (Network network : getNetworksFromLocation(l, Network.class)) { network.markDirty(l); } diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/core/networks/cargo/CargoNet.java b/src/main/java/io/github/thebusybiscuit/slimefun4/core/networks/cargo/CargoNet.java index 681fffaaa..c7fa6fcef 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/core/networks/cargo/CargoNet.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/core/networks/cargo/CargoNet.java @@ -9,6 +9,8 @@ import java.util.Optional; import java.util.Set; import java.util.logging.Level; +import javax.annotation.Nonnull; + import org.bukkit.Location; import org.bukkit.block.Block; import org.bukkit.inventory.ItemStack; @@ -46,11 +48,11 @@ public class CargoNet extends ChestTerminalNetwork { protected final Map roundRobin = new HashMap<>(); private int tickDelayThreshold = 0; - public static CargoNet getNetworkFromLocation(Location l) { + public static CargoNet getNetworkFromLocation(@Nonnull Location l) { return SlimefunPlugin.getNetworkManager().getNetworkFromLocation(l, CargoNet.class).orElse(null); } - public static CargoNet getNetworkFromLocationOrCreate(Location l) { + public static CargoNet getNetworkFromLocationOrCreate(@Nonnull Location l) { Optional cargoNetwork = SlimefunPlugin.getNetworkManager().getNetworkFromLocation(l, CargoNet.class); if (cargoNetwork.isPresent()) { @@ -69,7 +71,7 @@ public class CargoNet extends ChestTerminalNetwork { * @param l * The {@link Location} marking the manager of this {@link Network}. */ - protected CargoNet(Location l) { + protected CargoNet(@Nonnull Location l) { super(l); } @@ -79,7 +81,7 @@ public class CargoNet extends ChestTerminalNetwork { } @Override - public NetworkComponent classifyLocation(Location l) { + public NetworkComponent classifyLocation(@Nonnull Location l) { String id = BlockStorage.checkID(l); if (id == null) { diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/core/networks/cargo/CargoNetworkTask.java b/src/main/java/io/github/thebusybiscuit/slimefun4/core/networks/cargo/CargoNetworkTask.java index 11b87f47e..a65bdb25a 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/core/networks/cargo/CargoNetworkTask.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/core/networks/cargo/CargoNetworkTask.java @@ -8,6 +8,8 @@ import java.util.Map; import java.util.Optional; import java.util.Set; +import javax.annotation.ParametersAreNonnullByDefault; + import org.bukkit.Location; import org.bukkit.block.Block; import org.bukkit.inventory.Inventory; @@ -44,6 +46,7 @@ class CargoNetworkTask implements Runnable { private final Set chestTerminalInputs; private final Set chestTerminalOutputs; + @ParametersAreNonnullByDefault CargoNetworkTask(CargoNet network, Map inputs, Map> outputs, Set chestTerminalInputs, Set chestTerminalOutputs) { this.network = network; diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/core/networks/cargo/CargoUtils.java b/src/main/java/io/github/thebusybiscuit/slimefun4/core/networks/cargo/CargoUtils.java index 1d7b08dda..e6eefd438 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/core/networks/cargo/CargoUtils.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/core/networks/cargo/CargoUtils.java @@ -3,6 +3,9 @@ package io.github.thebusybiscuit.slimefun4.core.networks.cargo; import java.util.Map; import java.util.logging.Level; +import javax.annotation.Nonnull; +import javax.annotation.Nullable; + import org.bukkit.Location; import org.bukkit.Material; import org.bukkit.Tag; @@ -43,7 +46,7 @@ final class CargoUtils { * * @return Whether this {@link Block} represents a {@link BlockState} that is an {@link InventoryHolder} */ - static boolean hasInventory(Block block) { + static boolean hasInventory(@Nullable Block block) { if (block == null) { // No block, no inventory return false; @@ -83,9 +86,9 @@ final class CargoUtils { return false; } - static int[] getInputSlotRange(Inventory inv, ItemStack item) { + static int[] getInputSlotRange(@Nonnull Inventory inv, @Nullable ItemStack item) { if (inv instanceof FurnaceInventory) { - if (item.getType().isFuel()) { + if (item != null && item.getType().isFuel()) { if (isSmeltable(item, true)) { // Any non-smeltable items should not land in the upper slot return new int[] { 0, 2 }; @@ -352,7 +355,7 @@ final class CargoUtils { return stack; } - static DirtyChestMenu getChestMenu(Block block) { + static DirtyChestMenu getChestMenu(@Nonnull Block block) { if (BlockStorage.hasInventory(block)) { return BlockStorage.getInventory(block); } @@ -360,7 +363,7 @@ final class CargoUtils { return BlockStorage.getUniversalInventory(block); } - static boolean matchesFilter(Block block, ItemStack item) { + static boolean matchesFilter(@Nonnull Block block, @Nullable ItemStack item) { if (item == null || item.getType() == Material.AIR) { return false; } @@ -443,7 +446,7 @@ final class CargoUtils { * * @return Whether the given {@link ItemStack} can be smelted or not */ - private static boolean isSmeltable(ItemStack stack, boolean lazy) { + private static boolean isSmeltable(@Nullable ItemStack stack, boolean lazy) { if (lazy) { return stack != null && Tag.LOGS.isTagged(stack.getType()); } @@ -452,7 +455,7 @@ final class CargoUtils { } } - private static boolean isPotion(ItemStack item) { + private static boolean isPotion(@Nullable ItemStack item) { return item != null && (item.getType() == Material.POTION || item.getType() == Material.SPLASH_POTION || item.getType() == Material.LINGERING_POTION); } diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/core/networks/cargo/ChestTerminalNetwork.java b/src/main/java/io/github/thebusybiscuit/slimefun4/core/networks/cargo/ChestTerminalNetwork.java index 528a324cc..7def32c14 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/core/networks/cargo/ChestTerminalNetwork.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/core/networks/cargo/ChestTerminalNetwork.java @@ -14,6 +14,8 @@ import java.util.Queue; import java.util.Set; import java.util.logging.Level; +import javax.annotation.Nonnull; + import org.bukkit.Location; import org.bukkit.Material; import org.bukkit.block.Block; @@ -277,7 +279,7 @@ abstract class ChestTerminalNetwork extends Network { * * @return The time it took to compute this operation */ - protected long updateTerminals(Set providers) { + protected long updateTerminals(@Nonnull Set providers) { if (terminals.isEmpty()) { // Performance improvement - We don't need to compute items for // Cargo networks without any Chest Terminals @@ -316,7 +318,12 @@ abstract class ChestTerminalNetwork extends Network { item.error("An Exception was caused while trying to tick Chest terminals", x); } - return SlimefunPlugin.getProfiler().closeEntry(firstTerminal, item, timestamp); + if (firstTerminal != null) { + return SlimefunPlugin.getProfiler().closeEntry(firstTerminal, item, timestamp); + } + else { + return System.nanoTime() - timestamp; + } } private void updateTerminal(Location l, BlockMenu terminal, int slot, int index, List items) { @@ -361,7 +368,8 @@ abstract class ChestTerminalNetwork extends Network { } } - private List findAvailableItems(Set providers) { + @Nonnull + private List findAvailableItems(@Nonnull Set providers) { List items = new LinkedList<>(); for (Location l : providers) { diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/core/networks/energy/EnergyNet.java b/src/main/java/io/github/thebusybiscuit/slimefun4/core/networks/energy/EnergyNet.java index b0ca332ed..f10217f74 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/core/networks/energy/EnergyNet.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/core/networks/energy/EnergyNet.java @@ -8,6 +8,9 @@ import java.util.Set; import java.util.concurrent.atomic.AtomicLong; import java.util.function.LongConsumer; +import javax.annotation.Nonnull; +import javax.annotation.Nullable; + import org.bukkit.Location; import org.bukkit.Material; import org.bukkit.block.Block; @@ -47,7 +50,7 @@ public class EnergyNet extends Network { private final Map capacitors = new HashMap<>(); private final Map consumers = new HashMap<>(); - protected EnergyNet(Location l) { + protected EnergyNet(@Nonnull Location l) { super(SlimefunPlugin.getNetworkManager(), l); } @@ -57,7 +60,7 @@ public class EnergyNet extends Network { } @Override - public NetworkComponent classifyLocation(Location l) { + public NetworkComponent classifyLocation(@Nonnull Location l) { if (regulator.equals(l)) { return NetworkComponent.REGULATOR; } @@ -111,7 +114,7 @@ public class EnergyNet extends Network { } } - public void tick(Block b) { + public void tick(@Nonnull Block b) { AtomicLong timestamp = new AtomicLong(SlimefunPlugin.getProfiler().newEntry()); if (!regulator.equals(b.getLocation())) { @@ -204,7 +207,7 @@ public class EnergyNet extends Network { } } - private int tickAllGenerators(LongConsumer timings) { + private int tickAllGenerators(@Nonnull LongConsumer timings) { Set explodedBlocks = new HashSet<>(); int supply = 0; @@ -259,7 +262,7 @@ public class EnergyNet extends Network { return supply; } - private void updateHologram(Block b, double supply, double demand) { + private void updateHologram(@Nonnull Block b, double supply, double demand) { if (demand > supply) { String netLoss = DoubleHandler.getFancyDouble(Math.abs(supply - demand)); SimpleHologram.update(b, "&4&l- &c" + netLoss + " &7J &e\u26A1"); @@ -270,7 +273,8 @@ public class EnergyNet extends Network { } } - private static EnergyNetComponent getComponent(Location l) { + @Nullable + private static EnergyNetComponent getComponent(@Nonnull Location l) { SlimefunItem item = BlockStorage.check(l); if (item instanceof EnergyNetComponent) { @@ -289,7 +293,8 @@ public class EnergyNet extends Network { * * @return The {@link EnergyNet} at that {@link Location}, or a new one */ - public static EnergyNet getNetworkFromLocationOrCreate(Location l) { + @Nonnull + public static EnergyNet getNetworkFromLocationOrCreate(@Nonnull Location l) { Optional energyNetwork = SlimefunPlugin.getNetworkManager().getNetworkFromLocation(l, EnergyNet.class); if (energyNetwork.isPresent()) { diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/core/researching/Research.java b/src/main/java/io/github/thebusybiscuit/slimefun4/core/researching/Research.java index 410ed6b0e..5ddb56b59 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/core/researching/Research.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/core/researching/Research.java @@ -6,6 +6,10 @@ import java.util.List; import java.util.Optional; import java.util.function.Consumer; +import javax.annotation.Nonnull; +import javax.annotation.Nullable; + +import org.apache.commons.lang.Validate; import org.bukkit.Bukkit; import org.bukkit.GameMode; import org.bukkit.Keyed; @@ -58,16 +62,19 @@ public class Research implements Keyed { * A unique identifier for this {@link Research} * @param id * old way of identifying researches - * @param name + * @param defaultName * The displayed name of this {@link Research} * @param defaultCost * The Cost in XP levels to unlock this {@link Research} * */ - public Research(NamespacedKey key, int id, String name, int defaultCost) { + public Research(@Nonnull NamespacedKey key, int id, @Nonnull String defaultName, int defaultCost) { + Validate.notNull(key, "A NamespacedKey must be provided"); + Validate.notNull(defaultName, "A default name must be specified"); + this.key = key; this.id = id; - this.name = name; + this.name = defaultName; this.cost = defaultCost; } @@ -109,7 +116,8 @@ public class Research implements Keyed { * The {@link Player} to translate this name for. * @return The localized Name of this {@link Research}. */ - public String getName(Player p) { + @Nonnull + public String getName(@Nonnull Player p) { String localized = SlimefunPlugin.getLocalization().getResearchName(p, key); return localized != null ? localized : name; } @@ -159,6 +167,7 @@ public class Research implements Keyed { * * @return The current instance of {@link Research} */ + @Nonnull public Research addItems(ItemStack... items) { for (ItemStack item : items) { SlimefunItem sfItem = SlimefunItem.getByItem(item); @@ -176,6 +185,7 @@ public class Research implements Keyed { * * @return The Slimefun items bound to this {@link Research}. */ + @Nonnull public List getAffectedItems() { return items; } @@ -187,7 +197,7 @@ public class Research implements Keyed { * The {@link Player} to check * @return Whether that {@link Player} can unlock this {@link Research} */ - public boolean canUnlock(Player p) { + public boolean canUnlock(@Nonnull Player p) { if (!isEnabled()) { return true; } @@ -204,7 +214,7 @@ public class Research implements Keyed { * @param instant * Whether to unlock it instantly */ - public void unlock(Player p, boolean instant) { + public void unlock(@Nonnull Player p, boolean instant) { unlock(p, instant, pl -> {}); } @@ -218,18 +228,20 @@ public class Research implements Keyed { * @param callback * A callback which will be run when the {@link Research} animation completed */ - public void unlock(Player p, boolean instant, Consumer callback) { + public void unlock(@Nonnull Player p, boolean instant, @Nonnull Consumer callback) { if (!instant) { Slimefun.runSync(() -> { p.playSound(p.getLocation(), Sound.ENTITY_BAT_TAKEOFF, 0.7F, 1F); SlimefunPlugin.getLocalization().sendMessage(p, "messages.research.progress", true, msg -> msg.replace(PLACEHOLDER_RESEARCH, getName(p)).replace("%progress%", "0%")); }, 10L); } + PlayerProfile.get(p, profile -> { if (!profile.hasUnlocked(this)) { Slimefun.runSync(() -> { ResearchUnlockEvent event = new ResearchUnlockEvent(p, this); Bukkit.getPluginManager().callEvent(event); + if (!event.isCancelled()) { if (instant) { finishResearch(p, profile, callback); @@ -249,7 +261,7 @@ public class Research implements Keyed { }); } - private void finishResearch(Player p, PlayerProfile profile, Consumer callback) { + private void finishResearch(@Nonnull Player p, @Nonnull PlayerProfile profile, @Nonnull Consumer callback) { profile.setResearched(this, true); SlimefunPlugin.getLocalization().sendMessage(p, "messages.unlocked", true, msg -> msg.replace(PLACEHOLDER_RESEARCH, getName(p))); callback.accept(p); @@ -259,7 +271,7 @@ public class Research implements Keyed { } } - private void playResearchAnimation(Player p) { + private void playResearchAnimation(@Nonnull Player p) { for (int i = 1; i < RESEARCH_PROGRESS.length + 1; i++) { int j = i; @@ -306,7 +318,8 @@ public class Research implements Keyed { * * @return An {@link Optional} with or without the found {@link Research} */ - public static Optional getResearch(NamespacedKey key) { + @Nonnull + public static Optional getResearch(@Nullable NamespacedKey key) { if (key == null) { return Optional.empty(); } diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/core/services/github/Contributor.java b/src/main/java/io/github/thebusybiscuit/slimefun4/core/services/github/Contributor.java index a4e27d094..371a223e9 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/core/services/github/Contributor.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/core/services/github/Contributor.java @@ -165,7 +165,7 @@ public class Contributor { return headTexture.isComputed(); } - public void setTexture(@Nonnull String skin) { + public void setTexture(@Nullable String skin) { headTexture.compute(skin); } @@ -177,6 +177,7 @@ public class Contributor { return -getTotalContributions(); } + @Nonnull public String getDisplayName() { return ChatColor.GRAY + githubUsername + (!githubUsername.equals(minecraftUsername) ? ChatColor.DARK_GRAY + " (MC: " + minecraftUsername + ")" : ""); } diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/core/services/github/GitHubService.java b/src/main/java/io/github/thebusybiscuit/slimefun4/core/services/github/GitHubService.java index 5db576173..6853ee218 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/core/services/github/GitHubService.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/core/services/github/GitHubService.java @@ -101,9 +101,9 @@ public class GitHubService { connectors.add(new ContributionsConnector(this, "resourcepack", 1, "Slimefun/Resourcepack", "resourcepack")); // Issues and Pull Requests - connectors.add(new GitHubIssuesTracker(this, repository, (issues, pullRequests) -> { - this.issues = issues; - this.pullRequests = pullRequests; + connectors.add(new GitHubIssuesTracker(this, repository, (openIssues, openPullRequests) -> { + this.issues = openIssues; + this.pullRequests = openPullRequests; })); connectors.add(new GitHubConnector(this, repository) { diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/core/services/plugins/ThirdPartyPluginService.java b/src/main/java/io/github/thebusybiscuit/slimefun4/core/services/plugins/ThirdPartyPluginService.java index 65c285540..e90f0b0fa 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/core/services/plugins/ThirdPartyPluginService.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/core/services/plugins/ThirdPartyPluginService.java @@ -4,6 +4,8 @@ import java.util.Optional; import java.util.function.Function; import java.util.logging.Level; +import javax.annotation.Nonnull; + import org.bukkit.NamespacedKey; import org.bukkit.block.Block; import org.bukkit.inventory.ItemStack; @@ -38,7 +40,7 @@ public class ThirdPartyPluginService { // Overridden if ExoticGarden is loaded private Function> exoticGardenIntegration = b -> Optional.empty(); - public ThirdPartyPluginService(SlimefunPlugin plugin) { + public ThirdPartyPluginService(@Nonnull SlimefunPlugin plugin) { this.plugin = plugin; } @@ -92,7 +94,7 @@ public class ThirdPartyPluginService { }); } - private boolean isPluginInstalled(String hook) { + private boolean isPluginInstalled(@Nonnull String hook) { if (plugin.getServer().getPluginManager().isPluginEnabled(hook)) { Slimefun.getLogger().log(Level.INFO, "Hooked into Plugin: {0}", hook); return true; diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/SlimefunPlugin.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/SlimefunPlugin.java index 44ec525eb..da8208f6f 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/SlimefunPlugin.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/SlimefunPlugin.java @@ -10,6 +10,9 @@ import java.util.Set; import java.util.logging.Level; import java.util.stream.Collectors; +import javax.annotation.Nonnull; +import javax.annotation.Nullable; + import org.bukkit.Bukkit; import org.bukkit.Server; import org.bukkit.command.Command; @@ -288,6 +291,7 @@ public final class SlimefunPlugin extends JavaPlugin implements SlimefunAddon { } } + @Nonnull private String getStartupTime(long timestamp) { long ms = (System.nanoTime() - timestamp) / 1000000; @@ -332,6 +336,7 @@ public final class SlimefunPlugin extends JavaPlugin implements SlimefunAddon { return false; } + @Nonnull private Collection getSupportedVersions() { List list = new ArrayList<>(); @@ -511,6 +516,7 @@ public final class SlimefunPlugin extends JavaPlugin implements SlimefunAddon { * * @return The {@link SlimefunPlugin} instance */ + @Nullable public static SlimefunPlugin instance() { return instance; } @@ -643,6 +649,7 @@ public final class SlimefunPlugin extends JavaPlugin implements SlimefunAddon { * * @return A {@link Set} of every {@link Plugin} that is dependent on Slimefun */ + @Nonnull public static Set getInstalledAddons() { return Arrays.stream(instance.getServer().getPluginManager().getPlugins()).filter(plugin -> plugin.getDescription().getDepend().contains(instance.getName()) || plugin.getDescription().getSoftDepend().contains(instance.getName())).collect(Collectors.toSet()); } diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/SimpleSlimefunItem.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/SimpleSlimefunItem.java index f8ce58999..cdafede2d 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/SimpleSlimefunItem.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/SimpleSlimefunItem.java @@ -1,5 +1,7 @@ package io.github.thebusybiscuit.slimefun4.implementation.items; +import javax.annotation.Nonnull; + import org.bukkit.inventory.ItemStack; import io.github.thebusybiscuit.slimefun4.core.handlers.ItemUseHandler; @@ -45,6 +47,7 @@ public abstract class SimpleSlimefunItem extends Slimefun * * @return The {@link ItemHandler} that should be added to this {@link SlimefunItem} */ + @Nonnull public abstract T getItemHandler(); } diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/electric/gadgets/MultiTool.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/electric/gadgets/MultiTool.java index 72d6dda81..b9cd1696b 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/electric/gadgets/MultiTool.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/electric/gadgets/MultiTool.java @@ -8,7 +8,6 @@ import java.util.UUID; import org.bukkit.ChatColor; import org.bukkit.entity.Player; -import org.bukkit.event.block.BlockBreakEvent; import org.bukkit.inventory.ItemStack; import io.github.thebusybiscuit.slimefun4.core.attributes.Rechargeable; diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/medical/MedicalSupply.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/medical/MedicalSupply.java index a9c0cd826..243bb3d81 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/medical/MedicalSupply.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/medical/MedicalSupply.java @@ -3,7 +3,7 @@ package io.github.thebusybiscuit.slimefun4.implementation.items.medical; import javax.annotation.Nonnull; import org.bukkit.attribute.Attribute; -import org.bukkit.entity.Player; +import org.bukkit.entity.LivingEntity; import org.bukkit.inventory.ItemStack; import org.bukkit.potion.PotionEffect; import org.bukkit.potion.PotionEffectType; @@ -25,26 +25,32 @@ public abstract class MedicalSupply extends SimpleSlimefu } /** - * This method clears any negative {@link PotionEffect} from the given {@link Player}. + * This method clears any negative {@link PotionEffect} from the given {@link LivingEntity}. * - * @param p - * The {@link Player} + * @param n + * The {@link LivingEntity} to clear the effects from. */ - public void clearNegativeEffects(@Nonnull Player p) { - if (p.hasPotionEffect(PotionEffectType.POISON)) p.removePotionEffect(PotionEffectType.POISON); - if (p.hasPotionEffect(PotionEffectType.WITHER)) p.removePotionEffect(PotionEffectType.WITHER); - if (p.hasPotionEffect(PotionEffectType.SLOW)) p.removePotionEffect(PotionEffectType.SLOW); - if (p.hasPotionEffect(PotionEffectType.SLOW_DIGGING)) p.removePotionEffect(PotionEffectType.SLOW_DIGGING); - if (p.hasPotionEffect(PotionEffectType.WEAKNESS)) p.removePotionEffect(PotionEffectType.WEAKNESS); - if (p.hasPotionEffect(PotionEffectType.CONFUSION)) p.removePotionEffect(PotionEffectType.CONFUSION); - if (p.hasPotionEffect(PotionEffectType.BLINDNESS)) p.removePotionEffect(PotionEffectType.BLINDNESS); - if (p.hasPotionEffect(PotionEffectType.BAD_OMEN)) p.removePotionEffect(PotionEffectType.BLINDNESS); + public void clearNegativeEffects(@Nonnull LivingEntity n) { + if (n.hasPotionEffect(PotionEffectType.POISON)) n.removePotionEffect(PotionEffectType.POISON); + if (n.hasPotionEffect(PotionEffectType.WITHER)) n.removePotionEffect(PotionEffectType.WITHER); + if (n.hasPotionEffect(PotionEffectType.SLOW)) n.removePotionEffect(PotionEffectType.SLOW); + if (n.hasPotionEffect(PotionEffectType.SLOW_DIGGING)) n.removePotionEffect(PotionEffectType.SLOW_DIGGING); + if (n.hasPotionEffect(PotionEffectType.WEAKNESS)) n.removePotionEffect(PotionEffectType.WEAKNESS); + if (n.hasPotionEffect(PotionEffectType.CONFUSION)) n.removePotionEffect(PotionEffectType.CONFUSION); + if (n.hasPotionEffect(PotionEffectType.BLINDNESS)) n.removePotionEffect(PotionEffectType.BLINDNESS); + if (n.hasPotionEffect(PotionEffectType.BAD_OMEN)) n.removePotionEffect(PotionEffectType.BLINDNESS); } - public void heal(@Nonnull Player p) { - double health = p.getHealth() + healAmount; - double maxHealth = p.getAttribute(Attribute.GENERIC_MAX_HEALTH).getValue(); - p.setHealth(Math.min(health, maxHealth)); + /** + * This method heals the given {@link LivingEntity} by the amount provided via the constructor. + * + * @param n + * The {@link LivingEntity} to heal + */ + public void heal(@Nonnull LivingEntity n) { + double health = n.getHealth() + healAmount; + double maxHealth = n.getAttribute(Attribute.GENERIC_MAX_HEALTH).getValue(); + n.setHealth(Math.min(health, maxHealth)); } } diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/utils/ChestMenuUtils.java b/src/main/java/io/github/thebusybiscuit/slimefun4/utils/ChestMenuUtils.java index 22fb6b61b..82ff6cfee 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/utils/ChestMenuUtils.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/utils/ChestMenuUtils.java @@ -3,6 +3,8 @@ package io.github.thebusybiscuit.slimefun4.utils; import java.util.Arrays; import java.util.List; +import javax.annotation.Nonnull; + import org.bukkit.ChatColor; import org.bukkit.Material; import org.bukkit.entity.Player; @@ -36,23 +38,28 @@ public final class ChestMenuUtils { private static final MenuClickHandler CLICK_HANDLER = (p, s, i, a) -> false; + @Nonnull public static ItemStack getBackground() { return UI_BACKGROUND; } + @Nonnull public static MenuClickHandler getEmptyClickHandler() { return CLICK_HANDLER; } - public static ItemStack getBackButton(Player p, String... lore) { + @Nonnull + public static ItemStack getBackButton(@Nonnull Player p, String... lore) { return new CustomItem(BACK_BUTTON, "&7\u21E6 " + SlimefunPlugin.getLocalization().getMessage(p, "guide.back.title"), lore); } - public static ItemStack getMenuButton(Player p) { + @Nonnull + public static ItemStack getMenuButton(@Nonnull Player p) { return new CustomItem(MENU_BUTTON, ChatColor.YELLOW + SlimefunPlugin.getLocalization().getMessage(p, "guide.title.settings"), "", "&7\u21E8 " + SlimefunPlugin.getLocalization().getMessage(p, "guide.tooltips.open-category")); } - public static ItemStack getSearchButton(Player p) { + @Nonnull + public static ItemStack getSearchButton(@Nonnull Player p) { return new CustomItem(SEARCH_BUTTON, meta -> { meta.setDisplayName(ChatColors.color(SlimefunPlugin.getLocalization().getMessage(p, "guide.search.name"))); @@ -62,45 +69,50 @@ public final class ChestMenuUtils { }); } + @Nonnull public static ItemStack getWikiButton() { return WIKI_BUTTON; } - public static ItemStack getPreviousButton(Player p, int page, int pages) { + @Nonnull + public static ItemStack getPreviousButton(@Nonnull Player p, int page, int pages) { if (pages == 1 || page == 1) { return new CustomItem(PREV_BUTTON_INACTIVE, meta -> { meta.setDisplayName(ChatColor.DARK_GRAY + "\u21E6 " + SlimefunPlugin.getLocalization().getMessage(p, "guide.pages.previous")); meta.setLore(Arrays.asList("", ChatColor.GRAY + "(" + page + " / " + pages + ")")); }); } - - return new CustomItem(PREV_BUTTON_ACTIVE, meta -> { - meta.setDisplayName(ChatColor.WHITE + "\u21E6 " + SlimefunPlugin.getLocalization().getMessage(p, "guide.pages.previous")); - meta.setLore(Arrays.asList("", ChatColor.GRAY + "(" + page + " / " + pages + ")")); - }); + else { + return new CustomItem(PREV_BUTTON_ACTIVE, meta -> { + meta.setDisplayName(ChatColor.WHITE + "\u21E6 " + SlimefunPlugin.getLocalization().getMessage(p, "guide.pages.previous")); + meta.setLore(Arrays.asList("", ChatColor.GRAY + "(" + page + " / " + pages + ")")); + }); + } } - public static ItemStack getNextButton(Player p, int page, int pages) { + @Nonnull + public static ItemStack getNextButton(@Nonnull Player p, int page, int pages) { if (pages == 1 || page == pages) { return new CustomItem(NEXT_BUTTON_INACTIVE, meta -> { meta.setDisplayName(ChatColor.DARK_GRAY + SlimefunPlugin.getLocalization().getMessage(p, "guide.pages.next") + " \u21E8"); meta.setLore(Arrays.asList("", ChatColor.GRAY + "(" + page + " / " + pages + ")")); }); } - - return new CustomItem(NEXT_BUTTON_ACTIVE, meta -> { - meta.setDisplayName(ChatColor.WHITE + SlimefunPlugin.getLocalization().getMessage(p, "guide.pages.next") + " \u21E8"); - meta.setLore(Arrays.asList("", ChatColor.GRAY + "(" + page + " / " + pages + ")")); - }); + else { + return new CustomItem(NEXT_BUTTON_ACTIVE, meta -> { + meta.setDisplayName(ChatColor.WHITE + SlimefunPlugin.getLocalization().getMessage(p, "guide.pages.next") + " \u21E8"); + meta.setLore(Arrays.asList("", ChatColor.GRAY + "(" + page + " / " + pages + ")")); + }); + } } - public static void drawBackground(ChestMenu menu, int... slots) { + public static void drawBackground(@Nonnull ChestMenu menu, int... slots) { for (int slot : slots) { menu.addItem(slot, getBackground(), getEmptyClickHandler()); } } - public static void updateProgressbar(ChestMenu menu, int slot, int timeLeft, int time, ItemStack indicator) { + public static void updateProgressbar(@Nonnull ChestMenu menu, int slot, int timeLeft, int time, @Nonnull ItemStack indicator) { Inventory inv = menu.toInventory(); // We don't need to update the progress bar if noone is watching :o @@ -123,6 +135,7 @@ public final class ChestMenuUtils { menu.replaceExistingItem(slot, item); } + @Nonnull public static String getProgressBar(int time, int total) { StringBuilder builder = new StringBuilder(); float percentage = Math.round(((((total - time) * 100.0F) / total) * 100.0F) / 100.0F); @@ -145,7 +158,7 @@ public final class ChestMenuUtils { return ChatColors.color(builder.toString()); } - private static short getDurability(ItemStack item, int timeLeft, int max) { + private static short getDurability(@Nonnull ItemStack item, int timeLeft, int max) { return (short) ((item.getType().getMaxDurability() / max) * timeLeft); } diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/utils/holograms/ReactorHologram.java b/src/main/java/io/github/thebusybiscuit/slimefun4/utils/holograms/ReactorHologram.java index 4f5a537fd..0060a0454 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/utils/holograms/ReactorHologram.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/utils/holograms/ReactorHologram.java @@ -1,5 +1,8 @@ package io.github.thebusybiscuit.slimefun4.utils.holograms; +import javax.annotation.Nonnull; +import javax.annotation.Nullable; + import org.bukkit.Location; import org.bukkit.entity.ArmorStand; import org.bukkit.entity.Entity; @@ -11,7 +14,8 @@ public final class ReactorHologram { private ReactorHologram() {} - public static ArmorStand getArmorStand(Location reactor, boolean createIfNoneExists) { + @Nullable + public static ArmorStand getArmorStand(@Nonnull Location reactor, boolean createIfNoneExists) { Location l = new Location(reactor.getWorld(), reactor.getX() + 0.5, reactor.getY() + 0.7, reactor.getZ() + 0.5); for (Entity n : l.getChunk().getEntities()) { @@ -30,7 +34,7 @@ public final class ReactorHologram { return hologram; } - public static void update(Location l, String name) { + public static void update(@Nonnull Location l, @Nonnull String name) { Slimefun.runSync(() -> { ArmorStand hologram = getArmorStand(l, true); diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/utils/holograms/SimpleHologram.java b/src/main/java/io/github/thebusybiscuit/slimefun4/utils/holograms/SimpleHologram.java index 42204e421..fc24ea0a8 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/utils/holograms/SimpleHologram.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/utils/holograms/SimpleHologram.java @@ -1,5 +1,8 @@ package io.github.thebusybiscuit.slimefun4.utils.holograms; +import javax.annotation.Nonnull; +import javax.annotation.Nullable; + import org.bukkit.Location; import org.bukkit.block.Block; import org.bukkit.entity.ArmorStand; @@ -19,14 +22,14 @@ public final class SimpleHologram { private SimpleHologram() {} - public static void update(Block b, String name) { + public static void update(@Nonnull Block b, @Nonnull String name) { Slimefun.runSync(() -> { ArmorStand hologram = getArmorStand(b, true); hologram.setCustomName(ChatColors.color(name)); }); } - public static void remove(Block b) { + public static void remove(@Nonnull Block b) { Slimefun.runSync(() -> { ArmorStand hologram = getArmorStand(b, false); @@ -36,7 +39,8 @@ public final class SimpleHologram { }); } - private static ArmorStand getArmorStand(Block b, boolean createIfNoneExists) { + @Nullable + private static ArmorStand getArmorStand(@Nonnull Block b, boolean createIfNoneExists) { Location l = new Location(b.getWorld(), b.getX() + 0.5, b.getY() + 0.7F, b.getZ() + 0.5); for (Entity n : l.getChunk().getEntities()) { @@ -53,11 +57,12 @@ public final class SimpleHologram { } } - private static boolean isPossibleHologram(ArmorStand armorstand) { + private static boolean isPossibleHologram(@Nonnull ArmorStand armorstand) { return armorstand.isValid() && armorstand.isSilent() && armorstand.isMarker() && !armorstand.hasGravity() && armorstand.isCustomNameVisible(); } - public static ArmorStand create(Location l) { + @Nonnull + public static ArmorStand create(@Nonnull Location l) { ArmorStand armorStand = (ArmorStand) l.getWorld().spawnEntity(l, EntityType.ARMOR_STAND); armorStand.setVisible(false); armorStand.setSilent(true); diff --git a/src/main/java/me/mrCookieSlime/Slimefun/Objects/Category.java b/src/main/java/me/mrCookieSlime/Slimefun/Objects/Category.java index c6db50881..45f42508e 100644 --- a/src/main/java/me/mrCookieSlime/Slimefun/Objects/Category.java +++ b/src/main/java/me/mrCookieSlime/Slimefun/Objects/Category.java @@ -6,6 +6,9 @@ import java.util.Collections; import java.util.Comparator; import java.util.List; +import javax.annotation.Nonnull; +import javax.annotation.ParametersAreNonnullByDefault; + import org.apache.commons.lang.Validate; import org.bukkit.ChatColor; import org.bukkit.Keyed; @@ -49,6 +52,7 @@ public class Category implements Keyed { * @param item * The {@link ItemStack} that is used to display this {@link Category} */ + @ParametersAreNonnullByDefault public Category(NamespacedKey key, ItemStack item) { this(key, item, 3); } @@ -65,6 +69,7 @@ public class Category implements Keyed { * The tier of this {@link Category}, higher tiers will make this {@link Category} appear further down in * the {@link SlimefunGuide} */ + @ParametersAreNonnullByDefault public Category(NamespacedKey key, ItemStack item, int tier) { Validate.notNull(key, "A Category's NamespacedKey must not be null!"); Validate.notNull(item, "A Category's ItemStack must not be null!"); @@ -101,7 +106,7 @@ public class Category implements Keyed { * @param item * the {@link SlimefunItem} that should be added to this {@link Category} */ - public void add(SlimefunItem item) { + public void add(@Nonnull SlimefunItem item) { Validate.notNull(item, "Cannot add null Items to a Category!"); if (items.contains(item)) { @@ -118,7 +123,8 @@ public class Category implements Keyed { * @param item * the {@link SlimefunItem} that should be removed from this {@link Category} */ - public void remove(SlimefunItem item) { + public void remove(@Nonnull SlimefunItem item) { + Validate.notNull(item, "Cannot remove null from a Category!"); items.remove(item); } @@ -130,7 +136,8 @@ public class Category implements Keyed { * The Player to create this {@link ItemStack} for * @return A localized display item for this {@link Category} */ - public ItemStack getItem(Player p) { + @Nonnull + public ItemStack getItem(@Nonnull Player p) { return new CustomItem(item, meta -> { String name = SlimefunPlugin.getLocalization().getCategoryName(p, getKey()); @@ -155,6 +162,7 @@ public class Category implements Keyed { * * @return The unlocalized name of this {@link Category} */ + @Nonnull public String getUnlocalizedName() { return ChatColor.stripColor(item.getItemMeta().getDisplayName()); } @@ -164,6 +172,7 @@ public class Category implements Keyed { * * @return the list of SlimefunItems bound to this category */ + @Nonnull public List getItems() { return items; } @@ -206,7 +215,7 @@ public class Category implements Keyed { * * @return Whether this {@link Category} will be hidden to the given {@link Player} */ - public boolean isHidden(Player p) { + public boolean isHidden(@Nonnull Player p) { for (SlimefunItem slimefunItem : getItems()) { if (!slimefunItem.isHidden() && Slimefun.isEnabled(p, slimefunItem, false)) { return false; diff --git a/src/main/java/me/mrCookieSlime/Slimefun/Objects/SlimefunItem/SlimefunItem.java b/src/main/java/me/mrCookieSlime/Slimefun/Objects/SlimefunItem/SlimefunItem.java index 7536cf48e..5d94ade5c 100644 --- a/src/main/java/me/mrCookieSlime/Slimefun/Objects/SlimefunItem/SlimefunItem.java +++ b/src/main/java/me/mrCookieSlime/Slimefun/Objects/SlimefunItem/SlimefunItem.java @@ -10,6 +10,7 @@ import java.util.function.Consumer; import java.util.logging.Level; import javax.annotation.Nonnull; +import javax.annotation.Nullable; import org.apache.commons.lang.Validate; import org.bukkit.Material; @@ -136,6 +137,7 @@ public class SlimefunItem implements Placeable { * * @return the identifier of this {@link SlimefunItem} */ + @Nonnull public final String getID() { return id; } @@ -149,6 +151,7 @@ public class SlimefunItem implements Placeable { * * @return The {@link ItemState} of this {@link SlimefunItem} */ + @Nonnull public ItemState getState() { return state; } @@ -159,6 +162,7 @@ public class SlimefunItem implements Placeable { * * @return The {@link ItemStack} that this {@link SlimefunItem} represents */ + @Nonnull public ItemStack getItem() { return item; } @@ -169,6 +173,7 @@ public class SlimefunItem implements Placeable { * * @return The {@link Category} that this {@link SlimefunItem} belongs to */ + @Nonnull public Category getCategory() { return category; } @@ -186,6 +191,7 @@ public class SlimefunItem implements Placeable { * * @return The recipe output of this {@link SlimefunItem} */ + @Nonnull public ItemStack getRecipeOutput() { return recipeOutput != null ? recipeOutput.clone() : item.clone(); } @@ -196,6 +202,7 @@ public class SlimefunItem implements Placeable { * * @return The linked {@link Research} or null */ + @Nullable public Research getResearch() { return research; } @@ -205,6 +212,7 @@ public class SlimefunItem implements Placeable { * * @return A {@link Set} of every {@link ItemSetting} for this {@link SlimefunItem} */ + @Nonnull public Set> getItemSettings() { return itemSettings; } @@ -222,6 +230,7 @@ public class SlimefunItem implements Placeable { * @return An {@link Optional} describing the result */ @SuppressWarnings("unchecked") + @Nonnull public Optional> getItemSetting(String key, Class c) { for (ItemSetting setting : itemSettings) { if (setting.getKey().equals(key) && setting.isType(c)) { @@ -490,9 +499,9 @@ public class SlimefunItem implements Placeable { * using {@link Research#addItems(SlimefunItem...)} * * @param research - * The new {@link Research} for this {@link SlimefunItem} + * The new {@link Research} for this {@link SlimefunItem}, or null */ - public void setResearch(Research research) { + public void setResearch(@Nullable Research research) { if (this.research != null) { this.research.getAffectedItems().remove(this); } @@ -512,12 +521,12 @@ public class SlimefunItem implements Placeable { this.recipe = recipe; } - public void setRecipeType(RecipeType type) { + public void setRecipeType(@Nonnull RecipeType type) { Validate.notNull(type, "The RecipeType is not allowed to be null!"); this.recipeType = type; } - public void setCategory(Category category) { + public void setCategory(@Nonnull Category category) { Validate.notNull(category, "The Category is not allowed to be null!"); this.category.remove(this); @@ -533,7 +542,7 @@ public class SlimefunItem implements Placeable { * @param output * The {@link ItemStack} that will be the result of crafting this {@link SlimefunItem} */ - public void setRecipeOutput(ItemStack output) { + public void setRecipeOutput(@Nullable ItemStack output) { this.recipeOutput = output; } @@ -560,6 +569,7 @@ public class SlimefunItem implements Placeable { * * @return This instance of {@link SlimefunItem} */ + @Nonnull public SlimefunItem setUseableInWorkbench(boolean useable) { this.useableInWorkbench = useable; @@ -575,7 +585,7 @@ public class SlimefunItem implements Placeable { * * @return Whether the given {@link ItemStack} represents this {@link SlimefunItem} */ - public boolean isItem(ItemStack item) { + public boolean isItem(@Nullable ItemStack item) { if (item == null) { return false; } @@ -701,7 +711,7 @@ public class SlimefunItem implements Placeable { * @param page * The associated wiki page */ - public final void addOficialWikipage(String page) { + public final void addOficialWikipage(@Nonnull String page) { Validate.notNull(page, "Wiki page cannot be null."); wikiLink = Optional.of("https://github.com/TheBusyBiscuit/Slimefun4/wiki/" + page); } @@ -714,6 +724,7 @@ public class SlimefunItem implements Placeable { * * @return This item's wiki page */ + @Nonnull public Optional getWikipage() { return wikiLink; } @@ -724,6 +735,7 @@ public class SlimefunItem implements Placeable { * * @return This item's name in {@link ItemStack} form */ + @Nonnull public final String getItemName() { if (item instanceof SlimefunItemStack) { Optional name = ((SlimefunItemStack) item).getImmutableMeta().getDisplayName(); @@ -741,6 +753,7 @@ public class SlimefunItem implements Placeable { * * @return The Set of item handlers */ + @Nonnull public Collection getHandlers() { return itemhandlers.values(); } @@ -844,11 +857,13 @@ public class SlimefunItem implements Placeable { } } - public static SlimefunItem getByID(String id) { + @Nullable + public static SlimefunItem getByID(@Nonnull String id) { return SlimefunPlugin.getRegistry().getSlimefunItemIds().get(id); } - public static SlimefunItem getByItem(ItemStack item) { + @Nullable + public static SlimefunItem getByItem(@Nullable ItemStack item) { if (item == null || item.getType() == Material.AIR) { return null; }