mirror of
https://github.com/Xiao-MoMi/Custom-Fishing.git
synced 2025-12-19 15:09:24 +00:00
Update StatisticsPapi.java
This commit is contained in:
@@ -45,7 +45,7 @@ public class StatisticsPapi extends PlaceholderExpansion {
|
|||||||
public StatisticsPapi(BukkitCustomFishingPlugin plugin) {
|
public StatisticsPapi(BukkitCustomFishingPlugin plugin) {
|
||||||
this.plugin = plugin;
|
this.plugin = plugin;
|
||||||
this.offlineDataCache = Caffeine.newBuilder()
|
this.offlineDataCache = Caffeine.newBuilder()
|
||||||
.expireAfterWrite(5, TimeUnit.MINUTES)
|
.expireAfterWrite(3, TimeUnit.MINUTES)
|
||||||
.build();
|
.build();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -82,51 +82,48 @@ public class StatisticsPapi extends PlaceholderExpansion {
|
|||||||
Optional<UserData> onlineUser = plugin.getStorageManager().getOnlineUser(player.getUniqueId());
|
Optional<UserData> onlineUser = plugin.getStorageManager().getOnlineUser(player.getUniqueId());
|
||||||
String[] split = params.split("_", 2);
|
String[] split = params.split("_", 2);
|
||||||
if (onlineUser.isPresent()) {
|
if (onlineUser.isPresent()) {
|
||||||
return onlineUser.map(
|
UserData data = onlineUser.get();
|
||||||
data -> {
|
FishingStatistics statistics = data.statistics();
|
||||||
FishingStatistics statistics = data.statistics();
|
switch (split[0]) {
|
||||||
switch (split[0]) {
|
case "total" -> {
|
||||||
case "total" -> {
|
return String.valueOf(statistics.amountOfFishCaught());
|
||||||
return String.valueOf(statistics.amountOfFishCaught());
|
}
|
||||||
}
|
case "hascaught" -> {
|
||||||
case "hascaught" -> {
|
if (split.length == 1) return "Invalid format";
|
||||||
if (split.length == 1) return "Invalid format";
|
return String.valueOf(statistics.getAmount(split[1]) != 0);
|
||||||
return String.valueOf(statistics.getAmount(split[1]) != 0);
|
}
|
||||||
}
|
case "amount" -> {
|
||||||
case "amount" -> {
|
if (split.length == 1) return "Invalid format";
|
||||||
if (split.length == 1) return "Invalid format";
|
return String.valueOf(statistics.getAmount(split[1]));
|
||||||
return String.valueOf(statistics.getAmount(split[1]));
|
}
|
||||||
}
|
case "size-record" -> {
|
||||||
case "size-record" -> {
|
float size = statistics.getMaxSize(split[1]);
|
||||||
float size = statistics.getMaxSize(split[1]);
|
return String.format("%.2f", size < 0 ? 0 : size);
|
||||||
return String.format("%.2f", size < 0 ? 0 : size);
|
}
|
||||||
}
|
case "category" -> {
|
||||||
case "category" -> {
|
if (split.length == 1) return "Invalid format";
|
||||||
if (split.length == 1) return "Invalid format";
|
String[] categorySplit = split[1].split("_", 2);
|
||||||
String[] categorySplit = split[1].split("_", 2);
|
if (categorySplit.length == 1) return "Invalid format";
|
||||||
if (categorySplit.length == 1) return "Invalid format";
|
List<String> category = plugin.getStatisticsManager().getCategoryMembers(categorySplit[1]);
|
||||||
List<String> category = plugin.getStatisticsManager().getCategoryMembers(categorySplit[1]);
|
if (categorySplit[0].equals("total")) {
|
||||||
if (categorySplit[0].equals("total")) {
|
int total = 0;
|
||||||
int total = 0;
|
for (String loot : category) {
|
||||||
for (String loot : category) {
|
total += statistics.getAmount(loot);
|
||||||
total += statistics.getAmount(loot);
|
|
||||||
}
|
|
||||||
return String.valueOf(total);
|
|
||||||
} else if (categorySplit[0].equals("progress")) {
|
|
||||||
int size = category.size();
|
|
||||||
int unlocked = 0;
|
|
||||||
for (String loot : category) {
|
|
||||||
if (statistics.getAmount(loot) != 0) unlocked++;
|
|
||||||
}
|
|
||||||
double percent = ((double) unlocked * 100) / size;
|
|
||||||
String progress = String.format("%.1f", percent);
|
|
||||||
return progress.equals("100.0") ? "100" : progress;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return null;
|
return String.valueOf(total);
|
||||||
|
} else if (categorySplit[0].equals("progress")) {
|
||||||
|
int size = category.size();
|
||||||
|
int unlocked = 0;
|
||||||
|
for (String loot : category) {
|
||||||
|
if (statistics.getAmount(loot) != 0) unlocked++;
|
||||||
|
}
|
||||||
|
double percent = ((double) unlocked * 100) / size;
|
||||||
|
String progress = String.format("%.1f", percent);
|
||||||
|
return progress.equals("100.0") ? "100" : progress;
|
||||||
}
|
}
|
||||||
).orElse("");
|
}
|
||||||
|
}
|
||||||
|
return null;
|
||||||
} else {
|
} else {
|
||||||
Optional<PlayerData> optional = offlineDataCache.get(player.getUniqueId(), (uuid) -> {
|
Optional<PlayerData> optional = offlineDataCache.get(player.getUniqueId(), (uuid) -> {
|
||||||
CompletableFuture<Optional<PlayerData>> data = plugin.getStorageManager().getDataSource().getPlayerData(player.getUniqueId(), false, Runnable::run);
|
CompletableFuture<Optional<PlayerData>> data = plugin.getStorageManager().getDataSource().getPlayerData(player.getUniqueId(), false, Runnable::run);
|
||||||
|
|||||||
Reference in New Issue
Block a user