11package com .github .moincraft .cloudnet .module .commandscheduler ;
22
33import com .github .moincraft .cloudnet .module .commandscheduler .data .Schedule ;
4- import eu .cloudnetservice .common .language .I18n ;
4+ import eu .cloudnetservice .driver .language .I18n ;
55import eu .cloudnetservice .driver .document .Document ;
66import eu .cloudnetservice .node .command .annotation .Description ;
77import eu .cloudnetservice .node .command .exception .ArgumentNotAvailableException ;
3131public class CommandSchedulerCommand {
3232
3333 private final CommandSchedulerModule module ;
34+ private final I18n i18n ;
3435
3536 @ Inject
3637 public CommandSchedulerCommand (
37- @ NotNull CommandSchedulerModule module
38+ @ NotNull CommandSchedulerModule module ,
39+ @ NotNull I18n i18n
3840 ) {
3941 this .module = module ;
42+ this .i18n = i18n ;
4043 }
4144
4245 @ Parser (name = "schedule" , suggestions = "schedule" )
@@ -45,7 +48,7 @@ public Schedule parseSchedule(CommandInput input) {
4548 if (this .module .getDatabase ().contains (inputString )) {
4649 return Objects .requireNonNull (this .module .getDatabase ().get (inputString )).toInstanceOf (Schedule .class );
4750 }
48- throw new ArgumentNotAvailableException (I18n . trans ("module-commandscheduler-schedule-not-found" , inputString ));
51+ throw new ArgumentNotAvailableException (this . i18n . translate ("module-commandscheduler-schedule-not-found" , inputString ));
4952 }
5053
5154 @ Suggestions ("schedule" )
@@ -86,45 +89,45 @@ public Iterable<String> suggestScheduleCommands(CommandContext<CommandSource> co
8689 public void listSchedules (@ NotNull CommandSource source ) {
8790 var count = this .module .getDatabase ().documentCount ();
8891 if (count == 0 ) {
89- source .sendMessage (I18n . trans ("module-commandscheduler-no-schedules" ));
92+ source .sendMessage (this . i18n . translate ("module-commandscheduler-no-schedules" ));
9093 return ;
9194 }
9295
9396 if (count == 1 ) {
94- source .sendMessage (I18n . trans ("module-commandscheduler-one-schedule" ));
97+ source .sendMessage (this . i18n . translate ("module-commandscheduler-one-schedule" ));
9598 } else {
96- source .sendMessage (I18n . trans ("module-commandscheduler-multiple-schedules" , count ));
99+ source .sendMessage (this . i18n . translate ("module-commandscheduler-multiple-schedules" , count ));
97100 }
98- source .sendMessage (I18n . trans ("module-commandscheduler-schedule-list-header" ));
99- source .sendMessage (I18n . trans ("module-commandscheduler-schedule-list-separator" ));
101+ source .sendMessage (this . i18n . translate ("module-commandscheduler-schedule-list-header" ));
102+ source .sendMessage (this . i18n . translate ("module-commandscheduler-schedule-list-separator" ));
100103 var schedules = new TreeMap <String , Document >(Comparator .naturalOrder ());
101104 schedules .putAll (this .module .getDatabase ().entries ());
102105 schedules .forEach ((name , document ) -> {
103106 final var schedule = document .toInstanceOf (Schedule .class );
104107 final var nextExecution = schedule .determineNextExecution (ZonedDateTime .now ());
105108
106- source .sendMessage (I18n . trans ("module-commandscheduler-schedule-list-key-internal-id" , name ));
107- source .sendMessage (I18n . trans ("module-commandscheduler-schedule-list-key-name" , schedule .name ()));
108- source .sendMessage (I18n . trans ("module-commandscheduler-schedule-list-key-creation" , schedule .creationDate ()));
109- source .sendMessage (I18n . trans ("module-commandscheduler-schedule-list-key-expression" , schedule .expression ()));
110- source .sendMessage (I18n . trans ("module-commandscheduler-schedule-list-key-single-use" , schedule .singleUse ()));
111- source .sendMessage (I18n . trans ("module-commandscheduler-schedule-list-key-enabled" , schedule .enabled ()));
109+ source .sendMessage (this . i18n . translate ("module-commandscheduler-schedule-list-key-internal-id" , name ));
110+ source .sendMessage (this . i18n . translate ("module-commandscheduler-schedule-list-key-name" , schedule .name ()));
111+ source .sendMessage (this . i18n . translate ("module-commandscheduler-schedule-list-key-creation" , schedule .creationDate ()));
112+ source .sendMessage (this . i18n . translate ("module-commandscheduler-schedule-list-key-expression" , schedule .expression ()));
113+ source .sendMessage (this . i18n . translate ("module-commandscheduler-schedule-list-key-single-use" , schedule .singleUse ()));
114+ source .sendMessage (this . i18n . translate ("module-commandscheduler-schedule-list-key-enabled" , schedule .enabled ()));
112115 final List <String > commands = schedule .commands ();
113116 if (commands .isEmpty ()) {
114- source .sendMessage (I18n . trans ("module-commandscheduler-schedule-list-script-empty" ));
117+ source .sendMessage (this . i18n . translate ("module-commandscheduler-schedule-list-script-empty" ));
115118 } else {
116- source .sendMessage (I18n . trans ("module-commandscheduler-schedule-list-script" ));
119+ source .sendMessage (this . i18n . translate ("module-commandscheduler-schedule-list-script" ));
117120 for (var command : commands ) {
118121 source .sendMessage (" - " + command );
119122 }
120123 }
121- source .sendMessage (I18n . trans ("module-commandscheduler-schedule-list-key-last-execution" , schedule .lastExecution ()));
124+ source .sendMessage (this . i18n . translate ("module-commandscheduler-schedule-list-key-last-execution" , schedule .lastExecution ()));
122125 if (nextExecution == null ) {
123- source .sendMessage (I18n . trans ("module-commandscheduler-schedule-list-key-next-execution-invalid" ));
126+ source .sendMessage (this . i18n . translate ("module-commandscheduler-schedule-list-key-next-execution-invalid" ));
124127 } else {
125- source .sendMessage (I18n . trans ("module-commandscheduler-schedule-list-key-next-execution" , nextExecution ));
128+ source .sendMessage (this . i18n . translate ("module-commandscheduler-schedule-list-key-next-execution" , nextExecution ));
126129 }
127- source .sendMessage (I18n . trans ("module-commandscheduler-schedule-list-element-separator" ));
130+ source .sendMessage (this . i18n . translate ("module-commandscheduler-schedule-list-element-separator" ));
128131 });
129132 }
130133
@@ -142,7 +145,7 @@ public void createSchedule(
142145 singleUse ,
143146 enabled );
144147 this .saveSchedule (source , schedule );
145- source .sendMessage (I18n . trans ("module-commandscheduler-schedule-created" , name ));
148+ source .sendMessage (this . i18n . translate ("module-commandscheduler-schedule-created" , name ));
146149 }
147150
148151 @ Command ("scheduler set <schedule> expression <expression>" )
@@ -152,13 +155,13 @@ public void setExpression(
152155 @ Argument ("expression" ) @ Quoted String expression
153156 ) {
154157 if (!Schedule .validateExpression (schedule , expression )) {
155- source .sendMessage (I18n . trans ("module-commandscheduler-expression-parse-error" , expression ));
158+ source .sendMessage (this . i18n . translate ("module-commandscheduler-expression-parse-error" , expression ));
156159 return ;
157160 }
158161
159162 schedule = schedule .withExpression (expression );
160163 this .saveSchedule (source , schedule );
161- source .sendMessage (I18n . trans ("module-commandscheduler-expression-set" , schedule .name (), expression ));
164+ source .sendMessage (this . i18n . translate ("module-commandscheduler-expression-set" , schedule .name (), expression ));
162165 }
163166
164167 @ Command ("scheduler set <schedule> singleUse <singleUse>" )
@@ -170,9 +173,9 @@ public void setSingleUse(
170173 schedule = schedule .withSingleUse (singleUse );
171174 this .saveSchedule (source , schedule );
172175 if (singleUse ) {
173- source .sendMessage (I18n . trans ("module-commandscheduler-single-use-set" , schedule .name ()));
176+ source .sendMessage (this . i18n . translate ("module-commandscheduler-single-use-set" , schedule .name ()));
174177 } else {
175- source .sendMessage (I18n . trans ("module-commandscheduler-single-use-unset" , schedule .name ()));
178+ source .sendMessage (this . i18n . translate ("module-commandscheduler-single-use-unset" , schedule .name ()));
176179 }
177180 }
178181
@@ -185,9 +188,9 @@ public void setEnabled(
185188 schedule = schedule .withEnabled (enabled );
186189 this .saveSchedule (source , schedule );
187190 if (enabled ) {
188- source .sendMessage (I18n . trans ("module-commandscheduler-enabled" , schedule .name ()));
191+ source .sendMessage (this . i18n . translate ("module-commandscheduler-enabled" , schedule .name ()));
189192 } else {
190- source .sendMessage (I18n . trans ("module-commandscheduler-disabled" , schedule .name ()));
193+ source .sendMessage (this . i18n . translate ("module-commandscheduler-disabled" , schedule .name ()));
191194 }
192195 }
193196
@@ -200,7 +203,7 @@ public void addCommand(
200203 var commands = schedule .commands ();
201204 commands .add (command );
202205 this .saveSchedule (source , schedule .withCommands (commands ));
203- source .sendMessage (I18n . trans ("module-commandscheduler-command-added" , command , schedule .name ()));
206+ source .sendMessage (this . i18n . translate ("module-commandscheduler-command-added" , command , schedule .name ()));
204207 }
205208
206209 @ Command ("scheduler command <schedule> insert <index> <command>" )
@@ -212,7 +215,7 @@ public void insertCommand(
212215 ) {
213216 var commands = schedule .commands ();
214217 if (index < 0 ) {
215- source .sendMessage (I18n . trans ("module-commandscheduler-index-negative-error" ));
218+ source .sendMessage (this . i18n . translate ("module-commandscheduler-index-negative-error" ));
216219 return ;
217220 }
218221 if (index <= commands .size ()) {
@@ -221,7 +224,7 @@ public void insertCommand(
221224 commands .add (command );
222225 }
223226 this .saveSchedule (source , schedule .withCommands (commands ));
224- source .sendMessage (I18n . trans ("module-commandscheduler-command-inserted" , command , index , schedule .name ()));
227+ source .sendMessage (this . i18n . translate ("module-commandscheduler-command-inserted" , command , index , schedule .name ()));
225228 }
226229
227230 @ Command ("scheduler command <schedule> remove <command>" )
@@ -235,30 +238,30 @@ public void removeCommand(
235238 if (command .primary ().isPresent ()) {
236239 int index = command .primary ().get ();
237240 if (index < 0 || index >= commands .size ()) {
238- source .sendMessage (I18n . trans ("module-commandscheduler-index-out-of-bounds-error" , index , schedule .name (), commands .size ()));
241+ source .sendMessage (this . i18n . translate ("module-commandscheduler-index-out-of-bounds-error" , index , schedule .name (), commands .size ()));
239242 return ;
240243 }
241244 removed = commands .remove (index );
242245 if (removed == null ) {
243- source .sendMessage (I18n . trans ("module-commandscheduler-command-remove-index-error" , index , schedule .name ()));
246+ source .sendMessage (this . i18n . translate ("module-commandscheduler-command-remove-index-error" , index , schedule .name ()));
244247 return ;
245248 } else {
246- source .sendMessage (I18n . trans ("module-commandscheduler-command-removed-index" , removed , index , schedule .name ()));
249+ source .sendMessage (this . i18n . translate ("module-commandscheduler-command-removed-index" , removed , index , schedule .name ()));
247250 }
248251 } else if (command .fallback ().isPresent ()) {
249252 final String commandString = command .fallback ().get ();
250253 if (!commands .remove (commandString )) {
251- source .sendMessage (I18n . trans ("module-commandscheduler-command-remove-error" , commandString , schedule .name ()));
254+ source .sendMessage (this . i18n . translate ("module-commandscheduler-command-remove-error" , commandString , schedule .name ()));
252255 return ;
253256 }
254257 removed = commandString ;
255258 } else {
256- source .sendMessage (I18n . trans ("module-commandscheduler-parameter-error" ));
259+ source .sendMessage (this . i18n . translate ("module-commandscheduler-parameter-error" ));
257260 return ;
258261 }
259262
260263 this .saveSchedule (source , schedule .withCommands (commands ));
261- source .sendMessage (I18n . trans ("module-commandscheduler-command-removed" , removed , schedule .name ()));
264+ source .sendMessage (this . i18n . translate ("module-commandscheduler-command-removed" , removed , schedule .name ()));
262265 }
263266
264267
@@ -271,9 +274,9 @@ public void renameSchedule(
271274 if (this .module .getDatabase ().delete (schedule .name ())) {
272275 schedule = schedule .withName (newName );
273276 this .saveSchedule (source , schedule );
274- source .sendMessage (I18n . trans ("module-commandscheduler-schedule-renamed" , oldName , newName ));
277+ source .sendMessage (this . i18n . translate ("module-commandscheduler-schedule-renamed" , oldName , newName ));
275278 } else {
276- source .sendMessage (I18n . trans ("module-commandscheduler-schedule-rename-error" , oldName ));
279+ source .sendMessage (this . i18n . translate ("module-commandscheduler-schedule-rename-error" , oldName ));
277280 }
278281 }
279282
@@ -283,24 +286,24 @@ public void deleteSchedule(
283286 @ Argument (value = "schedule" , parserName = "schedule" ) Schedule schedule
284287 ) {
285288 if (this .module .getDatabase ().delete (schedule .name ())) {
286- source .sendMessage (I18n . trans ("module-commandscheduler-schedule-deleted" , schedule .name ()));
289+ source .sendMessage (this . i18n . translate ("module-commandscheduler-schedule-deleted" , schedule .name ()));
287290 } else {
288- source .sendMessage (I18n . trans ("module-commandscheduler-schedule-delete-error" , schedule .name ()));
291+ source .sendMessage (this . i18n . translate ("module-commandscheduler-schedule-delete-error" , schedule .name ()));
289292 }
290293 }
291294
292295 private void saveSchedule (@ NotNull CommandSource source , Schedule schedule ) {
293296 if (this .module .getDatabase ().insert (schedule .name (), Document .newJsonDocument ().appendTree (schedule ))) {
294- source .sendMessage (I18n . trans ("module-commandscheduler-schedule-saved" , schedule .name ()));
297+ source .sendMessage (this . i18n . translate ("module-commandscheduler-schedule-saved" , schedule .name ()));
295298 } else {
296- source .sendMessage (I18n . trans ("module-commandscheduler-schedule-save-error" , schedule .name ()));
299+ source .sendMessage (this . i18n . translate ("module-commandscheduler-schedule-save-error" , schedule .name ()));
297300 }
298301 }
299302
300303 private @ Nullable Schedule loadSchedule (@ NotNull CommandSource source , String scheduleName ) {
301304 var document = this .module .getDatabase ().get (scheduleName );
302305 if (document == null ) {
303- source .sendMessage (I18n . trans ("module-commandscheduler-schedule-not-found" , scheduleName ));
306+ source .sendMessage (this . i18n . translate ("module-commandscheduler-schedule-not-found" , scheduleName ));
304307 return null ;
305308 }
306309
0 commit comments