Exemple #1
0
  public void loadData() {
    try (Connection con = L2DatabaseFactory.getInstance().getConnection()) {
      PreparedStatement statement =
          con.prepareStatement("SELECT * FROM cursed_weapons WHERE itemId=?");
      statement.setInt(1, _itemId);
      ResultSet rset = statement.executeQuery();

      while (rset.next()) {
        _playerId = rset.getInt("playerId");
        _playerKarma = rset.getInt("playerKarma");
        _playerPkKills = rset.getInt("playerPkKills");
        _nbKills = rset.getInt("nbKills");
        _currentStage = rset.getInt("currentStage");
        _numberBeforeNextStage = rset.getInt("numberBeforeNextStage");
        _hungryTime = rset.getInt("hungryTime");
        _endTime = rset.getLong("endTime");

        reActivate(false);
      }

      rset.close();
      statement.close();
    } catch (Exception e) {
      _log.log(Level.WARNING, "Could not restore CursedWeapons data: " + e.getMessage(), e);
    }
  }
Exemple #2
0
  private static boolean changeCharAccessLevel(
      L2PcInstance targetPlayer, String player, L2PcInstance activeChar, int lvl) {
    if (targetPlayer != null) {
      targetPlayer.setAccessLevel(lvl);
      targetPlayer.logout();
      activeChar.sendMessage(targetPlayer.getName() + " has been banned.");
    } else {
      try (Connection con = L2DatabaseFactory.getInstance().getConnection()) {
        PreparedStatement statement =
            con.prepareStatement("UPDATE characters SET accesslevel=? WHERE char_name=?");
        statement.setInt(1, lvl);
        statement.setString(2, player);
        statement.execute();
        int count = statement.getUpdateCount();
        statement.close();

        if (count == 0) {
          activeChar.sendMessage("Character not found or access level unaltered.");
          return false;
        }

        activeChar.sendMessage(player + " now has an access level of " + lvl + ".");
      } catch (SQLException se) {
        activeChar.sendMessage("SQLException while changing character's access level");
        if (Config.DEBUG) se.printStackTrace();

        return false;
      }
    }
    return true;
  }
Exemple #3
0
  private static void jailOfflinePlayer(L2PcInstance activeChar, String name, int delay) {
    try (Connection con = L2DatabaseFactory.getInstance().getConnection()) {
      PreparedStatement statement =
          con.prepareStatement(
              "UPDATE characters SET x=?, y=?, z=?, punish_level=?, punish_timer=? WHERE char_name=?");
      statement.setInt(1, -114356);
      statement.setInt(2, -249645);
      statement.setInt(3, -2984);
      statement.setInt(4, L2PcInstance.PunishLevel.JAIL.value());
      statement.setLong(5, (delay > 0 ? delay * 60000L : 0));
      statement.setString(6, name);

      statement.execute();
      int count = statement.getUpdateCount();
      statement.close();

      if (count == 0) activeChar.sendMessage("Character not found!");
      else
        activeChar.sendMessage(
            name + " have been jailed for " + (delay > 0 ? delay + " minutes." : "ever!"));
    } catch (SQLException se) {
      activeChar.sendMessage("SQLException while jailing player");
      if (Config.DEBUG) se.printStackTrace();
    }
  }
Exemple #4
0
  private static void banChatOfflinePlayer(
      L2PcInstance activeChar, String name, int delay, boolean ban) {
    int level = 0;
    long value = 0;

    if (ban) {
      level = L2PcInstance.PunishLevel.CHAT.value();
      value = (delay > 0 ? delay * 60000L : 60000);
    } else {
      level = L2PcInstance.PunishLevel.NONE.value();
      value = 0;
    }

    try (Connection con = L2DatabaseFactory.getInstance().getConnection()) {
      PreparedStatement statement =
          con.prepareStatement(
              "UPDATE characters SET punish_level=?, punish_timer=? WHERE char_name=?");
      statement.setInt(1, level);
      statement.setLong(2, value);
      statement.setString(3, name);

      statement.execute();
      int count = statement.getUpdateCount();
      statement.close();

      if (count == 0) activeChar.sendMessage("Character isn't found.");
      else if (ban)
        activeChar.sendMessage(
            name + " is chat banned for " + (delay > 0 ? delay + " minutes." : "ever !"));
      else activeChar.sendMessage(name + "'s chat ban have been lifted.");
    } catch (SQLException se) {
      activeChar.sendMessage("SQLException while chat-banning player");
      if (Config.DEBUG) se.printStackTrace();
    }
  }
