Skip to content

Commit

Permalink
- Fix Townblocks having their mob setting overridden by the Towns' mob
Browse files Browse the repository at this point in the history
setting in scenarios where the town has mobs on, but the townblock has
mobs off.
    - Closes #4067.
  • Loading branch information
LlmDl committed Jun 20, 2020
1 parent c47a176 commit 26073a5
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 59 deletions.
4 changes: 3 additions & 1 deletion resources/ChangeLog.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4634,4 +4634,6 @@ v0.92.0.11:
- Allows admins to make a town leave their nation.
- API: Added to TownyAPI, hasNationZone(Location) and hasNationZone(WorldCoord) which will return either TownBlockStatus.UNCLAIMED_ZONE or TownBlockStatus.NATION_ZONE.
- API: Added to TownyAPI, isNationZone(Location), returns true if it is in a nation zone.
- Fix PlayerCacheUtil looking for a non-existant language string.
- Fix PlayerCacheUtil looking for a non-existant language string.
- Fix Townblocks having their mob setting overridden by the Towns' mob setting in scenarios where the town has mobs on, but the townblock has mobs off.
- Closes #4067.
2 changes: 1 addition & 1 deletion src/com/palmergames/bukkit/towny/TownyFormatter.java
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ public static List<String> getStatus(TownBlock townBlock) {
out.add(TownySettings.getLangString("status_pvp") + ((!preventPVP) ? TownySettings.getLangString("status_on"): TownySettings.getLangString("status_off")) +
TownySettings.getLangString("explosions") + ((world.isForceExpl() || townBlock.getPermissions().explosion) ? TownySettings.getLangString("status_on"): TownySettings.getLangString("status_off")) +
TownySettings.getLangString("firespread") + ((town.isFire() || world.isForceFire() || townBlock.getPermissions().fire) ? TownySettings.getLangString("status_on"):TownySettings.getLangString("status_off")) +
TownySettings.getLangString("mobspawns") + ((town.hasMobs() || world.isForceTownMobs() || townBlock.getPermissions().mobs) ? TownySettings.getLangString("status_on"): TownySettings.getLangString("status_off")));
TownySettings.getLangString("mobspawns") + ((world.isForceTownMobs() || townBlock.getPermissions().mobs) ? TownySettings.getLangString("status_on"): TownySettings.getLangString("status_off")));

if (townBlock.hasPlotObjectGroup())
out.add(String.format(TownySettings.getLangString("status_plot_group_name_and_size"), townBlock.getPlotObjectGroup().getName(), townBlock.getPlotObjectGroup().getTownBlocks().size()));
Expand Down
59 changes: 23 additions & 36 deletions src/com/palmergames/bukkit/towny/listeners/TownyEntityListener.java
Original file line number Diff line number Diff line change
Expand Up @@ -514,9 +514,19 @@ public void onCreatureSpawn(CreatureSpawnEvent event) throws NotRegisteredExcept
event.setCancelled(true);
return;
}

// ignore non-Towny worlds.
if (!TownyAPI.getInstance().isTownyWorld(event.getEntity().getWorld()))
return;

if (event.getEntity() != null) {

LivingEntity livingEntity = event.getEntity();

// ignore Citizens NPCs
if (plugin.isCitizens2() && CitizensAPI.getNPCRegistry().isNPC(livingEntity))
return;

Location loc = event.getLocation();
TownyWorld townyWorld = null;

Expand All @@ -528,48 +538,25 @@ public void onCreatureSpawn(CreatureSpawnEvent event) throws NotRegisteredExcept
}

