diff --git a/pom.xml b/pom.xml index 2d87949..9c2c9ca 100644 --- a/pom.xml +++ b/pom.xml @@ -109,15 +109,21 @@ org.bstats bstats-bukkit - 2.2.1 + 3.0.0 compile org.projectlombok lombok - 1.18.20 + 1.18.24 provided + + + com.google.code.findbugs + annotations + 3.0.1u2 + diff --git a/src/main/java/io/ncbpfluffybear/slimecustomizer/Events.java b/src/main/java/io/ncbpfluffybear/slimecustomizer/Events.java index 43de0c9..faebf7c 100644 --- a/src/main/java/io/ncbpfluffybear/slimecustomizer/Events.java +++ b/src/main/java/io/ncbpfluffybear/slimecustomizer/Events.java @@ -15,7 +15,6 @@ import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.bukkit.event.Listener; -import org.bukkit.event.block.BlockPlaceEvent; import org.bukkit.event.inventory.InventoryClickEvent; import org.bukkit.inventory.Inventory; import org.bukkit.inventory.ItemStack; @@ -44,8 +43,10 @@ public Events() {} private static final int[] INPUT_SLOTS = {28, 29}; private static final int[] OUTPUT_SLOTS = {33, 34}; - private static final NamespacedKey SF_KEY = new NamespacedKey(Slimefun.getPlugin(Slimefun.class), - "slimefun_item"); + private static final NamespacedKey SF_KEY = new NamespacedKey( + Slimefun.getPlugin(Slimefun.class), + "slimefun_item" + ); @EventHandler public void onDualRecipeClick(InventoryClickEvent e) { diff --git a/src/main/java/io/ncbpfluffybear/slimecustomizer/Links.java b/src/main/java/io/ncbpfluffybear/slimecustomizer/Links.java index 535b962..37ae806 100644 --- a/src/main/java/io/ncbpfluffybear/slimecustomizer/Links.java +++ b/src/main/java/io/ncbpfluffybear/slimecustomizer/Links.java @@ -6,7 +6,11 @@ * * @author NCBPFluffyBear */ -public class Links { +public final class Links { + + private Links() { + throw new IllegalStateException("Utility class"); + } private static final String PREFIX = "https://github.com/NCBPFluffyBear/SlimeCustomizer#"; diff --git a/src/main/java/io/ncbpfluffybear/slimecustomizer/SCTabCompleter.java b/src/main/java/io/ncbpfluffybear/slimecustomizer/SCTabCompleter.java index 0e201d5..fe95eca 100644 --- a/src/main/java/io/ncbpfluffybear/slimecustomizer/SCTabCompleter.java +++ b/src/main/java/io/ncbpfluffybear/slimecustomizer/SCTabCompleter.java @@ -49,6 +49,9 @@ public List onTabComplete (CommandSender sender, Command cmd, String lab break; case 4: Collections.addAll(options, "1", "2", "4", "8", "16", "32", "64"); + break; + default: + break; } } else if (args[0].equals("getsaveditem") && player.hasPermission("slimecustomizer.admin")) { if (args.length == 2) { diff --git a/src/main/java/io/ncbpfluffybear/slimecustomizer/SlimeCustomizer.java b/src/main/java/io/ncbpfluffybear/slimecustomizer/SlimeCustomizer.java index 36aee0c..eae6e33 100644 --- a/src/main/java/io/ncbpfluffybear/slimecustomizer/SlimeCustomizer.java +++ b/src/main/java/io/ncbpfluffybear/slimecustomizer/SlimeCustomizer.java @@ -1,8 +1,12 @@ package io.ncbpfluffybear.slimecustomizer; import io.github.thebusybiscuit.slimefun4.api.SlimefunAddon; +import io.github.thebusybiscuit.slimefun4.api.items.ItemGroup; import io.github.thebusybiscuit.slimefun4.api.items.SlimefunItem; +import io.github.thebusybiscuit.slimefun4.api.recipes.RecipeType; import io.github.thebusybiscuit.slimefun4.libraries.dough.collections.Pair; +import io.github.thebusybiscuit.slimefun4.libraries.dough.config.Config; +import io.github.thebusybiscuit.slimefun4.libraries.dough.items.CustomItemStack; import io.github.thebusybiscuit.slimefun4.libraries.dough.updater.GitHubBuildsUpdater; import io.github.thebusybiscuit.slimefun4.utils.ChestMenuUtils; import io.ncbpfluffybear.slimecustomizer.objects.SCMenu; @@ -14,10 +18,6 @@ import io.ncbpfluffybear.slimecustomizer.registration.MobDrops; import io.ncbpfluffybear.slimecustomizer.registration.SolarGenerators; import lombok.SneakyThrows; -import io.github.thebusybiscuit.slimefun4.api.recipes.RecipeType; -import io.github.thebusybiscuit.slimefun4.api.items.ItemGroup; -import io.github.thebusybiscuit.slimefun4.libraries.dough.config.Config; -import io.github.thebusybiscuit.slimefun4.libraries.dough.items.CustomItemStack; import org.bstats.bukkit.Metrics; import org.bukkit.Bukkit; import org.bukkit.ChatColor; @@ -29,6 +29,9 @@ import org.bukkit.inventory.meta.ItemMeta; import org.bukkit.plugin.java.JavaPlugin; +import javax.annotation.Nonnull; +import javax.annotation.Nullable; +import javax.annotation.ParametersAreNonnullByDefault; import java.io.File; import java.io.IOException; import java.nio.file.Files; @@ -36,6 +39,7 @@ import java.util.Arrays; import java.util.HashMap; import java.util.List; +import java.util.Map; import java.util.logging.Level; /** @@ -48,8 +52,8 @@ public class SlimeCustomizer extends JavaPlugin implements SlimefunAddon { public static SlimeCustomizer instance; public static File itemsFolder; - public static final HashMap> existingRecipes = new HashMap<>(); - public static final HashMap allCategories = new HashMap<>(); + private static final Map> existingRecipes = new HashMap<>(); + private static final Map allCategories = new HashMap<>(); @Override public void onEnable() { @@ -105,7 +109,7 @@ public void onEnable() { try { Files.createDirectory(itemsFolder.toPath()); } catch (IOException e) { - getInstance().getLogger().log(Level.SEVERE, "Failed to create saveditems folder", e); + getInstance().getLogger().log(Level.WARNING, "Failed to create saveditems folder", e); } } @@ -119,161 +123,182 @@ public void onEnable() { this.getCommand("slimecustomizer").setTabCompleter(new SCTabCompleter()); - Bukkit.getLogger().log(Level.INFO, "[SlimeCustomizer] " + ChatColor.BLUE + "Setting up custom stuff..."); - if (!Categories.register(categories)) {return;} - if (!Items.register(items)) {return;} - if (!Machines.register(machines)) {return;} - if (!Generators.register(generators)) {return;} - if (!SolarGenerators.register(solarGenerators)) {return;} - if (!MobDrops.register(mobDrops)) {return;} + Bukkit.getLogger().info("[SlimeCustomizer] " + ChatColor.BLUE + "Setting up custom stuff..."); + if (!Categories.register(categories)) { + return; + } + if (!Items.register(items)) { + return; + } + if (!Machines.register(machines)) { + return; + } + if (!Generators.register(generators)) { + return; + } + if (!SolarGenerators.register(solarGenerators)) { + return; + } + if (!MobDrops.register(mobDrops)) { + return; + } Bukkit.getPluginManager().registerEvents(new Events(), instance); } - @SneakyThrows @Override + @SneakyThrows + @ParametersAreNonnullByDefault public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { if (sender instanceof Player && args[0].equals("saveitem")) { - Player p = (Player) sender; - if (!Utils.checkPermission(p, "slimecustomizer.admin")) { - return true; - } - int id = 0; - File itemFile = new File(getInstance().getDataFolder().getPath() + "/saveditems", id + ".yml"); - while (itemFile.exists()) { - id++; - itemFile = new File(getInstance().getDataFolder().getPath() + "/saveditems", id + ".yml"); - } + onSaveItem((Player) sender); + } else if (sender instanceof Player && args[0].equals("give") && args.length > 2) { + onGiveItem((Player) sender, args); + } else if (sender instanceof Player && args[0].equals("getsaveditem") && args.length > 1) { + onGetSavedItem((Player) sender); + } else { + Utils.send(sender, "&eAll commands can be found at &9" + Links.COMMANDS); + } + return true; + } - if (!itemFile.createNewFile()) { - getInstance().getLogger().log(Level.SEVERE, "Failed to create config for item " + id); - } + @SneakyThrows + private void onSaveItem(Player player) { + if (!Utils.checkPermission(player, "slimecustomizer.admin")) { + return; + } - Config itemFileConfig = new Config(this, "saveditems/" + id + ".yml"); - itemFileConfig.setValue("item", p.getInventory().getItemInMainHand()); - itemFileConfig.save(); - Utils.send(p, "&eYour item has been saved to " + itemFile.getPath() + ". Please refer to " + - "&9" + Links.USING_CUSTOM_ITEMS); + int id = 0; + File itemFile = new File(getInstance().getDataFolder().getPath() + "/saveditems", id + ".yml"); + while (itemFile.exists()) { + id++; + itemFile = new File(getInstance().getDataFolder().getPath() + "/saveditems", id + ".yml"); + } - } else if (args[0].equals("give") && args.length > 2) { - if (sender instanceof Player && !Utils.checkPermission((Player) sender, "slimecustomizer.admin")) { - return true; - } + if (!itemFile.createNewFile()) { + getInstance().getLogger().severe("Failed to create config for item " + id); + } - Player target = Bukkit.getPlayer(args[1]); - if (target == null) { - Utils.send(sender, "&cThat player could not be found!"); - return true; - } + Config itemFileConfig = new Config(this, "saveditems/" + id + ".yml"); + itemFileConfig.setValue("item", player.getInventory().getItemInMainHand()); + itemFileConfig.save(); + Utils.send(player, "&eYour item has been saved to " + + itemFile.getPath() + + ". Please refer to " + + "&9" + + Links.USING_CUSTOM_ITEMS + ); + } - SlimefunItem sfItem = SlimefunItem.getById(args[2].toUpperCase()); - if (sfItem == null) { - Utils.send(sender, "&cThat Slimefun item could not be found!"); - return true; - } + @SneakyThrows + private void onGiveItem(@Nonnull Player player, @Nonnull String... args) { + if (!Utils.checkPermission(player, "slimecustomizer.admin")) { + return; + } - int amount; + Player target = Bukkit.getPlayer(args[1]); + if (target == null) { + Utils.send(player, "&cThat player could not be found!"); + return; + } - if (args[3] != null) { + SlimefunItem sfItem = SlimefunItem.getById(args[2].toUpperCase()); + if (sfItem == null) { + Utils.send(player, "&cThat Slimefun item could not be found!"); + return; + } - try { - amount = Integer.parseInt(args[3]); - } catch (NumberFormatException ignored) { - amount = 1; - } - } else { + int amount; + + if (args[3] != null) { + + try { + amount = Integer.parseInt(args[3]); + } catch (NumberFormatException ignored) { amount = 1; } + } else { + amount = 1; + } - giveItems(sender, target, sfItem, amount); - - } else if (args[0].equals("getsaveditem") && args.length > 1) { + giveItems(player, target, sfItem, amount); + } - if (sender instanceof Player && !Utils.checkPermission((Player) sender, "slimecustomizer.admin")) { - return true; - } + @SneakyThrows + private void onGetSavedItem(@Nonnull Player player, @Nonnull String... args) { + if (!Utils.checkPermission(player, "slimecustomizer.admin")) { + return; + } - if (args[1].equals("gui")) { + if (args[1].equals("gui")) { + List> items = new ArrayList<>(); + items.add(new Pair<>(null, null)); - if (!(sender instanceof Player)) { - Utils.send(sender, "&4This command can only be executed in game"); - return true; + String[] fileNames = itemsFolder.list(); + if (fileNames != null) { + for (int i = 0; i < fileNames.length; i++) { + fileNames[i] = fileNames[i].replace(".yml", ""); } - Player p = (Player) sender; - List> items = new ArrayList<>(); - items.add(new Pair<>(null, null)); + Arrays.sort(fileNames, new WindowsExplorerStringComparator()); - String[] fileNames = itemsFolder.list(); - if (fileNames != null) { - for (int i = 0; i < fileNames.length; i++) { - fileNames[i] = fileNames[i].replace(".yml", ""); - } - - Arrays.sort(fileNames, new WindowsExplorerStringComparator()); + for (String id : fileNames) { + items.add(new Pair<>(id, Utils.retrieveSavedItem(id, 1, false))); + } - for (String id : fileNames) { - items.add(new Pair<>(id, Utils.retrieveSavedItem(id, 1, false))); - } + int page = 1; + SCMenu menu = new SCMenu("&a&lSaved Items"); + menu.setSize(54); + populateMenu(menu, items, page, player); + menu.setPlayerInventoryClickable(false); + menu.setBackgroundNonClickable(false); + menu.open(player); + } + } else { + if (args.length < 4) { + Utils.send(player, "&c/sc getsaveditem gui | "); + return; + } - int page = 1; - SCMenu menu = new SCMenu("&a&lSaved Items"); - menu.setSize(54); - populateMenu(menu, items, page, p); - menu.setPlayerInventoryClickable(false); - menu.setBackgroundNonClickable(false); - menu.open(p); + String savedID = args[1]; - } + Player target = Bukkit.getPlayer(args[2]); + if (target == null) { + Utils.send(player, "&cThat player could not be found!"); + return; + } - } else { - if (args.length < 4) { - Utils.send(sender, "&c/sc getsaveditem gui | "); - return true; - } + int amount; - String savedID = args[1]; + try { + amount = Integer.parseInt(args[3]); + } catch (NumberFormatException ignored) { + amount = 1; + } - Player target = Bukkit.getPlayer(args[2]); - if (target == null) { - Utils.send(sender, "&cThat player could not be found!"); - return true; + ItemStack item = Utils.retrieveSavedItem(savedID, amount, false); + if (item != null) { + HashMap leftovers = target.getInventory().addItem(item); + for (ItemStack leftover : leftovers.values()) { + target.getWorld().dropItem(target.getLocation(), leftover); } - int amount; - - try { - amount = Integer.parseInt(args[3]); - } catch (NumberFormatException ignored) { - amount = 1; - } - - ItemStack item = Utils.retrieveSavedItem(savedID, amount, false); - if (item != null) { - HashMap leftovers = target.getInventory().addItem(item); - for (ItemStack leftover : leftovers.values()) { - target.getWorld().dropItem(target.getLocation(), leftover); - } - - Utils.send(sender, "&bYou have given " + target.getName() + " &a" + amount + " &bof &7\"&a" + - savedID + "&7\""); - } else { - Utils.send(sender, "&cThat saveditem could not be found!"); - } + Utils.send(player, "&bYou have given " + target.getName() + " &a" + amount + " &bof &7\"&a" + + savedID + "&7\""); + } else { + Utils.send(player, "&cThat saveditem could not be found!"); } - } else { - Utils.send(sender, "&eAll commands can be found at &9" + Links.COMMANDS); } - - return true; } /** * Populates the saveditem gui. 45 items per page. - * @param menu the SCMenu to populate + * + * @param menu the SCMenu to populate * @param items the List of items - * @param page the page number - * @param p the player that will be viewing this menu + * @param page the page number + * @param p the player that will be viewing this menu */ + @ParametersAreNonnullByDefault private void populateMenu(SCMenu menu, List> items, int page, Player p) { for (int i = 45; i < 54; i++) { menu.replaceExistingItem(i, ChestMenuUtils.getBackground()); @@ -284,33 +309,38 @@ private void populateMenu(SCMenu menu, List> items, int for (int i = 0; i < 45; i++) { int itemIndex = i + 1 + (page - 1) * 45; ItemStack item = getItemOrNull(items, itemIndex); - if (item != null) { - ItemMeta im = item.getItemMeta(); - if (im == null) { - Utils.notify("An item has no metadata! Is it corrupted? " + items.get(itemIndex).getFirstValue()); - continue; - } - List lore = im.getLore(); - - if (lore == null) { - lore = new ArrayList<>(Arrays.asList("", Utils.color("&bID: " + items.get(itemIndex).getFirstValue()), - Utils.color("&a> Click to get this item"))); - } else { - lore.addAll(new ArrayList<>(Arrays.asList("", Utils.color("&bID: " + items.get(itemIndex).getFirstValue()), - Utils.color("&a> Click to get this item")))); - } + if (item == null) { + continue; + } - im.setLore(lore); - item.setItemMeta(im); - menu.replaceExistingItem(i, item); - menu.addMenuClickHandler(i, (pl, s, is, action) -> { - HashMap leftovers = p.getInventory().addItem(getItemOrNull(items, itemIndex)); - for (ItemStack leftover : leftovers.values()) { - p.getWorld().dropItem(p.getLocation(), leftover); - } - return false; - }); + ItemMeta im = item.getItemMeta(); + if (im == null) { + Utils.notify("An item has no metadata! Is it corrupted? " + items.get(itemIndex).getFirstValue()); + continue; } + List lore = im.getLore(); + + if (lore == null) { + lore = new ArrayList<>(Arrays.asList("", Utils.color("&bID: " + items.get(itemIndex).getFirstValue()), + Utils.color("&a> Click to get this item") + )); + } else { + lore.addAll(new ArrayList<>(Arrays.asList("", + Utils.color("&bID: " + items.get(itemIndex).getFirstValue()), + Utils.color("&a> Click to get this item") + ))); + } + + im.setLore(lore); + item.setItemMeta(im); + menu.replaceExistingItem(i, item); + menu.addMenuClickHandler(i, (pl, s, is, action) -> { + HashMap leftovers = p.getInventory().addItem(getItemOrNull(items, itemIndex)); + for (ItemStack leftover : leftovers.values()) { + p.getWorld().dropItem(p.getLocation(), leftover); + } + return false; + }); } if (page != 1) { @@ -331,7 +361,8 @@ private void populateMenu(SCMenu menu, List> items, int } - private ItemStack getItemOrNull(List> items, int index) { + @Nullable + private ItemStack getItemOrNull(@Nonnull List> items, int index) { ItemStack item; try { item = items.get(index).getSecondValue().clone(); @@ -341,15 +372,16 @@ private ItemStack getItemOrNull(List> items, int index) return item; } + @ParametersAreNonnullByDefault private void giveItems(CommandSender s, Player p, SlimefunItem sfItem, int amount) { p.getInventory().addItem(new CustomItemStack(sfItem.getRecipeOutput(), amount)); Utils.send(s, "&bYou have given " + p.getName() + " &a" + amount + " &7\"&b" + sfItem.getItemName() + "&7\""); } - private void copyFile(File file, String name) { + private void copyFile(@Nonnull File file, @Nonnull String name) { if (!file.exists()) { try { - Files.copy(this.getClass().getResourceAsStream("/"+ name + ".yml"), file.toPath()); + Files.copy(this.getClass().getResourceAsStream("/" + name + ".yml"), file.toPath()); } catch (IOException e) { getInstance().getLogger().log(Level.SEVERE, "Failed to copy default " + name + ".yml file", e); } @@ -366,6 +398,7 @@ public String getBugTrackerURL() { return "https://github.com/NCBPFluffyBear/SlimeCustomizer/issues"; } + @Nonnull @Override public JavaPlugin getJavaPlugin() { return this; @@ -375,4 +408,11 @@ public static SlimeCustomizer getInstance() { return instance; } + public static Map> getExistingRecipes() { + return existingRecipes; + } + + public static Map getAllCategories() { + return allCategories; + } } diff --git a/src/main/java/io/ncbpfluffybear/slimecustomizer/Utils.java b/src/main/java/io/ncbpfluffybear/slimecustomizer/Utils.java index 4bb38db..f59b570 100644 --- a/src/main/java/io/ncbpfluffybear/slimecustomizer/Utils.java +++ b/src/main/java/io/ncbpfluffybear/slimecustomizer/Utils.java @@ -1,22 +1,26 @@ package io.ncbpfluffybear.slimecustomizer; +import io.github.thebusybiscuit.slimefun4.api.items.ItemGroup; import io.github.thebusybiscuit.slimefun4.api.items.SlimefunItem; import io.github.thebusybiscuit.slimefun4.api.recipes.RecipeType; -import io.github.thebusybiscuit.slimefun4.api.items.ItemGroup; import io.github.thebusybiscuit.slimefun4.libraries.dough.collections.Pair; -import io.github.thebusybiscuit.slimefun4.utils.SlimefunUtils; import io.github.thebusybiscuit.slimefun4.libraries.dough.config.Config; import io.github.thebusybiscuit.slimefun4.libraries.dough.items.CustomItemStack; +import io.github.thebusybiscuit.slimefun4.utils.SlimefunUtils; import org.bukkit.Bukkit; import org.bukkit.ChatColor; import org.bukkit.Material; import org.bukkit.NamespacedKey; +import org.bukkit.World; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.meta.ItemMeta; import org.bukkit.persistence.PersistentDataType; +import javax.annotation.Nonnull; +import javax.annotation.Nullable; +import javax.annotation.ParametersAreNonnullByDefault; import java.io.File; import java.util.ArrayList; import java.util.Arrays; @@ -30,7 +34,11 @@ * * @author NCBPFluffyBear */ -public class Utils { +public final class Utils { + + private Utils() { + throw new IllegalStateException("Utility class"); + } private static final NamespacedKey SCKEY = new NamespacedKey(SlimeCustomizer.getInstance(), "slimecustomizer_item"); private static final List STACK_LIMITED_MACHINES = new ArrayList<>(Arrays.asList( @@ -40,11 +48,11 @@ public class Utils { RecipeType.MAGIC_WORKBENCH )); - public static void send(CommandSender s, String msg) { + public static void send(@Nonnull CommandSender s, @Nonnull String msg) { s.sendMessage(ChatColor.translateAlternateColorCodes('&', "&a&l[&aSlimeCustomizer&a&l]&7 " + msg)); } - public static boolean checkPermission(Player p, String permission) { + public static boolean checkPermission(@Nonnull Player p, @Nonnull String permission) { if (!p.hasPermission(permission)) { Utils.send(p, "&cYou do not have permission to use this command!"); return false; @@ -53,19 +61,21 @@ public static boolean checkPermission(Player p, String permission) { return true; } - public static String color(String str) { + @Nonnull + public static String color(@Nonnull String str) { return ChatColor.translateAlternateColorCodes('&', str); } - public static void notify(String reason) { - Bukkit.getLogger().log(Level.INFO, "[SlimeCustomizer] " + ChatColor.GREEN + reason); + public static void notify(@Nonnull String reason) { + Bukkit.getLogger().info("[SlimeCustomizer] " + ChatColor.GREEN + reason); } - public static void disable(String reason) { - Bukkit.getLogger().log(Level.SEVERE, "[SlimeCustomizer] " + reason); + public static void disable(@Nonnull String reason) { + Bukkit.getLogger().severe("[SlimeCustomizer] " + reason); Bukkit.getPluginManager().disablePlugin(SlimeCustomizer.getInstance()); } + @ParametersAreNonnullByDefault public static boolean checkFitsStackSize(ItemStack item, String slot, String machineKey, String recipeKey) { if (item.getAmount() > item.getMaxStackSize()) { disable("The " + slot + "ingredient for recipe" + recipeKey + " for " + machineKey @@ -76,7 +86,8 @@ public static boolean checkFitsStackSize(ItemStack item, String slot, String mac } - public static List colorList(List plainList) { + @Nonnull + public static List colorList(@Nonnull List plainList) { List coloredList = new ArrayList<>(); for (String s : plainList) { coloredList.add(ChatColor.translateAlternateColorCodes('&', s)); @@ -85,6 +96,7 @@ public static List colorList(List plainList) { return coloredList; } + @Nonnull public static ItemStack[] buildCraftingRecipe(Config file, String key, RecipeType recipeType) { ItemStack[] recipe = new ItemStack[9]; for (int i = 0; i < 9; i++) { @@ -100,14 +112,14 @@ public static ItemStack[] buildCraftingRecipe(Config file, String key, RecipeTyp } catch (NumberFormatException e) { Utils.disable("Crafting recipe item " + configIndex + " for " + key + " must be a positive " + "integer!"); - return null; + return new ItemStack[0]; } // Only certain multiblock machines can use stack sizes larger than 1 if (STACK_LIMITED_MACHINES.contains(recipeType) && amount > 1) { disable(recipeType.getKey().getKey().toUpperCase() + " can not use items with a greater stack size than 1!" + " Please change the crafting-recipe-type or crafting-recipe.#.amount for " + key + "."); - return null; + return new ItemStack[0]; } if (type.equalsIgnoreCase("NONE")) { @@ -117,7 +129,7 @@ public static ItemStack[] buildCraftingRecipe(Config file, String key, RecipeTyp if (vanillaMat == null) { Utils.disable("Crafting ingredient " + configIndex + " for " + key + " is not a valid " + "vanilla ID!"); - return null; + return new ItemStack[0]; } else { recipe[i] = new ItemStack(vanillaMat, amount); } @@ -126,7 +138,7 @@ public static ItemStack[] buildCraftingRecipe(Config file, String key, RecipeTyp if (sfMat == null) { Utils.disable("Crafting ingredient " + configIndex + " for " + key + " is not a valid Slimefun ID!"); - return null; + return new ItemStack[0]; } else { recipe[i] = new CustomItemStack(sfMat.getItem().clone(), amount); } @@ -135,13 +147,13 @@ public static ItemStack[] buildCraftingRecipe(Config file, String key, RecipeTyp } else { Utils.disable("Crafting ingredient " + configIndex + " for " + key + " can only have a type of VANILLA, SLIMEFUN, SAVEDITEM, or NONE!"); - return null; + return new ItemStack[0]; } } AtomicBoolean invalid = new AtomicBoolean(false); - SlimeCustomizer.existingRecipes.forEach((itemStacks, recipeTypePair) -> { + SlimeCustomizer.getExistingRecipes().forEach((itemStacks, recipeTypePair) -> { if (Arrays.equals(itemStacks, recipe) && recipeType == recipeTypePair.getFirstValue()) { Utils.disable("The crafting recipe for " + key + " is already being used for " + recipeTypePair.getSecondValue()); @@ -150,15 +162,16 @@ public static ItemStack[] buildCraftingRecipe(Config file, String key, RecipeTyp }); if (invalid.get()) { - return null; + return new ItemStack[0]; } - if (!(recipeType == RecipeType.NULL)) { - SlimeCustomizer.existingRecipes.put(recipe, new Pair<>(recipeType, key)); + if (recipeType != RecipeType.NULL) { + SlimeCustomizer.getExistingRecipes().put(recipe, new Pair<>(recipeType, key)); } return recipe; } + @Nullable public static ItemStack getBlockFromConfig(String key, String materialString) { if (materialString == null) { Utils.disable("The material for " + key + " could not be found!"); @@ -180,10 +193,11 @@ public static ItemStack getBlockFromConfig(String key, String materialString) { return block; } + @ParametersAreNonnullByDefault public static void updateLoreFormat(Config config, String key, String machineType) { String path = key + "." + machineType + "-lore"; if (config.getStringList(path).toString().equals("[]")) { - Bukkit.getLogger().log(Level.WARNING, "Your " + key + " was reformatted to use the new lore system!" + + Bukkit.getLogger().warning("Your " + key + " was reformatted to use the new lore system!" + "Read " + Links.ADDING_YOUR_ITEM + " to learn how to use multiline lore!"); String lore = config.getString(path); @@ -192,7 +206,7 @@ public static void updateLoreFormat(Config config, String key, String machineTyp } } - public static void updateCraftingRecipeFormat(Config config, String key) { + public static void updateCraftingRecipeFormat(@Nonnull Config config, @Nonnull String key) { String path = key + ".crafting-recipe"; for (int i = 0; i < 9; i++) { int recipeIndex = i + 1; @@ -208,7 +222,7 @@ public static void updateCraftingRecipeFormat(Config config, String key) { config.save(); } - public static void updateCategoryFormat(Config config, String key) { + public static void updateCategoryFormat(@Nonnull Config config, @Nonnull String key) { String path = key + ".category"; if (config.getString(path) == null) { @@ -218,7 +232,7 @@ public static void updateCategoryFormat(Config config, String key) { config.save(); } - public static void updateInputAndOutputFormat(Config config, String key) { + public static void updateInputAndOutputFormat(@Nonnull Config config, @Nonnull String key) { String path = key + ".recipes"; for (String recipe : config.getKeys(path)) { for (int i = 0; i < 2; i++) { @@ -249,7 +263,7 @@ public static void updateInputAndOutputFormat(Config config, String key) { config.setValue(transportPath + ".2.id", "N/A"); config.setValue(transportPath + ".2.amount", 1); - Bukkit.getLogger().log(Level.WARNING, "Your " + key + " was reformatted to use the new " + + Bukkit.getLogger().warning("Your " + key + " was reformatted to use the new " + "input/output system! " + "Read " + Links.ADDING_YOUR_MACHINE + " to learn what this new format does!"); } @@ -259,20 +273,21 @@ public static void updateInputAndOutputFormat(Config config, String key) { config.save(); } - public static void updatePlaceableOption(Config config, String key) { + public static void updatePlaceableOption(@Nonnull Config config, @Nonnull String key) { if (config.getValue(key + ".placeable") != null) { return; } config.setValue(key + ".placeable", false); - Bukkit.getLogger().log(Level.WARNING, "Your " + key + " was reformatted to have a placeable option! " + + Bukkit.getLogger().warning("Your " + key + " was reformatted to have a placeable option! " + "Read " + Links.ADDING_YOUR_ITEM + " to learn what this new option does!"); - Bukkit.getLogger().log(Level.SEVERE, "This option is false by default, so if you have a block you need " + + Bukkit.getLogger().severe("This option is false by default, so if you have a block you need " + "to be placeable, change this immediately!"); config.save(); } - public static ItemStack retrieveSavedItem(String id, int amount, boolean disableIfNull) { + @Nullable + public static ItemStack retrieveSavedItem(@Nonnull String id, int amount, boolean disableIfNull) { File serializedItemFile = new File(SlimeCustomizer.getInstance().getDataFolder(), "saveditems/" + id + ".yml"); if (!serializedItemFile.exists()) { if (disableIfNull) { @@ -286,16 +301,15 @@ public static ItemStack retrieveSavedItem(String id, int amount, boolean disable } } - public static RecipeType getRecipeType(String str, String key) { + @Nullable + public static RecipeType getRecipeType(@Nullable String str, @Nonnull String key) { if (str == null) { disable("The crafting-recipe-type for " + key + " has to be a multiblock machine!" ); return null; } switch (str) { - default: - return null; case "ENCHANTED_CRAFTING_TABLE": - Bukkit.getLogger().log(Level.WARNING, "Hey buddy, it's the ENHANCED crafting table, not ENCHANTED. " + + Bukkit.getLogger().warning("Hey buddy, it's the ENHANCED crafting table, not ENCHANTED. " + "Don't worry, I know what you mean. But you should probably fix that."); return RecipeType.ENHANCED_CRAFTING_TABLE; case "ENHANCED_CRAFTING_TABLE": @@ -316,45 +330,58 @@ public static RecipeType getRecipeType(String str, String key) { return RecipeType.GRIND_STONE; case "NONE": return RecipeType.NULL; + default: + disable("The crafting-recipe-type for " + key + " is invalid" ); + return null; } } + @Nullable public static ItemGroup getCategory(String str, String key) { - ItemGroup category = SlimeCustomizer.allCategories.get(str); + ItemGroup category = SlimeCustomizer.getAllCategories().get(str); if (category == null) { disable(str + " is not a valid category for " + key + "!"); + return null; + } else { + return category; } - return category; } - public static String capitalize(String str) { + @Nonnull + public static String capitalize(@Nonnull String str) { return str.substring(0, 1).toUpperCase() + str.substring(1).toLowerCase(); } + @Nonnull public static String toOrdinal(int i) { switch (i) { - default: - return "ERR"; case 1: return "1st"; case 2: return "2nd"; + default: + return "ERR"; } } - public static ItemStack keyItem(ItemStack item, int i) { + @Nonnull + public static ItemStack keyItem(@Nonnull ItemStack item, int i) { ItemMeta meta = item.getItemMeta(); meta.getPersistentDataContainer().set(SCKEY, PersistentDataType.INTEGER, i); item.setItemMeta(meta); return item; } - public static boolean isKeyed(ItemStack item) { + public static boolean isKeyed(@Nonnull ItemStack item) { return item.getItemMeta().getPersistentDataContainer().has(SCKEY, PersistentDataType.INTEGER); } - public static int getItemKey(ItemStack item) { + public static int getItemKey(@Nonnull ItemStack item) { return item.getItemMeta().getPersistentDataContainer().get(SCKEY, PersistentDataType.INTEGER); } + public static boolean isDaytime(@Nonnull World world) { + long time = world.getTime(); + return !world.hasStorm() && !world.isThundering() && (time < 12300 || time > 23850); + } } diff --git a/src/main/java/io/ncbpfluffybear/slimecustomizer/objects/CustomGenerator.java b/src/main/java/io/ncbpfluffybear/slimecustomizer/objects/CustomGenerator.java index e37c853..ac83aca 100644 --- a/src/main/java/io/ncbpfluffybear/slimecustomizer/objects/CustomGenerator.java +++ b/src/main/java/io/ncbpfluffybear/slimecustomizer/objects/CustomGenerator.java @@ -5,12 +5,14 @@ import io.github.thebusybiscuit.slimefun4.api.items.ItemGroup; import io.github.thebusybiscuit.slimefun4.api.items.SlimefunItemStack; import io.github.thebusybiscuit.slimefun4.api.recipes.RecipeType; +import io.github.thebusybiscuit.slimefun4.libraries.dough.items.CustomItemStack; import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.abstractItems.AGenerator; import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.abstractItems.MachineFuel; -import io.github.thebusybiscuit.slimefun4.libraries.dough.items.CustomItemStack; import org.bukkit.Material; import org.bukkit.inventory.ItemStack; +import javax.annotation.Nonnull; +import javax.annotation.ParametersAreNonnullByDefault; import java.util.ArrayList; import java.util.List; @@ -27,9 +29,16 @@ public class CustomGenerator extends SCAGenerator { private final int energyBuffer; private final List customRecipes; - public CustomGenerator(ItemGroup category, SlimefunItemStack item, RecipeType recipeType, ItemStack[] recipe, - Material progressItem, int energyProduction, int energyBuffer, - List customRecipes) { + @ParametersAreNonnullByDefault + public CustomGenerator(ItemGroup category, + SlimefunItemStack item, + RecipeType recipeType, + ItemStack[] recipe, + Material progressItem, + int energyProduction, + int energyBuffer, + List customRecipes + ) { super(category, item, recipeType, recipe); this.progressItem = new CustomItemStack(progressItem, ""); @@ -43,6 +52,7 @@ public CustomGenerator(ItemGroup category, SlimefunItemStack item, RecipeType re registerDefaultFuelTypes(); } + @Nonnull @Override public ItemStack getProgressBar() { return progressItem; @@ -69,6 +79,7 @@ public int getCapacity() { return energyBuffer; } + @Nonnull @Override public List getDisplayRecipes() { List displayRecipes = new ArrayList<>(customRecipes.size() * 2); @@ -91,6 +102,4 @@ public List getDisplayRecipes() { return displayRecipes; } - - } diff --git a/src/main/java/io/ncbpfluffybear/slimecustomizer/objects/CustomMachine.java b/src/main/java/io/ncbpfluffybear/slimecustomizer/objects/CustomMachine.java index 7c7872f..5d57f01 100644 --- a/src/main/java/io/ncbpfluffybear/slimecustomizer/objects/CustomMachine.java +++ b/src/main/java/io/ncbpfluffybear/slimecustomizer/objects/CustomMachine.java @@ -1,20 +1,22 @@ package io.ncbpfluffybear.slimecustomizer.objects; +import io.github.thebusybiscuit.slimefun4.api.items.ItemGroup; +import io.github.thebusybiscuit.slimefun4.api.items.SlimefunItemStack; +import io.github.thebusybiscuit.slimefun4.api.recipes.RecipeType; import io.github.thebusybiscuit.slimefun4.core.attributes.RecipeDisplayItem; import io.github.thebusybiscuit.slimefun4.libraries.dough.collections.Pair; +import io.github.thebusybiscuit.slimefun4.libraries.dough.items.CustomItemStack; import io.ncbpfluffybear.slimecustomizer.Utils; -import io.github.thebusybiscuit.slimefun4.api.recipes.RecipeType; -import io.github.thebusybiscuit.slimefun4.api.items.ItemGroup; import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.abstractItems.AContainer; import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.abstractItems.MachineRecipe; -import io.github.thebusybiscuit.slimefun4.api.items.SlimefunItemStack; -import io.github.thebusybiscuit.slimefun4.libraries.dough.items.CustomItemStack; import org.bukkit.Material; import org.bukkit.inventory.ItemStack; +import javax.annotation.Nonnull; +import javax.annotation.ParametersAreNonnullByDefault; import java.util.ArrayList; -import java.util.HashMap; import java.util.List; +import java.util.Map; /** @@ -34,11 +36,19 @@ public class CustomMachine extends AContainer implements RecipeDisplayItem { private final ItemStack progressItem; private final int energyConsumption; private final int energyBuffer; - private final HashMap, Integer> customRecipes; - - public CustomMachine(ItemGroup category, SlimefunItemStack item, RecipeType recipeType, ItemStack[] recipe, - String id, Material progressItem, int energyConsumption, int energyBuffer, - HashMap, Integer> customRecipes) { + private final Map, Integer> customRecipes; + + @ParametersAreNonnullByDefault + public CustomMachine(ItemGroup category, + SlimefunItemStack item, + RecipeType recipeType, + ItemStack[] recipe, + String id, + Material progressItem, + int energyConsumption, + int energyBuffer, + Map, Integer> customRecipes + ) { super(category, item, recipeType, recipe); this.id = id; @@ -85,6 +95,7 @@ protected void registerDefaultRecipes() { } + @Nonnull @Override public List getDisplayRecipes() { List displayRecipes = new ArrayList<>(recipes.size() * 2); @@ -107,6 +118,7 @@ public List getDisplayRecipes() { return displayRecipes; } + @Nonnull @Override public String getMachineIdentifier() { return id; diff --git a/src/main/java/io/ncbpfluffybear/slimecustomizer/objects/CustomPassiveMachine.java b/src/main/java/io/ncbpfluffybear/slimecustomizer/objects/CustomPassiveMachine.java index 4966dce..b1e2263 100644 --- a/src/main/java/io/ncbpfluffybear/slimecustomizer/objects/CustomPassiveMachine.java +++ b/src/main/java/io/ncbpfluffybear/slimecustomizer/objects/CustomPassiveMachine.java @@ -2,18 +2,19 @@ import io.github.thebusybiscuit.slimefun4.api.items.ItemGroup; import io.github.thebusybiscuit.slimefun4.api.items.SlimefunItem; +import io.github.thebusybiscuit.slimefun4.api.items.SlimefunItemStack; +import io.github.thebusybiscuit.slimefun4.api.recipes.RecipeType; import io.github.thebusybiscuit.slimefun4.core.attributes.EnergyNetComponent; import io.github.thebusybiscuit.slimefun4.core.networks.energy.EnergyNetComponentType; import me.mrCookieSlime.CSCoreLibPlugin.Configuration.Config; -import io.github.thebusybiscuit.slimefun4.api.recipes.RecipeType; import me.mrCookieSlime.Slimefun.Objects.handlers.BlockTicker; -import io.github.thebusybiscuit.slimefun4.api.items.SlimefunItemStack; import me.mrCookieSlime.Slimefun.api.inventory.BlockMenuPreset; import me.mrCookieSlime.Slimefun.api.item_transport.ItemTransportFlow; import org.bukkit.block.Block; import org.bukkit.entity.Player; import org.bukkit.inventory.ItemStack; +import javax.annotation.ParametersAreNonnullByDefault; import java.util.List; public class CustomPassiveMachine extends SlimefunItem implements EnergyNetComponent { @@ -22,8 +23,15 @@ public class CustomPassiveMachine extends SlimefunItem implements EnergyNetCompo private final int capacity; private final List products; - public CustomPassiveMachine(ItemGroup category, SlimefunItemStack item, RecipeType recipeType, ItemStack[] recipe, - String name, int capacity, List products) { + @ParametersAreNonnullByDefault + public CustomPassiveMachine(ItemGroup category, + SlimefunItemStack item, + RecipeType recipeType, + ItemStack[] recipe, + String name, + int capacity, + List products + ) { super(category, item, recipeType, recipe); this.name = name; @@ -34,7 +42,7 @@ public CustomPassiveMachine(ItemGroup category, SlimefunItemStack item, RecipeTy @Override public void init() { - + // Unrequired } @Override @@ -73,8 +81,18 @@ public EnergyNetComponentType getEnergyComponentType() { return EnergyNetComponentType.CONSUMER; } + + + public String getName() { + return name; + } + + public List getProducts() { + return products; + } + @Override public int getCapacity() { - return 0; + return capacity; } } diff --git a/src/main/java/io/ncbpfluffybear/slimecustomizer/objects/CustomSCItem.java b/src/main/java/io/ncbpfluffybear/slimecustomizer/objects/CustomSCItem.java index ab99691..9622b45 100644 --- a/src/main/java/io/ncbpfluffybear/slimecustomizer/objects/CustomSCItem.java +++ b/src/main/java/io/ncbpfluffybear/slimecustomizer/objects/CustomSCItem.java @@ -1,11 +1,13 @@ package io.ncbpfluffybear.slimecustomizer.objects; -import io.github.thebusybiscuit.slimefun4.api.items.SlimefunItem; -import io.github.thebusybiscuit.slimefun4.api.recipes.RecipeType; import io.github.thebusybiscuit.slimefun4.api.items.ItemGroup; +import io.github.thebusybiscuit.slimefun4.api.items.SlimefunItem; import io.github.thebusybiscuit.slimefun4.api.items.SlimefunItemStack; +import io.github.thebusybiscuit.slimefun4.api.recipes.RecipeType; import org.bukkit.inventory.ItemStack; +import javax.annotation.ParametersAreNonnullByDefault; + /** * The {@link CustomSCItem} class is a wrapper * for the {@link SlimefunItem}. @@ -14,10 +16,12 @@ */ public class CustomSCItem extends SlimefunItem { + @ParametersAreNonnullByDefault public CustomSCItem(ItemGroup category, SlimefunItemStack item, RecipeType recipeType, ItemStack[] recipe, ItemStack output) { super(category, item, recipeType, recipe, output); } + @ParametersAreNonnullByDefault public CustomSCItem(ItemGroup category, SlimefunItemStack item, RecipeType recipeType, ItemStack[] recipe) { super(category, item, recipeType, recipe); } diff --git a/src/main/java/io/ncbpfluffybear/slimecustomizer/objects/CustomSolarGenerator.java b/src/main/java/io/ncbpfluffybear/slimecustomizer/objects/CustomSolarGenerator.java index 28fca71..3689bea 100644 --- a/src/main/java/io/ncbpfluffybear/slimecustomizer/objects/CustomSolarGenerator.java +++ b/src/main/java/io/ncbpfluffybear/slimecustomizer/objects/CustomSolarGenerator.java @@ -1,14 +1,18 @@ package io.ncbpfluffybear.slimecustomizer.objects; -import io.github.thebusybiscuit.slimefun4.implementation.items.electric.generators.SolarGenerator; -import me.mrCookieSlime.CSCoreLibPlugin.Configuration.Config; -import io.github.thebusybiscuit.slimefun4.api.recipes.RecipeType; import io.github.thebusybiscuit.slimefun4.api.items.ItemGroup; import io.github.thebusybiscuit.slimefun4.api.items.SlimefunItemStack; +import io.github.thebusybiscuit.slimefun4.api.recipes.RecipeType; +import io.github.thebusybiscuit.slimefun4.implementation.items.electric.generators.SolarGenerator; +import io.ncbpfluffybear.slimecustomizer.Utils; +import me.mrCookieSlime.CSCoreLibPlugin.Configuration.Config; import org.bukkit.Location; import org.bukkit.World; import org.bukkit.inventory.ItemStack; +import javax.annotation.Nonnull; +import javax.annotation.ParametersAreNonnullByDefault; + /** * The {@link CustomSolarGenerator} class is a generified * solar generator. @@ -18,24 +22,25 @@ */ public class CustomSolarGenerator extends SolarGenerator { + @ParametersAreNonnullByDefault public CustomSolarGenerator(ItemGroup category, int dayEnergy, int nightEnergy, SlimefunItemStack item, RecipeType recipeType, ItemStack[] recipe) { super(category, dayEnergy, nightEnergy, item, recipeType, recipe); } @Override - public int getGeneratedOutput(Location l, Config data) { - World world = l.getWorld(); + public int getGeneratedOutput(@Nonnull Location location, @Nonnull Config data) { + World world = location.getWorld(); if (world.getEnvironment() != World.Environment.NORMAL) { return 0; } else { - boolean isDaytime = isDaytime(world); + boolean isDaytime = Utils.isDaytime(world); // Performance optimization for daytime-only solar generators if (!isDaytime && getNightEnergy() < 1) { return 0; - } else if (!world.isChunkLoaded(l.getBlockX() >> 4, l.getBlockZ() >> 4) - || l.getBlock().getRelative(0, 1, 0).getLightFromSky() < 15) { + } else if (!world.isChunkLoaded(location.getBlockX() >> 4, location.getBlockZ() >> 4) + || location.getBlock().getRelative(0, 1, 0).getLightFromSky() < 15) { return 0; } else { return isDaytime ? getDayEnergy() : getNightEnergy(); @@ -43,9 +48,4 @@ public int getGeneratedOutput(Location l, Config data) { } } - private boolean isDaytime(World world) { - long time = world.getTime(); - return !world.hasStorm() && !world.isThundering() && (time < 12300 || time > 23850); - } - } \ No newline at end of file diff --git a/src/main/java/io/ncbpfluffybear/slimecustomizer/objects/NPCustomSCItem.java b/src/main/java/io/ncbpfluffybear/slimecustomizer/objects/NPCustomSCItem.java index bfb513c..25bbb52 100644 --- a/src/main/java/io/ncbpfluffybear/slimecustomizer/objects/NPCustomSCItem.java +++ b/src/main/java/io/ncbpfluffybear/slimecustomizer/objects/NPCustomSCItem.java @@ -4,9 +4,10 @@ import io.github.thebusybiscuit.slimefun4.api.items.SlimefunItem; import io.github.thebusybiscuit.slimefun4.api.items.SlimefunItemStack; import io.github.thebusybiscuit.slimefun4.api.recipes.RecipeType; -import io.github.thebusybiscuit.slimefun4.core.attributes.NotPlaceable; import org.bukkit.inventory.ItemStack; +import javax.annotation.ParametersAreNonnullByDefault; + /** * The {@link NPCustomSCItem} class is a wrapper * for the {@link SlimefunItem}. Modified to not be placeable @@ -15,10 +16,12 @@ */ public class NPCustomSCItem extends SlimefunItem implements SCNotPlaceable { + @ParametersAreNonnullByDefault public NPCustomSCItem(ItemGroup category, SlimefunItemStack item, RecipeType recipeType, ItemStack[] recipe, ItemStack output) { super(category, item, recipeType, recipe, output); } + @ParametersAreNonnullByDefault public NPCustomSCItem(ItemGroup category, SlimefunItemStack item, RecipeType recipeType, ItemStack[] recipe) { super(category, item, recipeType, recipe); } diff --git a/src/main/java/io/ncbpfluffybear/slimecustomizer/objects/SCAGenerator.java b/src/main/java/io/ncbpfluffybear/slimecustomizer/objects/SCAGenerator.java index 5555836..fcb7bd8 100644 --- a/src/main/java/io/ncbpfluffybear/slimecustomizer/objects/SCAGenerator.java +++ b/src/main/java/io/ncbpfluffybear/slimecustomizer/objects/SCAGenerator.java @@ -1,7 +1,10 @@ package io.ncbpfluffybear.slimecustomizer.objects; import io.github.thebusybiscuit.slimefun4.api.SlimefunAddon; +import io.github.thebusybiscuit.slimefun4.api.items.ItemGroup; import io.github.thebusybiscuit.slimefun4.api.items.ItemState; +import io.github.thebusybiscuit.slimefun4.api.items.SlimefunItemStack; +import io.github.thebusybiscuit.slimefun4.api.recipes.RecipeType; import io.github.thebusybiscuit.slimefun4.core.attributes.MachineProcessHolder; import io.github.thebusybiscuit.slimefun4.core.handlers.BlockBreakHandler; import io.github.thebusybiscuit.slimefun4.core.machines.MachineProcessor; @@ -10,6 +13,7 @@ import io.github.thebusybiscuit.slimefun4.implementation.handlers.SimpleBlockBreakHandler; import io.github.thebusybiscuit.slimefun4.implementation.items.electric.AbstractEnergyProvider; import io.github.thebusybiscuit.slimefun4.implementation.operations.FuelOperation; +import io.github.thebusybiscuit.slimefun4.libraries.dough.items.CustomItemStack; import io.github.thebusybiscuit.slimefun4.libraries.dough.protection.Interaction; import io.github.thebusybiscuit.slimefun4.utils.ChestMenuUtils; import io.github.thebusybiscuit.slimefun4.utils.SlimefunUtils; @@ -17,15 +21,11 @@ import me.mrCookieSlime.CSCoreLibPlugin.Configuration.Config; import me.mrCookieSlime.CSCoreLibPlugin.general.Inventory.ChestMenu; import me.mrCookieSlime.CSCoreLibPlugin.general.Inventory.ClickAction; -import io.github.thebusybiscuit.slimefun4.api.recipes.RecipeType; -import io.github.thebusybiscuit.slimefun4.api.items.ItemGroup; import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.abstractItems.MachineFuel; import me.mrCookieSlime.Slimefun.api.BlockStorage; -import io.github.thebusybiscuit.slimefun4.api.items.SlimefunItemStack; import me.mrCookieSlime.Slimefun.api.inventory.BlockMenu; import me.mrCookieSlime.Slimefun.api.inventory.BlockMenuPreset; import me.mrCookieSlime.Slimefun.api.item_transport.ItemTransportFlow; -import io.github.thebusybiscuit.slimefun4.libraries.dough.items.CustomItemStack; import org.apache.commons.lang.Validate; import org.bukkit.Location; import org.bukkit.Material; @@ -34,6 +34,9 @@ import org.bukkit.event.inventory.InventoryClickEvent; import org.bukkit.inventory.ItemStack; +import javax.annotation.Nonnull; +import javax.annotation.Nullable; +import javax.annotation.ParametersAreNonnullByDefault; import java.util.HashMap; import java.util.Map; @@ -55,6 +58,7 @@ public abstract class SCAGenerator extends AbstractEnergyProvider implements Mac private int energyProducedPerTick = -1; private int energyCapacity = -1; + @ParametersAreNonnullByDefault protected SCAGenerator(ItemGroup category, SlimefunItemStack item, RecipeType recipeType, ItemStack[] recipe) { super(category, item, recipeType, recipe); @@ -86,29 +90,31 @@ public int[] getSlotsAccessedByItemTransport(ItemTransportFlow flow) { registerDefaultFuelTypes(); } + @Nonnull @Override public MachineProcessor getMachineProcessor() { return processor; } + @Nonnull protected BlockBreakHandler onBlockBreak() { return new SimpleBlockBreakHandler() { @Override - public void onBlockBreak(Block b) { - BlockMenu inv = BlockStorage.getInventory(b); + public void onBlockBreak(@Nonnull Block block) { + BlockMenu inv = BlockStorage.getInventory(block); if (inv != null) { - inv.dropItems(b.getLocation(), getInputSlots()); - inv.dropItems(b.getLocation(), getOutputSlots()); + inv.dropItems(block.getLocation(), getInputSlots()); + inv.dropItems(block.getLocation(), getOutputSlots()); } - processor.endOperation(b); + processor.endOperation(block); } }; } - private void constructMenu(BlockMenuPreset preset) { + private void constructMenu(@Nonnull BlockMenuPreset preset) { for (int i : border) { preset.addItem(i, ChestMenuUtils.getBackground(), ChestMenuUtils.getEmptyClickHandler()); } @@ -152,16 +158,16 @@ public int[] getOutputSlots() { } @Override - public int getGeneratedOutput(Location l, Config data) { - BlockMenu inv = BlockStorage.getInventory(l); - FuelOperation operation = processor.getOperation(l); + public int getGeneratedOutput(@Nonnull Location location, @Nonnull Config data) { + BlockMenu inv = BlockStorage.getInventory(location); + FuelOperation operation = processor.getOperation(location); if (operation != null) { if (!operation.isFinished()) { processor.updateProgressBar(inv, 22, operation); if (isChargeable()) { - int charge = getCharge(l, data); + int charge = getCharge(location, data); if (getCapacity() - charge >= getEnergyProduction()) { operation.addProgress(1); @@ -186,7 +192,7 @@ public int getGeneratedOutput(Location l, Config data) { inv.replaceExistingItem(22, new CustomItemStack(Material.BLACK_STAINED_GLASS_PANE, " ")); - processor.endOperation(l); + processor.endOperation(location); return 0; } } else { @@ -198,14 +204,14 @@ public int getGeneratedOutput(Location l, Config data) { inv.consumeItem(entry.getKey(), entry.getValue()); } - processor.startOperation(l, new FuelOperation(fuel)); + processor.startOperation(location, new FuelOperation(fuel)); } return 0; } } - private boolean isBucket(ItemStack item) { + private boolean isBucket(@Nullable ItemStack item) { if (item == null) { return false; } @@ -214,7 +220,8 @@ private boolean isBucket(ItemStack item) { return item.getType() == Material.LAVA_BUCKET || SlimefunUtils.isItemSimilar(wrapper, SlimefunItems.FUEL_BUCKET, true) || SlimefunUtils.isItemSimilar(wrapper, SlimefunItems.OIL_BUCKET, true); } - private MachineFuel findRecipe(BlockMenu menu, Map found) { + @Nullable + private MachineFuel findRecipe(@Nonnull BlockMenu menu, @Nonnull Map found) { for (MachineFuel fuel : fuelTypes) { for (int slot : getInputSlots()) { if (fuel.test(menu.getItemInSlot(slot))) { @@ -256,6 +263,7 @@ public int getEnergyProduction() { * * @return This method will return the current instance of {@link SCAGenerator}, so that can be chained. */ + @Nonnull public final SCAGenerator setCapacity(int capacity) { Validate.isTrue(capacity >= 0, "The capacity cannot be negative!"); @@ -275,6 +283,7 @@ public final SCAGenerator setCapacity(int capacity) { * * @return This method will return the current instance of {@link SCAGenerator}, so that can be chained. */ + @Nonnull public final SCAGenerator setEnergyProduction(int energyProduced) { Validate.isTrue(energyProduced > 0, "The energy production must be greater than zero!"); @@ -283,7 +292,7 @@ public final SCAGenerator setEnergyProduction(int energyProduced) { } @Override - public void register(SlimefunAddon addon) { + public void register(@Nonnull SlimefunAddon addon) { this.addon = addon; if (getCapacity() < 0) { diff --git a/src/main/java/io/ncbpfluffybear/slimecustomizer/objects/SCMachine.java b/src/main/java/io/ncbpfluffybear/slimecustomizer/objects/SCMachine.java index dccc5a1..0f702df 100644 --- a/src/main/java/io/ncbpfluffybear/slimecustomizer/objects/SCMachine.java +++ b/src/main/java/io/ncbpfluffybear/slimecustomizer/objects/SCMachine.java @@ -1,15 +1,18 @@ package io.ncbpfluffybear.slimecustomizer.objects; import dev.j3fftw.extrautils.utils.LoreBuilderDynamic; -import io.github.thebusybiscuit.slimefun4.utils.SlimefunUtils; -import io.ncbpfluffybear.slimecustomizer.Utils; -import io.github.thebusybiscuit.slimefun4.api.recipes.RecipeType; import io.github.thebusybiscuit.slimefun4.api.items.SlimefunItemStack; +import io.github.thebusybiscuit.slimefun4.api.recipes.RecipeType; import io.github.thebusybiscuit.slimefun4.libraries.dough.config.Config; +import io.github.thebusybiscuit.slimefun4.utils.SlimefunUtils; +import io.ncbpfluffybear.slimecustomizer.Utils; import org.bukkit.Material; import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.meta.ItemMeta; +import javax.annotation.Nonnull; +import javax.annotation.Nullable; +import javax.annotation.ParametersAreNonnullByDefault; import java.util.ArrayList; import java.util.Arrays; import java.util.List; @@ -27,18 +30,23 @@ public class SCMachine { private final String key; private boolean valid = true; + @Nonnull private final String materialString; + @Nonnull private final Material progressItem; + @Nonnull private final String machineType; private ItemStack block; private int energyConsumption = 0; private int energyProduction = 0; private int energyBuffer = 0; + @Nonnull private final ItemStack[] recipe; + @Nonnull private final RecipeType recipeType; private SlimefunItemStack machineStack; - + @ParametersAreNonnullByDefault public SCMachine(Config config, String key, String machineType) { this.config = config; this.key = key; @@ -52,7 +60,7 @@ public SCMachine(Config config, String key, String machineType) { recipeType = Utils.getRecipeType(config.getString(key + ".crafting-recipe-type"), key); if (recipeType == null) {valid = false;} recipe = Utils.buildCraftingRecipe(config, key, recipeType); - if (recipe == null) {valid = false;} + if (recipe.length == 0) {valid = false;} buildMachineStack(); } @@ -122,6 +130,7 @@ private void buildMachineStack() { machineStack.setItemMeta(tempMeta); } + @Nullable private String getMachineTag() { if (machineType.equalsIgnoreCase("machine")) { return "&b" + Utils.capitalize(machineType); diff --git a/src/main/java/io/ncbpfluffybear/slimecustomizer/objects/SCMenu.java b/src/main/java/io/ncbpfluffybear/slimecustomizer/objects/SCMenu.java index 89672bd..1d4bc18 100644 --- a/src/main/java/io/ncbpfluffybear/slimecustomizer/objects/SCMenu.java +++ b/src/main/java/io/ncbpfluffybear/slimecustomizer/objects/SCMenu.java @@ -4,16 +4,20 @@ import io.github.thebusybiscuit.slimefun4.core.guide.GuideHistory; import io.github.thebusybiscuit.slimefun4.implementation.Slimefun; import io.github.thebusybiscuit.slimefun4.implementation.guide.SurvivalSlimefunGuide; +import io.github.thebusybiscuit.slimefun4.libraries.dough.items.CustomItemStack; import io.github.thebusybiscuit.slimefun4.libraries.dough.items.ItemUtils; import io.github.thebusybiscuit.slimefun4.utils.ChestMenuUtils; import io.github.thebusybiscuit.slimefun4.utils.itemstack.ItemStackWrapper; import me.mrCookieSlime.CSCoreLibPlugin.general.Inventory.ChestMenu; -import io.github.thebusybiscuit.slimefun4.libraries.dough.items.CustomItemStack; import org.bukkit.ChatColor; import org.bukkit.Material; import org.bukkit.entity.Player; import org.bukkit.inventory.ItemStack; +import javax.annotation.Nonnull; +import javax.annotation.Nullable; +import javax.annotation.ParametersAreNonnullByDefault; + /** * The {@link SCMenu} is a {@link ChestMenu} for * showing dual input/outputs. @@ -28,11 +32,12 @@ public SCMenu(String title) { super(title); } - public void addBackButton(SurvivalSlimefunGuide guide, Player p, PlayerProfile profile) { + @ParametersAreNonnullByDefault + public void addBackButton(SurvivalSlimefunGuide guide, Player player, PlayerProfile profile) { GuideHistory history = profile.getGuideHistory(); if (history.size() > 1) { - this.replaceExistingItem(BACK_BUTTON_SLOT, new CustomItemStack(ChestMenuUtils.getBackButton(p, "", "&fLeft Click: &7Go back to previous Page", "&fShift + left Click: &7Go back to Main Menu"))); + this.replaceExistingItem(BACK_BUTTON_SLOT, getBackButtonMainMenu(player)); this.addMenuClickHandler(BACK_BUTTON_SLOT, (pl, s, ic, action) -> { if (!action.isRightClicked() && action.isShiftClicked()) { @@ -44,7 +49,10 @@ public void addBackButton(SurvivalSlimefunGuide guide, Player p, PlayerProfile p }); } else { - this.replaceExistingItem(BACK_BUTTON_SLOT, new CustomItemStack(ChestMenuUtils.getBackButton(p, "", ChatColor.GRAY + Slimefun.getLocalization().getMessage(p, "guide.back.guide")))); + this.replaceExistingItem( + BACK_BUTTON_SLOT, + getBackButton(player) + ); this.addMenuClickHandler(BACK_BUTTON_SLOT, (pl, s, is, action) -> { guide.openMainMenu(profile, 1); return false; @@ -73,8 +81,9 @@ public void wipe(int start, int finish, boolean blockClicks) { } } - public ItemStack pushItem(ItemStack item, int... slots) { - if (item == null || item.getType() == Material.AIR) { + @Nullable + public ItemStack pushItem(@Nonnull ItemStack item, int... slots) { + if (item.getType() == Material.AIR) { throw new IllegalArgumentException("Cannot push null or AIR"); } @@ -121,4 +130,22 @@ public boolean hasClickHandler(int slot) { public void setSize(int size) { addItem(size - 1, null); } + + @Nonnull + private static CustomItemStack getBackButtonMainMenu(@Nonnull Player player) { + return new CustomItemStack(ChestMenuUtils.getBackButton( + player, + "", + "&fLeft Click: &7Go back to previous Page", "&fShift + left Click: &7Go back to Main Menu" + )); + } + + @Nonnull + private static CustomItemStack getBackButton(@Nonnull Player player) { + return new CustomItemStack(ChestMenuUtils.getBackButton( + player, + "", + ChatColor.GRAY + Slimefun.getLocalization().getMessage(player, "guide.back.guide") + )); + } } \ No newline at end of file diff --git a/src/main/java/io/ncbpfluffybear/slimecustomizer/objects/SCMobDrop.java b/src/main/java/io/ncbpfluffybear/slimecustomizer/objects/SCMobDrop.java index fd5acee..a9a4241 100644 --- a/src/main/java/io/ncbpfluffybear/slimecustomizer/objects/SCMobDrop.java +++ b/src/main/java/io/ncbpfluffybear/slimecustomizer/objects/SCMobDrop.java @@ -1,12 +1,14 @@ package io.ncbpfluffybear.slimecustomizer.objects; -import io.github.thebusybiscuit.slimefun4.api.items.SlimefunItem; -import io.github.thebusybiscuit.slimefun4.core.attributes.RandomMobDrop; -import io.github.thebusybiscuit.slimefun4.api.recipes.RecipeType; import io.github.thebusybiscuit.slimefun4.api.items.ItemGroup; +import io.github.thebusybiscuit.slimefun4.api.items.SlimefunItem; import io.github.thebusybiscuit.slimefun4.api.items.SlimefunItemStack; +import io.github.thebusybiscuit.slimefun4.api.recipes.RecipeType; +import io.github.thebusybiscuit.slimefun4.core.attributes.RandomMobDrop; import org.bukkit.inventory.ItemStack; +import javax.annotation.ParametersAreNonnullByDefault; + /** * A custom basic implementation of {@link RandomMobDrop} * with a constructor parameter for a chance value. @@ -15,13 +17,19 @@ public class SCMobDrop extends SlimefunItem implements RandomMobDrop { private final int chance; + @ParametersAreNonnullByDefault public SCMobDrop(ItemGroup category, SlimefunItemStack item, RecipeType recipeType, ItemStack[] recipe, int chance) { super(category, item, recipeType, recipe); this.chance = chance; } - public SCMobDrop(ItemGroup category, SlimefunItemStack item, RecipeType recipeType, ItemStack[] recipe, - ItemStack recipeOutput, int chance + @ParametersAreNonnullByDefault + public SCMobDrop(ItemGroup category, + SlimefunItemStack item, + RecipeType recipeType, + ItemStack[] recipe, + ItemStack recipeOutput, + int chance ) { super(category, item, recipeType, recipe, recipeOutput); this.chance = chance; diff --git a/src/main/java/io/ncbpfluffybear/slimecustomizer/objects/WindowsExplorerStringComparator.java b/src/main/java/io/ncbpfluffybear/slimecustomizer/objects/WindowsExplorerStringComparator.java index 29ae6b7..1562597 100644 --- a/src/main/java/io/ncbpfluffybear/slimecustomizer/objects/WindowsExplorerStringComparator.java +++ b/src/main/java/io/ncbpfluffybear/slimecustomizer/objects/WindowsExplorerStringComparator.java @@ -2,13 +2,16 @@ import java.util.Comparator; -public class WindowsExplorerStringComparator implements Comparator -{ - private String str1, str2; - private int pos1, pos2, len1, len2; +public class WindowsExplorerStringComparator implements Comparator { - public int compare(String s1, String s2) - { + private String str1; + private String str2; + private int pos1; + private int pos2; + private int len1; + private int len2; + + public int compare(String s1, String s2) { str1 = s1; str2 = s2; len1 = str1.length(); @@ -16,24 +19,24 @@ public int compare(String s1, String s2) pos1 = pos2 = 0; int result = 0; - while (result == 0 && pos1 < len1 && pos2 < len2) - { + while (result == 0 && pos1 < len1 && pos2 < len2) { char ch1 = str1.charAt(pos1); char ch2 = str2.charAt(pos2); - if (Character.isDigit(ch1)) - { + if (Character.isDigit(ch1)) { result = Character.isDigit(ch2) ? compareNumbers() : -1; - } - else if (Character.isLetter(ch1)) - { + } else if (Character.isLetter(ch1)) { result = Character.isLetter(ch2) ? compareOther(true) : 1; - } - else - { - result = Character.isDigit(ch2) ? 1 - : Character.isLetter(ch2) ? -1 - : compareOther(false); + } else { + if (Character.isDigit(ch2)) { + result = 1; + } else { + if (Character.isLetter(ch2)) { + result = -1; + } else { + result = compareOther(false); + } + } } pos1++; @@ -43,41 +46,35 @@ else if (Character.isLetter(ch1)) return result == 0 ? len1 - len2 : result; } - private int compareNumbers() - { + private int compareNumbers() { int end1 = pos1 + 1; - while (end1 < len1 && Character.isDigit(str1.charAt(end1))) - { + while (end1 < len1 && Character.isDigit(str1.charAt(end1))) { end1++; } + int fullLen1 = end1 - pos1; - while (pos1 < end1 && str1.charAt(pos1) == '0') - { + while (pos1 < end1 && str1.charAt(pos1) == '0') { pos1++; } int end2 = pos2 + 1; - while (end2 < len2 && Character.isDigit(str2.charAt(end2))) - { + while (end2 < len2 && Character.isDigit(str2.charAt(end2))) { end2++; } + int fullLen2 = end2 - pos2; - while (pos2 < end2 && str2.charAt(pos2) == '0') - { + while (pos2 < end2 && str2.charAt(pos2) == '0') { pos2++; } int delta = (end1 - pos1) - (end2 - pos2); - if (delta != 0) - { + if (delta != 0) { return delta; } - while (pos1 < end1 && pos2 < end2) - { + while (pos1 < end1 && pos2 < end2) { delta = str1.charAt(pos1++) - str2.charAt(pos2++); - if (delta != 0) - { + if (delta != 0) { return delta; } } @@ -88,22 +85,18 @@ private int compareNumbers() return fullLen2 - fullLen1; } - private int compareOther(boolean isLetters) - { + private int compareOther(boolean isLetters) { char ch1 = str1.charAt(pos1); char ch2 = str2.charAt(pos2); - if (ch1 == ch2) - { + if (ch1 == ch2) { return 0; } - if (isLetters) - { + if (isLetters) { ch1 = Character.toUpperCase(ch1); ch2 = Character.toUpperCase(ch2); - if (ch1 != ch2) - { + if (ch1 != ch2) { ch1 = Character.toLowerCase(ch1); ch2 = Character.toLowerCase(ch2); } diff --git a/src/main/java/io/ncbpfluffybear/slimecustomizer/registration/Categories.java b/src/main/java/io/ncbpfluffybear/slimecustomizer/registration/Categories.java index c20768b..ca74e5f 100644 --- a/src/main/java/io/ncbpfluffybear/slimecustomizer/registration/Categories.java +++ b/src/main/java/io/ncbpfluffybear/slimecustomizer/registration/Categories.java @@ -1,15 +1,16 @@ package io.ncbpfluffybear.slimecustomizer.registration; -import io.github.thebusybiscuit.slimefun4.utils.SlimefunUtils; -import io.ncbpfluffybear.slimecustomizer.SlimeCustomizer; -import io.ncbpfluffybear.slimecustomizer.Utils; import io.github.thebusybiscuit.slimefun4.api.items.ItemGroup; import io.github.thebusybiscuit.slimefun4.libraries.dough.config.Config; import io.github.thebusybiscuit.slimefun4.libraries.dough.items.CustomItemStack; +import io.github.thebusybiscuit.slimefun4.utils.SlimefunUtils; +import io.ncbpfluffybear.slimecustomizer.SlimeCustomizer; +import io.ncbpfluffybear.slimecustomizer.Utils; import org.bukkit.Material; import org.bukkit.NamespacedKey; import org.bukkit.inventory.ItemStack; +import javax.annotation.Nonnull; import java.util.concurrent.atomic.AtomicBoolean; /** @@ -18,9 +19,13 @@ * * @author NCBPFluffyBear */ -public class Categories { +public final class Categories { + + private Categories() { + throw new IllegalStateException("Utility class"); + } - public static boolean register(Config categories) { + public static boolean register(@Nonnull Config categories) { if (categories.getKeys().isEmpty()) { Utils.disable("No categories were found! Please add and use a category from categories.yml"); return false; @@ -46,7 +51,7 @@ public static boolean register(Config categories) { new CustomItemStack(item, name)); AtomicBoolean disable = new AtomicBoolean(false); - SlimeCustomizer.allCategories.forEach((key, storedCategory) -> { + SlimeCustomizer.getAllCategories().forEach((key, storedCategory) -> { if (key.equalsIgnoreCase(categoryKey)) { Utils.disable("The category " + categoryKey + " has already been registered!"); disable.set(true); @@ -56,7 +61,7 @@ public static boolean register(Config categories) { return false; } - SlimeCustomizer.allCategories.put(categoryKey, tempCategory); + SlimeCustomizer.getAllCategories().put(categoryKey, tempCategory); Utils.notify("Category " + categoryKey + " has been registered!"); } diff --git a/src/main/java/io/ncbpfluffybear/slimecustomizer/registration/Generators.java b/src/main/java/io/ncbpfluffybear/slimecustomizer/registration/Generators.java index a8a14e7..adc73d6 100644 --- a/src/main/java/io/ncbpfluffybear/slimecustomizer/registration/Generators.java +++ b/src/main/java/io/ncbpfluffybear/slimecustomizer/registration/Generators.java @@ -1,16 +1,17 @@ package io.ncbpfluffybear.slimecustomizer.registration; +import io.github.thebusybiscuit.slimefun4.api.items.ItemGroup; import io.github.thebusybiscuit.slimefun4.api.items.SlimefunItem; +import io.github.thebusybiscuit.slimefun4.libraries.dough.config.Config; import io.ncbpfluffybear.slimecustomizer.SlimeCustomizer; import io.ncbpfluffybear.slimecustomizer.Utils; import io.ncbpfluffybear.slimecustomizer.objects.CustomGenerator; import io.ncbpfluffybear.slimecustomizer.objects.SCMachine; -import io.github.thebusybiscuit.slimefun4.api.items.ItemGroup; import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.abstractItems.MachineFuel; -import io.github.thebusybiscuit.slimefun4.libraries.dough.config.Config; import org.bukkit.Material; import org.bukkit.inventory.ItemStack; +import javax.annotation.Nonnull; import java.util.ArrayList; import java.util.List; import java.util.logging.Level; @@ -21,14 +22,20 @@ * * @author NCBPFluffyBear */ -public class Generators { +public final class Generators { + + private Generators() { + throw new IllegalStateException("Utility class"); + } - public static boolean register(Config generators) { + public static boolean register(@Nonnull Config generators) { for (String generatorKey : generators.getKeys()) { if (generatorKey.equals("EXAMPLE_GENERATOR")) { - SlimeCustomizer.getInstance().getLogger().log(Level.WARNING, "Your generators.yml file still contains" + - " the example generator! " + - "Did you forget to set up the plugin?"); + SlimeCustomizer.getInstance().getLogger().warning( + "Your generators.yml file still contains" + + " the example generator! " + + "Did you forget to set up the plugin?" + ); } SCMachine generator = new SCMachine(generators, generatorKey, "generator"); @@ -50,14 +57,24 @@ public static boolean register(Config generators) { try { time = Integer.parseInt(generators.getString(path + ".time-in-seconds")); } catch (NumberFormatException e) { - Utils.disable("The time-in-seconds for recipe " + recipeKey + " for " + generatorKey - + " must be a positive integer!"); + Utils.disable( + "The time-in-seconds for recipe " + + recipeKey + + " for " + + generatorKey + + " must be a positive integer!" + ); return false; } if (time < 0) { - Utils.disable("The time-in-seconds for recipe " + recipeKey + " for " + generatorKey - + " must be a positive integer!"); + Utils.disable( + "The time-in-seconds for recipe " + + recipeKey + + " for " + + generatorKey + + " must be a positive integer!" + ); return false; } @@ -77,8 +94,12 @@ public static boolean register(Config generators) { /* Validate amount */ if (i == 0 && type.equalsIgnoreCase("NONE")) { - Utils.disable("The the input type for recipe " + recipeKey + " for " + generatorKey - + " can only be VANILLA or SLIMEFUN!"); + Utils.disable("The the input type for recipe " + + recipeKey + + " for " + + generatorKey + + " can only be VANILLA or SLIMEFUN!" + ); return false; } @@ -86,23 +107,41 @@ public static boolean register(Config generators) { try { amount = Integer.parseInt(generators.getString(path + "." + slot + ".amount")); } catch (NumberFormatException e) { - Utils.disable("The amount of " + slot + "s for recipe " + recipeKey + " for " + generatorKey - + " must be a positive integer!"); + Utils.disable("The amount of " + + slot + + "s for recipe " + + recipeKey + + " for " + + generatorKey + + " must be a positive integer!" + ); return false; } } if (amount < 0) { - Utils.disable("The amount of " + slot + "s for recipe " + recipeKey + " for " + generatorKey - + " must be a positive integer!"); + Utils.disable("The amount of " + + slot + + "s for recipe " + + recipeKey + + " for " + + generatorKey + + " must be a positive integer!" + ); return false; } if (type.equalsIgnoreCase("VANILLA")) { Material vanillaMat = Material.getMaterial(material); if (vanillaMat == null) { - Utils.disable("The " + slot + "ingredient for recipe" + recipeKey + " for " + generatorKey - + " is not a valid vanilla ID!"); + Utils.disable("The " + + slot + + "ingredient for recipe" + + recipeKey + + " for " + + generatorKey + + " is not a valid vanilla ID!" + ); return false; } else { if (i == 0) { @@ -118,8 +157,14 @@ public static boolean register(Config generators) { } else if (type.equalsIgnoreCase("SLIMEFUN")) { SlimefunItem sfMat = SlimefunItem.getById(material); if (sfMat == null) { - Utils.disable("The " + slot + " ingredient for recipe" + recipeKey + " for " + generatorKey - + " is not a valid Slimefun ID!"); + Utils.disable("The " + + slot + + " ingredient for recipe" + + recipeKey + + " for " + + generatorKey + + " is not a valid Slimefun ID!" + ); return false; } else { if (i == 0) { @@ -143,12 +188,24 @@ public static boolean register(Config generators) { if (!Utils.checkFitsStackSize(output, slot, generatorKey, recipeKey)) {return false;} } } else if (i == 0) { - Utils.disable("The " + slot + " ingredient type for recipe" + recipeKey + " for " + generatorKey - + " can only be VANILLA, SLIMEFUN, or SAVEDITEM!"); + Utils.disable("The " + + slot + + " ingredient type for recipe" + + recipeKey + + " for " + + generatorKey + + " can only be VANILLA, SLIMEFUN, or SAVEDITEM!" + ); return false; } else if (!type.equalsIgnoreCase("NONE")) { - Utils.disable("The " + slot + " ingredient type for recipe" + recipeKey + " for " + generatorKey - + " can only be VANILLA, SLIMEFUN, SAVEDITEM, or NONE!"); + Utils.disable("The " + + slot + + " ingredient type for recipe" + + recipeKey + + " for " + + generatorKey + + " can only be VANILLA, SLIMEFUN, SAVEDITEM, or NONE!" + ); return false; } } @@ -157,10 +214,15 @@ public static boolean register(Config generators) { } - new CustomGenerator(category, generator.getMachineStack(), - generator.getRecipeType(), generator.getRecipe(), - generator.getProgressItem(), generator.getEnergyProduction(), - generator.getEnergyBuffer(), customRecipe + new CustomGenerator( + category, + generator.getMachineStack(), + generator.getRecipeType(), + generator.getRecipe(), + generator.getProgressItem(), + generator.getEnergyProduction(), + generator.getEnergyBuffer(), + customRecipe ).register(SlimeCustomizer.getInstance()); Utils.notify("Generator " + generatorKey + " has been registered!"); diff --git a/src/main/java/io/ncbpfluffybear/slimecustomizer/registration/Items.java b/src/main/java/io/ncbpfluffybear/slimecustomizer/registration/Items.java index 574e784..5453291 100644 --- a/src/main/java/io/ncbpfluffybear/slimecustomizer/registration/Items.java +++ b/src/main/java/io/ncbpfluffybear/slimecustomizer/registration/Items.java @@ -1,18 +1,19 @@ package io.ncbpfluffybear.slimecustomizer.registration; +import io.github.thebusybiscuit.slimefun4.api.items.ItemGroup; +import io.github.thebusybiscuit.slimefun4.api.items.SlimefunItemStack; +import io.github.thebusybiscuit.slimefun4.api.recipes.RecipeType; +import io.github.thebusybiscuit.slimefun4.libraries.dough.config.Config; import io.github.thebusybiscuit.slimefun4.utils.SlimefunUtils; import io.ncbpfluffybear.slimecustomizer.SlimeCustomizer; import io.ncbpfluffybear.slimecustomizer.Utils; import io.ncbpfluffybear.slimecustomizer.objects.CustomSCItem; -import io.github.thebusybiscuit.slimefun4.api.recipes.RecipeType; -import io.github.thebusybiscuit.slimefun4.api.items.ItemGroup; -import io.github.thebusybiscuit.slimefun4.api.items.SlimefunItemStack; -import io.github.thebusybiscuit.slimefun4.libraries.dough.config.Config; import io.ncbpfluffybear.slimecustomizer.objects.NPCustomSCItem; import org.bukkit.Material; import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.meta.ItemMeta; +import javax.annotation.Nonnull; import java.util.List; import java.util.logging.Level; @@ -22,12 +23,16 @@ * * @author NCBPFluffyBear */ -public class Items { +public final class Items { + + private Items() { + throw new IllegalStateException("Utility class"); + } - public static boolean register(Config items) { + public static boolean register(@Nonnull Config items) { for (String itemKey : items.getKeys()) { if (itemKey.equals("EXAMPLE_ITEM")) { - SlimeCustomizer.getInstance().getLogger().log(Level.WARNING, "Your items.yml file still contains the example item! " + + SlimeCustomizer.getInstance().getLogger().warning("Your items.yml file still contains the example item! " + "Did you forget to set up the plugin?"); } @@ -96,7 +101,7 @@ public static boolean register(Config items) { /* Crafting recipe */ ItemStack[] recipe = Utils.buildCraftingRecipe(items, itemKey, recipeType); - if (recipe == null) {return false;} + if (recipe.length == 0) {return false;} if (placeable) { if (itemType.equalsIgnoreCase("CUSTOM")) { diff --git a/src/main/java/io/ncbpfluffybear/slimecustomizer/registration/Machines.java b/src/main/java/io/ncbpfluffybear/slimecustomizer/registration/Machines.java index 488e653..497442c 100644 --- a/src/main/java/io/ncbpfluffybear/slimecustomizer/registration/Machines.java +++ b/src/main/java/io/ncbpfluffybear/slimecustomizer/registration/Machines.java @@ -3,14 +3,15 @@ import io.github.thebusybiscuit.slimefun4.api.items.ItemGroup; import io.github.thebusybiscuit.slimefun4.api.items.SlimefunItem; import io.github.thebusybiscuit.slimefun4.libraries.dough.collections.Pair; +import io.github.thebusybiscuit.slimefun4.libraries.dough.config.Config; import io.ncbpfluffybear.slimecustomizer.SlimeCustomizer; import io.ncbpfluffybear.slimecustomizer.Utils; import io.ncbpfluffybear.slimecustomizer.objects.CustomMachine; import io.ncbpfluffybear.slimecustomizer.objects.SCMachine; -import io.github.thebusybiscuit.slimefun4.libraries.dough.config.Config; import org.bukkit.Material; import org.bukkit.inventory.ItemStack; +import javax.annotation.Nonnull; import java.util.HashMap; import java.util.logging.Level; @@ -20,12 +21,16 @@ * * @author NCBPFluffyBear */ -public class Machines { +public final class Machines { + + private Machines() { + throw new IllegalStateException("Utility class"); + } - public static boolean register(Config machines) { + public static boolean register(@Nonnull Config machines) { for (String machineKey : machines.getKeys()) { if (machineKey.equals("EXAMPLE_MACHINE")) { - SlimeCustomizer.getInstance().getLogger().log(Level.WARNING, "Your machines.yml file still contains " + + SlimeCustomizer.getInstance().getLogger().warning("Your machines.yml file still contains " + "the example machine! Did you forget to set up the plugin?"); } diff --git a/src/main/java/io/ncbpfluffybear/slimecustomizer/registration/MobDrops.java b/src/main/java/io/ncbpfluffybear/slimecustomizer/registration/MobDrops.java index 94163b8..ea6ce2d 100644 --- a/src/main/java/io/ncbpfluffybear/slimecustomizer/registration/MobDrops.java +++ b/src/main/java/io/ncbpfluffybear/slimecustomizer/registration/MobDrops.java @@ -1,19 +1,20 @@ package io.ncbpfluffybear.slimecustomizer.registration; -import io.github.thebusybiscuit.slimefun4.utils.SlimefunUtils; -import io.ncbpfluffybear.slimecustomizer.SlimeCustomizer; -import io.ncbpfluffybear.slimecustomizer.Utils; -import io.ncbpfluffybear.slimecustomizer.objects.SCMobDrop; -import io.github.thebusybiscuit.slimefun4.api.recipes.RecipeType; import io.github.thebusybiscuit.slimefun4.api.items.ItemGroup; import io.github.thebusybiscuit.slimefun4.api.items.SlimefunItemStack; +import io.github.thebusybiscuit.slimefun4.api.recipes.RecipeType; import io.github.thebusybiscuit.slimefun4.libraries.dough.config.Config; import io.github.thebusybiscuit.slimefun4.libraries.dough.items.CustomItemStack; +import io.github.thebusybiscuit.slimefun4.utils.SlimefunUtils; +import io.ncbpfluffybear.slimecustomizer.SlimeCustomizer; +import io.ncbpfluffybear.slimecustomizer.Utils; +import io.ncbpfluffybear.slimecustomizer.objects.SCMobDrop; import org.bukkit.Material; import org.bukkit.entity.EntityType; import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.meta.ItemMeta; +import javax.annotation.Nonnull; import java.util.List; import java.util.logging.Level; @@ -23,12 +24,16 @@ * * @author NCBPFluffyBear */ -public class MobDrops { +public final class MobDrops { + + private MobDrops() { + throw new IllegalStateException("Utility class"); + } - public static boolean register(Config drops) { + public static boolean register(@Nonnull Config drops) { for (String dropKey : drops.getKeys()) { if (dropKey.equals("EXAMPLE_DROP")) { - SlimeCustomizer.getInstance().getLogger().log(Level.WARNING, "Your mob-drops.yml file still contains the example mob drop! " + + SlimeCustomizer.getInstance().getLogger().warning("Your mob-drops.yml file still contains the example mob drop! " + "Did you forget to set up the plugin?"); } @@ -75,6 +80,11 @@ public static boolean register(Config drops) { item = SlimefunUtils.getCustomHead(materialString.replace("SKULL", "")); } + if (item == null) { + Utils.disable("The item for " + dropKey + " could not be setup and the reason is unknown"); + return false; + } + item.setAmount(amount); // Building lore diff --git a/src/main/java/io/ncbpfluffybear/slimecustomizer/registration/SolarGenerators.java b/src/main/java/io/ncbpfluffybear/slimecustomizer/registration/SolarGenerators.java index 9745736..d9b7ab1 100644 --- a/src/main/java/io/ncbpfluffybear/slimecustomizer/registration/SolarGenerators.java +++ b/src/main/java/io/ncbpfluffybear/slimecustomizer/registration/SolarGenerators.java @@ -1,16 +1,17 @@ package io.ncbpfluffybear.slimecustomizer.registration; import dev.j3fftw.extrautils.utils.LoreBuilderDynamic; -import io.ncbpfluffybear.slimecustomizer.SlimeCustomizer; -import io.ncbpfluffybear.slimecustomizer.Utils; -import io.ncbpfluffybear.slimecustomizer.objects.CustomSolarGenerator; -import io.github.thebusybiscuit.slimefun4.api.recipes.RecipeType; import io.github.thebusybiscuit.slimefun4.api.items.ItemGroup; import io.github.thebusybiscuit.slimefun4.api.items.SlimefunItemStack; +import io.github.thebusybiscuit.slimefun4.api.recipes.RecipeType; import io.github.thebusybiscuit.slimefun4.libraries.dough.config.Config; +import io.ncbpfluffybear.slimecustomizer.SlimeCustomizer; +import io.ncbpfluffybear.slimecustomizer.Utils; +import io.ncbpfluffybear.slimecustomizer.objects.CustomSolarGenerator; import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.meta.ItemMeta; +import javax.annotation.Nonnull; import java.util.ArrayList; import java.util.Arrays; import java.util.List; @@ -24,12 +25,16 @@ * * @author NCBPFluffyBear */ -public class SolarGenerators { +public final class SolarGenerators { + + private SolarGenerators() { + throw new IllegalStateException("Utility class"); + } - public static boolean register(Config generators) { + public static boolean register(@Nonnull Config generators) { for (String generatorKey : generators.getKeys()) { if (generatorKey.equals("EXAMPLE_SOLAR_GENERATOR")) { - SlimeCustomizer.getInstance().getLogger().log(Level.WARNING, "Your solar-generators.yml file still contains" + + SlimeCustomizer.getInstance().getLogger().warning("Your solar-generators.yml file still contains" + " the example solar generator! " + "Did you forget to set up the plugin?"); } @@ -73,7 +78,7 @@ public static boolean register(Config generators) { // Crafting recipe ItemStack[] recipe = Utils.buildCraftingRecipe(generators, generatorKey, recipeType); - if (recipe == null) {return false;} + if (recipe.length == 0) {return false;} // Building lore List itemLore = Utils.colorList(Stream.concat(