22
33import adhdmc .nerffarms .NerfFarms ;
44import org .bukkit .Material ;
5- import org .bukkit .configuration .file .FileConfiguration ;
65import org .bukkit .entity .EntityType ;
76import org .bukkit .event .entity .CreatureSpawnEvent ;
87import org .bukkit .event .entity .EntityDamageEvent ;
9- import org .jetbrains .annotations .NotNull ;
108
119import java .util .*;
1210
1311public class ConfigParser {
1412 private static final HashSet <Material > standOnBlacklist = new HashSet <>();
1513 private static final HashSet <Material > insideBlacklist = new HashSet <>();
16- private static final HashSet <EntityType > bypassList = new HashSet <>();
17- private static final HashSet <CreatureSpawnEvent .SpawnReason > spawnReasonList = new HashSet <>();
14+ private static final HashSet <EntityType > whitelistedMobList = new HashSet <>();
15+ private static final HashSet <EntityType > blacklistedMobList = new HashSet <>();
16+ private static final HashSet <CreatureSpawnEvent .SpawnReason > whitelistedSpawnReasonList = new HashSet <>();
17+ private static final HashSet <CreatureSpawnEvent .SpawnReason > blacklistedSpawnReasonList = new HashSet <>();
1818 private static final HashSet <EntityDamageEvent .DamageCause > blacklistedDamageTypes = new HashSet <>();
1919 private static int maxDistance = 0 ;
2020 private static int errorCount = 0 ;
@@ -27,17 +27,21 @@ public static void validateConfig() {
2727 //clear any set stuff.
2828 standOnBlacklist .clear ();
2929 insideBlacklist .clear ();
30- bypassList .clear ();
31- spawnReasonList .clear ();
30+ whitelistedMobList .clear ();
31+ blacklistedMobList .clear ();
32+ whitelistedSpawnReasonList .clear ();
33+ blacklistedSpawnReasonList .clear ();
3234 blacklistedDamageTypes .clear ();
3335 maxDistance = 0 ;
3436 errorCount = 0 ;
3537 debug = 0 ;
3638 maxBlacklistedDamage = 100 ;
3739 List <String > standStringList = NerfFarms .plugin .getConfig ().getStringList ("blacklisted-below" );
3840 List <String > inStringList = NerfFarms .plugin .getConfig ().getStringList ("blacklisted-in" );
39- List <String > bypassStringList = NerfFarms .plugin .getConfig ().getStringList ("bypass" );
40- List <String > spawnReasonStringList = NerfFarms .plugin .getConfig ().getStringList ("whitelisted-spawn-types" );
41+ List <String > whitelistedMobStringList = NerfFarms .plugin .getConfig ().getStringList ("whitelisted-mobs" );
42+ List <String > blacklistedMobStringList = NerfFarms .plugin .getConfig ().getStringList ("blacklisted-mobs" );
43+ List <String > whitelistedSpawnReasonStringList = NerfFarms .plugin .getConfig ().getStringList ("whitelisted-spawn-reasons" );
44+ List <String > blacklistedSpawnReasonStringList = NerfFarms .plugin .getConfig ().getStringList ("blacklisted-spawn-reasons" );
4145 List <String > blacklistedDamageTypesList = NerfFarms .plugin .getConfig ().getStringList ("blacklisted-damage-types" );
4246 int maxDistanceInt = NerfFarms .plugin .getConfig ().getInt ("max-distance" );
4347 int maxBlacklistedDamageConfig = NerfFarms .plugin .getConfig ().getInt ("max-blacklisted-damage-percent" );
@@ -65,8 +69,27 @@ public static void validateConfig() {
6569 }
6670 }
6771
68- // Mob Bypass
69- for (String type : bypassStringList ) {
72+ // Mob Whitelist
73+ for (String type : whitelistedMobStringList ) {
74+ if (type == null || type .equalsIgnoreCase ("" )) break ;
75+ try {
76+ EntityType .valueOf (type .toUpperCase (Locale .ENGLISH ));
77+ } catch (IllegalArgumentException e ) {
78+ NerfFarms .plugin .getLogger ().warning (type + " is not a valid entity to whitelist. Please choose another." );
79+ errorCount = errorCount + 1 ;
80+ continue ;
81+ }
82+ EntityType entityType = EntityType .valueOf (type .toUpperCase (Locale .ENGLISH ));
83+ if (entityType .isAlive ()) {
84+ whitelistedMobList .add (entityType );
85+ } else {
86+ NerfFarms .plugin .getLogger ().warning (type + " is not a valid entity to whitelist. Please choose another." );
87+ errorCount = errorCount + 1 ;
88+ }
89+ }
90+
91+ // Mob Blacklist
92+ for (String type : blacklistedMobStringList ) {
7093 if (type == null || type .equalsIgnoreCase ("" )) break ;
7194 try {
7295 EntityType .valueOf (type .toUpperCase (Locale .ENGLISH ));
@@ -77,23 +100,37 @@ public static void validateConfig() {
77100 }
78101 EntityType entityType = EntityType .valueOf (type .toUpperCase (Locale .ENGLISH ));
79102 if (entityType .isAlive ()) {
80- bypassList .add (entityType );
103+ blacklistedMobList .add (entityType );
81104 } else {
82- NerfFarms .plugin .getLogger ().warning (type + " is not a valid entity for bypass. Please choose another." );
105+ NerfFarms .plugin .getLogger ().warning (type + " is not a valid entity to blacklist. Please choose another." );
106+ errorCount = errorCount + 1 ;
107+ }
108+ }
109+
110+ // Generate Spawn Reasons
111+ for (String type : whitelistedSpawnReasonStringList ) {
112+ if (type == null || type .equalsIgnoreCase ("" )) break ;
113+ try {
114+ CreatureSpawnEvent .SpawnReason .valueOf (type .toUpperCase (Locale .ENGLISH ));
115+ } catch (IllegalArgumentException e ) {
116+ NerfFarms .plugin .getLogger ().warning (type + " is not a valid spawn reason (whitelisted-spawn-reasons). Please check that you have entered this correctly." );
83117 errorCount = errorCount + 1 ;
118+ continue ;
84119 }
120+ whitelistedSpawnReasonList .add (CreatureSpawnEvent .SpawnReason .valueOf (type .toUpperCase (Locale .ENGLISH )));
85121 }
86122
87123 // Generate Spawn Reasons
88- for (String type : spawnReasonStringList ) {
124+ for (String type : blacklistedSpawnReasonStringList ) {
125+ if (type == null || type .equalsIgnoreCase ("" )) break ;
89126 try {
90127 CreatureSpawnEvent .SpawnReason .valueOf (type .toUpperCase (Locale .ENGLISH ));
91128 } catch (IllegalArgumentException e ) {
92- NerfFarms .plugin .getLogger ().warning (type + " is not a valid spawn reason. Please check that you have entered this correctly." );
129+ NerfFarms .plugin .getLogger ().warning (type + " is not a valid spawn reason (blacklisted-spawn-reasons) . Please check that you have entered this correctly." );
93130 errorCount = errorCount + 1 ;
94131 continue ;
95132 }
96- spawnReasonList .add (CreatureSpawnEvent .SpawnReason .valueOf (type .toUpperCase (Locale .ENGLISH )));
133+ blacklistedSpawnReasonList .add (CreatureSpawnEvent .SpawnReason .valueOf (type .toUpperCase (Locale .ENGLISH )));
97134 }
98135 // Generate Environmental Causes
99136 for (String type : blacklistedDamageTypesList ) {
@@ -137,15 +174,21 @@ public static Set<Material> getInsideBlackList() {
137174 return Collections .unmodifiableSet (insideBlacklist );
138175 }
139176
140- public static Set <EntityType > getBypassList () {
141- return Collections .unmodifiableSet (bypassList );
177+ public static Set <EntityType > getWhitelistedMobList () {
178+ return Collections .unmodifiableSet (whitelistedMobList );
179+ }
180+ public static Set <EntityType > getBlacklistedMobList () {
181+ return Collections .unmodifiableSet (blacklistedMobList );
142182 }
143183
144- public static Set <CreatureSpawnEvent .SpawnReason > getSpawnReasonList () {
145- return Collections .unmodifiableSet (spawnReasonList );
184+ public static Set <CreatureSpawnEvent .SpawnReason > getWhitelistedSpawnReasonList () {
185+ return Collections .unmodifiableSet (whitelistedSpawnReasonList );
186+ }
187+ public static Set <CreatureSpawnEvent .SpawnReason > getBlacklistedSpawnReasonList () {
188+ return Collections .unmodifiableSet (blacklistedSpawnReasonList );
146189 }
147190
148- public static Set <EntityDamageEvent .DamageCause > getblacklistedDamageTypesSet () {
191+ public static Set <EntityDamageEvent .DamageCause > getBlacklistedDamageTypesSet () {
149192 return Collections .unmodifiableSet (blacklistedDamageTypes );
150193 }
151194
0 commit comments