Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add simple status command #124

Draft
wants to merge 10 commits into
base: master
Choose a base branch
from
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,17 @@

import co.aikar.commands.BaseCommand;
import co.aikar.commands.CommandHelp;
import co.aikar.commands.annotation.*;
import co.aikar.commands.annotation.CatchUnknown;
import co.aikar.commands.annotation.CommandAlias;
import co.aikar.commands.annotation.CommandCompletion;
import co.aikar.commands.annotation.CommandPermission;
import co.aikar.commands.annotation.Conditions;
import co.aikar.commands.annotation.Default;
import co.aikar.commands.annotation.Dependency;
import co.aikar.commands.annotation.Description;
import co.aikar.commands.annotation.Optional;
import co.aikar.commands.annotation.Subcommand;
import co.aikar.commands.annotation.Values;
import co.aikar.commands.bukkit.contexts.OnlinePlayer;
import me.roinujnosde.titansbattle.BaseGameConfiguration;
import me.roinujnosde.titansbattle.TitansBattle;
Expand Down Expand Up @@ -188,4 +198,24 @@ public void watch(Player sender, Game game, @Optional ArenaConfiguration arena)
SoundUtils.playSound(SoundUtils.Type.WATCH, plugin.getConfig(), sender);
}

@Subcommand("%status|status")
@CommandPermission("titansbattle.status")
SrBedrock marked this conversation as resolved.
Show resolved Hide resolved
@Conditions("happening")
@Description("{@@command.description.status}")
public void status(Player sender) {
plugin.debug(String.format("%s used /tb status", sender.getName()));
java.util.Optional<Game> currentGame = gameManager.getCurrentGame();
if (!currentGame.isPresent()) {
sender.sendMessage(plugin.getLang("not-starting-or-started"));
return;
}

Game game = currentGame.get();
if (game.getConfig().isGroupMode()) {
sender.sendMessage(plugin.getLang("game_status_group", game, Helper.buildStringFrom(game.getGroupParticipants())));
} else {
sender.sendMessage(plugin.getLang("game_status", game, game.getParticipants().size()));
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public abstract class GroupManager {
protected final Function<String, GroupData> idToData;
protected final TitansBattle plugin;

public GroupManager(@NotNull TitansBattle plugin) {
protected GroupManager(@NotNull TitansBattle plugin) {
this.plugin = plugin;
this.idToData = plugin.getDatabaseManager()::getGroupData;
}
Expand Down Expand Up @@ -76,7 +76,9 @@ public Set<Warrior> getWarriors(@NotNull final Group group) {
* @return the built String
*/
public @NotNull String buildStringFrom(@NotNull Collection<Group> groups) {
return Helper.buildStringFrom(groups.stream().filter(Objects::nonNull).map(Group::getName)
return Helper.buildStringFrom(groups.stream()
.filter(Objects::nonNull)
.map(Group::getName)
.collect(Collectors.toList()));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,9 @@ public boolean sameGroup(@NotNull UUID player1, @NotNull UUID player2) {

@Override
public @NotNull String buildStringFrom(@NotNull Collection<Group> groups) {
return Helper.buildStringFrom(groups.stream().map(Group::getId).collect(Collectors.toList()));
return Helper.buildStringFrom(groups.stream()
.map(Group::getId)
.map(String::toUpperCase)
.collect(Collectors.toList()));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -53,11 +53,6 @@ public GameConfiguration(@NotNull Map<String, Object> data) {
ConfigUtils.deserialize(this, data);
}

@Override
public Map<String, Object> serialize() {
return ConfigUtils.serialize(this);
}

/**
* The name of the class responsible for managing this game
*
Expand Down Expand Up @@ -91,14 +86,6 @@ public Integer getMinimumPlayers() {
return Math.max(2, minimumPlayers);
}

public Integer getPreparationTime() {
return preparationTime;
}

public Integer getExpirationTime() {
return expirationTime;
}

public Integer getAnnouncementGameInfoInterval() {
return announcementGameInfoInterval;
}
Expand Down
21 changes: 20 additions & 1 deletion src/main/java/me/roinujnosde/titansbattle/utils/Helper.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import me.roinujnosde.titansbattle.dao.ConfigurationDao;
import me.roinujnosde.titansbattle.games.Game;
import me.roinujnosde.titansbattle.types.GameConfiguration;
import me.roinujnosde.titansbattle.types.Group;
import me.roinujnosde.titansbattle.types.Warrior;
import me.roinujnosde.titansbattle.types.Winners;
import org.bukkit.Bukkit;
Expand All @@ -16,7 +17,14 @@
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import java.util.*;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Collection;
import java.util.Date;
import java.util.List;
import java.util.Map;
import java.util.TreeMap;
import java.util.UUID;
import java.util.stream.Collectors;

public class Helper {
Expand Down Expand Up @@ -322,6 +330,17 @@ public static boolean isWinnerQuitMessageEnabled(Player player) {
return sb.toString();
}

public static @NotNull String buildStringFrom(@NotNull Map<Group, Integer> groupIntegerMap) {
StringBuilder sb = new StringBuilder();
for (Map.Entry<Group, Integer> entry : groupIntegerMap.entrySet()) {
sb.append(entry.getKey().getId().toUpperCase())
.append("(")
.append(entry.getValue())
.append(") ");
}
return sb.toString();
}

/**
* Gets a String filled with the specified quantity of spaces
*
Expand Down
1 change: 1 addition & 0 deletions src/main/resources/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ commands:
info: "info"
setwinner: "setwinner"
config: "config"
status: "status"

#Sounds used in games, to disable one leave it ""
sounds:
Expand Down
3 changes: 3 additions & 0 deletions src/main/resources/language-en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ command.description.challenge.create: "Creates a challenge config file"
command.description.challenge.setdestination: "Sets a destination for a challenge"
command.description.challenge.setkit: "Sets your inventory as the kit for a challenge"
command.description.setwinner: "Sets a player as the winner"
command.description.status: "Shows the game status"
objective: "&a» Objective: &cKill all your opponents to win!"
item_not_allowed: "&c» You can't join the game with this item: {0}"
challenge_item_not_allowed: "&c» You can't join the challenge with this item: {0}"
Expand Down Expand Up @@ -119,6 +120,8 @@ game_info: "!!broadcast&b» There are {0} players and {1} groups participating!
game_info_duels: "!!broadcast&b» Current duel:\n &f{0} &bx &f{1}"
game_info_next_duels: "\n&bNext duels:\n{2}"
game_info_duels_line: " &b{0}. &f{1} &bx &f{2}\n"
game_status: "&b» Game Status: {0} players alive"
game_status_group: "&b» Game Status: {0}"
player_joined: "&b» {0} has joined the game!"
items_to_receive: "&b» You still have {0} item stacks to receive, clear your inventory and do not disconnect!"
clear-your-inventory: "&b» Clear your inventory before you join this game!"
Expand Down
3 changes: 3 additions & 0 deletions src/main/resources/plugin.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ permissions:
titansbattle.challenge.group: true
titansbattle.challenge.player: true
titansbattle.challenge.accept: true
titansbattle.status: true
titansbattle.challenge.accept:
default: false
titansbattle.challenge.player:
Expand Down Expand Up @@ -76,3 +77,5 @@ permissions:
default: false
titansbattle.setwinner:
default: false
titansbattle.status:
default: false
Loading