mirror of
https://github.com/BentoBoxWorld/Limits.git
synced 2024-09-27 14:12:57 +02:00
Added API to enable offset for limits.
This commit is contained in:
parent
ad1f060d76
commit
76c582ba1d
@ -110,7 +110,7 @@ public class Settings {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return the limits
|
* @return the entity limits
|
||||||
*/
|
*/
|
||||||
public Map<EntityType, Integer> getLimits() {
|
public Map<EntityType, Integer> getLimits() {
|
||||||
return Collections.unmodifiableMap(limits);
|
return Collections.unmodifiableMap(limits);
|
||||||
|
@ -141,7 +141,7 @@ public class LimitsCalc {
|
|||||||
|
|
||||||
private void tidyUp() {
|
private void tidyUp() {
|
||||||
if (ibc == null) {
|
if (ibc == null) {
|
||||||
ibc = new IslandBlockCount();
|
ibc = new IslandBlockCount(island.getUniqueId(), plugin.getIWM().getAddon(world).map(a -> a.getDescription().getName()).orElse("default"));
|
||||||
}
|
}
|
||||||
ibc.setBlockCounts(blockCount.entrySet().stream()
|
ibc.setBlockCounts(blockCount.entrySet().stream()
|
||||||
.collect(Collectors.toMap(
|
.collect(Collectors.toMap(
|
||||||
|
@ -220,7 +220,6 @@ public class EntityLimitListener implements Listener {
|
|||||||
addon.getIslands().getIslandAt(e.getLocation()).ifPresent(island -> {
|
addon.getIslands().getIslandAt(e.getLocation()).ifPresent(island -> {
|
||||||
// Check if creature is allowed to spawn or not
|
// Check if creature is allowed to spawn or not
|
||||||
AtLimitResult res = atLimit(island, e);
|
AtLimitResult res = atLimit(island, e);
|
||||||
|
|
||||||
if (bypass || island.isSpawn() || !res.hit()) {
|
if (bypass || island.isSpawn() || !res.hit()) {
|
||||||
// Allowed
|
// Allowed
|
||||||
if (async) {
|
if (async) {
|
||||||
@ -433,6 +432,7 @@ public class EntityLimitListener implements Listener {
|
|||||||
.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)
|
||||||
{
|
{
|
||||||
@ -440,10 +440,10 @@ public class EntityLimitListener implements Listener {
|
|||||||
.filter(e -> e.getType().equals(ent.getType()))
|
.filter(e -> e.getType().equals(ent.getType()))
|
||||||
.filter(e -> island.inIslandSpace(e.getLocation()))
|
.filter(e -> island.inIslandSpace(e.getLocation()))
|
||||||
.count();
|
.count();
|
||||||
if (count >= limitAmount)
|
if (count >= limitAmount) {
|
||||||
return new AtLimitResult(ent.getType(), limitAmount);
|
return new AtLimitResult(ent.getType(), limitAmount);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
// Merge in any permission-based limits
|
// Merge in any permission-based limits
|
||||||
if (addon.getBlockLimitListener().getIsland(island.getUniqueId()) != null) {
|
if (addon.getBlockLimitListener().getIsland(island.getUniqueId()) != null) {
|
||||||
Map<String, EntityGroup> groupbyname = groupsLimits.keySet().stream().collect(Collectors.toMap(e -> e.getName(), e -> e));
|
Map<String, EntityGroup> groupbyname = groupsLimits.keySet().stream().collect(Collectors.toMap(e -> e.getName(), e -> e));
|
||||||
@ -451,7 +451,6 @@ public class EntityLimitListener implements Listener {
|
|||||||
.filter(e -> groupbyname.containsKey(e.getKey()))
|
.filter(e -> groupbyname.containsKey(e.getKey()))
|
||||||
.forEach(e -> groupsLimits.put(groupbyname.get(e.getKey()), e.getValue()));
|
.forEach(e -> groupsLimits.put(groupbyname.get(e.getKey()), e.getValue()));
|
||||||
}
|
}
|
||||||
|
|
||||||
// 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)
|
||||||
|
@ -39,9 +39,12 @@ public class IslandBlockCount implements DataObject {
|
|||||||
private Map<EntityType, Integer> entityLimits = new EnumMap<>(EntityType.class);
|
private Map<EntityType, Integer> entityLimits = new EnumMap<>(EntityType.class);
|
||||||
@Expose
|
@Expose
|
||||||
private Map<String, Integer> entityGroupLimits = new HashMap<>();
|
private Map<String, Integer> entityGroupLimits = new HashMap<>();
|
||||||
|
@Expose
|
||||||
// Required for YAML database
|
private Map<Material, Integer> blockLimitsOffset = new EnumMap<>(Material.class);
|
||||||
public IslandBlockCount() {}
|
@Expose
|
||||||
|
private Map<EntityType, Integer> entityLimitsOffset = new EnumMap<>(EntityType.class);
|
||||||
|
@Expose
|
||||||
|
private Map<String, Integer> entityGroupLimitsOffset = new HashMap<>();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create an island block count object
|
* Create an island block count object
|
||||||
@ -131,7 +134,7 @@ public class IslandBlockCount implements DataObject {
|
|||||||
*/
|
*/
|
||||||
public boolean isAtLimit(Material m) {
|
public boolean isAtLimit(Material m) {
|
||||||
// Check island limits first
|
// Check island limits first
|
||||||
return blockLimits.containsKey(m) && blockCounts.getOrDefault(m, 0) >= blockLimits.get(m);
|
return blockLimits.containsKey(m) && blockCounts.getOrDefault(m, 0) >= getBlockLimit(m);
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isBlockLimited(Material m) {
|
public boolean isBlockLimited(Material m) {
|
||||||
@ -159,7 +162,7 @@ public class IslandBlockCount implements DataObject {
|
|||||||
* @return limit or -1 for unlimited
|
* @return limit or -1 for unlimited
|
||||||
*/
|
*/
|
||||||
public Integer getBlockLimit(Material m) {
|
public Integer getBlockLimit(Material m) {
|
||||||
return blockLimits.getOrDefault(m, -1);
|
return blockLimits.getOrDefault(m, -1) + getBlockLimitsOffset().getOrDefault(m, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -222,7 +225,7 @@ public class IslandBlockCount implements DataObject {
|
|||||||
* @return limit or -1 for unlimited
|
* @return limit or -1 for unlimited
|
||||||
*/
|
*/
|
||||||
public int getEntityLimit(EntityType t) {
|
public int getEntityLimit(EntityType t) {
|
||||||
return entityLimits.getOrDefault(t, -1);
|
return entityLimits.getOrDefault(t, -1) + getEntityLimitsOffset().getOrDefault(t, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -264,7 +267,7 @@ public class IslandBlockCount implements DataObject {
|
|||||||
* @return limit or -1 for unlimited
|
* @return limit or -1 for unlimited
|
||||||
*/
|
*/
|
||||||
public int getEntityGroupLimit(String name) {
|
public int getEntityGroupLimit(String name) {
|
||||||
return entityGroupLimits.getOrDefault(name, -1);
|
return entityGroupLimits.getOrDefault(name, -1) + getEntityLimitsOffset().getOrDefault(name, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -295,4 +298,61 @@ public class IslandBlockCount implements DataObject {
|
|||||||
public void setChanged() {
|
public void setChanged() {
|
||||||
this.changed = true;
|
this.changed = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return the blockLimitsOffset
|
||||||
|
*/
|
||||||
|
public Map<Material, Integer> getBlockLimitsOffset() {
|
||||||
|
if (blockLimitsOffset == null) {
|
||||||
|
blockLimitsOffset = new EnumMap<>(Material.class);
|
||||||
|
}
|
||||||
|
return blockLimitsOffset;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set an offset to a block limit. This will increase/decrease the value of the limit.
|
||||||
|
* @param m material
|
||||||
|
* @param blockLimitsOffset the blockLimitsOffset to set
|
||||||
|
*/
|
||||||
|
public void setBlockLimitsOffset(Material m, Integer blockLimitsOffset) {
|
||||||
|
getBlockLimitsOffset().put(m, blockLimitsOffset);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return the entityLimitsOffset
|
||||||
|
*/
|
||||||
|
public Map<EntityType, Integer> getEntityLimitsOffset() {
|
||||||
|
if (entityLimitsOffset == null) {
|
||||||
|
entityLimitsOffset = new EnumMap<>(EntityType.class);
|
||||||
|
}
|
||||||
|
return entityLimitsOffset;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set an offset to an entity limit. This will increase/decrease the value of the limit.
|
||||||
|
* @param t Entity Type
|
||||||
|
* @param entityLimitsOffset the entityLimitsOffset to set
|
||||||
|
*/
|
||||||
|
public void setEntityLimitsOffset(EntityType t, Integer entityLimitsOffset) {
|
||||||
|
this.getEntityLimitsOffset().put(t, entityLimitsOffset);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return the entityGroupLimitsOffset
|
||||||
|
*/
|
||||||
|
public Map<String, Integer> getEntityGroupLimitsOffset() {
|
||||||
|
if (entityGroupLimitsOffset == null) {
|
||||||
|
entityGroupLimitsOffset = new HashMap<>();
|
||||||
|
}
|
||||||
|
return entityGroupLimitsOffset;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set an offset to an entity group limit. This will increase/decrease the value of the limit.
|
||||||
|
* @param name group name
|
||||||
|
* @param entityGroupLimitsOffset the entityGroupLimitsOffset to set
|
||||||
|
*/
|
||||||
|
public void setEntityGroupLimitsOffset(String name, Integer entityGroupLimitsOffset) {
|
||||||
|
getEntityGroupLimitsOffset().put(name, entityGroupLimitsOffset);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user