Exemple #5
0
 /**
  * Drop dynamic infos regarding CW for the given itemId.<br>
  * Use : in endOfLife() method.
  */
 private void removeFromDb() {
   try (Connection con = L2DatabaseFactory.getInstance().getConnection()) {
     // Delete datas
     PreparedStatement statement =
         con.prepareStatement("DELETE FROM cursed_weapons WHERE itemId = ?");
     statement.setInt(1, _itemId);
     statement.executeUpdate();
     statement.close();
   } catch (SQLException e) {
     _log.log(Level.SEVERE, "CursedWeapon: Failed to remove data: " + e.getMessage(), e);
   }
 }
Exemple #6
0
  private static final void load() {
    try (Connection con = L2DatabaseFactory.getInstance().getConnection()) {
      PreparedStatement statement =
          con.prepareStatement("SELECT * FROM castle_siege_guards WHERE isHired=1");
      ResultSet rs = statement.executeQuery();

      int npcId;
      int itemId;
      int x, y, z;

      // start index to begin the search for the itemId corresponding to this NPC :
      // a) skip unnecessary iterations in the search loop
      // b) avoid finding the wrong itemId whenever tickets of different spawn the same npc!
      int startindex = 0;

      while (rs.next()) {
        npcId = rs.getInt("npcId");
        x = rs.getInt("x");
        y = rs.getInt("y");
        z = rs.getInt("z");

        Castle castle = CastleManager.getInstance().getCastle(x, y, z);
        if (castle != null) startindex = 10 * (castle.getCastleId() - 1);

        // find the FIRST ticket itemId with spawns the saved NPC in the saved location
        for (int i = startindex; i < NPC_IDS.length; i++) {
          if (NPC_IDS[i] == npcId) // Find the index of the item used
          {
            // only handle tickets if a siege is not ongoing in this npc's castle
            if (castle != null && !(castle.getSiege().isInProgress())) {
              itemId = ITEM_IDS[i];
              // create the ticket in the gameworld
              ItemInstance dropticket =
                  new ItemInstance(IdFactory.getInstance().getNextId(), itemId);
              dropticket.setLocation(ItemInstance.ItemLocation.INVENTORY);
              dropticket.setDestroyProtected(true);
              dropticket.dropMe(null, x, y, z);
              L2World.getInstance().storeObject(dropticket);
              _droppedTickets.add(dropticket);
            }
            break;
          }
        }
      }
      rs.close();
      statement.close();
    } catch (Exception e) {
      _log.log(Level.WARNING, "Exception: loadMercenaryData(): " + e.getMessage(), e);
    }
    _log.info("MercTicketManager: Loaded " + _droppedTickets.size() + " tickets.");
  }
Exemple #7
0
  public void deleteMe(Forum f) {
    TopicBBSManager.getInstance().delTopic(this);
    f.rmTopicByID(getID());

    try (Connection con = L2DatabaseFactory.getInstance().getConnection()) {
      PreparedStatement statement =
          con.prepareStatement("DELETE FROM topic WHERE topic_id=? AND topic_forum_id=?");
      statement.setInt(1, getID());
      statement.setInt(2, f.getID());
      statement.execute();
      statement.close();
    } catch (Exception e) {
      _log.log(Level.WARNING, "Error while deleting topic: " + e.getMessage(), e);
    }
  }
Exemple #8
0
 /**
  * Update && save dynamic data (a CW must have been already inserted).<br>
  * Use : in the 1min overall task.
  */
 protected void updateData() {
   try (Connection con = L2DatabaseFactory.getInstance().getConnection()) {
     PreparedStatement statement =
         con.prepareStatement(
             "UPDATE cursed_weapons SET nbKills=?, currentStage=?, numberBeforeNextStage=?, hungryTime=?, endTime=? WHERE itemId=?");
     statement.setInt(1, _nbKills);
     statement.setInt(2, _currentStage);
     statement.setInt(3, _numberBeforeNextStage);
     statement.setInt(4, _hungryTime);
     statement.setLong(5, _endTime);
     statement.setInt(6, _itemId);
     statement.executeUpdate();
     statement.close();
   } catch (SQLException e) {
     _log.log(Level.SEVERE, "CursedWeapon: Failed to update data.", e);
   }
 }
  private void init() {
    try (Connection con = L2DatabaseFactory.getInstance().getConnection()) {
      PreparedStatement statement =
          con.prepareStatement("SELECT * from raidboss_spawnlist ORDER BY boss_id");
      ResultSet rset = statement.executeQuery();

      while (rset.next()) {
        final L2NpcTemplate template = getValidTemplate(rset.getInt("boss_id"));
        if (template != null) {
          final L2Spawn spawnDat = new L2Spawn(template);
          spawnDat.setLocx(rset.getInt("loc_x"));
          spawnDat.setLocy(rset.getInt("loc_y"));
          spawnDat.setLocz(rset.getInt("loc_z"));
          spawnDat.setHeading(rset.getInt("heading"));
          spawnDat.setRespawnMinDelay(rset.getInt("spawn_time"));
          spawnDat.setRespawnMaxDelay(rset.getInt("random_time"));

          addNewSpawn(
              spawnDat,
              rset.getLong("respawn_time"),
              rset.getDouble("currentHP"),
              rset.getDouble("currentMP"),
              false);
        } else {
          _log.warning(
              "RaidBossSpawnManager: Could not load raidboss #"
                  + rset.getInt("boss_id")
                  + " from DB");
        }
      }

      _log.info("RaidBossSpawnManager: Loaded " + _bosses.size() + " instances.");
      _log.info("RaidBossSpawnManager: Scheduled " + _schedules.size() + " instances.");

      rset.close();
      statement.close();
    } catch (SQLException e) {
      _log.warning("RaidBossSpawnManager: Couldnt load raidboss_spawnlist table.");
    } catch (Exception e) {
      _log.log(
          Level.WARNING, "Error while initializing RaidBossSpawnManager: " + e.getMessage(), e);
    }
  }
Exemple #10
0
 private void insertIntoDb() {
   try (Connection con = L2DatabaseFactory.getInstance().getConnection()) {
     PreparedStatement statement =
         con.prepareStatement(
             "INSERT INTO topic (topic_id,topic_forum_id,topic_name,topic_date,topic_ownername,topic_ownerid,topic_type,topic_reply) values (?,?,?,?,?,?,?,?)");
     statement.setInt(1, _id);
     statement.setInt(2, _forumId);
     statement.setString(3, _topicName);
     statement.setLong(4, _date);
     statement.setString(5, _ownerName);
     statement.setInt(6, _ownerId);
     statement.setInt(7, _type);
     statement.setInt(8, _cReply);
     statement.execute();
     statement.close();
   } catch (Exception e) {
     _log.log(Level.WARNING, "Error while saving new Topic to db " + e.getMessage(), e);
   }
 }
Exemple #11
0
 /**
  * Insert a new line with fresh informations.<br>
  * Use : activate() method.
  */
 private void insertData() {
   try (Connection con = L2DatabaseFactory.getInstance().getConnection()) {
     PreparedStatement statement =
         con.prepareStatement(
             "INSERT INTO cursed_weapons (itemId, playerId, playerKarma, playerPkKills, nbKills, currentStage, numberBeforeNextStage, hungryTime, endTime) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)");
     statement.setInt(1, _itemId);
     statement.setInt(2, _playerId);
     statement.setInt(3, _playerKarma);
     statement.setInt(4, _playerPkKills);
     statement.setInt(5, _nbKills);
     statement.setInt(6, _currentStage);
     statement.setInt(7, _numberBeforeNextStage);
     statement.setInt(8, _hungryTime);
     statement.setLong(9, _endTime);
     statement.executeUpdate();
     statement.close();
   } catch (SQLException e) {
     _log.log(Level.SEVERE, "CursedWeapon: Failed to insert data.", e);
   }
 }
Exemple #12
0
  public void deleteSpawn(L2Spawn spawn, boolean updateDb) {
    if (!_spawntable.remove(spawn)) return;

    if (updateDb) {
      try (Connection con = L2DatabaseFactory.getInstance().getConnection()) {
        PreparedStatement statement =
            con.prepareStatement(
                "DELETE FROM spawnlist WHERE locx=? AND locy=? AND locz=? AND npc_templateid=? AND heading=?");
        statement.setInt(1, spawn.getLocx());
        statement.setInt(2, spawn.getLocy());
        statement.setInt(3, spawn.getLocz());
        statement.setInt(4, spawn.getNpcId());
        statement.setInt(5, spawn.getHeading());
        statement.execute();
        statement.close();
      } catch (Exception e) {
        // problem with deleting spawn
        _log.warning("SpawnTable: Spawn " + spawn + " could not be removed from DB: " + e);
      }
    }
  }
Exemple #13
0
 private static void unjailOfflinePlayer(L2PcInstance activeChar, String name) {
   try (Connection con = L2DatabaseFactory.getInstance().getConnection()) {
     PreparedStatement statement =
         con.prepareStatement(
             "UPDATE characters SET x=?, y=?, z=?, punish_level=?, punish_timer=? WHERE char_name=?");
     statement.setInt(1, 17836);
     statement.setInt(2, 170178);
     statement.setInt(3, -3507);
     statement.setInt(4, 0);
     statement.setLong(5, 0);
     statement.setString(6, name);
     statement.execute();
     int count = statement.getUpdateCount();
     statement.close();
     if (count == 0) activeChar.sendMessage("Character isn't found.");
     else activeChar.sendMessage(name + " have been unjailed.");
   } catch (SQLException se) {
     activeChar.sendMessage("SQLException while jailing player");
     if (Config.DEBUG) se.printStackTrace();
   }
 }
