Advertisement
Bluur

Voiced Command Handlers

Dec 27th, 2014
1,935
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 8.87 KB | None | 0 0
  1. ### Eclipse Workspace Patch 1.0
  2. #P aCis_gameserver
  3. Index: java/net/sf/l2j/gameserver/handler/IVoicedCommandHandler.java
  4. ===================================================================
  5. --- java/net/sf/l2j/gameserver/handler/IVoicedCommandHandler.java   (revision 0)
  6. +++ java/net/sf/l2j/gameserver/handler/IVoicedCommandHandler.java   (working copy)
  7. @@ -0,0 +1,24 @@
  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 net.sf.l2j.gameserver.handler;
  23. +
  24. +import net.sf.l2j.gameserver.model.actor.instance.L2PcInstance;
  25. +
  26. +public interface IVoicedCommandHandler
  27. +{
  28. +   public boolean useVoicedCommand(String command, L2PcInstance activeChar, String params);
  29. +
  30. +   public String[] getVoicedCommandList();
  31. +}
  32. \ No newline at end of file
  33. Index: java/net/sf/l2j/gameserver/handler/chathandlers/ChatAll.java
  34. ===================================================================
  35. --- java/net/sf/l2j/gameserver/handler/chathandlers/ChatAll.java    (revision 1)
  36. +++ java/net/sf/l2j/gameserver/handler/chathandlers/ChatAll.java    (working copy)
  37. @@ -14,7 +14,11 @@
  38.   */
  39.  package net.sf.l2j.gameserver.handler.chathandlers;
  40.  
  41. +import java.util.StringTokenizer;
  42. +
  43.  import net.sf.l2j.gameserver.handler.IChatHandler;
  44. +import net.sf.l2j.gameserver.handler.IVoicedCommandHandler;
  45. +import net.sf.l2j.gameserver.handler.VoicedCommandHandler;
  46.  import net.sf.l2j.gameserver.model.BlockList;
  47.  import net.sf.l2j.gameserver.model.actor.instance.L2PcInstance;
  48.  import net.sf.l2j.gameserver.network.serverpackets.CreatureSay;
  49. @@ -37,15 +41,43 @@
  50.     @Override
  51.     public void handleChat(int type, L2PcInstance activeChar, String params, String text)
  52.     {
  53. -       CreatureSay cs = new CreatureSay(activeChar.getObjectId(), type, activeChar.getName(), text);
  54. +       boolean vcd_used = false;
  55. +       if (text.startsWith("."))
  56. +       {
  57. +           StringTokenizer st = new StringTokenizer(text);
  58. +           IVoicedCommandHandler vch;
  59. +           String command = "";
  60.        
  61. -       for (L2PcInstance player : activeChar.getKnownList().getKnownTypeInRadius(L2PcInstance.class, 1250))
  62. +           if (st.countTokens() > 1)
  63. +           {
  64. +               command = st.nextToken().substring(1);
  65. +               params = text.substring(command.length() + 2);
  66. +               vch = VoicedCommandHandler.getInstance().getHandler(command);
  67. +           }
  68. +           else
  69. +           {
  70. +               command = text.substring(1);
  71. +               vch = VoicedCommandHandler.getInstance().getHandler(command);
  72. +           }
  73. +                  
  74. +           if (vch != null)
  75. +           {
  76. +               vch.useVoicedCommand(command, activeChar, params);
  77. +               vcd_used = true;
  78. +           }
  79. +       }
  80. +       if (!vcd_used)
  81.         {
  82. -           if (!BlockList.isBlocked(player, activeChar))
  83. -               player.sendPacket(cs);
  84. -       }
  85. -      
  86. -       activeChar.sendPacket(cs);
  87. +           CreatureSay cs = new CreatureSay(activeChar.getObjectId(), type, activeChar.getName(), text);
  88. +          
  89. +           for (L2PcInstance player : activeChar.getKnownList().getKnownTypeInRadius(L2PcInstance.class, 1250))
  90. +           {
  91. +               if (!BlockList.isBlocked(player, activeChar))
  92. +                   player.sendPacket(cs);
  93. +           }
  94. +          
  95. +           activeChar.sendPacket(cs);
  96. +       }  
  97.     }
  98.    
  99.     /**
  100. Index: java/net/sf/l2j/gameserver/GameServer.java
  101. ===================================================================
  102. --- java/net/sf/l2j/gameserver/GameServer.java  (revision 1)
  103. +++ java/net/sf/l2j/gameserver/GameServer.java  (working copy)
  104. @@ -63,6 +63,7 @@
  105.  import net.sf.l2j.gameserver.handler.ItemHandler;
  106.  import net.sf.l2j.gameserver.handler.SkillHandler;
  107.  import net.sf.l2j.gameserver.handler.UserCommandHandler;
  108. +import net.sf.l2j.gameserver.handler.VoicedCommandHandler;
  109.  import net.sf.l2j.gameserver.idfactory.IdFactory;
  110.  import net.sf.l2j.gameserver.instancemanager.AuctionManager;
  111.  import net.sf.l2j.gameserver.instancemanager.BoatManager;
  112. @@ -275,7 +276,8 @@
  113.         _log.config("ItemHandler: Loaded " + ItemHandler.getInstance().size() + " handlers.");
  114.         _log.config("SkillHandler: Loaded " + SkillHandler.getInstance().size() + " handlers.");
  115.         _log.config("UserCommandHandler: Loaded " + UserCommandHandler.getInstance().size() + " handlers.");
  116. -      
  117. +       _log.config("VoicedCommandHandler: Loaded " + VoicedCommandHandler.getInstance().size() + " handlers.");
  118. +
  119.         if (Config.ALLOW_WEDDING)
  120.             CoupleManager.getInstance();
  121.        
  122. Index: java/net/sf/l2j/gameserver/handler/voicedcommandhandlers/Online.java
  123. ===================================================================
  124. --- java/net/sf/l2j/gameserver/handler/voicedcommandhandlers/Online.java    (revision 0)
  125. +++ java/net/sf/l2j/gameserver/handler/voicedcommandhandlers/Online.java    (working copy)
  126. @@ -0,0 +1,42 @@
  127. +/*
  128. + * This program is free software: you can redistribute it and/or modify it under
  129. + * the terms of the GNU General Public License as published by the Free Software
  130. + * Foundation, either version 3 of the License, or (at your option) any later
  131. + * version.
  132. + *
  133. + * This program is distributed in the hope that it will be useful, but WITHOUT
  134. + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  135. + * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
  136. + * details.
  137. + *
  138. + * You should have received a copy of the GNU General Public License along with
  139. + * this program. If not, see <http://www.gnu.org/licenses/>.
  140. + */
  141. +package net.sf.l2j.gameserver.handler.voicedcommandhandlers;
  142. +
  143. +import net.sf.l2j.gameserver.handler.IVoicedCommandHandler;
  144. +import net.sf.l2j.gameserver.model.L2World;
  145. +import net.sf.l2j.gameserver.model.actor.instance.L2PcInstance;
  146. +
  147. +public class Online implements IVoicedCommandHandler
  148. +{
  149. +   private static final String[] _voicedCommands = {"online"};
  150. +  
  151. +   @Override
  152. +   public boolean useVoicedCommand(String command, L2PcInstance activeChar, String target)
  153. +   {
  154. +       if (command.equals("online"))  
  155. +       {
  156. +           activeChar.sendMessage("====[Online Players]====");
  157. +           activeChar.sendMessage("Player(s): " + L2World.getInstance().getAllPlayersCount() + " Online.");       
  158. +           activeChar.sendMessage("======[L2jFanatic]======");
  159. +       }
  160. +       return true;
  161. +   }
  162. +  
  163. +   @Override
  164. +   public String[] getVoicedCommandList()
  165. +   {
  166. +       return _voicedCommands;
  167. +   }
  168. +}
  169. \ No newline at end of file
  170. Index: java/net/sf/l2j/gameserver/handler/VoicedCommandHandler.java
  171. ===================================================================
  172. --- java/net/sf/l2j/gameserver/handler/VoicedCommandHandler.java    (revision 0)
  173. +++ java/net/sf/l2j/gameserver/handler/VoicedCommandHandler.java    (working copy)
  174. @@ -0,0 +1,64 @@
  175. +/*
  176. + * This program is free software: you can redistribute it and/or modify it under
  177. + * the terms of the GNU General Public License as published by the Free Software
  178. + * Foundation, either version 3 of the License, or (at your option) any later
  179. + * version.
  180. + *
  181. + * This program is distributed in the hope that it will be useful, but WITHOUT
  182. + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  183. + * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
  184. + * details.
  185. + *
  186. + * You should have received a copy of the GNU General Public License along with
  187. + * this program. If not, see <http://www.gnu.org/licenses/>.
  188. + */
  189. +package net.sf.l2j.gameserver.handler;
  190. +
  191. +import java.util.HashMap;
  192. +import java.util.Map;
  193. +
  194. +import net.sf.l2j.gameserver.handler.voicedcommandhandlers.Online;
  195. +
  196. +public class VoicedCommandHandler
  197. +{
  198. +   private final Map<Integer, IVoicedCommandHandler> _datatable = new HashMap<>();
  199. +  
  200. +   public static VoicedCommandHandler getInstance()
  201. +   {
  202. +       return SingletonHolder._instance;
  203. +   }
  204. +  
  205. +   protected VoicedCommandHandler()
  206. +   {
  207. +       // coloque aqui os comandos
  208. +       registerHandler(new Online());
  209. +   }
  210. +  
  211. +   public void registerHandler(IVoicedCommandHandler handler)
  212. +   {
  213. +       String[] ids = handler.getVoicedCommandList();
  214. +      
  215. +       for (int i = 0; i < ids.length; i++)       
  216. +           _datatable.put(ids[i].hashCode(), handler);
  217. +   }
  218. +      
  219. +   public IVoicedCommandHandler getHandler(String voicedCommand)
  220. +   {
  221. +       String command = voicedCommand;
  222. +      
  223. +       if (voicedCommand.indexOf(" ") != -1)      
  224. +           command = voicedCommand.substring(0, voicedCommand.indexOf(" "));      
  225. +
  226. +       return _datatable.get(command.hashCode());     
  227. +   }
  228. +  
  229. +   public int size()
  230. +   {
  231. +       return _datatable.size();
  232. +   }
  233. +  
  234. +   private static class SingletonHolder
  235. +   {
  236. +       protected static final VoicedCommandHandler _instance = new VoicedCommandHandler();
  237. +   }
  238. +}
  239. \ No newline at end of file
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement