@@ -75,50 +75,59 @@ public AndroidType getAndroidType() {
75
75
protected void dig (Block b , BlockMenu menu , Block block ) {
76
76
Collection <ItemStack > drops = block .getDrops (effectivePickaxe );
77
77
78
- if (!SlimefunTag .UNBREAKABLE_MATERIALS .isTagged (block .getType ()) && !drops .isEmpty ()) {
79
- OfflinePlayer owner = Bukkit .getOfflinePlayer (UUID .fromString (BlockStorage .getLocationInfo (b .getLocation (), "owner" )));
78
+ if (!canBreakBlock (block , b )) {
79
+ return ;
80
+ }
80
81
81
- if (Slimefun .getProtectionManager ().hasPermission (owner , block .getLocation (), Interaction .BREAK_BLOCK )) {
82
- AndroidMineEvent event = new AndroidMineEvent (block , new AndroidInstance (this , b ));
83
- Bukkit .getPluginManager ().callEvent (event );
82
+ AndroidMineEvent event = new AndroidMineEvent (block , new AndroidInstance (this , b ));
83
+ Bukkit .getPluginManager ().callEvent (event );
84
84
85
- if (event .isCancelled ()) {
86
- return ;
87
- }
85
+ if (event .isCancelled ()) {
86
+ return ;
87
+ }
88
88
89
- // We only want to break non-Slimefun blocks
90
- if (!BlockStorage .hasBlockInfo (block )) {
91
- breakBlock (menu , drops , block );
92
- }
93
- }
89
+ // We only want to break non-Slimefun blocks
90
+ if (!BlockStorage .hasBlockInfo (block )) {
91
+ breakBlock (menu , drops , block );
94
92
}
95
93
}
96
94
95
+ @ ParametersAreNonnullByDefault
96
+ protected boolean canBreakBlock (Block block , Block b ) {
97
+ Collection <ItemStack > drops = block .getDrops (effectivePickaxe );
98
+ if (SlimefunTag .UNBREAKABLE_MATERIALS .isTagged (block .getType ()) || drops .isEmpty ()) {
99
+ return false ;
100
+ }
101
+
102
+ String ownerName = BlockStorage .getLocationInfo (b .getLocation (), "owner" );
103
+ OfflinePlayer owner = Bukkit .getOfflinePlayer (UUID .fromString (ownerName ));
104
+ if (!Slimefun .getProtectionManager ().hasPermission (owner , block .getLocation (), Interaction .BREAK_BLOCK )) {
105
+ return false ;
106
+ }
107
+
108
+ return true ;
109
+ }
110
+
97
111
@ Override
98
112
@ ParametersAreNonnullByDefault
99
113
protected void moveAndDig (Block b , BlockMenu menu , BlockFace face , Block block ) {
100
114
Collection <ItemStack > drops = block .getDrops (effectivePickaxe );
101
115
102
- if (!SlimefunTag .UNBREAKABLE_MATERIALS .isTagged (block .getType ()) && !drops .isEmpty ()) {
103
- OfflinePlayer owner = Bukkit .getOfflinePlayer (UUID .fromString (BlockStorage .getLocationInfo (b .getLocation (), "owner" )));
116
+ if (!canBreakBlock (block , b )) {
117
+ move (b , face , block );
118
+ return ;
119
+ }
104
120
105
- if (Slimefun .getProtectionManager ().hasPermission (owner , block .getLocation (), Interaction .BREAK_BLOCK )) {
106
- AndroidMineEvent event = new AndroidMineEvent (block , new AndroidInstance (this , b ));
107
- Bukkit .getPluginManager ().callEvent (event );
121
+ AndroidMineEvent event = new AndroidMineEvent (block , new AndroidInstance (this , b ));
122
+ Bukkit .getPluginManager ().callEvent (event );
108
123
109
- if (event .isCancelled ()) {
110
- return ;
111
- }
124
+ if (event .isCancelled ()) {
125
+ return ;
126
+ }
112
127
113
- // We only want to break non-Slimefun blocks
114
- if (!BlockStorage .hasBlockInfo (block )) {
115
- breakBlock (menu , drops , block );
116
- move (b , face , block );
117
- }
118
- } else {
119
- move (b , face , block );
120
- }
121
- } else {
128
+ // We only want to break non-Slimefun blocks
129
+ if (!BlockStorage .hasBlockInfo (block )) {
130
+ breakBlock (menu , drops , block );
122
131
move (b , face , block );
123
132
}
124
133
}
0 commit comments