Jump to content

Question

5 answers to this question

Recommended Posts

  • 0
Posted
package custom.RewardForTimeOnline;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ScheduledFuture;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.l2jserver.gameserver.ThreadPoolManager;
import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
import com.l2jserver.gameserver.model.events.Containers;
import com.l2jserver.gameserver.model.events.EventType;
import com.l2jserver.gameserver.model.events.impl.character.player.OnPlayerLogin;
import com.l2jserver.gameserver.model.events.impl.character.player.OnPlayerLogout;
import com.l2jserver.gameserver.model.events.listeners.ConsumerEventListener;
import com.l2jserver.gameserver.model.quest.Quest;

/**
 * @author LifeGame32
 */
public final class RewardForTimeOnline extends Quest
{
	static final Logger LOG = LoggerFactory.getLogger(RewardForTimeOnline.class);
	
	// Enable/Disable
	static final boolean LOAD = true;
	
	final Map<Integer, PlayerHolder> players;
	
	final List<ItemHolder> rewardItem;
	
	// unique var DB(for saving), Item ID, Amount, time in milliseconds, save the last rewarded time.
	private void addItem()
	{
		rewardItem.add(new ItemHolder("rfto_1", 57, 50000, 30 * 1000, false));
		rewardItem.add(new ItemHolder("rfto_2", 57, 150000, 60 * 1000, true));
		rewardItem.add(new ItemHolder(getVar(), 57, 150000, 60 * 1000, true));
	}
	
	private String getVar()
	{
		return getClass().getSimpleName() + "_" + rewardItem.size();
	}
	
	private final class PlayerHolder
	{
		final L2PcInstance player;
		final List<RewardTask> rewardTask = new ArrayList<>();
		
		public PlayerHolder(L2PcInstance player)
		{
			this.player = player;
		}
		
		public final PlayerHolder startRewardTask()
		{
			for (ItemHolder item : rewardItem)
			{
				rewardTask.add(new RewardTask(this, item));
			}
			
			return this;
		}
		
		public final void onPlayerLogout()
		{
			for (RewardTask t : rewardTask)
			{
				t.onPlayerLogout();
			}
		}
	}
	
	private final class RewardTask implements Runnable
	{
		private final PlayerHolder ph;
		private final ItemHolder item;
		private ScheduledFuture<?> task = null;
		
		private long lastTime;
		
		public RewardTask(PlayerHolder playerHolder, ItemHolder item)
		{
			this.ph = playerHolder;
			this.item = item;
			this.lastTime = System.currentTimeMillis();
			
			long initialDelay;
			
			if (item.isSaveTime)
			{
				initialDelay = ph.player.getVariables().getLong(item.var, 0);
				if ((initialDelay == 0) || (initialDelay > item.time))
				{
					initialDelay = item.time;
				}
			}
			else
			{
				initialDelay = item.time;
			}
			
			this.task = ThreadPoolManager.getInstance().scheduleGeneralAtFixedRate(this, initialDelay, item.time);
		}
		
		@Override
		public void run()
		{
			if ((ph.player == null) || (ph.player.getClient() == null) || ph.player.getClient().isDetached())
			{
				return;
			}
			
			if (ph.player.isOnline())
			{
				if (item.isSaveTime)
				{
					ph.player.getVariables().set(item.var, 0);
				}
				
				lastTime = System.currentTimeMillis();
				
				ph.player.addItem(RewardForTimeOnline.class.getSimpleName(), item.id, item.count, null, true);
			}
		}
		
		public final void onPlayerLogout()
		{
			stopTask();
			
			if (item.isSaveTime)
			{
				ph.player.getVariables().set(item.var, (item.time - (System.currentTimeMillis() - lastTime)));
			}
		}
		
		public final void stopTask()
		{
			if (task != null)
			{
				task.cancel(false);
				task = null;
			}
		}
	}
	
	private final class ItemHolder
	{
		final String var;
		final int id;
		final long count;
		final long time;
		final boolean isSaveTime;
		
		public ItemHolder(String var, int id, long count, long time, boolean isSaveTime)
		{
			this.var = var;
			this.id = id;
			this.count = count;
			this.time = time;
			this.isSaveTime = isSaveTime;
		}
	}
	
	public RewardForTimeOnline()
	{
		super(-1, RewardForTimeOnline.class.getSimpleName(), "custom/RewardForTimeOnline");
		Containers.Global().addListener(new ConsumerEventListener(Containers.Global(), EventType.ON_PLAYER_LOGIN, (OnPlayerLogin event) -> onPlayerLogin(event), this));
		Containers.Global().addListener(new ConsumerEventListener(Containers.Global(), EventType.ON_PLAYER_LOGOUT, (OnPlayerLogout event) -> onPlayerLogout(event), this));
		players = new ConcurrentHashMap<>();
		rewardItem = new ArrayList<>();
		addItem();
	}
	
	private final void onPlayerLogin(OnPlayerLogin event)
	{
		PlayerHolder task = players.get(event.getActiveChar().getObjectId());
		if (task == null)
		{
			players.put(event.getActiveChar().getObjectId(), new PlayerHolder(event.getActiveChar()).startRewardTask());
		}
	}
	
	private final void onPlayerLogout(OnPlayerLogout event)
	{
		PlayerHolder task = players.remove(event.getActiveChar().getObjectId());
		if (task != null)
		{
			task.onPlayerLogout();
		}
	}
	
