SteamWar/FightSystem
Archiviert
13
1

The big refactoring #238

Manuell gemergt
Lixfel hat 16 Commits von refactoring nach master 2021-03-31 20:08:07 +02:00 zusammengeführt
26 geänderte Dateien mit 534 neuen und 456 gelöschten Zeilen
Nur Änderungen aus Commit 7268be7de9 werden angezeigt - Alle Commits anzeigen

Datei anzeigen

@ -19,6 +19,7 @@
package de.steamwar.fightsystem;
import de.steamwar.fightsystem.winconditions.Winconditions;
import de.steamwar.sql.Event;
import de.steamwar.sql.EventFight;
import de.steamwar.sql.Team;
@ -33,6 +34,7 @@ import org.bukkit.util.Vector;
import java.io.File;
import java.util.*;
import java.util.logging.Level;
import java.util.stream.Collectors;
public class Config {
@ -104,16 +106,7 @@ public class Config {
public static final boolean Ranked;
//Active win conditions
public static final boolean Timeout;
public static final boolean HeartRatioTimeout;
public static final boolean AllDead;
public static final boolean CaptainDead;
public static final boolean PercentSystem;
public static final boolean RelativePercent;
public static final boolean Points;
public static final boolean TechKO;
public static final boolean WaterTechKO;
public static final boolean PumpkinTechKO;
public static final Set<Winconditions> ActiveWinconditions;
//win condition parameters
public static final int TimeoutTime;
@ -202,16 +195,7 @@ public class Config {
GameName = config.getString("Output.GameName");
TeamChatDetection = config.getString("Output.TeamChatDetection");
Timeout = config.getBoolean("WinConditions.Timeout");
HeartRatioTimeout = config.getBoolean("WinConditions.HeartRatioTimeout");
AllDead = config.getBoolean("WinConditions.AllDead");
CaptainDead = config.getBoolean("WinConditions.CaptainDead");
PercentSystem = config.getBoolean("WinConditions.PercentSystem");
RelativePercent = config.getBoolean("WinConditions.RelativePercent");
Points = config.getBoolean("WinConditions.Points");
TechKO = config.getBoolean("WinConditions.TechKO");
WaterTechKO = config.getBoolean("WinConditions.WaterTechKO");
PumpkinTechKO = config.getBoolean("WinConditions.PumpkinTechKO");
ActiveWinconditions = config.getStringList("WinConditions").stream().map(Winconditions::valueOf).collect(Collectors.toSet());
TimeoutTime = config.getInt("WinConditionParams.TimeoutTime");
PercentWin = config.getDouble("WinConditionParams.PercentWin");

Datei anzeigen

@ -0,0 +1,34 @@
/*
This file is a part of the SteamWar software.
Copyright (C) 2020 SteamWar.de-Serverteam
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package de.steamwar.fightsystem.winconditions;
public enum Winconditions {
TIMEOUT,
HEART_RATIO_TIMEOUT,
PERCENT_TIMEOUT,
ALL_DEAD,
CAPTAIN_DEAD,
PERCENT_SYSTEM,
RELATIVE_PERCENT,
POINTS,
TIME_TECH_KO,
WATER_TECH_KO,
PUMPKIN_TECH_KO
}

Datei anzeigen

@ -96,8 +96,10 @@ public class FightSystem extends JavaPlugin {
new WinconditionPoints();
new WinconditionTimeout();
new WinconditionHeartRatioTimeout();
new WinconditionTechKO();
new WinconditionTimeTechKO();
new EventTeamOffWincondition();
new RankedPlayerLeftWincondition();
new WinconditionPercentTimeout();
new NoPlayersOnlineCountdown();
new PreSchemPasteCountdown();

Datei anzeigen

@ -25,14 +25,11 @@ import org.bukkit.Bukkit;
public class TimeOverCountdown extends Countdown {
private static TimeOverCountdown instance = null;
private final Runnable timeOver;
public TimeOverCountdown(Runnable timeOver) {
super(Config.TimeoutTime, SWSound.BLOCK_NOTE_BASS, false);
this.timeOver = timeOver;
instance = this;
enable();
}
@ -46,10 +43,4 @@ public class TimeOverCountdown extends Countdown {
Bukkit.broadcastMessage(FightSystem.PREFIX +"§aZeit abgelaufen!");
timeOver.run();
}
public static int getRemainingTime(){
if(instance == null)
return -1;
return instance.getTimeLeft();
}
}

Datei anzeigen

@ -1,3 +1,22 @@
/*
This file is a part of the SteamWar software.
Copyright (C) 2020 SteamWar.de-Serverteam
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package de.steamwar.fightsystem.fight;
import com.sk89q.worldedit.EditSession;

Datei anzeigen

@ -29,7 +29,6 @@ import de.steamwar.fightsystem.states.FightState;
import de.steamwar.fightsystem.utils.FightScoreboard;
import de.steamwar.fightsystem.utils.ItemBuilder;
import de.steamwar.fightsystem.utils.TechHider;
import de.steamwar.fightsystem.winconditions.RankedPlayerLeftWincondition;
import de.steamwar.inventory.SWItem;
import de.steamwar.sql.Schematic;
import de.steamwar.sql.SteamwarUser;
@ -204,9 +203,7 @@ public class FightTeam implements IFightTeam{
if(!players.isEmpty()) {
setLeader(players.values().iterator().next());
Bukkit.broadcastMessage(FightSystem.PREFIX + "§aDer Spieler §e" + this.leader.getPlayer().getName() + " §aist nun Leader von Team " + getColoredName() + "§a!");
}else if(Config.Ranked){
RankedPlayerLeftWincondition.leaderQuit(this);
}else if(!Config.event()){
}else if(!Config.event() && !Config.Ranked){
FightSystem.shutdown(FightSystem.PREFIX + "§cTeam " + getColoredName() + " §chat keine Spieler mehr.\n Arena schließt...");
}
return;

Datei anzeigen

@ -34,11 +34,10 @@ import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import org.bukkit.scoreboard.Scoreboard;
import java.util.EnumSet;
import java.util.HashMap;
import java.util.Set;
import java.util.*;
public class FightScoreboard {
private FightScoreboard(){}
private static final Set<FightState> fullScoreboard = EnumSet.of(FightState.RUNNING, FightState.SPECTATE);
private static int index = 0;
@ -72,9 +71,7 @@ public class FightScoreboard {
}
private static void teamScoreboard(FightTeam fightTeam){
title = fightTeam.getColoredName();
if(Config.recording())
RecordSystem.scoreboardTitle(title);
setTitle(fightTeam.getColoredName());
fightTeam.getPlayers().forEach(fp -> {
if(fp.isLiving())
addScore(fightTeam.getPrefix() + fp.getPlayer().getName(), (int) Math.ceil(fp.getPlayer().getHealth()));
@ -82,37 +79,31 @@ public class FightScoreboard {
}
private static void generalScoreboard(){
title = "§6Kampf";
if(Config.recording())
RecordSystem.scoreboardTitle(title);
int fightTime = TimeOverCountdown.getRemainingTime();
if (fightTime != -1) {
setTitle("§eKampf");
List<String> scores = new ArrayList<>();
TimeOverCountdown timeOverCountdown = TimeoutWincondition.getTimeOverCountdown();
if(timeOverCountdown != null){
int fightTime = timeOverCountdown.getTimeLeft();
if (fightTime >= 60)
addScore("§7Zeit: §a" + fightTime / 60 + "m " + fightTime % 60 + "s", 4);
scores.add("§7Zeit: §a" + fightTime / 60 + "m " + fightTime % 60 + "s");
else
addScore("§7Zeit: §a" + fightTime + "s", 4);
scores.add("§7Zeit: §a" + fightTime + "s");
}
addScore("§7TPS: §e" + TPSWatcher.getTPS(), 3);
scores.add("§7TPS: §e" + TPSWatcher.getTPS());
if(fullScoreboard.contains(FightState.getFightState())){
if (Config.PercentSystem){
addScore(Fight.getRedTeam().getPrefix() + "Schaden: " + (Math.round(100.0 * WinconditionPercentSystem.getRedPercent()) / 100.0) + "%", 1);
addScore(Fight.getBlueTeam().getPrefix() + "Schaden: " + (Math.round(100.0 * WinconditionPercentSystem.getBluePercent()) / 100.0) + "%", 0);
}else if(Config.WaterTechKO){
addScore(Fight.getRedTeam().getPrefix() + "Wasser: " + WinconditionWaterTechKO.getTeamRedWater(), 1);
addScore(Fight.getBlueTeam().getPrefix() + "Wasser: " + WinconditionWaterTechKO.getTeamBlueWater(), 0);
}else if(Config.RelativePercent){
addScore(Fight.getRedTeam().getPrefix() + "Schaden: " + WinconditionRelativePercent.getRed().getPrintablePercent() + "%", 1);
addScore(Fight.getBlueTeam().getPrefix() + "Schaden: " + WinconditionRelativePercent.getBlue().getPrintablePercent() + "%", 0);
}else if(Config.Points){
addScore(Fight.getRedTeam().getPrefix() + "Punkte: " + WinconditionPoints.getRed().getPoints(), 1);
addScore(Fight.getBlueTeam().getPrefix() + "Punkte: " + WinconditionPoints.getBlue().getPoints(), 0);
}else if(Config.PumpkinTechKO){
addScore(Fight.getRedTeam().getPrefix() + "Kanonen: " + WinconditionPumpkinTechKO.getTeamRedPumpkins(), 1);
addScore(Fight.getBlueTeam().getPrefix() + "Kanonen: " + WinconditionPumpkinTechKO.getTeamBluePumpkins(), 0);
for(PrintableWincondition wincondition : Wincondition.getPrintableWinconditions()){
scores.add(wincondition.getDisplay(Fight.getRedTeam()));
scores.add(wincondition.getDisplay(Fight.getBlueTeam()));
}
}
int value = scores.size();
for(String score : scores){
addScore(score, value--);
}
}
private static void nextIndexDisplay() {
@ -131,6 +122,12 @@ public class FightScoreboard {
generalScoreboard();
}
private static void setTitle(String t) {
title = t;
if(Config.recording())
RecordSystem.scoreboardTitle(t);
}
private static void addScore(String string, int i) {
if(Config.recording())
RecordSystem.scoreboardData(string, i);

Datei anzeigen

@ -25,6 +25,7 @@ import de.steamwar.fightsystem.countdown.TimeOverCountdown;
import de.steamwar.fightsystem.fight.Fight;
import de.steamwar.fightsystem.fight.FightPlayer;
import de.steamwar.fightsystem.fight.FightTeam;
import de.steamwar.fightsystem.winconditions.TimeoutWincondition;
import de.steamwar.sql.Elo;
import de.steamwar.sql.Schematic;
import de.steamwar.sql.SteamwarUser;
@ -76,8 +77,14 @@ public class FightStatistics {
redSchem = null;
}
int remainingTime = 0;
TimeOverCountdown timeOverCountdown = TimeoutWincondition.getTimeOverCountdown();
if(timeOverCountdown != null){
remainingTime = timeOverCountdown.getTimeLeft();
}
try {
int fightId = create(gameMode, Bukkit.getWorlds().get(0).getName(), starttime, TimeOverCountdown.getRemainingTime(),
int fightId = create(gameMode, Bukkit.getWorlds().get(0).getName(), starttime, remainingTime,
blueLeader.getId(), redLeader.getId(), blueSchem, redSchem, win, windescription);
for (FightPlayer fp : Fight.getBlueTeam().getPlayers())

Datei anzeigen

@ -20,25 +20,27 @@
package de.steamwar.fightsystem.winconditions;
import de.steamwar.fightsystem.Config;
import de.steamwar.fightsystem.FightSystem;
import de.steamwar.fightsystem.fight.Fight;
import de.steamwar.fightsystem.fight.FightTeam;
import de.steamwar.fightsystem.states.FightState;
import org.bukkit.Bukkit;
import java.util.EnumSet;
public class EventTeamOffWincondition extends Wincondition {
public EventTeamOffWincondition(){
super(Config.event(), EnumSet.of(FightState.PRE_RUNNING));
super(Config.event(), EnumSet.of(FightState.PRE_RUNNING), "TeamOffline");
}
@Override
public void enable() {
if(Fight.getBlueTeam().allPlayersOut() && Fight.getRedTeam().allPlayersOut()){
win(null, null, null, "§cBeide Teams sind offline!");
}else{
teamOff(Fight.getBlueTeam());
teamOff(Fight.getRedTeam());
}
}
@Override
public void disable() {
@ -47,8 +49,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), "TeamOffline");
win(Fight.getOpposite(team), "§cDas Team ", " §cist offline!");
}
}
}

Datei anzeigen

@ -29,9 +29,12 @@ import java.util.Set;
abstract class ListenerWincondition extends Wincondition implements Listener {
ListenerWincondition(boolean condition, Set<FightState> enabled){
//If the condition is not met, never enable
super(condition, enabled);
protected ListenerWincondition(Winconditions condition, Set<FightState> enabled, String windescription){
super(condition, enabled, windescription);
}
protected ListenerWincondition(boolean condition, Set<FightState> enabled, String windescription) {
super(condition, enabled, windescription);
}
/**

Datei anzeigen

@ -0,0 +1,7 @@
package de.steamwar.fightsystem.winconditions;
import de.steamwar.fightsystem.fight.FightTeam;
public interface PercentWincondition {
double getPercent(FightTeam team);
}

Datei anzeigen

@ -19,25 +19,8 @@
package de.steamwar.fightsystem.winconditions;
import de.steamwar.fightsystem.fight.Fight;
import de.steamwar.fightsystem.fight.FightTeam;
import de.steamwar.fightsystem.states.FightState;
import org.bukkit.entity.Player;
import java.util.EnumSet;
abstract class PlayerWincondition extends ListenerWincondition {
PlayerWincondition(boolean condition) {
super(condition, EnumSet.of(FightState.PRE_RUNNING, FightState.RUNNING));
}
boolean isTarget(Player player){
FightTeam fightTeam = Fight.getPlayerTeam(player);
if(fightTeam == null)
return false;
fightTeam.getFightPlayer(player).setOut();
return true;
}
public interface PrintableWincondition {
String getDisplay(FightTeam team);
}

Datei anzeigen

@ -19,14 +19,29 @@
package de.steamwar.fightsystem.winconditions;
import de.steamwar.fightsystem.FightSystem;
import de.steamwar.fightsystem.Config;
import de.steamwar.fightsystem.fight.Fight;
import de.steamwar.fightsystem.fight.FightTeam;
import de.steamwar.fightsystem.states.FightState;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.player.PlayerQuitEvent;
public class RankedPlayerLeftWincondition {
private RankedPlayerLeftWincondition(){}
public class RankedPlayerLeftWincondition extends ListenerWincondition{
public static void leaderQuit(FightTeam leaderlessTeam){
FightSystem.setSpectateState(Fight.getOpposite(leaderlessTeam), "LeaderQuit");
public RankedPlayerLeftWincondition(){
super(Config.Ranked, FightState.INGAME, "LeaderQuit");
}
@EventHandler
public void handlePlayerQuit(PlayerQuitEvent event) {
Player player = event.getPlayer();
FightTeam team = isTarget(player);
if(team == null)
return;
if(team.isPlayerLeader(player)) {
win(Fight.getOpposite(team), "§cDer Leader von ", " §chat den Kampf verlassen!");
}
}
}

Datei anzeigen

@ -0,0 +1,56 @@
/*
This file is a part of the SteamWar software.
Copyright (C) 2020 SteamWar.de-Serverteam
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package de.steamwar.fightsystem.winconditions;
import de.steamwar.fightsystem.countdown.TimeOverCountdown;
import de.steamwar.fightsystem.states.FightState;
import java.util.EnumSet;
import java.util.Set;
public abstract class TimeoutWincondition extends Wincondition {
private static TimeOverCountdown timeOverCountdown = null;
protected TimeoutWincondition(Winconditions condition, Set<FightState> enabled, String windescription) {
super(condition, enabled, windescription);
}
protected TimeoutWincondition(Winconditions condition, String windescription) {
super(condition, EnumSet.of(FightState.RUNNING), windescription);
}
protected abstract void timeOver();
@Override
public void enable() {
timeOverCountdown = new TimeOverCountdown(this::timeOver);
}
@Override
public void disable() {
if(timeOverCountdown != null)
timeOverCountdown.disable();
}
public static TimeOverCountdown getTimeOverCountdown(){
return timeOverCountdown;
}
}

Datei anzeigen

@ -19,23 +19,66 @@
package de.steamwar.fightsystem.winconditions;
import de.steamwar.fightsystem.Config;
import de.steamwar.fightsystem.FightSystem;
import de.steamwar.fightsystem.fight.Fight;
import de.steamwar.fightsystem.fight.FightTeam;
import de.steamwar.fightsystem.states.FightState;
import de.steamwar.fightsystem.states.StateDependent;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import java.util.ArrayList;
import java.util.List;
import java.util.Set;
abstract class Wincondition implements StateDependent {
public abstract class Wincondition implements StateDependent {
protected static PercentWincondition percentWincondition = null;
protected static final List<PrintableWincondition> printableWinconditions = new ArrayList<>();
private final Set<FightState> enabled;
private final String windescription;
Wincondition(boolean condition, Set<FightState> enabled){
protected Wincondition(Winconditions condition, Set<FightState> enabled, String windescription){
this(Config.ActiveWinconditions.contains(condition), enabled, windescription);
}
protected Wincondition(boolean condition, Set<FightState> enabled, String windescription){
this.enabled = enabled;
this.windescription = windescription;
if(condition)
FightState.registerStateDependent(this);
}
protected void win(FightTeam team, String preteammessage, String postteammessage){
win(team, preteammessage, postteammessage, null);
}
protected void win(FightTeam team, String preteammessage, String postteammessage, String tiemessage){
if(team != null){
Bukkit.broadcastMessage(FightSystem.PREFIX + preteammessage + team.getColoredName() + postteammessage);
}else{
Bukkit.broadcastMessage(FightSystem.PREFIX + tiemessage);
}
FightSystem.setSpectateState(team, windescription);
}
protected FightTeam isTarget(Player player){
FightTeam fightTeam = Fight.getPlayerTeam(player);
if(fightTeam == null)
return null;
fightTeam.getFightPlayer(player).setOut();
return fightTeam;
}
@Override
public Set<FightState> enabled(){
return enabled;
}
public static List<PrintableWincondition> getPrintableWinconditions(){
return printableWinconditions;
}
}

Datei anzeigen

@ -19,20 +19,18 @@
package de.steamwar.fightsystem.winconditions;
import de.steamwar.fightsystem.FightSystem;
import de.steamwar.fightsystem.fight.Fight;
import de.steamwar.fightsystem.fight.FightTeam;
import de.steamwar.fightsystem.Config;
import org.bukkit.Bukkit;
import de.steamwar.fightsystem.states.FightState;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.entity.PlayerDeathEvent;
import org.bukkit.event.player.PlayerQuitEvent;
public class WinconditionAllDead extends PlayerWincondition {
public class WinconditionAllDead extends ListenerWincondition {
public WinconditionAllDead(){
super(Config.AllDead);
super(Winconditions.ALL_DEAD, FightState.INGAME, "AllDead");
}
@EventHandler
@ -46,14 +44,12 @@ public class WinconditionAllDead extends PlayerWincondition {
}
private void handleDeath(Player player, String message){
if(!isTarget(player))
FightTeam team = isTarget(player);
if(team == null)
return;
FightTeam fightTeam = Fight.getPlayerTeam(player);
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), "AllDead");
if(team.allPlayersOut()) {
win(Fight.getOpposite(team), "§cDer letzte Spieler aus ", message);
}
}
}

Datei anzeigen

@ -19,20 +19,18 @@
package de.steamwar.fightsystem.winconditions;
import de.steamwar.fightsystem.FightSystem;
import de.steamwar.fightsystem.fight.Fight;
import de.steamwar.fightsystem.fight.FightTeam;
import de.steamwar.fightsystem.Config;
import org.bukkit.Bukkit;
import de.steamwar.fightsystem.states.FightState;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.entity.PlayerDeathEvent;
import org.bukkit.event.player.PlayerQuitEvent;
public class WinconditionCaptainDead extends PlayerWincondition {
public class WinconditionCaptainDead extends ListenerWincondition {
public WinconditionCaptainDead(){
super(Config.CaptainDead);
super(Winconditions.CAPTAIN_DEAD, FightState.INGAME, "LeaderDead");
}
@EventHandler
@ -46,14 +44,12 @@ public class WinconditionCaptainDead extends PlayerWincondition {
}
private void handleDeath(Player player, String message){
if(!isTarget(player))
FightTeam team = isTarget(player);
if(team == null)
return;
FightTeam fightTeam = Fight.getPlayerTeam(player);
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), "LeaderDead");
if(team.isPlayerLeader(player)) {
win(Fight.getOpposite(team), "§cDer Leader von ", message);
}
}
}

Datei anzeigen

@ -19,39 +19,26 @@
package de.steamwar.fightsystem.winconditions;
import de.steamwar.fightsystem.Config;
import de.steamwar.fightsystem.FightSystem;
import de.steamwar.fightsystem.countdown.TimeOverCountdown;
import de.steamwar.fightsystem.fight.Fight;
import de.steamwar.fightsystem.states.FightState;
import de.steamwar.fightsystem.fight.FightTeam;
import java.util.EnumSet;
public class WinconditionHeartRatioTimeout extends Wincondition {
private TimeOverCountdown countdown;
public class WinconditionHeartRatioTimeout extends TimeoutWincondition {
public WinconditionHeartRatioTimeout() {
super(Config.HeartRatioTimeout, EnumSet.of(FightState.RUNNING));
super(Winconditions.HEART_RATIO_TIMEOUT, "HeartTimeout");
}
@Override
public void enable() {
countdown = new TimeOverCountdown(() -> {
protected void timeOver() {
double blueHeartRatio = Fight.getBlueTeam().getHeartRatio();
double redHeartRatio = Fight.getRedTeam().getHeartRatio();
FightTeam team = null;
if(blueHeartRatio > redHeartRatio)
FightSystem.setSpectateState(Fight.getBlueTeam(), "HeartTimeout");
team = Fight.getBlueTeam();
else if(blueHeartRatio < redHeartRatio)
FightSystem.setSpectateState(Fight.getRedTeam(), "HeartTimeout");
else
FightSystem.setSpectateState(null, "HeartTimeout");
});
}
team = Fight.getRedTeam();
@Override
public void disable(){
countdown.disable();
win(team, "§cDie Zeit ist abgelaufen, und Team ", " §chatte mehr verbleibende Leben!", "§cDie Zeit ist abgelaufen, und beide Teams hatten die gleiche Anzahl an verbleibenden Leben!");
}
}

Datei anzeigen

@ -20,60 +20,66 @@
package de.steamwar.fightsystem.winconditions;
import de.steamwar.fightsystem.Config;
import de.steamwar.fightsystem.FightSystem;
import de.steamwar.fightsystem.fight.Fight;
import de.steamwar.fightsystem.fight.FightTeam;
import de.steamwar.fightsystem.states.FightState;
import de.steamwar.fightsystem.utils.Region;
import org.bukkit.entity.Entity;
import org.bukkit.event.EventHandler;
import org.bukkit.event.entity.EntityExplodeEvent;
import java.util.EnumSet;
import java.util.HashMap;
import java.util.Map;
public class WinconditionPercentSystem extends ListenerWincondition {
public class WinconditionPercentSystem extends ListenerWincondition implements PrintableWincondition, PercentWincondition {
private static double bluePercent = 0D;
private static double redPercent = 0D;
private static final int SCHEMATIC_SIZE = Math.abs(Config.SchemsizeX * Config.SchemsizeY * Config.SchemsizeZ);
private static int blueDestroyedBlocks;
private static int redDestroyedBlocks;
private static final int schematicSize = Math.abs(Config.SchemsizeX * Config.SchemsizeY * Config.SchemsizeZ);
private final Map<FightTeam, TeamPercent> teamMap = new HashMap<>();
public WinconditionPercentSystem() {
super(Config.PercentSystem, EnumSet.of(FightState.RUNNING));
super(Winconditions.PERCENT_SYSTEM, EnumSet.of(FightState.RUNNING), "Percent");
printableWinconditions.add(this);
percentWincondition = this;
teamMap.put(Fight.getBlueTeam(), new TeamPercent(Fight.getBlueTeam()));
teamMap.put(Fight.getRedTeam(), new TeamPercent(Fight.getRedTeam()));
}
@EventHandler
public void handleEntityExplode(EntityExplodeEvent event) {
Entity entity = event.getEntity();
//Team Blue
if(Region.isInRange(entity.getLocation(), Config.TeamBlueCornerX, Config.TeamBlueCornerY, Config.TeamBlueCornerZ, Config.SchemsizeX, Config.SchemsizeY, Config.SchemsizeZ, Config.BorderFromSchematic)){
blueDestroyedBlocks = blueDestroyedBlocks + event.blockList().size();
double doubleBlueDestroyedBlocks = blueDestroyedBlocks;
double destroyPercent = doubleBlueDestroyedBlocks * 100 / schematicSize;
bluePercent = destroyPercent;
if(destroyPercent >= Config.PercentWin) {
FightSystem.setSpectateState(Fight.getRedTeam(), "Percent");
}
//Team Red
}else if(Region.isInRange(entity.getLocation(), Config.TeamRedCornerX, Config.TeamRedCornerY, Config.TeamRedCornerZ, Config.SchemsizeX, Config.SchemsizeY, Config.SchemsizeZ, Config.BorderFromSchematic)) {
redDestroyedBlocks = redDestroyedBlocks + event.blockList().size();
double doubleRedDestroyedBlocks = redDestroyedBlocks;
double destroyPercent = doubleRedDestroyedBlocks * 100 / schematicSize;
redPercent = destroyPercent;
if(destroyPercent >= Config.PercentWin) {
FightSystem.setSpectateState(Fight.getBlueTeam(), "Percent");
}
}
teamMap.values().forEach(teamPercent -> teamPercent.check(event));
}
public static double getBluePercent() {
return bluePercent;
@Override
public String getDisplay(FightTeam team) {
return team.getPrefix() + "Schaden: " + (Math.round(100.0 * getPercent(team)) / 100.0) + "%";
}
public static double getRedPercent() {
return redPercent;
@Override
public double getPercent(FightTeam team) {
return teamMap.get(team).percent;
}
private class TeamPercent {
private final FightTeam team;
private double percent;
private int destroyedBlocks;
private TeamPercent(FightTeam team) {
this.team = team;
}
private void check(EntityExplodeEvent event) {
if(!Region.isInRange(event.getEntity().getLocation(), team.getCornerX(), team.getCornerY(), team.getCornerZ(), Config.SchemsizeX, Config.SchemsizeY, Config.SchemsizeZ, Config.BorderFromSchematic)){
return;
}
destroyedBlocks += event.blockList().size();
percent = (double)destroyedBlocks * 100 / SCHEMATIC_SIZE;
if(percent >= Config.PercentWin) {
win(Fight.getOpposite(team), "§cTeam ", " §chat den Gegnern");
}
}
}
}

Datei anzeigen

@ -1,40 +1,43 @@
/*
This file is a part of the SteamWar software.
Copyright (C) 2020 SteamWar.de-Serverteam
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package de.steamwar.fightsystem.winconditions;
import de.steamwar.fightsystem.Config;
import de.steamwar.fightsystem.FightSystem;
import de.steamwar.fightsystem.countdown.TimeOverCountdown;
import de.steamwar.fightsystem.fight.Fight;
import de.steamwar.fightsystem.states.FightState;
import de.steamwar.fightsystem.fight.FightTeam;
import java.util.EnumSet;
public class WinconditionPercentTimeout extends Wincondition {
private static final String WINDESCRIPTION = "PercentTimeout";
private TimeOverCountdown countdown;
public class WinconditionPercentTimeout extends TimeoutWincondition {
public WinconditionPercentTimeout() {
super(Config.HeartRatioTimeout, EnumSet.of(FightState.RUNNING));
super(Winconditions.HEART_RATIO_TIMEOUT, "PercentTimeout");
}
@Override
public void enable() {
countdown = new TimeOverCountdown(() -> {
double bluePercent = WinconditionPercentSystem.getBluePercent();
double redPercent = WinconditionPercentSystem.getRedPercent();
protected void timeOver() {
double bluePercent = Wincondition.percentWincondition.getPercent(Fight.getBlueTeam());
double redPercent = Wincondition.percentWincondition.getPercent(Fight.getRedTeam());
FightTeam team = null;
if(bluePercent > redPercent)
FightSystem.setSpectateState(Fight.getBlueTeam(), WINDESCRIPTION);
team = Fight.getRedTeam();
else if(bluePercent < redPercent)
FightSystem.setSpectateState(Fight.getRedTeam(), WINDESCRIPTION);
else
FightSystem.setSpectateState(null, WINDESCRIPTION);
});
}
@Override
public void disable(){
countdown.disable();
team = Fight.getBlueTeam();
win(team, "§cDie Zeit ist abgelaufen, und Team ", " §chatte weniger Schaden erlitten!", "§cDie Zeit ist abgelaufen, und beide Teams hatten gleichen Schaden!");
}
}

Datei anzeigen

@ -19,54 +19,67 @@
package de.steamwar.fightsystem.winconditions;
import de.steamwar.fightsystem.Config;
import de.steamwar.fightsystem.FightSystem;
import de.steamwar.fightsystem.countdown.TimeOverCountdown;
import de.steamwar.fightsystem.fight.Fight;
import de.steamwar.fightsystem.fight.FightTeam;
import de.steamwar.fightsystem.states.FightState;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.HandlerList;
import org.bukkit.event.Listener;
import org.bukkit.event.entity.PlayerDeathEvent;
import org.bukkit.event.player.PlayerQuitEvent;
public class WinconditionPoints extends PlayerWincondition {
import java.util.HashMap;
import java.util.Map;
private static TeamPoints blue;
private static TeamPoints red;
private TimeOverCountdown countdown;
public class WinconditionPoints extends TimeoutWincondition implements PrintableWincondition, Listener {
private final Map<FightTeam, WinconditionRelativePercent.TeamPercent> percentMap = new HashMap<>();
private final Map<FightTeam, TeamPoints> teamMap = new HashMap<>();
public WinconditionPoints(){
super(Config.Points);
super(Winconditions.POINTS, FightState.INGAME, "Points");
percentMap.put(Fight.getBlueTeam(), new WinconditionRelativePercent.TeamPercent(Fight.getBlueTeam()));
percentMap.put(Fight.getRedTeam(), new WinconditionRelativePercent.TeamPercent(Fight.getRedTeam()));
teamMap.put(Fight.getBlueTeam(), new TeamPoints(Fight.getBlueTeam()));
teamMap.put(Fight.getRedTeam(), new TeamPoints(Fight.getRedTeam()));
printableWinconditions.add(this);
}
public static TeamPoints getRed(){
return red;
}
@Override
protected void timeOver() {
int redPoints = teamMap.get(Fight.getRedTeam()).getPoints();
int bluePoints = teamMap.get(Fight.getBlueTeam()).getPoints();
public static TeamPoints getBlue(){
return blue;
FightTeam team = null;
if(redPoints > bluePoints)
team = Fight.getRedTeam();
else if(redPoints < bluePoints)
team = Fight.getBlueTeam();
win(team, "§cDas Team ", " §chat mehr Punkte!", "§cBeide Teams haben gleich viele Punkte!");
}
@Override
public void enable() {
super.enable();
blue = new TeamPoints(Fight.getRedTeam(), WinconditionRelativePercent.getBlue(), WinconditionRelativePercent.getRed());
red = new TeamPoints(Fight.getBlueTeam(), WinconditionRelativePercent.getRed(), WinconditionRelativePercent.getBlue());
Bukkit.getPluginManager().registerEvents(this, FightSystem.getPlugin());
teamMap.values().forEach(TeamPoints::enable);
}
@Override
public void disable() {
super.disable();
if(countdown != null)
countdown.disable();
HandlerList.unregisterAll(this);
}
@Override
public void stateChange(FightState state){
if(state == FightState.RUNNING){
countdown = new TimeOverCountdown(this::fightEnds);
super.enable();
}
}
@ -81,58 +94,49 @@ public class WinconditionPoints extends PlayerWincondition {
}
private void handleDeath(Player player, String message){
if(!isTarget(player))
FightTeam team = isTarget(player);
if(team == null)
return;
FightTeam fightTeam = Fight.getPlayerTeam(player);
TeamPoints enemy = getEnemyByTeam(fightTeam);
assert fightTeam != null; // Checked by isTarget
if(fightTeam.isPlayerLeader(player)) {
TeamPoints enemy = teamMap.get(Fight.getOpposite(team));
if(team.isPlayerLeader(player)) {
enemy.points += 500;
Bukkit.broadcastMessage(FightSystem.PREFIX + "§cDer Leader von " + fightTeam.getPrefix() + fightTeam.getColoredName() + message);
fightEnds();
}else if(fightTeam.getPlayers().size() <= 5)
Bukkit.broadcastMessage(FightSystem.PREFIX + "§cDer Leader von " + team.getColoredName() + message);
timeOver();
}else if(team.getPlayers().size() <= 5)
enemy.points += 300;
else
enemy.points += 200;
}
private void fightEnds(){
if(red.getPoints() > blue.getPoints())
FightSystem.setSpectateState(blue.enemy, "Points");
else if(red.getPoints() < blue.getPoints())
FightSystem.setSpectateState(red.enemy, "Points");
else
FightSystem.setSpectateState(null, "Points");
@Override
public String getDisplay(FightTeam team) {
return team.getPrefix() + "Punkte: " + teamMap.get(team).getPoints();
}
private TeamPoints getEnemyByTeam(FightTeam team){
if(team == blue.enemy)
return blue;
else
return red;
}
private class TeamPoints {
private static final int MAX_POINTS = 2000;
private final FightTeam team;
public static class TeamPoints {
private final FightTeam enemy;
private final WinconditionRelativePercent.TeamPercent enemyPercent;
private double factor;
private static final int maxPoints = 2000;
private int points;
TeamPoints(FightTeam enemy, WinconditionRelativePercent.TeamPercent ownPercent, WinconditionRelativePercent.TeamPercent enemyPercent){
this.enemy = enemy;
this.enemyPercent = enemyPercent;
TeamPoints(FightTeam team){
this.team = team;
points = 0;
}
//Prevent NPE
Bukkit.getScheduler().runTask(FightSystem.getPlugin(), () ->{
if(enemyPercent.getBlockCount() < ownPercent.getBlockCount())
public void enable() {
percentMap.get(team).enable();
int ownBlocks = percentMap.get(team).getBlockCount();
int enemyBlocks = percentMap.get(Fight.getOpposite(team)).getBlockCount();
if(enemyBlocks < ownBlocks) {
this.factor = 10000; //Original mit 20 (20% = 0.2 ergeben 2000 Punkte
else{
double f = 10000.0 * ownPercent.getBlockCount() / enemyPercent.getBlockCount();
} else {
double f = 10000.0 * ownBlocks / enemyBlocks;
if(f > 10000)
f = 10000;
@ -141,13 +145,12 @@ public class WinconditionPoints extends PlayerWincondition {
this.factor = f;
}
});
}
public int getPoints(){
int damagePoints = (int)(enemyPercent.getPercent() * factor);
if(damagePoints > maxPoints)
damagePoints = maxPoints;
int damagePoints = (int)(percentMap.get(Fight.getOpposite(team)).getPercent() * factor);
if(damagePoints > MAX_POINTS)
damagePoints = MAX_POINTS;
return points + damagePoints;
}
}

Datei anzeigen

@ -30,31 +30,26 @@ import org.bukkit.Material;
import org.bukkit.World;
import org.bukkit.scheduler.BukkitTask;
import java.util.EnumSet;
import java.util.HashMap;
import java.util.Map;
public class WinconditionPumpkinTechKO extends Wincondition {
public class WinconditionPumpkinTechKO extends Wincondition implements PrintableWincondition {
private static int teamRedPumpkins = -1;
private static int teamBluePumpkins = -1;
private static final World WORLD = Bukkit.getWorlds().get(0);
private static final World world = Bukkit.getWorlds().get(0);
private static final Material PUMPKIN_LANTERN = SWItem.getMaterial("JACK_O_LANTERN");
private final Map<FightTeam, TeamPumpkin> teamMap = new HashMap<>();
private BukkitTask task;
private static boolean running = false;
public WinconditionPumpkinTechKO(){
super(Config.PumpkinTechKO, EnumSet.of(FightState.PRE_RUNNING, FightState.RUNNING));
}
public static int getTeamBluePumpkins() {
return teamBluePumpkins;
}
public static int getTeamRedPumpkins() {
return teamRedPumpkins;
super(Winconditions.PUMPKIN_TECH_KO, FightState.INGAME, "PumpkinTechKO");
teamMap.put(Fight.getRedTeam(), new TeamPumpkin(Fight.getRedTeam()));
teamMap.put(Fight.getBlueTeam(), new TeamPumpkin(Fight.getBlueTeam()));
}
@Override
public void enable() {
task = Bukkit.getScheduler().runTaskTimerAsynchronously(FightSystem.getPlugin(), WinconditionPumpkinTechKO::recursiveCheck, 0, 200);
task = Bukkit.getScheduler().runTaskTimer(FightSystem.getPlugin(), this::check, 0, 200);
}
@Override
@ -62,45 +57,38 @@ public class WinconditionPumpkinTechKO extends Wincondition {
task.cancel();
}
private static void recursiveCheck(){
if(running)
return;
running = true;
teamRedPumpkins = getPumpkins(Config.TeamRedCornerX,
Config.TeamRedCornerY,
Config.TeamRedCornerZ,
Config.TeamRedCornerX + Config.SchemsizeX,
Config.TeamRedCornerY + Config.SchemsizeY,
Config.TeamRedCornerZ + Config.SchemsizeZ);
teamBluePumpkins = getPumpkins(Config.TeamBlueCornerX,
Config.TeamBlueCornerY,
Config.TeamBlueCornerZ,
Config.TeamBlueCornerX + Config.SchemsizeX,
Config.TeamBlueCornerY + Config.SchemsizeY,
Config.TeamBlueCornerZ + Config.SchemsizeZ);
checkKO(Fight.getRedTeam(), teamRedPumpkins);
checkKO(Fight.getBlueTeam(), teamBluePumpkins);
running = false;
private void check(){
teamMap.values().forEach(TeamPumpkin::check);
}
private static int getPumpkins(int minX, int minY, int minZ, int maxX, int maxY, int maxZ){
int pumpkins = 0;
for(int x = minX; x <= maxX; x++) {
for(int y = minY; y <= maxY; y++) {
for (int z = minZ; z <= maxZ; z++) {
if (WORLD.getBlockAt(x, y, z).getType() == PUMPKIN_LANTERN)
@Override
public String getDisplay(FightTeam team) {
return team.getPrefix() + "Kanonen: " + teamMap.get(team).pumpkins;
}
private class TeamPumpkin {
private final FightTeam team;
private int pumpkins;
private TeamPumpkin (FightTeam team) {
this.team = team;
}
private void check(){
pumpkins = 0;
for(int x = team.getCornerX(); x <= team.getCornerX() + Config.SchemsizeX; x++) {
for(int y = team.getCornerY(); y <= team.getCornerY() + Config.SchemsizeY; y++) {
for (int z = team.getCornerZ(); z <= team.getCornerZ() + Config.SchemsizeZ; z++) {
if (world.getBlockAt(x, y, z).getType() == PUMPKIN_LANTERN)
pumpkins++;
}
}
}
return pumpkins;
}
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), "PumpkinTechKO"));
if(pumpkins == 0) {
win(Fight.getOpposite(team), "§cDas Team ", " §cist Tech K.O.!");
}
}
}
}

Datei anzeigen

@ -21,7 +21,6 @@ package de.steamwar.fightsystem.winconditions;
import de.steamwar.fightsystem.Config;
import de.steamwar.fightsystem.FightSystem;
import de.steamwar.fightsystem.countdown.TimeOverCountdown;
import de.steamwar.fightsystem.fight.Fight;
import de.steamwar.fightsystem.fight.FightTeam;
import de.steamwar.fightsystem.states.FightState;
@ -30,16 +29,12 @@ import org.bukkit.Material;
import org.bukkit.World;
import org.bukkit.scheduler.BukkitTask;
import java.util.Collections;
import java.util.EnumSet;
import java.util.HashSet;
import java.util.Set;
import java.util.*;
public class WinconditionRelativePercent extends Wincondition{
public class WinconditionRelativePercent extends Wincondition implements PrintableWincondition, PercentWincondition {
private static final World world = Bukkit.getWorlds().get(0);
private static final Set<Material> ignoredBlocks;
private static TeamPercent blue = null;
private static TeamPercent red = null;
static{
Set<Material> ignored = new HashSet<>();
@ -48,74 +43,78 @@ public class WinconditionRelativePercent extends Wincondition{
ignoredBlocks = Collections.unmodifiableSet(ignored);
}
private final Map<FightTeam, TeamPercent> teamMap = new HashMap<>();
public WinconditionRelativePercent(){
super(Config.RelativePercent || Config.Points, EnumSet.of(FightState.PRE_RUNNING, FightState.RUNNING));
}
public static TeamPercent getBlue(){
if(blue == null)
blue = new TeamPercent(Fight.getBlueTeam());
return blue;
}
public static TeamPercent getRed(){
if(red == null)
red = new TeamPercent(Fight.getRedTeam());
return red;
super(Winconditions.RELATIVE_PERCENT, EnumSet.of(FightState.PRE_RUNNING, FightState.RUNNING), "RelativePercent");
teamMap.put(Fight.getBlueTeam(), new TeamPercent(Fight.getBlueTeam()));
teamMap.put(Fight.getRedTeam(), new TeamPercent(Fight.getRedTeam()));
printableWinconditions.add(this);
percentWincondition = this;
}
@Override
public void enable() {
getBlue();
getRed();
teamMap.values().forEach(TeamPercent::enable);
}
@Override
public void disable() {
blue.task.cancel();
red.task.cancel();
teamMap.values().forEach(teamPercent -> teamPercent.task.cancel());
}
@Override
public double getPercent(FightTeam team) {
return teamMap.get(team).getPercent();
}
@Override
public String getDisplay(FightTeam team) {
return team.getPrefix() + "Schaden: " + (Math.round(100.0 * getPercent(team)) / 100.0) + "%";
}
public static class TeamPercent {
private static final World world = Bukkit.getWorlds().get(0);
private final FightTeam team;
private final int blockCount;
private final BukkitTask task;
private boolean running = false;
private int blockCount;
private BukkitTask task;
private int currentBlocks;
private TeamPercent(FightTeam team){
public TeamPercent(FightTeam team){
this.team = team;
this.blockCount = currentBlocks();
this.currentBlocks = blockCount;
this.currentBlocks = 1;
}
task = Bukkit.getScheduler().runTaskTimerAsynchronously(FightSystem.getPlugin(), () -> {
if(running)
return;
running = true;
public void enable(){
blockCount = currentBlocks();
task = Bukkit.getScheduler().runTaskTimer(FightSystem.getPlugin(), this::check, 400, 400);
}
private void check(){
currentBlocks = currentBlocks();
checkPercentDefeat();
running = false;
}, 400, 400);
if(!Config.ActiveWinconditions.contains(Winconditions.RELATIVE_PERCENT))
return;
if(getPercent() >= Config.PercentWin){
Bukkit.broadcastMessage(FightSystem.PREFIX + "§cDer Schiff von " + team.getColoredName() + " §cwurde zu stark beschädigt!");
FightSystem.setSpectateState(Fight.getOpposite(team), "RelativePercent");
}
}
public double getPrintablePercent(){
return Math.round(10000.0 * getPercent()) / 100.0;
public double getPercent(){
if(currentBlocks > blockCount)
return 0;
return (blockCount - currentBlocks) * 100 / (double) blockCount;
}
final int getBlockCount(){
public int getBlockCount(){
return blockCount;
}
double getPercent(){
int blocksDestroyed = blockCount - currentBlocks;
return blocksDestroyed > 0 ? blocksDestroyed / (double) blockCount : 0;
}
private int currentBlocks(){
// Entern active
if(!Config.EnterStages.isEmpty() && Config.EnterStages.get(0) >= Config.TimeoutTime - TimeOverCountdown.getRemainingTime())
if(!Config.EnterStages.isEmpty() && Config.EnterStages.get(0) >= Config.TimeoutTime - TimeoutWincondition.getTimeOverCountdown().getTimeLeft())
return currentBlocks;
int blocks = 0;
@ -129,14 +128,5 @@ public class WinconditionRelativePercent extends Wincondition{
}
return blocks;
}
private void checkPercentDefeat(){
if(!Config.RelativePercent)
return;
if(getPercent() * 100 >= Config.PercentWin){
Bukkit.broadcastMessage(FightSystem.PREFIX + "§cDer Schiff von " + team.getColoredName() + " §cwurde zu stark beschädigt!");
Bukkit.getScheduler().runTask(FightSystem.getPlugin(), () -> FightSystem.setSpectateState(Fight.getOpposite(team), "RelativePercent"));
}
}
}
}

Datei anzeigen

@ -32,7 +32,7 @@ import org.bukkit.scheduler.BukkitTask;
import java.util.EnumSet;
public class WinconditionTechKO extends ListenerWincondition {
public class WinconditionTimeTechKO extends ListenerWincondition {
private static final int TECH_KO_TIME_IN_S = 90;
private static final int TECH_KO_HALF_TIME = TECH_KO_TIME_IN_S*10;
@ -51,8 +51,8 @@ public class WinconditionTechKO extends ListenerWincondition {
/**
* Works only for z-Axis fight direction for performance reasons
*/
public WinconditionTechKO(){
super(Config.TechKO, EnumSet.of(FightState.RUNNING));
public WinconditionTimeTechKO(){
super(Winconditions.TIME_TECH_KO, EnumSet.of(FightState.RUNNING), null);
if(Config.TeamBluetoReddistanceZ > 0) {
smallerZteam = Fight.getBlueTeam();

Datei anzeigen

@ -19,28 +19,14 @@
package de.steamwar.fightsystem.winconditions;
import de.steamwar.fightsystem.Config;
import de.steamwar.fightsystem.FightSystem;
import de.steamwar.fightsystem.countdown.TimeOverCountdown;
import de.steamwar.fightsystem.states.FightState;
import java.util.EnumSet;
public class WinconditionTimeout extends Wincondition {
private TimeOverCountdown countdown;
public class WinconditionTimeout extends TimeoutWincondition {
public WinconditionTimeout() {
super(Config.Timeout, EnumSet.of(FightState.RUNNING));
super(Winconditions.TIMEOUT, "Timeout");
}
@Override
public void enable() {
countdown = new TimeOverCountdown(() -> FightSystem.setSpectateState(null, "Timeout"));
}
@Override
public void disable() {
countdown.disable();
protected void timeOver() {
win(null, null, null, "§cDie Zeit ist abgelaufen!");
}
}

Datei anzeigen

@ -30,32 +30,26 @@ import org.bukkit.World;
import org.bukkit.scheduler.BukkitTask;
import java.util.EnumSet;
import java.util.HashMap;
import java.util.Map;
public class WinconditionWaterTechKO extends Wincondition {
public class WinconditionWaterTechKO extends Wincondition implements PrintableWincondition {
private static int teamRedWater;
private static int teamBlueWater;
private static final World WORLD = Bukkit.getWorlds().get(0);
private final Map<FightTeam, TeamWater> teamMap = new HashMap<>();
private BukkitTask task;
private boolean running = false;
public WinconditionWaterTechKO() {
super(Config.WaterTechKO, EnumSet.of(FightState.PRE_RUNNING, FightState.RUNNING));
}
public static int getTeamBlueWater() {
return teamBlueWater;
}
public static int getTeamRedWater() {
return teamRedWater;
super(Winconditions.WATER_TECH_KO, EnumSet.of(FightState.PRE_RUNNING, FightState.RUNNING), "WaterTechKO");
teamMap.put(Fight.getBlueTeam(), new TeamWater(Fight.getBlueTeam()));
teamMap.put(Fight.getRedTeam(), new TeamWater(Fight.getRedTeam()));
printableWinconditions.add(this);
}
@Override
public void enable() {
checkTask();
task = Bukkit.getScheduler().runTaskTimerAsynchronously(FightSystem.getPlugin(), this::checkTask, 200, 200);
task = Bukkit.getScheduler().runTaskTimer(FightSystem.getPlugin(), this::check, 200, 200);
}
@Override
@ -63,47 +57,37 @@ public class WinconditionWaterTechKO extends Wincondition {
task.cancel();
}
private void checkEmpty(FightTeam team, int teamWater){
if(teamWater == 0){
Bukkit.broadcastMessage(FightSystem.PREFIX + "§eDas Team " + team.getColoredName() + " §eist Tech K.O.!");
Bukkit.getScheduler().runTask(FightSystem.getPlugin(), () -> FightSystem.setSpectateState(Fight.getOpposite(team), "WaterTechKO"));
}
private void check() {
teamMap.values().forEach(TeamWater::check);
}
private void checkTask() {
if(running)
return;
running = true;
teamRedWater = calcWater(
Config.TeamRedCornerX,
Config.TeamRedCornerY,
Config.TeamRedCornerZ,
Config.TeamRedCornerX + Config.SchemsizeX,
Config.TeamRedCornerY + Config.SchemsizeY,
Config.TeamRedCornerZ + Config.SchemsizeZ);
teamBlueWater = calcWater(
Config.TeamBlueCornerX,
Config.TeamBlueCornerY,
Config.TeamBlueCornerZ,
Config.TeamBlueCornerX + Config.SchemsizeX,
Config.TeamBlueCornerY + Config.SchemsizeY,
Config.TeamBlueCornerZ + Config.SchemsizeZ);
checkEmpty(Fight.getRedTeam(), teamRedWater);
checkEmpty(Fight.getBlueTeam(), teamBlueWater);
running = false;
@Override
public String getDisplay(FightTeam team) {
return team.getPrefix() + "Wasser: " + teamMap.get(team).water;
}
private int calcWater(int minX, int minY, int minZ, int maxX, int maxY, int maxZ){
int teamWater = 0;
for(int x = minX; x <= maxX; x++) {
for(int y = minY; y <= maxY; y++) {
for (int z = minZ; z <= maxZ; z++) {
private class TeamWater {
private final FightTeam team;
private int water;
private TeamWater(FightTeam team) {
this.team = team;
}
private void check() {
water = 0;
for(int x = team.getCornerX(); x <= team.getCornerX() + Config.SchemsizeX; x++) {
for(int y = team.getCornerY(); y <= team.getCornerY() + Config.SchemsizeY; y++) {
for (int z = team.getCornerZ(); z <= team.getCornerZ() + Config.SchemsizeZ; z++) {
if (WaterRemover.isWater(WORLD.getBlockAt(x, y, z)))
teamWater++;
water++;
}
}
}
return teamWater;
if(water == 0){
win(Fight.getOpposite(team), "§cDas Team ", " §cist Tech K.O.!");
}
}
}
}