playerscouter: fix conmod exception, and various other updates. (#1294)

* playerscouter: fix conmod exception, and various other updates.

* playerscouter: revert config caching removal.
This commit is contained in:
Ganom
2019-08-14 21:11:05 -04:00
committed by GitHub
parent a3c3b9edf6
commit dd4986a9dd
3 changed files with 159 additions and 126 deletions

View File

@@ -31,30 +31,25 @@ import lombok.ToString;
import net.runelite.api.Player;
import net.runelite.http.api.hiscore.HiscoreResult;
/*
You may be asking, why in the fuck is there so much information
being gathered? The answer is, why not. Always plan for the future.
Better to have too much than to have too little.
*/
@Getter(AccessLevel.PACKAGE)
@Setter(AccessLevel.PACKAGE)
@ToString(exclude = "player")
class PlayerContainer
{
private boolean httpRetry;
private boolean scouted;
private HiscoreResult skills;
private int prayer;
private int risk;
private int scoutTimer;
private int weapon;
private int wildyLevel;
private LinkedHashMap<Integer, Integer> gear;
private LinkedHashMap<Integer, Integer> riskedGear;
private Player player;
private String location;
private String name;
private String targetString;
private boolean httpRetry;
private boolean scouted;
private int prayer;
private int risk;
private int scoutTimer;
private int weapon;
private int wildyLevel;
PlayerContainer(Player player)
{
@@ -66,8 +61,8 @@ class PlayerContainer
this.prayer = -1;
this.risk = 0;
this.riskedGear = new LinkedHashMap<>();
this.scouted = false;
this.scoutTimer = 500;
this.scouted = false;
this.skills = null;
this.targetString = "";
this.weapon = 0;

View File

@@ -94,7 +94,7 @@ public class PlayerScouter extends Plugin
private static final DiscordClient DISCORD_CLIENT = new DiscordClient();
private static final Map<WorldArea, String> WILD_LOCS = WorldLocation.getLocationMap();
private static final SimpleDateFormat SDF = new SimpleDateFormat("MMM dd h:mm a z");
private static final String ICONBASEURL = "https://www.osrsbox.com/osrsbox-db/items-icons/"; // Add item id + ".png"
private static final String ICON_URL = "https://www.osrsbox.com/osrsbox-db/items-icons/"; // Add item id + ".png"
@Inject
private Client client;
@Inject
@@ -103,17 +103,18 @@ public class PlayerScouter extends Plugin
private PlayerScouterConfig config;
@Inject
private EventBus eventBus;
private Set<PlayerContainer> playerContainer = new HashSet<>();
private ExecutorService executorService = Executors.newFixedThreadPool(Runtime.getRuntime().availableProcessors() * 2);
private Map<HiscoreResult, String> resultCache = new HashMap<>();
private Map<String, Integer> blacklist = new HashMap<>();
private HttpUrl url;
private final ExecutorService executorService = Executors.newFixedThreadPool(Runtime.getRuntime().availableProcessors() * 2);
private final Set<PlayerContainer> playerContainer = new HashSet<>();
private final Map<String, HiscoreResult> resultCache = new HashMap<>();
private final Map<String, Integer> blacklist = new HashMap<>();
private HttpUrl webhook;
private int minimumRisk;
private int minimumValue;
private int timeout;
private boolean onlyWildy;
private boolean outputItems;
private boolean scoutFriends;
private boolean scoutClan;
@Provides
PlayerScouterConfig provideConfig(ConfigManager configManager)
@@ -125,8 +126,15 @@ public class PlayerScouter extends Plugin
protected void startUp()
{
blacklist.clear();
updateConfig();
addSubscriptions();
updateConfig();
if (client.getGameState() == GameState.LOGGED_IN)
{
for (Player player : client.getPlayers())
{
addPlayer(player);
}
}
}
@Override
@@ -195,14 +203,17 @@ public class PlayerScouter extends Plugin
private void onPlayerSpawned(PlayerSpawned event)
{
final Player player = event.getPlayer();
addPlayer(player);
}
if (player == client.getLocalPlayer())
{
return;
}
if (!blacklist.isEmpty() && blacklist.keySet().contains(player.getName()))
private void addPlayer(Player player)
{
if (player == client.getLocalPlayer()
|| (!blacklist.isEmpty() && blacklist.containsKey(player.getName()))
|| (!this.scoutFriends && client.isFriended(player.getName(), false)
|| (!this.scoutClan && client.isClanMember(player.getName()))))
{
log.debug("Player Rejected: {}", player.getName());
return;
}
@@ -210,7 +221,6 @@ public class PlayerScouter extends Plugin
blacklist.put(player.getName(), client.getTickCount() + this.timeout);
}
private void resetBlacklist()
{
if (blacklist.isEmpty())
@@ -218,11 +228,13 @@ public class PlayerScouter extends Plugin
return;
}
blacklist.forEach((k, v) ->
Iterator<Map.Entry<String, Integer>> iter = blacklist.entrySet().iterator();
iter.forEachRemaining(entry ->
{
if (v == client.getTickCount())
if (entry.getValue() == client.getTickCount())
{
blacklist.remove(k, v);
iter.remove();
}
});
}
@@ -233,27 +245,24 @@ public class PlayerScouter extends Plugin
{
return true;
}
return client.getVar(Varbits.IN_WILDERNESS) == 1 || WorldType.isPvpWorld(client.getWorldType());
}
private void updateConfig()
{
this.url = HttpUrl.parse(config.webhook());
this.webhook = HttpUrl.parse(config.webhook());
this.minimumRisk = config.minimumRisk();
this.minimumValue = config.minimumValue();
this.timeout = config.timeout();
this.onlyWildy = config.onlyWildy();
this.outputItems = config.outputItems();
this.scoutClan = config.scoutClan();
this.scoutFriends = config.scoutFriends();
}
private void update(PlayerContainer player)
{
player.setRisk(0);
updatePlayerGear(player);
updateStats(player);
player.setLocation(location(player));
player.setWildyLevel(PvPUtil.getWildernessLevelFrom(player.getPlayer().getWorldLocation()));
player.setTargetString(targetStringBuilder(player));
if (player.isScouted())
{
player.setScoutTimer(player.getScoutTimer() - 1);
@@ -262,39 +271,37 @@ public class PlayerScouter extends Plugin
player.setScouted(false);
player.setScoutTimer(500);
}
return;
}
player.setRisk(0);
updatePlayerGear(player);
updateStats(player);
player.setLocation(location(player));
player.setWildyLevel(PvPUtil.getWildernessLevelFrom(player.getPlayer().getWorldLocation()));
player.setTargetString(targetStringBuilder(player));
log.debug(player.toString());
}
private void updateStats(PlayerContainer player)
{
if (player.getSkills() == null)
if (player.isHttpRetry() || player.getSkills() != null)
{
if (player.isHttpRetry())
return;
}
executorService.submit(() ->
{
player.setHttpRetry(true);
HiscoreResult result;
if (resultCache.containsKey(player.getName()))
{
return;
result = resultCache.get(player.getName());
}
executorService.submit(() ->
else
{
player.setHttpRetry(true);
HiscoreResult result = null;
try
{
if (!resultCache.values().contains(player.getName()))
{
result = HISCORE_CLIENT.lookup(player.getName());
}
else
{
for (Map.Entry<HiscoreResult, String> entry : resultCache.entrySet())
{
if (!entry.getValue().equals(player.getName()))
{
continue;
}
result = entry.getKey();
}
}
result = HISCORE_CLIENT.lookup(player.getName());
}
catch (IOException ex)
{
@@ -302,65 +309,71 @@ public class PlayerScouter extends Plugin
player.setHttpRetry(false);
return;
}
resultCache.put(result, player.getName());
}
if (result == null)
{
player.setHttpRetry(false);
player.setSkills(result);
player.setPrayer(player.getSkills().getPrayer().getLevel());
});
}
return;
}
resultCache.put(player.getName(), result);
player.setSkills(result);
player.setPrayer(player.getSkills().getPrayer().getLevel());
});
}
private void updatePlayerGear(PlayerContainer player)
{
Map<Integer, Integer> prices = new HashMap<>();
if (player.getPlayer().getPlayerAppearance() != null)
if (player.getPlayer().getPlayerAppearance() == null)
{
for (KitType kitType : KitType.values())
{
if (kitType.equals(KitType.RING) || kitType.equals(KitType.AMMUNITION))
{
continue;
}
final int id = player.getPlayer().getPlayerAppearance().getEquipmentId(kitType);
if (id == -1)
{
continue;
}
if (kitType.equals(KitType.WEAPON))
{
player.setWeapon(id);
}
final ItemStats item = itemManager.getItemStats(id, false);
final ItemDefinition itemDefinition = itemManager.getItemDefinition(id);
if (item == null)
{
log.debug("Item is null: {}", id);
continue;
}
if (PvPValueBrokenItem.breaksOnDeath(id))
{
prices.put(id, itemManager.getBrokenValue(id));
log.debug("Item has a broken value: Id {}, Value {}", id, itemManager.getBrokenValue(id));
}
if (!itemDefinition.isTradeable() && !PvPValueBrokenItem.breaksOnDeath(id))
{
prices.put(id, itemDefinition.getPrice());
}
else if (itemDefinition.isTradeable())
{
prices.put(id, itemManager.getItemPrice(id, false));
}
}
updateGear(player, prices);
return;
}
for (KitType kitType : KitType.values())
{
if (kitType.equals(KitType.RING) || kitType.equals(KitType.AMMUNITION))
{
continue;
}
final int id = player.getPlayer().getPlayerAppearance().getEquipmentId(kitType);
if (id == -1)
{
continue;
}
if (kitType.equals(KitType.WEAPON))
{
player.setWeapon(id);
}
final ItemStats item = itemManager.getItemStats(id, false);
final ItemDefinition itemDefinition = itemManager.getItemDefinition(id);
if (item == null)
{
log.debug("Item is null: {}", id);
continue;
}
if (PvPValueBrokenItem.breaksOnDeath(id))
{
prices.put(id, itemManager.getBrokenValue(id));
log.debug("Item has a broken value: Id {}, Value {}", id, itemManager.getBrokenValue(id));
}
if (!itemDefinition.isTradeable() && !PvPValueBrokenItem.breaksOnDeath(id))
{
prices.put(id, itemDefinition.getPrice());
}
else if (itemDefinition.isTradeable())
{
prices.put(id, itemManager.getItemPrice(id, false));
}
}
updateGear(player, prices);
}
private void updateGear(PlayerContainer player, Map<Integer, Integer> prices)
@@ -462,7 +475,7 @@ public class PlayerScouter extends Plugin
}
ThumbnailEmbed image = ThumbnailEmbed.builder()
.url(ICONBASEURL + player.getWeapon() + ".png")
.url(ICON_URL + player.getWeapon() + ".png")
.build();
fieldList.add(FieldEmbed.builder()
@@ -510,14 +523,16 @@ public class PlayerScouter extends Plugin
.value("━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━")
.build());
final int[] items = {0};
int items = 0;
player.getRiskedGear().forEach((gear, value) ->
for (Map.Entry<Integer, Integer> entry : player.getRiskedGear().entrySet())
{
Integer gear = entry.getKey();
Integer value = entry.getValue();
if (value <= 0 || value <= this.minimumValue)
{
items[0]++;
return;
items++;
continue;
}
ItemStats item = itemManager.getItemStats(gear, false);
@@ -525,7 +540,7 @@ public class PlayerScouter extends Plugin
if (item == null)
{
log.error("Item is Null: {}", gear);
return;
continue;
}
fieldList.add(FieldEmbed.builder()
@@ -533,19 +548,19 @@ public class PlayerScouter extends Plugin
.value("Value: " + StackFormatter.quantityToRSDecimalStack(value))
.inline(true)
.build());
});
}
if (items[0] > 0)
if (items > 0)
{
fieldList.add(FieldEmbed.builder()
.name("Items below value: " + this.minimumValue)
.value(Integer.toString(items[0]))
.value(Integer.toString(items))
.inline(true)
.build());
}
}
String icon = ICONBASEURL + Objects.requireNonNull(getEntry(player.getGear())).getKey() + ".png";
String icon = ICON_URL + Objects.requireNonNull(getEntry(player.getGear())).getKey() + ".png";
String name = "☠️ " + player.getName() + " ☠️";
if (player.getPlayer().getSkullIcon() == null)
@@ -560,7 +575,7 @@ public class PlayerScouter extends Plugin
private void message(String name, String iconUrl, ThumbnailEmbed thumbnail, List<FieldEmbed> fields, String color)
{
log.debug("Message Contents: {}, {}, {}, {}, {}", name, " ", thumbnail, Arrays.toString(fields.toArray()), this.url);
log.debug("Message Contents: {}, {}, {}, {}, {}", name, " ", thumbnail, Arrays.toString(fields.toArray()), this.webhook);
log.debug("Fields: {}", fields);
if (name.isEmpty() || fields.isEmpty())
@@ -588,7 +603,7 @@ public class PlayerScouter extends Plugin
DiscordMessage discordMessage = new DiscordMessage("Gabon Scouter", " ", "https://i.imgur.com/2A6dr7q.png");
discordMessage.getEmbeds().add(discordEmbed);
DISCORD_CLIENT.message(this.url, discordMessage);
DISCORD_CLIENT.message(this.webhook, discordMessage);
fields.clear();
}

View File

@@ -34,7 +34,8 @@ public interface PlayerScouterConfig extends Config
keyName = "webhook",
name = "Webhook Url",
description = "Input the url for your webhook.",
position = 0
position = 0,
secret = true
)
default String webhook()
{
@@ -52,11 +53,33 @@ public interface PlayerScouterConfig extends Config
return true;
}
@ConfigItem(
keyName = "scoutClan",
name = "Scout Clan Members",
description = "Enable this to scout clan members.",
position = 2
)
default boolean scoutClan()
{
return true;
}
@ConfigItem(
keyName = "scoutFriends",
name = "Scout Friends",
description = "Enable this to scout friends.",
position = 3
)
default boolean scoutFriends()
{
return true;
}
@ConfigItem(
keyName = "outputItems",
name = "Output Items",
description = "This will output all of their risked gear to the webhook.",
position = 2
position = 4
)
default boolean outputItems()
{
@@ -67,7 +90,7 @@ public interface PlayerScouterConfig extends Config
keyName = "minimumRisk",
name = "Minimum Risk",
description = "Minimum risk for the player to be scouted.",
position = 3
position = 5
)
default int minimumRisk()
{
@@ -78,7 +101,7 @@ public interface PlayerScouterConfig extends Config
keyName = "minimumValue",
name = "Minimum Value",
description = "Minimum value for the item to be posted on discord.",
position = 4
position = 6
)
default int minimumValue()
{
@@ -89,7 +112,7 @@ public interface PlayerScouterConfig extends Config
keyName = "timeout",
name = "Timeout",
description = "Minimum amount of ticks before the player can be scouted again. (1 tick = 600ms)",
position = 5
position = 7
)
default int timeout()
{