1
+ /*
2
+ * Copyright or © or Copr. ZLib contributors (2015 - 2016)
3
+ *
4
+ * This software is governed by the CeCILL-B license under French law and
5
+ * abiding by the rules of distribution of free software. You can use,
6
+ * modify and/ or redistribute the software under the terms of the CeCILL-B
7
+ * license as circulated by CEA, CNRS and INRIA at the following URL
8
+ * "http://www.cecill.info".
9
+ *
10
+ * As a counterpart to the access to the source code and rights to copy,
11
+ * modify and redistribute granted by the license, users are provided only
12
+ * with a limited warranty and the software's author, the holder of the
13
+ * economic rights, and the successive licensors have only limited
14
+ * liability.
15
+ *
16
+ * In this respect, the user's attention is drawn to the risks associated
17
+ * with loading, using, modifying and/or developing or reproducing the
18
+ * software by the user in light of its specific status of free software,
19
+ * that may mean that it is complicated to manipulate, and that also
20
+ * therefore means that it is reserved for developers and experienced
21
+ * professionals having in-depth computer knowledge. Users are therefore
22
+ * encouraged to load and test the software's suitability as regards their
23
+ * requirements in conditions enabling the security of their systems and/or
24
+ * data to be ensured and, more generally, to use and operate it in the
25
+ * same conditions as regards security.
26
+ *
27
+ * The fact that you are presently reading this means that you have had
28
+ * knowledge of the CeCILL-B license and that you accept its terms.
29
+ */
1
30
package fr .zcraft .zlib .components .gui ;
2
31
32
+ import org .apache .commons .lang .NotImplementedException ;
3
33
import org .bukkit .entity .Player ;
4
34
import org .bukkit .inventory .ItemStack ;
5
35
6
36
import fr .zcraft .zlib .components .gui .ExplorerGui ;
7
37
import fr .zcraft .zlib .components .gui .Gui ;
8
38
import fr .zcraft .zlib .tools .Callback ;
9
39
10
- public abstract class ArrayPromptGui <T > extends ExplorerGui <T > {
11
-
40
+ public abstract class ArrayPromptGui <T > extends ExplorerGui <T >
41
+ {
12
42
private Callback <T > cb ;
13
43
private String title ;
14
44
private T [] data ;
15
45
private boolean closeOnChoice ;
16
46
17
47
/**
18
- * @param callback
19
- * Callback called when the player made a choice
20
48
* @param player
21
49
* The player making the choice
22
50
* @param title
23
51
* The gui title
24
52
* @param data
25
53
* An array of datas to display
26
- * @param renderer
27
- * Interface for building gui's ItemStack from array values
28
54
* @param closeOnChoice
29
- * Close the interface when the player has choosen if true
55
+ * If true, close the interface when the player has choosen
56
+ * @param callback
57
+ * Callback called when the player made a choice
30
58
*/
31
- public <A > ArrayPromptGui (Callback < T > callback , Player player , String title , T [] data , boolean closeOnChoice ) {
59
+ public <A > ArrayPromptGui (Player player , String title , T [] data , boolean closeOnChoice , Callback < T > callback ) {
32
60
this .cb = callback ;
33
61
this .title = title ;
34
62
this .data = data ;
@@ -38,24 +66,22 @@ public <A> ArrayPromptGui(Callback<T> callback, Player player, String title, T[]
38
66
}
39
67
40
68
/**
41
- * @see #onChoice (Object)
69
+ * @see #onClick (Object)
42
70
*
43
71
* Constructor with no callback argument. Note that you must override
44
- * the onChoice method by using this constructor
72
+ * the onClick method if you use this constructor
45
73
*
46
74
* @param player
47
75
* The player making the choice
48
76
* @param title
49
77
* The gui title
50
78
* @param data
51
79
* An array of datas to display
52
- * @param renderer
53
- * Interface for building gui's ItemStack from array values
54
80
* @param closeOnChoice
55
81
* Close the interface when the player has choosen if true
56
82
*/
57
83
public <A > ArrayPromptGui (Player player , String title , T [] data , boolean closeOnChoice ) {
58
- this (null , player , title , data , closeOnChoice );
84
+ this (player , title , data , closeOnChoice , null );
59
85
}
60
86
61
87
/**
@@ -70,8 +96,8 @@ public <A> ArrayPromptGui(Player player, String title, T[] data, boolean closeOn
70
96
*
71
97
* @param data
72
98
*/
73
- public void onChoice (T data ) {
74
- System . err . println ( "Damn ! I'm not properly implemented : override me or use a callback." );
99
+ public void onClick (T data ) {
100
+ throw new NotImplementedException ( "Override this method or use a callback." );
75
101
}
76
102
77
103
@ Override
@@ -80,7 +106,7 @@ protected void onRightClick(T data) {
80
106
if (cb != null )
81
107
cb .call (data );
82
108
else
83
- onChoice (data );
109
+ onClick (data );
84
110
85
111
if (closeOnChoice )
86
112
close ();
@@ -92,20 +118,4 @@ protected void onUpdate() {
92
118
setMode (Mode .READONLY );
93
119
setData (data );
94
120
}
95
-
96
- public Callback <T > getCallback () {
97
- return cb ;
98
- }
99
-
100
- public String getPurpose () {
101
- return title ;
102
- }
103
-
104
- public T [] getData () {
105
- return data ;
106
- }
107
-
108
- public boolean closeOnChoice () {
109
- return closeOnChoice ;
110
- }
111
121
}
0 commit comments