Advertisement
Nik

Fences dp 9259

Nik
Oct 24th, 2012
131
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Diff 11.10 KB | None | 0 0
  1. Index: dist/game/config/adminCommands.xml
  2. ===================================================================
  3. --- dist/game/config/adminCommands.xml  (revision 9260)
  4. +++ dist/game/config/adminCommands.xml  (working copy)
  5. @@ -634,4 +634,15 @@
  6.     <admin command="banchat" accessLevel="7" />
  7.     <admin command="debug" accessLevel="7" />
  8.     <admin command="unbanchat" accessLevel="7" />
  9. +  
  10. +   <!-- COLOSSEUM FENCE COMMANDS -->
  11. +   <admin command="admin_fences" accessLevel="7" />
  12. +   <admin command="admin_open_fence" accessLevel="7" />
  13. +   <admin command="admin_close_fence" accessLevel="7" />
  14. +   <admin command="admin_hide_fence" accessLevel="7" />
  15. +   <admin command="admin_teleto_fence" accessLevel="7" />
  16. +   <admin command="admin_reload_fences" accessLevel="7" />
  17. +   <admin command="admin_spawn_fence" accessLevel="7" />
  18. +   <admin command="admin_delete_fence" accessLevel="7" />
  19. +   <admin command="admin_edit_fence" accessLevel="7" />
  20.  </list>
  21. \ No newline at end of file
  22. Index: dist/game/data/xsd/adminCommands.xsd
  23. ===================================================================
  24. --- dist/game/data/xsd/adminCommands.xsd    (revision 9260)
  25. +++ dist/game/data/xsd/adminCommands.xsd    (working copy)
  26. @@ -165,6 +165,15 @@
  27.                                     <xs:enumeration value="admin_event_store" />
  28.                                     <xs:enumeration value="admin_event" />
  29.                                     <xs:enumeration value="admin_exceptions" />
  30. +                                   <xs:enumeration value="admin_fences" />
  31. +                                   <xs:enumeration value="admin_open_fence" />
  32. +                                   <xs:enumeration value="admin_close_fence" />
  33. +                                   <xs:enumeration value="admin_hide_fence" />
  34. +                                   <xs:enumeration value="admin_teleto_fence" />
  35. +                                   <xs:enumeration value="admin_reload_fences" />
  36. +                                   <xs:enumeration value="admin_spawn_fence" />
  37. +                                   <xs:enumeration value="admin_delete_fence" />
  38. +                                   <xs:enumeration value="admin_edit_fence" />
  39.                                     <xs:enumeration value="admin_fcs" />
  40.                                     <xs:enumeration value="admin_fight_calculator_show" />
  41.                                     <xs:enumeration value="admin_fight_calculator" />
  42. Index: dist/game/data/scripts/handlers/admincommandhandlers/AdminFences.java
  43. ===================================================================
  44. --- dist/game/data/scripts/handlers/admincommandhandlers/AdminFences.java   (revision 0)
  45. +++ dist/game/data/scripts/handlers/admincommandhandlers/AdminFences.java   (revision 0)
  46. @@ -0,0 +1,205 @@
  47. +/*
  48. + * This program is free software: you can redistribute it and/or modify it under
  49. + * the terms of the GNU General Public License as published by the Free Software
  50. + * Foundation, either version 3 of the License, or (at your option) any later
  51. + * version.
  52. + *
  53. + * This program is distributed in the hope that it will be useful, but WITHOUT
  54. + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  55. + * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
  56. + * details.
  57. + *
  58. + * You should have received a copy of the GNU General Public License along with
  59. + * this program. If not, see <http://www.gnu.org/licenses/>.
  60. + */
  61. +package handlers.admincommandhandlers;
  62. +
  63. +import java.util.StringTokenizer;
  64. +import java.util.logging.Logger;
  65. +
  66. +import com.l2jserver.gameserver.datatables.FencesTable;
  67. +import com.l2jserver.gameserver.handler.IAdminCommandHandler;
  68. +import com.l2jserver.gameserver.model.L2World;
  69. +import com.l2jserver.gameserver.model.actor.instance.L2FenceInstance;
  70. +import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
  71. +import com.l2jserver.gameserver.network.serverpackets.NpcHtmlMessage;
  72. +
  73. +public class AdminFences implements IAdminCommandHandler
  74. +{
  75. +   protected static final Logger _LOGGER = Logger.getLogger(AdminFences.class.getName());
  76. +
  77. +   private static final String[] ADMIN_COMMANDS =
  78. +   {
  79. +       "admin_fences",
  80. +       "admin_open_fence",
  81. +       "admin_close_fence",
  82. +       "admin_hide_fence",
  83. +       "admin_teleto_fence",
  84. +       "admin_reload_fences",
  85. +       "admin_spawn_fence",
  86. +       "admin_delete_fence",
  87. +       "admin_edit_fence",
  88. +   };
  89. +  
  90. +   @Override
  91. +   public boolean useAdminCommand(String command, L2PcInstance activeChar)
  92. +   {
  93. +       StringTokenizer st = new StringTokenizer(command);
  94. +       st.nextToken(); // Actual command
  95. +      
  96. +       if (command.equals("admin_fences"))
  97. +       {
  98. +           // TODO: Html wizzard for managing fences manually. This is just temp
  99. +           StringBuilder sb = new StringBuilder((FencesTable.getInstance().getFences().size() * 140) + 89);
  100. +           sb.append("<html><body>List of currently spawn fences:<br><table cellpadding=-1>");
  101. +           for (L2FenceInstance fence : FencesTable.getInstance().getFences().values())
  102. +           {
  103. +               sb.append("<tr><td width=80><a action=\"bypass admin_teleto_fence " + fence.getObjectId() + " \">" + fence.getObjectId() + "</a></td>");
  104. +               sb.append("<td width=80>State: " + fence.getState() + "</td>");
  105. +               sb.append("<td width=80>Temp: " + (fence.isStoredToDB() ? "no" : "yes") + "</td>");
  106. +              
  107. +               if (sb.length() >= 16500) // HTML else will throw critical error.
  108. +                   break;
  109. +           }
  110. +           sb.append("</table></body></html>");
  111. +           NpcHtmlMessage html = new NpcHtmlMessage(0);
  112. +           html.setHtml(sb.toString());
  113. +           activeChar.sendPacket(html);
  114. +           return true;
  115. +       }
  116. +       else if (command.startsWith("admin_open_fence"))
  117. +       {
  118. +           manageFanceState(activeChar, L2FenceInstance.UNCLOSED, st);
  119. +       }
  120. +       else if (command.startsWith("admin_close_fence"))
  121. +       {
  122. +           manageFanceState(activeChar, L2FenceInstance.CLOSED, st);
  123. +       }
  124. +       else if (command.startsWith("admin_hide_fence"))
  125. +       {
  126. +           manageFanceState(activeChar, L2FenceInstance.HIDDEN, st);
  127. +       }
  128. +       else if (command.startsWith("admin_teleto_fence"))
  129. +       {
  130. +           try
  131. +           {
  132. +               int objectId = 0;
  133. +               if (st.hasMoreTokens())
  134. +               {
  135. +                   objectId = Integer.parseInt(st.nextToken());
  136. +                   L2FenceInstance fence = FencesTable.getInstance().getFence(objectId);
  137. +                   activeChar.teleToLocation(fence.getX(), fence.getY(), fence.getZ());
  138. +                   return true;
  139. +               }
  140. +              
  141. +               activeChar.sendMessage("Usage: //teleto_fence objectId");
  142. +           }
  143. +           catch (NumberFormatException nfex)
  144. +           {
  145. +               activeChar.sendMessage("Incorrect values, only numbers are accepted. Usage: //teleto_fence objectId");
  146. +           }
  147. +       }
  148. +       else if (command.equals("admin_reload_fences"))
  149. +       {
  150. +           FencesTable.getInstance().reload();
  151. +           activeChar.sendMessage("Reloaded stored fences.");
  152. +          
  153. +           return true;
  154. +       }
  155. +       else if (command.startsWith("admin_spawn_fence"))
  156. +       {
  157. +          
  158. +           try
  159. +           {
  160. +               int width = 0;
  161. +               int length = 0;
  162. +               boolean saveToDB = false;
  163. +               if (st.hasMoreTokens())
  164. +               {
  165. +                   width = Integer.parseInt(st.nextToken());
  166. +                   length = width;
  167. +                   if (st.hasMoreTokens())
  168. +                       length = Integer.parseInt(st.nextToken());
  169. +                   if (st.hasMoreTokens())
  170. +                       saveToDB = !st.nextToken().isEmpty();
  171. +                  
  172. +                   L2FenceInstance fence = new L2FenceInstance(activeChar.getX(), activeChar.getY(), activeChar.getZ(), width, length);
  173. +                   fence.spawnMe();
  174. +                   if (saveToDB)
  175. +                       FencesTable.getInstance().storeFence(fence);
  176. +                  
  177. +                   return true;
  178. +               }
  179. +              
  180. +               activeChar.sendMessage("Usage: //spawn_fence width&length OR //spawn_fence width length OR //spawn_fence width length storeToDB");
  181. +           }
  182. +           catch (NumberFormatException nfex)
  183. +           {
  184. +               activeChar.sendMessage("Incorrect values, only numbers are accepted. Usage: //spawn_fence width length");
  185. +               return false;
  186. +           }
  187. +       }
  188. +       else if (command.startsWith("admin_delete_fence"))
  189. +       {
  190. +           try
  191. +           {
  192. +               int objectId = 0;
  193. +               boolean deleteFromDB = false;
  194. +               if (st.hasMoreTokens())
  195. +               {
  196. +                   objectId = Integer.parseInt(st.nextToken());
  197. +                   if (st.hasMoreTokens())
  198. +                       deleteFromDB = !st.nextToken().isEmpty();
  199. +                  
  200. +                   FencesTable.getInstance().deleteFence(objectId, deleteFromDB);
  201. +                   return true;
  202. +               }
  203. +              
  204. +               activeChar.sendMessage("Usage: //delete_fence objectId OR //delete_fence objectId deleteFromDB");
  205. +           }
  206. +           catch (NumberFormatException nfex)
  207. +           {
  208. +               activeChar.sendMessage("Incorrect values, only numbers are accepted. Usage: //delete_fence objectId");
  209. +               return false;
  210. +           }
  211. +       }
  212. +       else if (command.startsWith("admin_edit_fence"))
  213. +       {
  214. +           //TODO: This will be probably required for the fence wizzard.
  215. +       }
  216. +      
  217. +       return false;
  218. +   }
  219. +  
  220. +   private void manageFanceState(L2PcInstance activeChar, int state, StringTokenizer st)
  221. +   {
  222. +       try
  223. +       {
  224. +           int objectId = 0;
  225. +           if (st.hasMoreTokens())
  226. +           {
  227. +               objectId = Integer.parseInt(st.nextToken());
  228. +               L2FenceInstance fence = FencesTable.getInstance().getFence(objectId);
  229. +               if (fence != null)
  230. +               {
  231. +                   fence.setState(state);
  232. +                   for (L2PcInstance plr : L2World.getInstance().getAllPlayersArray())
  233. +                       fence.sendInfo(plr);
  234. +               }
  235. +               return;
  236. +           }
  237. +          
  238. +           activeChar.sendMessage("Usage: //open_fence objectId");
  239. +       }
  240. +       catch (NumberFormatException nfex)
  241. +       {
  242. +           activeChar.sendMessage("Incorrect values, only numbers are accepted. Usage: //open_fence objectId");
  243. +       }
  244. +   }
  245. +  
  246. +   @Override
  247. +   public String[] getAdminCommandList()
  248. +   {
  249. +       return ADMIN_COMMANDS;
  250. +   }
  251. +}
  252. Index: dist/game/data/scripts/handlers/MasterHandler.java
  253. ===================================================================
  254. --- dist/game/data/scripts/handlers/MasterHandler.java  (revision 9260)
  255. +++ dist/game/data/scripts/handlers/MasterHandler.java  (working copy)
  256. @@ -40,7 +40,6 @@
  257.  import handlers.admincommandhandlers.AdminCamera;
  258.  import handlers.admincommandhandlers.AdminChangeAccessLevel;
  259.  import handlers.admincommandhandlers.AdminClan;
  260. -import handlers.admincommandhandlers.AdminPcCondOverride;
  261.  import handlers.admincommandhandlers.AdminCreateItem;
  262.  import handlers.admincommandhandlers.AdminCursedWeapons;
  263.  import handlers.admincommandhandlers.AdminDebug;
  264. @@ -55,6 +54,7 @@
  265.  import handlers.admincommandhandlers.AdminEventEngine;
  266.  import handlers.admincommandhandlers.AdminEvents;
  267.  import handlers.admincommandhandlers.AdminExpSp;
  268. +import handlers.admincommandhandlers.AdminFences;
  269.  import handlers.admincommandhandlers.AdminFightCalculator;
  270.  import handlers.admincommandhandlers.AdminFortSiege;
  271.  import handlers.admincommandhandlers.AdminGeoEditor;
  272. @@ -80,6 +80,7 @@
  273.  import handlers.admincommandhandlers.AdminMonsterRace;
  274.  import handlers.admincommandhandlers.AdminPForge;
  275.  import handlers.admincommandhandlers.AdminPathNode;
  276. +import handlers.admincommandhandlers.AdminPcCondOverride;
  277.  import handlers.admincommandhandlers.AdminPetition;
  278.  import handlers.admincommandhandlers.AdminPledge;
  279.  import handlers.admincommandhandlers.AdminPolymorph;
  280. @@ -387,6 +388,7 @@
  281.             AdminEventEngine.class,
  282.             AdminEvents.class,
  283.             AdminExpSp.class,
  284. +           AdminFences.class,
  285.             AdminFightCalculator.class,
  286.             AdminFortSiege.class,
  287.             AdminGeodata.class,
  288. Index: dist/sql/game/fences.sql
  289. ===================================================================
  290. --- dist/sql/game/fences.sql    (revision 0)
  291. +++ dist/sql/game/fences.sql    (revision 0)
  292. @@ -0,0 +1,12 @@
  293. +DROP TABLE IF EXISTS `fences`;
  294. +CREATE TABLE `fences` (
  295. +   `object_id` int(11) NOT NULL,
  296. +   `state` int(11) NOT NULL,
  297. +   `x` int(11) NOT NULL,
  298. +   `y` int(11) NOT NULL,
  299. +   `z` int(11) NOT NULL,
  300. +   `width` int(11) NOT NULL,
  301. +   `length` int(11) NOT NULL,
  302. +   `height` int(11) NOT NULL,
  303. +   PRIMARY KEY (`object_id`)
  304. +);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement