Skip to content
This repository has been archived by the owner on Dec 1, 2024. It is now read-only.

feat: Village composition display & commandline simplification #57

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# Compiled class file
*.class
target/

# Log file
*.log
Expand All @@ -23,3 +24,7 @@ hs_err_pid*

# Minecraft data
/minecraft_data

# Editor configs
.settings
.vscode
18 changes: 8 additions & 10 deletions src/main/java/fr/leomelki/loupgarou/MainLg.java
Original file line number Diff line number Diff line change
Expand Up @@ -228,11 +228,10 @@ public boolean onCommand(CommandSender sender, Command command, String label, St
sender.sendMessage(prefix+"§aLa position a bien été ajoutée !");
return true;
}else if(args[0].equalsIgnoreCase("end")) {
if(args.length != 2) {
sender.sendMessage("§4Utilisation : §c/lg end <pseudo>");
return true;
}
Player selected = Bukkit.getPlayer(args[1]);
Player selected = (args.length == 2)
? Bukkit.getPlayer(args[1])
: (Player)sender;

if(selected == null) {
sender.sendMessage("§4Erreur : §cLe joueur §4"+args[1]+"§c n'est pas connecté.");
return true;
Expand All @@ -247,11 +246,10 @@ public boolean onCommand(CommandSender sender, Command command, String label, St
game.broadcastMessage("§cLa partie a été arrêtée de force !");
return true;
}else if(args[0].equalsIgnoreCase("start")) {
if(args.length < 2) {
sender.sendMessage("§4Utilisation : §c/lg start <pseudo>");
return true;
}
Player player = Bukkit.getPlayer(args[1]);
Player player = (args.length == 2)
? Bukkit.getPlayer(args[1])
: (Player)sender;

if(player == null) {
sender.sendMessage("§4Erreur : §cLe joueur §4"+args[1]+"§c n'existe pas !");
return true;
Expand Down
29 changes: 24 additions & 5 deletions src/main/java/fr/leomelki/loupgarou/classes/LGGame.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import java.util.HashMap;
import java.util.List;
import java.util.Map.Entry;
import java.util.stream.Collectors;

import org.bukkit.Bukkit;
import org.bukkit.GameMode;
Expand Down Expand Up @@ -607,13 +608,32 @@ public void endGame(LGWinType winType) {
lgp.getPlayer().closeInventory();

cancelWait();//Also avoid bugs

ended = true;
//We unregister every role listener because they are unused after the game's end !
for(Role role : getRoles())
HandlerList.unregisterAll(role);

final Boolean shouldDisplayWinners = (winners.size() >= 1);

broadcastSpacer();
broadcastMessage("§9----------- §lFIN DE LA PARTIE -----------");
broadcastMessage(winType.getMessage());

if (shouldDisplayWinners) {
final List<String> winnerNames = winners.stream().map(lgp -> lgp.getName()).collect(Collectors.toList());
final String winnersFriendlyName = (winners.size() > 1) ? "aux vainqueurs" : "au vainqueur";
broadcastMessage("§6§l§oFélicitations " + winnersFriendlyName + ": §7§l" + String.join(", ", winnerNames));
}

broadcastSpacer();
broadcastMessage("§e§lLa composition du village à cette partie était la suivante");

//We unregister every role listener because they are unused after the game's end !
for(Role role : getRoles()) {
final List<String> playerNames = role.getPlayersThisRound().stream().map(lgp -> lgp.getName()).collect(Collectors.toList());
broadcastMessage("§e - " + role.getName() + " §e: §7§l" + String.join(", ", playerNames));
HandlerList.unregisterAll(role);
}

broadcastSpacer();

for(LGPlayer lgp : getInGame()) {
lgp.leaveChat();
lgp.joinChat(spectatorChat);
Expand All @@ -630,7 +650,6 @@ public void endGame(LGWinType winType) {
else
lgp.sendTitle("§c§lDéfaite...", "§4Vous avez perdu la partie.", 200);


Player p = lgp.getPlayer();
lgp.showView();
p.removePotionEffect(PotionEffectType.JUMP);
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/fr/leomelki/loupgarou/roles/Role.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
public abstract class Role implements Listener{
@Getter @Setter private int waitedPlayers;
@Getter private ArrayList<LGPlayer> players = new ArrayList<LGPlayer>();
@Getter private ArrayList<LGPlayer> playersThisRound = new ArrayList<LGPlayer>();
@Getter private final LGGame game;

public Role(LGGame game) {
Expand Down Expand Up @@ -95,6 +96,7 @@ public void run() {
public void join(LGPlayer player, boolean sendMessage) {
System.out.println(player.getName()+" est "+getName());
players.add(player);
playersThisRound.add(player);
if(player.getRole() == null)
player.setRole(this);
waitedPlayers--;
Expand Down