diff --git a/runelite-client/src/main/java/net/runelite/client/plugins/bronzeman/BronzeManConfig.java b/runelite-client/src/main/java/net/runelite/client/plugins/bronzeman/BronzeManConfig.java new file mode 100644 index 0000000000..adb57cc0c6 --- /dev/null +++ b/runelite-client/src/main/java/net/runelite/client/plugins/bronzeman/BronzeManConfig.java @@ -0,0 +1,104 @@ +package net.runelite.client.plugins.bronzeman; + +import net.runelite.client.config.Config; +import net.runelite.client.config.ConfigGroup; +import net.runelite.client.config.ConfigItem; +import net.runelite.client.config.ConfigSection; + +@ConfigGroup("bronzemanmode") +public interface BronzeManConfig extends Config +{ + @ConfigSection( + name = "Unlocked Notifications", + description = "", + position = 0, + keyName = "unlockNotifications" + ) + default boolean unlockNotifications() + { + return false; + } + + @ConfigSection( + name = "Chat Commands", + description = "", + position = 1, + keyName = "chatCommands" + ) + default boolean chatCommands() + { + return false; + } + + @ConfigItem( + keyName = "notifyImgUnlock", + name = "image unlocked notification", + description = "Configure whether to send the notification image when you unlock a new item.", + position = 0, + section = "unlockNotifications" + ) + default boolean notifyImgUnlock() + { + return true; + } + + @ConfigItem( + keyName = "notifyChatUnlock", + name = "Chat unlocked notification", + description = "Configure whether to send the chat notification when you unlock a new item.", + position = 1, + section = "unlockNotifications" + ) + default boolean notifyChatUnlock() + { + return true; + } + + @ConfigItem( + keyName = "resetCommand", + name = "Enable resetunlocks command", + description = "Enables the !resetunlocks command used for wiping your unlocked items.", + position = 0, + section = "chatCommands" + ) + default boolean resetCommand() + { + return false; + } + + @ConfigItem( + keyName = "countCommand", + name = "Enable countunlocks command", + description = "Enables the !countunlocks command used for counting your unlocked items.", + position = 1, + section = "chatCommands" + ) + default boolean countCommand() + { + return true; + } + + @ConfigItem( + keyName = "backupCommand", + name = "Enable backupunlocks command", + description = "Enables the !backupunlocks command used for backing up your unlocked items.", + position = 2, + section = "chatCommands" + ) + default boolean backupCommand() + { + return true; + } + + @ConfigItem( + keyName = "deleteCommand", + name = "Enable deleteunlocks command", + description = "Enables the !deleteunlocks command used for deleting your unlocked items file.", + position = 2, + section = "chatCommands" + ) + default boolean deleteCommand() + { + return false; + } +} diff --git a/runelite-client/src/main/java/net/runelite/client/plugins/bronzeman/BronzeManOverlay.java b/runelite-client/src/main/java/net/runelite/client/plugins/bronzeman/BronzeManOverlay.java index 3480fe881f..6824f1a92d 100644 --- a/runelite-client/src/main/java/net/runelite/client/plugins/bronzeman/BronzeManOverlay.java +++ b/runelite-client/src/main/java/net/runelite/client/plugins/bronzeman/BronzeManOverlay.java @@ -73,7 +73,7 @@ public class BronzeManOverlay extends Overlay { currentUnlock.setLocationY(drawY + 1); } - if (currentUnlock.displayed()) + if (currentUnlock.displayed(itemUnlockList.size())) { itemUnlockList.remove(currentUnlock); currentUnlock = null; diff --git a/runelite-client/src/main/java/net/runelite/client/plugins/bronzeman/BronzemanPlugin.java b/runelite-client/src/main/java/net/runelite/client/plugins/bronzeman/BronzemanPlugin.java index 2c32a0d697..582258012c 100644 --- a/runelite-client/src/main/java/net/runelite/client/plugins/bronzeman/BronzemanPlugin.java +++ b/runelite-client/src/main/java/net/runelite/client/plugins/bronzeman/BronzemanPlugin.java @@ -1,5 +1,6 @@ package net.runelite.client.plugins.bronzeman; +import com.google.inject.Provides; import java.awt.image.BufferedImage; import java.io.BufferedReader; import java.io.File; @@ -8,27 +9,45 @@ import java.io.InputStream; import java.io.PrintWriter; import java.net.URL; import java.nio.file.Files; +import java.nio.file.Path; import java.nio.file.Paths; +import java.nio.file.StandardCopyOption; +import java.text.SimpleDateFormat; import java.util.ArrayList; +import java.util.Calendar; import java.util.List; import javax.imageio.ImageIO; import javax.inject.Inject; import lombok.AccessLevel; import lombok.Getter; import lombok.extern.slf4j.Slf4j; +import net.runelite.api.ChatMessageType; import net.runelite.api.Client; import net.runelite.api.GameState; import net.runelite.api.Item; import net.runelite.api.ItemID; +import net.runelite.api.MenuEntry; +import net.runelite.api.Player; +import net.runelite.api.events.ChatMessage; +import net.runelite.api.events.ClientTick; import net.runelite.api.events.GameStateChanged; -import net.runelite.api.events.GameTick; import net.runelite.api.events.ItemContainerChanged; +import net.runelite.api.events.MenuOpened; import net.runelite.api.events.WidgetLoaded; +import net.runelite.api.util.Text; +import static net.runelite.api.util.Text.sanitize; import net.runelite.api.widgets.Widget; import net.runelite.api.widgets.WidgetID; import net.runelite.api.widgets.WidgetInfo; import net.runelite.client.RuneLite; +import net.runelite.client.chat.ChatColorType; +import net.runelite.client.chat.ChatMessageBuilder; +import net.runelite.client.chat.ChatMessageManager; +import net.runelite.client.chat.QueuedMessage; +import net.runelite.client.config.ConfigManager; import net.runelite.client.eventbus.Subscribe; +import net.runelite.client.events.ConfigChanged; +import net.runelite.client.game.ItemManager; import net.runelite.client.plugins.Plugin; import net.runelite.client.plugins.PluginDescriptor; import net.runelite.client.plugins.PluginType; @@ -50,31 +69,53 @@ import net.runelite.client.ui.overlay.OverlayManager; public class BronzemanPlugin extends Plugin { + private static final String BACKUP_CHAT_COMMAND = "!backupunlocks"; + private static final String COUNT_CHAT_COMMAND = "!countunlocks"; + private static final String DELETE_CHAT_COMMAND = "!deleteunlocks"; + private static final String RESET_CHAT_COMMAND = "!resetunlocks"; + + @Inject + ItemManager itemManager; @Inject private Client client; - @Inject private OverlayManager overlayManager; - + @Inject + private BronzeManConfig config; + @Inject + private ChatMessageManager chatMessageManager; @Inject private BronzeManOverlay bronzemanOverlay; - private List unlockedItems; - @Getter(AccessLevel.PACKAGE) private BufferedImage unlockImage = null; + private boolean notifyImgUnlock; + private boolean notifyChatUnlock; + private boolean resetCommand; + private boolean countCommand; + private boolean backupCommand; + private boolean deleteCommand; + /** * Loads GrandExchange widgets for further manipulation of the interface **/ private Widget grandExchangeWindow; private Widget grandExchangeChatBox; + @Provides + BronzeManConfig getConfig(ConfigManager configManager) + { + return configManager.getConfig(BronzeManConfig.class); + } + @Override protected void startUp() { loadUnlockImage(); unlockedItems = new ArrayList<>(); overlayManager.add(bronzemanOverlay); + updateConfig(); + loadPlayerUnlocks(); } @Override @@ -84,6 +125,21 @@ public class BronzemanPlugin extends Plugin overlayManager.remove(bronzemanOverlay); } + @Subscribe + private void onConfigChanged(ConfigChanged event) + { + if (!event.getKey().equals("notifyImgUnlock")) + { + overlayManager.remove(bronzemanOverlay); + } + if (!event.getGroup().equals("bronzemanmode")) + { + return; + } + + updateConfig(); + } + /** * Loads players unlocks on login **/ @@ -142,7 +198,7 @@ public class BronzemanPlugin extends Plugin * Handles greying out items in the GrandExchange **/ @Subscribe - public void onGameTick(GameTick e) + public void onClientTick(ClientTick e) { if (grandExchangeWindow == null || grandExchangeChatBox == null || grandExchangeWindow.isHidden()) { @@ -182,8 +238,18 @@ public class BronzemanPlugin extends Plugin private void queueItemUnlock(int itemId) { unlockedItems.add(itemId); - bronzemanOverlay.addItemUnlock(itemId); savePlayerUnlocks();// Save after every item to fail-safe logging out + if (this.notifyChatUnlock) + { + sendMessage("You have successfully unlocked item: " + itemManager.getItemDefinition(itemId).getName()); + } + + if (!this.notifyImgUnlock) + { + return; + } + bronzemanOverlay.addItemUnlock(itemId); + } /** @@ -193,6 +259,7 @@ public class BronzemanPlugin extends Plugin { queueItemUnlock(ItemID.COINS_995); queueItemUnlock(ItemID.OLD_SCHOOL_BOND); + queueItemUnlock(ItemID.PLATINUM_TOKEN); } /** @@ -218,7 +285,7 @@ public class BronzemanPlugin extends Plugin } /** - * Loads a players unlcoks everytime they login + * Loads a players unlocks everytime they login **/ private void loadPlayerUnlocks() { @@ -274,4 +341,148 @@ public class BronzemanPlugin extends Plugin } } -} + @Subscribe + public void onChatMessage(ChatMessage chatMessage) + { + final String playerName; + + if (chatMessage.equals(ChatMessageType.PRIVATECHATOUT)) + { + playerName = client.getLocalPlayer().getName(); + } + else + { + playerName = sanitize(chatMessage.getName()); + } + if (this.countCommand && chatMessage.getMessage().toLowerCase().equals(COUNT_CHAT_COMMAND)) + { + sendMessage("You have successfully unlocked " + unlockedItems.size() + " items."); + } + if (this.resetCommand && chatMessage.getMessage().toLowerCase().equals(RESET_CHAT_COMMAND)) + { + resetUnlocks(); + } + if (this.backupCommand && chatMessage.getMessage().toLowerCase().equals(BACKUP_CHAT_COMMAND)) + { + backupUnlocks(); + } + if (this.deleteCommand && chatMessage.getMessage().toLowerCase().equals(DELETE_CHAT_COMMAND)) + { + deleteUnlocks(); + } + } + + private void backupUnlocks() + { + File playerFolder = new File(RuneLite.PROFILES_DIR, client.getUsername()); + if (!playerFolder.exists()) + { + return; + } + File playerFile = new File(playerFolder, "bronzeman-unlocks.txt"); + if (!playerFile.exists()) + { + return; + } + + Path originalPath = playerFile.toPath(); + try + { + Calendar cal = Calendar.getInstance(); + SimpleDateFormat sdf = new SimpleDateFormat("MM_WW_HH_mm_ss"); + Files.copy(originalPath, Paths.get(playerFolder.getPath() + "_" + sdf.format(cal.getTime()) + ".backup"), + StandardCopyOption.REPLACE_EXISTING); + } + catch (Exception e) + { + e.printStackTrace(); + return; + } + sendMessage("Successfully backed up current unlock file!"); + } + + private void resetUnlocks() + { + try + { + File playerFolder = new File(RuneLite.PROFILES_DIR, client.getUsername()); + File playerFile = new File(playerFolder, "bronzeman-unlocks.txt"); + playerFile.delete(); + unlockedItems.clear(); + savePlayerUnlocks(); + unlockDefaultItems(); + } + catch (Exception e) + { + e.printStackTrace(); + return; + } + sendMessage("Current Unlock file succesfully reset!"); + } + + private void deleteUnlocks() + { + backupUnlocks(); + try + { + File playerFolder = new File(RuneLite.PROFILES_DIR, client.getUsername()); + File playerFile = new File(playerFolder, "bronzeman-unlocks.txt"); + playerFile.delete(); + } + catch (Exception e) + { + e.printStackTrace(); + return; + } + sendMessage("Current Unlock file succesfully deleted!"); + } + + @Subscribe + private void onMenuOpened(MenuOpened event) + { + Player localPlayer = client.getLocalPlayer(); + + if (localPlayer == null) + { + return; + } + + List menu_entries = new ArrayList<>(); + + for (MenuEntry entry : event.getMenuEntries()) + { + String option = Text.removeTags(entry.getOption()).toLowerCase(); + + if (option.contains("trade with")) + { + continue; + } + menu_entries.add(entry); + } + event.setMenuEntries(menu_entries.toArray(new MenuEntry[0])); + event.setModified(); + } + + private void sendMessage(String text) + { + final ChatMessageBuilder message = new ChatMessageBuilder() + .append(ChatColorType.HIGHLIGHT) + .append(text); + + chatMessageManager.queue(QueuedMessage.builder() + .type(ChatMessageType.CONSOLE) + .runeLiteFormattedMessage(message.build()) + .build()); + } + + private void updateConfig() + { + this.notifyImgUnlock = config.notifyImgUnlock(); + this.resetCommand = config.resetCommand(); + this.countCommand = config.countCommand(); + this.backupCommand = config.backupCommand(); + this.notifyChatUnlock = config.notifyChatUnlock(); + this.deleteCommand = config.deleteCommand(); + } + +} \ No newline at end of file diff --git a/runelite-client/src/main/java/net/runelite/client/plugins/bronzeman/ItemUnlock.java b/runelite-client/src/main/java/net/runelite/client/plugins/bronzeman/ItemUnlock.java index 55f02ef83f..2e2094f50a 100644 --- a/runelite-client/src/main/java/net/runelite/client/plugins/bronzeman/ItemUnlock.java +++ b/runelite-client/src/main/java/net/runelite/client/plugins/bronzeman/ItemUnlock.java @@ -40,8 +40,12 @@ public class ItemUnlock /** * Returns whether or not an items has been displayed as unlocked yet **/ - public boolean displayed() + public boolean displayed(int queue) { + if (queue >= 2) + { + return System.currentTimeMillis() > initTime + (750); + } return System.currentTimeMillis() > initTime + (5000); }