public void reloadLocalizedStrings() {
    File localizedStringsFile =
        new File(plugin.getDataFolder().getPath() + "/localization/" + languageFile);
    if (this.isDefault()) {
      if (defaultLocalizedStrings == null) {
        localizedStrings = defaultLocalizedStrings;
      }
      return;
    } else if (!localizedStringsFile.exists()) {

      CivLog.warning(
          "Configuration file:"
              + languageFile
              + " was missing. You must create this file in plugins/Civcraft/localization/");
      CivLog.warning("Using default_lang.yml");
      this.setLanguageFile("");
      return;
    }
    localizedStrings = YamlConfiguration.loadConfiguration(localizedStringsFile);

    CivLog.info("Loading Configuration file:" + languageFile);
    // read the config.yml into memory
    YamlConfiguration cfg = new YamlConfiguration();
    try {
      cfg.load(localizedStringsFile);
    } catch (FileNotFoundException e1) {
      e1.printStackTrace();
    } catch (IOException e1) {
      e1.printStackTrace();
    } catch (InvalidConfigurationException e1) {
      e1.printStackTrace();
    }
    localizedStrings.setDefaults(cfg);
  }
  public void reloadDefaultLocalizedStrings() {
    String defaultLanguageFile = "default_lang.yml";
    File defaultLocalizedStringsFile =
        new File(plugin.getDataFolder().getPath() + "/localization/" + defaultLanguageFile);
    CivLog.warning(
        "Configuration file:" + defaultLanguageFile + " in use. Updating to disk from Jar.");
    try {
      CivSettings.streamResourceToDisk("/localization/" + defaultLanguageFile);
    } catch (IOException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    }

    defaultLocalizedStrings = YamlConfiguration.loadConfiguration(defaultLocalizedStringsFile);

    CivLog.info("Loading Configuration file:" + defaultLanguageFile);
    // read the config.yml into memory
    YamlConfiguration cfg = new YamlConfiguration();
    try {
      cfg.load(defaultLocalizedStringsFile);
    } catch (FileNotFoundException e1) {
      e1.printStackTrace();
    } catch (IOException e1) {
      e1.printStackTrace();
    } catch (InvalidConfigurationException e1) {
      e1.printStackTrace();
    }
    defaultLocalizedStrings.setDefaults(cfg);
  }
  public static void loadConfig(
      FileConfiguration cfg, ArrayList<ConfigTempleSacrifice> temple_sacrifices) {
    List<Map<?, ?>> ts_list = cfg.getMapList("temple.sacrifices");
    for (Map<?, ?> cl : ts_list) {
      ConfigTempleSacrifice config_ts = new ConfigTempleSacrifice();

      List<?> entitiesList = (List<?>) cl.get("entities");
      if (entitiesList != null) {
        ArrayList<String> entities = new ArrayList<String>();

        for (Object obj : entitiesList) {
          if (obj instanceof String) {
            entities.add((String) obj);

            String split[] = ((String) obj).split(":");
            validEntities.add(split[0].toUpperCase());
          }
        }
        config_ts.entites = entities;
      }

      config_ts.reward = (Integer) cl.get("reward");
      temple_sacrifices.add(config_ts);
    }
    CivLog.info("Loaded " + temple_sacrifices.size() + " temple sacrifices.");
  }
Example #4
0
  public static void loadConfig(FileConfiguration cfg, Map<String, ConfigTownUpgrade> upgrades) {
    upgrades.clear();
    List<Map<?, ?>> culture_levels = cfg.getMapList("upgrades");
    for (Map<?, ?> level : culture_levels) {
      ConfigTownUpgrade town_upgrade = new ConfigTownUpgrade();

      town_upgrade.id = (String) level.get("id");
      town_upgrade.name = (String) level.get("name");
      town_upgrade.cost = (Double) level.get("cost");
      town_upgrade.action = (String) level.get("action");
      town_upgrade.require_upgrade = (String) level.get("require_upgrade");
      town_upgrade.require_tech = (String) level.get("require_tech");
      town_upgrade.require_structure = (String) level.get("require_structure");
      town_upgrade.category = (String) level.get("category");

      Integer categoryCount = categories.get(town_upgrade.category);
      if (categoryCount == null) {
        categories.put(town_upgrade.category.toLowerCase(), 1);
      } else {
        categories.put(town_upgrade.category.toLowerCase(), categoryCount + 1);
      }

      upgrades.put(town_upgrade.id, town_upgrade);
    }
    CivLog.info("Loaded " + upgrades.size() + " town upgrades.");
  }
Example #5
0
  public void setupLore(String id) {
    ConfigMission mission = CivSettings.missions.get(this.getId());

    if (mission == null) {
      CivLog.warning("Couldn't find mission with id:" + id + " to set the lore.");
      return;
    }

    for (String str : mission.description) {
      this.addLore(str);
    }
    this.addLore(CivColor.Yellow + mission.cost + " Coins.");
    this.addLore(CivColor.Gold + "Soulbound");
  }
  public static void init() throws SQLException {
    if (!SQL.hasTable(TABLE_NAME)) {
      String table_create =
          "CREATE TABLE "
              + SQL.tb_prefix
              + TABLE_NAME
              + " ("
              + "`id` int(11) unsigned NOT NULL auto_increment,"
              + "`town_id` int(11) unsigned DEFAULT 0,"
              + "`target_id` int(11) unsigned DEFAULT 0,"
              + "`time` long,"
              + "`playerName` mediumtext,"
              + "`missionName` mediumtext,"
              + "`result` mediumtext,"
              + "PRIMARY KEY (`id`)"
              + ")";

      SQL.makeTable(table_create);
      CivLog.info("Created " + TABLE_NAME + " table");
    } else {
      CivLog.info(TABLE_NAME + " table OK!");
    }
  }
Example #7
0
  @Override
  public void onDamage(
      EntityCreature e,
      DamageSource damagesource,
      PathfinderGoalSelector goalSelector,
      PathfinderGoalSelector targetSelector) {

    if (!(damagesource instanceof EntityDamageSource)) {
      return;
    }

    if (this.getLevel() == null) {
      this.setLevel(MobSpawner.CustomMobLevel.valueOf(getData("level")));
      if (this.getLevel() == null) {
        try {
          throw new CivException("Level was null after retry.");
        } catch (CivException e2) {
          CivLog.error("getData(level):" + getData("level"));
          e2.printStackTrace();
        }
      }
    }

    if (!angry) {
      angry = true;
      goalSelector.a(2, new PathfinderGoalMeleeAttack(e, EntityHuman.class, 1.0D, false));
      for (int i = 0; i < 4; i++) {
        try {
          this.minions.add(
              MobSpawner.spawnCustomMob(
                      MobSpawner.CustomMobType.ANGRYYOBO, this.getLevel(), getLocation(e))
                  .entity);
        } catch (CivException e1) {
          e1.printStackTrace();
        }
      }
    }
  }
Example #8
0
  public static void init() throws SQLException {
    if (!SQL.hasTable(TABLE_NAME)) {
      String table_create =
          "CREATE TABLE "
              + SQL.tb_prefix
              + TABLE_NAME
              + " ("
              + "`id` int(11) unsigned NOT NULL auto_increment,"
              + "`config_id` mediumtext,"
              + "`town_id` int(11),"
              + "`start_date` long NOT NULL,"
              + "`active` boolean DEFAULT false,"
              + "`component_vars` mediumtext,"
              + "`saved_messages` mediumtext,"
              + "PRIMARY KEY (`id`)"
              + ")";

      SQL.makeTable(table_create);
      CivLog.info("Created " + TABLE_NAME + " table");
    } else {
      SQL.makeCol("active", "boolean", TABLE_NAME);
    }
  }
Example #9
0
  public static void loadConfig(
      FileConfiguration cfg,
      String path,
      Map<String, ConfigBuildableInfo> structureMap,
      boolean isWonder) {
    structureMap.clear();
    List<Map<?, ?>> structures = cfg.getMapList(path);
    for (Map<?, ?> obj : structures) {
      ConfigBuildableInfo sinfo = new ConfigBuildableInfo();

      sinfo.id = (String) obj.get("id");
      sinfo.template_base_name = (String) obj.get("template");
      sinfo.templateYShift = (Integer) obj.get("template_y_shift");
      sinfo.displayName = (String) obj.get("displayName");
      sinfo.require_tech = (String) obj.get("require_tech");
      sinfo.require_upgrade = (String) obj.get("require_upgrade");
      sinfo.require_structure = (String) obj.get("require_structure");
      sinfo.check_event = (String) obj.get("check_event");
      sinfo.effect_event = (String) obj.get("effect_event");
      sinfo.update_event = (String) obj.get("update_event");
      sinfo.onBuild_event = (String) obj.get("onBuild_event");
      sinfo.limit = (Integer) obj.get("limit");
      // TODO handle signs
      sinfo.cost = (Double) obj.get("cost");
      sinfo.upkeep = (Double) obj.get("upkeep");
      sinfo.hammer_cost = (Double) obj.get("hammer_cost");
      sinfo.max_hitpoints = (Integer) obj.get("max_hitpoints");
      sinfo.destroyable = (Boolean) obj.get("destroyable");
      sinfo.allow_outside_town = (Boolean) obj.get("allow_outside_town");
      sinfo.regenRate = (Integer) obj.get("regen_rate");
      sinfo.isWonder = isWonder;
      sinfo.points = (Integer) obj.get("points");

      @SuppressWarnings("unchecked")
      List<Map<?, ?>> comps = (List<Map<?, ?>>) obj.get("components");
      if (comps != null) {
        for (Map<?, ?> compObj : comps) {

          HashMap<String, String> compMap = new HashMap<String, String>();
          for (Object key : compObj.keySet()) {
            compMap.put((String) key, (String) compObj.get(key));
          }

          sinfo.components.add(compMap);
        }
      }

      Boolean tileImprovement = (Boolean) obj.get("tile_improvement");
      if (tileImprovement != null && tileImprovement == true) {
        sinfo.tile_improvement = true;
      } else {
        sinfo.tile_improvement = false;
      }

      Boolean allowDemolish = (Boolean) obj.get("allow_demolish");
      if (allowDemolish == null || allowDemolish == true) {
        sinfo.allow_demolish = true;
      } else {
        sinfo.allow_demolish = false;
      }

      Boolean strategic = (Boolean) obj.get("strategic");
      if (strategic == null || strategic == false) {
        sinfo.strategic = false;
      } else {
        sinfo.strategic = true;
      }

      Boolean ignore_floating = (Boolean) obj.get("ignore_floating");
      if (ignore_floating != null) {
        sinfo.ignore_floating = ignore_floating;
      }

      Boolean has_template = (Boolean) obj.get("has_template");
      if (has_template != null) {
        sinfo.has_template = has_template;
      }

      if (isWonder) {
        sinfo.strategic = true;
      }

      structureMap.put(sinfo.id, sinfo);
    }
    CivLog.info("Loaded " + structureMap.size() + " structures.");
  }
Example #10
0
  public void createGoodieItemFrame(BlockCoord absCoord, int slotId, int direction) {
    if (slotId >= MAX_GOODIE_FRAMES) {
      return;
    }

    /*
     * Make sure there isn't another frame here. We have the position of the sign, but the entity's
     * position is the block it's attached to. We'll use the direction from the sign data to determine
     * which direction to look for the entity.
     */
    Block attachedBlock;
    BlockFace facingDirection;

    switch (direction) {
      case CivData.DATA_SIGN_EAST:
        attachedBlock = absCoord.getBlock().getRelative(BlockFace.WEST);
        facingDirection = BlockFace.EAST;
        break;
      case CivData.DATA_SIGN_WEST:
        attachedBlock = absCoord.getBlock().getRelative(BlockFace.EAST);
        facingDirection = BlockFace.WEST;
        break;
      case CivData.DATA_SIGN_NORTH:
        attachedBlock = absCoord.getBlock().getRelative(BlockFace.SOUTH);
        facingDirection = BlockFace.NORTH;
        break;
      case CivData.DATA_SIGN_SOUTH:
        attachedBlock = absCoord.getBlock().getRelative(BlockFace.NORTH);
        facingDirection = BlockFace.SOUTH;
        break;
      default:
        CivLog.error("Bad sign data for /itemframe sign in town hall.");
        return;
    }

    Block itemFrameBlock = absCoord.getBlock();
    if (ItemManager.getId(itemFrameBlock) != CivData.AIR) {
      ItemManager.setTypeId(itemFrameBlock, CivData.AIR);
    }

    ItemFrameStorage itemStore;
    ItemFrame frame = null;
    Entity entity = CivGlobal.getEntityAtLocation(absCoord.getBlock().getLocation());
    if (entity == null || (!(entity instanceof ItemFrame))) {
      itemStore = new ItemFrameStorage(attachedBlock.getLocation(), facingDirection);
    } else {
      try {
        frame = (ItemFrame) entity;
        itemStore = new ItemFrameStorage(frame, attachedBlock.getLocation());
      } catch (CivException e) {
        e.printStackTrace();
        return;
      }
      if (facingDirection != BlockFace.EAST) {
        itemStore.setFacingDirection(facingDirection);
      }
    }

    itemStore.setBuildable(this);
    goodieFrames.add(itemStore);
  }