Skip to content

Commit

Permalink
Merge pull request #1 from SmartGecko44/experimental
Browse files Browse the repository at this point in the history
Experimental -> master
  • Loading branch information
SmartGecko44 authored Oct 28, 2023
2 parents 7e2dde9 + b8c2147 commit 5449925
Show file tree
Hide file tree
Showing 8 changed files with 197 additions and 76 deletions.
9 changes: 0 additions & 9 deletions plugin.yml

This file was deleted.

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>1.0-closed</version>
<version>2.0.0</version>
<packaging>jar</packaging>

<name>Wauh</name>
Expand Down
35 changes: 22 additions & 13 deletions src/main/java/org/gecko/wauh/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,25 +4,38 @@
import org.bukkit.ChatColor;
import org.bukkit.plugin.java.JavaPlugin;
import org.gecko.wauh.barriuh.BarrierListener;
import org.gecko.wauh.commands.StopWauh;
import org.gecko.wauh.wauhbuck.BucketListener;
import org.gecko.wauh.commands.SetRadiusLimitCommand;

public final class Main extends JavaPlugin {
int radiusLimit = 500;
private int radiusLimit = 20;
public int getRadiusLimit() {
return radiusLimit + 2;
}

public void setRadiusLimit(int newLimit) {
radiusLimit = newLimit;
}

@Override
public void onEnable() {
// Plugin startup logic
Bukkit.getConsoleSender().sendMessage("");
Bukkit.getConsoleSender().sendMessage(ChatColor.AQUA + "Yay");
Bukkit.getConsoleSender().sendMessage(ChatColor.RED + "TEST");
getServer().getPluginManager().registerEvents(new BucketListener(), this);
getServer().getPluginManager().registerEvents(new BarrierListener(), this);
try {
getCommand("stopwauh").setExecutor(new BucketListener());
} catch (NullPointerException e) {
Bukkit.getConsoleSender().sendMessage(ChatColor.RED + "I am in eternal suffering.");
}

// Create instances of the listeners
BucketListener bucketListener = new BucketListener();
BarrierListener barrierListener = new BarrierListener();

// Register the listeners
getServer().getPluginManager().registerEvents(bucketListener, this);
getServer().getPluginManager().registerEvents(barrierListener, this);

// Register the StopWauh command with the listeners as arguments
this.getCommand("stopwauh").setExecutor(new StopWauh(bucketListener, barrierListener));
this.getCommand("setradiuslimit").setExecutor(new SetRadiusLimitCommand(this));
}

@Override
Expand All @@ -31,8 +44,4 @@ public void onDisable() {
Bukkit.getConsoleSender().sendMessage("");
Bukkit.getConsoleSender().sendMessage(ChatColor.RED + "kys");
}

public int getRadiusLimit() {
return radiusLimit + 2;
}
}
}
70 changes: 45 additions & 25 deletions src/main/java/org/gecko/wauh/barriuh/BarrierListener.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,6 @@
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.block.Block;
import org.bukkit.block.BlockFace;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
Expand All @@ -18,40 +14,35 @@
import java.util.HashSet;
import java.util.Set;

public class BarrierListener implements Listener, CommandExecutor {
public class BarrierListener implements Listener {

private int grassRemovedCount = 0;
private int dirtRemovedCount = 0;
private int barrierRemovedCount = 0;
private Set<Block> blocksToProcess = new HashSet<>();
private Player currentRemovingPlayer;
private boolean stopBlockRemoval = false;
public boolean stopBlockRemoval = false;
private Location clickedLocation;
private boolean limitReached = false;

@Override
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args){
if (sender instanceof Player) {
Player player = (Player) sender;
stopBlockRemoval = true;
player.sendMessage(ChatColor.GREEN + "" + ChatColor.BOLD + "Water removal" + ChatColor.RED + "stopped.");
displaySummary();
}
return true;
}
private int highestDist = 0;
public boolean blockRemovalActive = false;

@EventHandler
public void BarrierClick(BlockBreakEvent event) {
Player player = event.getPlayer();
if (event.getBlock().getType() == Material.GRASS || event.getBlock().getType() == Material.DIRT) {
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;
event.getBlock().setType(Material.BEDROCK);
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;

Expand All @@ -66,6 +57,7 @@ public void BarrierClick(BlockBreakEvent event) {

private void processBlockRemoval() {
int radiusLimit = Main.getPlugin(Main.class).getRadiusLimit();
int realRadiusLimit = radiusLimit - 2;
if (stopBlockRemoval) {
stopBlockRemoval = false;
displaySummary();
Expand All @@ -74,25 +66,52 @@ 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) {
if (clickedLocation.distance(block.getLocation()) > (radiusLimit + 2)) {
int dist = (int) clickedLocation.distance(block.getLocation());
if (dist > radiusLimit) {
limitReached = true;
limitReachedThisIteration = true;
}
if (dist > highestDist) {
if (highestDist <= (realRadiusLimit - 1)) {
highestDist = dist;
// 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);
}
} else {
limitReached = true;
limitReachedThisIteration = true;
}
}

// Check if the block is grass or dirt
if (block.getType() == Material.GRASS) {
grassRemovedCount++;
} else if (block.getType() == Material.DIRT) {
dirtRemovedCount++;
} else if (block.getType() == Material.BARRIER) {
barrierRemovedCount++;
}

block.setType(Material.AIR);

// Iterate through neighboring blocks and add them to the next set
for (BlockFace face : BlockFace.values()) {
Block neighboringBlock = block.getRelative(face);
if ((neighboringBlock.getType() == Material.GRASS || neighboringBlock.getType() == Material.DIRT)) {
nextSet.add(neighboringBlock);
for (int i = -1; i <= 1; i++) {
if (i == 0) continue; // Skip the current block
Block neighboringBlockX = block.getRelative(i, 0, 0);
Block neighboringBlockY = block.getRelative(0, i, 0);
Block neighboringBlockZ = block.getRelative(0, 0, i);

if ((neighboringBlockX.getType() == Material.GRASS || neighboringBlockX.getType() == Material.DIRT || neighboringBlockX.getType() == Material.BARRIER)) {
nextSet.add(neighboringBlockX);
}
if ((neighboringBlockY.getType() == Material.GRASS || neighboringBlockY.getType() == Material.DIRT || neighboringBlockY.getType() == Material.BARRIER)) {
nextSet.add(neighboringBlockY);
}
if ((neighboringBlockZ.getType() == Material.GRASS || neighboringBlockZ.getType() == Material.DIRT || neighboringBlockZ.getType() == Material.BARRIER)) {
nextSet.add(neighboringBlockZ);
}
}
}
Expand All @@ -119,12 +138,13 @@ private void barriuhFin() {
}
}

private void displaySummary() {
public void displaySummary() {
// Display the block removal summary to the player
Player player = currentRemovingPlayer;
player.sendMessage(ChatColor.GREEN + "Removed " + ChatColor.RED + grassRemovedCount + ChatColor.GREEN + " grass blocks and " + ChatColor.RED + dirtRemovedCount + ChatColor.GREEN + " dirt blocks.");

// Display the block removal summary in the console
Bukkit.getConsoleSender().sendMessage(ChatColor.LIGHT_PURPLE + player.getName() + ChatColor.GREEN + " removed " + ChatColor.RED + grassRemovedCount + ChatColor.GREEN + " grass blocks and " + ChatColor.RED + dirtRemovedCount + ChatColor.GREEN + " dirt blocks.");
Bukkit.getConsoleSender().sendMessage(ChatColor.LIGHT_PURPLE + player.getName() + ChatColor.GREEN + " removed " + ChatColor.RED + grassRemovedCount + ChatColor.GREEN + " grass blocks, " + ChatColor.RED + dirtRemovedCount + ChatColor.GREEN + " dirt blocks and " + ChatColor.RED + barrierRemovedCount + ChatColor.GREEN + " barriers");
blockRemovalActive = false;
}
}
38 changes: 38 additions & 0 deletions src/main/java/org/gecko/wauh/commands/SetRadiusLimitCommand.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package org.gecko.wauh.commands;

import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.gecko.wauh.Main;

public class SetRadiusLimitCommand implements CommandExecutor {
private final Main plugin; // Reference to the Main class

public SetRadiusLimitCommand(Main plugin) {
this.plugin = plugin;
}

@Override
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
if (sender instanceof Player) {
Player player = (Player) sender;

if (args.length == 1) {
// Check if the argument is an integer
try {
int newLimit = Integer.parseInt(args[0]);
plugin.setRadiusLimit(newLimit); // Use the setter method
player.sendMessage("Radius limit set to " + newLimit);
} catch (NumberFormatException e) {
player.sendMessage("Please specify a valid integer.");
}
} else {
player.sendMessage("Usage: /setradiuslimit <integer>");
}
} else {
sender.sendMessage("Only players can use this command.");
}
return true;
}
}
43 changes: 43 additions & 0 deletions src/main/java/org/gecko/wauh/commands/StopWauh.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package org.gecko.wauh.commands;

import org.bukkit.ChatColor;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.gecko.wauh.barriuh.BarrierListener;
import org.gecko.wauh.wauhbuck.BucketListener;

public class StopWauh implements CommandExecutor {
private final BucketListener bucketListener;
private final BarrierListener barrierListener;

public StopWauh(BucketListener bucketListener, BarrierListener barrierListener) {
this.bucketListener = bucketListener;
this.barrierListener = barrierListener;
}

@Override
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
if (!(sender instanceof Player)) {
sender.sendMessage(ChatColor.RED + "Only players can use this command.");
return true;
}

Player player = (Player) sender;

if (bucketListener.wauhRemovalActive) {
bucketListener.stopWaterRemoval = true;
player.sendMessage(ChatColor.GREEN + "Wauh removal " + ChatColor.RED + ChatColor.BOLD + "stopped.");
}
if (barrierListener.blockRemovalActive) {
barrierListener.stopBlockRemoval = true;
player.sendMessage(ChatColor.GREEN + "Block removal " + ChatColor.RED + ChatColor.BOLD + "stopped.");
}
if (!bucketListener.wauhRemovalActive && !barrierListener.blockRemovalActive) {
player.sendMessage(ChatColor.RED + "There are no block removals running");
}

return true;
}
}
Loading

0 comments on commit 5449925

Please sign in to comment.