3
3
import net .minecraft .command .CommandBase ;
4
4
import net .minecraft .command .CommandException ;
5
5
import net .minecraft .command .ICommandSender ;
6
+ import net .minecraft .entity .player .EntityPlayer ;
6
7
import net .minecraft .server .MinecraftServer ;
7
8
import net .minecraft .server .management .PlayerProfileCache ;
9
+ import net .minecraft .util .math .BlockPos ;
8
10
import net .minecraft .util .text .ITextComponent ;
9
11
import net .minecraft .util .text .TextComponentString ;
10
12
import play .ai .dragonrealm .geiloutils .config .ConfigurationManager ;
11
13
import play .ai .dragonrealm .geiloutils .config .kits .Kit ;
12
14
import play .ai .dragonrealm .geiloutils .config .kits .KitItem ;
13
15
import play .ai .dragonrealm .geiloutils .config .permissions .Permission ;
16
+ import play .ai .dragonrealm .geiloutils .utils .ArrayUtils ;
17
+ import play .ai .dragonrealm .geiloutils .utils .ItemUtils ;
14
18
import play .ai .dragonrealm .geiloutils .utils .KitUtils ;
19
+ import play .ai .dragonrealm .geiloutils .utils .PermissionUtils ;
20
+
21
+ import javax .annotation .Nullable ;
22
+ import java .util .ArrayList ;
23
+ import java .util .List ;
15
24
16
25
public class CommandGeiloKit extends CommandBase {
17
26
@@ -25,10 +34,36 @@ public String getUsage(ICommandSender sender) {
25
34
return "Manage your kits" ;
26
35
}
27
36
37
+ @ Override
38
+ public List <String > getTabCompletions (MinecraftServer server , ICommandSender sender , String [] args , @ Nullable BlockPos targetPos ){
39
+ List <String > tmpList = new ArrayList <String >();
40
+ EntityPlayer player ;
41
+ if (sender instanceof EntityPlayer ) {
42
+ player = (EntityPlayer ) sender ;
43
+ }
44
+
45
+ if (args .length == 1 ) {
46
+ tmpList .add ("addPermission" );
47
+ tmpList .add ("addItem" );
48
+ tmpList .add ("delPermission" );
49
+ tmpList .add ("delItem" );
50
+ tmpList .add ("create" );
51
+ tmpList .add ("list" );
52
+ tmpList .add ("delete" );
53
+ tmpList .add ("info" );
54
+
55
+ return ArrayUtils .startsWith (tmpList , args [0 ]);
56
+ }
57
+
58
+ //TODO: Tab Completion
59
+
60
+ return tmpList ;
61
+ }
62
+
28
63
@ Override
29
64
public void execute (MinecraftServer server , ICommandSender sender , String [] args ) throws CommandException {
30
65
ITextComponent msg ;
31
- if (args .length == 2 && args [0 ].equals ("create" ) && !args [1 ].equals (null )) {
66
+ if (args .length == 2 && args [0 ].equals ("create" ) && !args [1 ].equals ("" )) {
32
67
if (KitUtils .doesKitExist (args [1 ])) {
33
68
msg = new TextComponentString (ConfigurationManager .getGeneralConfig ().getCommandPrefix () + "This kit already exists" );
34
69
sender .sendMessage (msg );
@@ -44,7 +79,7 @@ public void execute(MinecraftServer server, ICommandSender sender, String[] args
44
79
}
45
80
}
46
81
47
- if (args .length == 2 && args [0 ].equals ("delete" ) && !args [1 ].equals (null )) {
82
+ if (args .length == 2 && args [0 ].equals ("delete" ) && !args [1 ].equals ("" )) {
48
83
String kit = KitUtils .removeKitByName (args [1 ]);
49
84
if (!kit .equals ("" )) {
50
85
ConfigurationManager .syncFromFields ();
@@ -67,31 +102,105 @@ public void execute(MinecraftServer server, ICommandSender sender, String[] args
67
102
}
68
103
}
69
104
70
- if (args .length == 3 && args [0 ].equals ("addItem" ) && !args [1 ].equals (null ) && !args [2 ].equals (null )) {
105
+ if (args .length == 5 && args [0 ].equals ("addItem" ) && !args [1 ].equals ("" ) && !args [2 ].equals ("" )) {
71
106
if (KitUtils .doesKitExist (args [1 ])) {
72
-
107
+ Kit kit = KitUtils .getKitByName (args [1 ]);
108
+ if (ItemUtils .doesItemExist (args [2 ])){
109
+ if (!KitUtils .doesKitHaveItem (kit , new KitItem (args [2 ], Integer .parseInt (args [3 ]), 0 ))){
110
+ kit .getItems ().add (new KitItem (args [2 ], Integer .parseInt (args [3 ]), Integer .parseInt (args [4 ])));
111
+ KitUtils .updateKit (kit );
112
+
113
+ msg = new TextComponentString (ConfigurationManager .getGeneralConfig ().getCommandPrefix () + "Added Item to kit" );
114
+ sender .sendMessage (msg );
115
+ }else {
116
+ msg = new TextComponentString (ConfigurationManager .getGeneralConfig ().getCommandPrefix () + "Kit already has that item" );
117
+ sender .sendMessage (msg );
118
+ }
119
+ }else {
120
+ msg = new TextComponentString (ConfigurationManager .getGeneralConfig ().getCommandPrefix () + "Couldn't find the item '" + args [2 ] + "'. Try tab completion" );
121
+ sender .sendMessage (msg );
122
+ }
123
+ }else {
124
+ msg = new TextComponentString (ConfigurationManager .getGeneralConfig ().getCommandPrefix () + "Couldn't find kit '" + args [1 ] + "'. Try /geilokit list" );
125
+ sender .sendMessage (msg );
73
126
}
74
127
}
75
128
76
- if (args .length == 3 && args [0 ].equals ("addPermission" ) && !args [1 ].equals (null ) && !args [2 ].equals (null )) {
129
+ if (args .length == 3 && args [0 ].equals ("addPermission" ) && !args [1 ].equals ("" ) && !args [2 ].equals ("" )) {
77
130
if (KitUtils .doesKitExist (args [1 ])) {
78
-
79
- }
131
+ if (PermissionUtils .doesPermissionExist (args [2 ])){
132
+ if (!KitUtils .doesKitHavePermission (KitUtils .getKitByName (args [1 ]), new Permission (args [2 ]))) {
133
+ Kit kit = KitUtils .getKitByName (args [1 ]);
134
+ kit .getPermissionList ().add (new Permission (args [2 ]));
135
+ KitUtils .updateKit (kit );
136
+
137
+ msg = new TextComponentString (ConfigurationManager .getGeneralConfig ().getCommandPrefix () + "Added permission to kit" );
138
+ sender .sendMessage (msg );
139
+ }else {
140
+ msg = new TextComponentString (ConfigurationManager .getGeneralConfig ().getCommandPrefix () + "Kit already has that permission" );
141
+ sender .sendMessage (msg );
142
+ }
143
+ }else {
144
+ msg = new TextComponentString (ConfigurationManager .getGeneralConfig ().getCommandPrefix () + "Couldn't find permissions '" + args [2 ] + "'. Try /geiloperm list" );
145
+ sender .sendMessage (msg );
146
+ }
147
+ }else {
148
+ msg = new TextComponentString (ConfigurationManager .getGeneralConfig ().getCommandPrefix () + "Couldn't find kit '" + args [1 ] + "'. Try /geilokit list" );
149
+ sender .sendMessage (msg );
150
+ }
80
151
}
81
152
82
- if (args .length == 3 && args [0 ].equals ("removeItem" ) && !args [1 ].equals (null ) && !args [2 ].equals (null )) {
153
+ if (args .length == 4 && args [0 ].equals ("removeItem" ) && !args [1 ].equals ("" ) && !args [2 ].equals ("" )) {
83
154
if (KitUtils .doesKitExist (args [1 ])) {
84
-
85
- }
155
+ Kit kit = KitUtils .getKitByName (args [1 ]);
156
+ if (ItemUtils .doesItemExist (args [2 ])){
157
+ KitItem kitItem = new KitItem (args [2 ], Integer .parseInt (args [3 ]), 0 );
158
+ if (KitUtils .doesKitHaveItem (kit , kitItem )){
159
+ KitUtils .updateKit (KitUtils .removeItemFromKit (kit , kitItem ));
160
+
161
+ msg = new TextComponentString (ConfigurationManager .getGeneralConfig ().getCommandPrefix () + "Removed the item from the Kit" );
162
+ sender .sendMessage (msg );
163
+ }else {
164
+ msg = new TextComponentString (ConfigurationManager .getGeneralConfig ().getCommandPrefix () + "Kit doesn't have that item" );
165
+ sender .sendMessage (msg );
166
+ }
167
+ }else {
168
+ msg = new TextComponentString (ConfigurationManager .getGeneralConfig ().getCommandPrefix () + "Couldn't find item '" + args [2 ] + "'. Try tab completion" );
169
+ sender .sendMessage (msg );
170
+ }
171
+ }else {
172
+ msg = new TextComponentString (ConfigurationManager .getGeneralConfig ().getCommandPrefix () + "Couldn't find kit '" + args [1 ] + "'. Try /geilokit list" );
173
+ sender .sendMessage (msg );
174
+ }
86
175
}
87
176
88
- if (args .length == 3 && args [0 ].equals ("removePermission" ) && !args [1 ].equals (null ) && !args [2 ].equals (null )) {
177
+ if (args .length == 3 && args [0 ].equals ("removePermission" ) && !args [1 ].equals ("" ) && !args [2 ].equals ("" )) {
89
178
if (KitUtils .doesKitExist (args [1 ])) {
90
-
179
+ if (KitUtils .doesKitExist (args [1 ])) {
180
+ if (PermissionUtils .doesPermissionExist (args [2 ])){
181
+ if (KitUtils .doesKitHavePermission (KitUtils .getKitByName (args [1 ]), new Permission (args [2 ]))) {
182
+ Kit kit = KitUtils .getKitByName (args [1 ]);
183
+ KitUtils .removePermissionFromKit (kit , new Permission (args [2 ]));
184
+ KitUtils .updateKit (kit );
185
+
186
+ msg = new TextComponentString (ConfigurationManager .getGeneralConfig ().getCommandPrefix () + "Removed permission from kit" );
187
+ sender .sendMessage (msg );
188
+ }else {
189
+ msg = new TextComponentString (ConfigurationManager .getGeneralConfig ().getCommandPrefix () + "Kit doesn't have that permission" );
190
+ sender .sendMessage (msg );
191
+ }
192
+ }else {
193
+ msg = new TextComponentString (ConfigurationManager .getGeneralConfig ().getCommandPrefix () + "Couldn't find permissions '" + args [2 ] + "'. Try /geiloperm list" );
194
+ sender .sendMessage (msg );
195
+ }
196
+ }else {
197
+ msg = new TextComponentString (ConfigurationManager .getGeneralConfig ().getCommandPrefix () + "Couldn't find kit '" + args [1 ] + "'. Try /geilokit list" );
198
+ sender .sendMessage (msg );
199
+ }
91
200
}
92
201
}
93
202
94
- if (args .length == 2 && args [0 ].equals ("info" ) && !args [1 ].equals (null )) {
203
+ if (args .length == 2 && args [0 ].equals ("info" ) && !args [1 ].equals ("" )) {
95
204
if (KitUtils .doesKitExist (args [1 ])) {
96
205
Kit kit = KitUtils .getKitByName (args [1 ]);
97
206
// Beginning
@@ -127,7 +236,10 @@ public void execute(MinecraftServer server, ICommandSender sender, String[] args
127
236
msg = new TextComponentString (ConfigurationManager .getGeneralConfig ().getCommandPrefix () + "Items: " + tmp .substring (0 , tmp .length () - 1 ));
128
237
sender .sendMessage (msg );
129
238
}
130
- }
239
+ }else {
240
+ msg = new TextComponentString (ConfigurationManager .getGeneralConfig ().getCommandPrefix () + "Couldn't find kit" );
241
+ sender .sendMessage (msg );
242
+ }
131
243
}
132
244
}
133
245
0 commit comments