Refactor PrayAgainstPrayer

This commit is contained in:
Scott Burns
2019-05-16 01:06:29 +02:00
parent 2b61a17447
commit 26f24ae54d
5 changed files with 483 additions and 277 deletions

View File

@@ -31,26 +31,34 @@ import net.runelite.api.Player;
* When they attacked me * When they attacked me
* And (in milliseconds) when to expire the overlay around them * And (in milliseconds) when to expire the overlay around them
*/ */
public class PlayerContainer { public class PlayerContainer
{
private Player player; private Player player;
private long whenTheyAttackedMe; private long whenTheyAttackedMe;
private int millisToExpireHighlight; private int millisToExpireHighlight;
public PlayerContainer(Player player, long whenTheyAttackedMe, int millisToExpireHighlight) { PlayerContainer(Player player, long whenTheyAttackedMe, int millisToExpireHighlight)
{
this.player = player; this.player = player;
this.whenTheyAttackedMe = whenTheyAttackedMe; this.whenTheyAttackedMe = whenTheyAttackedMe;
this.millisToExpireHighlight = millisToExpireHighlight; this.millisToExpireHighlight = millisToExpireHighlight;
} }
//getters //getters
public Player getPlayer() { public Player getPlayer()
{
return player; return player;
} }
public long getWhenTheyAttackedMe() {
long getWhenTheyAttackedMe()
{
return whenTheyAttackedMe; return whenTheyAttackedMe;
} }
public int getMillisToExpireHighlight() { return millisToExpireHighlight; };
int getMillisToExpireHighlight()
{
return millisToExpireHighlight;
}
} }

View File

@@ -24,160 +24,209 @@
package net.runelite.client.plugins.prayagainstplayer; package net.runelite.client.plugins.prayagainstplayer;
import java.awt.Color;
import net.runelite.client.config.Config; import net.runelite.client.config.Config;
import net.runelite.client.config.ConfigGroup; import net.runelite.client.config.ConfigGroup;
import net.runelite.client.config.ConfigItem; import net.runelite.client.config.ConfigItem;
import java.awt.*;
@ConfigGroup("prayagainstplayer") @ConfigGroup("prayagainstplayer")
public interface PrayAgainstPlayerConfig extends Config { public interface PrayAgainstPlayerConfig extends Config
{
@ConfigItem( @ConfigItem(
position = 0, position = 0,
keyName = "attackerPlayerColor", keyName = "attackerPlayerColor",
name = "Attacker color", name = "Attacker color",
description = "This is the color that will be used to highlight attackers." description = "This is the color that will be used to highlight attackers."
) )
default Color attackerPlayerColor() { return new Color(0xFF0006); } default Color attackerPlayerColor()
{
return new Color(0xFF0006);
}
@ConfigItem( @ConfigItem(
position = 1, position = 1,
keyName = "potentialPlayerColor", keyName = "potentialPlayerColor",
name = "Potential Attacker color", name = "Potential Attacker color",
description = "This is the color that will be used to highlight potential attackers." description = "This is the color that will be used to highlight potential attackers."
) )
default Color potentialPlayerColor() { return new Color(0xFFFF00); } default Color potentialPlayerColor()
{
//// return new Color(0xFFFF00);
@ConfigItem( }
position = 2,
keyName = "attackerTargetTimeout",
name = "Attacker Timeout",
description = "Seconds until attacker is no longer highlighted."
)
default int attackerTargetTimeout() { return 10; }
@ConfigItem( @ConfigItem(
position = 3, position = 2,
keyName = "potentialTargetTimeout", keyName = "attackerTargetTimeout",
name = "Potential Attacker Timeout", name = "Attacker Timeout",
description = "Seconds until potential attacker is no longer highlighted." description = "Seconds until attacker is no longer highlighted."
) )
default int potentialTargetTimeout() { return 10; } default int attackerTargetTimeout()
{
return 10;
}
@ConfigItem( @ConfigItem(
position = 4, position = 3,
keyName = "newSpawnTimeout", keyName = "potentialTargetTimeout",
name = "New Player Timeout", name = "Potential Attacker Timeout",
description = "Seconds until logged in/spawned player is no longer highlighted." description = "Seconds until potential attacker is no longer highlighted."
) )
default int newSpawnTimeout() { return 5; } default int potentialTargetTimeout()
//// {
return 10;
//// }
@ConfigItem(
position = 5,
keyName = "ignoreFriends",
name = "Ignore Friends",
description = "This lets you decide whether you want friends to be highlighted by this plugin."
)
default boolean ignoreFriends() { return true; }
@ConfigItem( @ConfigItem(
position = 6, position = 4,
keyName = "ignoreClanMates", keyName = "newSpawnTimeout",
name = "Ignore Clan Mates", name = "New Player Timeout",
description = "This lets you decide whether you want clan mates to be highlighted by this plugin." description = "Seconds until logged in/spawned player is no longer highlighted."
) )
default boolean ignoreClanMates() { return true; } default int newSpawnTimeout()
//// {
return 5;
}
@ConfigItem( @ConfigItem(
position = 7, position = 5,
keyName = "markNewPlayer", keyName = "ignoreFriends",
name = "Mark new player as potential attacker", name = "Ignore Friends",
description = "Marks someone that logged in or teleported as a potential attacker for your safety\nDO NOT RUN THIS IN WORLD 1-2 GRAND EXCHANGE!" description = "This lets you decide whether you want friends to be highlighted by this plugin."
) )
default boolean markNewPlayer() { return false; } default boolean ignoreFriends()
{
return true;
}
@ConfigItem( @ConfigItem(
position = 8, position = 6,
keyName = "drawTargetPrayAgainst", keyName = "ignoreClanMates",
name = "Draw what to pray on attacker", name = "Ignore Clan Mates",
description = "Tells you what to pray from what weapon the attacker is holding" description = "This lets you decide whether you want clan mates to be highlighted by this plugin."
) )
default boolean drawTargetPrayAgainst() { return true; } default boolean ignoreClanMates()
{
return true;
}
@ConfigItem( @ConfigItem(
position = 9, position = 7,
keyName = "drawPotentialTargetPrayAgainst", keyName = "markNewPlayer",
name = "Draw what to pray on potential attacker", name = "Mark new player as potential attacker",
description = "Tells you what to pray from what weapon the potential attacker is holding" description = "Marks someone that logged in or teleported as a potential attacker for your safety\nDO NOT RUN THIS IN WORLD 1-2 GRAND EXCHANGE!"
) )
default boolean drawPotentialTargetPrayAgainst() { return true; } default boolean markNewPlayer()
{
return false;
}
@ConfigItem( @ConfigItem(
position = 10, position = 8,
keyName = "drawTargetPrayAgainstPrayerTab", keyName = "drawTargetPrayAgainst",
name = "Draw what to pray from prayer tab", name = "Draw what to pray on attacker",
description = "Tells you what to pray from what weapon the attacker is holding from the prayer tab" description = "Tells you what to pray from what weapon the attacker is holding"
) )
default boolean drawTargetPrayAgainstPrayerTab() { return false; } default boolean drawTargetPrayAgainst()
{
return true;
}
@ConfigItem( @ConfigItem(
position = 11, position = 9,
keyName = "drawTargetsName", keyName = "drawPotentialTargetPrayAgainst",
name = "Draw name on attacker", name = "Draw what to pray on potential attacker",
description = "Configures whether or not the attacker\'s name should be shown" description = "Tells you what to pray from what weapon the potential attacker is holding"
) )
default boolean drawTargetsName() { return true; } default boolean drawPotentialTargetPrayAgainst()
{
return true;
}
@ConfigItem( @ConfigItem(
position = 12, position = 10,
keyName = "drawPotentialTargetsName", keyName = "drawTargetPrayAgainstPrayerTab",
name = "Draw name on potential attacker", name = "Draw what to pray from prayer tab",
description = "Configures whether or not the potential attacker\'s name should be shown" description = "Tells you what to pray from what weapon the attacker is holding from the prayer tab"
) )
default boolean drawPotentialTargetsName() { return true; } default boolean drawTargetPrayAgainstPrayerTab()
{
return false;
}
@ConfigItem( @ConfigItem(
position = 13, position = 11,
keyName = "drawTargetHighlight", keyName = "drawTargetsName",
name = "Draw highlight around attacker", name = "Draw name on attacker",
description = "Configures whether or not the attacker should be highlighted" description = "Configures whether or not the attacker\'s name should be shown"
) )
default boolean drawTargetHighlight() { return true; } default boolean drawTargetsName()
{
return true;
}
@ConfigItem( @ConfigItem(
position = 14, position = 12,
keyName = "drawPotentialTargetHighlight", keyName = "drawPotentialTargetsName",
name = "Draw highlight around potential attacker", name = "Draw name on potential attacker",
description = "Configures whether or not the potential attacker should be highlighted" description = "Configures whether or not the potential attacker\'s name should be shown"
) )
default boolean drawPotentialTargetHighlight() { return true; } default boolean drawPotentialTargetsName()
{
return true;
}
@ConfigItem( @ConfigItem(
position = 15, position = 13,
keyName = "drawTargetTile", keyName = "drawTargetHighlight",
name = "Draw tile under attacker", name = "Draw highlight around attacker",
description = "Configures whether or not the attacker\'s tile be highlighted" description = "Configures whether or not the attacker should be highlighted"
) )
default boolean drawTargetTile() { return false; } default boolean drawTargetHighlight()
{
return true;
}
@ConfigItem( @ConfigItem(
position = 16, position = 14,
keyName = "drawPotentialTargetTile", keyName = "drawPotentialTargetHighlight",
name = "Draw tile under potential attacker", name = "Draw highlight around potential attacker",
description = "Configures whether or not the potential attacker\'s tile be highlighted" description = "Configures whether or not the potential attacker should be highlighted"
) )
default boolean drawPotentialTargetTile() { return false; } default boolean drawPotentialTargetHighlight()
{
return true;
}
@ConfigItem( @ConfigItem(
position = 17, position = 15,
keyName = "drawUnknownWeapons", keyName = "drawTargetTile",
name = "Draw unknown weapons", name = "Draw tile under attacker",
description = "Configures whether or not the unknown weapons should be shown when a player equips one" description = "Configures whether or not the attacker\'s tile be highlighted"
) )
default boolean drawUnknownWeapons() { return false; } default boolean drawTargetTile()
{
return false;
}
@ConfigItem(
position = 16,
keyName = "drawPotentialTargetTile",
name = "Draw tile under potential attacker",
description = "Configures whether or not the potential attacker\'s tile be highlighted"
)
default boolean drawPotentialTargetTile()
{
return false;
}
@ConfigItem(
position = 17,
keyName = "drawUnknownWeapons",
name = "Draw unknown weapons",
description = "Configures whether or not the unknown weapons should be shown when a player equips one"
)
default boolean drawUnknownWeapons()
{
return false;
}
} }

View File

@@ -24,27 +24,35 @@
package net.runelite.client.plugins.prayagainstplayer; package net.runelite.client.plugins.prayagainstplayer;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Graphics2D;
import java.awt.Polygon;
import java.awt.image.BufferedImage;
import java.util.ConcurrentModificationException;
import javax.inject.Inject;
import net.runelite.api.Client; import net.runelite.api.Client;
import net.runelite.api.ItemComposition; import net.runelite.api.ItemComposition;
import net.runelite.api.Player; import net.runelite.api.Player;
import net.runelite.api.kit.KitType;
import net.runelite.client.ui.overlay.*;
import net.runelite.client.util.Text;
import net.runelite.api.Point; import net.runelite.api.Point;
import net.runelite.api.kit.KitType;
import net.runelite.client.ui.overlay.Overlay;
import net.runelite.client.ui.overlay.OverlayLayer;
import net.runelite.client.ui.overlay.OverlayPosition;
import net.runelite.client.ui.overlay.OverlayPriority;
import net.runelite.client.ui.overlay.OverlayUtil;
import net.runelite.client.util.Text;
import javax.inject.Inject; class PrayAgainstPlayerOverlay extends Overlay
import java.awt.*; {
import java.awt.image.BufferedImage;
import java.util.ConcurrentModificationException;
class PrayAgainstPlayerOverlay extends Overlay {
private final PrayAgainstPlayerPlugin plugin; private final PrayAgainstPlayerPlugin plugin;
private final PrayAgainstPlayerConfig config; private final PrayAgainstPlayerConfig config;
private final Client client; private final Client client;
@Inject @Inject
private PrayAgainstPlayerOverlay(PrayAgainstPlayerPlugin plugin, PrayAgainstPlayerConfig config, Client client) { private PrayAgainstPlayerOverlay(PrayAgainstPlayerPlugin plugin, PrayAgainstPlayerConfig config, Client client)
{
super(plugin); super(plugin);
this.plugin = plugin; this.plugin = plugin;
this.config = config; this.config = config;
@@ -57,73 +65,127 @@ class PrayAgainstPlayerOverlay extends Overlay {
@Override @Override
public Dimension render(Graphics2D graphics) { public Dimension render(Graphics2D graphics)
{
renderPotentialPlayers(graphics); renderPotentialPlayers(graphics);
renderAttackingPlayers(graphics); renderAttackingPlayers(graphics);
return null; return null;
} }
private void renderPotentialPlayers(Graphics2D graphics) { private void renderPotentialPlayers(Graphics2D graphics)
if (plugin.getPotentialPlayersAttackingMe() == null || !plugin.getPotentialPlayersAttackingMe().isEmpty()) { {
try { if (plugin.getPotentialPlayersAttackingMe() == null || !plugin.getPotentialPlayersAttackingMe().isEmpty())
for (PlayerContainer container : plugin.getPotentialPlayersAttackingMe()) { {
if ((System.currentTimeMillis() > (container.getWhenTheyAttackedMe() + container.getMillisToExpireHighlight())) && (container.getPlayer().getInteracting() != client.getLocalPlayer())) { try
plugin.removePlayerFromPotentialContainer(container); {
if (plugin.getPotentialPlayersAttackingMe() != null)
{
for (PlayerContainer container : plugin.getPotentialPlayersAttackingMe())
{
if ((System.currentTimeMillis() > (container.getWhenTheyAttackedMe() + container.getMillisToExpireHighlight())) && (container.getPlayer().getInteracting() != client.getLocalPlayer()))
{
plugin.removePlayerFromPotentialContainer(container);
}
if (config.drawPotentialTargetsName())
{
renderNameAboveHead(graphics, container.getPlayer(), config.potentialPlayerColor());
}
if (config.drawPotentialTargetHighlight())
{
renderHighlightedPlayer(graphics, container.getPlayer(), config.potentialPlayerColor());
}
if (config.drawPotentialTargetTile())
{
renderTileUnderPlayer(graphics, container.getPlayer(), config.potentialPlayerColor());
}
if (config.drawPotentialTargetPrayAgainst())
{
renderPrayAgainstOnPlayer(graphics, container.getPlayer(), config.potentialPlayerColor());
}
} }
if (config.drawPotentialTargetsName()) renderNameAboveHead(graphics, container.getPlayer(), config.potentialPlayerColor());
if (config.drawPotentialTargetHighlight()) renderHighlightedPlayer(graphics, container.getPlayer(), config.potentialPlayerColor());
if (config.drawPotentialTargetTile()) renderTileUnderPlayer(graphics, container.getPlayer(), config.potentialPlayerColor());
if (config.drawPotentialTargetPrayAgainst()) renderPrayAgainstOnPlayer(graphics, container.getPlayer(), config.potentialPlayerColor());
} }
} catch (ConcurrentModificationException e) { }
catch (ConcurrentModificationException ignored)
{
} }
} }
} }
private void renderAttackingPlayers(Graphics2D graphics) { private void renderAttackingPlayers(Graphics2D graphics)
if (plugin.getPlayersAttackingMe() == null || !plugin.getPlayersAttackingMe().isEmpty()) { {
try { if (plugin.getPlayersAttackingMe() == null || !plugin.getPlayersAttackingMe().isEmpty())
for (PlayerContainer container : plugin.getPlayersAttackingMe()) { {
if ((System.currentTimeMillis() > (container.getWhenTheyAttackedMe() + container.getMillisToExpireHighlight())) && (container.getPlayer().getInteracting() != client.getLocalPlayer())) { try
plugin.removePlayerFromAttackerContainer(container); {
} if (plugin.getPlayersAttackingMe() != null)
{
for (PlayerContainer container : plugin.getPlayersAttackingMe())
{
if ((System.currentTimeMillis() > (container.getWhenTheyAttackedMe() + container.getMillisToExpireHighlight())) && (container.getPlayer().getInteracting() != client.getLocalPlayer()))
{
plugin.removePlayerFromAttackerContainer(container);
}
if (config.drawTargetsName()) renderNameAboveHead(graphics, container.getPlayer(), config.attackerPlayerColor()); if (config.drawTargetsName())
if (config.drawTargetHighlight()) renderHighlightedPlayer(graphics, container.getPlayer(), config.attackerPlayerColor()); {
if (config.drawTargetTile()) renderTileUnderPlayer(graphics, container.getPlayer(), config.attackerPlayerColor()); renderNameAboveHead(graphics, container.getPlayer(), config.attackerPlayerColor());
if (config.drawTargetPrayAgainst()) renderPrayAgainstOnPlayer(graphics, container.getPlayer(), config.attackerPlayerColor()); }
if (config.drawTargetHighlight())
{
renderHighlightedPlayer(graphics, container.getPlayer(), config.attackerPlayerColor());
}
if (config.drawTargetTile())
{
renderTileUnderPlayer(graphics, container.getPlayer(), config.attackerPlayerColor());
}
if (config.drawTargetPrayAgainst())
{
renderPrayAgainstOnPlayer(graphics, container.getPlayer(), config.attackerPlayerColor());
}
}
} }
} catch (ConcurrentModificationException e) { }
catch (ConcurrentModificationException ignored)
{
} }
} }
} }
private void renderNameAboveHead(Graphics2D graphics, Player player, Color color) { private void renderNameAboveHead(Graphics2D graphics, Player player, Color color)
{
final String name = Text.sanitize(player.getName()); final String name = Text.sanitize(player.getName());
final int offset = player.getLogicalHeight() + 40; final int offset = player.getLogicalHeight() + 40;
Point textLocation = player.getCanvasTextLocation(graphics, name, offset); Point textLocation = player.getCanvasTextLocation(graphics, name, offset);
if (textLocation != null) { if (textLocation != null)
{
OverlayUtil.renderTextLocation(graphics, textLocation, name, color); OverlayUtil.renderTextLocation(graphics, textLocation, name, color);
} }
} }
private void renderHighlightedPlayer(Graphics2D graphics, Player player, Color color) { private void renderHighlightedPlayer(Graphics2D graphics, Player player, Color color)
try { {
try
{
OverlayUtil.renderPolygon(graphics, player.getConvexHull(), color); OverlayUtil.renderPolygon(graphics, player.getConvexHull(), color);
} catch (NullPointerException e) { }
catch (NullPointerException ignored)
{
} }
} }
private void renderTileUnderPlayer(Graphics2D graphics, Player player, Color color) { private void renderTileUnderPlayer(Graphics2D graphics, Player player, Color color)
{
Polygon poly = player.getCanvasTilePoly(); Polygon poly = player.getCanvasTilePoly();
OverlayUtil.renderPolygon(graphics, poly, color); OverlayUtil.renderPolygon(graphics, poly, color);
} }
private void renderPrayAgainstOnPlayer(Graphics2D graphics, Player player, Color color) { private void renderPrayAgainstOnPlayer(Graphics2D graphics, Player player, Color color)
{
final int offset = (player.getLogicalHeight() / 2) + 75; final int offset = (player.getLogicalHeight() / 2) + 75;
BufferedImage icon; BufferedImage icon;
switch (WeaponType.checkWeaponOnPlayer(client, player)) { switch (WeaponType.checkWeaponOnPlayer(client, player))
{
case WEAPON_MELEE: case WEAPON_MELEE:
icon = plugin.getProtectionIcon(WeaponType.WEAPON_MELEE); icon = plugin.getProtectionIcon(WeaponType.WEAPON_MELEE);
break; break;
@@ -137,12 +199,17 @@ class PrayAgainstPlayerOverlay extends Overlay {
icon = null; icon = null;
break; break;
} }
try { try
if (icon != null) { {
if (icon != null)
{
Point point = player.getCanvasImageLocation(icon, offset); Point point = player.getCanvasImageLocation(icon, offset);
OverlayUtil.renderImageLocation(graphics, point, icon); OverlayUtil.renderImageLocation(graphics, point, icon);
} else { }
if (config.drawUnknownWeapons()) { else
{
if (config.drawUnknownWeapons())
{
int itemId = player.getPlayerComposition().getEquipmentId(KitType.WEAPON); int itemId = player.getPlayerComposition().getEquipmentId(KitType.WEAPON);
ItemComposition itemComposition = client.getItemDefinition(itemId); ItemComposition itemComposition = client.getItemDefinition(itemId);
@@ -151,7 +218,9 @@ class PrayAgainstPlayerOverlay extends Overlay {
OverlayUtil.renderTextLocation(graphics, point, str, color); OverlayUtil.renderTextLocation(graphics, point, str, color);
} }
} }
} catch (Exception e) { }
catch (Exception ignored)
{
} }
} }

View File

@@ -24,24 +24,33 @@
package net.runelite.client.plugins.prayagainstplayer; package net.runelite.client.plugins.prayagainstplayer;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Graphics2D;
import java.awt.Polygon;
import java.awt.Rectangle;
import java.util.ConcurrentModificationException;
import javax.inject.Inject;
import net.runelite.api.Client; import net.runelite.api.Client;
import net.runelite.api.Player; import net.runelite.api.Player;
import net.runelite.api.widgets.Widget; import net.runelite.api.widgets.Widget;
import net.runelite.api.widgets.WidgetInfo; import net.runelite.api.widgets.WidgetInfo;
import net.runelite.client.ui.overlay.*; import net.runelite.client.ui.overlay.Overlay;
import net.runelite.client.ui.overlay.OverlayLayer;
import net.runelite.client.ui.overlay.OverlayPosition;
import net.runelite.client.ui.overlay.OverlayPriority;
import net.runelite.client.ui.overlay.OverlayUtil;
import javax.inject.Inject; class PrayAgainstPlayerOverlayPrayerTab extends Overlay
import java.awt.*; {
import java.util.ConcurrentModificationException;
class PrayAgainstPlayerOverlayPrayerTab extends Overlay {
private final PrayAgainstPlayerPlugin plugin; private final PrayAgainstPlayerPlugin plugin;
private final PrayAgainstPlayerConfig config; private final PrayAgainstPlayerConfig config;
private final Client client; private final Client client;
@Inject @Inject
private PrayAgainstPlayerOverlayPrayerTab (PrayAgainstPlayerPlugin plugin, PrayAgainstPlayerConfig config, Client client) { private PrayAgainstPlayerOverlayPrayerTab(PrayAgainstPlayerPlugin plugin, PrayAgainstPlayerConfig config, Client client)
{
super(plugin); super(plugin);
this.plugin = plugin; this.plugin = plugin;
this.config = config; this.config = config;
@@ -54,30 +63,46 @@ class PrayAgainstPlayerOverlayPrayerTab extends Overlay {
@Override @Override
public Dimension render(Graphics2D graphics) { public Dimension render(Graphics2D graphics)
if (plugin.getPlayersAttackingMe() == null || !plugin.getPlayersAttackingMe().isEmpty()) { {
try { if (plugin.getPlayersAttackingMe() == null || !plugin.getPlayersAttackingMe().isEmpty())
for (PlayerContainer container : plugin.getPlayersAttackingMe()) { {
if (plugin.getPlayersAttackingMe() != null && plugin.getPlayersAttackingMe().size() > 0) { try
//no reason to show you what prayers to pray in your prayer tab if multiple people are attacking you {
if ((plugin.getPlayersAttackingMe().size() == 1) && (config.drawTargetPrayAgainstPrayerTab())) { if (plugin.getPlayersAttackingMe() != null)
renderPrayerToClick(graphics, container.getPlayer()); {
for (PlayerContainer container : plugin.getPlayersAttackingMe())
{
if (plugin.getPlayersAttackingMe() != null && plugin.getPlayersAttackingMe().size() > 0)
{
// no reason to show you what prayers to pray in your prayer tab if multiple people are attacking you
if ((plugin.getPlayersAttackingMe().size() == 1) && (config.drawTargetPrayAgainstPrayerTab()))
{
renderPrayerToClick(graphics, container.getPlayer());
}
} }
} }
} }
} catch (ConcurrentModificationException e) { }
catch (ConcurrentModificationException ignored)
{
} }
} }
return null; return null;
} }
private void renderPrayerToClick(Graphics2D graphics, Player player) { private void renderPrayerToClick(Graphics2D graphics, Player player)
{
Widget PROTECT_FROM_MAGIC = client.getWidget(WidgetInfo.PRAYER_PROTECT_FROM_MAGIC); Widget PROTECT_FROM_MAGIC = client.getWidget(WidgetInfo.PRAYER_PROTECT_FROM_MAGIC);
Widget PROTECT_FROM_RANGED = client.getWidget(WidgetInfo.PRAYER_PROTECT_FROM_MISSILES); Widget PROTECT_FROM_RANGED = client.getWidget(WidgetInfo.PRAYER_PROTECT_FROM_MISSILES);
Widget PROTECT_FROM_MELEE = client.getWidget(WidgetInfo.PRAYER_PROTECT_FROM_MELEE); Widget PROTECT_FROM_MELEE = client.getWidget(WidgetInfo.PRAYER_PROTECT_FROM_MELEE);
Color color = Color.RED; Color color = Color.RED;
if (PROTECT_FROM_MELEE.isHidden()) return; if (PROTECT_FROM_MELEE.isHidden())
switch (WeaponType.checkWeaponOnPlayer(client, player)) { {
return;
}
switch (WeaponType.checkWeaponOnPlayer(client, player))
{
case WEAPON_MAGIC: case WEAPON_MAGIC:
OverlayUtil.renderPolygon(graphics, rectangleToPolygon(PROTECT_FROM_MAGIC.getBounds()), color); OverlayUtil.renderPolygon(graphics, rectangleToPolygon(PROTECT_FROM_MAGIC.getBounds()), color);
break; break;
@@ -92,9 +117,11 @@ class PrayAgainstPlayerOverlayPrayerTab extends Overlay {
} }
} }
private static Polygon rectangleToPolygon(Rectangle rect) { private static Polygon rectangleToPolygon(Rectangle rect)
{
int[] xpoints = {rect.x, rect.x + rect.width, rect.x + rect.width, rect.x}; int[] xpoints = {rect.x, rect.x + rect.width, rect.x + rect.width, rect.x};
int[] ypoints = {rect.y, rect.y, rect.y + rect.height, rect.y + rect.height}; int[] ypoints = {rect.y, rect.y, rect.y + rect.height, rect.y + rect.height};
return new Polygon(xpoints, ypoints, 4); return new Polygon(xpoints, ypoints, 4);
} }

View File

@@ -25,8 +25,27 @@
package net.runelite.client.plugins.prayagainstplayer; package net.runelite.client.plugins.prayagainstplayer;
import com.google.inject.Provides; import com.google.inject.Provides;
import net.runelite.api.*; import java.awt.Color;
import net.runelite.api.events.*; import java.awt.Dimension;
import java.awt.image.BufferedImage;
import java.awt.image.ColorModel;
import java.awt.image.DataBufferByte;
import java.awt.image.IndexColorModel;
import java.awt.image.WritableRaster;
import java.util.ArrayList;
import java.util.Arrays;
import javax.inject.Inject;
import net.runelite.api.AnimationID;
import net.runelite.api.Client;
import net.runelite.api.GameState;
import net.runelite.api.IndexedSprite;
import net.runelite.api.Player;
import net.runelite.api.SpriteID;
import net.runelite.api.events.AnimationChanged;
import net.runelite.api.events.GameStateChanged;
import net.runelite.api.events.InteractingChanged;
import net.runelite.api.events.PlayerDespawned;
import net.runelite.api.events.PlayerSpawned;
import net.runelite.client.config.ConfigManager; import net.runelite.client.config.ConfigManager;
import net.runelite.client.eventbus.Subscribe; import net.runelite.client.eventbus.Subscribe;
import net.runelite.client.game.SpriteManager; import net.runelite.client.game.SpriteManager;
@@ -36,33 +55,28 @@ import net.runelite.client.plugins.PluginType;
import net.runelite.client.ui.overlay.OverlayManager; import net.runelite.client.ui.overlay.OverlayManager;
import net.runelite.client.util.ImageUtil; import net.runelite.client.util.ImageUtil;
import javax.inject.Inject;
import java.awt.*;
import java.awt.image.*;
import java.util.ArrayList;
import java.util.Arrays;
@PluginDescriptor( @PluginDescriptor(
name = "Pray Against Player", name = "Pray Against Player",
description = "Use plugin in PvP situations for best results!!", description = "Use plugin in PvP situations for best results!!",
tags = {"highlight", "pvp", "overlay", "players"}, tags = {"highlight", "pvp", "overlay", "players"},
type = PluginType.PVP type = PluginType.PVP
) )
/** /**
* I am fully aware that there is plenty of overhead and is a MESS! * I am fully aware that there is plenty of overhead and is a MESS!
* If you'd like to contribute please do! * If you'd like to contribute please do!
*/ */
public class PrayAgainstPlayerPlugin extends Plugin { public class PrayAgainstPlayerPlugin extends Plugin
{
private static final int[] PROTECTION_ICONS = { private static final int[] PROTECTION_ICONS = {
SpriteID.PRAYER_PROTECT_FROM_MISSILES, SpriteID.PRAYER_PROTECT_FROM_MISSILES,
SpriteID.PRAYER_PROTECT_FROM_MELEE, SpriteID.PRAYER_PROTECT_FROM_MELEE,
SpriteID.PRAYER_PROTECT_FROM_MAGIC SpriteID.PRAYER_PROTECT_FROM_MAGIC
}; };
private static final Dimension PROTECTION_ICON_DIMENSION = new Dimension(33, 33); private static final Dimension PROTECTION_ICON_DIMENSION = new Dimension(33, 33);
private static final Color PROTECTION_ICON_OUTLINE_COLOR = new Color(33, 33, 33); private static final Color PROTECTION_ICON_OUTLINE_COLOR = new Color(33, 33, 33);
public final BufferedImage[] ProtectionIcons = new BufferedImage[PROTECTION_ICONS.length]; private final BufferedImage[] ProtectionIcons = new BufferedImage[PROTECTION_ICONS.length];
private ArrayList<PlayerContainer> potentialPlayersAttackingMe; private ArrayList<PlayerContainer> potentialPlayersAttackingMe;
private ArrayList<PlayerContainer> playersAttackingMe; private ArrayList<PlayerContainer> playersAttackingMe;
@@ -86,19 +100,23 @@ public class PrayAgainstPlayerPlugin extends Plugin {
private PrayAgainstPlayerConfig config; private PrayAgainstPlayerConfig config;
@Provides @Provides
PrayAgainstPlayerConfig provideConfig(ConfigManager configManager) { PrayAgainstPlayerConfig provideConfig(ConfigManager configManager)
{
return configManager.getConfig(PrayAgainstPlayerConfig.class); return configManager.getConfig(PrayAgainstPlayerConfig.class);
} }
@Subscribe @Subscribe
public void onGameStateChanged(GameStateChanged gameStateChanged) { public void onGameStateChanged(GameStateChanged gameStateChanged)
if (gameStateChanged.getGameState() == GameState.LOGGED_IN) { {
if (gameStateChanged.getGameState() == GameState.LOGGED_IN)
{
loadProtectionIcons(); loadProtectionIcons();
} }
} }
@Override @Override
protected void startUp() { protected void startUp()
{
potentialPlayersAttackingMe = new ArrayList<>(); potentialPlayersAttackingMe = new ArrayList<>();
playersAttackingMe = new ArrayList<>(); playersAttackingMe = new ArrayList<>();
overlayManager.add(overlay); overlayManager.add(overlay);
@@ -106,31 +124,44 @@ public class PrayAgainstPlayerPlugin extends Plugin {
} }
@Override @Override
protected void shutDown() throws Exception { protected void shutDown() throws Exception
{
overlayManager.remove(overlay); overlayManager.remove(overlay);
overlayManager.remove(overlayPrayerTab); overlayManager.remove(overlayPrayerTab);
} }
@Subscribe @Subscribe
protected void onAnimationChanged(AnimationChanged animationChanged) { protected void onAnimationChanged(AnimationChanged animationChanged)
if ((animationChanged.getActor() instanceof Player) && (animationChanged.getActor().getInteracting() instanceof Player) && (animationChanged.getActor().getInteracting() == client.getLocalPlayer())) { {
if ((animationChanged.getActor() instanceof Player) && (animationChanged.getActor().getInteracting() instanceof Player) && (animationChanged.getActor().getInteracting() == client.getLocalPlayer()))
{
Player sourcePlayer = (Player) animationChanged.getActor(); Player sourcePlayer = (Player) animationChanged.getActor();
//is the client is a friend/clan and the config is set to ignore friends/clan dont add them to list // is the client is a friend/clan and the config is set to ignore friends/clan dont add them to list
if (client.isFriended(sourcePlayer.getName(), true) && config.ignoreFriends()) return; if (client.isFriended(sourcePlayer.getName(), true) && config.ignoreFriends())
if (client.isClanMember(sourcePlayer.getName()) && config.ignoreClanMates()) return; {
return;
}
if (client.isClanMember(sourcePlayer.getName()) && config.ignoreClanMates())
{
return;
}
if ((sourcePlayer.getAnimation() != -1) && (!isBlockAnimation(sourcePlayer.getAnimation()))) { if ((sourcePlayer.getAnimation() != -1) && (!isBlockAnimation(sourcePlayer.getAnimation())))
//if attacker attacks again, reset his timer so overlay doesn't go away {
if (findPlayerInAttackerList(sourcePlayer) != null) { // if attacker attacks again, reset his timer so overlay doesn't go away
if (findPlayerInAttackerList(sourcePlayer) != null)
{
resetPlayerFromAttackerContainerTimer(findPlayerInAttackerList(sourcePlayer)); resetPlayerFromAttackerContainerTimer(findPlayerInAttackerList(sourcePlayer));
} }
//if he attacks and he was in the potential attackers list, remove him // if he attacks and he was in the potential attackers list, remove him
if (!potentialPlayersAttackingMe.isEmpty() && potentialPlayersAttackingMe.contains(findPlayerInPotentialList(sourcePlayer))) { if (!potentialPlayersAttackingMe.isEmpty() && potentialPlayersAttackingMe.contains(findPlayerInPotentialList(sourcePlayer)))
{
removePlayerFromPotentialContainer(findPlayerInPotentialList(sourcePlayer)); removePlayerFromPotentialContainer(findPlayerInPotentialList(sourcePlayer));
} }
//if he's not in the attackers list, add him // if he's not in the attackers list, add him
if (findPlayerInAttackerList(sourcePlayer) == null) { if (findPlayerInAttackerList(sourcePlayer) == null)
{
PlayerContainer container = new PlayerContainer(sourcePlayer, System.currentTimeMillis(), (config.attackerTargetTimeout() * 1000)); PlayerContainer container = new PlayerContainer(sourcePlayer, System.currentTimeMillis(), (config.attackerTargetTimeout() * 1000));
playersAttackingMe.add(container); playersAttackingMe.add(container);
} }
@@ -139,16 +170,25 @@ public class PrayAgainstPlayerPlugin extends Plugin {
} }
@Subscribe @Subscribe
protected void onInteractingChanged(InteractingChanged interactingChanged) { protected void onInteractingChanged(InteractingChanged interactingChanged)
//if someone interacts with you, add them to the potential attackers list {
if ((interactingChanged.getSource() instanceof Player) && (interactingChanged.getTarget() instanceof Player)) { // if someone interacts with you, add them to the potential attackers list
if ((interactingChanged.getSource() instanceof Player) && (interactingChanged.getTarget() instanceof Player))
{
Player sourcePlayer = (Player) interactingChanged.getSource(); Player sourcePlayer = (Player) interactingChanged.getSource();
Player targetPlayer = (Player) interactingChanged.getTarget(); Player targetPlayer = (Player) interactingChanged.getTarget();
if ((targetPlayer == client.getLocalPlayer()) && (findPlayerInPotentialList(sourcePlayer) == null)) { //we're being interacted with if ((targetPlayer == client.getLocalPlayer()) && (findPlayerInPotentialList(sourcePlayer) == null))
{ //we're being interacted with
//is the client is a friend/clan and the config is set to ignore friends/clan dont add them to list // is the client is a friend/clan and the config is set to ignore friends/clan dont add them to list
if (client.isFriended(sourcePlayer.getName(), true) && config.ignoreFriends()) return; if (client.isFriended(sourcePlayer.getName(), true) && config.ignoreFriends())
if (client.isClanMember(sourcePlayer.getName()) && config.ignoreClanMates()) return; {
return;
}
if (client.isClanMember(sourcePlayer.getName()) && config.ignoreClanMates())
{
return;
}
PlayerContainer container = new PlayerContainer(sourcePlayer, System.currentTimeMillis(), (config.potentialTargetTimeout() * 1000)); PlayerContainer container = new PlayerContainer(sourcePlayer, System.currentTimeMillis(), (config.potentialTargetTimeout() * 1000));
potentialPlayersAttackingMe.add(container); potentialPlayersAttackingMe.add(container);
@@ -157,53 +197,71 @@ public class PrayAgainstPlayerPlugin extends Plugin {
} }
@Subscribe @Subscribe
protected void onPlayerDespawned(PlayerDespawned playerDespawned) { protected void onPlayerDespawned(PlayerDespawned playerDespawned)
{
PlayerContainer container = findPlayerInAttackerList(playerDespawned.getPlayer()); PlayerContainer container = findPlayerInAttackerList(playerDespawned.getPlayer());
PlayerContainer container2 = findPlayerInPotentialList(playerDespawned.getPlayer()); PlayerContainer container2 = findPlayerInPotentialList(playerDespawned.getPlayer());
if (container != null) { if (container != null)
{
playersAttackingMe.remove(container); playersAttackingMe.remove(container);
} }
if (container2 != null) { if (container2 != null)
{
potentialPlayersAttackingMe.remove(container2); potentialPlayersAttackingMe.remove(container2);
} }
} }
@Subscribe @Subscribe
protected void onPlayerSpawned(PlayerSpawned playerSpawned) { protected void onPlayerSpawned(PlayerSpawned playerSpawned)
if (config.markNewPlayer()) { {
if (config.markNewPlayer())
{
Player p = playerSpawned.getPlayer(); Player p = playerSpawned.getPlayer();
if (client.isFriended(p.getName(), true) && config.ignoreFriends()) return; if (client.isFriended(p.getName(), true) && config.ignoreFriends())
if (client.isClanMember(p.getName()) && config.ignoreClanMates()) return; {
return;
}
if (client.isClanMember(p.getName()) && config.ignoreClanMates())
{
return;
}
PlayerContainer container = findPlayerInPotentialList(p); PlayerContainer container = findPlayerInPotentialList(p);
if (container == null) { if (container == null)
{
container = new PlayerContainer(p, System.currentTimeMillis(), (config.newSpawnTimeout() * 1000)); container = new PlayerContainer(p, System.currentTimeMillis(), (config.newSpawnTimeout() * 1000));
potentialPlayersAttackingMe.add(container); potentialPlayersAttackingMe.add(container);
} }
} }
} }
PlayerContainer findPlayerInAttackerList(Player player) { private PlayerContainer findPlayerInAttackerList(Player player)
if (playersAttackingMe.isEmpty()) { {
if (playersAttackingMe.isEmpty())
{
return null; return null;
} }
for (int i = 0 ; i < playersAttackingMe.size() ; i++) { for (PlayerContainer container : playersAttackingMe)
PlayerContainer container = playersAttackingMe.get(i); {
if (container.getPlayer() == player) { if (container.getPlayer() == player)
{
return container; return container;
} }
} }
return null; return null;
} }
PlayerContainer findPlayerInPotentialList(Player player) { private PlayerContainer findPlayerInPotentialList(Player player)
if (potentialPlayersAttackingMe.isEmpty()) { {
if (potentialPlayersAttackingMe.isEmpty())
{
return null; return null;
} }
for (int i = 0 ; i < potentialPlayersAttackingMe.size() ; i++) { for (PlayerContainer container : potentialPlayersAttackingMe)
PlayerContainer container = potentialPlayersAttackingMe.get(i); {
if (container.getPlayer() == player) { if (container.getPlayer() == player)
{
return container; return container;
} }
} }
@@ -212,29 +270,36 @@ public class PrayAgainstPlayerPlugin extends Plugin {
/** /**
* Resets player timer in case he attacks again, so his highlight doesn't go away so easily * Resets player timer in case he attacks again, so his highlight doesn't go away so easily
*
* @param container * @param container
*/ */
public void resetPlayerFromAttackerContainerTimer(PlayerContainer container) { private void resetPlayerFromAttackerContainerTimer(PlayerContainer container)
{
removePlayerFromAttackerContainer(container); removePlayerFromAttackerContainer(container);
PlayerContainer newContainer = new PlayerContainer(container.getPlayer(), System.currentTimeMillis(), (config.attackerTargetTimeout() * 1000)); PlayerContainer newContainer = new PlayerContainer(container.getPlayer(), System.currentTimeMillis(), (config.attackerTargetTimeout() * 1000));
playersAttackingMe.add(newContainer); playersAttackingMe.add(newContainer);
} }
void removePlayerFromPotentialContainer(PlayerContainer container)
public void removePlayerFromPotentialContainer(PlayerContainer container) { {
if ((potentialPlayersAttackingMe != null) && (!potentialPlayersAttackingMe.isEmpty()) && (potentialPlayersAttackingMe.contains(container))) { if ((potentialPlayersAttackingMe != null) && (!potentialPlayersAttackingMe.isEmpty()))
{
potentialPlayersAttackingMe.remove(container); potentialPlayersAttackingMe.remove(container);
} }
} }
public void removePlayerFromAttackerContainer(PlayerContainer container) { void removePlayerFromAttackerContainer(PlayerContainer container)
if ((playersAttackingMe != null) && (!playersAttackingMe.isEmpty()) && (playersAttackingMe.contains(container))) { {
if ((playersAttackingMe != null) && (!playersAttackingMe.isEmpty()))
{
playersAttackingMe.remove(container); playersAttackingMe.remove(container);
} }
} }
private boolean isBlockAnimation(int anim) { private boolean isBlockAnimation(int anim)
switch (anim) { {
switch (anim)
{
case AnimationID.BLOCK_DEFENDER: case AnimationID.BLOCK_DEFENDER:
case AnimationID.BLOCK_NO_SHIELD: case AnimationID.BLOCK_NO_SHIELD:
case AnimationID.BLOCK_SHIELD: case AnimationID.BLOCK_SHIELD:
@@ -246,49 +311,34 @@ public class PrayAgainstPlayerPlugin extends Plugin {
} }
} }
public ArrayList<PlayerContainer> getPotentialPlayersAttackingMe() { return potentialPlayersAttackingMe; } ArrayList<PlayerContainer> getPotentialPlayersAttackingMe()
public ArrayList<PlayerContainer> getPlayersAttackingMe() { return playersAttackingMe; } {
return potentialPlayersAttackingMe;
}
ArrayList<PlayerContainer> getPlayersAttackingMe()
{
return playersAttackingMe;
}
//All of the methods below are from the Zulrah plugin!!! Credits to it's respective owner //All of the methods below are from the Zulrah plugin!!! Credits to it's respective owner
private void loadProtectionIcons() { private void loadProtectionIcons()
final IndexedSprite[] protectionIcons = {}; {
final IndexedSprite[] newProtectionIcons = Arrays.copyOf(protectionIcons, PROTECTION_ICONS.length);
int curPosition = 0; int curPosition = 0;
for (int i = 0; i < PROTECTION_ICONS.length; i++, curPosition++) for (int i = 0; i < PROTECTION_ICONS.length; i++, curPosition++)
{ {
final int resource = PROTECTION_ICONS[i]; final int resource = PROTECTION_ICONS[i];
ProtectionIcons[i] = rgbaToIndexedBufferedImage(ProtectionIconFromSprite(spriteManager.getSprite(resource, 0))); ProtectionIcons[i] = rgbaToIndexedBufferedImage(ProtectionIconFromSprite(spriteManager.getSprite(resource, 0)));
newProtectionIcons[curPosition] = createIndexedSprite(client, ProtectionIcons[i]);
} }
} }
private static IndexedSprite createIndexedSprite(final Client client, final BufferedImage bufferedImage) { private static BufferedImage rgbaToIndexedBufferedImage(final BufferedImage sourceBufferedImage)
final IndexColorModel indexedCM = (IndexColorModel) bufferedImage.getColorModel(); {
final int width = bufferedImage.getWidth();
final int height = bufferedImage.getHeight();
final byte[] pixels = ((DataBufferByte) bufferedImage.getRaster().getDataBuffer()).getData();
final int[] palette = new int[indexedCM.getMapSize()];
indexedCM.getRGBs(palette);
final IndexedSprite newIndexedSprite = client.createIndexedSprite();
newIndexedSprite.setPixels(pixels);
newIndexedSprite.setPalette(palette);
newIndexedSprite.setWidth(width);
newIndexedSprite.setHeight(height);
newIndexedSprite.setOriginalWidth(width);
newIndexedSprite.setOriginalHeight(height);
newIndexedSprite.setOffsetX(0);
newIndexedSprite.setOffsetY(0);
return newIndexedSprite;
}
private static BufferedImage rgbaToIndexedBufferedImage(final BufferedImage sourceBufferedImage) {
final BufferedImage indexedImage = new BufferedImage( final BufferedImage indexedImage = new BufferedImage(
sourceBufferedImage.getWidth(), sourceBufferedImage.getWidth(),
sourceBufferedImage.getHeight(), sourceBufferedImage.getHeight(),
BufferedImage.TYPE_BYTE_INDEXED); BufferedImage.TYPE_BYTE_INDEXED);
final ColorModel cm = indexedImage.getColorModel(); final ColorModel cm = indexedImage.getColorModel();
final IndexColorModel icm = (IndexColorModel) cm; final IndexColorModel icm = (IndexColorModel) cm;
@@ -309,13 +359,16 @@ public class PrayAgainstPlayerPlugin extends Plugin {
return resultIndexedImage; return resultIndexedImage;
} }
private static BufferedImage ProtectionIconFromSprite(final BufferedImage freezeSprite) { private static BufferedImage ProtectionIconFromSprite(final BufferedImage freezeSprite)
{
final BufferedImage freezeCanvas = ImageUtil.resizeCanvas(freezeSprite, PROTECTION_ICON_DIMENSION.width, PROTECTION_ICON_DIMENSION.height); final BufferedImage freezeCanvas = ImageUtil.resizeCanvas(freezeSprite, PROTECTION_ICON_DIMENSION.width, PROTECTION_ICON_DIMENSION.height);
return ImageUtil.outlineImage(freezeCanvas, PROTECTION_ICON_OUTLINE_COLOR); return ImageUtil.outlineImage(freezeCanvas, PROTECTION_ICON_OUTLINE_COLOR);
} }
BufferedImage getProtectionIcon(WeaponType weaponType) { BufferedImage getProtectionIcon(WeaponType weaponType)
switch (weaponType) { {
switch (weaponType)
{
case WEAPON_RANGED: case WEAPON_RANGED:
return ProtectionIcons[0]; return ProtectionIcons[0];
case WEAPON_MELEE: case WEAPON_MELEE: