Jump to content

Recommended Posts

Posted (edited)

 

package l2s.gameserver.baylee;

import java.awt.Color;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.Map;
import l2s.gameserver.geometry.Location;
import l2s.gameserver.model.Player;
import l2s.gameserver.network.l2.s2c.ExServerPrimitivePacket;

/**
 * @author Belly <3
 * @date July 7, 2022
 */
public class ZoneBuilder
{
	private static final Map<Player, LinkedList<Location>> map = new HashMap<>();
	private static final ZoneBuilder instance = new ZoneBuilder();

	public static ZoneBuilder getInstance() {
		return instance;
	}

	public void addPoint(Player player, Location loc) {
		LinkedList<Location> locs = map.get(player);
		if (locs == null) {
			locs = new LinkedList<>();
			map.put(player, locs);
		}
		locs.add(loc);
	}

	public LinkedList<Location> getLocations(Player player) {
		return map.get(player);
	}
	
	public void clearZone(Player player) {
		map.remove(player);
	}

	public void buildZone(Player player) {
		try {
			final String fileName = player.getName() + "-" + System.currentTimeMillis() / 1000;
			final File spawnFile = new File(fileName + ".txt");
			final BufferedWriter writer = new BufferedWriter(new FileWriter(spawnFile));
			String out = "";
			final LinkedList<Location> locs = map.get(player);
			if (locs != null && !locs.isEmpty()) {
				out += "\t<zone name=\"[" + player.getName() + "_Zone" + System.currentTimeMillis() / 36_000 + "]\" type=\"dummy\">\n";
				out += "\t\t<polygon>\n";
				for (Location loc : locs)
					out += "\t\t\t<coords loc=\"" + loc.getX() + " " + loc.getY() + " " + (loc.getZ() - 1000) + " " + (loc.getZ() + 1000) + "\"/>\n";
				out += "\t\t</polygon>\n";
				out += "\t</zone>";
			}
			writer.write(out);
			writer.close();
			player.unsetVar("@admin_drawzone");
			player.sendGfxMessage("Zone saved under " + fileName + ".txt");
			clearZone(player);
			final ExServerPrimitivePacket packet = new ExServerPrimitivePacket("ZoneBuilder", player.getX(), player.getY(), 65535 + player.getZ());
			packet.addPoint(Color.GREEN, 0, 0, Short.MIN_VALUE);
			player.sendPacket(packet);
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
}

 

c2s -> MoveBackwardToLocation

		/** Belly - new draw zone by click **/
		if (activeChar.isGM() && activeChar.getVarBoolean("@admin_drawzone", false)) {
			ZoneBuilder.getInstance().addPoint(activeChar, _targetLoc);
			final LinkedList<Location> locs = ZoneBuilder.getInstance().getLocations(activeChar);
			if (locs.size() > 1) {
				final ExServerPrimitivePacket packet = new ExServerPrimitivePacket("ZoneBuilder", locs.get(0).getX(), locs.get(0).getY(), 65535 + locs.get(0).getZ());
				for (int i = 1; i < locs.size(); i++) {
					packet.addPoint("" + i, Color.RED, true, locs.get(i).getX(), locs.get(i).getY(), locs.get(i).getZ());
					packet.addLine(Color.GREEN, locs.get(i - 1).getX(), locs.get(i - 1).getY(), locs.get(i - 1).getZ(), locs.get(i).getX(), locs.get(i).getY(), locs.get(i).getZ());
				}
				activeChar.sendPacket(packet);
			}
			activeChar.sendGfxMessage("Point saved " + _targetLoc);
			activeChar.sendActionFailed();
			return;
		}

 

AdminCommandHandler

			
			case admin_drawzone: {
				if (!activeChar.getVarBoolean("@admin_drawzone", false)) {
					activeChar.setVar("@admin_drawzone", true);
					activeChar.sendGfxMessage("Draw zone active -> click on point to record");
					activeChar.sendGfxMessage("//drawzone to unset and save");
				}
				else {
					activeChar.ask(new ConfirmDlgPacket(SystemMsg.S1, 0).addString("Save zone and export to text file?"), new OnAnswerListener()
					{
						@Override
						public void sayYes() {
							ZoneBuilder.getInstance().buildZone(activeChar);
						}

						@Override
						public void sayNo() {
							ZoneBuilder.getInstance().clearZone(activeChar);
							activeChar.sendGfxMessage("Zone drawing cleared.");
						}
					});
				}
				break;
			}

 

PJVgTiv.png

 

simple tool to draw zones faster

if it works it works..

Edited by eMommy
Posted

1) ZoneBuilder class can be final since you're using a singleton approach.

2) addPoint method can be simplified to this:

 

