@@ -15,60 +15,153 @@ public abstract class PermissibleButton extends PerformButton {
1515 private Button elseButton ;
1616 private Button parentButton ;
1717
18+ /**
19+ * Retrieves the button displayed when the current button does not have the required permissions.
20+ *
21+ * @return the button displayed when the current button does not have the required permissions
22+ */
1823 public Button getElseButton () {
1924 return this .elseButton ;
2025 }
2126
27+ /**
28+ * Sets the button displayed when the current button does not have the required permissions.
29+ *
30+ * @param elseButton the button displayed when the current button does not have the required permissions
31+ */
2232 public void setElseButton (Button elseButton ) {
2333 this .elseButton = elseButton ;
2434 }
2535
36+ /**
37+ * Returns true if this button has any permissions (either AND or OR).
38+ *
39+ * @return true if this button has any permissions, false otherwise
40+ */
2641 public boolean hasPermission () {
2742 return !this .permissions .isEmpty () || !this .orPermissions .isEmpty ();
2843 }
2944
45+ /**
46+ * Returns true if this button has an alternative button set using the "elseButton" method.
47+ *
48+ * @return true if this button has an alternative button set using the "elseButton" method, false otherwise
49+ */
3050 public boolean hasElseButton () {
3151 return this .elseButton != null ;
3252 }
3353
54+ /**
55+ * Checks if the player has permission to interact with this button.
56+ * Permissions are checked in the following order:
57+ * <ol>
58+ * <li>OR permissions (if any of the OR permissions are true, the method returns true)</li>
59+ * <li>AND permissions (if all of the AND permissions are true, the method returns true)</li>
60+ * </ol>
61+ * If none of the above conditions are true, the method returns false.
62+ *
63+ * @param player the player to check
64+ * @param inventoryEngine the inventory engine
65+ * @param placeholders the placeholders
66+ * @return true if the player has permission, false otherwise
67+ */
3468 public boolean checkPermission (Player player , InventoryEngine inventoryEngine , Placeholders placeholders ) {
3569
3670 if (!this .orPermissions .isEmpty ()) {
37- return this .orPermissions .stream ().anyMatch (p -> p .hasPermission (player , null , inventoryEngine , placeholders ));
71+ for (PermissionPermissible permission : this .orPermissions ) {
72+ if (permission .hasPermission (player , null , inventoryEngine , placeholders )) {
73+ return true ;
74+ }
75+ }
76+ return false ;
3877 }
3978
4079 if (!this .permissions .isEmpty ()) {
41- return this .permissions .stream ().allMatch (p -> p .hasPermission (player , null , inventoryEngine , placeholders ));
80+ for (PermissionPermissible permission : this .permissions ) {
81+ if (!permission .hasPermission (player , null , inventoryEngine , placeholders )) {
82+ return false ;
83+ }
84+ }
85+ return true ;
4286 }
4387
4488 return true ;
4589 }
4690
91+ /**
92+ * Retrieves the parent button of this button.
93+ * The parent button is the button that is closest to this button in the
94+ * button hierarchy.
95+ *
96+ * @return the parent button of this button, or null if this button does not have a parent
97+ */
4798 public Button getParentButton () {
4899 return this .parentButton ;
49100 }
50101
102+ /**
103+ * Sets the parent button of this button.
104+ * The parent button is the button that is closest to this button in the
105+ * button hierarchy.
106+ *
107+ * @param parentButton the parent button of this button
108+ */
51109 public void setParentButton (Button parentButton ) {
52110 this .parentButton = parentButton ;
53111 }
54112
113+ /**
114+ * Retrieves the master parent button of this button.
115+ * The master parent button is the highest button in the button hierarchy that is not null.
116+ * If this button does not have a parent button, then this button is returned as the master parent button.
117+ *
118+ * @return the master parent button of this button
119+ */
55120 public Button getMasterParentButton () {
56121 Button button = this .getParentButton ();
57122 return button == null ? (Button ) this : button .getMasterParentButton ();
58123 }
59124
125+ /**
126+ * Retrieves the list of permissions that must be met for this button to be visible.
127+ * This list is used in conjunction with the list of permissions returned by
128+ * {@link #getPermissions()}, and is used to specify alternative permissions
129+ * that can be used to satisfy the visibility requirement of this button.
130+ *
131+ * @return the list of alternative permissions that can be used to satisfy the visibility requirement of this button
132+ */
60133 public List <PermissionPermissible > getOrPermission () {
61134 return this .orPermissions ;
62135 }
63136
137+ /**
138+ * Retrieves the list of permissions that must be met for this button to be visible.
139+ *
140+ * @return the list of permissions that must be met for this button to be visible
141+ */
64142 public List <PermissionPermissible > getPermissions () {
65143 return this .permissions ;
66144 }
67145
146+ /**
147+ * Sets the list of permissions that must be met for this button to be visible.
148+ * This list is used to specify the permissions that must be met for this button to be visible.
149+ * If this list is empty, then this button is always visible.
150+ *
151+ * @param permissions the list of permissions that must be met for this button to be visible
152+ */
68153 public void setPermissions (List <PermissionPermissible > permissions ) {
69154 this .permissions = permissions ;
70155 }
71156
157+ /**
158+ * Sets the list of permissions that can be used to satisfy the visibility requirement of this button.
159+ * This list is used in conjunction with the list of permissions returned by
160+ * {@link #getPermissions()}, and is used to specify alternative permissions that can be used to satisfy the visibility requirement of this button.
161+ * If this list is empty, then the list of permissions returned by {@link #getPermissions()} is used exclusively to satisfy the visibility requirement of this button.
162+ *
163+ * @param orPermissions the list of permissions that can be used to satisfy the visibility requirement of this button
164+ */
72165 public void setOrPermissions (List <PermissionPermissible > orPermissions ) {
73166 this .orPermissions = orPermissions ;
74167 }
0 commit comments