Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package mc.CustomBoss.custom.Main;
- import org.bukkit.plugin.java.*;
- import net.milkbowl.vault.economy.*;
- import com.sk89q.worldguard.bukkit.*;
- import java.io.*;
- import org.bukkit.configuration.file.*;
- import org.bukkit.plugin.*;
- import org.bukkit.scheduler.*;
- import org.inventivetalent.bossbar.*;
- import org.bukkit.event.*;
- import com.sk89q.worldguard.protection.regions.*;
- import com.sk89q.worldguard.protection.managers.*;
- import org.bukkit.util.*;
- import org.bukkit.entity.*;
- import org.bukkit.craftbukkit.v1_8_R3.entity.*;
- import mc.CustomBoss.custom.Main.Entyti.*;
- import java.util.logging.*;
- import org.bukkit.configuration.*;
- import org.bukkit.command.*;
- import org.bukkit.inventory.*;
- import org.bukkit.*;
- import org.bukkit.inventory.meta.*;
- public class Main extends JavaPlugin
- {
- public static Economy econ;
- FileConfiguration levelsConfig;
- public static Main instance;
- File levels1;
- FileConfiguration levelsConfig1;
- public WorldGuardPlugin wg;
- static {
- Main.econ = null;
- }
- public Main() {
- this.levels1 = new File(this.getDataFolder() + File.separator + "spawners.yml");
- this.wg = (WorldGuardPlugin)Bukkit.getPluginManager().getPlugin("WorldGuard");
- }
- private boolean setupEconomy() {
- if (this.getServer().getPluginManager().getPlugin("Vault") == null) {
- return false;
- }
- final RegisteredServiceProvider<Economy> rsp = (RegisteredServiceProvider<Economy>)this.getServer().getServicesManager().getRegistration((Class)Economy.class);
- if (rsp == null) {
- return false;
- }
- Main.econ = (Economy)rsp.getProvider();
- return Main.econ != null;
- }
- public void saveCustomYml(final FileConfiguration ymlConfig, final File ymlFile) {
- try {
- ymlConfig.save(ymlFile);
- }
- catch (IOException e) {
- e.printStackTrace();
- }
- }
- public File getconfigFilleNPC() {
- return new File(this.getDataFolder() + File.separator + "points.yml");
- }
- public FileConfiguration getfilecoFileConfigurationNPC() {
- return (FileConfiguration)YamlConfiguration.loadConfiguration(this.getconfigFilleNPC());
- }
- public void onEnable() {
- Main.instance = this;
- if (!this.setupEconomy()) {
- Bukkit.getLogger().severe(String.format("[%s] - Disabled due to no Vault dependency found!", this.getDescription().getName()));
- this.getServer().getPluginManager().disablePlugin((Plugin)this);
- return;
- }
- this.getConfig().options().copyDefaults(true);
- this.saveConfig();
- new BukkitRunnable() {
- public void run() {
- for (final Player player : Bukkit.getOnlinePlayers()) {
- if (player == null) {
- continue;
- }
- BossBarAPI.removeAllBars(player);
- }
- }
- }.runTaskTimer((Plugin)this, 40L, 5L);
- Bukkit.getPluginManager().registerEvents((Listener)new Bosslistener(), (Plugin)this);
- Bukkit.getPluginManager().registerEvents((Listener)new Bossinfo(), (Plugin)this);
- this.getCommand("bossinfo").setExecutor((CommandExecutor)new Bossinfo());
- this.levelsConfig1 = (FileConfiguration)YamlConfiguration.loadConfiguration(this.levels1);
- loadSpawners();
- new SpawnerUpdater().runTaskTimer((Plugin)this, 20L, 20L);
- Main.instance.saveCustomYml(Main.instance.levelsConfig1, Main.instance.levels1);
- }
- public void onDisable() {
- this.saveConfig();
- for (final World w : Bukkit.getWorlds()) {
- for (final LivingEntity e : w.getLivingEntities()) {
- if (!(e instanceof Player) && e.getCustomName() != "") {
- e.remove();
- }
- }
- }
- Main.instance.saveCustomYml(Main.instance.levelsConfig1, Main.instance.levels1);
- for (final Spawner cSpawner : Spawner.spawners.values()) {
- if (cSpawner.getCurrent() == null) {
- continue;
- }
- cSpawner.getCurrent().getBukkitEntity().remove();
- }
- }
- public boolean CheckregionLivingEntity(final Entity entity) {
- final RegionManager manager = this.wg.getRegionManager(entity.getLocation().getWorld());
- for (final ProtectedRegion region : manager.getApplicableRegions(entity.getLocation())) {
- if (region.getId().equalsIgnoreCase("Spawn")) {
- return true;
- }
- if (region.getId().equalsIgnoreCase("Spawn1")) {
- return true;
- }
- if (region.getId().equalsIgnoreCase("Spawn2")) {
- return true;
- }
- }
- return false;
- }
- public LivingEntity rayTraceEntity(final Player player, final int range) {
- final BlockIterator iterator = new BlockIterator(player.getWorld(), player.getEyeLocation().toVector(), player.getEyeLocation().getDirection(), 0.0, range);
- Chunk chunk = null;
- Entity[] entities = null;
- while (iterator.hasNext()) {
- final Location l = iterator.next().getLocation();
- if (chunk != l.getChunk()) {
- chunk = l.getChunk();
- entities = chunk.getEntities();
- }
- if (entities != null && entities.length > 0) {
- final Entity[] arr$ = entities;
- for (int len$ = entities.length, i$ = 0; i$ < len$; ++i$) {
- final Entity entity = arr$[i$];
- if (entity != player && entity instanceof LivingEntity && entity.getType() != EntityType.SQUID && l.getWorld() == entity.getLocation().getWorld() && l.distance(entity.getLocation()) < 1.5) {
- return (LivingEntity)entity;
- }
- }
- }
- }
- return null;
- }
- public LivingEntity rayTraceEntity(final CraftEntity bukkitEntity, final int range) {
- final BlockIterator iterator = new BlockIterator(bukkitEntity.getWorld(), ((LivingEntity)bukkitEntity).getEyeLocation().toVector(), ((LivingEntity)bukkitEntity).getEyeLocation().getDirection(), 0.0, range);
- Chunk chunk = null;
- Entity[] entities = null;
- while (iterator.hasNext()) {
- final Location l = iterator.next().getLocation();
- if (chunk != l.getChunk()) {
- chunk = l.getChunk();
- entities = chunk.getEntities();
- }
- if (entities != null && entities.length > 0) {
- final Entity[] arr$ = entities;
- for (int len$ = entities.length, i$ = 0; i$ < len$; ++i$) {
- final Entity entity = arr$[i$];
- if (entity != bukkitEntity && entity instanceof Player && entity.getType() != EntityType.SQUID && l.getWorld() == entity.getLocation().getWorld() && l.distance(entity.getLocation()) < 1.5) {
- return (LivingEntity)entity;
- }
- }
- }
- }
- return null;
- }
- private static void loadSpawners() {
- for (final String cSpawn : Main.instance.levelsConfig1.getKeys(false)) {
- final ConfigurationSection path = Main.instance.levelsConfig1.getConfigurationSection(cSpawn);
- final EntityTypes type = EntityTypes.valueOf(path.getString("type"));
- final double x = path.getDouble("x");
- final double y = path.getDouble("y");
- final double z = path.getDouble("z");
- final int interval = path.getInt("interval");
- final World world = Bukkit.getWorld(path.getString("world"));
- new Spawner(new Location(world, x, y, z), type, interval).update();
- }
- Main.instance.getLogger().log(Level.INFO, "Loaded " + Spawner.spawners.size() + " mob spawners");
- }
- boolean tryParseInt(final String value) {
- try {
- Integer.parseInt(value);
- return true;
- }
- catch (NumberFormatException numberFormatException) {
- return false;
- }
- }
- }
Add Comment
Please, Sign In to add comment