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..e3cdc0cb21 --- /dev/null +++ b/runelite-client/src/main/java/net/runelite/client/plugins/bronzeman/BronzeManConfig.java @@ -0,0 +1,139 @@ +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 = "Game Mode Options", + description = "", + position = 1, + keyName = "gameModeOptions" + ) + default boolean gameModeOptions() + { + return false; + } + + @ConfigSection( + name = "Chat Commands", + description = "", + position = 2, + 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 = "restoreCommand", + name = "Enable restoreunlocks command", + description = "Enables the !restoreunlocks command used for restoring your unlocked items file.", + position = 3, + section = "chatCommands" + ) + default boolean restoreCommand() + { + return true; + } + + @ConfigItem( + keyName = "deleteCommand", + name = "Enable deleteunlocks command", + description = "Enables the !deleteunlocks command used for deleting your unlocked items file.", + position = 4, + section = "chatCommands" + ) + default boolean deleteCommand() + { + return false; + } + + @ConfigItem( + keyName = "hideTradeOption", + name = "Hide trade with option", + description = "Hides the trade with option from the player menu", + position = 0, + section = "gameModeOptions" + ) + default boolean hideTradeOption() + { + return true; + } +} 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..f5a3dcf07f 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,38 +1,53 @@ package net.runelite.client.plugins.bronzeman; +import com.google.inject.Provides; import java.awt.image.BufferedImage; import java.io.BufferedReader; import java.io.File; import java.io.FileReader; -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.util.ArrayList; 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; import net.runelite.client.ui.overlay.OverlayManager; +import net.runelite.client.util.ImageUtil; /** * @author Seth Davis @@ -50,31 +65,62 @@ 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"; + private static final String RESTORE_CHAT_COMMAND = "!restoreunlocks"; + + private final BufferedImage UNLOCK_IMAGE = ImageUtil.getResourceStreamFromClass(getClass(), "item_unlocked.png"); + + @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; + private boolean restoreCommand; + private boolean hideTradeOption; + /** * 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(); + /** + * Downloads the item-unlock png file to display unlocks + **/ + unlockImage = UNLOCK_IMAGE; + unlockedItems = new ArrayList<>(); overlayManager.add(bronzemanOverlay); + updateConfig(); + loadPlayerUnlocks(); } @Override @@ -84,6 +130,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 +203,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 +243,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 +264,7 @@ public class BronzemanPlugin extends Plugin { queueItemUnlock(ItemID.COINS_995); queueItemUnlock(ItemID.OLD_SCHOOL_BOND); + queueItemUnlock(ItemID.PLATINUM_TOKEN); } /** @@ -218,7 +290,7 @@ public class BronzemanPlugin extends Plugin } /** - * Loads a players unlcoks everytime they login + * Loads a players unlocks everytime they login **/ private void loadPlayerUnlocks() { @@ -253,25 +325,180 @@ public class BronzemanPlugin extends Plugin } } - /** - * Downloads the item-unlock png file to display unlocks - **/ - private void loadUnlockImage() + + @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(); + } + if (this.restoreCommand && chatMessage.getMessage().toLowerCase().equals(RESTORE_CHAT_COMMAND)) + { + restoreUnlocks(); + } + } + + 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 { - File imageFile = new File(RuneLite.RUNELITE_DIR, "item-unlocked.png"); - if (!imageFile.exists()) - { - InputStream in = new URL("https://i.imgur.com/KWVNlsq.png").openStream(); - Files.copy(in, Paths.get(imageFile.getPath())); - } - unlockImage = ImageIO.read(imageFile); + Files.copy(originalPath, Paths.get(playerFile.getPath().replace(".txt", ".backup")), + StandardCopyOption.REPLACE_EXISTING); } catch (Exception e) { e.printStackTrace(); + return; } + sendMessage("Successfully backed up current unlock file!"); } -} + private void restoreUnlocks() + { + File playerFolder = new File(RuneLite.PROFILES_DIR, client.getUsername()); + if (!playerFolder.exists()) + { + return; + } + File playerFile = new File(playerFolder, "bronzeman-unlocks.backup"); + if (!playerFile.exists()) + { + return; + } + + Path originalPath = playerFile.toPath(); + try + { + Files.copy(originalPath, Paths.get(playerFile.getPath().replace(".backup", ".txt")), + StandardCopyOption.REPLACE_EXISTING); + } + catch (Exception e) + { + e.printStackTrace(); + return; + } + sendMessage("Successfully restored 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") && this.hideTradeOption) + { + 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(); + this.restoreCommand = config.restoreCommand(); + this.hideTradeOption = config.hideTradeOption(); + } + +} \ 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); } diff --git a/runelite-client/src/main/resources/net/runelite/client/plugins/bronzeman/item_unlocked.png b/runelite-client/src/main/resources/net/runelite/client/plugins/bronzeman/item_unlocked.png new file mode 100644 index 0000000000..a29840aacf Binary files /dev/null and b/runelite-client/src/main/resources/net/runelite/client/plugins/bronzeman/item_unlocked.png differ