mirror of
https://github.com/BentoBoxWorld/Limits.git
synced 2025-02-16 20:31:22 +01:00
show limits in limit command
This commit is contained in:
parent
e0c208e049
commit
625bbe3a9f
@ -6,6 +6,7 @@ import java.util.EnumMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.Set;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@ -84,6 +85,8 @@ public class Settings {
|
||||
}
|
||||
return null;
|
||||
}).filter(e -> e != null).collect(Collectors.toSet());
|
||||
if (entities.isEmpty())
|
||||
continue;
|
||||
EntityGroup group = new EntityGroup(name, entities, limit);
|
||||
entities.forEach(e -> {
|
||||
List<EntityGroup> groups = groupLimits.getOrDefault(e, new ArrayList());
|
||||
@ -111,6 +114,10 @@ public class Settings {
|
||||
public Map<EntityType, List<EntityGroup>> getGroupLimits() {
|
||||
return groupLimits;
|
||||
}
|
||||
|
||||
public List<EntityGroup> getGroupLimitDefinitions() {
|
||||
return groupLimits.values().stream().flatMap(e -> e.stream()).distinct().collect(Collectors.toList());
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the gameModes
|
||||
@ -145,5 +152,28 @@ public class Settings {
|
||||
public int getLimit() {
|
||||
return limit;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode()
|
||||
{
|
||||
int hash = 7;
|
||||
hash = 83 * hash + Objects.hashCode(this.name);
|
||||
return hash;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj)
|
||||
{
|
||||
if (this == obj)
|
||||
return true;
|
||||
if (obj == null)
|
||||
return false;
|
||||
if (getClass() != obj.getClass())
|
||||
return false;
|
||||
final EntityGroup other = (EntityGroup) obj;
|
||||
if (!Objects.equals(this.name, other.name))
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -11,6 +11,8 @@ import org.bukkit.World;
|
||||
import org.bukkit.entity.EntityType;
|
||||
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import world.bentobox.bentobox.api.localization.TextVariables;
|
||||
import world.bentobox.bentobox.api.panels.builders.PanelBuilder;
|
||||
@ -19,6 +21,8 @@ import world.bentobox.bentobox.api.user.User;
|
||||
import world.bentobox.bentobox.database.objects.Island;
|
||||
import world.bentobox.bentobox.util.Util;
|
||||
import world.bentobox.limits.Limits;
|
||||
import world.bentobox.limits.Settings;
|
||||
import world.bentobox.limits.Settings.EntityGroup;
|
||||
import world.bentobox.limits.objects.IslandBlockCount;
|
||||
|
||||
/**
|
||||
@ -133,6 +137,37 @@ public class LimitPanel {
|
||||
"[limit]", String.valueOf(v)));
|
||||
pb.item(pib.build());
|
||||
});
|
||||
|
||||
// Entity group limits
|
||||
List<Settings.EntityGroup> groupmap = addon.getSettings().getGroupLimitDefinitions();
|
||||
// Merge in any permission-based limits
|
||||
// if (ibc != null) ibc.getEntityLimits().forEach(map::put);
|
||||
groupmap.forEach(v -> {
|
||||
PanelItemBuilder pib = new PanelItemBuilder();
|
||||
EntityType k = v.getTypes().iterator().next();
|
||||
pib.name(v.getName() + " (" + v.getTypes().stream().map(e -> Util.prettifyText(e.toString())).collect(Collectors.joining(", ")) + ")");
|
||||
Material m;
|
||||
try {
|
||||
if (E2M.containsKey(k)) {
|
||||
m = E2M.get(k);
|
||||
} else if (k.isAlive()) {
|
||||
m = Material.valueOf(k.toString() + "_SPAWN_EGG");
|
||||
} else {
|
||||
// Regular material
|
||||
m = Material.valueOf(k.toString());
|
||||
}
|
||||
} catch (Exception e) {
|
||||
m = Material.BARRIER;
|
||||
}
|
||||
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");
|
||||
pib.description(color
|
||||
+ user.getTranslation("island.limits.block-limit-syntax",
|
||||
TextVariables.NUMBER, String.valueOf(count),
|
||||
"[limit]", String.valueOf(v.getLimit())));
|
||||
pb.item(pib.build());
|
||||
});
|
||||
pb.build();
|
||||
}
|
||||
|
||||
@ -154,4 +189,23 @@ public class LimitPanel {
|
||||
}
|
||||
return count;
|
||||
}
|
||||
|
||||
long getCount(Island island, EntityGroup group) {
|
||||
long count = island.getWorld().getEntities().stream()
|
||||
.filter(e -> group.contains(e.getType()))
|
||||
.filter(e -> island.inIslandSpace(e.getLocation())).count();
|
||||
// Nether
|
||||
if (addon.getPlugin().getIWM().isNetherIslands(island.getWorld()) && addon.getPlugin().getIWM().getNetherWorld(island.getWorld()) != null) {
|
||||
count += addon.getPlugin().getIWM().getNetherWorld(island.getWorld()).getEntities().stream()
|
||||
.filter(e -> group.contains(e.getType()))
|
||||
.filter(e -> island.inIslandSpace(e.getLocation())).count();
|
||||
}
|
||||
// End
|
||||
if (addon.getPlugin().getIWM().isEndIslands(island.getWorld()) && addon.getPlugin().getIWM().getEndWorld(island.getWorld()) != null) {
|
||||
count += addon.getPlugin().getIWM().getEndWorld(island.getWorld()).getEntities().stream()
|
||||
.filter(e -> group.contains(e.getType()))
|
||||
.filter(e -> island.inIslandSpace(e.getLocation())).count();
|
||||
}
|
||||
return count;
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user