diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/api/events/AncientAltarCraftEvent.java b/src/main/java/io/github/thebusybiscuit/slimefun4/api/events/AncientAltarCraftEvent.java index e871a02248..f49c6f788a 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/api/events/AncientAltarCraftEvent.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/api/events/AncientAltarCraftEvent.java @@ -68,10 +68,6 @@ public ItemStack getItem() { * being the {@link ItemStack} you want to change the item to. */ public void setItem(ItemStack output) { - if (output == null || output.getType() == Material.AIR) { - throw new IllegalArgumentException("An Ancient Altar cannot drop 'null' items"); - } - this.output = output; } 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 f596aa97f7..e7324ed72d 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 @@ -28,12 +28,9 @@ public class ItemSetting { /** * This creates a new {@link ItemSetting} with the given key and default value * - * @param item - * The {@link SlimefunItem} this {@link ItemSetting} belongs to - * @param key - * The key under which this setting will be stored (relative to the {@link SlimefunItem}) - * @param defaultValue - * The default value for this {@link ItemSetting} + * @param item The {@link SlimefunItem} this {@link ItemSetting} belongs to + * @param key The key under which this setting will be stored (relative to the {@link SlimefunItem}) + * @param defaultValue The default value for this {@link ItemSetting} */ public ItemSetting(SlimefunItem item, String key, T defaultValue) { this.item = item; @@ -45,9 +42,7 @@ public ItemSetting(SlimefunItem item, String key, T defaultValue) { * This method checks if a given input would be valid as a value for this * {@link ItemSetting}. You can override this method to implement your own checks. * - * @param input - * The input value to validate - * + * @param input The input value to validate * @return Whether the given input was valid */ public boolean validateInput(T input) { @@ -59,17 +54,10 @@ public boolean validateInput(T input) { * Override this method to catch changes of a value. * A value may never be null. * - * @param newValue - * The new value for this {@link ItemSetting} + * @param newValue The new value for this {@link ItemSetting} */ public void update(T newValue) { - if (validateInput(newValue)) { - this.value = newValue; - } else { - throw new IllegalArgumentException("The passed value was not valid. (Maybe null?)"); - } - - // Feel free to override this as necessary. + this.value = newValue; } /** @@ -105,9 +93,7 @@ public T getValue() { /** * This method checks if this {@link ItemSetting} stores the given data type. * - * @param c - * The class of data type you want to compare - * + * @param c The class of data type you want to compare * @return Whether this {@link ItemSetting} stores the given type */ public boolean isType(Class c) { @@ -127,7 +113,6 @@ protected String getErrorMessage() { /** * This method is called by a {@link SlimefunItem} which wants to load its {@link ItemSetting} * from the {@link Config} file. - * */ @SuppressWarnings("unchecked") public void reload() { @@ -143,16 +128,16 @@ public void reload() { this.value = newValue; } else { item.warn("发现在 Items.yml 中有无效的物品设置!" - + "\n 在 \"" - + item.getId() - + "." - + getKey() - + "\"" - + "\n " - + configuredValue - + " 不是一个有效值!" - + "\n" - + getErrorMessage()); + + "\n 在 \"" + + item.getId() + + "." + + getKey() + + "\"" + + "\n " + + configuredValue + + " 不是一个有效值!" + + "\n" + + getErrorMessage()); } } else { @@ -162,17 +147,17 @@ public void reload() { : configuredValue.getClass().getSimpleName(); item.warn("发现在 Items.yml 中有无效的物品设置!" - + "\n请只设置有效的值." - + "\n 在 \"" - + item.getId() - + "." - + getKey() - + "\"" - + "\n 期望值为 \"" - + defaultValue.getClass().getSimpleName() - + "\" 但填写了: \"" - + found - + "\""); + + "\n请只设置有效的值." + + "\n 在 \"" + + item.getId() + + "." + + getKey() + + "\"" + + "\n 期望值为 \"" + + defaultValue.getClass().getSimpleName() + + "\" 但填写了: \"" + + found + + "\""); } } 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 69dc448ff4..b41c7f885b 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 @@ -337,10 +337,6 @@ public boolean isDisabledIn(World world) { * @return The {@link SlimefunAddon} that registered this {@link SlimefunItem} */ public final SlimefunAddon getAddon() { - if (addon == null) { - throw new UnregisteredItemException(this); - } - return addon; } 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 b2a8a60286..3c5c40467b 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 @@ -105,12 +105,6 @@ public void register(SlimefunAddon addon) { * @see #removeParent(ItemGroup) */ public void addParent(ItemGroup group) { - if (group == this || group == null) { - throw new IllegalArgumentException("ItemGroup '" - + item.getItemMeta().getDisplayName() - + "' cannot be a parent of itself or have a 'null' parent."); - } - parents.add(group); } diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/api/player/PlayerBackpack.java b/src/main/java/io/github/thebusybiscuit/slimefun4/api/player/PlayerBackpack.java index 31d5467ce6..5fe45aba17 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/api/player/PlayerBackpack.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/api/player/PlayerBackpack.java @@ -173,7 +173,7 @@ public static void bindItem(ItemStack item, PlayerBackpack bp) { } public static void setItemDisplayInfo(ItemStack item, PlayerBackpack bp) { - var meta = item.getItemMeta(); + ItemMeta meta = item.getItemMeta(); setItem(meta, bp); item.setItemMeta(meta); } @@ -210,10 +210,6 @@ private static void setItem(ItemMeta meta, PlayerBackpack bp) { public PlayerBackpack( OfflinePlayer owner, UUID uuid, String name, int id, int size, @Nullable ItemStack[] contents) { - if (size < 9 || size > 54 || size % 9 != 0) { - throw new IllegalArgumentException("Invalid size! Size must be one of: [9, 18, 27, 36, 45, 54]"); - } - this.owner = owner; this.uuid = uuid; this.name = name; @@ -225,9 +221,6 @@ public PlayerBackpack( return; } - if (size != contents.length) { - throw new IllegalArgumentException("Invalid contents: size mismatched!"); - } inventory.setContents(contents); } @@ -263,10 +256,6 @@ public void open(Player p) { * The new size for this Backpack */ public void setSize(int size) { - if (size < 9 || size > 54 || size % 9 != 0) { - throw new IllegalArgumentException("Invalid size! Size must be one of: [9, 18, 27, 36, 45, 54]"); - } - this.size = size; updateInv(); Slimefun.getDatabaseManager().getProfileDataController().saveBackpackInfo(this); 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 3bec5d81ae..6431c04af9 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 @@ -38,6 +38,11 @@ public class Research implements Keyed { private final int id; private final String name; private boolean enabled = true; + /** + * -- SETTER -- + * Sets the cost in XP levels to unlock this + */ + @Setter @Getter private int levelCost; @Setter @@ -161,26 +166,9 @@ public int getCost() { */ @Deprecated public void setCost(int cost) { - if (levelCost < 0) { - throw new IllegalArgumentException("Research cost must be zero or greater!"); - } - levelCost = cost; } - /** - * Sets the cost in XP levels to unlock this {@link Research}. - * - * @param levelCost The cost in XP levels - */ - public void setLevelCost(int levelCost) { - if (levelCost < 0) { - throw new IllegalArgumentException("Research cost must be zero or greater!"); - } - - this.levelCost = levelCost; - } - /** * Bind the specified {@link SlimefunItem SlimefunItems} to this {@link Research}. * 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 c9b104bf3f..b9653a9f41 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 @@ -44,16 +44,8 @@ public interface Rechargeable extends ItemAttribute { * The amount of charge to store */ default void setItemCharge(ItemStack item, float charge) { - if (item == null || item.getType() == Material.AIR) { - throw new IllegalArgumentException("Cannot set Item charge for null or AIR"); - } - float maximum = getMaxItemCharge(item); - if (charge < 0 || charge > maximum) { - throw new IllegalArgumentException("Charge must be between zero and " + maximum + "."); - } - ItemMeta meta = item.getItemMeta(); ChargeUtils.setCharge(meta, charge, maximum); item.setItemMeta(meta); @@ -68,10 +60,6 @@ default void setItemCharge(ItemStack item, float charge) { * @return The charge stored on this {@link ItemStack} */ default float getItemCharge(ItemStack item) { - if (item == null || item.getType() == Material.AIR) { - throw new IllegalArgumentException("Cannot get Item charge for null or AIR"); - } - return ChargeUtils.getCharge(item.getItemMeta()); } @@ -96,10 +84,6 @@ default float getDistanceToMaxCharge(ItemStack item) { * @return Whether the given charge could be added successfully */ default boolean addItemCharge(ItemStack item, float charge) { - if (item == null || item.getType() == Material.AIR) { - throw new IllegalArgumentException("Cannot add Item charge for null or AIR"); - } - ItemMeta meta = item.getItemMeta(); float currentCharge = ChargeUtils.getCharge(meta); float maximum = getMaxItemCharge(item); @@ -128,10 +112,6 @@ default boolean addItemCharge(ItemStack item, float charge) { * @return Whether the given charge could be removed successfully */ default boolean removeItemCharge(ItemStack item, float charge) { - if (item == null || item.getType() == Material.AIR) { - throw new IllegalArgumentException("Cannot remove Item charge for null or AIR"); - } - ItemMeta meta = item.getItemMeta(); float currentCharge = ChargeUtils.getCharge(meta); 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 83296dee69..d3cfbb3d46 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 @@ -49,14 +49,6 @@ public static Set> getSupportedTags() { private final boolean isSymmetric; public MultiBlock(SlimefunItem item, Material[] build, BlockFace trigger) { - if (build == null || build.length != 9) { - throw new IllegalArgumentException("MultiBlocks must have a length of 9!"); - } - - if (trigger != BlockFace.SELF && trigger != BlockFace.UP && trigger != BlockFace.DOWN) { - throw new IllegalArgumentException("Multiblock Blockface must be either UP, DOWN or SELF"); - } - this.item = item; this.blocks = build; this.trigger = trigger; 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 7a51cceee5..b8d196066e 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 @@ -27,7 +27,6 @@ * This service is responsible for handling holograms. * * @author TheBusyBiscuit - * * @see HologramOwner */ public class HologramsService { @@ -66,8 +65,7 @@ public class HologramsService { /** * This constructs a new {@link HologramsService}. * - * @param plugin - * Our {@link Plugin} instance + * @param plugin Our {@link Plugin} instance */ public HologramsService(Plugin plugin) { this.plugin = plugin; @@ -96,14 +94,12 @@ private void purge() { * If createIfNoneExists is set to true a new {@link ArmorStand} will be spawned * if no existing one could be found. * - * @param loc - * The {@link Location} - * @param createIfNoneExists - * Whether to create a new {@link ArmorStand} if none was found - * + * @param loc The {@link Location} + * @param createIfNoneExists Whether to create a new {@link ArmorStand} if none was found * @return The existing (or newly created) hologram */ - @Nullable private Hologram getHologram(Location loc, boolean createIfNoneExists) { + @Nullable + private Hologram getHologram(Location loc, boolean createIfNoneExists) { BlockPosition position = new BlockPosition(loc); Hologram hologram = cache.get(position); @@ -158,9 +154,7 @@ private boolean hasHologramData(PersistentDataContainer container, BlockPosition * This checks if a given {@link Entity} is an {@link ArmorStand} * and whether it has the correct attributes to be considered a {@link Hologram}. * - * @param n - * The {@link Entity} to check - * + * @param n The {@link Entity} to check * @return Whether this could be a hologram */ private boolean isHologram(Entity n) { @@ -176,16 +170,13 @@ private boolean isHologram(Entity n) { * This will cast the {@link Entity} to an {@link ArmorStand} and it will apply * all necessary attributes to the {@link ArmorStand}, then return a {@link Hologram}. * - * @param position - * The {@link BlockPosition} of this hologram - * @param entity - * The {@link Entity} - * @param container - * The {@link PersistentDataContainer} of the given {@link Entity} - * + * @param position The {@link BlockPosition} of this hologram + * @param entity The {@link Entity} + * @param container The {@link PersistentDataContainer} of the given {@link Entity} * @return The {@link Hologram} */ - @Nullable private Hologram getAsHologram( + @Nullable + private Hologram getAsHologram( BlockPosition position, Entity entity, PersistentDataContainer container) { if (entity instanceof ArmorStand armorStand) { armorStand.setVisible(false); @@ -216,10 +207,8 @@ private boolean isHologram(Entity n) { *

* This method must be executed on the main {@link Server} {@link Thread}. * - * @param loc - * The {@link Location} - * @param consumer - * The callback to run + * @param loc The {@link Location} + * @param consumer The callback to run */ private void updateHologram(Location loc, Consumer consumer) { Runnable runnable = () -> { @@ -247,41 +236,33 @@ private void updateHologram(Location loc, Consumer consumer) { *

* This method must be executed on the main {@link Server} {@link Thread}. * - * @param loc - * The {@link Location} - * + * @param loc The {@link Location} * @return Whether the {@link Hologram} could be removed, false if the {@link Hologram} does not - * exist or was already removed + * exist or was already removed */ public boolean removeHologram(Location loc) { - if (Bukkit.isPrimaryThread()) { - try { - Hologram hologram = getHologram(loc, false); + try { + Hologram hologram = getHologram(loc, false); - if (hologram != null) { - cache.remove(new BlockPosition(loc)); - hologram.remove(); - return true; - } else { - return false; - } - } catch (RuntimeException | LinkageError x) { - Slimefun.logger().log(Level.SEVERE, "Hologram located at {0}", new BlockPosition(loc)); - Slimefun.logger().log(Level.SEVERE, "Something went wrong while trying to remove this hologram", x); + if (hologram != null) { + cache.remove(new BlockPosition(loc)); + hologram.remove(); + return true; + } else { return false; } - } else { - throw new UnsupportedOperationException("You cannot remove a hologram asynchronously."); + } catch (RuntimeException | LinkageError x) { + Slimefun.logger().log(Level.SEVERE, "Hologram located at {0}", new BlockPosition(loc)); + Slimefun.logger().log(Level.SEVERE, "Something went wrong while trying to remove this hologram", x); + return false; } } /** * This will update the label of the {@link Hologram}. * - * @param loc - * The {@link Location} of this {@link Hologram} - * @param label - * The label to set, can be null + * @param loc The {@link Location} of this {@link Hologram} + * @param label The label to set, can be null */ public void setHologramLabel(Location loc, @Nullable String label) { updateHologram(loc, hologram -> hologram.setLabel(label)); diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/listeners/BlockListener.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/listeners/BlockListener.java index ea0f97f8bd..235b6e38ad 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/listeners/BlockListener.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/listeners/BlockListener.java @@ -129,7 +129,7 @@ public void onBlockPlace(BlockPlaceEvent e) { block.setBlockData(rotatable); } } - var placeEvent = new SlimefunBlockPlaceEvent(e.getPlayer(), item, block, sfItem); + SlimefunBlockPlaceEvent placeEvent = new SlimefunBlockPlaceEvent(e.getPlayer(), item, block, sfItem); Bukkit.getPluginManager().callEvent(placeEvent); if (placeEvent.isCancelled()) { @@ -144,12 +144,7 @@ public void onBlockPlace(BlockPlaceEvent e) { .createBlock(block.getLocation(), sfItem.getId()); if (data instanceof SlimefunUniversalBlockData) { - if (Slimefun.getBlockDataService().isTileEntity(block.getType())) { - Slimefun.getBlockDataService().updateUniversalDataUUID(block, data.getKey()); - } else { - throw new IllegalStateException( - "You must use pdc support material for this Slimefun item!"); - } + Slimefun.getBlockDataService().updateUniversalDataUUID(block, data.getKey()); } sfItem.callItemHandler(BlockPlaceHandler.class, handler -> handler.onPlayerPlace(e)); 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 8e2ad07dd7..c97bdcc4a7 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/utils/SlimefunUtils.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/utils/SlimefunUtils.java @@ -151,10 +151,6 @@ private static boolean hasSoulboundFlag(@Nullable ItemMeta meta) { * @see #isSoulbound(ItemStack) */ public static void setSoulbound(@Nullable ItemStack item, boolean makeSoulbound) { - if (item == null || item.getType() == Material.AIR) { - throw new IllegalArgumentException("A soulbound item cannot be null or air!"); - } - boolean isSoulbound = isSoulbound(item); ItemMeta meta = item.getItemMeta(); diff --git a/src/main/java/me/mrCookieSlime/CSCoreLibPlugin/general/Inventory/ChestMenu.java b/src/main/java/me/mrCookieSlime/CSCoreLibPlugin/general/Inventory/ChestMenu.java index ab3a3b1576..9e774a52e9 100644 --- a/src/main/java/me/mrCookieSlime/CSCoreLibPlugin/general/Inventory/ChestMenu.java +++ b/src/main/java/me/mrCookieSlime/CSCoreLibPlugin/general/Inventory/ChestMenu.java @@ -363,32 +363,26 @@ public int getSize() { } public ChestMenu setSize(int size) { - if (size % 9 == 0 && size >= 0 && size < 55) { - // Resize items list to match actual inventory size in order to reset inventory. - // I'm sure that use size of items as inventory size is somehow strange. - if (size > items.size()) { - while (items.size() < size) { - this.items.add(null); - } - } else if (size < items.size()) { - while (items.size() > size) { - this.items.remove(items.size() - 1); - } - } else { - return this; + // Resize items list to match actual inventory size in order to reset inventory. + // I'm sure that use size of items as inventory size is somehow strange. + if (size > items.size()) { + while (items.size() < size) { + this.items.add(null); } + } else if (size < items.size()) { + while (items.size() > size) { + this.items.remove(items.size() - 1); + } + } else { + return this; + } - this.size = size; + this.size = size; - reset(false); + reset(false); + + return this; - return this; - } else { - throw new IllegalArgumentException( - "The size of a ChestMenu must be a multiple of 9 and within the bounds 0-54," - + " received: " - + size); - } } public boolean isSizeAutomaticallyInferred() { 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 10abebf640..a0f91cac9e 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 @@ -188,12 +188,8 @@ 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) { - if (getState() == ItemState.UNREGISTERED) { - this.energyCapacity = capacity; - return this; - } else { - throw new IllegalStateException("You cannot modify the capacity after the Item was registered."); - } + this.energyCapacity = capacity; + return this; } /** @@ -222,23 +218,6 @@ public final AContainer setEnergyConsumption(int energyConsumption) { public void register(SlimefunAddon addon) { this.addon = addon; - if (getCapacity() <= 0) { - warn("The capacity has not been configured correctly. The Item was disabled."); - warn("Make sure to call '" + getClass().getSimpleName() + "#setEnergyCapacity(...)' before registering!"); - } - - if (getEnergyConsumption() <= 0) { - warn("The energy consumption has not been configured correctly. The Item was disabled."); - warn("Make sure to call '" - + getClass().getSimpleName() - + "#setEnergyConsumption(...)' before registering!"); - } - - if (getSpeed() <= 0) { - warn("The processing speed has not been configured correctly. The Item was disabled."); - warn("Make sure to call '" + getClass().getSimpleName() + "#setProcessingSpeed(...)' before registering!"); - } - if (getCapacity() > 0 && getEnergyConsumption() > 0 && getSpeed() > 0) { super.register(addon); }