Skip to content

Commit 28c0a3f

Browse files
committed
uh config additions and stuff
1 parent 385d413 commit 28c0a3f

5 files changed

Lines changed: 84 additions & 21 deletions

File tree

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
<groupId>ADHDMC</groupId>
88
<artifactId>NerfFarms</artifactId>
9-
<version>0.0.7</version>
9+
<version>0.0.9</version>
1010
<packaging>jar</packaging>
1111

1212
<name>NerfFarms</name>

src/main/java/adhdmc/nerffarms/NerfFarms.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
public final class NerfFarms extends JavaPlugin {
1717
public static NerfFarms plugin;
1818
public final MiniMessage miniMessage = MiniMessage.miniMessage();
19-
public final String version = "0.0.7";
19+
public final String version = "0.0.8";
2020

2121
@Override
2222
public void onEnable() {
@@ -46,8 +46,10 @@ private void configDefaults() {
4646
config.addDefault("blacklisted-below", Arrays.asList("MAGMA_BLOCK", "HONEY_BLOCK", "LAVA"));
4747
config.addDefault("blacklisted-in", Arrays.asList("HONEY_BLOCK", "LAVA", "BUBBLE_COLUMN"));
4848
config.addDefault("require-path", false);
49+
config.addDefault("require-line-of-sight", false);
50+
config.addDefault("require-no-obstructions", false);
4951
config.addDefault("max-distance", 15);
5052
config.addDefault("disallowed-damage-types", Arrays.asList("FALL", "FALLING_BLOCK", "LAVA", "DROWNING"));
51-
config.addDefault("damage-buffer-percent", 75);
53+
config.addDefault("max-disallowed-damage-percent", 75);
5254
}
5355
}

src/main/java/adhdmc/nerffarms/config/ConfigParser.java

Lines changed: 30 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,15 @@ public enum ModType {EXP, DROPS, BOTH, NEITHER}
1717
private static final HashSet<Material> insideBlacklist = new HashSet<>();
1818
private static final HashSet<EntityType> bypassList = new HashSet<>();
1919
private static final HashSet<CreatureSpawnEvent.SpawnReason> spawnReasonList = new HashSet<>();
20-
private static final HashSet<EntityDamageEvent.DamageCause> damageCauseWhitelist = new HashSet<>();
21-
private static final HashSet<EntityDamageEvent.DamageCause> environmentalDamage = new HashSet<>();
20+
private static final HashSet<EntityDamageEvent.DamageCause> disallowedDamageTypes = new HashSet<>();
2221
private static ModType modType = ModType.NEITHER;
2322
private static int maxDistance = 0;
2423
private static int errorCount = 0;
2524
private static int maxDisallowedDamage = 100;
2625
private static boolean nerfHostilesOnly = true;
27-
private static boolean requireTargeting = false;
26+
private static boolean requirePath = false;
27+
private static boolean requireLineOfSight = false;
28+
private static boolean requireNoObstructions = false;
2829
private static boolean debug = false;
2930

3031
public static void validateConfig() {
@@ -34,25 +35,29 @@ public static void validateConfig() {
3435
insideBlacklist.clear();
3536
bypassList.clear();
3637
spawnReasonList.clear();
37-
damageCauseWhitelist.clear();
38+
disallowedDamageTypes.clear();
3839
modType = null;
3940
maxDistance = 0;
4041
errorCount = 0;
4142
maxDisallowedDamage = 100;
4243
nerfHostilesOnly = true;
43-
requireTargeting = false;
44+
requirePath = false;
45+
requireLineOfSight = false;
46+
requireNoObstructions = false;
4447
debug = false;
4548
FileConfiguration config = NerfFarms.plugin.getConfig();
4649
List<String> standStringList = config.getStringList("blacklisted-below");
4750
List<String> inStringList = config.getStringList("blacklisted-in");
4851
List<String> bypassStringList = config.getStringList("bypass");
4952
List<String> spawnReasonStringList = config.getStringList("blacklisted-spawn-types");
50-
List<String> environmentalDamageList = config.getStringList("disallowed-damage-types");
53+
List<String> disallowedDamageTypesList = config.getStringList("disallowed-damage-types");
5154
String modificationTypeString = config.getString("modification-type");
5255
int maxDistanceInt = config.getInt("max-distance");
53-
int maxDisallowedDamage = config.getInt("damage-buffer-percent");
56+
int maxDisallowedDamage = config.getInt("max-disallowed-damage-percent");
5457
boolean nerfHostilesBoolean = config.getBoolean("only-nerf-hostiles");
55-
boolean requireTargetingBoolean = config.getBoolean("require-path");
58+
boolean requirePathBoolean = config.getBoolean("require-path");
59+
boolean requireLineOfSightBoolean = config.getBoolean("require-line-of-sight");
60+
boolean requireNoObstructionsBoolean = config.getBoolean("require-no-obstructions");
5661
boolean debugSetting = config.getBoolean("debug");
5762

5863
// Assemble the Stand On BlackList
@@ -109,15 +114,15 @@ public static void validateConfig() {
109114
}
110115

111116
// Generate Environmental Causes
112-
for (String type : environmentalDamageList) {
117+
for (String type : disallowedDamageTypesList) {
113118
try {
114119
EntityDamageEvent.DamageCause.valueOf(type);
115120
} catch (IllegalArgumentException e) {
116121
NerfFarms.plugin.getLogger().warning(type + " is not a valid damage type. Please check that you have entered this correctly.");
117122
errorCount = errorCount + 1;
118123
continue;
119124
}
120-
environmentalDamage.add(EntityDamageEvent.DamageCause.valueOf(type));
125+
disallowedDamageTypes.add(EntityDamageEvent.DamageCause.valueOf(type));
121126
}
122127

123128
// Determine modType
@@ -146,7 +151,9 @@ public static void validateConfig() {
146151

147152
// Set Booleans
148153
nerfHostilesOnly = nerfHostilesBoolean;
149-
requireTargeting = requireTargetingBoolean;
154+
requirePath = requirePathBoolean;
155+
requireLineOfSight = requireLineOfSightBoolean;
156+
requireNoObstructions = requireNoObstructionsBoolean;
150157
debug = debugSetting;
151158
}
152159

@@ -166,8 +173,8 @@ public static Set<CreatureSpawnEvent.SpawnReason> getSpawnReasonList() {
166173
return Collections.unmodifiableSet(spawnReasonList);
167174
}
168175

169-
public static Set<EntityDamageEvent.DamageCause> getEnvironmentalDamageSet() {
170-
return Collections.unmodifiableSet(environmentalDamage);
176+
public static Set<EntityDamageEvent.DamageCause> getdisallowedDamageTypesSet() {
177+
return Collections.unmodifiableSet(disallowedDamageTypes);
171178
}
172179

173180
/**
@@ -192,8 +199,16 @@ public static boolean isNerfHostilesOnly() {
192199
return nerfHostilesOnly;
193200
}
194201

195-
public static boolean isRequireTargeting() {
196-
return requireTargeting;
202+
public static boolean isRequirePath() {
203+
return requirePath;
204+
}
205+
206+
public static boolean isRequireLineOfSight() {
207+
return requireLineOfSight;
208+
}
209+
210+
public static boolean isRequireNoObstructions() {
211+
return requireNoObstructions;
197212
}
198213

199214
public static boolean isDebug() {

src/main/java/adhdmc/nerffarms/listener/MobDamageListener.java

Lines changed: 44 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@
22

33
import adhdmc.nerffarms.NerfFarms;
44
import adhdmc.nerffarms.config.ConfigParser;
5+
import adhdmc.nerffarms.util.LocationMath;
56
import com.destroystokyo.paper.entity.Pathfinder;
7+
import net.kyori.adventure.text.Component;
68
import org.bukkit.Location;
79
import org.bukkit.Material;
810
import org.bukkit.NamespacedKey;
@@ -16,6 +18,7 @@
1618
import org.bukkit.persistence.PersistentDataType;
1719

1820
import java.util.Objects;
21+
import java.util.Set;
1922
import java.util.logging.Logger;
2023

2124
public class MobDamageListener implements Listener {
@@ -41,6 +44,8 @@ public void onMobDamage(EntityDamageEvent damageEvent) {
4144
if (isExemptedMob(damagedEntity)) { return; }
4245

4346
// Pre-Death Nerfing Checks
47+
if (isBlockedFromAccess(damageEvent)) { return; }
48+
if (hasBlockedLineofSight(damageEvent)) { return; }
4449
if (isNerfableEnvironmentally(damageEvent)) { return; }
4550

4651
// Death Check
@@ -62,7 +67,7 @@ public void onMobDamage(EntityDamageEvent damageEvent) {
6267
}
6368

6469
private boolean hasPathToPlayer(Player p, Mob m) {
65-
if (!ConfigParser.isRequireTargeting()) {
70+
if (!ConfigParser.isRequirePath()) {
6671
if (debugSetting) {
6772
logger.info("Ignoring pathfinding check on " + m.getName() + " because require targetting is false.");
6873
}
@@ -176,7 +181,7 @@ private boolean isNerfableEnvironmentally(EntityDamageEvent event) {
176181
logger.info("Performing isNerfableEnvironmentally on " + e.getName());
177182
}
178183

179-
if (ConfigParser.getEnvironmentalDamageSet().contains(event.getCause())) {
184+
if (ConfigParser.getdisallowedDamageTypesSet().contains(event.getCause())) {
180185
if (debugSetting) {
181186
logger.info("Noting environmental damage of " + hitDamage + " to " + e.getName() + "."
182187
+ "\nCurrent PDC amount is: " + mobPDC.getOrDefault(disallowedDamage, PersistentDataType.DOUBLE, 0.0));
@@ -316,4 +321,41 @@ private boolean isNerfableInBlock(EntityDamageEvent event) {
316321
return false;
317322
}
318323

324+
private boolean isBlockedFromAccess(EntityDamageEvent event){
325+
if (!(event instanceof EntityDamageByEntityEvent)) return false;
326+
if (!ConfigParser.isRequireNoObstructions()) return true;
327+
328+
Entity entity = event.getEntity();
329+
Entity damager = ((EntityDamageByEntityEvent) event).getDamager();
330+
PersistentDataContainer mobPDC = entity.getPersistentDataContainer();
331+
double damageAmount = event.getDamage();
332+
double entityHeight = entity.getHeight();
333+
double damagerHeight = damager.getHeight();
334+
Location damagerLocation = damager.getLocation().add(0, damagerHeight, 0);
335+
Location entityLocation = entity.getLocation().add(0, entityHeight, 0);
336+
Set<Location> blocksBetween = LocationMath.getAdjacentTowards(entityLocation, damagerLocation);
337+
damager.getWorld().sendMessage(Component.text(blocksBetween.stream().toList().toString()));
338+
return false;
339+
}
340+
341+
private boolean hasBlockedLineofSight(EntityDamageEvent event){
342+
if (!(event instanceof EntityDamageByEntityEvent)) return false;
343+
if (!(event.getEntity() instanceof LivingEntity entity)) return false;
344+
if (!ConfigParser.isRequireLineOfSight()) return true;
345+
346+
Entity damager = ((EntityDamageByEntityEvent) event).getDamager();
347+
PersistentDataContainer mobPDC = entity.getPersistentDataContainer();
348+
double damageAmount = event.getDamage();
349+
boolean lineofsight = entity.hasLineOfSight(damager);
350+
if (!lineofsight){
351+
if (debugSetting) {
352+
logger.info("Adding " + damageAmount + " to " + entity.getName() + "'s PDC because they do not have a valid line of sight to the damager"
353+
+ "\nCurrent PDC amount is: " + mobPDC.getOrDefault(disallowedDamage, PersistentDataType.DOUBLE, 0.0));
354+
}
355+
addPDCDamage(mobPDC, damageAmount);
356+
return true;
357+
}
358+
return false;
359+
}
360+
319361
}

src/main/resources/config.yml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,13 @@ modification-type: "EXP"
2222

2323
require-path: false
2424

25+
require-line-of-sight: false
26+
27+
require-no-obstructions: false
28+
2529
max-distance: 15
2630

27-
damage-buffer-percent: 75
31+
max-disallowed-damage-percent: 75
2832

2933
disallowed-damage-types:
3034
- FALL

0 commit comments

Comments
 (0)