worldhopper: add free/member world filter option
Co-authored-by: DrRobosnarfen <wush14@gmail.com>
This commit is contained in:
@@ -0,0 +1,45 @@
|
||||
/*
|
||||
* Copyright (c) 2019, Shawn <http://github.com/DrRobosnarfen>
|
||||
* 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.worldhopper;
|
||||
|
||||
import lombok.Getter;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
|
||||
@Getter
|
||||
@RequiredArgsConstructor
|
||||
public enum SubscriptionFilterMode
|
||||
{
|
||||
BOTH("Both"),
|
||||
FREE("Free"),
|
||||
MEMBERS("Member");
|
||||
|
||||
private final String name;
|
||||
|
||||
@Override
|
||||
public String toString()
|
||||
{
|
||||
return name;
|
||||
}
|
||||
}
|
||||
@@ -101,4 +101,15 @@ public interface WorldHopperConfig extends Config
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
@ConfigItem(
|
||||
keyName = "subscriptionFilter",
|
||||
name = "Show subscription types",
|
||||
description = "Only show free worlds, member worlds, or both types of worlds in sidebar",
|
||||
position = 6
|
||||
)
|
||||
default SubscriptionFilterMode subscriptionFilter()
|
||||
{
|
||||
return SubscriptionFilterMode.BOTH;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -200,6 +200,7 @@ public class WorldHopperPlugin extends Plugin
|
||||
clientToolbar.addNavigation(navButton);
|
||||
}
|
||||
|
||||
panel.setFilterMode(config.subscriptionFilter());
|
||||
worldResultFuture = executorService.scheduleAtFixedRate(this::tick, 0, WORLD_FETCH_TIMER, TimeUnit.MINUTES);
|
||||
|
||||
hopperExecutorService = new ExecutorServiceExceptionLogger(Executors.newSingleThreadScheduledExecutor());
|
||||
@@ -253,6 +254,10 @@ public class WorldHopperPlugin extends Plugin
|
||||
SwingUtilities.invokeLater(() -> panel.hidePing());
|
||||
}
|
||||
break;
|
||||
case "subscriptionFilter":
|
||||
panel.setFilterMode(config.subscriptionFilter());
|
||||
updateList();
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -35,11 +35,14 @@ import java.util.List;
|
||||
import java.util.Map;
|
||||
import javax.swing.JPanel;
|
||||
import javax.swing.SwingUtilities;
|
||||
import lombok.AccessLevel;
|
||||
import lombok.Setter;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import net.runelite.client.ui.ColorScheme;
|
||||
import net.runelite.client.ui.DynamicGridLayout;
|
||||
import net.runelite.client.ui.PluginPanel;
|
||||
import net.runelite.http.api.worlds.World;
|
||||
import net.runelite.http.api.worlds.WorldType;
|
||||
|
||||
@Slf4j
|
||||
class WorldSwitcherPanel extends PluginPanel
|
||||
@@ -62,6 +65,8 @@ class WorldSwitcherPanel extends PluginPanel
|
||||
|
||||
private ArrayList<WorldTableRow> rows = new ArrayList<>();
|
||||
private WorldHopperPlugin plugin;
|
||||
@Setter(AccessLevel.PACKAGE)
|
||||
private SubscriptionFilterMode filterMode;
|
||||
|
||||
WorldSwitcherPanel(WorldHopperPlugin plugin)
|
||||
{
|
||||
@@ -219,6 +224,23 @@ class WorldSwitcherPanel extends PluginPanel
|
||||
for (int i = 0; i < worlds.size(); i++)
|
||||
{
|
||||
World world = worlds.get(i);
|
||||
|
||||
switch (filterMode)
|
||||
{
|
||||
case FREE:
|
||||
if (world.getTypes().contains(WorldType.MEMBERS))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
break;
|
||||
case MEMBERS:
|
||||
if (!world.getTypes().contains(WorldType.MEMBERS))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
rows.add(buildRow(world, i % 2 == 0, world.getId() == plugin.getCurrentWorld() && plugin.getLastWorld() != 0, plugin.isFavorite(world)));
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user