@@ -26,39 +26,66 @@ public class BlockPlayerListener implements Listener {
26
26
@ EventHandler (priority = EventPriority .NORMAL )
27
27
public void onPlayerQuickLockChest (PlayerInteractEvent event ){
28
28
if (event .isCancelled ()) return ;
29
+ // Check quick lock enabled
29
30
if (Config .getQuickProtectAction () == (byte )0 ) return ;
31
+ // Get player and action info
30
32
Action action = event .getAction ();
31
33
Player player = event .getPlayer ();
34
+ // Check action correctness
32
35
if (action == Action .RIGHT_CLICK_BLOCK && player .getItemInHand ().getType () == Material .SIGN ){
36
+ // Check quick lock action correctness
33
37
if (!((event .getPlayer ().isSneaking () && Config .getQuickProtectAction () == (byte )2 ) ||
34
38
(!event .getPlayer ().isSneaking () && Config .getQuickProtectAction () == (byte )1 ))) return ;
39
+ // Check permission
35
40
if (!player .hasPermission ("lockettepro.lock" )) return ;
41
+ // Get target block to lock
36
42
BlockFace blockface = event .getBlockFace ();
37
43
if (blockface == BlockFace .NORTH || blockface == BlockFace .WEST || blockface == BlockFace .EAST || blockface == BlockFace .SOUTH ){
38
44
Block block = event .getClickedBlock ();
39
- if (Dependency .isProtectedFrom (block , player )) return ; // External check here
40
- if (Dependency .isProtectedFrom (block .getRelative (event .getBlockFace ()), player )) return ; // External check again for sign here
41
- if (block .getRelative (blockface ).getType () != Material .AIR ) return ; // This location is obstructed
45
+ // Check permission with external plugin
46
+ if (Dependency .isProtectedFrom (block , player )) return ; // blockwise
47
+ if (Dependency .isProtectedFrom (block .getRelative (event .getBlockFace ()), player )) return ; // signwise
48
+ // Check whether locking location is obstructed
49
+ if (block .getRelative (blockface ).getType () != Material .AIR ) return ;
50
+ // Check whether this block is lockable
42
51
if (LocketteProAPI .isLockable (block )){
52
+ // Is this block already locked?
43
53
boolean locked = LocketteProAPI .isLocked (block );
54
+ // Cancel event here
44
55
event .setCancelled (true );
56
+ // Check lock info info
45
57
if (!locked && !LocketteProAPI .isUpDownLockedDoor (block )){
58
+ // Not locked, not a locked door nearby
46
59
Utils .removeASign (player );
60
+ // Send message
47
61
Utils .sendMessages (player , Config .getLang ("locked-quick" ));
48
- Utils .putSignOn (block , blockface , Config .getDefaultPrivateString (), player .getName ());
62
+ // Put sign on
63
+ Block newsign = Utils .putSignOn (block , blockface , Config .getDefaultPrivateString (), player .getName ());
49
64
Utils .resetCache (block );
65
+ // Cleanups - UUID
50
66
if (Config .isUuidEnabled ()){
51
- Utils .updateLineByPlayer (block . getRelative ( blockface ) , 1 , player );
67
+ Utils .updateLineByPlayer (newsign , 1 , player );
52
68
}
69
+ // Cleanups - Expiracy
70
+ // if (Config.isLockExpire()){
71
+ // if (player.hasPermission("lockettepro.noexpire")){
72
+ // Utils.updateLineWithTime(newsign, true); // set created to -1 (no expire)
73
+ // } else {
74
+ Utils .updateLineWithTime (newsign , false ); // set created to now
75
+ // }
76
+ // }
53
77
} else if (!locked && LocketteProAPI .isOwnerUpDownLockedDoor (block , player )){
78
+ // Not locked, (is locked door nearby), is owner of locked door nearby
54
79
Utils .removeASign (player );
55
80
Utils .sendMessages (player , Config .getLang ("additional-sign-added-quick" ));
56
81
Utils .putSignOn (block , blockface , Config .getDefaultAdditionalString (), "" );
57
82
} else if (LocketteProAPI .isOwner (block , player )){
83
+ // Locked, (not locked door nearby), is owner of locked block
58
84
Utils .removeASign (player );
59
85
Utils .putSignOn (block , blockface , Config .getDefaultAdditionalString (), "" );
60
86
Utils .sendMessages (player , Config .getLang ("additional-sign-added-quick" ));
61
87
} else {
88
+ // Cannot lock this block
62
89
Utils .sendMessages (player , Config .getLang ("cannot-lock-quick" ));
63
90
}
64
91
}
@@ -159,7 +186,11 @@ public void onAttemptBreakSign(BlockBreakEvent event){
159
186
Utils .playAccessDenyEffect (player , block );
160
187
}
161
188
} else if (LocketteProAPI .isAdditionalSign (block )){
162
- if (LocketteProAPI .isOwnerOfSign (block , player )){
189
+ // TODO the next line is spaghetti
190
+ if (!LocketteProAPI .isLocked (LocketteProAPI .getAttachedBlock (block ))){
191
+ // phew, the locked block is expired!
192
+ // nothing
193
+ } else if (LocketteProAPI .isOwnerOfSign (block , player )){
163
194
Utils .sendMessages (player , Config .getLang ("break-own-additional-sign" ));
164
195
} else if (!LocketteProAPI .isProtected (LocketteProAPI .getAttachedBlock (block ))){
165
196
Utils .sendMessages (player , Config .getLang ("break-redundant-additional-sign" ));
0 commit comments