runelite-client: update bosstimer plugin to use infobox timers
@@ -25,18 +25,93 @@
|
||||
*/
|
||||
package net.runelite.client.plugins.bosstimer;
|
||||
|
||||
public class Boss
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.time.Duration;
|
||||
import java.time.temporal.ChronoUnit;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import javax.imageio.ImageIO;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
enum Boss
|
||||
{
|
||||
private String name;
|
||||
private int spawnTime;
|
||||
GENERAL_GRAARDOR("General Graardor", 90, ChronoUnit.SECONDS, "bando"),
|
||||
KRIL_TSUTSAROTH("K'ril Tsutsaroth", 90, ChronoUnit.SECONDS, "zammy"),
|
||||
KREEARRA("Kree'arra", 90, ChronoUnit.SECONDS, "arma"),
|
||||
COMMANDER_ZILYANA("Commander Zilyana", 90, ChronoUnit.SECONDS, "sara"),
|
||||
CALLISTO("Callisto", 30, ChronoUnit.SECONDS, "callisto"),
|
||||
CHAOS_FANATIC("Chaos fanatic", 30, ChronoUnit.SECONDS, "chaos_fanatic"),
|
||||
CRAZY_ARCHAEOLOGIST("Crazy archaeologist", 30, ChronoUnit.SECONDS, "crazy_arch"),
|
||||
KING_BLACK_DRAGON("King Black Dragon", 10, ChronoUnit.SECONDS, "kbd"),
|
||||
SCORPIA("Scorpia", 10, ChronoUnit.SECONDS, "scorpia"),
|
||||
VENENATIS("Venenatis", 30, ChronoUnit.SECONDS, "venenatis"),
|
||||
VETION("Vet'ion", 30, ChronoUnit.SECONDS, "vetion"),
|
||||
DAGANNOTH_PRIME("Dagannoth Prime", 90, ChronoUnit.SECONDS, "prime"),
|
||||
DAGANNOTH_REX("Dagannoth Rex", 90, ChronoUnit.SECONDS, "rex"),
|
||||
DAGANNOTH_SUPREME("Dagannoth Supreme", 90, ChronoUnit.SECONDS, "supreme"),
|
||||
CORPOREAL_BEAST("Corporeal Beast", 30, ChronoUnit.SECONDS, "corp"),
|
||||
GIANT_MOLE("Giant Mole", 10, ChronoUnit.SECONDS, "mole");
|
||||
|
||||
private static final Logger logger = LoggerFactory.getLogger(Boss.class);
|
||||
|
||||
private static final Map<String, Boss> bosses = new HashMap<>();
|
||||
|
||||
private final String name;
|
||||
private final Duration spawnTime;
|
||||
private final String imageResource;
|
||||
|
||||
private BufferedImage image;
|
||||
|
||||
static
|
||||
{
|
||||
for (Boss boss : values())
|
||||
{
|
||||
bosses.put(boss.getName(), boss);
|
||||
}
|
||||
}
|
||||
|
||||
private Boss(String name, long period, ChronoUnit unit, String imageResource)
|
||||
{
|
||||
this.name = name;
|
||||
this.spawnTime = Duration.of(period, unit);
|
||||
this.imageResource = imageResource;
|
||||
}
|
||||
|
||||
public String getName()
|
||||
{
|
||||
return name;
|
||||
}
|
||||
|
||||
public int getSpawnTime()
|
||||
public Duration getSpawnTime()
|
||||
{
|
||||
return spawnTime;
|
||||
}
|
||||
|
||||
public BufferedImage getImage()
|
||||
{
|
||||
if (image != null)
|
||||
{
|
||||
return image;
|
||||
}
|
||||
|
||||
InputStream in = Boss.class.getResourceAsStream(imageResource + ".png");
|
||||
try
|
||||
{
|
||||
image = ImageIO.read(in);
|
||||
}
|
||||
catch (IOException ex)
|
||||
{
|
||||
logger.warn("unable to load image", ex);
|
||||
}
|
||||
|
||||
return image;
|
||||
}
|
||||
|
||||
public static Boss find(String name)
|
||||
{
|
||||
return bosses.get(name);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -26,21 +26,11 @@
|
||||
package net.runelite.client.plugins.bosstimer;
|
||||
|
||||
import com.google.common.eventbus.Subscribe;
|
||||
import com.google.common.reflect.TypeToken;
|
||||
import com.google.gson.Gson;
|
||||
import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
import java.lang.reflect.Type;
|
||||
import java.time.Instant;
|
||||
import java.time.temporal.ChronoUnit;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import net.runelite.api.Actor;
|
||||
import net.runelite.client.RuneLite;
|
||||
import net.runelite.client.events.ActorDeath;
|
||||
import net.runelite.client.plugins.Plugin;
|
||||
import net.runelite.client.ui.overlay.Overlay;
|
||||
import net.runelite.client.ui.overlay.OverlayPosition;
|
||||
import net.runelite.client.ui.overlay.OverlayPriority;
|
||||
import net.runelite.client.ui.overlay.infobox.InfoBoxManager;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
@@ -48,10 +38,7 @@ public class BossTimers extends Plugin
|
||||
{
|
||||
private static final Logger logger = LoggerFactory.getLogger(BossTimers.class);
|
||||
|
||||
private final BossTimersOverlay overlay = new BossTimersOverlay(this, OverlayPosition.TOP_LEFT, OverlayPriority.LOW);
|
||||
|
||||
private final List<Boss> bosses = loadBossData();
|
||||
private final List<RespawnTimer> timers = new ArrayList<>();
|
||||
private final InfoBoxManager infoBoxManager = RuneLite.getRunelite().getInfoBoxManager();
|
||||
|
||||
@Override
|
||||
protected void startUp() throws Exception
|
||||
@@ -63,74 +50,23 @@ public class BossTimers extends Plugin
|
||||
{
|
||||
}
|
||||
|
||||
@Override
|
||||
public Overlay getOverlay()
|
||||
{
|
||||
return overlay;
|
||||
}
|
||||
|
||||
public List<RespawnTimer> getTimers()
|
||||
{
|
||||
return timers;
|
||||
}
|
||||
|
||||
@Subscribe
|
||||
public void onActorDeath(ActorDeath death)
|
||||
{
|
||||
Actor actor = death.getActor();
|
||||
|
||||
Boss boss = findBoss(actor.getName());
|
||||
Boss boss = Boss.find(actor.getName());
|
||||
if (boss == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (findTimerFor(actor.getName()) != null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
// remove existing timer
|
||||
infoBoxManager.removeIf(t -> t instanceof RespawnTimer && ((RespawnTimer) t).getBoss() == boss);
|
||||
|
||||
logger.debug("Creating spawn timer for {} ({} seconds)", actor.getName(), boss.getSpawnTime());
|
||||
|
||||
Instant respawnTime = Instant.now().plus(boss.getSpawnTime(), ChronoUnit.SECONDS);
|
||||
RespawnTimer respawnTimer = new RespawnTimer(boss, respawnTime);
|
||||
|
||||
timers.add(respawnTimer);
|
||||
RespawnTimer timer = new RespawnTimer(boss);
|
||||
infoBoxManager.addInfoBox(timer);
|
||||
}
|
||||
|
||||
public Boss findBoss(String name)
|
||||
{
|
||||
for (Boss boss : bosses)
|
||||
{
|
||||
if (boss.getName().equals(name))
|
||||
{
|
||||
return boss;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private RespawnTimer findTimerFor(String name)
|
||||
{
|
||||
for (RespawnTimer timer : timers)
|
||||
{
|
||||
if (timer.getBoss().getName().equals(name))
|
||||
{
|
||||
return timer;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private static List<Boss> loadBossData()
|
||||
{
|
||||
Gson gson = new Gson();
|
||||
Type type = new TypeToken<List<Boss>>()
|
||||
{
|
||||
}.getType();
|
||||
|
||||
InputStream in = BossTimers.class.getResourceAsStream("boss_timers.json");
|
||||
return gson.fromJson(new InputStreamReader(in), type);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,111 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2016-2017, Cameron Moberg <Moberg@tuta.io>
|
||||
* Copyright (c) 2017, Adam <Adam@sigterm.info>
|
||||
* 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.bosstimer;
|
||||
|
||||
import java.awt.Color;
|
||||
import java.awt.Dimension;
|
||||
import java.awt.FontMetrics;
|
||||
import java.awt.Graphics2D;
|
||||
import java.time.Duration;
|
||||
import java.time.Instant;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import net.runelite.api.GameState;
|
||||
import net.runelite.client.RuneLite;
|
||||
import net.runelite.client.ui.overlay.Overlay;
|
||||
import net.runelite.client.ui.overlay.OverlayPosition;
|
||||
import net.runelite.client.ui.overlay.OverlayPriority;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
public class BossTimersOverlay extends Overlay
|
||||
{
|
||||
private static final Logger logger = LoggerFactory.getLogger(BossTimersOverlay.class);
|
||||
|
||||
private static final int TOP_BORDER = 2;
|
||||
private static final int LEFT_BORDER = 2;
|
||||
private static final int RIGHT_BORDER = 2;
|
||||
private static final int WIDTH = 140;
|
||||
private static final int SEPARATOR = 2;
|
||||
|
||||
private static final Color BACKGROUND = new Color(Color.gray.getRed(), Color.gray.getGreen(), Color.gray.getBlue(), 127);
|
||||
|
||||
private final BossTimers bossTimers;
|
||||
|
||||
public BossTimersOverlay(BossTimers bossTimers, OverlayPosition position, OverlayPriority priority)
|
||||
{
|
||||
super(position, priority);
|
||||
this.bossTimers = bossTimers;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Dimension render(Graphics2D graphics)
|
||||
{
|
||||
if (RuneLite.getClient().getGameState() != GameState.LOGGED_IN)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
List<RespawnTimer> timers = bossTimers.getTimers();
|
||||
|
||||
if (timers.isEmpty())
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
FontMetrics metrics = graphics.getFontMetrics();
|
||||
|
||||
int height = TOP_BORDER + timers.size() * (SEPARATOR + metrics.getHeight()) + TOP_BORDER;
|
||||
graphics.setColor(BACKGROUND);
|
||||
graphics.fillRect(0, 0, WIDTH, height);
|
||||
|
||||
int y = TOP_BORDER;
|
||||
Instant now = Instant.now();
|
||||
|
||||
for (RespawnTimer respawnTimer : new ArrayList<>(timers))
|
||||
{
|
||||
if (respawnTimer.getRespawnTime().isBefore(now))
|
||||
{
|
||||
timers.remove(respawnTimer);
|
||||
continue;
|
||||
}
|
||||
|
||||
graphics.setColor(Color.white);
|
||||
|
||||
graphics.drawString(respawnTimer.getBoss().getName(), LEFT_BORDER, y + metrics.getHeight());
|
||||
|
||||
// calculate time left
|
||||
Duration timeLeft = Duration.between(Instant.now(), respawnTimer.getRespawnTime());
|
||||
|
||||
String secLeft = "" + timeLeft.getSeconds();
|
||||
graphics.drawString(secLeft, WIDTH - RIGHT_BORDER - metrics.stringWidth(secLeft), y + metrics.getHeight());
|
||||
|
||||
y += metrics.getHeight() + SEPARATOR;
|
||||
}
|
||||
|
||||
return new Dimension(WIDTH, height);
|
||||
}
|
||||
}
|
||||
@@ -24,26 +24,21 @@
|
||||
*/
|
||||
package net.runelite.client.plugins.bosstimer;
|
||||
|
||||
import java.time.Instant;
|
||||
import java.time.temporal.ChronoUnit;
|
||||
import net.runelite.client.ui.overlay.infobox.Timer;
|
||||
|
||||
public class RespawnTimer
|
||||
class RespawnTimer extends Timer
|
||||
{
|
||||
private final Boss boss;
|
||||
private final Instant respawnTime;
|
||||
|
||||
public RespawnTimer(Boss boss, Instant respawnTime)
|
||||
public RespawnTimer(Boss boss)
|
||||
{
|
||||
super(boss.getSpawnTime().toMillis(), ChronoUnit.MILLIS, boss.getImage());
|
||||
this.boss = boss;
|
||||
this.respawnTime = respawnTime;
|
||||
}
|
||||
|
||||
public Boss getBoss()
|
||||
{
|
||||
return boss;
|
||||
}
|
||||
|
||||
public Instant getRespawnTime()
|
||||
{
|
||||
return respawnTime;
|
||||
}
|
||||
}
|
||||
|
||||
|
After Width: | Height: | Size: 1.7 KiB |
|
After Width: | Height: | Size: 2.1 KiB |
@@ -1,49 +0,0 @@
|
||||
[{
|
||||
"name": "General Graardor",
|
||||
"spawnTime": 90
|
||||
}, {
|
||||
"name": "K'ril Tsutsaroth",
|
||||
"spawnTime": 90
|
||||
}, {
|
||||
"name": "Kree'arra",
|
||||
"spawnTime": 90
|
||||
}, {
|
||||
"name": "Commander Zilyana",
|
||||
"spawnTime": 90
|
||||
}, {
|
||||
"name": "Callisto",
|
||||
"spawnTime": 30
|
||||
}, {
|
||||
"name": "Chaos fanatic",
|
||||
"spawnTime": 30
|
||||
}, {
|
||||
"name": "Crazy archaeologist",
|
||||
"spawnTime": 30
|
||||
}, {
|
||||
"name": "King Black Dragon",
|
||||
"spawnTime": 10
|
||||
}, {
|
||||
"name": "Scorpia",
|
||||
"spawnTime": 10
|
||||
}, {
|
||||
"name": "Venenatis",
|
||||
"spawnTime": 30
|
||||
}, {
|
||||
"name": "Vet'ion",
|
||||
"spawnTime": 30
|
||||
}, {
|
||||
"name": "Dagannoth Prime",
|
||||
"spawnTime": 90
|
||||
}, {
|
||||
"name": "Dagannoth Rex",
|
||||
"spawnTime": 90
|
||||
}, {
|
||||
"name": "Dagannoth Supreme",
|
||||
"spawnTime": 90
|
||||
}, {
|
||||
"name": "Corporeal Beast",
|
||||
"spawnTime": 30
|
||||
}, {
|
||||
"name": "Giant Mole",
|
||||
"spawnTime": 10
|
||||
}]
|
||||
|
After Width: | Height: | Size: 1.6 KiB |
|
After Width: | Height: | Size: 1.5 KiB |
|
After Width: | Height: | Size: 2.5 KiB |
|
After Width: | Height: | Size: 1.1 KiB |
|
After Width: | Height: | Size: 1.8 KiB |
|
After Width: | Height: | Size: 1.5 KiB |
|
After Width: | Height: | Size: 1.4 KiB |
|
After Width: | Height: | Size: 1.9 KiB |
|
After Width: | Height: | Size: 1.6 KiB |
|
After Width: | Height: | Size: 1.6 KiB |
|
After Width: | Height: | Size: 1.5 KiB |
|
After Width: | Height: | Size: 1.4 KiB |
|
After Width: | Height: | Size: 2.1 KiB |
|
After Width: | Height: | Size: 2.3 KiB |