Skip to content

Commit 8ef0c85

Browse files
committed
1.3 - Fix Veinmining
1 parent 6a6b856 commit 8ef0c85

File tree

4 files changed

+37
-34
lines changed

4 files changed

+37
-34
lines changed

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
<groupId>me.setloth</groupId>
88
<artifactId>ModificationMaster</artifactId>
9-
<version>1.2</version>
9+
<version>1.3</version>
1010
<packaging>jar</packaging>
1111

1212
<name>ModificationMaster</name>

src/main/java/me/setloth/modificationMaster/ModificationMaster.java

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import me.setloth.modificationMaster.commands.Sort;
44
import me.setloth.modificationMaster.listeners.BlockBreaking;
5+
import org.bukkit.plugin.Plugin;
56
import org.bukkit.plugin.java.JavaPlugin;
67

78
import java.util.Objects;
@@ -10,20 +11,29 @@
1011
@SuppressWarnings("unused")
1112
public final class ModificationMaster extends JavaPlugin {
1213

14+
static ModificationMaster INSTANCE;
15+
public static Plugin instance() {
16+
return INSTANCE;
17+
}
18+
1319
@Override
1420
public void onEnable() {
21+
INSTANCE = this;
1522
// Plugin startup logic
16-
Logger.getLogger("MM").info("Registering Events");
23+
log("Registering Events");
1724
getServer().getPluginManager().registerEvents(new BlockBreaking(), this);
18-
Logger.getLogger("MM").info("Registering Commands");
25+
log("Registering Commands");
1926
Objects.requireNonNull(getServer().getPluginCommand("sort")).setExecutor(new Sort());
2027

2128
}
2229

2330
@Override
2431
public void onDisable() {
2532
// Plugin shutdown logic
26-
Logger.getLogger("MM").info("Goodbye :(");
33+
log("Goodbye :(");
34+
}
2735

36+
public static void log(String msg) {
37+
Logger.getLogger("MM").info(msg);
2838
}
2939
}

src/main/java/me/setloth/modificationMaster/util/Utility.java

Lines changed: 22 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,12 @@
33
import java.util.*;
44

55
import org.bukkit.Material;
6-
import org.bukkit.block.Block;
7-
import org.bukkit.entity.Player;
86
import org.bukkit.event.inventory.InventoryType;
97
import org.bukkit.inventory.Inventory;
108
import org.bukkit.inventory.ItemStack;
119
import org.bukkit.inventory.meta.ItemMeta;
10+
import org.bukkit.block.Block;
11+
import org.bukkit.entity.Player;
1212

1313
public class Utility {
1414

@@ -24,52 +24,45 @@ public static boolean isVeinBlock(Material m) {
2424
}
2525

2626

27-
public static void destroyBranch(Player p, Block startBlock, boolean down) {
28-
Material blockType = startBlock.getType(); // Type of block to match
29-
Set<Block> visited = new HashSet<>(); // Tracks blocks we've already processed
30-
Deque<Block> toVisit = new ArrayDeque<>(); // BFS queue to process blocks layer by layer (ArrayDeque is used for efficiency)
31-
32-
// Initialize with the starting block
33-
toVisit.add(startBlock);
34-
visited.add(startBlock);
27+
public static void destroyBranch(Player p, Block b, boolean down) {
28+
Material branchType = b.getType();
29+
final Queue<Block> blocksToDestroy = new LinkedList<>();
30+
final Set<Block> processedBlocks = new HashSet<>();
31+
blocksToDestroy.add(b);
3532

36-
while (!toVisit.isEmpty()) {
37-
Block currentBlock = toVisit.poll(); // Remove and process the current block
33+
while (!blocksToDestroy.isEmpty()) {
34+
Block currentBlock = blocksToDestroy.remove();
35+
Material currentBlockType = currentBlock.getType();
3836

39-
// Ensure the block type still matches
40-
if (!currentBlock.getType().equals(blockType)) continue;
37+
if (processedBlocks.contains(currentBlock) || currentBlockType != branchType) continue;
4138

42-
// Try to break the block
43-
boolean broken = p.breakBlock(currentBlock);
44-
if (!broken) continue; // If the block couldn't be broken, skip it
39+
processedBlocks.add(currentBlock);
4540

46-
// Check all adjacent blocks within a 3x3x3 cube around the current block
4741
for (int x = -1; x <= 1; x++) {
48-
for (int y = (down ? -1 : 0); y <= 1; y++) { // If 'down' is true, check below
49-
for (int z = -1; z <= 1; z++) {
50-
// Skip the current block itself (x == 0, y == 0, z == 0)
51-
if (x == 0 && y == 0 && z == 0) continue;
52-
42+
for (int z = -1; z <= 1; z++) {
43+
for (int y = (down ? -1 : 0); y <= 1; y++) {
5344
Block neighbor = currentBlock.getRelative(x, y, z);
54-
55-
// If the neighbor is the same block type and hasn't been visited, add it to the deque
56-
if (!visited.contains(neighbor) && neighbor.getType().equals(blockType)) {
57-
toVisit.add(neighbor); // Add to the end of the deque
58-
visited.add(neighbor); // Mark it as visited immediately to avoid re-adding it
45+
if (neighbor.getType() == branchType) {
46+
blocksToDestroy.add(neighbor);
5947
}
6048
}
6149
}
6250
}
51+
52+
currentBlock.breakNaturally(p.getInventory().getItemInMainHand());
53+
6354
}
6455
}
6556

57+
6658
/**
6759
* Sorts and combines an array of ItemStacks.
6860
*
6961
* @param items the ItemStack array to sort and combine
7062
* @return the sorted and combined ItemStack array
7163
*/
72-
@SuppressWarnings("all")
64+
65+
@SuppressWarnings("all")
7366
public static ItemStack[] sortAndCombine(ItemStack[] items) {
7467
// Map to store item counts with metadata as the key
7568
Map<ItemStack, Integer> itemCount = new HashMap<>();

src/main/resources/plugin.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name: ModificationMaster
2-
version: 1.2
2+
version: 1.3
33
main: me.setloth.modificationMaster.ModificationMaster
44
api-version: '1.21'
55
authors: [ Setloth ]

0 commit comments

Comments
 (0)