Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --- Código: ---
- ### Eclipse Workspace Patch 1.0
- #P L2jFrozen_GameServer
- Index: head-src/com/l2jfrozen/Config.java
- ===================================================================
- --- head-src/com/l2jfrozen/Config.java (revision 1004)
- +++ head-src/com/l2jfrozen/Config.java (working copy)
- @@ -2398,7 +2398,20 @@
- public static String FARM2_CUSTOM_MESSAGE;
- public static String PVP1_CUSTOM_MESSAGE;
- public static String PVP2_CUSTOM_MESSAGE;
- -
- +
- + // Vote Reward System Configs
- + public static int VOTES_FOR_REWARD;
- +
- + public static String VOTES_REWARDS;
- + public static String VOTES_SITE_L2JBrasil_URL;
- + public static String VOTES_SITE_Adminsprol2_URL;
- + public static FastMap VOTES_REWARDS_LIST;
- +
- + public static int VOTES_SYSYEM_INITIAL_DELAY;
- + public static int VOTES_SYSYEM_STEP_DELAY;
- +
- + public static String SERVER_WEB_SITE;
- + public static boolean AUTOVOTEREWARD_ENABLED;
- //============================================================
- public static void loadL2JFrozenConfig()
- {
- @@ -2517,6 +2530,33 @@
- FARM2_CUSTOM_MESSAGE = L2JFrozenSettings.getProperty("Farm2CustomMeesage", "You have been teleported to Farm Zone 2!");
- PVP1_CUSTOM_MESSAGE = L2JFrozenSettings.getProperty("PvP1CustomMeesage", "You have been teleported to PvP Zone 1!");
- PVP2_CUSTOM_MESSAGE = L2JFrozenSettings.getProperty("PvP2CustomMeesage", "You have been teleported to PvP Zone 2!");
- + AUTOVOTEREWARD_ENABLED = Boolean.parseBoolean(L2JFrozenSettings.getProperty("VoteRewardSystem", "true"));
- + VOTES_FOR_REWARD = Integer.parseInt(L2JFrozenSettings.getProperty("VotesRequiredForReward", "100"));
- + VOTES_SYSYEM_INITIAL_DELAY = Integer.parseInt(L2JFrozenSettings.getProperty("VotesSystemInitialDelay", "60000"));
- + VOTES_SYSYEM_STEP_DELAY = Integer.parseInt(L2JFrozenSettings.getProperty("VotesSystemStepDelay", "1800000"));
- + VOTES_SITE_Adminsprol2_URL = L2JFrozenSettings.getProperty("VotesSiteAdminsprol2Url", "");
- + VOTES_SITE_L2JBrasil_URL = L2JFrozenSettings.getProperty("VotesSiteL2JBrasilUrl", "");
- + SERVER_WEB_SITE = L2JFrozenSettings.getProperty("ServerWebSite", "");
- + VOTES_REWARDS = L2JFrozenSettings.getProperty("VotesRewards", "");
- + VOTES_REWARDS_LIST = new FastMap();
- +
- + String[] splitted_VOTES_REWARDS = VOTES_REWARDS.split(";");
- +
- + for (String reward : splitted_VOTES_REWARDS)
- + {
- +
- + String[] item_count = reward.split(",");
- +
- + if (item_count.length != 2)
- + {
- + System.out.println("[VotesRewards]: invalid config property -> VotesRewards \"" + VOTES_REWARDS + "\"");
- + }
- + else
- + {
- + VOTES_REWARDS_LIST.put(Integer.parseInt(item_count[0]), Integer.parseInt(item_count[1]));
- + }
- +
- + }
- }
- catch(Exception e)
- {
- Index: head-src/com/l2jfrozen/gameserver/handler/AutoVoteRewardCaFi.java
- ===================================================================
- --- head-src/com/l2jfrozen/gameserver/handler/AutoVoteRewardCaFi.java (revision 0)
- +++ head-src/com/l2jfrozen/gameserver/handler/AutoVoteRewardCaFi.java (working copy)
- @@ -0,0 +1,361 @@
- +package com.l2jfrozen.gameserver.handler;
- +
- +import java.io.BufferedReader;
- +import java.io.IOException;
- +import java.io.InputStream;
- +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.l2jfrozen.Config;
- +import com.l2jfrozen.gameserver.model.L2World;
- +import com.l2jfrozen.gameserver.model.actor.instance.L2PcInstance;
- +import com.l2jfrozen.gameserver.model.entity.Announcements;
- +import com.l2jfrozen.gameserver.thread.ThreadPoolManager;
- +
- +/*************************************
- + * @author* Fissban * Adaptacion CaFi*
- + ************************************/
- +
- +public class AutoVoteRewardCaFi
- +{
- + protected static final Logger _log = Logger.getLogger(AutoVoteRewardCaFi.class.getName());
- +
- + private int Adminsprol2VotesCount = 0;
- + private int L2JBrasilVotesCount = 0;
- + protected List already_rewarded;
- +
- + protected static boolean L2JBrasil = false;
- + protected static boolean Adminsprol2 = false;
- +
- + private AutoVoteRewardCaFi()
- + {
- + _log.info("Vote Reward System Initiated.");
- +
- + if (Adminsprol2)
- + {
- + int Adminsprol2_votes = getAdminsprol2Votes();
- +
- + if (Adminsprol2_votes == -1)
- + {
- + Adminsprol2_votes = 0;
- + }
- +
- + setAdminsprol2VoteCount(Adminsprol2_votes);
- + }
- +
- + if (L2JBrasil)
- + {
- + int L2JBrasil_votes = getL2JBrasilVotes();
- +
- + if (L2JBrasil_votes == -1)
- + {
- + L2JBrasil_votes = 0;
- + }
- +
- + setL2JBrasilVoteCount(L2JBrasil_votes);
- + }
- +
- + ThreadPoolManager.getInstance().scheduleGeneralAtFixedRate(new AutoReward(), Config.VOTES_SYSYEM_INITIAL_DELAY, Config.VOTES_SYSYEM_STEP_DELAY);
- + }
- +
- + protected class AutoReward implements Runnable
- + {
- + @Override
- + public void run()
- + {
- + int minutes = (Config.VOTES_SYSYEM_STEP_DELAY / 1000) / 60;
- +
- + if (Adminsprol2)
- + {
- + int Adminsprol2_votes = getAdminsprol2Votes();
- +
- + if (Adminsprol2_votes != -1)
- + {
- + _log.info("[AutoVoteReward] Server Adminsprol2 Votes: " + Adminsprol2_votes);
- + Announcements.getInstance().gameAnnounceToAll("[AutoVoteReward] Actual Adminsprol2 Votes are " + Adminsprol2_votes + "...");
- +
- + if ((Adminsprol2_votes != 0) && (Adminsprol2_votes >= (getAdminsprol2VoteCount() + Config.VOTES_FOR_REWARD)))
- + {
- + already_rewarded = new ArrayList();
- +
- + Collection pls = L2World.getInstance().getAllPlayers();
- +
- + Announcements.getInstance().gameAnnounceToAll("[AutoVoteReward] Great Work! Check your inventory for Reward!!");
- +
- + // L2ItemInstance item;
- + for (L2PcInstance player : pls)
- + {
- + if ((player != null) && !player.isOffline() && (player.isOnline() == 1))
- + {
- + if ((player._active_boxes <= 1) || ((player._active_boxes > 1) && checkSingleBox(player)))
- + {
- +
- + Set items = Config.VOTES_REWARDS_LIST.keySet();
- + for (Integer i : items)
- + {
- + // item = player.getInventory().getItemByItemId(i);
- +
- + // TODO: check on maxstack for item
- + player.addItem("reward", i, Config.VOTES_REWARDS_LIST.get(i), player, true);
- +
- + }
- +
- + }
- + }
- + }
- + setAdminsprol2VoteCount(Adminsprol2_votes);
- + }
- + Announcements.getInstance().gameAnnounceToAll("[AutoVoteReward] Next Adminsprol2 Reward in " + minutes + " minutes at " + (getAdminsprol2VoteCount() + Config.VOTES_FOR_REWARD) + " Votes!!");
- + // site web
- + Announcements.getInstance().gameAnnounceToAll("[SiteWeb] " + Config.SERVER_WEB_SITE);
- +
- + }
- +
- + }
- +
- + if (L2JBrasil && Adminsprol2 && (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();
- + }
- + }
- + }
- +
- + if (L2JBrasil)
- + {
- + int L2JBrasil_votes = getL2JBrasilVotes();
- +
- + if (L2JBrasil_votes != -1)
- + {
- +
- + _log.info("[AutoVoteReward] Server L2JBrasil Votes: " + L2JBrasil_votes);
- + Announcements.getInstance().gameAnnounceToAll("[AutoVoteReward] Actual L2JBrasil Votes are " + L2JBrasil_votes + "...");
- +
- + if ((L2JBrasil_votes != 0) && (L2JBrasil_votes >= (getL2JBrasilVoteCount() + Config.VOTES_FOR_REWARD)))
- + {
- + already_rewarded = new ArrayList();
- +
- + Collection pls = L2World.getInstance().getAllPlayers();
- +
- + Announcements.getInstance().gameAnnounceToAll("[AutoVoteReward] Great Work! Check your inventory for Reward!!");
- +
- + // L2ItemInstance item;
- + for (L2PcInstance player : pls)
- + {
- + if ((player != null) && !player.isOffline() && (player.isOnline() == 1))
- + {
- + if ((player._active_boxes <= 1) || ((player._active_boxes > 1) && checkSingleBox(player)))
- + {
- +
- + Set items = Config.VOTES_REWARDS_LIST.keySet();
- + for (Integer i : items)
- + {
- + // item = player.getInventory().getItemByItemId(i);
- +
- + // TODO: check on maxstack for item
- + player.addItem("reward", i, Config.VOTES_REWARDS_LIST.get(i), player, true);
- +
- + }
- +
- + }
- + }
- + }
- + setL2JBrasilVoteCount(L2JBrasil_votes);
- + }
- +
- + Announcements.getInstance().gameAnnounceToAll("[AutoVoteReward] Next L2JBrasil Reward in " + minutes + " minutes at " + (getL2JBrasilVoteCount() + Config.VOTES_FOR_REWARD) + " Votes!!");
- + // site web
- + Announcements.getInstance().gameAnnounceToAll("[SiteWeb] " + Config.SERVER_WEB_SITE);
- +
- + }
- +
- + }
- +
- + }
- + }
- +
- + protected 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;
- + already_rewarded.add(playerip);
- + return true;
- + }
- +
- + // if no connection (maybe offline shop) dnt reward
- + return false;
- + }
- +
- + protected int getAdminsprol2Votes()
- + {
- + int votes = -1;
- + URL url = null;
- + URLConnection con = null;
- + InputStream is = null;
- + InputStreamReader isr = null;
- + BufferedReader in = null;
- + try
- + {
- + url = new URL("http://hopzone.com.e...omServer.php?ID=" + Config.VOTES_SITE_Adminsprol2_URL);
- + con = url.openConnection();
- + con.addRequestProperty("User-Agent", "Mozilla/4.76");
- + is = con.getInputStream();
- + isr = new InputStreamReader(is);
- + in = new BufferedReader(isr);
- + String inputLine;
- + while ((inputLine = in.readLine()) != null)
- + {
- + return Integer.parseInt(inputLine);
- + }
- + }
- + catch (Exception e)
- + {
- + _log.info("[AutoVoteReward] Server Adminsprol2 is offline or something is wrong in link");
- + Announcements.getInstance().gameAnnounceToAll("[AutoVoteReward] Adminsprol2 is offline. We will check reward as it will be online again");
- + // e.printStackTrace();
- + }
- + finally
- + {
- + if (in != null)
- + {
- + try
- + {
- + in.close();
- + }
- + catch (IOException e1)
- + {
- + e1.printStackTrace();
- + }
- + }
- + if (isr != null)
- + {
- + try
- + {
- + isr.close();
- + }
- + catch (IOException e1)
- + {
- + e1.printStackTrace();
- + }
- + }
- + if (is != null)
- + {
- + try
- + {
- + is.close();
- + }
- + catch (IOException e1)
- + {
- + e1.printStackTrace();
- + }
- + }
- +
- + }
- + return votes;
- + }
- +
- + protected int getL2JBrasilVotes()
- + {
- + try
- + {
- + URL url = new URL(Config.VOTES_SITE_L2JBrasil_URL);
- + URLConnection con = url.openConnection();
- + con.addRequestProperty("User-Agent", "Mozilla/4.76");
- + InputStreamReader isr = new InputStreamReader(con.getInputStream());
- + BufferedReader in = new BufferedReader(isr);
- + String inputLine;
- +
- + boolean search = false;
- + int count = 0;
- + while ((inputLine = in.readLine()) != null)
- + {
- + if (inputLine.contains("Este M"))
- + {
- + search = true;
- + }
- + else if (search && inputLine.contains(""))
- + {
- + if (count > 0)
- + {
- + String votes = inputLine.replace("", "");
- + votes = votes.replace("", "");
- + votes = votes.trim();
- + return Integer.parseInt(votes);
- + }
- + count++;
- + }
- + }
- + }
- + catch (IOException e)
- + {
- + _log.warning("AutoVoteBrasil: " + e);
- + }
- + finally
- + {
- + }
- + return 0;
- + }
- +
- + protected void setAdminsprol2VoteCount(int voteCount)
- + {
- + Adminsprol2VotesCount = voteCount;
- + }
- +
- + protected int getAdminsprol2VoteCount()
- + {
- + return Adminsprol2VotesCount;
- + }
- +
- + protected void setL2JBrasilVoteCount(int voteCount)
- + {
- + L2JBrasilVotesCount = voteCount;
- + }
- +
- + protected int getL2JBrasilVoteCount()
- + {
- + return L2JBrasilVotesCount;
- + }
- +
- + public static AutoVoteRewardCaFi getInstance()
- + {
- + if ((Config.VOTES_SITE_Adminsprol2_URL != null) && !Config.VOTES_SITE_Adminsprol2_URL.equals(""))
- + {
- + Adminsprol2 = true;
- + }
- +
- + if ((Config.VOTES_SITE_L2JBrasil_URL != null) && !Config.VOTES_SITE_L2JBrasil_URL.equals(""))
- + {
- + L2JBrasil = true;
- + }
- +
- + if (L2JBrasil || Adminsprol2)
- + {
- + return SingletonHolder._instance;
- + }
- + return null;
- + }
- +
- + @SuppressWarnings("synthetic-access")
- + private static class SingletonHolder
- + {
- + protected static final AutoVoteRewardCaFi _instance = new AutoVoteRewardCaFi();
- + }
- +}
- \ No newline at end of file
- Index: head-src/com/l2jfrozen/gameserver/GameServer.java
- ===================================================================
- --- head-src/com/l2jfrozen/gameserver/GameServer.java (revision 1004)
- +++ head-src/com/l2jfrozen/gameserver/GameServer.java (working copy)
- @@ -81,6 +81,7 @@
- import com.l2jfrozen.gameserver.handler.AdminCommandHandler;
- import com.l2jfrozen.gameserver.handler.AutoAnnouncementHandler;
- import com.l2jfrozen.gameserver.handler.AutoChatHandler;
- +import com.l2jfrozen.gameserver.handler.AutoVoteRewardCaFi;
- import com.l2jfrozen.gameserver.handler.ItemHandler;
- import com.l2jfrozen.gameserver.handler.SkillHandler;
- import com.l2jfrozen.gameserver.handler.UserCommandHandler;
- @@ -230,6 +231,7 @@
- MapRegionTable.getInstance();
- Announcements.getInstance();
- AutoAnnouncementHandler.getInstance();
- + AutoVoteRewardCaFi.getInstance();
- if (!IdFactory.getInstance().isInitialized())
- {
- _log.info("Could not read object IDs from DB. Please Check Your Data.");
- Index: config/functions/l2jfrozen.properties
- ===================================================================
- --- config/functions/l2jfrozen.properties (revision 1004)
- +++ config/functions/l2jfrozen.properties (working copy)
- @@ -280,4 +280,17 @@
- ProtectorSkillLevel = 13
- ProtectorSkillTime = 600
- # Npc Protector Message
- -ProtectorMessage = Hey You!, Never Kill On This Area, Go Read The Rules!
- \ No newline at end of file
- +ProtectorMessage = Hey You!, Never Kill On This Area, Go Read The Rules!
- +
- +# Automatic Vote Reward System
- +VoteRewardSystem= True
- +VotesRequiredForReward = 10
- +VotesSystemInitialDelay= 60000
- +VotesSystemStepDelay= 1800000
- +VotesRewards= 3470,20;
- +
- +#Leave empty to disable one site
- +#if you need just one of these
- +VotesSiteAdminsprol2Url=
- +VotesSiteL2JBrasilUrl=
- +ServerWebSite= http://www.l2jbrasil.com
- \ No newline at end of file
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement