Advertisement
Guest User

Main Class

a guest
Jan 2nd, 2016
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.36 KB | None | 0 0
  1. package com.feeliiix.fundamental.plugin;
  2.  
  3. import com.feeliiix.fundamental.api.Fundamental;
  4. import com.feeliiix.fundamental.api.configuration.hocon.HoconConfiguration;
  5. import com.feeliiix.fundamental.api.message.style.MessageStyle;
  6. import com.feeliiix.fundamental.api.message.style.MessageStyles;
  7. import com.feeliiix.fundamental.plugin.configuration.MainConfiguration;
  8. import com.feeliiix.fundamental.plugin.registry.MessageStyleRegistryModule;
  9. import com.google.inject.Inject;
  10. import org.slf4j.Logger;
  11. import org.spongepowered.api.Sponge;
  12. import org.spongepowered.api.config.ConfigDir;
  13. import org.spongepowered.api.event.Listener;
  14. import org.spongepowered.api.event.game.state.GameInitializationEvent;
  15. import org.spongepowered.api.event.game.state.GamePreInitializationEvent;
  16. import org.spongepowered.api.event.game.state.GameStartedServerEvent;
  17. import org.spongepowered.api.plugin.Plugin;
  18.  
  19. import java.nio.file.Path;
  20.  
  21. @Plugin(name = "Fundamentals", id = "Fundamentals", version = "0.1-SNAPSHOT")
  22. public final class FundamentalPlugin implements Fundamental {
  23.  
  24.     private static Fundamental INSTANCE;
  25.  
  26.     @Inject private Logger logger;
  27.     @Inject @ConfigDir(sharedRoot = false) private Path configDirectory;
  28.  
  29.     private HoconConfiguration mainConfiguration;
  30.  
  31.     @Listener
  32.     public void onPreInitialization(GamePreInitializationEvent event) {
  33.         INSTANCE = this;
  34.         Sponge.getRegistry().registerModule(MessageStyle.class, new MessageStyleRegistryModule());
  35.     }
  36.  
  37.     @Listener
  38.     public void onInitialization(GameInitializationEvent event) {
  39.         this.mainConfiguration = new MainConfiguration(this.configDirectory.resolve("config.conf"));
  40.     }
  41.  
  42.     @Listener
  43.     public void onStarted(GameStartedServerEvent event) {
  44.         StringBuilder stringBuilder = new StringBuilder("MessageStyles: ");
  45.         Sponge.getRegistry().getAllOf(MessageStyle.class).forEach(messageStyle -> stringBuilder.append(messageStyle.getName() + ", "));
  46.         this.logger.info(stringBuilder.toString().substring(0, stringBuilder.toString().length() -1));
  47.     }
  48.  
  49.     public static Fundamental getInstance() {
  50.         return INSTANCE;
  51.     }
  52.  
  53.     @Override
  54.     public Logger getLogger() {
  55.         return this.logger;
  56.     }
  57.  
  58.     public Path getConfigDirectory() {
  59.         return this.configDirectory;
  60.     }
  61.  
  62.     @Override
  63.     public HoconConfiguration getMainConfiguration() {
  64.         return this.mainConfiguration;
  65.     }
  66.  
  67. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement