|
@@ -72,88 +72,86 @@ public class ConditionalExecuteCommand extends Command {
|
72
|
72
|
final String arg = arguments[i].toLowerCase();
|
73
|
73
|
final String nextArg = i + 1 < arguments.length ? arguments[i + 1] : "";
|
74
|
74
|
|
75
|
|
- if (arg.equalsIgnoreCase("--help")) {
|
76
|
|
- sendLine(origin, args.isSilent(), FORMAT_OUTPUT, "Usage:");
|
77
|
|
- sendLine(origin, args.isSilent(), FORMAT_OUTPUT, "");
|
78
|
|
- sendLine(origin, args.isSilent(), FORMAT_OUTPUT, cmdname + " <args>");
|
79
|
|
- sendLine(origin, args.isSilent(), FORMAT_OUTPUT, cmdname
|
|
75
|
+ if ("--help".equalsIgnoreCase(arg)) {
|
|
76
|
+ showOutput(origin, args.isSilent(), "Usage:");
|
|
77
|
+ showOutput(origin, args.isSilent(), "");
|
|
78
|
+ showOutput(origin, args.isSilent(), cmdname + " <args>");
|
|
79
|
+ showOutput(origin, args.isSilent(), cmdname
|
80
|
80
|
+ " --namespace <name> <namespace commands>");
|
81
|
|
- sendLine(origin, args.isSilent(), FORMAT_OUTPUT, cmdname
|
|
81
|
+ showOutput(origin, args.isSilent(), cmdname
|
82
|
82
|
+ " --namespace <name> [--inverse] </commandToRun <command args>>");
|
83
|
|
- sendLine(origin, args.isSilent(), FORMAT_OUTPUT, "");
|
84
|
|
- sendLine(origin, args.isSilent(), FORMAT_OUTPUT,
|
|
83
|
+ showOutput(origin, args.isSilent(), "");
|
|
84
|
+ showOutput(origin, args.isSilent(),
|
85
|
85
|
"Commands can only be specified if no other non-namespace args are given.");
|
86
|
|
- sendLine(origin, args.isSilent(), FORMAT_OUTPUT, "");
|
87
|
|
- sendLine(origin, args.isSilent(), FORMAT_OUTPUT,
|
|
86
|
+ showOutput(origin, args.isSilent(), "");
|
|
87
|
+ showOutput(origin, args.isSilent(),
|
88
|
88
|
"When trying to run a command, the namespace will be checked to see if the command can be run.");
|
89
|
|
- sendLine(origin, args.isSilent(), FORMAT_OUTPUT,
|
|
89
|
+ showOutput(origin, args.isSilent(),
|
90
|
90
|
"The checks performed are as follows:");
|
91
|
|
- sendLine(origin, args.isSilent(), FORMAT_OUTPUT,
|
|
91
|
+ showOutput(origin, args.isSilent(),
|
92
|
92
|
" 1) Does the namespace exist? if not, run the command and create the namespace.");
|
93
|
|
- sendLine(origin, args.isSilent(), FORMAT_OUTPUT,
|
|
93
|
+ showOutput(origin, args.isSilent(),
|
94
|
94
|
" 2) Is the namespace inhibited? - Do not run the command.");
|
95
|
|
- sendLine(origin, args.isSilent(), FORMAT_OUTPUT,
|
|
95
|
+ showOutput(origin, args.isSilent(),
|
96
|
96
|
" 3) Is the namespace in forced mode? - Run the command.");
|
97
|
|
- sendLine(origin, args.isSilent(), FORMAT_OUTPUT,
|
|
97
|
+ showOutput(origin, args.isSilent(),
|
98
|
98
|
" 4) If --inverse is specified, are we under the limit time? Run the command");
|
99
|
|
- sendLine(origin, args.isSilent(), FORMAT_OUTPUT,
|
|
99
|
+ showOutput(origin, args.isSilent(),
|
100
|
100
|
" 5) If --inverse is not specified, are we over the limit time? Run the command");
|
101
|
|
- sendLine(origin, args.isSilent(), FORMAT_OUTPUT, " 6) Do not run the command.");
|
102
|
|
- sendLine(origin, args.isSilent(), FORMAT_OUTPUT, "");
|
103
|
|
- sendLine(origin, args.isSilent(), FORMAT_OUTPUT, "General Arguments.");
|
104
|
|
- sendLine(origin, args.isSilent(), FORMAT_OUTPUT,
|
|
101
|
+ showOutput(origin, args.isSilent(), " 6) Do not run the command.");
|
|
102
|
+ showOutput(origin, args.isSilent(), "");
|
|
103
|
+ showOutput(origin, args.isSilent(), "General Arguments.");
|
|
104
|
+ showOutput(origin, args.isSilent(),
|
105
|
105
|
" --list - List all current namespaces and their status");
|
106
|
|
- sendLine(origin, args.isSilent(), FORMAT_OUTPUT,
|
|
106
|
+ showOutput(origin, args.isSilent(),
|
107
|
107
|
" --help - Print this help.");
|
108
|
|
- sendLine(origin, args.isSilent(), FORMAT_OUTPUT,
|
|
108
|
+ showOutput(origin, args.isSilent(),
|
109
|
109
|
" --reset - Remove all namespaces.");
|
110
|
|
- sendLine(origin, args.isSilent(), FORMAT_OUTPUT, "");
|
111
|
|
- sendLine(origin, args.isSilent(), FORMAT_OUTPUT, "Useful things:");
|
112
|
|
- sendLine(origin, args.isSilent(), FORMAT_OUTPUT,
|
|
110
|
+ showOutput(origin, args.isSilent(), "");
|
|
111
|
+ showOutput(origin, args.isSilent(), "Useful things:");
|
|
112
|
+ showOutput(origin, args.isSilent(),
|
113
|
113
|
" --namespace <name> - Namespace to modify. If the namespace does not exist, it will be created. Namespaces are not remembered across sessions.");
|
114
|
|
- sendLine(origin, args.isSilent(), FORMAT_OUTPUT, "");
|
115
|
|
- sendLine(origin, args.isSilent(), FORMAT_OUTPUT, "Arguments related to a namespace:");
|
116
|
|
- sendLine(origin, args.isSilent(), FORMAT_OUTPUT,
|
|
114
|
+ showOutput(origin, args.isSilent(), "");
|
|
115
|
+ showOutput(origin, args.isSilent(), "Arguments related to a namespace:");
|
|
116
|
+ showOutput(origin, args.isSilent(),
|
117
|
117
|
" --settime <time> - Set the limit time on this namespace. Time can be either a time in seconds, 'now' for now, or 'nowifless' to set to now only if it is currently less.");
|
118
|
|
- sendLine(origin, args.isSilent(), FORMAT_OUTPUT,
|
|
118
|
+ showOutput(origin, args.isSilent(),
|
119
|
119
|
" --delay <seconds> - Increase the 'limit' time on this namespace by <seconds> seconds");
|
120
|
|
- sendLine(origin, args.isSilent(), FORMAT_OUTPUT,
|
|
120
|
+ showOutput(origin, args.isSilent(),
|
121
|
121
|
" --inhibit - Prevent any attempts at running commands in this namespace from executing");
|
122
|
|
- sendLine(origin, args.isSilent(), FORMAT_OUTPUT,
|
|
122
|
+ showOutput(origin, args.isSilent(),
|
123
|
123
|
" --force - Any future attempts at running commands in this namespace will always execute");
|
124
|
|
- sendLine(origin, args.isSilent(), FORMAT_OUTPUT,
|
|
124
|
+ showOutput(origin, args.isSilent(),
|
125
|
125
|
" --allow - Disable '--force' or '--inhibit' and resume normal operation.");
|
126
|
|
- sendLine(origin, args.isSilent(), FORMAT_OUTPUT,
|
|
126
|
+ showOutput(origin, args.isSilent(),
|
127
|
127
|
" --remove - Remove this namespace.");
|
128
|
|
- sendLine(origin, args.isSilent(), FORMAT_OUTPUT,
|
|
128
|
+ showOutput(origin, args.isSilent(),
|
129
|
129
|
" --status - Show the status of this namespace.");
|
130
|
|
- sendLine(origin, args.isSilent(), FORMAT_OUTPUT, "");
|
131
|
|
- sendLine(origin, args.isSilent(), FORMAT_OUTPUT, "Arguments when running a command:");
|
132
|
|
- sendLine(origin, args.isSilent(), FORMAT_OUTPUT,
|
|
130
|
+ showOutput(origin, args.isSilent(), "");
|
|
131
|
+ showOutput(origin, args.isSilent(), "Arguments when running a command:");
|
|
132
|
+ showOutput(origin, args.isSilent(),
|
133
|
133
|
" --inverse - Inverse the match against the 'limit' time.");
|
134
|
134
|
return;
|
135
|
|
- } else if (arg.equalsIgnoreCase("--list")) {
|
|
135
|
+ } else if ("--list".equalsIgnoreCase(arg)) {
|
136
|
136
|
if (namespaces.isEmpty()) {
|
137
|
|
- sendLine(origin, args.isSilent(), FORMAT_OUTPUT,
|
|
137
|
+ showOutput(origin, args.isSilent(),
|
138
|
138
|
"There are currently no known namespaces.");
|
139
|
139
|
} else {
|
140
|
|
- sendLine(origin, args.isSilent(), FORMAT_OUTPUT, "Current namespaces: ");
|
|
140
|
+ showOutput(origin, args.isSilent(), "Current namespaces: ");
|
141
|
141
|
for (final Map.Entry<String, ConditionalExecuteNamespace> e : namespaces.
|
142
|
142
|
entrySet()) {
|
143
|
|
- sendLine(origin, args.isSilent(), FORMAT_OUTPUT, " " + e.getValue().
|
144
|
|
- toString());
|
|
143
|
+ showOutput(origin, args.isSilent()," " + e.getValue());
|
145
|
144
|
}
|
146
|
145
|
}
|
147
|
146
|
return;
|
148
|
|
- } else if (arg.equalsIgnoreCase("--reset")) {
|
|
147
|
+ } else if ("--reset".equalsIgnoreCase(arg)) {
|
149
|
148
|
namespaces.clear();
|
150
|
|
- sendLine(origin, args.isSilent(), FORMAT_OUTPUT, "All namespaces removed.");
|
|
149
|
+ showOutput(origin, args.isSilent(), "All namespaces removed.");
|
151
|
150
|
return;
|
152
|
151
|
} else if (namespace == null) {
|
153
|
|
- if (arg.equalsIgnoreCase("--namespace")) {
|
|
152
|
+ if ("--namespace".equalsIgnoreCase(arg)) {
|
154
|
153
|
if (nextArg.isEmpty()) {
|
155
|
|
- sendLine(origin, args.isSilent(), FORMAT_ERROR,
|
156
|
|
- "Error: You must specify a namespace.");
|
|
154
|
+ showError(origin, args.isSilent(), "Error: You must specify a namespace.");
|
157
|
155
|
return;
|
158
|
156
|
} else {
|
159
|
157
|
if (!namespaces.containsKey(nextArg.toLowerCase())) {
|
|
@@ -166,29 +164,28 @@ public class ConditionalExecuteCommand extends Command {
|
166
|
164
|
i++;
|
167
|
165
|
}
|
168
|
166
|
} else {
|
169
|
|
- sendLine(origin, args.isSilent(), FORMAT_ERROR,
|
|
167
|
+ showError(origin, args.isSilent(),
|
170
|
168
|
"Error: You must specify a namespace first.");
|
171
|
169
|
return;
|
172
|
170
|
}
|
173
|
|
- } else if (arg.equalsIgnoreCase("--inhibit")) {
|
|
171
|
+ } else if ("--inhibit".equalsIgnoreCase(arg)) {
|
174
|
172
|
namespace.inhibit();
|
175
|
173
|
manipulated = true;
|
176
|
|
- } else if (arg.equalsIgnoreCase("--force")) {
|
|
174
|
+ } else if ("--force".equalsIgnoreCase(arg)) {
|
177
|
175
|
namespace.force();
|
178
|
176
|
manipulated = true;
|
179
|
|
- } else if (arg.equalsIgnoreCase("--allow")) {
|
|
177
|
+ } else if ("--allow".equalsIgnoreCase(arg)) {
|
180
|
178
|
namespace.reset();
|
181
|
179
|
manipulated = true;
|
182
|
|
- } else if (arg.equalsIgnoreCase("--settime")) {
|
|
180
|
+ } else if ("--settime".equalsIgnoreCase(arg)) {
|
183
|
181
|
if (nextArg.isEmpty()) {
|
184
|
|
- sendLine(origin, args.isSilent(), FORMAT_ERROR,
|
185
|
|
- "Error: You must provide a time to use.");
|
|
182
|
+ showError(origin, args.isSilent(), "Error: You must provide a time to use.");
|
186
|
183
|
return;
|
187
|
|
- } else if (nextArg.equalsIgnoreCase("now")) {
|
|
184
|
+ } else if ("now".equalsIgnoreCase(nextArg)) {
|
188
|
185
|
namespace.setLimit(System.currentTimeMillis());
|
189
|
186
|
i++;
|
190
|
187
|
manipulated = true;
|
191
|
|
- } else if (nextArg.equalsIgnoreCase("nowifless")) {
|
|
188
|
+ } else if ("nowifless".equalsIgnoreCase(nextArg)) {
|
192
|
189
|
if (namespace.getLimitTime() < System.currentTimeMillis()) {
|
193
|
190
|
namespace.setLimit(System.currentTimeMillis());
|
194
|
191
|
}
|
|
@@ -200,15 +197,13 @@ public class ConditionalExecuteCommand extends Command {
|
200
|
197
|
i++;
|
201
|
198
|
manipulated = true;
|
202
|
199
|
} catch (final NumberFormatException nfe) {
|
203
|
|
- sendLine(origin, args.isSilent(), FORMAT_ERROR, "Error: Invalid time: "
|
204
|
|
- + nextArg);
|
|
200
|
+ showError(origin, args.isSilent(), "Error: Invalid time: " + nextArg);
|
205
|
201
|
return;
|
206
|
202
|
}
|
207
|
203
|
}
|
208
|
|
- } else if (arg.equalsIgnoreCase("--delay")) {
|
|
204
|
+ } else if ("--delay".equalsIgnoreCase(arg)) {
|
209
|
205
|
if (nextArg.isEmpty()) {
|
210
|
|
- sendLine(origin, args.isSilent(), FORMAT_ERROR,
|
211
|
|
- "Error: You must provide a delay to use.");
|
|
206
|
+ showError(origin, args.isSilent(), "Error: You must provide a delay to use.");
|
212
|
207
|
return;
|
213
|
208
|
} else {
|
214
|
209
|
try {
|
|
@@ -216,24 +211,23 @@ public class ConditionalExecuteCommand extends Command {
|
216
|
211
|
i++;
|
217
|
212
|
manipulated = true;
|
218
|
213
|
} catch (final NumberFormatException nfe) {
|
219
|
|
- sendLine(origin, args.isSilent(), FORMAT_ERROR, "Error: Invalid delay: "
|
220
|
|
- + nextArg);
|
|
214
|
+ showError(origin, args.isSilent(), "Error: Invalid delay: " + nextArg);
|
221
|
215
|
return;
|
222
|
216
|
}
|
223
|
217
|
}
|
224
|
|
- } else if (arg.equalsIgnoreCase("--remove")) {
|
|
218
|
+ } else if ("--remove".equalsIgnoreCase(arg)) {
|
225
|
219
|
namespaces.remove(namespace.getName());
|
226
|
|
- sendLine(origin, args.isSilent(), FORMAT_OUTPUT, "Removed namespace '" + namespace.
|
227
|
|
- getName() + "'");
|
|
220
|
+ showOutput(origin, args.isSilent(),
|
|
221
|
+ "Removed namespace '" + namespace.getName() + '\'');
|
228
|
222
|
return;
|
229
|
|
- } else if (arg.equalsIgnoreCase("--status")) {
|
|
223
|
+ } else if ("--status".equalsIgnoreCase(arg)) {
|
230
|
224
|
// Show the current status, in case some manipulations occurred prior to this.
|
231
|
|
- sendLine(origin, args.isSilent(), FORMAT_OUTPUT, namespaces.get(namespace.getName()));
|
|
225
|
+ showOutput(origin, args.isSilent(), namespaces.get(namespace.getName()).toString());
|
232
|
226
|
return;
|
233
|
|
- } else if (arg.equalsIgnoreCase("--inverse")) {
|
|
227
|
+ } else if ("--inverse".equalsIgnoreCase(arg)) {
|
234
|
228
|
inverse = true;
|
235
|
229
|
} else if (manipulated) {
|
236
|
|
- sendLine(origin, args.isSilent(), FORMAT_ERROR,
|
|
230
|
+ showError(origin, args.isSilent(),
|
237
|
231
|
"You can't run commands and manipulate the namespace at the same time, ignored.");
|
238
|
232
|
} else {
|
239
|
233
|
// Command to run!
|
|
@@ -246,19 +240,19 @@ public class ConditionalExecuteCommand extends Command {
|
246
|
240
|
|
247
|
241
|
// If we get here, we either manipulated something, or should show the usage text.
|
248
|
242
|
if (manipulated) {
|
249
|
|
- sendLine(origin, args.isSilent(), FORMAT_OUTPUT, "Namespace updated.");
|
250
|
|
- sendLine(origin, args.isSilent(), FORMAT_OUTPUT, namespace.toString());
|
|
243
|
+ showOutput(origin, args.isSilent(), "Namespace updated.");
|
|
244
|
+ showOutput(origin, args.isSilent(), namespace.toString());
|
251
|
245
|
namespaces.put(namespace.getName(), namespace);
|
252
|
246
|
} else {
|
253
|
|
- sendLine(origin, args.isSilent(), FORMAT_ERROR, "Usage:");
|
254
|
|
- sendLine(origin, args.isSilent(), FORMAT_ERROR, "");
|
255
|
|
- sendLine(origin, args.isSilent(), FORMAT_ERROR, cmdname + " <args>");
|
256
|
|
- sendLine(origin, args.isSilent(), FORMAT_ERROR, cmdname
|
|
247
|
+ showError(origin, args.isSilent(), "Usage:");
|
|
248
|
+ showError(origin, args.isSilent(), "");
|
|
249
|
+ showError(origin, args.isSilent(), cmdname + " <args>");
|
|
250
|
+ showError(origin, args.isSilent(), cmdname
|
257
|
251
|
+ " --namespace <name> <namespace commands>");
|
258
|
|
- sendLine(origin, args.isSilent(), FORMAT_ERROR, cmdname
|
|
252
|
+ showError(origin, args.isSilent(), cmdname
|
259
|
253
|
+ " --namespace <name> [--inverse] </commandToRun <command args>>");
|
260
|
|
- sendLine(origin, args.isSilent(), FORMAT_ERROR, "");
|
261
|
|
- sendLine(origin, args.isSilent(), FORMAT_ERROR, "For more information, see " + cmdname
|
|
254
|
+ showError(origin, args.isSilent(), "");
|
|
255
|
+ showError(origin, args.isSilent(), "For more information, see " + cmdname
|
262
|
256
|
+ " --help");
|
263
|
257
|
}
|
264
|
258
|
}
|