Skip to content

Commit 0cb7ce1

Browse files
committed
refactor: define the game messages in the messages/game.properties and use their keys instead
1 parent b72b114 commit 0cb7ce1

File tree

3 files changed

+41
-4
lines changed

3 files changed

+41
-4
lines changed

spigot/src/main/java/io/tofpu/speedbridge2/game/infra/command/GameCommand.java

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package io.tofpu.speedbridge2.game.infra.command;
22

33
import io.tofpu.speedbridge2.command.ChildrenCommand;
4+
import io.tofpu.speedbridge2.game.infra.message.GameMessage;
45
import io.tofpu.speedbridge2.game.service.GameService;
56
import io.tofpu.speedbridge2.island.domain.Island;
67
import revxrsal.commands.annotation.Subcommand;
@@ -17,18 +18,22 @@ public GameCommand(GameService gameService) {
1718
@Subcommand("join")
1819
public void joinGame(BukkitCommandActor actor, Island island) {
1920
if (gameService.startGame(actor.requirePlayer(), island)) {
20-
actor.reply(String.format("You joined island %d", island.slot()));
21+
GameMessage.GAME_JOINED.of(island.slot())
22+
.send(actor.sender());
2123
} else {
22-
actor.reply("&cYou're already in a game!");
24+
GameMessage.ALREADY_IN_GAME.of(island.slot())
25+
.send(actor.sender());
2326
}
2427
}
2528

2629
@Subcommand("leave")
2730
public void leaveGame(BukkitCommandActor actor) {
2831
if (gameService.stopGame(actor.requirePlayer())) {
29-
actor.reply("&eYou left the game");
32+
GameMessage.GAME_LEFT.of()
33+
.send(actor.sender());
3034
} else {
31-
actor.reply("&cYou're not in a game!");
35+
GameMessage.NOT_IN_GAME.of()
36+
.send(actor.sender());
3237
}
3338
}
3439
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
package io.tofpu.speedbridge2.game.infra.message;
2+
3+
import io.tofpu.speedbridge2.util.message.MessageKey;
4+
5+
public enum GameMessage implements MessageKey {
6+
GAME_JOINED("game.joined", "game"),
7+
ALREADY_IN_GAME("game.alreadyInGame", "game"),
8+
GAME_LEFT("game.left", "game"),
9+
NOT_IN_GAME("game.notInGame", "game");
10+
11+
private final String key;
12+
private final String component;
13+
14+
GameMessage(String key, String component) {
15+
this.key = key;
16+
this.component = component;
17+
}
18+
19+
@Override
20+
public String key() {
21+
return key;
22+
}
23+
24+
@Override
25+
public String component() {
26+
return component;
27+
}
28+
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
game.joined=&eYou have joined island {0}!
2+
game.alreadyInGame=&cYou are already in a game!
3+
game.left=&eYou have left island {0}!
4+
game.notInGame=&cYou are not in a game!

0 commit comments

Comments
 (0)