Ejemplo n.º 1
0
  @Override
  public void onEnable() {
    p = this;

    // Version check
    String v = Bukkit.getBukkitVersion();
    useUUID = !v.matches(".*1\\.[1-6].*") && !v.matches(".*1\\.7\\.[0-5].*");

    // load the Config
    try {
      if (!readConfig()) {
        p = null;
        getServer().getPluginManager().disablePlugin(this);
        return;
      }
    } catch (Exception e) {
      e.printStackTrace();
      p = null;
      getServer().getPluginManager().disablePlugin(this);
      return;
    }
    readData();

    // Setup Metrics
    setupMetrics();

    // Listeners
    blockListener = new BlockListener();
    playerListener = new PlayerListener();
    entityListener = new EntityListener();
    inventoryListener = new InventoryListener();
    worldListener = new WorldListener();
    getCommand("Brewery").setExecutor(new CommandListener());

    p.getServer().getPluginManager().registerEvents(blockListener, p);
    p.getServer().getPluginManager().registerEvents(playerListener, p);
    p.getServer().getPluginManager().registerEvents(entityListener, p);
    p.getServer().getPluginManager().registerEvents(inventoryListener, p);
    p.getServer().getPluginManager().registerEvents(worldListener, p);

    // Heartbeat
    p.getServer().getScheduler().runTaskTimer(p, new BreweryRunnable(), 650, 1200);
    p.getServer().getScheduler().runTaskTimer(p, new DrunkRunnable(), 120, 120);

    if (updateCheck) {
      p.getServer().getScheduler().runTaskLaterAsynchronously(p, new UpdateChecker(), 135);
    }

    this.log(this.getDescription().getName() + " enabled!");
  }
Ejemplo n.º 2
0
 // create empty World save Sections
 public void createWorldSections(ConfigurationSection section) {
   for (World world : p.getServer().getWorlds()) {
     String worldName = world.getName();
     if (worldName.startsWith("DXL_")) {
       worldName = getDxlName(worldName);
     } else {
       worldName = world.getUID().toString();
     }
     section.createSection(worldName);
   }
 }
Ejemplo n.º 3
0
  // load all Data
  public void readData() {
    File file = new File(p.getDataFolder(), "data.yml");
    if (file.exists()) {

      FileConfiguration data = YamlConfiguration.loadConfiguration(file);

      // Check if data is the newest version
      String version = data.getString("Version", null);
      if (version != null) {
        if (!version.equals(DataSave.dataVersion)) {
          P.p.log("Data File is being updated...");
          new DataUpdater(data, file).update(version);
          data = YamlConfiguration.loadConfiguration(file);
          P.p.log("Data Updated to version: " + DataSave.dataVersion);
        }
      }

      // loading Ingredients into ingMap
      Map<String, BIngredients> ingMap = new HashMap<String, BIngredients>();
      ConfigurationSection section = data.getConfigurationSection("Ingredients");
      if (section != null) {
        for (String id : section.getKeys(false)) {
          ConfigurationSection matSection = section.getConfigurationSection(id + ".mats");
          if (matSection != null) {
            // matSection has all the materials + amount as Integers
            ArrayList<ItemStack> ingredients = deserializeIngredients(matSection);
            ingMap.put(id, new BIngredients(ingredients, section.getInt(id + ".cookedTime", 0)));
          } else {
            errorLog("Ingredient id: '" + id + "' incomplete in data.yml");
          }
        }
      }

      // loading Brew
      section = data.getConfigurationSection("Brew");
      if (section != null) {
        // All sections have the UID as name
        for (String uid : section.getKeys(false)) {
          BIngredients ingredients = getIngredients(ingMap, section.getString(uid + ".ingId"));
          int quality = section.getInt(uid + ".quality", 0);
          int distillRuns = section.getInt(uid + ".distillRuns", 0);
          float ageTime = (float) section.getDouble(uid + ".ageTime", 0.0);
          float wood = (float) section.getDouble(uid + ".wood", -1.0);
          String recipe = section.getString(uid + ".recipe", null);
          boolean unlabeled = section.getBoolean(uid + ".unlabeled", false);
          boolean persistent = section.getBoolean(uid + ".persist", false);
          boolean stat = section.getBoolean(uid + ".stat", false);

          new Brew(
              parseInt(uid),
              ingredients,
              quality,
              distillRuns,
              ageTime,
              wood,
              recipe,
              unlabeled,
              persistent,
              stat);
        }
      }

      // loading BPlayer
      section = data.getConfigurationSection("Player");
      if (section != null) {
        // keys have players name
        for (String name : section.getKeys(false)) {
          try {
            UUID.fromString(name);
            if (!useUUID) {
              continue;
            }
          } catch (IllegalArgumentException e) {
            if (useUUID) {
              continue;
            }
          }

          int quality = section.getInt(name + ".quality");
          int drunk = section.getInt(name + ".drunk");
          int offDrunk = section.getInt(name + ".offDrunk", 0);
          boolean passedOut = section.getBoolean(name + ".passedOut", false);

          new BPlayer(name, quality, drunk, offDrunk, passedOut);
        }
      }

      for (World world : p.getServer().getWorlds()) {
        if (world.getName().startsWith("DXL_")) {
          loadWorldData(getDxlName(world.getName()), world);
        } else {
          loadWorldData(world.getUID().toString(), world);
        }
      }

    } else {
      errorLog("No data.yml found, will create new one!");
    }
  }