-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Make a game per player for joining parties
- Loading branch information
1 parent
ee443b7
commit cbc3a1a
Showing
5 changed files
with
81 additions
and
44 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
51 changes: 51 additions & 0 deletions
51
src/main/java/dev/emortal/minestom/marathon/MarathonGameRunner.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
package dev.emortal.minestom.marathon; | ||
|
||
import dev.emortal.minestom.gamesdk.config.GameCreationInfo; | ||
import dev.emortal.minestom.gamesdk.game.Game; | ||
import net.minestom.server.entity.Player; | ||
import net.minestom.server.instance.Instance; | ||
import org.jetbrains.annotations.NotNull; | ||
|
||
import java.util.HashMap; | ||
import java.util.Map; | ||
import java.util.UUID; | ||
|
||
public final class MarathonGameRunner extends Game { | ||
|
||
private final Map<UUID, MarathonGame> games = new HashMap<>(); | ||
|
||
public MarathonGameRunner(@NotNull GameCreationInfo creationInfo) { | ||
super(creationInfo); | ||
} | ||
|
||
@Override | ||
public void start() { | ||
} | ||
|
||
@Override | ||
public void onJoin(@NotNull Player player) { | ||
MarathonGame game = this.games.computeIfAbsent(player.getUuid(), uuid -> new MarathonGame(player, this.getEventNode())); | ||
game.onJoin(player); | ||
} | ||
|
||
@Override | ||
public void onLeave(@NotNull Player player) { | ||
// Do nothing - game SDK will check if player count is 0 and end the game | ||
} | ||
|
||
@Override | ||
public void cleanUp() { | ||
for (MarathonGame game : this.games.values()) { | ||
game.cleanUp(); | ||
} | ||
} | ||
|
||
@Override | ||
public @NotNull Instance getSpawningInstance(@NotNull Player player) { | ||
MarathonGame game = this.games.get(player.getUuid()); | ||
if (game == null) { | ||
throw new IllegalStateException("No game found for player " + player.getUsername() + " when instance requested!"); | ||
} | ||
return game.getInstance(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters