Jump to content
  • 0

Online Time reward


Question

Posted

I want to give 1 GCM per hour to online players.

I am editing the java code I found for this, but it does not give an hourly reward.

 

package services;

import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.concurrent.ScheduledFuture;

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

import l2f.gameserver.Config;
import l2f.gameserver.ThreadPoolManager;
import l2f.gameserver.database.mysql;
import l2f.gameserver.model.GameObjectsStorage;
import l2f.gameserver.model.Player;
import l2f.gameserver.scripts.ScriptFile;
/**
 *
 * @author Special
 */
public class AutoReward implements ScriptFile, Runnable
{
    private static final Logger _log = LoggerFactory.getLogger(Player.class);
    
    private static final int REWARD_DELAY = 3600000; // 1h.
    private static final int REQUIRED_ONLINE = Config.DAILY_REWARD_REQUIRED_ONLINE * 3600000; // 1h.
    private static final int NOT_REWARD_AFK_DELAY = Config.DAILY_REWARD_AFK_TIME * 60000; // 10 mins.(Config 10)
    private static final DateFormat TIME_FORMAT = new SimpleDateFormat("HH");
    private boolean CLEANED = false;

    private ScheduledFuture<?> _task = null;

    @Override
    public void run()
    {
        if(CLEANED && time() >= Config.DAILY_REWARD_END_HOUR || time() < Config.DAILY_REWARD_START_HOUR)
            CLEANED = false;
        
        if(time() >= Config.DAILY_REWARD_START_HOUR && time() <= Config.DAILY_REWARD_END_HOUR)
        {
            for(Player player : GameObjectsStorage.getAllPlayersForIterate()) {
                    if(player.isOnline() && player.getUptime() >= REQUIRED_ONLINE
                        && (System.currentTimeMillis() - player.getLastNotAfkTime()) > NOT_REWARD_AFK_DELAY) {
                        if(!isRewardedDB(player)) {
                            player.sendMessage("You have been rewarded for online time!");
                            setRewardDB(player);
                        }
                    }
            }
        }
        
        if(CLEANED == false && time() <= Config.DAILY_REWARD_START_HOUR) {
            CLEANED = true;
            wipeRewardDB();
        }
    }
    
    public static int time()
    {
        return Integer.parseInt(TIME_FORMAT.format(new Date(System.currentTimeMillis())));
    }
    
    public static boolean isRewardedDB(Player player) {
        String value = Config.DAILY_REWARD_PROTECTION.equals("HWID") ? player.getHWID() : player.getIP();
    
        if(player.getVar("daily_reward") != null)
            return true;
        
        if(mysql.get("SELECT value FROM character_variables WHERE name='daily_reward' AND value='"+value+"'") != null)
            return true;
        
        return false;
    }
    
    public static void setRewardDB(Player player) {
        String value = Config.DAILY_REWARD_PROTECTION.equals("HWID") ? player.getHWID() : player.getIP();
        
        mysql.set("INSERT INTO character_variables (obj_id, type, name, value, expire_time) VALUES (?,?,?,?,?)", player.getObjectId(), "user-var", "daily_reward", value, -1);
    }
    
    public static void wipeRewardDB() {

        mysql.set("DELETE FROM `character_variables` WHERE `type`='user-var' and `name`='daily_reward'");
    }

    @Override
    public void onLoad()
    {
        _log.info("Loaded Service: AutoReward");
        if(_task == null)
            _task = ThreadPoolManager.getInstance().scheduleAtFixedDelay(this, REWARD_DELAY, REWARD_DELAY);
    }

    @Override
    public void onReload()
    {
        if(_task != null)
        {
            _task.cancel(true);
            _task = null;
        }
        _task = ThreadPoolManager.getInstance().scheduleAtFixedDelay(this, REWARD_DELAY, REWARD_DELAY);
    }

    @Override
    public void onShutdown()
    {
        //
    }
}

1 answer to this question

Recommended Posts

  • 0
Posted

I don't even think this is compilable to honest.

 

Do you want the reward to be every hour on the 24 hour clock, or every hour from the moment the server starts? I mean should it be exactly at 12:00, 13:00, 14:00 or if server starts at 12:21 rewards at 13:21, 14:21, 15:21?

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

    • buenas no puedo poner el server On para que entren mis amigos   LoginServer # ================================================= # Settings authorization server # ================================================= # Host and port for client connections LoginserverHostname = 127.0.0.1 LoginserverPort = 2106 # Host and port for game servers LoginHost = 192.168.100.25 ( mi Ip interna) LoginPort = 9014     GameServer   # =============================== # Network Configuration Server  # # =============================== # IP which Bind Game server, * - all possible GameserverHostname = * GameserverPort = 7777 # This is transmitted to the clients connecting from an external network, so it has to be a public IP or resolvable hostname ExternalHostname = 186.158.144.71 ( Ip externa ovbio) # This is transmitted to the client from the same network, so it has to be a local IP or resolvable host name InternalHostname = 192.168.100.25 # AdvIpSystem Make more GameServerIDs. Every Ip should be Protected by a DDoS Guard. # Your Server will have Success with this system Online. AdvIPSystem = False # Address \ port LS LoginPort = 9014 LoginHost = 192.168.100.25 LoginUseCrypt = true # How to request ID of LS RequestServerID = 4 # Permission to take a different id, if requested busy AcceptAlternateID = False     en que estaria fallando ?    
    • mporeis na valeis l2jaCis i kapoio etimo project  free sources gia aCis edw https://acis.i-live.eu/index.php?topic=1974.0 server install ktl edw https://acis.i-live.eu/index.php?topic=10190.0 an dn vgaleis akrh steile mou discord margazeas2
    • Hello! I am new to l2 server creation and i need your help please!!! I want to make my own l2 interlude c6 server with custom thing in it.  I need help with where to start. What source pack to pick to start and what to do. Please if you can help me i would appreciate it very much !!!
    • Need Discord with rare badge? VISIT US AND SHOP WITH US! NEW STOCK   Aged, Early Supporter Discord Accounts I sell HQ Aged and Early, Discord Accounts that are inactive and not flagged by discord at cheap prices   If you want to contact me, you can add me on discord: worldcoldwar Features: Format - age : email : pass : token Not flagged and undetected by discord HQ % With OGE Emails, password etc can be changed Unverified Early Supporter 24M Boost Badge HypeSquad Events Early Verified Bot Developer Early Supporters SHOP LINK: disvault1.mypaylix.gg/ For PayPal payments, please open a ticket. If you experience any problems with cryptocurrency payments, please open a ticket as well.
  • 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..