Skip to content
Permalink
Browse files

world hopper plugin: make world pings persist across world fetches

  • Loading branch information
Trevor159 committed Jan 2, 2020
1 parent f09f630 commit 56f2829640a3aadeb761e457b0d0349bdd6c4b79
@@ -160,6 +160,8 @@
@Getter(AccessLevel.PACKAGE)
private int currentPing;

private final Map<Integer, Integer> storedPings = new HashMap<>();

private final HotkeyListener previousKeyListener = new HotkeyListener(() -> config.previousKey())
{
@Override
@@ -754,7 +756,7 @@ private void pingInitialWorlds()

for (World world : worldResult.getWorlds())
{
int ping = Ping.ping(world);
int ping = ping(world);
SwingUtilities.invokeLater(() -> panel.updatePing(world.getId(), ping));
}

@@ -795,7 +797,7 @@ private void pingNextWorld()
return;
}

int ping = Ping.ping(world);
int ping = ping(world);
log.trace("Ping for world {} is: {}", world.getId(), ping);
SwingUtilities.invokeLater(() -> panel.updatePing(world.getId(), ping));
}
@@ -819,9 +821,26 @@ private void pingCurrentWorld()
return;
}

currentPing = Ping.ping(currentWorld);
currentPing = ping(currentWorld);
log.trace("Ping for current world is: {}", 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;
}
}
@@ -378,7 +378,7 @@ public void mousePressed(MouseEvent mouseEvent)
*/
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 ->
{
plugin.hopTo(world1);
@@ -91,7 +91,7 @@
private Color lastBackground;
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.world = world;
@@ -164,7 +164,7 @@ public void mouseExited(MouseEvent mouseEvent)
worldField.setPreferredSize(new Dimension(WORLD_COLUMN_WIDTH, 0));
worldField.setOpaque(false);

JPanel pingField = buildPingField();
JPanel pingField = buildPingField(ping);
pingField.setPreferredSize(new Dimension(PING_COLUMN_WIDTH, 0));
pingField.setOpaque(false);

@@ -282,7 +282,7 @@ private JPanel buildPlayersField()
return column;
}

private JPanel buildPingField()
private JPanel buildPingField(Integer ping)
{
JPanel column = new JPanel(new BorderLayout());
column.setBorder(new EmptyBorder(0, 5, 0, 5));
@@ -292,6 +292,11 @@ private JPanel buildPingField()

column.add(pingField, BorderLayout.EAST);

if (ping != null)
{
setPing(ping);
}

return column;
}

0 comments on commit 56f2829

Please sign in to comment.
You can’t perform that action at this time.