|
|
|
|
@@ -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<Integer> 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<MenuEntry> 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();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|