Code clean up. Java updates.
This commit is contained in:
parent
0248c398f6
commit
51408751a6
|
@ -17,6 +17,7 @@ import world.bentobox.limits.commands.PlayerCommand;
|
||||||
import world.bentobox.limits.listeners.BlockLimitsListener;
|
import world.bentobox.limits.listeners.BlockLimitsListener;
|
||||||
import world.bentobox.limits.listeners.EntityLimitListener;
|
import world.bentobox.limits.listeners.EntityLimitListener;
|
||||||
import world.bentobox.limits.listeners.JoinListener;
|
import world.bentobox.limits.listeners.JoinListener;
|
||||||
|
import world.bentobox.limits.objects.IslandBlockCount;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -134,7 +135,7 @@ public class Limits extends Addon {
|
||||||
private void registerPlaceholders(GameModeAddon gm) {
|
private void registerPlaceholders(GameModeAddon gm) {
|
||||||
if (getPlugin().getPlaceholdersManager() == null) return;
|
if (getPlugin().getPlaceholdersManager() == null) return;
|
||||||
Arrays.stream(Material.values())
|
Arrays.stream(Material.values())
|
||||||
.filter(m -> m.isBlock())
|
.filter(Material::isBlock)
|
||||||
.forEach(m -> registerCountAndLimitPlaceholders(m, gm));
|
.forEach(m -> registerCountAndLimitPlaceholders(m, gm));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -148,8 +149,8 @@ public class Limits extends Addon {
|
||||||
* "Limits_bskyblock_island_hopper_count"
|
* "Limits_bskyblock_island_hopper_count"
|
||||||
* "Limits_bskyblock_island_hopper_limit"
|
* "Limits_bskyblock_island_hopper_limit"
|
||||||
*
|
*
|
||||||
* @param m
|
* @param m material
|
||||||
* @param gm
|
* @param gm game mode
|
||||||
*/
|
*/
|
||||||
private void registerCountAndLimitPlaceholders(Material m, GameModeAddon gm) {
|
private void registerCountAndLimitPlaceholders(Material m, GameModeAddon gm) {
|
||||||
getPlugin().getPlaceholdersManager().registerPlaceholder(this,
|
getPlugin().getPlaceholdersManager().registerPlaceholder(this,
|
||||||
|
@ -163,7 +164,7 @@ public class Limits extends Addon {
|
||||||
/**
|
/**
|
||||||
* @param user - Used to identify the island the user belongs to
|
* @param user - Used to identify the island the user belongs to
|
||||||
* @param m - The material we are trying to count on the island
|
* @param m - The material we are trying to count on the island
|
||||||
* @param gm
|
* @param gm Game Mode Addon
|
||||||
* @return Number of blocks of the specified material on the given user's island
|
* @return Number of blocks of the specified material on the given user's island
|
||||||
*/
|
*/
|
||||||
private int getCount(@Nullable User user, Material m, GameModeAddon gm) {
|
private int getCount(@Nullable User user, Material m, GameModeAddon gm) {
|
||||||
|
@ -171,13 +172,17 @@ public class Limits extends Addon {
|
||||||
if (is == null) {
|
if (is == null) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
return getBlockLimitListener().getIsland(gm.getIslands().getIsland(gm.getOverWorld(), user).getUniqueId()).getBlockCount(m);
|
@Nullable IslandBlockCount ibc = getBlockLimitListener().getIsland(is.getUniqueId());
|
||||||
|
if (ibc == null) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
return ibc.getBlockCount(m);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param user - Used to identify the island the user belongs to
|
* @param user - Used to identify the island the user belongs to
|
||||||
* @param m - The material whose limit we are querying
|
* @param m - The material whose limit we are querying
|
||||||
* @param gm
|
* @param gm Game Mode Addon
|
||||||
* @return The limit of the specified material on the given user's island
|
* @return The limit of the specified material on the given user's island
|
||||||
*/
|
*/
|
||||||
private String getLimit(@Nullable User user, Material m, GameModeAddon gm) {
|
private String getLimit(@Nullable User user, Material m, GameModeAddon gm) {
|
||||||
|
@ -185,8 +190,11 @@ public class Limits extends Addon {
|
||||||
if (is == null) {
|
if (is == null) {
|
||||||
return "Limit not set";
|
return "Limit not set";
|
||||||
}
|
}
|
||||||
int limit = getBlockLimitListener().getIsland(gm.getIslands().getIsland(gm.getOverWorld(), user).getUniqueId()).
|
@Nullable IslandBlockCount ibc = getBlockLimitListener().getIsland(is.getUniqueId());
|
||||||
getBlockLimit(m);
|
if (ibc == null) {
|
||||||
|
return "Limit not set";
|
||||||
|
}
|
||||||
|
int limit = ibc.getBlockLimit(m);
|
||||||
return limit == -1 ? "Limit not set" : String.valueOf(limit);
|
return limit == -1 ? "Limit not set" : String.valueOf(limit);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,14 +1,6 @@
|
||||||
package world.bentobox.limits;
|
package world.bentobox.limits;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.*;
|
||||||
import java.util.Arrays;
|
|
||||||
import java.util.Collections;
|
|
||||||
import java.util.EnumMap;
|
|
||||||
import java.util.LinkedHashSet;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Map;
|
|
||||||
import java.util.Objects;
|
|
||||||
import java.util.Set;
|
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
import org.bukkit.configuration.ConfigurationSection;
|
import org.bukkit.configuration.ConfigurationSection;
|
||||||
|
@ -89,7 +81,7 @@ public class Settings {
|
||||||
addon.logError("Unknown entity type: " + s + " - skipping...");
|
addon.logError("Unknown entity type: " + s + " - skipping...");
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}).filter(e -> e != null).collect(Collectors.toCollection(LinkedHashSet::new));
|
}).filter(Objects::nonNull).collect(Collectors.toCollection(LinkedHashSet::new));
|
||||||
if (entities.isEmpty())
|
if (entities.isEmpty())
|
||||||
continue;
|
continue;
|
||||||
EntityGroup group = new EntityGroup(name, entities, limit);
|
EntityGroup group = new EntityGroup(name, entities, limit);
|
||||||
|
@ -102,7 +94,7 @@ public class Settings {
|
||||||
}
|
}
|
||||||
|
|
||||||
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(Enum::name).collect(Collectors.joining(", ")) + ") to " + e.getLimit()).forEach(addon::log);
|
||||||
}
|
}
|
||||||
|
|
||||||
private EntityType getType(String key) {
|
private EntityType getType(String key) {
|
||||||
|
@ -127,7 +119,7 @@ public class Settings {
|
||||||
* @return the group limit definitions
|
* @return the group limit definitions
|
||||||
*/
|
*/
|
||||||
public List<EntityGroup> getGroupLimitDefinitions() {
|
public List<EntityGroup> getGroupLimitDefinitions() {
|
||||||
return groupLimits.values().stream().flatMap(e -> e.stream()).distinct().collect(Collectors.toList());
|
return groupLimits.values().stream().flatMap(Collection::stream).distinct().collect(Collectors.toList());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -186,9 +178,7 @@ public class Settings {
|
||||||
if (getClass() != obj.getClass())
|
if (getClass() != obj.getClass())
|
||||||
return false;
|
return false;
|
||||||
final EntityGroup other = (EntityGroup) obj;
|
final EntityGroup other = (EntityGroup) obj;
|
||||||
if (!Objects.equals(this.name, other.name))
|
return Objects.equals(this.name, other.name);
|
||||||
return false;
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -1,13 +1,7 @@
|
||||||
package world.bentobox.limits.commands;
|
package world.bentobox.limits.commands;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.*;
|
||||||
import java.util.Collections;
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Map;
|
|
||||||
import java.util.Map.Entry;
|
import java.util.Map.Entry;
|
||||||
import java.util.Objects;
|
|
||||||
import java.util.Optional;
|
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
|
@ -88,21 +82,18 @@ public class LimitTab implements Tab {
|
||||||
addEntityLimits(ibc, island);
|
addEntityLimits(ibc, island);
|
||||||
addEntityGroupLimits(ibc, island);
|
addEntityGroupLimits(ibc, island);
|
||||||
// Sort
|
// Sort
|
||||||
switch (sortBy) {
|
if (sortBy == SORT_BY.Z2A) {
|
||||||
default:
|
result.sort((o1, o2) -> o2.getName().compareTo(o1.getName()));
|
||||||
Collections.sort(result, (o1, o2) -> o1.getName().compareTo(o2.getName()));
|
} else {
|
||||||
break;
|
result.sort(Comparator.comparing(PanelItem::getName));
|
||||||
case Z2A:
|
|
||||||
Collections.sort(result, (o1, o2) -> o2.getName().compareTo(o1.getName()));
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void addEntityGroupLimits(IslandBlockCount ibc, Island island) {
|
private void addEntityGroupLimits(IslandBlockCount ibc, Island island) {
|
||||||
// Entity group limits
|
// Entity group limits
|
||||||
Map<EntityGroup, Integer> groupmap = addon.getSettings().getGroupLimitDefinitions().stream().collect(Collectors.toMap(e -> e, e -> e.getLimit()));
|
Map<EntityGroup, Integer> groupmap = addon.getSettings().getGroupLimitDefinitions().stream().collect(Collectors.toMap(e -> e, EntityGroup::getLimit));
|
||||||
Map<String, EntityGroup> groupbyname = groupmap.keySet().stream().collect(Collectors.toMap(e -> e.getName(), e -> e));
|
Map<String, EntityGroup> groupbyname = groupmap.keySet().stream().collect(Collectors.toMap(EntityGroup::getName, e -> e));
|
||||||
// Merge in any permission-based limits
|
// Merge in any permission-based limits
|
||||||
if (ibc == null) {
|
if (ibc == null) {
|
||||||
return;
|
return;
|
||||||
|
@ -111,8 +102,7 @@ public class LimitTab implements Tab {
|
||||||
.filter(e -> groupbyname.containsKey(e.getKey()))
|
.filter(e -> groupbyname.containsKey(e.getKey()))
|
||||||
.forEach(e -> groupmap.put(groupbyname.get(e.getKey()), e.getValue()));
|
.forEach(e -> groupmap.put(groupbyname.get(e.getKey()), e.getValue()));
|
||||||
|
|
||||||
ibc.getEntityGroupLimitsOffset().entrySet().forEach(o ->
|
ibc.getEntityGroupLimitsOffset().forEach((key, value) -> groupmap.put(groupbyname.get(key), (groupmap.getOrDefault(key, 0) + value)));
|
||||||
groupmap.put(groupbyname.get(o.getKey()), (groupmap.getOrDefault(o.getKey(), 0) + o.getValue())));
|
|
||||||
groupmap.forEach((v, limit) -> {
|
groupmap.forEach((v, limit) -> {
|
||||||
PanelItemBuilder pib = new PanelItemBuilder();
|
PanelItemBuilder pib = new PanelItemBuilder();
|
||||||
EntityType k = v.getTypes().iterator().next();
|
EntityType k = v.getTypes().iterator().next();
|
||||||
|
@ -124,7 +114,7 @@ public class LimitTab implements Tab {
|
||||||
if (E2M.containsKey(k)) {
|
if (E2M.containsKey(k)) {
|
||||||
m = E2M.get(k);
|
m = E2M.get(k);
|
||||||
} else if (k.isAlive()) {
|
} else if (k.isAlive()) {
|
||||||
m = Material.valueOf(k.toString() + "_SPAWN_EGG");
|
m = Material.valueOf(k + "_SPAWN_EGG");
|
||||||
} else {
|
} else {
|
||||||
// Regular material
|
// Regular material
|
||||||
m = Material.valueOf(k.toString());
|
m = Material.valueOf(k.toString());
|
||||||
|
@ -149,7 +139,7 @@ public class LimitTab implements Tab {
|
||||||
Map<EntityType, Integer> map = new HashMap<>(addon.getSettings().getLimits());
|
Map<EntityType, Integer> map = new HashMap<>(addon.getSettings().getLimits());
|
||||||
// Merge in any permission-based limits
|
// Merge in any permission-based limits
|
||||||
if (ibc != null) {
|
if (ibc != null) {
|
||||||
ibc.getEntityLimits().forEach(map::put);
|
map.putAll(ibc.getEntityLimits());
|
||||||
ibc.getEntityLimitsOffset().forEach((k,v) -> map.put(k, map.getOrDefault(k, 0) + v));
|
ibc.getEntityLimitsOffset().forEach((k,v) -> map.put(k, map.getOrDefault(k, 0) + v));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -161,7 +151,7 @@ public class LimitTab implements Tab {
|
||||||
if (E2M.containsKey(k)) {
|
if (E2M.containsKey(k)) {
|
||||||
m = E2M.get(k);
|
m = E2M.get(k);
|
||||||
} else if (k.isAlive()) {
|
} else if (k.isAlive()) {
|
||||||
m = Material.valueOf(k.toString() + "_SPAWN_EGG");
|
m = Material.valueOf(k + "_SPAWN_EGG");
|
||||||
} else {
|
} else {
|
||||||
// Regular material
|
// Regular material
|
||||||
m = Material.valueOf(k.toString());
|
m = Material.valueOf(k.toString());
|
||||||
|
|
|
@ -37,10 +37,9 @@ public class LimitsCalc {
|
||||||
private IslandBlockCount ibc;
|
private IslandBlockCount ibc;
|
||||||
private final Map<Material, AtomicInteger> blockCount;
|
private final Map<Material, AtomicInteger> blockCount;
|
||||||
private final User sender;
|
private final User sender;
|
||||||
private final Set<Pair<Integer, Integer>> chunksToScan;
|
|
||||||
private int count;
|
private int count;
|
||||||
private int chunksToScanCount;
|
private final int chunksToScanCount;
|
||||||
private BentoBox plugin;
|
private final BentoBox plugin;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -56,13 +55,13 @@ public class LimitsCalc {
|
||||||
this.addon = addon;
|
this.addon = addon;
|
||||||
this.island = instance.getIslands().getIsland(world, targetPlayer);
|
this.island = instance.getIslands().getIsland(world, targetPlayer);
|
||||||
this.bll = addon.getBlockLimitListener();
|
this.bll = addon.getBlockLimitListener();
|
||||||
this.ibc = bll.getIsland(island.getUniqueId());
|
this.ibc = bll.getIsland(Objects.requireNonNull(island).getUniqueId());
|
||||||
blockCount = new EnumMap<>(Material.class);
|
blockCount = new EnumMap<>(Material.class);
|
||||||
this.sender = sender;
|
this.sender = sender;
|
||||||
this.world = world;
|
this.world = world;
|
||||||
|
|
||||||
// Get chunks to scan
|
// Get chunks to scan
|
||||||
chunksToScan = getChunksToScan(island);
|
Set<Pair<Integer, Integer>> chunksToScan = getChunksToScan(island);
|
||||||
count = 0;
|
count = 0;
|
||||||
|
|
||||||
boolean isNether = plugin.getIWM().isNetherGenerate(world) && plugin.getIWM().isNetherIslands(world);
|
boolean isNether = plugin.getIWM().isNetherGenerate(world) && plugin.getIWM().isNetherIslands(world);
|
||||||
|
|
|
@ -110,7 +110,7 @@ public class LimitsJoinPermCheckEvent extends BentoBoxEvent implements Cancellab
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Ignore player's perms. This differs to canceling the event in that the IslandBlockCount will be used if given via
|
* Ignore player's perms. This differs to canceling the event in that the IslandBlockCount will be used if given via
|
||||||
* {@link setIbc(IslandBlockCount ibc)}
|
* {@link #setIbc(IslandBlockCount ibc)}
|
||||||
* @param ignorePerms the ignorePerms to set
|
* @param ignorePerms the ignorePerms to set
|
||||||
*/
|
*/
|
||||||
public void setIgnorePerms(boolean ignorePerms) {
|
public void setIgnorePerms(boolean ignorePerms) {
|
||||||
|
|
|
@ -52,7 +52,7 @@ public class LimitsPermCheckEvent extends LimitsJoinPermCheckEvent {
|
||||||
/**
|
/**
|
||||||
* @return the entityGroup
|
* @return the entityGroup
|
||||||
*/
|
*/
|
||||||
public EntityGroup getEntityGroup() {
|
public @Nullable EntityGroup getEntityGroup() {
|
||||||
return entityGroup;
|
return entityGroup;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -60,7 +60,7 @@ public class LimitsPermCheckEvent extends LimitsJoinPermCheckEvent {
|
||||||
/**
|
/**
|
||||||
* @param entityGroup the entityGroup to set
|
* @param entityGroup the entityGroup to set
|
||||||
*/
|
*/
|
||||||
public void setEntityGroup(EntityGroup entityGroup) {
|
public void setEntityGroup(@Nullable EntityGroup entityGroup) {
|
||||||
this.entityGroup = entityGroup;
|
this.entityGroup = entityGroup;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -68,7 +68,7 @@ public class LimitsPermCheckEvent extends LimitsJoinPermCheckEvent {
|
||||||
/**
|
/**
|
||||||
* @return the entityType
|
* @return the entityType
|
||||||
*/
|
*/
|
||||||
public EntityType getEntityType() {
|
public @Nullable EntityType getEntityType() {
|
||||||
return entityType;
|
return entityType;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -76,7 +76,7 @@ public class LimitsPermCheckEvent extends LimitsJoinPermCheckEvent {
|
||||||
/**
|
/**
|
||||||
* @param entityType the entityType to set
|
* @param entityType the entityType to set
|
||||||
*/
|
*/
|
||||||
public void setEntityType(EntityType entityType) {
|
public void setEntityType(@Nullable EntityType entityType) {
|
||||||
this.entityType = entityType;
|
this.entityType = entityType;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -84,7 +84,7 @@ public class LimitsPermCheckEvent extends LimitsJoinPermCheckEvent {
|
||||||
/**
|
/**
|
||||||
* @return the material
|
* @return the material
|
||||||
*/
|
*/
|
||||||
public Material getMaterial() {
|
public @Nullable Material getMaterial() {
|
||||||
return material;
|
return material;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -92,7 +92,7 @@ public class LimitsPermCheckEvent extends LimitsJoinPermCheckEvent {
|
||||||
/**
|
/**
|
||||||
* @param material the material to set
|
* @param material the material to set
|
||||||
*/
|
*/
|
||||||
public void setMaterial(Material material) {
|
public void setMaterial(@Nullable Material material) {
|
||||||
this.material = material;
|
this.material = material;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -164,7 +164,7 @@ public class BlockLimitsListener implements Listener {
|
||||||
|
|
||||||
@EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true)
|
@EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true)
|
||||||
public void onTurtleEggBreak(PlayerInteractEvent e) {
|
public void onTurtleEggBreak(PlayerInteractEvent e) {
|
||||||
if (e.getAction().equals(Action.PHYSICAL) && e.getClickedBlock().getType().equals(Material.TURTLE_EGG)) {
|
if (e.getAction().equals(Action.PHYSICAL) && e.getClickedBlock() != null && e.getClickedBlock().getType().equals(Material.TURTLE_EGG)) {
|
||||||
handleBreak(e, e.getClickedBlock());
|
handleBreak(e, e.getClickedBlock());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -296,8 +296,8 @@ public class BlockLimitsListener implements Listener {
|
||||||
return Material.PLAYER_HEAD;
|
return Material.PLAYER_HEAD;
|
||||||
} else if (mat == Material.DRAGON_WALL_HEAD) {
|
} else if (mat == Material.DRAGON_WALL_HEAD) {
|
||||||
return Material.DRAGON_HEAD;
|
return Material.DRAGON_HEAD;
|
||||||
} else if (mat != null && mat == Material.getMaterial("BAMBOO_SAPLING")) {
|
} else if (mat == Material.BAMBOO_SAPLING) {
|
||||||
return Material.getMaterial("BAMBOO");
|
return Material.BAMBOO;
|
||||||
} else if (mat == Material.PISTON_HEAD || mat == Material.MOVING_PISTON) {
|
} else if (mat == Material.PISTON_HEAD || mat == Material.MOVING_PISTON) {
|
||||||
TechnicalPiston tp = (TechnicalPiston) b;
|
TechnicalPiston tp = (TechnicalPiston) b;
|
||||||
if (tp.getType() == TechnicalPiston.Type.NORMAL) {
|
if (tp.getType() == TechnicalPiston.Type.NORMAL) {
|
||||||
|
@ -314,7 +314,6 @@ public class BlockLimitsListener implements Listener {
|
||||||
*
|
*
|
||||||
* @param b - block
|
* @param b - block
|
||||||
* @param add - true to add a block, false to remove
|
* @param add - true to add a block, false to remove
|
||||||
* @param changeTo - material this block will become
|
|
||||||
* @return limit amount if over limit, or -1 if no limitation
|
* @return limit amount if over limit, or -1 if no limitation
|
||||||
*/
|
*/
|
||||||
private int process(Block b, boolean add) {
|
private int process(Block b, boolean add) {
|
||||||
|
@ -415,14 +414,14 @@ public class BlockLimitsListener implements Listener {
|
||||||
// Merge limits
|
// Merge limits
|
||||||
Map<Material, Integer> result = new EnumMap<>(Material.class);
|
Map<Material, Integer> result = new EnumMap<>(Material.class);
|
||||||
// Default
|
// Default
|
||||||
defaultLimitMap.forEach(result::put);
|
result.putAll(defaultLimitMap);
|
||||||
// World
|
// World
|
||||||
if (worldLimitMap.containsKey(w)) {
|
if (worldLimitMap.containsKey(w)) {
|
||||||
worldLimitMap.get(w).forEach(result::put);
|
result.putAll(worldLimitMap.get(w));
|
||||||
}
|
}
|
||||||
// Island
|
// Island
|
||||||
if (islandCountMap.containsKey(id)) {
|
if (islandCountMap.containsKey(id)) {
|
||||||
islandCountMap.get(id).getBlockLimits().forEach(result::put);
|
result.putAll(islandCountMap.get(id).getBlockLimits());
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
|
@ -52,7 +52,6 @@ public class EntityLimitListener implements Listener {
|
||||||
*/
|
*/
|
||||||
public EntityLimitListener(Limits addon) {
|
public EntityLimitListener(Limits addon) {
|
||||||
this.addon = addon;
|
this.addon = addon;
|
||||||
justSpawned.clear();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -178,9 +177,7 @@ public class EntityLimitListener implements Listener {
|
||||||
if (island.isSpawn() || !res.hit()) {
|
if (island.isSpawn() || !res.hit()) {
|
||||||
// Allowed
|
// Allowed
|
||||||
if (async) {
|
if (async) {
|
||||||
Bukkit.getScheduler().runTask(BentoBox.getInstance(), () -> {
|
Bukkit.getScheduler().runTask(BentoBox.getInstance(), () -> l.getWorld().spawn(l, e.getClass(), entity -> preSpawn(entity, reason, l)));
|
||||||
l.getWorld().spawn(l, e.getClass(), entity -> preSpawn(entity, reason, l));
|
|
||||||
});
|
|
||||||
} // else do nothing
|
} // else do nothing
|
||||||
} else {
|
} else {
|
||||||
if (async) {
|
if (async) {
|
||||||
|
@ -199,21 +196,15 @@ public class EntityLimitListener implements Listener {
|
||||||
justSpawned.add(entity.getUniqueId());
|
justSpawned.add(entity.getUniqueId());
|
||||||
// Check for entities that need cleanup
|
// Check for entities that need cleanup
|
||||||
switch (reason) {
|
switch (reason) {
|
||||||
case BUILD_IRONGOLEM:
|
case BUILD_IRONGOLEM -> detectIronGolem(l);
|
||||||
detectIronGolem(l);
|
case BUILD_SNOWMAN -> detectSnowman(l);
|
||||||
break;
|
case BUILD_WITHER -> {
|
||||||
case BUILD_SNOWMAN:
|
detectWither(l);
|
||||||
detectSnowman(l);
|
// Create explosion
|
||||||
break;
|
l.getWorld().createExplosion(l, 7F, true, true, entity);
|
||||||
case BUILD_WITHER:
|
}
|
||||||
detectWither(l);
|
default -> {
|
||||||
// Create explosion
|
}
|
||||||
l.getWorld().createExplosion(l, 7F, true, true, entity);
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
break;
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -410,7 +401,7 @@ public class EntityLimitListener implements Listener {
|
||||||
}
|
}
|
||||||
// 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(EntityGroup::getName, e -> e));
|
||||||
addon.getBlockLimitListener().getIsland(island.getUniqueId()).getEntityGroupLimits().entrySet().stream()
|
addon.getBlockLimitListener().getIsland(island.getUniqueId()).getEntityGroupLimits().entrySet().stream()
|
||||||
.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()));
|
||||||
|
@ -428,7 +419,7 @@ public class EntityLimitListener implements Listener {
|
||||||
return new AtLimitResult();
|
return new AtLimitResult();
|
||||||
}
|
}
|
||||||
|
|
||||||
class AtLimitResult {
|
static 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;
|
||||||
|
|
||||||
|
|
|
@ -80,10 +80,9 @@ public class EntityLimitsDO implements DataObject {
|
||||||
if (obj == null) {
|
if (obj == null) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (!(obj instanceof EntityLimitsDO)) {
|
if (!(obj instanceof EntityLimitsDO other)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
EntityLimitsDO other = (EntityLimitsDO) obj;
|
|
||||||
if (uniqueId == null) {
|
if (uniqueId == null) {
|
||||||
return other.uniqueId == null;
|
return other.uniqueId == null;
|
||||||
} else return uniqueId.equals(other.uniqueId);
|
} else return uniqueId.equals(other.uniqueId);
|
||||||
|
|
|
@ -20,10 +20,10 @@ import world.bentobox.bentobox.database.objects.Table;
|
||||||
public class IslandBlockCount implements DataObject {
|
public class IslandBlockCount implements DataObject {
|
||||||
|
|
||||||
@Expose
|
@Expose
|
||||||
private String uniqueId = "";
|
private String uniqueId;
|
||||||
|
|
||||||
@Expose
|
@Expose
|
||||||
private String gameMode = "";
|
private String gameMode;
|
||||||
|
|
||||||
@Expose
|
@Expose
|
||||||
private Map<Material, Integer> blockCounts = new EnumMap<>(Material.class);
|
private Map<Material, Integer> blockCounts = new EnumMap<>(Material.class);
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
package bentobox.addon.limits.listeners;
|
package bentobox.addon.limits.listeners;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.*;
|
||||||
import java.util.Arrays;
|
|
||||||
import static org.mockito.ArgumentMatchers.any;
|
import static org.mockito.ArgumentMatchers.any;
|
||||||
import static org.mockito.ArgumentMatchers.anyString;
|
import static org.mockito.ArgumentMatchers.anyString;
|
||||||
import static org.mockito.ArgumentMatchers.eq;
|
import static org.mockito.ArgumentMatchers.eq;
|
||||||
|
@ -11,12 +11,6 @@ import static org.mockito.Mockito.times;
|
||||||
import static org.mockito.Mockito.verify;
|
import static org.mockito.Mockito.verify;
|
||||||
import static org.mockito.Mockito.when;
|
import static org.mockito.Mockito.when;
|
||||||
|
|
||||||
import java.util.Collections;
|
|
||||||
import java.util.HashSet;
|
|
||||||
import java.util.Map;
|
|
||||||
import java.util.Set;
|
|
||||||
import java.util.UUID;
|
|
||||||
|
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
import org.bukkit.OfflinePlayer;
|
import org.bukkit.OfflinePlayer;
|
||||||
|
@ -86,7 +80,7 @@ public class JoinListenerTest {
|
||||||
when(addon.getGameModePermPrefix(any())).thenReturn("bskyblock.");
|
when(addon.getGameModePermPrefix(any())).thenReturn("bskyblock.");
|
||||||
when(addon.getSettings()).thenReturn(settings);
|
when(addon.getSettings()).thenReturn(settings);
|
||||||
// Settings
|
// Settings
|
||||||
when(settings.getGroupLimitDefinitions()).thenReturn(new ArrayList<>(Arrays.asList(new Settings.EntityGroup("friendly", new HashSet<>(), -1))));
|
when(settings.getGroupLimitDefinitions()).thenReturn(new ArrayList<>(List.of(new Settings.EntityGroup("friendly", new HashSet<>(), -1))));
|
||||||
// Island Manager
|
// Island Manager
|
||||||
when(im.hasIsland(any(), any(UUID.class))).thenReturn(true);
|
when(im.hasIsland(any(), any(UUID.class))).thenReturn(true);
|
||||||
when(island.getUniqueId()).thenReturn("unique_id");
|
when(island.getUniqueId()).thenReturn("unique_id");
|
||||||
|
|
|
@ -55,7 +55,7 @@ public class LimitTabTest {
|
||||||
private Settings settings;
|
private Settings settings;
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
public void setUp() throws Exception {
|
public void setUp() {
|
||||||
// Island
|
// Island
|
||||||
when(island.getWorld()).thenReturn(world);
|
when(island.getWorld()).thenReturn(world);
|
||||||
// Addon
|
// Addon
|
||||||
|
@ -78,7 +78,7 @@ public class LimitTabTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@After
|
@After
|
||||||
public void tearDown() throws Exception {
|
public void tearDown() {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|
|
@ -45,7 +45,6 @@ public class EntityLimitListenerTest {
|
||||||
private LivingEntity ent;
|
private LivingEntity ent;
|
||||||
@Mock
|
@Mock
|
||||||
private BlockLimitsListener bll;
|
private BlockLimitsListener bll;
|
||||||
private Settings settings;
|
|
||||||
@Mock
|
@Mock
|
||||||
private World world;
|
private World world;
|
||||||
private List<Entity> collection;
|
private List<Entity> collection;
|
||||||
|
@ -71,7 +70,7 @@ public class EntityLimitListenerTest {
|
||||||
config.load("src/main/resources/config.yml");
|
config.load("src/main/resources/config.yml");
|
||||||
// Settings
|
// Settings
|
||||||
when(addon.getConfig()).thenReturn(config);
|
when(addon.getConfig()).thenReturn(config);
|
||||||
settings = new Settings(addon);
|
Settings settings = new Settings(addon);
|
||||||
when(addon.getSettings()).thenReturn(settings);
|
when(addon.getSettings()).thenReturn(settings);
|
||||||
|
|
||||||
// World
|
// World
|
||||||
|
@ -87,7 +86,7 @@ public class EntityLimitListenerTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@After
|
@After
|
||||||
public void tearDown() throws Exception {
|
public void tearDown() {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Reference in New Issue