Skip to content

Commit

Permalink
Added ability to break portal aswell
Browse files Browse the repository at this point in the history
  • Loading branch information
PeachesMLG committed Sep 23, 2023
1 parent 0afae52 commit 3a90628
Showing 1 changed file with 30 additions and 5 deletions.
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -14,6 +17,7 @@
import org.bukkit.inventory.ItemStack;

import java.util.Optional;
import java.util.concurrent.atomic.AtomicInteger;

public class PlayerInteractListener implements Listener {

Expand All @@ -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)) {
Expand All @@ -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);
}
}
}
}
}

}

0 comments on commit 3a90628

Please sign in to comment.