tobaJK

aCis zone creation

Mar 25th, 2018
691
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 14.95 KB | None | 0 0
  1. ### Eclipse Workspace Patch 1.0
  2. #P aCis_gameserver
  3. Index: java/net/sf/l2j/gameserver/handler/AdminCommandHandler.java
  4. ===================================================================
  5. --- java/net/sf/l2j/gameserver/handler/AdminCommandHandler.java (revision 3)
  6. +++ java/net/sf/l2j/gameserver/handler/AdminCommandHandler.java (working copy)
  7.  
  8. @@ -46,6 +48,7 @@
  9.  import net.sf.l2j.gameserver.handler.admincommandhandlers.AdminTarget;
  10.  import net.sf.l2j.gameserver.handler.admincommandhandlers.AdminTeleport;
  11.  import net.sf.l2j.gameserver.handler.admincommandhandlers.AdminZone;
  12. +import net.sf.l2j.gameserver.handler.admincommandhandlers.AdminZoneCreation;
  13.  
  14.  public class AdminCommandHandler
  15.  {
  16. @@ -96,6 +99,8 @@
  17.         registerHandler(new AdminTarget());
  18.         registerHandler(new AdminTeleport());
  19.         registerHandler(new AdminZone());
  20. +       registerHandler(new AdminZoneCreation());
  21.     }
  22.    
  23.     private void registerHandler(IAdminCommandHandler handler)
  24. Index: java/net/sf/l2j/gameserver/handler/admincommandhandlers/AdminZoneCreation.java
  25. ===================================================================
  26. --- java/net/sf/l2j/gameserver/handler/admincommandhandlers/AdminZoneCreation.java  (nonexistent)
  27. +++ java/net/sf/l2j/gameserver/handler/admincommandhandlers/AdminZoneCreation.java  (working copy)
  28. @@ -0,0 +1,342 @@
  29. +package net.sf.l2j.gameserver.handler.admincommandhandlers;
  30. +
  31. +import java.io.BufferedWriter;
  32. +import java.io.File;
  33. +import java.io.FileWriter;
  34. +import java.io.IOException;
  35. +import java.text.SimpleDateFormat;
  36. +import java.util.ArrayList;
  37. +import java.util.Date;
  38. +import java.util.List;
  39. +import java.util.StringTokenizer;
  40. +
  41. +import net.sf.l2j.gameserver.handler.IAdminCommandHandler;
  42. +import net.sf.l2j.gameserver.model.actor.instance.Player;
  43. +import net.sf.l2j.gameserver.model.location.Location;
  44. +import net.sf.l2j.gameserver.network.serverpackets.NpcHtmlMessage;
  45. +
  46. +public class AdminZoneCreation implements IAdminCommandHandler
  47. +{
  48. +  
  49. +   private static enum ZoneShape
  50. +   {
  51. +       NONE,
  52. +       NPoly,
  53. +       Cuboid,
  54. +       Cylinder
  55. +   }
  56. +  
  57. +   private static final String[] ADMIN_COMMANDS =
  58. +   {
  59. +       "admin_create_zone",
  60. +       "admin_setType",
  61. +       "admin_setRad",
  62. +       "admin_saveLoc",
  63. +       "admin_reset",
  64. +       "admin_removeLoc",
  65. +       "admin_storeLocs",
  66. +   };
  67. +  
  68. +   private static final List<Location> savedLocs = new ArrayList<>();
  69. +   private static final String fileLoc = "data/html/admin/zoneCreation/";
  70. +   private static final String fileName = "coordinates" + "%s" + ".xml";
  71. +   private static ZoneShape shape = ZoneShape.NONE;
  72. +   private static final int zDifference = 1000;
  73. +   private static final String maxLocs = "You have reached the maximum locations for this shape.";
  74. +   private static int radius = 0;
  75. +  
  76. +   @Override
  77. +   public boolean useAdminCommand(String command, Player activeChar)
  78. +   {
  79. +       final StringTokenizer st = new StringTokenizer(command);
  80. +       st.nextToken();
  81. +       if (command.startsWith("admin_create_zone"))
  82. +       {
  83. +           openHtml(activeChar);
  84. +       }
  85. +       else if (command.startsWith("admin_setType"))
  86. +       {
  87. +           shape = ZoneShape.valueOf(st.nextToken());
  88. +          
  89. +           switch (shape)
  90. +           {
  91. +               case NPoly:
  92. +                   activeChar.sendMessage("You can add unlimited but atleast 3 coordinates in this shape.");
  93. +                   break;
  94. +               case Cuboid:
  95. +                   activeChar.sendMessage("You must add 2 coordinates (in order to make a square) in this shape.");
  96. +                   break;
  97. +               case Cylinder:
  98. +                   activeChar.sendMessage("You must add 1 coordinates and radius (in order to make a circle) in this shape.");
  99. +                   break;
  100. +               default:
  101. +                   activeChar.sendMessage("You have to select the zone shape first.");
  102. +           }
  103. +          
  104. +           openHtml(activeChar);
  105. +       }
  106. +       else if (command.startsWith("admin_saveLoc"))
  107. +       {
  108. +           if (canSaveLoc(activeChar))
  109. +           {
  110. +               final Location loc = new Location(activeChar.getX(), activeChar.getY(), activeChar.getZ());
  111. +               if (savedLocs.add(loc))
  112. +                   activeChar.sendMessage(loc + " saved..");
  113. +              
  114. +           }
  115. +           openHtml(activeChar);
  116. +       }
  117. +       else if (command.startsWith("admin_reset"))
  118. +       {
  119. +           clear();
  120. +           activeChar.sendMessage("Reset completed.");
  121. +           openHtml(activeChar);
  122. +       }
  123. +       else if (command.startsWith("admin_removeLoc"))
  124. +       {
  125. +           if (savedLocs.size() > 0)
  126. +               activeChar.sendMessage(savedLocs.remove(savedLocs.size() - 1) + " removed.");
  127. +           openHtml(activeChar);
  128. +       }
  129. +       else if (command.startsWith("admin_storeLocs"))
  130. +       {
  131. +           if (savedLocs.isEmpty())
  132. +           {
  133. +               activeChar.sendMessage("Empty locs..");
  134. +               return false;
  135. +           }
  136. +           store(activeChar);
  137. +       }
  138. +       else if (command.startsWith("admin_setRad"))
  139. +       {
  140. +           if (!st.hasMoreTokens() || !setRadius(parseInt(st.nextToken())))
  141. +               activeChar.sendMessage("Invalid value or shape.");
  142. +           else
  143. +               activeChar.sendMessage("Radius stored.");
  144. +          
  145. +           openHtml(activeChar);
  146. +       }
  147. +       return true;
  148. +   }
  149. +
  150. +   private static int calcZ(boolean minZ)
  151. +   {
  152. +       return (savedLocs.stream().mapToInt(loc -> loc.getZ()).sum() / savedLocs.size()) + (minZ ? -zDifference : zDifference);
  153. +   }
  154. +
  155. +   private static int parseInt(String nextToken)
  156. +   {
  157. +       try
  158. +       {
  159. +           return Integer.parseInt(nextToken);
  160. +       }
  161. +       catch (NumberFormatException e)
  162. +       {
  163. +           return 0;
  164. +       }
  165. +   }
  166. +  
  167. +   private static void store(Player gm)
  168. +   {
  169. +       if (!canStoreLocs(gm))
  170. +           return;
  171. +       final String fName = String.format(fileName, "_" + shape.name() + "_" + getTimeStamp());
  172. +       String filePath = "";
  173. +       try (BufferedWriter writer = new BufferedWriter(new FileWriter(fName)))
  174. +       {
  175. +           final File file = new File(fName);
  176. +           filePath = file.getAbsolutePath().replaceAll("\\\\", "/");
  177. +           writer.write(getHeadLine());
  178. +           for (Location loc : savedLocs)
  179. +               writer.write(String.format("\t<node X=\"%s\" Y=\"%s\" />\r\n", loc.getX(), loc.getY()));
  180. +          
  181. +           writer.write("</zone>");
  182. +       }
  183. +       catch (IOException e)
  184. +       {
  185. +           gm.sendMessage(String.format("Couldn't store coordinates in %s file.", fName));
  186. +           e.printStackTrace();
  187. +       }
  188. +       gm.sendMessage("Coordinates has been successfully stored at " + filePath);
  189. +       clear();
  190. +       openHtml(gm);
  191. +   }
  192. +  
  193. +   private static String getTimeStamp()
  194. +   {
  195. +       return new SimpleDateFormat("hh-mm-ss").format(new Date());
  196. +   }
  197. +  
  198. +   private static boolean canStoreLocs(Player gm)
  199. +   {
  200. +       switch (shape)
  201. +       {
  202. +           case NPoly:
  203. +               if (savedLocs.size() < 3)
  204. +               {
  205. +                   gm.sendMessage("You have to set atleast 3 coordinates!");
  206. +                   return false;
  207. +               }
  208. +              
  209. +               return true;
  210. +           case Cuboid:
  211. +               if (savedLocs.size() != 2)
  212. +               {
  213. +                   gm.sendMessage("You have to set 2 coordinates.");
  214. +                   return false;
  215. +               }
  216. +               return true;
  217. +           case Cylinder:
  218. +               if (savedLocs.size() != 1)
  219. +               {
  220. +                   gm.sendMessage("Only 1 location required for this shape.");
  221. +                   return false;
  222. +               }
  223. +               return true;
  224. +           default:
  225. +               gm.sendMessage("You have to select the zone shape first.");
  226. +               return false;
  227. +       }
  228. +   }
  229. +  
  230. +   private static boolean canSaveLoc(Player activeChar)
  231. +   {
  232. +       switch (shape)
  233. +       {
  234. +           case NPoly:
  235. +               return true; // unlimited locs can be added
  236. +           case Cuboid:
  237. +               if (savedLocs.size() >= 2)
  238. +               {
  239. +                   activeChar.sendMessage(maxLocs);
  240. +                   return false;
  241. +               }
  242. +               return true;
  243. +           case Cylinder:
  244. +               if (savedLocs.size() >= 1)
  245. +               {
  246. +                   activeChar.sendMessage("Only 1 locations required for this shape.");
  247. +                   return false;
  248. +               }
  249. +               return true;
  250. +           default:
  251. +               activeChar.sendMessage("You have to select the zone shape first.");
  252. +               return false;
  253. +       }
  254. +   }
  255. +  
  256. +   private static String getHeadLine()
  257. +   {
  258. +       switch (shape)
  259. +       {
  260. +           case NPoly:
  261. +               return String.format("<zone shape='NPoly' minZ='%s' maxZ='%s'>\r\n", calcZ(true), calcZ(false));
  262. +           case Cuboid:
  263. +               return String.format("<zone shape='Cuboid' minZ='%s' maxZ='%s'>\r\n", calcZ(true), calcZ(false));
  264. +           case Cylinder:
  265. +               return String.format("<zone shape='Cylinder' minZ='%s' maxZ='%s' rad='%s'>\r\n", calcZ(true), calcZ(false), getRad());
  266. +           default:
  267. +               return "";
  268. +       }
  269. +   }
  270. +  
  271. +   private static boolean setRadius(int val)
  272. +   {
  273. +       if (shape == ZoneShape.Cylinder)
  274. +       {
  275. +           if (val == 0)
  276. +               return false;
  277. +           radius = val;
  278. +       }
  279. +      
  280. +       return shape == ZoneShape.Cylinder;
  281. +   }
  282. +  
  283. +   private static int getRad()
  284. +   {
  285. +       return radius;
  286. +   }
  287. +  
  288. +  
  289. +   private static void openHtml(Player activeChar)
  290. +   {
  291. +       final NpcHtmlMessage html = new NpcHtmlMessage(0);
  292. +      
  293. +       if (shape != ZoneShape.NONE)
  294. +       {
  295. +           html.setFile(fileLoc + type());
  296. +           html.replace("%zoneShape%", shape.name());
  297. +           html.replace("%locsSize%", savedLocs.size());
  298. +           if (savedLocs.size() > 0)
  299. +               html.replace("%undo%", "<button value=\"Undo\" action=\"bypass admin_removeLoc\" back=\"l2ui_ch3.smallbutton2_down\" width=65 height=20 fore=\"l2ui_ch3.smallbutton2\">");
  300. +           else
  301. +               html.replace("%undo%", "");
  302. +       }
  303. +       else
  304. +           html.setFile(fileLoc + "index.htm");
  305. +      
  306. +       switch (shape)
  307. +       {
  308. +           case NPoly:
  309. +               if (savedLocs.size() > 2)
  310. +                   html.replace("%proceed%", "<button value=\"Store\" action=\"bypass admin_storeLocs\" back=\"l2ui_ch3.smallbutton2_down\" width=65 height=20 fore=\"l2ui_ch3.smallbutton2\">");
  311. +               else
  312. +                   html.replace("%proceed%", "");
  313. +              
  314. +               break;
  315. +           case Cuboid:
  316. +               if (savedLocs.size() == 2)
  317. +                   html.replace("%proceed%", "<button value=\"Store\" action=\"bypass admin_storeLocs\" back=\"l2ui_ch3.smallbutton2_down\" width=65 height=20 fore=\"l2ui_ch3.smallbutton2\">");
  318. +               else
  319. +                   html.replace("%proceed%", "");
  320. +               break;
  321. +           case Cylinder:
  322. +              
  323. +               if (savedLocs.size() == 1)
  324. +               {
  325. +                   if (radius == 0)
  326. +                   {
  327. +                       html.replace("%dist%", "Set the radius: <edit var=\"Radius\" width=110 height=15> <button value=\"Save\" action=\"bypass admin_setRad $Radius\" back=\"l2ui_ch3.smallbutton2_down\" width=65 height=20 fore=\"l2ui_ch3.smallbutton2\">");
  328. +                       html.replace("%proceed%", "");
  329. +                   }
  330. +                   else
  331. +                   {
  332. +                       html.replace("%proceed%", "<button value=\"Store\" action=\"bypass admin_storeLocs\" back=\"l2ui_ch3.smallbutton2_down\" width=65 height=20 fore=\"l2ui_ch3.smallbutton2\">");
  333. +                       html.replace("%dist%", "");
  334. +                   }
  335. +               }
  336. +               else
  337. +               {
  338. +                   html.replace("%proceed%", "");
  339. +                   html.replace("%dist%", "");
  340. +               }
  341. +               break;
  342. +       }
  343. +      
  344. +       activeChar.sendPacket(html);
  345. +      
  346. +   }
  347. +  
  348. +   private static String type()
  349. +   {
  350. +       return shape + ".htm";
  351. +   }
  352. +  
  353. +   private static void clear()
  354. +   {
  355. +       shape = ZoneShape.NONE;
  356. +       savedLocs.clear();
  357. +       radius = 0;
  358. +   }
  359. +  
  360. +   @Override
  361. +   public String[] getAdminCommandList()
  362. +   {
  363. +       return ADMIN_COMMANDS;
  364. +   }
  365. +}
  366. \ No newline at end of file
  367.  
  368.  
  369. ### Eclipse Workspace Patch 1.0
  370. #P aCis_datapack
  371. Index: data/html/admin/zoneCreation/Cuboid.htm
  372. ===================================================================
  373. --- data/html/admin/zoneCreation/Cuboid.htm (nonexistent)
  374. +++ data/html/admin/zoneCreation/Cuboid.htm (working copy)
  375. @@ -0,0 +1,18 @@
  376. +<html><body><center><font color="LEVEL">%zoneShape%</font></center><br>
  377. +   <table border=0 width=270>
  378. +       <tr>
  379. +           <td>Locations Saved:</td>
  380. +           <td>%locsSize%</td>
  381. +       </tr>
  382. +   </table>
  383. +       <br><br><br>
  384. +   %proceed%
  385. +   <br><br>
  386. +   %undo%
  387. +  
  388. +   <br><br>
  389. +   <br><br>
  390. +   <br><br>
  391. +   <center>
  392. +   <button value="Reset" action="bypass admin_reset" width=60 height=15 back="sek.cbui94" fore="sek.cbui92">
  393. +   </body></html>
  394. \ No newline at end of file
  395. Index: data/html/admin/zoneCreation/Cylinder.htm
  396. ===================================================================
  397. --- data/html/admin/zoneCreation/Cylinder.htm   (nonexistent)
  398. +++ data/html/admin/zoneCreation/Cylinder.htm   (working copy)
  399. @@ -0,0 +1,20 @@
  400. +<html><body><center><font color="LEVEL">%zoneShape%</font></center><br>
  401. +   <table border=0 width=270>
  402. +       <tr>
  403. +           <td>Locations Saved:</td>
  404. +           <td>%locsSize%</td>
  405. +       </tr>
  406. +   </table>
  407. +       <br><br><br>
  408. +   %proceed%
  409. +   <br><br>
  410. +   %undo%
  411. +  
  412. +       <br><br>
  413. +   %dist%
  414. +   <br><br>
  415. +   <br><br>
  416. +   <br><br>
  417. +   <center>
  418. +   <button value="Reset" action="bypass admin_reset" width=60 height=15 back="sek.cbui94" fore="sek.cbui92">
  419. +</body></html>
  420. \ No newline at end of file
  421. Index: data/html/admin/zoneCreation/NPoly.htm
  422. ===================================================================
  423. --- data/html/admin/zoneCreation/NPoly.htm  (nonexistent)
  424. +++ data/html/admin/zoneCreation/NPoly.htm  (working copy)
  425. @@ -0,0 +1,18 @@
  426. +<html><body><center><font color="LEVEL">%zoneShape%</font></center><br>
  427. +   <table border=0 width=270>
  428. +       <tr>
  429. +           <td>Locations Saved:</td>
  430. +           <td>%locsSize%</td>
  431. +       </tr>
  432. +   </table>
  433. +   <br><br><br>
  434. +   %proceed%
  435. +   <br><br>
  436. +   %undo%
  437. +  
  438. +       <br><br>
  439. +   <br><br>
  440. +   <br><br>
  441. +   <center>
  442. +   <button value="Reset" action="bypass admin_reset" width=60 height=15 back="sek.cbui94" fore="sek.cbui92">
  443. +</body></html>
  444. \ No newline at end of file
  445. Index: data/html/admin/zoneCreation/index.htm
  446. ===================================================================
  447. --- data/html/admin/zoneCreation/index.htm  (nonexistent)
  448. +++ data/html/admin/zoneCreation/index.htm  (working copy)
  449. @@ -0,0 +1,40 @@
  450. +<html>
  451. +<body>
  452. +<title>Zone Creator</title>
  453. +<center>
  454. +<img src="L2UI.SquareWhite" width=296 height=1>
  455. +<img src="l2ui_ch3.tutorial_img10" height=120 width=296></td>
  456. +<img src="L2UI.SquareWhite" width=296 height=1>
  457. +<table width=296 height=10 bgcolor=000000>
  458. +   <tr>
  459. +       <td fixwidth=230 height=15 align=center>
  460. +           <font color="336699">Zone Creation</font>
  461. +       </td>
  462. +      
  463. +   </tr>
  464. +</table>
  465. +<img src="L2UI.SquareWhite" width=296 height=1>
  466. +<br>
  467. +<table width=296 bgcolor=000000>
  468. +    <tr>
  469. +        <td width=40>Type</td>
  470. +        <td width=95><combobox width="70" var="zoneType" list=NPoly;Cuboid;Cylinder></td>
  471. +        <td><button value="Select" action="bypass admin_setType $zoneType" width=60 height=15 back="sek.cbui94" fore="sek.cbui92"></td>
  472. +    </tr>
  473. +</table>
  474. +<br><br>
  475. +<center>
  476. +<table>
  477. +   <tr>
  478. +       <td><img src="icon.etc_alphabet_l_i00" width=32 height=32></td>
  479. +       <td><img src="icon.etc_alphabet_i_i00" width=32 height=32></td>
  480. +       <td><img src="icon.etc_alphabet_n_i00" width=32 height=32></td>
  481. +       <td><img src="icon.etc_alphabet_e_i00" width=32 height=32></td>
  482. +       <td><img src="icon.etc_alphabet_a_i00" width=32 height=32></td>
  483. +       <td><img src="icon.etc_alphabet_g_i00" width=32 height=32></td>
  484. +       <td><img src="icon.etc_alphabet_e_i00" width=32 height=32></td>
  485. +   </tr>
  486. +</table>
  487. +</center>
  488. +</body>
  489. +</html>
  490.  
  491. \ No newline at end of file
  492. Index: data/xml/adminCommands.xml
  493. ===================================================================
  494. --- data/xml/adminCommands.xml  (revision 4)
  495. +++ data/xml/adminCommands.xml  (working copy)
  496. @@ -11,6 +11,14 @@
  497.     <aCar name="admin_silence" accessLevel="7"/>
  498.     <aCar name="admin_tradeoff" accessLevel="7"/>
  499.     <aCar name="admin_reload" accessLevel="7"/>
  500. +  
  501. +   <aCar name="admin_create_zone" accessLevel="7"/>
  502. +   <aCar name="admin_setType" accessLevel="7"/>
  503. +   <aCar name="admin_saveLoc" accessLevel="7"/>
  504. +   <aCar name="admin_setRad" accessLevel="7"/>
  505. +   <aCar name="admin_reset" accessLevel="7"/>
  506. +   <aCar name="admin_removeLoc" accessLevel="7"/>
  507. +   <aCar name="admin_storeLocs" accessLevel="7"/>
  508.  
  509.     <!-- ANNOUNCEMENTS -->
  510.     <aCar name="admin_announce" accessLevel="7"/>
Add Comment
Please, Sign In to add comment