Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Index: java/com/l2jserver/gameserver/ThreadPoolManager.java
- ===================================================================
- --- java/com/l2jserver/gameserver/ThreadPoolManager.java (revision 5685)
- +++ java/com/l2jserver/gameserver/ThreadPoolManager.java (working copy)
- @@ -190,6 +190,7 @@
- }
- catch (RejectedExecutionException e)
- {
- + _log.info("Ignorado: " + initial + " " + delay);
- return null; /* shutdown, ignore */
- }
- }
- Index: java/com/l2jserver/gameserver/taskmanager/TaskTypes.java
- ===================================================================
- --- java/com/l2jserver/gameserver/taskmanager/TaskTypes.java (revision 5685)
- +++ java/com/l2jserver/gameserver/taskmanager/TaskTypes.java (working copy)
- @@ -25,5 +25,6 @@
- TYPE_FIXED_SHEDULED,
- TYPE_GLOBAL_TASK,
- TYPE_STARTUP,
- - TYPE_SPECIAL
- + TYPE_SPECIAL,
- + TYPE_SCHEDULED_PER_DAY // Por Kimeraweb
- }
- Index: java/com/l2jserver/gameserver/taskmanager/TaskManager.java
- ===================================================================
- --- java/com/l2jserver/gameserver/taskmanager/TaskManager.java (revision 5685)
- +++ java/com/l2jserver/gameserver/taskmanager/TaskManager.java (working copy)
- @@ -38,6 +38,8 @@
- import com.l2jserver.gameserver.taskmanager.tasks.TaskCleanUp;
- import com.l2jserver.gameserver.taskmanager.tasks.TaskDailySkillReuseClean;
- import com.l2jserver.gameserver.taskmanager.tasks.TaskGlobalVariablesSave;
- +import com.l2jserver.gameserver.taskmanager.tasks.TaskHappyHourEnd;
- +import com.l2jserver.gameserver.taskmanager.tasks.TaskHappyHourStart;
- import com.l2jserver.gameserver.taskmanager.tasks.TaskJython;
- import com.l2jserver.gameserver.taskmanager.tasks.TaskOlympiadSave;
- import com.l2jserver.gameserver.taskmanager.tasks.TaskRaidPointsReset;
- @@ -195,6 +197,8 @@
- registerTask(new TaskScript());
- registerTask(new TaskSevenSignsUpdate());
- registerTask(new TaskShutdown());
- + registerTask(new TaskHappyHourStart()); // por Kimeraweb
- + registerTask(new TaskHappyHourEnd()); // por Kimeraweb
- }
- public void registerTask(Task task)
- @@ -315,8 +319,42 @@
- }
- task.scheduled = scheduler.scheduleGeneralAtFixedRate(task, delay, interval);
- return true;
- +
- +
- + // Por Kimeraweb
- + case TYPE_SCHEDULED_PER_DAY:
- + String[] hour_spd = task.getParams()[1].split(":");
- + if (hour_spd.length != 3)
- + {
- + _log.warning("Task " + task.getId() + " no esta correctamente formateado.");
- + return false;
- + }
- +
- + // Convierto la hora programada a un objeto Calendar
- + Calendar scheduledTime = Calendar.getInstance();
- + scheduledTime.set(Calendar.HOUR_OF_DAY, Integer.parseInt(hour_spd[0]));
- + scheduledTime.set(Calendar.MINUTE, Integer.parseInt(hour_spd[1]));
- + scheduledTime.set(Calendar.SECOND, Integer.parseInt(hour_spd[2]));
- +
- + long timeLeft = scheduledTime.getTimeInMillis() - System.currentTimeMillis();
- +
- + _log.info("Evento programado " + scheduledTime.get(Calendar.HOUR_OF_DAY) + ":" + scheduledTime.get(Calendar.MINUTE));
- + if (timeLeft>0) {
- + task.scheduled = scheduler.scheduleGeneralAtFixedRate(task, timeLeft, 86400000L); // Ejecutado 1 vez al dia
- + _log.info("Quedan " + (timeLeft/1000) + " segundos.");
- + }
- + else {
- + // Si el evento termina el dia siguiente
- + _log.info("Evento pasado al siguiente dia, ID: " + task.getId());
- + task.scheduled = scheduler.scheduleGeneralAtFixedRate(task, timeLeft + 86400000L, 86400000L);
- + _log.info("Quedan " + (timeLeft + 86400000L/3600000) + " horas.");
- + }
- + return true;
- +
- +
- default:
- return false;
- +
- }
- return false;
- }
- Index: java/com/l2jserver/gameserver/taskmanager/tasks/TaskHappyHourEnd.java
- ===================================================================
- --- java/com/l2jserver/gameserver/taskmanager/tasks/TaskHappyHourEnd.java (revision 0)
- +++ java/com/l2jserver/gameserver/taskmanager/tasks/TaskHappyHourEnd.java (revision 0)
- @@ -0,0 +1,86 @@
- +/*
- + * This program 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.
- + *
- + * This program 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 com.l2jserver.Config;
- +import com.l2jserver.gameserver.model.L2World;
- +import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
- +import com.l2jserver.gameserver.network.serverpackets.ExShowScreenMessage;
- +import com.l2jserver.gameserver.taskmanager.Task;
- +import com.l2jserver.gameserver.taskmanager.TaskManager.ExecutedTask;
- +
- +/**
- + * @author Kimera
- + */
- +public class TaskHappyHourEnd extends Task
- +{
- +
- + private static final String NAME = "happy_hour_end";
- +
- + @Override
- + public String getName() { return NAME; }
- +
- + @Override
- + public void onTimeElapsed(ExecutedTask task)
- + {
- + _log.info("HappyHour finalizada.");
- +
- + _log.info("Cargando y aplicando configuracion por defecto.");
- + Config.RATE_XP = OldConfig.RATE_XP.getFloatRate();
- + Config.RATE_SP = OldConfig.RATE_SP.getFloatRate();
- + Config.RATE_PARTY_XP = OldConfig.RATE_PARTY_XP.getFloatRate();
- + Config.RATE_PARTY_SP = OldConfig.RATE_PARTY_SP.getFloatRate();
- + Config.RATE_DROP_ITEMS = OldConfig. RATE_DROP_ITEMS.getFloatRate();
- + Config.RATE_DROP_ITEMS_BY_RAID = OldConfig.RATE_DROP_ITEMS_BY_RAID.getFloatRate();
- + Config.RATE_DROP_SPOIL = OldConfig.RATE_DROP_SPOIL.getFloatRate();
- + Config.RATE_DROP_MANOR = OldConfig.RATE_DROP_MANOR.getIntegerRate();
- + Config.RATE_QUEST_DROP = OldConfig.RATE_QUEST_DROP.getFloatRate();
- + Config.RATE_QUEST_REWARD_XP = OldConfig.RATE_QUEST_REWARD_XP.getFloatRate();
- + Config.RATE_QUEST_REWARD_SP = OldConfig.RATE_QUEST_REWARD_SP.getFloatRate();
- + Config.RATE_QUEST_REWARD_POTION = OldConfig.RATE_QUEST_REWARD_POTION.getFloatRate();
- + Config.RATE_QUEST_REWARD_SCROLL = OldConfig.RATE_QUEST_REWARD_SCROLL.getFloatRate();
- + Config.RATE_QUEST_REWARD_RECIPE = OldConfig.RATE_QUEST_REWARD_RECIPE.getFloatRate();
- + Config.RATE_QUEST_REWARD_MATERIAL = OldConfig.RATE_QUEST_REWARD_MATERIAL.getFloatRate();
- + Config.ENCHANT_CHANCE = OldConfig.ENCHANT_CHANCE.getDoubleRate();
- +
- + // Y de esta ingeniosa forma se actualiza la informacion del Community
- + _log.info(" RATE_XP: " + Config.RATE_XP); _log.info(" RATE_SP: " + Config.RATE_SP);
- + _log.info(" RATE_PARTY_XP: " + Config.RATE_PARTY_XP); _log.info(" RATE_PARTY_SP: " + Config.RATE_PARTY_SP);
- + _log.info(" RATE_DROP_ITEMS: " + Config.RATE_DROP_ITEMS); _log.info(" RATE_DROP_ITEMS_BY_RAID: " + Config.RATE_DROP_ITEMS_BY_RAID);
- + _log.info(" RATE_DROP_SPOIL: " + Config.RATE_DROP_SPOIL); _log.info(" RATE_DROP_MANOR: " + Config.RATE_DROP_MANOR);
- + _log.info(" RATE_QUEST_DROP: " + Config.RATE_QUEST_DROP); _log.info(" RATE_QUEST_REWARD_XP: " + Config.RATE_QUEST_REWARD_XP);
- + _log.info(" RATE_QUEST_REWARD_SP: " + Config.RATE_QUEST_REWARD_SP); _log.info(" RATE_QUEST_REWARD_POTION: " + Config.RATE_QUEST_REWARD_POTION);
- + _log.info(" RATE_QUEST_REWARD_SCROLL: " + Config.RATE_QUEST_REWARD_SCROLL); _log.info(" RATE_QUEST_REWARD_RECIPE: " + Config.RATE_QUEST_REWARD_RECIPE);
- + _log.info(" RATE_QUEST_REWARD_RECIPE: " + Config.RATE_QUEST_REWARD_RECIPE); _log.info(" RATE_QUEST_REWARD_MATERIAL: " + Config.RATE_QUEST_REWARD_MATERIAL);
- + _log.info(" ENCHANT_CHANCE: " + Config.ENCHANT_CHANCE);
- +
- + // Share por fissban
- + // http://www.adminsprol2.com/t38423-share-l2jserver-mensajes-por-pantalla
- + ExShowScreenMessage ess = new ExShowScreenMessage("Evento Happyhour finalizado!",1000);
- + L2PcInstance[] PjsOnline = L2World.getInstance().getAllPlayersArray();
- + for (L2PcInstance pj : PjsOnline)
- + pj.sendPacket(ess);
- +
- + }
- +
- + @Override
- + public void initializate()
- + {
- + super.initializate();
- + _log.info("*** Happyhour (End time) *** Inicializada");
- + }
- +
- +
- +}
- Index: java/com/l2jserver/gameserver/taskmanager/tasks/TaskHappyHourStart.java
- ===================================================================
- --- java/com/l2jserver/gameserver/taskmanager/tasks/TaskHappyHourStart.java (revision 0)
- +++ java/com/l2jserver/gameserver/taskmanager/tasks/TaskHappyHourStart.java (revision 0)
- @@ -0,0 +1,212 @@
- +/*
- + * This program 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.
- + *
- + * This program 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.io.BufferedReader;
- +import java.io.File;
- +import java.io.FileReader;
- +import java.io.IOException;
- +import java.sql.Connection;
- +import java.sql.ResultSet;
- +import java.sql.Statement;
- +import java.util.Calendar;
- +import java.util.Date;
- +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.ExShowScreenMessage;
- +import com.l2jserver.gameserver.taskmanager.Task;
- +import com.l2jserver.gameserver.taskmanager.TaskManager;
- +import com.l2jserver.gameserver.taskmanager.TaskTypes;
- +import com.l2jserver.gameserver.taskmanager.TaskManager.ExecutedTask;
- +
- +/**
- + * @author Kimera
- + *
- + */
- +public class TaskHappyHourStart extends Task
- +{
- + String param1, param2, param3;
- +
- + private static final String NAME = "happy_hour_start";
- +
- + @Override
- + public String getName() { return NAME; }
- +
- + @Override
- + public void onTimeElapsed(ExecutedTask task)
- + {
- + OldConfig.values();
- + Date d = new Date();
- + Calendar c = Calendar.getInstance();
- + c.setTime(d);
- +
- + final int day = c.get(Calendar.DAY_OF_WEEK);
- + String todayIs = ""; // Dia de hoy
- + String [] params = null; // Parámetros del evento
- +
- + //File
- + String lineRead = "";
- +
- + switch (day) {
- + case 1:
- + todayIs = "D";
- + break;
- + case 2:
- + todayIs = "L";
- + break;
- + case 3:
- + todayIs = "M";
- + break;
- + case 4:
- + todayIs = "W";
- + break;
- + case 5:
- + todayIs = "J";
- + break;
- + case 6:
- + todayIs = "V";
- + case 7:
- + todayIs = "S";
- + break;
- + default: // Nunca deberia ocurir
- + {
- + todayIs = "S";
- + _log.info("Algo raro ha ocurrido con las fechas en TaskHappyHourStart: " + day);
- + }
- + }
- +
- + if (Config.DEBUG) _log.info("Hoy es " + todayIs);
- + params = task.getParams();
- + if (Config.DEBUG) _log.info("Parametros: " + params[0] + " " + params[1] + " " + params[2]);
- +
- + if (todayIs.equals(params[2].split(" ")[0]))
- + {
- + _log.info("Evento happyHour iniciado.");
- + File f = new File("./config/happyHour.properties");
- + try (FileReader fr = new FileReader(f); BufferedReader br = new BufferedReader(fr);
- + )
- + {
- + while ((lineRead = br.readLine())!=null)
- + {
- + if (lineRead.split(" ")[0].contains("NAME"))
- + {
- + if (lineRead.split(" ")[1].equals(params[2].split(" ")[1]))
- + {
- + _log.info("Cargando y aplicando configuracion evento HappyHour.");
- + Config.RATE_XP = Float.valueOf((br.readLine()).split(" ")[1]);
- + Config.RATE_SP = Float.valueOf((br.readLine()).split(" ")[1]);
- + Config.RATE_PARTY_XP = Float.valueOf((br.readLine()).split(" ")[1]);
- + Config.RATE_PARTY_SP = Float.valueOf((br.readLine()).split(" ")[1]);
- + Config.RATE_DROP_ITEMS = Float.valueOf((br.readLine()).split(" ")[1]);
- + Config.RATE_DROP_ITEMS_BY_RAID = Float.valueOf((br.readLine()).split(" ")[1]);
- + Config.RATE_DROP_SPOIL = Float.valueOf((br.readLine()).split(" ")[1]);
- + Config.RATE_DROP_MANOR = Integer.valueOf((br.readLine()).split(" ")[1]);
- + Config.RATE_QUEST_DROP = Float.valueOf((br.readLine()).split(" ")[1]);
- + Config.RATE_QUEST_REWARD_XP = Float.valueOf((br.readLine()).split(" ")[1]);
- + Config.RATE_QUEST_REWARD_SP = Float.valueOf((br.readLine()).split(" ")[1]);
- + Config.RATE_QUEST_REWARD_POTION = Float.valueOf((br.readLine()).split(" ")[1]);
- + Config.RATE_QUEST_REWARD_SCROLL = Float.valueOf((br.readLine()).split(" ")[1]);
- + Config.RATE_QUEST_REWARD_RECIPE = Float.valueOf((br.readLine()).split(" ")[1]);
- + Config.RATE_QUEST_REWARD_MATERIAL = Float.valueOf((br.readLine()).split(" ")[1]);
- + Config.ENCHANT_CHANCE = Double.valueOf((br.readLine()).split(" ")[1]);
- +
- + // Y de esta ingeniosa forma se actualiza la informacion del Community
- + _log.info(" RATE_XP: " + Config.RATE_XP); _log.info(" RATE_SP: " + Config.RATE_SP);
- + _log.info(" RATE_PARTY_XP: " + Config.RATE_PARTY_XP); _log.info(" RATE_PARTY_SP: " + Config.RATE_PARTY_SP);
- + _log.info(" RATE_DROP_ITEMS: " + Config.RATE_DROP_ITEMS); _log.info(" RATE_DROP_ITEMS_BY_RAID: " + Config.RATE_DROP_ITEMS_BY_RAID);
- + _log.info(" RATE_DROP_SPOIL: " + Config.RATE_DROP_SPOIL); _log.info(" RATE_DROP_MANOR: " + Config.RATE_DROP_MANOR);
- + _log.info(" RATE_QUEST_DROP: " + Config.RATE_QUEST_DROP); _log.info(" RATE_QUEST_REWARD_XP: " + Config.RATE_QUEST_REWARD_XP);
- + _log.info(" RATE_QUEST_REWARD_SP: " + Config.RATE_QUEST_REWARD_SP); _log.info(" RATE_QUEST_REWARD_POTION: " + Config.RATE_QUEST_REWARD_POTION);
- + _log.info(" RATE_QUEST_REWARD_SCROLL: " + Config.RATE_QUEST_REWARD_SCROLL); _log.info(" RATE_QUEST_REWARD_RECIPE: " + Config.RATE_QUEST_REWARD_RECIPE);
- + _log.info(" RATE_QUEST_REWARD_RECIPE: " + Config.RATE_QUEST_REWARD_RECIPE); _log.info(" RATE_QUEST_REWARD_MATERIAL: " + Config.RATE_QUEST_REWARD_MATERIAL);
- + _log.info(" ENCHANT_CHANCE: " + Config.ENCHANT_CHANCE);
- +
- + // Share por fissban
- + // http://www.adminsprol2.com/t38423-share-l2jserver-mensajes-por-pantalla
- + ExShowScreenMessage ess = new ExShowScreenMessage("Evento Happyhour iniciado!",1000);
- + L2PcInstance[] PjsOnline = L2World.getInstance().getAllPlayersArray();
- + for (L2PcInstance pj : PjsOnline)
- + pj.sendPacket(ess);
- +
- + break;
- + }
- + }
- + }
- + }
- + catch (IOException e) { e.printStackTrace(); }
- + }
- + }
- +
- + @Override
- + public void initializate()
- + {
- + super.initializate();
- + _log.info("*** Happyhour (Start time) *** Inicializada");
- + try ( Connection con = L2DatabaseFactory.getInstance().getConnection(); )
- + {
- + Statement st = con.createStatement();
- + String query = "Select param1,param2,param3 from global_tasks where task=\"happy_hour_start\"";
- + ResultSet executeQuery = st.executeQuery(query);
- + while (executeQuery.next())
- + {
- + param1 = executeQuery.getString("param1");
- + param2 = executeQuery.getString("param2");
- + param3 = executeQuery.getString("param3"); // Donde reside el dia de la programacion semanal
- + }
- + con.close(); st.close();
- + }
- + catch (Exception e) { e.printStackTrace(); }
- +
- + if (param1!=null && param2!=null)
- + TaskManager.addUniqueTask(NAME, TaskTypes.TYPE_GLOBAL_TASK, param1, param2, param3, 0L);
- +
- + _log.info("Se ha anadido: " + NAME + " " + param1 + " " + param2 + " " + param3);
- + }
- +
- + // TODO: Deberia crearse una clase enumeracion en su propio fichero para reutilizar codigo.
- +}
- +
- +enum OldConfig
- +{
- + RATE_XP(Config.RATE_XP),RATE_SP(Config.RATE_SP),RATE_PARTY_XP(Config.RATE_PARTY_XP), RATE_PARTY_SP(Config.RATE_PARTY_SP),
- + RATE_DROP_ITEMS(Config.RATE_DROP_ITEMS), RATE_DROP_ITEMS_BY_RAID(Config.RATE_DROP_ITEMS_BY_RAID), RATE_DROP_SPOIL(Config.RATE_DROP_SPOIL),
- + RATE_DROP_MANOR(Config.RATE_DROP_MANOR), RATE_QUEST_DROP(Config.RATE_QUEST_DROP), RATE_QUEST_REWARD_XP(Config.RATE_QUEST_REWARD_XP),
- + RATE_QUEST_REWARD_SP(Config.RATE_QUEST_REWARD_SP), RATE_QUEST_REWARD_ADENA(Config.RATE_QUEST_REWARD_SP),
- + RATE_QUEST_REWARD_POTION(Config.RATE_QUEST_REWARD_POTION), RATE_QUEST_REWARD_SCROLL(Config.RATE_QUEST_REWARD_SCROLL),
- + RATE_QUEST_REWARD_RECIPE(Config.RATE_QUEST_REWARD_RECIPE), RATE_QUEST_REWARD_MATERIAL(Config.RATE_QUEST_REWARD_MATERIAL),
- + ENCHANT_CHANCE(Config.ENCHANT_CHANCE);
- +
- + float rateFloat;
- + int rateInt;
- + double rateDouble;
- +
- + OldConfig(float f) {
- + this.rateFloat = f;
- + }
- +
- + OldConfig(int i) {
- + this.rateInt = i;
- + }
- +
- + OldConfig(double d) {
- + this.rateDouble = d;
- + }
- +
- + float getFloatRate() { return rateFloat; }
- + int getIntegerRate() { return rateInt; } // Drop manor usa tipo int
- + double getDoubleRate() { return rateDouble; } // Enchant rate usa double
- +}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement