1
mirror of https://github.com/StarWishsama/Slimefun4.git synced 2024-09-19 19:25:48 +00:00
This commit is contained in:
TheBusyBiscuit 2021-01-14 14:41:09 +01:00
parent a3715d3b88
commit ac590fdde3
2 changed files with 19 additions and 20 deletions

View File

@ -36,6 +36,7 @@
* Fixed #2511 * Fixed #2511
* Fixed #2636 * Fixed #2636
* Fixed a threading issue related to BlockStates and persistent data * Fixed a threading issue related to BlockStates and persistent data
* Fixed #2721
## Release Candidate 19 (11 Jan 2021) ## Release Candidate 19 (11 Jan 2021)

View File

@ -2,6 +2,9 @@ package io.github.thebusybiscuit.slimefun4.implementation.items.tools;
import java.util.List; import java.util.List;
import javax.annotation.Nonnull;
import javax.annotation.ParametersAreNonnullByDefault;
import org.bukkit.Axis; import org.bukkit.Axis;
import org.bukkit.Effect; import org.bukkit.Effect;
import org.bukkit.Material; import org.bukkit.Material;
@ -17,9 +20,10 @@ import io.github.thebusybiscuit.slimefun4.core.attributes.NotPlaceable;
import io.github.thebusybiscuit.slimefun4.core.handlers.ItemUseHandler; import io.github.thebusybiscuit.slimefun4.core.handlers.ItemUseHandler;
import io.github.thebusybiscuit.slimefun4.core.handlers.ToolUseHandler; import io.github.thebusybiscuit.slimefun4.core.handlers.ToolUseHandler;
import io.github.thebusybiscuit.slimefun4.implementation.SlimefunPlugin; import io.github.thebusybiscuit.slimefun4.implementation.SlimefunPlugin;
import io.github.thebusybiscuit.slimefun4.implementation.items.SimpleSlimefunItem;
import me.mrCookieSlime.Slimefun.Lists.RecipeType; import me.mrCookieSlime.Slimefun.Lists.RecipeType;
import me.mrCookieSlime.Slimefun.Objects.Category; import me.mrCookieSlime.Slimefun.Objects.Category;
import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.SlimefunItem;
import me.mrCookieSlime.Slimefun.api.BlockStorage;
import me.mrCookieSlime.Slimefun.api.SlimefunItemStack; import me.mrCookieSlime.Slimefun.api.SlimefunItemStack;
/** /**
@ -30,33 +34,27 @@ import me.mrCookieSlime.Slimefun.api.SlimefunItemStack;
* @author TheBusyBiscuit * @author TheBusyBiscuit
* *
*/ */
public class LumberAxe extends SimpleSlimefunItem<ItemUseHandler> implements NotPlaceable { public class LumberAxe extends SlimefunItem implements NotPlaceable {
private static final int MAX_BROKEN = 100; private static final int MAX_BROKEN = 100;
private static final int MAX_STRIPPED = 20; private static final int MAX_STRIPPED = 20;
@ParametersAreNonnullByDefault
public LumberAxe(Category category, SlimefunItemStack item, RecipeType recipeType, ItemStack[] recipe) { public LumberAxe(Category category, SlimefunItemStack item, RecipeType recipeType, ItemStack[] recipe) {
super(category, item, recipeType, recipe); super(category, item, recipeType, recipe);
addItemHandler(onBlockBreak(), onItemUse());
} }
@Override @Nonnull
public void preRegister() {
super.preRegister();
addItemHandler(onBlockBreak());
}
private ToolUseHandler onBlockBreak() { private ToolUseHandler onBlockBreak() {
return (e, tool, fortune, drops) -> { return (e, tool, fortune, drops) -> {
if (Tag.LOGS.isTagged(e.getBlock().getType())) { if (Tag.LOGS.isTagged(e.getBlock().getType())) {
List<Block> logs = Vein.find(e.getBlock(), MAX_BROKEN, b -> Tag.LOGS.isTagged(b.getType())); List<Block> logs = Vein.find(e.getBlock(), MAX_BROKEN, b -> Tag.LOGS.isTagged(b.getType()));
logs.remove(e.getBlock());
if (logs.contains(e.getBlock())) {
logs.remove(e.getBlock());
}
for (Block b : logs) { for (Block b : logs) {
if (SlimefunPlugin.getProtectionManager().hasPermission(e.getPlayer(), b, ProtectableAction.BREAK_BLOCK)) { if (!BlockStorage.hasBlockInfo(b) && SlimefunPlugin.getProtectionManager().hasPermission(e.getPlayer(), b, ProtectableAction.BREAK_BLOCK)) {
breakLog(b); breakLog(b);
} }
} }
@ -64,8 +62,8 @@ public class LumberAxe extends SimpleSlimefunItem<ItemUseHandler> implements Not
}; };
} }
@Override @Nonnull
public ItemUseHandler getItemHandler() { public ItemUseHandler onItemUse() {
return e -> { return e -> {
if (e.getClickedBlock().isPresent()) { if (e.getClickedBlock().isPresent()) {
Block block = e.getClickedBlock().get(); Block block = e.getClickedBlock().get();
@ -78,7 +76,7 @@ public class LumberAxe extends SimpleSlimefunItem<ItemUseHandler> implements Not
} }
for (Block b : logs) { for (Block b : logs) {
if (SlimefunPlugin.getProtectionManager().hasPermission(e.getPlayer(), b, ProtectableAction.BREAK_BLOCK)) { if (!BlockStorage.hasBlockInfo(b) && SlimefunPlugin.getProtectionManager().hasPermission(e.getPlayer(), b, ProtectableAction.BREAK_BLOCK)) {
stripLog(b); stripLog(b);
} }
} }
@ -87,11 +85,11 @@ public class LumberAxe extends SimpleSlimefunItem<ItemUseHandler> implements Not
}; };
} }
private boolean isUnstrippedLog(Block block) { private boolean isUnstrippedLog(@Nonnull Block block) {
return Tag.LOGS.isTagged(block.getType()) && !block.getType().name().startsWith("STRIPPED_"); return Tag.LOGS.isTagged(block.getType()) && !block.getType().name().startsWith("STRIPPED_");
} }
private void stripLog(Block b) { private void stripLog(@Nonnull Block b) {
b.getWorld().playSound(b.getLocation(), Sound.ITEM_AXE_STRIP, 1, 1); b.getWorld().playSound(b.getLocation(), Sound.ITEM_AXE_STRIP, 1, 1);
Axis axis = ((Orientable) b.getBlockData()).getAxis(); Axis axis = ((Orientable) b.getBlockData()).getAxis();
b.setType(Material.valueOf("STRIPPED_" + b.getType().name())); b.setType(Material.valueOf("STRIPPED_" + b.getType().name()));
@ -101,7 +99,7 @@ public class LumberAxe extends SimpleSlimefunItem<ItemUseHandler> implements Not
b.setBlockData(orientable); b.setBlockData(orientable);
} }
private void breakLog(Block b) { private void breakLog(@Nonnull Block b) {
b.getWorld().playEffect(b.getLocation(), Effect.STEP_SOUND, b.getType()); b.getWorld().playEffect(b.getLocation(), Effect.STEP_SOUND, b.getType());
for (ItemStack drop : b.getDrops(getItem())) { for (ItemStack drop : b.getDrops(getItem())) {