Varp Fix
This commit is contained in:
@@ -33,6 +33,7 @@ import net.runelite.api.events.GameTick;
|
|||||||
import net.runelite.api.events.NpcDespawned;
|
import net.runelite.api.events.NpcDespawned;
|
||||||
import net.runelite.api.events.NpcSpawned;
|
import net.runelite.api.events.NpcSpawned;
|
||||||
import net.runelite.api.events.VarbitChanged;
|
import net.runelite.api.events.VarbitChanged;
|
||||||
|
import net.runelite.client.callback.ClientThread;
|
||||||
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.SkillIconManager;
|
import net.runelite.client.game.SkillIconManager;
|
||||||
@@ -87,6 +88,9 @@ public class GauntletPlugin extends Plugin {
|
|||||||
@Inject
|
@Inject
|
||||||
private Client client;
|
private Client client;
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
private ClientThread clientThread;
|
||||||
|
|
||||||
@Getter(AccessLevel.PUBLIC)
|
@Getter(AccessLevel.PUBLIC)
|
||||||
@Inject
|
@Inject
|
||||||
private OverlayManager overlayManager;
|
private OverlayManager overlayManager;
|
||||||
@@ -113,6 +117,8 @@ public class GauntletPlugin extends Plugin {
|
|||||||
public boolean tornadoesActive = false;
|
public boolean tornadoesActive = false;
|
||||||
public int tornadoTicks = GauntletUtils.TORNADO_TICKS;
|
public int tornadoTicks = GauntletUtils.TORNADO_TICKS;
|
||||||
|
|
||||||
|
public boolean completeStartup = false;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void startUp() {
|
protected void startUp() {
|
||||||
loadImages(config.iconSize());
|
loadImages(config.iconSize());
|
||||||
@@ -121,13 +127,25 @@ public class GauntletPlugin extends Plugin {
|
|||||||
|
|
||||||
timerVisible = config.displayTimerWidget();
|
timerVisible = config.displayTimerWidget();
|
||||||
timer.resetStates();
|
timer.resetStates();
|
||||||
timer.initStates();
|
|
||||||
|
|
||||||
if (timerVisible) {
|
if (timerVisible) {
|
||||||
overlayManager.add(timer);
|
overlayManager.add(timer);
|
||||||
}
|
}
|
||||||
|
|
||||||
overlayManager.add(overlay);
|
overlayManager.add(overlay);
|
||||||
|
|
||||||
|
// This section checks if the user is trying to start the timer while mid-raid.
|
||||||
|
// Varbits can only be checked on the client thread. Perform init check if nessessary.
|
||||||
|
if (client.getGameState() != GameState.STARTING && client.getGameState() != GameState.UNKNOWN) {
|
||||||
|
completeStartup = false;
|
||||||
|
clientThread.invoke(new Runnable() {
|
||||||
|
public void run() {
|
||||||
|
timer.initStates();
|
||||||
|
completeStartup = true;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
} else
|
||||||
|
completeStartup = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -179,7 +197,8 @@ public class GauntletPlugin extends Plugin {
|
|||||||
@Subscribe
|
@Subscribe
|
||||||
public void onVarbitChanged(VarbitChanged event) {
|
public void onVarbitChanged(VarbitChanged event) {
|
||||||
// This handles the timer based on varp states.
|
// This handles the timer based on varp states.
|
||||||
timer.checkStates(true);
|
if (this.completeStartup)
|
||||||
|
timer.checkStates(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Subscribe
|
@Subscribe
|
||||||
@@ -336,7 +355,8 @@ public class GauntletPlugin extends Plugin {
|
|||||||
@Subscribe
|
@Subscribe
|
||||||
public void onGameTick(GameTick event) {
|
public void onGameTick(GameTick event) {
|
||||||
// This handles the timer based on player health.
|
// This handles the timer based on player health.
|
||||||
timer.checkStates(false);
|
if (this.completeStartup)
|
||||||
|
timer.checkStates(false);
|
||||||
|
|
||||||
// This section handles the boss attack counter if they perform a projectile attack.
|
// This section handles the boss attack counter if they perform a projectile attack.
|
||||||
Set<Projectile> newProjectiles = new HashSet<>();
|
Set<Projectile> newProjectiles = new HashSet<>();
|
||||||
|
@@ -26,7 +26,6 @@ package net.runelite.client.plugins.gauntlet;
|
|||||||
|
|
||||||
import net.runelite.api.ChatMessageType;
|
import net.runelite.api.ChatMessageType;
|
||||||
import net.runelite.api.Client;
|
import net.runelite.api.Client;
|
||||||
import net.runelite.api.GameState;
|
|
||||||
import net.runelite.api.Player;
|
import net.runelite.api.Player;
|
||||||
import net.runelite.client.ui.overlay.Overlay;
|
import net.runelite.client.ui.overlay.Overlay;
|
||||||
import net.runelite.client.ui.overlay.OverlayMenuEntry;
|
import net.runelite.client.ui.overlay.OverlayMenuEntry;
|
||||||
@@ -79,16 +78,16 @@ class GauntletTimer extends Overlay {
|
|||||||
* Good luck to you. If you restart plugin mid raid, oh well. Your timer's going to be inaccurate.
|
* Good luck to you. If you restart plugin mid raid, oh well. Your timer's going to be inaccurate.
|
||||||
*/
|
*/
|
||||||
public void initStates() {
|
public void initStates() {
|
||||||
// timeRaidStart = -1L;
|
timeRaidStart = -1L;
|
||||||
// timeBossEnter = -1L;
|
timeBossEnter = -1L;
|
||||||
//
|
|
||||||
// if (GauntletUtils.inRaid(client)) {
|
if (GauntletUtils.inRaid(client)) {
|
||||||
// currentState = RaidState.IN_RAID;
|
currentState = RaidState.IN_RAID;
|
||||||
// if (GauntletUtils.inBoss(client)) {
|
if (GauntletUtils.inBoss(client)) {
|
||||||
// currentState = RaidState.IN_BOSS;
|
currentState = RaidState.IN_BOSS;
|
||||||
// }
|
}
|
||||||
// } else
|
} else
|
||||||
// currentState = RaidState.UNKNOWN;
|
currentState = RaidState.UNKNOWN;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -125,7 +124,7 @@ class GauntletTimer extends Overlay {
|
|||||||
public void checkStates(boolean checkVarps) {
|
public void checkStates(boolean checkVarps) {
|
||||||
final Player p = client.getLocalPlayer();
|
final Player p = client.getLocalPlayer();
|
||||||
|
|
||||||
if (p == null)
|
if (p == null || !plugin.completeStartup)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (checkVarps) {
|
if (checkVarps) {
|
||||||
@@ -201,7 +200,7 @@ class GauntletTimer extends Overlay {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Dimension render(Graphics2D graphics) {
|
public Dimension render(Graphics2D graphics) {
|
||||||
if (currentState == RaidState.UNKNOWN || timeRaidStart == -1L) {
|
if (currentState == RaidState.UNKNOWN) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -209,20 +208,24 @@ class GauntletTimer extends Overlay {
|
|||||||
|
|
||||||
panelComponent.getChildren().add(TitleComponent.builder().text("Gauntlet Timer").color(Color.WHITE).build());
|
panelComponent.getChildren().add(TitleComponent.builder().text("Gauntlet Timer").color(Color.WHITE).build());
|
||||||
|
|
||||||
String elapsedPrepTime, elapsedBossTime, elapsedTotalTime;
|
if(timeRaidStart == -1L) { // User restarted the plugin mid raid. Timer is inaccurate.
|
||||||
elapsedTotalTime = calculateElapsedTime(System.currentTimeMillis(), timeRaidStart);
|
panelComponent.getChildren().add(LineComponent.builder().left("Inactive").right("0:00").build());
|
||||||
|
|
||||||
if (currentState == RaidState.IN_RAID) {
|
|
||||||
elapsedPrepTime = calculateElapsedTime(timeRaidStart, System.currentTimeMillis());
|
|
||||||
elapsedBossTime = "0:00";
|
|
||||||
} else {
|
} else {
|
||||||
elapsedPrepTime = calculateElapsedTime(timeRaidStart, timeBossEnter);
|
String elapsedPrepTime, elapsedBossTime, elapsedTotalTime;
|
||||||
elapsedBossTime = calculateElapsedTime(System.currentTimeMillis(), timeBossEnter);
|
elapsedTotalTime = calculateElapsedTime(System.currentTimeMillis(), timeRaidStart);
|
||||||
}
|
|
||||||
|
|
||||||
panelComponent.getChildren().add(LineComponent.builder().left("Preparation").right(elapsedPrepTime).build());
|
if (currentState == RaidState.IN_RAID) {
|
||||||
panelComponent.getChildren().add(LineComponent.builder().left("Boss Fight").right(elapsedBossTime).build());
|
elapsedPrepTime = calculateElapsedTime(timeRaidStart, System.currentTimeMillis());
|
||||||
panelComponent.getChildren().add(LineComponent.builder().left("Total Time").right(elapsedTotalTime).build());
|
elapsedBossTime = "0:00";
|
||||||
|
} else {
|
||||||
|
elapsedPrepTime = calculateElapsedTime(timeRaidStart, timeBossEnter);
|
||||||
|
elapsedBossTime = calculateElapsedTime(System.currentTimeMillis(), timeBossEnter);
|
||||||
|
}
|
||||||
|
|
||||||
|
panelComponent.getChildren().add(LineComponent.builder().left("Preparation").right(elapsedPrepTime).build());
|
||||||
|
panelComponent.getChildren().add(LineComponent.builder().left("Boss Fight").right(elapsedBossTime).build());
|
||||||
|
panelComponent.getChildren().add(LineComponent.builder().left("Total Time").right(elapsedTotalTime).build());
|
||||||
|
}
|
||||||
|
|
||||||
return panelComponent.render(graphics);
|
return panelComponent.render(graphics);
|
||||||
}
|
}
|
||||||
|
@@ -141,7 +141,7 @@ public class GauntletUtils {
|
|||||||
public static boolean inRaid(Client client) {
|
public static boolean inRaid(Client client) {
|
||||||
try {
|
try {
|
||||||
return client.getVarbitValue(client.getVarps(), VARP_RAID_ROOM) == 1;
|
return client.getVarbitValue(client.getVarps(), VARP_RAID_ROOM) == 1;
|
||||||
} catch (IndexOutOfBoundsException ignore) {
|
} catch (IndexOutOfBoundsException | NullPointerException ignored) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -155,7 +155,7 @@ public class GauntletUtils {
|
|||||||
public static boolean inBoss(Client client) {
|
public static boolean inBoss(Client client) {
|
||||||
try {
|
try {
|
||||||
return client.getVarbitValue(client.getVarps(), VARP_BOSS_ROOM) == 1;
|
return client.getVarbitValue(client.getVarps(), VARP_BOSS_ROOM) == 1;
|
||||||
} catch (IndexOutOfBoundsException ignore) {
|
} catch (IndexOutOfBoundsException | NullPointerException ignored) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user