[#483] 'Display_options.Open_player_links_in_new_tab'

- Added a config setting for /player links opening in new tab, defaults
  to false. Only exists in case someone wants to have previous behavior
- Changed Player table links to follow the setting, some plugin links
  may still use the "wrong" link
This commit is contained in:
Rsl1122 2019-01-05 12:08:26 +02:00
parent c9e80e31f1
commit b1746c5dab
7 changed files with 28 additions and 7 deletions

View File

@ -36,6 +36,7 @@ public class DisplaySettings {
public static final Setting<Boolean> ORDER_WORLD_PIE_BY_PERC = new BooleanSetting("Display_options.Sessions.Order_world_pies_by_percentage");
public static final Setting<Integer> PLAYERS_PER_SERVER_PAGE = new IntegerSetting("Display_options.Players_table.Show_on_server_page");
public static final Setting<Integer> PLAYERS_PER_PLAYERS_PAGE = new IntegerSetting("Display_options.Players_table.Show_on_players_page");
public static final Setting<Boolean> OPEN_PLAYER_LINKS_IN_NEW_TAB = new BooleanSetting("Display_options.Open_player_links_in_new_tab");
public static final Setting<Boolean> PLAYER_IPS = new BooleanSetting("Display_options.Show_player_IPs");
public static final Setting<Boolean> GAPS_IN_GRAPH_DATA = new BooleanSetting("Display_options.Graphs.Show_gaps_in_data");
public static final Setting<Integer> GRAPH_TPS_THRESHOLD_HIGH = new IntegerSetting("Display_options.Graphs.TPS.High_threshold");

View File

@ -157,6 +157,7 @@ public class HtmlTables {
config.get(DisplaySettings.PLAYERS_PER_SERVER_PAGE),
config.get(TimeSettings.ACTIVE_PLAY_THRESHOLD),
config.get(TimeSettings.ACTIVE_LOGIN_THRESHOLD),
config.get(DisplaySettings.OPEN_PLAYER_LINKS_IN_NEW_TAB),
formatters.timeAmount(), formatters.yearLong(), formatters.decimals()
);
}
@ -172,6 +173,7 @@ public class HtmlTables {
players, config.get(DisplaySettings.PLAYERS_PER_PLAYERS_PAGE),
config.get(TimeSettings.ACTIVE_PLAY_THRESHOLD),
config.get(TimeSettings.ACTIVE_LOGIN_THRESHOLD),
config.get(DisplaySettings.OPEN_PLAYER_LINKS_IN_NEW_TAB),
formatters.timeAmount(), formatters.yearLong(), formatters.decimals()
);
}
@ -184,6 +186,10 @@ public class HtmlTables {
* @return a new {@link PluginPlayersTable}.
*/
public TableContainer pluginPlayersTable(Map<PluginData, AnalysisContainer> containers, Collection<PlayerContainer> players) {
return new PluginPlayersTable(containers, players, config.get(DisplaySettings.PLAYERS_PER_SERVER_PAGE));
return new PluginPlayersTable(
containers, players,
config.get(DisplaySettings.PLAYERS_PER_SERVER_PAGE),
config.get(DisplaySettings.OPEN_PLAYER_LINKS_IN_NEW_TAB)
);
}
}

View File

@ -43,6 +43,7 @@ class PlayersTable extends TableContainer {
private final int maxPlayers;
private final long activeMsThreshold;
private final int activeLoginThreshold;
private final boolean openPlayerPageInNewTab;
private final Formatter<Double> decimalFormatter;
@ -51,6 +52,7 @@ class PlayersTable extends TableContainer {
int maxPlayers,
long activeMsThreshold,
int activeLoginThreshold,
boolean openPlayerPageInNewTab,
Formatter<Long> timeAmountFormatter,
Formatter<Long> yearLongFormatter,
Formatter<Double> decimalFormatter
@ -68,6 +70,7 @@ class PlayersTable extends TableContainer {
this.maxPlayers = maxPlayers;
this.activeMsThreshold = activeMsThreshold;
this.activeLoginThreshold = activeLoginThreshold;
this.openPlayerPageInNewTab = openPlayerPageInNewTab;
this.decimalFormatter = decimalFormatter;
useJqueryDataTables("player-table");
@ -104,8 +107,10 @@ class PlayersTable extends TableContainer {
String geolocation = GeoInfoMutator.forContainer(player).mostRecent().map(GeoInfo::getGeolocation).orElse("-");
Html link = openPlayerPageInNewTab ? Html.LINK_EXTERNAL : Html.LINK;
addRow(
Html.LINK_EXTERNAL.parse(url, name),
link.parse(url, name),
activityString,
playtime,
loginTimes,

View File

@ -39,24 +39,28 @@ class PluginPlayersTable extends TableContainer {
private Collection<PlayerContainer> players;
private final int maxPlayers;
private final boolean openPlayerPageInNewTab;
PluginPlayersTable(
Map<PluginData, AnalysisContainer> containers,
Collection<PlayerContainer> players,
int maxPlayers
int maxPlayers,
boolean openPlayerPageInNewTab
) {
this(getPluginDataSet(containers), players, maxPlayers);
this(getPluginDataSet(containers), players, maxPlayers, openPlayerPageInNewTab);
}
private PluginPlayersTable(
TreeMap<String, Map<UUID, ? extends Serializable>> pluginDataSet,
Collection<PlayerContainer> players,
int maxPlayers
int maxPlayers,
boolean openPlayerPageInNewTab
) {
super(true, getHeaders(pluginDataSet.keySet()));
this.players = players;
this.maxPlayers = maxPlayers;
this.openPlayerPageInNewTab = openPlayerPageInNewTab;
useJqueryDataTables("player-plugin-table");
@ -91,11 +95,13 @@ class PluginPlayersTable extends TableContainer {
if (i >= maxPlayers) {
break;
}
UUID uuid = profile.getUnsafe(PlayerKeys.UUID);
String name = profile.getValue(PlayerKeys.NAME).orElse("Unknown");
String link = Html.LINK_EXTERNAL.parse(PlanAPI.getInstance().getPlayerInspectPageLink(name), name);
Html link = openPlayerPageInNewTab ? Html.LINK_EXTERNAL : Html.LINK;
String linkHtml = link.parse(PlanAPI.getInstance().getPlayerInspectPageLink(name), name);
String[] playerData = ArrayUtil.merge(new String[]{link}, rows.getOrDefault(uuid, new String[]{}));
String[] playerData = ArrayUtil.merge(new String[]{linkHtml}, rows.getOrDefault(uuid, new String[]{}));
addRow(ArrayUtils.addAll(playerData));
i++;

View File

@ -104,6 +104,7 @@ Display_options:
Order_world_pies_by_percentage: false
Players_table:
Show_on_players_page: 25000
Open_player_links_in_new_tab: false
Show_player_IPs: true
Graphs:
Show_gaps_in_data: false

View File

@ -112,6 +112,7 @@ Display_options:
Players_table:
Show_on_server_page: 2500
Show_on_players_page: 25000
Open_player_links_in_new_tab: false
Show_player_IPs: true
Graphs:
Show_gaps_in_data: false

View File

@ -63,6 +63,7 @@ public class PlayersTableTest {
50, // maxPlayers
TimeUnit.MINUTES.toMillis(60), // activeMsThreshold
5, // activeLoginThreshold
false,
l -> "",
l -> "",
d -> ""