Skip to content

Commit

Permalink
fix entity group limits not showing properly in limit panel
Browse files Browse the repository at this point in the history
  • Loading branch information
weaondara committed Sep 19, 2020
1 parent 0c107f2 commit 6c09746
Showing 1 changed file with 11 additions and 7 deletions.
18 changes: 11 additions & 7 deletions src/main/java/world/bentobox/limits/commands/LimitTab.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import org.eclipse.jdt.annotation.Nullable;

import com.google.common.collect.ImmutableMap;
import java.util.stream.Collectors;

import world.bentobox.bentobox.api.localization.TextVariables;
import world.bentobox.bentobox.api.panels.PanelItem;
Expand Down Expand Up @@ -86,7 +87,7 @@ public LimitTab(Limits addon, IslandBlockCount ibc, Map<Material, Integer> matLi
result = new ArrayList<>();
addMaterialIcons(ibc, matLimits);
addEntityLimits(ibc, island);
addEntityGroupLimits(island);
addEntityGroupLimits(ibc, island);
// Sort
switch (sortBy) {
default:
Expand All @@ -99,12 +100,15 @@ public LimitTab(Limits addon, IslandBlockCount ibc, Map<Material, Integer> matLi

}

private void addEntityGroupLimits(Island island) {
private void addEntityGroupLimits(IslandBlockCount ibc, Island island) {
// Entity group limits
List<Settings.EntityGroup> groupmap = addon.getSettings().getGroupLimitDefinitions();
Map<EntityGroup, Integer> groupmap = addon.getSettings().getGroupLimitDefinitions().stream().collect(Collectors.toMap(e -> e, e -> e.getLimit()));
Map<String, EntityGroup> groupbyname = groupmap.keySet().stream().collect(Collectors.toMap(e -> e.getName(), e -> e));
// Merge in any permission-based limits
// if (ibc != null) ibc.getEntityLimits().forEach(map::put);
groupmap.forEach(v -> {
if (ibc != null) ibc.getEntityGroupLimits().entrySet().stream()
.filter(e -> groupbyname.containsKey(e.getKey()))
.forEach(e -> groupmap.put(groupbyname.get(e.getKey()), e.getValue()));
groupmap.forEach((v, limit) -> {
PanelItemBuilder pib = new PanelItemBuilder();
EntityType k = v.getTypes().iterator().next();
pib.name(v.getName());
Expand All @@ -125,11 +129,11 @@ private void addEntityGroupLimits(Island island) {
}
pib.icon(m);
long count = getCount(island, v);
String color = count >= v.getLimit() ? user.getTranslation("island.limits.max-color") : user.getTranslation("island.limits.regular-color");
String color = count >= limit ? user.getTranslation("island.limits.max-color") : user.getTranslation("island.limits.regular-color");
description += color
+ user.getTranslation("island.limits.block-limit-syntax",
TextVariables.NUMBER, String.valueOf(count),
"[limit]", String.valueOf(v.getLimit()));
"[limit]", String.valueOf(limit));
pib.description(description);
result.add(pib.build());
});
Expand Down

0 comments on commit 6c09746

Please sign in to comment.