|
10 | 10 | import com.laytonsmith.core.constructs.Target;
|
11 | 11 | import com.laytonsmith.core.events.BoundEvent.Priority;
|
12 | 12 | import com.laytonsmith.core.exceptions.CRE.CREBindException;
|
| 13 | +import com.laytonsmith.core.exceptions.CRE.CRECastException; |
13 | 14 | import com.laytonsmith.core.exceptions.CRE.CREEventException;
|
| 15 | +import com.laytonsmith.core.exceptions.CRE.CREIllegalArgumentException; |
14 | 16 | import com.laytonsmith.core.extensions.Extension;
|
15 | 17 | import com.laytonsmith.core.extensions.ExtensionManager;
|
16 | 18 | import com.laytonsmith.core.extensions.ExtensionTracker;
|
@@ -140,42 +142,44 @@ public static SortedSet<BoundEvent> GetEvents(Driver type) {
|
140 | 142 | }
|
141 | 143 |
|
142 | 144 | public static void ManualTrigger(String eventName, CArray object, Target t, boolean serverWide) {
|
143 |
| - for(Driver type : event_handles.keySet()) { |
| 145 | + // Get the event |
| 146 | + Event event = EventList.getEvent(eventName); |
| 147 | + if(event == null) { |
| 148 | + // Abort if event is not existing |
| 149 | + throw new CREIllegalArgumentException("Non existant event is being triggered: " + eventName, t); |
| 150 | + } |
| 151 | + |
| 152 | + BindableEvent convertedEvent = null; |
| 153 | + try { |
| 154 | + // Either an exception will be thrown, or null returned |
| 155 | + convertedEvent = event.convert(object, t); |
| 156 | + } catch(UnsupportedOperationException ex) { |
| 157 | + } |
| 158 | + if(convertedEvent == null) { |
| 159 | + throw new CREBindException(eventName + " doesn't support the use of trigger() yet.", t); |
| 160 | + } |
| 161 | + |
| 162 | + // By Javadoc, if supportsExternal() false there is no use to call it serverwide |
| 163 | + if(serverWide && event.supportsExternal()) { |
| 164 | + event.manualTrigger(convertedEvent); |
| 165 | + } else { |
144 | 166 | SortedSet<BoundEvent> toRun = new TreeSet<>();
|
145 |
| - SortedSet<BoundEvent> bounded = GetEvents(type); |
146 |
| - Event driver = EventList.getEvent(type, eventName); |
147 |
| - if(bounded != null) { |
148 |
| - for(BoundEvent b : bounded) { |
149 |
| - if(b.getEventName().equalsIgnoreCase(eventName)) { |
| 167 | + for(Driver type : event_handles.keySet()) { |
| 168 | + for(BoundEvent boundEvent: GetEvents(type)) { |
| 169 | + if(boundEvent.getEventName().equalsIgnoreCase(eventName)) { |
150 | 170 | try {
|
151 |
| - BindableEvent convertedEvent = null; |
152 |
| - try { |
153 |
| - convertedEvent = driver.convert(object, t); |
154 |
| - } catch(UnsupportedOperationException ex) { |
155 |
| - // The event will stay null, and be caught below |
156 |
| - } |
157 |
| - if(convertedEvent == null) { |
158 |
| - throw new CREBindException(eventName + " doesn't support the use of trigger() yet.", t); |
159 |
| - } else if(driver.matches(b.getPrefilter(), convertedEvent)) { |
160 |
| - toRun.add(b); |
| 171 | + if(event.matches(boundEvent.getPrefilter(), convertedEvent)) { |
| 172 | + toRun.add(boundEvent); |
161 | 173 | }
|
162 | 174 | } catch(PrefilterNonMatchException ex) {
|
163 | 175 | //Not running this one
|
164 | 176 | }
|
165 | 177 | }
|
166 | 178 | }
|
167 | 179 | }
|
168 |
| - //If it's not a serverwide event, or this event doesn't support external events. |
| 180 | + |
169 | 181 | if(!toRun.isEmpty()) {
|
170 |
| - if(!serverWide || !driver.supportsExternal()) { |
171 |
| - FireListeners(toRun, driver, driver.convert(object, t)); |
172 |
| - } else { |
173 |
| - //It's serverwide, so we can just trigger it normally with the driver, and it should trickle back down to us |
174 |
| - driver.manualTrigger(driver.convert(object, t)); |
175 |
| - } |
176 |
| - } else { |
177 |
| - //They have fired a non existant event |
178 |
| - ConfigRuntimeException.DoWarning(ConfigRuntimeException.CreateUncatchableException("Non existant event is being triggered: " + eventName, object.getTarget())); |
| 182 | + FireListeners(toRun, event, convertedEvent); |
179 | 183 | }
|
180 | 184 | }
|
181 | 185 | }
|
|
0 commit comments