SteamWar/FightSystem
Archiviert
13
1

Adding fight statistics #105

Zusammengeführt
Lixfel hat 1 Commits von statistics nach master 2020-01-26 08:39:42 +01:00 zusammengeführt
15 geänderte Dateien mit 83 neuen und 22 gelöschten Zeilen
Nur Änderungen aus Commit e053ecf286 werden angezeigt - Alle Commits anzeigen

Datei anzeigen

@ -9,10 +9,7 @@ import de.steamwar.fightsystem.kit.KitManager;
import de.steamwar.fightsystem.listener.*; import de.steamwar.fightsystem.listener.*;
import de.steamwar.fightsystem.states.FightState; import de.steamwar.fightsystem.states.FightState;
import de.steamwar.fightsystem.states.StateDependent; import de.steamwar.fightsystem.states.StateDependent;
import de.steamwar.fightsystem.utils.FightScoreboard; import de.steamwar.fightsystem.utils.*;
import de.steamwar.fightsystem.utils.ITechHider;
import de.steamwar.fightsystem.utils.TechHider;
import de.steamwar.fightsystem.utils.WaterRemover;
import de.steamwar.fightsystem.winconditions.*; import de.steamwar.fightsystem.winconditions.*;
import de.steamwar.sql.EventFight; import de.steamwar.sql.EventFight;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
@ -158,6 +155,7 @@ public class FightSystem extends JavaPlugin {
if(Config.Entern) if(Config.Entern)
mainCountdown = new EnternCountdown(); mainCountdown = new EnternCountdown();
FightStatistics.start();
WaterRemover.init(); WaterRemover.init();
Bukkit.broadcastMessage(PREFIX + "§aArena freigegeben!"); 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()) if(!fightState.ingame())
throw new SecurityException(fightState.name()); throw new SecurityException(fightState.name());
setFightState(FightState.SPECTATE); setFightState(FightState.SPECTATE);
@ -205,8 +203,10 @@ public class FightSystem extends JavaPlugin {
getEventFight().setErgebnis(2); getEventFight().setErgebnis(2);
} }
if(!Config.test()) if(!Config.test()){
new SpectateOverCountdown(); new SpectateOverCountdown();
FightStatistics.saveStats(winFightTeam, windescription);
}
} }
public static void setFightTime(int fightTime) { public static void setFightTime(int fightTime) {

Datei anzeigen

@ -23,6 +23,6 @@ public class TechKOCountdown extends Countdown {
@Override @Override
void countdownFinished() { void countdownFinished() {
Bukkit.broadcastMessage(FightSystem.PREFIX + team.getColoredName() + "§7 ist §eTech K§8.§eO§8.!"); Bukkit.broadcastMessage(FightSystem.PREFIX + team.getColoredName() + "§7 ist §eTech K§8.§eO§8.!");
FightSystem.setSpectateState(Fight.getOpposite(team)); FightSystem.setSpectateState(Fight.getOpposite(team), "TechKO");
} }
} }

Datei anzeigen

@ -11,6 +11,7 @@ public class FightPlayer {
private final FightTeam team; private final FightTeam team;
private boolean isOut; private boolean isOut;
private Kit kit; private Kit kit;
private int kills;
public void sendMessage(String message) { public void sendMessage(String message) {
if (this.player != null && this.player.isOnline()) if (this.player != null && this.player.isOnline())
@ -22,6 +23,7 @@ public class FightPlayer {
this.team = team; this.team = team;
this.isOut = false; this.isOut = false;
kit = KitManager.getKitByName(Config.MemberDefault); kit = KitManager.getKitByName(Config.MemberDefault);
kills = 0;
} }
public void setOut() { public void setOut() {
@ -52,4 +54,12 @@ public class FightPlayer {
public FightTeam getTeam(){ public FightTeam getTeam(){
return team; return team;
} }
public int getKills(){
return kills;
}
public void addKill(){
kills++;
}
} }

Datei anzeigen

@ -10,6 +10,7 @@ import org.bukkit.event.entity.EntityDamageByEntityEvent;
import org.bukkit.event.entity.EntityDamageEvent; import org.bukkit.event.entity.EntityDamageEvent;
import java.util.EnumSet; import java.util.EnumSet;
import java.util.Objects;
public class InFightDamageListener extends BasicListener { public class InFightDamageListener extends BasicListener {
@ -61,5 +62,9 @@ public class InFightDamageListener extends BasicListener {
event.setCancelled(true); event.setCancelled(true);
toActionbar(damager, TextComponent.fromLegacyText("§cDu darfst deinen Teamkollegen keinen Schaden zufügen!")); toActionbar(damager, TextComponent.fromLegacyText("§cDu darfst deinen Teamkollegen keinen Schaden zufügen!"));
} }
if(player.getHealth() - event.getFinalDamage() <= 0){
Objects.requireNonNull(Fight.getFightPlayer(damager)).addKill();
}
} }
} }

Datei anzeigen

@ -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());
}
}

