Java Code Examples for net.runelite.api.Player#getName()
The following examples show how to use
net.runelite.api.Player#getName() .
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: ChatCommandsPlugin.java From plugins with GNU General Public License v3.0 | 6 votes |
/** * Gets correct lookup data for message * * @param chatMessage chat message * @return hiscore lookup data */ private HiscoreLookup getCorrectLookupFor(final ChatMessage chatMessage) { Player localPlayer = client.getLocalPlayer(); final String player = Text.sanitize(chatMessage.getName()); // If we are sending the message then just use the local hiscore endpoint for the world if (chatMessage.getType().equals(ChatMessageType.PRIVATECHATOUT) || player.equals(localPlayer.getName())) { return new HiscoreLookup(localPlayer.getName(), hiscoreEndpoint); } // Public chat on a leagues world is always league hiscores, regardless of icon if (chatMessage.getType() == ChatMessageType.PUBLICCHAT || chatMessage.getType() == ChatMessageType.MODCHAT) { if (client.getWorldType().contains(WorldType.LEAGUE)) { return new HiscoreLookup(player, HiscoreEndpoint.LEAGUE); } } // Get ironman status from their icon in chat HiscoreEndpoint endpoint = getHiscoreEndpointByName(chatMessage.getName()); return new HiscoreLookup(player, endpoint); }
Example 2
Source File: LootTrackerPlugin.java From runelite with BSD 2-Clause "Simplified" License | 6 votes |
@Subscribe public void onPlayerLootReceived(final PlayerLootReceived playerLootReceived) { // Ignore Last Man Standing player loots if (isPlayerWithinMapRegion(LAST_MAN_STANDING_REGIONS)) { return; } final Player player = playerLootReceived.getPlayer(); final Collection<ItemStack> items = playerLootReceived.getItems(); final String name = player.getName(); final int combat = player.getCombatLevel(); addLoot(name, combat, LootRecordType.PLAYER, items); if (config.pvpKillChatMessage()) { lootReceivedChatMessage(items, name); } }
Example 3
Source File: ChatCommandsPlugin.java From runelite with BSD 2-Clause "Simplified" License | 6 votes |
/** * Gets correct lookup data for message * * @param chatMessage chat message * @return hiscore lookup data */ private HiscoreLookup getCorrectLookupFor(final ChatMessage chatMessage) { Player localPlayer = client.getLocalPlayer(); final String player = Text.sanitize(chatMessage.getName()); // If we are sending the message then just use the local hiscore endpoint for the world if (chatMessage.getType().equals(ChatMessageType.PRIVATECHATOUT) || player.equals(localPlayer.getName())) { return new HiscoreLookup(localPlayer.getName(), hiscoreEndpoint); } // Public chat on a leagues world is always league hiscores, regardless of icon if (chatMessage.getType() == ChatMessageType.PUBLICCHAT || chatMessage.getType() == ChatMessageType.MODCHAT) { if (client.getWorldType().contains(WorldType.LEAGUE)) { return new HiscoreLookup(player, HiscoreEndpoint.LEAGUE); } } // Get ironman status from their icon in chat HiscoreEndpoint endpoint = getHiscoreEndpointByName(chatMessage.getName()); return new HiscoreLookup(player, endpoint); }
Example 4
Source File: Anonymizer.java From ExternalPlugins with GNU General Public License v3.0 | 6 votes |
@Subscribe public void onGameTick(GameTick event) { Player p = client.getLocalPlayer(); if (p == null) { return; } name = p.getName(); if (config.hideXp()) { Widget xp = client.getWidget(122, 9); if (xp != null && xp.getText() != null && !xp.isHidden()) { xp.setText("123,456,789"); xp.revalidate(); } } }
Example 5
Source File: IdleNotifierPlugin.java From plugins with GNU General Public License v3.0 | 5 votes |
@Subscribe private void onPlayerSpawned(PlayerSpawned event) { final Player p = event.getPlayer(); if (config.notifyPkers() && p != null && p != client.getLocalPlayer() && PvPUtil.isAttackable(client, p) && !client.isFriended(p.getName(), false) && !friendChatManager.isMember(p.getName())) { String playerName = p.getName(); int combat = p.getCombatLevel(); notifier.notify("PK'er warning! A level " + combat + " player named " + playerName + " appeared!", TrayIcon.MessageType.WARNING); } }
Example 6
Source File: DevToolsOverlay.java From plugins with GNU General Public License v3.0 | 5 votes |
private void renderPlayers(Graphics2D graphics) { List<Player> players = client.getPlayers(); Player local = client.getLocalPlayer(); for (Player p : players) { String text = p.getName() + " (A: " + p.getAnimation() + ") (P: " + p.getPoseAnimation() + ") (G: " + p.getSpotAnimation() + ") (IDX: " + p.getPlayerId() + ")"; OverlayUtil.renderActorOverlay(graphics, p, text, p == local ? CYAN : BLUE); } renderPlayerWireframe(graphics, local, CYAN); }
Example 7
Source File: ScreenshotPlugin.java From plugins with GNU General Public License v3.0 | 5 votes |
@Subscribe private void onPlayerLootReceived(final PlayerLootReceived playerLootReceived) { if (config.screenshotKills() && (config.pvpKillScreenshotMode() == PvPKillScreenshotMode.ON_LOOT || config.pvpKillScreenshotMode() == PvPKillScreenshotMode.BOTH)) { final Player player = playerLootReceived.getPlayer(); final String name = player.getName(); String fileName = "Kill " + name; takeScreenshot(fileName, "PvP Kills"); } }
Example 8
Source File: LeagueChatIconsPlugin.java From runelite with BSD 2-Clause "Simplified" License | 5 votes |
/** * Gets the default name, including possible icon, of the local player. * * @return String of icon + name */ private String getNameDefault() { Player player = client.getLocalPlayer(); if (player == null) { return null; } int iconIndex; switch (client.getAccountType()) { case IRONMAN: iconIndex = IconID.IRONMAN.getIndex(); break; case HARDCORE_IRONMAN: iconIndex = IconID.HARDCORE_IRONMAN.getIndex(); break; case ULTIMATE_IRONMAN: iconIndex = IconID.ULTIMATE_IRONMAN.getIndex(); break; default: return player.getName(); } return getNameWithIcon(iconIndex, player.getName()); }
Example 9
Source File: ScreenshotPlugin.java From runelite with BSD 2-Clause "Simplified" License | 5 votes |
@Subscribe public void onPlayerLootReceived(final PlayerLootReceived playerLootReceived) { if (config.screenshotKills()) { final Player player = playerLootReceived.getPlayer(); final String name = player.getName(); String fileName = "Kill " + name; takeScreenshot(fileName, "PvP Kills"); } }
Example 10
Source File: DpsCounterPlugin.java From runelite with BSD 2-Clause "Simplified" License | 4 votes |
@Subscribe public void onHitsplatApplied(HitsplatApplied hitsplatApplied) { Player player = client.getLocalPlayer(); Actor actor = hitsplatApplied.getActor(); if (!(actor instanceof NPC)) { return; } Hitsplat hitsplat = hitsplatApplied.getHitsplat(); if (hitsplat.isMine()) { int hit = hitsplat.getAmount(); // Update local member PartyMember localMember = partyService.getLocalMember(); // If not in a party, user local player name final String name = localMember == null ? player.getName() : localMember.getName(); DpsMember dpsMember = members.computeIfAbsent(name, DpsMember::new); dpsMember.addDamage(hit); // broadcast damage if (localMember != null) { final DpsUpdate specialCounterUpdate = new DpsUpdate(hit); specialCounterUpdate.setMemberId(localMember.getMemberId()); wsClient.send(specialCounterUpdate); } // apply to total } else if (hitsplat.isOthers()) { final int npcId = ((NPC) actor).getId(); boolean isBoss = BOSSES.contains(npcId); if (actor != player.getInteracting() && !isBoss) { // only track damage to npcs we are attacking, or is a nearby common boss return; } // apply to total } else { return; } unpause(); total.addDamage(hitsplat.getAmount()); }
Example 11
Source File: XpTrackerPlugin.java From runelite with BSD 2-Clause "Simplified" License | 4 votes |
@Subscribe public void onGameStateChanged(GameStateChanged event) { GameState state = event.getGameState(); if (state == GameState.LOGGED_IN) { // LOGGED_IN is triggered between region changes too. // Check that the username changed or the world type changed. XpWorldType type = worldSetToType(client.getWorldType()); if (!Objects.equals(client.getUsername(), lastUsername) || lastWorldType != type) { // Reset log.debug("World change: {} -> {}, {} -> {}", lastUsername, client.getUsername(), firstNonNull(lastWorldType, "<unknown>"), firstNonNull(type, "<unknown>")); lastUsername = client.getUsername(); // xp is not available until after login is finished, so fetch it on the next gametick fetchXp = true; lastWorldType = type; resetState(); // Must be set from hitting the LOGGING_IN or HOPPING case below assert initializeTracker; } } else if (state == GameState.LOGGING_IN || state == GameState.HOPPING) { initializeTracker = true; } else if (state == GameState.LOGIN_SCREEN) { Player local = client.getLocalPlayer(); if (local == null) { return; } String username = local.getName(); if (username == null) { return; } long totalXp = client.getOverallExperience(); // Don't submit xptrack unless xp threshold is reached if (Math.abs(totalXp - lastXp) > XP_THRESHOLD) { xpClient.update(username); lastXp = totalXp; } } }
Example 12
Source File: PlayerIndicatorsService.java From runelite with BSD 2-Clause "Simplified" License | 4 votes |
public void forEachPlayer(final BiConsumer<Player, Color> consumer) { if (!config.highlightOwnPlayer() && !config.drawFriendsChatMemberNames() && !config.highlightFriends() && !config.highlightOthers()) { return; } final Player localPlayer = client.getLocalPlayer(); for (Player player : client.getPlayers()) { if (player == null || player.getName() == null) { continue; } boolean isFriendsChatMember = player.isFriendsChatMember(); if (player == localPlayer) { if (config.highlightOwnPlayer()) { consumer.accept(player, config.getOwnPlayerColor()); } } else if (config.highlightFriends() && player.isFriend()) { consumer.accept(player, config.getFriendColor()); } else if (config.drawFriendsChatMemberNames() && isFriendsChatMember) { consumer.accept(player, config.getFriendsChatMemberColor()); } else if (config.highlightTeamMembers() && localPlayer.getTeam() > 0 && localPlayer.getTeam() == player.getTeam()) { consumer.accept(player, config.getTeamMemberColor()); } else if (config.highlightOthers() && !isFriendsChatMember) { consumer.accept(player, config.getOthersColor()); } } }
Example 13
Source File: ClientUI.java From runelite with BSD 2-Clause "Simplified" License | 4 votes |
private void updateFrameConfig(boolean updateResizable) { if (frame == null) { return; } // Update window opacity if the frame is undecorated, translucency capable and not fullscreen if (frame.isUndecorated() && frame.getGraphicsConfiguration().isTranslucencyCapable() && frame.getGraphicsConfiguration().getDevice().getFullScreenWindow() == null) { frame.setOpacity(((float) config.windowOpacity()) / 100.0f); } if (config.usernameInTitle() && (client instanceof Client)) { final Player player = ((Client)client).getLocalPlayer(); if (player != null && player.getName() != null) { frame.setTitle(RuneLiteProperties.getTitle() + " - " + player.getName()); } } else { frame.setTitle(RuneLiteProperties.getTitle()); } if (frame.isAlwaysOnTopSupported()) { frame.setAlwaysOnTop(config.gameAlwaysOnTop()); } if (updateResizable) { frame.setResizable(!config.lockWindowSize()); } frame.setExpandResizeType(config.automaticResizeType()); ContainableFrame.Mode containMode = config.containInScreen(); if (containMode == ContainableFrame.Mode.ALWAYS && !withTitleBar) { // When native window decorations are enabled we don't have a way to receive window move events // so we can't contain to screen always. containMode = ContainableFrame.Mode.RESIZING; } frame.setContainedInScreen(containMode); if (!config.rememberScreenBounds()) { configManager.unsetConfiguration(CONFIG_GROUP, CONFIG_CLIENT_MAXIMIZED); configManager.unsetConfiguration(CONFIG_GROUP, CONFIG_CLIENT_BOUNDS); } if (client == null) { return; } // The upper bounds are defined by the applet's max size // The lower bounds are defined by the client's fixed size int width = Math.max(Math.min(config.gameSize().width, 7680), Constants.GAME_FIXED_WIDTH); int height = Math.max(Math.min(config.gameSize().height, 2160), Constants.GAME_FIXED_HEIGHT); final Dimension size = new Dimension(width, height); if (!size.equals(lastClientSize)) { lastClientSize = size; client.setSize(size); client.setPreferredSize(size); client.getParent().setPreferredSize(size); client.getParent().setSize(size); if (frame.isVisible()) { frame.pack(); } } }
Example 14
Source File: DpsOverlay.java From plugins with GNU General Public License v3.0 | 4 votes |
@Override public Dimension render(Graphics2D graphics) { Map<String, DpsMember> dpsMembers = dpsCounterPlugin.getMembers(); if (dpsMembers.isEmpty()) { return null; } boolean inParty = !partyService.getMembers().isEmpty(); boolean showDamage = dpsConfig.showDamage(); DpsMember total = dpsCounterPlugin.getTotal(); boolean paused = total.isPaused(); final String title = (inParty ? "Party " : "") + (showDamage ? "Damage" : "DPS") + (paused ? " (paused)" : ""); panelComponent.getChildren().add( TitleComponent.builder() .text(title) .build()); int maxWidth = ComponentConstants.STANDARD_WIDTH; FontMetrics fontMetrics = graphics.getFontMetrics(); for (DpsMember dpsMember : dpsMembers.values()) { String left = dpsMember.getName(); String right = showDamage ? QuantityFormatter.formatNumber(dpsMember.getDamage()) : DPS_FORMAT.format(dpsMember.getDps()); maxWidth = Math.max(maxWidth, fontMetrics.stringWidth(left) + fontMetrics.stringWidth(right)); panelComponent.getChildren().add( LineComponent.builder() .left(left) .right(right) .build()); } panelComponent.setPreferredSize(new Dimension(maxWidth + PANEL_WIDTH_OFFSET, 0)); if (!inParty) { Player player = client.getLocalPlayer(); if (player.getName() != null) { DpsMember self = dpsMembers.get(player.getName()); if (self != null && total.getDamage() > self.getDamage()) { panelComponent.getChildren().add( LineComponent.builder() .left(total.getName()) .right(showDamage ? Integer.toString(total.getDamage()) : DPS_FORMAT.format(total.getDps())) .build()); } } } return super.render(graphics); }
Example 15
Source File: DpsCounterPlugin.java From plugins with GNU General Public License v3.0 | 4 votes |
@Subscribe public void onHitsplatApplied(HitsplatApplied hitsplatApplied) { Player player = client.getLocalPlayer(); Actor actor = hitsplatApplied.getActor(); if (!(actor instanceof NPC)) { return; } Hitsplat hitsplat = hitsplatApplied.getHitsplat(); if (hitsplat.isMine()) { int hit = hitsplat.getAmount(); // Update local member PartyMember localMember = partyService.getLocalMember(); // If not in a party, user local player name final String name = localMember == null ? player.getName() : localMember.getName(); DpsMember dpsMember = members.computeIfAbsent(name, DpsMember::new); dpsMember.addDamage(hit); // broadcast damage if (localMember != null) { final DpsUpdate specialCounterUpdate = new DpsUpdate(hit); specialCounterUpdate.setMemberId(localMember.getMemberId()); wsClient.send(specialCounterUpdate); } // apply to total } else if (hitsplat.isOthers()) { final int npcId = ((NPC) actor).getId(); boolean isBoss = BOSSES.contains(npcId); if (actor != player.getInteracting() && !isBoss) { // only track damage to npcs we are attacking, or is a nearby common boss return; } // apply to total } else { return; } unpause(); total.addDamage(hitsplat.getAmount()); }
Example 16
Source File: LootTrackerPlugin.java From plugins with GNU General Public License v3.0 | 4 votes |
@Subscribe private void onPlayerLootReceived(final PlayerLootReceived playerLootReceived) { if (client.getLocalPlayer() == null) { return; } // Ignore Last Man Standing player loots if (isPlayerWithinMapRegion(LAST_MAN_STANDING_REGIONS)) { return; } if (config.sendLootValueMessages()) { if (WorldType.isDeadmanWorld(client.getWorldType()) || WorldType.isHighRiskWorld(client.getWorldType()) || WorldType.isPvpWorld(client.getWorldType()) || client.getVar(Varbits.IN_WILDERNESS) == 1) { final String totalValue = QuantityFormatter.quantityToStackSize(playerLootReceived.getItems().stream() .mapToInt(itemStack -> itemManager.getItemPrice(itemStack.getId()) * itemStack.getQuantity()).sum()); chatMessageManager.queue(QueuedMessage.builder().type(ChatMessageType.CONSOLE).runeLiteFormattedMessage( new ChatMessageBuilder().append("The total value of your loot is " + totalValue + " GP.") .build()).build()); } } final Player player = playerLootReceived.getPlayer(); final Collection<ItemStack> items = playerLootReceived.getItems(); final String name = player.getName(); final int combat = player.getCombatLevel(); final LootTrackerItem[] entries = buildEntries(stack(items)); String localUsername = client.getLocalPlayer().getName(); LootRecord lootRecord = new LootRecord(name, localUsername, LootRecordType.PLAYER, toGameItems(items), Instant.now()); SwingUtilities.invokeLater(() -> panel.add(name, localUsername, lootRecord.getType(), combat, entries)); if (config.saveLoot()) { synchronized (queuedLoots) { queuedLoots.add(lootRecord); } } if (config.localPersistence()) { saveLocalLootRecord(lootRecord); } eventBus.post(LootReceived.class, new LootReceived(name, combat, LootRecordType.PLAYER, items)); }
Example 17
Source File: XpTrackerPlugin.java From plugins with GNU General Public License v3.0 | 4 votes |
@Subscribe void onGameStateChanged(GameStateChanged event) { GameState state = event.getGameState(); if (state == GameState.LOGGED_IN) { // LOGGED_IN is triggered between region changes too. // Check that the username changed or the world type changed. XpWorldType type = worldSetToType(client.getWorldType()); if (!Objects.equals(client.getUsername(), lastUsername) || lastWorldType != type) { // Reset log.debug("World change: {} -> {}, {} -> {}", lastUsername, client.getUsername(), Objects.requireNonNullElse(lastWorldType, "<unknown>"), Objects.requireNonNullElse(type, "<unknown>")); lastUsername = client.getUsername(); // xp is not available until after login is finished, so fetch it on the next gametick fetchXp = true; lastWorldType = type; resetState(); // Must be set from hitting the LOGGING_IN or HOPPING case below assert initializeTracker; } } else if (state == GameState.LOGGING_IN || state == GameState.HOPPING) { initializeTracker = true; } else if (state == GameState.LOGIN_SCREEN) { Player local = client.getLocalPlayer(); if (local == null) { return; } String username = local.getName(); if (username == null) { return; } long totalXp = client.getOverallExperience(); // Don't submit xptrack unless xp threshold is reached if (Math.abs(totalXp - lastXp) > XP_THRESHOLD) { xpClient.update(username); lastXp = totalXp; } } }
Example 18
Source File: CombatOverlay.java From plugins with GNU General Public License v3.0 | 4 votes |
@Override public Dimension render(Graphics2D graphics) { if (config.showTickCounter()) { panelComponent.getChildren().clear(); Player local = client.getLocalPlayer(); if (local == null || local.getName() == null) { return null; } panelComponent.setBackgroundColor(config.bgColor()); panelComponent.getChildren().add(TitleComponent.builder().text("Tick Counter").color(config.titleColor()).build()); int total = 0; TableComponent tableComponent = new TableComponent(); tableComponent.setColumnAlignments(TableAlignment.LEFT, TableAlignment.RIGHT); if (plugin.getCounter().isEmpty()) { tableComponent.addRow(local.getName(), "0"); } else { Map<String, Long> map = this.plugin.getCounter(); if (map == null) { return null; } for (Map.Entry<String, Long> counter : map.entrySet()) { String name = counter.getKey(); if (client.getLocalPlayer().getName().contains(name)) { tableComponent.addRow(ColorUtil.prependColorTag(name, config.selfColor()), ColorUtil.prependColorTag(Long.toString(counter.getValue()), config.selfColor())); } else { tableComponent.addRow(ColorUtil.prependColorTag(name, config.otherColor()), ColorUtil.prependColorTag(Long.toString(counter.getValue()), config.otherColor())); } total += counter.getValue(); } if (!map.containsKey(local.getName())) { tableComponent.addRow(ColorUtil.prependColorTag(local.getName(), config.selfColor()), ColorUtil.prependColorTag("0", config.selfColor())); } } tableComponent.addRow(ColorUtil.prependColorTag("Total:", config.totalColor()), ColorUtil.prependColorTag(String.valueOf(total), config.totalColor())); if (!tableComponent.isEmpty()) { panelComponent.getChildren().add(tableComponent); } return panelComponent.render(graphics); } else { return null; } }
Example 19
Source File: DamageOverlay.java From plugins with GNU General Public License v3.0 | 4 votes |
@Override public Dimension render(Graphics2D graphics) { if (config.showDamageCounter()) { panelComponent.getChildren().clear(); Player local = client.getLocalPlayer(); if (local == null || local.getName() == null) { return null; } panelComponent.setBackgroundColor(config.bgColor()); panelComponent.getChildren().add(TitleComponent.builder().text("Damage Counter").color(config.titleColor()).build()); TableComponent tableComponent = new TableComponent(); tableComponent.setColumnAlignments(TableAlignment.LEFT, TableAlignment.RIGHT); if (plugin.getCounter().isEmpty()) { tableComponent.addRow(local.getName(), "0"); } else { Map<String, Double> map = this.plugin.playerDamage; if (map == null) { return null; } for (Map.Entry<String, Double> damage : map.entrySet()) { String val = String.format("%.1f", damage.getValue()); if (client.getLocalPlayer().getName().contains(damage.getKey())) { tableComponent.addRow(ColorUtil.prependColorTag(damage.getKey(), config.selfColor()), ColorUtil.prependColorTag(val, config.selfColor())); } else { tableComponent.addRow(ColorUtil.prependColorTag(damage.getKey(), config.otherColor()), ColorUtil.prependColorTag(val, config.otherColor())); } } if (!map.containsKey(local.getName())) { tableComponent.addRow(ColorUtil.prependColorTag(local.getName(), config.selfColor()), ColorUtil.prependColorTag("0", config.selfColor())); } } if (!tableComponent.isEmpty()) { panelComponent.getChildren().add(tableComponent); } return panelComponent.render(graphics); } else { return null; } }
Example 20
Source File: DpsOverlay.java From runelite with BSD 2-Clause "Simplified" License | 4 votes |
@Override public Dimension render(Graphics2D graphics) { Map<String, DpsMember> dpsMembers = dpsCounterPlugin.getMembers(); if (dpsMembers.isEmpty()) { return null; } boolean inParty = !partyService.getMembers().isEmpty(); boolean showDamage = dpsConfig.showDamage(); DpsMember total = dpsCounterPlugin.getTotal(); boolean paused = total.isPaused(); final String title = (inParty ? "Party " : "") + (showDamage ? "Damage" : "DPS") + (paused ? " (paused)" : ""); panelComponent.getChildren().add( TitleComponent.builder() .text(title) .build()); int maxWidth = ComponentConstants.STANDARD_WIDTH; FontMetrics fontMetrics = graphics.getFontMetrics(); for (DpsMember dpsMember : dpsMembers.values()) { String left = dpsMember.getName(); String right = showDamage ? QuantityFormatter.formatNumber(dpsMember.getDamage()) : DPS_FORMAT.format(dpsMember.getDps()); maxWidth = Math.max(maxWidth, fontMetrics.stringWidth(left) + fontMetrics.stringWidth(right)); panelComponent.getChildren().add( LineComponent.builder() .left(left) .right(right) .build()); } panelComponent.setPreferredSize(new Dimension(maxWidth + PANEL_WIDTH_OFFSET, 0)); if (!inParty) { Player player = client.getLocalPlayer(); if (player.getName() != null) { DpsMember self = dpsMembers.get(player.getName()); if (self != null && total.getDamage() > self.getDamage()) { panelComponent.getChildren().add( LineComponent.builder() .left(total.getName()) .right(showDamage ? Integer.toString(total.getDamage()) : DPS_FORMAT.format(total.getDps())) .build()); } } } return super.render(graphics); }