From 34b16cf300ad6e0e6693b832942bd207aa1d68e9 Mon Sep 17 00:00:00 2001 From: Lucas Date: Fri, 17 May 2019 03:33:05 +0200 Subject: [PATCH] checkstyle - blackjack/player indicators/shayzien infirmary --- .../plugins/blackjack/BlackjackPlugin.java | 155 +++++++----- .../PlayerIndicatorsMinimapOverlay.java | 45 ++-- .../PlayerIndicatorsOverlay.java | 52 ++-- .../PlayerIndicatorsPlugin.java | 20 +- .../PlayerIndicatorsService.java | 18 +- .../PlayerIndicatorsTileOverlay.java | 5 - .../ShayzienInfirmaryOverlay.java | 197 +++++++-------- .../ShayzienInfirmaryPlugin.java | 239 +++++++++--------- 8 files changed, 354 insertions(+), 377 deletions(-) diff --git a/runelite-client/src/main/java/net/runelite/client/plugins/blackjack/BlackjackPlugin.java b/runelite-client/src/main/java/net/runelite/client/plugins/blackjack/BlackjackPlugin.java index 72e3735318..c3a8a0876b 100644 --- a/runelite-client/src/main/java/net/runelite/client/plugins/blackjack/BlackjackPlugin.java +++ b/runelite-client/src/main/java/net/runelite/client/plugins/blackjack/BlackjackPlugin.java @@ -46,88 +46,107 @@ import net.runelite.client.plugins.PluginType; * Authors gazivodag longstreet */ @PluginDescriptor( - name = "Blackjack", - description = "Uses chat messages and tick timers instead of animations to read", - tags = {"blackjack", "thieving"}, - type = PluginType.UTILITY + name = "Blackjack", + description = "Uses chat messages and tick timers instead of animations to read", + tags = {"blackjack", "thieving"}, + type = PluginType.UTILITY ) @Singleton @Slf4j -public class BlackjackPlugin extends Plugin { +public class BlackjackPlugin extends Plugin +{ - @Inject - Client client; + @Inject + Client client; - private static long timeSinceKnockout; - private static long timeSinceAggro; + private static long timeSinceKnockout; + private static long timeSinceAggro; - @Getter - private static long currentGameTick; + @Getter + private static long currentGameTick; - @Override - public void configure(Binder binder) { - } + @Override + public void configure(Binder binder) + { + } - @Override - protected void startUp() throws Exception { - currentGameTick = 0; - } + @Override + protected void startUp() throws Exception + { + currentGameTick = 0; + } - @Override - protected void shutDown() throws Exception { - currentGameTick = 0; - } + @Override + protected void shutDown() throws Exception + { + currentGameTick = 0; + } - @Subscribe - public void onGameTick(GameTick gameTick) { - currentGameTick++; - } + @Subscribe + public void onGameTick(GameTick gameTick) + { + currentGameTick++; + } - @Subscribe - public void onChatMessage(ChatMessage chatMessage) { - if (chatMessage.getType() == ChatMessageType.SPAM) { - if (chatMessage.getMessage().equals("You smack the bandit over the head and render them unconscious.")) { - timeSinceKnockout = getCurrentGameTick(); - } - if (chatMessage.getMessage().equals("Your blow only glances off the bandit's head.")) { - timeSinceAggro = getCurrentGameTick(); - } - } - } + @Subscribe + public void onChatMessage(ChatMessage chatMessage) + { + if (chatMessage.getType() == ChatMessageType.SPAM) + { + if (chatMessage.getMessage().equals("You smack the bandit over the head and render them unconscious.")) + { + timeSinceKnockout = getCurrentGameTick(); + } + if (chatMessage.getMessage().equals("Your blow only glances off the bandit's head.")) + { + timeSinceAggro = getCurrentGameTick(); + } + } + } - @Subscribe - public void onMenuEntryAdded(MenuEntryAdded menuEntryAdded) { - String target = menuEntryAdded.getTarget().toLowerCase(); - if ((target.contains("bandit") | target.contains("menaphite thug"))) { - Quest quest = Quest.THE_FEUD; - if (quest.getState(client) == QuestState.FINISHED) { - if (currentGameTick < (timeSinceKnockout + 4)) { - stripSpecificEntries("pickpocket"); - } - if (currentGameTick < (timeSinceAggro + 4)) { - stripSpecificEntries("pickpocket"); - } - stripSpecificEntries("knock-out"); - } - } - } + @Subscribe + public void onMenuEntryAdded(MenuEntryAdded menuEntryAdded) + { + String target = menuEntryAdded.getTarget().toLowerCase(); + if ((target.contains("bandit") | target.contains("menaphite thug"))) + { + Quest quest = Quest.THE_FEUD; + if (quest.getState(client) == QuestState.FINISHED) + { + if (currentGameTick < (timeSinceKnockout + 4)) + { + stripSpecificEntries("pickpocket"); + } + if (currentGameTick < (timeSinceAggro + 4)) + { + stripSpecificEntries("pickpocket"); + } + stripSpecificEntries("knock-out"); + } + } + } - private void stripSpecificEntries(String exceptFor) { - MenuEntry[] currentEntires = client.getMenuEntries(); - MenuEntry[] newEntries = new MenuEntry[2]; + private void stripSpecificEntries(String exceptFor) + { + MenuEntry[] currentEntires = client.getMenuEntries(); + MenuEntry[] newEntries = new MenuEntry[2]; - for (MenuEntry currentEntry : currentEntires) { - if (currentEntry.getOption().toLowerCase().equals(exceptFor.toLowerCase())) { - newEntries[1] = currentEntry; - } - if (currentEntry.getOption().toLowerCase().equals("lure")) { - newEntries[0] = currentEntry; - } - } + for (MenuEntry currentEntry : currentEntires) + { + if (currentEntry.getOption().toLowerCase().equals(exceptFor.toLowerCase())) + { + newEntries[1] = currentEntry; + } + if (currentEntry.getOption().toLowerCase().equals("lure")) + { + newEntries[0] = currentEntry; + } + } - if (newEntries[0] != null && newEntries[1] != null) { - client.setMenuEntries(newEntries); - } - } + if (newEntries[0] != null && newEntries[1] != null) + { + client.setMenuEntries(newEntries); + } + } } \ No newline at end of file diff --git a/runelite-client/src/main/java/net/runelite/client/plugins/playerindicators/PlayerIndicatorsMinimapOverlay.java b/runelite-client/src/main/java/net/runelite/client/plugins/playerindicators/PlayerIndicatorsMinimapOverlay.java index 10e722ea01..32f4b3c07b 100644 --- a/runelite-client/src/main/java/net/runelite/client/plugins/playerindicators/PlayerIndicatorsMinimapOverlay.java +++ b/runelite-client/src/main/java/net/runelite/client/plugins/playerindicators/PlayerIndicatorsMinimapOverlay.java @@ -30,10 +30,9 @@ import java.awt.Graphics2D; import java.awt.image.BufferedImage; import javax.inject.Inject; import javax.inject.Singleton; -import net.runelite.api.Client; import net.runelite.api.Player; import net.runelite.api.Point; -import net.runelite.client.game.ItemManager; +import net.runelite.api.SkullIcon; import net.runelite.client.plugins.friendtagging.FriendTaggingPlugin; import net.runelite.client.ui.overlay.Overlay; import net.runelite.client.ui.overlay.OverlayLayer; @@ -49,10 +48,6 @@ public class PlayerIndicatorsMinimapOverlay extends Overlay private final PlayerIndicatorsConfig config; private final BufferedImage skullIcon = ImageUtil.getResourceStreamFromClass(PlayerIndicatorsPlugin.class, "skull.png"); - @Inject - private ItemManager itemManager; - @Inject - private Client client; @Inject private PlayerIndicatorsMinimapOverlay(PlayerIndicatorsConfig config, PlayerIndicatorsService playerIndicatorsService) @@ -98,31 +93,23 @@ public class PlayerIndicatorsMinimapOverlay extends Overlay } if (config.drawMinimapNames()) { - if (actor.getSkullIcon() != null && config.playerSkull()) + if (actor.getSkullIcon() != null && config.playerSkull() && actor.getSkullIcon() == SkullIcon.SKULL) { - switch (actor.getSkullIcon()) + int width = graphics.getFontMetrics().stringWidth(name); + int height = graphics.getFontMetrics().getHeight(); + if (config.skullLocation().equals(PlayerIndicatorsPlugin.minimapSkullLocations.AFTER_NAME)) { - case SKULL: - - int width = graphics.getFontMetrics().stringWidth(name); - int height = graphics.getFontMetrics().getHeight(); - if (config.skullLocation().equals(PlayerIndicatorsPlugin.minimapSkullLocations.AFTER_NAME)) - { - OverlayUtil.renderImageLocation(graphics, new Point(minimapLocation.getX() - + width, minimapLocation.getY() - height), - ImageUtil.resizeImage(skullIcon, height, height)); - } - else - { - OverlayUtil.renderImageLocation(graphics, new Point(minimapLocation.getX(), - minimapLocation.getY() - height), - ImageUtil.resizeImage(skullIcon, height, height)); - minimapLocation = new Point(minimapLocation.getX() + skullIcon.getWidth(), - minimapLocation.getY()); - } - break; - default: - break; + OverlayUtil.renderImageLocation(graphics, new Point(minimapLocation.getX() + + width, minimapLocation.getY() - height), + ImageUtil.resizeImage(skullIcon, height, height)); + } + else + { + OverlayUtil.renderImageLocation(graphics, new Point(minimapLocation.getX(), + minimapLocation.getY() - height), + ImageUtil.resizeImage(skullIcon, height, height)); + minimapLocation = new Point(minimapLocation.getX() + skullIcon.getWidth(), + minimapLocation.getY()); } } OverlayUtil.renderTextLocation(graphics, minimapLocation, name, color); diff --git a/runelite-client/src/main/java/net/runelite/client/plugins/playerindicators/PlayerIndicatorsOverlay.java b/runelite-client/src/main/java/net/runelite/client/plugins/playerindicators/PlayerIndicatorsOverlay.java index d475f0ea42..97ba662798 100644 --- a/runelite-client/src/main/java/net/runelite/client/plugins/playerindicators/PlayerIndicatorsOverlay.java +++ b/runelite-client/src/main/java/net/runelite/client/plugins/playerindicators/PlayerIndicatorsOverlay.java @@ -36,12 +36,11 @@ import net.runelite.api.Client; import net.runelite.api.ItemComposition; import net.runelite.api.Player; import net.runelite.api.Point; +import net.runelite.api.SkullIcon; import net.runelite.api.kit.KitType; import net.runelite.client.game.ClanManager; import net.runelite.client.game.ItemManager; -import net.runelite.client.game.SpriteManager; import net.runelite.client.plugins.friendtagging.FriendTaggingPlugin; -import net.runelite.client.plugins.pvptools.PvpToolsPlugin; import net.runelite.client.ui.overlay.Overlay; import net.runelite.client.ui.overlay.OverlayPosition; import net.runelite.client.ui.overlay.OverlayPriority; @@ -62,12 +61,9 @@ public class PlayerIndicatorsOverlay extends Overlay private final ClanManager clanManager; private final BufferedImage skullIcon = ImageUtil.getResourceStreamFromClass(PlayerIndicatorsPlugin.class, "skull.png"); - PvpToolsPlugin pvpToolsPlugin; @Inject private Client client; @Inject - private SpriteManager spriteManager; - @Inject private PlayerIndicatorsPlugin playerIndicatorsPlugin; @Inject private ItemManager itemManager; @@ -164,7 +160,7 @@ public class PlayerIndicatorsOverlay extends Overlay } } - String tag = ""; + String tag; String prefix = "tag_"; if (FriendTaggingPlugin.taggedFriends.containsKey(prefix + name.trim().toLowerCase())) { @@ -190,13 +186,13 @@ public class PlayerIndicatorsOverlay extends Overlay if (config.targetRisk() && PvPUtil.isAttackable(client, actor) && actor.getPlayerComposition() != null) { long totalValue = 0; - int newValue = 0; + int newValue; StringBuilder stringBuilder = new StringBuilder(" "); for (KitType kitType : KitType.values()) { ItemComposition itemComposition = itemManager.getItemComposition(actor.getPlayerComposition().getEquipmentId(kitType)); - if (itemComposition != null || itemComposition.getName() != null) + if (itemComposition != null && itemComposition.getName() != null) { totalValue = totalValue + itemComposition.getPrice(); } @@ -204,7 +200,7 @@ public class PlayerIndicatorsOverlay extends Overlay newValue = (int) (totalValue / 1000); if (newValue != 0) { - stringBuilder.append("(" + formatNumber(newValue) + "K)"); + stringBuilder.append("(").append(formatNumber(newValue)).append("K)"); name = name + stringBuilder; } } @@ -216,30 +212,24 @@ public class PlayerIndicatorsOverlay extends Overlay name = name + " cGLORY"; } } - if (actor.getSkullIcon() != null && config.playerSkull()) + + if (actor.getSkullIcon() != null && config.playerSkull() && actor.getSkullIcon() == SkullIcon.SKULL) { - switch (actor.getSkullIcon()) + int width = graphics.getFontMetrics().stringWidth(name); + int height = graphics.getFontMetrics().getHeight(); + if (config.skullLocation().equals(PlayerIndicatorsPlugin.minimapSkullLocations.AFTER_NAME)) { - case SKULL: - int width = graphics.getFontMetrics().stringWidth(name); - int height = graphics.getFontMetrics().getHeight(); - if (config.skullLocation().equals(PlayerIndicatorsPlugin.minimapSkullLocations.AFTER_NAME)) - { - OverlayUtil.renderImageLocation(graphics, new Point(textLocation.getX() - + width, textLocation.getY() - height), - ImageUtil.resizeImage(skullIcon, height, height)); - } - else - { - OverlayUtil.renderImageLocation(graphics, new Point(textLocation.getX(), - textLocation.getY() - height), - ImageUtil.resizeImage(skullIcon, height, height)); - textLocation = new Point(textLocation.getX() + skullIcon.getWidth(), - textLocation.getY()); - } - break; - default: - break; + OverlayUtil.renderImageLocation(graphics, new Point(textLocation.getX() + + width, textLocation.getY() - height), + ImageUtil.resizeImage(skullIcon, height, height)); + } + else + { + OverlayUtil.renderImageLocation(graphics, new Point(textLocation.getX(), + textLocation.getY() - height), + ImageUtil.resizeImage(skullIcon, height, height)); + textLocation = new Point(textLocation.getX() + skullIcon.getWidth(), + textLocation.getY()); } } OverlayUtil.renderTextLocation(graphics, textLocation, name, color); diff --git a/runelite-client/src/main/java/net/runelite/client/plugins/playerindicators/PlayerIndicatorsPlugin.java b/runelite-client/src/main/java/net/runelite/client/plugins/playerindicators/PlayerIndicatorsPlugin.java index 425726a461..2c38b7fc3d 100644 --- a/runelite-client/src/main/java/net/runelite/client/plugins/playerindicators/PlayerIndicatorsPlugin.java +++ b/runelite-client/src/main/java/net/runelite/client/plugins/playerindicators/PlayerIndicatorsPlugin.java @@ -31,15 +31,12 @@ import java.util.Arrays; import java.util.List; import java.util.Objects; import javax.inject.Inject; - import net.runelite.api.Actor; import net.runelite.api.ClanMember; import net.runelite.api.ClanMemberRank; import static net.runelite.api.ClanMemberRank.UNRANKED; import net.runelite.api.Client; import static net.runelite.api.MenuAction.*; - -import net.runelite.api.HeadIcon; import net.runelite.api.MenuEntry; import net.runelite.api.Player; import net.runelite.api.events.ClanMemberJoined; @@ -128,7 +125,7 @@ public class PlayerIndicatorsPlugin extends Plugin { for (String name:callers) { - Actor pile = null; + Actor pile; String finalName = name.toLowerCase().replace("_", " "); if (p.getName().toLowerCase().replace("_", " ").equals(finalName)) { @@ -160,7 +157,7 @@ public class PlayerIndicatorsPlugin extends Plugin getCallerList(); } - public void getCallerList() + private void getCallerList() { callers.clear(); if (config.useClanchatRanks() && client.getClanMembers() != null) @@ -187,7 +184,7 @@ public class PlayerIndicatorsPlugin extends Plugin pileList = Arrays.asList(new String[callers.size()]); } - public boolean isCaller(Player player) + boolean isCaller(Player player) { if (callers != null) { @@ -200,18 +197,15 @@ public class PlayerIndicatorsPlugin extends Plugin } } } - else {return false;} + return false; } - public boolean isPile(Player player) + boolean isPile(Player player) { if (Objects.nonNull(pileList) && pileList.size() > 0) { - if (pileList.contains(player.getName())) - { - return true; - } + return pileList.contains(player.getName()); } return false; } @@ -359,7 +353,7 @@ public class PlayerIndicatorsPlugin extends Plugin } } - public static enum minimapSkullLocations + public enum minimapSkullLocations { BEFORE_NAME, AFTER_NAME diff --git a/runelite-client/src/main/java/net/runelite/client/plugins/playerindicators/PlayerIndicatorsService.java b/runelite-client/src/main/java/net/runelite/client/plugins/playerindicators/PlayerIndicatorsService.java index 5dda29c978..0fae391e05 100644 --- a/runelite-client/src/main/java/net/runelite/client/plugins/playerindicators/PlayerIndicatorsService.java +++ b/runelite-client/src/main/java/net/runelite/client/plugins/playerindicators/PlayerIndicatorsService.java @@ -51,7 +51,7 @@ public class PlayerIndicatorsService { if (!config.highlightOwnPlayer() && !config.drawClanMemberNames() && !config.highlightFriends() && !config.highlightNonClanMembers() && !config.highlightTargets() - && !config.highlightPile() && !config.highlightCallers() && !config.highlightTeamMembers()) + && !config.highlightPile() && !config.highlightCallers() && !config.highlightTeamMembers()) { return; } @@ -94,14 +94,14 @@ public class PlayerIndicatorsService else if (config.highlightTargets() && PvPUtil.isAttackable(client, player) && !client.isFriended(player.getName(), false) && !player.isClanMember()) { - if (config.skulledTargetsOnly() && player.getSkullIcon() != null) - { - consumer.accept(player, config.getTargetColor()); - } - else if (!config.skulledTargetsOnly()) - { - consumer.accept(player, config.getTargetColor()); - } + if (config.skulledTargetsOnly() && player.getSkullIcon() != null) + { + consumer.accept(player, config.getTargetColor()); + } + else if (!config.skulledTargetsOnly()) + { + consumer.accept(player, config.getTargetColor()); + } } if (config.highlightCallers() && config.callers() != null && playerIndicatorsPlugin.isCaller(player)) { diff --git a/runelite-client/src/main/java/net/runelite/client/plugins/playerindicators/PlayerIndicatorsTileOverlay.java b/runelite-client/src/main/java/net/runelite/client/plugins/playerindicators/PlayerIndicatorsTileOverlay.java index bc5a49fbc1..98602e7a4c 100644 --- a/runelite-client/src/main/java/net/runelite/client/plugins/playerindicators/PlayerIndicatorsTileOverlay.java +++ b/runelite-client/src/main/java/net/runelite/client/plugins/playerindicators/PlayerIndicatorsTileOverlay.java @@ -63,11 +63,6 @@ public class PlayerIndicatorsTileOverlay extends Overlay Polygon objectClickbox = player.getConvexHull(); renderPoly(graphics, config.pileColor(), objectClickbox); - - if (objectClickbox != null) - { - - } } }); } diff --git a/runelite-client/src/main/java/net/runelite/client/plugins/shayzieninfirmary/ShayzienInfirmaryOverlay.java b/runelite-client/src/main/java/net/runelite/client/plugins/shayzieninfirmary/ShayzienInfirmaryOverlay.java index 726702f8eb..e6191b1015 100644 --- a/runelite-client/src/main/java/net/runelite/client/plugins/shayzieninfirmary/ShayzienInfirmaryOverlay.java +++ b/runelite-client/src/main/java/net/runelite/client/plugins/shayzieninfirmary/ShayzienInfirmaryOverlay.java @@ -1,100 +1,97 @@ -/* - * Copyright (c) 2019, Yani - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, this - * list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED - * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR - * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES - * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND - * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ -package net.runelite.client.plugins.shayzieninfirmary; - -import java.awt.AlphaComposite; -import java.awt.Color; -import java.awt.Composite; -import java.awt.Dimension; -import java.awt.Graphics2D; -import java.awt.Polygon; -import java.awt.image.BufferedImage; -import javax.inject.Inject; -import net.runelite.api.Client; -import net.runelite.api.ItemID; -import net.runelite.api.NPC; -import net.runelite.api.Point; -import net.runelite.client.game.ItemManager; -import net.runelite.client.ui.overlay.Overlay; -import net.runelite.client.ui.overlay.OverlayPosition; -import net.runelite.client.ui.overlay.OverlayUtil; - -public class ShayzienInfirmaryOverlay extends Overlay -{ - private final ShayzienInfirmaryPlugin plugin; - private final Client client; - - private BufferedImage medPackImage; - - @Inject - public ShayzienInfirmaryOverlay(ShayzienInfirmaryPlugin plugin, Client client, ItemManager itemManager) - { - setPosition(OverlayPosition.DYNAMIC); - this.plugin = plugin; - this.client = client; - - medPackImage = itemManager.getImage(ItemID.SHAYZIEN_MEDPACK); - } - - @Override - public Dimension render(Graphics2D graphics) - { - if (!plugin.isAtInfirmary()) - { - return null; - } - - for (NPC npc : plugin.getUnhealedSoldiers()) - { - - Polygon tilePoly = npc.getCanvasTilePoly(); - - if (tilePoly == null) - { - continue; - } - - OverlayUtil.renderPolygon(graphics, npc.getCanvasTilePoly(), Color.ORANGE); - - Point imageLocation = npc.getCanvasImageLocation(medPackImage, 25); - - if (imageLocation == null) - { - continue; - } - - Composite originalComposite = graphics.getComposite(); - Composite translucentComposite = AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.8f); - - graphics.setComposite(translucentComposite); - - OverlayUtil.renderImageLocation(graphics, imageLocation, medPackImage); - - graphics.setComposite(originalComposite); - } - - return null; - } -} +/* + * Copyright (c) 2019, Yani + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR + * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +package net.runelite.client.plugins.shayzieninfirmary; + +import java.awt.AlphaComposite; +import java.awt.Color; +import java.awt.Composite; +import java.awt.Dimension; +import java.awt.Graphics2D; +import java.awt.Polygon; +import java.awt.image.BufferedImage; +import javax.inject.Inject; +import net.runelite.api.ItemID; +import net.runelite.api.NPC; +import net.runelite.api.Point; +import net.runelite.client.game.ItemManager; +import net.runelite.client.ui.overlay.Overlay; +import net.runelite.client.ui.overlay.OverlayPosition; +import net.runelite.client.ui.overlay.OverlayUtil; + +public class ShayzienInfirmaryOverlay extends Overlay +{ + private final ShayzienInfirmaryPlugin plugin; + + private BufferedImage medPackImage; + + @Inject + public ShayzienInfirmaryOverlay(ShayzienInfirmaryPlugin plugin, ItemManager itemManager) + { + setPosition(OverlayPosition.DYNAMIC); + this.plugin = plugin; + + medPackImage = itemManager.getImage(ItemID.SHAYZIEN_MEDPACK); + } + + @Override + public Dimension render(Graphics2D graphics) + { + if (!plugin.isAtInfirmary()) + { + return null; + } + + for (NPC npc : plugin.getUnhealedSoldiers()) + { + + Polygon tilePoly = npc.getCanvasTilePoly(); + + if (tilePoly == null) + { + continue; + } + + OverlayUtil.renderPolygon(graphics, npc.getCanvasTilePoly(), Color.ORANGE); + + Point imageLocation = npc.getCanvasImageLocation(medPackImage, 25); + + if (imageLocation == null) + { + continue; + } + + Composite originalComposite = graphics.getComposite(); + Composite translucentComposite = AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.8f); + + graphics.setComposite(translucentComposite); + + OverlayUtil.renderImageLocation(graphics, imageLocation, medPackImage); + + graphics.setComposite(originalComposite); + } + + return null; + } +} diff --git a/runelite-client/src/main/java/net/runelite/client/plugins/shayzieninfirmary/ShayzienInfirmaryPlugin.java b/runelite-client/src/main/java/net/runelite/client/plugins/shayzieninfirmary/ShayzienInfirmaryPlugin.java index 70f47daf4c..f84ace58de 100644 --- a/runelite-client/src/main/java/net/runelite/client/plugins/shayzieninfirmary/ShayzienInfirmaryPlugin.java +++ b/runelite-client/src/main/java/net/runelite/client/plugins/shayzieninfirmary/ShayzienInfirmaryPlugin.java @@ -1,123 +1,118 @@ -/* - * Copyright (c) 2019, Yani - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, this - * list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED - * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR - * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES - * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND - * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ -package net.runelite.client.plugins.shayzieninfirmary; - -import java.util.ArrayList; -import java.util.List; -import javax.inject.Inject; -import lombok.AccessLevel; -import lombok.Getter; -import lombok.extern.slf4j.Slf4j; -import net.runelite.api.Client; -import net.runelite.api.NPC; -import net.runelite.api.events.GameTick; -import net.runelite.client.eventbus.Subscribe; -import net.runelite.client.plugins.Plugin; -import net.runelite.client.plugins.PluginDescriptor; -import net.runelite.client.plugins.PluginType; -import net.runelite.client.ui.overlay.OverlayManager; - -@Slf4j -@PluginDescriptor( - name = "Shayzien Infirmary", - description = "Shows the status of wounded soldiers", - tags = {"shayzien", "infirmary", "soldiers"}, - type = PluginType.UTILITY -) -public class ShayzienInfirmaryPlugin extends Plugin -{ - @Getter(AccessLevel.PACKAGE) - private List unhealedSoldiers = new ArrayList(); - - @Inject - private OverlayManager overlayManager; - - @Inject - private Client client; - - @Inject - private ShayzienInfirmaryOverlay overlay; - - @Override - protected void startUp() throws Exception - { - loadPlugin(); - } - - @Override - protected void shutDown() throws Exception - { - unloadPlugin(); - } - - private void loadPlugin() - { - overlayManager.add(overlay); - } - - private void unloadPlugin() - { - overlayManager.remove(overlay); - } - - @Subscribe - public void onGameTick(GameTick event) - { - if(!isAtInfirmary()) - { - return; - } - - unhealedSoldiers.clear(); - - for (NPC npc : client.getNpcs()) - { - if (isUnhealedSoldierId(npc.getId())) - { - unhealedSoldiers.add(npc); - } - } - } - - public boolean isSoldierId(int npcId) - { - return (npcId >= 6826 && npcId <= 6857); - } - - public boolean isUnhealedSoldierId(int npcId) - { - return (isSoldierId(npcId) && npcId % 2 == 0); - } - - public boolean isHealedSoldierId(int npcId) - { - return (isSoldierId(npcId) && npcId % 2 == 1); - } - - public boolean isAtInfirmary() - { - return client.getLocalPlayer().getWorldLocation().getRegionID() == 6200; - } +/* + * Copyright (c) 2019, Yani + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR + * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +package net.runelite.client.plugins.shayzieninfirmary; + +import java.util.ArrayList; +import java.util.List; +import javax.inject.Inject; +import lombok.AccessLevel; +import lombok.Getter; +import lombok.extern.slf4j.Slf4j; +import net.runelite.api.Client; +import net.runelite.api.NPC; +import net.runelite.api.events.GameTick; +import net.runelite.client.eventbus.Subscribe; +import net.runelite.client.plugins.Plugin; +import net.runelite.client.plugins.PluginDescriptor; +import net.runelite.client.plugins.PluginType; +import net.runelite.client.ui.overlay.OverlayManager; + +@Slf4j +@PluginDescriptor( + name = "Shayzien Infirmary", + description = "Shows the status of wounded soldiers", + tags = {"shayzien", "infirmary", "soldiers"}, + type = PluginType.UTILITY +) +public class ShayzienInfirmaryPlugin extends Plugin +{ + @Getter(AccessLevel.PACKAGE) + private List unhealedSoldiers = new ArrayList(); + + @Inject + private OverlayManager overlayManager; + + @Inject + private Client client; + + @Inject + private ShayzienInfirmaryOverlay overlay; + + @Override + protected void startUp() throws Exception + { + loadPlugin(); + } + + @Override + protected void shutDown() throws Exception + { + unloadPlugin(); + } + + private void loadPlugin() + { + overlayManager.add(overlay); + } + + private void unloadPlugin() + { + overlayManager.remove(overlay); + } + + @Subscribe + public void onGameTick(GameTick event) + { + if (!isAtInfirmary()) + { + return; + } + + unhealedSoldiers.clear(); + + for (NPC npc : client.getNpcs()) + { + if (isUnhealedSoldierId(npc.getId())) + { + unhealedSoldiers.add(npc); + } + } + } + + private boolean isSoldierId(int npcId) + { + return (npcId >= 6826 && npcId <= 6857); + } + + private boolean isUnhealedSoldierId(int npcId) + { + return (isSoldierId(npcId) && npcId % 2 == 0); + } + + boolean isAtInfirmary() + { + return client.getLocalPlayer().getWorldLocation().getRegionID() == 6200; + } } \ No newline at end of file