Relative Prozensystem Wincondition und SG.eu-Punktesystem Wincondition #75
@ -80,6 +80,8 @@ public class Config {
|
|||||||
public static final boolean AllDead;
|
public static final boolean AllDead;
|
||||||
public static final boolean CaptainDead;
|
public static final boolean CaptainDead;
|
||||||
public static final boolean PercentSystem;
|
public static final boolean PercentSystem;
|
||||||
|
public static final boolean RelativePercent;
|
||||||
|
public static final boolean Points;
|
||||||
public static final boolean Entern;
|
public static final boolean Entern;
|
||||||
public static final boolean TechKO;
|
public static final boolean TechKO;
|
||||||
public static final boolean WaterTechKO;
|
public static final boolean WaterTechKO;
|
||||||
@ -88,6 +90,7 @@ public class Config {
|
|||||||
public static final int TimeoutTime;
|
public static final int TimeoutTime;
|
||||||
public static final int EnterPhaseBegin;
|
public static final int EnterPhaseBegin;
|
||||||
public static final double PercentWin;
|
public static final double PercentWin;
|
||||||
|
public static final List<String> IgnoredBlocks;
|
||||||
|
|
||||||
//default kits
|
//default kits
|
||||||
public static final String MemberDefault;
|
public static final String MemberDefault;
|
||||||
@ -155,6 +158,8 @@ public class Config {
|
|||||||
AllDead = config.getBoolean("WinConditions.AllDead");
|
AllDead = config.getBoolean("WinConditions.AllDead");
|
||||||
CaptainDead = config.getBoolean("WinConditions.CaptainDead");
|
CaptainDead = config.getBoolean("WinConditions.CaptainDead");
|
||||||
PercentSystem = config.getBoolean("WinConditions.PercentSystem");
|
PercentSystem = config.getBoolean("WinConditions.PercentSystem");
|
||||||
|
RelativePercent = config.getBoolean("WinConditions.RelativePercent");
|
||||||
|
Points = config.getBoolean("WinConditions.Points");
|
||||||
Entern = config.getBoolean("WinConditions.Entern");
|
Entern = config.getBoolean("WinConditions.Entern");
|
||||||
TechKO = config.getBoolean("WinConditions.TechKO");
|
TechKO = config.getBoolean("WinConditions.TechKO");
|
||||||
WaterTechKO = config.getBoolean("WinConditions.WaterTechKO");
|
WaterTechKO = config.getBoolean("WinConditions.WaterTechKO");
|
||||||
@ -162,6 +167,7 @@ public class Config {
|
|||||||
TimeoutTime = config.getInt("WinConditionParams.TimeoutTime");
|
TimeoutTime = config.getInt("WinConditionParams.TimeoutTime");
|
||||||
EnterPhaseBegin = config.getInt("WinConditionParams.EnterPhaseBegin");
|
EnterPhaseBegin = config.getInt("WinConditionParams.EnterPhaseBegin");
|
||||||
PercentWin = config.getDouble("WinConditionParams.PercentWin");
|
PercentWin = config.getDouble("WinConditionParams.PercentWin");
|
||||||
|
IgnoredBlocks = Collections.unmodifiableList(config.getStringList("WinConditionParams.IgnoredBlocks"));
|
||||||
|
|
||||||
MemberDefault = config.getString("Kits.MemberDefault");
|
MemberDefault = config.getString("Kits.MemberDefault");
|
||||||
LeaderDefault = config.getString("Kits.LeaderDefault");
|
LeaderDefault = config.getString("Kits.LeaderDefault");
|
||||||
|
@ -40,12 +40,19 @@ WinConditions:
|
|||||||
AllDead: boolean
|
AllDead: boolean
|
||||||
CaptainDead: boolean
|
CaptainDead: boolean
|
||||||
PercentSystem: boolean
|
PercentSystem: boolean
|
||||||
|
RelativePercent: boolean
|
||||||
|
Points: boolean
|
||||||
Entern: boolean
|
Entern: boolean
|
||||||
TechKO: boolean
|
TechKO: boolean
|
||||||
WinConditionParams:
|
WinConditionParams:
|
||||||
TimeoutTime: 0
|
TimeoutTime: 0
|
||||||
EnterPhaseBegin: 0
|
EnterPhaseBegin: 0
|
||||||
PercentWin: 0.0
|
PercentWin: 0.0
|
||||||
|
IgnoredBlocks:
|
||||||
|
- AIR
|
||||||
|
- WATER
|
||||||
|
- TNT
|
||||||
|
- OBSIDIAN
|
||||||
Money:
|
Money:
|
||||||
Win: 0
|
Win: 0
|
||||||
Lose: 0
|
Lose: 0
|
||||||
@ -55,6 +62,7 @@ Kits:
|
|||||||
LeaderDefault: default
|
LeaderDefault: default
|
||||||
Techhider:
|
Techhider:
|
||||||
ObfuscateWith: 1
|
ObfuscateWith: 1
|
||||||
|
ObfuscateWithTag: STONE
|
||||||
HiddenBlocks:
|
HiddenBlocks:
|
||||||
- 7
|
- 7
|
||||||
- 8
|
- 8
|
||||||
|
@ -113,7 +113,6 @@ public class FightSystem extends JavaPlugin {
|
|||||||
new WinconditionAllDead();
|
new WinconditionAllDead();
|
||||||
new WinconditionCaptainDead();
|
new WinconditionCaptainDead();
|
||||||
new WinconditionWaterTechKO();
|
new WinconditionWaterTechKO();
|
||||||
new WinconditionPercentSystem();
|
|
||||||
|
|
||||||
if(Config.event()){
|
if(Config.event()){
|
||||||
new EventTeamOffWincondition();
|
new EventTeamOffWincondition();
|
||||||
@ -131,6 +130,9 @@ public class FightSystem extends JavaPlugin {
|
|||||||
new WinconditionTechKO();
|
new WinconditionTechKO();
|
||||||
new WinconditionTimeout();
|
new WinconditionTimeout();
|
||||||
new WinconditionEntern();
|
new WinconditionEntern();
|
||||||
|
new WinconditionPercentSystem();
|
||||||
|
new WinconditionRelativePercent();
|
||||||
|
new WinconditionPoints();
|
||||||
|
|
||||||
WaterRemover.init();
|
WaterRemover.init();
|
||||||
|
|
||||||
|
@ -6,8 +6,11 @@ import org.bukkit.Bukkit;
|
|||||||
|
|
||||||
public class TimeOverCountdown extends Countdown {
|
public class TimeOverCountdown extends Countdown {
|
||||||
|
|
||||||
public TimeOverCountdown() {
|
private final Runnable timeOver;
|
||||||
|
|
||||||
|
public TimeOverCountdown(Runnable timeOver) {
|
||||||
super(Config.TimeoutTime, "BLOCK_NOTE_BASS", false);
|
super(Config.TimeoutTime, "BLOCK_NOTE_BASS", false);
|
||||||
|
this.timeOver = timeOver;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -18,7 +21,7 @@ public class TimeOverCountdown extends Countdown {
|
|||||||
@Override
|
@Override
|
||||||
public void countdownFinished() {
|
public void countdownFinished() {
|
||||||
Bukkit.broadcastMessage(FightSystem.PREFIX +"§aZeit abgelaufen!");
|
Bukkit.broadcastMessage(FightSystem.PREFIX +"§aZeit abgelaufen!");
|
||||||
FightSystem.setSpectateState(null);
|
timeOver.run();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -86,6 +86,18 @@ public class FightTeam implements IFightTeam{
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public final int getCornerX() {
|
||||||
|
return cornerX;
|
||||||
|
}
|
||||||
|
|
||||||
|
public final int getCornerY() {
|
||||||
|
return cornerY;
|
||||||
|
}
|
||||||
|
|
||||||
|
public final int getCornerZ() {
|
||||||
|
return cornerZ;
|
||||||
|
}
|
||||||
|
|
||||||
public boolean canbeLeader(Player p){
|
public boolean canbeLeader(Player p){
|
||||||
return !hasTeamLeader() && (designatedLeader == null || designatedLeader.equals(p.getUniqueId()));
|
return !hasTeamLeader() && (designatedLeader == null || designatedLeader.equals(p.getUniqueId()));
|
||||||
}
|
}
|
||||||
|
@ -5,22 +5,27 @@ import de.steamwar.fightsystem.FightSystem;
|
|||||||
import de.steamwar.fightsystem.fight.Fight;
|
import de.steamwar.fightsystem.fight.Fight;
|
||||||
import de.steamwar.fightsystem.fight.FightTeam;
|
import de.steamwar.fightsystem.fight.FightTeam;
|
||||||
import de.steamwar.fightsystem.winconditions.WinconditionPercentSystem;
|
import de.steamwar.fightsystem.winconditions.WinconditionPercentSystem;
|
||||||
|
import de.steamwar.fightsystem.winconditions.WinconditionPoints;
|
||||||
|
import de.steamwar.fightsystem.winconditions.WinconditionRelativePercent;
|
||||||
import de.steamwar.fightsystem.winconditions.WinconditionWaterTechKO;
|
import de.steamwar.fightsystem.winconditions.WinconditionWaterTechKO;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.scoreboard.DisplaySlot;
|
import org.bukkit.scoreboard.DisplaySlot;
|
||||||
import org.bukkit.scoreboard.Objective;
|
import org.bukkit.scoreboard.Objective;
|
||||||
import org.bukkit.scoreboard.Scoreboard;
|
import org.bukkit.scoreboard.Scoreboard;
|
||||||
|
|
||||||
|
import java.util.Objects;
|
||||||
|
|
||||||
public class FightScoreboard {
|
public class FightScoreboard {
|
||||||
|
|
||||||
private FightScoreboard(){}
|
private FightScoreboard(){}
|
||||||
|
|
||||||
private static final Scoreboard scoreboard = Bukkit.getScoreboardManager().getMainScoreboard();
|
private static final Scoreboard scoreboard = Objects.requireNonNull(Bukkit.getScoreboardManager()).getMainScoreboard();
|
||||||
private static final Objective objective;
|
private static final Objective objective;
|
||||||
private static int index = 0;
|
private static int index = 0;
|
||||||
|
|
||||||
static{
|
static{
|
||||||
if(scoreboard.getObjective("AAA") == null)
|
if(scoreboard.getObjective("AAA") == null)
|
||||||
|
//noinspection deprecation
|
||||||
objective = scoreboard.registerNewObjective("AAA", "BBB");
|
objective = scoreboard.registerNewObjective("AAA", "BBB");
|
||||||
else
|
else
|
||||||
objective = scoreboard.getObjective("AAA");
|
objective = scoreboard.getObjective("AAA");
|
||||||
@ -29,6 +34,7 @@ public class FightScoreboard {
|
|||||||
public static void init(){
|
public static void init(){
|
||||||
Bukkit.getScheduler().scheduleSyncRepeatingTask(FightSystem.getPlugin(), () -> {
|
Bukkit.getScheduler().scheduleSyncRepeatingTask(FightSystem.getPlugin(), () -> {
|
||||||
objective.unregister();
|
objective.unregister();
|
||||||
|
//noinspection deprecation
|
||||||
scoreboard.registerNewObjective("AAA", "BBB");
|
scoreboard.registerNewObjective("AAA", "BBB");
|
||||||
objective.setDisplaySlot(DisplaySlot.SIDEBAR);
|
objective.setDisplaySlot(DisplaySlot.SIDEBAR);
|
||||||
|
|
||||||
@ -71,6 +77,12 @@ public class FightScoreboard {
|
|||||||
}else if(Config.WaterTechKO){
|
}else if(Config.WaterTechKO){
|
||||||
objective.getScore(Fight.getRedTeam().getPrefix() + "Wasser: " + WinconditionWaterTechKO.getTeamRedWater()).setScore(1);
|
objective.getScore(Fight.getRedTeam().getPrefix() + "Wasser: " + WinconditionWaterTechKO.getTeamRedWater()).setScore(1);
|
||||||
objective.getScore(Fight.getBlueTeam().getPrefix() + "Wasser: " + WinconditionWaterTechKO.getTeamBlueWater()).setScore(0);
|
objective.getScore(Fight.getBlueTeam().getPrefix() + "Wasser: " + WinconditionWaterTechKO.getTeamBlueWater()).setScore(0);
|
||||||
|
}else if(Config.RelativePercent){
|
||||||
|
objective.getScore(Fight.getRedTeam().getPrefix() + "Schaden: " + WinconditionRelativePercent.getRed().getPrintablePercent() + "%").setScore(1);
|
||||||
|
objective.getScore(Fight.getBlueTeam().getPrefix() + "Schaden: " + WinconditionRelativePercent.getBlue().getPrintablePercent() + "%").setScore(0);
|
||||||
|
}else if(Config.Points){
|
||||||
|
objective.getScore(Fight.getRedTeam().getPrefix() + "Punkte: " + WinconditionPoints.getRed().getPoints()).setScore(1);
|
||||||
|
objective.getScore(Fight.getBlueTeam().getPrefix() + "Punkte: " + WinconditionPoints.getBlue().getPoints()).setScore(0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -18,28 +18,22 @@ public class WinconditionAllDead extends PlayerWincondition {
|
|||||||
|
|
||||||
@EventHandler
|
@EventHandler
|
||||||
public void handlePlayerDeath(PlayerDeathEvent event) {
|
public void handlePlayerDeath(PlayerDeathEvent event) {
|
||||||
Player player = event.getEntity().getPlayer();
|
handleDeath(event.getEntity().getPlayer(), " §cist gestorben!");
|
||||||
|
|
||||||
if(!isTarget(player))
|
|
||||||
return;
|
|
||||||
|
|
||||||
FightTeam fightTeam = Fight.getPlayerTeam(player);
|
|
||||||
if(fightTeam.allPlayersOut()) {
|
|
||||||
Bukkit.broadcastMessage(FightSystem.PREFIX + "§cDer letzte Spieler aus " + fightTeam.getPrefix() + fightTeam.getColoredName() + " §cist gestorben!");
|
|
||||||
FightSystem.setSpectateState(Fight.getOpposite(fightTeam));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler
|
@EventHandler
|
||||||
public void handlePlayerQuit(PlayerQuitEvent event) {
|
public void handlePlayerQuit(PlayerQuitEvent event) {
|
||||||
Player player = event.getPlayer();
|
handleDeath(event.getPlayer(), " §chat den Kampf verlassen!");
|
||||||
|
}
|
||||||
|
|
||||||
|
private void handleDeath(Player player, String message){
|
||||||
if(!isTarget(player))
|
if(!isTarget(player))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
FightTeam fightTeam = Fight.getPlayerTeam(player);
|
FightTeam fightTeam = Fight.getPlayerTeam(player);
|
||||||
|
assert fightTeam != null; // Checked with isTarget
|
||||||
if(fightTeam.allPlayersOut()) {
|
if(fightTeam.allPlayersOut()) {
|
||||||
Bukkit.broadcastMessage(FightSystem.PREFIX + "§cDer letzte Spieler aus §6" + fightTeam.getPrefix() + fightTeam.getColoredName() + " §chat den Kampf verlassen!");
|
Bukkit.broadcastMessage(FightSystem.PREFIX + "§cDer letzte Spieler aus " + fightTeam.getColoredName() + message);
|
||||||
FightSystem.setSpectateState(Fight.getOpposite(fightTeam));
|
FightSystem.setSpectateState(Fight.getOpposite(fightTeam));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -18,28 +18,22 @@ public class WinconditionCaptainDead extends PlayerWincondition {
|
|||||||
|
|
||||||
@EventHandler
|
@EventHandler
|
||||||
public void handlePlayerDeath(PlayerDeathEvent event) {
|
public void handlePlayerDeath(PlayerDeathEvent event) {
|
||||||
Player player = event.getEntity().getPlayer();
|
handleDeath(event.getEntity().getPlayer(), " §cist gestorben!");
|
||||||
|
|
||||||
if(!isTarget(player))
|
|
||||||
return;
|
|
||||||
|
|
||||||
FightTeam fightTeam = Fight.getPlayerTeam(player);
|
|
||||||
if(fightTeam.isPlayerLeader(player)) {
|
|
||||||
Bukkit.broadcastMessage(FightSystem.PREFIX + "§cDer Leader von " + fightTeam.getPrefix() + fightTeam.getColoredName() + " §cist gestorben!");
|
|
||||||
FightSystem.setSpectateState(Fight.getOpposite(fightTeam));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler
|
@EventHandler
|
||||||
public void handlePlayerQuit(PlayerQuitEvent event) {
|
public void handlePlayerQuit(PlayerQuitEvent event) {
|
||||||
Player player = event.getPlayer();
|
handleDeath(event.getPlayer(), " §chat den Kampf verlassen!");
|
||||||
|
}
|
||||||
|
|
||||||
|
private void handleDeath(Player player, String message){
|
||||||
if(!isTarget(player))
|
if(!isTarget(player))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
FightTeam fightTeam = Fight.getPlayerTeam(player);
|
FightTeam fightTeam = Fight.getPlayerTeam(player);
|
||||||
|
assert fightTeam != null; // Checked with isTarget
|
||||||
if(fightTeam.isPlayerLeader(player)) {
|
if(fightTeam.isPlayerLeader(player)) {
|
||||||
Bukkit.broadcastMessage(FightSystem.PREFIX + "§cDer Leader von " + fightTeam.getPrefix() + fightTeam.getColoredName() + " §chat den Kampf verlassen!");
|
Bukkit.broadcastMessage(FightSystem.PREFIX + "§cDer Leader von " + fightTeam.getColoredName() + message);
|
||||||
FightSystem.setSpectateState(Fight.getOpposite(fightTeam));
|
FightSystem.setSpectateState(Fight.getOpposite(fightTeam));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,116 @@
|
|||||||
|
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 org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
import org.bukkit.event.EventHandler;
|
||||||
|
import org.bukkit.event.entity.PlayerDeathEvent;
|
||||||
|
import org.bukkit.event.player.PlayerQuitEvent;
|
||||||
|
|
||||||
|
public class WinconditionPoints extends PlayerWincondition {
|
||||||
|
|
||||||
|
private static TeamPoints blue;
|
||||||
|
private static TeamPoints red;
|
||||||
|
|
||||||
|
public WinconditionPoints(){
|
||||||
|
if(!Config.Points)
|
||||||
|
return;
|
||||||
|
|
||||||
|
init(true);
|
||||||
|
blue = new TeamPoints(Fight.getRedTeam(), WinconditionRelativePercent.getBlue(), WinconditionRelativePercent.getRed());
|
||||||
|
red = new TeamPoints(Fight.getBlueTeam(), WinconditionRelativePercent.getRed(), WinconditionRelativePercent.getBlue());
|
||||||
|
new TimeOverCountdown(this::fightEnds);
|
||||||
|
}
|
||||||
|
|
||||||
|
@EventHandler
|
||||||
|
public void handlePlayerDeath(PlayerDeathEvent event) {
|
||||||
|
handleDeath(event.getEntity().getPlayer(), " §cist gestorben!");
|
||||||
|
}
|
||||||
|
|
||||||
|
@EventHandler
|
||||||
|
public void handlePlayerQuit(PlayerQuitEvent event) {
|
||||||
|
handleDeath(event.getPlayer(), " §chat den Kampf verlassen!");
|
||||||
|
}
|
||||||
|
|
||||||
|
private void handleDeath(Player player, String message){
|
||||||
|
if(!isTarget(player))
|
||||||
|
return;
|
||||||
|
|
||||||
|
FightTeam fightTeam = Fight.getPlayerTeam(player);
|
||||||
|
TeamPoints enemy = getEnemyByTeam(fightTeam);
|
||||||
|
assert fightTeam != null; // Checked by isTarget
|
||||||
|
if(fightTeam.isPlayerLeader(player)) {
|
||||||
|
enemy.points += 500;
|
||||||
|
Bukkit.broadcastMessage(FightSystem.PREFIX + "§cDer Leader von " + fightTeam.getPrefix() + fightTeam.getColoredName() + message);
|
||||||
|
FightSystem.setSpectateState(Fight.getOpposite(fightTeam));
|
||||||
|
}else if(fightTeam.getPlayers().size() <= 5)
|
||||||
|
enemy.points += 300;
|
||||||
|
else
|
||||||
|
enemy.points += 200;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public static TeamPoints getRed(){
|
||||||
|
return red;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static TeamPoints getBlue(){
|
||||||
|
return blue;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void fightEnds(){
|
||||||
|
if(red.getPoints() > blue.getPoints())
|
||||||
|
FightSystem.setSpectateState(blue.enemy);
|
||||||
|
else if(red.getPoints() < blue.getPoints())
|
||||||
|
FightSystem.setSpectateState(red.enemy);
|
||||||
|
else
|
||||||
|
FightSystem.setSpectateState(null);
|
||||||
|
}
|
||||||
|
|
||||||
|
private TeamPoints getEnemyByTeam(FightTeam team){
|
||||||
|
if(team == blue.enemy)
|
||||||
|
return blue;
|
||||||
|
else
|
||||||
|
return red;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class TeamPoints extends PlayerWincondition {
|
||||||
|
private final FightTeam enemy;
|
||||||
|
private final WinconditionRelativePercent.TeamPercent enemyPercent;
|
||||||
|
private final 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;
|
||||||
|
init(true);
|
||||||
|
points = 0;
|
||||||
|
|
||||||
|
if(enemyPercent.getBlockCount() < ownPercent.getBlockCount())
|
||||||
|
this.factor = 10000; //Original mit 20 (20% = 0.2 ergeben 2000 Punkte
|
||||||
|
else{
|
||||||
|
double f = 10000 * ownPercent.getBlockCount() / enemyPercent.getBlockCount();
|
||||||
|
|
||||||
|
if(f > 10000)
|
||||||
|
f = 10000;
|
||||||
|
else if(f < 4000)
|
||||||
|
f = 4000;
|
||||||
|
|
||||||
|
this.factor = f;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getPoints(){
|
||||||
|
int damagePoints = (int)(enemyPercent.getPercent() * factor);
|
||||||
|
if(damagePoints > maxPoints)
|
||||||
|
damagePoints = maxPoints;
|
||||||
|
return points + damagePoints;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,99 @@
|
|||||||
|
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 org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.Material;
|
||||||
|
import org.bukkit.World;
|
||||||
|
|
||||||
|
import java.util.Collections;
|
||||||
|
import java.util.HashSet;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
|
public class WinconditionRelativePercent{
|
||||||
|
|
||||||
|
private static final Set<Material> ignoredBlocks;
|
||||||
|
private static TeamPercent blue;
|
||||||
|
private static TeamPercent red;
|
||||||
|
|
||||||
|
static{
|
||||||
|
Set<Material> ignored = new HashSet<>();
|
||||||
|
for(String s : Config.IgnoredBlocks)
|
||||||
|
ignored.add(Material.valueOf(s));
|
||||||
|
ignoredBlocks = Collections.unmodifiableSet(ignored);
|
||||||
|
}
|
||||||
|
|
||||||
|
public WinconditionRelativePercent(){
|
||||||
|
if(!Config.RelativePercent && !Config.Points)
|
||||||
|
return;
|
||||||
|
|
||||||
|
blue = new TeamPercent(Fight.getBlueTeam());
|
||||||
|
red = new TeamPercent(Fight.getRedTeam());
|
||||||
|
}
|
||||||
|
|
||||||
|
public static TeamPercent getBlue(){
|
||||||
|
return blue;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static TeamPercent getRed(){
|
||||||
|
return red;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class TeamPercent {
|
||||||
|
private static final World world = Bukkit.getWorlds().get(0);
|
||||||
|
private final FightTeam team;
|
||||||
|
private final int blockCount;
|
||||||
|
|
||||||
|
private int currentBlocks;
|
||||||
|
|
||||||
|
TeamPercent(FightTeam team){
|
||||||
|
this.team = team;
|
||||||
|
this.blockCount = currentBlocks();
|
||||||
|
|
||||||
|
Bukkit.getScheduler().runTaskTimerAsynchronously(FightSystem.getPlugin(), () -> {
|
||||||
|
currentBlocks = currentBlocks();
|
||||||
|
checkPercentDefeat();
|
||||||
|
}, 400, 400);
|
||||||
|
}
|
||||||
|
|
||||||
|
public double getPrintablePercent(){
|
||||||
|
return Math.round(10000.0 * getPercent()) / 100.0;
|
||||||
|
}
|
||||||
|
|
||||||
|
final int getBlockCount(){
|
||||||
|
return blockCount;
|
||||||
|
}
|
||||||
|
|
||||||
|
double getPercent(){
|
||||||
|
int blocksDestroyed = blockCount - currentBlocks;
|
||||||
|
return blocksDestroyed > 0 ? blocksDestroyed / (double) blockCount : 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
private int currentBlocks(){
|
||||||
|
if(FightSystem.isEntern())
|
||||||
|
return currentBlocks;
|
||||||
|
|
||||||
|
int blocks = 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(!ignoredBlocks.contains(world.getBlockAt(x,y,z).getType()))
|
||||||
|
blocks++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
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!");
|
||||||
|
FightSystem.setSpectateState(Fight.getOpposite(team));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -1,5 +1,6 @@
|
|||||||
package de.steamwar.fightsystem.winconditions;
|
package de.steamwar.fightsystem.winconditions;
|
||||||
|
|
||||||
|
import de.steamwar.fightsystem.FightSystem;
|
||||||
import de.steamwar.fightsystem.countdown.TimeOverCountdown;
|
import de.steamwar.fightsystem.countdown.TimeOverCountdown;
|
||||||
import de.steamwar.fightsystem.Config;
|
import de.steamwar.fightsystem.Config;
|
||||||
|
|
||||||
@ -8,6 +9,6 @@ public class WinconditionTimeout {
|
|||||||
if(!Config.Timeout)
|
if(!Config.Timeout)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
new TimeOverCountdown();
|
new TimeOverCountdown(() -> FightSystem.setSpectateState(null));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
In neuem Issue referenzieren
Einen Benutzer sperren