Skip to content

Commit

Permalink
Implement winner commands in game configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
goodbyepavlyi committed Jul 23, 2023
1 parent 913acfb commit d9f4169
Show file tree
Hide file tree
Showing 5 changed files with 60 additions and 31 deletions.
54 changes: 28 additions & 26 deletions Plugin/pom.xml
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.goodbyepavlyi</groupId>
<artifactId>plugin</artifactId>
<packaging>jar</packaging>
<name>LavaRise</name>
<version>1.0.0</version>
<version>1.1.0</version>

<repositories>
<repository>
Expand All @@ -26,13 +27,13 @@
<version>1.8.8-R0.1-SNAPSHOT</version>
<type>jar</type>
<scope>provided</scope>
<optional>true</optional>
</dependency>
</dependencies>

<build>
<directory>../dist</directory>
<finalName>LavaRise</finalName>
<outputDirectory>./server/plugins</outputDirectory>

<resources>
<resource>
Expand Down Expand Up @@ -66,30 +67,31 @@
</executions>
</plugin>

<!-- <plugin>-->
<!-- <groupId>org.apache.maven.plugins</groupId>-->
<!-- <artifactId>maven-resources-plugin</artifactId>-->
<!-- <version>3.2.0</version>-->
<!-- <executions>-->
<!-- <execution>-->
<!-- <id>copy-files-on-build</id>-->
<!-- <phase>package</phase>-->
<!-- <goals>-->
<!-- <goal>copy-resources</goal>-->
<!-- </goals>-->
<!-- <configuration>-->
<!-- <outputDirectory>${project.build.outputDirectory}</outputDirectory>-->
<!-- <resources>-->
<!-- <resource>-->
<!-- <directory>${project.build.directory}</directory>-->
<!-- <include>${project.build.finalName}.jar</include>-->
<!-- <filtering>false</filtering>-->
<!-- </resource>-->
<!-- </resources>-->
<!-- </configuration>-->
<!-- </execution>-->
<!-- </executions>-->
<!-- </plugin>-->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
<version>3.2.0</version>
<executions>
<execution>
<id>copy-files-on-build</id>
<phase>package</phase>
<goals>
<goal>copy-resources</goal>
</goals>
<configuration>
<outputDirectory>${project.build.outputDirectory}</outputDirectory>
<resources>
<resource>
<directory>${project.build.directory}</directory>
<include>${project.build.finalName}.jar</include>
<filtering>false</filtering>
</resource>
</resources>
</configuration>
</execution>
</executions>
</plugin>

<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -151,15 +151,34 @@ public void switchToLavaMode() {
}

public void checkForWinner() {
if (this.arena.getPlayers().stream().filter(gamePlayer -> !gamePlayer.isSpectator()).count() > 1) return;
long remainingPlayers = this.arena.getPlayers().stream()
.filter(gamePlayer -> !gamePlayer.isSpectator())
.count();

if (remainingPlayers > 1)
return;

if (remainingPlayers == 1) {
GamePlayer winner = this.arena.getPlayers().stream()
.filter(gamePlayer -> !gamePlayer.isSpectator())
.findFirst()
.orElse(null);

this.instance.getConfiguration().GAME_COMMANDS_WINNER().forEach(command -> {
String winnerCommand = command.replace("%winner%", winner.getPlayer().getName());
this.instance.getServer().dispatchCommand(this.instance.getServer().getConsoleSender(), winnerCommand);
});
}

this.stop();

this.instance.debug(Level.INFO, String.format("Checked for winner in arena %s", this.arena.getName()));
}

public void makeSpectator(Player player) {
this.checkForWinner();

GamePlayer gamePlayer = this.arena.getPlayer(player.getUniqueId());
if (gamePlayer == null) return;

gamePlayer.spectate();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ public void playerDeath(PlayerDeathEvent event) {

Game game = arena.getGame();
game.makeSpectator(player);
game.checkForWinner();

this.instance.debug(Level.INFO, String.format("Player %s died in arena %s", player.getName(), arena.getName()));
}
Expand All @@ -71,7 +70,6 @@ public void playerDamage(EntityDamageEvent event) {
Game game = arena.getGame();
arena.announce(Arena.Announce.PLAYER_DEATH, player.getName());
game.makeSpectator(player);
game.checkForWinner();

this.instance.debug(Level.INFO, String.format("Player %s died in arena %s (Cancelled)", player.getName(), arena.getName()));
}
Expand Down Expand Up @@ -101,7 +99,6 @@ public void playerDisconnect(PlayerQuitEvent event) {

Game game = arena.getGame();
game.makeSpectator(player);
game.checkForWinner();

this.instance.debug(Level.INFO, String.format("Player %s disconnected in arena %s", player.getName(), arena.getName()));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ public List<Material> GAME_ITEMS() {
.collect(Collectors.toList());
}

public List<String> GAME_COMMANDS_WINNER() {
return this.getConfig().getStringList("game.commands.winner");
}

public int QUEUE_COUNTDOWN() {
return this.getConfig().getInt("queue.countdown");
}
Expand Down
7 changes: 7 additions & 0 deletions Plugin/src/main/resources/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,17 @@
game:
gracePhaseTime: 60 # Duration of the grace phase in seconds
lavaRisingTime: 5 # Time it takes for the lava to rise in seconds

# List of items that players will receive during the game
items:
- "IRON_AXE" # Example of an item that players will receive
- "IRON_PICKAXE" # Another example of an item

# Commands to be executed when a player wins the game
commands:
winner:
- "tell %winner% You won the game!" # Send a congratulatory message to the winner using %winner% placeholder

# Configuration for the queue settings
queue:
countdown: 45 # Countdown time in seconds before the game starts
Expand Down

0 comments on commit d9f4169

Please sign in to comment.