Datei anzeigen

@ -29,7 +29,7 @@ public class EventTeamOffWincondition extends Wincondition {
private void teamOff(FightTeam team){ private void teamOff(FightTeam team){
if(team.allPlayersOut()){ if(team.allPlayersOut()){
Bukkit.broadcastMessage(FightSystem.PREFIX + "§6Das Team " + team.getColoredName() + " §6ist Offline!"); Bukkit.broadcastMessage(FightSystem.PREFIX + "§6Das Team " + team.getColoredName() + " §6ist Offline!");
FightSystem.setSpectateState(Fight.getOpposite(team)); FightSystem.setSpectateState(Fight.getOpposite(team), "TeamOffline");
} }
} }
} }

Datei anzeigen

@ -34,7 +34,7 @@ public class WinconditionAllDead extends PlayerWincondition {
assert fightTeam != null; // Checked with isTarget assert fightTeam != null; // Checked with isTarget
if(fightTeam.allPlayersOut()) { if(fightTeam.allPlayersOut()) {
Bukkit.broadcastMessage(FightSystem.PREFIX + "§cDer letzte Spieler aus " + fightTeam.getColoredName() + message); Bukkit.broadcastMessage(FightSystem.PREFIX + "§cDer letzte Spieler aus " + fightTeam.getColoredName() + message);
FightSystem.setSpectateState(Fight.getOpposite(fightTeam)); FightSystem.setSpectateState(Fight.getOpposite(fightTeam), "AllDead");
} }
} }
} }

Datei anzeigen

@ -34,7 +34,7 @@ public class WinconditionCaptainDead extends PlayerWincondition {
assert fightTeam != null; // Checked with isTarget assert fightTeam != null; // Checked with isTarget
if(fightTeam.isPlayerLeader(player)) { if(fightTeam.isPlayerLeader(player)) {
Bukkit.broadcastMessage(FightSystem.PREFIX + "§cDer Leader von " + fightTeam.getColoredName() + message); Bukkit.broadcastMessage(FightSystem.PREFIX + "§cDer Leader von " + fightTeam.getColoredName() + message);
FightSystem.setSpectateState(Fight.getOpposite(fightTeam)); FightSystem.setSpectateState(Fight.getOpposite(fightTeam), "LeaderDead");
} }
} }
} }

Datei anzeigen

@ -23,11 +23,11 @@ public class WinconditionHeartRatioTimeout extends Wincondition {
double redHeartRatio = Fight.getRedTeam().getHeartRatio(); double redHeartRatio = Fight.getRedTeam().getHeartRatio();
if(blueHeartRatio > redHeartRatio) if(blueHeartRatio > redHeartRatio)
FightSystem.setSpectateState(Fight.getBlueTeam()); FightSystem.setSpectateState(Fight.getBlueTeam(), "HeartTimeout");
else if(blueHeartRatio < redHeartRatio) else if(blueHeartRatio < redHeartRatio)
FightSystem.setSpectateState(Fight.getRedTeam()); FightSystem.setSpectateState(Fight.getRedTeam(), "HeartTimeout");
else else
FightSystem.setSpectateState(null); FightSystem.setSpectateState(null, "HeartTimeout");
}); });
} }

