Merge pull request #166 from emmanuelvlad/new-placeholders
This commit is contained in:
commit
68f696a46c
|
@ -7,6 +7,7 @@ import java.util.stream.Collectors;
|
|||
import org.bukkit.Material;
|
||||
import org.bukkit.World;
|
||||
|
||||
import org.bukkit.entity.EntityType;
|
||||
import org.eclipse.jdt.annotation.Nullable;
|
||||
import world.bentobox.bentobox.api.addons.Addon;
|
||||
import world.bentobox.bentobox.api.addons.GameModeAddon;
|
||||
|
@ -138,6 +139,9 @@ public class Limits extends Addon {
|
|||
Arrays.stream(Material.values())
|
||||
.filter(Material::isBlock)
|
||||
.forEach(m -> registerCountAndLimitPlaceholders(m, gm));
|
||||
|
||||
Arrays.stream(EntityType.values())
|
||||
.forEach(e -> registerCountAndLimitPlaceholders(e, gm));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -149,6 +153,8 @@ public class Limits extends Addon {
|
|||
* Placeholders:
|
||||
* "Limits_bskyblock_island_hopper_count"
|
||||
* "Limits_bskyblock_island_hopper_limit"
|
||||
* "Limits_bskyblock_island_hopper_base_limit"
|
||||
* "Limits_bskyblock_island_zombie_limit"
|
||||
*
|
||||
* @param m material
|
||||
* @param gm game mode
|
||||
|
@ -160,6 +166,18 @@ public class Limits extends Addon {
|
|||
getPlugin().getPlaceholdersManager().registerPlaceholder(this,
|
||||
gm.getDescription().getName().toLowerCase() + "_island_" + m.toString().toLowerCase() + "_limit",
|
||||
user -> getLimit(user, m, gm));
|
||||
getPlugin().getPlaceholdersManager().registerPlaceholder(this,
|
||||
gm.getDescription().getName().toLowerCase() + "_island_" + m.toString().toLowerCase() + "_base_limit",
|
||||
user -> getBaseLimit(user, m, gm));
|
||||
}
|
||||
|
||||
private void registerCountAndLimitPlaceholders(EntityType e, GameModeAddon gm) {
|
||||
getPlugin().getPlaceholdersManager().registerPlaceholder(this,
|
||||
gm.getDescription().getName().toLowerCase() + "_island_" + e.toString().toLowerCase() + "_limit",
|
||||
user -> getLimit(user, e, gm));
|
||||
getPlugin().getPlaceholdersManager().registerPlaceholder(this,
|
||||
gm.getDescription().getName().toLowerCase() + "_island_" + e.toString().toLowerCase() + "_base_limit",
|
||||
user -> getBaseLimit(user, e, gm));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -199,4 +217,46 @@ public class Limits extends Addon {
|
|||
return limit == -1 ? LIMIT_NOT_SET : String.valueOf(limit);
|
||||
}
|
||||
|
||||
private String getBaseLimit(@Nullable User user, Material m, GameModeAddon gm) {
|
||||
Island is = gm.getIslands().getIsland(gm.getOverWorld(), user);
|
||||
if (is == null) {
|
||||
return LIMIT_NOT_SET;
|
||||
}
|
||||
|
||||
int limit = this.getBlockLimitListener().
|
||||
getMaterialLimits(is.getWorld(), is.getUniqueId()).
|
||||
getOrDefault(m, -1);
|
||||
|
||||
if (limit > 0) {
|
||||
limit -= this.getBlockLimitListener().getIsland(is).getBlockLimitOffset(m);
|
||||
}
|
||||
|
||||
return limit == -1 ? LIMIT_NOT_SET : String.valueOf(limit);
|
||||
}
|
||||
|
||||
private String getLimit(@Nullable User user, EntityType e, GameModeAddon gm) {
|
||||
Island is = gm.getIslands().getIsland(gm.getOverWorld(), user);
|
||||
if (is == null) {
|
||||
return LIMIT_NOT_SET;
|
||||
}
|
||||
|
||||
int limit = this.getBlockLimitListener().getIsland(is).getEntityLimit(e);
|
||||
if (limit < 0 && this.getSettings().getLimits().containsKey(e)) {
|
||||
limit = this.getSettings().getLimits().get(e);
|
||||
}
|
||||
|
||||
return limit == -1 ? LIMIT_NOT_SET : String.valueOf(limit);
|
||||
}
|
||||
|
||||
private String getBaseLimit(@Nullable User user, EntityType e, GameModeAddon gm) {
|
||||
Island is = gm.getIslands().getIsland(gm.getOverWorld(), user);
|
||||
if (is == null || !this.getSettings().getLimits().containsKey(e)) {
|
||||
return LIMIT_NOT_SET;
|
||||
}
|
||||
|
||||
int limit = this.getSettings().getLimits().get(e);
|
||||
|
||||
return limit == -1 ? LIMIT_NOT_SET : String.valueOf(limit);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1,14 +1,6 @@
|
|||
package world.bentobox.limits.listeners;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.EnumMap;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.Optional;
|
||||
import java.util.*;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Material;
|
||||
|
@ -23,18 +15,7 @@ import org.bukkit.event.Event;
|
|||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.block.Action;
|
||||
import org.bukkit.event.block.BlockBreakEvent;
|
||||
import org.bukkit.event.block.BlockBurnEvent;
|
||||
import org.bukkit.event.block.BlockExplodeEvent;
|
||||
import org.bukkit.event.block.BlockFadeEvent;
|
||||
import org.bukkit.event.block.BlockFormEvent;
|
||||
import org.bukkit.event.block.BlockFromToEvent;
|
||||
import org.bukkit.event.block.BlockMultiPlaceEvent;
|
||||
import org.bukkit.event.block.BlockPlaceEvent;
|
||||
import org.bukkit.event.block.BlockSpreadEvent;
|
||||
import org.bukkit.event.block.EntityBlockFormEvent;
|
||||
import org.bukkit.event.block.LeavesDecayEvent;
|
||||
import org.bukkit.event.block.*;
|
||||
import org.bukkit.event.entity.EntityChangeBlockEvent;
|
||||
import org.bukkit.event.entity.EntityExplodeEvent;
|
||||
import org.bukkit.event.player.PlayerInteractEvent;
|
||||
|
@ -256,6 +237,16 @@ public class BlockLimitsListener implements Listener {
|
|||
process(e.getBlock(), true);
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true)
|
||||
public void onBlock(BlockGrowEvent e) {
|
||||
if (process(e.getNewState().getBlock(), true) > -1) {
|
||||
e.setCancelled(true);
|
||||
e.getBlock().getWorld().getBlockAt(e.getBlock().getLocation()).setBlockData(e.getBlock().getBlockData());
|
||||
} else {
|
||||
process(e.getBlock(), false);
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true)
|
||||
public void onBlock(LeavesDecayEvent e) {
|
||||
process(e.getBlock(), false);
|
||||
|
|
|
@ -403,9 +403,12 @@ public class EntityLimitListener implements Listener {
|
|||
// We have to count the entities
|
||||
if (limitAmount >= 0)
|
||||
{
|
||||
int count = (int) ent.getWorld().getEntities().stream()
|
||||
// int count = (int) ent.getWorld().getEntities().stream()
|
||||
// .filter(e -> e.getType().equals(ent.getType()))
|
||||
// .filter(e -> island.inIslandSpace(e.getLocation()))
|
||||
// .count();
|
||||
int count = (int) ent.getWorld().getNearbyEntities(island.getBoundingBox()).stream()
|
||||
.filter(e -> e.getType().equals(ent.getType()))
|
||||
.filter(e -> island.inIslandSpace(e.getLocation()))
|
||||
.count();
|
||||
int max = limitAmount + (ibc == null ? 0 : ibc.getEntityLimitOffset(ent.getType()));
|
||||
if (count >= max) {
|
||||
|
@ -424,9 +427,12 @@ public class EntityLimitListener implements Listener {
|
|||
for (Map.Entry<Settings.EntityGroup, Integer> group : groupsLimits.entrySet()) { //do not use lambda
|
||||
if (group.getValue() < 0)
|
||||
continue;
|
||||
int count = (int) ent.getWorld().getEntities().stream()
|
||||
// int count = (int) ent.getWorld().getEntities().stream()
|
||||
// .filter(e -> group.getKey().contains(e.getType()))
|
||||
// .filter(e -> island.inIslandSpace(e.getLocation())).count();
|
||||
int count = (int) ent.getWorld().getNearbyEntities(island.getBoundingBox()).stream()
|
||||
.filter(e -> group.getKey().contains(e.getType()))
|
||||
.filter(e -> island.inIslandSpace(e.getLocation())).count();
|
||||
.count();
|
||||
int max = group.getValue() + + (ibc == null ? 0 : ibc.getEntityGroupLimitOffset(group.getKey().getName()));
|
||||
if (count >= max) {
|
||||
return new AtLimitResult(group.getKey(), max);
|
||||
|
|
Loading…
Reference in New Issue