mirror of
https://github.com/plan-player-analytics/Plan.git
synced 2024-12-15 05:41:51 +08:00
Add online player names to player tab completion
Affects issues: - Close #2216
This commit is contained in:
parent
60486f8795
commit
e3bea9ee77
@ -16,11 +16,15 @@
|
||||
*/
|
||||
package com.djrapitops.plan.gathering;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Server;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Singleton;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@Singleton
|
||||
public class BukkitSensor implements ServerSensor<World> {
|
||||
@ -118,4 +122,11 @@ public class BukkitSensor implements ServerSensor<World> {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getOnlinePlayerNames() {
|
||||
return Bukkit.getOnlinePlayers().stream()
|
||||
.map(Player::getName)
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
}
|
||||
|
@ -19,19 +19,26 @@ package com.djrapitops.plan.gathering;
|
||||
import com.djrapitops.plan.PlanBungee;
|
||||
import com.djrapitops.plan.identification.properties.RedisCheck;
|
||||
import com.djrapitops.plan.identification.properties.RedisPlayersOnlineSupplier;
|
||||
import net.md_5.bungee.api.connection.ProxiedPlayer;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Singleton;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.function.IntSupplier;
|
||||
import java.util.function.Supplier;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@Singleton
|
||||
public class BungeeSensor implements ServerSensor<Object> {
|
||||
|
||||
private final IntSupplier onlinePlayerCountSupplier;
|
||||
private final IntSupplier onlinePlayerCountBungee;
|
||||
private final Supplier<Collection<ProxiedPlayer>> getPlayers;
|
||||
|
||||
@Inject
|
||||
public BungeeSensor(PlanBungee plugin) {
|
||||
getPlayers = plugin.getProxy()::getPlayers;
|
||||
onlinePlayerCountBungee = plugin.getProxy()::getOnlineCount;
|
||||
onlinePlayerCountSupplier = RedisCheck.isClassAvailable() ? new RedisPlayersOnlineSupplier() : onlinePlayerCountBungee;
|
||||
}
|
||||
@ -46,4 +53,9 @@ public class BungeeSensor implements ServerSensor<Object> {
|
||||
int count = onlinePlayerCountSupplier.getAsInt();
|
||||
return count != -1 ? count : onlinePlayerCountBungee.getAsInt();
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getOnlinePlayerNames() {
|
||||
return getPlayers.get().stream().map(ProxiedPlayer::getName).collect(Collectors.toList());
|
||||
}
|
||||
}
|
||||
|
@ -18,6 +18,7 @@ package com.djrapitops.plan.commands;
|
||||
|
||||
import com.djrapitops.plan.SubSystem;
|
||||
import com.djrapitops.plan.delivery.domain.auth.User;
|
||||
import com.djrapitops.plan.gathering.ServerSensor;
|
||||
import com.djrapitops.plan.identification.Server;
|
||||
import com.djrapitops.plan.identification.ServerUUID;
|
||||
import com.djrapitops.plan.processing.Processing;
|
||||
@ -43,25 +44,28 @@ public class TabCompleteCache implements SubSystem {
|
||||
private final Processing processing;
|
||||
private final PlanFiles files;
|
||||
private final DBSystem dbSystem;
|
||||
private final ServerSensor<?> serverSensor;
|
||||
|
||||
private final List<String> playerIdentifiers;
|
||||
private final List<String> serverIdentifiers;
|
||||
private final List<String> userIdentifiers;
|
||||
private final List<String> backupFileNames;
|
||||
private final Set<String> playerIdentifiers;
|
||||
private final Set<String> serverIdentifiers;
|
||||
private final Set<String> userIdentifiers;
|
||||
private final Set<String> backupFileNames;
|
||||
|
||||
@Inject
|
||||
public TabCompleteCache(
|
||||
Processing processing,
|
||||
PlanFiles files,
|
||||
DBSystem dbSystem
|
||||
DBSystem dbSystem,
|
||||
ServerSensor<?> serverSensor
|
||||
) {
|
||||
this.processing = processing;
|
||||
this.files = files;
|
||||
this.dbSystem = dbSystem;
|
||||
playerIdentifiers = new ArrayList<>();
|
||||
serverIdentifiers = new ArrayList<>();
|
||||
userIdentifiers = new ArrayList<>();
|
||||
backupFileNames = new ArrayList<>();
|
||||
this.serverSensor = serverSensor;
|
||||
playerIdentifiers = new HashSet<>();
|
||||
serverIdentifiers = new HashSet<>();
|
||||
userIdentifiers = new HashSet<>();
|
||||
backupFileNames = new HashSet<>();
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -71,11 +75,6 @@ public class TabCompleteCache implements SubSystem {
|
||||
refreshServerIdentifiers();
|
||||
refreshUserIdentifiers();
|
||||
refreshBackupFileNames();
|
||||
|
||||
Collections.sort(playerIdentifiers);
|
||||
Collections.sort(serverIdentifiers);
|
||||
Collections.sort(userIdentifiers);
|
||||
Collections.sort(backupFileNames);
|
||||
});
|
||||
}
|
||||
|
||||
@ -115,30 +114,45 @@ public class TabCompleteCache implements SubSystem {
|
||||
}
|
||||
|
||||
public List<String> getMatchingServerIdentifiers(String searchFor) {
|
||||
if (searchFor == null || searchFor.isEmpty()) {
|
||||
return serverIdentifiers.size() < 100 ? serverIdentifiers : Collections.emptyList();
|
||||
if (serverIdentifiers.size() >= 100) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
return serverIdentifiers.stream().filter(identifier -> identifier.startsWith(searchFor)).collect(Collectors.toList());
|
||||
return serverIdentifiers.stream()
|
||||
.filter(identifier -> searchFor == null || searchFor.isEmpty() || identifier.startsWith(searchFor))
|
||||
.sorted(String.CASE_INSENSITIVE_ORDER)
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
public List<String> getMatchingPlayerIdentifiers(String searchFor) {
|
||||
if (searchFor == null || searchFor.isEmpty()) {
|
||||
return playerIdentifiers.size() < 100 ? playerIdentifiers : Collections.emptyList();
|
||||
if (playerIdentifiers.size() >= 100) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
return playerIdentifiers.stream().filter(identifier -> identifier.startsWith(searchFor)).collect(Collectors.toList());
|
||||
|
||||
playerIdentifiers.addAll(serverSensor.getOnlinePlayerNames());
|
||||
|
||||
return playerIdentifiers.stream()
|
||||
.filter(identifier -> searchFor == null || searchFor.isEmpty() || identifier.startsWith(searchFor))
|
||||
.sorted(String.CASE_INSENSITIVE_ORDER)
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
public List<String> getMatchingUserIdentifiers(String searchFor) {
|
||||
if (searchFor == null || searchFor.isEmpty()) {
|
||||
return userIdentifiers.size() < 100 ? userIdentifiers : Collections.emptyList();
|
||||
if (userIdentifiers.size() >= 100) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
return userIdentifiers.stream().filter(identifier -> identifier.startsWith(searchFor)).collect(Collectors.toList());
|
||||
return userIdentifiers.stream()
|
||||
.filter(identifier -> searchFor == null || searchFor.isEmpty() || identifier.startsWith(searchFor))
|
||||
.sorted(String.CASE_INSENSITIVE_ORDER)
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
public List<String> getMatchingBackupFilenames(String searchFor) {
|
||||
if (searchFor == null || searchFor.isEmpty()) {
|
||||
return backupFileNames.size() < 100 ? backupFileNames : Collections.emptyList();
|
||||
if (backupFileNames.size() >= 100) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
return backupFileNames.stream().filter(identifier -> identifier.startsWith(searchFor)).collect(Collectors.toList());
|
||||
return backupFileNames.stream()
|
||||
.filter(identifier -> searchFor == null || searchFor.isEmpty() || identifier.startsWith(searchFor))
|
||||
.sorted(String.CASE_INSENSITIVE_ORDER)
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
}
|
||||
|
@ -17,6 +17,7 @@
|
||||
package com.djrapitops.plan.gathering;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Allows sensing values from different server platforms.
|
||||
@ -55,4 +56,8 @@ public interface ServerSensor<W> {
|
||||
default int getEntityCount(W world) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
default List<String> getOnlinePlayerNames() {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
}
|
||||
|
@ -23,6 +23,8 @@ import net.minecraft.server.world.ServerWorld;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Singleton;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
@Singleton
|
||||
@ -82,4 +84,9 @@ public class FabricSensor implements ServerSensor<ServerWorld> {
|
||||
public int getOnlinePlayerCount() {
|
||||
return server.getCurrentPlayerCount();
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getOnlinePlayerNames() {
|
||||
return Arrays.asList(server.getPlayerNames());
|
||||
}
|
||||
}
|
||||
|
@ -16,11 +16,14 @@
|
||||
*/
|
||||
package com.djrapitops.plan.gathering;
|
||||
|
||||
import cn.nukkit.Player;
|
||||
import cn.nukkit.level.Level;
|
||||
import com.djrapitops.plan.PlanNukkit;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Singleton;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@Singleton
|
||||
public class NukkitSensor implements ServerSensor<Level> {
|
||||
@ -63,4 +66,12 @@ public class NukkitSensor implements ServerSensor<Level> {
|
||||
public Iterable<Level> getWorlds() {
|
||||
return plugin.getServer().getLevels().values();
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getOnlinePlayerNames() {
|
||||
return plugin.getServer().getOnlinePlayers()
|
||||
.values().stream()
|
||||
.map(Player::getName)
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
}
|
||||
|
@ -17,12 +17,15 @@
|
||||
package com.djrapitops.plan.gathering;
|
||||
|
||||
import org.spongepowered.api.Game;
|
||||
import org.spongepowered.api.entity.living.player.server.ServerPlayer;
|
||||
import org.spongepowered.api.world.chunk.WorldChunk;
|
||||
import org.spongepowered.api.world.server.ServerWorld;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Singleton;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@Singleton
|
||||
public class SpongeSensor implements ServerSensor<ServerWorld> {
|
||||
@ -73,4 +76,9 @@ public class SpongeSensor implements ServerSensor<ServerWorld> {
|
||||
public int getEntityCount(ServerWorld world) {
|
||||
return world.entities().size();
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getOnlinePlayerNames() {
|
||||
return game.server().onlinePlayers().stream().map(ServerPlayer::name).collect(Collectors.toList());
|
||||
}
|
||||
}
|
||||
|
@ -19,18 +19,25 @@ package com.djrapitops.plan.gathering;
|
||||
import com.djrapitops.plan.PlanVelocity;
|
||||
import com.djrapitops.plan.identification.properties.VelocityRedisCheck;
|
||||
import com.djrapitops.plan.identification.properties.VelocityRedisPlayersOnlineSupplier;
|
||||
import com.velocitypowered.api.proxy.Player;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Singleton;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.function.IntSupplier;
|
||||
import java.util.function.Supplier;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@Singleton
|
||||
public class VelocitySensor implements ServerSensor<Object> {
|
||||
|
||||
private final IntSupplier onlinePlayerCountSupplier;
|
||||
private final Supplier<Collection<Player>> getPlayers;
|
||||
|
||||
@Inject
|
||||
public VelocitySensor(PlanVelocity plugin) {
|
||||
getPlayers = plugin.getProxy()::getAllPlayers;
|
||||
onlinePlayerCountSupplier = VelocityRedisCheck.isClassAvailable()
|
||||
? new VelocityRedisPlayersOnlineSupplier()
|
||||
: plugin.getProxy()::getPlayerCount;
|
||||
@ -45,4 +52,9 @@ public class VelocitySensor implements ServerSensor<Object> {
|
||||
public int getOnlinePlayerCount() {
|
||||
return onlinePlayerCountSupplier.getAsInt();
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getOnlinePlayerNames() {
|
||||
return getPlayers.get().stream().map(Player::getUsername).collect(Collectors.toList());
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user