Advertisement
Guest User

Untitled

a guest
Mar 20th, 2017
111
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.65 KB | None | 0 0
  1. // VOICEMOIONADHANDER
  2.  
  3. * This program is free software: you can redistribute it and/or modify it under
  4. * the terms of the GNU General Public License as published by the Free Software
  5. * Foundation, either version 3 of the License, or (at your option) any later
  6. * version.
  7. *
  8. * This program is distributed in the hope that it will be useful, but WITHOUT
  9. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  10. * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
  11. * details.
  12. *
  13. * You should have received a copy of the GNU General Public License along with
  14. * this program. If not, see <http://www.gnu.org/licenses/>.
  15. */
  16. package net.sf.l2j.gameserver.handler;
  17. import java.util.HashMap;
  18. import java.util.Map;
  19. import net.sf.l2j.gameserver.handler.voicedcommandhandlers.Online;
  20. public class VoicedCommandHandler
  21. {
  22. private final Map<Integer, IVoicedCommandHandler> _datatable = new HashMap<>();
  23.  
  24. public static VoicedCommandHandler getInstance()
  25. {
  26. return SingletonHolder._instance;
  27. }
  28.  
  29. protected VoicedCommandHandler()
  30. {
  31. // coloque aqui os comandos
  32. registerHandler(new Online());
  33. }
  34.  
  35.  
  36. public void registerHandler(IVoicedCommandHandler handler)
  37. {
  38. String[] ids = handler.getVoicedCommandList();
  39.  
  40. for (int i = 0; i < ids.length; i++)
  41. _datatable.put(ids[i].hashCode(), handler);
  42. }
  43.  
  44. public IVoicedCommandHandler getHandler(String voicedCommand)
  45. {
  46. String command = voicedCommand;
  47.  
  48. if (voicedCommand.indexOf(" ") != -1)
  49. command = voicedCommand.substring(0, voicedCommand.indexOf(" "));
  50.  
  51. return _datatable.get(command.hashCode());
  52. }
  53.  
  54. public int size()
  55. {
  56. return _datatable.size();
  57. }
  58.  
  59. private static class SingletonHolder
  60. {
  61. protected static final VoicedCommandHandler _instance = new VoicedCommandHandler();
  62. }
  63. }
  64.  
  65. // online
  66. /*
  67. * This program is free software: you can redistribute it and/or modify it under
  68. * the terms of the GNU General Public License as published by the Free Software
  69. * Foundation, either version 3 of the License, or (at your option) any later
  70. * version.
  71. *
  72. * This program is distributed in the hope that it will be useful, but WITHOUT
  73. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  74. * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
  75. * details.
  76. *
  77. * You should have received a copy of the GNU General Public License along with
  78. * this program. If not, see <http://www.gnu.org/licenses/>.
  79. */
  80. package net.sf.l2j.gameserver.handler.voicedcommandhandlers;
  81.  
  82. import net.sf.l2j.gameserver.handler.IVoicedCommandHandler;
  83. import net.sf.l2j.gameserver.model.World;
  84. import net.sf.l2j.gameserver.model.actor.instance.Player;
  85.  
  86. public class Online implements IVoicedCommandHandler
  87. {
  88.  
  89. private static final String[] _voicedCommands =
  90. {
  91. "online"
  92. };
  93.  
  94. @Override
  95. public boolean useVoicedCommand(String command, Player activeChar, String target)
  96. {
  97. if (command.equals("online"))
  98. {
  99. activeChar.sendMessage("====[Online Players]====");
  100. activeChar.sendMessage("Player(s): " + World.getInstance().getAllPlayersCount() * 1+ " Online.");
  101. activeChar.sendMessage("======[L2-Might]======");
  102. }
  103. return true;
  104. }
  105.  
  106. @Override
  107. public String[] getVoicedCommandList()
  108. {
  109. return _voicedCommands;
  110. }
  111. }
  112.  
  113.  
  114. // IVoicedCommandHandler
  115. /*
  116. * This program is free software: you can redistribute it and/or modify it under
  117. * the terms of the GNU General Public License as published by the Free Software
  118. * Foundation, either version 3 of the License, or (at your option) any later
  119. * version.
  120. *
  121. * This program is distributed in the hope that it will be useful, but WITHOUT
  122. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  123. * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
  124. * details.
  125. *
  126. * You should have received a copy of the GNU General Public License along with
  127. * this program. If not, see <http://www.gnu.org/licenses/>.
  128. */
  129.  
  130. package net.sf.l2j.gameserver.handler;
  131. import net.sf.l2j.gameserver.handler.IVoicedCommandHandler;
  132. import net.sf.l2j.gameserver.model.actor.instance.Player;
  133.  
  134. import java.util.logging.Logger;
  135.  
  136.  
  137. public interface IVoicedCommandHandler
  138.  
  139. {
  140. public static Logger _log = Logger.getLogger(IVoicedCommandHandler.class.getName());
  141.  
  142. public boolean useVoicedCommand(String command, Player activeChar, String params);
  143.  
  144. public String[] getVoicedCommandList();
  145. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement