From 7c92625c9b812663d79db208e9252f036acd69fe Mon Sep 17 00:00:00 2001 From: TheBusyBiscuit Date: Fri, 9 Apr 2021 17:15:35 +0200 Subject: [PATCH] Updated to new Block Handler system --- pom.xml | 2 +- .../coloredenderchests/ColoredEnderChest.java | 91 +++++++++++-------- .../EnderChestBlockHandler.java | 18 ---- 3 files changed, 52 insertions(+), 59 deletions(-) delete mode 100644 src/main/java/io/github/thebusybiscuit/coloredenderchests/EnderChestBlockHandler.java diff --git a/pom.xml b/pom.xml index c8e031f..9b26128 100644 --- a/pom.xml +++ b/pom.xml @@ -105,7 +105,7 @@ com.github.TheBusyBiscuit Slimefun4 - RC-20 + RC-21 provided diff --git a/src/main/java/io/github/thebusybiscuit/coloredenderchests/ColoredEnderChest.java b/src/main/java/io/github/thebusybiscuit/coloredenderchests/ColoredEnderChest.java index 8e284a6..5620762 100644 --- a/src/main/java/io/github/thebusybiscuit/coloredenderchests/ColoredEnderChest.java +++ b/src/main/java/io/github/thebusybiscuit/coloredenderchests/ColoredEnderChest.java @@ -10,8 +10,10 @@ import org.bukkit.event.block.BlockPlaceEvent; import org.bukkit.inventory.ItemStack; +import io.github.thebusybiscuit.slimefun4.core.handlers.BlockBreakHandler; import io.github.thebusybiscuit.slimefun4.core.handlers.BlockPlaceHandler; import io.github.thebusybiscuit.slimefun4.implementation.SlimefunItems; +import io.github.thebusybiscuit.slimefun4.implementation.handlers.SimpleBlockBreakHandler; import io.github.thebusybiscuit.slimefun4.utils.ColoredMaterial; import me.mrCookieSlime.Slimefun.Lists.RecipeType; import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.SlimefunItem; @@ -40,40 +42,8 @@ SlimefunItems.WITHER_PROOF_OBSIDIAN, getSmallerEnderChest(c1, c2, c3), SlimefunI int[] slots = IntStream.range(0, size).toArray(); - addItemHandler(new BlockPlaceHandler(false) { - - @Override - public void onPlayerPlace(BlockPlaceEvent e) { - int yaw = 0; - - EnderChest chest = (EnderChest) e.getBlock().getBlockData(); - - switch (chest.getFacing()) { - case NORTH: - yaw = 180; - break; - case SOUTH: - yaw = 0; - break; - case WEST: - yaw = 90; - break; - case EAST: - yaw = -90; - break; - default: - break; - } - - BlockStorage.addBlockInfo(e.getBlock(), "yaw", String.valueOf(yaw)); - ColorIndicator.updateIndicator(e.getBlock(), c1, c2, c3, yaw + 45); - } - }); - - SlimefunItem.registerBlockHandler(getId(), (p, b, tool, reason) -> { - ColorIndicator.removeIndicator(b); - return true; - }); + addItemHandler(onBlockBreak()); + addItemHandler(onBlockPlace(c1, c2, c3)); new BlockMenuPreset(getId(), "&eEnder Chest", true) { @@ -82,7 +52,6 @@ public void init() { setSize(size); addMenuOpeningHandler(p -> p.playSound(p.getLocation(), Sound.BLOCK_ENDER_CHEST_OPEN, 1.8F, 1.6F)); - addMenuCloseHandler(p -> p.playSound(p.getLocation(), Sound.BLOCK_ENDER_CHEST_CLOSE, 1.8F, 1.6F)); } @@ -102,6 +71,51 @@ public boolean canOpen(Block b, Player p) { EnderChest chest = (EnderChest) b.getBlockData(); switch (chest.getFacing()) { + case NORTH: + yaw = 180; + break; + case SOUTH: + yaw = 0; + break; + case WEST: + yaw = 90; + break; + case EAST: + yaw = -90; + break; + default: + break; + } + + BlockStorage.addBlockInfo(b, "yaw", String.valueOf(yaw)); + } + + ColorIndicator.updateIndicator(b, c1, c2, c3, yaw + 45); + return true; + } + }; + } + + private BlockBreakHandler onBlockBreak() { + return new SimpleBlockBreakHandler() { + + @Override + public void onBlockBreak(Block b) { + ColorIndicator.removeIndicator(b); + } + }; + } + + private BlockPlaceHandler onBlockPlace(int c1, int c2, int c3) { + return new BlockPlaceHandler(false) { + + @Override + public void onPlayerPlace(BlockPlaceEvent e) { + int yaw = 0; + + EnderChest chest = (EnderChest) e.getBlock().getBlockData(); + + switch (chest.getFacing()) { case NORTH: yaw = 180; break; @@ -116,13 +130,10 @@ public boolean canOpen(Block b, Player p) { break; default: break; - } - - BlockStorage.addBlockInfo(b, "yaw", String.valueOf(yaw)); } - ColorIndicator.updateIndicator(b, c1, c2, c3, yaw + 45); - return true; + BlockStorage.addBlockInfo(e.getBlock(), "yaw", String.valueOf(yaw)); + ColorIndicator.updateIndicator(e.getBlock(), c1, c2, c3, yaw + 45); } }; } diff --git a/src/main/java/io/github/thebusybiscuit/coloredenderchests/EnderChestBlockHandler.java b/src/main/java/io/github/thebusybiscuit/coloredenderchests/EnderChestBlockHandler.java deleted file mode 100644 index ce003cd..0000000 --- a/src/main/java/io/github/thebusybiscuit/coloredenderchests/EnderChestBlockHandler.java +++ /dev/null @@ -1,18 +0,0 @@ -package io.github.thebusybiscuit.coloredenderchests; - -import org.bukkit.block.Block; -import org.bukkit.entity.Player; - -import me.mrCookieSlime.Slimefun.Objects.SlimefunBlockHandler; -import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.SlimefunItem; -import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.UnregisterReason; - -class EnderChestBlockHandler implements SlimefunBlockHandler { - - @Override - public boolean onBreak(Player p, Block b, SlimefunItem item, UnregisterReason reason) { - ; - return true; - } - -}