11package net .minelink .instantbreak ;
22
33import java .util .HashSet ;
4+ import java .util .List ;
45import java .util .Set ;
56
67import net .minelink .instantbreak .hooks .AACHook ;
2122import org .bukkit .plugin .java .JavaPlugin ;
2223
2324public 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}
0 commit comments