mirror of
https://github.com/BentoBoxWorld/BentoBox.git
synced 2024-11-22 10:45:22 +01:00
Merge pull request #2300 from BentoBoxWorld/2299_placeholder_counts
Placeholder counts
This commit is contained in:
commit
b43197d54f
2
pom.xml
2
pom.xml
@ -88,7 +88,7 @@
|
||||
<!-- Do not change unless you want different name for local builds. -->
|
||||
<build.number>-LOCAL</build.number>
|
||||
<!-- This allows to change between versions. -->
|
||||
<build.version>2.0.1</build.version>
|
||||
<build.version>2.1.0</build.version>
|
||||
<sonar.organization>bentobox-world</sonar.organization>
|
||||
<sonar.host.url>https://sonarcloud.io</sonar.host.url>
|
||||
<server.jars>${project.basedir}/lib</server.jars>
|
||||
|
@ -4,6 +4,8 @@ import java.util.Arrays;
|
||||
import java.util.Optional;
|
||||
import java.util.UUID;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.eclipse.jdt.annotation.NonNull;
|
||||
import org.eclipse.jdt.annotation.Nullable;
|
||||
@ -167,6 +169,26 @@ public class PlaceholdersManager {
|
||||
return "";
|
||||
});
|
||||
}
|
||||
// Counts
|
||||
// Number of online members
|
||||
registerPlaceholder(addon, "island_online_members_count", user -> {
|
||||
if (user == null)
|
||||
return "";
|
||||
Island island = plugin.getIslands().getIsland(addon.getOverWorld(), user);
|
||||
return island != null
|
||||
? String.valueOf(island.getMemberSet(RanksManager.MEMBER_RANK).stream()
|
||||
.map(Bukkit::getOfflinePlayer).filter(OfflinePlayer::isOnline).count())
|
||||
: "";
|
||||
});
|
||||
// Number of online members of visited island
|
||||
registerPlaceholder(addon, "visited_island_online_members_count", user -> {
|
||||
if (user == null)
|
||||
return "";
|
||||
return plugin.getIslands().getIslandAt(user.getLocation())
|
||||
.map(island -> String.valueOf(island.getMemberSet(RanksManager.MEMBER_RANK).stream()
|
||||
.map(Bukkit::getOfflinePlayer).filter(OfflinePlayer::isOnline).count()))
|
||||
.orElse("");
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -77,7 +77,7 @@ public class PlaceholdersManagerTest {
|
||||
public void testRegisterGameModePlaceholdersAllDefaults() {
|
||||
pm.registerDefaultPlaceholders(addon);
|
||||
// + 300 because we register team member placeholders up to 50 members
|
||||
verify(hook, times(GameModePlaceholder.values().length + 300)).registerPlaceholder(any(), anyString(), any());
|
||||
verify(hook, times(GameModePlaceholder.values().length + 302)).registerPlaceholder(any(), anyString(), any());
|
||||
}
|
||||
|
||||
/**
|
||||
@ -91,6 +91,7 @@ public class PlaceholdersManagerTest {
|
||||
pm.registerDefaultPlaceholders(addon);
|
||||
|
||||
// 3 less registrations for this addon
|
||||
verify(hook, times(GameModePlaceholder.values().length - 3 + 300)).registerPlaceholder(any(), anyString(), any());
|
||||
verify(hook, times(GameModePlaceholder.values().length - 3 + 302)).registerPlaceholder(any(), anyString(),
|
||||
any());
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user