Datei anzeigen

@ -37,7 +37,7 @@ public class WinconditionPercentSystem extends ListenerWincondition {
double destroyPercent = doubleBlueDestroyedBlocks * 100 / schematicSize; double destroyPercent = doubleBlueDestroyedBlocks * 100 / schematicSize;
bluePercent = destroyPercent; bluePercent = destroyPercent;
if(destroyPercent >= Config.PercentWin) { if(destroyPercent >= Config.PercentWin) {
FightSystem.setSpectateState(Fight.redTeam); FightSystem.setSpectateState(Fight.redTeam, "Percent");
} }
//Team Red //Team Red
}else if(Region.isInRange(entity.getLocation(), Config.TeamRedCornerX, Config.TeamRedCornerY, Config.TeamRedCornerZ, Config.SchemsizeX, Config.SchemsizeY, Config.SchemsizeZ, Config.BorderFromSchematic)) { }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; double destroyPercent = doubleRedDestroyedBlocks * 100 / schematicSize;
redPercent = destroyPercent; redPercent = destroyPercent;
if(destroyPercent >= Config.PercentWin) { if(destroyPercent >= Config.PercentWin) {
FightSystem.setSpectateState(Fight.blueTeam); FightSystem.setSpectateState(Fight.blueTeam, "Percent");
} }
} }
} }

Datei anzeigen

@ -80,11 +80,11 @@ public class WinconditionPoints extends PlayerWincondition {
private void fightEnds(){ private void fightEnds(){
if(red.getPoints() > blue.getPoints()) if(red.getPoints() > blue.getPoints())
FightSystem.setSpectateState(blue.enemy); FightSystem.setSpectateState(blue.enemy, "Points");
else if(red.getPoints() < blue.getPoints()) else if(red.getPoints() < blue.getPoints())
FightSystem.setSpectateState(red.enemy); FightSystem.setSpectateState(red.enemy, "Points");
else else
FightSystem.setSpectateState(null); FightSystem.setSpectateState(null, "Points");
} }
private TeamPoints getEnemyByTeam(FightTeam team){ private TeamPoints getEnemyByTeam(FightTeam team){

Datei anzeigen

@ -76,7 +76,7 @@ public class WinconditionPumpkinTechKO extends Wincondition {
private static void checkKO(FightTeam team, int pumpkins){ private static void checkKO(FightTeam team, int pumpkins){
if(pumpkins == 0){ if(pumpkins == 0){
Bukkit.broadcastMessage(FightSystem.PREFIX + "§eDas Team " + team.getColoredName() + " §eist Tech K.O.!"); 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"));
} }
} }
} }

Datei anzeigen

@ -105,7 +105,7 @@ public class WinconditionRelativePercent extends Wincondition{
return; return;
if(getPercent() * 100 >= Config.PercentWin){ if(getPercent() * 100 >= Config.PercentWin){
Bukkit.broadcastMessage(FightSystem.PREFIX + "§cDer Schiff von " + team.getColoredName() + " §cwurde zu stark beschädigt!"); 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");
} }
} }
} }

Datei anzeigen

@ -17,7 +17,7 @@ public class WinconditionTimeout extends Wincondition {
@Override @Override
public void enable() { public void enable() {
countdown = new TimeOverCountdown(() -> FightSystem.setSpectateState(null)); countdown = new TimeOverCountdown(() -> FightSystem.setSpectateState(null, "Timeout"));
} }
@Override @Override

Datei anzeigen

@ -63,7 +63,7 @@ public class WinconditionWaterTechKO extends Wincondition {
private void checkEmpty(FightTeam team, Set<Location> teamWater){ private void checkEmpty(FightTeam team, Set<Location> teamWater){
if(teamWater.isEmpty()){ if(teamWater.isEmpty()){
Bukkit.broadcastMessage(FightSystem.PREFIX + "§eDas Team " + team.getColoredName() + " §eist Tech K.O.!"); 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"));
} }
} }