Compare commits
5 Commits
develop-bl
...
develop-st
| Author | SHA1 | Date | |
|---|---|---|---|
| 4a5c24235b | |||
| 62c0250049 | |||
| b4ccc3c4c8 | |||
| 78f87d97f0 | |||
| db13a9f0a2 |
@@ -21,18 +21,17 @@ class ChatMessagesListener extends ApplianceListener<ChatMessages> {
|
|||||||
public void onPlayerChatEvent(AsyncChatEvent event) {
|
public void onPlayerChatEvent(AsyncChatEvent event) {
|
||||||
event.renderer(
|
event.renderer(
|
||||||
(source, sourceDisplayName, message, viewer) ->
|
(source, sourceDisplayName, message, viewer) ->
|
||||||
Component.text("")
|
Component.text()
|
||||||
.append(this.getAppliance().getReportablePlayerName(source))
|
.append(this.getAppliance().getReportablePlayerName(source))
|
||||||
.append(Component.text(" > ").color(TextColor.color(Color.GRAY.asRGB())))
|
.append(Component.text(" > ").color(TextColor.color(Color.GRAY.asRGB())))
|
||||||
.append(message).color(TextColor.color(Color.SILVER.asRGB()))
|
.append(message).color(TextColor.color(Color.SILVER.asRGB()))
|
||||||
|
.build()
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler(priority = EventPriority.HIGH)
|
@EventHandler(priority = EventPriority.HIGH)
|
||||||
public void onPlayerJoin(PlayerJoinEvent event) {
|
public void onPlayerJoin(PlayerJoinEvent event) {
|
||||||
boolean wasHidden = event.joinMessage() == null;
|
if(event.joinMessage() == null) return;
|
||||||
event.joinMessage(null);
|
|
||||||
if(wasHidden) return;
|
|
||||||
IteratorUtil.onlinePlayers(player -> {
|
IteratorUtil.onlinePlayers(player -> {
|
||||||
if(!Settings.instance().getSetting(player, Settings.Key.ShowJoinAndLeaveMessages, Boolean.class)) return;
|
if(!Settings.instance().getSetting(player, Settings.Key.ShowJoinAndLeaveMessages, Boolean.class)) return;
|
||||||
player.sendMessage(
|
player.sendMessage(
|
||||||
@@ -45,9 +44,7 @@ class ChatMessagesListener extends ApplianceListener<ChatMessages> {
|
|||||||
|
|
||||||
@EventHandler
|
@EventHandler
|
||||||
public void onPlayerLeave(PlayerQuitEvent event) {
|
public void onPlayerLeave(PlayerQuitEvent event) {
|
||||||
boolean wasHidden = event.quitMessage() == null;
|
if(event.quitMessage() == null) return;
|
||||||
event.quitMessage(null);
|
|
||||||
if(wasHidden) return;
|
|
||||||
IteratorUtil.onlinePlayers(player -> {
|
IteratorUtil.onlinePlayers(player -> {
|
||||||
if(!Settings.instance().getSetting(player, Settings.Key.ShowJoinAndLeaveMessages, Boolean.class)) return;
|
if(!Settings.instance().getSetting(player, Settings.Key.ShowJoinAndLeaveMessages, Boolean.class)) return;
|
||||||
player.sendMessage(
|
player.sendMessage(
|
||||||
|
|||||||
@@ -0,0 +1,51 @@
|
|||||||
|
package eu.mhsl.craftattack.spawn.craftattack.appliances.tooling.statistics;
|
||||||
|
|
||||||
|
import eu.mhsl.craftattack.spawn.core.Main;
|
||||||
|
import eu.mhsl.craftattack.spawn.core.api.server.HttpServer;
|
||||||
|
import eu.mhsl.craftattack.spawn.core.appliance.Appliance;
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.Material;
|
||||||
|
import org.bukkit.Statistic;
|
||||||
|
|
||||||
|
import java.util.*;
|
||||||
|
|
||||||
|
public class Statistics extends Appliance {
|
||||||
|
record StatisticsResponse(List<PlayerStatistics> playerStatistics) {
|
||||||
|
record PlayerStatistics(String playerName, String playerUuid, List<MaterialStatistic> statistics) {
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
record MaterialStatistic(String name, String material, int value) {
|
||||||
|
}
|
||||||
|
|
||||||
|
record StatisticsRequest(List<MaterialStatistic> categories) {
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void httpApi(HttpServer.ApiBuilder apiBuilder) {
|
||||||
|
apiBuilder.post(
|
||||||
|
"getStatistics",
|
||||||
|
StatisticsRequest.class,
|
||||||
|
(statistics, request) -> {
|
||||||
|
Main.instance().getLogger().info("API requested statistics");
|
||||||
|
List<StatisticsResponse.PlayerStatistics> statisticsList = Arrays.stream(Bukkit.getOfflinePlayers())
|
||||||
|
.parallel()
|
||||||
|
.map(player -> new StatisticsResponse.PlayerStatistics(
|
||||||
|
player.getName(),
|
||||||
|
player.getUniqueId().toString(),
|
||||||
|
statistics.categories().stream()
|
||||||
|
.map(category -> {
|
||||||
|
String material = (category.material() == null || category.material().isBlank()) ? null : category.material();
|
||||||
|
return new MaterialStatistic(category.name(), material, material == null
|
||||||
|
? player.getStatistic(Statistic.valueOf(category.name()))
|
||||||
|
: player.getStatistic(Statistic.valueOf(category.name()), Material.valueOf(material))
|
||||||
|
);
|
||||||
|
})
|
||||||
|
.toList()
|
||||||
|
))
|
||||||
|
.toList();
|
||||||
|
return new StatisticsResponse(statisticsList);
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user