Skip to content

Commit cfba18b

Browse files
committed
Blocked worlds and only break while holding
For version 1.0.1
1 parent 9fd40af commit cfba18b

4 files changed

Lines changed: 54 additions & 11 deletions

File tree

pom.xml

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

77
<groupId>net.minelink</groupId>
88
<artifactId>InstantBreak</artifactId>
9-
<version>1.0.0-RELEASE</version>
109

1110
<properties>
1211
<maven.compiler.source>1.7</maven.compiler.source>
@@ -57,4 +56,5 @@
5756
<systemPath>${basedir}/AAC.jar</systemPath>
5857
</dependency>
5958
</dependencies>
59+
<version>1.0.1</version>
6060
</project>

src/main/java/net/minelink/instantbreak/InstantBreak.java

Lines changed: 44 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package net.minelink.instantbreak;
22

33
import java.util.HashSet;
4+
import java.util.List;
45
import java.util.Set;
56

67
import net.minelink.instantbreak.hooks.AACHook;
@@ -21,12 +22,16 @@
2122
import org.bukkit.plugin.java.JavaPlugin;
2223

2324
public final class InstantBreak extends JavaPlugin implements Listener {
24-
public static InstantBreak plugin; // Create listener variable
25-
public final static Set<Material> materials = new HashSet<>();
25+
public InstantBreak plugin;
26+
public static final Set<Material> materials = new HashSet<>();
27+
public final List<String> blockedWorlds = getConfig().getStringList("blocked-worlds");
28+
public final boolean restrictionsEnabled = getConfig().getBoolean("only-allow-instantbreak-with.enabled", false);
29+
public final List<String> restrictionsItems = getConfig().getStringList("only-allow-instantbreak-with.items");
30+
public final boolean restrictionsDamageItem = getConfig().getBoolean("only-allow-instantbreak-with.damage-item");
2631

2732
@Override
2833
public void onEnable() {
29-
plugin = this; // Assign listener plugin to this class
34+
plugin = this;
3035
saveDefaultConfig();
3136

3237
for (String mat : getConfig().getStringList("materials")) {
@@ -37,6 +42,17 @@ public void onEnable() {
3742
getLogger().severe("Unknown material: " + mat);
3843
}
3944
}
45+
46+
if (restrictionsEnabled) {
47+
for (String item : restrictionsItems) {
48+
try {
49+
Material.valueOf(item);
50+
} catch (IllegalArgumentException e) {
51+
getLogger().severe("Unknown item: " + item);
52+
}
53+
}
54+
}
55+
4056

4157
Bukkit.getPluginManager().registerEvents(this, this);
4258
if (Bukkit.getPluginManager().isPluginEnabled("AAC")) {
@@ -48,6 +64,13 @@ public void onEnable() {
4864
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
4965
public void onInteract(PlayerInteractEvent event) {
5066
Player player = event.getPlayer();
67+
68+
for (String s : blockedWorlds) {
69+
if (player.getWorld().getName().equals(s)) {
70+
return;
71+
}
72+
}
73+
5174
if (player.getGameMode() == GameMode.CREATIVE) {
5275
return;
5376
}
@@ -59,12 +82,25 @@ public void onInteract(PlayerInteractEvent event) {
5982

6083
Block block = event.getClickedBlock();
6184
if (materials.contains(block.getType())) {
62-
BlockBreakEvent blockBreakEvent = new BlockBreakEvent(block, player);
63-
Bukkit.getPluginManager().callEvent(blockBreakEvent);
64-
if (!blockBreakEvent.isCancelled()) {
65-
block.getWorld().playEffect(block.getLocation(), Effect.STEP_SOUND, block.getType(), 16);
66-
block.breakNaturally();
85+
if (restrictionsEnabled) {
86+
for (String item : restrictionsItems) {
87+
if (player.getItemInHand().getType() == Material.valueOf(item)) {
88+
breakBlock(block, player);
89+
return;
90+
}
91+
}
92+
} else {
93+
breakBlock(block, player);
6794
}
6895
}
6996
}
97+
98+
public void breakBlock(Block block, Player player) {
99+
BlockBreakEvent blockBreakEvent = new BlockBreakEvent(block, player);
100+
Bukkit.getPluginManager().callEvent(blockBreakEvent);
101+
if (!blockBreakEvent.isCancelled()) {
102+
block.getWorld().playEffect(block.getLocation(), Effect.STEP_SOUND, block.getType(), 16);
103+
block.breakNaturally();
104+
}
105+
}
70106
}

src/main/resources/config.yml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,9 @@
11
materials:
22
- SPONGE
3+
blocked-worlds: []
4+
only-allow-instantbreak-with:
5+
enabled: false
6+
items:
7+
- DIAMOND_PICKAXE
8+
- WOOL
9+
- DIRT

src/main/resources/plugin.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name: InstantBreak
22
description: Instantly break certain blocks
33
version: ${version}
4-
author: Byteflux
4+
authors: [Byteflux, Terrobility]
55
softdepend: [AAC]
6-
main: net.minelink.instantbreak.InstantBreak
6+
main: net.minelink.instantbreak.InstantBreak

0 commit comments

Comments
 (0)