Merge pull request #10534 from Trevor159/world-ping-fix

world hopper plugin: make world pings persist across world fetches
This commit is contained in:
Adam
2020-01-11 21:46:18 -05:00
committed by GitHub
3 changed files with 31 additions and 7 deletions

View File

@@ -160,6 +160,8 @@ public class WorldHopperPlugin extends Plugin
@Getter(AccessLevel.PACKAGE) @Getter(AccessLevel.PACKAGE)
private int currentPing; private int currentPing;
private final Map<Integer, Integer> storedPings = new HashMap<>();
private final HotkeyListener previousKeyListener = new HotkeyListener(() -> config.previousKey()) private final HotkeyListener previousKeyListener = new HotkeyListener(() -> config.previousKey())
{ {
@Override @Override
@@ -754,7 +756,7 @@ public class WorldHopperPlugin extends Plugin
for (World world : worldResult.getWorlds()) for (World world : worldResult.getWorlds())
{ {
int ping = Ping.ping(world); int ping = ping(world);
SwingUtilities.invokeLater(() -> panel.updatePing(world.getId(), ping)); SwingUtilities.invokeLater(() -> panel.updatePing(world.getId(), ping));
} }
@@ -795,7 +797,7 @@ public class WorldHopperPlugin extends Plugin
return; return;
} }
int ping = Ping.ping(world); int ping = ping(world);
log.trace("Ping for world {} is: {}", world.getId(), ping); log.trace("Ping for world {} is: {}", world.getId(), ping);
SwingUtilities.invokeLater(() -> panel.updatePing(world.getId(), ping)); SwingUtilities.invokeLater(() -> panel.updatePing(world.getId(), ping));
} }
@@ -819,9 +821,26 @@ public class WorldHopperPlugin extends Plugin
return; return;
} }
currentPing = Ping.ping(currentWorld); currentPing = ping(currentWorld);
log.trace("Ping for current world is: {}", currentPing); log.trace("Ping for current world is: {}", currentPing);
SwingUtilities.invokeLater(() -> panel.updatePing(currentWorld.getId(), currentPing)); SwingUtilities.invokeLater(() -> panel.updatePing(currentWorld.getId(), currentPing));
} }
Integer getStoredPing(World world)
{
if (!config.ping())
{
return null;
}
return storedPings.get(world.getId());
}
private int ping(World world)
{
int ping = Ping.ping(world);
storedPings.put(world.getId(), ping);
return ping;
}
} }

View File

@@ -378,7 +378,7 @@ class WorldSwitcherPanel extends PluginPanel
*/ */
private WorldTableRow buildRow(World world, boolean stripe, boolean current, boolean favorite) private WorldTableRow buildRow(World world, boolean stripe, boolean current, boolean favorite)
{ {
WorldTableRow row = new WorldTableRow(world, current, favorite, WorldTableRow row = new WorldTableRow(world, current, favorite, plugin.getStoredPing(world),
world1 -> world1 ->
{ {
plugin.hopTo(world1); plugin.hopTo(world1);

View File

@@ -91,7 +91,7 @@ class WorldTableRow extends JPanel
private Color lastBackground; private Color lastBackground;
private boolean current; private boolean current;
WorldTableRow(World world, boolean current, boolean favorite, Consumer<World> onSelect, BiConsumer<World, Boolean> onFavorite) WorldTableRow(World world, boolean current, boolean favorite, Integer ping, Consumer<World> onSelect, BiConsumer<World, Boolean> onFavorite)
{ {
this.current = current; this.current = current;
this.world = world; this.world = world;
@@ -164,7 +164,7 @@ class WorldTableRow extends JPanel
worldField.setPreferredSize(new Dimension(WORLD_COLUMN_WIDTH, 0)); worldField.setPreferredSize(new Dimension(WORLD_COLUMN_WIDTH, 0));
worldField.setOpaque(false); worldField.setOpaque(false);
JPanel pingField = buildPingField(); JPanel pingField = buildPingField(ping);
pingField.setPreferredSize(new Dimension(PING_COLUMN_WIDTH, 0)); pingField.setPreferredSize(new Dimension(PING_COLUMN_WIDTH, 0));
pingField.setOpaque(false); pingField.setOpaque(false);
@@ -282,7 +282,7 @@ class WorldTableRow extends JPanel
return column; return column;
} }
private JPanel buildPingField() private JPanel buildPingField(Integer ping)
{ {
JPanel column = new JPanel(new BorderLayout()); JPanel column = new JPanel(new BorderLayout());
column.setBorder(new EmptyBorder(0, 5, 0, 5)); column.setBorder(new EmptyBorder(0, 5, 0, 5));
@@ -292,6 +292,11 @@ class WorldTableRow extends JPanel
column.add(pingField, BorderLayout.EAST); column.add(pingField, BorderLayout.EAST);
if (ping != null)
{
setPing(ping);
}
return column; return column;
} }