Skip to content

Commit

Permalink
Merge pull request #5 from SmartGecko44/experimental
Browse files Browse the repository at this point in the history
Update to version 3.0.0
  • Loading branch information
SmartGecko44 authored Nov 5, 2023
2 parents 270314a + 3432e89 commit c2a27b7
Show file tree
Hide file tree
Showing 8 changed files with 370 additions and 163 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>org.gecko</groupId>
<artifactId>Wauh</artifactId>
<version>2.0.0</version>
<version>3.0.0</version>
<packaging>jar</packaging>

<name>Wauh</name>
Expand Down
85 changes: 48 additions & 37 deletions src/main/java/org/gecko/wauh/Listeners/BarrierListener.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
import org.bukkit.event.Listener;
import org.bukkit.event.block.BlockBreakEvent;
import org.gecko.wauh.Main;
import net.md_5.bungee.api.ChatMessageType;
import net.md_5.bungee.api.chat.TextComponent;

import java.util.HashSet;
import java.util.Set;
Expand All @@ -26,37 +28,47 @@ public class BarrierListener implements Listener {
private Location clickedLocation;
private boolean limitReached = false;
private int highestDist = 0;
private int dist;
private int radiusLimit;
private int realRadiusLimit;

@EventHandler
public void BarrierClick(BlockBreakEvent event) {
Player player = event.getPlayer();
if (event.getBlock().getType() == Material.GRASS || event.getBlock().getType() == Material.DIRT || event.getBlock().getType() == Material.BARRIER) {
// Check if the bucket is filling with water
if (player.getInventory().getItemInMainHand().getType() == Material.BARRIER) {
blockRemovalActive = true;
limitReached = false;
clickedLocation = event.getBlock().getLocation();

// Reset the water removal counts and initialize the set of blocks to process
grassRemovedCount = 0;
dirtRemovedCount = 0;
barrierRemovedCount = 0;
highestDist = 0;
blocksToProcess.clear();
currentRemovingPlayer = player;

// Add the clicked block to the set of blocks to process
blocksToProcess.add(clickedLocation.getBlock());

// Start the water removal process
processBlockRemoval();
BucketListener bucketListener = Main.getPlugin(Main.class).getBucketListener();
BedrockListener bedrockListener = Main.getPlugin(Main.class).getBedrockListener();
WaterBucketListener waterBucketListener = Main.getPlugin(Main.class).getWaterBucketListener();
radiusLimit = Main.getPlugin(Main.class).getRadiusLimit();
realRadiusLimit = radiusLimit - 2;
if (realRadiusLimit > 1) {
if (!bucketListener.wauhRemovalActive && !bedrockListener.allRemovalActive && !waterBucketListener.tsunamiActive) {
Player player = event.getPlayer();
if (event.getBlock().getType() == Material.GRASS || event.getBlock().getType() == Material.DIRT || event.getBlock().getType() == Material.BARRIER) {
// Check if the bucket is filling with water
if (player.getInventory().getItemInMainHand().getType() == Material.BARRIER) {
blockRemovalActive = true;
limitReached = false;
clickedLocation = event.getBlock().getLocation();

// Reset the water removal counts and initialize the set of blocks to process
grassRemovedCount = 0;
dirtRemovedCount = 0;
barrierRemovedCount = 0;
highestDist = 0;
blocksToProcess.clear();
currentRemovingPlayer = player;

// Add the clicked block to the set of blocks to process
blocksToProcess.add(clickedLocation.getBlock());

// Start the water removal process
processBlockRemoval();
}
}
}
}
}

private void processBlockRemoval() {
int radiusLimit = Main.getPlugin(Main.class).getRadiusLimit();
int realRadiusLimit = radiusLimit - 2;
if (stopBlockRemoval) {
stopBlockRemoval = false;
displaySummary();
Expand All @@ -65,24 +77,22 @@ private void processBlockRemoval() {
Set<Block> nextSet = new HashSet<>();
boolean limitReachedThisIteration = false; // Variable to track whether the limit was reached this iteration
for (Block block : blocksToProcess) {
int dist = (int) clickedLocation.distance(block.getLocation());
if (dist > radiusLimit) {
dist = (int) clickedLocation.distance(block.getLocation()) + 1;
if (dist > radiusLimit - 3) {
limitReached = true;
limitReachedThisIteration = true;
}
if (dist > highestDist) {
if (highestDist <= (realRadiusLimit - 1)) {
highestDist = dist;
if ((dist - 1) > highestDist) {
int progressPercentage = (int) ((double) highestDist / (realRadiusLimit - 2) * 100);
highestDist = dist - 1;
// Send a message to the player only when the dist value rises
if (highestDist < realRadiusLimit) {
currentRemovingPlayer.sendMessage(ChatColor.GREEN + "Block removal: " + ChatColor.RED + dist + ChatColor.WHITE + "/" + ChatColor.GREEN + realRadiusLimit);
} else if (highestDist == realRadiusLimit) {
currentRemovingPlayer.sendMessage(ChatColor.GREEN + "Block removal: " + ChatColor.GREEN + dist + ChatColor.WHITE + "/" + ChatColor.GREEN + realRadiusLimit);
if (highestDist < realRadiusLimit - 1) {
currentRemovingPlayer.spigot().sendMessage(ChatMessageType.ACTION_BAR, new TextComponent(ChatColor.GREEN + "Block removal: " + ChatColor.RED + progressPercentage + "% " + ChatColor.GREEN + "(" + ChatColor.RED + dist + ChatColor.WHITE + "/" + ChatColor.GREEN + realRadiusLimit + ")"));
} else if (!limitReachedThisIteration) {
currentRemovingPlayer.spigot().sendMessage(ChatMessageType.ACTION_BAR, new TextComponent(ChatColor.GREEN + "Block removal: " + ChatColor.GREEN + progressPercentage + "% (" + dist + ChatColor.WHITE + "/" + ChatColor.GREEN + realRadiusLimit + ")"));
} else {
currentRemovingPlayer.spigot().sendMessage(ChatMessageType.ACTION_BAR, new TextComponent(ChatColor.GREEN + "Block removal: " + ChatColor.GREEN + "100% " + "(" + dist + ChatColor.WHITE + "/" + ChatColor.GREEN + realRadiusLimit + ")"));
}
} else {
limitReached = true;
limitReachedThisIteration = true;
}
}

// Check if the block is grass or dirt
Expand All @@ -94,7 +104,7 @@ private void processBlockRemoval() {
barrierRemovedCount++;
}

block.setType(Material.AIR);
block.breakNaturally();

// Iterate through neighboring blocks and add them to the next set
for (int i = -1; i <= 1; i++) {
Expand Down Expand Up @@ -122,6 +132,7 @@ private void processBlockRemoval() {
} else if (!blocksToProcess.isEmpty()) {
Bukkit.getScheduler().runTaskLater(Main.getPlugin(Main.class), this::processBlockRemoval, 2L);
} else {
currentRemovingPlayer.spigot().sendMessage(ChatMessageType.ACTION_BAR, new TextComponent(ChatColor.GREEN + "Block removal: " + ChatColor.GREEN + "100% " + "(" + dist + ChatColor.WHITE + "/" + ChatColor.GREEN + realRadiusLimit + ")"));
displaySummary();
}
}
Expand Down
106 changes: 68 additions & 38 deletions src/main/java/org/gecko/wauh/Listeners/BedrockListener.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
import org.bukkit.event.Listener;
import org.bukkit.event.block.BlockBreakEvent;
import org.gecko.wauh.Main;
import net.md_5.bungee.api.ChatMessageType;
import net.md_5.bungee.api.chat.TextComponent;

import java.util.HashSet;
import java.util.Set;
Expand All @@ -24,35 +26,45 @@ public class BedrockListener implements Listener {
private Location clickedLocation;
private boolean limitReached = false;
private int highestDist = 0;
private int dist;
private int radiusLimit;
private int realRadiusLimit;

@EventHandler
public void BedrockClick(BlockBreakEvent event) {
Player player = event.getPlayer();
// Check if the bucket is filling with water
if (player.getInventory().getItemInMainHand().getType() == Material.BEDROCK) {
if (event.getBlock().getType() != Material.BEDROCK) {
allRemovalActive = true;
limitReached = false;
clickedLocation = event.getBlock().getLocation();

// Reset the water removal counts and initialize the set of blocks to process
highestDist = 0;
allRemovedCount = 0;
blocksToProcess.clear();
currentRemovingPlayer = player;

// Add the clicked block to the set of blocks to process
blocksToProcess.add(clickedLocation.getBlock());

// Start the water removal process
processAllRemoval();
BucketListener bucketListener = Main.getPlugin(Main.class).getBucketListener();
BarrierListener barrierListener = Main.getPlugin(Main.class).getBarrierListener();
WaterBucketListener waterBucketListener = Main.getPlugin(Main.class).getWaterBucketListener();
radiusLimit = Main.getPlugin(Main.class).getRadiusLimit();
realRadiusLimit = radiusLimit - 2;
if (realRadiusLimit > 1) {
if (!bucketListener.wauhRemovalActive && !barrierListener.blockRemovalActive && !waterBucketListener.tsunamiActive) {
Player player = event.getPlayer();
// Check if the bucket is filling with water
if (player.getInventory().getItemInMainHand().getType() == Material.BEDROCK) {
if (event.getBlock().getType() != Material.BEDROCK) {
allRemovalActive = true;
limitReached = false;
clickedLocation = event.getBlock().getLocation();

// Reset the water removal counts and initialize the set of blocks to process
highestDist = 0;
allRemovedCount = 0;
blocksToProcess.clear();
currentRemovingPlayer = player;

// Add the clicked block to the set of blocks to process
blocksToProcess.add(clickedLocation.getBlock());

// Start the water removal process
processAllRemoval();
}
}
}
}
}

private void processAllRemoval() {
int radiusLimit = Main.getPlugin(Main.class).getRadiusLimit();
int realRadiusLimit = radiusLimit - 2;
if (stopAllRemoval) {
stopAllRemoval = false;
displaySummary();
Expand All @@ -61,30 +73,31 @@ private void processAllRemoval() {
Set<Block> nextSet = new HashSet<>();
boolean limitReachedThisIteration = false; // Variable to track whether the limit was reached this iteration
for (Block block : blocksToProcess) {
int dist = (int) clickedLocation.distance(block.getLocation());
if (dist > radiusLimit) {
dist = (int) clickedLocation.distance(block.getLocation()) + 1;
if (dist > radiusLimit - 3) {
limitReached = true;
limitReachedThisIteration = true;
}
if (dist > highestDist) {
if (highestDist <= (realRadiusLimit - 1)) {
highestDist = dist;
int progressPercentage = (int) ((double) highestDist / (realRadiusLimit - 2) * 100);
highestDist = dist - 1;
// Send a message to the player only when the dist value rises
if (highestDist < realRadiusLimit) {
currentRemovingPlayer.sendMessage(ChatColor.GREEN + "All removal: " + ChatColor.RED + dist + ChatColor.WHITE + "/" + ChatColor.GREEN + realRadiusLimit);
} else if (highestDist == realRadiusLimit) {
currentRemovingPlayer.sendMessage(ChatColor.GREEN + "All removal: " + ChatColor.GREEN + dist + ChatColor.WHITE + "/" + ChatColor.GREEN + realRadiusLimit);
if (highestDist < realRadiusLimit - 1) {
currentRemovingPlayer.spigot().sendMessage(ChatMessageType.ACTION_BAR, new TextComponent(ChatColor.GREEN + "All removal: " + ChatColor.RED + progressPercentage + "% " + ChatColor.GREEN + "(" + ChatColor.RED + dist + ChatColor.WHITE + "/" + ChatColor.GREEN + realRadiusLimit + ")"));
} else if (!limitReachedThisIteration) {
currentRemovingPlayer.spigot().sendMessage(ChatMessageType.ACTION_BAR, new TextComponent(ChatColor.GREEN + "All removal: " + ChatColor.GREEN + progressPercentage + "% (" + dist + ChatColor.WHITE + "/" + ChatColor.GREEN + realRadiusLimit + ")"));
} else {
currentRemovingPlayer.spigot().sendMessage(ChatMessageType.ACTION_BAR, new TextComponent(ChatColor.GREEN + "All removal: " + ChatColor.GREEN + "100% " + "(" + dist + ChatColor.WHITE + "/" + ChatColor.GREEN + realRadiusLimit + ")"));
}
} else {
limitReached = true;
limitReachedThisIteration = true;
}
}

// Check if the block is grass or dirt
allRemovedCount++;

block.setType(Material.AIR);
if (block.getType() != Material.DIAMOND_ORE) {
block.setType(Material.AIR);
} else {
block.breakNaturally();
}

// Iterate through neighboring blocks and add them to the next set
for (int i = -1; i <= 1; i++) {
Expand All @@ -93,16 +106,32 @@ private void processAllRemoval() {
Block neighboringBlockY = block.getRelative(0, i, 0);
Block neighboringBlockZ = block.getRelative(0, 0, i);

if ((neighboringBlockX.getType() != Material.AIR && neighboringBlockX.getType() != Material.BEDROCK && neighboringBlockX.getType() != Material.STATIONARY_WATER && neighboringBlockX.getType() != Material.WATER)) {
if (neighboringBlockX.getType() != Material.AIR
&& neighboringBlockX.getType() != Material.BEDROCK
&& neighboringBlockX.getType() != Material.STATIONARY_WATER
&& neighboringBlockX.getType() != Material.WATER
&& neighboringBlockX.getType() != Material.LAVA
&& neighboringBlockX.getType() != Material.STATIONARY_LAVA) {
nextSet.add(neighboringBlockX);
}
if ((neighboringBlockY.getType() != Material.AIR && neighboringBlockY.getType() != Material.BEDROCK && neighboringBlockY.getType() != Material.STATIONARY_WATER && neighboringBlockY.getType() != Material.WATER)) {
if (neighboringBlockY.getType() != Material.AIR
&& neighboringBlockY.getType() != Material.BEDROCK
&& neighboringBlockY.getType() != Material.STATIONARY_WATER
&& neighboringBlockY.getType() != Material.WATER
&& neighboringBlockY.getType() != Material.LAVA
&& neighboringBlockY.getType() != Material.STATIONARY_LAVA) {
nextSet.add(neighboringBlockY);
}
if ((neighboringBlockZ.getType() != Material.AIR && neighboringBlockZ.getType() != Material.BEDROCK && neighboringBlockZ.getType() != Material.STATIONARY_WATER && neighboringBlockZ.getType() != Material.WATER)) {
if (neighboringBlockZ.getType() != Material.AIR
&& neighboringBlockZ.getType() != Material.BEDROCK
&& neighboringBlockZ.getType() != Material.STATIONARY_WATER
&& neighboringBlockZ.getType() != Material.WATER
&& neighboringBlockZ.getType() != Material.LAVA
&& neighboringBlockZ.getType() != Material.STATIONARY_LAVA) {
nextSet.add(neighboringBlockZ);
}
}

}

blocksToProcess = nextSet;
Expand All @@ -112,6 +141,7 @@ private void processAllRemoval() {
} else if (!blocksToProcess.isEmpty()) {
Bukkit.getScheduler().runTaskLater(Main.getPlugin(Main.class), this::processAllRemoval, 2L);
} else {
currentRemovingPlayer.spigot().sendMessage(ChatMessageType.ACTION_BAR, new TextComponent(ChatColor.GREEN + "All removal: " + ChatColor.GREEN + "100% " + "(" + dist + ChatColor.WHITE + "/" + ChatColor.GREEN + realRadiusLimit + ")"));
displaySummary();
}
}
Expand Down
Loading

0 comments on commit c2a27b7

Please sign in to comment.