net.runelite.api.GameState Java Examples

The following examples show how to use net.runelite.api.GameState. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: PlayerInfoPlugin.java    From plugins with GNU General Public License v3.0 6 votes vote down vote up
@Override
protected void startUp()
{
	clientThread.invoke(() ->
	{
		if (client.getGameState().ordinal() < GameState.LOGIN_SCREEN.ordinal())
		{
			return false;
		}

		BufferedImage healthImg = spriteManager.getSprite(SpriteID.MINIMAP_ORB_HITPOINTS_ICON, 0);
		BufferedImage prayerImg = spriteManager.getSprite(SpriteID.MINIMAP_ORB_PRAYER_ICON, 0);
		BufferedImage energyImg = spriteManager.getSprite(SpriteID.MINIMAP_ORB_RUN_ICON, 0);
		BufferedImage combatImg = spriteManager.getSprite(SpriteID.MINIMAP_ORB_SPECIAL_ICON, 0);
		BufferedImage worldImg = spriteManager.getSprite(SpriteID.MINIMAP_ORB_WORLD_MAP_PLANET, 0);

		infoBoxManager.addInfoBox(new PlayerInfoCustomIndicator(healthImg, this, config, client, IndicatorType.HEALTH));
		infoBoxManager.addInfoBox(new PlayerInfoCustomIndicator(prayerImg, this, config, client, IndicatorType.PRAYER));
		infoBoxManager.addInfoBox(new PlayerInfoCustomIndicator(energyImg, this, config, client, IndicatorType.ENERGY));
		infoBoxManager.addInfoBox(new PlayerInfoCustomIndicator(combatImg, this, config, client, IndicatorType.SPECIAL));
		infoBoxManager.addInfoBox(new PlayerInfoCustomIndicator(worldImg, this, config, client, IndicatorType.WORLD));

		return true;
	});
}
 
Example #2
Source File: RaidsPlugin.java    From runelite with BSD 2-Clause "Simplified" License 6 votes vote down vote up
@Subscribe
public void onGameStateChanged(GameStateChanged event)
{
	if (client.getGameState() == GameState.LOGGED_IN)
	{
		// skip event while the game decides if the player belongs in a raid or not
		if (client.getLocalPlayer() == null
			|| client.getLocalPlayer().getWorldLocation().equals(TEMP_LOCATION))
		{
			return;
		}

		checkInRaid = true;
	}
	else if (client.getGameState() == GameState.LOGIN_SCREEN
		|| client.getGameState() == GameState.CONNECTION_LOST)
	{
		loggedIn = false;
	}
	else if (client.getGameState() == GameState.HOPPING)
	{
		reset();
	}
}
 
Example #3
Source File: RunecraftPlugin.java    From plugins with GNU General Public License v3.0 6 votes vote down vote up
@Subscribe
private void onGameStateChanged(GameStateChanged event)
{
	final GameState gameState = event.getGameState();

	switch (gameState)
	{
		case LOADING:
			abyssObjects.clear();
			break;
		case CONNECTION_LOST:
		case HOPPING:
		case LOGIN_SCREEN:
			darkMage = null;
			break;
		case LOGGED_IN:
			removeSwaps();
			handleSwaps();
			break;
	}
}
 
Example #4
Source File: LeftClickCast.java    From ExternalPlugins with GNU General Public License v3.0 6 votes vote down vote up
@Subscribe
public void onGameStateChanged(GameStateChanged event)
{
	if (event.getGameState() != GameState.LOGGED_IN)
	{
		keyManager.unregisterKeyListener(spellOneSwap);
		keyManager.unregisterKeyListener(spellTwoSwap);
		keyManager.unregisterKeyListener(spellThreeSwap);
		keyManager.unregisterKeyListener(spellFourSwap);
		keyManager.unregisterKeyListener(spellFiveSwap);
		keyManager.unregisterKeyListener(spellSixSwap);
		return;
	}
	keyManager.registerKeyListener(spellOneSwap);
	keyManager.registerKeyListener(spellTwoSwap);
	keyManager.registerKeyListener(spellThreeSwap);
	keyManager.registerKeyListener(spellFourSwap);
	keyManager.registerKeyListener(spellFiveSwap);
	keyManager.registerKeyListener(spellSixSwap);
}
 
Example #5
Source File: EmojiPluginTest.java    From runelite with BSD 2-Clause "Simplified" License 6 votes vote down vote up
@Test
public void testGtLt()
{
	when(client.getGameState()).thenReturn(GameState.LOGGED_IN);
	when(client.getModIcons()).thenReturn(new IndexedSprite[0]);
	when(client.createIndexedSprite()).thenReturn(mock(IndexedSprite.class));

	// Trip emoji loading
	GameStateChanged gameStateChanged = new GameStateChanged();
	gameStateChanged.setGameState(GameState.LOGGED_IN);
	emojiPlugin.onGameStateChanged(gameStateChanged);

	MessageNode messageNode = mock(MessageNode.class);
	when(messageNode.getValue()).thenReturn("<gt>:D<lt>");

	ChatMessage chatMessage = new ChatMessage();
	chatMessage.setType(ChatMessageType.PUBLICCHAT);
	chatMessage.setMessageNode(messageNode);

	emojiPlugin.onChatMessage(chatMessage);

	verify(messageNode).setRuneLiteFormatMessage("<img=10>");
}
 
Example #6
Source File: CannonPlugin.java    From plugins with GNU General Public License v3.0 6 votes vote down vote up
@Subscribe
public void onGameStateChanged(GameStateChanged gameStateChanged)
{
	if (gameStateChanged.getGameState() != GameState.LOGGED_IN)
	{
		return;
	}

	spotPoints.clear();
	for (WorldPoint spot : CannonSpots.getCannonSpots())
	{
		if (WorldPoint.isInScene(client, spot.getX(), spot.getY()))
		{
			spotPoints.add(spot);
		}
	}
}
 
Example #7
Source File: ObjectIndicatorsPlugin.java    From plugins with GNU General Public License v3.0 6 votes vote down vote up
@Subscribe
private void onGameStateChanged(GameStateChanged gameStateChanged)
{
	GameState gameState = gameStateChanged.getGameState();
	if (gameState == GameState.LOADING)
	{
		// Reload points with new map regions

		points.clear();
		for (int regionId : client.getMapRegions())
		{
			// load points for region
			final Set<ObjectPoint> regionPoints = loadPoints(regionId);
			if (regionPoints != null)
			{
				points.put(regionId, regionPoints);
			}
		}
	}

	if (gameStateChanged.getGameState() != GameState.LOGGED_IN)
	{
		objects.clear();
	}
}
 
Example #8
Source File: OpponentInfoPlugin.java    From plugins with GNU General Public License v3.0 6 votes vote down vote up
@Subscribe
private void onGameStateChanged(GameStateChanged gameStateChanged)
{
	if (gameStateChanged.getGameState() != GameState.LOGGED_IN)
	{
		return;
	}

	final EnumSet<WorldType> worldType = client.getWorldType();
	if (worldType.contains(WorldType.DEADMAN_TOURNAMENT))
	{
		hiscoreEndpoint = HiscoreEndpoint.TOURNAMENT;
	}
	else if (worldType.contains(WorldType.DEADMAN))
	{
		hiscoreEndpoint = HiscoreEndpoint.DEADMAN;
	}
	else if (worldType.contains(WorldType.LEAGUE))
	{
		hiscoreEndpoint = HiscoreEndpoint.LEAGUE;
	}
	else
	{
		hiscoreEndpoint = HiscoreEndpoint.NORMAL;
	}
}
 
Example #9
Source File: IdleNotifierPluginTest.java    From runelite with BSD 2-Clause "Simplified" License 6 votes vote down vote up
@Test
public void checkCombatLogout()
{
	plugin.onInteractingChanged(new InteractingChanged(player, monster));
	when(player.getInteracting()).thenReturn(mock(Actor.class));
	plugin.onGameTick(new GameTick());

	// Logout
	when(client.getGameState()).thenReturn(GameState.LOGIN_SCREEN);
	GameStateChanged gameStateChanged = new GameStateChanged();
	gameStateChanged.setGameState(GameState.LOGIN_SCREEN);
	plugin.onGameStateChanged(gameStateChanged);

	// Log back in
	when(client.getGameState()).thenReturn(GameState.LOGGED_IN);
	gameStateChanged.setGameState(GameState.LOGGED_IN);
	plugin.onGameStateChanged(gameStateChanged);

	// Tick
	plugin.onInteractingChanged(new InteractingChanged(player, null));
	plugin.onGameTick(new GameTick());
	verify(notifier, times(0)).notify(any());
}
 
Example #10
Source File: RaidsPlugin.java    From plugins with GNU General Public License v3.0 6 votes vote down vote up
@Subscribe
private void onClientTick(ClientTick event)
{
	if (!config.raidsTimer()
		|| !client.getGameState().equals(GameState.LOGGED_IN)
		|| tooltip == null)
	{
		return;
	}

	final Point mousePosition = client.getMouseCanvasPosition();
	if (widgetOverlay.getBounds().contains(mousePosition.getX(), mousePosition.getY()))
	{
		tooltipManager.add(new Tooltip(tooltip));
	}
}
 
Example #11
Source File: IdleNotifierPluginTest.java    From runelite with BSD 2-Clause "Simplified" License 6 votes vote down vote up
@Test
public void checkAnimationLogout()
{
	when(player.getAnimation()).thenReturn(AnimationID.WOODCUTTING_BRONZE);
	AnimationChanged animationChanged = new AnimationChanged();
	animationChanged.setActor(player);
	plugin.onAnimationChanged(animationChanged);
	plugin.onGameTick(new GameTick());

	// Logout
	when(client.getGameState()).thenReturn(GameState.LOGIN_SCREEN);
	GameStateChanged gameStateChanged = new GameStateChanged();
	gameStateChanged.setGameState(GameState.LOGIN_SCREEN);
	plugin.onGameStateChanged(gameStateChanged);

	// Log back in
	when(client.getGameState()).thenReturn(GameState.LOGGED_IN);
	gameStateChanged.setGameState(GameState.LOGGED_IN);
	plugin.onGameStateChanged(gameStateChanged);

	// Tick
	when(player.getAnimation()).thenReturn(AnimationID.IDLE);
	plugin.onAnimationChanged(animationChanged);
	plugin.onGameTick(new GameTick());
	verify(notifier, times(0)).notify(any());
}
 
Example #12
Source File: KeyManager.java    From runelite with BSD 2-Clause "Simplified" License 6 votes vote down vote up
private boolean shouldProcess(final KeyListener keyListener)
{
	if (client == null)
	{
		return true;
	}

	if (!(keyListener instanceof HotkeyListener))
	{
		return true;
	}

	final HotkeyListener hotkeyListener = (HotkeyListener) keyListener;

	if (hotkeyListener.isEnabledOnLogin())
	{
		return true;
	}

	return client.getGameState() != GameState.LOGIN_SCREEN;
}
 
Example #13
Source File: MenuEntrySwapperPlugin.java    From plugins with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void startUp()
{
	addSwaps();
	loadCustomSwaps(config.customSwaps(), customSwaps);

	updateBuySellEntries();
	addBuySellEntries();

	updateWithdrawEntries();
	addWithdrawEntries();

	updateRemovedObjects();

	if (client.getGameState() == GameState.LOGGED_IN)
	{
		keyManager.registerKeyListener(ctrlHotkey);
		keyManager.registerKeyListener(hotkey);
	}
}
 
Example #14
Source File: IdleNotifierPluginTest.java    From plugins with GNU General Public License v3.0 6 votes vote down vote up
@Test
public void checkAnimationLogout()
{
	when(player.getAnimation()).thenReturn(AnimationID.WOODCUTTING_BRONZE);
	AnimationChanged animationChanged = new AnimationChanged();
	animationChanged.setActor(player);
	plugin.onAnimationChanged(animationChanged);
	plugin.onGameTick(GameTick.INSTANCE);

	// Logout
	when(client.getGameState()).thenReturn(GameState.LOGIN_SCREEN);
	GameStateChanged gameStateChanged = new GameStateChanged();
	gameStateChanged.setGameState(GameState.LOGIN_SCREEN);
	plugin.onGameStateChanged(gameStateChanged);

	// Log back in
	when(client.getGameState()).thenReturn(GameState.LOGGED_IN);
	gameStateChanged.setGameState(GameState.LOGGED_IN);
	plugin.onGameStateChanged(gameStateChanged);

	// Tick
	when(player.getAnimation()).thenReturn(AnimationID.IDLE);
	plugin.onAnimationChanged(animationChanged);
	plugin.onGameTick(GameTick.INSTANCE);
	verify(notifier, times(0)).notify(any());
}
 
Example #15
Source File: LeagueChatIconsPlugin.java    From runelite with BSD 2-Clause "Simplified" License 6 votes vote down vote up
@Override
protected void startUp()
{
	onLeagueWorld = false;

	clientThread.invoke(() ->
	{
		if (client.getGameState() == GameState.LOGGED_IN)
		{
			loadLeagueIcon();
			onLeagueWorld = isLeagueWorld(client.getWorld());
			if (onLeagueWorld)
			{
				setChatboxName(getNameChatbox());
			}
		}
	});
}
 
Example #16
Source File: WorldHopperPlugin.java    From plugins with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Ping the current world for the ping overlay
 */
private void pingCurrentWorld()
{
	WorldResult worldResult = worldService.getWorlds();
	// There is no reason to ping the current world if not logged in, as the overlay doesn't draw
	if (worldResult == null || !config.displayPing() || client.getGameState() != GameState.LOGGED_IN)
	{
		return;
	}

	final World currentWorld = worldResult.findWorld(client.getWorld());
	if (currentWorld == null)
	{
		log.debug("unable to find current world: {}", client.getWorld());
		return;
	}

	currentPing = ping(currentWorld);
	log.trace("Ping for current world is: {}", currentPing);

	SwingUtilities.invokeLater(() -> panel.updatePing(currentWorld.getId(), currentPing));
}
 
Example #17
Source File: BatsLocatorPlugin.java    From plugins with GNU General Public License v3.0 6 votes vote down vote up
private void checkRaidPresence(boolean force)
{
	if (client.getGameState() != GameState.LOGGED_IN)
	{
		return;
	}

	boolean setting = client.getVar(Varbits.IN_RAID) == 1;

	if (force || inRaidChambers != setting)
	{
		//A new instance is created when leaving the raid chambers instead of entering the raid chambers.
		//Entering the raid chambers will change the IN_RAID varbit but game objects spawn before the varbit change.
		if (!setting)
		{
			batsLocator = new BatsLocator(client);
		}

		inRaidChambers = setting;
	}
}
 
Example #18
Source File: EmojiPluginTest.java    From plugins with GNU General Public License v3.0 6 votes vote down vote up
@Test
public void testOnChatMessage()
{
	when(client.getGameState()).thenReturn(GameState.LOGGED_IN);
	when(client.getModIcons()).thenReturn(new IndexedSprite[0]);
	when(client.createIndexedSprite()).thenReturn(mock(IndexedSprite.class));

	// Trip emoji loading
	GameStateChanged gameStateChanged = new GameStateChanged();
	gameStateChanged.setGameState(GameState.LOGGED_IN);
	emojiPlugin.onGameStateChanged(gameStateChanged);

	MessageNode messageNode = mock(MessageNode.class);
	// With chat recolor, message may be wrapped in col tags
	when(messageNode.getValue()).thenReturn("<col=ff0000>:) :) :)</col>");

	ChatMessage chatMessage = new ChatMessage();
	chatMessage.setType(ChatMessageType.PUBLICCHAT);
	chatMessage.setMessageNode(messageNode);

	emojiPlugin.onChatMessage(chatMessage);

	verify(messageNode).setRuneLiteFormatMessage("<col=ff0000><img=0> <img=0> <img=0></col>");
}
 
Example #19
Source File: IdleNotifierPlugin.java    From runelite with BSD 2-Clause "Simplified" License 6 votes vote down vote up
private void resetTimers()
{
	final Player local = client.getLocalPlayer();

	// Reset animation idle timer
	lastAnimating = null;
	if (client.getGameState() == GameState.LOGIN_SCREEN || local == null || local.getAnimation() != lastAnimation)
	{
		lastAnimation = IDLE;
	}

	// Reset interaction idle timer
	lastInteracting = null;
	if (client.getGameState() == GameState.LOGIN_SCREEN || local == null || local.getInteracting() != lastInteract)
	{
		lastInteract = null;
	}
}
 
Example #20
Source File: AntiDragPlugin.java    From runelite with BSD 2-Clause "Simplified" License 6 votes vote down vote up
@Override
protected void startUp() throws Exception
{
	if (client.getGameState() == GameState.LOGGED_IN)
	{
		clientThread.invokeLater(() ->
		{
			inPvp = client.getVar(Varbits.PVP_SPEC_ORB) == 1;
			if (!config.onShiftOnly() && !inPvp)
			{
				setDragDelay();
			}
		});
	}

	keyManager.registerKeyListener(this);
}
 
Example #21
Source File: GrandExchangePlugin.java    From runelite with BSD 2-Clause "Simplified" License 5 votes vote down vote up
@Subscribe
public void onGrandExchangeOfferChanged(GrandExchangeOfferChanged offerEvent)
{
	final int slot = offerEvent.getSlot();
	final GrandExchangeOffer offer = offerEvent.getOffer();

	if (offer.getState() == GrandExchangeOfferState.EMPTY && client.getGameState() != GameState.LOGGED_IN)
	{
		// Trades are cleared by the client during LOGIN_SCREEN/HOPPING/LOGGING_IN, ignore those so we don't
		// zero and re-submit the trade on login as an update
		return;
	}

	log.debug("GE offer updated: state: {}, slot: {}, item: {}, qty: {}, login: {}",
		offer.getState(), slot, offer.getItemId(), offer.getQuantitySold(), loginBurstGeUpdates);

	ItemComposition offerItem = itemManager.getItemComposition(offer.getItemId());
	boolean shouldStack = offerItem.isStackable() || offer.getTotalQuantity() > 1;
	BufferedImage itemImage = itemManager.getImage(offer.getItemId(), offer.getTotalQuantity(), shouldStack);
	SwingUtilities.invokeLater(() -> panel.getOffersPanel().updateOffer(offerItem, itemImage, offer, slot));

	submitTrade(slot, offer);

	updateConfig(slot, offer);

	if (loginBurstGeUpdates && slot == GE_SLOTS - 1) // slots are sent sequentially on login; this is the last one
	{
		loginBurstGeUpdates = false;
	}
}
 
