|
@@ -22,7 +22,6 @@
|
22
|
22
|
|
23
|
23
|
package com.dmdirc.actions.wrappers;
|
24
|
24
|
|
25
|
|
-import com.dmdirc.DMDircMBassador;
|
26
|
25
|
import com.dmdirc.actions.Action;
|
27
|
26
|
import com.dmdirc.actions.ActionComponentChain;
|
28
|
27
|
import com.dmdirc.actions.ActionCondition;
|
|
@@ -33,11 +32,11 @@ import com.dmdirc.actions.ConditionTree;
|
33
|
32
|
import com.dmdirc.actions.CoreActionComparison;
|
34
|
33
|
import com.dmdirc.actions.CoreActionComponent;
|
35
|
34
|
import com.dmdirc.actions.CoreActionType;
|
36
|
|
-import com.dmdirc.events.UserErrorEvent;
|
|
35
|
+import com.dmdirc.commandparser.auto.AutoCommand;
|
|
36
|
+import com.dmdirc.commandparser.auto.AutoCommandManager;
|
37
|
37
|
import com.dmdirc.interfaces.Connection;
|
38
|
38
|
import com.dmdirc.interfaces.actions.ActionComponent;
|
39
|
39
|
import com.dmdirc.interfaces.actions.ActionType;
|
40
|
|
-import com.dmdirc.logger.ErrorLevel;
|
41
|
40
|
|
42
|
41
|
import java.util.ArrayList;
|
43
|
42
|
import java.util.List;
|
|
@@ -47,61 +46,28 @@ import javax.inject.Singleton;
|
47
|
46
|
|
48
|
47
|
/**
|
49
|
48
|
* An action wrapper for performs.
|
|
49
|
+ *
|
|
50
|
+ * @deprecated Use {@link AutoCommandManager}
|
50
|
51
|
*/
|
51
|
52
|
@Singleton
|
|
53
|
+@Deprecated
|
52
|
54
|
public class PerformWrapper extends ActionGroup {
|
53
|
55
|
|
54
|
56
|
/** The component name for per-profile perform conditions. */
|
55
|
57
|
private static final String PP_COMP_NAME = "SERVER_PROFILE.IDENTITY_NAME";
|
56
|
58
|
/** Factory to use for actions. */
|
57
|
59
|
private final ActionFactory actionFactory;
|
58
|
|
- /** The event bus to post events to. */
|
59
|
|
- private final DMDircMBassador eventBus;
|
60
|
60
|
|
61
|
61
|
/**
|
62
|
62
|
* Creates a new instance of PerformWrapper.
|
63
|
63
|
*
|
64
|
64
|
* @param actionFactory Factory to use to create actions.
|
65
|
|
- * @param eventBus The event bus to post events to.
|
66
|
65
|
*/
|
67
|
66
|
@Inject
|
68
|
|
- public PerformWrapper(final ActionFactory actionFactory,
|
69
|
|
- final DMDircMBassador eventBus) {
|
|
67
|
+ public PerformWrapper(final ActionFactory actionFactory) {
|
70
|
68
|
super("performs");
|
71
|
69
|
|
72
|
70
|
this.actionFactory = actionFactory;
|
73
|
|
- this.eventBus = eventBus;
|
74
|
|
- }
|
75
|
|
-
|
76
|
|
- @Override
|
77
|
|
- public void add(final Action action) {
|
78
|
|
- if (action.getTriggers().length != 1) {
|
79
|
|
- eventBus.publishAsync(new UserErrorEvent(ErrorLevel.MEDIUM, null,
|
80
|
|
- "Invalid perform action: " + action.getName(),
|
81
|
|
- "Perform actions may only have one trigger"));
|
82
|
|
- } else if (action.getTriggers()[0] != CoreActionType.SERVER_CONNECTED) {
|
83
|
|
- eventBus.publishAsync(new UserErrorEvent(ErrorLevel.MEDIUM, null,
|
84
|
|
- "Invalid perform action: " + action.getName(),
|
85
|
|
- "Perform actions must be triggered when a server connects"));
|
86
|
|
- } else if (!checkConditions(action.getConditions())) {
|
87
|
|
- eventBus.publishAsync(new UserErrorEvent(ErrorLevel.MEDIUM, null,
|
88
|
|
- "Invalid perform action: " + action.getName(),
|
89
|
|
- "Perform actions must have exactly one or two conditions, "
|
90
|
|
- + "one may target the server's name or network, and one may "
|
91
|
|
- + "target the server's profile name. No other targets are "
|
92
|
|
- + "allowed."));
|
93
|
|
- } else {
|
94
|
|
- synchronized (this) {
|
95
|
|
- super.add(action);
|
96
|
|
- }
|
97
|
|
- }
|
98
|
|
- }
|
99
|
|
-
|
100
|
|
- @Override
|
101
|
|
- public void deleteAction(final Action action) {
|
102
|
|
- synchronized (this) {
|
103
|
|
- super.deleteAction(action);
|
104
|
|
- }
|
105
|
71
|
}
|
106
|
72
|
|
107
|
73
|
/**
|
|
@@ -187,35 +153,6 @@ public class PerformWrapper extends ActionGroup {
|
187
|
153
|
return true;
|
188
|
154
|
}
|
189
|
155
|
|
190
|
|
- /**
|
191
|
|
- * Checks that the specified conditions are valid for a perform action.
|
192
|
|
- *
|
193
|
|
- * @param conditions The conditions to be checked
|
194
|
|
- *
|
195
|
|
- * @since 0.6.3m2
|
196
|
|
- * @return True if the conditions are valid, false otherwise
|
197
|
|
- */
|
198
|
|
- protected boolean checkConditions(final Iterable<ActionCondition> conditions) {
|
199
|
|
- boolean target = false;
|
200
|
|
- boolean profile = false;
|
201
|
|
-
|
202
|
|
- for (ActionCondition condition : conditions) {
|
203
|
|
- if ((condition.getComponent() == CoreActionComponent.SERVER_NETWORK
|
204
|
|
- || condition.getComponent() == CoreActionComponent.SERVER_NAME)
|
205
|
|
- && !target) {
|
206
|
|
- target = true;
|
207
|
|
- } else if (condition.getComponent() instanceof ActionComponentChain
|
208
|
|
- && PP_COMP_NAME.equals(condition.getComponent().toString())
|
209
|
|
- && !profile) {
|
210
|
|
- profile = true;
|
211
|
|
- } else {
|
212
|
|
- return false;
|
213
|
|
- }
|
214
|
|
- }
|
215
|
|
-
|
216
|
|
- return target || profile;
|
217
|
|
- }
|
218
|
|
-
|
219
|
156
|
/**
|
220
|
157
|
* Creates a new, empty, perform wrapper for the specified server or network. Note that both
|
221
|
158
|
* server and network must be specified, and exactly one of them must be empty.
|
|
@@ -304,7 +241,9 @@ public class PerformWrapper extends ActionGroup {
|
304
|
241
|
* Describes one specific perform.
|
305
|
242
|
*
|
306
|
243
|
* @since 0.6.4
|
|
244
|
+ * @deprecated See {@link AutoCommand}
|
307
|
245
|
*/
|
|
246
|
+ @Deprecated
|
308
|
247
|
public static class PerformDescription {
|
309
|
248
|
|
310
|
249
|
/** The type of the perform being described. */
|