Exemple #14
0
  public void addNewSpawn(L2Spawn spawn, boolean storeInDb) {
    _spawntable.add(spawn);

    if (storeInDb) {
      try (Connection con = L2DatabaseFactory.getInstance().getConnection()) {
        PreparedStatement statement =
            con.prepareStatement(
                "INSERT INTO spawnlist (npc_templateid,locx,locy,locz,heading,respawn_delay) values(?,?,?,?,?,?)");
        statement.setInt(1, spawn.getNpcId());
        statement.setInt(2, spawn.getLocx());
        statement.setInt(3, spawn.getLocy());
        statement.setInt(4, spawn.getLocz());
        statement.setInt(5, spawn.getHeading());
        statement.setInt(6, spawn.getRespawnDelay() / 1000);
        statement.execute();
        statement.close();
      } catch (Exception e) {
        // problem with storing spawn
        _log.warning("SpawnTable: Could not store spawn in the DB:" + e);
      }
    }
  }
  private void updateDb() {
    try (Connection con = L2DatabaseFactory.getInstance().getConnection()) {
      PreparedStatement statement =
          con.prepareStatement(
              "UPDATE raidboss_spawnlist SET respawn_time = ?, currentHP = ?, currentMP = ? WHERE boss_id = ?");

      for (Integer bossId : _storedInfo.keySet()) {
        if (bossId == null) continue;

        final L2RaidBossInstance boss = _bosses.get(bossId);
        if (boss == null) continue;

        if (boss.getRaidStatus().equals(StatusEnum.ALIVE)) updateStatus(boss, false);

        final StatsSet info = _storedInfo.get(bossId);
        if (info == null) continue;

        try {
          statement.setLong(1, info.getLong("respawnTime"));
          statement.setDouble(2, info.getDouble("currentHP"));
          statement.setDouble(3, info.getDouble("currentMP"));
          statement.setInt(4, bossId);
          statement.executeUpdate();
          statement.clearParameters();
        } catch (SQLException e) {
          _log.log(
              Level.WARNING,
              "RaidBossSpawnManager: Couldnt update raidboss_spawnlist table " + e.getMessage(),
              e);
        }
      }
      statement.close();
    } catch (SQLException e) {
      _log.log(
          Level.WARNING,
          "SQL error while updating RaidBoss spawn to database: " + e.getMessage(),
          e);
    }
  }
  public void deleteSpawn(L2Spawn spawnDat, boolean updateDb) {
    if (spawnDat == null) return;

    final int bossId = spawnDat.getNpcId();
    if (!_spawns.containsKey(bossId)) return;

    SpawnTable.getInstance().deleteSpawn(spawnDat, false);
    _spawns.remove(bossId);

    if (_bosses.containsKey(bossId)) _bosses.remove(bossId);

    if (_schedules.containsKey(bossId)) {
      final ScheduledFuture<?> f = _schedules.remove(bossId);
      f.cancel(true);
    }

    if (_storedInfo.containsKey(bossId)) _storedInfo.remove(bossId);

    if (updateDb) {
      try (Connection con = L2DatabaseFactory.getInstance().getConnection()) {
        PreparedStatement statement =
            con.prepareStatement("DELETE FROM raidboss_spawnlist WHERE boss_id=?");
        statement.setInt(1, bossId);
        statement.execute();
        statement.close();
      } catch (Exception e) {
        // problem with deleting spawn
        _log.log(
            Level.WARNING,
            "RaidBossSpawnManager: Could not remove raidboss #"
                + bossId
                + " from DB: "
                + e.getMessage(),
            e);
      }
    }
  }
