2
2
3
3
import me .flame .menus .items .MenuItem ;
4
4
import me .flame .menus .modifiers .Modifier ;
5
+ import org .jetbrains .annotations .Contract ;
5
6
import org .jetbrains .annotations .NotNull ;
6
7
7
8
import java .util .EnumSet ;
8
- import java .util .List ;
9
9
10
+ /**
11
+ * Most commonly used normal Menu extending BaseMenu.
12
+ */
10
13
@ SuppressWarnings ("unused" )
11
- public final class Menu extends BaseMenu <Menu > {
12
- public Menu (int rows , String title , EnumSet <Modifier > modifiers , boolean colorize ) {
13
- super (rows , title , modifiers , colorize );
14
- }
15
-
16
- public Menu (int rows , String title , EnumSet <Modifier > modifiers ) {
14
+ public final class Menu extends BaseMenu implements Cloneable {
15
+ private Menu (int rows , String title , EnumSet <Modifier > modifiers ) {
17
16
super (rows , title , modifiers );
18
17
}
19
18
20
- public Menu (MenuType type , String title , EnumSet <Modifier > modifiers ) {
19
+ private Menu (MenuType type , String title , EnumSet <Modifier > modifiers ) {
21
20
super (type , title , modifiers );
22
21
}
23
22
24
- public Menu (int rows , String title ) {
23
+ private Menu (int rows , String title ) {
25
24
super (rows , title , EnumSet .noneOf (Modifier .class ));
26
25
}
27
26
28
- public Menu (MenuType type , String title ) {
27
+ private Menu (MenuType type , String title ) {
29
28
super (type , title , EnumSet .noneOf (Modifier .class ));
30
29
}
31
30
32
- public Menu (MenuType type , String title , EnumSet <Modifier > modifiers , boolean colorize ) {
31
+ private Menu (MenuType type , String title , EnumSet <Modifier > modifiers , boolean colorize ) {
33
32
super (type , title , modifiers , colorize );
34
33
}
35
34
35
+ @ NotNull
36
+ @ Contract ("_, _ -> new" )
37
+ public static Menu create (String title , int rows ) {
38
+ return new Menu (rows , title );
39
+ }
40
+
41
+ @ NotNull
42
+ @ Contract ("_, _, _ -> new" )
43
+ public static Menu create (String title , int rows , EnumSet <Modifier > modifiers ) {
44
+ return new Menu (rows , title , modifiers );
45
+ }
46
+
47
+ @ NotNull
48
+ @ Contract ("_, _ -> new" )
49
+ public static Menu create (String title , MenuType type ) {
50
+ return new Menu (type , title );
51
+ }
52
+
53
+ @ NotNull
54
+ @ Contract ("_, _, _ -> new" )
55
+ public static Menu create (String title , MenuType type , EnumSet <Modifier > modifiers ) {
56
+ return new Menu (type , title , modifiers );
57
+ }
58
+
59
+ public static Menu create (MenuData menuData ) {
60
+ MenuType type = menuData .getType ();
61
+ Menu menu = type != MenuType .CHEST
62
+ ? new Menu (type , menuData .getTitle (), menuData .getModifiers ())
63
+ : new Menu (menuData .getRows (), menuData .getTitle (), menuData .getModifiers ());
64
+ menu .setContents (menuData .getItems ().toArray (new MenuItem [0 ]));
65
+ return menu ;
66
+ }
67
+
36
68
/**
37
69
* Generate a paginated menu; convert to a {@link PaginatedMenu} from a {@link Menu}
38
70
*
@@ -42,9 +74,7 @@ public Menu(MenuType type, String title, EnumSet<Modifier> modifiers, boolean co
42
74
@ NotNull
43
75
public PaginatedMenu pagination () {
44
76
PaginatedMenu menu = PaginatedMenu .create (title , rows , 3 , modifiers );
45
- for (int i = 0 ; i < size ; i ++) {
46
- menu .setItem (i , itemMap .get (i ));
47
- }
77
+ menu .setContents (itemMap );
48
78
return menu ;
49
79
}
50
80
@@ -56,9 +86,16 @@ public PaginatedMenu pagination() {
56
86
@ NotNull
57
87
public PaginatedMenu pagination (int pages ) {
58
88
PaginatedMenu menu = PaginatedMenu .create (title , rows , pages , modifiers );
59
- for (int i = 0 ; i < size ; i ++) {
60
- menu .setItem (i , itemMap .get (i ));
61
- }
89
+ menu .setContents (itemMap );
62
90
return menu ;
63
91
}
92
+
93
+ @ Override
94
+ public Menu clone () {
95
+ try {
96
+ return (Menu ) super .clone ();
97
+ } catch (CloneNotSupportedException e ) {
98
+ throw new RuntimeException (e );
99
+ }
100
+ }
64
101
}
0 commit comments