Untitled

mail@pastecode.io avatar
unknown
plain_text
a year ago
2.4 kB
2
Indexable
Never
import net.runelite.api.*;
import net.runelite.api.events.MenuEntryAdded;
import net.runelite.api.events.MenuOptionClicked;
import net.runelite.client.eventbus.Subscribe;
import net.runelite.client.plugins.Plugin;
import net.runelite.client.plugins.PluginDescriptor;
import net.runelite.client.ui.ClientUI;

import javax.inject.Inject;
import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent;

@PluginDescriptor(
	name = "Tile Selection Plugin"
)
public class TileSelectionPlugin extends Plugin
{
	@Inject
	private Client client;

	@Inject
	private ClientUI clientUI;

	private ShiftKeyListener shiftKeyListener = new ShiftKeyListener();
	private WorldPoint firstTile = null;

	@Override
	protected void startUp() throws Exception
	{
		clientUI.addKeyListener(shiftKeyListener);
	}

	@Override
	protected void shutDown() throws Exception
	{
		clientUI.removeKeyListener(shiftKeyListener);
	}

	@Subscribe
	public void onMenuEntryAdded(MenuEntryAdded event)
	{
		if (!shiftKeyListener.isShiftPressed())
		{
			return;
		}

		MenuEntry newEntry = new MenuEntry();
		newEntry.setOption("Select Tile");
		newEntry.setTarget("");
		newEntry.setType(MenuAction.RUNELITE.getId());

		MenuEntry[] menuEntries = client.getMenuEntries();
		MenuEntry[] newMenuEntries = new MenuEntry[menuEntries.length + 1];
		System.arraycopy(menuEntries, 0, newMenuEntries, 0, menuEntries.length);
		newMenuEntries[menuEntries.length] = newEntry;
		client.setMenuEntries(newMenuEntries);
	}

	@Subscribe
	public void onMenuOptionClicked(MenuOptionClicked event)
	{
		if (event.getMenuOption().equals("Select Tile"))
		{
			Tile selectedTile = client.getSelectedSceneTile();

			if (firstTile == null)
			{
				firstTile = selectedTile.getWorldLocation();
			}
			else
			{
				WorldPoint secondTile = selectedTile.getWorldLocation();
				// Save or use the second tile as needed
				firstTile = null; // Reset for the next pair of tiles
			}
		}
	}

	public class ShiftKeyListener extends KeyAdapter
	{
		private boolean isShiftPressed = false;

		@Override
		public void keyPressed(KeyEvent e)
		{
			if (e.getKeyCode() == KeyEvent.VK_SHIFT)
			{
				isShiftPressed = true;
			}
		}

		@Override
		public void keyReleased(KeyEvent e)
		{
			if (e.getKeyCode() == KeyEvent.VK_SHIFT)
			{
				isShiftPressed = false;
			}
		}

		public boolean isShiftPressed()
		{
			return isShiftPressed;
		}
	}
}