	public static void main(String[] args)
	{
		if (LOAD)
		{
			new RewardForTimeOnline();
		}
		
		LOG.info("{}: load {}.", RewardForTimeOnline.class.getSimpleName(), LOAD);
	}
}

 

Original share here.

  • 0
Posted

@Rootware

Da heck.. So much code for such a little addon.

 

Hint, take a look on gametime task, you can see the 'take a break' message after an hour. You can follow the logic of the task. Add player on login, store time and then check if hour passed.

Guest
This topic is now closed to further replies.


  • Posts

    • Your options are , 1. pay for files like lucera 2. pay for a dev to create what u need 3. learn how to code and u do it urself 4. find the old discontinued interlude classic source from mobius and work with that.  5. there are some heavily modded interlude files on other forums that offer what u asking ( interface , classic/essence style etc)
    • Since ur interested on the latest client(s) Your best bet is l2jmobius.  Their free repo is more than enough to get you started. They also offer a subscription of 100$ in order to access the latest sources. A big + is the community there is pretty active and helpful.
    • Hey chatgpt. Make me a website for my private l2jserver called l2karma. Make no mistakes.
    • Server Description L2 Karma is a permanent Interlude 1x server built on L2J with retail-like mechanics and a long-term vision — not a seasonal reset or wipe server. We focus on competitive longevity, fair play, and a community where every player matters. Core Features ✔ True x1 Experience (XP / SP / Adena / Drop / Spoil) ✔ Retail mechanics — no forced progression shortcuts ✔ Single-box only (1 client per player — no multi-boxing advantage) ✔ No Pay-to-Win & strict anti-RMT policy ✔ Already live and active with players progressing ✔ Long-term commitment — 3-year guarantee ✔ Designed for meaningful PvP and community cohesion 📏 Server Rules No Multi-Boxing Advantage — Only one client per account is allowed. No Pay-to-Win Items or Services — VIP runes are optional and do not lock content. No Bots, Scripts, or Automation — Zero tolerance. Suspicious accounts will be banned. No Exploit Abuse — Reporting exploits immediately avoids penalties. No RMT / Real Money Trading — Strict enforcement — economy integrity matters. Fair Play Only — Harassment and racism are not allowed in chat or Discord. Respect Admin Decisions — Official rulings are final to keep the server stable. 📥 How to Join 🔗 Website: https://l2karma.org 🔗 Discord: https://discord.gg/VV9RAfmnth Chronicle: Interlude Rates: x1 (Classic) Box Limit: Single Box 🧠 What Makes Us Different ✔ Permanent World — No resets ever ✔ Designed for players tired of wipe-cycle servers ✔ Community-centric growth — not rinse-and-repeat launches ✔ Competitive but fair environment ✔ Events, structured seasons, and ongoing content support
    • A widespread proxy service, operating through hijacked devices, has been shut down in a cross-industry effort led by Google. The network, known as IPIDEA, functioned by secretly converting millions of personal devices into proxies for malicious actors. The Mechanism of the Scheme The operation distributed hidden code within seemingly legitimate free apps and VPN services. Once installed, this code enrolled the user’s device into a pool of residential IP addresses. These addresses were then sold anonymously, primarily to cybercriminal and state-sponsored groups, to mask the origin of attacks, fraud, and espionage. Key impacts of the network included: Facilitating operations for more than 550 identified threat actors. Exposing unsuspecting device owners to potential legal and security risks by associating their IP addresses with criminal traffic. The Takedown Strategy Google and its partners disrupted the service by: Seizing core operational domains. Using Google Play Protect to detect and remove malicious applications. Coordinating with infrastructure providers to prevent the network from reestablishing itself. The action highlights the necessity of continuous user awareness, developer diligence in code reviews, and proactive industry cooperation to maintain cybersecurity. Front Companies Associated with IPIDEA IPIDEA masked its activities under various brand names, such as: Proxy Brands: 360 Proxy, 922 Proxy, Luna Proxy, IP2World, ABC Proxy. VPN Brands: Door VPN, Radish VPN, Galleon VPN. SDK Brands: PacketSDK, HexSDK (the toolkits used to embed proxy code).   Choosing Ethical Proxy Services Alternatives For lawful purposes like market research, ad verification, or data aggregation, selecting a transparent and consensual provider is essential. Reputable services obtain explicit user permission for their networks and enforce strict compliance measures. Examples of Established Providers: Bright Data: A leading, consent-based residential proxy network. Oxylabs: Provides large-scale proxy solutions for enterprise needs. MoMoProxy: Maintains a large pool of residential IPs for tasks like web scraping.   Only $850/1TB.  https://momoproxy.com   Identifying a Legitimate Provider: A trustworthy service will typically demonstrate: Informed Consent: Networks are built with the clear agreement of participants. Robust Compliance: Proactive systems to prevent abuse and respect website terms. Operational Transparency: Public-facing policies, identifiable corporate structure, and genuine customer support. Conduct thorough due diligence. Opt for providers that are clear about their IP sources and maintain strong anti-abuse policies, ensuring your legitimate activities do not inadvertently support harmful operations.
  • Topics

×
×
  • Create New...

Important Information

This community uses essential cookies to function properly. Non-essential cookies and third-party services are used only with your consent. Read our Privacy Policy and We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue..