diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 6e6d01d2e8..9c17567466 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -131,7 +131,7 @@ But do try to follow our code style as best as you can.* * Do not declare multiple fields/variables on the same line! (e.g. Don't do this: `int x, y, z;`) * Use a Logger, try to avoid `System.out.println(...)` and `Throwable#printStacktrace()`, use `Logger#log` instead! * Do not use Exceptions to validate data, empty catch blocks are a very bad practice, use other means like a regular expression to validate data. -* If a parameter is annotated with `@Nonnull`, you should enforce this behaviour by doing `Validate.notNull(variable, "...");` and give a meaningful message about what went wrong +* If a parameter is annotated with `@Nonnull`, you should enforce this behaviour by doing `Preconditions.checkNotNull(variable, "...");` and give a meaningful message about what went wrong * Any `switch/case` should always have a `default:` case at the end. * If you are working with a resource that must be closed, use a `try/with-resource`, this will automatically close the resource at the end. (e.g. `try (InputStream stream = ...) {`) * Array designators should be placed behind the type, not the variable name. (e.g. `int[] myArray`) diff --git a/pom.xml b/pom.xml index 5bc0d0d651..5d82acbcb5 100644 --- a/pom.xml +++ b/pom.xml @@ -508,13 +508,6 @@ - - - commons-lang - commons-lang - 2.6 - compile - org.spigotmc spigot-api diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/api/MinecraftVersion.java b/src/main/java/io/github/thebusybiscuit/slimefun4/api/MinecraftVersion.java index 4fc0160ac6..a5690ea1ee 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/api/MinecraftVersion.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/api/MinecraftVersion.java @@ -2,7 +2,7 @@ import javax.annotation.Nonnull; -import org.apache.commons.lang.Validate; +import com.google.common.base.Preconditions; import org.bukkit.Server; import io.github.thebusybiscuit.slimefun4.implementation.Slimefun; @@ -227,7 +227,7 @@ public boolean isMinecraftVersion(int minecraftVersion, int patchVersion) { * @return Whether this {@link MinecraftVersion} is newer or equal to the given {@link MinecraftVersion} */ public boolean isAtLeast(@Nonnull MinecraftVersion version) { - Validate.notNull(version, "A Minecraft version cannot be null!"); + Preconditions.checkNotNull(version, "A Minecraft version cannot be null!"); if (this == UNKNOWN) { return false; @@ -262,7 +262,7 @@ public boolean isAtLeast(@Nonnull MinecraftVersion version) { * @return Whether this {@link MinecraftVersion} is older than the given one */ public boolean isBefore(@Nonnull MinecraftVersion version) { - Validate.notNull(version, "A Minecraft version cannot be null!"); + Preconditions.checkNotNull(version, "A Minecraft version cannot be null!"); if (this == UNKNOWN) { return true; diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/api/SlimefunAddon.java b/src/main/java/io/github/thebusybiscuit/slimefun4/api/SlimefunAddon.java index 8d8609c8be..582ad3fe45 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/api/SlimefunAddon.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/api/SlimefunAddon.java @@ -5,7 +5,7 @@ import javax.annotation.Nonnull; import javax.annotation.Nullable; -import org.apache.commons.lang.Validate; +import com.google.common.base.Preconditions; import org.bukkit.plugin.Plugin; import org.bukkit.plugin.PluginDescriptionFile; import org.bukkit.plugin.java.JavaPlugin; @@ -86,7 +86,7 @@ public interface SlimefunAddon { * @return Whether this {@link SlimefunAddon} depends on the given {@link Plugin} */ default boolean hasDependency(@Nonnull String dependency) { - Validate.notNull(dependency, "The dependency cannot be null"); + Preconditions.checkNotNull(dependency, "The dependency cannot be null"); // Well... it cannot depend on itself but you get the idea. if (getJavaPlugin().getName().equalsIgnoreCase(dependency)) { diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/api/SlimefunBranch.java b/src/main/java/io/github/thebusybiscuit/slimefun4/api/SlimefunBranch.java index f755717da1..effc6771a2 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/api/SlimefunBranch.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/api/SlimefunBranch.java @@ -2,7 +2,7 @@ import javax.annotation.Nonnull; -import org.apache.commons.lang.Validate; +import com.google.common.base.Preconditions; import io.github.bakedlibs.dough.common.CommonPatterns; @@ -45,7 +45,7 @@ public enum SlimefunBranch { private final boolean official; SlimefunBranch(@Nonnull String name, boolean official) { - Validate.notNull(name, "The branch name cannot be null"); + Preconditions.checkNotNull(name, "The branch name cannot be null"); this.name = name; this.official = official; diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/api/events/AsyncAutoEnchanterProcessEvent.java b/src/main/java/io/github/thebusybiscuit/slimefun4/api/events/AsyncAutoEnchanterProcessEvent.java index 09f306186e..43338094c1 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/api/events/AsyncAutoEnchanterProcessEvent.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/api/events/AsyncAutoEnchanterProcessEvent.java @@ -2,7 +2,7 @@ import javax.annotation.Nonnull; -import org.apache.commons.lang.Validate; +import com.google.common.base.Preconditions; import org.bukkit.event.Cancellable; import org.bukkit.event.Event; import org.bukkit.event.HandlerList; @@ -31,9 +31,9 @@ public class AsyncAutoEnchanterProcessEvent extends Event implements Cancellable public AsyncAutoEnchanterProcessEvent(@Nonnull ItemStack item, @Nonnull ItemStack enchantedBook, @Nonnull BlockMenu menu) { super(true); - Validate.notNull(item, "The item to enchant cannot be null!"); - Validate.notNull(enchantedBook, "The enchanted book to enchant cannot be null!"); - Validate.notNull(menu, "The menu of auto-enchanter cannot be null!"); + Preconditions.checkNotNull(item, "The item to enchant cannot be null!"); + Preconditions.checkNotNull(enchantedBook, "The enchanted book to enchant cannot be null!"); + Preconditions.checkNotNull(menu, "The menu of auto-enchanter cannot be null!"); this.item = item; this.enchantedBook = enchantedBook; diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/api/events/AsyncProfileLoadEvent.java b/src/main/java/io/github/thebusybiscuit/slimefun4/api/events/AsyncProfileLoadEvent.java index b05f8e5c30..fe50eef7c8 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/api/events/AsyncProfileLoadEvent.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/api/events/AsyncProfileLoadEvent.java @@ -4,7 +4,7 @@ import javax.annotation.Nonnull; -import org.apache.commons.lang.Validate; +import com.google.common.base.Preconditions; import org.bukkit.entity.Player; import org.bukkit.event.Event; import org.bukkit.event.HandlerList; @@ -32,7 +32,7 @@ public class AsyncProfileLoadEvent extends Event { public AsyncProfileLoadEvent(@Nonnull PlayerProfile profile) { super(true); - Validate.notNull(profile, "The Profile cannot be null"); + Preconditions.checkNotNull(profile, "The Profile cannot be null"); this.uniqueId = profile.getUUID(); this.profile = profile; @@ -56,8 +56,8 @@ public PlayerProfile getProfile() { * The {@link PlayerProfile} */ public void setProfile(@Nonnull PlayerProfile profile) { - Validate.notNull(profile, "The PlayerProfile cannot be null!"); - Validate.isTrue(profile.getUUID().equals(uniqueId), "Cannot inject a PlayerProfile with a different UUID"); + Preconditions.checkNotNull(profile, "The PlayerProfile cannot be null!"); + Preconditions.checkArgument(profile.getUUID().equals(uniqueId), "Cannot inject a PlayerProfile with a different UUID"); this.profile = profile; } diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/api/events/BlockPlacerPlaceEvent.java b/src/main/java/io/github/thebusybiscuit/slimefun4/api/events/BlockPlacerPlaceEvent.java index 59ee4bdf51..be7503c37d 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/api/events/BlockPlacerPlaceEvent.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/api/events/BlockPlacerPlaceEvent.java @@ -3,7 +3,7 @@ import javax.annotation.Nonnull; import javax.annotation.ParametersAreNonnullByDefault; -import org.apache.commons.lang.Validate; +import com.google.common.base.Preconditions; import org.bukkit.block.Block; import org.bukkit.event.Cancellable; import org.bukkit.event.Event; @@ -75,7 +75,7 @@ public ItemStack getItemStack() { * The {@link ItemStack} to be placed */ public void setItemStack(@Nonnull ItemStack item) { - Validate.notNull(item, "The ItemStack must not be null!"); + Preconditions.checkNotNull(item, "The ItemStack must not be null!"); if (!locked) { this.placedItem = item; diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/api/events/ClimbingPickLaunchEvent.java b/src/main/java/io/github/thebusybiscuit/slimefun4/api/events/ClimbingPickLaunchEvent.java index e5bb91dc24..ebef3eddf6 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/api/events/ClimbingPickLaunchEvent.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/api/events/ClimbingPickLaunchEvent.java @@ -3,7 +3,7 @@ import javax.annotation.Nonnull; import javax.annotation.ParametersAreNonnullByDefault; -import org.apache.commons.lang.Validate; +import com.google.common.base.Preconditions; import org.bukkit.block.Block; import org.bukkit.entity.Player; import org.bukkit.event.Cancellable; @@ -63,7 +63,7 @@ public Vector getVelocity() { * The {@link Vector} velocity to apply */ public void setVelocity(@Nonnull Vector velocity) { - Validate.notNull(velocity); + Preconditions.checkNotNull(velocity); this.velocity = velocity; } diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/api/events/CoolerFeedPlayerEvent.java b/src/main/java/io/github/thebusybiscuit/slimefun4/api/events/CoolerFeedPlayerEvent.java index b6a3d579cb..63e7363714 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/api/events/CoolerFeedPlayerEvent.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/api/events/CoolerFeedPlayerEvent.java @@ -3,7 +3,7 @@ import javax.annotation.Nonnull; import javax.annotation.ParametersAreNonnullByDefault; -import org.apache.commons.lang.Validate; +import com.google.common.base.Preconditions; import org.bukkit.entity.Player; import org.bukkit.event.Cancellable; import org.bukkit.event.Event; @@ -84,8 +84,8 @@ public ItemStack getConsumedItem() { * The new {@link ItemStack} */ public void setConsumedItem(@Nonnull ItemStack item) { - Validate.notNull(item, "The consumed Item cannot be null!"); - Validate.isTrue(item.getItemMeta() instanceof PotionMeta, "The item must be a potion!"); + Preconditions.checkNotNull(item, "The consumed Item cannot be null!"); + Preconditions.checkArgument(item.getItemMeta() instanceof PotionMeta, "The item must be a potion!"); this.consumedItem = item; } diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/api/events/ExplosiveToolBreakBlocksEvent.java b/src/main/java/io/github/thebusybiscuit/slimefun4/api/events/ExplosiveToolBreakBlocksEvent.java index e0bd18e6e0..29f8bbb6d9 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/api/events/ExplosiveToolBreakBlocksEvent.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/api/events/ExplosiveToolBreakBlocksEvent.java @@ -5,7 +5,7 @@ import javax.annotation.Nonnull; import javax.annotation.ParametersAreNonnullByDefault; -import org.apache.commons.lang.Validate; +import com.google.common.base.Preconditions; import org.bukkit.block.Block; import org.bukkit.entity.Player; import org.bukkit.event.Cancellable; @@ -38,10 +38,10 @@ public class ExplosiveToolBreakBlocksEvent extends PlayerEvent implements Cancel public ExplosiveToolBreakBlocksEvent(Player player, Block block, List blocks, ItemStack item, ExplosiveTool explosiveTool) { super(player); - Validate.notNull(block, "The center block cannot be null!"); - Validate.notNull(blocks, "Blocks cannot be null"); - Validate.notNull(item, "Item cannot be null"); - Validate.notNull(explosiveTool, "ExplosiveTool cannot be null"); + Preconditions.checkNotNull(block, "The center block cannot be null!"); + Preconditions.checkNotNull(blocks, "Blocks cannot be null"); + Preconditions.checkNotNull(item, "Item cannot be null"); + Preconditions.checkNotNull(explosiveTool, "ExplosiveTool cannot be null"); this.mainBlock = block; this.additionalBlocks = blocks; diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/api/events/PlayerPreResearchEvent.java b/src/main/java/io/github/thebusybiscuit/slimefun4/api/events/PlayerPreResearchEvent.java index 1e0a618697..bf7ffcd2f5 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/api/events/PlayerPreResearchEvent.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/api/events/PlayerPreResearchEvent.java @@ -3,7 +3,7 @@ import javax.annotation.Nonnull; import javax.annotation.ParametersAreNonnullByDefault; -import org.apache.commons.lang.Validate; +import com.google.common.base.Preconditions; import org.bukkit.entity.Player; import org.bukkit.event.Cancellable; import org.bukkit.event.Event; @@ -35,9 +35,9 @@ public class PlayerPreResearchEvent extends Event implements Cancellable { @ParametersAreNonnullByDefault public PlayerPreResearchEvent(Player p, Research research, SlimefunItem slimefunItem) { - Validate.notNull(p, "The Player cannot be null"); - Validate.notNull(research, "Research cannot be null"); - Validate.notNull(slimefunItem, "SlimefunItem cannot be null"); + Preconditions.checkNotNull(p, "The Player cannot be null"); + Preconditions.checkNotNull(research, "Research cannot be null"); + Preconditions.checkNotNull(slimefunItem, "SlimefunItem cannot be null"); this.player = p; this.research = research; diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/api/events/PlayerRightClickEvent.java b/src/main/java/io/github/thebusybiscuit/slimefun4/api/events/PlayerRightClickEvent.java index 30c9c927af..bf6e641d5f 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/api/events/PlayerRightClickEvent.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/api/events/PlayerRightClickEvent.java @@ -4,7 +4,7 @@ import javax.annotation.Nonnull; -import org.apache.commons.lang.Validate; +import com.google.common.base.Preconditions; import org.bukkit.Material; import org.bukkit.block.Block; import org.bukkit.block.BlockFace; @@ -168,12 +168,12 @@ public Result useBlock() { } public void setUseItem(@Nonnull Result result) { - Validate.notNull(result, "Result cannot be null"); + Preconditions.checkNotNull(result, "Result cannot be null"); itemResult = result; } public void setUseBlock(@Nonnull Result result) { - Validate.notNull(result, "Result cannot be null"); + Preconditions.checkNotNull(result, "Result cannot be null"); blockResult = result; } diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/api/events/ReactorExplodeEvent.java b/src/main/java/io/github/thebusybiscuit/slimefun4/api/events/ReactorExplodeEvent.java index 859a80935b..c4ac6a48cd 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/api/events/ReactorExplodeEvent.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/api/events/ReactorExplodeEvent.java @@ -2,7 +2,7 @@ import javax.annotation.Nonnull; -import org.apache.commons.lang.Validate; +import com.google.common.base.Preconditions; import org.bukkit.Location; import org.bukkit.event.Event; import org.bukkit.event.HandlerList; @@ -24,8 +24,8 @@ public class ReactorExplodeEvent extends Event { private final Reactor reactor; public ReactorExplodeEvent(@Nonnull Location l, @Nonnull Reactor reactor) { - Validate.notNull(l, "A Location must be provided"); - Validate.notNull(reactor, "A Reactor cannot be null"); + Preconditions.checkNotNull(l, "A Location must be provided"); + Preconditions.checkNotNull(reactor, "A Reactor cannot be null"); this.location = l; this.reactor = reactor; diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/api/events/ResearchUnlockEvent.java b/src/main/java/io/github/thebusybiscuit/slimefun4/api/events/ResearchUnlockEvent.java index 59d097a2ad..4f2884a34f 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/api/events/ResearchUnlockEvent.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/api/events/ResearchUnlockEvent.java @@ -2,7 +2,7 @@ import javax.annotation.Nonnull; -import org.apache.commons.lang.Validate; +import com.google.common.base.Preconditions; import org.bukkit.Bukkit; import org.bukkit.entity.Player; import org.bukkit.event.Cancellable; @@ -30,8 +30,8 @@ public class ResearchUnlockEvent extends Event implements Cancellable { public ResearchUnlockEvent(@Nonnull Player p, @Nonnull Research research) { super(!Bukkit.isPrimaryThread()); - Validate.notNull(p, "The Player cannot be null"); - Validate.notNull(research, "Research cannot be null"); + Preconditions.checkNotNull(p, "The Player cannot be null"); + Preconditions.checkNotNull(research, "Research cannot be null"); this.player = p; this.research = research; diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/api/events/SlimefunGuideOpenEvent.java b/src/main/java/io/github/thebusybiscuit/slimefun4/api/events/SlimefunGuideOpenEvent.java index ecf46a5311..aa5a041cd8 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/api/events/SlimefunGuideOpenEvent.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/api/events/SlimefunGuideOpenEvent.java @@ -2,7 +2,7 @@ import javax.annotation.Nonnull; -import org.apache.commons.lang.Validate; +import com.google.common.base.Preconditions; import org.bukkit.entity.Player; import org.bukkit.event.Cancellable; import org.bukkit.event.Event; @@ -28,9 +28,9 @@ public class SlimefunGuideOpenEvent extends Event implements Cancellable { private boolean cancelled; public SlimefunGuideOpenEvent(@Nonnull Player p, @Nonnull ItemStack guide, @Nonnull SlimefunGuideMode layout) { - Validate.notNull(p, "The Player cannot be null"); - Validate.notNull(guide, "Guide cannot be null"); - Validate.notNull(layout, "Layout cannot be null"); + Preconditions.checkNotNull(p, "The Player cannot be null"); + Preconditions.checkNotNull(guide, "Guide cannot be null"); + Preconditions.checkNotNull(layout, "Layout cannot be null"); this.player = p; this.guide = guide; this.layout = layout; @@ -76,7 +76,7 @@ public SlimefunGuideMode getGuideLayout() { * The new {@link SlimefunGuideMode} */ public void setGuideLayout(@Nonnull SlimefunGuideMode layout) { - Validate.notNull(layout, "You must specify a layout that is not-null!"); + Preconditions.checkNotNull(layout, "You must specify a layout that is not-null!"); this.layout = layout; } diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/api/events/SlimefunItemSpawnEvent.java b/src/main/java/io/github/thebusybiscuit/slimefun4/api/events/SlimefunItemSpawnEvent.java index 95b5fadf6f..88f564a011 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/api/events/SlimefunItemSpawnEvent.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/api/events/SlimefunItemSpawnEvent.java @@ -6,7 +6,7 @@ import javax.annotation.Nullable; import javax.annotation.ParametersAreNonnullByDefault; -import org.apache.commons.lang.Validate; +import com.google.common.base.Preconditions; import org.bukkit.Location; import org.bukkit.entity.Player; import org.bukkit.event.Cancellable; @@ -83,7 +83,7 @@ public SlimefunItemSpawnEvent(Location location, ItemStack itemStack, ItemSpawnR * The {@link Location} where to drop the {@link ItemStack} */ public void setLocation(@Nonnull Location location) { - Validate.notNull(location, "The Location cannot be null!"); + Preconditions.checkNotNull(location, "The Location cannot be null!"); this.location = location; } @@ -104,8 +104,8 @@ public void setLocation(@Nonnull Location location) { * The {@link ItemStack} to drop */ public void setItemStack(@Nonnull ItemStack itemStack) { - Validate.notNull(itemStack, "Cannot drop null."); - Validate.isTrue(!itemStack.getType().isAir(), "Cannot drop air."); + Preconditions.checkNotNull(itemStack, "Cannot drop null."); + Preconditions.checkArgument(!itemStack.getType().isAir(), "Cannot drop air."); this.itemStack = itemStack; } diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/api/events/WaypointCreateEvent.java b/src/main/java/io/github/thebusybiscuit/slimefun4/api/events/WaypointCreateEvent.java index 4253f7983e..56867007e7 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/api/events/WaypointCreateEvent.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/api/events/WaypointCreateEvent.java @@ -2,7 +2,8 @@ import javax.annotation.Nonnull; -import org.apache.commons.lang.Validate; +import com.google.common.base.Preconditions; +import com.google.common.base.Preconditions; import org.bukkit.Location; import org.bukkit.entity.Player; import org.bukkit.event.Cancellable; @@ -37,8 +38,8 @@ public class WaypointCreateEvent extends PlayerEvent implements Cancellable { public WaypointCreateEvent(@Nonnull Player player, @Nonnull String name, @Nonnull Location location) { super(player); - Validate.notNull(location, "Location must not be null!"); - Validate.notNull(name, "Name must not be null!"); + Preconditions.checkNotNull(location, "Location must not be null!"); + Preconditions.checkNotNull(name, "Name must not be null!"); this.location = location; this.name = name; @@ -63,7 +64,7 @@ public Location getLocation() { * The {@link Location} to set */ public void setLocation(@Nonnull Location loc) { - Validate.notNull(loc, "Cannot set the Location to null!"); + Preconditions.checkNotNull(loc, "Cannot set the Location to null!"); this.location = loc; } @@ -84,7 +85,7 @@ public String getName() { * The name for this waypoint */ public void setName(@Nonnull String name) { - Validate.notEmpty(name, "The name of a waypoint must not be empty!"); + Preconditions.checkArgument(!name.isEmpty(), "The name of a waypoint must not be empty!"); this.name = name; } diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/api/geo/ResourceManager.java b/src/main/java/io/github/thebusybiscuit/slimefun4/api/geo/ResourceManager.java index ce4fea9b02..d5f5b83f24 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/api/geo/ResourceManager.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/api/geo/ResourceManager.java @@ -9,7 +9,7 @@ import javax.annotation.Nonnull; -import org.apache.commons.lang.Validate; +import com.google.common.base.Preconditions; import org.bukkit.Bukkit; import org.bukkit.ChatColor; import org.bukkit.Chunk; @@ -69,8 +69,8 @@ public ResourceManager(@Nonnull Slimefun plugin) { * The {@link GEOResource} to register */ void register(@Nonnull GEOResource resource) { - Validate.notNull(resource, "Cannot register null as a GEO-Resource"); - Validate.notNull(resource.getKey(), "GEO-Resources must have a NamespacedKey which is not null"); + Preconditions.checkNotNull(resource, "Cannot register null as a GEO-Resource"); + Preconditions.checkNotNull(resource.getKey(), "GEO-Resources must have a NamespacedKey which is not null"); // Resources may only be registered once if (Slimefun.getRegistry().getGEOResources().containsKey(resource.getKey())) { @@ -106,8 +106,8 @@ void register(@Nonnull GEOResource resource) { * @return An {@link OptionalInt}, either empty or containing the amount of the given {@link GEOResource} */ public @Nonnull OptionalInt getSupplies(@Nonnull GEOResource resource, @Nonnull World world, int x, int z) { - Validate.notNull(resource, "Cannot get supplies for null"); - Validate.notNull(world, "World must not be null"); + Preconditions.checkNotNull(resource, "Cannot get supplies for null"); + Preconditions.checkNotNull(world, "World must not be null"); String key = resource.getKey().toString().replace(':', '-'); String value = BlockStorage.getChunkInfo(world, x, z, key); @@ -134,8 +134,8 @@ void register(@Nonnull GEOResource resource) { * The new supply value */ public void setSupplies(@Nonnull GEOResource resource, @Nonnull World world, int x, int z, int value) { - Validate.notNull(resource, "Cannot set supplies for null"); - Validate.notNull(world, "World cannot be null"); + Preconditions.checkNotNull(resource, "Cannot set supplies for null"); + Preconditions.checkNotNull(world, "World cannot be null"); String key = resource.getKey().toString().replace(':', '-'); BlockStorage.setChunkInfo(world, x, z, key, String.valueOf(value)); @@ -160,8 +160,8 @@ public void setSupplies(@Nonnull GEOResource resource, @Nonnull World world, int * @return The new supply value */ private int generate(@Nonnull GEOResource resource, @Nonnull World world, int x, int y, int z) { - Validate.notNull(resource, "Cannot generate resources for null"); - Validate.notNull(world, "World cannot be null"); + Preconditions.checkNotNull(resource, "Cannot generate resources for null"); + Preconditions.checkNotNull(world, "World cannot be null"); // Get the corresponding Block (and Biome) Block block = world.getBlockAt(x << 4, y, z << 4); @@ -171,7 +171,7 @@ private int generate(@Nonnull GEOResource resource, @Nonnull World world, int x, * getBiome() is marked as NotNull, but it seems like some servers ignore this entirely. * We have seen multiple reports on Tuinity where it has indeed returned null. */ - Validate.notNull(biome, "Biome appears to be null for position: " + new BlockPosition(block)); + Preconditions.checkNotNull(biome, "Biome appears to be null for position: " + new BlockPosition(block)); // Make sure the value is not below zero. int value = Math.max(0, resource.getDefaultSupply(world.getEnvironment(), biome)); diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/api/gps/GPSNetwork.java b/src/main/java/io/github/thebusybiscuit/slimefun4/api/gps/GPSNetwork.java index 47574fb2ca..ca3e1fc18d 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/api/gps/GPSNetwork.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/api/gps/GPSNetwork.java @@ -10,7 +10,7 @@ import javax.annotation.Nonnull; import javax.annotation.ParametersAreNonnullByDefault; -import org.apache.commons.lang.Validate; +import com.google.common.base.Preconditions; import org.bukkit.Bukkit; import org.bukkit.ChatColor; import org.bukkit.Location; @@ -280,8 +280,8 @@ public void openWaypointControlPanel(@Nonnull Player p) { * The {@link Location} of the new waypoint */ public void createWaypoint(@Nonnull Player p, @Nonnull Location l) { - Validate.notNull(p, "Player cannot be null!"); - Validate.notNull(l, "Waypoint Location cannot be null!"); + Preconditions.checkNotNull(p, "Player cannot be null!"); + Preconditions.checkNotNull(l, "Waypoint Location cannot be null!"); PlayerProfile.get(p, profile -> { if ((profile.getWaypoints().size() + 2) > inventory.length) { @@ -307,9 +307,9 @@ public void createWaypoint(@Nonnull Player p, @Nonnull Location l) { * The {@link Location} of this waypoint */ public void addWaypoint(@Nonnull Player p, @Nonnull String name, @Nonnull Location l) { - Validate.notNull(p, "Player cannot be null!"); - Validate.notNull(name, "Waypoint name cannot be null!"); - Validate.notNull(l, "Waypoint Location cannot be null!"); + Preconditions.checkNotNull(p, "Player cannot be null!"); + Preconditions.checkNotNull(name, "Waypoint name cannot be null!"); + Preconditions.checkNotNull(l, "Waypoint Location cannot be null!"); PlayerProfile.get(p, profile -> { if ((profile.getWaypoints().size() + 2) > inventory.length) { diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/api/gps/TeleportationManager.java b/src/main/java/io/github/thebusybiscuit/slimefun4/api/gps/TeleportationManager.java index 6f65962024..ba3570341c 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/api/gps/TeleportationManager.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/api/gps/TeleportationManager.java @@ -8,7 +8,7 @@ import javax.annotation.Nullable; import javax.annotation.ParametersAreNonnullByDefault; -import org.apache.commons.lang.Validate; +import com.google.common.base.Preconditions; import org.bukkit.Bukkit; import org.bukkit.ChatColor; import org.bukkit.Location; @@ -154,8 +154,8 @@ public void teleport(UUID uuid, int complexity, Location source, Location destin * @return The amount of time the teleportation will take */ public int getTeleportationTime(int complexity, @Nonnull Location source, @Nonnull Location destination) { - Validate.notNull(source, "Source cannot be null"); - Validate.notNull(source, "Destination cannot be null"); + Preconditions.checkNotNull(source, "Source cannot be null"); + Preconditions.checkNotNull(source, "Destination cannot be null"); if (complexity < 100) { return 100; diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/api/gps/Waypoint.java b/src/main/java/io/github/thebusybiscuit/slimefun4/api/gps/Waypoint.java index 468b70af6b..c1e8e32b4a 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/api/gps/Waypoint.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/api/gps/Waypoint.java @@ -6,7 +6,7 @@ import javax.annotation.Nonnull; import javax.annotation.ParametersAreNonnullByDefault; -import org.apache.commons.lang.Validate; +import com.google.common.base.Preconditions; import org.bukkit.Bukkit; import org.bukkit.Location; import org.bukkit.World.Environment; @@ -71,10 +71,10 @@ public Waypoint(PlayerProfile profile, String id, Location loc, String name) { */ @ParametersAreNonnullByDefault public Waypoint(UUID ownerId, String id, Location loc, String name) { - Validate.notNull(ownerId, "owner ID must never be null!"); - Validate.notNull(id, "id must never be null!"); - Validate.notNull(loc, "Location must never be null!"); - Validate.notNull(name, "Name must never be null!"); + Preconditions.checkNotNull(ownerId, "owner ID must never be null!"); + Preconditions.checkNotNull(id, "id must never be null!"); + Preconditions.checkNotNull(loc, "Location must never be null!"); + Preconditions.checkNotNull(name, "Name must never be null!"); this.ownerId = ownerId; this.id = id; diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/api/items/ItemGroup.java b/src/main/java/io/github/thebusybiscuit/slimefun4/api/items/ItemGroup.java index 81b8f331f6..afdeb36c72 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/api/items/ItemGroup.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/api/items/ItemGroup.java @@ -10,7 +10,7 @@ import javax.annotation.Nullable; import javax.annotation.ParametersAreNonnullByDefault; -import org.apache.commons.lang.Validate; +import com.google.common.base.Preconditions; import org.bukkit.ChatColor; import org.bukkit.Keyed; import org.bukkit.NamespacedKey; @@ -77,8 +77,8 @@ public ItemGroup(NamespacedKey key, ItemStack item) { */ @ParametersAreNonnullByDefault public ItemGroup(NamespacedKey key, ItemStack item, int tier) { - Validate.notNull(key, "An item group's NamespacedKey must not be null!"); - Validate.notNull(item, "An item group's ItemStack must not be null!"); + Preconditions.checkNotNull(key, "An item group's NamespacedKey must not be null!"); + Preconditions.checkNotNull(item, "An item group's ItemStack must not be null!"); this.item = item; this.key = key; @@ -106,7 +106,7 @@ public ItemGroup(NamespacedKey key, ItemStack item, int tier) { * The {@link SlimefunAddon} that wants to register this {@link ItemGroup} */ public void register(@Nonnull SlimefunAddon addon) { - Validate.notNull(addon, "The Addon cannot be null"); + Preconditions.checkNotNull(addon, "The Addon cannot be null"); if (isRegistered()) { throw new UnsupportedOperationException("This ItemGroup has already been registered!"); @@ -179,7 +179,7 @@ private void sortCategoriesByTier() { * the {@link SlimefunItem} that should be added to this {@link ItemGroup} */ public void add(@Nonnull SlimefunItem item) { - Validate.notNull(item, "Cannot add null Items to an ItemGroup!"); + Preconditions.checkNotNull(item, "Cannot add null Items to an ItemGroup!"); if (items.contains(item)) { // Ignore duplicate entries @@ -200,7 +200,7 @@ public void add(@Nonnull SlimefunItem item) { * the {@link SlimefunItem} that should be removed from this {@link ItemGroup} */ public void remove(@Nonnull SlimefunItem item) { - Validate.notNull(item, "Cannot remove null from an ItemGroup!"); + Preconditions.checkNotNull(item, "Cannot remove null from an ItemGroup!"); items.remove(item); } diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/api/items/ItemSetting.java b/src/main/java/io/github/thebusybiscuit/slimefun4/api/items/ItemSetting.java index 4a49b89ec8..f22579537a 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/api/items/ItemSetting.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/api/items/ItemSetting.java @@ -6,8 +6,7 @@ import javax.annotation.Nonnull; import javax.annotation.ParametersAreNonnullByDefault; -import org.apache.commons.lang.Validate; - +import com.google.common.base.Preconditions; import io.github.bakedlibs.dough.config.Config; import io.github.thebusybiscuit.slimefun4.implementation.Slimefun; @@ -41,9 +40,9 @@ public class ItemSetting { */ @ParametersAreNonnullByDefault public ItemSetting(SlimefunItem item, String key, T defaultValue) { - Validate.notNull(item, "The provided SlimefunItem must not be null!"); - Validate.notNull(key, "The key of an ItemSetting is not allowed to be null!"); - Validate.notNull(defaultValue, "The default value of an ItemSetting is not allowed to be null!"); + Preconditions.checkNotNull(item, "The provided SlimefunItem must not be null!"); + Preconditions.checkNotNull(key, "The key of an ItemSetting is not allowed to be null!"); + Preconditions.checkNotNull(defaultValue, "The default value of an ItemSetting is not allowed to be null!"); this.item = item; this.key = key; @@ -164,7 +163,7 @@ public boolean isType(@Nonnull Class c) { */ @SuppressWarnings("unchecked") public void reload() { - Validate.notNull(item, "Cannot apply settings for a non-existing SlimefunItem"); + Preconditions.checkNotNull(item, "Cannot apply settings for a non-existing SlimefunItem"); Slimefun.getItemCfg().setDefaultValue(item.getId() + '.' + getKey(), getDefaultValue()); Object configuredValue = Slimefun.getItemCfg().getValue(item.getId() + '.' + getKey()); diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/api/items/SlimefunItem.java b/src/main/java/io/github/thebusybiscuit/slimefun4/api/items/SlimefunItem.java index ea3775037c..0c3ee6d0fd 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/api/items/SlimefunItem.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/api/items/SlimefunItem.java @@ -4,6 +4,7 @@ import java.util.Collection; import java.util.HashMap; import java.util.HashSet; +import java.util.Objects; import java.util.Optional; import java.util.Set; import java.util.function.Consumer; @@ -14,7 +15,7 @@ import javax.annotation.Nullable; import javax.annotation.ParametersAreNonnullByDefault; -import org.apache.commons.lang.Validate; +import com.google.common.base.Preconditions; import org.bukkit.Material; import org.bukkit.World; import org.bukkit.entity.Player; @@ -148,9 +149,9 @@ public SlimefunItem(ItemGroup itemGroup, SlimefunItemStack item, RecipeType reci */ @ParametersAreNonnullByDefault public SlimefunItem(ItemGroup itemGroup, SlimefunItemStack item, RecipeType recipeType, ItemStack[] recipe, @Nullable ItemStack recipeOutput) { - Validate.notNull(itemGroup, "'itemGroup' is not allowed to be null!"); - Validate.notNull(item, "'item' is not allowed to be null!"); - Validate.notNull(recipeType, "'recipeType' is not allowed to be null!"); + Preconditions.checkNotNull(itemGroup, "'itemGroup' is not allowed to be null!"); + Preconditions.checkNotNull(item, "'item' is not allowed to be null!"); + Preconditions.checkNotNull(recipeType, "'recipeType' is not allowed to be null!"); this.itemGroup = itemGroup; this.itemStackTemplate = item; @@ -178,10 +179,10 @@ public SlimefunItem(ItemGroup itemGroup, SlimefunItemStack item) { // Previously deprecated constructor, now only for internal purposes @ParametersAreNonnullByDefault protected SlimefunItem(ItemGroup itemGroup, ItemStack item, String id, RecipeType recipeType, ItemStack[] recipe) { - Validate.notNull(itemGroup, "'itemGroup' is not allowed to be null!"); - Validate.notNull(item, "'item' is not allowed to be null!"); - Validate.notNull(id, "'id' is not allowed to be null!"); - Validate.notNull(recipeType, "'recipeType' is not allowed to be null!"); + Preconditions.checkNotNull(itemGroup, "'itemGroup' is not allowed to be null!"); + Preconditions.checkNotNull(item, "'item' is not allowed to be null!"); + Preconditions.checkNotNull(id, "'id' is not allowed to be null!"); + Preconditions.checkNotNull(recipeType, "'recipeType' is not allowed to be null!"); this.itemGroup = itemGroup; this.itemStackTemplate = item; @@ -427,8 +428,8 @@ public BlockTicker getBlockTicker() { * The {@link SlimefunAddon} that this {@link SlimefunItem} belongs to. */ public void register(@Nonnull SlimefunAddon addon) { - Validate.notNull(addon, "A SlimefunAddon cannot be null!"); - Validate.notNull(addon.getJavaPlugin(), "SlimefunAddon#getJavaPlugin() is not allowed to return null!"); + Preconditions.checkNotNull(addon, "A SlimefunAddon cannot be null!"); + Preconditions.checkNotNull(addon.getJavaPlugin(), "SlimefunAddon#getJavaPlugin() is not allowed to return null!"); this.addon = addon; @@ -700,7 +701,7 @@ public void setRecipe(@Nonnull ItemStack[] recipe) { * The {@link RecipeType} for this {@link SlimefunItem} */ public void setRecipeType(@Nonnull RecipeType type) { - Validate.notNull(type, "The RecipeType is not allowed to be null!"); + Preconditions.checkNotNull(type, "The RecipeType is not allowed to be null!"); this.recipeType = type; } @@ -711,7 +712,7 @@ public void setRecipeType(@Nonnull RecipeType type) { * The new {@link ItemGroup} */ public void setItemGroup(@Nonnull ItemGroup itemGroup) { - Validate.notNull(itemGroup, "The ItemGroup is not allowed to be null!"); + Preconditions.checkNotNull(itemGroup, "The ItemGroup is not allowed to be null!"); this.itemGroup.remove(this); itemGroup.add(this); @@ -808,8 +809,8 @@ public void load() { * Any {@link ItemHandler} that should be added to this {@link SlimefunItem} */ public final void addItemHandler(ItemHandler... handlers) { - Validate.notEmpty(handlers, "You cannot add zero handlers..."); - Validate.noNullElements(handlers, "You cannot add any 'null' ItemHandler!"); + Preconditions.checkArgument(handlers.length != 0, "You cannot add zero handlers..."); + Preconditions.checkArgument(Arrays.stream(handlers).noneMatch(Objects::isNull), "You cannot add any 'null' ItemHandler!"); // Make sure they are added before the item was registered. if (state != ItemState.UNREGISTERED) { @@ -836,8 +837,8 @@ public final void addItemHandler(ItemHandler... handlers) { * Any {@link ItemSetting} that should be added to this {@link SlimefunItem} */ public final void addItemSetting(ItemSetting... settings) { - Validate.notEmpty(settings, "You cannot add zero settings..."); - Validate.noNullElements(settings, "You cannot add any 'null' ItemSettings!"); + Preconditions.checkArgument(settings.length != 0, "You cannot add zero settings..."); + Preconditions.checkArgument(Arrays.stream(settings).noneMatch(Objects::isNull), "You cannot add any 'null' ItemSettings!"); if (state != ItemState.UNREGISTERED) { throw new UnsupportedOperationException("You cannot add an ItemSetting after the SlimefunItem was registered."); @@ -889,7 +890,7 @@ public void postRegister() { * The associated wiki page */ public final void addOfficialWikipage(@Nonnull String page) { - Validate.notNull(page, "Wiki page cannot be null."); + Preconditions.checkNotNull(page, "Wiki page cannot be null."); wikiURL = Optional.of("https://github.com/Slimefun/Slimefun4/wiki/" + page); } @@ -1000,7 +1001,7 @@ public String toString() { */ @ParametersAreNonnullByDefault public void info(String message) { - Validate.notNull(addon, "Cannot log a message for an unregistered item!"); + Preconditions.checkNotNull(addon, "Cannot log a message for an unregistered item!"); String msg = toString() + ": " + message; addon.getLogger().log(Level.INFO, msg); @@ -1016,7 +1017,7 @@ public void info(String message) { */ @ParametersAreNonnullByDefault public void warn(String message) { - Validate.notNull(addon, "Cannot send a warning for an unregistered item!"); + Preconditions.checkNotNull(addon, "Cannot send a warning for an unregistered item!"); String msg = toString() + ": " + message; addon.getLogger().log(Level.WARNING, msg); @@ -1038,7 +1039,7 @@ public void warn(String message) { */ @ParametersAreNonnullByDefault public void error(String message, Throwable throwable) { - Validate.notNull(addon, "Cannot send an error for an unregistered item!"); + Preconditions.checkNotNull(addon, "Cannot send an error for an unregistered item!"); addon.getLogger().log(Level.SEVERE, "Item \"{0}\" from {1} v{2} has caused an Error!", new Object[] { id, addon.getName(), addon.getPluginVersion() }); if (addon.getBugTrackerURL() != null) { @@ -1063,7 +1064,7 @@ public void error(String message, Throwable throwable) { */ @ParametersAreNonnullByDefault public void sendDeprecationWarning(Player player) { - Validate.notNull(player, "The Player must not be null."); + Preconditions.checkNotNull(player, "The Player must not be null."); Slimefun.getLocalization().sendMessage(player, "messages.deprecated-item"); } @@ -1089,7 +1090,7 @@ public void sendDeprecationWarning(Player player) { * @return Whether this {@link Player} is able to use this {@link SlimefunItem}. */ public boolean canUse(@Nonnull Player p, boolean sendMessage) { - Validate.notNull(p, "The Player cannot be null!"); + Preconditions.checkNotNull(p, "The Player cannot be null!"); if (getState() == ItemState.VANILLA_FALLBACK) { // Vanilla items (which fell back) can always be used. diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/api/items/SlimefunItemStack.java b/src/main/java/io/github/thebusybiscuit/slimefun4/api/items/SlimefunItemStack.java index 611e85df6d..41fa7741bf 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/api/items/SlimefunItemStack.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/api/items/SlimefunItemStack.java @@ -11,7 +11,7 @@ import javax.annotation.Nonnull; import javax.annotation.Nullable; -import org.apache.commons.lang.Validate; +import com.google.common.base.Preconditions; import org.bukkit.ChatColor; import org.bukkit.Color; import org.bukkit.Material; @@ -52,8 +52,8 @@ public class SlimefunItemStack extends ItemStack { public SlimefunItemStack(@Nonnull String id, @Nonnull ItemStack item) { super(item); - Validate.notNull(id, "The Item id must never be null!"); - Validate.isTrue(id.equals(id.toUpperCase(Locale.ROOT)), "Slimefun Item Ids must be uppercase! (e.g. 'MY_ITEM_ID')"); + Preconditions.checkNotNull(id, "The Item id must never be null!"); + Preconditions.checkArgument(id.equals(id.toUpperCase(Locale.ROOT)), "Slimefun Item Ids must be uppercase! (e.g. 'MY_ITEM_ID')"); if (Slimefun.instance() == null) { throw new PrematureCodeException("A SlimefunItemStack must never be be created before your Plugin was enabled."); @@ -292,8 +292,8 @@ public void lock() { } private static @Nonnull String getTexture(@Nonnull String id, @Nonnull String texture) { - Validate.notNull(id, "The id cannot be null"); - Validate.notNull(texture, "The texture cannot be null"); + Preconditions.checkNotNull(id, "The id cannot be null"); + Preconditions.checkNotNull(texture, "The texture cannot be null"); if (texture.startsWith("ey")) { return texture; diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/api/items/groups/LockedItemGroup.java b/src/main/java/io/github/thebusybiscuit/slimefun4/api/items/groups/LockedItemGroup.java index 826ddbf301..8e0911af5f 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/api/items/groups/LockedItemGroup.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/api/items/groups/LockedItemGroup.java @@ -1,15 +1,17 @@ package io.github.thebusybiscuit.slimefun4.api.items.groups; import java.util.ArrayList; +import java.util.Arrays; import java.util.HashSet; import java.util.List; +import java.util.Objects; import java.util.Set; import java.util.logging.Level; import javax.annotation.Nonnull; import javax.annotation.ParametersAreNonnullByDefault; -import org.apache.commons.lang.Validate; +import com.google.common.base.Preconditions; import org.bukkit.NamespacedKey; import org.bukkit.entity.Player; import org.bukkit.inventory.ItemStack; @@ -70,7 +72,7 @@ public LockedItemGroup(NamespacedKey key, ItemStack item, NamespacedKey... paren @ParametersAreNonnullByDefault public LockedItemGroup(NamespacedKey key, ItemStack item, int tier, NamespacedKey... parents) { super(key, item, tier); - Validate.noNullElements(parents, "A LockedItemGroup must not have any 'null' parents!"); + Preconditions.checkArgument(Arrays.stream(parents).noneMatch(Objects::isNull), "A LockedItemGroup must not have any 'null' parents!"); this.keys = parents; } @@ -151,8 +153,8 @@ public void removeParent(@Nonnull ItemGroup group) { * @return Whether the {@link Player} has fully completed all parent categories, otherwise false */ public boolean hasUnlocked(@Nonnull Player p, @Nonnull PlayerProfile profile) { - Validate.notNull(p, "The player cannot be null!"); - Validate.notNull(profile, "The Profile cannot be null!"); + Preconditions.checkNotNull(p, "The player cannot be null!"); + Preconditions.checkNotNull(profile, "The Profile cannot be null!"); for (ItemGroup parent : parents) { for (SlimefunItem item : parent.getItems()) { diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/api/items/groups/NestedItemGroup.java b/src/main/java/io/github/thebusybiscuit/slimefun4/api/items/groups/NestedItemGroup.java index 9a928c8be1..319a1c009f 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/api/items/groups/NestedItemGroup.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/api/items/groups/NestedItemGroup.java @@ -6,7 +6,7 @@ import javax.annotation.Nonnull; import javax.annotation.ParametersAreNonnullByDefault; -import org.apache.commons.lang.Validate; +import com.google.common.base.Preconditions; import org.bukkit.ChatColor; import org.bukkit.NamespacedKey; import org.bukkit.entity.Player; @@ -46,7 +46,7 @@ public NestedItemGroup(NamespacedKey key, ItemStack item, int tier) { * The {@link SubItemGroup} to add. */ public void addSubGroup(@Nonnull SubItemGroup group) { - Validate.notNull(group, "The sub item group cannot be null!"); + Preconditions.checkNotNull(group, "The sub item group cannot be null!"); subGroups.add(group); } @@ -58,7 +58,7 @@ public void addSubGroup(@Nonnull SubItemGroup group) { * The {@link SubItemGroup} to remove. */ public void removeSubGroup(@Nonnull SubItemGroup group) { - Validate.notNull(group, "The sub item group cannot be null!"); + Preconditions.checkNotNull(group, "The sub item group cannot be null!"); subGroups.remove(group); } diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/api/items/groups/SeasonalItemGroup.java b/src/main/java/io/github/thebusybiscuit/slimefun4/api/items/groups/SeasonalItemGroup.java index c61212c265..bbce821f3a 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/api/items/groups/SeasonalItemGroup.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/api/items/groups/SeasonalItemGroup.java @@ -6,7 +6,7 @@ import javax.annotation.Nonnull; import javax.annotation.ParametersAreNonnullByDefault; -import org.apache.commons.lang.Validate; +import com.google.common.base.Preconditions; import org.bukkit.NamespacedKey; import org.bukkit.entity.Player; import org.bukkit.inventory.ItemStack; @@ -41,7 +41,7 @@ public class SeasonalItemGroup extends ItemGroup { @ParametersAreNonnullByDefault public SeasonalItemGroup(NamespacedKey key, Month month, int tier, ItemStack item) { super(key, item, tier); - Validate.notNull(month, "The Month cannot be null"); + Preconditions.checkNotNull(month, "The Month cannot be null"); this.month = month; } diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/api/items/groups/SubItemGroup.java b/src/main/java/io/github/thebusybiscuit/slimefun4/api/items/groups/SubItemGroup.java index 35b5aef3d1..23f48ad407 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/api/items/groups/SubItemGroup.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/api/items/groups/SubItemGroup.java @@ -3,7 +3,7 @@ import javax.annotation.Nonnull; import javax.annotation.ParametersAreNonnullByDefault; -import org.apache.commons.lang.Validate; +import com.google.common.base.Preconditions; import org.bukkit.NamespacedKey; import org.bukkit.entity.Player; import org.bukkit.inventory.ItemStack; @@ -34,7 +34,7 @@ public SubItemGroup(NamespacedKey key, NestedItemGroup parent, ItemStack item) { public SubItemGroup(NamespacedKey key, NestedItemGroup parent, ItemStack item, int tier) { super(key, item, tier); - Validate.notNull(parent, "The parent group cannot be null"); + Preconditions.checkNotNull(parent, "The parent group cannot be null"); parentItemGroup = parent; parent.addSubGroup(this); diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/api/items/settings/DoubleRangeSetting.java b/src/main/java/io/github/thebusybiscuit/slimefun4/api/items/settings/DoubleRangeSetting.java index 3caeb974b3..e4d21d5b29 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/api/items/settings/DoubleRangeSetting.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/api/items/settings/DoubleRangeSetting.java @@ -3,7 +3,7 @@ import javax.annotation.Nonnull; import javax.annotation.ParametersAreNonnullByDefault; -import org.apache.commons.lang.Validate; +import com.google.common.base.Preconditions; import io.github.thebusybiscuit.slimefun4.api.items.ItemSetting; import io.github.thebusybiscuit.slimefun4.api.items.SlimefunItem; @@ -26,7 +26,7 @@ public class DoubleRangeSetting extends ItemSetting { @ParametersAreNonnullByDefault public DoubleRangeSetting(SlimefunItem item, String key, double min, double defaultValue, double max) { super(item, key, defaultValue); - Validate.isTrue(defaultValue >= min && defaultValue <= max, "The default value is not in range."); + Preconditions.checkArgument(defaultValue >= min && defaultValue <= max, "The default value is not in range."); this.min = min; this.max = max; diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/api/items/settings/IntRangeSetting.java b/src/main/java/io/github/thebusybiscuit/slimefun4/api/items/settings/IntRangeSetting.java index 58e5dc34bf..f548a17022 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/api/items/settings/IntRangeSetting.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/api/items/settings/IntRangeSetting.java @@ -3,7 +3,7 @@ import javax.annotation.Nonnull; import javax.annotation.ParametersAreNonnullByDefault; -import org.apache.commons.lang.Validate; +import com.google.common.base.Preconditions; import io.github.thebusybiscuit.slimefun4.api.items.ItemSetting; import io.github.thebusybiscuit.slimefun4.api.items.SlimefunItem; @@ -26,7 +26,7 @@ public class IntRangeSetting extends ItemSetting { @ParametersAreNonnullByDefault public IntRangeSetting(SlimefunItem item, String key, int min, int defaultValue, int max) { super(item, key, defaultValue); - Validate.isTrue(defaultValue >= min && defaultValue <= max, "The default value is not in range."); + Preconditions.checkArgument(defaultValue >= min && defaultValue <= max, "The default value is not in range."); this.min = min; this.max = max; 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 49fb36520e..ba96a1ed8f 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 @@ -9,7 +9,7 @@ import javax.annotation.Nonnull; import javax.annotation.Nullable; -import org.apache.commons.lang.Validate; +import com.google.common.base.Preconditions; import org.bukkit.Color; import org.bukkit.Location; import org.bukkit.Particle; @@ -68,8 +68,8 @@ public abstract class Network { * The {@link Location} marking the regulator of this {@link Network}. */ protected Network(@Nonnull NetworkManager manager, @Nonnull Location regulator) { - Validate.notNull(manager, "A NetworkManager must be provided"); - Validate.notNull(regulator, "No regulator was specified"); + Preconditions.checkNotNull(manager, "A NetworkManager must be provided"); + Preconditions.checkNotNull(regulator, "No regulator was specified"); this.manager = manager; this.regulator = regulator; @@ -131,8 +131,8 @@ public int getSize() { * The {@link Location} to add */ protected void addLocationToNetwork(@Nonnull Location l) { - Validate.notNull(l, "You cannot add a Location to a Network which is null!"); - Validate.isTrue(l.getWorld().getUID().equals(worldId), "Networks cannot exist in multiple worlds!"); + Preconditions.checkNotNull(l, "You cannot add a Location to a Network which is null!"); + Preconditions.checkArgument(l.getWorld().getUID().equals(worldId), "Networks cannot exist in multiple worlds!"); if (positions.add(BlockPosition.getAsLong(l))) { markDirty(l); @@ -163,7 +163,7 @@ public void markDirty(@Nonnull Location l) { * @return Whether the given {@link Location} is part of this {@link Network} */ public boolean connectsTo(@Nonnull Location l) { - Validate.notNull(l, "The Location cannot be null."); + Preconditions.checkNotNull(l, "The Location cannot be null."); if (this.regulator.equals(l)) { return true; diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/api/network/NetworkVisualizer.java b/src/main/java/io/github/thebusybiscuit/slimefun4/api/network/NetworkVisualizer.java index 256442972a..b1f76c0018 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/api/network/NetworkVisualizer.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/api/network/NetworkVisualizer.java @@ -2,7 +2,7 @@ import javax.annotation.Nonnull; -import org.apache.commons.lang.Validate; +import com.google.common.base.Preconditions; import org.bukkit.Color; import org.bukkit.Location; import org.bukkit.Particle.DustOptions; @@ -34,8 +34,8 @@ class NetworkVisualizer implements Runnable { * The {@link Network} to visualize */ NetworkVisualizer(@Nonnull Network network, @Nonnull Color color) { - Validate.notNull(network, "The network should not be null."); - Validate.notNull(color, "The color cannot be null."); + Preconditions.checkNotNull(network, "The network should not be null."); + Preconditions.checkNotNull(color, "The color cannot be null."); this.network = network; this.particleOptions = new DustOptions(color, 3F); diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/api/player/PlayerProfile.java b/src/main/java/io/github/thebusybiscuit/slimefun4/api/player/PlayerProfile.java index 8dfc7414f8..d6ec6a5ff7 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/api/player/PlayerProfile.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/api/player/PlayerProfile.java @@ -15,7 +15,7 @@ import javax.annotation.Nullable; import io.github.thebusybiscuit.slimefun4.storage.data.PlayerData; -import org.apache.commons.lang.Validate; +import com.google.common.base.Preconditions; import org.bukkit.Bukkit; import org.bukkit.ChatColor; import org.bukkit.NamespacedKey; @@ -150,7 +150,7 @@ public void save() { * Whether the {@link Research} should be unlocked or locked */ public void setResearched(@Nonnull Research research, boolean unlock) { - Validate.notNull(research, "Research must not be null!"); + Preconditions.checkNotNull(research, "Research must not be null!"); dirty = true; if (unlock) { @@ -364,7 +364,7 @@ public static boolean fromUUID(@Nonnull UUID uuid, @Nonnull Consumer callback) { - Validate.notNull(p, "Cannot get a PlayerProfile for: null!"); + Preconditions.checkNotNull(p, "Cannot get a PlayerProfile for: null!"); UUID uuid = p.getUniqueId(); Debug.log(TestCase.PLAYER_PROFILE_DATA, "Getting PlayerProfile for {}", uuid); @@ -422,7 +422,7 @@ public static boolean get(@Nonnull OfflinePlayer p, @Nonnull Consumer { * The callback to run when the task has completed */ PlayerResearchTask(@Nonnull Research research, boolean isInstant, @Nullable Consumer callback) { - Validate.notNull(research, "The Research must not be null"); + Preconditions.checkNotNull(research, "The Research must not be null"); this.research = research; this.isInstant = isInstant; diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/api/researches/Research.java b/src/main/java/io/github/thebusybiscuit/slimefun4/api/researches/Research.java index c4c96e4e79..8ecc46a1f4 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/api/researches/Research.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/api/researches/Research.java @@ -10,7 +10,7 @@ import javax.annotation.Nullable; import javax.annotation.ParametersAreNonnullByDefault; -import org.apache.commons.lang.Validate; +import com.google.common.base.Preconditions; import org.bukkit.Bukkit; import org.bukkit.ChatColor; import org.bukkit.GameMode; @@ -68,8 +68,8 @@ public class Research implements Keyed { * */ 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"); + Preconditions.checkNotNull(key, "A NamespacedKey must be provided"); + Preconditions.checkNotNull(defaultName, "A default name must be specified"); this.key = key; this.id = id; diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/core/SlimefunRegistry.java b/src/main/java/io/github/thebusybiscuit/slimefun4/core/SlimefunRegistry.java index bdafdc4293..f46c6259d7 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/core/SlimefunRegistry.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/core/SlimefunRegistry.java @@ -14,7 +14,7 @@ import javax.annotation.Nonnull; -import org.apache.commons.lang.Validate; +import com.google.common.base.Preconditions; import org.bukkit.NamespacedKey; import org.bukkit.Server; import org.bukkit.entity.Entity; @@ -94,8 +94,8 @@ public final class SlimefunRegistry { private final Map, Set> globalItemHandlers = new HashMap<>(); public void load(@Nonnull Slimefun plugin, @Nonnull Config cfg) { - Validate.notNull(plugin, "The Plugin cannot be null!"); - Validate.notNull(cfg, "The Config cannot be null!"); + Preconditions.checkNotNull(plugin, "The Plugin cannot be null!"); + Preconditions.checkNotNull(cfg, "The Config cannot be null!"); soulboundKey = new NamespacedKey(plugin, "soulbound"); itemChargeKey = new NamespacedKey(plugin, "item_charge"); @@ -249,7 +249,7 @@ public List getMultiBlocks() { */ @Nonnull public SlimefunGuideImplementation getSlimefunGuide(@Nonnull SlimefunGuideMode mode) { - Validate.notNull(mode, "The Guide mode cannot be null"); + Preconditions.checkNotNull(mode, "The Guide mode cannot be null"); SlimefunGuideImplementation guide = guides.get(mode); @@ -319,7 +319,7 @@ public Map, Set> getGlobalItemHandlers @Nonnull public Set getGlobalItemHandlers(@Nonnull Class identifier) { - Validate.notNull(identifier, "The identifier for an ItemHandler cannot be null!"); + Preconditions.checkNotNull(identifier, "The identifier for an ItemHandler cannot be null!"); return globalItemHandlers.computeIfAbsent(identifier, c -> new HashSet<>()); } 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 64a9063ec3..d114906153 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 @@ -4,7 +4,7 @@ import javax.annotation.Nonnull; -import org.apache.commons.lang.Validate; +import com.google.common.base.Preconditions; import org.bukkit.Location; import io.github.bakedlibs.dough.blocks.BlockPosition; @@ -92,8 +92,8 @@ default int getCharge(@Nonnull Location l) { * @return The charge stored at that {@link Location} */ default int getCharge(@Nonnull Location l, @Nonnull Config data) { - Validate.notNull(l, "Location was null!"); - Validate.notNull(data, "data was null!"); + Preconditions.checkNotNull(l, "Location was null!"); + Preconditions.checkNotNull(data, "data was null!"); // Emergency fallback, this cannot hold a charge, so we'll just return zero if (!isChargeable()) { @@ -120,8 +120,8 @@ default int getCharge(@Nonnull Location l, @Nonnull Config data) { * The new 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!"); + Preconditions.checkNotNull(l, "Location was null!"); + Preconditions.checkArgument(charge >= 0, "You can only set a charge of zero or more!"); try { int capacity = getCapacity(); @@ -146,8 +146,8 @@ default void setCharge(@Nonnull 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!"); + Preconditions.checkNotNull(l, "Location was null!"); + Preconditions.checkArgument(charge > 0, "You can only add a positive charge!"); try { int capacity = getCapacity(); @@ -173,8 +173,8 @@ default void addCharge(@Nonnull 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!"); + Preconditions.checkNotNull(l, "Location was null!"); + Preconditions.checkArgument(charge > 0, "The charge to remove must be greater than zero!"); try { int capacity = getCapacity(); diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/core/attributes/Rechargeable.java b/src/main/java/io/github/thebusybiscuit/slimefun4/core/attributes/Rechargeable.java index e76348c62f..e160a17a64 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/core/attributes/Rechargeable.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/core/attributes/Rechargeable.java @@ -1,6 +1,6 @@ package io.github.thebusybiscuit.slimefun4.core.attributes; -import org.apache.commons.lang.Validate; +import com.google.common.base.Preconditions; import org.bukkit.Material; import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.meta.ItemMeta; @@ -91,7 +91,7 @@ default float getItemCharge(ItemStack item) { * @return Whether the given charge could be added successfully */ default boolean addItemCharge(ItemStack item, float charge) { - Validate.isTrue(charge > 0, "Charge must be above zero!"); + Preconditions.checkArgument(charge > 0, "Charge must be above zero!"); if (item == null || item.getType() == Material.AIR) { throw new IllegalArgumentException("Cannot add Item charge for null or AIR"); @@ -126,7 +126,7 @@ default boolean addItemCharge(ItemStack item, float charge) { * @return Whether the given charge could be removed successfully */ default boolean removeItemCharge(ItemStack item, float charge) { - Validate.isTrue(charge > 0, "Charge must be above zero!"); + Preconditions.checkArgument(charge > 0, "Charge must be above zero!"); if (item == null || item.getType() == Material.AIR) { throw new IllegalArgumentException("Cannot remove Item charge for null or AIR"); 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 4ef1a411a5..1f298741db 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 @@ -8,7 +8,7 @@ import javax.annotation.Nonnull; -import org.apache.commons.lang.Validate; +import com.google.common.base.Preconditions; import org.bukkit.command.Command; import org.bukkit.command.CommandExecutor; import org.bukkit.command.CommandSender; @@ -44,7 +44,7 @@ public SlimefunCommand(@Nonnull Slimefun plugin) { } public void register() { - Validate.isTrue(!registered, "Slimefun's subcommands have already been registered!"); + Preconditions.checkArgument(!registered, "Slimefun's subcommands have already been registered!"); registered = true; plugin.getServer().getPluginManager().registerEvents(this, plugin); 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 d84adcfee2..1dfa75ed33 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 @@ -6,7 +6,7 @@ import javax.annotation.Nonnull; import javax.annotation.Nullable; -import org.apache.commons.lang.Validate; +import com.google.common.base.Preconditions; import org.bukkit.entity.Player; import org.bukkit.inventory.ItemStack; @@ -37,7 +37,7 @@ public class GuideHistory { * The {@link PlayerProfile} this {@link GuideHistory} was made for */ public GuideHistory(@Nonnull PlayerProfile profile) { - Validate.notNull(profile, "Cannot create a GuideHistory without a PlayerProfile!"); + Preconditions.checkNotNull(profile, "Cannot create a GuideHistory without a PlayerProfile!"); this.profile = profile; } @@ -55,7 +55,7 @@ public void clear() { * The current page of the main menu that should be stored */ public void setMainMenuPage(int page) { - Validate.isTrue(page >= 1, "page must be greater than 0!"); + Preconditions.checkArgument(page >= 1, "page must be greater than 0!"); mainMenuPage = page; } @@ -104,7 +104,7 @@ public void add(@Nonnull ItemStack item, int page) { * The {@link SlimefunItem} that should be added to this {@link GuideHistory} */ public void add(@Nonnull SlimefunItem item) { - Validate.notNull(item, "Cannot add a non-existing SlimefunItem to the GuideHistory!"); + Preconditions.checkNotNull(item, "Cannot add a non-existing SlimefunItem to the GuideHistory!"); queue.add(new GuideEntry<>(item, 0)); } @@ -115,13 +115,13 @@ public void add(@Nonnull SlimefunItem item) { * The term that the {@link Player} searched for */ public void add(@Nonnull String searchTerm) { - Validate.notNull(searchTerm, "Cannot add an empty Search Term to the GuideHistory!"); + Preconditions.checkNotNull(searchTerm, "Cannot add an empty Search Term to the GuideHistory!"); queue.add(new GuideEntry<>(searchTerm, 0)); } 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!"); + Preconditions.checkNotNull(object, "Cannot add a null Entry to the GuideHistory!"); + Preconditions.checkArgument(page >= 0, "page must not be negative!"); GuideEntry lastEntry = getLastEntry(false); diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/core/handlers/RainbowTickHandler.java b/src/main/java/io/github/thebusybiscuit/slimefun4/core/handlers/RainbowTickHandler.java index 6fa656f6d0..7efc6e5d34 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/core/handlers/RainbowTickHandler.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/core/handlers/RainbowTickHandler.java @@ -2,10 +2,11 @@ import java.util.Arrays; import java.util.List; +import java.util.Objects; import javax.annotation.Nonnull; -import org.apache.commons.lang.Validate; +import com.google.common.base.Preconditions; import org.bukkit.Material; import org.bukkit.block.Block; import org.bukkit.block.BlockFace; @@ -39,7 +40,7 @@ public class RainbowTickHandler extends BlockTicker { private Material material; public RainbowTickHandler(@Nonnull List materials) { - Validate.noNullElements(materials, "A RainbowTicker cannot have a Material that is null!"); + Preconditions.checkArgument(materials.stream().noneMatch(Objects::isNull), "A RainbowTicker cannot have a Material that is null!"); if (materials.isEmpty()) { throw new IllegalArgumentException("A RainbowTicker must have at least one Material associated with it!"); diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/core/machines/MachineProcessor.java b/src/main/java/io/github/thebusybiscuit/slimefun4/core/machines/MachineProcessor.java index 9ec92b578a..3fd78f6772 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/core/machines/MachineProcessor.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/core/machines/MachineProcessor.java @@ -6,7 +6,7 @@ import javax.annotation.Nonnull; import javax.annotation.Nullable; -import org.apache.commons.lang.Validate; +import com.google.common.base.Preconditions; import org.bukkit.Bukkit; import org.bukkit.Location; import org.bukkit.block.Block; @@ -46,7 +46,7 @@ public class MachineProcessor { * The owner of this {@link MachineProcessor}. */ public MachineProcessor(@Nonnull MachineProcessHolder owner) { - Validate.notNull(owner, "The MachineProcessHolder cannot be null."); + Preconditions.checkNotNull(owner, "The MachineProcessHolder cannot be null."); this.owner = owner; } @@ -93,8 +93,8 @@ public void setProgressBar(@Nullable ItemStack progressBar) { * {@link MachineOperation} has already been started at that {@link Location}. */ public boolean startOperation(@Nonnull Location loc, @Nonnull T operation) { - Validate.notNull(loc, "The location must not be null"); - Validate.notNull(operation, "The operation cannot be null"); + Preconditions.checkNotNull(loc, "The location must not be null"); + Preconditions.checkNotNull(operation, "The operation cannot be null"); return startOperation(new BlockPosition(loc), operation); } @@ -111,8 +111,8 @@ public boolean startOperation(@Nonnull Location loc, @Nonnull T operation) { * {@link MachineOperation} has already been started at that {@link Block}. */ public boolean startOperation(@Nonnull Block b, @Nonnull T operation) { - Validate.notNull(b, "The Block must not be null"); - Validate.notNull(operation, "The machine operation cannot be null"); + Preconditions.checkNotNull(b, "The Block must not be null"); + Preconditions.checkNotNull(operation, "The machine operation cannot be null"); return startOperation(new BlockPosition(b), operation); } @@ -129,8 +129,8 @@ public boolean startOperation(@Nonnull Block b, @Nonnull T operation) { * {@link MachineOperation} has already been started at that {@link BlockPosition}. */ public boolean startOperation(@Nonnull BlockPosition pos, @Nonnull T operation) { - Validate.notNull(pos, "The BlockPosition must not be null"); - Validate.notNull(operation, "The machine operation cannot be null"); + Preconditions.checkNotNull(pos, "The BlockPosition must not be null"); + Preconditions.checkNotNull(operation, "The machine operation cannot be null"); return machines.putIfAbsent(pos, operation) == null; } @@ -144,7 +144,7 @@ public boolean startOperation(@Nonnull BlockPosition pos, @Nonnull T operation) * @return The current {@link MachineOperation} or null. */ public @Nullable T getOperation(@Nonnull Location loc) { - Validate.notNull(loc, "The location cannot be null"); + Preconditions.checkNotNull(loc, "The location cannot be null"); return getOperation(new BlockPosition(loc)); } @@ -158,7 +158,7 @@ public boolean startOperation(@Nonnull BlockPosition pos, @Nonnull T operation) * @return The current {@link MachineOperation} or null. */ public @Nullable T getOperation(@Nonnull Block b) { - Validate.notNull(b, "The Block cannot be null"); + Preconditions.checkNotNull(b, "The Block cannot be null"); return getOperation(new BlockPosition(b)); } @@ -172,7 +172,7 @@ public boolean startOperation(@Nonnull BlockPosition pos, @Nonnull T operation) * @return The current {@link MachineOperation} or null. */ public @Nullable T getOperation(@Nonnull BlockPosition pos) { - Validate.notNull(pos, "The BlockPosition must not be null"); + Preconditions.checkNotNull(pos, "The BlockPosition must not be null"); return machines.get(pos); } @@ -187,7 +187,7 @@ public boolean startOperation(@Nonnull BlockPosition pos, @Nonnull T operation) * {@link MachineOperation} to begin with. */ public boolean endOperation(@Nonnull Location loc) { - Validate.notNull(loc, "The location should not be null"); + Preconditions.checkNotNull(loc, "The location should not be null"); return endOperation(new BlockPosition(loc)); } @@ -202,7 +202,7 @@ public boolean endOperation(@Nonnull Location loc) { * {@link MachineOperation} to begin with. */ public boolean endOperation(@Nonnull Block b) { - Validate.notNull(b, "The Block should not be null"); + Preconditions.checkNotNull(b, "The Block should not be null"); return endOperation(new BlockPosition(b)); } @@ -217,7 +217,7 @@ public boolean endOperation(@Nonnull Block b) { * {@link MachineOperation} to begin with. */ public boolean endOperation(@Nonnull BlockPosition pos) { - Validate.notNull(pos, "The BlockPosition cannot be null"); + Preconditions.checkNotNull(pos, "The BlockPosition cannot be null"); T operation = machines.remove(pos); @@ -240,8 +240,8 @@ public boolean endOperation(@Nonnull BlockPosition pos) { } public void updateProgressBar(@Nonnull BlockMenu inv, int slot, @Nonnull T operation) { - Validate.notNull(inv, "The inventory must not be null."); - Validate.notNull(operation, "The MachineOperation must not be null."); + Preconditions.checkNotNull(inv, "The inventory must not be null."); + Preconditions.checkNotNull(operation, "The MachineOperation must not be null."); if (getProgressBar() == null) { // No progress bar, no need to update anything. diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/core/multiblocks/MultiBlock.java b/src/main/java/io/github/thebusybiscuit/slimefun4/core/multiblocks/MultiBlock.java index 4175b20527..810e5916b3 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/core/multiblocks/MultiBlock.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/core/multiblocks/MultiBlock.java @@ -8,7 +8,7 @@ import javax.annotation.Nonnull; import javax.annotation.Nullable; -import org.apache.commons.lang.Validate; +import com.google.common.base.Preconditions; import org.bukkit.Material; import org.bukkit.Tag; import org.bukkit.World; @@ -55,7 +55,7 @@ public static Set> getSupportedTags() { private final boolean isSymmetric; public MultiBlock(@Nonnull SlimefunItem item, Material[] build, @Nonnull BlockFace trigger) { - Validate.notNull(item, "A MultiBlock requires a SlimefunItem!"); + Preconditions.checkNotNull(item, "A MultiBlock requires a SlimefunItem!"); if (build == null || build.length != 9) { throw new IllegalArgumentException("MultiBlocks must have a length of 9!"); diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/core/multiblocks/MultiBlockMachine.java b/src/main/java/io/github/thebusybiscuit/slimefun4/core/multiblocks/MultiBlockMachine.java index d18f6ba2cd..caf20fb18b 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/core/multiblocks/MultiBlockMachine.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/core/multiblocks/MultiBlockMachine.java @@ -11,8 +11,6 @@ import com.google.common.base.Preconditions; -import org.apache.commons.lang.Validate; - import org.bukkit.Material; import org.bukkit.World; import org.bukkit.block.Block; @@ -87,7 +85,7 @@ protected void registerDefaultRecipes(@Nonnull List recipes) { } public void addRecipe(ItemStack[] input, ItemStack output) { - Validate.notNull(output, "Recipes must have an Output!"); + Preconditions.checkNotNull(output, "Recipes must have an Output!"); recipes.add(input); recipes.add(new ItemStack[] { output }); 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 14d88e121d..044eb86b33 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 @@ -10,7 +10,7 @@ import javax.annotation.Nonnull; import javax.annotation.Nullable; -import org.apache.commons.lang.Validate; +import com.google.common.base.Preconditions; import org.bukkit.Location; import org.bukkit.Server; @@ -62,7 +62,7 @@ public class NetworkManager { * Whether excess items from a {@link CargoNet} should be voided */ public NetworkManager(int maxStepSize, boolean enableVisualizer, boolean deleteExcessItems) { - Validate.isTrue(maxStepSize > 0, "The maximal Network size must be above zero!"); + Preconditions.checkArgument(maxStepSize > 0, "The maximal Network size must be above zero!"); this.enableVisualizer = enableVisualizer; this.deleteExcessItems = deleteExcessItems; @@ -125,7 +125,7 @@ public Optional getNetworkFromLocation(@Nullable Location return Optional.empty(); } - Validate.notNull(type, "Type must not be null"); + Preconditions.checkNotNull(type, "Type must not be null"); for (Network network : networks) { if (type.isInstance(network) && network.connectsTo(l)) { @@ -143,7 +143,7 @@ public List getNetworksFromLocation(@Nullable Location l, return new ArrayList<>(); } - Validate.notNull(type, "Type must not be null"); + Preconditions.checkNotNull(type, "Type must not be null"); List list = new ArrayList<>(); for (Network network : networks) { @@ -162,7 +162,7 @@ public List getNetworksFromLocation(@Nullable Location l, * The {@link Network} to register */ public void registerNetwork(@Nonnull Network network) { - Validate.notNull(network, "Cannot register a null Network"); + Preconditions.checkNotNull(network, "Cannot register a null Network"); networks.add(network); } @@ -173,7 +173,7 @@ public void registerNetwork(@Nonnull Network network) { * The {@link Network} to remove */ public void unregisterNetwork(@Nonnull Network network) { - Validate.notNull(network, "Cannot unregister a null Network"); + Preconditions.checkNotNull(network, "Cannot unregister a null Network"); networks.remove(network); } @@ -185,7 +185,7 @@ public void unregisterNetwork(@Nonnull Network network) { * The {@link Location} to update */ public void updateAllNetworks(@Nonnull Location l) { - Validate.notNull(l, "The Location cannot be null"); + Preconditions.checkNotNull(l, "The Location cannot be null"); try { /* diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/core/networks/cargo/ItemStackAndInteger.java b/src/main/java/io/github/thebusybiscuit/slimefun4/core/networks/cargo/ItemStackAndInteger.java index d149efdc79..79392ea17e 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/core/networks/cargo/ItemStackAndInteger.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/core/networks/cargo/ItemStackAndInteger.java @@ -2,7 +2,7 @@ import javax.annotation.Nonnull; -import org.apache.commons.lang.Validate; +import com.google.common.base.Preconditions; import org.bukkit.inventory.ItemStack; import io.github.thebusybiscuit.slimefun4.utils.itemstack.ItemStackWrapper; @@ -14,7 +14,7 @@ class ItemStackAndInteger { private int number; ItemStackAndInteger(@Nonnull ItemStack item, int amount) { - Validate.notNull(item, "Item cannot be null!"); + Preconditions.checkNotNull(item, "Item cannot be null!"); this.number = amount; this.item = item; } diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/core/services/BackupService.java b/src/main/java/io/github/thebusybiscuit/slimefun4/core/services/BackupService.java index 80ce5b999b..23de245feb 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/core/services/BackupService.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/core/services/BackupService.java @@ -17,7 +17,7 @@ import javax.annotation.Nonnull; -import org.apache.commons.lang.Validate; +import com.google.common.base.Preconditions; import io.github.thebusybiscuit.slimefun4.implementation.Slimefun; @@ -79,7 +79,7 @@ public void run() { } private void createBackup(@Nonnull ZipOutputStream output) throws IOException { - Validate.notNull(output, "The Output Stream cannot be null!"); + Preconditions.checkNotNull(output, "The Output Stream cannot be null!"); for (File folder : new File("data-storage/Slimefun/stored-blocks/").listFiles()) { addDirectory(output, folder, "stored-blocks/" + folder.getName()); diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/core/services/BlockDataService.java b/src/main/java/io/github/thebusybiscuit/slimefun4/core/services/BlockDataService.java index 69c9579286..7c6cf5c9b9 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/core/services/BlockDataService.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/core/services/BlockDataService.java @@ -7,7 +7,7 @@ import javax.annotation.Nullable; import io.github.thebusybiscuit.slimefun4.utils.tags.SlimefunTag; -import org.apache.commons.lang.Validate; +import com.google.common.base.Preconditions; import org.bukkit.Bukkit; import org.bukkit.Keyed; import org.bukkit.Material; @@ -64,8 +64,8 @@ public NamespacedKey getKey() { * The value to store */ public void setBlockData(@Nonnull Block b, @Nonnull String value) { - Validate.notNull(b, "The block cannot be null!"); - Validate.notNull(value, "The value cannot be null!"); + Preconditions.checkNotNull(b, "The block cannot be null!"); + Preconditions.checkNotNull(value, "The value cannot be null!"); /** * Don't use PaperLib here, it seems to be quite buggy in block-placing scenarios @@ -98,7 +98,7 @@ public void setBlockData(@Nonnull Block b, @Nonnull String value) { * @return The stored value */ public Optional getBlockData(@Nonnull Block b) { - Validate.notNull(b, "The block cannot be null!"); + Preconditions.checkNotNull(b, "The block cannot be null!"); BlockState state = PaperLib.getBlockState(b, false).getState(); PersistentDataContainer container = getPersistentDataContainer(state); diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/core/services/CustomItemDataService.java b/src/main/java/io/github/thebusybiscuit/slimefun4/core/services/CustomItemDataService.java index e9617b7eec..988f18826f 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/core/services/CustomItemDataService.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/core/services/CustomItemDataService.java @@ -5,7 +5,7 @@ import javax.annotation.Nonnull; import javax.annotation.Nullable; -import org.apache.commons.lang.Validate; +import com.google.common.base.Preconditions; import org.bukkit.Keyed; import org.bukkit.Material; import org.bukkit.NamespacedKey; @@ -64,8 +64,8 @@ public NamespacedKey getKey() { * The id to store on the {@link ItemStack} */ public void setItemData(@Nonnull ItemStack item, @Nonnull String id) { - Validate.notNull(item, "The Item cannot be null!"); - Validate.notNull(id, "Cannot store null on an Item!"); + Preconditions.checkNotNull(item, "The Item cannot be null!"); + Preconditions.checkNotNull(id, "Cannot store null on an Item!"); ItemMeta im = item.getItemMeta(); setItemData(im, id); @@ -82,8 +82,8 @@ public void setItemData(@Nonnull ItemStack item, @Nonnull String id) { * The id to store on the {@link ItemMeta} */ public void setItemData(@Nonnull ItemMeta meta, @Nonnull String id) { - Validate.notNull(meta, "The ItemMeta cannot be null!"); - Validate.notNull(id, "Cannot store null on an ItemMeta!"); + Preconditions.checkNotNull(meta, "The ItemMeta cannot be null!"); + Preconditions.checkNotNull(id, "Cannot store null on an ItemMeta!"); PersistentDataContainer container = meta.getPersistentDataContainer(); container.set(namespacedKey, PersistentDataType.STRING, id); @@ -117,7 +117,7 @@ public void setItemData(@Nonnull ItemMeta meta, @Nonnull String id) { * @return An {@link Optional} describing the result */ public @Nonnull Optional getItemData(@Nonnull ItemMeta meta) { - Validate.notNull(meta, "Cannot read data from null!"); + Preconditions.checkNotNull(meta, "Cannot read data from null!"); PersistentDataContainer container = meta.getPersistentDataContainer(); return Optional.ofNullable(container.get(namespacedKey, PersistentDataType.STRING)); @@ -136,8 +136,8 @@ public void setItemData(@Nonnull ItemMeta meta, @Nonnull String id) { * @return Whether both metas have data on them and its the same. */ public boolean hasEqualItemData(@Nonnull ItemMeta meta1, @Nonnull ItemMeta meta2) { - Validate.notNull(meta1, "Cannot read data from null (first arg)"); - Validate.notNull(meta2, "Cannot read data from null (second arg)"); + Preconditions.checkNotNull(meta1, "Cannot read data from null (first arg)"); + Preconditions.checkNotNull(meta2, "Cannot read data from null (second arg)"); Optional data1 = getItemData(meta1); diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/core/services/CustomTextureService.java b/src/main/java/io/github/thebusybiscuit/slimefun4/core/services/CustomTextureService.java index 7c84a1de2a..9c642dd403 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/core/services/CustomTextureService.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/core/services/CustomTextureService.java @@ -10,7 +10,7 @@ import javax.annotation.Nonnull; import javax.annotation.Nullable; -import org.apache.commons.lang.Validate; +import com.google.common.base.Preconditions; import org.bukkit.configuration.file.FileConfiguration; import org.bukkit.configuration.file.YamlConfiguration; import org.bukkit.inventory.ItemStack; @@ -71,7 +71,7 @@ public CustomTextureService(@Nonnull Config config) { * Whether to save this file */ public void register(@Nonnull Collection items, boolean save) { - Validate.notEmpty(items, "items must neither be null or empty."); + Preconditions.checkArgument(!items.isEmpty(), "items must neither be null or empty."); loadDefaultValues(); @@ -130,7 +130,7 @@ public boolean isActive() { * @return The configured custom model data */ public int getModelData(@Nonnull String id) { - Validate.notNull(id, "Cannot get the ModelData for 'null'"); + Preconditions.checkNotNull(id, "Cannot get the ModelData for 'null'"); return config.getInt(id); } @@ -145,8 +145,8 @@ public int getModelData(@Nonnull String id) { * The id for which to get the configured model data */ public void setTexture(@Nonnull ItemStack item, @Nonnull String id) { - Validate.notNull(item, "The Item cannot be null!"); - Validate.notNull(id, "Cannot store null on an Item!"); + Preconditions.checkNotNull(item, "The Item cannot be null!"); + Preconditions.checkNotNull(id, "Cannot store null on an Item!"); ItemMeta im = item.getItemMeta(); setTexture(im, id); @@ -163,8 +163,8 @@ public void setTexture(@Nonnull ItemStack item, @Nonnull String id) { * The id for which to get the configured model data */ public void setTexture(@Nonnull ItemMeta im, @Nonnull String id) { - Validate.notNull(im, "The ItemMeta cannot be null!"); - Validate.notNull(id, "Cannot store null on an ItemMeta!"); + Preconditions.checkNotNull(im, "The ItemMeta cannot be null!"); + Preconditions.checkNotNull(id, "Cannot store null on an ItemMeta!"); int data = getModelData(id); im.setCustomModelData(data == 0 ? null : data); diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/core/services/LocalizationService.java b/src/main/java/io/github/thebusybiscuit/slimefun4/core/services/LocalizationService.java index 39b533335a..1260ebfd35 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/core/services/LocalizationService.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/core/services/LocalizationService.java @@ -16,7 +16,7 @@ import javax.annotation.Nullable; import javax.annotation.ParametersAreNonnullByDefault; -import org.apache.commons.lang.Validate; +import com.google.common.base.Preconditions; import org.bukkit.NamespacedKey; import org.bukkit.Server; import org.bukkit.configuration.InvalidConfigurationException; @@ -113,7 +113,7 @@ public NamespacedKey getKey() { @Override @Nullable public Language getLanguage(@Nonnull String id) { - Validate.notNull(id, "The language id cannot be null"); + Preconditions.checkNotNull(id, "The language id cannot be null"); return languages.get(id); } @@ -125,7 +125,7 @@ public Collection getLanguages() { @Override public boolean hasLanguage(@Nonnull String id) { - Validate.notNull(id, "The language id cannot be null"); + Preconditions.checkNotNull(id, "The language id cannot be null"); // Checks if our jar files contains a messages.yml file for that language String file = LanguageFile.MESSAGES.getFilePath(id); @@ -141,7 +141,7 @@ public boolean hasLanguage(@Nonnull String id) { * @return Whether or not this {@link Language} is loaded */ public boolean isLanguageLoaded(@Nonnull String id) { - Validate.notNull(id, "The language cannot be null!"); + Preconditions.checkNotNull(id, "The language cannot be null!"); return languages.containsKey(id); } @@ -152,7 +152,7 @@ public Language getDefaultLanguage() { @Override public Language getLanguage(@Nonnull Player p) { - Validate.notNull(p, "Player cannot be null!"); + Preconditions.checkNotNull(p, "Player cannot be null!"); PersistentDataContainer container = p.getPersistentDataContainer(); String language = container.get(languageKey, PersistentDataType.STRING); @@ -205,8 +205,8 @@ private void copyToDefaultLanguage(String language, LanguageFile file) { @Override protected void addLanguage(@Nonnull String id, @Nonnull String texture) { - Validate.notNull(id, "The language id cannot be null!"); - Validate.notNull(texture, "The language texture cannot be null"); + Preconditions.checkNotNull(id, "The language id cannot be null!"); + Preconditions.checkNotNull(texture, "The language texture cannot be null"); if (hasLanguage(id)) { Language language = new Language(id, texture); @@ -232,7 +232,7 @@ protected void addLanguage(@Nonnull String id, @Nonnull String texture) { * @return A percentage {@code (0.0 - 100.0)} for the progress of translation of that {@link Language} */ public double calculateProgress(@Nonnull Language lang) { - Validate.notNull(lang, "Cannot get the language progress of null"); + Preconditions.checkNotNull(lang, "Cannot get the language progress of null"); Set defaultKeys = getTotalKeys(languages.get("en")); diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/core/services/MinecraftRecipeService.java b/src/main/java/io/github/thebusybiscuit/slimefun4/core/services/MinecraftRecipeService.java index c9137ed242..9f71b608da 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/core/services/MinecraftRecipeService.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/core/services/MinecraftRecipeService.java @@ -10,7 +10,7 @@ import javax.annotation.Nonnull; import javax.annotation.Nullable; -import org.apache.commons.lang.Validate; +import com.google.common.base.Preconditions; import org.bukkit.Bukkit; import org.bukkit.Keyed; import org.bukkit.NamespacedKey; @@ -86,7 +86,7 @@ public void refresh() { * A callback to run when the {@link RecipeSnapshot} has been created. */ public void subscribe(@Nonnull Consumer subscription) { - Validate.notNull(subscription, "Callback must not be null!"); + Preconditions.checkNotNull(subscription, "Callback must not be null!"); subscriptions.add(subscription); } @@ -132,7 +132,7 @@ public boolean isSmeltable(@Nullable ItemStack input) { * @return An Array of {@link RecipeChoice} representing the shape of this {@link Recipe} */ public @Nonnull RecipeChoice[] getRecipeShape(@Nonnull Recipe recipe) { - Validate.notNull(recipe, "Recipe must not be null!"); + Preconditions.checkNotNull(recipe, "Recipe must not be null!"); if (recipe instanceof ShapedRecipe shapedRecipe) { List choices = new LinkedList<>(); @@ -185,7 +185,7 @@ public boolean isSmeltable(@Nullable ItemStack input) { * @return The corresponding {@link Recipe} or null */ public @Nullable Recipe getRecipe(@Nonnull NamespacedKey key) { - Validate.notNull(key, "The NamespacedKey should not be null"); + Preconditions.checkNotNull(key, "The NamespacedKey should not be null"); if (snapshot != null) { // We operate on a cached HashMap which is much faster than Bukkit's method. diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/core/services/PerWorldSettingsService.java b/src/main/java/io/github/thebusybiscuit/slimefun4/core/services/PerWorldSettingsService.java index a0dc615d30..4b90e8e61e 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/core/services/PerWorldSettingsService.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/core/services/PerWorldSettingsService.java @@ -13,7 +13,7 @@ import javax.annotation.Nonnull; -import org.apache.commons.lang.Validate; +import com.google.common.base.Preconditions; import org.bukkit.Server; import org.bukkit.World; @@ -61,7 +61,7 @@ public void load(@Nonnull Iterable worlds) { * The {@link World} to load */ public void load(@Nonnull World world) { - Validate.notNull(world, "Cannot load a world that is null"); + Preconditions.checkNotNull(world, "Cannot load a world that is null"); disabledItems.putIfAbsent(world.getUID(), loadWorldFromConfig(world)); } @@ -76,8 +76,8 @@ public void load(@Nonnull World world) { * @return Whether the given {@link SlimefunItem} is enabled in that {@link World} */ public boolean isEnabled(@Nonnull World world, @Nonnull SlimefunItem item) { - Validate.notNull(world, "The world cannot be null"); - Validate.notNull(item, "The SlimefunItem cannot be null"); + Preconditions.checkNotNull(world, "The world cannot be null"); + Preconditions.checkNotNull(item, "The SlimefunItem cannot be null"); Set items = disabledItems.computeIfAbsent(world.getUID(), id -> loadWorldFromConfig(world)); @@ -99,8 +99,8 @@ public boolean isEnabled(@Nonnull World world, @Nonnull SlimefunItem item) { * Whether the given {@link SlimefunItem} should be enabled in that world */ public void setEnabled(@Nonnull World world, @Nonnull SlimefunItem item, boolean enabled) { - Validate.notNull(world, "The world cannot be null"); - Validate.notNull(item, "The SlimefunItem cannot be null"); + Preconditions.checkNotNull(world, "The world cannot be null"); + Preconditions.checkNotNull(item, "The SlimefunItem cannot be null"); Set items = disabledItems.computeIfAbsent(world.getUID(), id -> loadWorldFromConfig(world)); @@ -120,7 +120,7 @@ public void setEnabled(@Nonnull World world, @Nonnull SlimefunItem item, boolean * Whether this {@link World} should be enabled or not */ public void setEnabled(@Nonnull World world, boolean enabled) { - Validate.notNull(world, "null is not a valid World"); + Preconditions.checkNotNull(world, "null is not a valid World"); load(world); if (enabled) { @@ -139,7 +139,7 @@ public void setEnabled(@Nonnull World world, boolean enabled) { * @return Whether this {@link World} is enabled */ public boolean isWorldEnabled(@Nonnull World world) { - Validate.notNull(world, "null is not a valid World"); + Preconditions.checkNotNull(world, "null is not a valid World"); load(world); return !disabledWorlds.contains(world.getUID()); @@ -156,8 +156,8 @@ public boolean isWorldEnabled(@Nonnull World world) { * @return Whether this addon is enabled in that {@link World} */ public boolean isAddonEnabled(@Nonnull World world, @Nonnull SlimefunAddon addon) { - Validate.notNull(world, "World cannot be null"); - Validate.notNull(addon, "Addon cannot be null"); + Preconditions.checkNotNull(world, "World cannot be null"); + Preconditions.checkNotNull(addon, "Addon cannot be null"); return isWorldEnabled(world) && disabledAddons.getOrDefault(addon, Collections.emptySet()).contains(world.getName()); } @@ -170,7 +170,7 @@ public boolean isAddonEnabled(@Nonnull World world, @Nonnull SlimefunAddon addon * The {@link World} to save */ public void save(@Nonnull World world) { - Validate.notNull(world, "Cannot save a World that does not exist"); + Preconditions.checkNotNull(world, "Cannot save a World that does not exist"); Set items = disabledItems.computeIfAbsent(world.getUID(), id -> loadWorldFromConfig(world)); Config config = getConfig(world); @@ -187,7 +187,7 @@ public void save(@Nonnull World world) { @Nonnull private Set loadWorldFromConfig(@Nonnull World world) { - Validate.notNull(world, "Cannot load a World that does not exist"); + Preconditions.checkNotNull(world, "Cannot load a World that does not exist"); String name = world.getName(); Optional> optional = disabledItems.get(world.getUID()); @@ -249,7 +249,7 @@ private void loadItemsFromWorldConfig(@Nonnull String worldName, @Nonnull Config */ @Nonnull private Config getConfig(@Nonnull World world) { - Validate.notNull(world, "World cannot be null"); + Preconditions.checkNotNull(world, "World cannot be null"); return new Config(plugin, "world-settings/" + world.getName() + ".yml"); } diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/core/services/PermissionsService.java b/src/main/java/io/github/thebusybiscuit/slimefun4/core/services/PermissionsService.java index de92df6d87..e2aafe4534 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/core/services/PermissionsService.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/core/services/PermissionsService.java @@ -10,7 +10,7 @@ import javax.annotation.Nonnull; import javax.annotation.Nullable; -import org.apache.commons.lang.Validate; +import com.google.common.base.Preconditions; import org.bukkit.entity.Player; import org.bukkit.permissions.Permissible; import org.bukkit.permissions.Permission; @@ -107,7 +107,7 @@ public boolean hasPermission(Permissible p, SlimefunItem item) { */ @Nonnull public Optional getPermission(@Nonnull SlimefunItem item) { - Validate.notNull(item, "Cannot get permissions for null"); + Preconditions.checkNotNull(item, "Cannot get permissions for null"); String permission = permissions.get(item.getId()); if (permission == null || permission.equals("none")) { @@ -126,7 +126,7 @@ public Optional getPermission(@Nonnull SlimefunItem item) { * The {@link Permission} to set */ public void setPermission(@Nonnull SlimefunItem item, @Nullable String permission) { - Validate.notNull(item, "You cannot set the permission for null"); + Preconditions.checkNotNull(item, "You cannot set the permission for null"); permissions.put(item.getId(), permission != null ? permission : "none"); } 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 03173056bd..6b868e1028 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 @@ -12,7 +12,7 @@ import javax.annotation.Nonnull; import javax.annotation.Nullable; -import org.apache.commons.lang.Validate; +import com.google.common.base.Preconditions; import org.bukkit.ChatColor; import io.github.bakedlibs.dough.data.TriStateOptional; @@ -48,8 +48,8 @@ public class Contributor { * A link to their GitHub profile */ public Contributor(@Nonnull String minecraftName, @Nonnull String profile) { - Validate.notNull(minecraftName, "Username must never be null!"); - Validate.notNull(profile, "The profile cannot be null!"); + Preconditions.checkNotNull(minecraftName, "Username must never be null!"); + Preconditions.checkNotNull(profile, "The profile cannot be null!"); githubUsername = profile.substring(profile.lastIndexOf('/') + 1); minecraftUsername = minecraftName; @@ -63,7 +63,7 @@ public Contributor(@Nonnull String minecraftName, @Nonnull String profile) { * The username of this {@link Contributor} */ public Contributor(@Nonnull String username) { - Validate.notNull(username, "Username must never be null!"); + Preconditions.checkNotNull(username, "Username must never be null!"); githubUsername = username; minecraftUsername = username; @@ -80,8 +80,8 @@ public Contributor(@Nonnull String username) { * The amount of contributions made as that role */ public void setContributions(@Nonnull String role, int commits) { - Validate.notNull(role, "The role cannot be null!"); - Validate.isTrue(commits >= 0, "Contributions cannot be negative"); + Preconditions.checkNotNull(role, "The role cannot be null!"); + Preconditions.checkArgument(commits >= 0, "Contributions cannot be negative"); contributions.put(role, commits); } @@ -141,7 +141,7 @@ public List> getContributions() { * @return The amount of contributions this {@link Contributor} submitted as the given role */ public int getContributions(@Nonnull String role) { - Validate.notNull(role, "The role cannot be null!"); + Preconditions.checkNotNull(role, "The role cannot be null!"); return contributions.getOrDefault(role, 0); } 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 17d158d27f..08cb070a85 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 @@ -14,7 +14,7 @@ import javax.annotation.Nonnull; import javax.annotation.Nullable; -import org.apache.commons.lang.Validate; +import com.google.common.base.Preconditions; import io.github.bakedlibs.dough.config.Config; import io.github.thebusybiscuit.slimefun4.implementation.Slimefun; @@ -105,10 +105,10 @@ private void addContributor(@Nonnull String name, @Nonnull String role) { } public @Nonnull Contributor addContributor(@Nonnull String minecraftName, @Nonnull String profileURL, @Nonnull String role, int commits) { - Validate.notNull(minecraftName, "Minecraft username must not be null."); - Validate.notNull(profileURL, "GitHub profile url must not be null."); - Validate.notNull(role, "Role should not be null."); - Validate.isTrue(commits >= 0, "Commit count cannot be negative."); + Preconditions.checkNotNull(minecraftName, "Minecraft username must not be null."); + Preconditions.checkNotNull(profileURL, "GitHub profile url must not be null."); + Preconditions.checkNotNull(role, "Role should not be null."); + Preconditions.checkArgument(commits >= 0, "Commit count cannot be negative."); String username = profileURL.substring(profileURL.lastIndexOf('/') + 1); @@ -119,9 +119,9 @@ private void addContributor(@Nonnull String name, @Nonnull String role) { } public @Nonnull Contributor addContributor(@Nonnull String username, @Nonnull String role, int commits) { - Validate.notNull(username, "Username must not be null."); - Validate.notNull(role, "Role should not be null."); - Validate.isTrue(commits >= 0, "Commit count cannot be negative."); + Preconditions.checkNotNull(username, "Username must not be null."); + Preconditions.checkNotNull(role, "Role should not be null."); + Preconditions.checkArgument(commits >= 0, "Commit count cannot be negative."); Contributor contributor = contributors.computeIfAbsent(username, key -> new Contributor(username)); contributor.setContributions(role, commits); diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/core/services/holograms/HologramsService.java b/src/main/java/io/github/thebusybiscuit/slimefun4/core/services/holograms/HologramsService.java index 2673dd9b91..4c8679ffbd 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/core/services/holograms/HologramsService.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/core/services/holograms/HologramsService.java @@ -11,7 +11,7 @@ import javax.annotation.Nullable; import javax.annotation.ParametersAreNonnullByDefault; -import org.apache.commons.lang.Validate; +import com.google.common.base.Preconditions; import org.bukkit.Bukkit; import org.bukkit.Location; import org.bukkit.NamespacedKey; @@ -128,7 +128,7 @@ private void purge() { */ @Nullable private Hologram getHologram(@Nonnull Location loc, boolean createIfNoneExists) { - Validate.notNull(loc, "Location cannot be null"); + Preconditions.checkNotNull(loc, "Location cannot be null"); BlockPosition position = new BlockPosition(loc); Hologram hologram = cache.get(position); @@ -249,8 +249,8 @@ private Hologram getAsHologram(@Nonnull BlockPosition position, @Nonnull Entity * The callback to run */ private void updateHologram(@Nonnull Location loc, @Nonnull Consumer consumer) { - Validate.notNull(loc, "Location must not be null"); - Validate.notNull(consumer, "Callbacks must not be null"); + Preconditions.checkNotNull(loc, "Location must not be null"); + Preconditions.checkNotNull(consumer, "Callbacks must not be null"); Runnable runnable = () -> { try { @@ -284,7 +284,7 @@ private void updateHologram(@Nonnull Location loc, @Nonnull Consumer c * exist or was already removed */ public boolean removeHologram(@Nonnull Location loc) { - Validate.notNull(loc, "Location cannot be null"); + Preconditions.checkNotNull(loc, "Location cannot be null"); if (Bukkit.isPrimaryThread()) { try { @@ -316,7 +316,7 @@ public boolean removeHologram(@Nonnull Location loc) { * The label to set, can be null */ public void setHologramLabel(@Nonnull Location loc, @Nullable String label) { - Validate.notNull(loc, "Location must not be null"); + Preconditions.checkNotNull(loc, "Location must not be null"); updateHologram(loc, hologram -> hologram.setLabel(label)); } diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/core/services/localization/Language.java b/src/main/java/io/github/thebusybiscuit/slimefun4/core/services/localization/Language.java index 0db0125e2e..ce25f684ef 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/core/services/localization/Language.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/core/services/localization/Language.java @@ -8,7 +8,7 @@ import javax.annotation.Nonnull; import javax.annotation.Nullable; -import org.apache.commons.lang.Validate; +import com.google.common.base.Preconditions; import org.bukkit.Server; import org.bukkit.configuration.file.FileConfiguration; import org.bukkit.entity.Player; @@ -45,8 +45,8 @@ public final class Language { * The hash of the skull texture to use */ public Language(@Nonnull String id, @Nonnull String hash) { - Validate.notNull(id, "A Language must have an id that is not null!"); - Validate.notNull(hash, "A Language must have a texture that is not null!"); + Preconditions.checkNotNull(id, "A Language must have an id that is not null!"); + Preconditions.checkNotNull(hash, "A Language must have a texture that is not null!"); this.id = id; this.item = SlimefunUtils.getCustomHead(hash); @@ -88,8 +88,8 @@ FileConfiguration getFile(@Nonnull LanguageFile file) { } public void setFile(@Nonnull LanguageFile file, @Nonnull FileConfiguration config) { - Validate.notNull(file, "The provided file should not be null."); - Validate.notNull(config, "The provided config should not be null."); + Preconditions.checkNotNull(file, "The provided file should not be null."); + Preconditions.checkNotNull(config, "The provided config should not be null."); files.put(file, config); } diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/core/services/localization/LanguageFile.java b/src/main/java/io/github/thebusybiscuit/slimefun4/core/services/localization/LanguageFile.java index 67f90dfb60..9e5a55075d 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/core/services/localization/LanguageFile.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/core/services/localization/LanguageFile.java @@ -2,7 +2,7 @@ import javax.annotation.Nonnull; -import org.apache.commons.lang.Validate; +import com.google.common.base.Preconditions; /** * This enum holds the different types of files each {@link Language} holds. @@ -36,7 +36,7 @@ public String getFilePath(@Nonnull Language language) { @Nonnull public String getFilePath(@Nonnull String languageId) { - Validate.notNull(languageId, "Language id must not be null!"); + Preconditions.checkNotNull(languageId, "Language id must not be null!"); return "/languages/" + languageId + '/' + fileName; } diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/core/services/localization/SlimefunLocalization.java b/src/main/java/io/github/thebusybiscuit/slimefun4/core/services/localization/SlimefunLocalization.java index 893e3baf21..9b15963e53 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/core/services/localization/SlimefunLocalization.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/core/services/localization/SlimefunLocalization.java @@ -11,7 +11,7 @@ import javax.annotation.Nullable; import javax.annotation.ParametersAreNonnullByDefault; -import org.apache.commons.lang.Validate; +import com.google.common.base.Preconditions; import org.bukkit.ChatColor; import org.bukkit.Keyed; import org.bukkit.Material; @@ -167,8 +167,8 @@ protected void loadEmbeddedLanguages() { @ParametersAreNonnullByDefault private @Nullable String getStringOrNull(@Nullable Language language, LanguageFile file, String path) { - Validate.notNull(file, "You need to provide a LanguageFile!"); - Validate.notNull(path, "The path cannot be null!"); + Preconditions.checkNotNull(file, "You need to provide a LanguageFile!"); + Preconditions.checkNotNull(path, "The path cannot be null!"); if (language == null) { // Unit-Test scenario (or something went horribly wrong) @@ -202,8 +202,8 @@ protected void loadEmbeddedLanguages() { @ParametersAreNonnullByDefault private @Nullable List getStringListOrNull(@Nullable Language language, LanguageFile file, String path) { - Validate.notNull(file, "You need to provide a LanguageFile!"); - Validate.notNull(path, "The path cannot be null!"); + Preconditions.checkNotNull(file, "You need to provide a LanguageFile!"); + Preconditions.checkNotNull(path, "The path cannot be null!"); if (language == null) { // Unit-Test scenario (or something went horribly wrong) @@ -236,7 +236,7 @@ protected void loadEmbeddedLanguages() { } public @Nonnull String getMessage(@Nonnull String key) { - Validate.notNull(key, "Message key must not be null!"); + Preconditions.checkNotNull(key, "Message key must not be null!"); Language language = getDefaultLanguage(); @@ -250,8 +250,8 @@ protected void loadEmbeddedLanguages() { } public @Nonnull String getMessage(@Nonnull Player p, @Nonnull String key) { - Validate.notNull(p, "Player must not be null!"); - Validate.notNull(key, "Message key must not be null!"); + Preconditions.checkNotNull(p, "Player must not be null!"); + Preconditions.checkNotNull(key, "Message key must not be null!"); return getString(getLanguage(p), LanguageFile.MESSAGES, key); } @@ -268,17 +268,17 @@ protected void loadEmbeddedLanguages() { } public @Nonnull List getMessages(@Nonnull Player p, @Nonnull String key) { - Validate.notNull(p, "Player should not be null."); - Validate.notNull(key, "Message key cannot be null."); + Preconditions.checkNotNull(p, "Player should not be null."); + Preconditions.checkNotNull(key, "Message key cannot be null."); return getStringList(getLanguage(p), LanguageFile.MESSAGES, key); } @ParametersAreNonnullByDefault public @Nonnull List getMessages(Player p, String key, UnaryOperator function) { - Validate.notNull(p, "Player cannot be null."); - Validate.notNull(key, "Message key cannot be null."); - Validate.notNull(function, "Function cannot be null."); + Preconditions.checkNotNull(p, "Player cannot be null."); + Preconditions.checkNotNull(key, "Message key cannot be null."); + Preconditions.checkNotNull(function, "Function cannot be null."); List messages = getMessages(p, key); messages.replaceAll(function); @@ -287,29 +287,29 @@ protected void loadEmbeddedLanguages() { } public @Nullable String getResearchName(@Nonnull Player p, @Nonnull NamespacedKey key) { - Validate.notNull(p, "Player must not be null."); - Validate.notNull(key, "NamespacedKey cannot be null."); + Preconditions.checkNotNull(p, "Player must not be null."); + Preconditions.checkNotNull(key, "NamespacedKey cannot be null."); return getStringOrNull(getLanguage(p), LanguageFile.RESEARCHES, key.getNamespace() + '.' + key.getKey()); } public @Nullable String getItemGroupName(@Nonnull Player p, @Nonnull NamespacedKey key) { - Validate.notNull(p, "Player must not be null."); - Validate.notNull(key, "NamespacedKey cannot be null!"); + Preconditions.checkNotNull(p, "Player must not be null."); + Preconditions.checkNotNull(key, "NamespacedKey cannot be null!"); return getStringOrNull(getLanguage(p), LanguageFile.CATEGORIES, key.getNamespace() + '.' + key.getKey()); } public @Nullable String getResourceString(@Nonnull Player p, @Nonnull String key) { - Validate.notNull(p, "Player should not be null!"); - Validate.notNull(key, "Message key should not be null!"); + Preconditions.checkNotNull(p, "Player should not be null!"); + Preconditions.checkNotNull(key, "Message key should not be null!"); return getStringOrNull(getLanguage(p), LanguageFile.RESOURCES, key); } public @Nonnull ItemStack getRecipeTypeItem(@Nonnull Player p, @Nonnull RecipeType recipeType) { - Validate.notNull(p, "Player cannot be null!"); - Validate.notNull(recipeType, "Recipe type cannot be null!"); + Preconditions.checkNotNull(p, "Player cannot be null!"); + Preconditions.checkNotNull(recipeType, "Recipe type cannot be null!"); ItemStack item = recipeType.toItem(); @@ -343,8 +343,8 @@ protected void loadEmbeddedLanguages() { } public void sendMessage(@Nonnull CommandSender recipient, @Nonnull String key, boolean addPrefix) { - Validate.notNull(recipient, "Recipient cannot be null!"); - Validate.notNull(key, "Message key cannot be null!"); + Preconditions.checkNotNull(recipient, "Recipient cannot be null!"); + Preconditions.checkNotNull(key, "Message key cannot be null!"); String prefix = addPrefix ? getChatPrefix() : ""; @@ -356,8 +356,8 @@ public void sendMessage(@Nonnull CommandSender recipient, @Nonnull String key, b } public void sendActionbarMessage(@Nonnull Player player, @Nonnull String key, boolean addPrefix) { - Validate.notNull(player, "Player cannot be null!"); - Validate.notNull(key, "Message key cannot be null!"); + Preconditions.checkNotNull(player, "Player cannot be null!"); + Preconditions.checkNotNull(key, "Message key cannot be null!"); String prefix = addPrefix ? getChatPrefix() : ""; String message = ChatColors.color(prefix + getMessage(player, key)); diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/core/services/profiler/PerformanceRating.java b/src/main/java/io/github/thebusybiscuit/slimefun4/core/services/profiler/PerformanceRating.java index 6af39582d9..a61ed1f695 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/core/services/profiler/PerformanceRating.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/core/services/profiler/PerformanceRating.java @@ -5,7 +5,7 @@ import javax.annotation.Nonnull; import javax.annotation.Nullable; -import org.apache.commons.lang.Validate; +import com.google.common.base.Preconditions; import org.bukkit.ChatColor; /** @@ -35,7 +35,7 @@ public enum PerformanceRating implements Predicate { private final float threshold; PerformanceRating(@Nonnull ChatColor color, float threshold) { - Validate.notNull(color, "Color cannot be null"); + Preconditions.checkNotNull(color, "Color cannot be null"); this.color = color; this.threshold = threshold; } diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/core/services/profiler/SlimefunProfiler.java b/src/main/java/io/github/thebusybiscuit/slimefun4/core/services/profiler/SlimefunProfiler.java index 408fdc439e..6ecb8b36f3 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/core/services/profiler/SlimefunProfiler.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/core/services/profiler/SlimefunProfiler.java @@ -15,7 +15,7 @@ import javax.annotation.Nonnull; -import org.apache.commons.lang.Validate; +import com.google.common.base.Preconditions; import org.bukkit.Chunk; import org.bukkit.Location; import org.bukkit.Server; @@ -154,8 +154,8 @@ public void scheduleEntries(int amount) { * @return The total timings of this entry */ public long closeEntry(@Nonnull Location l, @Nonnull SlimefunItem item, long timestamp) { - Validate.notNull(l, "Location must not be null!"); - Validate.notNull(item, "You need to specify a SlimefunItem!"); + Preconditions.checkNotNull(l, "Location must not be null!"); + Preconditions.checkNotNull(item, "You need to specify a SlimefunItem!"); if (timestamp == 0) { return 0; @@ -255,7 +255,7 @@ private void finishReport() { * The {@link PerformanceInspector} who shall receive this summary. */ public void requestSummary(@Nonnull PerformanceInspector inspector) { - Validate.notNull(inspector, "Cannot request a summary for null"); + Preconditions.checkNotNull(inspector, "Cannot request a summary for null"); requests.add(inspector); } @@ -299,7 +299,7 @@ protected Map getByChunk() { } protected int getBlocksInChunk(@Nonnull String chunk) { - Validate.notNull(chunk, "The chunk cannot be null!"); + Preconditions.checkNotNull(chunk, "The chunk cannot be null!"); int blocks = 0; for (ProfiledBlock block : timings.keySet()) { @@ -316,7 +316,7 @@ protected int getBlocksInChunk(@Nonnull String chunk) { } protected int getBlocksOfId(@Nonnull String id) { - Validate.notNull(id, "The id cannot be null!"); + Preconditions.checkNotNull(id, "The id cannot be null!"); int blocks = 0; for (ProfiledBlock block : timings.keySet()) { @@ -329,7 +329,7 @@ protected int getBlocksOfId(@Nonnull String id) { } protected int getBlocksFromPlugin(@Nonnull String pluginName) { - Validate.notNull(pluginName, "The Plugin name cannot be null!"); + Preconditions.checkNotNull(pluginName, "The Plugin name cannot be null!"); int blocks = 0; for (ProfiledBlock block : timings.keySet()) { @@ -385,27 +385,27 @@ public int getTickRate() { * @return Whether timings of this {@link Block} have been collected */ public boolean hasTimings(@Nonnull Block b) { - Validate.notNull(b, "Cannot get timings for a null Block"); + Preconditions.checkNotNull(b, "Cannot get timings for a null Block"); return timings.containsKey(new ProfiledBlock(b)); } public String getTime(@Nonnull Block b) { - Validate.notNull(b, "Cannot get timings for a null Block"); + Preconditions.checkNotNull(b, "Cannot get timings for a null Block"); long time = timings.getOrDefault(new ProfiledBlock(b), 0L); return NumberUtils.getAsMillis(time); } public String getTime(@Nonnull Chunk chunk) { - Validate.notNull(chunk, "Cannot get timings for a null Chunk"); + Preconditions.checkNotNull(chunk, "Cannot get timings for a null Chunk"); long time = getByChunk().getOrDefault(chunk.getWorld().getName() + " (" + chunk.getX() + ',' + chunk.getZ() + ')', 0L); return NumberUtils.getAsMillis(time); } public String getTime(@Nonnull SlimefunItem item) { - Validate.notNull(item, "Cannot get timings for a null SlimefunItem"); + Preconditions.checkNotNull(item, "Cannot get timings for a null SlimefunItem"); long time = getByItem().getOrDefault(item.getId(), 0L); return NumberUtils.getAsMillis(time); diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/core/services/profiler/inspectors/ConsolePerformanceInspector.java b/src/main/java/io/github/thebusybiscuit/slimefun4/core/services/profiler/inspectors/ConsolePerformanceInspector.java index f4249a3cff..1546e9a24f 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/core/services/profiler/inspectors/ConsolePerformanceInspector.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/core/services/profiler/inspectors/ConsolePerformanceInspector.java @@ -4,7 +4,7 @@ import javax.annotation.ParametersAreNonnullByDefault; import io.github.thebusybiscuit.slimefun4.core.services.profiler.SummaryOrderType; -import org.apache.commons.lang.Validate; +import com.google.common.base.Preconditions; import org.bukkit.command.CommandSender; import org.bukkit.command.ConsoleCommandSender; @@ -47,8 +47,8 @@ public class ConsolePerformanceInspector implements PerformanceInspector { */ @ParametersAreNonnullByDefault public ConsolePerformanceInspector(CommandSender console, boolean verbose, SummaryOrderType orderType) { - Validate.notNull(console, "CommandSender cannot be null"); - Validate.notNull(orderType, "SummaryOrderType cannot be null"); + Preconditions.checkNotNull(console, "CommandSender cannot be null"); + Preconditions.checkNotNull(orderType, "SummaryOrderType cannot be null"); this.console = console; this.verbose = verbose; diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/core/services/profiler/inspectors/PlayerPerformanceInspector.java b/src/main/java/io/github/thebusybiscuit/slimefun4/core/services/profiler/inspectors/PlayerPerformanceInspector.java index 8ce7811e3e..317a9db3ea 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/core/services/profiler/inspectors/PlayerPerformanceInspector.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/core/services/profiler/inspectors/PlayerPerformanceInspector.java @@ -6,7 +6,7 @@ import javax.annotation.Nullable; import io.github.thebusybiscuit.slimefun4.core.services.profiler.SummaryOrderType; -import org.apache.commons.lang.Validate; +import com.google.common.base.Preconditions; import org.bukkit.Bukkit; import org.bukkit.entity.Player; @@ -42,8 +42,8 @@ public class PlayerPerformanceInspector implements PerformanceInspector { * The {@link SummaryOrderType} of the timings */ public PlayerPerformanceInspector(@Nonnull Player player, @Nonnull SummaryOrderType orderType) { - Validate.notNull(player, "Player cannot be null"); - Validate.notNull(orderType, "SummaryOrderType cannot be null"); + Preconditions.checkNotNull(player, "Player cannot be null"); + Preconditions.checkNotNull(orderType, "SummaryOrderType cannot be null"); this.uuid = player.getUniqueId(); this.orderType = orderType; diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/Slimefun.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/Slimefun.java index 1be851ba17..5090cde1bc 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/Slimefun.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/Slimefun.java @@ -14,10 +14,10 @@ import javax.annotation.Nonnull; import javax.annotation.Nullable; +import com.google.common.base.Preconditions; import io.github.thebusybiscuit.slimefun4.storage.Storage; import io.github.thebusybiscuit.slimefun4.storage.backend.legacy.LegacyStorage; -import org.apache.commons.lang.Validate; import org.bukkit.Bukkit; import org.bukkit.Server; import org.bukkit.World; @@ -1038,8 +1038,8 @@ public static boolean isNewlyInstalled() { * @return The resulting {@link BukkitTask} or null if Slimefun was disabled */ public static @Nullable BukkitTask runSync(@Nonnull Runnable runnable, long delay) { - Validate.notNull(runnable, "Cannot run null"); - Validate.isTrue(delay >= 0, "The delay cannot be negative"); + Preconditions.checkNotNull(runnable, "Cannot run null"); + Preconditions.checkArgument(delay >= 0, "The delay cannot be negative"); // Run the task instantly within a Unit Test if (getMinecraftVersion() == MinecraftVersion.UNIT_TEST) { @@ -1067,7 +1067,7 @@ public static boolean isNewlyInstalled() { * @return The resulting {@link BukkitTask} or null if Slimefun was disabled */ public static @Nullable BukkitTask runSync(@Nonnull Runnable runnable) { - Validate.notNull(runnable, "Cannot run null"); + Preconditions.checkNotNull(runnable, "Cannot run null"); // Run the task instantly within a Unit Test if (getMinecraftVersion() == MinecraftVersion.UNIT_TEST) { diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/guide/SurvivalSlimefunGuide.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/guide/SurvivalSlimefunGuide.java index 83e43be65f..1dc8615164 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/guide/SurvivalSlimefunGuide.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/guide/SurvivalSlimefunGuide.java @@ -11,7 +11,7 @@ import javax.annotation.Nonnull; import javax.annotation.ParametersAreNonnullByDefault; -import org.apache.commons.lang.Validate; +import com.google.common.base.Preconditions; import org.bukkit.ChatColor; import org.bukkit.Material; import org.bukkit.Tag; @@ -582,9 +582,9 @@ private void displayItem(ChestMenu menu, PlayerProfile profile, Player p, Object @ParametersAreNonnullByDefault public void createHeader(Player p, PlayerProfile profile, ChestMenu menu) { - Validate.notNull(p, "The Player cannot be null!"); - Validate.notNull(profile, "The Profile cannot be null!"); - Validate.notNull(menu, "The Inventory cannot be null!"); + Preconditions.checkNotNull(p, "The Player cannot be null!"); + Preconditions.checkNotNull(profile, "The Profile cannot be null!"); + Preconditions.checkNotNull(menu, "The Inventory cannot be null!"); for (int i = 0; i < 9; i++) { menu.addItem(i, ChestMenuUtils.getBackground(), ChestMenuUtils.getEmptyClickHandler()); diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/handlers/VanillaInventoryDropHandler.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/handlers/VanillaInventoryDropHandler.java index 7ead892718..3890a27c72 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/handlers/VanillaInventoryDropHandler.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/handlers/VanillaInventoryDropHandler.java @@ -5,7 +5,7 @@ import javax.annotation.Nonnull; import javax.annotation.ParametersAreNonnullByDefault; -import org.apache.commons.lang.Validate; +import com.google.common.base.Preconditions; import org.bukkit.block.Block; import org.bukkit.block.BlockState; import org.bukkit.block.Chest; @@ -49,7 +49,7 @@ public class VanillaInventoryDropHandler */ public VanillaInventoryDropHandler(@Nonnull Class blockStateClass) { super(false, true); - Validate.notNull(blockStateClass, "The provided class must not be null!"); + Preconditions.checkNotNull(blockStateClass, "The provided class must not be null!"); this.blockStateClass = blockStateClass; } diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/LimitedUseItem.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/LimitedUseItem.java index c4377d4585..dbeab47b56 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/LimitedUseItem.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/LimitedUseItem.java @@ -6,7 +6,7 @@ import javax.annotation.Nonnull; import javax.annotation.ParametersAreNonnullByDefault; -import org.apache.commons.lang.Validate; +import com.google.common.base.Preconditions; import org.bukkit.Material; import org.bukkit.NamespacedKey; import org.bukkit.entity.Player; @@ -70,7 +70,7 @@ public final int getMaxUseCount() { * @return The {@link LimitedUseItem} for chaining of setters */ public final @Nonnull LimitedUseItem setMaxUseCount(int count) { - Validate.isTrue(count > 0, "The maximum use count must be greater than zero!"); + Preconditions.checkArgument(count > 0, "The maximum use count must be greater than zero!"); maxUseCount = count; return this; diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/androids/Instruction.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/androids/Instruction.java index 03fba08cff..e40bf355d1 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/androids/Instruction.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/androids/Instruction.java @@ -8,7 +8,7 @@ import javax.annotation.Nullable; import javax.annotation.ParametersAreNonnullByDefault; -import org.apache.commons.lang.Validate; +import com.google.common.base.Preconditions; import org.bukkit.Location; import org.bukkit.block.Block; import org.bukkit.block.BlockFace; @@ -282,7 +282,7 @@ public AndroidType getRequiredType() { @ParametersAreNonnullByDefault public void execute(ProgrammableAndroid android, Block b, BlockMenu inventory, BlockFace face) { - Validate.notNull(method, "Instruction '" + name() + "' must be executed manually!"); + Preconditions.checkNotNull(method, "Instruction '" + name() + "' must be executed manually!"); method.perform(android, b, inventory, face); } @@ -299,7 +299,7 @@ public void execute(ProgrammableAndroid android, Block b, BlockMenu inventory, B */ @Nullable public static Instruction getInstruction(@Nonnull String value) { - Validate.notNull(value, "An Instruction cannot be null!"); + Preconditions.checkNotNull(value, "An Instruction cannot be null!"); return nameLookup.get(value); } } diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/androids/ProgrammableAndroid.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/androids/ProgrammableAndroid.java index 8db9826bc7..b09a95c830 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/androids/ProgrammableAndroid.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/androids/ProgrammableAndroid.java @@ -10,7 +10,7 @@ import javax.annotation.Nonnull; import javax.annotation.ParametersAreNonnullByDefault; -import org.apache.commons.lang.Validate; +import com.google.common.base.Preconditions; import org.bukkit.ChatColor; import org.bukkit.Location; import org.bukkit.Material; @@ -577,17 +577,17 @@ protected void editInstruction(Player p, Block b, String[] script, int index) { @Nonnull public String getScript(@Nonnull Location l) { - Validate.notNull(l, "Location for android not specified"); + Preconditions.checkNotNull(l, "Location for android not specified"); String script = BlockStorage.getLocationInfo(l, "script"); return script != null ? script : DEFAULT_SCRIPT; } public void setScript(@Nonnull Location l, @Nonnull String script) { - Validate.notNull(l, "Location for android not specified"); - Validate.notNull(script, "No script given"); - Validate.isTrue(script.startsWith(Instruction.START.name() + '-'), "A script must begin with a 'START' token."); - Validate.isTrue(script.endsWith('-' + Instruction.REPEAT.name()), "A script must end with a 'REPEAT' token."); - Validate.isTrue(CommonPatterns.DASH.split(script).length <= MAX_SCRIPT_LENGTH, "Scripts may not have more than " + MAX_SCRIPT_LENGTH + " segments"); + Preconditions.checkNotNull(l, "Location for android not specified"); + Preconditions.checkNotNull(script, "No script given"); + Preconditions.checkArgument(script.startsWith(Instruction.START.name() + '-'), "A script must begin with a 'START' token."); + Preconditions.checkArgument(script.endsWith('-' + Instruction.REPEAT.name()), "A script must end with a 'REPEAT' token."); + Preconditions.checkArgument(CommonPatterns.DASH.split(script).length <= MAX_SCRIPT_LENGTH, "Scripts may not have more than " + MAX_SCRIPT_LENGTH + " segments"); BlockStorage.addBlockInfo(l, "script", script); } @@ -629,7 +629,7 @@ private void registerDefaultFuelTypes() { } public void registerFuelType(@Nonnull MachineFuel fuel) { - Validate.notNull(fuel, "Cannot register null as a Fuel type"); + Preconditions.checkNotNull(fuel, "Cannot register null as a Fuel type"); fuelTypes.add(fuel); } @@ -852,7 +852,7 @@ private void constructMenu(@Nonnull BlockMenuPreset preset) { @ParametersAreNonnullByDefault public void addItems(Block b, ItemStack... items) { - Validate.notNull(b, "The Block cannot be null."); + Preconditions.checkNotNull(b, "The Block cannot be null."); BlockMenu inv = BlockStorage.getInventory(b); diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/androids/Script.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/androids/Script.java index 652a75f9ba..b19e6d7d73 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/androids/Script.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/androids/Script.java @@ -12,7 +12,7 @@ import javax.annotation.Nonnull; import javax.annotation.ParametersAreNonnullByDefault; -import org.apache.commons.lang.Validate; +import com.google.common.base.Preconditions; import org.bukkit.Bukkit; import org.bukkit.ChatColor; import org.bukkit.OfflinePlayer; @@ -45,18 +45,18 @@ public final class Script { * The {@link Config} */ private Script(@Nonnull Config config) { - Validate.notNull(config); + Preconditions.checkNotNull(config); this.config = config; this.name = config.getString("name"); this.code = config.getString("code"); String uuid = config.getString("author"); - Validate.notNull(name); - Validate.notNull(code); - Validate.notNull(uuid); - Validate.notNull(config.getStringList("rating.positive")); - Validate.notNull(config.getStringList("rating.negative")); + Preconditions.checkNotNull(name); + Preconditions.checkNotNull(code); + Preconditions.checkNotNull(uuid); + Preconditions.checkNotNull(config.getStringList("rating.positive")); + Preconditions.checkNotNull(config.getStringList("rating.negative")); OfflinePlayer player = Bukkit.getOfflinePlayer(UUID.fromString(uuid)); this.author = player.getName() != null ? player.getName() : config.getString("author_name"); diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/armor/RainbowArmorPiece.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/armor/RainbowArmorPiece.java index 10a5030b5d..bb1687edc7 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/armor/RainbowArmorPiece.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/armor/RainbowArmorPiece.java @@ -5,7 +5,7 @@ import javax.annotation.Nonnull; import javax.annotation.ParametersAreNonnullByDefault; -import org.apache.commons.lang.Validate; +import com.google.common.base.Preconditions; import org.bukkit.Color; import org.bukkit.DyeColor; import org.bukkit.inventory.ItemStack; @@ -38,8 +38,7 @@ public class RainbowArmorPiece extends SlimefunArmorPiece { public RainbowArmorPiece(ItemGroup itemGroup, SlimefunItemStack item, RecipeType recipeType, ItemStack[] recipe, DyeColor[] dyeColors) { super(itemGroup, item, recipeType, recipe, new PotionEffect[0]); - // TODO Change this validation over to our custom validation blocked by https://github.com/baked-libs/dough/pull/184 - Validate.notEmpty(dyeColors, "RainbowArmorPiece colors cannot be empty!"); + Preconditions.checkArgument(dyeColors.length != 0, "RainbowArmorPiece colors cannot be empty!"); if (!SlimefunTag.LEATHER_ARMOR.isTagged(item.getType())) { throw new IllegalArgumentException("Rainbow armor needs to be a leather armor piece!"); diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/autocrafters/AbstractAutoCrafter.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/autocrafters/AbstractAutoCrafter.java index b75d3c6643..8cb0a1292c 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/autocrafters/AbstractAutoCrafter.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/autocrafters/AbstractAutoCrafter.java @@ -10,7 +10,7 @@ import javax.annotation.Nullable; import javax.annotation.ParametersAreNonnullByDefault; -import org.apache.commons.lang.Validate; +import com.google.common.base.Preconditions; import org.bukkit.Location; import org.bukkit.Material; import org.bukkit.NamespacedKey; @@ -125,8 +125,8 @@ public boolean isSynchronized() { */ @ParametersAreNonnullByDefault public void onRightClick(Block b, Player p) { - Validate.notNull(b, "The Block must not be null!"); - Validate.notNull(p, "The Player cannot be null!"); + Preconditions.checkNotNull(b, "The Block must not be null!"); + Preconditions.checkNotNull(p, "The Player cannot be null!"); // Check if we have a valid chest below if (!isValidInventory(b.getRelative(BlockFace.DOWN))) { @@ -238,7 +238,7 @@ protected boolean isValidInventory(@Nonnull Block block) { * The {@link AbstractRecipe} to select */ protected void setSelectedRecipe(@Nonnull Block b, @Nullable AbstractRecipe recipe) { - Validate.notNull(b, "The Block cannot be null!"); + Preconditions.checkNotNull(b, "The Block cannot be null!"); BlockStateSnapshotResult result = PaperLib.getBlockState(b, false); BlockState state = result.getState(); @@ -274,9 +274,9 @@ protected void setSelectedRecipe(@Nonnull Block b, @Nullable AbstractRecipe reci */ @ParametersAreNonnullByDefault protected void showRecipe(Player p, Block b, AbstractRecipe recipe) { - Validate.notNull(p, "The Player should not be null"); - Validate.notNull(b, "The Block should not be null"); - Validate.notNull(recipe, "The Recipe should not be null"); + Preconditions.checkNotNull(p, "The Player should not be null"); + Preconditions.checkNotNull(b, "The Block should not be null"); + Preconditions.checkNotNull(recipe, "The Recipe should not be null"); ChestMenu menu = new ChestMenu(getItemName()); menu.setPlayerInventoryClickable(false); @@ -399,8 +399,8 @@ protected boolean matchesAny(Inventory inv, Map itemQuantities * @return Whether this crafting operation was successful or not */ public boolean craft(@Nonnull Inventory inv, @Nonnull AbstractRecipe recipe) { - Validate.notNull(inv, "The Inventory must not be null"); - Validate.notNull(recipe, "The Recipe shall not be null"); + Preconditions.checkNotNull(inv, "The Inventory must not be null"); + Preconditions.checkNotNull(recipe, "The Recipe shall not be null"); // Make sure that the Recipe is actually enabled if (!recipe.isEnabled()) { @@ -513,7 +513,7 @@ public int getEnergyConsumption() { */ @Nonnull public final AbstractAutoCrafter setCapacity(int capacity) { - Validate.isTrue(capacity > 0, "The capacity must be greater than zero!"); + Preconditions.checkArgument(capacity > 0, "The capacity must be greater than zero!"); if (getState() == ItemState.UNREGISTERED) { this.energyCapacity = capacity; @@ -533,9 +533,9 @@ public final AbstractAutoCrafter setCapacity(int capacity) { */ @Nonnull public final AbstractAutoCrafter setEnergyConsumption(int energyConsumption) { - Validate.isTrue(energyConsumption > 0, "The energy consumption must be greater than zero!"); - Validate.isTrue(energyCapacity > 0, "You must specify the capacity before you can set the consumption amount."); - Validate.isTrue(energyConsumption <= energyCapacity, "The energy consumption cannot be higher than the capacity (" + energyCapacity + ')'); + Preconditions.checkArgument(energyConsumption > 0, "The energy consumption must be greater than zero!"); + Preconditions.checkArgument(energyCapacity > 0, "You must specify the capacity before you can set the consumption amount."); + Preconditions.checkArgument(energyConsumption <= energyCapacity, "The energy consumption cannot be higher than the capacity (" + energyCapacity + ')'); this.energyConsumed = energyConsumption; return this; @@ -543,7 +543,7 @@ public final AbstractAutoCrafter setEnergyConsumption(int energyConsumption) { @Override public void register(@Nonnull SlimefunAddon addon) { - Validate.notNull(addon, "A SlimefunAddon cannot be null!"); + Preconditions.checkNotNull(addon, "A SlimefunAddon cannot be null!"); this.addon = addon; if (getCapacity() <= 0) { diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/autocrafters/AbstractRecipe.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/autocrafters/AbstractRecipe.java index 12cef3cf9a..085c1f1d96 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/autocrafters/AbstractRecipe.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/autocrafters/AbstractRecipe.java @@ -7,7 +7,7 @@ import javax.annotation.Nullable; import javax.annotation.ParametersAreNonnullByDefault; -import org.apache.commons.lang.Validate; +import com.google.common.base.Preconditions; import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.Recipe; import org.bukkit.inventory.RecipeChoice.MaterialChoice; @@ -60,8 +60,8 @@ public abstract class AbstractRecipe { */ @ParametersAreNonnullByDefault protected AbstractRecipe(Collection> ingredients, ItemStack result) { - Validate.notEmpty(ingredients, "The input predicates cannot be null or an empty array"); - Validate.notNull(result, "The recipe result must not be null!"); + Preconditions.checkArgument(!ingredients.isEmpty(), "The input predicates cannot be null or an empty array"); + Preconditions.checkNotNull(result, "The recipe result must not be null!"); this.ingredients = ingredients; this.result = result; diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/autocrafters/SlimefunAutoCrafter.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/autocrafters/SlimefunAutoCrafter.java index 620e689b70..ee3a53ee7f 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/autocrafters/SlimefunAutoCrafter.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/autocrafters/SlimefunAutoCrafter.java @@ -4,7 +4,7 @@ import javax.annotation.Nullable; import javax.annotation.ParametersAreNonnullByDefault; -import org.apache.commons.lang.Validate; +import com.google.common.base.Preconditions; import org.bukkit.ChatColor; import org.bukkit.Material; import org.bukkit.block.Block; @@ -56,7 +56,7 @@ protected SlimefunAutoCrafter(ItemGroup itemGroup, SlimefunItemStack item, Recip @Override @Nullable public AbstractRecipe getSelectedRecipe(@Nonnull Block b) { - Validate.notNull(b, "The Block cannot be null!"); + Preconditions.checkNotNull(b, "The Block cannot be null!"); BlockState state = PaperLib.getBlockState(b, false).getState(); diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/autocrafters/SlimefunItemRecipe.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/autocrafters/SlimefunItemRecipe.java index 32cede3e95..e4754bbcb2 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/autocrafters/SlimefunItemRecipe.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/autocrafters/SlimefunItemRecipe.java @@ -7,7 +7,7 @@ import javax.annotation.Nonnull; -import org.apache.commons.lang.Validate; +import com.google.common.base.Preconditions; import org.bukkit.inventory.ItemStack; import io.github.thebusybiscuit.slimefun4.api.items.SlimefunItem; @@ -54,8 +54,8 @@ private static Collection> getInputs(@Nonnull SlimefunItem @Override public void show(@Nonnull ChestMenu menu, @Nonnull AsyncRecipeChoiceTask task) { - Validate.notNull(menu, "The ChestMenu cannot be null!"); - Validate.notNull(task, "The RecipeChoiceTask cannot be null!"); + Preconditions.checkNotNull(menu, "The ChestMenu cannot be null!"); + Preconditions.checkNotNull(task, "The RecipeChoiceTask cannot be null!"); menu.addItem(24, getResult().clone(), ChestMenuUtils.getEmptyClickHandler()); ItemStack[] recipe = item.getRecipe(); diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/autocrafters/VanillaAutoCrafter.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/autocrafters/VanillaAutoCrafter.java index e9c9c962dc..3b81f81f42 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/autocrafters/VanillaAutoCrafter.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/autocrafters/VanillaAutoCrafter.java @@ -8,7 +8,7 @@ import javax.annotation.Nullable; import javax.annotation.ParametersAreNonnullByDefault; -import org.apache.commons.lang.Validate; +import com.google.common.base.Preconditions; import org.bukkit.ChatColor; import org.bukkit.Material; import org.bukkit.NamespacedKey; @@ -130,7 +130,7 @@ protected void updateRecipe(@Nonnull Block b, @Nonnull Player p) { @ParametersAreNonnullByDefault private void offerRecipe(Player p, Block b, List recipes, int index, ChestMenu menu, AsyncRecipeChoiceTask task) { - Validate.isTrue(index >= 0 && index < recipes.size(), "page must be between 0 and " + (recipes.size() - 1)); + Preconditions.checkArgument(index >= 0 && index < recipes.size(), "page must be between 0 and " + (recipes.size() - 1)); menu.replaceExistingItem(46, ChestMenuUtils.getPreviousButton(p, index + 1, recipes.size())); menu.addMenuClickHandler(46, (pl, slot, item, action) -> { diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/autocrafters/VanillaRecipe.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/autocrafters/VanillaRecipe.java index 0654c4e366..305fc13e40 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/autocrafters/VanillaRecipe.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/autocrafters/VanillaRecipe.java @@ -7,7 +7,7 @@ import javax.annotation.Nonnull; -import org.apache.commons.lang.Validate; +import com.google.common.base.Preconditions; import org.bukkit.Keyed; import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.Recipe; @@ -72,8 +72,8 @@ private static RecipeChoice[] getShape(@Nonnull Recipe recipe) { @Override public void show(@Nonnull ChestMenu menu, @Nonnull AsyncRecipeChoiceTask task) { - Validate.notNull(menu, "The ChestMenu cannot be null!"); - Validate.notNull(task, "The RecipeChoiceTask cannot be null!"); + Preconditions.checkNotNull(menu, "The ChestMenu cannot be null!"); + Preconditions.checkNotNull(task, "The RecipeChoiceTask cannot be null!"); menu.replaceExistingItem(24, getResult().clone()); menu.addMenuClickHandler(24, ChestMenuUtils.getEmptyClickHandler()); diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/blocks/AbstractMonsterSpawner.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/blocks/AbstractMonsterSpawner.java index d0c24310f4..ea4645cf68 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/blocks/AbstractMonsterSpawner.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/blocks/AbstractMonsterSpawner.java @@ -7,7 +7,7 @@ import javax.annotation.Nonnull; import javax.annotation.ParametersAreNonnullByDefault; -import org.apache.commons.lang.Validate; +import com.google.common.base.Preconditions; import org.bukkit.ChatColor; import org.bukkit.block.BlockState; import org.bukkit.block.CreatureSpawner; @@ -50,7 +50,7 @@ public abstract class AbstractMonsterSpawner extends SlimefunItem { */ @Nonnull public Optional getEntityType(@Nonnull ItemStack item) { - Validate.notNull(item, "The Item cannot be null"); + Preconditions.checkNotNull(item, "The Item cannot be null"); ItemMeta meta = item.getItemMeta(); @@ -77,7 +77,7 @@ public Optional getEntityType(@Nonnull ItemStack item) { */ @Nonnull public ItemStack getItemForEntityType(@Nonnull EntityType type) { - Validate.notNull(type, "The EntityType cannot be null"); + Preconditions.checkNotNull(type, "The EntityType cannot be null"); ItemStack item = getItem().clone(); ItemMeta meta = item.getItemMeta(); diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/blocks/IgnitionChamber.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/blocks/IgnitionChamber.java index 50c55891aa..745a0564de 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/blocks/IgnitionChamber.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/blocks/IgnitionChamber.java @@ -4,7 +4,7 @@ import javax.annotation.Nullable; import javax.annotation.ParametersAreNonnullByDefault; -import org.apache.commons.lang.Validate; +import com.google.common.base.Preconditions; import org.bukkit.Material; import org.bukkit.block.Block; import org.bukkit.block.BlockFace; @@ -71,8 +71,8 @@ public IgnitionChamber(ItemGroup itemGroup, SlimefunItemStack item, RecipeType r */ @ParametersAreNonnullByDefault public static boolean useFlintAndSteel(Player p, Block smelteryBlock) { - Validate.notNull(p, "The Player must not be null!"); - Validate.notNull(smelteryBlock, "The smeltery block cannot be null!"); + Preconditions.checkNotNull(p, "The Player must not be null!"); + Preconditions.checkNotNull(smelteryBlock, "The smeltery block cannot be null!"); Inventory inv = findIgnitionChamber(smelteryBlock); diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/blocks/OutputChest.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/blocks/OutputChest.java index 5e82014379..6f8cd7b4b9 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/blocks/OutputChest.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/blocks/OutputChest.java @@ -5,7 +5,7 @@ import javax.annotation.Nonnull; import javax.annotation.ParametersAreNonnullByDefault; -import org.apache.commons.lang.Validate; +import com.google.common.base.Preconditions; import org.bukkit.Material; import org.bukkit.block.Block; import org.bukkit.block.BlockFace; @@ -68,8 +68,8 @@ public OutputChest(ItemGroup itemGroup, SlimefunItemStack item, RecipeType recip */ @Nonnull public static Optional findOutputChestFor(@Nonnull Block b, @Nonnull ItemStack item) { - Validate.notNull(b, "The target block must not be null!"); - Validate.notNull(item, "The ItemStack should not be null!"); + Preconditions.checkNotNull(b, "The target block must not be null!"); + Preconditions.checkNotNull(item, "The ItemStack should not be null!"); for (BlockFace face : possibleFaces) { Block potentialOutput = b.getRelative(face); diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/cargo/AbstractCargoNode.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/cargo/AbstractCargoNode.java index b662a060c1..ffce784be8 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/cargo/AbstractCargoNode.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/cargo/AbstractCargoNode.java @@ -4,7 +4,7 @@ import javax.annotation.Nullable; import javax.annotation.ParametersAreNonnullByDefault; -import org.apache.commons.lang.Validate; +import com.google.common.base.Preconditions; import org.bukkit.Location; import org.bukkit.block.Block; import org.bukkit.entity.Player; @@ -128,7 +128,7 @@ protected void addChannelSelector(Block b, BlockMenu menu, int slotPrev, int slo @Override public int getSelectedChannel(@Nonnull Block b) { - Validate.notNull(b, "Block must not be null"); + Preconditions.checkNotNull(b, "Block must not be null"); if (!BlockStorage.hasBlockInfo(b)) { return 0; diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/electric/AbstractEnergyProvider.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/electric/AbstractEnergyProvider.java index e84871e1ce..910e29131d 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/electric/AbstractEnergyProvider.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/electric/AbstractEnergyProvider.java @@ -8,7 +8,7 @@ import javax.annotation.Nonnull; import javax.annotation.ParametersAreNonnullByDefault; -import org.apache.commons.lang.Validate; +import com.google.common.base.Preconditions; import org.bukkit.inventory.Inventory; import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.meta.ItemMeta; @@ -90,7 +90,7 @@ public final EnergyNetComponentType getEnergyComponentType() { } public void registerFuel(@Nonnull MachineFuel fuel) { - Validate.notNull(fuel, "Machine Fuel cannot be null!"); + Preconditions.checkNotNull(fuel, "Machine Fuel cannot be null!"); fuelTypes.add(fuel); } diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/electric/machines/entities/AnimalProduce.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/electric/machines/entities/AnimalProduce.java index ed4e2c381f..c00ccbab49 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/electric/machines/entities/AnimalProduce.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/electric/machines/entities/AnimalProduce.java @@ -5,7 +5,7 @@ import javax.annotation.Nonnull; import javax.annotation.ParametersAreNonnullByDefault; -import org.apache.commons.lang.Validate; +import com.google.common.base.Preconditions; import org.bukkit.entity.LivingEntity; import org.bukkit.inventory.ItemStack; @@ -26,7 +26,7 @@ public class AnimalProduce extends MachineRecipe implements Predicate predicate) { super(5, new ItemStack[] { input }, new ItemStack[] { result }); - Validate.notNull(predicate, "The Predicate must not be null"); + Preconditions.checkNotNull(predicate, "The Predicate must not be null"); this.predicate = predicate; } diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/electric/machines/entities/ProduceCollector.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/electric/machines/entities/ProduceCollector.java index 24ecf5d86d..657af2c12c 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/electric/machines/entities/ProduceCollector.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/electric/machines/entities/ProduceCollector.java @@ -10,7 +10,7 @@ import javax.annotation.Nullable; import javax.annotation.ParametersAreNonnullByDefault; -import org.apache.commons.lang.Validate; +import com.google.common.base.Preconditions; import org.bukkit.Material; import org.bukkit.block.Block; import org.bukkit.entity.Ageable; @@ -90,7 +90,7 @@ protected void registerDefaultRecipes() { * The {@link AnimalProduce} to add */ public void addProduce(@Nonnull AnimalProduce produce) { - Validate.notNull(produce, "A produce cannot be null"); + Preconditions.checkNotNull(produce, "A produce cannot be null"); this.animalProduces.add(produce); } diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/elevator/ElevatorFloor.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/elevator/ElevatorFloor.java index be9245e51a..5cc7ff9be7 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/elevator/ElevatorFloor.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/elevator/ElevatorFloor.java @@ -2,7 +2,7 @@ import javax.annotation.Nonnull; -import org.apache.commons.lang.Validate; +import com.google.common.base.Preconditions; import org.bukkit.Location; import org.bukkit.block.Block; import org.bukkit.entity.Player; @@ -41,8 +41,8 @@ class ElevatorFloor { * The {@link Block} of this floor */ public ElevatorFloor(@Nonnull String name, int number, @Nonnull Block block) { - Validate.notNull(name, "An ElevatorFloor must have a name"); - Validate.notNull(block, "An ElevatorFloor must have a block"); + Preconditions.checkNotNull(name, "An ElevatorFloor must have a name"); + Preconditions.checkNotNull(block, "An ElevatorFloor must have a block"); this.name = name; this.number = number; diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/geo/GEOMiner.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/geo/GEOMiner.java index d21815533b..6df5474ce3 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/geo/GEOMiner.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/geo/GEOMiner.java @@ -7,7 +7,7 @@ import javax.annotation.Nonnull; import javax.annotation.ParametersAreNonnullByDefault; -import org.apache.commons.lang.Validate; +import com.google.common.base.Preconditions; import org.bukkit.ChatColor; import org.bukkit.Material; import org.bukkit.block.Block; @@ -118,7 +118,7 @@ public int getSpeed() { * @return This method will return the current instance of {@link GEOMiner}, so that can be chained. */ public final GEOMiner setCapacity(int capacity) { - Validate.isTrue(capacity > 0, "The capacity must be greater than zero!"); + Preconditions.checkArgument(capacity > 0, "The capacity must be greater than zero!"); if (getState() == ItemState.UNREGISTERED) { this.energyCapacity = capacity; @@ -137,7 +137,7 @@ public final GEOMiner setCapacity(int capacity) { * @return This method will return the current instance of {@link GEOMiner}, so that can be chained. */ public final GEOMiner setProcessingSpeed(int speed) { - Validate.isTrue(speed > 0, "The speed must be greater than zero!"); + Preconditions.checkArgument(speed > 0, "The speed must be greater than zero!"); this.processingSpeed = speed; return this; @@ -152,9 +152,9 @@ public final GEOMiner setProcessingSpeed(int speed) { * @return This method will return the current instance of {@link GEOMiner}, so that can be chained. */ public final GEOMiner setEnergyConsumption(int energyConsumption) { - Validate.isTrue(energyConsumption > 0, "The energy consumption must be greater than zero!"); - Validate.isTrue(energyCapacity > 0, "You must specify the capacity before you can set the consumption amount."); - Validate.isTrue(energyConsumption <= energyCapacity, "The energy consumption cannot be higher than the capacity (" + energyCapacity + ')'); + Preconditions.checkArgument(energyConsumption > 0, "The energy consumption must be greater than zero!"); + Preconditions.checkArgument(energyCapacity > 0, "You must specify the capacity before you can set the consumption amount."); + Preconditions.checkArgument(energyConsumption <= energyCapacity, "The energy consumption cannot be higher than the capacity (" + energyCapacity + ')'); this.energyConsumedPerTick = energyConsumption; return this; diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/magical/talismans/MagicianTalisman.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/magical/talismans/MagicianTalisman.java index 6c5ad0ffb7..6316eabdc2 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/magical/talismans/MagicianTalisman.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/magical/talismans/MagicianTalisman.java @@ -11,7 +11,7 @@ import javax.annotation.Nullable; import javax.annotation.ParametersAreNonnullByDefault; -import org.apache.commons.lang.Validate; +import com.google.common.base.Preconditions; import org.bukkit.Material; import org.bukkit.enchantments.Enchantment; import org.bukkit.entity.Player; @@ -74,8 +74,8 @@ public MagicianTalisman(SlimefunItemStack item, ItemStack[] recipe) { */ @Nullable public TalismanEnchantment getRandomEnchantment(@Nonnull ItemStack item, @Nonnull Set existingEnchantments) { - Validate.notNull(item, "The ItemStack cannot be null"); - Validate.notNull(existingEnchantments, "The Enchantments Set cannot be null"); + Preconditions.checkNotNull(item, "The ItemStack cannot be null"); + Preconditions.checkNotNull(existingEnchantments, "The Enchantments Set cannot be null"); // @formatter:off List enabled = enchantments.stream() diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/magical/talismans/Talisman.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/magical/talismans/Talisman.java index 9f97f19892..5f6a8567cb 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/magical/talismans/Talisman.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/magical/talismans/Talisman.java @@ -9,7 +9,7 @@ import javax.annotation.Nullable; import javax.annotation.ParametersAreNonnullByDefault; -import org.apache.commons.lang.Validate; +import com.google.common.base.Preconditions; import org.bukkit.Bukkit; import org.bukkit.ChatColor; import org.bukkit.NamespacedKey; @@ -280,7 +280,7 @@ protected final String getMessageSuffix() { * The {@link Player} who shall receive the message */ public void sendMessage(@Nonnull Player p) { - Validate.notNull(p, "The Player must not be null."); + Preconditions.checkNotNull(p, "The Player must not be null."); // Check if this Talisman has a message if (!isSilent()) { diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/misc/GoldIngot.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/misc/GoldIngot.java index 689df4264d..70719fbe9b 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/misc/GoldIngot.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/misc/GoldIngot.java @@ -2,7 +2,7 @@ import javax.annotation.ParametersAreNonnullByDefault; -import org.apache.commons.lang.Validate; +import com.google.common.base.Preconditions; import org.bukkit.inventory.ItemStack; import io.github.thebusybiscuit.slimefun4.api.items.ItemGroup; @@ -33,8 +33,8 @@ public class GoldIngot extends SlimefunItem { public GoldIngot(ItemGroup itemGroup, int caratRating, SlimefunItemStack item, RecipeType recipeType, ItemStack[] recipe) { super(itemGroup, item, recipeType, recipe); - Validate.isTrue(caratRating > 0, "Carat rating must be above zero."); - Validate.isTrue(caratRating <= 24, "Carat rating cannot go above 24."); + Preconditions.checkArgument(caratRating > 0, "Carat rating must be above zero."); + Preconditions.checkArgument(caratRating <= 24, "Carat rating cannot go above 24."); this.caratRating = caratRating; } diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/multiblocks/miner/IndustrialMiner.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/multiblocks/miner/IndustrialMiner.java index 3ad9381c6c..c149181422 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/multiblocks/miner/IndustrialMiner.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/multiblocks/miner/IndustrialMiner.java @@ -10,7 +10,7 @@ import javax.annotation.Nonnull; import javax.annotation.ParametersAreNonnullByDefault; -import org.apache.commons.lang.Validate; +import com.google.common.base.Preconditions; import org.bukkit.Location; import org.bukkit.Material; import org.bukkit.Tag; @@ -146,8 +146,8 @@ protected void registerDefaultFuelTypes() { * The item that shall be consumed */ public void addFuelType(int ores, @Nonnull ItemStack item) { - Validate.isTrue(ores > 1 && ores % 2 == 0, "The amount of ores must be at least 2 and a multiple of 2."); - Validate.notNull(item, "The fuel item cannot be null"); + Preconditions.checkArgument(ores > 1 && ores % 2 == 0, "The amount of ores must be at least 2 and a multiple of 2."); + Preconditions.checkNotNull(item, "The fuel item cannot be null"); fuelTypes.add(new MachineFuel(ores / 2, item)); } diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/tools/ClimbingPick.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/tools/ClimbingPick.java index 265db240ed..90f9e55610 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/tools/ClimbingPick.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/tools/ClimbingPick.java @@ -14,7 +14,7 @@ import javax.annotation.Nullable; import javax.annotation.ParametersAreNonnullByDefault; -import org.apache.commons.lang.Validate; +import com.google.common.base.Preconditions; import org.bukkit.Bukkit; import org.bukkit.Effect; import org.bukkit.GameMode; @@ -124,7 +124,7 @@ public Collection getClimbableSurfaces() { * @return The climbing speed for this {@link Material} or 0. */ public double getClimbingSpeed(@Nonnull Material type) { - Validate.notNull(type, "The surface cannot be null"); + Preconditions.checkNotNull(type, "The surface cannot be null"); ClimbableSurface surface = surfaces.get(type); if (surface != null) { diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/listeners/BackpackListener.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/listeners/BackpackListener.java index 135d2682c2..3937647923 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/listeners/BackpackListener.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/listeners/BackpackListener.java @@ -9,7 +9,7 @@ import javax.annotation.Nullable; import javax.annotation.ParametersAreNonnullByDefault; -import org.apache.commons.lang.Validate; +import com.google.common.base.Preconditions; import org.bukkit.ChatColor; import org.bukkit.Material; import org.bukkit.OfflinePlayer; @@ -192,8 +192,8 @@ private void openBackpack(Player p, ItemStack item, PlayerProfile profile, int s * The id of this backpack */ public void setBackpackId(@Nonnull OfflinePlayer backpackOwner, @Nonnull ItemStack item, int line, int id) { - Validate.notNull(backpackOwner, "Backpacks must have an owner!"); - Validate.notNull(item, "Cannot set the id onto null!"); + Preconditions.checkNotNull(backpackOwner, "Backpacks must have an owner!"); + Preconditions.checkNotNull(item, "Cannot set the id onto null!"); ItemMeta im = item.getItemMeta(); diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/operations/CraftingOperation.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/operations/CraftingOperation.java index 410664e314..2605a4e13d 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/operations/CraftingOperation.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/operations/CraftingOperation.java @@ -2,7 +2,7 @@ import javax.annotation.Nonnull; -import org.apache.commons.lang.Validate; +import com.google.common.base.Preconditions; import org.bukkit.inventory.ItemStack; import io.github.thebusybiscuit.slimefun4.core.machines.MachineOperation; @@ -28,9 +28,9 @@ public CraftingOperation(@Nonnull MachineRecipe recipe) { } public CraftingOperation(@Nonnull ItemStack[] ingredients, @Nonnull ItemStack[] results, int totalTicks) { - Validate.notEmpty(ingredients, "The Ingredients array cannot be empty or null"); - Validate.notEmpty(results, "The results array cannot be empty or null"); - Validate.isTrue(totalTicks >= 0, "The amount of total ticks must be a positive integer or zero, received: " + totalTicks); + Preconditions.checkArgument(ingredients.length != 0, "The Ingredients array cannot be empty or null"); + Preconditions.checkArgument(results.length != 0, "The results array cannot be empty or null"); + Preconditions.checkArgument(totalTicks >= 0, "The amount of total ticks must be a positive integer or zero, received: " + totalTicks); this.ingredients = ingredients; this.results = results; @@ -39,7 +39,7 @@ public CraftingOperation(@Nonnull ItemStack[] ingredients, @Nonnull ItemStack[] @Override public void addProgress(int num) { - Validate.isTrue(num > 0, "Progress must be positive."); + Preconditions.checkArgument(num > 0, "Progress must be positive."); currentTicks += num; } diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/operations/FuelOperation.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/operations/FuelOperation.java index a86fd1991e..708db7fc46 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/operations/FuelOperation.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/operations/FuelOperation.java @@ -3,7 +3,7 @@ import javax.annotation.Nonnull; import javax.annotation.Nullable; -import org.apache.commons.lang.Validate; +import com.google.common.base.Preconditions; import org.bukkit.inventory.ItemStack; import io.github.thebusybiscuit.slimefun4.core.machines.MachineOperation; @@ -29,8 +29,8 @@ public FuelOperation(@Nonnull MachineFuel recipe) { } public FuelOperation(@Nonnull ItemStack ingredient, @Nullable ItemStack result, int totalTicks) { - Validate.notNull(ingredient, "The Ingredient cannot be null"); - Validate.isTrue(totalTicks > 0, "The amount of total ticks must be a positive integer"); + Preconditions.checkNotNull(ingredient, "The Ingredient cannot be null"); + Preconditions.checkArgument(totalTicks > 0, "The amount of total ticks must be a positive integer"); this.ingredient = ingredient; this.result = result; @@ -39,7 +39,7 @@ public FuelOperation(@Nonnull ItemStack ingredient, @Nullable ItemStack result, @Override public void addProgress(int num) { - Validate.isTrue(num > 0, "Progress must be positive."); + Preconditions.checkArgument(num > 0, "Progress must be positive."); currentTicks += num; } diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/operations/MiningOperation.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/operations/MiningOperation.java index e7f94c98bf..54e7792bbb 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/operations/MiningOperation.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/operations/MiningOperation.java @@ -2,7 +2,7 @@ import javax.annotation.Nonnull; -import org.apache.commons.lang.Validate; +import com.google.common.base.Preconditions; import org.bukkit.inventory.ItemStack; import io.github.thebusybiscuit.slimefun4.core.machines.MachineOperation; @@ -22,8 +22,8 @@ public class MiningOperation implements MachineOperation { private int currentTicks = 0; public MiningOperation(@Nonnull ItemStack result, int totalTicks) { - Validate.notNull(result, "The result cannot be null"); - Validate.isTrue(totalTicks >= 0, "The amount of total ticks must be a positive integer or zero, received: " + totalTicks); + Preconditions.checkNotNull(result, "The result cannot be null"); + Preconditions.checkArgument(totalTicks >= 0, "The amount of total ticks must be a positive integer or zero, received: " + totalTicks); this.result = result; this.totalTicks = totalTicks; @@ -31,7 +31,7 @@ public MiningOperation(@Nonnull ItemStack result, int totalTicks) { @Override public void addProgress(int num) { - Validate.isTrue(num > 0, "Progress must be positive."); + Preconditions.checkArgument(num > 0, "Progress must be positive."); currentTicks += num; } diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/resources/AbstractResource.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/resources/AbstractResource.java index cfe995787f..2040ab3741 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/resources/AbstractResource.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/resources/AbstractResource.java @@ -5,7 +5,7 @@ import javax.annotation.Nonnull; import javax.annotation.ParametersAreNonnullByDefault; -import org.apache.commons.lang.Validate; +import com.google.common.base.Preconditions; import org.bukkit.NamespacedKey; import org.bukkit.inventory.ItemStack; @@ -37,9 +37,9 @@ abstract class AbstractResource implements GEOResource { @ParametersAreNonnullByDefault AbstractResource(String key, String defaultName, ItemStack item, int maxDeviation, boolean geoMiner) { - Validate.notNull(key, "NamespacedKey cannot be null!"); - Validate.notNull(defaultName, "The default name cannot be null!"); - Validate.notNull(item, "item cannot be null!"); + Preconditions.checkNotNull(key, "NamespacedKey cannot be null!"); + Preconditions.checkNotNull(defaultName, "The default name cannot be null!"); + Preconditions.checkNotNull(item, "item cannot be null!"); this.key = new NamespacedKey(Slimefun.instance(), key); this.defaultName = defaultName; @@ -89,8 +89,8 @@ public boolean isObtainableFromGEOMiner() { */ @ParametersAreNonnullByDefault static final @Nonnull BiomeMap getBiomeMap(AbstractResource resource, String path) { - Validate.notNull(resource, "Resource cannot be null."); - Validate.notNull(path, "Path cannot be null."); + Preconditions.checkNotNull(resource, "Resource cannot be null."); + Preconditions.checkNotNull(path, "Path cannot be null."); try { return BiomeMap.fromResource(resource.getKey(), Slimefun.instance(), path, JsonElement::getAsInt); diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/tasks/AsyncRecipeChoiceTask.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/tasks/AsyncRecipeChoiceTask.java index 9ac00aa3ca..93be6eab83 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/tasks/AsyncRecipeChoiceTask.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/tasks/AsyncRecipeChoiceTask.java @@ -7,7 +7,7 @@ import javax.annotation.Nonnull; -import org.apache.commons.lang.Validate; +import com.google.common.base.Preconditions; import org.bukkit.Bukkit; import org.bukkit.Material; import org.bukkit.Tag; @@ -47,14 +47,14 @@ public class AsyncRecipeChoiceTask implements Runnable { * The {@link Inventory} to start this task for */ public void start(@Nonnull Inventory inv) { - Validate.notNull(inv, "Inventory must not be null"); + Preconditions.checkNotNull(inv, "Inventory must not be null"); inventory = inv; id = Bukkit.getScheduler().runTaskTimerAsynchronously(Slimefun.instance(), this, 0, UPDATE_INTERVAL).getTaskId(); } public void add(int slot, @Nonnull MaterialChoice choice) { - Validate.notNull(choice, "Cannot add a null RecipeChoice"); + Preconditions.checkNotNull(choice, "Cannot add a null RecipeChoice"); lock.writeLock().lock(); @@ -66,7 +66,7 @@ public void add(int slot, @Nonnull MaterialChoice choice) { } public void add(int slot, @Nonnull Tag tag) { - Validate.notNull(tag, "Cannot add a null Tag"); + Preconditions.checkNotNull(tag, "Cannot add a null Tag"); lock.writeLock().lock(); diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/tasks/CapacitorTextureUpdateTask.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/tasks/CapacitorTextureUpdateTask.java index 4f79580831..87871a2668 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/tasks/CapacitorTextureUpdateTask.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/tasks/CapacitorTextureUpdateTask.java @@ -2,7 +2,7 @@ import javax.annotation.Nonnull; -import org.apache.commons.lang.Validate; +import com.google.common.base.Preconditions; import org.bukkit.Location; import org.bukkit.Material; import org.bukkit.Server; @@ -45,7 +45,7 @@ public class CapacitorTextureUpdateTask implements Runnable { * The capacity of this {@link Capacitor} */ public CapacitorTextureUpdateTask(@Nonnull Location l, double charge, double capacity) { - Validate.notNull(l, "The Location cannot be null"); + Preconditions.checkNotNull(l, "The Location cannot be null"); this.l = l; this.filledPercentage = charge / capacity; diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/tasks/TickerTask.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/tasks/TickerTask.java index cbf6e42eb1..740beefdb9 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/tasks/TickerTask.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/tasks/TickerTask.java @@ -13,7 +13,7 @@ import javax.annotation.Nonnull; import javax.annotation.ParametersAreNonnullByDefault; -import org.apache.commons.lang.Validate; +import com.google.common.base.Preconditions; import org.bukkit.Bukkit; import org.bukkit.Chunk; import org.bukkit.Location; @@ -222,15 +222,15 @@ public void halt() { @ParametersAreNonnullByDefault public void queueMove(Location from, Location to) { - Validate.notNull(from, "Source Location cannot be null!"); - Validate.notNull(to, "Target Location cannot be null!"); + Preconditions.checkNotNull(from, "Source Location cannot be null!"); + Preconditions.checkNotNull(to, "Target Location cannot be null!"); movingQueue.put(from, to); } @ParametersAreNonnullByDefault public void queueDelete(Location l, boolean destroy) { - Validate.notNull(l, "Location must not be null!"); + Preconditions.checkNotNull(l, "Location must not be null!"); deletionQueue.put(l, destroy); } @@ -238,11 +238,11 @@ public void queueDelete(Location l, boolean destroy) { @ParametersAreNonnullByDefault public void queueDelete(Collection locations, boolean destroy) { - Validate.notNull(locations, "Locations must not be null"); + Preconditions.checkNotNull(locations, "Locations must not be null"); Map toDelete = new HashMap<>(locations.size(), 1.0F); for (Location location : locations) { - Validate.notNull(location, "Locations must not contain null locations"); + Preconditions.checkNotNull(location, "Locations must not contain null locations"); toDelete.put(location, destroy); } deletionQueue.putAll(toDelete); @@ -250,10 +250,10 @@ public void queueDelete(Collection locations, boolean destroy) { @ParametersAreNonnullByDefault public void queueDelete(Map locations) { - Validate.notNull(locations, "Locations must not be null"); + Preconditions.checkNotNull(locations, "Locations must not be null"); for (Map.Entry entry : locations.entrySet()) { - Validate.notNull(entry.getKey(), "Location in locations cannot be null"); - Validate.notNull(entry.getValue(), "Boolean toDestroy in locations cannot be null"); + Preconditions.checkNotNull(entry.getKey(), "Location in locations cannot be null"); + Preconditions.checkNotNull(entry.getValue(), "Boolean toDestroy in locations cannot be null"); } deletionQueue.putAll(locations); } @@ -272,7 +272,7 @@ public void queueDelete(Map locations) { * @return Whether this {@link Location} has been reserved and will be filled upon the next tick */ public boolean isOccupiedSoon(@Nonnull Location l) { - Validate.notNull(l, "Null is not a valid Location!"); + Preconditions.checkNotNull(l, "Null is not a valid Location!"); return movingQueue.containsValue(l); } @@ -286,7 +286,7 @@ public boolean isOccupiedSoon(@Nonnull Location l) { * @return Whether this {@link Location} will be deleted on the next tick */ public boolean isDeletedSoon(@Nonnull Location l) { - Validate.notNull(l, "Null is not a valid Location!"); + Preconditions.checkNotNull(l, "Null is not a valid Location!"); return deletionQueue.containsKey(l); } @@ -327,7 +327,7 @@ public Map> getLocations() { */ @Nonnull public Set getLocations(@Nonnull Chunk chunk) { - Validate.notNull(chunk, "The Chunk cannot be null!"); + Preconditions.checkNotNull(chunk, "The Chunk cannot be null!"); Set locations = tickingLocations.getOrDefault(new ChunkPosition(chunk), new HashSet<>()); return Collections.unmodifiableSet(locations); @@ -340,7 +340,7 @@ public Set getLocations(@Nonnull Chunk chunk) { * The {@link Location} to activate */ public void enableTicker(@Nonnull Location l) { - Validate.notNull(l, "Location cannot be null!"); + Preconditions.checkNotNull(l, "Location cannot be null!"); ChunkPosition chunk = new ChunkPosition(l.getWorld(), l.getBlockX() >> 4, l.getBlockZ() >> 4); Set newValue = new HashSet<>(); @@ -365,7 +365,7 @@ public void enableTicker(@Nonnull Location l) { * The {@link Location} to remove */ public void disableTicker(@Nonnull Location l) { - Validate.notNull(l, "Location cannot be null!"); + Preconditions.checkNotNull(l, "Location cannot be null!"); ChunkPosition chunk = new ChunkPosition(l.getWorld(), l.getBlockX() >> 4, l.getBlockZ() >> 4); Set locations = tickingLocations.get(chunk); diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/storage/data/PlayerData.java b/src/main/java/io/github/thebusybiscuit/slimefun4/storage/data/PlayerData.java index 8615b6ee5f..04cb0f9f54 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/storage/data/PlayerData.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/storage/data/PlayerData.java @@ -13,7 +13,7 @@ import javax.annotation.Nonnull; -import org.apache.commons.lang.Validate; +import com.google.common.base.Preconditions; /** * The data which backs {@link io.github.thebusybiscuit.slimefun4.api.player.PlayerProfile} @@ -39,12 +39,12 @@ public Set getResearches() { } public void addResearch(@Nonnull Research research) { - Validate.notNull(research, "Cannot add a 'null' research!"); + Preconditions.checkNotNull(research, "Cannot add a 'null' research!"); researches.add(research); } public void removeResearch(@Nonnull Research research) { - Validate.notNull(research, "Cannot remove a 'null' research!"); + Preconditions.checkNotNull(research, "Cannot remove a 'null' research!"); researches.remove(research); } @@ -59,12 +59,12 @@ public PlayerBackpack getBackpack(int id) { } public void addBackpack(@Nonnull PlayerBackpack backpack) { - Validate.notNull(backpack, "Cannot add a 'null' backpack!"); + Preconditions.checkNotNull(backpack, "Cannot add a 'null' backpack!"); backpacks.put(backpack.getId(), backpack); } public void removeBackpack(@Nonnull PlayerBackpack backpack) { - Validate.notNull(backpack, "Cannot remove a 'null' backpack!"); + Preconditions.checkNotNull(backpack, "Cannot remove a 'null' backpack!"); backpacks.remove(backpack.getId()); } @@ -73,7 +73,7 @@ public Set getWaypoints() { } public void addWaypoint(@Nonnull Waypoint waypoint) { - Validate.notNull(waypoint, "Cannot add a 'null' waypoint!"); + Preconditions.checkNotNull(waypoint, "Cannot add a 'null' waypoint!"); for (Waypoint wp : waypoints) { if (wp.getId().equals(waypoint.getId())) { @@ -90,7 +90,7 @@ public void addWaypoint(@Nonnull Waypoint waypoint) { } public void removeWaypoint(@Nonnull Waypoint waypoint) { - Validate.notNull(waypoint, "Cannot remove a 'null' waypoint!"); + Preconditions.checkNotNull(waypoint, "Cannot remove a 'null' waypoint!"); waypoints.remove(waypoint); } } diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/utils/ChargeUtils.java b/src/main/java/io/github/thebusybiscuit/slimefun4/utils/ChargeUtils.java index 9c23ff0075..30acc786ff 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/utils/ChargeUtils.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/utils/ChargeUtils.java @@ -8,7 +8,7 @@ import javax.annotation.Nonnull; -import org.apache.commons.lang.Validate; +import com.google.common.base.Preconditions; import org.bukkit.ChatColor; import org.bukkit.NamespacedKey; import org.bukkit.inventory.meta.ItemMeta; @@ -37,10 +37,10 @@ public final class ChargeUtils { private ChargeUtils() {} public static void setCharge(@Nonnull ItemMeta meta, float charge, float capacity) { - Validate.notNull(meta, "Meta cannot be null!"); - Validate.isTrue(charge >= 0, "Charge has to be equal to or greater than 0!"); - Validate.isTrue(capacity > 0, "Capacity has to be greater than 0!"); - Validate.isTrue(charge <= capacity, "Charge may not be bigger than the capacity!"); + Preconditions.checkNotNull(meta, "Meta cannot be null!"); + Preconditions.checkArgument(charge >= 0, "Charge has to be equal to or greater than 0!"); + Preconditions.checkArgument(capacity > 0, "Capacity has to be greater than 0!"); + Preconditions.checkArgument(charge <= capacity, "Charge may not be bigger than the capacity!"); BigDecimal decimal = BigDecimal.valueOf(charge).setScale(2, RoundingMode.HALF_UP); float value = decimal.floatValue(); @@ -64,7 +64,7 @@ public static void setCharge(@Nonnull ItemMeta meta, float charge, float capacit } public static float getCharge(@Nonnull ItemMeta meta) { - Validate.notNull(meta, "Meta cannot be null!"); + Preconditions.checkNotNull(meta, "Meta cannot be null!"); NamespacedKey key = Slimefun.getRegistry().getItemChargeDataKey(); PersistentDataContainer container = meta.getPersistentDataContainer(); diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/utils/ColoredMaterial.java b/src/main/java/io/github/thebusybiscuit/slimefun4/utils/ColoredMaterial.java index 9fe766e5e0..03d44e6c39 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/utils/ColoredMaterial.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/utils/ColoredMaterial.java @@ -3,10 +3,11 @@ import java.util.Arrays; import java.util.Collections; import java.util.List; +import java.util.Objects; import javax.annotation.Nonnull; -import org.apache.commons.lang.Validate; +import com.google.common.base.Preconditions; import org.bukkit.DyeColor; import org.bukkit.Material; @@ -216,8 +217,8 @@ public enum ColoredMaterial { * The {@link Material Materials} for this {@link ColoredMaterial}. */ ColoredMaterial(@Nonnull Material[] materials) { - Validate.noNullElements(materials, "The List cannot contain any null elements"); - Validate.isTrue(materials.length == 16, "Expected 16, received: " + materials.length + ". Did you miss a color?"); + Preconditions.checkArgument(Arrays.stream(materials).noneMatch(Objects::isNull), "The List cannot contain any null elements"); + Preconditions.checkArgument(materials.length == 16, "Expected 16, received: " + materials.length + ". Did you miss a color?"); list = Collections.unmodifiableList(Arrays.asList(materials)); } @@ -241,7 +242,7 @@ public enum ColoredMaterial { * @return The {@link Material} at that index */ public @Nonnull Material get(int index) { - Validate.isTrue(index >= 0 && index < 16, "The index must be between 0 and 15 (inclusive)."); + Preconditions.checkArgument(index >= 0 && index < 16, "The index must be between 0 and 15 (inclusive)."); return list.get(index); } @@ -255,7 +256,7 @@ public enum ColoredMaterial { * @return The {@link Material} with that {@link DyeColor} */ public @Nonnull Material get(@Nonnull DyeColor color) { - Validate.notNull(color, "Color cannot be null!"); + Preconditions.checkNotNull(color, "Color cannot be null!"); return get(color.ordinal()); } diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/utils/HeadTexture.java b/src/main/java/io/github/thebusybiscuit/slimefun4/utils/HeadTexture.java index a4caf14774..c24e0a31e5 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/utils/HeadTexture.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/utils/HeadTexture.java @@ -5,7 +5,7 @@ import javax.annotation.Nonnull; -import org.apache.commons.lang.Validate; +import com.google.common.base.Preconditions; import org.bukkit.inventory.ItemStack; import io.github.bakedlibs.dough.common.CommonPatterns; @@ -127,8 +127,8 @@ public enum HeadTexture { private final UUID uuid; HeadTexture(@Nonnull String texture) { - Validate.notNull(texture, "Texture cannot be null"); - Validate.isTrue(CommonPatterns.HEXADECIMAL.matcher(texture).matches(), "Textures must be in hexadecimal."); + Preconditions.checkNotNull(texture, "Texture cannot be null"); + Preconditions.checkArgument(CommonPatterns.HEXADECIMAL.matcher(texture).matches(), "Textures must be in hexadecimal."); this.texture = texture; this.uuid = UUID.nameUUIDFromBytes(texture.getBytes(StandardCharsets.UTF_8)); diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/utils/InfiniteBlockGenerator.java b/src/main/java/io/github/thebusybiscuit/slimefun4/utils/InfiniteBlockGenerator.java index 9c0a80c5b7..b9271c574a 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/utils/InfiniteBlockGenerator.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/utils/InfiniteBlockGenerator.java @@ -6,7 +6,7 @@ import javax.annotation.Nullable; import javax.annotation.ParametersAreNonnullByDefault; -import org.apache.commons.lang.Validate; +import com.google.common.base.Preconditions; import org.bukkit.Bukkit; import org.bukkit.Material; import org.bukkit.block.Block; @@ -74,7 +74,7 @@ public enum InfiniteBlockGenerator implements Predicate { */ @Override public boolean test(@Nonnull Block b) { - Validate.notNull(b, "Block cannot be null!"); + Preconditions.checkNotNull(b, "Block cannot be null!"); /* * This will eliminate non-matching base materials If we @@ -106,8 +106,8 @@ public boolean test(@Nonnull Block b) { @ParametersAreNonnullByDefault private boolean hasSurroundingMaterials(Block b, Material... materials) { - Validate.notNull(b, "The Block cannot be null!"); - Validate.notEmpty(materials, "Materials need to have a size of at least one!"); + Preconditions.checkNotNull(b, "The Block cannot be null!"); + Preconditions.checkArgument(materials.length != 0, "Materials need to have a size of at least one!"); boolean[] matches = new boolean[materials.length]; int count = 0; @@ -143,7 +143,7 @@ private boolean hasSurroundingMaterials(Block b, Material... materials) { * @return Our called {@link BlockFormEvent} */ public @Nonnull BlockFormEvent callEvent(@Nonnull Block block) { - Validate.notNull(block, "The Block cannot be null!"); + Preconditions.checkNotNull(block, "The Block cannot be null!"); BlockState state = PaperLib.getBlockState(block, false).getState(); BlockFormEvent event = new BlockFormEvent(block, state); Bukkit.getPluginManager().callEvent(event); @@ -159,7 +159,7 @@ private boolean hasSurroundingMaterials(Block b, Material... materials) { * @return An {@link InfiniteBlockGenerator} or null if none was found. */ public static @Nullable InfiniteBlockGenerator findAt(@Nonnull Block b) { - Validate.notNull(b, "Cannot find a generator without a Location!"); + Preconditions.checkNotNull(b, "Cannot find a generator without a Location!"); for (InfiniteBlockGenerator generator : valuesCached) { if (generator.test(b)) { diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/utils/NumberUtils.java b/src/main/java/io/github/thebusybiscuit/slimefun4/utils/NumberUtils.java index 0b85e6e68d..d89f3387e1 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/utils/NumberUtils.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/utils/NumberUtils.java @@ -11,7 +11,7 @@ import javax.annotation.Nonnull; import javax.annotation.Nullable; -import org.apache.commons.lang.Validate; +import com.google.common.base.Preconditions; import org.bukkit.ChatColor; import io.github.bakedlibs.dough.common.CommonPatterns; @@ -89,7 +89,7 @@ private NumberUtils() {} * @return The {@link LocalDateTime} for the given input */ public static @Nonnull LocalDateTime parseGitHubDate(@Nonnull String date) { - Validate.notNull(date, "Provided date was null"); + Preconditions.checkNotNull(date, "Provided date was null"); return LocalDateTime.parse(date.substring(0, date.length() - 1)); } @@ -155,8 +155,8 @@ private NumberUtils() {} * @return The elapsed time as a {@link String} */ public static @Nonnull String getElapsedTime(@Nonnull LocalDateTime current, @Nonnull LocalDateTime priorDate) { - Validate.notNull(current, "Provided current date was null"); - Validate.notNull(priorDate, "Provided past date was null"); + Preconditions.checkNotNull(current, "Provided current date was null"); + Preconditions.checkNotNull(priorDate, "Provided past date was null"); long hours = Duration.between(priorDate, current).toHours(); diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/utils/SlimefunUtils.java b/src/main/java/io/github/thebusybiscuit/slimefun4/utils/SlimefunUtils.java index a509b207f3..274407abff 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/utils/SlimefunUtils.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/utils/SlimefunUtils.java @@ -11,7 +11,7 @@ import javax.annotation.Nullable; import javax.annotation.ParametersAreNonnullByDefault; -import org.apache.commons.lang.Validate; +import com.google.common.base.Preconditions; import org.bukkit.ChatColor; import org.bukkit.Location; import org.bukkit.Material; @@ -225,7 +225,7 @@ public static boolean isRadioactive(@Nullable ItemStack item) { * @return An {@link ItemStack} with this Head texture */ public static @Nonnull ItemStack getCustomHead(@Nonnull String texture) { - Validate.notNull(texture, "The provided texture is null"); + Preconditions.checkNotNull(texture, "The provided texture is null"); if (Slimefun.instance() == null) { throw new PrematureCodeException("You cannot instantiate a custom head before Slimefun was loaded."); @@ -517,8 +517,8 @@ private static boolean equalsItemMeta(@Nonnull ItemMeta itemMeta, @Nonnull ItemM * @return Whether the two lores are equal */ public static boolean equalsLore(@Nonnull List lore1, @Nonnull List lore2) { - Validate.notNull(lore1, "Cannot compare lore that is null!"); - Validate.notNull(lore2, "Cannot compare lore that is null!"); + Preconditions.checkNotNull(lore1, "Cannot compare lore that is null!"); + Preconditions.checkNotNull(lore2, "Cannot compare lore that is null!"); List longerList = lore1.size() > lore2.size() ? lore1 : lore2; List shorterList = lore1.size() > lore2.size() ? lore2 : lore1; @@ -556,8 +556,8 @@ private static boolean isLineIgnored(@Nonnull String line) { } public static void updateCapacitorTexture(@Nonnull Location l, int charge, int capacity) { - Validate.notNull(l, "Cannot update a texture for null"); - Validate.isTrue(capacity > 0, "Capacity must be greater than zero!"); + Preconditions.checkNotNull(l, "Cannot update a texture for null"); + Preconditions.checkArgument(capacity > 0, "Capacity must be greater than zero!"); Slimefun.runSync(new CapacitorTextureUpdateTask(l, charge, capacity)); } @@ -578,7 +578,7 @@ public static void updateCapacitorTexture(@Nonnull Location l, int charge, int c * @return Whether the {@link Player} is able to use that item. */ public static boolean canPlayerUseItem(@Nonnull Player p, @Nullable ItemStack item, boolean sendMessage) { - Validate.notNull(p, "The player cannot be null"); + Preconditions.checkNotNull(p, "The player cannot be null"); SlimefunItem sfItem = SlimefunItem.getByItem(item); diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/utils/biomes/BiomeMap.java b/src/main/java/io/github/thebusybiscuit/slimefun4/utils/biomes/BiomeMap.java index 872972c687..b4e4f6b12d 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/utils/biomes/BiomeMap.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/utils/biomes/BiomeMap.java @@ -12,7 +12,7 @@ import javax.annotation.Nullable; import javax.annotation.ParametersAreNonnullByDefault; -import org.apache.commons.lang.Validate; +import com.google.common.base.Preconditions; import org.bukkit.Keyed; import org.bukkit.NamespacedKey; import org.bukkit.block.Biome; @@ -60,31 +60,31 @@ public class BiomeMap implements Keyed { */ @ParametersAreNonnullByDefault public BiomeMap(NamespacedKey namespacedKey) { - Validate.notNull(namespacedKey, "The key must not be null."); + Preconditions.checkNotNull(namespacedKey, "The key must not be null."); this.namespacedKey = namespacedKey; } public @Nullable T get(@Nonnull Biome biome) { - Validate.notNull(biome, "The biome shall not be null."); + Preconditions.checkNotNull(biome, "The biome shall not be null."); return dataMap.get(biome); } public @Nonnull T getOrDefault(@Nonnull Biome biome, T defaultValue) { - Validate.notNull(biome, "The biome should not be null."); + Preconditions.checkNotNull(biome, "The biome should not be null."); return dataMap.getOrDefault(biome, defaultValue); } public boolean containsKey(@Nonnull Biome biome) { - Validate.notNull(biome, "The biome must not be null."); + Preconditions.checkNotNull(biome, "The biome must not be null."); return dataMap.containsKey(biome); } public boolean containsValue(@Nonnull T value) { - Validate.notNull(value, "The value must not be null."); + Preconditions.checkNotNull(value, "The value must not be null."); return dataMap.containsValue(value); } @@ -100,26 +100,26 @@ public boolean isEmpty() { } public boolean put(@Nonnull Biome biome, @Nonnull T value) { - Validate.notNull(biome, "The biome should not be null."); - Validate.notNull(value, "Values cannot be null."); + Preconditions.checkNotNull(biome, "The biome should not be null."); + Preconditions.checkNotNull(value, "Values cannot be null."); return dataMap.put(biome, value) == null; } public void putAll(@Nonnull Map map) { - Validate.notNull(map, "The map should not be null."); + Preconditions.checkNotNull(map, "The map should not be null."); dataMap.putAll(map); } public void putAll(@Nonnull BiomeMap map) { - Validate.notNull(map, "The map should not be null."); + Preconditions.checkNotNull(map, "The map should not be null."); dataMap.putAll(map.dataMap); } public boolean remove(@Nonnull Biome biome) { - Validate.notNull(biome, "The biome cannot be null."); + Preconditions.checkNotNull(biome, "The biome cannot be null."); return dataMap.remove(biome) != null; } @@ -162,9 +162,9 @@ public static BiomeMap fromJson(NamespacedKey key, String json, BiomeData @Nonnull @ParametersAreNonnullByDefault public static BiomeMap fromResource(NamespacedKey key, JavaPlugin plugin, String path, BiomeDataConverter valueConverter) throws BiomeMapException { - Validate.notNull(key, "The key shall not be null."); - Validate.notNull(plugin, "The plugin shall not be null."); - Validate.notNull(path, "The path should not be null!"); + Preconditions.checkNotNull(key, "The key shall not be null."); + Preconditions.checkNotNull(plugin, "The plugin shall not be null."); + Preconditions.checkNotNull(path, "The path should not be null!"); try (BufferedReader reader = new BufferedReader(new InputStreamReader(plugin.getClass().getResourceAsStream(path), StandardCharsets.UTF_8))) { return fromJson(key, reader.lines().collect(Collectors.joining("")), valueConverter); diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/utils/biomes/BiomeMapParser.java b/src/main/java/io/github/thebusybiscuit/slimefun4/utils/biomes/BiomeMapParser.java index 62d345acf8..8ab63384ee 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/utils/biomes/BiomeMapParser.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/utils/biomes/BiomeMapParser.java @@ -9,7 +9,7 @@ import javax.annotation.Nonnull; import javax.annotation.ParametersAreNonnullByDefault; -import org.apache.commons.lang.Validate; +import com.google.common.base.Preconditions; import org.bukkit.NamespacedKey; import org.bukkit.block.Biome; @@ -62,8 +62,8 @@ public class BiomeMapParser { */ @ParametersAreNonnullByDefault public BiomeMapParser(NamespacedKey key, BiomeDataConverter valueConverter) { - Validate.notNull(key, "The key shall not be null."); - Validate.notNull(valueConverter, "You must provide a Function to convert raw json values to your desired data type."); + Preconditions.checkNotNull(key, "The key shall not be null."); + Preconditions.checkNotNull(valueConverter, "You must provide a Function to convert raw json values to your desired data type."); this.key = key; this.valueConverter = valueConverter; @@ -97,7 +97,7 @@ public boolean isLenient() { } public void read(@Nonnull String json) throws BiomeMapException { - Validate.notNull(json, "The JSON string should not be null!"); + Preconditions.checkNotNull(json, "The JSON string should not be null!"); JsonArray root = null; try { @@ -114,7 +114,7 @@ public void read(@Nonnull String json) throws BiomeMapException { } public void read(@Nonnull JsonArray json) throws BiomeMapException { - Validate.notNull(json, "The JSON Array should not be null!"); + Preconditions.checkNotNull(json, "The JSON Array should not be null!"); for (JsonElement element : json) { if (element instanceof JsonObject) { @@ -126,7 +126,7 @@ public void read(@Nonnull JsonArray json) throws BiomeMapException { } private void readEntry(@Nonnull JsonObject entry) throws BiomeMapException { - Validate.notNull(entry, "The JSON entry should not be null!"); + Preconditions.checkNotNull(entry, "The JSON entry should not be null!"); /* * Check if the entry has a "value" element. @@ -158,7 +158,7 @@ private void readEntry(@Nonnull JsonObject entry) throws BiomeMapException { } private @Nonnull Set readBiomes(@Nonnull JsonArray array) throws BiomeMapException { - Validate.notNull(array, "The JSON array should not be null!"); + Preconditions.checkNotNull(array, "The JSON array should not be null!"); Set biomes = EnumSet.noneOf(Biome.class); for (JsonElement element : array) { diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/utils/itemstack/ItemStackWrapper.java b/src/main/java/io/github/thebusybiscuit/slimefun4/utils/itemstack/ItemStackWrapper.java index 9091db07b8..8cb4f2a580 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/utils/itemstack/ItemStackWrapper.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/utils/itemstack/ItemStackWrapper.java @@ -5,7 +5,7 @@ import javax.annotation.Nonnull; -import org.apache.commons.lang.Validate; +import com.google.common.base.Preconditions; import org.bukkit.Material; import org.bukkit.enchantments.Enchantment; import org.bukkit.inventory.ItemStack; @@ -114,7 +114,7 @@ public void addUnsafeEnchantment(Enchantment ench, int level) { * @see #wrap(ItemStack) */ public static @Nonnull ItemStackWrapper forceWrap(@Nonnull ItemStack itemStack) { - Validate.notNull(itemStack, "The ItemStack cannot be null!"); + Preconditions.checkNotNull(itemStack, "The ItemStack cannot be null!"); return new ItemStackWrapper(itemStack); } @@ -130,7 +130,7 @@ public void addUnsafeEnchantment(Enchantment ench, int level) { * @see #forceWrap(ItemStack) */ public static @Nonnull ItemStackWrapper wrap(@Nonnull ItemStack itemStack) { - Validate.notNull(itemStack, "The ItemStack cannot be null!"); + Preconditions.checkNotNull(itemStack, "The ItemStack cannot be null!"); if (itemStack instanceof ItemStackWrapper wrapper) { return wrapper; @@ -148,7 +148,7 @@ public void addUnsafeEnchantment(Enchantment ench, int level) { * @return An {@link ItemStackWrapper} array */ public static @Nonnull ItemStackWrapper[] wrapArray(@Nonnull ItemStack[] items) { - Validate.notNull(items, "The array must not be null!"); + Preconditions.checkNotNull(items, "The array must not be null!"); ItemStackWrapper[] array = new ItemStackWrapper[items.length]; @@ -170,7 +170,7 @@ public void addUnsafeEnchantment(Enchantment ench, int level) { * @return An {@link ItemStackWrapper} array */ public static @Nonnull List wrapList(@Nonnull List items) { - Validate.notNull(items, "The list must not be null!"); + Preconditions.checkNotNull(items, "The list must not be null!"); List list = new ArrayList<>(items.size()); for (ItemStack item : items) { diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/utils/tags/SlimefunTag.java b/src/main/java/io/github/thebusybiscuit/slimefun4/utils/tags/SlimefunTag.java index 7962c7b027..92473b5dff 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/utils/tags/SlimefunTag.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/utils/tags/SlimefunTag.java @@ -13,7 +13,7 @@ import javax.annotation.Nullable; import io.github.thebusybiscuit.slimefun4.implementation.items.autocrafters.AbstractAutoCrafter; -import org.apache.commons.lang.Validate; +import com.google.common.base.Preconditions; import org.bukkit.Material; import org.bukkit.NamespacedKey; import org.bukkit.Tag; @@ -435,7 +435,7 @@ public boolean isEmpty() { * @return The {@link SlimefunTag} or null if it does not exist. */ public static @Nullable SlimefunTag getTag(@Nonnull String value) { - Validate.notNull(value, "A tag cannot be null!"); + Preconditions.checkNotNull(value, "A tag cannot be null!"); return nameLookup.get(value); } diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/utils/tags/TagParser.java b/src/main/java/io/github/thebusybiscuit/slimefun4/utils/tags/TagParser.java index 76ef463645..aa2ba8d76d 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/utils/tags/TagParser.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/utils/tags/TagParser.java @@ -14,7 +14,7 @@ import javax.annotation.Nonnull; import javax.annotation.ParametersAreNonnullByDefault; -import org.apache.commons.lang.Validate; +import com.google.common.base.Preconditions; import org.bukkit.Bukkit; import org.bukkit.Keyed; import org.bukkit.Material; @@ -93,7 +93,7 @@ void parse(@Nonnull SlimefunTag tag, @Nonnull BiConsumer, Set, Set>> callback) throws TagMisconfigurationException { - Validate.notNull(json, "Cannot parse a null String"); + Preconditions.checkNotNull(json, "Cannot parse a null String"); try { Set materials = EnumSet.noneOf(Material.class); diff --git a/src/main/java/me/mrCookieSlime/Slimefun/Objects/SlimefunItem/abstractItems/AContainer.java b/src/main/java/me/mrCookieSlime/Slimefun/Objects/SlimefunItem/abstractItems/AContainer.java index 04747b4f84..e6b3041f42 100644 --- a/src/main/java/me/mrCookieSlime/Slimefun/Objects/SlimefunItem/abstractItems/AContainer.java +++ b/src/main/java/me/mrCookieSlime/Slimefun/Objects/SlimefunItem/abstractItems/AContainer.java @@ -8,7 +8,7 @@ import javax.annotation.Nonnull; import javax.annotation.ParametersAreNonnullByDefault; -import org.apache.commons.lang.Validate; +import com.google.common.base.Preconditions; import org.bukkit.Location; import org.bukkit.Material; import org.bukkit.block.Block; @@ -179,7 +179,7 @@ public int getSpeed() { * @return This method will return the current instance of {@link AContainer}, so that can be chained. */ public final AContainer setCapacity(int capacity) { - Validate.isTrue(capacity > 0, "The capacity must be greater than zero!"); + Preconditions.checkArgument(capacity > 0, "The capacity must be greater than zero!"); if (getState() == ItemState.UNREGISTERED) { this.energyCapacity = capacity; @@ -198,7 +198,7 @@ public final AContainer setCapacity(int capacity) { * @return This method will return the current instance of {@link AContainer}, so that can be chained. */ public final AContainer setProcessingSpeed(int speed) { - Validate.isTrue(speed > 0, "The speed must be greater than zero!"); + Preconditions.checkArgument(speed > 0, "The speed must be greater than zero!"); this.processingSpeed = speed; return this; @@ -213,9 +213,9 @@ public final AContainer setProcessingSpeed(int speed) { * @return This method will return the current instance of {@link AContainer}, so that can be chained. */ public final AContainer setEnergyConsumption(int energyConsumption) { - Validate.isTrue(energyConsumption > 0, "The energy consumption must be greater than zero!"); - Validate.isTrue(energyCapacity > 0, "You must specify the capacity before you can set the consumption amount."); - Validate.isTrue(energyConsumption <= energyCapacity, "The energy consumption cannot be higher than the capacity (" + energyCapacity + ')'); + Preconditions.checkArgument(energyConsumption > 0, "The energy consumption must be greater than zero!"); + Preconditions.checkArgument(energyCapacity > 0, "You must specify the capacity before you can set the consumption amount."); + Preconditions.checkArgument(energyConsumption <= energyCapacity, "The energy consumption cannot be higher than the capacity (" + energyCapacity + ')'); this.energyConsumedPerTick = energyConsumption; return this; @@ -374,7 +374,7 @@ protected void tick(Block b) { * @return Whether charge was taken if its chargeable */ protected boolean takeCharge(@Nonnull Location l) { - Validate.notNull(l, "Can't attempt to take charge from a null location!"); + Preconditions.checkNotNull(l, "Can't attempt to take charge from a null location!"); if (isChargeable()) { int charge = getCharge(l); diff --git a/src/main/java/me/mrCookieSlime/Slimefun/Objects/SlimefunItem/abstractItems/AGenerator.java b/src/main/java/me/mrCookieSlime/Slimefun/Objects/SlimefunItem/abstractItems/AGenerator.java index db5555f6c9..4acb76fd0e 100644 --- a/src/main/java/me/mrCookieSlime/Slimefun/Objects/SlimefunItem/abstractItems/AGenerator.java +++ b/src/main/java/me/mrCookieSlime/Slimefun/Objects/SlimefunItem/abstractItems/AGenerator.java @@ -7,7 +7,7 @@ import javax.annotation.Nullable; import javax.annotation.ParametersAreNonnullByDefault; -import org.apache.commons.lang.Validate; +import com.google.common.base.Preconditions; import org.bukkit.Location; import org.bukkit.Material; import org.bukkit.block.Block; @@ -237,7 +237,7 @@ public int getEnergyProduction() { * @return This method will return the current instance of {@link AGenerator}, so that can be chained. */ public final AGenerator setCapacity(int capacity) { - Validate.isTrue(capacity >= 0, "The capacity cannot be negative!"); + Preconditions.checkArgument(capacity >= 0, "The capacity cannot be negative!"); if (getState() == ItemState.UNREGISTERED) { this.energyCapacity = capacity; @@ -256,7 +256,7 @@ public final AGenerator setCapacity(int capacity) { * @return This method will return the current instance of {@link AGenerator}, so that can be chained. */ public final AGenerator setEnergyProduction(int energyProduced) { - Validate.isTrue(energyProduced > 0, "The energy production must be greater than zero!"); + Preconditions.checkArgument(energyProduced > 0, "The energy production must be greater than zero!"); this.energyProducedPerTick = energyProduced; return this; diff --git a/src/main/java/me/mrCookieSlime/Slimefun/Objects/SlimefunItem/abstractItems/MachineFuel.java b/src/main/java/me/mrCookieSlime/Slimefun/Objects/SlimefunItem/abstractItems/MachineFuel.java index b333bde74f..1bafc3a509 100644 --- a/src/main/java/me/mrCookieSlime/Slimefun/Objects/SlimefunItem/abstractItems/MachineFuel.java +++ b/src/main/java/me/mrCookieSlime/Slimefun/Objects/SlimefunItem/abstractItems/MachineFuel.java @@ -2,7 +2,7 @@ import java.util.function.Predicate; -import org.apache.commons.lang.Validate; +import com.google.common.base.Preconditions; import org.bukkit.inventory.ItemStack; import io.github.thebusybiscuit.slimefun4.utils.SlimefunUtils; @@ -23,8 +23,8 @@ public MachineFuel(int seconds, ItemStack fuel) { } public MachineFuel(int seconds, ItemStack fuel, ItemStack output) { - Validate.notNull(fuel, "Fuel must never be null!"); - Validate.isTrue(seconds > 0, "Fuel must last at least one second!"); + Preconditions.checkNotNull(fuel, "Fuel must never be null!"); + Preconditions.checkArgument(seconds > 0, "Fuel must last at least one second!"); this.ticks = seconds * 2; this.fuel = fuel; diff --git a/src/main/java/me/mrCookieSlime/Slimefun/api/BlockStorage.java b/src/main/java/me/mrCookieSlime/Slimefun/api/BlockStorage.java index c2df4fd2c9..73c84d1749 100644 --- a/src/main/java/me/mrCookieSlime/Slimefun/api/BlockStorage.java +++ b/src/main/java/me/mrCookieSlime/Slimefun/api/BlockStorage.java @@ -18,7 +18,7 @@ import javax.annotation.Nullable; import javax.annotation.ParametersAreNonnullByDefault; -import org.apache.commons.lang.Validate; +import com.google.common.base.Preconditions; import org.bukkit.Bukkit; import org.bukkit.Chunk; import org.bukkit.Location; @@ -402,7 +402,7 @@ public Map getRawStorage() { */ @Nullable public static Map getRawStorage(@Nonnull World world) { - Validate.notNull(world, "World cannot be null!"); + Preconditions.checkNotNull(world, "World cannot be null!"); BlockStorage storage = getStorage(world); if (storage != null) { diff --git a/src/main/java/me/mrCookieSlime/Slimefun/api/inventory/BlockMenuPreset.java b/src/main/java/me/mrCookieSlime/Slimefun/api/inventory/BlockMenuPreset.java index 1ef479341f..33d1144798 100644 --- a/src/main/java/me/mrCookieSlime/Slimefun/api/inventory/BlockMenuPreset.java +++ b/src/main/java/me/mrCookieSlime/Slimefun/api/inventory/BlockMenuPreset.java @@ -6,7 +6,7 @@ import javax.annotation.Nonnull; import javax.annotation.Nullable; -import org.apache.commons.lang.Validate; +import com.google.common.base.Preconditions; import org.bukkit.Location; import org.bukkit.block.Block; import org.bukkit.entity.Player; @@ -41,7 +41,7 @@ protected BlockMenuPreset(@Nonnull String id, @Nonnull String title) { protected BlockMenuPreset(@Nonnull String id, @Nonnull String title, boolean universal) { super(title); - Validate.notNull(id, "You need to specify an id!"); + Preconditions.checkNotNull(id, "You need to specify an id!"); this.id = id; this.inventoryTitle = title; @@ -119,7 +119,7 @@ public void replaceExistingItem(int slot, ItemStack item) { * The slots which should be treated as background */ public void drawBackground(@Nonnull ItemStack item, @Nonnull int[] slots) { - Validate.notNull(item, "The background item cannot be null!"); + Preconditions.checkNotNull(item, "The background item cannot be null!"); checkIfLocked(); for (int slot : slots) { @@ -248,7 +248,7 @@ protected void clone(@Nonnull DirtyChestMenu menu) { } public void newInstance(@Nonnull BlockMenu menu, @Nonnull Location l) { - Validate.notNull(l, "Cannot create a new BlockMenu without a Location"); + Preconditions.checkNotNull(l, "Cannot create a new BlockMenu without a Location"); Slimefun.runSync(() -> { locked = true; diff --git a/src/test/java/io/github/thebusybiscuit/slimefun4/core/services/localization/AbstractLocaleRegexChecker.java b/src/test/java/io/github/thebusybiscuit/slimefun4/core/services/localization/AbstractLocaleRegexChecker.java index df8668f285..570addff81 100644 --- a/src/test/java/io/github/thebusybiscuit/slimefun4/core/services/localization/AbstractLocaleRegexChecker.java +++ b/src/test/java/io/github/thebusybiscuit/slimefun4/core/services/localization/AbstractLocaleRegexChecker.java @@ -15,7 +15,7 @@ import javax.annotation.Nullable; import javax.annotation.ParametersAreNonnullByDefault; -import org.apache.commons.lang.Validate; +import com.google.common.base.Preconditions; import org.bukkit.configuration.InvalidConfigurationException; import org.bukkit.configuration.file.FileConfiguration; import org.bukkit.configuration.file.YamlConfiguration; @@ -31,7 +31,7 @@ class AbstractLocaleRegexChecker { private final Pattern pattern; AbstractLocaleRegexChecker(@Nonnull Pattern pattern) { - Validate.notNull(pattern, "The pattern cannot be null."); + Preconditions.checkNotNull(pattern, "The pattern cannot be null."); this.pattern = pattern; }