Finishing SG.eu Points Wincondition implementation
Signed-off-by: Lixfel <agga-games@gmx.de>
Dieser Commit ist enthalten in:
Ursprung
09acb366d3
Commit
dbae65bf82
@ -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
|
||||||
|
@ -5,6 +5,7 @@ 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.WinconditionRelativePercent;
|
||||||
import de.steamwar.fightsystem.winconditions.WinconditionWaterTechKO;
|
import de.steamwar.fightsystem.winconditions.WinconditionWaterTechKO;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
@ -12,16 +13,19 @@ 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");
|
||||||
@ -30,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);
|
||||||
|
|
||||||
@ -75,6 +80,9 @@ public class FightScoreboard {
|
|||||||
}else if(Config.RelativePercent){
|
}else if(Config.RelativePercent){
|
||||||
objective.getScore(Fight.getRedTeam().getPrefix() + "Schaden: " + WinconditionRelativePercent.getRed().getPrintablePercent() + "%").setScore(1);
|
objective.getScore(Fight.getRedTeam().getPrefix() + "Schaden: " + WinconditionRelativePercent.getRed().getPrintablePercent() + "%").setScore(1);
|
||||||
objective.getScore(Fight.getBlueTeam().getPrefix() + "Schaden: " + WinconditionRelativePercent.getBlue().getPrintablePercent() + "%").setScore(0);
|
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));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,10 +1,17 @@
|
|||||||
package de.steamwar.fightsystem.winconditions;
|
package de.steamwar.fightsystem.winconditions;
|
||||||
|
|
||||||
import de.steamwar.fightsystem.Config;
|
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.Fight;
|
||||||
import de.steamwar.fightsystem.fight.FightTeam;
|
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 {
|
public class WinconditionPoints extends PlayerWincondition {
|
||||||
|
|
||||||
private static TeamPoints blue;
|
private static TeamPoints blue;
|
||||||
private static TeamPoints red;
|
private static TeamPoints red;
|
||||||
@ -13,22 +20,69 @@ public class WinconditionPoints {
|
|||||||
if(!Config.Points)
|
if(!Config.Points)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
init(true);
|
||||||
blue = new TeamPoints(Fight.getRedTeam(), WinconditionRelativePercent.getBlue(), WinconditionRelativePercent.getRed());
|
blue = new TeamPoints(Fight.getRedTeam(), WinconditionRelativePercent.getBlue(), WinconditionRelativePercent.getRed());
|
||||||
red = new TeamPoints(Fight.getBlueTeam(), WinconditionRelativePercent.getRed(), WinconditionRelativePercent.getBlue());
|
red = new TeamPoints(Fight.getBlueTeam(), WinconditionRelativePercent.getRed(), WinconditionRelativePercent.getBlue());
|
||||||
|
new TimeOverCountdown(this::fightEnds);
|
||||||
}
|
}
|
||||||
|
|
||||||
public TeamPoints getRed(){
|
@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;
|
return red;
|
||||||
}
|
}
|
||||||
|
|
||||||
public TeamPoints getBlue(){
|
public static TeamPoints getBlue(){
|
||||||
return blue;
|
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 {
|
public static class TeamPoints extends PlayerWincondition {
|
||||||
private final FightTeam enemy;
|
private final FightTeam enemy;
|
||||||
private final WinconditionRelativePercent.TeamPercent enemyPercent;
|
private final WinconditionRelativePercent.TeamPercent enemyPercent;
|
||||||
private final double factor;
|
private final double factor;
|
||||||
|
private static final int maxPoints = 2000;
|
||||||
|
|
||||||
private int points;
|
private int points;
|
||||||
|
|
||||||
@ -39,14 +93,24 @@ public class WinconditionPoints {
|
|||||||
points = 0;
|
points = 0;
|
||||||
|
|
||||||
if(enemyPercent.getBlockCount() < ownPercent.getBlockCount())
|
if(enemyPercent.getBlockCount() < ownPercent.getBlockCount())
|
||||||
factor = 20;
|
this.factor = 10000; //Original mit 20 (20% = 0.2 ergeben 2000 Punkte
|
||||||
else{
|
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(){
|
public int getPoints(){
|
||||||
return points;
|
int damagePoints = (int)(enemyPercent.getPercent() * factor);
|
||||||
|
if(damagePoints > maxPoints)
|
||||||
|
damagePoints = maxPoints;
|
||||||
|
return points + damagePoints;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -62,20 +62,19 @@ public class WinconditionRelativePercent{
|
|||||||
return Math.round(10000.0 * getPercent()) / 100.0;
|
return Math.round(10000.0 * getPercent()) / 100.0;
|
||||||
}
|
}
|
||||||
|
|
||||||
public final int getBlockCount(){
|
final int getBlockCount(){
|
||||||
return blockCount;
|
return blockCount;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getCurrentBlocks(){
|
double getPercent(){
|
||||||
return currentBlocks;
|
|
||||||
}
|
|
||||||
|
|
||||||
private double getPercent(){
|
|
||||||
int blocksDestroyed = blockCount - currentBlocks;
|
int blocksDestroyed = blockCount - currentBlocks;
|
||||||
return blocksDestroyed > 0 ? blocksDestroyed / (double) blockCount : 0;
|
return blocksDestroyed > 0 ? blocksDestroyed / (double) blockCount : 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
private int currentBlocks(){
|
private int currentBlocks(){
|
||||||
|
if(FightSystem.isEntern())
|
||||||
|
return currentBlocks;
|
||||||
|
|
||||||
int blocks = 0;
|
int blocks = 0;
|
||||||
for(int x = team.getCornerX(); x < team.getCornerX() + Config.SchemsizeX; x++){
|
for(int x = team.getCornerX(); x < team.getCornerX() + Config.SchemsizeX; x++){
|
||||||
for(int y = team.getCornerY(); y < team.getCornerY() + Config.SchemsizeY; y++){
|
for(int y = team.getCornerY(); y < team.getCornerY() + Config.SchemsizeY; y++){
|
||||||
@ -91,7 +90,7 @@ public class WinconditionRelativePercent{
|
|||||||
private void checkPercentDefeat(){
|
private void checkPercentDefeat(){
|
||||||
if(!Config.RelativePercent)
|
if(!Config.RelativePercent)
|
||||||
return;
|
return;
|
||||||
if(getPercent() >= 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));
|
||||||
}
|
}
|
||||||
|
@ -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