2828import com .google .common .collect .Maps ;
2929import com .google .common .collect .Sets ;
3030import com .google .inject .Inject ;
31+ import com .helion3 .prism .api .data .PrismEvent ;
3132import com .helion3 .prism .api .filters .FilterList ;
3233import com .helion3 .prism .api .filters .FilterMode ;
3334import com .helion3 .prism .api .flags .FlagClean ;
4445import com .helion3 .prism .api .parameters .ParameterRadius ;
4546import com .helion3 .prism .api .parameters .ParameterTime ;
4647import com .helion3 .prism .api .records .ActionableResult ;
47- import com .helion3 .prism .api .records .BlockResult ;
48- import com .helion3 .prism .api .records .EntityResult ;
49- import com .helion3 .prism .api .records .Result ;
5048import com .helion3 .prism .api .storage .StorageAdapter ;
5149import com .helion3 .prism .commands .PrismCommands ;
5250import com .helion3 .prism .listeners .ChangeBlockListener ;
53- import com .helion3 .prism .listeners .ChangeInventoryListener ;
54- import com .helion3 .prism .listeners .DeathListener ;
55- import com .helion3 .prism .listeners .DropItemListener ;
56- import com .helion3 .prism .listeners .JoinListener ;
57- import com .helion3 .prism .listeners .QuitListener ;
51+ import com .helion3 .prism .listeners .EntityListener ;
52+ import com .helion3 .prism .listeners .InventoryListener ;
5853import com .helion3 .prism .listeners .RequiredInteractListener ;
5954import com .helion3 .prism .queues .RecordingQueueManager ;
6055import com .helion3 .prism .storage .h2 .H2StorageAdapter ;
6156import com .helion3 .prism .storage .mongodb .MongoStorageAdapter ;
6257import com .helion3 .prism .storage .mysql .MySQLStorageAdapter ;
58+ import com .helion3 .prism .util .PrismEvents ;
6359import com .helion3 .prism .util .Reference ;
6460import ninja .leaping .configurate .commented .CommentedConfigurationNode ;
6561import ninja .leaping .configurate .loader .ConfigurationLoader ;
@@ -125,7 +121,7 @@ public final class Prism {
125121 private final Set <FlagHandler > flagHandlers = Sets .newHashSet ();
126122 private final Map <UUID , List <ActionableResult >> lastActionResults = Maps .newHashMap ();
127123 private final Set <ParameterHandler > parameterHandlers = Sets .newHashSet ();
128- private final Map < String , Class <? extends Result >> resultRecords = Maps . newHashMap ();
124+ private final Set < PrismEvent > prismEvents = Sets . newHashSet ();
129125
130126 @ Listener
131127 public void onConstruction (GameConstructionEvent event ) {
@@ -155,38 +151,29 @@ public void onInitialization(GameInitializationEvent event) {
155151 registerParameterHandler (new ParameterRadius ());
156152 registerParameterHandler (new ParameterTime ());
157153
158- // Register ResultRecords
159- registerResultRecord ("break" , BlockResult .class );
160- registerResultRecord ("decay" , BlockResult .class );
161- registerResultRecord ("grow" , BlockResult .class );
162- registerResultRecord ("place" , BlockResult .class );
163- registerResultRecord ("death" , EntityResult .class );
154+ // Register PrismEvents
155+ registerPrismEvent (PrismEvents .BLOCK_BREAK );
156+ registerPrismEvent (PrismEvents .BLOCK_DECAY );
157+ registerPrismEvent (PrismEvents .BLOCK_GROW );
158+ registerPrismEvent (PrismEvents .BLOCK_PLACE );
159+ registerPrismEvent (PrismEvents .ENTITY_DEATH );
160+ registerPrismEvent (PrismEvents .COMMAND_EXECUTE );
161+ registerPrismEvent (PrismEvents .INVENTORY_CLOSE );
162+ registerPrismEvent (PrismEvents .INVENTORY_OPEN );
163+ registerPrismEvent (PrismEvents .ITEM_DROP );
164+ registerPrismEvent (PrismEvents .ITEM_INSERT );
165+ registerPrismEvent (PrismEvents .ITEM_PICKUP );
166+ registerPrismEvent (PrismEvents .ITEM_REMOVE );
167+ registerPrismEvent (PrismEvents .PLAYER_DISCONNECT );
168+ registerPrismEvent (PrismEvents .PLAYER_JOIN );
164169
165170 // Register Commands
166171 Sponge .getCommandManager ().register (this , PrismCommands .getCommand (), Reference .ID , "pr" );
167172
168173 // Register Listeners
169174 Sponge .getEventManager ().registerListeners (getPluginContainer (), new ChangeBlockListener ());
170-
171- if (getListening ().DEATH ) {
172- Sponge .getEventManager ().registerListeners (getPluginContainer (), new DeathListener ());
173- }
174-
175- if (getListening ().DROP ) {
176- Sponge .getEventManager ().registerListeners (getPluginContainer (), new DropItemListener ());
177- }
178-
179- if (getListening ().JOIN ) {
180- Sponge .getEventManager ().registerListeners (getPluginContainer (), new JoinListener ());
181- }
182-
183- if (getListening ().PICKUP ) {
184- Sponge .getEventManager ().registerListeners (getPluginContainer (), new ChangeInventoryListener ());
185- }
186-
187- if (getListening ().QUIT ) {
188- Sponge .getEventManager ().registerListeners (getPluginContainer (), new QuitListener ());
189- }
175+ Sponge .getEventManager ().registerListeners (getPluginContainer (), new EntityListener ());
176+ Sponge .getEventManager ().registerListeners (getPluginContainer (), new InventoryListener ());
190177
191178 // Events required for internal operation
192179 Sponge .getEventManager ().registerListeners (getPluginContainer (), new RequiredInteractListener ());
@@ -210,7 +197,7 @@ public void onStartedServer(GameStartedServerEvent event) {
210197 throw new Exception ("Invalid storage engine configured." );
211198 }
212199
213- Preconditions .checkArgument (getStorageAdapter ().connect ());
200+ Preconditions .checkState (getStorageAdapter ().connect ());
214201
215202 // Initialize the recording queue manager
216203 Task .builder ()
@@ -354,34 +341,31 @@ public boolean registerParameterHandler(ParameterHandler parameterHandler) {
354341 }
355342
356343 /**
357- * Returns all currently registered result records .
344+ * Returns all currently registered prism events .
358345 *
359- * @return Map of event names to their {@link Result} class
346+ * @return List of {@link PrismEvent}
360347 */
361- private Map < String , Class <? extends Result >> getResultRecords () {
362- return resultRecords ;
348+ public Set < PrismEvent > getPrismEvents () {
349+ return prismEvents ;
363350 }
364351
365- /**
366- * Returns the result record class for a given event
367- *
368- * @param event event name
369- * @return {@link Result} Record class, or null if unsupported
370- */
371- public Class <? extends Result > getResultRecord ( String event ) {
372- return getResultRecords (). get ( event );
352+ public Optional < PrismEvent > getPrismEvent ( String id ) {
353+ for ( PrismEvent prismEvent : getPrismEvents ()) {
354+ if ( StringUtils . equals ( prismEvent . getId (), id )) {
355+ return Optional . of ( prismEvent );
356+ }
357+ }
358+
359+ return Optional . empty ( );
373360 }
374361
375362 /**
376- * Register a custom result record for a given event name .
363+ * Register a prism event.
377364 *
378- * @param event {@link String} event name
379- * @param resultRecord {@link Result} Record class
380- * @return True if the {@link Result} Record class was registered
365+ * @param prismEvent
381366 */
382- public boolean registerResultRecord (String event , Class <? extends Result > resultRecord ) {
383- Preconditions .checkNotNull (event );
384- Preconditions .checkNotNull (resultRecord );
385- return getResultRecords ().putIfAbsent (event , resultRecord ) == null ;
367+ public boolean registerPrismEvent (PrismEvent prismEvent ) {
368+ Preconditions .checkNotNull (prismEvent );
369+ return getPrismEvents ().add (prismEvent );
386370 }
387371}
0 commit comments