added year rank
This commit is contained in:
parent
247dae0155
commit
d66996bc73
@ -33,6 +33,7 @@ import eu.mhsl.craftattack.spawn.appliances.tablist.Tablist;
|
||||
import eu.mhsl.craftattack.spawn.appliances.titleClear.TitleClear;
|
||||
import eu.mhsl.craftattack.spawn.appliances.whitelist.Whitelist;
|
||||
import eu.mhsl.craftattack.spawn.appliances.worldmuseum.WorldMuseum;
|
||||
import eu.mhsl.craftattack.spawn.appliances.yearRank.YearRank;
|
||||
import eu.mhsl.craftattack.spawn.config.Configuration;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.event.HandlerList;
|
||||
@ -89,7 +90,8 @@ public final class Main extends JavaPlugin {
|
||||
new PackSelect(),
|
||||
new GlowingBerries(),
|
||||
new Maintenance(),
|
||||
new OptionLinks()
|
||||
new OptionLinks(),
|
||||
new YearRank()
|
||||
)
|
||||
.filter(appliance -> disabledAppliances.stream()
|
||||
.noneMatch(s -> s.equalsIgnoreCase(appliance.getClass().getSimpleName())))
|
||||
|
@ -1,9 +1,11 @@
|
||||
package eu.mhsl.craftattack.spawn.appliances.displayName;
|
||||
|
||||
import eu.mhsl.craftattack.spawn.Main;
|
||||
import eu.mhsl.craftattack.spawn.appliance.Appliance;
|
||||
import eu.mhsl.craftattack.spawn.appliances.adminMarker.AdminMarker;
|
||||
import eu.mhsl.craftattack.spawn.appliances.adminMarker.AdminMarkerListener;
|
||||
import eu.mhsl.craftattack.spawn.appliances.outlawed.Outlawed;
|
||||
import eu.mhsl.craftattack.spawn.appliances.yearRank.YearRank;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.ComponentBuilder;
|
||||
import net.kyori.adventure.text.TextComponent;
|
||||
@ -14,19 +16,22 @@ import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.function.Supplier;
|
||||
import java.util.logging.Level;
|
||||
|
||||
public class DisplayName extends Appliance {
|
||||
public void update(Player player) {
|
||||
TextColor playerColor = queryAppliance(AdminMarker.class).getPlayerColor(player);
|
||||
List<Supplier<Component>> prefixes = List.of(
|
||||
() -> queryAppliance(Outlawed.class).getNamePrefix(player)
|
||||
() -> queryAppliance(Outlawed.class).getNamePrefix(player),
|
||||
() -> queryAppliance(YearRank.class).getNamePrefix(player)
|
||||
);
|
||||
|
||||
ComponentBuilder<TextComponent, TextComponent.Builder> playerName = Component.text();
|
||||
prefixes.forEach(supplier -> {
|
||||
Component prefix = supplier.get();
|
||||
if(prefix == null) return;
|
||||
playerName.append(prefix).append(Component.text(" "));
|
||||
playerName.append(prefix).append(
|
||||
Component.text(" ").hoverEvent(Component.empty().asHoverEvent()));
|
||||
});
|
||||
|
||||
playerName.append(Component.text(player.getName(), playerColor));
|
||||
@ -41,7 +46,7 @@ public class DisplayName extends Appliance {
|
||||
player.playerListName(component);
|
||||
} catch(Exception e) {
|
||||
//TODO this throws often exceptions, but still works, don't know why
|
||||
//Main.instance().getLogger().log(Level.SEVERE, e, e::getMessage);
|
||||
Main.instance().getLogger().log(Level.SEVERE, e, e::getMessage);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -41,8 +41,6 @@ public class OptionLinks extends Appliance {
|
||||
|
||||
public void setServerLinks(Player player) {
|
||||
ServerLinks playerLinks = Bukkit.getServerLinks().copy();
|
||||
Main.logger().info("Set server links for " + player.getName());
|
||||
|
||||
Bukkit.getScheduler().runTaskAsynchronously(Main.instance(), () -> {
|
||||
this.links.forEach(suppliedLink -> {
|
||||
Component component = suppliedLink.component.apply(new ComponentSupplier());
|
||||
@ -54,9 +52,6 @@ public class OptionLinks extends Appliance {
|
||||
Main.logger().log(Level.INFO, String.format("Failed to create OptionLink '%s' for player '%s'", uri, player.getName()), e);
|
||||
}
|
||||
});
|
||||
|
||||
Main.logger().info("Sent links for " + player.getName());
|
||||
|
||||
player.sendLinks(playerLinks);
|
||||
});
|
||||
}
|
||||
|
@ -0,0 +1,99 @@
|
||||
package eu.mhsl.craftattack.spawn.appliances.yearRank;
|
||||
|
||||
import eu.mhsl.craftattack.spawn.Main;
|
||||
import eu.mhsl.craftattack.spawn.appliance.Appliance;
|
||||
import eu.mhsl.craftattack.spawn.appliance.ApplianceCommand;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.TextComponent;
|
||||
import net.kyori.adventure.text.event.ClickEvent;
|
||||
import net.kyori.adventure.text.event.HoverEvent;
|
||||
import net.kyori.adventure.text.format.NamedTextColor;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.*;
|
||||
|
||||
public class YearRank extends Appliance {
|
||||
record CraftAttackYear(String name) {}
|
||||
private final Map<UUID, List<CraftAttackYear>> rankMap = new HashMap<>();
|
||||
|
||||
@Override
|
||||
public void onEnable() {
|
||||
File folder = new File(Main.instance().getDataFolder(), "yearRank");
|
||||
|
||||
//noinspection ResultOfMethodCallIgnored
|
||||
folder.mkdirs();
|
||||
|
||||
Optional<File[]> dataFolders = Optional.ofNullable(folder.listFiles());
|
||||
if(dataFolders.isEmpty()) return;
|
||||
|
||||
List.of(dataFolders.get()).forEach(playerDataFolder -> {
|
||||
Optional<File[]> datFiles = Optional.ofNullable(playerDataFolder.listFiles());
|
||||
if(datFiles.isEmpty()) return;
|
||||
|
||||
CraftAttackYear craftAttackYear = new CraftAttackYear(playerDataFolder.getName());
|
||||
|
||||
Arrays.stream(datFiles.get())
|
||||
.map(file -> file.getName().split("\\.")[0])
|
||||
.distinct()
|
||||
.map(UUID::fromString)
|
||||
.peek(uuid -> rankMap.computeIfAbsent(uuid, p -> new ArrayList<>()))
|
||||
.forEach(uuid -> rankMap.get(uuid).add(craftAttackYear));
|
||||
});
|
||||
}
|
||||
|
||||
public @Nullable Component getNamePrefix(Player player) {
|
||||
if(!rankMap.containsKey(player.getUniqueId())) return null;
|
||||
int yearCount = rankMap.get(player.getUniqueId()).size();
|
||||
if(yearCount <= 3) return null;
|
||||
|
||||
return Component.text()
|
||||
.append(Component.text("[\uD83C\uDF1F]", NamedTextColor.GOLD))
|
||||
.hoverEvent(HoverEvent.showText(
|
||||
Component.text(String.format("Langzeitspieler: %s ist bereits seit %d Jahren dabei!", player.getName(), yearCount))
|
||||
))
|
||||
.build();
|
||||
}
|
||||
|
||||
public Component listYearRanks() {
|
||||
TextComponent.Builder builder = Component.text();
|
||||
builder.append(Component.text("Top 30 Spieler: ", NamedTextColor.GOLD));
|
||||
rankMap.keySet().stream()
|
||||
.map(uuid -> Map.entry(uuid, rankMap.get(uuid).size()))
|
||||
.sorted(Map.Entry.comparingByValue(Comparator.reverseOrder()))
|
||||
.limit(30)
|
||||
.forEach(entry -> builder
|
||||
.appendNewline()
|
||||
.append(Component.text(entry.getKey().toString(), NamedTextColor.GRAY)
|
||||
.hoverEvent(HoverEvent.showText(Component.text(entry.getKey().toString())))
|
||||
.clickEvent(ClickEvent.copyToClipboard(entry.getKey().toString())))
|
||||
.append(Component.text(": "))
|
||||
.append(Component.text(entry.getValue(), NamedTextColor.GOLD)));
|
||||
|
||||
builder
|
||||
.appendNewline()
|
||||
.appendNewline()
|
||||
.append(Component.text("Übersischt:", NamedTextColor.GOLD));
|
||||
|
||||
rankMap.values().stream()
|
||||
.mapMulti(Iterable::forEach)
|
||||
.filter(o -> o instanceof CraftAttackYear)
|
||||
.map(o -> (CraftAttackYear) o)
|
||||
.distinct()
|
||||
.forEach(craftAttackYear -> builder
|
||||
.appendNewline()
|
||||
.append(Component.text(craftAttackYear.name, NamedTextColor.GRAY))
|
||||
.append(Component.text(": "))
|
||||
.append(Component.text(rankMap.keySet().stream()
|
||||
.filter(uuid -> rankMap.get(uuid).contains(craftAttackYear)).count())));
|
||||
|
||||
return builder.build();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected @NotNull List<ApplianceCommand<?>> commands() {
|
||||
return List.of(new YearRankCommand());
|
||||
}
|
||||
}
|
@ -0,0 +1,17 @@
|
||||
package eu.mhsl.craftattack.spawn.appliances.yearRank;
|
||||
|
||||
import eu.mhsl.craftattack.spawn.appliance.ApplianceCommand;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class YearRankCommand extends ApplianceCommand<YearRank> {
|
||||
public YearRankCommand() {
|
||||
super("yearRank");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void execute(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, @NotNull String[] args) throws Exception {
|
||||
sender.sendMessage(getAppliance().listYearRanks());
|
||||
}
|
||||
}
|
@ -38,4 +38,5 @@ commands:
|
||||
vogelfrei:
|
||||
settings:
|
||||
texturepack:
|
||||
maintanance:
|
||||
maintanance:
|
||||
yearRank:
|
Loading…
x
Reference in New Issue
Block a user