123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158 |
- /*
- * Copyright (C) 2004-2015 L2J Server
- *
- * This file is part of L2J Server.
- *
- * L2J Server is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * L2J Server is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
- package com.l2jserver.gameserver.communitybbs.Manager;
- import java.sql.Connection;
- import java.sql.ResultSet;
- import java.sql.Statement;
- import java.util.List;
- import java.util.concurrent.CopyOnWriteArrayList;
- import java.util.logging.Level;
- import java.util.logging.Logger;
- import com.l2jserver.commons.database.pool.impl.ConnectionFactory;
- import com.l2jserver.gameserver.communitybbs.BB.Forum;
- import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
- public class ForumsBBSManager extends BaseBBSManager
- {
- private static Logger _log = Logger.getLogger(ForumsBBSManager.class.getName());
- private final List<Forum> _table = new CopyOnWriteArrayList<>();
- private int _lastid = 1;
-
- /**
- * Instantiates a new forums bbs manager.
- */
- protected ForumsBBSManager()
- {
- try (Connection con = ConnectionFactory.getInstance().getConnection();
- Statement s = con.createStatement();
- ResultSet rs = s.executeQuery("SELECT forum_id FROM forums WHERE forum_type = 0"))
- {
- while (rs.next())
- {
- int forumId = rs.getInt("forum_id");
- Forum f = new Forum(forumId, null);
- addForum(f);
- }
- }
- catch (Exception e)
- {
- _log.log(Level.WARNING, "Data error on Forum (root): " + e.getMessage(), e);
- }
- }
-
- /**
- * Inits the root.
- */
- public void initRoot()
- {
- _table.forEach(f -> f.vload());
- _log.info("Loaded " + _table.size() + " forums. Last forum id used: " + _lastid);
- }
-
- /**
- * Adds the forum.
- * @param ff the forum
- */
- public void addForum(Forum ff)
- {
- if (ff == null)
- {
- return;
- }
-
- _table.add(ff);
-
- if (ff.getID() > _lastid)
- {
- _lastid = ff.getID();
- }
- }
-
- @Override
- public void parsecmd(String command, L2PcInstance activeChar)
- {
- }
-
- /**
- * Gets the forum by name.
- * @param name the forum name
- * @return the forum by name
- */
- public Forum getForumByName(String name)
- {
- return _table.stream().filter(f -> f.getName().equals(name)).findFirst().orElse(null);
- }
-
- /**
- * Creates the new forum.
- * @param name the forum name
- * @param parent the parent forum
- * @param type the forum type
- * @param perm the perm
- * @param oid the oid
- * @return the new forum
- */
- public Forum createNewForum(String name, Forum parent, int type, int perm, int oid)
- {
- Forum forum = new Forum(name, parent, type, perm, oid);
- forum.insertIntoDb();
- return forum;
- }
-
- /**
- * Gets the a new Id.
- * @return the a new Id
- */
- public int getANewID()
- {
- return ++_lastid;
- }
-
- /**
- * Gets the forum by Id.
- * @param idf the the forum Id
- * @return the forum by Id
- */
- public Forum getForumByID(int idf)
- {
- return _table.stream().filter(f -> f.getID() == idf).findFirst().orElse(null);
- }
-
- @Override
- public void parsewrite(String ar1, String ar2, String ar3, String ar4, String ar5, L2PcInstance activeChar)
- {
-
- }
-
- /**
- * Gets the single instance of ForumsBBSManager.
- * @return single instance of ForumsBBSManager
- */
- public static ForumsBBSManager getInstance()
- {
- return SingletonHolder._instance;
- }
-
- private static class SingletonHolder
- {
- protected static final ForumsBBSManager _instance = new ForumsBBSManager();
- }
- }
|