From 86715cd3d0f6a629b5887bce58ff971ff5e4673c Mon Sep 17 00:00:00 2001 From: TheBusyBiscuit Date: Thu, 19 Nov 2020 13:11:30 +0100 Subject: [PATCH] Fixed CoreProtect not recognizing Slimefun blocks getting broken --- CHANGELOG.md | 1 + .../slimefun4/api/items/ItemSetting.java | 12 +++++++++--- .../implementation/listeners/BlockListener.java | 4 ++++ 3 files changed, 14 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 707db6db2..44086d599 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -63,6 +63,7 @@ * Fixed network visualizers spawning particles for other player heads * Fixed #2418 * Fixed #2446 +* Fixed CoreProtect not recognizing Slimefun blocks getting broken ## Release Candidate 17 (17 Oct 2020) diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/api/items/ItemSetting.java b/src/main/java/io/github/thebusybiscuit/slimefun4/api/items/ItemSetting.java index e51ff0bcb..8d0a27c14 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/api/items/ItemSetting.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/api/items/ItemSetting.java @@ -113,6 +113,7 @@ public class ItemSetting { * * @param c * The class of data type you want to compare + * * @return Whether this {@link ItemSetting} stores the given type */ public boolean isType(@Nonnull Class c) { @@ -137,14 +138,19 @@ public class ItemSetting { * @param item * The {@link SlimefunItem} who called this method */ - @SuppressWarnings("unchecked") public void load(@Nonnull SlimefunItem item) { + Validate.notNull(item, "Cannot apply settings for a non-existing SlimefunItem"); + SlimefunPlugin.getItemCfg().setDefaultValue(item.getId() + '.' + getKey(), getDefaultValue()); Object configuredValue = SlimefunPlugin.getItemCfg().getValue(item.getId() + '.' + getKey()); if (defaultValue.getClass().isInstance(configuredValue)) { - if (validateInput((T) configuredValue)) { - this.value = (T) configuredValue; + // We can suppress the warning here, we did an isInstance(...) check before! + @SuppressWarnings("unchecked") + T newValue = (T) configuredValue; + + if (validateInput(newValue)) { + this.value = newValue; } else { Slimefun.getLogger().log(Level.WARNING, "Slimefun has found an invalid config setting in your Items.yml!"); Slimefun.getLogger().log(Level.WARNING, " at \"{0}.{1}\"", new Object[] { item.getId(), getKey() }); diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/listeners/BlockListener.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/listeners/BlockListener.java index 815cb6c6e..080372fc1 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/listeners/BlockListener.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/listeners/BlockListener.java @@ -22,6 +22,7 @@ import org.bukkit.event.block.BlockBreakEvent; import org.bukkit.event.block.BlockPlaceEvent; import org.bukkit.inventory.ItemStack; +import io.github.thebusybiscuit.cscorelib2.protection.ProtectableAction; import io.github.thebusybiscuit.slimefun4.core.attributes.NotPlaceable; import io.github.thebusybiscuit.slimefun4.core.handlers.BlockBreakHandler; import io.github.thebusybiscuit.slimefun4.core.handlers.BlockPlaceHandler; @@ -152,6 +153,9 @@ public class BlockListener implements Listener { if (!drops.isEmpty()) { e.getBlock().setType(Material.AIR); + // Notify plugins like CoreProtect + SlimefunPlugin.getProtectionManager().logAction(e.getPlayer(), e.getBlock(), ProtectableAction.BREAK_BLOCK); + if (e.isDropItems()) { for (ItemStack drop : drops) { if (drop != null && drop.getType() != Material.AIR) {