1
mirror of https://github.com/StarWishsama/Slimefun4.git synced 2024-09-19 19:25:48 +00:00

A few more changes

This commit is contained in:
TheBusyBiscuit 2020-08-03 00:30:58 +02:00
parent 1aeba31a96
commit 8d1e427409
3 changed files with 59 additions and 45 deletions

View File

@ -39,6 +39,7 @@
* Fixed #2147
* Fixed #2179
* Fixed Reinforced Spawners not working sometimes
* Fixed Explosive Pickaxe not handling normal Shulker boxes correctly
## Release Candidate 15 (01 Aug 2020)

View File

@ -1,8 +1,5 @@
package io.github.thebusybiscuit.slimefun4.implementation.items.tools;
import java.util.List;
import org.bukkit.Effect;
import org.bukkit.block.Block;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
@ -31,15 +28,8 @@ public class ExplosiveShovel extends ExplosiveTool {
}
@Override
protected void breakBlock(Player p, ItemStack item, Block b, int fortune, List<ItemStack> drops) {
if (MaterialTools.getBreakableByShovel().contains(b.getType()) && SlimefunPlugin.getProtectionManager().hasPermission(p, b.getLocation(), ProtectableAction.BREAK_BLOCK)) {
SlimefunPlugin.getProtectionManager().logAction(p, b, ProtectableAction.BREAK_BLOCK);
b.getWorld().playEffect(b.getLocation(), Effect.STEP_SOUND, b.getType());
b.breakNaturally(item);
damageItem(p, item);
}
protected boolean canBreak(Player p, Block b) {
return MaterialTools.getBreakableByShovel().contains(b.getType()) && SlimefunPlugin.getProtectionManager().hasPermission(p, b.getLocation(), ProtectableAction.BREAK_BLOCK);
}
}

View File

@ -29,6 +29,15 @@ import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.UnregisterReason;
import me.mrCookieSlime.Slimefun.api.BlockStorage;
import me.mrCookieSlime.Slimefun.api.SlimefunItemStack;
/**
* This {@link SlimefunItem} is a super class for items like the {@link ExplosivePickaxe} or {@link ExplosiveShovel}.
*
* @author TheBusyBiscuit
*
* @see ExplosivePickaxe
* @see ExplosiveShovel
*
*/
class ExplosiveTool extends SimpleSlimefunItem<ToolUseHandler> implements NotPlaceable, DamageableItem {
private final ItemSetting<Boolean> damageOnUse = new ItemSetting<>("damage-on-use", true);
@ -61,13 +70,17 @@ class ExplosiveTool extends SimpleSlimefunItem<ToolUseHandler> implements NotPla
if (!blockExplodeEvent.isCancelled()) {
for (Block block : blockExplodeEvent.blockList()) {
breakBlock(p, item, block, fortune, drops);
if (canBreak(p, block)) {
breakBlock(p, item, block, fortune, drops);
}
}
}
}
else {
for (Block block : blocks) {
breakBlock(p, item, block, fortune, drops);
if (canBreak(p, block)) {
breakBlock(p, item, block, fortune, drops);
}
}
}
}
@ -96,38 +109,48 @@ class ExplosiveTool extends SimpleSlimefunItem<ToolUseHandler> implements NotPla
return damageOnUse.getValue();
}
protected void breakBlock(Player p, ItemStack item, Block b, int fortune, List<ItemStack> drops) {
if (!b.isEmpty() && !b.isLiquid() && !MaterialCollections.getAllUnbreakableBlocks().contains(b.getType()) && SlimefunPlugin.getProtectionManager().hasPermission(p, b.getLocation(), ProtectableAction.BREAK_BLOCK)) {
SlimefunPlugin.getProtectionManager().logAction(p, b, ProtectableAction.BREAK_BLOCK);
b.getWorld().playEffect(b.getLocation(), Effect.STEP_SOUND, b.getType());
SlimefunItem sfItem = BlockStorage.check(b);
if (sfItem != null && !sfItem.useVanillaBlockBreaking()) {
SlimefunBlockHandler handler = SlimefunPlugin.getRegistry().getBlockHandlers().get(sfItem.getID());
if (handler != null && !handler.onBreak(p, b, sfItem, UnregisterReason.PLAYER_BREAK)) {
drops.add(BlockStorage.retrieve(b));
}
}
else if (b.getType() == Material.PLAYER_HEAD || b.getType().name().endsWith("_SHULKER_BOX")) {
b.breakNaturally();
}
else {
boolean applyFortune = b.getType().name().endsWith("_ORE") && b.getType() != Material.IRON_ORE && b.getType() != Material.GOLD_ORE;
for (ItemStack drop : b.getDrops(getItem())) {
// For some reason this check is necessary with Paper
if (drop != null && drop.getType() != Material.AIR) {
b.getWorld().dropItemNaturally(b.getLocation(), applyFortune ? new CustomItem(drop, fortune) : drop);
}
}
b.setType(Material.AIR);
}
damageItem(p, item);
protected boolean canBreak(Player p, Block b) {
if (b.isEmpty() || b.isLiquid()) {
return false;
}
else if (MaterialCollections.getAllUnbreakableBlocks().contains(b.getType())) {
return false;
}
else {
return SlimefunPlugin.getProtectionManager().hasPermission(p, b.getLocation(), ProtectableAction.BREAK_BLOCK);
}
}
private void breakBlock(Player p, ItemStack item, Block b, int fortune, List<ItemStack> drops) {
SlimefunPlugin.getProtectionManager().logAction(p, b, ProtectableAction.BREAK_BLOCK);
b.getWorld().playEffect(b.getLocation(), Effect.STEP_SOUND, b.getType());
SlimefunItem sfItem = BlockStorage.check(b);
if (sfItem != null && !sfItem.useVanillaBlockBreaking()) {
SlimefunBlockHandler handler = SlimefunPlugin.getRegistry().getBlockHandlers().get(sfItem.getID());
if (handler != null && !handler.onBreak(p, b, sfItem, UnregisterReason.PLAYER_BREAK)) {
drops.add(BlockStorage.retrieve(b));
}
}
else if (b.getType() == Material.PLAYER_HEAD || b.getType() == Material.SHULKER_BOX || b.getType().name().endsWith("_SHULKER_BOX")) {
b.breakNaturally(item);
}
else {
boolean applyFortune = b.getType().name().endsWith("_ORE") && b.getType() != Material.IRON_ORE && b.getType() != Material.GOLD_ORE;
for (ItemStack drop : b.getDrops(getItem())) {
// For some reason this check is necessary with Paper
if (drop != null && drop.getType() != Material.AIR) {
b.getWorld().dropItemNaturally(b.getLocation(), applyFortune ? new CustomItem(drop, fortune) : drop);
}
}
b.setType(Material.AIR);
}
damageItem(p, item);
}
}