Example #22
Source File: LowMemoryPlugin.java    From runelite with BSD 2-Clause "Simplified" License 5 votes vote down vote up
@Subscribe
public void onGameStateChanged(GameStateChanged event)
{
	// When the client starts it initializes the texture size based on the memory mode setting.
	// Don't set low memory before the login screen is ready to prevent loading the low detail textures,
	// which breaks the gpu plugin due to it requiring the 128x128px textures
	if (event.getGameState() == GameState.LOGIN_SCREEN)
	{
		client.changeMemoryMode(true);
	}
}
 
Example #23
Source File: MotherlodePluginTest.java    From plugins with GNU General Public License v3.0 5 votes vote down vote up
@Before
public void before()
{
	Guice.createInjector(BoundFieldModule.of(this)).injectMembers(this);

	when(client.getGameState()).thenReturn(GameState.LOGGED_IN);
	when(client.getMapRegions()).thenReturn(new int[]{14679});
}
 
Example #24
Source File: SpawnTimerPlugin.java    From plugins with GNU General Public License v3.0 5 votes vote down vote up
@Subscribe
private void onGameStateChanged(GameStateChanged event)
{
	if (event.getGameState() == GameState.LOGIN_SCREEN ||
		event.getGameState() == GameState.HOPPING)
	{
		highlightedNpcs.clear();
		ticks.clear();
	}
}
 
Example #25
Source File: KeyRemappingListenerTest.java    From plugins with GNU General Public License v3.0 5 votes vote down vote up
@Before
public void setUp()
{
	Guice.createInjector(BoundFieldModule.of(this)).injectMembers(this);

	when(client.getGameState()).thenReturn(GameState.LOGGED_IN);
}
 
Example #26
Source File: QuestListPlugin.java    From runelite with BSD 2-Clause "Simplified" License 5 votes vote down vote up
@Subscribe
public void onGameStateChanged(GameStateChanged e)
{
	if (e.getGameState() == GameState.LOGGING_IN)
	{
		currentFilterState = QuestState.ALL;
	}
}
 
Example #27
Source File: LootTrackerPlugin.java    From runelite with BSD 2-Clause "Simplified" License 5 votes vote down vote up
@Subscribe
public void onGameStateChanged(final GameStateChanged event)
{
	if (event.getGameState() == GameState.LOADING && !client.isInInstancedRegion())
	{
		chestLooted = false;
	}
}
 
Example #28
Source File: KourendLibraryPlugin.java    From runelite with BSD 2-Clause "Simplified" License 5 votes vote down vote up
@Subscribe
public void onGameStateChanged(GameStateChanged event)
{
	if (event.getGameState() == GameState.LOGIN_SCREEN ||
		event.getGameState() == GameState.HOPPING)
	{
		npcsToMark.clear();
	}
}
 
Example #29
Source File: StatusOrbsPlugin.java    From plugins with GNU General Public License v3.0 5 votes vote down vote up
@Subscribe
private void onGameStateChanged(GameStateChanged ev)
{
	if (ev.getGameState() == GameState.HOPPING || ev.getGameState() == GameState.LOGIN_SCREEN)
	{
		ticksSinceHPRegen = -2; // For some reason this makes this accurate
		ticksSinceSpecRegen = 0;
		ticksSinceRunRegen = -1;
	}
}
 
Example #30
Source File: FriendsChatPlugin.java    From runelite with BSD 2-Clause "Simplified" License 5 votes vote down vote up
@Subscribe
public void onGameStateChanged(GameStateChanged state)
{
	GameState gameState = state.getGameState();

	if (gameState == GameState.LOGIN_SCREEN || gameState == GameState.CONNECTION_LOST || gameState == GameState.HOPPING)
	{
		members.clear();
		resetCounter();

		joinMessages.clear();
	}
}