コード例 #1
0
ファイル: P.java プロジェクト: ProgrammerDan/Brewery
  @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!");
  }
コード例 #2
0
ファイル: P.java プロジェクト: ProgrammerDan/Brewery
  public void reload(CommandSender sender) {
    // clear all existent config Data
    BIngredients.possibleIngredients.clear();
    BIngredients.recipes.clear();
    BIngredients.cookedNames.clear();
    Words.words.clear();
    BPlayer.drainItems.clear();
    if (useLB) {
      try {
        LogBlockBarrel.clear();
      } catch (Exception e) {
        e.printStackTrace();
      }
    }

    // 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;
    }

    // save and load LanguageReader
    languageReader.save();
    languageReader =
        new LanguageReader(new File(p.getDataFolder(), "languages/" + language + ".yml"));

    // Reload Recipes
    Boolean successful = true;
    for (Brew brew : Brew.potions.values()) {
      if (!brew.reloadRecipe()) {
        successful = false;
      }
    }
    if (!successful) {
      msg(sender, p.languageReader.get("Error_Recipeload"));
    }
  }
コード例 #3
0
ファイル: P.java プロジェクト: ProgrammerDan/Brewery
  public boolean readConfig() {
    File file = new File(p.getDataFolder(), "config.yml");
    if (!checkConfigs()) {
      return false;
    }
    FileConfiguration config = YamlConfiguration.loadConfiguration(file);

    // Set the Language
    language = config.getString("language", "en");

    // Load LanguageReader
    languageReader =
        new LanguageReader(new File(p.getDataFolder(), "languages/" + language + ".yml"));

    // Check if config is the newest version
    String version = config.getString("version", null);
    if (version != null) {
      if (!version.equals(configVersion)) {
        new ConfigUpdater(file).update(version, language);
        P.p.log("Config Updated to version: " + configVersion);
        config = YamlConfiguration.loadConfiguration(file);
      }
    }

    // If the Update Checker should be enabled
    updateCheck = config.getBoolean("updateCheck", false);

    // Third-Party
    useWG =
        config.getBoolean("useWorldGuard", true)
            && getServer().getPluginManager().isPluginEnabled("WorldGuard");
    if (useWG) {
      try {
        try {
          Class.forName("com.sk89q.worldguard.bukkit.RegionContainer");
          wg = new WGBarrelNew();
        } catch (ClassNotFoundException e) {
          wg = new WGBarrelOld();
        }
      } catch (Throwable e) {
        wg = null;
        P.p.errorLog("Failed loading WorldGuard Integration! Opening Barrels will NOT work!");
        P.p.errorLog("Brewery was tested with version 5.8 to 6.0 of WorldGuard!");
        P.p.errorLog("Disable the WorldGuard support in the config and do /brew reload");
        e.printStackTrace();
      }
    }
    useLWC =
        config.getBoolean("useLWC", true) && getServer().getPluginManager().isPluginEnabled("LWC");
    useGP =
        config.getBoolean("useGriefPrevention", true)
            && getServer().getPluginManager().isPluginEnabled("GriefPrevention");
    useLB =
        config.getBoolean("useLogBlock", false)
            && getServer().getPluginManager().isPluginEnabled("LogBlock");
    hasVault = getServer().getPluginManager().isPluginEnabled("Vault");

    // various Settings
    DataSave.autosave = config.getInt("autosave", 3);
    debug = config.getBoolean("debug", false);
    BPlayer.pukeItem = Material.matchMaterial(config.getString("pukeItem", "SOUL_SAND"));
    BPlayer.hangoverTime = config.getInt("hangoverDays", 0) * 24 * 60;
    BPlayer.overdrinkKick = config.getBoolean("enableKickOnOverdrink", false);
    BPlayer.enableHome = config.getBoolean("enableHome", false);
    BPlayer.enableLoginDisallow = config.getBoolean("enableLoginDisallow", false);
    BPlayer.enablePuke = config.getBoolean("enablePuke", false);
    BPlayer.homeType = config.getString("homeType", null);
    Brew.colorInBarrels = config.getBoolean("colorInBarrels", false);
    Brew.colorInBrewer = config.getBoolean("colorInBrewer", false);
    PlayerListener.openEverywhere = config.getBoolean("openLargeBarrelEverywhere", false);
    Words.log = config.getBoolean("logRealChat", false);
    Words.commands = config.getStringList("distortCommands");
    Words.doSigns = config.getBoolean("distortSignText", false);
    for (String bypass : config.getStringList("distortBypass")) {
      Words.ignoreText.add(bypass.split(","));
    }

    // loading recipes
    ConfigurationSection configSection = config.getConfigurationSection("recipes");
    if (configSection != null) {
      for (String recipeId : configSection.getKeys(false)) {
        BRecipe recipe = new BRecipe(configSection, recipeId);
        if (recipe.isValid()) {
          BIngredients.recipes.add(recipe);
        } else {
          errorLog("Loading the Recipe with id: '" + recipeId + "' failed!");
        }
      }
    }

    // loading cooked names and possible ingredients
    configSection = config.getConfigurationSection("cooked");
    if (configSection != null) {
      for (String ingredient : configSection.getKeys(false)) {
        Material mat = Material.matchMaterial(ingredient);
        if (mat == null && hasVault) {
          try {
            net.milkbowl.vault.item.ItemInfo vaultItem =
                net.milkbowl.vault.item.Items.itemByString(ingredient);
            if (vaultItem != null) {
              mat = vaultItem.getType();
            }
          } catch (Exception e) {
            P.p.errorLog("Could not check vault for Item Name");
            e.printStackTrace();
          }
        }
        if (mat != null) {
          BIngredients.cookedNames.put(mat, (configSection.getString(ingredient, null)));
          BIngredients.possibleIngredients.add(mat);
        } else {
          errorLog("Unknown Material: " + ingredient);
        }
      }
    }

    // loading drainItems
    List<String> drainList = config.getStringList("drainItems");
    if (drainList != null) {
      for (String drainString : drainList) {
        String[] drainSplit = drainString.split("/");
        if (drainSplit.length > 1) {
          Material mat = Material.matchMaterial(drainSplit[0]);
          int strength = p.parseInt(drainSplit[1]);
          if (mat == null && hasVault && strength > 0) {
            try {
              net.milkbowl.vault.item.ItemInfo vaultItem =
                  net.milkbowl.vault.item.Items.itemByString(drainSplit[0]);
              if (vaultItem != null) {
                mat = vaultItem.getType();
              }
            } catch (Exception e) {
              P.p.errorLog("Could not check vault for Item Name");
              e.printStackTrace();
            }
          }
          if (mat != null && strength > 0) {
            BPlayer.drainItems.put(mat, strength);
          }
        }
      }
    }

    // telling Words the path, it will load it when needed
    Words.config = config;

    return true;
  }