Removed debug
This commit is contained in:
parent
64b25b0ca6
commit
088f853f0a
|
@ -1,17 +1,16 @@
|
||||||
package world.bentobox.limits.listeners;
|
package world.bentobox.limits.listeners;
|
||||||
|
|
||||||
import java.text.NumberFormat;
|
|
||||||
import java.util.AbstractMap;
|
import java.util.AbstractMap;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Locale;
|
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.Location;
|
import org.bukkit.Location;
|
||||||
|
import org.bukkit.Material;
|
||||||
import org.bukkit.World;
|
import org.bukkit.World;
|
||||||
import org.bukkit.entity.Entity;
|
import org.bukkit.entity.Entity;
|
||||||
import org.bukkit.entity.EntityType;
|
import org.bukkit.entity.EntityType;
|
||||||
|
@ -23,6 +22,7 @@ import org.bukkit.event.entity.CreatureSpawnEvent;
|
||||||
import org.bukkit.event.entity.CreatureSpawnEvent.SpawnReason;
|
import org.bukkit.event.entity.CreatureSpawnEvent.SpawnReason;
|
||||||
import org.bukkit.event.hanging.HangingPlaceEvent;
|
import org.bukkit.event.hanging.HangingPlaceEvent;
|
||||||
import org.bukkit.event.vehicle.VehicleCreateEvent;
|
import org.bukkit.event.vehicle.VehicleCreateEvent;
|
||||||
|
import org.bukkit.inventory.ItemStack;
|
||||||
|
|
||||||
import world.bentobox.bentobox.BentoBox;
|
import world.bentobox.bentobox.BentoBox;
|
||||||
import world.bentobox.bentobox.api.localization.TextVariables;
|
import world.bentobox.bentobox.api.localization.TextVariables;
|
||||||
|
@ -96,7 +96,6 @@ public class EntityLimitListener implements Listener {
|
||||||
if (!addon.getPlugin().getIWM().inWorld(e.getLocation())) {
|
if (!addon.getPlugin().getIWM().inWorld(e.getLocation())) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
long timer = System.nanoTime();
|
|
||||||
boolean bypass = false;
|
boolean bypass = false;
|
||||||
// Check why it was spawned
|
// Check why it was spawned
|
||||||
switch (e.getSpawnReason()) {
|
switch (e.getSpawnReason()) {
|
||||||
|
@ -117,11 +116,6 @@ public class EntityLimitListener implements Listener {
|
||||||
// BentoBox.getInstance().logDebug("Bypass check took " + getTime(timer));
|
// BentoBox.getInstance().logDebug("Bypass check took " + getTime(timer));
|
||||||
// Tag the entity with the island spawn location
|
// Tag the entity with the island spawn location
|
||||||
checkLimit(e, bypass);
|
checkLimit(e, bypass);
|
||||||
// BentoBox.getInstance().logDebug("Creature spawn event total = " + getTime(timer));
|
|
||||||
}
|
|
||||||
|
|
||||||
private String getTime(long timer) {
|
|
||||||
return NumberFormat.getNumberInstance(Locale.US).format(((double)(System.nanoTime() - timer) / 1000000)) + "ms";
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean checkByPass(Location l) {
|
private boolean checkByPass(Location l) {
|
||||||
|
@ -174,8 +168,9 @@ public class EntityLimitListener implements Listener {
|
||||||
//// BentoBox.getInstance().logDebug("Entity limit hit");
|
//// BentoBox.getInstance().logDebug("Entity limit hit");
|
||||||
// Not allowed
|
// Not allowed
|
||||||
Bukkit.getScheduler().runTask(BentoBox.getInstance(), () -> {
|
Bukkit.getScheduler().runTask(BentoBox.getInstance(), () -> {
|
||||||
//e.setCancelled(true);
|
|
||||||
e.getEntity().remove();
|
e.getEntity().remove();
|
||||||
|
// If the entity was build, drop the building materials
|
||||||
|
Bukkit.getScheduler().runTask(addon.getPlugin(), () -> replaceEntity(e));
|
||||||
// If the reason is anything but because of a spawner then tell players within range
|
// If the reason is anything but because of a spawner then tell players within range
|
||||||
tellPlayers(e, res);
|
tellPlayers(e, res);
|
||||||
});
|
});
|
||||||
|
@ -186,13 +181,45 @@ public class EntityLimitListener implements Listener {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void replaceEntity(CreatureSpawnEvent e) {
|
||||||
|
World world = e.getEntity().getWorld();
|
||||||
|
Location l = e.getLocation();
|
||||||
|
switch (e.getSpawnReason()) {
|
||||||
|
case BUILD_IRONGOLEM:
|
||||||
|
world.dropItem(l, new ItemStack(Material.IRON_BLOCK,3));
|
||||||
|
world.dropItem(l, new ItemStack(Material.CARVED_PUMPKIN));
|
||||||
|
break;
|
||||||
|
case BUILD_SNOWMAN:
|
||||||
|
world.dropItem(l, new ItemStack(Material.SNOW_BLOCK,2));
|
||||||
|
world.dropItem(l, new ItemStack(Material.CARVED_PUMPKIN));
|
||||||
|
l.getBlock().setType(Material.AIR);
|
||||||
|
break;
|
||||||
|
case BUILD_WITHER:
|
||||||
|
world.dropItem(l, new ItemStack(Material.SOUL_SAND,3));
|
||||||
|
world.dropItem(l, new ItemStack(Material.WITHER_SKELETON_SKULL, 3));
|
||||||
|
break;
|
||||||
|
case CURED:
|
||||||
|
world.spawnEntity(e.getLocation(), EntityType.ZOMBIE_VILLAGER);
|
||||||
|
break;
|
||||||
|
case DISPENSE_EGG:
|
||||||
|
break;
|
||||||
|
case EGG:
|
||||||
|
world.dropItem(l, new ItemStack(Material.EGG));
|
||||||
|
break;
|
||||||
|
case SPAWNER_EGG:
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private void tellPlayers(CreatureSpawnEvent e, AtLimitResult res) {
|
private void tellPlayers(CreatureSpawnEvent e, AtLimitResult res) {
|
||||||
if (!e.getSpawnReason().equals(SpawnReason.SPAWNER) && !e.getSpawnReason().equals(SpawnReason.NATURAL)
|
if (!e.getSpawnReason().equals(SpawnReason.SPAWNER) && !e.getSpawnReason().equals(SpawnReason.NATURAL)
|
||||||
&& !e.getSpawnReason().equals(SpawnReason.INFECTION) && !e.getSpawnReason().equals(SpawnReason.NETHER_PORTAL)
|
&& !e.getSpawnReason().equals(SpawnReason.INFECTION) && !e.getSpawnReason().equals(SpawnReason.NETHER_PORTAL)
|
||||||
&& !e.getSpawnReason().equals(SpawnReason.REINFORCEMENTS) && !e.getSpawnReason().equals(SpawnReason.SLIME_SPLIT)) {
|
&& !e.getSpawnReason().equals(SpawnReason.REINFORCEMENTS) && !e.getSpawnReason().equals(SpawnReason.SLIME_SPLIT)) {
|
||||||
World w = e.getLocation().getWorld();
|
World w = e.getLocation().getWorld();
|
||||||
if (w == null) return;
|
if (w == null) return;
|
||||||
long localTime = System.nanoTime();
|
|
||||||
for (Entity ent : w.getNearbyEntities(e.getLocation(), 5, 5, 5)) {
|
for (Entity ent : w.getNearbyEntities(e.getLocation(), 5, 5, 5)) {
|
||||||
if (ent instanceof Player) {
|
if (ent instanceof Player) {
|
||||||
if (res.getTypelimit() != null) {
|
if (res.getTypelimit() != null) {
|
||||||
|
@ -206,7 +233,6 @@ public class EntityLimitListener implements Listener {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// BentoBox.getInstance().logDebug("Notification to players took " + getTime(localTime));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -218,7 +244,6 @@ public class EntityLimitListener implements Listener {
|
||||||
* @return true if at the limit, false if not
|
* @return true if at the limit, false if not
|
||||||
*/
|
*/
|
||||||
private AtLimitResult atLimit(Island island, Entity ent) {
|
private AtLimitResult atLimit(Island island, Entity ent) {
|
||||||
long localTime = System.nanoTime();
|
|
||||||
// Check island settings first
|
// Check island settings first
|
||||||
int limitAmount = -1;
|
int limitAmount = -1;
|
||||||
Map<Settings.EntityGroup, Integer> groupsLimits = new HashMap<>();
|
Map<Settings.EntityGroup, Integer> groupsLimits = new HashMap<>();
|
||||||
|
@ -231,8 +256,6 @@ public class EntityLimitListener implements Listener {
|
||||||
groupsLimits.put(def, limit);
|
groupsLimits.put(def, limit);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
// BentoBox.getInstance().logDebug("Island limits check took " + getTime(localTime));
|
|
||||||
localTime = System.nanoTime();
|
|
||||||
// If no island settings then try global settings
|
// If no island settings then try global settings
|
||||||
if (limitAmount < 0 && addon.getSettings().getLimits().containsKey(ent.getType())) {
|
if (limitAmount < 0 && addon.getSettings().getLimits().containsKey(ent.getType())) {
|
||||||
limitAmount = addon.getSettings().getLimits().get(ent.getType());
|
limitAmount = addon.getSettings().getLimits().get(ent.getType());
|
||||||
|
@ -242,19 +265,14 @@ public class EntityLimitListener implements Listener {
|
||||||
.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()));
|
||||||
}
|
}
|
||||||
// BentoBox.getInstance().logDebug("Global limits check took " + getTime(localTime));
|
|
||||||
localTime = System.nanoTime();
|
|
||||||
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)
|
||||||
{
|
{
|
||||||
int count = (int) ent.getWorld().getEntitiesByClasses(ent.getClass()).stream()
|
int count = (int) ent.getWorld().getEntitiesByClasses(ent.getClass()).stream()
|
||||||
//.filter(e -> e.getType().equals(ent.getType()))
|
|
||||||
.filter(e -> island.inIslandSpace(e.getLocation()))
|
.filter(e -> island.inIslandSpace(e.getLocation()))
|
||||||
.count();
|
.count();
|
||||||
// BentoBox.getInstance().logDebug("Island entity count took " + getTime(localTime));
|
if (count > limitAmount)
|
||||||
localTime = System.nanoTime();
|
|
||||||
if (count >= limitAmount)
|
|
||||||
return new AtLimitResult(ent.getType(), limitAmount);
|
return new AtLimitResult(ent.getType(), limitAmount);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -265,12 +283,9 @@ public class EntityLimitListener implements Listener {
|
||||||
int count = (int) ent.getWorld().getEntities().stream()
|
int count = (int) ent.getWorld().getEntities().stream()
|
||||||
.filter(e -> group.getKey().contains(e.getType()))
|
.filter(e -> group.getKey().contains(e.getType()))
|
||||||
.filter(e -> island.inIslandSpace(e.getLocation())).count();
|
.filter(e -> island.inIslandSpace(e.getLocation())).count();
|
||||||
// BentoBox.getInstance().logDebug("Island group limits check took " + getTime(localTime));
|
if (count > group.getValue())
|
||||||
localTime = System.nanoTime();
|
|
||||||
if (count >= group.getValue())
|
|
||||||
return new AtLimitResult(group.getKey(), group.getValue());
|
return new AtLimitResult(group.getKey(), group.getValue());
|
||||||
}
|
}
|
||||||
// BentoBox.getInstance().logDebug("Island limits to find no limits took " + getTime(localTime));
|
|
||||||
return new AtLimitResult();
|
return new AtLimitResult();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -8,30 +8,12 @@ authors: tastybento
|
||||||
softdepend: AcidIsland, BSkyBlock, CaveBlock
|
softdepend: AcidIsland, BSkyBlock, CaveBlock
|
||||||
|
|
||||||
permissions:
|
permissions:
|
||||||
acidisland.limits.player.limits:
|
'[gamemode].limits.player.limits':
|
||||||
description: Player can use limits command
|
description: Player can use limits command
|
||||||
default: true
|
default: true
|
||||||
acidisland.limits.player.recount:
|
'[gamemode].limits.player.recount':
|
||||||
description: Player can use recount command
|
description: Player can use recount command
|
||||||
default: true
|
default: true
|
||||||
acidisland.limits.admin.limits:
|
'[gamemode].limits.admin.limits':
|
||||||
description: Player can use admin limits command
|
|
||||||
default: op
|
|
||||||
bskyblock.limits.player.limits:
|
|
||||||
description: Player can use limits command
|
|
||||||
default: true
|
|
||||||
bskyblock.limits.player.recount:
|
|
||||||
description: Player can use recount command
|
|
||||||
default: true
|
|
||||||
bskyblock.limits.admin.limits:
|
|
||||||
description: Player can use admin limits command
|
|
||||||
default: op
|
|
||||||
caveblock.limits.player.limits:
|
|
||||||
description: Player can use limits command
|
|
||||||
default: true
|
|
||||||
caveblock.limits.player.recount:
|
|
||||||
description: Player can use recount command
|
|
||||||
default: true
|
|
||||||
caveblock.limits.admin.limits:
|
|
||||||
description: Player can use admin limits command
|
description: Player can use admin limits command
|
||||||
default: op
|
default: op
|
||||||
|
|
Loading…
Reference in New Issue