Guest User

Main

a guest
Jul 18th, 2019
117
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 8.24 KB | None | 0 0
  1. package mc.CustomBoss.custom.Main;
  2.  
  3. import org.bukkit.plugin.java.*;
  4. import net.milkbowl.vault.economy.*;
  5. import com.sk89q.worldguard.bukkit.*;
  6. import java.io.*;
  7. import org.bukkit.configuration.file.*;
  8. import org.bukkit.plugin.*;
  9. import org.bukkit.scheduler.*;
  10. import org.inventivetalent.bossbar.*;
  11. import org.bukkit.event.*;
  12. import com.sk89q.worldguard.protection.regions.*;
  13. import com.sk89q.worldguard.protection.managers.*;
  14. import org.bukkit.util.*;
  15. import org.bukkit.entity.*;
  16. import org.bukkit.craftbukkit.v1_8_R3.entity.*;
  17. import mc.CustomBoss.custom.Main.Entyti.*;
  18. import java.util.logging.*;
  19. import org.bukkit.configuration.*;
  20. import org.bukkit.command.*;
  21. import org.bukkit.inventory.*;
  22. import org.bukkit.*;
  23. import org.bukkit.inventory.meta.*;
  24.  
  25. public class Main extends JavaPlugin
  26. {
  27.     public static Economy econ;
  28.     FileConfiguration levelsConfig;
  29.     public static Main instance;
  30.     File levels1;
  31.     FileConfiguration levelsConfig1;
  32.     public WorldGuardPlugin wg;
  33.    
  34.     static {
  35.         Main.econ = null;
  36.     }
  37.    
  38.     public Main() {
  39.         this.levels1 = new File(this.getDataFolder() + File.separator + "spawners.yml");
  40.         this.wg = (WorldGuardPlugin)Bukkit.getPluginManager().getPlugin("WorldGuard");
  41.     }
  42.    
  43.     private boolean setupEconomy() {
  44.         if (this.getServer().getPluginManager().getPlugin("Vault") == null) {
  45.             return false;
  46.         }
  47.         final RegisteredServiceProvider<Economy> rsp = (RegisteredServiceProvider<Economy>)this.getServer().getServicesManager().getRegistration((Class)Economy.class);
  48.         if (rsp == null) {
  49.             return false;
  50.         }
  51.         Main.econ = (Economy)rsp.getProvider();
  52.         return Main.econ != null;
  53.     }
  54.    
  55.     public void saveCustomYml(final FileConfiguration ymlConfig, final File ymlFile) {
  56.         try {
  57.             ymlConfig.save(ymlFile);
  58.         }
  59.         catch (IOException e) {
  60.             e.printStackTrace();
  61.         }
  62.     }
  63.    
  64.     public File getconfigFilleNPC() {
  65.         return new File(this.getDataFolder() + File.separator + "points.yml");
  66.     }
  67.    
  68.     public FileConfiguration getfilecoFileConfigurationNPC() {
  69.         return (FileConfiguration)YamlConfiguration.loadConfiguration(this.getconfigFilleNPC());
  70.     }
  71.    
  72.     public void onEnable() {
  73.         Main.instance = this;
  74.         if (!this.setupEconomy()) {
  75.             Bukkit.getLogger().severe(String.format("[%s] - Disabled due to no Vault dependency found!", this.getDescription().getName()));
  76.             this.getServer().getPluginManager().disablePlugin((Plugin)this);
  77.             return;
  78.         }
  79.         this.getConfig().options().copyDefaults(true);
  80.         this.saveConfig();
  81.         new BukkitRunnable() {
  82.             public void run() {
  83.                 for (final Player player : Bukkit.getOnlinePlayers()) {
  84.                     if (player == null) {
  85.                         continue;
  86.                     }
  87.                     BossBarAPI.removeAllBars(player);
  88.                 }
  89.             }
  90.         }.runTaskTimer((Plugin)this, 40L, 5L);
  91.         Bukkit.getPluginManager().registerEvents((Listener)new Bosslistener(), (Plugin)this);
  92.         Bukkit.getPluginManager().registerEvents((Listener)new Bossinfo(), (Plugin)this);
  93.         this.getCommand("bossinfo").setExecutor((CommandExecutor)new Bossinfo());
  94.         this.levelsConfig1 = (FileConfiguration)YamlConfiguration.loadConfiguration(this.levels1);
  95.         loadSpawners();
  96.         new SpawnerUpdater().runTaskTimer((Plugin)this, 20L, 20L);
  97.         Main.instance.saveCustomYml(Main.instance.levelsConfig1, Main.instance.levels1);
  98.     }
  99.    
  100.     public void onDisable() {
  101.         this.saveConfig();
  102.         for (final World w : Bukkit.getWorlds()) {
  103.             for (final LivingEntity e : w.getLivingEntities()) {
  104.                 if (!(e instanceof Player) && e.getCustomName() != "") {
  105.                     e.remove();
  106.                 }
  107.             }
  108.         }
  109.         Main.instance.saveCustomYml(Main.instance.levelsConfig1, Main.instance.levels1);
  110.         for (final Spawner cSpawner : Spawner.spawners.values()) {
  111.             if (cSpawner.getCurrent() == null) {
  112.                 continue;
  113.             }
  114.             cSpawner.getCurrent().getBukkitEntity().remove();
  115.         }
  116.     }
  117.    
  118.     public boolean CheckregionLivingEntity(final Entity entity) {
  119.         final RegionManager manager = this.wg.getRegionManager(entity.getLocation().getWorld());
  120.         for (final ProtectedRegion region : manager.getApplicableRegions(entity.getLocation())) {
  121.             if (region.getId().equalsIgnoreCase("Spawn")) {
  122.                 return true;
  123.             }
  124.             if (region.getId().equalsIgnoreCase("Spawn1")) {
  125.                 return true;
  126.             }
  127.             if (region.getId().equalsIgnoreCase("Spawn2")) {
  128.                 return true;
  129.             }
  130.         }
  131.         return false;
  132.     }
  133.    
  134.     public LivingEntity rayTraceEntity(final Player player, final int range) {
  135.         final BlockIterator iterator = new BlockIterator(player.getWorld(), player.getEyeLocation().toVector(), player.getEyeLocation().getDirection(), 0.0, range);
  136.         Chunk chunk = null;
  137.         Entity[] entities = null;
  138.         while (iterator.hasNext()) {
  139.             final Location l = iterator.next().getLocation();
  140.             if (chunk != l.getChunk()) {
  141.                 chunk = l.getChunk();
  142.                 entities = chunk.getEntities();
  143.             }
  144.             if (entities != null && entities.length > 0) {
  145.                 final Entity[] arr$ = entities;
  146.                 for (int len$ = entities.length, i$ = 0; i$ < len$; ++i$) {
  147.                     final Entity entity = arr$[i$];
  148.                     if (entity != player && entity instanceof LivingEntity && entity.getType() != EntityType.SQUID && l.getWorld() == entity.getLocation().getWorld() && l.distance(entity.getLocation()) < 1.5) {
  149.                         return (LivingEntity)entity;
  150.                     }
  151.                 }
  152.             }
  153.         }
  154.         return null;
  155.     }
  156.    
  157.     public LivingEntity rayTraceEntity(final CraftEntity bukkitEntity, final int range) {
  158.         final BlockIterator iterator = new BlockIterator(bukkitEntity.getWorld(), ((LivingEntity)bukkitEntity).getEyeLocation().toVector(), ((LivingEntity)bukkitEntity).getEyeLocation().getDirection(), 0.0, range);
  159.         Chunk chunk = null;
  160.         Entity[] entities = null;
  161.         while (iterator.hasNext()) {
  162.             final Location l = iterator.next().getLocation();
  163.             if (chunk != l.getChunk()) {
  164.                 chunk = l.getChunk();
  165.                 entities = chunk.getEntities();
  166.             }
  167.             if (entities != null && entities.length > 0) {
  168.                 final Entity[] arr$ = entities;
  169.                 for (int len$ = entities.length, i$ = 0; i$ < len$; ++i$) {
  170.                     final Entity entity = arr$[i$];
  171.                     if (entity != bukkitEntity && entity instanceof Player && entity.getType() != EntityType.SQUID && l.getWorld() == entity.getLocation().getWorld() && l.distance(entity.getLocation()) < 1.5) {
  172.                         return (LivingEntity)entity;
  173.                     }
  174.                 }
  175.             }
  176.         }
  177.         return null;
  178.     }
  179.    
  180.     private static void loadSpawners() {
  181.         for (final String cSpawn : Main.instance.levelsConfig1.getKeys(false)) {
  182.             final ConfigurationSection path = Main.instance.levelsConfig1.getConfigurationSection(cSpawn);
  183.             final EntityTypes type = EntityTypes.valueOf(path.getString("type"));
  184.             final double x = path.getDouble("x");
  185.             final double y = path.getDouble("y");
  186.             final double z = path.getDouble("z");
  187.             final int interval = path.getInt("interval");
  188.             final World world = Bukkit.getWorld(path.getString("world"));
  189.             new Spawner(new Location(world, x, y, z), type, interval).update();
  190.         }
  191.         Main.instance.getLogger().log(Level.INFO, "Loaded " + Spawner.spawners.size() + " mob spawners");
  192.     }
  193.    
  194.     boolean tryParseInt(final String value) {
  195.         try {
  196.             Integer.parseInt(value);
  197.             return true;
  198.         }
  199.         catch (NumberFormatException numberFormatException) {
  200.             return false;
  201.         }
  202.     }
  203. }
Add Comment
Please, Sign In to add comment