Exemple #17
0
  private void fillSpawnTable() {
    try (Connection con = L2DatabaseFactory.getInstance().getConnection()) {
      PreparedStatement statement = con.prepareStatement("SELECT * FROM spawnlist");
      ResultSet rset = statement.executeQuery();

      L2Spawn spawnDat;
      L2NpcTemplate template1;

      while (rset.next()) {
        template1 = NpcTable.getInstance().getTemplate(rset.getInt("npc_templateid"));
        if (template1 != null) {
          if (template1.isType("L2SiegeGuard")) {
            // Don't spawn guards, they're spawned during castle sieges.
          } else if (template1.isType("L2RaidBoss")) {
            // Don't spawn raidbosses ; raidbosses are supposed to be loaded in another table !
            _log.warning(
                "SpawnTable: RB ("
                    + template1.getIdTemplate()
                    + ") is in regular spawnlist, move it in raidboss_spawnlist.");
          } else if (!Config.ALLOW_CLASS_MASTERS && template1.isType("L2ClassMaster")) {
            // Dont' spawn class masters (if config is setuped to false).
          } else if (!Config.WYVERN_ALLOW_UPGRADER && template1.isType("L2WyvernManager")) {
            // Dont' spawn wyvern managers (if config is setuped to false).
          } else {
            spawnDat = new L2Spawn(template1);
            spawnDat.setLocx(rset.getInt("locx"));
            spawnDat.setLocy(rset.getInt("locy"));
            spawnDat.setLocz(rset.getInt("locz"));
            spawnDat.setHeading(rset.getInt("heading"));
            spawnDat.setRespawnDelay(rset.getInt("respawn_delay"));

            switch (rset.getInt("periodOfDay")) {
              case 0: // default
                spawnDat.init();
                _npcSpawnCount++;
                break;
              case 1: // Day
                DayNightSpawnManager.getInstance().addDayCreature(spawnDat);
                _npcSpawnCount++;
                break;
              case 2: // Night
                DayNightSpawnManager.getInstance().addNightCreature(spawnDat);
                _npcSpawnCount++;
                break;
            }

            _spawntable.add(spawnDat);
          }
        } else {
          _log.warning(
              "SpawnTable: Data missing in NPC table for ID: "
                  + rset.getInt("npc_templateid")
                  + ".");
        }
      }
      rset.close();
      statement.close();
    } catch (Exception e) {
      // problem with initializing spawn, go to next one
      _log.warning("SpawnTable: Spawn could not be initialized: " + e);
    }

    _log.config("SpawnTable: Loaded " + _spawntable.size() + " Npc Spawn Locations.");

    if (Config.DEBUG)
      _log.fine(
          "SpawnTable: Spawning completed, total number of NPCs in the world: " + _npcSpawnCount);
  }
  public void addNewSpawn(
      L2Spawn spawnDat, long respawnTime, double currentHP, double currentMP, boolean storeInDb) {
    if (spawnDat == null) return;

    final int bossId = spawnDat.getNpcId();
    if (_spawns.containsKey(bossId)) return;

    final long time = Calendar.getInstance().getTimeInMillis();

    SpawnTable.getInstance().addNewSpawn(spawnDat, false);

    if (respawnTime == 0L || (time > respawnTime)) {
      L2RaidBossInstance raidboss = null;

      if (bossId == 25328) raidboss = DayNightSpawnManager.getInstance().handleBoss(spawnDat);
      else raidboss = (L2RaidBossInstance) spawnDat.doSpawn();

      if (raidboss != null) {
        currentHP = (currentHP == 0) ? raidboss.getMaxHp() : currentHP;
        currentMP = (currentMP == 0) ? raidboss.getMaxMp() : currentMP;

        raidboss.setCurrentHp(currentHP);
        raidboss.setCurrentMp(currentMP);
        raidboss.setRaidStatus(StatusEnum.ALIVE);

        _bosses.put(bossId, raidboss);

        final StatsSet info = new StatsSet();
        info.set("currentHP", currentHP);
        info.set("currentMP", currentMP);
        info.set("respawnTime", 0L);

        _storedInfo.put(bossId, info);
      }
    } else {
      long spawnTime = respawnTime - Calendar.getInstance().getTimeInMillis();
      _schedules.put(
          bossId,
          ThreadPoolManager.getInstance().scheduleGeneral(new spawnSchedule(bossId), spawnTime));
    }

    _spawns.put(bossId, spawnDat);

    if (storeInDb) {
      try (Connection con = L2DatabaseFactory.getInstance().getConnection()) {
        PreparedStatement statement =
            con.prepareStatement(
                "INSERT INTO raidboss_spawnlist (boss_id,loc_x,loc_y,loc_z,heading,respawn_time,currentHp,currentMp) values(?,?,?,?,?,?,?,?)");
        statement.setInt(1, spawnDat.getNpcId());
        statement.setInt(2, spawnDat.getLocx());
        statement.setInt(3, spawnDat.getLocy());
        statement.setInt(4, spawnDat.getLocz());
        statement.setInt(5, spawnDat.getHeading());
        statement.setLong(6, respawnTime);
        statement.setDouble(7, currentHP);
        statement.setDouble(8, currentMP);
        statement.execute();
        statement.close();
      } catch (Exception e) {
        // problem with storing spawn
        _log.log(
            Level.WARNING,
            "RaidBossSpawnManager: Could not store raidboss #"
                + bossId
                + " in the DB:"
                + e.getMessage(),
            e);
      }
    }
  }
  public boolean useAdminCommand(String command, L2PcInstance activeChar) {
    if (command.equals("admin_current_player")) {
      showCharacterInfo(activeChar, null);
    } else if ((command.startsWith("admin_character_list"))
        || (command.startsWith("admin_character_info"))) {
      try {
        String val = command.substring(21);
        L2PcInstance target = L2World.getInstance().getPlayer(val);
        if (target != null) showCharacterInfo(activeChar, target);
        else activeChar.sendPacket(new SystemMessage(SystemMessageId.CHARACTER_DOES_NOT_EXIST));
      } catch (StringIndexOutOfBoundsException e) {
        activeChar.sendMessage(385);
      }
    } else if (command.startsWith("admin_show_characters")) {
      try {
        String val = command.substring(22);
        int page = Integer.parseInt(val);
        listCharacters(activeChar, page);
      } catch (StringIndexOutOfBoundsException e) {
        // Case of empty page number
        activeChar.sendMessage(421);
      }
    } else if (command.startsWith("admin_find_character")) {
      try {
        String val = command.substring(21);
        findCharacter(activeChar, val);
      } catch (StringIndexOutOfBoundsException e) { // Case of empty character name
        activeChar.sendMessage(392);
        listCharacters(activeChar, 0);
      }
    } else if (command.startsWith("admin_find_ip")) {
      try {
        String val = command.substring(14);
        findCharactersPerIp(activeChar, val);
      } catch (Exception e) { // Case of empty or malformed IP number
        activeChar.sendMessage(393);
        listCharacters(activeChar, 0);
      }
    } else if (command.startsWith("admin_find_account")) {
      try {
        String val = command.substring(19);
        findCharactersPerAccount(activeChar, val);
      } catch (Exception e) { // Case of empty or malformed player name
        activeChar.sendMessage(391);
        listCharacters(activeChar, 0);
      }
    } else if (command.equals("admin_edit_character")) editCharacter(activeChar);
    // Karma control commands
    else if (command.equals("admin_nokarma")) setTargetKarma(activeChar, 0);
    else if (command.startsWith("admin_setkarma")) {
      try {
        String val = command.substring(15);
        int karma = Integer.parseInt(val);
        setTargetKarma(activeChar, karma);
      } catch (Exception e) {
        if (Config.DEVELOPER) _log.warning("Set karma error: " + e);
        activeChar.sendMessage(419);
      }
    } else if (command.startsWith("admin_setfame")) {
      try {
        String val = command.substring(14);
        int fame = Integer.parseInt(val);
        L2Object target = activeChar.getTarget();
        if (target instanceof L2PcInstance) {
          L2PcInstance player = (L2PcInstance) target;
          player.setFame(fame);
          player.sendPacket(new UserInfo(player));
          player.sendPacket(new ExBrExtraUserInfo(player));
          L2CoreMessage cm = new L2CoreMessage(MessageTable.Messages[261]);
          cm.addNumber(fame);
          cm.sendMessage(player);
        } else {
          activeChar.sendPacket(new SystemMessage(SystemMessageId.INCORRECT_TARGET));
        }
      } catch (Exception e) {
        if (Config.DEVELOPER) _log.warning("Set Fame error: " + e);
        activeChar.sendMessage(316);
      }
    } else if (command.startsWith("admin_save_modifications")) {
      try {
        String val = command.substring(24);
        adminModifyCharacter(activeChar, val);
      } catch (StringIndexOutOfBoundsException e) { // Case of empty character name
        activeChar.sendMessage(113);
        listCharacters(activeChar, 0);
      }
    } else if (command.startsWith("admin_rec")) {
      try {
        String val = command.substring(10);
        int recVal = Integer.parseInt(val);
        L2Object target = activeChar.getTarget();
        L2PcInstance player = null;
        if (target instanceof L2PcInstance) {
          player = (L2PcInstance) target;
        } else {
          return false;
        }
        player.setRecomHave(recVal);
        player.sendMessage(528);
        player.broadcastUserInfo();
      } catch (Exception e) {
        activeChar.sendMessage(414);
      }
    } else if (command.startsWith("admin_setclass")) {
      try {
        String val = command.substring(15);
        int classidval = Integer.parseInt(val);
        L2Object target = activeChar.getTarget();
        L2PcInstance player = null;
        if (target instanceof L2PcInstance) player = (L2PcInstance) target;
        else return false;
        boolean valid = false;
        for (ClassId classid : ClassId.values()) if (classidval == classid.getId()) valid = true;
        if (valid && (player.getClassId().getId() != classidval)) {
          player.setClassId(classidval);
          if (!player.isSubClassActive()) player.setBaseClass(classidval);
          String newclass = player.getTemplate().className;
          player.store();
          L2CoreMessage cm = new L2CoreMessage(MessageTable.Messages[14]);
          cm.addString(newclass);
          cm.sendMessage(player);
          player.broadcastUserInfo();
          cm = new L2CoreMessage(MessageTable.Messages[670]);
          cm.addString(player.getName());
          cm.addString(newclass);
          cm.sendMessage(activeChar);
        }
        activeChar.sendMessage(418);
      } catch (StringIndexOutOfBoundsException e) {
        AdminHelpPage.showHelpPage(activeChar, "charclasses.htm");
      }
    } else if (command.startsWith("admin_settitle")) {
      try {
        String val = command.substring(15);
        L2Object target = activeChar.getTarget();
        L2PcInstance player = null;
        if (target instanceof L2PcInstance) {
          player = (L2PcInstance) target;
        } else {
          return false;
        }
        player.setTitle(val);
        player.sendMessage(644);
        player.broadcastTitleInfo();
      } catch (StringIndexOutOfBoundsException e) { // Case of empty character title
        activeChar.sendMessage(584);
      }
    } else if (command.startsWith("admin_changename")) {
      try {
        String val = command.substring(17);
        L2Object target = activeChar.getTarget();
        L2PcInstance player = null;
        if (target instanceof L2PcInstance) {
          player = (L2PcInstance) target;
        } else {
          return false;
        }
        L2World.getInstance().removeFromAllPlayers(player);
        player.setName(val);
        player.store();
        L2World.getInstance().addToAllPlayers(player);

        player.sendMessage(623);
        player.broadcastUserInfo();

        if (player.isInParty()) {
          // Delete party window for other party members
          player.getParty().broadcastToPartyMembers(player, new PartySmallWindowDeleteAll());
          for (L2PcInstance member : player.getParty().getPartyMembers()) {
            // And re-add
            if (member != player)
              member.sendPacket(new PartySmallWindowAll(member, player.getParty()));
          }
        }
        if (player.getClan() != null) {
          player.getClan().broadcastClanStatus();
        }

        RegionBBSManager.getInstance().changeCommunityBoard();
      } catch (StringIndexOutOfBoundsException e) { // Case of empty character name
        activeChar.sendMessage(420);
      }
    } else if (command.startsWith("admin_setsex")) {
      L2Object target = activeChar.getTarget();
      L2PcInstance player = null;
      if (target instanceof L2PcInstance) {
        player = (L2PcInstance) target;
      } else {
        return false;
      }
      player.getAppearance().setSex(player.getAppearance().getSex() ? false : true);
      player.sendMessage(621);
      player.broadcastUserInfo();
      player.decayMe();
      player.spawnMe(player.getX(), player.getY(), player.getZ());
    } else if (command.startsWith("admin_setcolor")) {
      try {
        String val = command.substring(15);
        L2Object target = activeChar.getTarget();
        L2PcInstance player = null;
        if (target instanceof L2PcInstance) {
          player = (L2PcInstance) target;
        } else {
          return false;
        }
        player.getAppearance().setNameColor(Integer.decode("0x" + val));
        player.sendMessage(622);
        player.broadcastUserInfo();
      } catch (Exception e) { // Case of empty color or invalid hex string
        activeChar.sendMessage(583);
      }
    } else if (command.startsWith("admin_fullfood")) {
      L2Object target = activeChar.getTarget();
      if (target instanceof L2PetInstance) {
        L2PetInstance targetPet = (L2PetInstance) target;
        targetPet.setCurrentFed(targetPet.getMaxFed());
        targetPet
            .getOwner()
            .sendPacket(new SetSummonRemainTime(targetPet.getMaxFed(), targetPet.getCurrentFed()));
      } else activeChar.sendPacket(new SystemMessage(SystemMessageId.INCORRECT_TARGET));
    } else if (command.startsWith("admin_unpenalty")) {
      try {
        StringTokenizer st = new StringTokenizer(command, " ");
        if (st.countTokens() != 3) {
          activeChar.sendMessage(364);
          return false;
        }

        st.nextToken();

        boolean changeCreateExpiryTime = st.nextToken().equalsIgnoreCase("create");

        String playerName = st.nextToken();
        L2PcInstance player = null;
        player = L2World.getInstance().getPlayer(playerName);

        if (player == null) {
          Connection con = L2DatabaseFactory.getInstance().getConnection();
          PreparedStatement ps =
              con.prepareStatement(
                  "UPDATE characters SET "
                      + (changeCreateExpiryTime
                          ? "clan_create_expiry_time"
                          : "clan_join_expiry_time")
                      + " WHERE char_name=? LIMIT 1");

          ps.setString(1, playerName);
          ps.execute();
        } else {
          // removing penalty
          if (changeCreateExpiryTime) player.setClanCreateExpiryTime(0);
          else player.setClanJoinExpiryTime(0);
        }

        L2CoreMessage cm = new L2CoreMessage(MessageTable.Messages[470]);
        cm.addString(playerName);
        cm.sendMessage(activeChar);
      } catch (Exception e) {
        e.printStackTrace();
      }
    } else if (command.startsWith("admin_find_dualbox")) {
      int multibox = 2;
      try {
        String val = command.substring(19);
        multibox = Integer.parseInt(val);
        if (multibox < 1) {
          activeChar.sendMessage(97);
          return false;
        }
      } catch (Exception e) {
      }
      findDualbox(activeChar, multibox);
    }

    return true;
  }
