|
|
@ -106,7 +106,7 @@ public class BukkitPlayer extends OnlineUser {
|
|
|
|
if (healthToSet < 1) {
|
|
|
|
if (healthToSet < 1) {
|
|
|
|
Bukkit.getScheduler().runTask(BukkitHuskSync.getInstance(), () -> player.setHealth(healthToSet));
|
|
|
|
Bukkit.getScheduler().runTask(BukkitHuskSync.getInstance(), () -> player.setHealth(healthToSet));
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
player.setHealth(healthToSet);
|
|
|
|
player.setHealth(Math.min(healthToSet, currentMaxHealth));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -355,32 +355,52 @@ public class BukkitPlayer extends OnlineUser {
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public CompletableFuture<Void> setStatistics(@NotNull StatisticsData statisticsData) {
|
|
|
|
public CompletableFuture<Void> setStatistics(@NotNull StatisticsData statisticsData) {
|
|
|
|
return CompletableFuture.runAsync(() -> {
|
|
|
|
return CompletableFuture.runAsync(() -> {
|
|
|
|
// Set untyped statistics
|
|
|
|
// Set generic statistics
|
|
|
|
for (String statistic : statisticsData.untypedStatistics.keySet()) {
|
|
|
|
for (String statistic : statisticsData.untypedStatistics.keySet()) {
|
|
|
|
|
|
|
|
try {
|
|
|
|
player.setStatistic(Statistic.valueOf(statistic), statisticsData.untypedStatistics.get(statistic));
|
|
|
|
player.setStatistic(Statistic.valueOf(statistic), statisticsData.untypedStatistics.get(statistic));
|
|
|
|
|
|
|
|
} catch (IllegalArgumentException e) {
|
|
|
|
|
|
|
|
BukkitHuskSync.getInstance().getLogger().log(Level.WARNING,
|
|
|
|
|
|
|
|
"Failed to set generic statistic " + statistic + " for " + username);
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Set block statistics
|
|
|
|
// Set block statistics
|
|
|
|
for (String statistic : statisticsData.blockStatistics.keySet()) {
|
|
|
|
for (String statistic : statisticsData.blockStatistics.keySet()) {
|
|
|
|
for (String blockMaterial : statisticsData.blockStatistics.get(statistic).keySet()) {
|
|
|
|
for (String blockMaterial : statisticsData.blockStatistics.get(statistic).keySet()) {
|
|
|
|
|
|
|
|
try {
|
|
|
|
player.setStatistic(Statistic.valueOf(statistic), Material.valueOf(blockMaterial),
|
|
|
|
player.setStatistic(Statistic.valueOf(statistic), Material.valueOf(blockMaterial),
|
|
|
|
statisticsData.blockStatistics.get(statistic).get(blockMaterial));
|
|
|
|
statisticsData.blockStatistics.get(statistic).get(blockMaterial));
|
|
|
|
|
|
|
|
} catch (IllegalArgumentException e) {
|
|
|
|
|
|
|
|
BukkitHuskSync.getInstance().getLogger().log(Level.WARNING,
|
|
|
|
|
|
|
|
"Failed to set " + blockMaterial + " statistic " + statistic + " for " + username);
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Set item statistics
|
|
|
|
// Set item statistics
|
|
|
|
for (String statistic : statisticsData.itemStatistics.keySet()) {
|
|
|
|
for (String statistic : statisticsData.itemStatistics.keySet()) {
|
|
|
|
for (String itemMaterial : statisticsData.itemStatistics.get(statistic).keySet()) {
|
|
|
|
for (String itemMaterial : statisticsData.itemStatistics.get(statistic).keySet()) {
|
|
|
|
|
|
|
|
try {
|
|
|
|
player.setStatistic(Statistic.valueOf(statistic), Material.valueOf(itemMaterial),
|
|
|
|
player.setStatistic(Statistic.valueOf(statistic), Material.valueOf(itemMaterial),
|
|
|
|
statisticsData.itemStatistics.get(statistic).get(itemMaterial));
|
|
|
|
statisticsData.itemStatistics.get(statistic).get(itemMaterial));
|
|
|
|
|
|
|
|
} catch (IllegalArgumentException e) {
|
|
|
|
|
|
|
|
BukkitHuskSync.getInstance().getLogger().log(Level.WARNING,
|
|
|
|
|
|
|
|
"Failed to set " + itemMaterial + " statistic " + statistic + " for " + username);
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Set entity statistics
|
|
|
|
// Set entity statistics
|
|
|
|
for (String statistic : statisticsData.entityStatistics.keySet()) {
|
|
|
|
for (String statistic : statisticsData.entityStatistics.keySet()) {
|
|
|
|
for (String entityType : statisticsData.entityStatistics.get(statistic).keySet()) {
|
|
|
|
for (String entityType : statisticsData.entityStatistics.get(statistic).keySet()) {
|
|
|
|
|
|
|
|
try {
|
|
|
|
player.setStatistic(Statistic.valueOf(statistic), EntityType.valueOf(entityType),
|
|
|
|
player.setStatistic(Statistic.valueOf(statistic), EntityType.valueOf(entityType),
|
|
|
|
statisticsData.entityStatistics.get(statistic).get(entityType));
|
|
|
|
statisticsData.entityStatistics.get(statistic).get(entityType));
|
|
|
|
|
|
|
|
} catch (IllegalArgumentException e) {
|
|
|
|
|
|
|
|
BukkitHuskSync.getInstance().getLogger().log(Level.WARNING,
|
|
|
|
|
|
|
|
"Failed to set " + entityType + " statistic " + statistic + " for " + username);
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|