Skip to content

Commit

Permalink
Refactored round/game ending code, config options for times
Browse files Browse the repository at this point in the history
Took 2 hours 23 minutes
  • Loading branch information
TheNathanSpace committed Sep 4, 2021
1 parent 1d0c566 commit b668402
Show file tree
Hide file tree
Showing 21 changed files with 304 additions and 288 deletions.
7 changes: 5 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

### Bugs

- Names are all white
- **Names are all white**
- can still get over wall barriers
- `NullPointerException` with `GamePlayer`
- Defending team logging out times are weird
Expand All @@ -11,12 +11,15 @@
- Team buff effects are sometimes persisting in-between rounds(/games?)
- Double "join" message
- Some instances start where coins don't decrease when buying stuff
- Citizens NPCs aren't deleted properly, so they stick around in Citizens' config

### Features

- Time to forfeit config option
- Building time config option
- Re-examine forfeit system to make sure it works as intended
- Package maps with plugin
- Add more game modifiers like First to 5 (stars) or Most stars in 8 minutes
- Can you add a config option for the assault command /help to not override normal /help if you have a permission?

- Actual documentation

Expand Down
2 changes: 1 addition & 1 deletion dependency-reduced-pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<groupId>com.thekingelessar.assault</groupId>
<artifactId>assault</artifactId>
<name>Assault</name>
<version>0.11.5</version>
<version>0.11.6</version>
<description>Still in development</description>
<url>https://github.com/thekingelessar/assault</url>
<build>
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>com.thekingelessar.assault</groupId>
<artifactId>assault</artifactId>
<version>0.11.5</version>
<version>0.11.6</version>
<packaging>jar</packaging>
<name>Assault</name>
<url>https://github.com/thekingelessar/assault</url>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package com.thekingelessar.assault.commands;

import com.thekingelessar.assault.Assault;
import com.thekingelessar.assault.game.GameInstance;
import com.thekingelessar.assault.game.team.GameTeam;
import org.bukkit.ChatColor;
import org.bukkit.Color;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
Expand All @@ -21,21 +21,21 @@ public boolean onCommand(CommandSender sender, Command command, String label, St
sender.sendMessage(ChatColor.RED + "You don't have permission to use that command");
return true;
}

Player player = (Player) sender;
GameInstance gameInstance = GameInstance.getPlayerGameInstance(player);

if (gameInstance != null)
{
GameTeam gameTeam = gameInstance.getPlayerTeam(player);

if (gameTeam.canForfeit() || (args != null && args.length != 0 && args[0].equalsIgnoreCase("force")))
if (gameTeam.canForfeit() || (args != null && args.length != 0 && args[0].equalsIgnoreCase("force") && player.hasPermission("assault.command.forceforfeit")))
{
gameTeam.toggleForfeit(player);
}
else
{
player.sendRawMessage(Assault.ASSAULT_PREFIX + "Your team cannot forfeit right now! You probably need to wait longer.");
player.sendRawMessage(Color.RED + "The defending team cannot forfeit!");
return true;
}
}
Expand Down
131 changes: 131 additions & 0 deletions src/main/java/com/thekingelessar/assault/game/GameEndManager.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,131 @@
package com.thekingelessar.assault.game;

import com.thekingelessar.assault.Assault;
import com.thekingelessar.assault.game.player.GamePlayer;
import com.thekingelessar.assault.game.player.PlayerMode;
import com.thekingelessar.assault.game.team.GameTeam;
import com.thekingelessar.assault.game.timertasks.TaskCountdownGameEnd;
import com.thekingelessar.assault.game.world.WorldManager;
import com.thekingelessar.assault.util.FireworkUtils;
import com.thekingelessar.assault.util.Title;
import com.thekingelessar.assault.util.Util;
import org.bukkit.ChatColor;
import org.bukkit.entity.Player;
import org.bukkit.scheduler.BukkitRunnable;

