From 7c08152114666a0aec70c958dc91f925832c5b93 Mon Sep 17 00:00:00 2001 From: Lightling Date: Thu, 19 Sep 2019 17:09:19 -0400 Subject: [PATCH] created chunkloader item --- .../gibsoniacraft/GibsoniaCraft.java | 4 +- .../gibsoniacraft/crafting/ChunkLoader.java | 62 +++++++++++++++++++ .../{util => listener}/BlockListener.java | 3 +- .../PlayerInteractListener.java | 2 +- 4 files changed, 67 insertions(+), 4 deletions(-) create mode 100644 plugin/src/lightling/gibsoniacraft/crafting/ChunkLoader.java rename plugin/src/lightling/gibsoniacraft/{util => listener}/BlockListener.java (99%) rename plugin/src/lightling/gibsoniacraft/{util => listener}/PlayerInteractListener.java (97%) diff --git a/plugin/src/lightling/gibsoniacraft/GibsoniaCraft.java b/plugin/src/lightling/gibsoniacraft/GibsoniaCraft.java index c89afbb..57161e2 100644 --- a/plugin/src/lightling/gibsoniacraft/GibsoniaCraft.java +++ b/plugin/src/lightling/gibsoniacraft/GibsoniaCraft.java @@ -7,8 +7,8 @@ import org.bukkit.plugin.java.JavaPlugin; import lightling.gibsoniacraft.crafting.Excavator; import lightling.gibsoniacraft.crafting.Hammer; import lightling.gibsoniacraft.crafting.LumberAxe; -import lightling.gibsoniacraft.util.BlockListener; -import lightling.gibsoniacraft.util.PlayerInteractListener; +import lightling.gibsoniacraft.listener.BlockListener; +import lightling.gibsoniacraft.listener.PlayerInteractListener; @SuppressWarnings("unused") public final class GibsoniaCraft extends JavaPlugin { diff --git a/plugin/src/lightling/gibsoniacraft/crafting/ChunkLoader.java b/plugin/src/lightling/gibsoniacraft/crafting/ChunkLoader.java new file mode 100644 index 0000000..188d1ce --- /dev/null +++ b/plugin/src/lightling/gibsoniacraft/crafting/ChunkLoader.java @@ -0,0 +1,62 @@ +package lightling.gibsoniacraft.crafting; + +import java.util.ArrayList; + +import org.bukkit.Material; +import org.bukkit.NamespacedKey; +import org.bukkit.Server; +import org.bukkit.inventory.ItemStack; +import org.bukkit.inventory.ShapedRecipe; +import org.bukkit.inventory.meta.ItemMeta; +import org.bukkit.plugin.java.JavaPlugin; + +/** + * A chunk loader is a block (beacon in appearance) that keeps a chunk loaded + * @author Lightling + */ +@SuppressWarnings("serial") +public class ChunkLoader { + + private ItemStack chunkItem; + private ShapedRecipe chunkRecipe; + private NamespacedKey chunkKey; + private ItemMeta chunkMeta; + + /** + * Initializes a chunk loader + * @param plugin + */ + public ChunkLoader(final JavaPlugin plugin) + { + Setup(plugin); + } + + /** + * Defines the chunk loader block + * @param plugin + */ + public void Setup(JavaPlugin plugin) + { + // Handle initial values + chunkItem = new ItemStack(Material.BEACON); + chunkKey = new NamespacedKey(plugin, "chunkloader"); + + // Handle meta + chunkMeta = chunkItem.getItemMeta(); + String loreString = "Keeps chunks loaded"; + ArrayList lore = new ArrayList() {{ add(loreString); }}; + chunkMeta.setLore(lore); + chunkMeta.setDisplayName("Chunk Loader"); + chunkItem.setItemMeta(chunkMeta); + + // Handle recipe + chunkRecipe = new ShapedRecipe(chunkKey, chunkItem); + chunkRecipe.shape(new String[] { "ooo", "eme", "epe" }); + chunkRecipe.setIngredient('o', Material.OBSIDIAN); + chunkRecipe.setIngredient('e', Material.EMERALD); + chunkRecipe.setIngredient('m', Material.MAGMA_BLOCK); + chunkRecipe.setIngredient('p', Material.PRISMARINE_CRYSTALS); + Server server = plugin.getServer(); + server.addRecipe(chunkRecipe); + } +} diff --git a/plugin/src/lightling/gibsoniacraft/util/BlockListener.java b/plugin/src/lightling/gibsoniacraft/listener/BlockListener.java similarity index 99% rename from plugin/src/lightling/gibsoniacraft/util/BlockListener.java rename to plugin/src/lightling/gibsoniacraft/listener/BlockListener.java index 309d00d..3a938d7 100644 --- a/plugin/src/lightling/gibsoniacraft/util/BlockListener.java +++ b/plugin/src/lightling/gibsoniacraft/listener/BlockListener.java @@ -1,4 +1,4 @@ -package lightling.gibsoniacraft.util; +package lightling.gibsoniacraft.listener; // Needed for block information import org.bukkit.Material; @@ -18,6 +18,7 @@ import org.bukkit.event.Listener; import org.bukkit.event.block.BlockBreakEvent; import lightling.gibsoniacraft.GibsoniaCraft; import lightling.gibsoniacraft.lib.BlockRef; +import lightling.gibsoniacraft.util.ToolUtil; // Needed for GibsoniaCraft tools import org.bukkit.inventory.ItemStack; diff --git a/plugin/src/lightling/gibsoniacraft/util/PlayerInteractListener.java b/plugin/src/lightling/gibsoniacraft/listener/PlayerInteractListener.java similarity index 97% rename from plugin/src/lightling/gibsoniacraft/util/PlayerInteractListener.java rename to plugin/src/lightling/gibsoniacraft/listener/PlayerInteractListener.java index 98cb54a..fc75ac8 100644 --- a/plugin/src/lightling/gibsoniacraft/util/PlayerInteractListener.java +++ b/plugin/src/lightling/gibsoniacraft/listener/PlayerInteractListener.java @@ -1,4 +1,4 @@ -package lightling.gibsoniacraft.util; +package lightling.gibsoniacraft.listener; import java.util.HashMap; // Needed to store block-face information