Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ### Eclipse Workspace Patch 1.0
- #P aCis_gameserver
- Index: java/additional/files/AutoRewarder.java
- ===================================================================
- --- java/additional/files/AutoRewarder.java (revision 0)
- +++ java/additional/files/AutoRewarder.java (working copy)
- @@ -0,0 +1,141 @@
- +/*
- + * 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 3 of the License, 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, see <http://www.gnu.org/licenses/>.
- + */
- +package additional.files;
- +
- +import java.util.Collection;
- +import java.util.HashMap;
- +import java.util.Map;
- +import java.util.logging.Level;
- +import java.util.logging.Logger;
- +
- +import net.sf.l2j.Config;
- +import net.sf.l2j.gameserver.Announcements;
- +import net.sf.l2j.gameserver.ThreadPoolManager;
- +import net.sf.l2j.gameserver.model.L2ItemInstance;
- +import net.sf.l2j.gameserver.model.L2World;
- +import net.sf.l2j.gameserver.model.actor.instance.L2PcInstance;
- +import net.sf.l2j.gameserver.network.SystemMessageId;
- +import net.sf.l2j.gameserver.network.clientpackets.Say2;
- +import net.sf.l2j.gameserver.network.serverpackets.CreatureSay;
- +import net.sf.l2j.gameserver.network.serverpackets.InventoryUpdate;
- +import net.sf.l2j.gameserver.network.serverpackets.SystemMessage;
- +
- +/**
- + * @author Devlin
- + *
- + */
- +public class AutoRewarder implements Runnable
- +{
- + protected static final Logger _log = Logger.getLogger(AutoRewarder.class.getName());
- + public static int rewardTime = Config.AUTO_REWARDER_SCHEDULE; // schedule in minutes.
- + public static int[][] rewards = Config.AUTO_REWARDER_REWARDS; // rewards.
- + public static int dualboxAllowed = Config.AUTO_REWARDER_DUALBOX_ALLOWED;
- + private static Map<String, Integer> playerIps = new HashMap<>();
- +
- + @Override
- + public void run()
- + {
- + schedule(rewardTime);
- + rewardOnlinePlayers();
- + }
- +
- + public void rewardOnlinePlayers()
- + {
- + Collection<L2PcInstance> _players = L2World.getInstance().getAllPlayers().values();
- + for (L2PcInstance players : _players)
- + {
- + boolean canReward = false;
- + String pIp = players.getClient().getConnection().getInetAddress().getHostAddress();
- + if (playerIps.containsKey(pIp))
- + {
- + int count = playerIps.get(pIp);
- + if (count < dualboxAllowed)
- + {
- + playerIps.remove(pIp);
- + playerIps.put(pIp, count+1);
- + canReward = true;
- + }
- + }
- + else
- + {
- + canReward = true;
- + playerIps.put(pIp, 1);
- + }
- +
- + if (canReward)
- + {
- + Announcements.announceToAll("All players have been rewarded.");
- + players.sendPacket(new CreatureSay(0, Say2.TRADE, "[AR]", "You have been rewarded."));
- + autoRewards(players, getAutoRewards());
- + }
- + else
- + {
- + players.sendMessage("Already "+dualboxAllowed+" character(s) of your ip have been rewarded, so this character won't be rewarded.");
- + }
- + }
- + playerIps.clear();
- + }
- +
- + public static final void autoRewards(L2PcInstance player, int[][] reward)
- + {
- + if (player == null || !player.isOnline() || reward == null)
- + return;
- +
- + try
- + {
- + final InventoryUpdate iu = new InventoryUpdate();
- + for (int[] it : reward)
- + {
- + if (it == null || it.length != 2)
- + continue;
- +
- + final L2ItemInstance item = player.getInventory().addItem("Init", it[0], it[1], player, null);
- + if (item == null)
- + continue;
- +
- + iu.addModifiedItem(item);
- + player.sendPacket(SystemMessage.getSystemMessage(SystemMessageId.EARNED_S2_S1_S).addItemName(it[0]).addNumber(it[1]));
- + }
- + player.sendPacket(iu);
- + }
- + catch (Exception e)
- + {
- + _log.log(Level.WARNING, e.getMessage(), e);
- + }
- + }
- +
- + public final static int[][] getAutoRewards()
- + {
- + return rewards;
- + }
- +
- + protected ThreadPoolManager thread;
- + private AutoRewarder task;
- +
- + protected void schedule(int time)
- + {
- + thread.scheduleGeneral(task, time*1000*60);
- + }
- +
- + public static AutoRewarder getInstance()
- + {
- + return SingletonHolder._instance;
- + }
- +
- + private static class SingletonHolder
- + {
- + protected static final AutoRewarder _instance = new AutoRewarder();
- + }
- +}
- \ No newline at end of file
- Index: java/net/sf/l2j/gameserver/GameServer.java
- ===================================================================
- --- java/net/sf/l2j/gameserver/GameServer.java (revision 32)
- +++ java/net/sf/l2j/gameserver/GameServer.java (working copy)
- @@ -14,6 +14,7 @@
- */
- package net.sf.l2j.gameserver;
- +import additional.files.AutoRewarder;
- import additional.files.events.EventBuffer;
- import additional.files.events.EventManager;
- import additional.files.events.EventStats;
- @@ -247,6 +248,8 @@
- Util.printSection("Quests & Scripts");
- QuestManager.getInstance();
- BoatManager.getInstance();
- + if (Config.ALLOW_AUTO_REWARDER)
- + AutoRewarder.getInstance();
- if (!Config.ALT_DEV_NO_SCRIPTS)
- {
- Index: config/custom.properties
- ===================================================================
- --- config/custom.properties (revision 32)
- +++ config/custom.properties (working copy)
- @@ -167,4 +167,25 @@
- # Bow restriction on some classes.
- AllowBowRestriction = True
- # Heavy restriction on some classes.
- -AllowHeavyRestriction = True
- \ No newline at end of file
- +AllowHeavyRestriction = True
- +
- +# Auto rewarder by Devlin.
- +AllowAutoRewarder = True
- +# Schedule (minutes).
- +AutoRewarderSchedule = 180
- +# Rewards.
- +AutoRewarderRewards = 57,1000
- +# Dual box allowed.
- +AutoRewarderDualboxAllowed = 2
- \ No newline at end of file
- Index: java/net/sf/l2j/Config.java
- ===================================================================
- --- java/net/sf/l2j/Config.java (revision 32)
- +++ java/net/sf/l2j/Config.java (working copy)
- @@ -783,6 +783,13 @@
- public static boolean ALLOW_BOW_RESTRICTION;
- public static boolean ALLOW_HEAVY_RESTRICTION;
- +
- + public static boolean ALLOW_AUTO_REWARDER;
- + public static int AUTO_REWARDER_SCHEDULE;
- + public static int[][] AUTO_REWARDER_REWARDS;
- + public static int AUTO_REWARDER_DUALBOX_ALLOWED;
- // --------------------------------------------------
- @@ -923,6 +930,35 @@
- ALLOW_BOW_RESTRICTION = custom.getProperty("AllowBowRestriction", true);
- ALLOW_HEAVY_RESTRICTION = custom.getProperty("AllowHeavyRestriction", true);
- +
- + ALLOW_AUTO_REWARDER = custom.getProperty("AllowAutoRewarder", true);
- + AUTO_REWARDER_SCHEDULE = custom.getProperty("AutoRewarderSchedule", 0);
- + AUTO_REWARDER_REWARDS = parseItemsList(custom.getProperty("AutoRewarderRewards", "6651,50"));
- + AUTO_REWARDER_DUALBOX_ALLOWED = custom.getProperty("AutoRewarderDualboxAllowed", 0);
- // ...
- // Clans settings
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement