/* * 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.taskmanager.tasks; import java.sql.Connection; import java.sql.PreparedStatement; import com.l2jserver.Config; import com.l2jserver.L2DatabaseFactory; import com.l2jserver.gameserver.model.L2World; import com.l2jserver.gameserver.model.actor.instance.L2PcInstance; import com.l2jserver.gameserver.network.serverpackets.ExWorldChatCnt; import com.l2jserver.gameserver.taskmanager.Task; import com.l2jserver.gameserver.taskmanager.TaskManager; import com.l2jserver.gameserver.taskmanager.TaskManager.ExecutedTask; import com.l2jserver.gameserver.taskmanager.TaskTypes; public class TaskDailyWorldChatPointReset extends Task { private static final String NAME = "daily_world_chat_reset"; @Override public String getName() { return NAME; } @Override public void onTimeElapsed(ExecutedTask task) { // Update data for offline players. try (Connection con = L2DatabaseFactory.getInstance().getConnection(); PreparedStatement ps = con.prepareStatement("UPDATE character_variables SET val = ? WHERE var = ?")) { ps.setInt(1, Config.WORLD_CHAT_POINTS_PER_DAY); ps.setString(2, L2PcInstance.WORLD_CHAT_VARIABLE_NAME); ps.executeUpdate(); } catch (Exception e) { _log.severe(getClass().getSimpleName() + ": Could not reset daily world chat points: " + e); } // Update data for online players. L2World.getInstance().getPlayers().stream().forEach(player -> { player.setWorldChatPoints(Config.WORLD_CHAT_POINTS_PER_DAY); player.sendPacket(new ExWorldChatCnt(player)); player.getVariables().storeMe(); }); _log.info("Daily world chat points has been resetted."); } @Override public void initializate() { TaskManager.addUniqueTask(getName(), TaskTypes.TYPE_GLOBAL_TASK, "1", Config.WORLD_CHAT_RESET_TIME, ""); } }