// remove from world if set to remove mobs globally
if (townyWorld.isUsingTowny()) {
if (!townyWorld.hasWorldMobs() && MobRemovalTimerTask.isRemovingWorldEntity(livingEntity)) {
if (plugin.isCitizens2()) {
if (!CitizensAPI.getNPCRegistry().isNPC(livingEntity)) {
// TownyMessaging.sendDebugMsg("onCreatureSpawn world: Canceled "
// + event.getEntityType().name() +
// " from spawning within "+coord.toString()+".");
event.setCancelled(true);
}
} else
event.setCancelled(true);
}
if (livingEntity instanceof Villager && !((Villager) livingEntity).isAdult() && (TownySettings.isRemovingVillagerBabiesWorld())) {
if (!townyWorld.hasWorldMobs() && MobRemovalTimerTask.isRemovingWorldEntity(livingEntity)) {
event.setCancelled(true);
}
}
// handle villager baby removal in wilderness
if (livingEntity instanceof Villager && !((Villager) livingEntity).isAdult() && (TownySettings.isRemovingVillagerBabiesWorld())) {
event.setCancelled(true);
}
if (TownyAPI.getInstance().isWilderness(loc))
return;

// handle mob removal in towns
TownBlock townBlock = TownyAPI.getInstance().getTownBlock(loc);
try {

if (townyWorld.isUsingTowny() && !townyWorld.isForceTownMobs()) {
if (!townBlock.getTown().hasMobs() && !townBlock.getPermissions().mobs) {
if (MobRemovalTimerTask.isRemovingTownEntity(livingEntity)) {
if (plugin.isCitizens2()) {
if (!CitizensAPI.getNPCRegistry().isNPC(livingEntity)) {
// TownyMessaging.sendDebugMsg("onCreatureSpawn town: Canceled "
// + event.getEntityType().name() +
// " from spawning within "+coord.toString()+".");
event.setCancelled(true);
}
} else
event.setCancelled(true);
}
}
}
if (livingEntity instanceof Villager && !((Villager) livingEntity).isAdult() && TownySettings.isRemovingVillagerBabiesTown()) {
event.setCancelled(true);
}
} catch (TownyException x) {

if (!townyWorld.isForceTownMobs() && !townBlock.getPermissions().mobs && MobRemovalTimerTask.isRemovingTownEntity(livingEntity)) {
event.setCancelled(true);
}

// handle villager baby removal in towns
if (livingEntity instanceof Villager && !((Villager) livingEntity).isAdult() && TownySettings.isRemovingVillagerBabiesTown()) {
event.setCancelled(true);
}
}
}
Expand Down
27 changes: 6 additions & 21 deletions src/com/palmergames/bukkit/towny/tasks/MobRemovalTimerTask.java
Original file line number Diff line number Diff line change
Expand Up @@ -103,38 +103,23 @@ public void run() {
TownBlock townBlock = TownyAPI.getInstance().getTownBlock(livingEntityLoc);

// Check if mobs are always allowed inside towns in this world.
if (townyWorld.isForceTownMobs())
if (townyWorld.isForceTownMobs() || townBlock.getPermissions().mobs)
continue;

// Check if plot allows mobs.
if (townBlock.getPermissions().mobs)
// Check that Towny is removing this type of entity inside towns.
if (!isRemovingTownEntity(livingEntity))
continue;

// Get the town this is registered to.
Town town = null;
try {
town = townBlock.getTown();
} catch (NotRegisteredException ignored) {
}

// Check if the town this plot is registered to allows mobs.
if (town.hasMobs())
if (TownySettings.isSkippingRemovalOfNamedMobs() && livingEntity.getCustomName() != null)
continue;

// Special check if it's a rabbit, for the Killer Bunny variant.
if (livingEntity.getType().equals(EntityType.RABBIT))
if (isRemovingKillerBunny && ((Rabbit) livingEntity).getRabbitType().equals(Rabbit.Type.THE_KILLER_BUNNY)) {
livingEntitiesToRemove.add(livingEntity);
continue;
}

// Check that Towny is removing this type of entity inside towns.
if (!isRemovingTownEntity(livingEntity))
continue;

if (TownySettings.isSkippingRemovalOfNamedMobs() && livingEntity.getCustomName() != null)
continue;


livingEntitiesToRemove.add(livingEntity);
}
}
Expand Down

0 comments on commit 26073a5

Please sign in to comment.