cooking plugin: add wine ferment timer
This commit is contained in:
@@ -42,4 +42,15 @@ public interface CookingConfig extends Config
|
||||
{
|
||||
return 5;
|
||||
}
|
||||
|
||||
@ConfigItem(
|
||||
position = 2,
|
||||
keyName = "fermentTimer",
|
||||
name = "Show wine ferment timer",
|
||||
description = "Configures if the timer before wines are fermented is shown"
|
||||
)
|
||||
default boolean fermentTimer()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -28,19 +28,27 @@ package net.runelite.client.plugins.cooking;
|
||||
import com.google.inject.Provides;
|
||||
import java.time.Duration;
|
||||
import java.time.Instant;
|
||||
import java.util.Optional;
|
||||
import javax.inject.Inject;
|
||||
import lombok.AccessLevel;
|
||||
import lombok.Getter;
|
||||
import net.runelite.api.ChatMessageType;
|
||||
import net.runelite.api.Client;
|
||||
import net.runelite.api.GraphicID;
|
||||
import net.runelite.api.ItemID;
|
||||
import net.runelite.api.Player;
|
||||
import net.runelite.api.events.ChatMessage;
|
||||
import net.runelite.api.events.GameTick;
|
||||
import net.runelite.api.events.GraphicChanged;
|
||||
import net.runelite.client.config.ConfigManager;
|
||||
import net.runelite.client.eventbus.Subscribe;
|
||||
import net.runelite.client.game.ItemManager;
|
||||
import net.runelite.client.plugins.Plugin;
|
||||
import net.runelite.client.plugins.PluginDependency;
|
||||
import net.runelite.client.plugins.PluginDescriptor;
|
||||
import net.runelite.client.plugins.xptracker.XpTrackerPlugin;
|
||||
import net.runelite.client.ui.overlay.OverlayManager;
|
||||
import net.runelite.client.ui.overlay.infobox.InfoBoxManager;
|
||||
|
||||
@PluginDescriptor(
|
||||
name = "Cooking",
|
||||
@@ -50,6 +58,9 @@ import net.runelite.client.ui.overlay.OverlayManager;
|
||||
@PluginDependency(XpTrackerPlugin.class)
|
||||
public class CookingPlugin extends Plugin
|
||||
{
|
||||
@Inject
|
||||
private Client client;
|
||||
|
||||
@Inject
|
||||
private CookingConfig config;
|
||||
|
||||
@@ -59,6 +70,12 @@ public class CookingPlugin extends Plugin
|
||||
@Inject
|
||||
private OverlayManager overlayManager;
|
||||
|
||||
@Inject
|
||||
private InfoBoxManager infoBoxManager;
|
||||
|
||||
@Inject
|
||||
private ItemManager itemManager;
|
||||
|
||||
@Getter(AccessLevel.PACKAGE)
|
||||
private CookingSession session;
|
||||
|
||||
@@ -78,6 +95,7 @@ public class CookingPlugin extends Plugin
|
||||
@Override
|
||||
protected void shutDown() throws Exception
|
||||
{
|
||||
infoBoxManager.removeIf(FermentTimer.class::isInstance);
|
||||
overlayManager.remove(overlay);
|
||||
session = null;
|
||||
}
|
||||
@@ -99,6 +117,36 @@ public class CookingPlugin extends Plugin
|
||||
}
|
||||
}
|
||||
|
||||
@Subscribe
|
||||
public void onGraphicChanged(GraphicChanged graphicChanged)
|
||||
{
|
||||
Player player = client.getLocalPlayer();
|
||||
|
||||
if (graphicChanged.getActor() != player)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (player.getGraphic() == GraphicID.WINE_MAKE && config.fermentTimer())
|
||||
{
|
||||
Optional<FermentTimer> fermentTimerOpt = infoBoxManager.getInfoBoxes().stream()
|
||||
.filter(FermentTimer.class::isInstance)
|
||||
.map(FermentTimer.class::cast)
|
||||
.findAny();
|
||||
|
||||
if (fermentTimerOpt.isPresent())
|
||||
{
|
||||
FermentTimer fermentTimer = fermentTimerOpt.get();
|
||||
fermentTimer.reset();
|
||||
}
|
||||
else
|
||||
{
|
||||
FermentTimer fermentTimer = new FermentTimer(itemManager.getImage(ItemID.JUG_OF_WINE), this);
|
||||
infoBoxManager.addInfoBox(fermentTimer);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Subscribe
|
||||
public void onChatMessage(ChatMessage event)
|
||||
{
|
||||
@@ -113,8 +161,7 @@ public class CookingPlugin extends Plugin
|
||||
|| message.startsWith("You successfully bake")
|
||||
|| message.startsWith("You manage to cook")
|
||||
|| message.startsWith("You roast a")
|
||||
|| message.startsWith("You cook")
|
||||
|| message.startsWith("You squeeze the grapes into the jug"))
|
||||
|| message.startsWith("You cook"))
|
||||
{
|
||||
if (session == null)
|
||||
{
|
||||
|
||||
@@ -0,0 +1,76 @@
|
||||
/*
|
||||
* Copyright (c) 2019, 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.cooking;
|
||||
|
||||
import java.awt.Color;
|
||||
import java.awt.Image;
|
||||
import java.time.Duration;
|
||||
import java.time.Instant;
|
||||
import net.runelite.client.plugins.Plugin;
|
||||
import net.runelite.client.ui.overlay.infobox.InfoBox;
|
||||
|
||||
final class FermentTimer extends InfoBox
|
||||
{
|
||||
private static final Duration FERMENT_TIME = Duration.ofMillis(13_800);
|
||||
|
||||
private Instant fermentTime;
|
||||
|
||||
FermentTimer(Image image, Plugin plugin)
|
||||
{
|
||||
super(image, plugin);
|
||||
reset();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getText()
|
||||
{
|
||||
int seconds = timeUntilFerment();
|
||||
return Integer.toString(seconds);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Color getTextColor()
|
||||
{
|
||||
int seconds = timeUntilFerment();
|
||||
return seconds <= 3 ? Color.RED : Color.WHITE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean cull()
|
||||
{
|
||||
int seconds = timeUntilFerment();
|
||||
return seconds <= 0;
|
||||
}
|
||||
|
||||
void reset()
|
||||
{
|
||||
fermentTime = Instant.now().plus(FERMENT_TIME);
|
||||
}
|
||||
|
||||
private int timeUntilFerment()
|
||||
{
|
||||
return (int) Duration.between(Instant.now(), fermentTime).getSeconds();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user