Advertisement
Drawethree

UltraBombs - Main

Sep 23rd, 2022
718
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 3.67 KB | None | 0 0
  1. package dev.drawethree.ultrabombs;
  2.  
  3. import com.github.lalyos.jfiglet.FigletFont;
  4. import dev.drawethree.ultrabombs.api.impl.UltraBombsBackendAPI;
  5. import dev.drawethree.ultrabombs.api.service.BackendAPI;
  6. import dev.drawethree.ultrabombs.commands.UltraBombsCommand;
  7. import dev.drawethree.ultrabombs.config.UltraBombsConfig;
  8. import dev.drawethree.ultrabombs.listener.UltraBombsListener;
  9. import dev.drawethree.ultrabombs.service.UltraBombsService;
  10. import lombok.Getter;
  11. import net.milkbowl.vault.economy.Economy;
  12. import org.bstats.bukkit.Metrics;
  13. import org.bukkit.Bukkit;
  14. import org.bukkit.plugin.RegisteredServiceProvider;
  15. import org.bukkit.plugin.java.JavaPlugin;
  16. import org.codemc.worldguardwrapper.WorldGuardWrapper;
  17. import org.codemc.worldguardwrapper.flag.WrappedState;
  18.  
  19. import java.io.IOException;
  20.  
  21. import static dev.drawethree.ultrabombs.utils.UltraBombsConstants.METRICS_ID;
  22. import static dev.drawethree.ultrabombs.utils.UltraBombsConstants.WG_FLAG_NAME;
  23.  
  24. public final class UltraBombs extends JavaPlugin {
  25.  
  26.     @Getter
  27.     private static UltraBombs instance;
  28.     @Getter
  29.     private UltraBombsConfig ultraBombsConfig;
  30.     @Getter
  31.     private UltraBombsCommand ultraBombsCommand;
  32.     @Getter
  33.     private UltraBombsListener ultraBombsListener;
  34.     @Getter
  35.     private UltraBombsService ultraBombsService;
  36.     private Economy economy;
  37.  
  38.     @Override
  39.     public void onLoad() {
  40.         this.registerWGFLag();
  41.     }
  42.  
  43.     @Override
  44.     public void onEnable() {
  45.         instance = this;
  46.         this.printOnEnableMessage();
  47.         this.saveDefaultConfig();
  48.  
  49.         this.ultraBombsConfig = new UltraBombsConfig(this);
  50.         this.ultraBombsConfig.load();
  51.  
  52.         this.ultraBombsCommand = new UltraBombsCommand(this);
  53.         this.getCommand("ultrabombs").setExecutor(this.ultraBombsCommand);
  54.  
  55.         this.ultraBombsService = new UltraBombsService(this);
  56.         this.ultraBombsService.enable();
  57.  
  58.         this.ultraBombsListener = new UltraBombsListener(this);
  59.         this.getServer().getPluginManager().registerEvents(this.ultraBombsListener, this);
  60.  
  61.         UltraBombsBackendAPI backendApi = new UltraBombsBackendAPI(this.ultraBombsService);
  62.         BackendAPI.setImplementation(backendApi);
  63.  
  64.         new Metrics(this,METRICS_ID);
  65.     }
  66.  
  67.     private void printOnEnableMessage() {
  68.         try {
  69.             this.getLogger().info(FigletFont.convertOneLine("UltraBombs"));
  70.             this.getLogger().info(this.getDescription().getVersion());
  71.             this.getLogger().info("By: " + this.getDescription().getAuthors());
  72.             this.getLogger().info("Website: " + this.getDescription().getWebsite());
  73.         } catch (IOException ignored) {
  74.         }
  75.     }
  76.  
  77.     @Override
  78.     public void onDisable() {
  79.         this.ultraBombsService.disable();
  80.     }
  81.  
  82.     public void reloadPlugin() {
  83.         this.printOnEnableMessage();
  84.         this.ultraBombsConfig.reload();
  85.         this.ultraBombsService.reload();
  86.     }
  87.  
  88.  
  89.     public Economy getEconomy() {
  90.         if (this.economy == null) {
  91.             this.economy = this.setupEconomy();
  92.         }
  93.         return this.economy;
  94.     }
  95.  
  96.     public Economy setupEconomy() {
  97.         if (this.getServer().getPluginManager().getPlugin("Vault") == null) {
  98.             return null;
  99.         }
  100.  
  101.         RegisteredServiceProvider<Economy> rsp = this.getServer().getServicesManager().getRegistration(Economy.class);
  102.  
  103.         if (rsp == null) {
  104.             return null;
  105.         }
  106.  
  107.         return rsp.getProvider();
  108.     }
  109.  
  110.     private void registerWGFLag() {
  111.  
  112.         if (Bukkit.getPluginManager().getPlugin("WorldGuard") == null) {
  113.             return;
  114.         }
  115.  
  116.         try {
  117.             getWorldGuardWrapper().registerFlag(WG_FLAG_NAME, WrappedState.class, WrappedState.DENY);
  118.         } catch (IllegalStateException e) {
  119.             // This happens during plugin reloads. Flag cannot be registered as WG was already loaded,
  120.             // so we can safely ignore this exception.
  121.         }
  122.     }
  123.  
  124.     public WorldGuardWrapper getWorldGuardWrapper() {
  125.         return WorldGuardWrapper.getInstance();
  126.     }
  127. }
  128.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement