This commit is contained in:
parent
a6e15828c1
commit
bf35582b13
|
@ -170,6 +170,7 @@ public final class StatCommand implements CommandExecutor {
|
|||
switch (targetArg) {
|
||||
case "me" -> {
|
||||
if (sender instanceof Player) {
|
||||
//TODO this is where an excluded player can sneak in
|
||||
target = Target.PLAYER;
|
||||
playerName = sender.getName();
|
||||
} else {
|
||||
|
|
|
@ -21,7 +21,7 @@ public final class ConfigHandler extends FileHandler {
|
|||
super("config.yml");
|
||||
config = super.getFileConfiguration();
|
||||
|
||||
configVersion = 6;
|
||||
configVersion = 7;
|
||||
checkAndUpdateConfigVersion();
|
||||
MyLogger.setDebugLevel(getDebugLevel());
|
||||
}
|
||||
|
@ -132,6 +132,14 @@ public final class ConfigHandler extends FileHandler {
|
|||
return config.getInt("number-of-days-since-last-joined", 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* Whether to allow the /stat player command for excluded players.
|
||||
* @return the config setting (default: true)
|
||||
*/
|
||||
public boolean allowPlayerLookupsForExcludedPlayers() {
|
||||
return config.getBoolean("allow-player-lookups-for-excluded-players", true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Whether to use TranslatableComponents wherever possible.
|
||||
*
|
||||
|
|
|
@ -64,7 +64,7 @@ final class StatAction extends RecursiveTask<ConcurrentHashMap<String, Integer>>
|
|||
do {
|
||||
String playerName = iterator.next();
|
||||
MyLogger.actionRunning(Thread.currentThread().getName());
|
||||
OfflinePlayer player = offlinePlayerHandler.getOfflinePlayer(playerName);
|
||||
OfflinePlayer player = offlinePlayerHandler.getLoadedOfflinePlayer(playerName);
|
||||
int statistic = 0;
|
||||
switch (requestSettings.getStatistic().getType()) {
|
||||
case UNTYPED -> statistic = player.getStatistic(requestSettings.getStatistic());
|
||||
|
|
|
@ -4,6 +4,7 @@ import com.artemis.the.gr8.playerstats.api.RequestGenerator;
|
|||
import com.artemis.the.gr8.playerstats.api.StatManager;
|
||||
import com.artemis.the.gr8.playerstats.api.StatRequest;
|
||||
import com.artemis.the.gr8.playerstats.api.StatResult;
|
||||
import com.artemis.the.gr8.playerstats.core.config.ConfigHandler;
|
||||
import com.artemis.the.gr8.playerstats.core.msg.msgutils.FormattingFunction;
|
||||
import com.artemis.the.gr8.playerstats.core.msg.OutputManager;
|
||||
import com.artemis.the.gr8.playerstats.core.multithreading.ThreadManager;
|
||||
|
@ -85,10 +86,12 @@ public final class RequestManager implements StatManager {
|
|||
|
||||
private final class RequestProcessor {
|
||||
|
||||
private static ConfigHandler config;
|
||||
private static OutputManager outputManager;
|
||||
private static ShareManager shareManager;
|
||||
|
||||
public RequestProcessor(OutputManager outputManager) {
|
||||
RequestProcessor.config = ConfigHandler.getInstance();
|
||||
RequestProcessor.outputManager = outputManager;
|
||||
RequestProcessor.shareManager = ShareManager.getInstance();
|
||||
}
|
||||
|
@ -121,7 +124,13 @@ public final class RequestManager implements StatManager {
|
|||
}
|
||||
|
||||
private int getPlayerStat(@NotNull StatRequest.Settings requestSettings) {
|
||||
OfflinePlayer player = offlinePlayerHandler.getOfflinePlayer(requestSettings.getPlayerName());
|
||||
OfflinePlayer player;
|
||||
if (offlinePlayerHandler.isExcludedPlayer(requestSettings.getPlayerName()) &&
|
||||
config.allowPlayerLookupsForExcludedPlayers()) {
|
||||
player = offlinePlayerHandler.getExcludedOfflinePlayer(requestSettings.getPlayerName());
|
||||
} else {
|
||||
player = offlinePlayerHandler.getLoadedOfflinePlayer(requestSettings.getPlayerName());
|
||||
}
|
||||
return switch (requestSettings.getStatistic().getType()) {
|
||||
case UNTYPED -> player.getStatistic(requestSettings.getStatistic());
|
||||
case ENTITY -> player.getStatistic(requestSettings.getStatistic(), requestSettings.getEntity());
|
||||
|
|
|
@ -132,7 +132,7 @@ public final class OfflinePlayerHandler extends FileHandler {
|
|||
* @throws IllegalArgumentException if this player is not on the list
|
||||
* of players that should be included in statistic calculations
|
||||
*/
|
||||
public @NotNull OfflinePlayer getOfflinePlayer(String playerName) throws IllegalArgumentException {
|
||||
public @NotNull OfflinePlayer getLoadedOfflinePlayer(String playerName) throws IllegalArgumentException {
|
||||
if (includedPlayerUUIDs.get(playerName) != null) {
|
||||
return Bukkit.getOfflinePlayer(includedPlayerUUIDs.get(playerName));
|
||||
}
|
||||
|
@ -140,10 +140,17 @@ public final class OfflinePlayerHandler extends FileHandler {
|
|||
MyLogger.logWarning("Cannot calculate statistics for player-name: " + playerName +
|
||||
"! Double-check if the name is spelled correctly (including capital letters), " +
|
||||
"or if any of your config settings exclude them");
|
||||
throw new IllegalArgumentException("Cannot convert this player-name into a valid Player to calculate statistics for");
|
||||
throw new IllegalArgumentException("PlayerStats does not know a player by this name");
|
||||
}
|
||||
}
|
||||
|
||||
public @NotNull OfflinePlayer getExcludedOfflinePlayer(String playerName) throws IllegalArgumentException {
|
||||
if (excludedPlayerUUIDs.get(playerName) != null) {
|
||||
return Bukkit.getOfflinePlayer(excludedPlayerUUIDs.get(playerName));
|
||||
}
|
||||
throw new IllegalArgumentException("There is no player on the exclude-list with this name");
|
||||
}
|
||||
|
||||
private void loadOfflinePlayers() {
|
||||
Executors.newSingleThreadExecutor().execute(() -> {
|
||||
loadExcludedPlayerNames();
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
# ------------------------------------------------------------------------------------------------------ #
|
||||
# PlayerStats Configuration #
|
||||
# ------------------------------------------------------------------------------------------------------ #
|
||||
config-version: 6
|
||||
config-version: 7
|
||||
|
||||
|
||||
# # ------------------------------- # #
|
||||
|
@ -33,6 +33,11 @@ exclude-banned-players: false
|
|||
# Leave this on 0 to include all players
|
||||
number-of-days-since-last-joined: 0
|
||||
|
||||
# Players that are excluded through the previous settings or the excluded-players-file will not
|
||||
# show up in top or server statistics. This setting controls whether you can still see their stats with
|
||||
# the /stat player command
|
||||
allow-player-lookups-for-excluded-players: true
|
||||
|
||||
|
||||
# # ------------------------------- # #
|
||||
# # Format & Display # #
|
||||
|
|
Loading…
Reference in New Issue