Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -2096,6 +2096,13 @@ public enum ConfigNodes {
"",
"# Setting this to false will allow block projectile sources, namely dispensers, to harm the above protected mobs (using potions, arrows, etc.), if they're in the same townblock and PvP is enabled."
),
PROT_PREVENT_MONSTER_DAMAGE_TO_PLAYERS_IN_MOBLESS_AREAS(
"protection.prevent_monster_damage_to_players_in_mobless_areas",
"false",
"",
"# When set to true, players will be protected from monster damage in locations where mobs are disabled.",
"# Warning: This allows players to abuse mob farms while being invulnerable in a nearby chunk where mob spawns are disabled."
),
PROT_POTION_TYPES(
"protection.potion_types",
"BLINDNESS,NAUSEA,INSTANT_DAMAGE,HUNGER,POISON,SLOWNESS,MINING_FATIGUE,WEAKNESS,WITHER,WIND_CHARGED,WEAVING,INFESTED,OOZING",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4097,6 +4097,10 @@ public static boolean areProtectedEntitiesProtectedAgainstMobs() {
public static boolean areProtectedEntitiesProtectedAgainstBlockProjectileSource() {
return getBoolean(ConfigNodes.PROT_MOB_TYPES_MOB_VS_BLOCK_PROJECTILE_SOURCE_BYPASS);
}

public static boolean isMonsterDamageBlockedInMoblessAreas() {
return getBoolean(ConfigNodes.PROT_PREVENT_MONSTER_DAMAGE_TO_PLAYERS_IN_MOBLESS_AREAS);
}

public static String getBossBarNotificationColor() {
return getString(ConfigNodes.NOTIFICATION_BOSSBARS_COLOR);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import org.bukkit.entity.EntityType;
import org.bukkit.entity.HumanEntity;
import org.bukkit.entity.LightningStrike;
import org.bukkit.entity.Monster;
import org.bukkit.entity.Player;
import org.bukkit.entity.Projectile;
import org.bukkit.entity.Wolf;
Expand Down Expand Up @@ -236,6 +237,14 @@ private static boolean preventDamageCall(TownyWorld world, Entity attackingEntit
* If Defender is a player, Attacker is not.
*/
if (defendingPlayer != null) {
/*
* Protects players against monster damage when mobs spawns are not allowed.
*/
if (TownySettings.isMonsterDamageBlockedInMoblessAreas()
&& attackingEntity instanceof Monster
&& !TownyAPI.getInstance().areMobsEnabled(defendingPlayer.getLocation())) {
return true;
}

/*
* If attackingEntity is a tamed Wolf and...
Expand Down
Loading