Skip to content

Commit

Permalink
Merge pull request #177 from Braekpo1nt/139-make-final-game
Browse files Browse the repository at this point in the history
Last minute changes from game day
  • Loading branch information
Braekpo1nt authored Apr 13, 2023
2 parents 2158c62 + cfde576 commit a6b23a4
Show file tree
Hide file tree
Showing 5 changed files with 61 additions and 14 deletions.
29 changes: 18 additions & 11 deletions src/main/java/org/braekpo1nt/mctmanager/games/GameManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -328,18 +328,25 @@ public void gameIsOver() {
hubManager.returnParticipantsToHubWithDelay(getOnlineParticipants());
}

public void finalGameIsOver(String winningTeam) {
activeGame = null;
List<Player> winningTeamParticipants = getOnlinePlayersOnTeam(winningTeam);
String colorString = gameStateStorageUtil.getTeamColorString(winningTeam);
ChatColor chatColor = ColorMap.getChatColor(colorString);
List<Player> otherParticipants = new ArrayList<>();
for (Player player : getOnlineParticipants()) {
if (!winningTeamParticipants.contains(player)) {
otherParticipants.add(player);
public void finalGameIsOver(String winningTeamName) {
Bukkit.getLogger().info("Final game is over");
new BukkitRunnable() {
@Override
public void run() {
activeGame = null;
String winningTeamDisplayName = gameStateStorageUtil.getTeamDisplayName(winningTeamName);
List<Player> winningTeamParticipants = getOnlinePlayersOnTeam(winningTeamName);
String colorString = gameStateStorageUtil.getTeamColorString(winningTeamName);
ChatColor chatColor = ColorMap.getChatColor(colorString);
List<Player> otherParticipants = new ArrayList<>();
for (Player player : getOnlineParticipants()) {
if (!winningTeamParticipants.contains(player)) {
otherParticipants.add(player);
}
}
hubManager.pedestalTeleport(winningTeamParticipants, winningTeamDisplayName, chatColor, otherParticipants);
}
}
hubManager.pedestalTeleport(winningTeamParticipants, winningTeam, chatColor, otherParticipants);
}.runTaskLater(plugin, 5*20);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@

public class FinalGame implements MCTGame, Listener {

private static final int MAX_KILLS = 3;
private static final int MAX_KILLS = 9;
private final Main plugin;
private final GameManager gameManager;
private final World finalGameWorld;
Expand Down Expand Up @@ -215,6 +215,7 @@ public void onPlayerDeath(PlayerDeathEvent event) {
if (teamWith3Kills != null) {
finishFinalGame(teamWith3Kills);
}
event.setCancelled(true);
}

private void finishFinalGame(String winningTeam) {
Expand All @@ -224,7 +225,7 @@ private void finishFinalGame(String winningTeam) {
.append(Component.text(" wins MCT #1!"))
.color(teamColor)
.decorate(TextDecoration.BOLD));
stop();
stop(winningTeam);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.entity.EntityDamageEvent;
import org.bukkit.event.player.PlayerMoveEvent;
import org.bukkit.potion.PotionEffect;
import org.bukkit.potion.PotionEffectType;
Expand Down Expand Up @@ -112,6 +113,15 @@ public void onParticipantQuit(Player participant) {

}

@EventHandler
public void onPlayerDamage(EntityDamageEvent event) {
if (!gameActive) {
return;
}
event.setCancelled(true);
}


@EventHandler
public void onPlayerMove(PlayerMoveEvent event) {
if (!gameActive) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,9 @@ private void onParticipantDeath(Player killed) {
participantsAlive.put(killed.getUniqueId(), false);
for (Player participant : participants) {
if (!participant.getUniqueId().equals(killed.getUniqueId())) {
gameManager.awardPointsToPlayer(participant, 10);
if (participantsAlive.get(participant.getUniqueId())) {
gameManager.awardPointsToPlayer(participant, 10);
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.entity.EntityDamageEvent;
import org.bukkit.event.player.PlayerMoveEvent;
import org.bukkit.plugin.Plugin;

Expand Down Expand Up @@ -52,6 +53,32 @@ public void onPlayerOutofBounds(PlayerMoveEvent event) {
}

}

@EventHandler
public void onPlayerDamage(EntityDamageEvent event) {
if (!boundaryEnabled) {
return;
}

if (!(event.getEntity() instanceof Player)) {
return;
}
Player player = ((Player) event.getEntity());

Plugin multiversePlugin = Bukkit.getPluginManager().getPlugin("Multiverse-Core");
MultiverseCore multiverseCore = ((MultiverseCore) multiversePlugin);
MVWorldManager worldManager = multiverseCore.getMVWorldManager();
MultiverseWorld hubWorld = worldManager.getMVWorld("Hub");
MultiverseWorld playerWorld = worldManager.getMVWorld(player.getWorld());

// make sure the player is in the hub world
if (playerWorld.equals(hubWorld)) {
if (!event.getCause().equals(EntityDamageEvent.DamageCause.LAVA)
|| event.getCause().equals(EntityDamageEvent.DamageCause.FIRE)) {
event.setCancelled(true);
}
}
}

public void disableBoundary() {
boundaryEnabled = false;
Expand Down

0 comments on commit a6b23a4

Please sign in to comment.