Advertisement
Guest User

Auto Rewarder by Devlin

a guest
Jan 12th, 2014
1,231
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 7.13 KB | None | 0 0
  1. ### Eclipse Workspace Patch 1.0
  2. #P aCis_gameserver
  3. Index: java/additional/files/AutoRewarder.java
  4. ===================================================================
  5. --- java/additional/files/AutoRewarder.java (revision 0)
  6. +++ java/additional/files/AutoRewarder.java (working copy)
  7. @@ -0,0 +1,141 @@
  8. +/*
  9. + * This program is free software: you can redistribute it and/or modify it under
  10. + * the terms of the GNU General Public License as published by the Free Software
  11. + * Foundation, either version 3 of the License, or (at your option) any later
  12. + * version.
  13. + *
  14. + * This program is distributed in the hope that it will be useful, but WITHOUT
  15. + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  16. + * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
  17. + * details.
  18. + *
  19. + * You should have received a copy of the GNU General Public License along with
  20. + * this program. If not, see <http://www.gnu.org/licenses/>.
  21. + */
  22. +package additional.files;
  23. +
  24. +import java.util.Collection;
  25. +import java.util.HashMap;
  26. +import java.util.Map;
  27. +import java.util.logging.Level;
  28. +import java.util.logging.Logger;
  29. +
  30. +import net.sf.l2j.Config;
  31. +import net.sf.l2j.gameserver.Announcements;
  32. +import net.sf.l2j.gameserver.ThreadPoolManager;
  33. +import net.sf.l2j.gameserver.model.L2ItemInstance;
  34. +import net.sf.l2j.gameserver.model.L2World;
  35. +import net.sf.l2j.gameserver.model.actor.instance.L2PcInstance;
  36. +import net.sf.l2j.gameserver.network.SystemMessageId;
  37. +import net.sf.l2j.gameserver.network.clientpackets.Say2;
  38. +import net.sf.l2j.gameserver.network.serverpackets.CreatureSay;
  39. +import net.sf.l2j.gameserver.network.serverpackets.InventoryUpdate;
  40. +import net.sf.l2j.gameserver.network.serverpackets.SystemMessage;
  41. +
  42. +/**
  43. + * @author Devlin
  44. + *
  45. + */
  46. +public class AutoRewarder implements Runnable
  47. +{ 
  48. +   protected static final Logger _log = Logger.getLogger(AutoRewarder.class.getName());
  49. +   public static int rewardTime = Config.AUTO_REWARDER_SCHEDULE; // schedule in minutes.
  50. +   public static int[][] rewards = Config.AUTO_REWARDER_REWARDS; // rewards.
  51. +   public static int dualboxAllowed = Config.AUTO_REWARDER_DUALBOX_ALLOWED;
  52. +   private static Map<String, Integer> playerIps = new HashMap<>();
  53. +  
  54. +   @Override
  55. +   public void run()
  56. +   {
  57. +       schedule(rewardTime);
  58. +       rewardOnlinePlayers();
  59. +   }
  60. +  
  61. +   public void rewardOnlinePlayers()
  62. +   {
  63. +       Collection<L2PcInstance> _players = L2World.getInstance().getAllPlayers().values();
  64. +       for (L2PcInstance players : _players)
  65. +       {
  66. +           boolean canReward = false;
  67. +           String pIp = players.getClient().getConnection().getInetAddress().getHostAddress();
  68. +           if (playerIps.containsKey(pIp))
  69. +           {
  70. +               int count = playerIps.get(pIp);
  71. +               if (count < dualboxAllowed)
  72. +               {
  73. +                   playerIps.remove(pIp);
  74. +                   playerIps.put(pIp, count+1);
  75. +                   canReward = true;
  76. +               }
  77. +           }
  78. +           else
  79. +           {
  80. +               canReward = true;
  81. +               playerIps.put(pIp, 1);
  82. +           }
  83. +          
  84. +           if (canReward)
  85. +           {
  86. +               Announcements.announceToAll("All players have been rewarded.");
  87. +               players.sendPacket(new CreatureSay(0, Say2.TRADE, "[AR]", "You have been rewarded."));
  88. +               autoRewards(players, getAutoRewards());
  89. +           }
  90. +           else
  91. +           {
  92. +               players.sendMessage("Already "+dualboxAllowed+" character(s) of your ip have been rewarded, so this character won't be rewarded.");
  93. +           }
  94. +       }
  95. +       playerIps.clear();
  96. +   }
  97. +  
  98. +   public static final void autoRewards(L2PcInstance player, int[][] reward)
  99. +   {
  100. +       if (player == null || !player.isOnline() || reward == null)
  101. +           return;
  102. +      
  103. +       try
  104. +       {
  105. +           final InventoryUpdate iu = new InventoryUpdate();
  106. +           for (int[] it : reward)
  107. +           {
  108. +               if (it == null || it.length != 2)
  109. +                   continue;
  110. +              
  111. +               final L2ItemInstance item = player.getInventory().addItem("Init", it[0], it[1], player, null);
  112. +               if (item == null)
  113. +                   continue;
  114. +              
  115. +               iu.addModifiedItem(item);
  116. +               player.sendPacket(SystemMessage.getSystemMessage(SystemMessageId.EARNED_S2_S1_S).addItemName(it[0]).addNumber(it[1]));
  117. +           }
  118. +           player.sendPacket(iu);
  119. +       }
  120. +       catch (Exception e)
  121. +       {
  122. +           _log.log(Level.WARNING, e.getMessage(), e);
  123. +       }
  124. +   }
  125. +  
  126. +   public final static int[][] getAutoRewards()
  127. +   {
  128. +       return rewards;
  129. +   }
  130. +  
  131. +   protected ThreadPoolManager thread;
  132. +   private AutoRewarder task;
  133. +  
  134. +   protected void schedule(int time)
  135. +   {
  136. +       thread.scheduleGeneral(task, time*1000*60);
  137. +   }
  138. +  
  139. +   public static AutoRewarder getInstance()
  140. +   {
  141. +       return SingletonHolder._instance;
  142. +   }
  143. +  
  144. +   private static class SingletonHolder
  145. +   {
  146. +       protected static final AutoRewarder _instance = new AutoRewarder();
  147. +   }
  148. +}
  149. \ No newline at end of file
  150. Index: java/net/sf/l2j/gameserver/GameServer.java
  151. ===================================================================
  152. --- java/net/sf/l2j/gameserver/GameServer.java  (revision 32)
  153. +++ java/net/sf/l2j/gameserver/GameServer.java  (working copy)
  154. @@ -14,6 +14,7 @@
  155.   */
  156.  package net.sf.l2j.gameserver;
  157.  
  158. +import additional.files.AutoRewarder;
  159.  import additional.files.events.EventBuffer;
  160.  import additional.files.events.EventManager;
  161.  import additional.files.events.EventStats;
  162. @@ -247,6 +248,8 @@
  163.         Util.printSection("Quests & Scripts");
  164.         QuestManager.getInstance();
  165.         BoatManager.getInstance();
  166. +       if (Config.ALLOW_AUTO_REWARDER)
  167. +           AutoRewarder.getInstance();
  168.        
  169.         if (!Config.ALT_DEV_NO_SCRIPTS)
  170.         {
  171. Index: config/custom.properties
  172. ===================================================================
  173. --- config/custom.properties    (revision 32)
  174. +++ config/custom.properties    (working copy)
  175. @@ -167,4 +167,25 @@
  176.  # Bow restriction on some classes.
  177.  AllowBowRestriction = True
  178.  # Heavy restriction on some classes.
  179. -AllowHeavyRestriction = True
  180. \ No newline at end of file
  181. +AllowHeavyRestriction = True
  182. +
  183. +# Auto rewarder by Devlin.
  184. +AllowAutoRewarder = True
  185. +# Schedule (minutes).
  186. +AutoRewarderSchedule = 180
  187. +# Rewards.
  188. +AutoRewarderRewards = 57,1000
  189. +# Dual box allowed.
  190. +AutoRewarderDualboxAllowed = 2
  191. \ No newline at end of file
  192. Index: java/net/sf/l2j/Config.java
  193. ===================================================================
  194. --- java/net/sf/l2j/Config.java (revision 32)
  195. +++ java/net/sf/l2j/Config.java (working copy)
  196. @@ -783,6 +783,13 @@
  197.  
  198.     public static boolean ALLOW_BOW_RESTRICTION;
  199.     public static boolean ALLOW_HEAVY_RESTRICTION;
  200. +
  201. +   public static boolean ALLOW_AUTO_REWARDER;
  202. +   public static int AUTO_REWARDER_SCHEDULE;
  203. +   public static int[][] AUTO_REWARDER_REWARDS;
  204. +   public static int AUTO_REWARDER_DUALBOX_ALLOWED;
  205.    
  206.     // --------------------------------------------------
  207.    
  208. @@ -923,6 +930,35 @@
  209.            
  210.             ALLOW_BOW_RESTRICTION = custom.getProperty("AllowBowRestriction", true);
  211.             ALLOW_HEAVY_RESTRICTION = custom.getProperty("AllowHeavyRestriction", true);
  212. +          
  213. +           ALLOW_AUTO_REWARDER = custom.getProperty("AllowAutoRewarder", true);
  214. +           AUTO_REWARDER_SCHEDULE = custom.getProperty("AutoRewarderSchedule", 0);
  215. +           AUTO_REWARDER_REWARDS = parseItemsList(custom.getProperty("AutoRewarderRewards", "6651,50"));
  216. +           AUTO_REWARDER_DUALBOX_ALLOWED = custom.getProperty("AutoRewarderDualboxAllowed", 0);
  217.             // ...
  218.            
  219.             // Clans settings
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement