Jump to content
  • 0

Java code gia announce


Psych_O

Question

καλησπέρα παιδιά... θα ήθελα να φτιάξω ένα Java Code για το vote reward system έτσι ώστε να κάνει announce έτσι:

 

Vote Reward: We need bla bla bla

 

Θα ήθελα να μου πείτε πως μπορώ να το φτιάξω έτσι....

 

PS:Client Freya

Ευχαριστώ

Link to comment
Share on other sites

Recommended Posts

  • 0

καλησπέρα παιδιά... θα ήθελα να φτιάξω ένα Java Code για το vote reward system έτσι ώστε να κάνει announce έτσι:

 

Vote Reward: We need bla bla bla

 

Θα ήθελα να μου πείτε πως μπορώ να το φτιάξω έτσι....

 

PS:Client Freya

Ευχαριστώ

Ama enoeis na to kaneis esu to announce psakse sto Scripts Handlers > admincommandhandlers >AdminAnnouncements.java  pare paradigma apo kapio pou exei ekei mesa kai kane add to diko s.

Link to comment
Share on other sites

  • 0

Ama enoeis na to kaneis esu to announce psakse sto Scripts Handlers > admincommandhandlers >AdminAnnouncements.java  pare paradigma apo kapio pou exei ekei mesa kai kane add to diko s.

 

oxi dn 8a to kanw egw to announce...

twra kanei announcement etsi: 

44297339.jpg

 

 

 

kai 8elw na to kanw etsi:

unled1zj.jpg

 

 

Link to comment
Share on other sites

  • 0

prota apo ola prepei n ftiakseis vote system 2on molis t kaneis

 

apla sto p.x AutoVoteReward addare

+if(maxcheaters_vote != -1){
+                                        _log.info("[Vote System] Server Topsite current votes : " + maxcheaters_vote);
+                                        Announcements.getInstance().gameAnnounceToAll("[Vote system] current votes are " + maxcheaters_vote + "...");

Link to comment
Share on other sites

  • 0

prota apo ola prepei n ftiakseis vote system 2on molis t kaneis

 

apla sto p.x AutoVoteReward addare

 

 

+if(maxcheaters_vote != -1){
+                                        _log.info("[Vote System] Server Topsite current votes : " + maxcheaters_vote);
+                                        Announcements.getInstance().gameAnnounceToAll("[Vote system] current votes are " + maxcheaters_vote + "...");

 

eyxaristw alla dn to kanei etsi opws edei3a..... kapoios allos?

Link to comment
Share on other sites

  • 0

eyxaristw alla dn to kanei etsi opws edei3a..... kapoios allos?

kane c/p to simio tou announcements ph:Announcements.getInstance().gameAnnounceToAll("[Vote system] current votes are " + maxcheaters_vote + "..."); (ap to diko sou code) na sto ftia3w
Link to comment
Share on other sites

  • 0

ahh damn poso eukolo

 

allakse t announce get instance me

 

player.sendPacket(new CreatureSay(1, Say2.PARTY, "SYSTEM", "[Vote system] current votes are " + maxcheaters_vote + "..."));

Link to comment
Share on other sites

  • 0

logiko einai na min to kaneis file mou. giati esu theleis announce.

den tha sou pw ton tropw na to ftia3eis alla tha sou pw se poia java mporeis na  psa3eis kai na piramatistis oste na to mathis kai monos sou...

 

 


 

Announcements.java  and Broadcast.java

 

Link to comment
Share on other sites

  • 0

kala den zitise tpt tromero :P

 

Collection<L2PcInstance> plss = L2World.getInstance().getAllPlayers();
for (L2PcInstance player : plss)
{
player.sendPacket(new CreatureSay(1,Say2.TELL,"Vote System :"," Votes Now: " + hopzone_votes + "Next Reward in " + minutes + " minutes at " + (getHopZoneVoteCount() + Config.VOTES_FOR_REWARD) + " Votes ;)"));
}

 

sto ekana me to diko m vote twra ama 8es tpt parapano pes m :P

Link to comment
Share on other sites

  • 0

to announce mou einai etsi

 

}	
			setLastVoteCount(newVoteCount);
		}
		Announcements.getInstance().announceToAll(" Help your server by voting now. We need " + (getLastVoteCount()+ Config.VOTES_FOR_REWARD) + " Votes in HopZone for reward all players. At this moment we have " + newVoteCount + " Votes. ");
		if (getLastVoteCount() == 0)
		{
			setLastVoteCount(newVoteCount);
		}

 

kanto etsi kai pes m :P

 

Collection<L2PcInstance> plss = L2World.getInstance().getAllPlayers();
for (L2PcInstance player : plss)
{
player.sendPacket(new CreatureSay(1,Say2.TELL,"Vote System :"," Help your server by voting now. We need " + (getLastVoteCount()+ Config.VOTES_FOR_REWARD) + " Votes in HopZone for reward all players. At this moment we have " + newVoteCount + " Votes. )"));
}

Link to comment
Share on other sites

  • 0

loipon ekana add autes tis 2 lines....

import com.l2jserver.gameserver.network.clientpackets.Say2;
import com.l2jserver.gameserver.network.serverpackets.CreatureSay;

 

kai meta to ekana etsi...

}	
			setLastVoteCount(newVoteCount);
		}
		Collection<L2PcInstance> plss = L2World.getInstance().getAllPlayers();
		for (L2PcInstance player : plss)
		{
		player.sendPacket(new CreatureSay(1,Say2.PARTY,"Vote System :"," Help your server by voting now at  We need " + (getLastVoteCount()+ Config.VOTES_FOR_REWARD) + " Votes in HopZone for reward all players. At this moment we have " + newVoteCount + " Votes. )"));
		if (getLastVoteCount() == 0)
		{
			setLastVoteCount(newVoteCount);
		}

 

 

kai mou bgazei error sto

 

}

Collection<L2PcInstance> plss = L2World.getInstance().getAllPlayers();

for (L2PcInstance player : plss)

{

 

 

 

pws borw na to lisw auto?

Link to comment
Share on other sites

  • 0

loipon ekana add autes tis 2 lines....

import com.l2jserver.gameserver.network.clientpackets.Say2;
import com.l2jserver.gameserver.network.serverpackets.CreatureSay;

 

kai meta to ekana etsi...

}	
			setLastVoteCount(newVoteCount);
		}
		Collection<L2PcInstance> plss = L2World.getInstance().getAllPlayers();
		for (L2PcInstance player : plss)
		{
		player.sendPacket(new CreatureSay(1,Say2.PARTY,"Vote System :"," Help your server by voting now at l2darkdays.com. We need " + (getLastVoteCount()+ Config.VOTES_FOR_REWARD) + " Votes in HopZone for reward all players. At this moment we have " + newVoteCount + " Votes. )"));
		if (getLastVoteCount() == 0)
		{
			setLastVoteCount(newVoteCount);
		}

 

 

kai mou bgazei error sto

 

 

 

pws borw na to lisw auto?

 

l2pcinstance import iparxei?

Link to comment
Share on other sites

  • 0

sou egrapsa 1 new me 1 method dn evala n pernei variable apo kapio site an thes allakse method k kanto anti reward_votes hopzone_votes

 

 

vasismeno s l2jfrozen elpizw n voithisi

 

handler k ena arxeio AutoVoteRewardHandler.java (mn ksexaseis gia register sto gameserver)

 

edit: prepei n ftiaksis dika s config opote sta afisa etc apla  n deis t value

package com.l2jserver.gameserver.handler;

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.net.URL;
import java.net.URLConnection;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.Set;
import java.util.logging.Logger;

import com.l2jserver.Config;
import com.l2jserver.gameserver.model.L2World;
import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
import com.l2jserver.gameserver.model.entity.Announcements;
import com.l2jserver.gameserver.thread.ThreadPoolManager;

public class AutoVoteRewardHandler
{
        private static Logger _log = Logger.getLogger(AutoVoteRewardHandler.class.getName());

        private int hopzoneVotesCount = 0;
        private List<String> already_rewarded;
        
        private static boolean hopzone = false;
        
        private AutoVoteRewardHandler()
        {
                _log.info("Vote Reward System Initiated.");
                
                if(votereward){
                        int reward_votes = getVotes();
                        
                        if(reward_votes == -1){
                                reward_votes = 0;
                        }
                        
                        setVoteCount(reward_votes);
                }
             
                ThreadPoolManager.getInstance().scheduleGeneralAtFixedRate(new AutoReward(), Config.VOTES_SYSYEM_INITIAL_DELAY, Config.VOTES_SYSYEM_STEP_DELAY);
        }

        private class AutoReward implements Runnable
        {
                @Override
                public void run()
                {
                        int minutes = (Config.VOTES_SYSYEM_STEP_DELAY/1000)/60;
                        
                        if(votereward){
                                int reward_votes = getVotes();
                                
                                if(reward_votes != -1){
                                        _log.info("[server] Server's Votes: " + reward_votes);
                                        player.sendPacket(new CreatureSay(1,Say2.PARTY,"Vote System :"," Help your server by voting now at l2darkdays.com. Current votes are " + reward_votes + "...");

                                   if (reward_votes != 0 && reward_votes >= getVoteCount() + Config.VOTES_FOR_REWARD)
                                        {
                                                already_rewarded = new ArrayList<String>();
                                                
                                                Collection<L2PcInstance> pls = L2World.getInstance().getAllPlayers();

                                                Announcements.getInstance().gameAnnounceToAll("[Vote System] You have been rewarder for voting,check inventory");
                                                
                                                //iteminstance check edw pigenei
                                                for (L2PcInstance player : pls)
                                                {
                                                        if (player != null && !player.isOffline())
                                                        {
                                                                if(player._active_boxes<=1 || (player._active_boxes>1 && checkSingleBox(player))){ //must have anti dualbox method
                                                                        
                                                                        Set<Integer> items = Config.VOTES_REWARD_LIST.keySet();
                                                                        for (Integer i : items)
                                                                        {
                                                                                //item = player.getInventory().getItemByItemId(i);

                                                                                player.addItem("reward", i, Config.VOTES_REWARDS_LIST.get(i), player, true);

                                                                        }
                                                                        
                                                                }
                                                        }
                                                }
                                                setVoteCount(reward_votes);
                                        }
                                       player.sendPacket(new CreatureSay(1,Say2.PARTY,"Vote System :"," Help your server by voting now at l2darkdays.com. Next count at "+minutes+" minutes and at " + (getVoteCount() + Config.VOTES_FOR_REWARD) + " Votes!!");
                                        }
                                
                        }

if(votereward && Config.VOTES_SYSYEM_STEP_DELAY>0)
                                try
                                {
                                        Thread.sleep(Config.VOTES_SYSYEM_STEP_DELAY/2);
                                }
                                catch(InterruptedException e)
                                {
                                        if(Config.ENABLE_ALL_EXCEPTIONS)
                                                e.printStackTrace();
                                }

private boolean checkSingleBox(L2PcInstance player){
                
                if(player.getClient()!=null && player.getClient().getConnection()!=null && !player.getClient().getConnection().isClosed() && !player.isOffline()){
                        
                        String playerip = player.getClient().getConnection().getInetAddress().getHostAddress();
                        
                        if(already_rewarded.contains(playerip))
                                return false;
                        else{
                                already_rewarded.add(playerip);
                                return true;
                        }
                }
                
                //maybe offline shop so dont reward
                return false;
        }
        
        private int getVotes()
        {
                int votes = -1;
                URL url = null;
                InputStreamReader isr = null;
                BufferedReader in = null;
                try
                {
                        url = new URL(Config.VOTES_SITE_X_URL);
                        URLConnection con = url.openConnection();    
                        con.addRequestProperty("User-Agent", "Mozilla/4.76");               
                        isr = new InputStreamReader(con.getInputStream());                  
                        in = new BufferedReader(isr);
                        String inputLine;
                        while ((inputLine = in.readLine()) != null)
                        {
                                if (inputLine.contains("moreinfo_total_rank_text"))
                                {
                                        votes = Integer.valueOf(inputLine.split(">")[2].replace("</div", ""));
                                        break;
                                }
                        }
                }
                catch (Exception e)
                {
                        _log.info("topsite is offline or something is wrong in link");
                        Announcements.getInstance().gameAnnounceToAll("Current topsite is offline,try not to restart the server because will be crushed on reboot/");
                        //e.printStackTrace();
                }
                finally
                {
                        try
                        {
                                if(in!=null)
                                        in.close();
                        }
                        catch (Exception e)
                        {
                                if(Config.ENABLE_ALL_EXCEPTIONS)
                                        e.printStackTrace();
                        }
                        try
                        {
                                if(isr!=null)
                                        isr.close();
                        }
                        catch (Exception e)
                        {
                                if(Config.ENABLE_ALL_EXCEPTIONS)
                                        e.printStackTrace();
                        }
                }
                return votes;
        }

private void setVoteCount(int voteCount)
        {
                VotesCount = voteCount;
        }

        private int getVoteCount()
        {
                return VotesCount;
        }


   public static AutoVoteRewardHandler getInstance()
        {
                if(Config.VOTES_SITE_X_URL != null && !Config.VOTES_SITE_X_URL.equals("")){
                        votereward = true;
                }

if(hopzone())
                        return SingletonHolder._instance;
                else
                        return null;
        }

        @SuppressWarnings("synthetic-access")
        private static class SingletonHolder
        {
                protected static final AutoVoteRewardHandler    _instance       = new AutoVoteRewardHandler();
        }
}

Link to comment
Share on other sites

  • 0

edw einai to AutoVoteRewardHandler pou exw

/* 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.l2jserver.gameserver.model;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.URL;
import java.net.URLConnection;

import com.l2jserver.Config;
import com.l2jserver.gameserver.Announcements;
import com.l2jserver.gameserver.GmListTable;
import com.l2jserver.gameserver.ThreadPoolManager;
import com.l2jserver.gameserver.model.L2ItemInstance;
import com.l2jserver.gameserver.model.L2World;
import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
import com.l2jserver.gameserver.network.clientpackets.Say2;
import com.l2jserver.gameserver.network.serverpackets.CreatureSay;




public class AutoVoteRewardHandler
{
private int	lastVoteCount = 0;
private int	initialCheck = 60 * 1000;														
private int	delayForCheck = Config.DELAY_FOR_NEXT_REWARD * 1000;	

private AutoVoteRewardHandler()

{
	if (Config.VOTE_REWARD_ENABLE)
	{		
	System.out.println("========= "+Config.SERVER_NAME_FOR_VOTES+" ========= HopZone =========");
	System.out.println("Vote Reward System activated");
	System.out.println("========= "+Config.SERVER_NAME_FOR_VOTES+" ========= HopZone =========");
	ThreadPoolManager.getInstance().scheduleGeneralAtFixedRate(new AutoReward(), initialCheck, delayForCheck);
	}
}


private class AutoReward implements Runnable
{
	public void run()		
	{
		if (Config.VOTE_REWARD_ENABLE)
		{
		System.out.println("");
		System.out.println("========= HopZone =========");
		System.out.println("Vote Count Check.");
		if (Config.VOTE_REWARD1_ID == 0 || Config.VOTE_REWARD1_COUNT == 0 || Config.VOTE_REWARD2_ID == 0 || Config.VOTE_REWARD2_COUNT == 0 || Config.VOTE_REWARD3_ID == 0 || Config.VOTE_REWARD3_COUNT == 0 || Config.VOTE_REWARD4_ID == 0 || Config.VOTE_REWARD4_COUNT == 0 || Config.VOTE_REWARD5_ID == 0 || Config.VOTE_REWARD5_COUNT == 0 || Config.VOTE_REWARD6_ID == 0 || Config.VOTE_REWARD6_COUNT == 0)
		{
			GmListTable.broadcastMessageToGMs("The rewards aren't Identified. Please take a look.");
			return;
		}
		int newVoteCount = getVotes(Config.VOTE_HTML_PATCH);
		System.out.println("getLastVoteCount:"+getLastVoteCount());
		System.out.println("newVoteCount:"+newVoteCount);
		System.out.println("========= HopZone =========");
		System.out.println("");
		if (newVoteCount != 0 && getLastVoteCount() != 0 && newVoteCount >= getLastVoteCount() + Config.VOTES_FOR_REWARD)
		{
			for (L2PcInstance player : L2World.getInstance().getAllPlayers().values())
			{
				if (player != null)
				{
						L2ItemInstance item1 = player.getInventory().getItemByItemId(Config.VOTE_REWARD1_ID);
						if (item1 == null || item1.getCount() < Config.MAX_REWARD_COUNT_FOR_STACK_ITEM1)
						{
							if (player.getAppearance().getNameColor() != Config.OFFLINE_NAME_COLOR)
							{
								player.addItem("reward", Config.VOTE_REWARD1_ID, Config.VOTE_REWARD1_COUNT, player, true);
							}
						}
						else
						{
							player.sendMessage("[" + Config.SERVER_NAME_FOR_VOTES+"]" + "You have reached our limit for vote reward items!!");
						}
						L2ItemInstance item2 = player.getInventory().getItemByItemId(Config.VOTE_REWARD2_ID);
						if (item2 == null || item2.getCount() < Config.MAX_REWARD_COUNT_FOR_STACK_ITEM2)
						{
							if (player.getAppearance().getNameColor() != Config.OFFLINE_NAME_COLOR)
							{
								player.addItem("reward", Config.VOTE_REWARD2_ID, Config.VOTE_REWARD2_COUNT, player, true);
							}
						}
						else
						{
							player.sendMessage("[" + Config.SERVER_NAME_FOR_VOTES+"]" + "You have reached our limit for vote reward items!!");
						}
						L2ItemInstance item3 = player.getInventory().getItemByItemId(Config.VOTE_REWARD3_ID);
				if (item3 == null || item3.getCount() < Config.MAX_REWARD_COUNT_FOR_STACK_ITEM3)
				{
					if (player.getAppearance().getNameColor() != Config.OFFLINE_NAME_COLOR)
					{
						player.addItem("reward", Config.VOTE_REWARD3_ID, Config.VOTE_REWARD3_COUNT, player, true);
					}
				}
				else
				{
					player.sendMessage("[" + Config.SERVER_NAME_FOR_VOTES+"]" + "You have reached our limit for vote reward items!!");
				}
				L2ItemInstance item4 = player.getInventory().getItemByItemId(Config.VOTE_REWARD4_ID);
				if (item4 == null || item4.getCount() < Config.MAX_REWARD_COUNT_FOR_STACK_ITEM4)
				{
					if (player.getAppearance().getNameColor() != Config.OFFLINE_NAME_COLOR)
					{
						player.addItem("reward", Config.VOTE_REWARD4_ID, Config.VOTE_REWARD4_COUNT, player, true);
					}
				}
				else
				{
					player.sendMessage("[" + Config.SERVER_NAME_FOR_VOTES+"]" + "You have reached our limit for vote reward items!!");
				}
				L2ItemInstance item5 = player.getInventory().getItemByItemId(Config.VOTE_REWARD5_ID);
				if (item5 == null || item5.getCount() < Config.MAX_REWARD_COUNT_FOR_STACK_ITEM5)
				{
					if (player.getAppearance().getNameColor() != Config.OFFLINE_NAME_COLOR)
					{
						player.addItem("reward", Config.VOTE_REWARD5_ID, Config.VOTE_REWARD5_COUNT, player, true);
					}
				}
				else
				{
					player.sendMessage("[" + Config.SERVER_NAME_FOR_VOTES+"]" + "You have reached our limit for vote reward items!!");
				}
				L2ItemInstance item6 = player.getInventory().getItemByItemId(Config.VOTE_REWARD6_ID);
				if (item6 == null || item6.getCount() < Config.MAX_REWARD_COUNT_FOR_STACK_ITEM6)
				{
					if (player.getAppearance().getNameColor() != Config.OFFLINE_NAME_COLOR)
					{
						player.addItem("reward", Config.VOTE_REWARD6_ID, Config.VOTE_REWARD6_COUNT, player, true);
					}
				}
				else
				{
					player.sendMessage("[" + Config.SERVER_NAME_FOR_VOTES+"]" + "You have reached our limit for vote reward items!!");
				}
				}
			}	
			setLastVoteCount(newVoteCount);
		}
		Announcements.getInstance().announceToAll(" Help your server by voting now at mywebsite. We need " + (getLastVoteCount()+ Config.VOTES_FOR_REWARD) + " Votes in HopZone for reward all players. At this moment we have " + newVoteCount + " Votes. ");
		if (getLastVoteCount() == 0)
		{
			setLastVoteCount(newVoteCount);
		}
		}
	}
}

private int getVotes(String urlString)
{
	InputStreamReader isr = null;
	BufferedReader in = null;
	try
	{
		URL url = new URL(urlString);
		URLConnection con = url.openConnection();
		con.addRequestProperty("User-Agent", "Mozilla/4.76"); 
		isr = new InputStreamReader(con.getInputStream());
		in = new BufferedReader(isr);
		String inputLine;
		int voteCount = 0;
		while ((inputLine = in.readLine()) != null)
		{
			if (inputLine.contains("moreinfo_total_rank_text"))
			{
				int Sub = 12;
				switch (inputLine.length())
				{
					case 116:
						Sub = 13; 
						break;
					case 117:
						Sub = 14; 
						break;
					case 118:
						Sub = 15;
						break;
					case 119:
						Sub = 16; 
						break;
				}
				voteCount = Integer.parseInt(inputLine.substring(inputLine.length() - Sub, inputLine.length() - 11));
				break;
			}
		}
		return voteCount;
	}
	catch (IOException e)
	{
		e.printStackTrace();
		return 0;
	}
	finally
	{
		try
		{
			in.close();
		}
		catch (IOException e)
		{

		}
		try
		{
			isr.close();
		}
		catch (IOException e)
		{

		}
	}
}

/**
 * @return
 */

private void setLastVoteCount(int voteCount)
{
	lastVoteCount = voteCount;
}

private int getLastVoteCount()
{
	return lastVoteCount;
}

public static AutoVoteRewardHandler getInstance()
{
	return SingletonHolder._instance;
}

@SuppressWarnings("synthetic-access")
private static class SingletonHolder
{
	protected static final AutoVoteRewardHandler _instance = new AutoVoteRewardHandler();
}
}

 

an to kanw etsi

 

}	
			setLastVoteCount(newVoteCount);
		}
		player.sendPacket(new CreatureSay(1,Say2.PARTY,"Vote System :"," Help your server by voting now at myweb. We need " + (getLastVoteCount()+ Config.VOTES_FOR_REWARD) + " Votes in HopZone for reward all players. At this moment we have " + newVoteCount + " Votes. )"));
		if (getLastVoteCount() == 0)
		{
			setLastVoteCount(newVoteCount);
		}

 

xwris na balw to

}
         Collection<L2PcInstance> plss = L2World.getInstance().getAllPlayers();
         for (L2PcInstance player : plss)
         {

 

mou bgazei error mono to

{

player.sendPacket(new CreatureSay(1,Say2.PARTY,"Vote System :"," Help your server by voting now at myweb. We need " + (getLastVoteCount()+ Config.VOTES_FOR_REWARD) + " Votes in HopZone for reward all players. At this moment we have " + newVoteCount + " Votes. )"));

if (getLastVoteCount() == 0)

{

 

enw an balw to allo apo panw mou bgazei k poio katw error

 

 

Link to comment
Share on other sites

Guest
This topic is now closed to further replies.


×
×
  • Create New...