Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ### Eclipse Workspace Patch 1.0
- #P aCis_gameserver
- Index: java/net/sf/l2j/gameserver/handler/AdminCommandHandler.java
- ===================================================================
- --- java/net/sf/l2j/gameserver/handler/AdminCommandHandler.java (revision 3)
- +++ java/net/sf/l2j/gameserver/handler/AdminCommandHandler.java (working copy)
- @@ -46,6 +48,7 @@
- import net.sf.l2j.gameserver.handler.admincommandhandlers.AdminTarget;
- import net.sf.l2j.gameserver.handler.admincommandhandlers.AdminTeleport;
- import net.sf.l2j.gameserver.handler.admincommandhandlers.AdminZone;
- +import net.sf.l2j.gameserver.handler.admincommandhandlers.AdminZoneCreation;
- public class AdminCommandHandler
- {
- @@ -96,6 +99,8 @@
- registerHandler(new AdminTarget());
- registerHandler(new AdminTeleport());
- registerHandler(new AdminZone());
- + registerHandler(new AdminZoneCreation());
- }
- private void registerHandler(IAdminCommandHandler handler)
- Index: java/net/sf/l2j/gameserver/handler/admincommandhandlers/AdminZoneCreation.java
- ===================================================================
- --- java/net/sf/l2j/gameserver/handler/admincommandhandlers/AdminZoneCreation.java (nonexistent)
- +++ java/net/sf/l2j/gameserver/handler/admincommandhandlers/AdminZoneCreation.java (working copy)
- @@ -0,0 +1,342 @@
- +package net.sf.l2j.gameserver.handler.admincommandhandlers;
- +
- +import java.io.BufferedWriter;
- +import java.io.File;
- +import java.io.FileWriter;
- +import java.io.IOException;
- +import java.text.SimpleDateFormat;
- +import java.util.ArrayList;
- +import java.util.Date;
- +import java.util.List;
- +import java.util.StringTokenizer;
- +
- +import net.sf.l2j.gameserver.handler.IAdminCommandHandler;
- +import net.sf.l2j.gameserver.model.actor.instance.Player;
- +import net.sf.l2j.gameserver.model.location.Location;
- +import net.sf.l2j.gameserver.network.serverpackets.NpcHtmlMessage;
- +
- +public class AdminZoneCreation implements IAdminCommandHandler
- +{
- +
- + private static enum ZoneShape
- + {
- + NONE,
- + NPoly,
- + Cuboid,
- + Cylinder
- + }
- +
- + private static final String[] ADMIN_COMMANDS =
- + {
- + "admin_create_zone",
- + "admin_setType",
- + "admin_setRad",
- + "admin_saveLoc",
- + "admin_reset",
- + "admin_removeLoc",
- + "admin_storeLocs",
- + };
- +
- + private static final List<Location> savedLocs = new ArrayList<>();
- + private static final String fileLoc = "data/html/admin/zoneCreation/";
- + private static final String fileName = "coordinates" + "%s" + ".xml";
- + private static ZoneShape shape = ZoneShape.NONE;
- + private static final int zDifference = 1000;
- + private static final String maxLocs = "You have reached the maximum locations for this shape.";
- + private static int radius = 0;
- +
- + @Override
- + public boolean useAdminCommand(String command, Player activeChar)
- + {
- + final StringTokenizer st = new StringTokenizer(command);
- + st.nextToken();
- + if (command.startsWith("admin_create_zone"))
- + {
- + openHtml(activeChar);
- + }
- + else if (command.startsWith("admin_setType"))
- + {
- + shape = ZoneShape.valueOf(st.nextToken());
- +
- + switch (shape)
- + {
- + case NPoly:
- + activeChar.sendMessage("You can add unlimited but atleast 3 coordinates in this shape.");
- + break;
- + case Cuboid:
- + activeChar.sendMessage("You must add 2 coordinates (in order to make a square) in this shape.");
- + break;
- + case Cylinder:
- + activeChar.sendMessage("You must add 1 coordinates and radius (in order to make a circle) in this shape.");
- + break;
- + default:
- + activeChar.sendMessage("You have to select the zone shape first.");
- + }
- +
- + openHtml(activeChar);
- + }
- + else if (command.startsWith("admin_saveLoc"))
- + {
- + if (canSaveLoc(activeChar))
- + {
- + final Location loc = new Location(activeChar.getX(), activeChar.getY(), activeChar.getZ());
- + if (savedLocs.add(loc))
- + activeChar.sendMessage(loc + " saved..");
- +
- + }
- + openHtml(activeChar);
- + }
- + else if (command.startsWith("admin_reset"))
- + {
- + clear();
- + activeChar.sendMessage("Reset completed.");
- + openHtml(activeChar);
- + }
- + else if (command.startsWith("admin_removeLoc"))
- + {
- + if (savedLocs.size() > 0)
- + activeChar.sendMessage(savedLocs.remove(savedLocs.size() - 1) + " removed.");
- + openHtml(activeChar);
- + }
- + else if (command.startsWith("admin_storeLocs"))
- + {
- + if (savedLocs.isEmpty())
- + {
- + activeChar.sendMessage("Empty locs..");
- + return false;
- + }
- + store(activeChar);
- + }
- + else if (command.startsWith("admin_setRad"))
- + {
- + if (!st.hasMoreTokens() || !setRadius(parseInt(st.nextToken())))
- + activeChar.sendMessage("Invalid value or shape.");
- + else
- + activeChar.sendMessage("Radius stored.");
- +
- + openHtml(activeChar);
- + }
- + return true;
- + }
- +
- + private static int calcZ(boolean minZ)
- + {
- + return (savedLocs.stream().mapToInt(loc -> loc.getZ()).sum() / savedLocs.size()) + (minZ ? -zDifference : zDifference);
- + }
- +
- + private static int parseInt(String nextToken)
- + {
- + try
- + {
- + return Integer.parseInt(nextToken);
- + }
- + catch (NumberFormatException e)
- + {
- + return 0;
- + }
- + }
- +
- + private static void store(Player gm)
- + {
- + if (!canStoreLocs(gm))
- + return;
- + final String fName = String.format(fileName, "_" + shape.name() + "_" + getTimeStamp());
- + String filePath = "";
- + try (BufferedWriter writer = new BufferedWriter(new FileWriter(fName)))
- + {
- + final File file = new File(fName);
- + filePath = file.getAbsolutePath().replaceAll("\\\\", "/");
- + writer.write(getHeadLine());
- + for (Location loc : savedLocs)
- + writer.write(String.format("\t<node X=\"%s\" Y=\"%s\" />\r\n", loc.getX(), loc.getY()));
- +
- + writer.write("</zone>");
- + }
- + catch (IOException e)
- + {
- + gm.sendMessage(String.format("Couldn't store coordinates in %s file.", fName));
- + e.printStackTrace();
- + }
- + gm.sendMessage("Coordinates has been successfully stored at " + filePath);
- + clear();
- + openHtml(gm);
- + }
- +
- + private static String getTimeStamp()
- + {
- + return new SimpleDateFormat("hh-mm-ss").format(new Date());
- + }
- +
- + private static boolean canStoreLocs(Player gm)
- + {
- + switch (shape)
- + {
- + case NPoly:
- + if (savedLocs.size() < 3)
- + {
- + gm.sendMessage("You have to set atleast 3 coordinates!");
- + return false;
- + }
- +
- + return true;
- + case Cuboid:
- + if (savedLocs.size() != 2)
- + {
- + gm.sendMessage("You have to set 2 coordinates.");
- + return false;
- + }
- + return true;
- + case Cylinder:
- + if (savedLocs.size() != 1)
- + {
- + gm.sendMessage("Only 1 location required for this shape.");
- + return false;
- + }
- + return true;
- + default:
- + gm.sendMessage("You have to select the zone shape first.");
- + return false;
- + }
- + }
- +
- + private static boolean canSaveLoc(Player activeChar)
- + {
- + switch (shape)
- + {
- + case NPoly:
- + return true; // unlimited locs can be added
- + case Cuboid:
- + if (savedLocs.size() >= 2)
- + {
- + activeChar.sendMessage(maxLocs);
- + return false;
- + }
- + return true;
- + case Cylinder:
- + if (savedLocs.size() >= 1)
- + {
- + activeChar.sendMessage("Only 1 locations required for this shape.");
- + return false;
- + }
- + return true;
- + default:
- + activeChar.sendMessage("You have to select the zone shape first.");
- + return false;
- + }
- + }
- +
- + private static String getHeadLine()
- + {
- + switch (shape)
- + {
- + case NPoly:
- + return String.format("<zone shape='NPoly' minZ='%s' maxZ='%s'>\r\n", calcZ(true), calcZ(false));
- + case Cuboid:
- + return String.format("<zone shape='Cuboid' minZ='%s' maxZ='%s'>\r\n", calcZ(true), calcZ(false));
- + case Cylinder:
- + return String.format("<zone shape='Cylinder' minZ='%s' maxZ='%s' rad='%s'>\r\n", calcZ(true), calcZ(false), getRad());
- + default:
- + return "";
- + }
- + }
- +
- + private static boolean setRadius(int val)
- + {
- + if (shape == ZoneShape.Cylinder)
- + {
- + if (val == 0)
- + return false;
- + radius = val;
- + }
- +
- + return shape == ZoneShape.Cylinder;
- + }
- +
- + private static int getRad()
- + {
- + return radius;
- + }
- +
- +
- + private static void openHtml(Player activeChar)
- + {
- + final NpcHtmlMessage html = new NpcHtmlMessage(0);
- +
- + if (shape != ZoneShape.NONE)
- + {
- + html.setFile(fileLoc + type());
- + html.replace("%zoneShape%", shape.name());
- + html.replace("%locsSize%", savedLocs.size());
- + if (savedLocs.size() > 0)
- + html.replace("%undo%", "<button value=\"Undo\" action=\"bypass admin_removeLoc\" back=\"l2ui_ch3.smallbutton2_down\" width=65 height=20 fore=\"l2ui_ch3.smallbutton2\">");
- + else
- + html.replace("%undo%", "");
- + }
- + else
- + html.setFile(fileLoc + "index.htm");
- +
- + switch (shape)
- + {
- + case NPoly:
- + if (savedLocs.size() > 2)
- + html.replace("%proceed%", "<button value=\"Store\" action=\"bypass admin_storeLocs\" back=\"l2ui_ch3.smallbutton2_down\" width=65 height=20 fore=\"l2ui_ch3.smallbutton2\">");
- + else
- + html.replace("%proceed%", "");
- +
- + break;
- + case Cuboid:
- + if (savedLocs.size() == 2)
- + html.replace("%proceed%", "<button value=\"Store\" action=\"bypass admin_storeLocs\" back=\"l2ui_ch3.smallbutton2_down\" width=65 height=20 fore=\"l2ui_ch3.smallbutton2\">");
- + else
- + html.replace("%proceed%", "");
- + break;
- + case Cylinder:
- +
- + if (savedLocs.size() == 1)
- + {
- + if (radius == 0)
- + {
- + 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\">");
- + html.replace("%proceed%", "");
- + }
- + else
- + {
- + html.replace("%proceed%", "<button value=\"Store\" action=\"bypass admin_storeLocs\" back=\"l2ui_ch3.smallbutton2_down\" width=65 height=20 fore=\"l2ui_ch3.smallbutton2\">");
- + html.replace("%dist%", "");
- + }
- + }
- + else
- + {
- + html.replace("%proceed%", "");
- + html.replace("%dist%", "");
- + }
- + break;
- + }
- +
- + activeChar.sendPacket(html);
- +
- + }
- +
- + private static String type()
- + {
- + return shape + ".htm";
- + }
- +
- + private static void clear()
- + {
- + shape = ZoneShape.NONE;
- + savedLocs.clear();
- + radius = 0;
- + }
- +
- + @Override
- + public String[] getAdminCommandList()
- + {
- + return ADMIN_COMMANDS;
- + }
- +}
- \ No newline at end of file
- ### Eclipse Workspace Patch 1.0
- #P aCis_datapack
- Index: data/html/admin/zoneCreation/Cuboid.htm
- ===================================================================
- --- data/html/admin/zoneCreation/Cuboid.htm (nonexistent)
- +++ data/html/admin/zoneCreation/Cuboid.htm (working copy)
- @@ -0,0 +1,18 @@
- +<html><body><center><font color="LEVEL">%zoneShape%</font></center><br>
- + <table border=0 width=270>
- + <tr>
- + <td>Locations Saved:</td>
- + <td>%locsSize%</td>
- + </tr>
- + </table>
- + <br><br><br>
- + %proceed%
- + <br><br>
- + %undo%
- +
- + <br><br>
- + <br><br>
- + <br><br>
- + <center>
- + <button value="Reset" action="bypass admin_reset" width=60 height=15 back="sek.cbui94" fore="sek.cbui92">
- + </body></html>
- \ No newline at end of file
- Index: data/html/admin/zoneCreation/Cylinder.htm
- ===================================================================
- --- data/html/admin/zoneCreation/Cylinder.htm (nonexistent)
- +++ data/html/admin/zoneCreation/Cylinder.htm (working copy)
- @@ -0,0 +1,20 @@
- +<html><body><center><font color="LEVEL">%zoneShape%</font></center><br>
- + <table border=0 width=270>
- + <tr>
- + <td>Locations Saved:</td>
- + <td>%locsSize%</td>
- + </tr>
- + </table>
- + <br><br><br>
- + %proceed%
- + <br><br>
- + %undo%
- +
- + <br><br>
- + %dist%
- + <br><br>
- + <br><br>
- + <br><br>
- + <center>
- + <button value="Reset" action="bypass admin_reset" width=60 height=15 back="sek.cbui94" fore="sek.cbui92">
- +</body></html>
- \ No newline at end of file
- Index: data/html/admin/zoneCreation/NPoly.htm
- ===================================================================
- --- data/html/admin/zoneCreation/NPoly.htm (nonexistent)
- +++ data/html/admin/zoneCreation/NPoly.htm (working copy)
- @@ -0,0 +1,18 @@
- +<html><body><center><font color="LEVEL">%zoneShape%</font></center><br>
- + <table border=0 width=270>
- + <tr>
- + <td>Locations Saved:</td>
- + <td>%locsSize%</td>
- + </tr>
- + </table>
- + <br><br><br>
- + %proceed%
- + <br><br>
- + %undo%
- +
- + <br><br>
- + <br><br>
- + <br><br>
- + <center>
- + <button value="Reset" action="bypass admin_reset" width=60 height=15 back="sek.cbui94" fore="sek.cbui92">
- +</body></html>
- \ No newline at end of file
- Index: data/html/admin/zoneCreation/index.htm
- ===================================================================
- --- data/html/admin/zoneCreation/index.htm (nonexistent)
- +++ data/html/admin/zoneCreation/index.htm (working copy)
- @@ -0,0 +1,40 @@
- +<html>
- +<body>
- +<title>Zone Creator</title>
- +<center>
- +<img src="L2UI.SquareWhite" width=296 height=1>
- +<img src="l2ui_ch3.tutorial_img10" height=120 width=296></td>
- +<img src="L2UI.SquareWhite" width=296 height=1>
- +<table width=296 height=10 bgcolor=000000>
- + <tr>
- + <td fixwidth=230 height=15 align=center>
- + <font color="336699">Zone Creation</font>
- + </td>
- +
- + </tr>
- +</table>
- +<img src="L2UI.SquareWhite" width=296 height=1>
- +<br>
- +<table width=296 bgcolor=000000>
- + <tr>
- + <td width=40>Type</td>
- + <td width=95><combobox width="70" var="zoneType" list=NPoly;Cuboid;Cylinder></td>
- + <td><button value="Select" action="bypass admin_setType $zoneType" width=60 height=15 back="sek.cbui94" fore="sek.cbui92"></td>
- + </tr>
- +</table>
- +<br><br>
- +<center>
- +<table>
- + <tr>
- + <td><img src="icon.etc_alphabet_l_i00" width=32 height=32></td>
- + <td><img src="icon.etc_alphabet_i_i00" width=32 height=32></td>
- + <td><img src="icon.etc_alphabet_n_i00" width=32 height=32></td>
- + <td><img src="icon.etc_alphabet_e_i00" width=32 height=32></td>
- + <td><img src="icon.etc_alphabet_a_i00" width=32 height=32></td>
- + <td><img src="icon.etc_alphabet_g_i00" width=32 height=32></td>
- + <td><img src="icon.etc_alphabet_e_i00" width=32 height=32></td>
- + </tr>
- +</table>
- +</center>
- +</body>
- +</html>
- \ No newline at end of file
- Index: data/xml/adminCommands.xml
- ===================================================================
- --- data/xml/adminCommands.xml (revision 4)
- +++ data/xml/adminCommands.xml (working copy)
- @@ -11,6 +11,14 @@
- <aCar name="admin_silence" accessLevel="7"/>
- <aCar name="admin_tradeoff" accessLevel="7"/>
- <aCar name="admin_reload" accessLevel="7"/>
- +
- + <aCar name="admin_create_zone" accessLevel="7"/>
- + <aCar name="admin_setType" accessLevel="7"/>
- + <aCar name="admin_saveLoc" accessLevel="7"/>
- + <aCar name="admin_setRad" accessLevel="7"/>
- + <aCar name="admin_reset" accessLevel="7"/>
- + <aCar name="admin_removeLoc" accessLevel="7"/>
- + <aCar name="admin_storeLocs" accessLevel="7"/>
- <!-- ANNOUNCEMENTS -->
- <aCar name="admin_announce" accessLevel="7"/>
Add Comment
Please, Sign In to add comment