Exemplo n.º 1
0
  public static void tpNext() {
    checkId++;
    if (checkId >= wakeups.size()) {
      p.msg(checkPlayer, p.languageReader.get("Player_WakeLast"));
      checkId = -1;
      checkPlayer = null;
      return;
    }

    Wakeup wakeup = wakeups.get(checkId);
    if (!wakeup.active) {
      tpNext();
      return;
    }

    String world = wakeup.loc.getWorld().getName();
    int x = (int) wakeup.loc.getX();
    int y = (int) wakeup.loc.getY();
    int z = (int) wakeup.loc.getZ();

    if (wakeup.check()) {
      p.msg(
          checkPlayer,
          p.languageReader.get("Player_WakeTeleport", "" + checkId, world, "" + x, "" + y, "" + z));
      checkPlayer.teleport(wakeup.loc);
    } else {
      p.msg(
          checkPlayer,
          p.languageReader.get("Player_WakeFilled", "" + checkId, world, "" + x, "" + y, "" + z));
    }
    p.msg(checkPlayer, p.languageReader.get("Player_WakeHint1"));
    p.msg(checkPlayer, p.languageReader.get("Player_WakeHint2"));
  }
Exemplo n.º 2
0
  public static void list(CommandSender sender, int page, String worldOnly) {
    if (wakeups.isEmpty()) {
      p.msg(sender, p.languageReader.get("Player_WakeNoPoints"));
      return;
    }

    ArrayList<String> locs = new ArrayList<>();
    for (int id = 0; id < wakeups.size(); id++) {

      Wakeup wakeup = wakeups.get(id);

      String s = "&m";
      if (wakeup.active) {
        s = "";
      }

      String world = wakeup.loc.getWorld().getName();

      if (worldOnly == null || world.equalsIgnoreCase(worldOnly)) {
        int x = (int) wakeup.loc.getX();
        int y = (int) wakeup.loc.getY();
        int z = (int) wakeup.loc.getZ();

        locs.add("&6" + s + id + "&f" + s + ": " + world + " " + x + "," + y + "," + z);
      }
    }
    p.list(sender, locs, page);
  }
Exemplo n.º 3
0
 public static void cancel(CommandSender sender) {
   if (checkPlayer != null) {
     checkPlayer = null;
     checkId = -1;
     p.msg(sender, p.languageReader.get("Player_WakeCancel"));
     return;
   }
   p.msg(sender, p.languageReader.get("Player_WakeNoCheck"));
 }
Exemplo n.º 4
0
  public static void set(CommandSender sender) {
    if (sender instanceof Player) {

      Player player = (Player) sender;
      wakeups.add(new Wakeup(player.getLocation()));
      p.msg(sender, p.languageReader.get("Player_WakeCreated", "" + (wakeups.size() - 1)));

    } else {
      p.msg(sender, p.languageReader.get("Error_PlayerCommand"));
    }
  }
Exemplo n.º 5
0
  // get the nearest of two random Wakeup-Locations
  public static Location getRandom(Location playerLoc) {
    if (wakeups.isEmpty()) {
      return null;
    }

    ArrayList<Wakeup> worldWakes = new ArrayList<>();

    for (Wakeup wakeup : wakeups) {
      if (wakeup.active) {
        if (wakeup.loc.getWorld().equals(playerLoc.getWorld())) {
          worldWakes.add(wakeup);
        }
      }
    }

    if (worldWakes.isEmpty()) {
      return null;
    }

    Wakeup w1 = calcRandom(worldWakes);
    worldWakes.remove(w1);
    if (w1 == null) return null;

    while (!w1.check()) {
      p.errorLog("Please Check Wakeup-Location with id: &6" + wakeups.indexOf(w1));

      w1 = calcRandom(worldWakes);
      if (w1 == null) {
        return null;
      }
      worldWakes.remove(w1);
    }

    Wakeup w2 = calcRandom(worldWakes);
    if (w2 != null) {
      worldWakes.remove(w2);

      while (!w2.check()) {
        p.errorLog("Please Check Wakeup-Location with id: &6" + wakeups.indexOf(w2));

        w2 = calcRandom(worldWakes);
        if (w2 == null) {
          return w1.loc;
        }
        worldWakes.remove(w2);
      }

      if (w1.loc.distance(playerLoc) > w2.loc.distance(playerLoc)) {
        return w2.loc;
      }
    }
    return w1.loc;
  }
Exemplo n.º 6
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!");
  }
Exemplo n.º 7
0
  public static void save(ConfigurationSection section, ConfigurationSection oldData) {
    p.createWorldSections(section);

    // loc is saved as a String in world sections with format x/y/z/pitch/yaw
    if (!wakeups.isEmpty()) {

      Iterator<Wakeup> iter = wakeups.iterator();
      for (int id = 0; iter.hasNext(); id++) {
        Wakeup wakeup = iter.next();

        if (!wakeup.active) {
          continue;
        }

        String worldName = wakeup.loc.getWorld().getName();
        String prefix;

        if (worldName.startsWith("DXL_")) {
          prefix = p.getDxlName(worldName) + "." + id;
        } else {
          prefix = wakeup.loc.getWorld().getUID().toString() + "." + id;
        }

        section.set(
            prefix,
            wakeup.loc.getX()
                + "/"
                + wakeup.loc.getY()
                + "/"
                + wakeup.loc.getZ()
                + "/"
                + wakeup.loc.getPitch()
                + "/"
                + wakeup.loc.getYaw());
      }
    }

    // copy Wakeups that are not loaded
    if (oldData != null) {
      for (String uuid : oldData.getKeys(false)) {
        if (!section.contains(uuid)) {
          section.set(uuid, oldData.get(uuid));
        }
      }
    }
  }
Exemplo n.º 8
0
  public static void remove(CommandSender sender, int id) {
    if (wakeups.isEmpty() || id < 0 || id >= wakeups.size()) {
      p.msg(
          sender,
          p.languageReader.get(
              "Player_WakeNotExist",
              "" + id)); // "&cDer Aufwachpunkt mit der id: &6" + id + " &cexistiert nicht!");
      return;
    }

    Wakeup wakeup = wakeups.get(id);

    if (wakeup.active) {
      wakeup.active = false;
      p.msg(sender, p.languageReader.get("Player_WakeDeleted", "" + id));

    } else {
      p.msg(sender, p.languageReader.get("Player_WakeAlreadyDeleted", "" + id));
    }
  }
Exemplo n.º 9
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);
   }
 }
Exemplo n.º 10
0
  public static void check(CommandSender sender, int id, boolean all) {
    if (sender instanceof Player) {
      Player player = (Player) sender;

      if (!all) {
        if (wakeups.isEmpty() || id >= wakeups.size()) {
          p.msg(sender, p.languageReader.get("Player_WakeNotExist", "" + id));
          return;
        }

        Wakeup wakeup = wakeups.get(id);
        if (wakeup.check()) {
          player.teleport(wakeup.loc);
        } else {
          String world = wakeup.loc.getWorld().getName();
          int x = (int) wakeup.loc.getX();
          int y = (int) wakeup.loc.getY();
          int z = (int) wakeup.loc.getZ();
          p.msg(
              sender,
              p.languageReader.get("Player_WakeFilled", "" + id, world, "" + x, "" + y, "" + z));
        }

      } else {
        if (wakeups.isEmpty()) {
          p.msg(sender, p.languageReader.get("Player_WakeNoPoints"));
          return;
        }
        if (checkPlayer != null && checkPlayer != player) {
          checkId = -1;
        }
        checkPlayer = player;
        tpNext();
      }

    } else {
      p.msg(sender, p.languageReader.get("Error_PlayerCommand"));
    }
  }
Exemplo n.º 11
0
  private boolean checkConfigs() {
    File cfg = new File(p.getDataFolder(), "config.yml");
    if (!cfg.exists()) {
      errorLog(
          "No config.yml found, creating default file! You may want to choose a config according to your language!");
      InputStream defconf = getResource("config/en/config.yml");
      if (defconf == null) {
        errorLog("default config file not found, your jarfile may be corrupt. Disabling Brewery!");
        return false;
      }
      try {
        saveFile(defconf, getDataFolder(), "config.yml");
      } catch (IOException e) {
        e.printStackTrace();
        return false;
      }
    }
    if (!cfg.exists()) {
      errorLog(
          "default config file could not be copied, your jarfile may be corrupt. Disabling Brewery!");
      return false;
    }

    File configs = new File(getDataFolder(), "configs");
    if (!configs.exists()) {
      String lang[] = new String[] {"de", "en", "fr"};
      for (String l : lang) {
        File lfold = new File(configs, l);
        try {
          saveFile(getResource("config/" + l + "/config.yml"), lfold, "config.yml");
        } catch (IOException e) {
          e.printStackTrace();
        }
      }
    }

    File languages = new File(getDataFolder(), "languages");
    if (!languages.exists()) {
      String lang[] = new String[] {"de", "en", "fr", "no"};
      for (String l : lang) {
        try {
          saveFile(getResource("languages/" + l + ".yml"), languages, l + ".yml");
        } catch (IOException e) {
          e.printStackTrace();
        }
      }
    }
    return true;
  }
Exemplo n.º 12
0
  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"));
    }
  }
Exemplo n.º 13
0
  // load Block locations of given world
  public void loadWorldData(String uuid, World world) {

    File file = new File(p.getDataFolder(), "data.yml");
    if (file.exists()) {

      FileConfiguration data = YamlConfiguration.loadConfiguration(file);

      // loading BCauldron
      if (data.contains("BCauldron." + uuid)) {
        ConfigurationSection section = data.getConfigurationSection("BCauldron." + uuid);
        for (String cauldron : section.getKeys(false)) {
          // block is splitted into x/y/z
          String block = section.getString(cauldron + ".block");
          if (block != null) {
            String[] splitted = block.split("/");
            if (splitted.length == 3) {

              Block worldBlock =
                  world.getBlockAt(
                      parseInt(splitted[0]), parseInt(splitted[1]), parseInt(splitted[2]));
              BIngredients ingredients =
                  loadIngredients(section.getConfigurationSection(cauldron + ".ingredients"));
              int state = section.getInt(cauldron + ".state", 1);

              new BCauldron(worldBlock, ingredients, state);
            } else {
              errorLog(
                  "Incomplete Block-Data in data.yml: "
                      + section.getCurrentPath()
                      + "."
                      + cauldron);
            }
          } else {
            errorLog(
                "Missing Block-Data in data.yml: " + section.getCurrentPath() + "." + cauldron);
          }
        }
      }

      // loading Barrel
      if (data.contains("Barrel." + uuid)) {
        ConfigurationSection section = data.getConfigurationSection("Barrel." + uuid);
        for (String barrel : section.getKeys(false)) {
          // block spigot is splitted into x/y/z
          String spigot = section.getString(barrel + ".spigot");
          if (spigot != null) {
            String[] splitted = spigot.split("/");
            if (splitted.length == 3) {

              // load itemStacks from invSection
              ConfigurationSection invSection = section.getConfigurationSection(barrel + ".inv");
              Block block =
                  world.getBlockAt(
                      parseInt(splitted[0]), parseInt(splitted[1]), parseInt(splitted[2]));
              float time = (float) section.getDouble(barrel + ".time", 0.0);
              byte sign = (byte) section.getInt(barrel + ".sign", 0);
              String[] st = section.getString(barrel + ".st", "").split(",");
              String[] wo = section.getString(barrel + ".wo", "").split(",");

              if (invSection != null) {
                new Barrel(block, sign, st, wo, invSection.getValues(true), time);
              } else {
                // Barrel has no inventory
                new Barrel(block, sign, st, wo, null, time);
              }

            } else {
              errorLog(
                  "Incomplete Block-Data in data.yml: " + section.getCurrentPath() + "." + barrel);
            }
          } else {
            errorLog("Missing Block-Data in data.yml: " + section.getCurrentPath() + "." + barrel);
          }
        }
      }

      // loading Wakeup
      if (data.contains("Wakeup." + uuid)) {
        ConfigurationSection section = data.getConfigurationSection("Wakeup." + uuid);
        for (String wakeup : section.getKeys(false)) {
          // loc of wakeup is splitted into x/y/z/pitch/yaw
          String loc = section.getString(wakeup);
          if (loc != null) {
            String[] splitted = loc.split("/");
            if (splitted.length == 5) {

              double x = NumberUtils.toDouble(splitted[0]);
              double y = NumberUtils.toDouble(splitted[1]);
              double z = NumberUtils.toDouble(splitted[2]);
              float pitch = NumberUtils.toFloat(splitted[3]);
              float yaw = NumberUtils.toFloat(splitted[4]);
              Location location = new Location(world, x, y, z, yaw, pitch);

              Wakeup.wakeups.add(new Wakeup(location));

            } else {
              errorLog(
                  "Incomplete Location-Data in data.yml: "
                      + section.getCurrentPath()
                      + "."
                      + wakeup);
            }
          }
        }
      }
    }
  }
Exemplo n.º 14
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!");
    }
  }
Exemplo n.º 15
0
  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;
  }