Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ### Eclipse Workspace Patch 1.0
- #P aCis_datapack
- Index: data/html/admin/zone.htm
- ===================================================================
- --- data/html/admin/zone.htm (revision 15)
- +++ data/html/admin/zone.htm (working copy)
- @@ -6,11 +6,12 @@
- <td width=45><button value="Back" action="bypass -h admin_admin4" width=45 height=15 back="sek.cbui94" fore="sek.cbui92"></td>
- </tr>
- </table><br>
- - <center><table width=225>
- + <center><table width=260>
- <tr>
- - <td><button value="Refresh" action="bypass -h admin_zone_check" width=75 height=21 back="L2UI_ch3.Btn1_normalOn" fore="L2UI_ch3.Btn1_normal"></td>
- - <td><button value="Visualize all" action="bypass -h admin_zone_visual all" width=75 height=21 back="L2UI_ch3.Btn1_normalOn" fore="L2UI_ch3.Btn1_normal"></td>
- - <td><button value="Clear" action="bypass -h admin_zone_visual clear" width=75 height=21 back="L2UI_ch3.Btn1_normalOn" fore="L2UI_ch3.Btn1_normal"></td>
- + <td><button value="Create" action="bypass -h admin_create_zone" width=65 height=19 back="L2UI_ch3.smallbutton2_over" fore="L2UI_ch3.smallbutton2"></td>
- + <td><button value="Refresh" action="bypass -h admin_zone_check" width=65 height=19 back="L2UI_ch3.smallbutton2_over" fore="L2UI_ch3.smallbutton2"></td>
- + <td><button value="Visualize" action="bypass -h admin_zone_visual all" width=65 height=19 back="L2UI_ch3.smallbutton2_over" fore="L2UI_ch3.smallbutton2"></td>
- + <td><button value="Clear" action="bypass -h admin_zone_visual clear" width=65 height=19 back="L2UI_ch3.smallbutton2_over" fore="L2UI_ch3.smallbutton2"></td>
- </tr>
- </table>
- <br><img src="l2ui.SquareGray" width=270 height=1><br>
- Index: data/html/admin/zone_create.htm
- ===================================================================
- --- data/html/admin/zone_create.htm (revision 0)
- +++ data/html/admin/zone_create.htm (revision 0)
- @@ -0,0 +1,33 @@
- +<html><title>Zone Creation</title><body>
- + <table width=270>
- + <tr>
- + <td width=45><button value="Main" action="bypass -h admin_admin" width=45 height=15 back="sek.cbui94" fore="sek.cbui92"></td>
- + <td width=180 align=center>Zone Creation</td>
- + <td width=45><button value="Back" action="bypass -h admin_zone_check" width=45 height=15 back="sek.cbui94" fore="sek.cbui92"></td>
- + </tr>
- + </table><br>
- + <center>
- + <img src=l2ui.SquareGray width=270 height=1>
- + <table width=270>
- + <tr>
- + <td width=65>Type:</td>
- + <td width=140><combobox width="100" var="zoneType" list=NPoly;Cuboid;Cylinder></td>
- + <td align=right width=65><button value="Select" action="bypass admin_setType $zoneType" width=65 height=19 back="L2UI_ch3.smallbutton2_over" fore="L2UI_ch3.smallbutton2"></td>
- + </tr>
- + </table><br>
- + <img src=l2ui.SquareGray width=270 height=1>
- + <table width=270>
- + <tr><td width=140>Type: <font color=LEVEL>%zoneShape%</font></td></tr>
- + <tr><td width=140>%locsSize%</td></tr>
- + </table>
- + <img src=l2ui.SquareGray width=270 height=1><br>
- + <table width=280>
- + <tr>
- + <td align=center width=70>%proceed%</td>
- + <td align=center width=70>%undo%</td>
- + <td align=center width=70><button value="Add Loc" action="bypass admin_saveLoc" width=65 height=19 back="L2UI_ch3.smallbutton2_over" fore="L2UI_ch3.smallbutton2"></td>
- + <td align=center width=70><button value="Reset" action="bypass admin_reset" width=65 height=19 back="L2UI_ch3.smallbutton2_over" fore="L2UI_ch3.smallbutton2"></td>
- + </tr>
- + </table>
- + <br><br>%dist%
- +</center></body></html>
- \ No newline at end of file
- Index: data/xml/adminCommands.xml
- ===================================================================
- --- data/xml/adminCommands.xml (revision 15)
- +++ data/xml/adminCommands.xml (working copy)
- @@ -335,4 +335,13 @@
- <!-- ZONE -->
- <aCar name="admin_zone_check" accessLevel="7"/>
- <aCar name="admin_zone_visual" accessLevel="7"/>
- +
- + <!-- ZONE CREATE -->
- + <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"/>
- </list>
- \ No newline at end of file
- #P aCis_gameserver
- Index: java/net/sf/l2j/gameserver/handler/AdminCommandHandler.java
- ===================================================================
- --- java/net/sf/l2j/gameserver/handler/AdminCommandHandler.java (revision 15)
- +++ java/net/sf/l2j/gameserver/handler/AdminCommandHandler.java (working copy)
- @@ -46,6 +46,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 +97,7 @@
- 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 (revision 0)
- +++ java/net/sf/l2j/gameserver/handler/admincommandhandlers/AdminZoneCreation.java (revision 0)
- @@ -0,0 +1,322 @@
- +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;
- +
- +/**
- + * @author melron
- + */
- +public class AdminZoneCreation implements IAdminCommandHandler
- +{
- + private static final List<Location> savedLocs = new ArrayList<>();
- + 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;
- +
- + 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",
- + };
- +
- + @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"))
- + {
- + clear();
- + 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);
- + html.setFile("data/html/admin/zone_create.htm");
- + switch (shape)
- + {
- + case NONE:
- + html.replace("%zoneShape%", "Empty");
- + html.replace("%locsSize%", "Locations Saved: Null");
- + html.replace("%proceed%", "");
- + html.replace("%undo%", savedLocs.size() > 0 ? "<button value=\"Undo\" action=\"bypass admin_removeLoc\" back=\"l2ui_ch3.smallbutton2_down\" width=65 height=20 fore=\"l2ui_ch3.smallbutton2\">" : "");
- + html.replace("%dist%", "");
- + break;
- + case NPoly:
- + html.replace("%zoneShape%", shape.name());
- + html.replace("%locsSize%", "Locations Saved: " + savedLocs.size());
- + html.replace("%proceed%", savedLocs.size() > 2 ? "<button value=\"Store\" action=\"bypass admin_storeLocs\" back=\"l2ui_ch3.smallbutton2_down\" width=65 height=20 fore=\"l2ui_ch3.smallbutton2\">" : "");
- + html.replace("%undo%", savedLocs.size() > 0 ? "<button value=\"Undo\" action=\"bypass admin_removeLoc\" back=\"l2ui_ch3.smallbutton2_down\" width=65 height=20 fore=\"l2ui_ch3.smallbutton2\">" : "");
- + html.replace("%dist%", "");
- + break;
- + case Cuboid:
- + html.replace("%zoneShape%", shape.name());
- + html.replace("%locsSize%", "Locations Saved: " + savedLocs.size());
- + html.replace("%proceed%", savedLocs.size() == 2 ? "<button value=\"Store\" action=\"bypass admin_storeLocs\" back=\"l2ui_ch3.smallbutton2_down\" width=65 height=20 fore=\"l2ui_ch3.smallbutton2\">" : "");
- + html.replace("%undo%", savedLocs.size() > 0 ? "<button value=\"Undo\" action=\"bypass admin_removeLoc\" back=\"l2ui_ch3.smallbutton2_down\" width=65 height=20 fore=\"l2ui_ch3.smallbutton2\">" : "");
- + html.replace("%dist%", "");
- + break;
- + case Cylinder:
- + html.replace("%zoneShape%", shape.name());
- + html.replace("%locsSize%", "Locations Saved: " + savedLocs.size());
- + html.replace("%undo%", savedLocs.size() == 1 ? "<button value=\"Undo\" action=\"bypass admin_removeLoc\" back=\"l2ui_ch3.smallbutton2_down\" width=65 height=20 fore=\"l2ui_ch3.smallbutton2\">" : "");
- + if (savedLocs.size() == 1)
- + {
- + if (radius == 0)
- + {
- + html.replace("%proceed%", "");
- + 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\">");
- + }
- + 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 void clear()
- + {
- + shape = ZoneShape.NONE;
- + savedLocs.clear();
- + radius = 0;
- + }
- +
- + @Override
- + public String[] getAdminCommandList()
- + {
- + return ADMIN_COMMANDS;
- + }
- +}
- \ No newline at end of file
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement