From df4a87d9fad00be6f4030b5308c351f318f02fda Mon Sep 17 00:00:00 2001 From: TheBusyBiscuit Date: Sun, 11 Oct 2020 15:41:42 +0200 Subject: [PATCH] [Ci skip] A little bit of refactoring --- .../slimefun4/core/SlimefunRegistry.java | 9 +- .../core/handlers/RainbowTickHandler.java | 20 ++- .../items/cargo/AbstractCargoNode.java | 4 +- .../setup/SlimefunItemSetup.java | 14 +- .../slimefun4/utils/ColoredMaterials.java | 160 ++++++++++++++++++ 5 files changed, 187 insertions(+), 20 deletions(-) create mode 100644 src/main/java/io/github/thebusybiscuit/slimefun4/utils/ColoredMaterials.java diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/core/SlimefunRegistry.java b/src/main/java/io/github/thebusybiscuit/slimefun4/core/SlimefunRegistry.java index 1b05dbcf1..ae85b19ab 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/core/SlimefunRegistry.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/core/SlimefunRegistry.java @@ -11,6 +11,9 @@ import java.util.Set; import java.util.UUID; import java.util.concurrent.ConcurrentHashMap; +import javax.annotation.Nonnull; + +import org.apache.commons.lang.Validate; import org.bukkit.Server; import org.bukkit.entity.Entity; import org.bukkit.entity.EntityType; @@ -47,7 +50,7 @@ import me.mrCookieSlime.Slimefun.api.inventory.UniversalBlockMenu; * @author TheBusyBiscuit * */ -public class SlimefunRegistry { +public final class SlimefunRegistry { private final Map slimefunIds = new HashMap<>(); private final List slimefunItems = new ArrayList<>(); @@ -86,7 +89,9 @@ public class SlimefunRegistry { private final Map automatedCraftingChamberRecipes = new HashMap<>(); - public void load(Config cfg) { + public void load(@Nonnull Config cfg) { + Validate.notNull(cfg, "The Config cannot be null!"); + boolean showVanillaRecipes = cfg.getBoolean("guide.show-vanilla-recipes"); layouts.put(SlimefunGuideLayout.CHEST, new ChestSlimefunGuide(showVanillaRecipes)); diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/core/handlers/RainbowTickHandler.java b/src/main/java/io/github/thebusybiscuit/slimefun4/core/handlers/RainbowTickHandler.java index 5cd2867ea..4ba7ed63a 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/core/handlers/RainbowTickHandler.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/core/handlers/RainbowTickHandler.java @@ -1,6 +1,9 @@ package io.github.thebusybiscuit.slimefun4.core.handlers; import java.util.Arrays; +import java.util.List; + +import javax.annotation.Nonnull; import org.apache.commons.lang.Validate; import org.bukkit.Material; @@ -10,7 +13,6 @@ import org.bukkit.block.data.BlockData; import org.bukkit.block.data.type.GlassPane; import io.github.thebusybiscuit.cscorelib2.collections.LoopIterator; -import io.github.thebusybiscuit.cscorelib2.materials.MaterialCollection; import io.github.thebusybiscuit.slimefun4.api.MinecraftVersion; import io.github.thebusybiscuit.slimefun4.implementation.SlimefunPlugin; import io.github.thebusybiscuit.slimefun4.implementation.items.blocks.RainbowBlock; @@ -34,18 +36,22 @@ public class RainbowTickHandler extends BlockTicker { private final boolean glassPanes; private Material material; - public RainbowTickHandler(Material... materials) { + public RainbowTickHandler(@Nonnull List materials) { Validate.noNullElements(materials, "A RainbowTicker cannot have a Material that is null!"); - if (materials.length == 0) { + if (materials.isEmpty()) { throw new IllegalArgumentException("A RainbowTicker must have at least one Material associated with it!"); } glassPanes = containsGlassPanes(materials); - iterator = new LoopIterator<>(Arrays.asList(materials)); + iterator = new LoopIterator<>(materials); material = iterator.next(); } + public RainbowTickHandler(Material... materials) { + this(Arrays.asList(materials)); + } + /** * This method checks whether a given {@link Material} array contains any {@link Material} * that would result in a {@link GlassPane} {@link BlockData}. @@ -57,7 +63,7 @@ public class RainbowTickHandler extends BlockTicker { * * @return Whether the array contained any {@link GlassPane} materials */ - private boolean containsGlassPanes(Material[] materials) { + private boolean containsGlassPanes(@Nonnull List materials) { if (SlimefunPlugin.getMinecraftVersion() == MinecraftVersion.UNIT_TEST) { // BlockData is not available to us during Unit Tests :/ return false; @@ -75,10 +81,6 @@ public class RainbowTickHandler extends BlockTicker { return false; } - public RainbowTickHandler(MaterialCollection collection) { - this(collection.getAsArray()); - } - @Override public void tick(Block b, SlimefunItem item, Config data) { if (b.getType() == Material.AIR) { diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/cargo/AbstractCargoNode.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/cargo/AbstractCargoNode.java index 56534ae8d..d7fbabe69 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/cargo/AbstractCargoNode.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/cargo/AbstractCargoNode.java @@ -6,12 +6,12 @@ import org.bukkit.event.block.BlockPlaceEvent; import org.bukkit.inventory.ItemStack; import io.github.thebusybiscuit.cscorelib2.item.CustomItem; -import io.github.thebusybiscuit.cscorelib2.materials.MaterialCollections; import io.github.thebusybiscuit.cscorelib2.protection.ProtectableAction; import io.github.thebusybiscuit.slimefun4.core.handlers.BlockPlaceHandler; import io.github.thebusybiscuit.slimefun4.implementation.SlimefunPlugin; import io.github.thebusybiscuit.slimefun4.utils.ChatUtils; import io.github.thebusybiscuit.slimefun4.utils.ChestMenuUtils; +import io.github.thebusybiscuit.slimefun4.utils.ColoredMaterials; import io.github.thebusybiscuit.slimefun4.utils.HeadTexture; import io.github.thebusybiscuit.slimefun4.utils.NumberUtils; import me.mrCookieSlime.Slimefun.Lists.RecipeType; @@ -100,7 +100,7 @@ abstract class AbstractCargoNode extends SlimefunItem { menu.replaceExistingItem(slotCurrent, new CustomItem(HeadTexture.CHEST_TERMINAL.getAsItemStack(), "&bChannel ID: &3" + (channel + 1))); menu.addMenuClickHandler(slotCurrent, ChestMenuUtils.getEmptyClickHandler()); } else { - menu.replaceExistingItem(slotCurrent, new CustomItem(MaterialCollections.getAllWoolColors().get(channel), "&bChannel ID: &3" + (channel + 1))); + menu.replaceExistingItem(slotCurrent, new CustomItem(ColoredMaterials.WOOL.get(channel), "&bChannel ID: &3" + (channel + 1))); menu.addMenuClickHandler(slotCurrent, ChestMenuUtils.getEmptyClickHandler()); } diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/setup/SlimefunItemSetup.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/setup/SlimefunItemSetup.java index 840ef13f5..6859f4fd7 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/setup/SlimefunItemSetup.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/setup/SlimefunItemSetup.java @@ -15,7 +15,6 @@ import org.bukkit.potion.PotionEffectType; import org.bukkit.potion.PotionType; import io.github.thebusybiscuit.cscorelib2.item.CustomItem; -import io.github.thebusybiscuit.cscorelib2.materials.MaterialCollections; import io.github.thebusybiscuit.slimefun4.api.MinecraftVersion; import io.github.thebusybiscuit.slimefun4.api.SlimefunAddon; import io.github.thebusybiscuit.slimefun4.core.attributes.Radioactivity; @@ -189,6 +188,7 @@ import io.github.thebusybiscuit.slimefun4.implementation.items.weapons.IcyBow; import io.github.thebusybiscuit.slimefun4.implementation.items.weapons.SeismicAxe; import io.github.thebusybiscuit.slimefun4.implementation.items.weapons.SwordOfBeheading; import io.github.thebusybiscuit.slimefun4.implementation.items.weapons.VampireBlade; +import io.github.thebusybiscuit.slimefun4.utils.ColoredMaterials; import io.github.thebusybiscuit.slimefun4.utils.HeadTexture; import io.github.thebusybiscuit.slimefun4.utils.SlimefunUtils; import me.mrCookieSlime.Slimefun.Lists.RecipeType; @@ -2313,32 +2313,32 @@ public final class SlimefunItemSetup { new RainbowBlock(categories.magicalGadgets, SlimefunItems.RAINBOW_WOOL, RecipeType.ANCIENT_ALTAR, new ItemStack[] {new ItemStack(Material.WHITE_WOOL), new ItemStack(Material.WHITE_WOOL), new ItemStack(Material.WHITE_WOOL), new ItemStack(Material.WHITE_WOOL), SlimefunItems.RAINBOW_RUNE, new ItemStack(Material.WHITE_WOOL), new ItemStack(Material.WHITE_WOOL), new ItemStack(Material.WHITE_WOOL), new ItemStack(Material.WHITE_WOOL)}, - new SlimefunItemStack(SlimefunItems.RAINBOW_WOOL, 8), new RainbowTickHandler(MaterialCollections.getAllWoolColors())) + new SlimefunItemStack(SlimefunItems.RAINBOW_WOOL, 8), new RainbowTickHandler(ColoredMaterials.WOOL)) .register(plugin); new RainbowBlock(categories.magicalGadgets, SlimefunItems.RAINBOW_GLASS, RecipeType.ANCIENT_ALTAR, new ItemStack[] {new ItemStack(Material.WHITE_STAINED_GLASS), new ItemStack(Material.WHITE_STAINED_GLASS), new ItemStack(Material.WHITE_STAINED_GLASS), new ItemStack(Material.WHITE_STAINED_GLASS), SlimefunItems.RAINBOW_RUNE, new ItemStack(Material.WHITE_STAINED_GLASS), new ItemStack(Material.WHITE_STAINED_GLASS), new ItemStack(Material.WHITE_STAINED_GLASS), new ItemStack(Material.WHITE_STAINED_GLASS)}, - new SlimefunItemStack(SlimefunItems.RAINBOW_GLASS, 8), new RainbowTickHandler(MaterialCollections.getAllStainedGlassColors())) + new SlimefunItemStack(SlimefunItems.RAINBOW_GLASS, 8), new RainbowTickHandler(ColoredMaterials.STAINED_GLASS)) .register(plugin); new RainbowBlock(categories.magicalGadgets, SlimefunItems.RAINBOW_GLASS_PANE, RecipeType.ANCIENT_ALTAR, new ItemStack[] {new ItemStack(Material.WHITE_STAINED_GLASS_PANE), new ItemStack(Material.WHITE_STAINED_GLASS_PANE), new ItemStack(Material.WHITE_STAINED_GLASS_PANE), new ItemStack(Material.WHITE_STAINED_GLASS_PANE), SlimefunItems.RAINBOW_RUNE, new ItemStack(Material.WHITE_STAINED_GLASS_PANE), new ItemStack(Material.WHITE_STAINED_GLASS_PANE), new ItemStack(Material.WHITE_STAINED_GLASS_PANE), new ItemStack(Material.WHITE_STAINED_GLASS_PANE)}, - new SlimefunItemStack(SlimefunItems.RAINBOW_GLASS_PANE, 8), new RainbowTickHandler(MaterialCollections.getAllStainedGlassPaneColors())) + new SlimefunItemStack(SlimefunItems.RAINBOW_GLASS_PANE, 8), new RainbowTickHandler(ColoredMaterials.STAINED_GLASS_PANE)) .register(plugin); new RainbowBlock(categories.magicalGadgets, SlimefunItems.RAINBOW_CLAY, RecipeType.ANCIENT_ALTAR, new ItemStack[] {new ItemStack(Material.WHITE_TERRACOTTA), new ItemStack(Material.WHITE_TERRACOTTA), new ItemStack(Material.WHITE_TERRACOTTA), new ItemStack(Material.WHITE_TERRACOTTA), SlimefunItems.RAINBOW_RUNE, new ItemStack(Material.WHITE_TERRACOTTA), new ItemStack(Material.WHITE_TERRACOTTA), new ItemStack(Material.WHITE_TERRACOTTA), new ItemStack(Material.WHITE_TERRACOTTA)}, - new SlimefunItemStack(SlimefunItems.RAINBOW_CLAY, 8), new RainbowTickHandler(MaterialCollections.getAllTerracottaColors())) + new SlimefunItemStack(SlimefunItems.RAINBOW_CLAY, 8), new RainbowTickHandler(ColoredMaterials.TERRACOTTA)) .register(plugin); new RainbowBlock(categories.magicalGadgets, SlimefunItems.RAINBOW_CONCRETE, RecipeType.ANCIENT_ALTAR, new ItemStack[] {new ItemStack(Material.WHITE_CONCRETE), new ItemStack(Material.WHITE_CONCRETE), new ItemStack(Material.WHITE_CONCRETE), new ItemStack(Material.WHITE_CONCRETE), SlimefunItems.RAINBOW_RUNE, new ItemStack(Material.WHITE_CONCRETE), new ItemStack(Material.WHITE_CONCRETE), new ItemStack(Material.WHITE_CONCRETE), new ItemStack(Material.WHITE_CONCRETE)}, - new SlimefunItemStack(SlimefunItems.RAINBOW_CONCRETE, 8), new RainbowTickHandler(MaterialCollections.getAllConcreteColors())) + new SlimefunItemStack(SlimefunItems.RAINBOW_CONCRETE, 8), new RainbowTickHandler(ColoredMaterials.CONCRETE)) .register(plugin); new RainbowBlock(categories.magicalGadgets, SlimefunItems.RAINBOW_GLAZED_TERRACOTTA, RecipeType.ANCIENT_ALTAR, new ItemStack[] {new ItemStack(Material.WHITE_GLAZED_TERRACOTTA), new ItemStack(Material.WHITE_GLAZED_TERRACOTTA), new ItemStack(Material.WHITE_GLAZED_TERRACOTTA), new ItemStack(Material.WHITE_GLAZED_TERRACOTTA), SlimefunItems.RAINBOW_RUNE, new ItemStack(Material.WHITE_GLAZED_TERRACOTTA), new ItemStack(Material.WHITE_GLAZED_TERRACOTTA), new ItemStack(Material.WHITE_GLAZED_TERRACOTTA), new ItemStack(Material.WHITE_GLAZED_TERRACOTTA)}, - new SlimefunItemStack(SlimefunItems.RAINBOW_GLAZED_TERRACOTTA, 8), new RainbowTickHandler(MaterialCollections.getAllGlazedTerracottaColors())) + new SlimefunItemStack(SlimefunItems.RAINBOW_GLAZED_TERRACOTTA, 8), new RainbowTickHandler(ColoredMaterials.GLAZED_TERRACOTTA)) .register(plugin); // Christmas diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/utils/ColoredMaterials.java b/src/main/java/io/github/thebusybiscuit/slimefun4/utils/ColoredMaterials.java new file mode 100644 index 000000000..274f0ed09 --- /dev/null +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/utils/ColoredMaterials.java @@ -0,0 +1,160 @@ +package io.github.thebusybiscuit.slimefun4.utils; + +import java.util.Arrays; +import java.util.Collections; +import java.util.List; + +import org.bukkit.Material; + +import io.github.thebusybiscuit.slimefun4.utils.tags.SlimefunTag; + +/** + * This class holds a few ordered {@link List Lists} that hold colored variants + * of {@link Material}. + * + * @author TheBusyBiscuit + * + * @see SlimefunTag + * + */ +public final class ColoredMaterials { + + /** + * We don't want any instances of this class, so we set the + * constructor to be private. + */ + private ColoredMaterials() {} + + /** + * This {@link List} contains all wool colors ordered by their appearance ingame. + */ + public static final List WOOL = Collections.unmodifiableList(Arrays.asList( + Material.WHITE_WOOL, + Material.ORANGE_WOOL, + Material.MAGENTA_WOOL, + Material.LIGHT_BLUE_WOOL, + Material.YELLOW_WOOL, + Material.LIME_WOOL, + Material.PINK_WOOL, + Material.GRAY_WOOL, + Material.LIGHT_GRAY_WOOL, + Material.CYAN_WOOL, + Material.PURPLE_WOOL, + Material.BLUE_WOOL, + Material.BROWN_WOOL, + Material.GREEN_WOOL, + Material.RED_WOOL, + Material.BLACK_WOOL + )); + + /** + * This {@link List} contains all stained glass colors ordered by their appearance ingame. + */ + public static final List STAINED_GLASS = Collections.unmodifiableList(Arrays.asList( + Material.WHITE_STAINED_GLASS, + Material.ORANGE_STAINED_GLASS, + Material.MAGENTA_STAINED_GLASS, + Material.LIGHT_BLUE_STAINED_GLASS, + Material.YELLOW_STAINED_GLASS, + Material.LIME_STAINED_GLASS, + Material.PINK_STAINED_GLASS, + Material.GRAY_STAINED_GLASS, + Material.LIGHT_GRAY_STAINED_GLASS, + Material.CYAN_STAINED_GLASS, + Material.PURPLE_STAINED_GLASS, + Material.BLUE_STAINED_GLASS, + Material.BROWN_STAINED_GLASS, + Material.GREEN_STAINED_GLASS, + Material.RED_STAINED_GLASS, + Material.BLACK_STAINED_GLASS + )); + + /** + * This {@link List} contains all stained glass pane colors ordered by their appearance ingame. + */ + public static final List STAINED_GLASS_PANE = Collections.unmodifiableList(Arrays.asList( + Material.WHITE_STAINED_GLASS_PANE, + Material.ORANGE_STAINED_GLASS_PANE, + Material.MAGENTA_STAINED_GLASS_PANE, + Material.LIGHT_BLUE_STAINED_GLASS_PANE, + Material.YELLOW_STAINED_GLASS_PANE, + Material.LIME_STAINED_GLASS_PANE, + Material.PINK_STAINED_GLASS_PANE, + Material.GRAY_STAINED_GLASS_PANE, + Material.LIGHT_GRAY_STAINED_GLASS_PANE, + Material.CYAN_STAINED_GLASS_PANE, + Material.PURPLE_STAINED_GLASS_PANE, + Material.BLUE_STAINED_GLASS_PANE, + Material.BROWN_STAINED_GLASS_PANE, + Material.GREEN_STAINED_GLASS_PANE, + Material.RED_STAINED_GLASS_PANE, + Material.BLACK_STAINED_GLASS_PANE + )); + + /** + * This {@link List} contains all terracotta colors ordered by their appearance ingame. + */ + public static final List TERRACOTTA = Collections.unmodifiableList(Arrays.asList( + Material.WHITE_TERRACOTTA, + Material.ORANGE_TERRACOTTA, + Material.MAGENTA_TERRACOTTA, + Material.LIGHT_BLUE_TERRACOTTA, + Material.YELLOW_TERRACOTTA, + Material.LIME_TERRACOTTA, + Material.PINK_TERRACOTTA, + Material.GRAY_TERRACOTTA, + Material.LIGHT_GRAY_TERRACOTTA, + Material.CYAN_TERRACOTTA, + Material.PURPLE_TERRACOTTA, + Material.BLUE_TERRACOTTA, + Material.BROWN_TERRACOTTA, + Material.GREEN_TERRACOTTA, + Material.RED_TERRACOTTA, + Material.BLACK_TERRACOTTA + )); + + /** + * This {@link List} contains all glazed terracotta colors ordered by their appearance ingame. + */ + public static final List GLAZED_TERRACOTTA = Collections.unmodifiableList(Arrays.asList( + Material.WHITE_GLAZED_TERRACOTTA, + Material.ORANGE_GLAZED_TERRACOTTA, + Material.MAGENTA_GLAZED_TERRACOTTA, + Material.LIGHT_BLUE_GLAZED_TERRACOTTA, + Material.YELLOW_GLAZED_TERRACOTTA, + Material.LIME_GLAZED_TERRACOTTA, + Material.PINK_GLAZED_TERRACOTTA, + Material.GRAY_GLAZED_TERRACOTTA, + Material.LIGHT_GRAY_GLAZED_TERRACOTTA, + Material.CYAN_GLAZED_TERRACOTTA, + Material.PURPLE_GLAZED_TERRACOTTA, + Material.BLUE_GLAZED_TERRACOTTA, + Material.BROWN_GLAZED_TERRACOTTA, + Material.GREEN_GLAZED_TERRACOTTA, + Material.RED_GLAZED_TERRACOTTA, + Material.BLACK_GLAZED_TERRACOTTA + )); + + /** + * This {@link List} contains all concrete colors ordered by their appearance ingame. + */ + public static final List CONCRETE = Collections.unmodifiableList(Arrays.asList( + Material.WHITE_CONCRETE, + Material.ORANGE_CONCRETE, + Material.MAGENTA_CONCRETE, + Material.LIGHT_BLUE_CONCRETE, + Material.YELLOW_CONCRETE, + Material.LIME_CONCRETE, + Material.PINK_CONCRETE, + Material.GRAY_CONCRETE, + Material.LIGHT_GRAY_CONCRETE, + Material.CYAN_CONCRETE, + Material.PURPLE_CONCRETE, + Material.BLUE_CONCRETE, + Material.BROWN_CONCRETE, + Material.GREEN_CONCRETE, + Material.RED_CONCRETE, + Material.BLACK_CONCRETE + )); + +}