11package com .flyaway .smartmobs ;
22
33import org .bukkit .configuration .file .FileConfiguration ;
4+ import org .bukkit .configuration .ConfigurationSection ;
45import org .bukkit .entity .EntityType ;
56
67import java .util .List ;
@@ -18,6 +19,9 @@ public class ConfigManager {
1819 // Вероятности
1920 private double hardenedChance = 0.15 ;
2021 private double eliteChance = 0.05 ;
22+ private boolean radiusComplication = false ;
23+ private double worldRadius = 10000 ;
24+ List <RadiusLevel > radiusLevels = new ArrayList <>();
2125
2226 // Множители для hardened
2327 private double hardenedHpMultiplier = 1.25 ;
@@ -52,14 +56,40 @@ public void loadConfig() {
5256
5357 public void reloadConfig () {
5458 SmartMobs plugin = SmartMobs .getInstance ();
55- plugin .reloadConfig ();
5659 loadConfig ();
5760 }
5861
5962 private void loadChances () {
6063 if (config == null ) return ;
6164 hardenedChance = config .getDouble ("chances.hardened" , hardenedChance );
6265 eliteChance = config .getDouble ("chances.elite" , eliteChance );
66+ worldRadius = config .getDouble ("chances.world-radius" , 10000.0 );
67+ radiusComplication = config .getBoolean ("chances.radius-complication" , false );
68+ if (!radiusComplication ) return ;
69+
70+ List <RadiusLevel > result = new ArrayList <>();
71+
72+ List <?> rawList = config .getList ("chances.radius-levels" );
73+ if (rawList == null ) {
74+ SmartMobs .getInstance ().getLogger ().warning ("[SmartMobs] radius-levels не найден в конфиге!" );
75+ return ;
76+ }
77+
78+ for (Object item : rawList ) {
79+ if (item instanceof Map <?, ?> map ) {
80+ double from = parseDouble (map .get ("from" ), 0.0 );
81+ double to = parseDouble (map .get ("to" ), 1.0 );
82+ double hardened = parseDouble (map .get ("hardened" ), getHardenedChance ());
83+ double elite = parseDouble (map .get ("elite" ), getEliteChance ());
84+
85+ result .add (new RadiusLevel (from , to , hardened , elite ));
86+ } else {
87+ SmartMobs .getInstance ().getLogger ().warning ("[SmartMobs] Элемент radius-levels имеет неверный формат: " + item );
88+ }
89+ }
90+
91+ radiusLevels = result ;
92+ SmartMobs .getInstance ().getLogger ().info ("[SmartMobs] Загружено уровней сложности: " + result .size ());
6393 }
6494
6595 private void loadEnabledMobs () {
@@ -164,8 +194,15 @@ private void loadSpecialAbilities() {
164194 public double getEliteChance () { return eliteChance ; }
165195 public boolean isMobEnabled (EntityType type ) { return enabledMobs .getOrDefault (type , false ); }
166196 public boolean isMobEnabled (String mobName ) {
167- if (config == null ) return false ;
168- return config .getBoolean ("enabled-mobs." + mobName .toLowerCase (), false );
197+ if (mobName == null ) return false ;
198+
199+ try {
200+ EntityType type = EntityType .valueOf (mobName .toUpperCase ());
201+ return enabledMobs .getOrDefault (type , false );
202+ } catch (IllegalArgumentException e ) {
203+ SmartMobs .getInstance ().getLogger ().warning ("[SmartMobs] isMobEnabled: неизвестный тип моба " + mobName );
204+ return false ;
205+ }
169206 }
170207 public double getHardenedHpMultiplier () { return hardenedHpMultiplier ; }
171208 public double getHardenedDamageMultiplier () { return hardenedDamageMultiplier ; }
@@ -183,11 +220,10 @@ public boolean isMobEnabled(String mobName) {
183220
184221 public List <String > getEnabledMobTypes () {
185222 List <String > result = new ArrayList <>();
186- if (config == null || !config .isConfigurationSection ("enabled-mobs" )) return result ;
187223
188- for (String key : config . getConfigurationSection ( "enabled-mobs" ). getKeys ( false )) {
189- if (config . getBoolean ( "enabled-mobs." + key )) {
190- result .add (key .toLowerCase ());
224+ for (Map . Entry < EntityType , Boolean > entry : enabledMobs . entrySet ( )) {
225+ if (Boolean . TRUE . equals ( entry . getValue () )) {
226+ result .add (entry . getKey (). name () .toLowerCase ());
191227 }
192228 }
193229 return result ;
@@ -198,6 +234,42 @@ public String getDisplayName(String type, EntityType mobType) {
198234 return names != null ? names .get (mobType ) : null ;
199235 }
200236
237+ public boolean isRadiusComplicationEnabled () {
238+ return radiusComplication ;
239+ }
240+
241+ public double getWorldRadius () {
242+ return worldRadius ;
243+ }
244+
245+ public static class RadiusLevel {
246+ public final double from ;
247+ public final double to ;
248+ public final double hardened ;
249+ public final double elite ;
250+
251+ public RadiusLevel (double from , double to , double hardened , double elite ) {
252+ this .from = from ;
253+ this .to = to ;
254+ this .hardened = hardened ;
255+ this .elite = elite ;
256+ }
257+ }
258+
259+ public List <RadiusLevel > getRadiusLevels () {
260+ return radiusLevels ;
261+ }
262+
263+ private double parseDouble (Object obj , double def ) {
264+ if (obj instanceof Number num ) return num .doubleValue ();
265+ if (obj instanceof String str ) {
266+ try {
267+ return Double .parseDouble (str );
268+ } catch (NumberFormatException ignored ) {}
269+ }
270+ return def ;
271+ }
272+
201273 @ SuppressWarnings ("unchecked" )
202274 public Map <String , Object > getSpecialAbilities (EntityType mobType , String variant ) {
203275 Map <String , Object > abilities = specialAbilities .get (mobType );
0 commit comments