Added type chevrons
This commit is contained in:
parent
598ccf383c
commit
b9ea6ecddd
|
@ -4,7 +4,6 @@ import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.EnumMap;
|
import java.util.EnumMap;
|
||||||
import java.util.HashSet;
|
|
||||||
import java.util.LinkedHashSet;
|
import java.util.LinkedHashSet;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
@ -68,7 +67,7 @@ public class Settings {
|
||||||
}
|
}
|
||||||
addon.log("Entity limits:");
|
addon.log("Entity limits:");
|
||||||
limits.entrySet().stream().map(e -> "Limit " + e.getKey().toString() + " to " + e.getValue()).forEach(addon::log);
|
limits.entrySet().stream().map(e -> "Limit " + e.getKey().toString() + " to " + e.getValue()).forEach(addon::log);
|
||||||
|
|
||||||
//group limits
|
//group limits
|
||||||
el = addon.getConfig().getConfigurationSection("entitygrouplimits");
|
el = addon.getConfig().getConfigurationSection("entitygrouplimits");
|
||||||
if (el != null) {
|
if (el != null) {
|
||||||
|
@ -91,13 +90,13 @@ public class Settings {
|
||||||
continue;
|
continue;
|
||||||
EntityGroup group = new EntityGroup(name, entities, limit);
|
EntityGroup group = new EntityGroup(name, entities, limit);
|
||||||
entities.forEach(e -> {
|
entities.forEach(e -> {
|
||||||
List<EntityGroup> groups = groupLimits.getOrDefault(e, new ArrayList());
|
List<EntityGroup> groups = groupLimits.getOrDefault(e, new ArrayList<>());
|
||||||
groups.add(group);
|
groups.add(group);
|
||||||
groupLimits.put(e, groups);
|
groupLimits.put(e, groups);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
addon.log("Entity group limits:");
|
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);
|
getGroupLimitDefinitions().stream().map(e -> "Limit " + e.getName() + " (" + e.getTypes().stream().map(x -> x.name()).collect(Collectors.joining(", ")) + ") to " + e.getLimit()).forEach(addon::log);
|
||||||
}
|
}
|
||||||
|
@ -119,7 +118,7 @@ public class Settings {
|
||||||
public Map<EntityType, List<EntityGroup>> getGroupLimits() {
|
public Map<EntityType, List<EntityGroup>> getGroupLimits() {
|
||||||
return groupLimits;
|
return groupLimits;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return the group limit definitions
|
* @return the group limit definitions
|
||||||
*/
|
*/
|
||||||
|
@ -144,7 +143,7 @@ public class Settings {
|
||||||
this.types = types;
|
this.types = types;
|
||||||
this.limit = limit;
|
this.limit = limit;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean contains(EntityType type) {
|
public boolean contains(EntityType type) {
|
||||||
return types.contains(type);
|
return types.contains(type);
|
||||||
}
|
}
|
||||||
|
|
|
@ -198,7 +198,7 @@ public class EntityLimitListener implements Listener {
|
||||||
Map<Settings.EntityGroup, Integer> groupsLimits = new HashMap<>();
|
Map<Settings.EntityGroup, Integer> groupsLimits = new HashMap<>();
|
||||||
if (addon.getBlockLimitListener().getIsland(island.getUniqueId()) != null) {
|
if (addon.getBlockLimitListener().getIsland(island.getUniqueId()) != null) {
|
||||||
limitAmount = addon.getBlockLimitListener().getIsland(island.getUniqueId()).getEntityLimit(ent.getType());
|
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 -> {
|
groupdefs.forEach(def -> {
|
||||||
int limit = addon.getBlockLimitListener().getIsland(island.getUniqueId()).getEntityGroupLimit(def.getName());
|
int limit = addon.getBlockLimitListener().getIsland(island.getUniqueId()).getEntityGroupLimit(def.getName());
|
||||||
if (limit >= 0)
|
if (limit >= 0)
|
||||||
|
@ -211,11 +211,11 @@ public class EntityLimitListener implements Listener {
|
||||||
}
|
}
|
||||||
if (addon.getSettings().getGroupLimits().containsKey(ent.getType())) {
|
if (addon.getSettings().getGroupLimits().containsKey(ent.getType())) {
|
||||||
addon.getSettings().getGroupLimits().getOrDefault(ent.getType(), new ArrayList<>()).stream()
|
addon.getSettings().getGroupLimits().getOrDefault(ent.getType(), new ArrayList<>()).stream()
|
||||||
.filter(group -> !groupsLimits.containsKey(group) || groupsLimits.get(group) > group.getLimit())
|
.filter(group -> !groupsLimits.containsKey(group) || groupsLimits.get(group) > group.getLimit())
|
||||||
.forEach(group -> groupsLimits.put(group, group.getLimit()));
|
.forEach(group -> groupsLimits.put(group, group.getLimit()));
|
||||||
}
|
}
|
||||||
if (limitAmount < 0 && groupsLimits.isEmpty()) return new AtLimitResult();
|
if (limitAmount < 0 && groupsLimits.isEmpty()) return new AtLimitResult();
|
||||||
|
|
||||||
// We have to count the entities
|
// We have to count the entities
|
||||||
if (limitAmount >= 0)
|
if (limitAmount >= 0)
|
||||||
{
|
{
|
||||||
|
@ -225,7 +225,7 @@ public class EntityLimitListener implements Listener {
|
||||||
if (count >= limitAmount)
|
if (count >= limitAmount)
|
||||||
return new AtLimitResult(ent.getType(), limitAmount);
|
return new AtLimitResult(ent.getType(), limitAmount);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Now do the group limits
|
// Now do the group limits
|
||||||
for (Map.Entry<Settings.EntityGroup, Integer> group : groupsLimits.entrySet()) { //do not use lambda
|
for (Map.Entry<Settings.EntityGroup, Integer> group : groupsLimits.entrySet()) { //do not use lambda
|
||||||
if (group.getValue() < 0)
|
if (group.getValue() < 0)
|
||||||
|
@ -238,13 +238,13 @@ public class EntityLimitListener implements Listener {
|
||||||
}
|
}
|
||||||
return new AtLimitResult();
|
return new AtLimitResult();
|
||||||
}
|
}
|
||||||
|
|
||||||
private class AtLimitResult {
|
private class AtLimitResult {
|
||||||
private Map.Entry<EntityType, Integer> typelimit;
|
private Map.Entry<EntityType, Integer> typelimit;
|
||||||
private Map.Entry<EntityGroup, Integer> grouplimit;
|
private Map.Entry<EntityGroup, Integer> grouplimit;
|
||||||
|
|
||||||
public AtLimitResult() {}
|
public AtLimitResult() {}
|
||||||
|
|
||||||
public AtLimitResult(EntityType type, int limit) {
|
public AtLimitResult(EntityType type, int limit) {
|
||||||
typelimit = new AbstractMap.SimpleEntry<>(type, limit);
|
typelimit = new AbstractMap.SimpleEntry<>(type, limit);
|
||||||
}
|
}
|
||||||
|
@ -252,7 +252,7 @@ public class EntityLimitListener implements Listener {
|
||||||
public AtLimitResult(EntityGroup type, int limit) {
|
public AtLimitResult(EntityGroup type, int limit) {
|
||||||
grouplimit = new AbstractMap.SimpleEntry<>(type, limit);
|
grouplimit = new AbstractMap.SimpleEntry<>(type, limit);
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean hit() {
|
public boolean hit() {
|
||||||
return typelimit != null || grouplimit != null;
|
return typelimit != null || grouplimit != null;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue