diff --git a/dough-chat/src/main/java/io/github/bakedlibs/dough/chat/ChatInput.java b/dough-chat/src/main/java/io/github/bakedlibs/dough/chat/ChatInput.java index d7225d9b..dd64dc94 100644 --- a/dough-chat/src/main/java/io/github/bakedlibs/dough/chat/ChatInput.java +++ b/dough-chat/src/main/java/io/github/bakedlibs/dough/chat/ChatInput.java @@ -6,6 +6,7 @@ import javax.annotation.Nonnull; +import org.apache.commons.lang.Validate; import org.bukkit.entity.Player; import org.bukkit.plugin.Plugin; @@ -27,6 +28,9 @@ private ChatInput() {} * A callback to invoke when the Player has entered some text */ public static void waitForPlayer(@Nonnull Plugin plugin, @Nonnull Player p, @Nonnull Consumer handler) { + Validate.notNull(plugin, "The plugin cannot be null"); + Validate.notNull(p, "The player cannot be null"); + Validate.notNull(handler, "The handler cannot be null"); waitForPlayer(plugin, p, s -> true, handler); } @@ -46,6 +50,11 @@ public static void waitForPlayer(@Nonnull Plugin plugin, @Nonnull Player p, @Non * A callback to invoke when the Player has entered some text */ public static void waitForPlayer(@Nonnull Plugin plugin, @Nonnull Player p, @Nonnull Predicate predicate, @Nonnull Consumer handler) { + Validate.notNull(plugin, "The plugin cannot be null"); + Validate.notNull(p, "The player cannot be null"); + Validate.notNull(handler, "The handler cannot be null"); + Validate.notNull(predicate, "The predicate cannot be null"); + queue(plugin, p, new ChatInputHandler() { @Override @@ -73,6 +82,9 @@ public void onChat(Player p, String msg) { * A callback to invoke when the Player has entered some text */ public static void waitForPlayer(@Nonnull Plugin plugin, @Nonnull Player p, @Nonnull BiConsumer handler) { + Validate.notNull(plugin, "The plugin cannot be null"); + Validate.notNull(p, "The player cannot be null"); + Validate.notNull(handler, "The handler cannot be null"); waitForPlayer(plugin, p, s -> true, handler); } @@ -92,6 +104,11 @@ public static void waitForPlayer(@Nonnull Plugin plugin, @Nonnull Player p, @Non * A callback to invoke when the Player has entered some text */ public static void waitForPlayer(@Nonnull Plugin plugin, @Nonnull Player p, @Nonnull Predicate predicate, @Nonnull BiConsumer handler) { + Validate.notNull(plugin, "The plugin cannot be null"); + Validate.notNull(p, "The player cannot be null"); + Validate.notNull(handler, "The handler cannot be null"); + Validate.notNull(predicate, "The predicate cannot be null"); + queue(plugin, p, new ChatInputHandler() { @Override @@ -108,6 +125,10 @@ public void onChat(Player p, String msg) { } public static void queue(@Nonnull Plugin plugin, @Nonnull Player p, @Nonnull ChatInputHandler callback) { + Validate.notNull(plugin, "The plugin cannot be null"); + Validate.notNull(p, "The player cannot be null"); + Validate.notNull(callback, "The callback cannot be null"); + if (listener == null) { listener = new ChatInputListener(plugin); } diff --git a/dough-common/src/main/java/io/github/bakedlibs/dough/common/ChatColors.java b/dough-common/src/main/java/io/github/bakedlibs/dough/common/ChatColors.java index 3958547b..21b61e59 100644 --- a/dough-common/src/main/java/io/github/bakedlibs/dough/common/ChatColors.java +++ b/dough-common/src/main/java/io/github/bakedlibs/dough/common/ChatColors.java @@ -2,6 +2,7 @@ import javax.annotation.Nonnull; +import org.apache.commons.lang.Validate; import org.bukkit.ChatColor; /** @@ -24,6 +25,7 @@ private ChatColors() {} * @return The colored String */ public static @Nonnull String color(@Nonnull String input) { + Validate.notNull(input, "The input cannot be null"); return ChatColor.translateAlternateColorCodes('&', input); } @@ -40,6 +42,7 @@ private ChatColors() {} * @return The colored String */ public static @Nonnull String alternating(@Nonnull String text, ChatColor... colors) { + Validate.notNull(text, "The text cannot be null"); int i = 0; StringBuilder builder = new StringBuilder(text.length() * 3); diff --git a/dough-common/src/main/java/io/github/bakedlibs/dough/common/DoughLogger.java b/dough-common/src/main/java/io/github/bakedlibs/dough/common/DoughLogger.java index 88c51398..646f8d03 100644 --- a/dough-common/src/main/java/io/github/bakedlibs/dough/common/DoughLogger.java +++ b/dough-common/src/main/java/io/github/bakedlibs/dough/common/DoughLogger.java @@ -12,10 +12,10 @@ /** * A utility {@link Logger} implementation which automatically sets the * {@link Server} as its parent {@link Logger}. - * + * * This allows us to properly log messages and warnings without the need * for a {@link PluginLogger}. - * + * * @author TheBusyBiscuit * */ diff --git a/dough-common/src/main/java/io/github/bakedlibs/dough/common/PlayerList.java b/dough-common/src/main/java/io/github/bakedlibs/dough/common/PlayerList.java index 81a30907..d3f593b7 100644 --- a/dough-common/src/main/java/io/github/bakedlibs/dough/common/PlayerList.java +++ b/dough-common/src/main/java/io/github/bakedlibs/dough/common/PlayerList.java @@ -7,6 +7,7 @@ import javax.annotation.Nonnull; +import org.apache.commons.lang.Validate; import org.bukkit.Bukkit; import org.bukkit.entity.Player; @@ -38,6 +39,7 @@ private PlayerList() {} * @return An Optional describing the player (or an empty Optional) */ public static @Nonnull Optional findByName(@Nonnull String name) { + Validate.notNull(name, "The name cannot be null"); return stream().filter(p -> p.getName().equalsIgnoreCase(name)).findAny(); } @@ -50,6 +52,7 @@ private PlayerList() {} * @return A Set of Players */ public static @Nonnull Set findPermitted(@Nonnull String permission) { + Validate.notNull(permission, "The permission cannot be null"); return stream().filter(p -> p.hasPermission(permission)).collect(Collectors.toSet()); } @@ -62,6 +65,7 @@ private PlayerList() {} * @return Whether the Player is online */ public static boolean isOnline(@Nonnull String name) { + Validate.notNull(name, "The name cannot be null"); return findByName(name).isPresent(); } diff --git a/dough-config/src/main/java/io/github/bakedlibs/dough/config/Config.java b/dough-config/src/main/java/io/github/bakedlibs/dough/config/Config.java index 3815a61d..e4c62ae2 100644 --- a/dough-config/src/main/java/io/github/bakedlibs/dough/config/Config.java +++ b/dough-config/src/main/java/io/github/bakedlibs/dough/config/Config.java @@ -14,6 +14,7 @@ import javax.annotation.Nonnull; import javax.annotation.Nullable; +import org.apache.commons.lang.Validate; import org.bukkit.Bukkit; import org.bukkit.ChatColor; import org.bukkit.Chunk; @@ -45,6 +46,8 @@ public class Config { * The Instance of the Plugin, the config.yml is referring to */ public Config(@Nonnull Plugin plugin) { + Validate.notNull(plugin, "Plugin cannot be null"); + plugin.getConfig().options().copyDefaults(true); plugin.saveConfig(); @@ -56,6 +59,9 @@ public Config(@Nonnull Plugin plugin) { } public Config(@Nonnull Plugin plugin, @Nonnull String name) { + Validate.notNull(plugin, "Plugin cannot be null"); + Validate.notNull(name, "Name cannot be null"); + this.logger = plugin.getLogger(); this.file = new File("plugins/" + plugin.getName().replace(" ", "_"), name); this.fileConfig = YamlConfiguration.loadConfiguration(this.file); @@ -72,6 +78,9 @@ public Config(@Nonnull Plugin plugin, @Nonnull String name) { * The FileConfiguration */ public Config(@Nonnull File file, @Nonnull FileConfiguration config) { + Validate.notNull(file, "File cannot be null"); + Validate.notNull(config, "FileConfiguration cannot be null"); + this.logger = new DoughLogger("config"); this.file = file; @@ -128,6 +137,7 @@ public void setHeader(@Nullable String header) { * Your {@link Logger} instance */ public void setLogger(@Nonnull Logger logger) { + Validate.notNull(logger, "The logger cannot be null"); this.logger = logger; } @@ -138,6 +148,7 @@ public void clear() { } protected void store(@Nonnull String path, Object value) { + Validate.notNull(path, "The path cannot be null"); this.fileConfig.set(path, value); } @@ -150,6 +161,7 @@ protected void store(@Nonnull String path, Object value) { * The Value for that path */ public void setValue(@Nonnull String path, Object value) { + Validate.notNull(path, "THe path cannot be null"); if (value == null) { this.store(path, value); } else if (value instanceof Optional) { @@ -198,6 +210,7 @@ public void save() { * The {@link File} you are saving this {@link Config} to */ public void save(@Nonnull File file) { + Validate.notNull(file, "The file cannot be null"); try { if (header != null) { fileConfig.options().copyHeader(true); @@ -222,6 +235,7 @@ public void save(@Nonnull File file) { * The Value for that path */ public void setDefaultValue(@Nonnull String path, @Nullable Object value) { + Validate.notNull(path, "The path cannot be null"); if (!contains(path)) { setValue(path, value); } @@ -229,6 +243,7 @@ public void setDefaultValue(@Nonnull String path, @Nullable Object value) { @SuppressWarnings("unchecked") public T getOrSetDefault(@Nonnull String path, T value) { + Validate.notNull(path, "The path cannot be null"); Object val = getValue(path); if (value.getClass().isInstance(val)) { @@ -247,6 +262,7 @@ public T getOrSetDefault(@Nonnull String path, T value) { * @return True/false */ public boolean contains(@Nonnull String path) { + Validate.notNull(path, "The path cannot be null"); return fileConfig.contains(path); } @@ -260,11 +276,15 @@ public boolean contains(@Nonnull String path) { */ @Nullable public Object getValue(@Nonnull String path) { + Validate.notNull(path, "The path cannot be null"); return fileConfig.get(path); } @Nonnull public Optional getValueAs(@Nonnull Class c, @Nonnull String path) { + Validate.notNull(c, "The class cannot be null"); + Validate.notNull(path, "The path cannot be null"); + Object obj = getValue(path); return c.isInstance(obj) ? Optional.of(c.cast(obj)) : Optional.empty(); } @@ -279,6 +299,7 @@ public Optional getValueAs(@Nonnull Class c, @Nonnull String path) { */ @Nullable public ItemStack getItem(@Nonnull String path) { + Validate.notNull(path, "The path cannot be null"); return fileConfig.getItemStack(path); } @@ -292,6 +313,7 @@ public ItemStack getItem(@Nonnull String path) { */ @Nullable public String getString(@Nonnull String path) { + Validate.notNull(path, "The path cannot be null"); return fileConfig.getString(path); } @@ -304,6 +326,7 @@ public String getString(@Nonnull String path) { * @return The Integer at that path */ public int getInt(@Nonnull String path) { + Validate.notNull(path, "The path cannot be null"); return fileConfig.getInt(path); } @@ -316,6 +339,7 @@ public int getInt(@Nonnull String path) { * @return The Boolean at that path */ public boolean getBoolean(@Nonnull String path) { + Validate.notNull(path, "The path cannot be null"); return fileConfig.getBoolean(path); } @@ -329,6 +353,7 @@ public boolean getBoolean(@Nonnull String path) { */ @Nonnull public List getStringList(@Nonnull String path) { + Validate.notNull(path, "The path cannot be null"); return fileConfig.getStringList(path); } @@ -342,6 +367,7 @@ public List getStringList(@Nonnull String path) { */ @Nonnull public List getIntList(@Nonnull String path) { + Validate.notNull(path, "The path cannot be null"); return fileConfig.getIntegerList(path); } @@ -368,6 +394,7 @@ public boolean createFile() { * @return The Float at that path */ public float getFloat(@Nonnull String path) { + Validate.notNull(path, "The path cannot be null"); return Float.valueOf(String.valueOf(getValue(path))); } @@ -380,6 +407,7 @@ public float getFloat(@Nonnull String path) { * @return The Long at that path */ public long getLong(@Nonnull String path) { + Validate.notNull(path, "The path cannot be null"); return Long.valueOf(String.valueOf(getValue(path))); } @@ -392,6 +420,7 @@ public long getLong(@Nonnull String path) { * @return The Date at that path */ public Date getDate(@Nonnull String path) { + Validate.notNull(path, "The path cannot be null"); return new Date(getLong(path)); } @@ -404,6 +433,7 @@ public Date getDate(@Nonnull String path) { * @return The Chunk at that path */ public Chunk getChunk(@Nonnull String path) { + Validate.notNull(path, "The path cannot be null"); return Bukkit.getWorld(getString(path + ".world")).getChunkAt(getInt(path + ".x"), getInt(path + ".z")); } @@ -416,6 +446,7 @@ public Chunk getChunk(@Nonnull String path) { * @return The UUID at that path */ public UUID getUUID(@Nonnull String path) { + Validate.notNull(path, "The path cannot be null"); String value = getString(path); return value != null ? UUID.fromString(value) : null; } @@ -429,6 +460,7 @@ public UUID getUUID(@Nonnull String path) { * @return The World at that path */ public World getWorld(@Nonnull String path) { + Validate.notNull(path, "The path cannot be null"); return Bukkit.getWorld(getString(path)); } @@ -441,6 +473,7 @@ public World getWorld(@Nonnull String path) { * @return The Double at that path */ public double getDouble(@Nonnull String path) { + Validate.notNull(path, "The path cannot be null"); return fileConfig.getDouble(path); } @@ -454,6 +487,7 @@ public double getDouble(@Nonnull String path) { */ @Nonnull public Location getLocation(@Nonnull String path) { + Validate.notNull(path, "The path cannot be null"); return new Location(Bukkit.getWorld(getString(path + ".world")), getDouble(path + ".x"), getDouble(path + ".y"), getDouble(path + ".z"), getFloat(path + ".yaw"), getFloat(path + ".pitch")); } @@ -471,6 +505,9 @@ public Location getLocation(@Nonnull String path) { */ @Nonnull public Inventory getInventory(@Nonnull String path, int size, @Nonnull String title) { + Validate.notNull(path, "The path cannot be null"); + Validate.notNull(title, "The title cannot be null"); + Inventory inventory = Bukkit.createInventory(null, size, ChatColor.translateAlternateColorCodes('&', title)); for (int i = 0; i < size; i++) { inventory.setItem(i, getItem(path + "." + i)); @@ -490,6 +527,9 @@ public Inventory getInventory(@Nonnull String path, int size, @Nonnull String ti */ @Nonnull public Inventory getInventory(@Nonnull String path, @Nonnull String title) { + Validate.notNull(path, "The path cannot be null"); + Validate.notNull(title, "The title cannot be null"); + int size = getInt(path + ".size"); Inventory inventory = Bukkit.createInventory(null, size, ChatColor.translateAlternateColorCodes('&', title)); @@ -520,6 +560,7 @@ public Set getKeys() { */ @Nonnull public Set getKeys(@Nonnull String path) { + Validate.notNull(path, "The path cannot be null"); ConfigurationSection section = fileConfig.getConfigurationSection(path); return section == null ? new HashSet<>() : section.getKeys(false); } diff --git a/dough-data/src/main/java/io/github/bakedlibs/dough/blocks/BlockPosition.java b/dough-data/src/main/java/io/github/bakedlibs/dough/blocks/BlockPosition.java index 2760862c..71153c9f 100644 --- a/dough-data/src/main/java/io/github/bakedlibs/dough/blocks/BlockPosition.java +++ b/dough-data/src/main/java/io/github/bakedlibs/dough/blocks/BlockPosition.java @@ -4,6 +4,7 @@ import javax.annotation.Nonnull; +import org.apache.commons.lang.Validate; import org.bukkit.Chunk; import org.bukkit.Location; import org.bukkit.World; @@ -41,6 +42,7 @@ public final class BlockPosition { * The {@link BlockPosition} (as a long) */ public BlockPosition(@Nonnull World world, long position) { + Validate.notNull(world, "The world cannot be null"); this.world = new WeakReference<>(world); this.position = position; } @@ -58,6 +60,7 @@ public BlockPosition(@Nonnull World world, long position) { * The z coordinate */ public BlockPosition(@Nonnull World world, int x, int y, int z) { + Validate.notNull(world, "The world cannot be null"); this.world = new WeakReference<>(world); this.position = getAsLong(x, y, z); } diff --git a/dough-data/src/main/java/io/github/bakedlibs/dough/blocks/ChunkPosition.java b/dough-data/src/main/java/io/github/bakedlibs/dough/blocks/ChunkPosition.java index 932761ba..9196802b 100644 --- a/dough-data/src/main/java/io/github/bakedlibs/dough/blocks/ChunkPosition.java +++ b/dough-data/src/main/java/io/github/bakedlibs/dough/blocks/ChunkPosition.java @@ -5,6 +5,7 @@ import javax.annotation.Nonnull; +import org.apache.commons.lang.Validate; import org.bukkit.Chunk; import org.bukkit.Location; import org.bukkit.World; @@ -25,11 +26,13 @@ public final class ChunkPosition { private final long position; public ChunkPosition(@Nonnull World world, long position) { + Validate.notNull(world, "The world cannot be null"); this.world = new WeakReference<>(world); this.position = position; } public ChunkPosition(@Nonnull World world, int x, int z) { + Validate.notNull(world, "The world cannot be null"); this.world = new WeakReference<>(world); this.position = getAsLong(x, z); } diff --git a/dough-inventories/src/main/java/io/github/bakedlibs/dough/inventory/InvUtils.java b/dough-inventories/src/main/java/io/github/bakedlibs/dough/inventory/InvUtils.java index f055742d..7b983844 100644 --- a/dough-inventories/src/main/java/io/github/bakedlibs/dough/inventory/InvUtils.java +++ b/dough-inventories/src/main/java/io/github/bakedlibs/dough/inventory/InvUtils.java @@ -5,6 +5,8 @@ import java.util.function.Predicate; import java.util.stream.IntStream; +import org.apache.commons.lang.Validate; + import javax.annotation.Nonnull; import org.bukkit.Material; @@ -27,6 +29,7 @@ private InvUtils() {} * @return Whether an empty slot exists */ public static boolean hasEmptySlot(@Nonnull Inventory inv) { + Validate.notNull(inv, "The inventory cannot be null"); return inv.firstEmpty() != 1; } @@ -39,6 +42,7 @@ public static boolean hasEmptySlot(@Nonnull Inventory inv) { * @return Whether that {@link Inventory} is empty */ public static boolean isEmpty(@Nonnull Inventory inv) { + Validate.notNull(inv, "The inventory cannot be null"); // Sadly Inventory#isEmpty() is not available everywhere for (ItemStack item : inv) { @@ -66,6 +70,10 @@ public static boolean isEmpty(@Nonnull Inventory inv) { * @return Whether the maxStackSizes allow for these items to stack */ public static boolean isValidStackSize(@Nonnull ItemStack stack, @Nonnull ItemStack item, @Nonnull Inventory inv) { + Validate.notNull(stack, "The stack cannot be null"); + Validate.notNull(item, "The item cannot be null"); + Validate.notNull(inv, "The inventory cannot be null"); + int newStackSize = stack.getAmount() + item.getAmount(); return newStackSize <= stack.getMaxStackSize() && newStackSize <= inv.getMaxStackSize(); } @@ -81,6 +89,9 @@ public static boolean isValidStackSize(@Nonnull ItemStack stack, @Nonnull ItemSt * @return Whether the given {@link InventoryType} allows this {@link Material} to be stored within */ public static boolean isItemAllowed(@Nonnull Material itemType, @Nonnull InventoryType inventoryType) { + Validate.notNull(itemType, "The item type cannot be null"); + Validate.notNull(inventoryType, "The inventory type cannot be null"); + switch (inventoryType) { case LECTERN: // Lecterns only allow written books or writable books @@ -109,6 +120,9 @@ public static boolean isItemAllowed(@Nonnull Material itemType, @Nonnull Invento * @return Whether the slots have space for the {@link ItemStack} */ public static boolean fits(@Nonnull Inventory inv, @Nonnull ItemStack item, int... slots) { + Validate.notNull(item, "The item type cannot be null"); + Validate.notNull(inv, "The inventory cannot be null"); + if (!isItemAllowed(item.getType(), inv.getType())) { return false; } @@ -148,6 +162,10 @@ public static boolean fits(@Nonnull Inventory inv, @Nonnull ItemStack item, int. * @return Whether the slots have space for the given {@link ItemStack ItemStacks} */ public static boolean fitAll(@Nonnull Inventory inv, @Nonnull ItemStack[] items, int... slots) { + Validate.notNull(inv, "The inventory cannot be null"); + Validate.notNull(items, "The items cannot be null"); + Validate.noNullElements(items, "The items array cannot have null elements"); + if (slots.length == 0) { slots = IntStream.range(0, inv.getSize()).toArray(); } @@ -205,6 +223,9 @@ public static boolean fitAll(@Nonnull Inventory inv, @Nonnull ItemStack[] items, * @return Whether the operation was successful */ public static boolean removeItem(@Nonnull Inventory inv, int amount, boolean replaceConsumables, @Nonnull Predicate predicate) { + Validate.notNull(inv, "The inventory cannot be null"); + Validate.notNull(predicate, "The predicate cannot be null"); + int removed = 0; for (int slot = 0; slot < inv.getSize(); slot++) { ItemStack item = inv.getItem(slot); @@ -223,4 +244,4 @@ public static boolean removeItem(@Nonnull Inventory inv, int amount, boolean rep return false; } -} \ No newline at end of file +} diff --git a/dough-items/src/main/java/io/github/bakedlibs/dough/items/ItemMetaSnapshot.java b/dough-items/src/main/java/io/github/bakedlibs/dough/items/ItemMetaSnapshot.java index 62e94fd4..68b75863 100644 --- a/dough-items/src/main/java/io/github/bakedlibs/dough/items/ItemMetaSnapshot.java +++ b/dough-items/src/main/java/io/github/bakedlibs/dough/items/ItemMetaSnapshot.java @@ -10,6 +10,7 @@ import javax.annotation.Nonnull; +import org.apache.commons.lang.Validate; import org.bukkit.enchantments.Enchantment; import org.bukkit.inventory.ItemFlag; import org.bukkit.inventory.ItemStack; @@ -44,6 +45,8 @@ public ItemMetaSnapshot(@Nonnull Supplier supplier) { } public ItemMetaSnapshot(@Nonnull ItemMeta meta) { + Validate.notNull(meta, "The ItemMeta cannot be null"); + this.displayName = meta.hasDisplayName() ? Optional.of(meta.getDisplayName()) : Optional.empty(); this.lore = meta.hasLore() ? Optional.of(Collections.unmodifiableList(meta.getLore())) : Optional.empty(); this.customModelData = meta.hasCustomModelData() ? OptionalInt.of(meta.getCustomModelData()) : OptionalInt.empty(); @@ -73,6 +76,8 @@ public ItemMetaSnapshot(@Nonnull ItemMeta meta) { } public boolean isSimilar(@Nonnull ItemMetaSnapshot snapshot) { + Validate.notNull(snapshot, "The snapshot cannot be null"); + if (snapshot.displayName.isPresent() != displayName.isPresent()) { return false; } else if (snapshot.displayName.isPresent() && displayName.isPresent() && !snapshot.displayName.get().equals(displayName.get())) { @@ -85,6 +90,8 @@ public boolean isSimilar(@Nonnull ItemMetaSnapshot snapshot) { } public boolean isSimilar(@Nonnull ItemMeta meta) { + Validate.notNull(meta, "The ItemMeta cannot be null"); + boolean hasDisplayName = meta.hasDisplayName(); if (hasDisplayName != displayName.isPresent()) { diff --git a/dough-items/src/main/java/io/github/bakedlibs/dough/items/ItemUtils.java b/dough-items/src/main/java/io/github/bakedlibs/dough/items/ItemUtils.java index c3789b30..06d360f6 100644 --- a/dough-items/src/main/java/io/github/bakedlibs/dough/items/ItemUtils.java +++ b/dough-items/src/main/java/io/github/bakedlibs/dough/items/ItemUtils.java @@ -5,6 +5,7 @@ import javax.annotation.Nonnull; import javax.annotation.Nullable; +import org.apache.commons.lang.Validate; import org.bukkit.Material; import org.bukkit.enchantments.Enchantment; import org.bukkit.inventory.ItemStack; @@ -151,6 +152,7 @@ public static boolean canStack(@Nullable ItemStack a, @Nullable ItemStack b) { * Whether the Unbreaking Enchantment should be ignored */ public static void damageItem(@Nonnull ItemStack item, boolean ignoreEnchantments) { + Validate.notNull(item, "The item cannot be null"); damageItem(item, 1, ignoreEnchantments); } @@ -166,6 +168,8 @@ public static void damageItem(@Nonnull ItemStack item, boolean ignoreEnchantment * Whether the Unbreaking Enchantment should be ignored */ public static void damageItem(@Nonnull ItemStack item, int damage, boolean ignoreEnchantments) { + Validate.notNull(item, "The item cannot be null"); + if (item.getType() != Material.AIR && item.getAmount() > 0) { int remove = damage; @@ -202,6 +206,7 @@ public static void damageItem(@Nonnull ItemStack item, int damage, boolean ignor * {@link ItemUtils#consumeItem(ItemStack, int, boolean)} */ public static void consumeItem(@Nonnull ItemStack item, boolean replaceConsumables) { + Validate.notNull(item, "The item cannot be null"); consumeItem(item, 1, replaceConsumables); } @@ -226,6 +231,8 @@ public static void consumeItem(@Nonnull ItemStack item, boolean replaceConsumabl * Whether Items should be replaced with their "empty" version */ public static void consumeItem(@Nonnull ItemStack item, int amount, boolean replaceConsumables) { + Validate.notNull(item, "The item cannot be null"); + if (item.getType() != Material.AIR && item.getAmount() > 0) { if (replaceConsumables) { switch (item.getType()) { diff --git a/dough-protection/src/main/java/io/github/bakedlibs/dough/protection/ProtectionManager.java b/dough-protection/src/main/java/io/github/bakedlibs/dough/protection/ProtectionManager.java index 492e1337..811ee1b3 100644 --- a/dough-protection/src/main/java/io/github/bakedlibs/dough/protection/ProtectionManager.java +++ b/dough-protection/src/main/java/io/github/bakedlibs/dough/protection/ProtectionManager.java @@ -8,6 +8,8 @@ import javax.annotation.Nonnull; +import org.apache.commons.lang.Validate; + import org.bukkit.Location; import org.bukkit.OfflinePlayer; import org.bukkit.Server; @@ -53,6 +55,8 @@ public final class ProtectionManager { */ @SuppressWarnings("java:S1612") public ProtectionManager(@Nonnull Server server) { + Validate.notNull(server, "The server cannot be null"); + logger = new DoughLogger(server, "protection"); logger.log(Level.INFO, "Loading Protection Modules..."); @@ -102,11 +106,16 @@ public ProtectionManager(@Nonnull Server server) { } public void registerLogger(@Nonnull String name, @Nonnull ProtectionLogger module) { + Validate.notNull(name, "The name cannot be null"); + Validate.notNull(module, "The module cannot be null"); protectionLoggers.add(module); loadModuleMSG(name); } public void registerModule(@Nonnull Server server, @Nonnull String pluginName, @Nonnull Function constructor) { + Validate.notNull(server, "The server cannot be null"); + Validate.notNull(pluginName, "The plugin name cannot be null"); + Validate.notNull(constructor, "The constructor cannot be null"); Plugin plugin = server.getPluginManager().getPlugin(pluginName); if (plugin != null && plugin.isEnabled()) { @@ -127,6 +136,8 @@ private void registerModule(@Nonnull Plugin plugin, @Nonnull Function { } @ParametersAreNonnullByDefault - private static @Nullable MinecraftRecipe findRecipeType(Logger logger, String type, Function> supplier) { + private static @Nullable MinecraftRecipe findRecipeType(Logger logger, String type, Function> supplier) { try { return supplier.apply(type); } catch (Exception | LinkageError x) { @@ -162,6 +163,7 @@ protected boolean validate(@Nonnull ItemStack[] inputs) { @SuppressWarnings("unchecked") public static Optional> of(@Nonnull T recipe) { + Validate.notNull(recipe, "The recipe cannot be null"); Class recipeClass = recipe.getClass(); return recipeTypes.stream().filter(type -> type.getRecipeClass().isAssignableFrom(recipeClass)).findAny().map(type -> (MinecraftRecipe) type); diff --git a/dough-recipes/src/main/java/io/github/bakedlibs/dough/recipes/RecipeSnapshot.java b/dough-recipes/src/main/java/io/github/bakedlibs/dough/recipes/RecipeSnapshot.java index a91b3437..7bf9bac1 100644 --- a/dough-recipes/src/main/java/io/github/bakedlibs/dough/recipes/RecipeSnapshot.java +++ b/dough-recipes/src/main/java/io/github/bakedlibs/dough/recipes/RecipeSnapshot.java @@ -15,6 +15,7 @@ import javax.annotation.Nonnull; import javax.annotation.Nullable; +import org.apache.commons.lang.Validate; import org.bukkit.Keyed; import org.bukkit.Material; import org.bukkit.NamespacedKey; @@ -42,6 +43,8 @@ public class RecipeSnapshot { * The Plugin running on the Server that serves as the Snapshot's source. */ public RecipeSnapshot(@Nonnull Plugin plugin) { + Validate.notNull(plugin, "The plugin cannot be null"); + Iterator iterator = plugin.getServer().recipeIterator(); plugin.getLogger().log(Level.INFO, "Collecting Snapshots of all Recipes..."); @@ -87,6 +90,7 @@ public Stream streamAllRecipes() { */ @Nonnull public Set getRecipes(@Nonnull Class recipeClass) { + Validate.notNull(recipeClass, "The recipe class cannot be null"); return stream(recipeClass).collect(Collectors.toSet()); } @@ -103,6 +107,7 @@ public Set getRecipes(@Nonnull Class recipeClass) { */ @Nonnull public Stream stream(@Nonnull Class recipeClass) { + Validate.notNull(recipeClass, "The recipe class cannot be null"); return recipes.entrySet().stream().filter(entry -> recipeClass.isAssignableFrom(entry.getKey())).flatMap(entry -> entry.getValue().stream()).map(recipeClass::cast); } @@ -121,6 +126,8 @@ public Stream stream(@Nonnull Class recipeClass) { */ @Nonnull public RecipeChoice[] getRecipeInput(@Nonnull MinecraftRecipe recipeType, @Nonnull T recipe) { + Validate.notNull(recipeType, "The recipe type cannot be null"); + Validate.notNull(recipe, "The recipe cannot be null"); return recipeType.getInputs(recipe); } @@ -141,6 +148,8 @@ public RecipeChoice[] getRecipeInput(@Nonnull MinecraftRecipe */ @Nonnull public RecipeChoice[] getRecipeInput(@Nonnull T recipe) { + Validate.notNull(recipe, "The recipe cannot be null"); + Optional> type = MinecraftRecipe.of(recipe); if (type.isPresent()) { @@ -167,6 +176,8 @@ public RecipeChoice[] getRecipeInput(@Nonnull T recipe) { */ @Nonnull public Optional getRecipeOutput(@Nonnull MinecraftRecipe recipeType, ItemStack... inputs) { + Validate.notNull(recipeType, "The recipe type cannot be null"); + if (recipeType.validate(inputs)) { return recipeType.getOutput(stream(recipeType.getRecipeClass()), inputs); } else { @@ -184,6 +195,7 @@ public Optional getRecipeOutput(@Nonnull Minecraft */ @Nonnull public Set getRecipes(@Nonnull Predicate predicate) { + Validate.notNull(predicate, "The predicate cannot be null"); return streamAllRecipes().filter(predicate).collect(Collectors.toSet()); } @@ -198,6 +210,7 @@ public Set getRecipes(@Nonnull Predicate predicate) { */ @Nonnull public Set getRecipesFor(@Nonnull Material type) { + Validate.notNull(type, "The type cannot be null"); return getRecipes(recipe -> recipe.getResult().getType() == type); } @@ -211,6 +224,7 @@ public Set getRecipesFor(@Nonnull Material type) { */ @Nonnull public Set getRecipesFor(@Nonnull ItemStack item) { + Validate.notNull(item, "The item cannot be null"); return getRecipes(recipe -> recipe.getResult().isSimilar(item)); } @@ -226,6 +240,7 @@ public Set getRecipesFor(@Nonnull ItemStack item) { */ @Nonnull public Set getRecipesWith(@Nonnull ItemStack item) { + Validate.notNull(item, "The item cannot be null"); return getRecipes(recipe -> Arrays.stream(getRecipeInput(recipe)).anyMatch(choice -> choice.test(item))); } @@ -243,6 +258,7 @@ public Set getRecipesWith(@Nonnull ItemStack item) { */ @Nullable public Recipe getRecipe(@Nonnull NamespacedKey key) { + Validate.notNull(key, "The key cannot be null"); return keyedRecipes.get(key); } diff --git a/dough-reflection/src/main/java/io/github/bakedlibs/dough/reflection/PrimitiveTypeConversion.java b/dough-reflection/src/main/java/io/github/bakedlibs/dough/reflection/PrimitiveTypeConversion.java index 0648ff73..b49c9be9 100644 --- a/dough-reflection/src/main/java/io/github/bakedlibs/dough/reflection/PrimitiveTypeConversion.java +++ b/dough-reflection/src/main/java/io/github/bakedlibs/dough/reflection/PrimitiveTypeConversion.java @@ -1,5 +1,7 @@ package io.github.bakedlibs.dough.reflection; +import org.apache.commons.lang.Validate; + import java.util.HashMap; import java.util.Map; @@ -24,10 +26,12 @@ final class PrimitiveTypeConversion { private PrimitiveTypeConversion() {} static @Nullable Class convert(@Nonnull Class boxedClassType) { + Validate.notNull(boxedClassType, "The boxed class type cannot be null"); return primitiveTypes.get(boxedClassType); } static @Nonnull Class convertIfNecessary(@Nonnull Class boxedClassType) { + Validate.notNull(boxedClassType, "The boxed class type cannot be null"); Class primitiveType = convert(boxedClassType); return primitiveType != null ? primitiveType : boxedClassType; } diff --git a/dough-reflection/src/main/java/io/github/bakedlibs/dough/reflection/ReflectionUtils.java b/dough-reflection/src/main/java/io/github/bakedlibs/dough/reflection/ReflectionUtils.java index d40c065a..d41fb0e3 100644 --- a/dough-reflection/src/main/java/io/github/bakedlibs/dough/reflection/ReflectionUtils.java +++ b/dough-reflection/src/main/java/io/github/bakedlibs/dough/reflection/ReflectionUtils.java @@ -17,7 +17,7 @@ /** * This class provides some useful static methods to perform reflection. - * + * * @author TheBusyBiscuit * */ @@ -33,12 +33,12 @@ private ReflectionUtils() {} *
* If the minecraft version check is enabled, then this will return an empty * {@link String} for Minecraft versions 1.17 or later. - * + * * @param checkMinecraftVersion * Whether the {@link MinecraftVersion} should be checked - * + * * @return The version-specific package name - * + * * @throws UnknownServerVersionException * If the {@link MinecraftVersion} could not be determined successfully */ @@ -132,7 +132,7 @@ private ReflectionUtils() {} * The Name of that Field * @param value * The Value for that Field - * + * * @throws NoSuchFieldException * If the field could not be found. * @throws IllegalAccessException @@ -155,7 +155,7 @@ public static void setFieldValue(@Nonnull T object, @Nonnull Class c, @No * The Name of that Field * @param value * The Value for that Field - * + * * @throws NoSuchFieldException * If the field could not be found. * @throws IllegalAccessException @@ -172,12 +172,12 @@ public static void setFieldValue(@Nonnull T object, @Nonnull String field, @ * The Object containing the Field * @param field * The Name of that Field - * + * * @throws NoSuchFieldException * If the field could not be found. * @throws IllegalAccessException * If the field could not be queried. - * + * * @return The Value of a Field */ @ParametersAreNonnullByDefault @@ -193,7 +193,7 @@ public static void setFieldValue(@Nonnull T object, @Nonnull String field, @ * * @param classes * The Types you want to convert - * + * * @return An Array of primitive Types */ public static @Nonnull Class[] toPrimitiveTypeArray(@Nonnull Class[] classes) { @@ -216,7 +216,7 @@ public static void setFieldValue(@Nonnull T object, @Nonnull String field, @ * The Class containing the Constructor * @param paramTypes * The Parameters for that Constructor - * + * * @return The Constructor for that Class */ @SuppressWarnings("unchecked") @@ -241,12 +241,12 @@ public static void setFieldValue(@Nonnull T object, @Nonnull String field, @ * The Name of the Class your Inner class is located in * @param subname * The Name of the inner Class you are looking for - * + * * @throws ClassNotFoundException * If the class could not be found. - * + * * @return The Class in your specified Class - * + * * @throws UnknownServerVersionException * If the {@link MinecraftVersion} was unable to be determined */ @@ -274,9 +274,9 @@ public static void setFieldValue(@Nonnull T object, @Nonnull String field, @ * * @param name * The Name of the Class you are looking for - * + * * @return The Class in that Package - * + * * @throws ClassNotFoundException * If the class could not be found. * @throws UnknownServerVersionException @@ -293,10 +293,10 @@ public static void setFieldValue(@Nonnull T object, @Nonnull String field, @ * The Name of the Class your Inner class is located in * @param subname * The Name of the inner Class you are looking for - * + * * @throws ClassNotFoundException * If the class could not be found. - * + * * @return The Class in your specified Class */ @ParametersAreNonnullByDefault @@ -309,10 +309,10 @@ public static void setFieldValue(@Nonnull T object, @Nonnull String field, @ * * @param name * The Name of the Class you are looking for - * + * * @throws ClassNotFoundException * If the class could not be found. - * + * * @return The Class in that Package */ public static @Nonnull Class getOBCClass(@Nonnull String name) throws ClassNotFoundException { @@ -330,7 +330,7 @@ public static void setFieldValue(@Nonnull T object, @Nonnull String field, @ * The first Array for comparison * @param b * All following Array you want to compare - * + * * @return Whether they equal each other */ private static boolean equalsTypeArray(@Nonnull Class[] a, Class[] b) { @@ -354,7 +354,7 @@ private static boolean equalsTypeArray(@Nonnull Class[] a, Class[] b) { * The Type argument of the enum we are querying * @param c * The Enum you are targeting - * + * * @return An ArrayList of all Enum Constants in that Enum */ public static @Nonnull > List getEnumConstants(@Nonnull Class c) { @@ -370,7 +370,7 @@ private static boolean equalsTypeArray(@Nonnull Class[] a, Class[] b) { * The Enum you are targeting * @param name * The Name of the Constant you are targeting - * + * * @return The found Enum Constant */ @ParametersAreNonnullByDefault diff --git a/dough-scheduling/src/main/java/io/github/bakedlibs/dough/scheduling/TaskNode.java b/dough-scheduling/src/main/java/io/github/bakedlibs/dough/scheduling/TaskNode.java index f5d54fb7..1f84049b 100644 --- a/dough-scheduling/src/main/java/io/github/bakedlibs/dough/scheduling/TaskNode.java +++ b/dough-scheduling/src/main/java/io/github/bakedlibs/dough/scheduling/TaskNode.java @@ -16,11 +16,15 @@ class TaskNode { private TaskNode nextNode; protected TaskNode(@Nonnull IntConsumer consumer, boolean async) { + Validate.notNull(consumer, "The consumer cannot be null"); + this.runnable = consumer; this.asynchronous = async; } protected TaskNode(@Nonnull IntConsumer consumer, int delay, boolean async) { + Validate.notNull(consumer, "The consumer cannot be null"); + this.runnable = consumer; this.delay = delay; this.asynchronous = async; diff --git a/dough-scheduling/src/main/java/io/github/bakedlibs/dough/scheduling/TaskQueue.java b/dough-scheduling/src/main/java/io/github/bakedlibs/dough/scheduling/TaskQueue.java index d3914e36..32e21abe 100644 --- a/dough-scheduling/src/main/java/io/github/bakedlibs/dough/scheduling/TaskQueue.java +++ b/dough-scheduling/src/main/java/io/github/bakedlibs/dough/scheduling/TaskQueue.java @@ -5,6 +5,7 @@ import javax.annotation.Nonnull; import javax.annotation.Nullable; +import org.apache.commons.lang.Validate; import org.bukkit.Bukkit; import org.bukkit.plugin.Plugin; @@ -32,6 +33,7 @@ public class TaskQueue { * The plugin that is performing this execution */ public void execute(@Nonnull Plugin plugin) { + Validate.notNull(plugin, "Plugin cannot be null"); if (head == null) { throw new IllegalStateException("Cannot execute TaskQueue, no head was found"); } @@ -40,6 +42,7 @@ public void execute(@Nonnull Plugin plugin) { } private void run(@Nonnull Plugin plugin, @Nullable TaskNode node, int index) { + Validate.notNull(plugin, "Plugin cannot be null"); if (node == null) { return; } @@ -74,6 +77,7 @@ private void run(@Nonnull Plugin plugin, @Nullable TaskNode node, int index) { * @return The current instance of {@link TaskQueue} */ public @Nonnull TaskQueue thenRun(@Nonnull IntConsumer consumer) { + Validate.notNull(consumer, "The consumer cannot be null"); return append(new TaskNode(consumer, false)); } @@ -86,6 +90,7 @@ private void run(@Nonnull Plugin plugin, @Nullable TaskNode node, int index) { * @return The current instance of {@link TaskQueue} */ public @Nonnull TaskQueue thenRun(@Nonnull Runnable runnable) { + Validate.notNull(runnable, "The runnable cannot be null"); return thenRun(i -> runnable.run()); } @@ -99,6 +104,7 @@ private void run(@Nonnull Plugin plugin, @Nullable TaskNode node, int index) { * @return The current instance of {@link TaskQueue} */ public @Nonnull TaskQueue thenRunAsynchronously(@Nonnull IntConsumer consumer) { + Validate.notNull(consumer, "The consumer cannot be null"); return append(new TaskNode(consumer, true)); } @@ -111,6 +117,7 @@ private void run(@Nonnull Plugin plugin, @Nullable TaskNode node, int index) { * @return The current instance of {@link TaskQueue} */ public @Nonnull TaskQueue thenRunAsynchronously(@Nonnull Runnable runnable) { + Validate.notNull(runnable, "The runnable cannot be null"); return thenRunAsynchronously(i -> runnable.run()); } @@ -126,6 +133,7 @@ private void run(@Nonnull Plugin plugin, @Nullable TaskNode node, int index) { * @return The current instance of {@link TaskQueue} */ public @Nonnull TaskQueue thenRun(int ticks, @Nonnull IntConsumer consumer) { + Validate.notNull(consumer, "The consumer cannot be null"); if (ticks < 1) { throw new IllegalArgumentException("thenAfter() must be given a time that is greater than zero!"); } @@ -144,6 +152,7 @@ private void run(@Nonnull Plugin plugin, @Nullable TaskNode node, int index) { * @return The current instance of {@link TaskQueue} */ public @Nonnull TaskQueue thenRun(int ticks, @Nonnull Runnable runnable) { + Validate.notNull(runnable, "The runnable cannot be null"); return thenRun(ticks, i -> runnable.run()); } @@ -159,6 +168,7 @@ private void run(@Nonnull Plugin plugin, @Nullable TaskNode node, int index) { * @return The current instance of {@link TaskQueue} */ public @Nonnull TaskQueue thenRunAsynchronously(int ticks, @Nonnull IntConsumer consumer) { + Validate.notNull(consumer, "The consumer cannot be null"); if (ticks < 1) { throw new IllegalArgumentException("thenAfter() must be given a time that is greater than zero!"); } @@ -177,6 +187,7 @@ private void run(@Nonnull Plugin plugin, @Nullable TaskNode node, int index) { * @return The current instance of {@link TaskQueue} */ public @Nonnull TaskQueue thenRunAsynchronously(int ticks, @Nonnull Runnable runnable) { + Validate.notNull(runnable, "The runnable cannot be null"); return thenRunAsynchronously(ticks, i -> runnable.run()); } @@ -193,6 +204,7 @@ private void run(@Nonnull Plugin plugin, @Nullable TaskNode node, int index) { * @return The current instance of {@link TaskQueue} */ public @Nonnull TaskQueue thenRepeat(int iterations, @Nonnull IntConsumer consumer) { + Validate.notNull(consumer, "The consumer cannot be null"); for (int i = 0; i < iterations; i++) { append(new TaskNode(consumer, false)); } @@ -212,6 +224,7 @@ private void run(@Nonnull Plugin plugin, @Nullable TaskNode node, int index) { * @return The current instance of {@link TaskQueue} */ public @Nonnull TaskQueue thenRepeat(int iterations, @Nonnull Runnable runnable) { + Validate.notNull(runnable, "The runnable cannot be null"); return thenRepeat(iterations, i -> runnable.run()); } @@ -228,6 +241,7 @@ private void run(@Nonnull Plugin plugin, @Nullable TaskNode node, int index) { * @return The current instance of {@link TaskQueue} */ public @Nonnull TaskQueue thenRepeatAsynchronously(int iterations, @Nonnull IntConsumer consumer) { + Validate.notNull(consumer, "The consumer cannot be null"); for (int i = 0; i < iterations; i++) { append(new TaskNode(consumer, true)); } @@ -247,6 +261,7 @@ private void run(@Nonnull Plugin plugin, @Nullable TaskNode node, int index) { * @return The current instance of {@link TaskQueue} */ public @Nonnull TaskQueue thenRepeatAsynchronously(int iterations, @Nonnull Runnable runnable) { + Validate.notNull(runnable, "The runnable cannot be null"); return thenRepeatAsynchronously(iterations, i -> runnable.run()); } @@ -290,6 +305,7 @@ private void run(@Nonnull Plugin plugin, @Nullable TaskNode node, int index) { * @return The current instance of {@link TaskQueue} */ public @Nonnull TaskQueue thenRepeatEvery(int ticks, int iterations, @Nonnull Runnable runnable) { + Validate.notNull(runnable, "The runnable cannot be null"); return thenRepeatEvery(ticks, iterations, i -> runnable.run()); } @@ -308,6 +324,7 @@ private void run(@Nonnull Plugin plugin, @Nullable TaskNode node, int index) { * @return The current instance of {@link TaskQueue} */ public @Nonnull TaskQueue thenRepeatEveryAsynchronously(int ticks, int iterations, @Nonnull IntConsumer consumer) { + Validate.notNull(consumer, "The consumer cannot be null"); if (ticks < 1) { throw new IllegalArgumentException("thenRepeatEveryAsynchronously() must be given a time that is greater than zero!"); } @@ -333,6 +350,7 @@ private void run(@Nonnull Plugin plugin, @Nullable TaskNode node, int index) { * @return The current instance of {@link TaskQueue} */ public @Nonnull TaskQueue thenRepeatEveryAsynchronously(int ticks, int iterations, @Nonnull Runnable runnable) { + Validate.notNull(runnable, "The runnable cannot be null"); return thenRepeatEveryAsynchronously(ticks, iterations, i -> runnable.run()); } @@ -345,6 +363,7 @@ private void run(@Nonnull Plugin plugin, @Nullable TaskNode node, int index) { * The callback to run */ public void thenLoop(@Nonnull IntConsumer consumer) { + Validate.notNull(consumer, "The consumer cannot be null"); TaskNode node = new TaskNode(consumer, false); node.setNextNode(node); append(node); @@ -359,6 +378,7 @@ public void thenLoop(@Nonnull IntConsumer consumer) { * The callback to run */ public void thenLoop(@Nonnull Runnable runnable) { + Validate.notNull(runnable, "The runnable cannot be null"); thenLoop(i -> runnable.run()); } @@ -371,6 +391,7 @@ public void thenLoop(@Nonnull Runnable runnable) { * The callback to run */ public void thenLoopAsynchronously(@Nonnull IntConsumer consumer) { + Validate.notNull(consumer, "The consumer cannot be null"); TaskNode node = new TaskNode(consumer, true); node.setNextNode(node); append(node); @@ -385,6 +406,7 @@ public void thenLoopAsynchronously(@Nonnull IntConsumer consumer) { * The callback to run */ public void thenLoopAsynchronously(@Nonnull Runnable runnable) { + Validate.notNull(runnable, "The runnable cannot be null"); thenLoopAsynchronously(i -> runnable.run()); } @@ -399,6 +421,7 @@ public void thenLoopAsynchronously(@Nonnull Runnable runnable) { * The callback to run */ public void thenLoopEvery(int ticks, @Nonnull IntConsumer consumer) { + Validate.notNull(consumer, "The consumer cannot be null"); if (ticks < 1) { throw new IllegalArgumentException("thenLoopEvery() must be given a time that is greater than zero!"); } @@ -419,6 +442,7 @@ public void thenLoopEvery(int ticks, @Nonnull IntConsumer consumer) { * The callback to run */ public void thenLoopEvery(int ticks, @Nonnull Runnable runnable) { + Validate.notNull(runnable, "The runnable cannot be null"); thenLoopEvery(ticks, i -> runnable.run()); } @@ -433,6 +457,8 @@ public void thenLoopEvery(int ticks, @Nonnull Runnable runnable) { * The callback to run */ public void thenLoopEveryAsynchronously(int ticks, @Nonnull IntConsumer consumer) { + Validate.notNull(consumer, "The consumer cannot be null"); + if (ticks < 1) { throw new IllegalArgumentException("thenLoopEveryAsynchronously() must be given a time that is greater than zero!"); } @@ -453,6 +479,7 @@ public void thenLoopEveryAsynchronously(int ticks, @Nonnull IntConsumer consumer * The callback to run */ public void thenLoopEveryAsynchronously(int ticks, @Nonnull Runnable runnable) { + Validate.notNull(runnable, "The runnable cannot be null"); thenLoopEveryAsynchronously(ticks, i -> runnable.run()); } diff --git a/dough-updater/src/main/java/io/github/bakedlibs/dough/updater/UpdateInfo.java b/dough-updater/src/main/java/io/github/bakedlibs/dough/updater/UpdateInfo.java index 68a66263..3a70e14b 100644 --- a/dough-updater/src/main/java/io/github/bakedlibs/dough/updater/UpdateInfo.java +++ b/dough-updater/src/main/java/io/github/bakedlibs/dough/updater/UpdateInfo.java @@ -4,8 +4,11 @@ import javax.annotation.ParametersAreNonnullByDefault; +import org.apache.commons.lang.Validate; + import io.github.bakedlibs.dough.versions.Version; + // TODO: Convert to Java 16 record class UpdateInfo { @@ -14,6 +17,9 @@ class UpdateInfo { @ParametersAreNonnullByDefault UpdateInfo(URL url, Version version) { + Validate.notNull(url, "The URL cannot be null"); + Validate.notNull(version, "The version cannot be null"); + this.url = url; this.version = version; }