Skip to content

Commit

Permalink
Added type chevrons
Browse files Browse the repository at this point in the history
  • Loading branch information
tastybento committed Jun 26, 2020
1 parent 598ccf3 commit b9ea6ec
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 14 deletions.
11 changes: 5 additions & 6 deletions src/main/java/world/bentobox/limits/Settings.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import java.util.Arrays;
import java.util.Collections;
import java.util.EnumMap;
import java.util.HashSet;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Map;
Expand Down Expand Up @@ -68,7 +67,7 @@ public Settings(Limits addon) {
}
addon.log("Entity limits:");
limits.entrySet().stream().map(e -> "Limit " + e.getKey().toString() + " to " + e.getValue()).forEach(addon::log);

//group limits
el = addon.getConfig().getConfigurationSection("entitygrouplimits");
if (el != null) {
Expand All @@ -91,13 +90,13 @@ public Settings(Limits addon) {
continue;
EntityGroup group = new EntityGroup(name, entities, limit);
entities.forEach(e -> {
List<EntityGroup> groups = groupLimits.getOrDefault(e, new ArrayList());
List<EntityGroup> groups = groupLimits.getOrDefault(e, new ArrayList<>());
groups.add(group);
groupLimits.put(e, groups);
});
}
}

addon.log("Entity group limits:");
getGroupLimitDefinitions().stream().map(e -> "Limit " + e.getName() + " (" + e.getTypes().stream().map(x -> x.name()).collect(Collectors.joining(", ")) + ") to " + e.getLimit()).forEach(addon::log);
}
Expand All @@ -119,7 +118,7 @@ public Map<EntityType, Integer> getLimits() {
public Map<EntityType, List<EntityGroup>> getGroupLimits() {
return groupLimits;
}

/**
* @return the group limit definitions
*/
Expand All @@ -144,7 +143,7 @@ public EntityGroup(String name, Set<EntityType> types, int limit) {
this.types = types;
this.limit = limit;
}

public boolean contains(EntityType type) {
return types.contains(type);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ private AtLimitResult atLimit(Island island, Entity ent) {
Map<Settings.EntityGroup, Integer> groupsLimits = new HashMap<>();
if (addon.getBlockLimitListener().getIsland(island.getUniqueId()) != null) {
limitAmount = addon.getBlockLimitListener().getIsland(island.getUniqueId()).getEntityLimit(ent.getType());
List<Settings.EntityGroup> groupdefs = addon.getSettings().getGroupLimits().getOrDefault(ent.getType(), new ArrayList());
List<Settings.EntityGroup> groupdefs = addon.getSettings().getGroupLimits().getOrDefault(ent.getType(), new ArrayList<>());
groupdefs.forEach(def -> {
int limit = addon.getBlockLimitListener().getIsland(island.getUniqueId()).getEntityGroupLimit(def.getName());
if (limit >= 0)
Expand All @@ -211,11 +211,11 @@ private AtLimitResult atLimit(Island island, Entity ent) {
}
if (addon.getSettings().getGroupLimits().containsKey(ent.getType())) {
addon.getSettings().getGroupLimits().getOrDefault(ent.getType(), new ArrayList<>()).stream()
.filter(group -> !groupsLimits.containsKey(group) || groupsLimits.get(group) > group.getLimit())
.forEach(group -> groupsLimits.put(group, group.getLimit()));
.filter(group -> !groupsLimits.containsKey(group) || groupsLimits.get(group) > group.getLimit())
.forEach(group -> groupsLimits.put(group, group.getLimit()));
}
if (limitAmount < 0 && groupsLimits.isEmpty()) return new AtLimitResult();

// We have to count the entities
if (limitAmount >= 0)
{
Expand All @@ -225,7 +225,7 @@ private AtLimitResult atLimit(Island island, Entity ent) {
if (count >= limitAmount)
return new AtLimitResult(ent.getType(), limitAmount);
}

// Now do the group limits
for (Map.Entry<Settings.EntityGroup, Integer> group : groupsLimits.entrySet()) { //do not use lambda
if (group.getValue() < 0)
Expand All @@ -238,21 +238,21 @@ private AtLimitResult atLimit(Island island, Entity ent) {
}
return new AtLimitResult();
}

private class AtLimitResult {
private Map.Entry<EntityType, Integer> typelimit;
private Map.Entry<EntityGroup, Integer> grouplimit;

public AtLimitResult() {}

public AtLimitResult(EntityType type, int limit) {
typelimit = new AbstractMap.SimpleEntry<>(type, limit);
}

public AtLimitResult(EntityGroup type, int limit) {
grouplimit = new AbstractMap.SimpleEntry<>(type, limit);
}

public boolean hit() {
return typelimit != null || grouplimit != null;
}
Expand Down

0 comments on commit b9ea6ec

Please sign in to comment.