コード例 #1
0
  public void changeToIslandInventory(PlayerInfo pi) {
    if (pi.isPlaying()) return;

    if (this.settings.getAllowContent()) {
      pi.setIsPlaying(true);
      return;
    }

    // save old inventory
    pi.setOldInventory(pi.getPlayer().getInventory().getContents());
    pi.setOldArmor(pi.getPlayer().getInventory().getArmorContents());
    pi.setOldHealth(pi.getPlayer().getHealth());
    pi.setOldFood(pi.getPlayer().getFoodLevel());
    pi.setOldLevel(pi.getPlayer().getLevel());
    pi.setOldExp(pi.getPlayer().getExp());

    // set island inventory
    pi.getPlayer().getInventory().setContents(pi.getIslandInventory());
    pi.getPlayer().getInventory().setArmorContents(pi.getIslandArmor());
    if (pi.getIslandHealth() <= 0) {
      pi.getPlayer().setHealth(pi.getPlayer().getMaxHealth());
    } else {
      pi.getPlayer().setHealth(pi.getIslandHealth());
    }

    if (pi.getIslandFood() <= 0) {
      pi.getPlayer().setFoodLevel(20);
    } else {
      pi.getPlayer().setHealth(pi.getIslandFood());
    }
    pi.getPlayer().setLevel(pi.getIslandLevel());
    pi.getPlayer().setExp(pi.getIslandExp());

    pi.setIsPlaying(true);
  }
コード例 #2
0
  public void savePlayerInfo(PlayerInfo pi) {
    YamlConfiguration yamlPlayerInfo = new YamlConfiguration();
    File filePlayerInfo = new File(this.directoryPlayers, pi.getPlayerName() + ".yml");

    // island info
    if (pi.getIslandInfo() != null) {
      yamlPlayerInfo.set(
          EnumPlayerConfig.ISLAND_NUMBER.getPath(), pi.getIslandInfo().getIslandNumber());
    }

    yamlPlayerInfo.set(EnumPlayerConfig.IS_PLAYING.getPath(), pi.isPlaying());
    yamlPlayerInfo.set(EnumPlayerConfig.IS_DEAD.getPath(), pi.isDead());
    yamlPlayerInfo.set(EnumPlayerConfig.ISLAND_FOOD.getPath(), "" + pi.getIslandFood());
    yamlPlayerInfo.set(EnumPlayerConfig.ISLAND_HEALTH.getPath(), "" + pi.getIslandHealth());
    yamlPlayerInfo.set(EnumPlayerConfig.ISLAND_EXP.getPath(), "" + pi.getIslandExp());
    yamlPlayerInfo.set(EnumPlayerConfig.ISLAND_LEVEL.getPath(), "" + pi.getIslandLevel());
    yamlPlayerInfo.set(
        EnumPlayerConfig.ISLAND_INVENTORY.getPath(),
        ItemParser.getListFromItemStackArray(pi.getIslandInventory()));
    yamlPlayerInfo.set(
        EnumPlayerConfig.ISLAND_ARMOR.getPath(),
        ItemParser.getListFromItemStackArray(pi.getIslandArmor()));
    yamlPlayerInfo.set(
        EnumPlayerConfig.OLD_LOCATION.getPath(),
        LocationParser.getStringFromLocation(pi.getOldLocation()));
    yamlPlayerInfo.set(EnumPlayerConfig.OLD_FOOD.getPath(), "" + pi.getOldFood());
    yamlPlayerInfo.set(EnumPlayerConfig.OLD_HEALTH.getPath(), "" + pi.getOldHealth());
    yamlPlayerInfo.set(EnumPlayerConfig.OLD_EXP.getPath(), "" + pi.getOldExp());
    yamlPlayerInfo.set(EnumPlayerConfig.OLD_LEVEL.getPath(), "" + pi.getOldLevel());
    yamlPlayerInfo.set(
        EnumPlayerConfig.OLD_INVENTORY.getPath(),
        ItemParser.getListFromItemStackArray(pi.getOldInventory()));
    yamlPlayerInfo.set(
        EnumPlayerConfig.OLD_ARMOR.getPath(),
        ItemParser.getListFromItemStackArray(pi.getOldArmor()));
    yamlPlayerInfo.set(EnumPlayerConfig.ISLAND_BUILTLIST.getPath(), pi.getBuildListNumbers());

    try {
      yamlPlayerInfo.save(filePlayerInfo);
    } catch (IOException e) {
      e.printStackTrace();
    }
  }