diff --git a/src/main/java/com/iridium/iridiumskyblock/listeners/PlayerInteractListener.java b/src/main/java/com/iridium/iridiumskyblock/listeners/PlayerInteractListener.java index 372257220..eb1143f1b 100644 --- a/src/main/java/com/iridium/iridiumskyblock/listeners/PlayerInteractListener.java +++ b/src/main/java/com/iridium/iridiumskyblock/listeners/PlayerInteractListener.java @@ -1,11 +1,14 @@ package com.iridium.iridiumskyblock.listeners; +import com.iridium.iridiumcore.dependencies.xseries.XMaterial; import com.iridium.iridiumcore.utils.StringUtils; import com.iridium.iridiumskyblock.IridiumSkyblock; import com.iridium.iridiumskyblock.database.Island; import com.iridium.iridiumskyblock.database.User; import com.iridium.iridiumteams.PermissionType; +import org.bukkit.Location; import org.bukkit.Material; +import org.bukkit.block.Block; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.bukkit.event.Listener; @@ -14,6 +17,7 @@ import org.bukkit.inventory.ItemStack; import java.util.Optional; +import java.util.concurrent.atomic.AtomicInteger; public class PlayerInteractListener implements Listener { @@ -32,7 +36,7 @@ public void onClick(PlayerInteractEvent event) { return; } - if(IridiumSkyblock.getInstance().getConfiguration().obsidianBucket + if (IridiumSkyblock.getInstance().getConfiguration().obsidianBucket && event.getAction().equals(Action.RIGHT_CLICK_BLOCK) && event.getClickedBlock().getType().equals(Material.OBSIDIAN) && itemInHand.getType().equals(Material.BUCKET)) { @@ -49,15 +53,36 @@ public void onClick(PlayerInteractEvent event) { } } - if(IridiumSkyblock.getInstance().getConfiguration().endPortalPick + if (IridiumSkyblock.getInstance().getConfiguration().endPortalPick && (event.getAction().equals(Action.LEFT_CLICK_BLOCK) && player.isSneaking()) && event.getClickedBlock().getType().equals(Material.END_PORTAL_FRAME) && (itemInHand.getType().name().contains("PICKAXE"))) { - + event.getClickedBlock().breakNaturally(); - player.getInventory().addItem(new ItemStack(Material.END_PORTAL_FRAME)).values().forEach(itemStack -> - player.getWorld().dropItem(player.getLocation(), itemStack)); + player.getWorld().dropItem(event.getClickedBlock().getLocation(), new ItemStack(Material.END_PORTAL_FRAME)); + removeAdjacentBlocks(event.getClickedBlock().getLocation(), XMaterial.END_PORTAL.parseMaterial(), new AtomicInteger(9)); } } + + public void removeAdjacentBlocks(Location location, Material targetMaterial, AtomicInteger iterationsLeft) { + if (iterationsLeft.get() <= 0) { + return; + } + + for (int xOffset = -1; xOffset <= 1; xOffset++) { + for (int yOffset = -1; yOffset <= 1; yOffset++) { + for (int zOffset = -1; zOffset <= 1; zOffset++) { + Location adjacentLocation = location.clone().add(xOffset, yOffset, zOffset); + Block block = adjacentLocation.getBlock(); + if (block.getType() == targetMaterial) { + block.breakNaturally(); + iterationsLeft.getAndDecrement(); + removeAdjacentBlocks(adjacentLocation, targetMaterial, iterationsLeft); + } + } + } + } + } + }