From dc7728f5ca54b3a96243999e0c311781f17f875e Mon Sep 17 00:00:00 2001 From: Justin Date: Thu, 2 Dec 2021 17:15:15 +1100 Subject: [PATCH] worldhopper: revert back to pre-upstream --- .../plugins/worldhopper/RegionFilterMode.java | 52 ++++------ .../worldhopper/WorldHopperConfig.java | 98 +++++++++---------- .../worldhopper/WorldHopperPlugin.java | 83 ++++++++-------- .../worldhopper/WorldSwitcherPanel.java | 29 +++--- 4 files changed, 121 insertions(+), 141 deletions(-) diff --git a/runelite-client/src/main/java/net/runelite/client/plugins/worldhopper/RegionFilterMode.java b/runelite-client/src/main/java/net/runelite/client/plugins/worldhopper/RegionFilterMode.java index 0b88556032..dccd9d499c 100644 --- a/runelite-client/src/main/java/net/runelite/client/plugins/worldhopper/RegionFilterMode.java +++ b/runelite-client/src/main/java/net/runelite/client/plugins/worldhopper/RegionFilterMode.java @@ -24,49 +24,35 @@ */ package net.runelite.client.plugins.worldhopper; +import lombok.AllArgsConstructor; import lombok.Getter; -import lombok.RequiredArgsConstructor; +import lombok.NoArgsConstructor; import net.runelite.http.api.worlds.WorldRegion; -@RequiredArgsConstructor -enum RegionFilterMode +@NoArgsConstructor +@AllArgsConstructor +public enum RegionFilterMode { + NONE, AUSTRALIA(WorldRegion.AUSTRALIA), GERMANY(WorldRegion.GERMANY), UNITED_KINGDOM(WorldRegion.UNITED_KINGDOM) - { - @Override - public String toString() { - return "U.K."; - } - }, + @Override + public String toString() + { + return "U.K."; + } + }, UNITED_STATES(WorldRegion.UNITED_STATES_OF_AMERICA) - { - @Override - public String toString() { - return "USA"; - } - }; + @Override + public String toString() + { + return "USA"; + } + }; @Getter - private final WorldRegion region; - - static RegionFilterMode of(WorldRegion region) - { - switch (region) - { - case UNITED_STATES_OF_AMERICA: - return UNITED_STATES; - case UNITED_KINGDOM: - return UNITED_KINGDOM; - case AUSTRALIA: - return AUSTRALIA; - case GERMANY: - return GERMANY; - default: - throw new IllegalStateException(); - } - } + private WorldRegion region; } diff --git a/runelite-client/src/main/java/net/runelite/client/plugins/worldhopper/WorldHopperConfig.java b/runelite-client/src/main/java/net/runelite/client/plugins/worldhopper/WorldHopperConfig.java index 8996dd12f4..11db14d55a 100644 --- a/runelite-client/src/main/java/net/runelite/client/plugins/worldhopper/WorldHopperConfig.java +++ b/runelite-client/src/main/java/net/runelite/client/plugins/worldhopper/WorldHopperConfig.java @@ -27,8 +27,6 @@ package net.runelite.client.plugins.worldhopper; import java.awt.event.InputEvent; import java.awt.event.KeyEvent; -import java.util.Collections; -import java.util.Set; import net.runelite.client.config.Config; import net.runelite.client.config.ConfigGroup; import net.runelite.client.config.ConfigItem; @@ -40,10 +38,10 @@ public interface WorldHopperConfig extends Config String GROUP = "worldhopper"; @ConfigItem( - keyName = "previousKey", - name = "Quick-hop previous", - description = "When you press this key you'll hop to the previous world", - position = 0 + keyName = "previousKey", + name = "Quick-hop previous", + description = "When you press this key you'll hop to the previous world", + position = 0 ) default Keybind previousKey() { @@ -51,10 +49,10 @@ public interface WorldHopperConfig extends Config } @ConfigItem( - keyName = "nextKey", - name = "Quick-hop next", - description = "When you press this key you'll hop to the next world", - position = 1 + keyName = "nextKey", + name = "Quick-hop next", + description = "When you press this key you'll hop to the next world", + position = 1 ) default Keybind nextKey() { @@ -62,10 +60,10 @@ public interface WorldHopperConfig extends Config } @ConfigItem( - keyName = "quickhopOutOfDanger", - name = "Quick-hop out of dangerous worlds", - description = "Don't hop to a PVP/high risk world when quick-hopping", - position = 2 + keyName = "quickhopOutOfDanger", + name = "Quick-hop out of dangerous worlds", + description = "Don't hop to a PVP/high risk world when quick-hopping", + position = 2 ) default boolean quickhopOutOfDanger() { @@ -73,21 +71,21 @@ public interface WorldHopperConfig extends Config } @ConfigItem( - keyName = "quickHopRegionFilter", - name = "Quick-hop region", - description = "Limit quick-hopping to worlds of a specific region", - position = 3 + keyName = "quickHopRegionFilter", + name = "Quick-hop region", + description = "Limit quick-hopping to worlds of a specific region", + position = 3 ) - default Set quickHopRegionFilter() + default RegionFilterMode quickHopRegionFilter() { - return Collections.emptySet(); + return RegionFilterMode.NONE; } @ConfigItem( - keyName = "showSidebar", - name = "Show world switcher sidebar", - description = "Show sidebar containing all worlds that mimics in-game interface", - position = 4 + keyName = "showSidebar", + name = "Show world switcher sidebar", + description = "Show sidebar containing all worlds that mimics in-game interface", + position = 4 ) default boolean showSidebar() { @@ -95,10 +93,10 @@ public interface WorldHopperConfig extends Config } @ConfigItem( - keyName = "ping", - name = "Show world ping", - description = "Shows ping to each game world", - position = 5 + keyName = "ping", + name = "Show world ping", + description = "Shows ping to each game world", + position = 5 ) default boolean ping() { @@ -106,10 +104,10 @@ public interface WorldHopperConfig extends Config } @ConfigItem( - keyName = "showMessage", - name = "Show world hop message in chat", - description = "Shows what world is being hopped to in the chat", - position = 6 + keyName = "showMessage", + name = "Show world hop message in chat", + description = "Shows what world is being hopped to in the chat", + position = 6 ) default boolean showWorldHopMessage() { @@ -117,10 +115,10 @@ public interface WorldHopperConfig extends Config } @ConfigItem( - keyName = "menuOption", - name = "Show Hop-to menu option", - description = "Adds Hop-to menu option to the friends list and friends chat members list", - position = 7 + keyName = "menuOption", + name = "Show Hop-to menu option", + description = "Adds Hop-to menu option to the friends list and friends chat members list", + position = 7 ) default boolean menuOption() { @@ -128,10 +126,10 @@ public interface WorldHopperConfig extends Config } @ConfigItem( - keyName = "subscriptionFilter", - name = "Show subscription types", - description = "Only show free worlds, member worlds, or both types of worlds in sidebar", - position = 8 + keyName = "subscriptionFilter", + name = "Show subscription types", + description = "Only show free worlds, member worlds, or both types of worlds in sidebar", + position = 8 ) default SubscriptionFilterMode subscriptionFilter() { @@ -139,21 +137,21 @@ public interface WorldHopperConfig extends Config } @ConfigItem( - keyName = "regionFilter", - name = "Filter worlds by region", - description = "Restrict sidebar worlds to one region", - position = 8 + keyName = "regionFilter", + name = "Filter worlds by region", + description = "Restrict sidebar worlds to one region", + position = 8 ) - default Set regionFilter() + default RegionFilterMode regionFilter() { - return Collections.emptySet(); + return RegionFilterMode.NONE; } @ConfigItem( - keyName = "displayPing", - name = "Display current ping", - description = "Displays ping to current game world", - position = 9 + keyName = "displayPing", + name = "Display current ping", + description = "Displays ping to current game world", + position = 9 ) default boolean displayPing() { diff --git a/runelite-client/src/main/java/net/runelite/client/plugins/worldhopper/WorldHopperPlugin.java b/runelite-client/src/main/java/net/runelite/client/plugins/worldhopper/WorldHopperPlugin.java index f0abbfb07b..dcb8d5e560 100644 --- a/runelite-client/src/main/java/net/runelite/client/plugins/worldhopper/WorldHopperPlugin.java +++ b/runelite-client/src/main/java/net/runelite/client/plugins/worldhopper/WorldHopperPlugin.java @@ -36,7 +36,6 @@ import java.util.EnumSet; import java.util.HashMap; import java.util.List; import java.util.Map; -import java.util.Set; import java.util.concurrent.Executors; import java.util.concurrent.ScheduledExecutorService; import java.util.concurrent.ScheduledFuture; @@ -95,9 +94,9 @@ import net.runelite.http.api.worlds.WorldType; import org.apache.commons.lang3.ArrayUtils; @PluginDescriptor( - name = "World Hopper", - description = "Allows you to quickly hop worlds", - tags = {"ping", "switcher"} + name = "World Hopper", + description = "Allows you to quickly hop worlds", + tags = {"ping", "switcher"} ) @Slf4j public class WorldHopperPlugin extends Plugin @@ -199,11 +198,11 @@ public class WorldHopperPlugin extends Plugin BufferedImage icon = ImageUtil.loadImageResource(WorldHopperPlugin.class, "icon.png"); navButton = NavigationButton.builder() - .tooltip("World Switcher") - .icon(icon) - .priority(3) - .panel(panel) - .build(); + .tooltip("World Switcher") + .icon(icon) + .priority(3) + .panel(panel) + .build(); if (config.showSidebar()) { @@ -361,7 +360,7 @@ public class WorldHopperPlugin extends Plugin String option = event.getOption(); if (groupId == WidgetInfo.FRIENDS_LIST.getGroupId() || groupId == WidgetInfo.FRIENDS_CHAT.getGroupId() - || componentId == WidgetInfo.CLAN_MEMBER_LIST.getId() || componentId == WidgetInfo.CLAN_GUEST_MEMBER_LIST.getId()) + || componentId == WidgetInfo.CLAN_MEMBER_LIST.getId() || componentId == WidgetInfo.CLAN_GUEST_MEMBER_LIST.getId()) { boolean after; @@ -383,7 +382,7 @@ public class WorldHopperPlugin extends Plugin WorldResult worldResult = worldService.getWorlds(); if (player == null || player.getWorld() == 0 || player.getWorld() == client.getWorld() - || worldResult == null) + || worldResult == null) { return; } @@ -391,7 +390,7 @@ public class WorldHopperPlugin extends Plugin World currentWorld = worldResult.findWorld(client.getWorld()); World targetWorld = worldResult.findWorld(player.getWorld()); if (targetWorld == null || currentWorld == null - || (!currentWorld.getTypes().contains(WorldType.PVP) && targetWorld.getTypes().contains(WorldType.PVP))) + || (!currentWorld.getTypes().contains(WorldType.PVP) && targetWorld.getTypes().contains(WorldType.PVP))) { // Disable Hop-to a PVP world from a regular world return; @@ -534,8 +533,6 @@ public class WorldHopperPlugin extends Plugin int worldIdx = worlds.indexOf(currentWorld); int totalLevel = client.getTotalLevel(); - final Set regionFilter = config.quickHopRegionFilter(); - World world; do { @@ -567,7 +564,7 @@ public class WorldHopperPlugin extends Plugin world = worlds.get(worldIdx); // Check world region if filter is enabled - if (!regionFilter.isEmpty() && !regionFilter.contains(RegionFilterMode.of(world.getRegion()))) + if (config.quickHopRegionFilter() != RegionFilterMode.NONE && world.getRegion() != config.quickHopRegionFilter().getRegion()) { continue; } @@ -612,14 +609,14 @@ public class WorldHopperPlugin extends Plugin if (world == currentWorld) { String chatMessage = new ChatMessageBuilder() - .append(ChatColorType.NORMAL) - .append("Couldn't find a world to quick-hop to.") - .build(); + .append(ChatColorType.NORMAL) + .append("Couldn't find a world to quick-hop to.") + .build(); chatMessageManager.queue(QueuedMessage.builder() - .type(ChatMessageType.CONSOLE) - .runeLiteFormattedMessage(chatMessage) - .build()); + .type(ChatMessageType.CONSOLE) + .runeLiteFormattedMessage(chatMessage) + .build()); } else { @@ -657,19 +654,19 @@ public class WorldHopperPlugin extends Plugin if (config.showWorldHopMessage()) { String chatMessage = new ChatMessageBuilder() - .append(ChatColorType.NORMAL) - .append("Quick-hopping to World ") - .append(ChatColorType.HIGHLIGHT) - .append(Integer.toString(world.getId())) - .append(ChatColorType.NORMAL) - .append("..") - .build(); + .append(ChatColorType.NORMAL) + .append("Quick-hopping to World ") + .append(ChatColorType.HIGHLIGHT) + .append(Integer.toString(world.getId())) + .append(ChatColorType.NORMAL) + .append("..") + .build(); chatMessageManager - .queue(QueuedMessage.builder() - .type(ChatMessageType.CONSOLE) - .runeLiteFormattedMessage(chatMessage) - .build()); + .queue(QueuedMessage.builder() + .type(ChatMessageType.CONSOLE) + .runeLiteFormattedMessage(chatMessage) + .build()); } quickHopTargetWorld = rsWorld; @@ -691,19 +688,19 @@ public class WorldHopperPlugin extends Plugin if (++displaySwitcherAttempts >= DISPLAY_SWITCHER_MAX_ATTEMPTS) { String chatMessage = new ChatMessageBuilder() - .append(ChatColorType.NORMAL) - .append("Failed to quick-hop after ") - .append(ChatColorType.HIGHLIGHT) - .append(Integer.toString(displaySwitcherAttempts)) - .append(ChatColorType.NORMAL) - .append(" attempts.") - .build(); + .append(ChatColorType.NORMAL) + .append("Failed to quick-hop after ") + .append(ChatColorType.HIGHLIGHT) + .append(Integer.toString(displaySwitcherAttempts)) + .append(ChatColorType.NORMAL) + .append(" attempts.") + .build(); chatMessageManager - .queue(QueuedMessage.builder() - .type(ChatMessageType.CONSOLE) - .runeLiteFormattedMessage(chatMessage) - .build()); + .queue(QueuedMessage.builder() + .type(ChatMessageType.CONSOLE) + .runeLiteFormattedMessage(chatMessage) + .build()); resetQuickHopper(); } diff --git a/runelite-client/src/main/java/net/runelite/client/plugins/worldhopper/WorldSwitcherPanel.java b/runelite-client/src/main/java/net/runelite/client/plugins/worldhopper/WorldSwitcherPanel.java index 2878a36ca3..e1e541d1bf 100644 --- a/runelite-client/src/main/java/net/runelite/client/plugins/worldhopper/WorldSwitcherPanel.java +++ b/runelite-client/src/main/java/net/runelite/client/plugins/worldhopper/WorldSwitcherPanel.java @@ -34,7 +34,6 @@ import java.awt.event.MouseEvent; import java.util.ArrayList; import java.util.List; import java.util.Map; -import java.util.Set; import java.util.function.Function; import javax.swing.JPanel; import javax.swing.SwingUtilities; @@ -69,7 +68,7 @@ class WorldSwitcherPanel extends PluginPanel @Setter(AccessLevel.PACKAGE) private SubscriptionFilterMode subscriptionFilterMode; @Setter(AccessLevel.PACKAGE) - private Set regionFilterMode; + private RegionFilterMode regionFilterMode; WorldSwitcherPanel(WorldHopperPlugin plugin) { @@ -250,7 +249,7 @@ class WorldSwitcherPanel extends PluginPanel break; } - if (!regionFilterMode.isEmpty() && !regionFilterMode.contains(RegionFilterMode.of(world.getRegion()))) + if (regionFilterMode.getRegion() != null && !regionFilterMode.getRegion().equals(world.getRegion())) { continue; } @@ -378,20 +377,20 @@ class WorldSwitcherPanel extends PluginPanel private WorldTableRow buildRow(World world, boolean stripe, boolean current, boolean favorite) { WorldTableRow row = new WorldTableRow(world, current, favorite, plugin.getStoredPing(world), - plugin::hopTo, - (world12, add) -> - { - if (add) + plugin::hopTo, + (world12, add) -> { - plugin.addToFavorites(world12); - } - else - { - plugin.removeFromFavorites(world12); - } + if (add) + { + plugin.addToFavorites(world12); + } + else + { + plugin.removeFromFavorites(world12); + } - updateList(); - } + updateList(); + } ); row.setBackground(stripe ? ODD_ROW : ColorScheme.DARK_GRAY_COLOR); return row;