mirror of
https://github.com/BentoBoxWorld/BentoBox.git
synced 2025-02-10 09:21:31 +01:00
Improved the IslandTeamCommand: added last joined timestamp for offline team members
Redid the whole layout - it looks much nicer now! Implements https://github.com/BentoBoxWorld/BentoBox/issues/997
This commit is contained in:
parent
1304f8bace
commit
85b45df13b
@ -1,13 +1,17 @@
|
||||
package world.bentobox.bentobox.api.commands.island.team;
|
||||
|
||||
import java.time.Duration;
|
||||
import java.time.Instant;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
|
||||
import org.bukkit.OfflinePlayer;
|
||||
import org.eclipse.jdt.annotation.NonNull;
|
||||
import org.eclipse.jdt.annotation.Nullable;
|
||||
import world.bentobox.bentobox.api.commands.CompositeCommand;
|
||||
@ -15,6 +19,8 @@ import world.bentobox.bentobox.api.events.IslandBaseEvent;
|
||||
import world.bentobox.bentobox.api.events.team.TeamEvent;
|
||||
import world.bentobox.bentobox.api.localization.TextVariables;
|
||||
import world.bentobox.bentobox.api.user.User;
|
||||
import world.bentobox.bentobox.database.objects.Island;
|
||||
import world.bentobox.bentobox.managers.RanksManager;
|
||||
|
||||
public class IslandTeamCommand extends CompositeCommand {
|
||||
|
||||
@ -76,10 +82,77 @@ public class IslandTeamCommand extends CompositeCommand {
|
||||
}
|
||||
}
|
||||
// Show members of island
|
||||
getIslands().getIsland(getWorld(), playerUUID).showMembers(user);
|
||||
showMembers(getIslands().getIsland(getWorld(), playerUUID), user);
|
||||
return true;
|
||||
}
|
||||
|
||||
private void showMembers(Island island, User user) {
|
||||
// Gather online members
|
||||
List<UUID> onlineMembers = island.getMemberSet(RanksManager.MEMBER_RANK).stream()
|
||||
.filter(uuid -> Bukkit.getOfflinePlayer(uuid).isOnline()).collect(Collectors.toList());
|
||||
|
||||
// List of ranks that we will loop through
|
||||
Integer[] ranks = new Integer[]{RanksManager.OWNER_RANK, RanksManager.SUB_OWNER_RANK, RanksManager.MEMBER_RANK, RanksManager.TRUSTED_RANK, RanksManager.COOP_RANK};
|
||||
|
||||
// Show header:
|
||||
user.sendMessage("commands.island.team.info.header",
|
||||
"[max]", String.valueOf(inviteCommand.getMaxTeamSize(user)),
|
||||
"[total]", String.valueOf(island.getMemberSet().size()),
|
||||
"[online]", String.valueOf(onlineMembers.size()));
|
||||
|
||||
// We now need to get all online "members" of the island - incl. Trusted and coop
|
||||
onlineMembers = island.getMemberSet(RanksManager.COOP_RANK).stream()
|
||||
.filter(uuid -> Bukkit.getOfflinePlayer(uuid).isOnline()).collect(Collectors.toList());
|
||||
|
||||
for (int rank : ranks) {
|
||||
Set<UUID> players = island.getMemberSet(rank, false);
|
||||
if (!players.isEmpty()) {
|
||||
if (rank == RanksManager.OWNER_RANK) {
|
||||
// Slightly special handling for the owner rank
|
||||
user.sendMessage("commands.island.team.info.rank-layout.owner",
|
||||
TextVariables.RANK, user.getTranslation(RanksManager.OWNER_RANK_REF));
|
||||
} else {
|
||||
user.sendMessage("commands.island.team.info.rank-layout.generic",
|
||||
TextVariables.RANK, user.getTranslation(getPlugin().getRanksManager().getRank(rank)),
|
||||
TextVariables.NUMBER, String.valueOf(island.getMemberSet(rank, false).size()));
|
||||
}
|
||||
for (UUID member : island.getMemberSet(rank, false)) {
|
||||
OfflinePlayer offlineMember = Bukkit.getOfflinePlayer(member);
|
||||
if (onlineMembers.contains(member)) {
|
||||
// the player is online
|
||||
user.sendMessage("commands.island.team.info.member-layout.online",
|
||||
TextVariables.NAME, offlineMember.getName());
|
||||
} else {
|
||||
// A bit of handling for the last joined date
|
||||
Instant lastJoined = Instant.ofEpochMilli(offlineMember.getLastPlayed());
|
||||
Instant now = Instant.now();
|
||||
|
||||
Duration duration = Duration.between(lastJoined, now);
|
||||
String lastSeen;
|
||||
final String reference = "commands.island.team.info.last-seen.layout";
|
||||
if (duration.toMinutes() < 60L) {
|
||||
lastSeen = user.getTranslation(reference,
|
||||
TextVariables.NUMBER, String.valueOf(duration.toMinutes()),
|
||||
"[unit]", user.getTranslation("commands.island.team.info.last-seen.minutes"));
|
||||
} else if (duration.toHours() < 24L) {
|
||||
lastSeen = user.getTranslation(reference,
|
||||
TextVariables.NUMBER, String.valueOf(duration.toHours()),
|
||||
"[unit]", user.getTranslation("commands.island.team.info.last-seen.hours"));
|
||||
} else {
|
||||
lastSeen = user.getTranslation(reference,
|
||||
TextVariables.NUMBER, String.valueOf(duration.toDays()),
|
||||
"[unit]", user.getTranslation("commands.island.team.info.last-seen.days"));
|
||||
}
|
||||
|
||||
user.sendMessage("commands.island.team.info.member-layout.offline",
|
||||
TextVariables.NAME, offlineMember.getName(),
|
||||
"[last_seen]", lastSeen);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private boolean fireEvent(User user) {
|
||||
IslandBaseEvent event = TeamEvent.builder()
|
||||
.island(getIslands()
|
||||
|
@ -479,6 +479,21 @@ commands:
|
||||
description: "manage your team"
|
||||
info:
|
||||
description: "display detailed info about your team"
|
||||
member-layout:
|
||||
online: "&a&l o &r&f[name]"
|
||||
offline: "&c&l o &r&f[name] &7([last_seen])"
|
||||
last-seen:
|
||||
layout: "&b[number] &7[unit] ago"
|
||||
days: "days"
|
||||
hours: "hours"
|
||||
minutes: "minutes"
|
||||
header: |+
|
||||
&f--- &aTeam details &f---
|
||||
&aMembers: &b[total]&7/&b[max]
|
||||
&aOnline members: &b[online]
|
||||
rank-layout:
|
||||
owner: "&6[rank]:"
|
||||
generic: "&6[rank] &7(&b[number]&7)&6:"
|
||||
coop:
|
||||
description: "make a player coop rank on your island"
|
||||
parameters: "<player>"
|
||||
|
@ -161,7 +161,6 @@ public class IslandTeamCommandTest {
|
||||
public void testExecuteUserStringListOfStringIslandIsNotFull() {
|
||||
assertTrue(tc.execute(user, "team", Collections.emptyList()));
|
||||
verify(user).sendMessage(eq("commands.island.team.invite.you-can-invite"), eq(TextVariables.NUMBER), eq("3"));
|
||||
verify(island).showMembers(eq(user));
|
||||
}
|
||||
|
||||
/**
|
||||
@ -172,7 +171,6 @@ public class IslandTeamCommandTest {
|
||||
when(user.getPermissionValue(eq("bskyblock.team.maxsize"), anyInt())).thenReturn(0);
|
||||
assertTrue(tc.execute(user, "team", Collections.emptyList()));
|
||||
verify(user).sendMessage(eq("commands.island.team.invite.errors.island-is-full"));
|
||||
verify(island).showMembers(eq(user));
|
||||
}
|
||||
|
||||
/**
|
||||
@ -233,5 +231,4 @@ public class IslandTeamCommandTest {
|
||||
tc.removeInvite(invitee);
|
||||
assertNull(tc.getInvite(invitee));
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user