public class GameEndManager
{
GameInstance gameInstance;

public GameEndManager(GameInstance gameInstance)
{
this.gameInstance = gameInstance;
}

// alertLastEnemyLeft

// separate end of round and declare winners

public enum WinState
{
LOWEST_TIME,
ATTACKERS_LEFT,
DEFENDERS_LEFT,
BUILDING_LEFT;
}


public void declareWinners(WinState winState)
{
gameInstance.gameStage = GameStage.FINISHED;

String winnerTitleString = gameInstance.winningTeam.color.chatColor + ChatColor.BOLD.toString() + "YOU" + ChatColor.WHITE + " WIN!";
String loserTitleString = gameInstance.winningTeam.color.getFormattedName(true, true, ChatColor.BOLD) + ChatColor.WHITE + " team wins!";

String subtitleString;

switch (winState)
{
case LOWEST_TIME:
subtitleString = "Time: " + ChatColor.LIGHT_PURPLE + Util.secondsToMinutes(Util.round(gameInstance.winningTeam.finalAttackingTime, 2), false) + ChatColor.WHITE + " seconds";
break;

case ATTACKERS_LEFT:
subtitleString = "All of the " + gameInstance.getAttackingTeam().color.chatColor + "attackers" + ChatColor.RESET + " left!";
break;

case DEFENDERS_LEFT:
GameTeam disconnectedTeam = gameInstance.getRemainingTeam().getOppositeTeam();
subtitleString = "The " + disconnectedTeam.color.chatColor + "enemy team" + ChatColor.RESET + " disconnected!";
break;

case BUILDING_LEFT:
disconnectedTeam = gameInstance.getRemainingTeam().getOppositeTeam();
subtitleString = "The " + disconnectedTeam.color.chatColor + "enemy team" + ChatColor.RESET + " disconnected!";
break;

default:
throw new IllegalStateException("Unexpected value: " + winState);
}

Title winnerTitle = new Title(winnerTitleString, subtitleString, 0, 6, 1);
Title loserTitle = new Title(loserTitleString, subtitleString, 0, 6, 1);

for (Player player : gameInstance.winningTeam.getPlayers())
{
for (int i = 0; i < 5; i++)
{
FireworkUtils.spawnRandomFirework(player.getLocation(), gameInstance.winningTeam.color);
}

winnerTitle.clearTitle(player);
winnerTitle.send(player);

PlayerMode playerMode = PlayerMode.setPlayerMode(player, PlayerMode.HAM, gameInstance);
}

for (Player player : gameInstance.winningTeam.getOppositeTeam().getPlayers())
{
loserTitle.clearTitle(player);
loserTitle.send(player);

PlayerMode playerMode = PlayerMode.setPlayerMode(player, PlayerMode.HAM, gameInstance);
}

gameInstance.taskCountdownGameEnd = new TaskCountdownGameEnd(240, 20, 20, gameInstance);
gameInstance.taskCountdownGameEnd.runTaskTimer(Assault.INSTANCE, gameInstance.taskCountdownGameEnd.startDelay, gameInstance.taskCountdownGameEnd.tickDelay);

gameInstance.updateScoreboards();

}

public void cleanupGameInstance()
{
for (GameTeam gameTeam : gameInstance.teams.values())
{
gameTeam.mapBase.destroyShops();
}

for (BukkitRunnable taskTimer : gameInstance.allTimers)
{
taskTimer.cancel();
}

for (GameTeam gameTeam : gameInstance.teams.values())
{
gameTeam.buffList.clear();

for (Player player : gameTeam.getPlayers())
{
GamePlayer gamePlayer = gameTeam.getGamePlayer(player);
gamePlayer.scoreboard.delete();
gameTeam.removeMember(player);
}

gameTeam.teamScoreboard.unregister();
}

WorldManager.closeWorld(gameInstance.gameWorld);
Assault.gameInstances.remove(gameInstance);
}
}
Loading

0 comments on commit b668402

Please sign in to comment.