Jump to content
  • 0

Question

Posted (edited)

Hello,

I have problem while setting aio for player. Today is 30th month day and if  I set aio for 1 day some how end date is december 31(i think it is because november does not have 31 day). But if I set aio for 2 days its end time is december 1. How I can fix it? l2jfrozen rev 1132.

P.S. when it was november 25 and I set aio for 1 day it worked perfectly.

Adding code:

/*
 * L2jFrozen Project - www.l2jfrozen.com 
 * 
 * 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 2, 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, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
 * 02111-1307, USA.
 *
 * http://www.gnu.org/copyleft/gpl.html
 */
package com.l2jfrozen.gameserver.handler.admincommandhandlers;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.util.StringTokenizer;

import org.apache.log4j.Logger;

import com.l2jfrozen.Config;
import com.l2jfrozen.gameserver.datatables.GmListTable;
import com.l2jfrozen.gameserver.handler.IAdminCommandHandler;
import com.l2jfrozen.gameserver.model.L2World;
import com.l2jfrozen.gameserver.model.actor.instance.L2PcInstance;
import com.l2jfrozen.gameserver.network.serverpackets.EtcStatusUpdate;
import com.l2jfrozen.util.CloseUtil;
import com.l2jfrozen.util.database.DatabaseUtils;
import com.l2jfrozen.util.database.L2DatabaseFactory;

/**
 * Give / Take Status Aio to Player Changes name color and title color if enabled Uses: setaio [<player_name>] [<time_duration in days>] removeaio [<player_name>] If <player_name> is not specified, the current target player is used.
 * @author KhayrusS
 */
public class AdminAio implements IAdminCommandHandler
{
	private final static Logger LOGGER = Logger.getLogger(AdminAio.class);
	
	private static String[] _adminCommands =
	{
		"admin_setaio",
		"admin_removeaio"
	};
	
	private enum CommandEnum
	{
		admin_setaio,
		admin_removeaio
	}
	
	@Override
	public boolean useAdminCommand(final String command, final L2PcInstance activeChar)
	{
		/*
		 * if(!AdminCommandAccessRights.getInstance().hasAccess(command, activeChar.getAccessLevel())){ return false; } if(Config.GMAUDIT) { Logger _logAudit = Logger.getLogger("gmaudit"); LogRecord record = new LogRecord(Level.INFO, command); record.setParameters(new Object[] { "GM: " +
		 * activeChar.getName(), " to target [" + activeChar.getTarget() + "] " }); _logAudit.LOGGER(record); }
		 */
		
		final StringTokenizer st = new StringTokenizer(command);
		
		final CommandEnum comm = CommandEnum.valueOf(st.nextToken());
		
		if (comm == null)
			return false;
		
		switch (comm)
		{
			case admin_setaio:
			{
				
				boolean no_token = false;
				
				if (st.hasMoreTokens())
				{ // char_name not specified
				
					final String char_name = st.nextToken();
					
					final L2PcInstance player = L2World.getInstance().getPlayer(char_name);
					
					if (player != null)
					{
						
						if (st.hasMoreTokens()) // time
						{
							final String time = st.nextToken();
							
							try
							{
								final int value = Integer.parseInt(time);
								
								if (value > 0)
								{
									
									doAio(activeChar, player, char_name, time);
									
									if (player.isAio())
										return true;
									
								}
								else
								{
									activeChar.sendMessage("Time must be bigger then 0!");
									return false;
								}
								
							}
							catch (final NumberFormatException e)
							{
								activeChar.sendMessage("Time must be a number!");
								return false;
							}
							
						}
						else
						{
							no_token = true;
						}
						
					}
					else
					{
						activeChar.sendMessage("Player must be online to set AIO status");
						no_token = true;
					}
					
				}
				else
				{
					
					no_token = true;
					
				}
				
				if (no_token)
				{
					activeChar.sendMessage("Usage: //setaio <char_name> [time](in days)");
					return false;
				}
				
			}
			case admin_removeaio:
			{
				
				boolean no_token = false;
				
				if (st.hasMoreTokens())
				{ // char_name
				
					final String char_name = st.nextToken();
					
					final L2PcInstance player = L2World.getInstance().getPlayer(char_name);
					
					if (player != null)
					{
						
						removeAio(activeChar, player, char_name);
						
						if (!player.isAio())
							return true;
						
					}
					else
					{
						
						activeChar.sendMessage("Player must be online to remove AIO status");
						no_token = true;
					}
					
				}
				else
				{
					no_token = true;
				}
				
				if (no_token)
				{
					activeChar.sendMessage("Usage: //removeaio <char_name>");
					return false;
				}
				
			}
		}
		
		return true;
		
	}
	
	public void doAio(final L2PcInstance activeChar, final L2PcInstance _player, final String _playername, final String _time)
	{
		final int days = Integer.parseInt(_time);
		if (_player == null)
		{
			activeChar.sendMessage("not found char" + _playername);
			return;
		}
		
		if (days > 0)
		{
			_player.setAio(true);
			_player.setEndTime("aio", days);
			_player.getStat().addExp(_player.getStat().getExpForLevel(81));
			
			Connection connection = null;
			try
			{
				connection = L2DatabaseFactory.getInstance().getConnection(false);
				
				final PreparedStatement statement = connection.prepareStatement("UPDATE characters SET aio=1, aio_end=? WHERE obj_id=?");
				statement.setLong(1, _player.getAioEndTime());
				statement.setInt(2, _player.getObjectId());
				statement.execute();
				DatabaseUtils.close(statement);
				connection.close();
				
				if (Config.ALLOW_AIO_NCOLOR && activeChar.isAio())
					_player.getAppearance().setNameColor(Config.AIO_NCOLOR);
				
				if (Config.ALLOW_AIO_TCOLOR && activeChar.isAio())
					_player.getAppearance().setTitleColor(Config.AIO_TCOLOR);
				
				_player.rewardAioSkills();
				_player.broadcastUserInfo();
				_player.sendPacket(new EtcStatusUpdate(_player));
				_player.sendSkillList();
				GmListTable.broadcastMessageToGMs("GM " + activeChar.getName() + " set Aio stat for player " + _playername + " for " + _time + " day(s)");
				_player.sendMessage("You are now an Aio, Congratulations!");
				_player.broadcastUserInfo();
			}
			catch (final Exception e)
			{
				if (Config.DEBUG)
					e.printStackTrace();
				
				LOGGER.warn("could not set Aio stats to char:", e);
			}
			finally
			{
				CloseUtil.close(connection);
			}
		}
		else
		{
			removeAio(activeChar, _player, _playername);
		}
	}
	
	public void removeAio(final L2PcInstance activeChar, final L2PcInstance _player, final String _playername)
	{
		_player.setAio(false);
		_player.setAioEndTime(0);
		
		Connection connection = null;
		try
		{
			connection = L2DatabaseFactory.getInstance().getConnection(false);
			
			final PreparedStatement statement = connection.prepareStatement("UPDATE characters SET Aio=0, Aio_end=0 WHERE obj_id=?");
			statement.setInt(1, _player.getObjectId());
			statement.execute();
			DatabaseUtils.close(statement);
			connection.close();
			
			_player.lostAioSkills();
			_player.getAppearance().setNameColor(0xFFFFFF);
			_player.getAppearance().setTitleColor(0xFFFFFF);
			_player.broadcastUserInfo();
			_player.sendPacket(new EtcStatusUpdate(_player));
			_player.sendSkillList();
			GmListTable.broadcastMessageToGMs("GM " + activeChar.getName() + " remove Aio stat of player " + _playername);
			_player.sendMessage("Now You are not an Aio..");
			_player.broadcastUserInfo();
		}
		catch (final Exception e)
		{
			if (Config.DEBUG)
				e.printStackTrace();
			
			LOGGER.warn("could not remove Aio stats of char:", e);
		}
		finally
		{
			CloseUtil.close(connection);
		}
	}
	
	@Override
	public String[] getAdminCommandList()
	{
		return _adminCommands;
	}
}

EDIT adding aioendtime code:

public void setEndTime(final String process, int val)
	{
		if (val > 0)
		{
			long end_day;
			final Calendar calendar = Calendar.getInstance();
			if (val >= 30)
			{
				while (val >= 30)
				{
					if (calendar.get(Calendar.MONTH) == 11)
						calendar.roll(Calendar.YEAR, true);
					calendar.roll(Calendar.MONTH, true);
					val -= 30;
				}
			}
			if (val < 30 && val > 0)
			{
				while (val > 0)
				{
					if (calendar.get(Calendar.DATE) == 28 && calendar.get(Calendar.MONTH) == 1)
						calendar.roll(Calendar.MONTH, true);
					if (calendar.get(Calendar.DATE) == 30)
					{
						if (calendar.get(Calendar.MONTH) == 11)
							calendar.roll(Calendar.YEAR, true);
						calendar.roll(Calendar.MONTH, true);
						
					}
					calendar.roll(Calendar.DATE, true);
					val--;
				}
			}
			
			end_day = calendar.getTimeInMillis();
			if (process.equals("aio"))
				_aio_endTime = end_day;
			
			else
			{
				LOGGER.info("process " + process + "no Known while try set end date");
				return;
			}
			final Date dt = new Date(end_day);
			LOGGER.info("" + process + " end time for player " + getName() + " is " + dt);
		}
		else
		{
			if (process.equals("aio"))
				_aio_endTime = 0;
			
			else
			{
				LOGGER.info("process " + process + "no Known while try set end date");
				return;
			}
		}
	}
	
	/**
	 * Gets the aio end time.
	 * @return the aio end time
	 */
	public long getAioEndTime()
	{
		return _aio_endTime;
	}
Edited by Helperis

2 answers to this question

Recommended Posts

  • 0
Posted

Why not do it this way?

 

long endDateMillis = System.currentTimeMillis() + TimeUnit.DAYS.toMillis(val);

this. Millisecond can be translated into anything since is static time. If you get current millisecond and the day is about to change in 1 minute and you add 3600000 ms this will just go to the next day. 

This setEndTime is the most fucked up thing i ever seen in my life... delete it and recycle the whole code is 2 lines

 

long endDateMillis = System.currentTimeMillis() + TimeUnit.DAYS.toMillis(val); (As guy said)

player.setPremiumTime(endDateMillis)  <-- example.

 

or make a direct method to update base on Days

long premtime = 0;

public void setPremiumTime(int days)
{
   premTime = System.currentTimeMillis() + TimeUnit.DAYS.toMillis(days)
}
  • 0
Posted

Why not do it this way?

 

long endDateMillis = System.currentTimeMillis() + TimeUnit.DAYS.toMillis(val);

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now


  • Posts

    • Trust and Honesty   We don’t need to brag - what matters is that you actually feel the service works the way it should. No surprises, no stress. With Vibe SMS, you can focus on your tasks knowing everything runs smoothly. Like having a friend by your side calm, reliable, and without unnecessary words.   Website link — https://vibe-sms.net/ Our Telegram channel — https://t.me/vibe_sms
    • The old Trances packs were built using Java 7, which is outdated. Our server is running on the latest Java version, fully up-to-date for 2025
    • Experience L2Gold like never before – available ONLY on Saturdays & Sundays! Custom Armors: Dynasty, Apella Custom Weapons: L2Gold Weapons Custom Jewelry: L2Gold Jewelry Custom Teleport System & AIO Buffer Custom Zones, NPCs & Raidbosses This is not just another private server – it’s a limited-time battleground for the ultimate L2 experience! Play only on weekends Website: https://l2kandra.online/ Info & Contact: https://www.facebook.com/profile.php?id=61578869175323  
    • 突发新闻! Twitter Premium(推特高级版) 现以优惠价发售!立即尝试 — 限时优惠! ➡ Twitter Premium X 订阅(适用于您的推特账户),可选 1 个月 / 1 年(任选)。需要登录授权您的推特账户。价格:每月 $7–13(每年 $75) ➡ Twitter X Premium Plus 订阅 + GROK AI 助手(适用于您的推特账户),可选 1 个月 / 1 年(任选)。需要登录授权您的推特账户。价格:每月 $48–55(每年 $480) ➡ 2010–2023 年老推特账号,带蓝色认证标志(Tier 1/2/3 国家)| 提供完整访问权限(含登录名、密码和令牌)| 价格:起价 $9 ➡ 2010–2023 年老推特 NFT 账号,带蓝色认证标志(Tier 1/2/3 国家)| 提供完整访问权限(含登录名、密码和令牌)| 价格:起价 $9 ➡ 2010–2023 年老推特账号,带蓝色认证标志 + 真实粉丝(100–20000,可自选)| Tier 1/2/3 国家 | 提供完整访问权限(含登录名、密码和令牌)| 支持补充:30+ 天 | 价格:起价 $9.5 ➡ 2010–2023 年老推特账号,带广告管理器(ADS Manager)和蓝色认证标志,并绑定信用卡 | 区域:Tier 1 国家 | 提供完整访问权限(含登录名、密码和令牌)| 价格:起价 $35 您可以在我们的网站商店或通过 Telegram 机器人购买! ➡ 数字商品商店(网站):前往 ➡ 商店 Telegram 机器人:前往 ➡ Telegram Stars 购买机器人:前往 ➡ SMM 面板:前往 – 推广您的社交媒体账户。 我们为您呈现最新的优惠与特别活动,用于购买我们平台的商品和服务: 1. 使用优惠码 OCTOBER2025(8% 折扣)在十月于我们的网站或机器人中购物!首次购买还可使用优惠码 SOCNET(15% 折扣) 2. 注册后在我们网站的论坛主题中按以下格式留言,即可获得 $1 商店余额或 10–20% 折扣:"SEND ME BONUS, MY USERNAME IS..." 3. 首次试用 SMM 面板即可获得 $1:只需在网站支持中心提交标题为 “Get Trial Bonus” 的工单。 4. 我们的 Telegram 频道与 Telegram Stars 购买机器人每周举行 Telegram Stars 抽奖活动! 新闻资讯: ➡ Telegram 频道:https://t.me/accsforyou_shop✅ ➡ WhatsApp 频道:https://chat.whatsapp.com/K8rBy500nA73z27PxgaJUw?mode=ems_copy_t✅ ➡ Discord 服务器:https://discord.gg/y9AStFFsrh✅ 联系方式与支持: ➡ Telegram:https://t.me/socnet_support✅ ➡ WhatsApp:https://wa.me/79051904467✅ ➡ Discord:socnet_support ✅ ➡ ✉ 邮箱:solomonbog@socnet.store ✅
    • Breaking News! Twitter Premium now available at a discounted price! Try it right now — limited-time offer! ➡ Twitter Premium X subscription for your Twitter account for 1 month / 1 year (your choice). Requires login authorization to your Twitter account. Price from: $7–13 per 1 month ($75 per 12 months) ➡ Twitter X Premium Plus subscription and GROK AI assistant for your Twitter account for 1 month / 1 year (your choice). Requires login authorization to your Twitter account. Price from: $48–55 per 1 month ($480 per 12 months) ➡ Old Twitter Accounts 2010–2023 with BLUE Regular Tick (Tier 1/2/3 countries) | Full access with Login, Password, and Token included! | Price from: $9 ➡ Old Twitter NFT Accounts 2010–2023 with BLUE Tick (Tier 1/2/3 countries) | Full access with Login, Password, and Token included! | Price from: $9 ➡ Old Twitter Accounts 2010–2023 with BLUE Regular Tick and real followers: 100–20000 (followers of your choice) | Tier 1/2/3 countries | Full access with Login, Password, and Token included | Refill: 30+ days | Price from: $9.5 ➡ Old Twitter Accounts 2010–2023 with ADS Manager and BLUE Regular Tick linked with Credit Card | GEO: Tier 1 countries | Full access with Login, Password, and Token included | Price from: $35 Shop in our online store or through our Telegram bot! ➡ Digital goods store (Website): Go ➡ Store Telegram bot: Go ➡ Telegram bot for purchasing Telegram Stars: Go ➡ SMM Panel: Go – promote your social media accounts. We would like to present you with the latest list of promotions and special offers for purchasing products and services from our platform: 1. Promo code OCTOBER2025 (8% discount) for purchases in our store (Website or Bot) in October! You can also use the first-time promo code SOCNET (15% discount) 2. Get $1 credited to your store balance or a 10–20% discount — just post your username after registration on our website in the following format: "SEND ME BONUS, MY USERNAME IS..." – post it in our forum thread! 3. Get $1 for your first SMM Panel trial — just open a support ticket with the title “Get Trial Bonus” on our website (Support). 4. Weekly giveaways of Telegram Stars in our Telegram channel and our Telegram bot for Star purchases! News: ➡ Telegram channel: https://t.me/accsforyou_shop✅ ➡ WhatsApp channel: https://chat.whatsapp.com/K8rBy500nA73z27PxgaJUw?mode=ems_copy_t✅ ➡ Discord server: https://discord.gg/y9AStFFsrh✅ Contacts and Support: ➡ Telegram: https://t.me/socnet_support✅ ➡ WhatsApp: https://wa.me/79051904467✅ ➡ Discord: socnet_support ✅ ➡ ✉ Email: solomonbog@socnet.store ✅
  • Topics

×
×
  • Create New...

AdBlock Extension Detected!

Our website is made possible by displaying online advertisements to our members.

Please disable AdBlock browser extension first, to be able to use our community.

I've Disabled AdBlock