Merge pull request #259 from runelite/master

Pre-Patch day Pull
This commit is contained in:
Tyler Bochard
2019-05-16 00:59:02 -04:00
committed by GitHub
24 changed files with 483 additions and 136 deletions

View File

@@ -150,6 +150,8 @@ public class Notifier
{
flashStart = Instant.now();
}
log.debug(message);
}
public void processFlash(final Graphics2D graphics)

View File

@@ -140,6 +140,6 @@ public class WesternDiaryRequirement extends GenericDiaryRequirement
new QuestRequirement(Quest.BIG_CHOMPY_BIRD_HUNTING));
add("Pickpocket an Elf.",
new SkillRequirement(Skill.THIEVING, 85),
new QuestRequirement(Quest.MOURNINGS_ENDS_PART_II));
new QuestRequirement(Quest.MOURNINGS_ENDS_PART_I, true));
}
}

View File

@@ -27,6 +27,7 @@ package net.runelite.client.plugins.barrows;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.Sets;
import com.google.inject.Provides;
import java.time.temporal.ChronoUnit;
import java.util.HashSet;
import java.util.Set;
import javax.inject.Inject;
@@ -41,6 +42,7 @@ import net.runelite.api.Item;
import net.runelite.api.ItemContainer;
import net.runelite.api.NullObjectID;
import net.runelite.api.ObjectID;
import net.runelite.api.SpriteID;
import net.runelite.api.WallObject;
import net.runelite.api.events.ConfigChanged;
import net.runelite.api.events.GameObjectChanged;
@@ -66,6 +68,8 @@ import net.runelite.client.plugins.Plugin;
import net.runelite.client.plugins.PluginDescriptor;
import net.runelite.client.ui.overlay.OverlayManager;
import net.runelite.client.ui.overlay.infobox.InfoBoxManager;
import net.runelite.client.ui.overlay.infobox.InfoBoxPriority;
import net.runelite.client.ui.overlay.infobox.LoopTimer;
import net.runelite.client.util.StackFormatter;
@PluginDescriptor(
@@ -92,6 +96,7 @@ public class BarrowsPlugin extends Plugin
WidgetInfo.BARROWS_PUZZLE_ANSWER3
);
private static final long PRAYER_DRAIN_INTERVAL_MS = 18200;
private static final int CRYPT_REGION_ID = 14231;
@Getter(AccessLevel.PACKAGE)
@@ -100,6 +105,7 @@ public class BarrowsPlugin extends Plugin
@Getter(AccessLevel.PACKAGE)
private final Set<GameObject> ladders = new HashSet<>();
private LoopTimer barrowsPrayerDrainTimer;
private boolean wasInCrypt = false;
@Getter
@@ -313,13 +319,25 @@ public class BarrowsPlugin extends Plugin
{
if (config.showPrayerDrainTimer())
{
infoBoxManager.addInfoBox(new BarrowsPrayerDrainTimer(this, spriteManager));
final LoopTimer loopTimer = new LoopTimer(
PRAYER_DRAIN_INTERVAL_MS,
ChronoUnit.MILLIS,
spriteManager.getSprite(SpriteID.TAB_PRAYER, 0),
this,
true);
loopTimer.setPriority(InfoBoxPriority.MED);
loopTimer.setTooltip("Prayer Drain");
infoBoxManager.addInfoBox(loopTimer);
barrowsPrayerDrainTimer = loopTimer;
}
}
private void stopPrayerDrainTimer()
{
infoBoxManager.removeIf(BarrowsPrayerDrainTimer.class::isInstance);
infoBoxManager.removeInfoBox(barrowsPrayerDrainTimer);
barrowsPrayerDrainTimer = null;
}
private boolean isInCrypt()

View File

@@ -24,20 +24,9 @@
*/
package net.runelite.client.plugins.chatfilter;
import lombok.RequiredArgsConstructor;
@RequiredArgsConstructor
public enum ChatFilterType
{
CENSOR_WORDS("Censor words"),
CENSOR_MESSAGE("Censor message"),
REMOVE_MESSAGE("Remove message");
private final String name;
@Override
public String toString()
{
return name;
}
CENSOR_WORDS,
CENSOR_MESSAGE,
REMOVE_MESSAGE
}

View File

@@ -57,7 +57,7 @@ public class CipherClue extends ClueScroll implements TextClueScroll, NpcClueScr
new CipherClue("GBJSZ RVFFO", "Fairy Queen", new WorldPoint(2347, 4435, 0), "Fairy Resistance Hideout", "Puzzle"),
new CipherClue("QSPGFTTPS HSBDLMFCPOF", "Professor Gracklebone", new WorldPoint(1625, 3802, 0), "Ground floor of Arceuus Library", "9"),
new CipherClue("IWPPLQTP", "Gunnjorn", new WorldPoint(2541, 3548, 0), "Barbarian Outpost Agility course", "Puzzle"),
new CipherClue("BSOPME MZETQPS", "Arnold Lydspor", new WorldPoint(2329, 3689, 0), "Piscatorus Fishing Colony general store/bank", "Puzzle")
new CipherClue("BSOPME MZETQPS", "Arnold Lydspor", new WorldPoint(2329, 3689, 0), "Piscatoris Fishing Colony general store/bank", "Puzzle")
);
private String text;

View File

@@ -168,12 +168,18 @@ class CombatLevelOverlay extends Overlay
@VisibleForTesting
static int calcLevelsPray(double start, int end, int prayerLevel)
{
final int neededLevels = (int) Math.floor(calcMultipliedLevels(start, end, PRAY_MULT));
int neededLevels = (int) Math.ceil(calcMultipliedLevels(start, end, PRAY_MULT));
if (prayerLevel % 2 != 0)
{
neededLevels--;
}
if ((prayerLevel + neededLevels) % 2 != 0)
{
return neededLevels + 1;
}
return neededLevels;
}

View File

@@ -591,7 +591,7 @@ public class ConfigPanel extends PluginPanel
{
Enum selectedItem = Enum.valueOf(type, configManager.getConfiguration(cd.getGroup().value(), cid.getItem().keyName()));
box.setSelectedItem(selectedItem);
box.setToolTipText(selectedItem.toString());
box.setToolTipText(Text.titleCase(selectedItem));
}
catch (IllegalArgumentException ex)
{
@@ -602,7 +602,7 @@ public class ConfigPanel extends PluginPanel
if (e.getStateChange() == ItemEvent.SELECTED)
{
changeConfiguration(listItem, config, box, cd, cid);
box.setToolTipText(box.getSelectedItem().toString());
box.setToolTipText(Text.titleCase((Enum) box.getSelectedItem()));
}
});
item.add(box, BorderLayout.EAST);

View File

@@ -0,0 +1,114 @@
/*
* Copyright (c) 2019, Lotto <https://github.com/devLotto>
* 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.emojis;
import com.google.common.collect.ImmutableMap;
import java.awt.image.BufferedImage;
import java.util.Map;
import net.runelite.client.util.ImageUtil;
enum Emoji
{
SLIGHT_SMILE(":)"),
JOY("=')"),
COWBOY("3:)"),
BLUSH("^_^"),
SMILE(":D"),
GRINNING("=D"),
WINK(";)"),
STUCK_OUT_TONGUE_CLOSED_EYES("X-P"),
STUCK_OUT_TONGUE(":P"),
YUM("=P~"),
HUGGING("<gt>:D<lt>"), // >:D<
TRIUMPH(":<gt>"), // :>
THINKING(":-?"),
CONFUSED(":/"),
NEUTRAL_FACE("=|"),
EXPRESSIONLESS(":|"),
UNAMUSED(":-|"),
SLIGHT_FROWN(":("),
FROWNING2("=("),
CRY(":'("),
SOB(":_("),
FLUSHED(":$"),
ZIPPER_MOUTH(":-#"),
PERSEVERE("<gt>_<lt>"), // >_<
SUNGLASSES("8-)"),
INNOCENT("O:)"),
SMILING_IMP("<gt>:)"), // >:)
RAGE("<gt>:("), // >:(
HUSHED(":-O"),
OPEN_MOUTH(":O"),
SCREAM(":-@"),
SEE_NO_EVIL("X_X"),
DANCER("\\:D/"),
OK_HAND("(Ok)"),
THUMBSUP("(Y)"),
THUMBSDOWN("(N)"),
HEARTS("<lt>3"), // <3
BROKEN_HEART("<lt>/3"), // </3
ZZZ("Zzz"),
FISH("<lt><gt><lt>"), // <><
CAT(":3"),
DOG("=3"),
CRAB("V(;,;)V"),
FORK_AND_KNIFE("--E"),
COOKING("--(o)"),
PARTY_POPPER("@@@"),
EYES("O.O"),
SWEAT(";;"),
PILE_OF_POO("~@~");
private static final Map<String, Emoji> emojiMap;
private final String trigger;
static
{
ImmutableMap.Builder<String, Emoji> builder = new ImmutableMap.Builder<>();
for (final Emoji emoji : values())
{
builder.put(emoji.trigger, emoji);
}
emojiMap = builder.build();
}
Emoji(String trigger)
{
this.trigger = trigger;
}
BufferedImage loadImage()
{
return ImageUtil.getResourceStreamFromClass(getClass(), this.name().toLowerCase() + ".png");
}
static Emoji getEmoji(String trigger)
{
return emojiMap.get(trigger);
}
}

View File

@@ -0,0 +1,192 @@
/*
* Copyright (c) 2019, Lotto <https://github.com/devLotto>
* 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.emojis;
import java.awt.image.BufferedImage;
import java.util.Arrays;
import javax.annotation.Nullable;
import javax.inject.Inject;
import joptsimple.internal.Strings;
import lombok.extern.slf4j.Slf4j;
import net.runelite.api.Client;
import net.runelite.api.GameState;
import net.runelite.api.IndexedSprite;
import net.runelite.api.MessageNode;
import net.runelite.api.Player;
import net.runelite.api.events.ChatMessage;
import net.runelite.api.events.GameStateChanged;
import net.runelite.api.events.OverheadTextChanged;
import net.runelite.client.chat.ChatMessageManager;
import net.runelite.client.eventbus.Subscribe;
import net.runelite.client.plugins.Plugin;
import net.runelite.client.plugins.PluginDescriptor;
import net.runelite.client.util.ImageUtil;
@PluginDescriptor(
name = "Emojis",
description = "Replaces common emoticons such as :) with their corresponding emoji in the chat",
enabledByDefault = false
)
@Slf4j
public class EmojiPlugin extends Plugin
{
@Inject
private Client client;
@Inject
private ChatMessageManager chatMessageManager;
private int modIconsStart = -1;
@Override
protected void startUp()
{
loadEmojiIcons();
}
@Subscribe
public void onGameStateChanged(GameStateChanged gameStateChanged)
{
if (gameStateChanged.getGameState() == GameState.LOGGED_IN)
{
loadEmojiIcons();
}
}
private void loadEmojiIcons()
{
final IndexedSprite[] modIcons = client.getModIcons();
if (modIconsStart != -1 || modIcons == null)
{
return;
}
final Emoji[] emojis = Emoji.values();
final IndexedSprite[] newModIcons = Arrays.copyOf(modIcons, modIcons.length + emojis.length);
modIconsStart = modIcons.length;
for (int i = 0; i < emojis.length; i++)
{
final Emoji emoji = emojis[i];
try
{
final BufferedImage image = emoji.loadImage();
final IndexedSprite sprite = ImageUtil.getImageIndexedSprite(image, client);
newModIcons[modIconsStart + i] = sprite;
}
catch (Exception ex)
{
log.warn("Failed to load the sprite for emoji " + emoji, ex);
}
}
log.debug("Adding emoji icons");
client.setModIcons(newModIcons);
}
@Subscribe
public void onChatMessage(ChatMessage chatMessage)
{
if (client.getGameState() != GameState.LOGGED_IN || modIconsStart == -1)
{
return;
}
switch (chatMessage.getType())
{
case PUBLICCHAT:
case MODCHAT:
case FRIENDSCHAT:
case PRIVATECHAT:
case PRIVATECHATOUT:
break;
default:
return;
}
final String message = chatMessage.getMessage();
final String updatedMessage = updateMessage(message);
if (updatedMessage == null)
{
return;
}
final MessageNode messageNode = chatMessage.getMessageNode();
messageNode.setRuneLiteFormatMessage(updatedMessage);
chatMessageManager.update(messageNode);
client.refreshChat();
}
@Subscribe
public void onOverheadTextChanged(final OverheadTextChanged event)
{
if (!(event.getActor() instanceof Player))
{
return;
}
final String message = event.getOverheadText();
final String updatedMessage = updateMessage(message);
if (updatedMessage == null)
{
return;
}
event.getActor().setOverheadText(updatedMessage);
}
@Nullable
private String updateMessage(final String message)
{
final String[] messageWords = message.split(" ");
boolean editedMessage = false;
for (int i = 0; i < messageWords.length; i++)
{
final Emoji emoji = Emoji.getEmoji(messageWords[i]);
if (emoji == null)
{
continue;
}
final int emojiId = modIconsStart + emoji.ordinal();
messageWords[i] = "<img=" + emojiId + ">";
editedMessage = true;
}
// If we haven't edited the message any, don't update it.
if (!editedMessage)
{
return null;
}
return Strings.join(messageWords, " ");
}
}

View File

@@ -24,11 +24,6 @@
*/
package net.runelite.client.plugins.fps;
import lombok.Getter;
import lombok.RequiredArgsConstructor;
@Getter
@RequiredArgsConstructor
public enum FpsLimitMode
{
NEVER,

View File

@@ -24,21 +24,8 @@
*/
package net.runelite.client.plugins.itemidentification;
import lombok.Getter;
import lombok.RequiredArgsConstructor;
@Getter
@RequiredArgsConstructor
public enum ItemIdentificationMode
{
SHORT("Short"),
MEDIUM("Medium");
private final String type;
@Override
public String toString()
{
return type;
}
SHORT,
MEDIUM
}

View File

@@ -59,22 +59,22 @@ public class ItemStatChanges
add(food(3), SHRIMPS, COOKED_MEAT, COOKED_CHICKEN, ROE, CHOCOLATE_BAR);
add(food(4), SARDINE, CAKE, _23_CAKE, SLICE_OF_CAKE, CHOCOLATEY_MILK, BAKED_POTATO, EDIBLE_SEAWEED, MOONLIGHT_MEAD);
add(food(5), BREAD, HERRING, CHOCOLATE_CAKE, _23_CHOCOLATE_CAKE, CHOCOLATE_SLICE, COOKED_RABBIT, CHILLI_CON_CARNE,
FRIED_MUSHROOMS, FRIED_ONIONS, REDBERRY_PIE, HALF_A_REDBERRY_PIE, CAVIAR);
FRIED_MUSHROOMS, FRIED_ONIONS, REDBERRY_PIE, HALF_A_REDBERRY_PIE, CAVIAR, PYSK_FISH_0);
add(food(6), CHOCICE, MACKEREL, MEAT_PIE, HALF_A_MEAT_PIE, GUANIC_BAT_0, ROAST_BIRD_MEAT,
SQUARE_SANDWICH, ROLL, BAGUETTE, TRIANGLE_SANDWICH, GIANT_CARP);
add(food(7), TROUT, COD, PLAIN_PIZZA, _12_PLAIN_PIZZA, APPLE_PIE, HALF_AN_APPLE_PIE, ROAST_RABBIT,
PREMADE_CH_CRUNCH, CHOCCHIP_CRUNCHIES, PREMADE_SY_CRUNCH, SPICY_CRUNCHIES);
add(food(8), PIKE, ROAST_BEAST_MEAT, MEAT_PIZZA, _12_MEAT_PIZZA, PREMADE_WM_CRUN, WORM_CRUNCHIES, PREMADE_TD_CRUNCH,
TOAD_CRUNCHIES, EGG_AND_TOMATO, LECKISH_FISH_2, PRAEL_BAT_1, PEACH);
TOAD_CRUNCHIES, EGG_AND_TOMATO, PRAEL_BAT_1, PEACH, SUPHI_FISH_1);
add(food(9), PREMADE_P_PUNCH, PINEAPPLE_PUNCH, PREMADE_FR_BLAST, FRUIT_BLAST, SALMON, ANCHOVY_PIZZA,
_12_ANCHOVY_PIZZA);
add(food(10), TUNA, COOKED_CRAB_MEAT, CHOPPED_TUNA, COOKED_CHOMPY, FIELD_RATION);
add(food(11), RAINBOW_FISH, STEW, PINEAPPLE_PIZZA, _12_PINEAPPLE_PIZZA, COOKED_FISHCAKE,
PREMADE_VEG_BATTA, VEGETABLE_BATTA, PREMADE_WM_BATTA, WORM_BATTA, PREMADE_TD_BATTA, TOAD_BATTA, PREMADE_CT_BATTA,
CHEESETOM_BATTA, PREMADE_FRT_BATTA, FRUIT_BATTA, MUSHROOM__ONION, GIRAL_BAT_2, LAVA_EEL);
CHEESETOM_BATTA, PREMADE_FRT_BATTA, FRUIT_BATTA, MUSHROOM__ONION, GIRAL_BAT_2, LAVA_EEL, LECKISH_FISH_2);
add(food(12), LOBSTER, PREMADE_WORM_HOLE, WORM_HOLE, PREMADE_VEG_BALL, VEG_BALL);
add(food(13), BASS, TUNA_AND_CORN);
add(food(14), POTATO_WITH_BUTTER, CHILLI_POTATO, SWORDFISH, PHLUXIA_BAT_3, PUMPKIN, EASTER_EGG);
add(food(14), POTATO_WITH_BUTTER, CHILLI_POTATO, SWORDFISH, PHLUXIA_BAT_3, PUMPKIN, EASTER_EGG, BRAWK_FISH_3);
add(food(15), PREMADE_TTL, TANGLED_TOADS_LEGS, PREMADE_CHOC_BOMB, CHOCOLATE_BOMB, COOKED_JUBBLY);
add(food(16), MONKFISH, POTATO_WITH_CHEESE, EGG_POTATO);
add(food(17), MYCIL_FISH_4, KRYKET_BAT_4);

View File

@@ -26,23 +26,10 @@
package net.runelite.client.plugins.prayer;
import lombok.Getter;
import lombok.RequiredArgsConstructor;
@Getter
@RequiredArgsConstructor
public enum PrayerFlickLocation
{
NONE("Off"),
PRAYER_ORB("Prayer Orb"),
PRAYER_BAR("Prayer Bar"),
BOTH("Both");
private final String name;
@Override
public String toString()
{
return name;
}
NONE,
PRAYER_ORB,
PRAYER_BAR,
BOTH
}

View File

@@ -24,22 +24,9 @@
*/
package net.runelite.client.plugins.runepouch.config;
import lombok.Getter;
import lombok.RequiredArgsConstructor;
@Getter
@RequiredArgsConstructor
public enum RunePouchOverlayMode
{
INVENTORY("Inventory"),
MOUSE_HOVER("Mouse hover"),
BOTH("Both");
private final String name;
@Override
public String toString()
{
return name;
}
INVENTORY,
MOUSE_HOVER,
BOTH
}

View File

@@ -24,22 +24,9 @@
*/
package net.runelite.client.plugins.worldhopper;
import lombok.Getter;
import lombok.RequiredArgsConstructor;
@Getter
@RequiredArgsConstructor
public enum SubscriptionFilterMode
{
BOTH("Both"),
FREE("Free"),
MEMBERS("Member");
private final String name;
@Override
public String toString()
{
return name;
}
BOTH,
FREE,
MEMBERS
}

View File

@@ -110,12 +110,12 @@ class XpInfoBoxOverlay extends Overlay
rightNum = snapshot.getActionsRemainingToGoal();
break;
case XP_LEFT:
leftStr = config.onScreenDisplayMode().toString();
leftStr = "XP Left";
rightNum = snapshot.getXpRemainingToGoal();
break;
case XP_GAINED:
default:
leftStr = config.onScreenDisplayMode().toString();
leftStr = "XP Gained";
rightNum = snapshot.getXpGainedInSession();
break;
}

View File

@@ -35,18 +35,10 @@ public interface XpTrackerConfig extends Config
@AllArgsConstructor
enum OnScreenDisplayMode
{
XP_GAINED("XP Gained"),
XP_LEFT("XP Left"),
ACTIONS_DONE("Actions Done"),
ACTIONS_LEFT("Actions Left");
private final String name;
@Override
public String toString()
{
return name;
}
XP_GAINED,
XP_LEFT,
ACTIONS_DONE,
ACTIONS_LEFT
}
@ConfigItem(

View File

@@ -31,6 +31,7 @@ import javax.swing.JList;
import javax.swing.ListCellRenderer;
import javax.swing.border.EmptyBorder;
import net.runelite.client.ui.ColorScheme;
import net.runelite.client.util.Text;
/**
* A custom list renderer to avoid substance's weird coloring.
@@ -57,7 +58,16 @@ public final class ComboBoxListRenderer extends JLabel implements ListCellRender
setBorder(new EmptyBorder(5, 5, 5, 0));
String text = o.toString();
String text;
if (o instanceof Enum)
{
text = Text.titleCase((Enum) o);
}
else
{
text = o.toString();
}
setText(text);
return this;

View File

@@ -1,5 +1,5 @@
/*
* Copyright (c) 2019, Ryan <progrs.site@gmail.com>
* Copyright (c) 2019, Tomas Slusny <slusnucky@gmail.com>
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -22,45 +22,59 @@
* (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.barrows;
package net.runelite.client.ui.overlay.infobox;
import com.google.common.base.Preconditions;
import java.awt.Color;
import java.awt.image.BufferedImage;
import java.time.Duration;
import java.time.Instant;
import net.runelite.api.SpriteID;
import net.runelite.client.game.SpriteManager;
import net.runelite.client.ui.overlay.infobox.InfoBox;
import net.runelite.client.ui.overlay.infobox.InfoBoxPriority;
import java.time.temporal.ChronoUnit;
import lombok.Getter;
import lombok.ToString;
import net.runelite.client.plugins.Plugin;
class BarrowsPrayerDrainTimer extends InfoBox
@Getter
@ToString
public class LoopTimer extends InfoBox
{
private static final long PRAYER_DRAIN_INTERVAL_MS = 18200;
private final Instant startTime;
private final Duration duration;
private final boolean reverse;
BarrowsPrayerDrainTimer(BarrowsPlugin plugin, SpriteManager spriteManager)
public LoopTimer(long period, ChronoUnit unit, BufferedImage image, Plugin plugin, boolean reverse)
{
super(spriteManager.getSprite(SpriteID.TAB_PRAYER, 0), plugin);
setPriority(InfoBoxPriority.MED);
setTooltip("Prayer Drain");
super(image, plugin);
Preconditions.checkArgument(period > 0, "negative period!");
startTime = Instant.now();
duration = Duration.of(period, unit);
this.reverse = reverse;
}
public LoopTimer(long period, ChronoUnit unit, BufferedImage image, Plugin plugin)
{
this(period, unit, image, plugin, false);
}
@Override
public String getText()
{
Duration timeLeft = Duration.between(Instant.now(), getNextPrayerDrainTime());
int seconds = (int) (timeLeft.toMillis() / 1000L);
return String.format("0:%02d", seconds);
final Duration progress = getProgress();
final int seconds = (int) (progress.toMillis() / 1000L);
final int minutes = (seconds % 3600) / 60;
final int secs = seconds % 60;
return String.format("%d:%02d", minutes, secs);
}
@Override
public Color getTextColor()
{
Duration timeLeft = Duration.between(Instant.now(), getNextPrayerDrainTime());
final Duration progress = getProgress();
//check if timer has 10% of time left
if (timeLeft.getSeconds() < (PRAYER_DRAIN_INTERVAL_MS / 1000 * .10))
// check if timer has 10% of time left
if (progress.getSeconds() < (duration.getSeconds() * .10))
{
return Color.RED.brighter();
}
@@ -68,10 +82,15 @@ class BarrowsPrayerDrainTimer extends InfoBox
return Color.WHITE;
}
private Instant getNextPrayerDrainTime()
private Duration getProgress()
{
Duration timePassed = Duration.between(startTime, Instant.now());
// Get how many intervals have passed so far and add one more to find the next prayer drain time
return startTime.plusMillis((timePassed.toMillis() / PRAYER_DRAIN_INTERVAL_MS + 1) * PRAYER_DRAIN_INTERVAL_MS);
final Duration passed = Duration.between(startTime, Instant.now());
final long passedMillis = passed.toMillis();
final long durationMillis = duration.toMillis();
final long progress = passedMillis % durationMillis;
return Duration.ofMillis(reverse
? durationMillis - progress
: progress);
}
}
}

View File

@@ -31,6 +31,7 @@ import com.google.common.base.Splitter;
import java.util.Collection;
import java.util.List;
import java.util.regex.Pattern;
import org.apache.commons.text.WordUtils;
/**
* A set of utilities to use when dealing with text.
@@ -159,4 +160,28 @@ public class Text
String cleaned = name.contains("<img") ? name.substring(name.lastIndexOf('>') + 1) : name;
return cleaned.replace('\u00A0', ' ');
}
/**
* If passed in enum doesn't implement its own toString,
* converts enum name format from THIS_FORMAT to This Format.
*
* @param o an enum
* @return the enum's name in title case,
* or if it overrides toString,
* the value returned by toString
*/
public static String titleCase(Enum o)
{
String toString = o.toString();
// .toString() returns the value of .name() if not overridden
if (o.name().equals(toString))
{
return WordUtils
.capitalize(toString.toLowerCase(), '_')
.replace("_", " ");
}
return toString;
}
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 KiB

View File

@@ -270,10 +270,47 @@ public class CombatLevelPluginTest
when(client.getRealSkillLevel(Skill.MAGIC)).thenReturn(99);
when(client.getRealSkillLevel(Skill.HITPOINTS)).thenReturn(99);
assertEquals(1, neededPrayerLevels());
}
@Test
public void testEvenPrayerLevelsNeededWhenNearNextCombatLevel()
{
when(player.getCombatLevel()).thenReturn(90);
when(client.getRealSkillLevel(Skill.ATTACK)).thenReturn(74);
when(client.getRealSkillLevel(Skill.STRENGTH)).thenReturn(75);
when(client.getRealSkillLevel(Skill.DEFENCE)).thenReturn(72);
when(client.getRealSkillLevel(Skill.PRAYER)).thenReturn(52);
when(client.getRealSkillLevel(Skill.RANGED)).thenReturn(44);
when(client.getRealSkillLevel(Skill.MAGIC)).thenReturn(60);
when(client.getRealSkillLevel(Skill.HITPOINTS)).thenReturn(72);
assertEquals(2, neededPrayerLevels());
}
@Test
public void testOddPrayerLevelsNeededWhenNearNextCombatLevel()
{
when(player.getCombatLevel()).thenReturn(90);
when(client.getRealSkillLevel(Skill.ATTACK)).thenReturn(74);
when(client.getRealSkillLevel(Skill.STRENGTH)).thenReturn(75);
when(client.getRealSkillLevel(Skill.DEFENCE)).thenReturn(72);
when(client.getRealSkillLevel(Skill.PRAYER)).thenReturn(53);
when(client.getRealSkillLevel(Skill.RANGED)).thenReturn(44);
when(client.getRealSkillLevel(Skill.MAGIC)).thenReturn(60);
when(client.getRealSkillLevel(Skill.HITPOINTS)).thenReturn(72);
assertEquals(1, neededPrayerLevels());
}
private int neededPrayerLevels()
{
HashMap<String, Double> baseValues = getBaseValues();
// test prayer
assertEquals(1, calcLevelsPray(baseValues.get("base") + baseValues.get("max"),
player.getCombatLevel() + 1, client.getRealSkillLevel(Skill.PRAYER)));
return calcLevelsPray(
baseValues.get("base") + baseValues.get("max"),
player.getCombatLevel() + 1,
client.getRealSkillLevel(Skill.PRAYER)
);
}
}