Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Changed CreatureSpawnEvent to be EntitySpawnEvent and attempted to ed… #1635

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,10 @@
public class GeoMobLimitTab implements Tab, ClickHandler {

/**
* A list of all living entity types, minus some
* A list of all entity types, minus some
*/
private static final List<EntityType> LIVING_ENTITY_TYPES = Collections.unmodifiableList(Arrays.stream(EntityType.values())
.filter(EntityType::isAlive)
.filter(t -> !(t.equals(EntityType.PLAYER) || t.equals(EntityType.GIANT) || t.equals(EntityType.ARMOR_STAND)))
.filter(t -> !(t.equals(EntityType.PLAYER) || t.equals(EntityType.GIANT) || t.equals(EntityType.AREA_EFFECT_CLOUD)))
.sorted(Comparator.comparing(EntityType::name))
.collect(Collectors.toList()));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,10 @@
import org.bukkit.entity.Projectile;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.entity.CreatureSpawnEvent;
import org.bukkit.event.entity.EntityDeathEvent;
import org.bukkit.event.entity.EntitySpawnEvent;
import org.bukkit.event.entity.ExplosionPrimeEvent;
import org.bukkit.event.vehicle.VehicleCreateEvent;
import org.bukkit.projectiles.ProjectileSource;

import world.bentobox.bentobox.api.events.BentoBoxReadyEvent;
Expand Down Expand Up @@ -46,13 +47,26 @@ public void onPluginReady(BentoBoxReadyEvent event) {
* @param e - event
*/
@EventHandler(priority = EventPriority.LOW, ignoreCancelled = true)
public void onMobSpawn(CreatureSpawnEvent e) {
public void onMobSpawn(EntitySpawnEvent e) {
if (getIWM().inWorld(e.getLocation())
&& getIWM().getGeoLimitSettings(e.getLocation().getWorld()).contains(e.getEntityType().name())) {
getIslands().getIslandAt(e.getLocation()).ifPresent(i -> mobSpawnTracker.put(e.getEntity(), i));
}
}

/**
* Track where a vehicle was created. This will determine its allowable movement zone.
* @param e - event
*/
@EventHandler(priority = EventPriority.LOW, ignoreCancelled = true)
public void onVehicleSpawn(VehicleCreateEvent e) {
Entity entity = e.getVehicle();
if (getIWM().inWorld(entity.getLocation())
&& getIWM().getGeoLimitSettings(entity.getLocation().getWorld()).contains(entity.getType().name())) {
getIslands().getIslandAt(entity.getLocation()).ifPresent(i -> mobSpawnTracker.put(entity, i));
}
}

/**
* Clean up the map when entity dies (does not handle entity removal)
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,11 +100,11 @@ public void testOnClick() {
assertEquals("COW", list.get(1));
assertEquals("BAT", list.get(0));
// Click on BAT
tab.onClick(panel, user, ClickType.LEFT, 9);
tab.onClick(panel, user, ClickType.LEFT, 11);
assertEquals(1, list.size());
assertEquals("COW", list.get(0));
// Click on BAT again to have it added
tab.onClick(panel, user, ClickType.LEFT, 9);
tab.onClick(panel, user, ClickType.LEFT, 11);
assertEquals(2, list.size());
assertEquals("COW", list.get(0));
assertEquals("BAT", list.get(1));
Expand Down