feat(war): add battle interface

This commit is contained in:
darksaid98 committed 2023-10-31 10:30:32 +01:00
1 parent ed9d00bf74
commit 5658eda886
3 files changed
+35 -23

No files matched your search

@@ -176,7 +176,7 @@ public class SiegeCommands {
if (!(args.get("siege") instanceof final @NotNull Siege siege)) if (!(args.get("siege") instanceof final @NotNull Siege siege))
throw CommandAPIBukkit.failWithAdventureComponent(ColorParser.of("<red>Invalid siege.").build()); throw CommandAPIBukkit.failWithAdventureComponent(ColorParser.of("<red>Invalid siege.").build());
siege.noWinner(); siege.equalWin();
} }
private static void siegeAbandon(Player p, @NotNull CommandArguments args, boolean asAdmin) throws WrapperCommandSyntaxException { private static void siegeAbandon(Player p, @NotNull CommandArguments args, boolean asAdmin) throws WrapperCommandSyntaxException {
@@ -1,30 +1,42 @@
package com.github.alathra.AlathranWars.conflict.battle; package com.github.alathra.AlathranWars.conflict.battle;
public class Battle { import org.jetbrains.annotations.NotNull;
/*private int attackerPoints;
private int defenderPoints;
public int getAttackerPoints() { import java.util.UUID;
return this.attackerPoints;
public interface Battle {
void start(); // Initiates battle
void stop(); // Ends battle
void resume(); // Resume battle after server restart or plugin reload
void attackersWin(); // A Attacker victory
void defendersWin(); // A Defender victory
void equalWin(); // A Draw
UUID uuid = null; // Battle UUID
default @NotNull UUID getUUID() {
return uuid;
} }
public void setAttackerPoints(int points) { /**
this.attackerPoints = points; * Equals boolean.
*
* @param uuid the uuid
* @return the boolean
*/
default boolean equals(UUID uuid) {
return getUUID().equals(uuid);
} }
public int getDefenderPoints() { /**
return this.defenderPoints; * Equals boolean.
*
* @param battle the battle
* @return the boolean
*/
default boolean equals(@NotNull Battle battle) {
return getUUID().equals(battle.getUUID());
} }
public void setDefenderPoints(int points) {
this.defenderPoints = points;
}
public void addPointsToAttackers(final int points) {
this.attackerPoints += points;
}
public void addPointsToDefenders(final int points) {
this.defenderPoints += points;
}*/
} }
@@ -31,7 +31,7 @@ import java.util.*;
import java.util.stream.Collectors; import java.util.stream.Collectors;
import java.util.stream.Stream; import java.util.stream.Stream;
public class Siege extends Battle { public class Siege implements Battle {
public static final Duration SIEGE_DURATION = Duration.ofMinutes(60); public static final Duration SIEGE_DURATION = Duration.ofMinutes(60);
public static final int MAX_SIEGE_PROGRESS_MINUTES = 8; // How many minutes attackers will need to be on point uncontested for to reach 100% public static final int MAX_SIEGE_PROGRESS_MINUTES = 8; // How many minutes attackers will need to be on point uncontested for to reach 100%
public static final int MAX_SIEGE_PROGRESS = 60 * 10 * MAX_SIEGE_PROGRESS_MINUTES; // On reaching this, the attackers win. 10 points is added per second public static final int MAX_SIEGE_PROGRESS = 60 * 10 * MAX_SIEGE_PROGRESS_MINUTES; // On reaching this, the attackers win. 10 points is added per second
@@ -284,7 +284,7 @@ public class Siege extends Battle {
/** /**
* No winner declared * No winner declared
*/ */
public void noWinner() { public void equalWin() {
Bukkit.broadcast( Bukkit.broadcast(
ColorParser.of("<prefix>The siege of <town> has ended in a draw!") ColorParser.of("<prefix>The siege of <town> has ended in a draw!")
.parseMinimessagePlaceholder("prefix", UtilsChat.getPrefix()) .parseMinimessagePlaceholder("prefix", UtilsChat.getPrefix())