public void addPoint(Player player, Location loc)
{
	LinkedList<Location> locs = map.get(player);
	if (locs == null)
	{
		locs = new LinkedList<>();
		map.put(player, locs);
	}
  
	locs.add(loc);
}

 

3) You should use a singleton holder approach as

 

private static ZoneBuilder instance;

 

should be final. Check similar classes in your source.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now


  • Posts

    • TG Support: https://t.me/buyingproxysup | Channel: https://t.me/buyingproxycom Discord support: #buyingproxy | Server: Join the BuyingProxy Discord Server! Create your free account here  
    • I've purchased the Samurai interface. Everything went smoothly, and the interface is excellent. Highly recommended!
    • For quick reference, I’ve been using the D12 dice roller when testing dice mechanics—clean design and instant results help a lot. It might give you a solid visual template to work from as you build your own games.
    • 🪙 GoldRush — High Five x20 🪙   A fresh High Five server focused on active progression, fair competition, and a healthy player-driven economy.   GoldRush is built for players who want a fresh spin on our beloved game that is connected to today's world via Web3 marketplace.    🏅 Gold Bar & Marketplace • Gold Bars are part of the server's custom economy — they can be used in Marketplace or Cosmetics shop. • Tokens are optional and used only for server Marketplace features.   ⚙️ Server Rates • EXP: 20x • SP: 20x • Adena: 10x • Normal Drop Chance: 8x • Spoil Chance: 12x • Raid Drop Chance: 3x • Quest Item Drop Amount: 5x • Quest EXP/SP Reward: 10x • Quest Adena Reward: 5x   ✨ Enchant Rates • Max Enchant: Weapons +16 / Armors +12 • +0 to +3 armor / weapon = 100% safe • +0 to +4 full body armor = 100% safe • +4 to +6 = 66% • +7 to +9 = 60% • +10 to +12 = 54% • +13 to +14 = 48% • +15 to +16 = 42%   🛒 Alt+B Services GoldRush includes useful Alt+B services: • GM Shop up to Dynasty • Buffer 1h • Teleports • Drop Search • Rankings   🎒 Auto-Loot • Normal mob drops: auto-loot • Adena: auto-loot • Raid drops: stay on the ground • Herbs: stay on the ground   🧙 Class Progression • 1st and 2nd professions are free with shadow weapon reward. • 3rd profession: 5kk • Auto Learn Skills • Subclass - No Quest • Noblesse - Full Quest     ⚔️ Olympiad • Hero period: 1 week • Olympiad time: 18:00–00:00 server time • Match duration: 5 minutes • Max enchant in Olympiad: +6   🏰 Sieges Castle sieges take place on Sundays at 16:00 and 20:00 GMT+3. The first siege will happen 2 weeks after launch.   🐉 Grand Boss Respawn Queen Ant: 24h + 2h random Core: 30h + 2h random Orfen: 48h + 2h random Baium: 120h + 3h random Antharas: 120h + 24h random Valakas: 120h + 24h random Beleth: 120h + 24h random   ⚔️ Fair Play Bots are strictly forbidden and will result in a ban without warning. Dualbox is limited to 1 box. GoldRush is built around a healthy player-to-player economy. Website : https://www.goldrushpvp.xyz/ Discord : https://discord.com/invite/v3zRZVV6ka Guide of how to make an account on our web3 server!  
    • Patch notes of update v1.0 is done regarding some feedbacks. Added Special Buffs category to the buffer. Queen Cat, Seraphim and Dwarf equipment buffs are now available. Special buffs last 1 hour and can be saved in schemes. Players can now Shift+Click monsters to check drops and spoil directly in-game.
  • Topics

×
×
  • Create New...

Important Information

This community uses essential cookies to function properly. Non-essential cookies and third-party services are used only with your consent. Read our Privacy Policy and We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue..