Adding fight statistics #105
@ -9,10 +9,7 @@ import de.steamwar.fightsystem.kit.KitManager;
|
||||
import de.steamwar.fightsystem.listener.*;
|
||||
import de.steamwar.fightsystem.states.FightState;
|
||||
import de.steamwar.fightsystem.states.StateDependent;
|
||||
import de.steamwar.fightsystem.utils.FightScoreboard;
|
||||
import de.steamwar.fightsystem.utils.ITechHider;
|
||||
import de.steamwar.fightsystem.utils.TechHider;
|
||||
import de.steamwar.fightsystem.utils.WaterRemover;
|
||||
import de.steamwar.fightsystem.utils.*;
|
||||
import de.steamwar.fightsystem.winconditions.*;
|
||||
import de.steamwar.sql.EventFight;
|
||||
import org.bukkit.Bukkit;
|
||||
@ -158,6 +155,7 @@ public class FightSystem extends JavaPlugin {
|
||||
if(Config.Entern)
|
||||
mainCountdown = new EnternCountdown();
|
||||
|
||||
FightStatistics.start();
|
||||
WaterRemover.init();
|
||||
Bukkit.broadcastMessage(PREFIX + "§aArena freigegeben!");
|
||||
}
|
||||
@ -178,7 +176,7 @@ public class FightSystem extends JavaPlugin {
|
||||
}
|
||||
}
|
||||
|
||||
public static void setSpectateState(FightTeam winFightTeam) {
|
||||
public static void setSpectateState(FightTeam winFightTeam, String windescription) {
|
||||
if(!fightState.ingame())
|
||||
throw new SecurityException(fightState.name());
|
||||
setFightState(FightState.SPECTATE);
|
||||
@ -205,8 +203,10 @@ public class FightSystem extends JavaPlugin {
|
||||
getEventFight().setErgebnis(2);
|
||||
}
|
||||
|
||||
if(!Config.test())
|
||||
if(!Config.test()){
|
||||
new SpectateOverCountdown();
|
||||
FightStatistics.saveStats(winFightTeam, windescription);
|
||||
}
|
||||
}
|
||||
|
||||
public static void setFightTime(int fightTime) {
|
||||
|
@ -23,6 +23,6 @@ public class TechKOCountdown extends Countdown {
|
||||
@Override
|
||||
void countdownFinished() {
|
||||
Bukkit.broadcastMessage(FightSystem.PREFIX + team.getColoredName() + "§7 ist §eTech K§8.§eO§8.!");
|
||||
FightSystem.setSpectateState(Fight.getOpposite(team));
|
||||
FightSystem.setSpectateState(Fight.getOpposite(team), "TechKO");
|
||||
}
|
||||
}
|
||||
|
@ -11,6 +11,7 @@ public class FightPlayer {
|
||||
private final FightTeam team;
|
||||
private boolean isOut;
|
||||
private Kit kit;
|
||||
private int kills;
|
||||
|
||||
public void sendMessage(String message) {
|
||||
if (this.player != null && this.player.isOnline())
|
||||
@ -22,6 +23,7 @@ public class FightPlayer {
|
||||
this.team = team;
|
||||
this.isOut = false;
|
||||
kit = KitManager.getKitByName(Config.MemberDefault);
|
||||
kills = 0;
|
||||
}
|
||||
|
||||
public void setOut() {
|
||||
@ -52,4 +54,12 @@ public class FightPlayer {
|
||||
public FightTeam getTeam(){
|
||||
return team;
|
||||
}
|
||||
|
||||
public int getKills(){
|
||||
return kills;
|
||||
}
|
||||
|
||||
public void addKill(){
|
||||
kills++;
|
||||
}
|
||||
}
|
||||
|
@ -10,6 +10,7 @@ import org.bukkit.event.entity.EntityDamageByEntityEvent;
|
||||
import org.bukkit.event.entity.EntityDamageEvent;
|
||||
|
||||
import java.util.EnumSet;
|
||||
import java.util.Objects;
|
||||
|
||||
public class InFightDamageListener extends BasicListener {
|
||||
|
||||
@ -61,5 +62,9 @@ public class InFightDamageListener extends BasicListener {
|
||||
event.setCancelled(true);
|
||||
toActionbar(damager, TextComponent.fromLegacyText("§cDu darfst deinen Teamkollegen keinen Schaden zufügen!"));
|
||||
}
|
||||
|
||||
if(player.getHealth() - event.getFinalDamage() <= 0){
|
||||
Objects.requireNonNull(Fight.getFightPlayer(damager)).addKill();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,46 @@
|
||||
package de.steamwar.fightsystem.utils;
|
||||
|
||||
import de.steamwar.fightsystem.Config;
|
||||
import de.steamwar.fightsystem.FightSystem;
|
||||
import de.steamwar.fightsystem.fight.Fight;
|
||||
import de.steamwar.fightsystem.fight.FightPlayer;
|
||||
import de.steamwar.fightsystem.fight.FightTeam;
|
||||
import de.steamwar.sql.SteamwarUser;
|
||||
import org.bukkit.Bukkit;
|
||||
|
||||
import java.sql.Timestamp;
|
||||
import java.time.Instant;
|
||||
|
||||
import static de.steamwar.sql.Fight.create;
|
||||
|
||||
public class FightStatistics {
|
||||
private FightStatistics(){}
|
||||
|
||||
private static Timestamp starttime = Timestamp.from(Instant.now());
|
||||
|
||||
public static void start(){
|
||||
starttime = Timestamp.from(Instant.now());
|
||||
}
|
||||
|
||||
public static void saveStats(FightTeam winner, String windescription){
|
||||
SteamwarUser blueLeader = SteamwarUser.get(Fight.getBlueTeam().getLeader().getPlayer().getUniqueId());
|
||||
SteamwarUser redLeader = SteamwarUser.get(Fight.getRedTeam().getLeader().getPlayer().getUniqueId());
|
||||
int win = 0;
|
||||
if(winner == Fight.getBlueTeam())
|
||||
win = 1;
|
||||
else if(winner == Fight.getRedTeam())
|
||||
win = 2;
|
||||
int fightId = create(Config.SchematicType.toDB(), Bukkit.getWorlds().get(0).getName(), starttime, Config.TimeoutTime - FightSystem.getFightTime(),
|
||||
blueLeader.getId(), redLeader.getId(), Fight.getBlueTeam().getSchematic().getSchemID(), Fight.getRedTeam().getSchematic().getSchemID(), win, windescription);
|
||||
|
||||
for(FightPlayer fp : Fight.getBlueTeam().getPlayers())
|
||||
savePlayerStats(fp, fightId);
|
||||
for(FightPlayer fp : Fight.getRedTeam().getPlayers())
|
||||
savePlayerStats(fp, fightId);
|
||||
}
|
||||
|
||||
private static void savePlayerStats(FightPlayer fp, int fightId){
|
||||
SteamwarUser user = SteamwarUser.get(fp.getPlayer().getUniqueId());
|
||||
de.steamwar.sql.FightPlayer.create(fightId, user.getId(), fp.getKit().getName(), fp.getKills(), !fp.isLiving());
|
||||
}
|
||||
}
|
@ -29,7 +29,7 @@ public class EventTeamOffWincondition extends Wincondition {
|
||||
private void teamOff(FightTeam team){
|
||||
if(team.allPlayersOut()){
|
||||
Bukkit.broadcastMessage(FightSystem.PREFIX + "§6Das Team " + team.getColoredName() + " §6ist Offline!");
|
||||
FightSystem.setSpectateState(Fight.getOpposite(team));
|
||||
FightSystem.setSpectateState(Fight.getOpposite(team), "TeamOffline");
|
||||
}
|
||||
}
|
||||
}
|
@ -34,7 +34,7 @@ public class WinconditionAllDead extends PlayerWincondition {
|
||||
assert fightTeam != null; // Checked with isTarget
|
||||
if(fightTeam.allPlayersOut()) {
|
||||
Bukkit.broadcastMessage(FightSystem.PREFIX + "§cDer letzte Spieler aus " + fightTeam.getColoredName() + message);
|
||||
FightSystem.setSpectateState(Fight.getOpposite(fightTeam));
|
||||
FightSystem.setSpectateState(Fight.getOpposite(fightTeam), "AllDead");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -34,7 +34,7 @@ public class WinconditionCaptainDead extends PlayerWincondition {
|
||||
assert fightTeam != null; // Checked with isTarget
|
||||
if(fightTeam.isPlayerLeader(player)) {
|
||||
Bukkit.broadcastMessage(FightSystem.PREFIX + "§cDer Leader von " + fightTeam.getColoredName() + message);
|
||||
FightSystem.setSpectateState(Fight.getOpposite(fightTeam));
|
||||
FightSystem.setSpectateState(Fight.getOpposite(fightTeam), "LeaderDead");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -23,11 +23,11 @@ public class WinconditionHeartRatioTimeout extends Wincondition {
|
||||
double redHeartRatio = Fight.getRedTeam().getHeartRatio();
|
||||
|
||||
if(blueHeartRatio > redHeartRatio)
|
||||
FightSystem.setSpectateState(Fight.getBlueTeam());
|
||||
FightSystem.setSpectateState(Fight.getBlueTeam(), "HeartTimeout");
|
||||
else if(blueHeartRatio < redHeartRatio)
|
||||
FightSystem.setSpectateState(Fight.getRedTeam());
|
||||
FightSystem.setSpectateState(Fight.getRedTeam(), "HeartTimeout");
|
||||
else
|
||||
FightSystem.setSpectateState(null);
|
||||
FightSystem.setSpectateState(null, "HeartTimeout");
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -37,7 +37,7 @@ public class WinconditionPercentSystem extends ListenerWincondition {
|
||||
double destroyPercent = doubleBlueDestroyedBlocks * 100 / schematicSize;
|
||||
bluePercent = destroyPercent;
|
||||
if(destroyPercent >= Config.PercentWin) {
|
||||
FightSystem.setSpectateState(Fight.redTeam);
|
||||
FightSystem.setSpectateState(Fight.redTeam, "Percent");
|
||||
}
|
||||
//Team Red
|
||||
}else if(Region.isInRange(entity.getLocation(), Config.TeamRedCornerX, Config.TeamRedCornerY, Config.TeamRedCornerZ, Config.SchemsizeX, Config.SchemsizeY, Config.SchemsizeZ, Config.BorderFromSchematic)) {
|
||||
@ -46,7 +46,7 @@ public class WinconditionPercentSystem extends ListenerWincondition {
|
||||
double destroyPercent = doubleRedDestroyedBlocks * 100 / schematicSize;
|
||||
redPercent = destroyPercent;
|
||||
if(destroyPercent >= Config.PercentWin) {
|
||||
FightSystem.setSpectateState(Fight.blueTeam);
|
||||
FightSystem.setSpectateState(Fight.blueTeam, "Percent");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -80,11 +80,11 @@ public class WinconditionPoints extends PlayerWincondition {
|
||||
|
||||
private void fightEnds(){
|
||||
if(red.getPoints() > blue.getPoints())
|
||||
FightSystem.setSpectateState(blue.enemy);
|
||||
FightSystem.setSpectateState(blue.enemy, "Points");
|
||||
else if(red.getPoints() < blue.getPoints())
|
||||
FightSystem.setSpectateState(red.enemy);
|
||||
FightSystem.setSpectateState(red.enemy, "Points");
|
||||
else
|
||||
FightSystem.setSpectateState(null);
|
||||
FightSystem.setSpectateState(null, "Points");
|
||||
}
|
||||
|
||||
private TeamPoints getEnemyByTeam(FightTeam team){
|
||||
|
@ -76,7 +76,7 @@ public class WinconditionPumpkinTechKO extends Wincondition {
|
||||
private static void checkKO(FightTeam team, int pumpkins){
|
||||
if(pumpkins == 0){
|
||||
Bukkit.broadcastMessage(FightSystem.PREFIX + "§eDas Team " + team.getColoredName() + " §eist Tech K.O.!");
|
||||
Bukkit.getScheduler().runTask(FightSystem.getPlugin(), () -> FightSystem.setSpectateState(Fight.getOpposite(team)));
|
||||
Bukkit.getScheduler().runTask(FightSystem.getPlugin(), () -> FightSystem.setSpectateState(Fight.getOpposite(team), "PumpkinTechKO"));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -105,7 +105,7 @@ public class WinconditionRelativePercent extends Wincondition{
|
||||
return;
|
||||
if(getPercent() * 100 >= Config.PercentWin){
|
||||
Bukkit.broadcastMessage(FightSystem.PREFIX + "§cDer Schiff von " + team.getColoredName() + " §cwurde zu stark beschädigt!");
|
||||
FightSystem.setSpectateState(Fight.getOpposite(team));
|
||||
FightSystem.setSpectateState(Fight.getOpposite(team), "RelativePercent");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -17,7 +17,7 @@ public class WinconditionTimeout extends Wincondition {
|
||||
|
||||
@Override
|
||||
public void enable() {
|
||||
countdown = new TimeOverCountdown(() -> FightSystem.setSpectateState(null));
|
||||
countdown = new TimeOverCountdown(() -> FightSystem.setSpectateState(null, "Timeout"));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -63,7 +63,7 @@ public class WinconditionWaterTechKO extends Wincondition {
|
||||
private void checkEmpty(FightTeam team, Set<Location> teamWater){
|
||||
if(teamWater.isEmpty()){
|
||||
Bukkit.broadcastMessage(FightSystem.PREFIX + "§eDas Team " + team.getColoredName() + " §eist Tech K.O.!");
|
||||
Bukkit.getScheduler().runTask(FightSystem.getPlugin(), () -> FightSystem.setSpectateState(Fight.getOpposite(team)));
|
||||
Bukkit.getScheduler().runTask(FightSystem.getPlugin(), () -> FightSystem.setSpectateState(Fight.getOpposite(team), "WaterTechKO"));
|
||||
}
|
||||
}
|
||||
|
||||
|
In neuem Issue referenzieren
Einen Benutzer sperren