Exemple #20
0
  /**
   * This method is used to destroy a CW.<br>
   * It manages following states :
   *
   * <ul>
   *   <li><u>item on a online player</u> : drops the CW from inventory, and set back ancient
   *       pk/karma values.
   *   <li><u>item on a offline player</u> : make SQL operations in order to drop item from
   *       inventory.
   *   <li><u>item on ground</u> : destroys the item directly.
   * </ul>
   *
   * For all cases, a message is broadcasted, and the different states are reinitialized.
   */
  public void endOfLife() {
    if (_isActivated) {
      // Player is online ; unequip weapon && destroy it.
      if (_player != null && _player.isOnline()) {
        _log.info(_name + " being removed online.");

        _player.abortAttack();

        _player.setKarma(_playerKarma);
        _player.setPkKills(_playerPkKills);
        _player.setCursedWeaponEquippedId(0);
        removeDemonicSkills();

        // Unequip && remove.
        _player.useEquippableItem(_item, true);
        _player.destroyItemByItemId("CW", _itemId, 1, _player, false);

        _player.broadcastUserInfo();

        _player.store();
      }
      // Player is offline ; make only SQL operations.
      else {
        _log.info(_name + " being removed offline.");

        try (Connection con = L2DatabaseFactory.getInstance().getConnection()) {
          // Delete the item
          PreparedStatement statement =
              con.prepareStatement("DELETE FROM items WHERE owner_id=? AND item_id=?");
          statement.setInt(1, _playerId);
          statement.setInt(2, _itemId);
          if (statement.executeUpdate() != 1)
            _log.warning("Error while deleting itemId " + _itemId + " from userId " + _playerId);

          statement.close();

          // Restore the karma and PK kills.
          statement =
              con.prepareStatement("UPDATE characters SET karma=?, pkkills=? WHERE obj_id=?");
          statement.setInt(1, _playerKarma);
          statement.setInt(2, _playerPkKills);
          statement.setInt(3, _playerId);
          if (statement.executeUpdate() != 1)
            _log.warning("Error while updating karma & pkkills for userId " + _playerId);

          statement.close();
        } catch (Exception e) {
          _log.log(Level.WARNING, "Could not delete : " + e.getMessage(), e);
        }
      }
    } else {
      // This CW is in the inventory of someone who has another cursed weapon equipped.
      if (_player != null && _player.getInventory().getItemByItemId(_itemId) != null) {
        _player.destroyItemByItemId("CW", _itemId, 1, _player, false);
        _log.info(_name + " item has been assimilated.");
      }
      // This CW is on the ground.
      else if (_item != null) {
        _item.decayMe();
        _log.info(_name + " item has been removed from world.");
      }
    }

    // Drop tasks.
    cancelDailyTimerTask();
    cancelOverallTimerTask();
    cancelDropTimerTask();

    // Delete infos from table, if any.
    removeFromDb();

    // Inform all ppl.
    Broadcast.toAllOnlinePlayers(
        SystemMessage.getSystemMessage(SystemMessageId.S1_HAS_DISAPPEARED).addItemName(_itemId));

    // Reset state.
    _player = null;
    _item = null;

    _isActivated = false;
    _isDropped = false;

    _nbKills = 0;
    _currentStage = 1;
    _numberBeforeNextStage = 0;

    _hungryTime = 0;
    _endTime = 0;

    _playerId = 0;
    _playerKarma = 0;
    _playerPkKills = 0;
  }