2929import cn .nukkit .Player ;
3030import cn .nukkit .block .Block ;
3131import cn .nukkit .block .BlockLava ;
32+ import cn .nukkit .entity .Entity ;
3233import cn .nukkit .entity .item .EntityPrimedTNT ;
34+ import cn .nukkit .entity .mob .EntityMob ;
35+ import cn .nukkit .entity .passive .EntityAnimal ;
3336import cn .nukkit .event .EventHandler ;
3437import cn .nukkit .event .EventPriority ;
3538import cn .nukkit .event .Listener ;
3639import cn .nukkit .event .block .BlockBreakEvent ;
3740import cn .nukkit .event .block .BlockPlaceEvent ;
3841import cn .nukkit .event .entity .EntityDamageByEntityEvent ;
42+ import cn .nukkit .event .entity .EntityDamageEvent ;
3943import cn .nukkit .event .entity .EntityExplodeEvent ;
4044import cn .nukkit .event .inventory .CraftItemEvent ;
45+ import cn .nukkit .event .inventory .InventoryPickupItemEvent ;
4146import cn .nukkit .event .player .*;
4247import cn .nukkit .utils .TextFormat ;
4348import com .larryTheCoder .ASkyBlock ;
@@ -139,26 +144,6 @@ public void onPlayerMove(PlayerMoveEvent e) {
139144 }
140145 }
141146
142- @ EventHandler (priority = EventPriority .LOWEST )
143- public void onBucketUseEvent (PlayerBucketFillEvent e ) {
144- if (onBucketEvent (e .getPlayer (), e .getBlockClicked ())) e .setCancelled ();
145- }
146-
147- @ EventHandler (priority = EventPriority .LOWEST )
148- public void onBucketEmpty (PlayerBucketEmptyEvent e ) {
149- if (onBucketEvent (e .getPlayer (), e .getBlockClicked ())) e .setCancelled ();
150- }
151-
152- private boolean onBucketEvent (Player player , Block blockClicked ) {
153- if (notInWorld (player )) return false ;
154- if (actionAllowed (player , blockClicked .getLocation (), SettingsFlag .BUCKET )) {
155- if (blockClicked instanceof BlockLava && actionAllowed (player , blockClicked .getLocation (), SettingsFlag .COLLECT_LAVA )) {
156- return false ;
157- } else return !actionAllowed (player , blockClicked .getLocation (), SettingsFlag .COLLECT_WATER );
158- }
159- return true ;
160- }
161-
162147 @ EventHandler (priority = EventPriority .LOW )
163148 public void onPlayerExecuteCommand (PlayerCommandPreprocessEvent event ) {
164149 log .debug ("DEBUG: " + event .getEventName ());
@@ -173,10 +158,35 @@ public void onPlayerExecuteCommand(PlayerCommandPreprocessEvent event) {
173158 }
174159 }
175160
161+ @ EventHandler (priority = EventPriority .LOW )
162+ public void onPlayerHitEvent (EntityDamageEvent e ) {
163+ Entity target = e .getEntity ();
164+
165+ if (notInWorld (target )) return ;
166+ if (e instanceof EntityDamageByEntityEvent ) {
167+ EntityDamageByEntityEvent damage = (EntityDamageByEntityEvent ) e ;
168+ Entity cause = damage .getDamager ();
169+
170+ // Identifier for player mobs attack.
171+ if (!(cause instanceof Player )) {
172+ if (cause instanceof EntityAnimal ) {
173+ if (actionAllowed (target .getLocation (), SettingsFlag .HURT_MOBS )) return ;
174+ } else if (cause instanceof EntityMob ) {
175+ if (actionAllowed (target .getLocation (), SettingsFlag .HURT_MONSTERS )) return ;
176+ }
177+ } else {
178+ if (actionAllowed (target .getLocation (), SettingsFlag .PVP )) return ;
179+ }
180+
181+ e .setCancelled ();
182+ }
183+ }
184+
176185 @ EventHandler (priority = EventPriority .LOWEST )
177186 public void onPlayerDropItem (PlayerDropItemEvent e ) {
178187 log .debug ("DEBUG: " + e .getEventName ());
179188 log .debug ("DEBUG: Item is " + e .getItem ().toString ());
189+
180190 Player p = e .getPlayer ();
181191 if (notInWorld (p )) {
182192 log .debug ("Event is not in world" );
@@ -196,7 +206,37 @@ public void onPlayerDropItem(PlayerDropItemEvent e) {
196206 return ;
197207 }
198208
199- // Do not send any message, it may spam
209+ log .debug ("Action not allowed: Drop item" );
210+ e .setCancelled ();
211+ }
212+
213+ @ EventHandler (priority = EventPriority .LOWEST )
214+ public void onPlayerPickupItem (InventoryPickupItemEvent e ) {
215+ log .debug ("DEBUG: " + e .getEventName ());
216+ log .debug ("DEBUG: Item is " + e .getItem ().toString ());
217+
218+ Player p = (Player ) e .getInventory ().getHolder ();
219+ if (notInWorld (p )) {
220+ log .debug ("Event is not in world" );
221+ return ;
222+ }
223+ if (p .isOp () || hasPermission (p , "is.mod.bypassprotect" )) {
224+ return ;
225+ }
226+
227+ // Too bad that the item is not a vector3
228+ if (plugin .getIslandManager ().locationIsOnIsland (p , e .getItem ())) {
229+ log .debug ("Action is allowed: Player on island" );
230+ // You can do anything on your island
231+ return ;
232+ }
233+
234+ if (actionAllowed (e .getItem ().getLocation (), SettingsFlag .VISITOR_ITEM_PICKUP )) {
235+ log .debug ("Action is allowed: Item pickup is allowed" );
236+ return ;
237+ }
238+
239+ log .debug ("Action not allowed: Pickup item" );
200240 e .setCancelled ();
201241 }
202242
@@ -231,27 +271,27 @@ public void onPlayerInteract(PlayerInteractEvent e) {
231271 // No need stupid checks. Just cancel them
232272 p .sendMessage (getPrefix () + plugin .getLocale (e .getPlayer ()).islandProtected );
233273 e .setCancelled ();
234- log .debug ("Action is blocked" );
274+ log .debug ("Action is blocked PHYSICAL " );
235275 return ;
236276 }
237277 break ;
238278 case LEFT_CLICK_BLOCK :
239279 // Player is interacting with an item. Check if it allowed
240- if (!Utils .isItemAllowed (p , e .getItem ())) {
280+ if (!Utils .isItemAllowed (p , e .getItem (), e . getBlock () )) {
241281 // No need stupid checks. Just cancel them
242282 p .sendMessage (getPrefix () + plugin .getLocale (e .getPlayer ()).islandProtected );
243283 e .setCancelled ();
244- log .debug ("Action is blocked" );
284+ log .debug ("Action is blocked LEFT_CLICK_BLOCK " );
245285 return ;
246286 }
247287 break ;
248288 case RIGHT_CLICK_BLOCK :
249289 // Player is clicking on something. Check if it allowed
250- if (!Utils .isInventoryAllowed (p , e .getBlock ())) {
290+ if (!Utils .isInventoryAllowed (p , e .getItem (), e . getBlock ())) {
251291 // No need stupid checks. Just cancel them
252292 p .sendMessage (getPrefix () + plugin .getLocale (e .getPlayer ()).islandProtected );
253293 e .setCancelled ();
254- log .debug ("Action is blocked" );
294+ log .debug ("Action is blocked RIGHT_CLICK_BLOCK " );
255295 return ;
256296 }
257297 break ;
0 commit comments