Skip to content

Commit

Permalink
Sidebar and Tab improvements, session stats remake (#845)
Browse files Browse the repository at this point in the history
tab rework, sidebar imrovements, new top system and session statistics
  • Loading branch information
andrei1058 authored Oct 28, 2023
1 parent 22ec7e5 commit 6f4433a
Show file tree
Hide file tree
Showing 76 changed files with 9,580 additions and 1,513 deletions.
2 changes: 1 addition & 1 deletion bedwars-api/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<artifactId>BedWars1058</artifactId>
<groupId>com.andrei1058.bedwars</groupId>
<version>23.7-SNAPSHOT</version>
<version>23.10-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>bedwars-api</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
package com.andrei1058.bedwars.api.arena;

import com.andrei1058.bedwars.api.arena.generator.IGenerator;
import com.andrei1058.bedwars.api.arena.stats.GameStatsHolder;
import com.andrei1058.bedwars.api.arena.team.ITeam;
import com.andrei1058.bedwars.api.arena.team.ITeamAssigner;
import com.andrei1058.bedwars.api.configuration.ConfigManager;
Expand All @@ -37,12 +38,10 @@
import org.jetbrains.annotations.Nullable;

import java.time.Instant;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.UUID;
import java.util.*;
import java.util.concurrent.ConcurrentHashMap;

@SuppressWarnings("unused")
public interface IArena {

/**
Expand Down Expand Up @@ -265,13 +264,22 @@ public interface IArena {
* @param p Target player
* @param finalKills True if you want to get the Final Kills. False for regular kills.
*/
@Deprecated
int getPlayerKills(Player p, boolean finalKills);

/**
* Session stats.
* @return stats container for this game.
*/
@Nullable
GameStatsHolder getStatsHolder();

/**
* Get the player beds destroyed count
*
* @param p Target player
*/
@Deprecated
int getPlayerBedsDestroyed(Player p);

/**
Expand Down Expand Up @@ -319,11 +327,13 @@ default boolean isRespawning(Player p) {
/**
* Add a kill point to the game stats.
*/
@Deprecated
void addPlayerKill(Player p, boolean finalKill, Player victim);

/**
* Add a destroyed bed point to the player temp stats.
*/
@Deprecated
void addPlayerBedDestroyed(Player p);


Expand All @@ -344,6 +354,7 @@ default boolean isRespawning(Player p) {
/**
* Add a kill to the player temp stats.
*/
@Deprecated
void addPlayerDeath(Player p);

/**
Expand Down Expand Up @@ -393,6 +404,7 @@ default boolean isRespawning(Player p) {
/**
* Get player deaths.
*/
@Deprecated
int getPlayerDeaths(Player p, boolean finalDeaths);

/**
Expand Down Expand Up @@ -501,6 +513,7 @@ default boolean isRespawning(Player p) {
* Check if breaking map is allowed, otherwise only placed blocks are allowed.
* Some blocks like have a special protections, like blocks under shopkeepers, bed, ecc.
*/
@SuppressWarnings("BooleanMethodIsAlwaysInverted")
boolean isAllowMapBreak();

/**
Expand All @@ -517,4 +530,10 @@ default boolean isRespawning(Player p) {
* Get owner team of a bed based on location.
*/
@Nullable ITeam getBedsTeam(Location location);

/**
* Provides the winner team.
* This is populated on restarting phase.
*/
@Nullable ITeam getWinner();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package com.andrei1058.bedwars.api.arena.stats;

import org.jetbrains.annotations.NotNull;

@SuppressWarnings("SpellCheckingInspection")
public enum DefaultStatistics {

KILLS("kills", true),
KILLS_FINAL("finalKills", true),
DEATHS("deaths", true),
DEATHS_FINAL("finalDeaths", true),
BEDS_DESTROYED("bedsDestroyed", true);

private final String id;
private final boolean incrementable;
DefaultStatistics(String id, boolean incrementable) {
this.id = id;
this.incrementable = incrementable;
}

@Override
public @NotNull String toString() {
return id;
}

public boolean isIncrementable() {
return incrementable;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package com.andrei1058.bedwars.api.arena.stats;

import com.andrei1058.bedwars.api.language.Language;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

/**
* Game statistic.
* @param <T> statistic type. We usually work with integers.
*/
public interface GameStatistic<T> extends Comparable<GameStatistic<T>> {

/**
* Current value.
*/
T getValue();

/**
* Value displayed in tops etc.
* @param language - message receiver.
*/
String getDisplayValue(@Nullable Language language);

/**
* Comparison for tops.
* @param o the object to be compared.
*/
int compareTo(@NotNull GameStatistic<T> o);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package com.andrei1058.bedwars.api.arena.stats;

import com.andrei1058.bedwars.api.language.Language;
import org.bukkit.plugin.Plugin;
import org.jetbrains.annotations.Nullable;

public interface GameStatisticProvider<T extends GameStatistic<?>> {

/**
* Unique statistic identifier.
*/
String getIdentifier();

/**
* Plugin provider.
* @return statistic owner.
*/
Plugin getOwner();

/**
* Default value used when initializing game stats.
*/
T getDefault();

/**
* Display value for undetermined values.
* @param language desired translation.
*/
String getVoidReplacement(@Nullable Language language);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
package com.andrei1058.bedwars.api.arena.stats;

import com.andrei1058.bedwars.api.arena.IArena;
import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import java.util.Collection;
import java.util.List;
import java.util.Optional;
import java.util.UUID;

@SuppressWarnings("unused")
public interface GameStatsHolder {

IArena getArena();

/**
* Register statistic.
* Throws a runtime exception if statistic is already registered.
* @param statistic new statistic.
*/
void register(@NotNull GameStatisticProvider<?> statistic);

/**
* Initialize game session stats for given player.
* @param player stats holder.
*/
PlayerGameStats init(Player player);

/**
* Remove player tracked data.
* @param uuid holder.
*/
void unregisterPlayer(UUID uuid);

/**
* Get existing or initialize statistic for given player.
* @param holder player holder.
* @return Existing or new statistic.
*/
@NotNull PlayerGameStats getCreate(@NotNull Player holder);

/**
* Get existing or initialize statistic for given player.
* @param holder player holder.
* @return Existing or new statistic.
*/
Optional<PlayerGameStats> get(@NotNull UUID holder);

/**
* Get existing or initialize statistic for given player.
* @param holder player holder.
* @return Existing or new statistic.
*/
default Optional<PlayerGameStats> get(@NotNull Player holder) {
return get(holder.getUniqueId());
}

/**
* Get tracked players.
*
* @return Unmodifiable list of tracked players.
*/
Collection<Optional<PlayerGameStats>> getTrackedPlayers();


/**
* @param statistic Order collection by given statistic.
* @return top list.
*/
default Collection<Optional<PlayerGameStats>> getOrderedBy(@NotNull DefaultStatistics statistic) {
return getOrderedBy(statistic.toString());
}

/**
* @param statistic Order collection by given statistic.
* @return top list.
*/
List<Optional<PlayerGameStats>> getOrderedBy(@NotNull String statistic);

/**
* Check if given statistic is registered.
*/
boolean hasStatistic(String orderBy);

/**
* @return unmodifiable list of registered game statistics.
*/
List<String> getRegistered();

/**
* Get statistic provider.
*/
@Nullable GameStatisticProvider<?> getProvider(String registered);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package com.andrei1058.bedwars.api.arena.stats;

public interface Incrementable {

void increment();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package com.andrei1058.bedwars.api.arena.stats;

import org.jetbrains.annotations.NotNull;

import java.util.List;
import java.util.Optional;
import java.util.UUID;

/**
* Player stats container for a game.
*/
public interface PlayerGameStats {

@NotNull UUID getPlayer();

/**
* @return player display name.
*/
@NotNull String getDisplayPlayer();

/**
* @return player username.
*/
@NotNull String getUsername();

void registerStatistic(@NotNull String id, @NotNull GameStatistic<?> defaultValue);

Optional<GameStatistic<?>> getStatistic(@NotNull String id);

default Optional<GameStatistic<?>> getStatistic(@NotNull DefaultStatistics id) {
return getStatistic(id.toString());
}

/**
* List of registered statistics.
*/
@SuppressWarnings("unused")
List<String> getRegistered();
}
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,11 @@

public interface ITeam {

/**
* Runtime identifier.
*/
UUID getIdentity();

/**
* Get team color.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ public class ConfigManager {
*/
public ConfigManager(Plugin plugin, String name, String dir) {
File d = new File(dir);

if (!d.exists()) {
if (!d.mkdirs()) {
plugin.getLogger().log(Level.SEVERE, "Could not create " + d.getPath());
Expand Down
Loading

0 comments on commit 6f4433a

Please sign in to comment.