Advertisement
JackOUT

Untitled

Jul 30th, 2022
1,067
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 5.31 KB | None | 0 0
  1. package games.coob.laserturrets;
  2.  
  3. import games.coob.laserturrets.menu.ShopMenu;
  4. import games.coob.laserturrets.model.TurretData;
  5. import games.coob.laserturrets.model.TurretRegistry;
  6. import games.coob.laserturrets.settings.Settings;
  7. import games.coob.laserturrets.settings.TurretSettings;
  8. import games.coob.laserturrets.task.ArrowTask;
  9. import games.coob.laserturrets.task.LaserPointerTask;
  10. import games.coob.laserturrets.task.LaserTask;
  11. import net.milkbowl.vault.economy.Economy;
  12. import org.bukkit.block.Block;
  13. import org.bukkit.entity.Player;
  14. import org.bukkit.event.EventHandler;
  15. import org.bukkit.event.block.BlockBreakEvent;
  16. import org.bukkit.event.block.BlockBurnEvent;
  17. import org.bukkit.event.block.BlockExplodeEvent;
  18. import org.bukkit.event.player.PlayerInteractEvent;
  19. import org.mineacademy.fo.Common;
  20. import org.mineacademy.fo.debug.LagCatcher;
  21. import org.mineacademy.fo.model.HookManager;
  22. import org.mineacademy.fo.plugin.SimplePlugin;
  23.  
  24. /**
  25.  * PluginTemplate is a simple template you can use every time you make
  26.  * a new plugin. This will save you time because you no longer have to
  27.  * recreate the same skeleton and features each time.
  28.  * <p>
  29.  * It uses Foundation for fast and efficient development process.
  30.  */
  31. public final class LaserTurrets extends SimplePlugin { // TODO create an animation when registering a turret (spiny head animation)
  32.  
  33.     // TODO allow players to buy already placed turrets
  34.  
  35.     private static Economy econ = null;
  36.  
  37.     public static Economy getEconomy() {
  38.         return econ;
  39.     }
  40.  
  41.     /**
  42.      * Automatically perform login ONCE when the plugin starts.
  43.      */
  44.     @Override
  45.     protected void onPluginStart() {
  46.         Common.runLater(TurretRegistry::getInstance);
  47.  
  48.         LagCatcher.start("onStart");
  49.         for (final String type : getTypes())
  50.             Common.runLater(10, () -> TurretSettings.getInstance(type));
  51.  
  52.         LagCatcher.end("onStart", true);
  53.  
  54.         if (!HookManager.isVaultLoaded() && Settings.CurrencySection.USE_VAULT) {
  55.             Common.log("[LaserTurrets] - Disabled due to no Vault dependency found!", getDescription().getName());
  56.             getServer().getPluginManager().disablePlugin(this);
  57.         }
  58.     }
  59.  
  60.     public String[] getTypes() {
  61.         return new String[]{
  62.                 "arrow", "laser", "flame"
  63.         };
  64.     }
  65.  
  66.     @Override
  67.     protected void onPluginReload() {
  68.         TurretRegistry.getInstance().save();
  69.         for (final String type : getTypes())
  70.             TurretSettings.getInstance(type).save();
  71.     }
  72.  
  73.     @Override
  74.     protected void onPluginStop() {
  75.         TurretRegistry.getInstance().save();
  76.         for (final String type : getTypes())
  77.             TurretSettings.getInstance(type).save();
  78.     }
  79.  
  80.     /**
  81.      * Automatically perform login when the plugin starts and each time it is reloaded.
  82.      */
  83.     @Override
  84.     protected void onReloadablesStart() {
  85.  
  86.         // You can check for necessary plugins and disable loading if they are missing
  87.         // Valid.checkBoolean(HookManager.isVaultLoaded(), "You need to install Vault so that we can work with packets, offline player data, prefixes and groups.");
  88.  
  89.         // Uncomment to load variables
  90.         // Variable.loadVariables();
  91.  
  92.         //
  93.         // Add your own plugin parts to load automatically here
  94.         // Please see @AutoRegister for parts you do not have to register manually
  95.         //
  96.         Common.runTimer(20, new ArrowTask());
  97.         Common.runTimer(2, new LaserPointerTask());
  98.         Common.runTimer(30, new LaserTask());
  99.     }
  100.  
  101.     /* ------------------------------------------------------------------------------- */
  102.     /* Events */
  103.     /* ------------------------------------------------------------------------------- */
  104.  
  105.     @EventHandler
  106.     public void onBlockBreak(final BlockBreakEvent event) {
  107.         final Block block = event.getBlock();
  108.         final TurretRegistry turretRegistry = TurretRegistry.getInstance();
  109.  
  110.         if (turretRegistry.isRegistered(block))
  111.             event.setCancelled(true);
  112.     }
  113.  
  114.     @EventHandler
  115.     public void onBlockExplode(final BlockExplodeEvent event) {
  116.         final Block block = event.getBlock();
  117.         final TurretRegistry turretRegistry = TurretRegistry.getInstance();
  118.  
  119.         if (turretRegistry.isRegistered(block))
  120.             event.setCancelled(true);
  121.     }
  122.  
  123.     @EventHandler
  124.     public void onBlockBurn(final BlockBurnEvent event) {
  125.         final Block block = event.getBlock();
  126.         final TurretRegistry turretRegistry = TurretRegistry.getInstance();
  127.  
  128.         if (turretRegistry.isRegistered(block))
  129.             event.setCancelled(true);
  130.     }
  131.  
  132.     @EventHandler
  133.     public void onPlayerInteractAtBlock(final PlayerInteractEvent event) {
  134.         final Block block = event.getClickedBlock();
  135.         final TurretRegistry registry = TurretRegistry.getInstance();
  136.  
  137.         if (registry.isRegistered(block)) {
  138.             final TurretData turretData = registry.getTurretByBlock(block);
  139.             final Player player = event.getPlayer();
  140.  
  141.             if (turretData.getPlayerBlacklist() != null && turretData.getPlayerBlacklist().contains(player))
  142.                 new ShopMenu.UpgradeMenu(turretData, turretData.getCurrentLevel(), player).displayTo(player);
  143.         }
  144.     }
  145.  
  146.     /* ------------------------------------------------------------------------------- */
  147.     /* Static */
  148.     /* ------------------------------------------------------------------------------- */
  149.  
  150.     /**
  151.      * Return the instance of this plugin, which simply refers to a static
  152.      * field already created for you in SimplePlugin but casts it to your
  153.      * specific plugin instance for your convenience.
  154.      *
  155.      * @return
  156.      */
  157.     public static LaserTurrets getInstance() {
  158.         return (LaserTurrets) SimplePlugin.getInstance();
  159.     }
  160. }
  161.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement