-
Notifications
You must be signed in to change notification settings - Fork 13
Expand file tree
/
Copy pathConfig.java
More file actions
461 lines (387 loc) · 18.3 KB
/
Config.java
File metadata and controls
461 lines (387 loc) · 18.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
package studio.magemonkey.divinity.config;
import org.bukkit.Material;
import org.bukkit.configuration.InvalidConfigurationException;
import org.bukkit.inventory.ItemStack;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import studio.magemonkey.codex.api.items.ItemType;
import studio.magemonkey.codex.config.api.IConfigTemplate;
import studio.magemonkey.codex.config.api.JYML;
import studio.magemonkey.codex.util.StringUT;
import studio.magemonkey.codex.util.actions.ActionManipulator;
import studio.magemonkey.codex.util.constants.JStrings;
import studio.magemonkey.divinity.Divinity;
import studio.magemonkey.divinity.stats.items.ItemStats;
import studio.magemonkey.divinity.stats.items.attributes.*;
import studio.magemonkey.divinity.stats.items.attributes.api.SimpleStat;
import studio.magemonkey.divinity.stats.items.attributes.api.TypedStat;
import studio.magemonkey.divinity.stats.items.attributes.stats.BleedStat;
import studio.magemonkey.divinity.stats.items.attributes.stats.DurabilityStat;
import studio.magemonkey.divinity.stats.items.attributes.stats.DynamicBuffStat;
import studio.magemonkey.divinity.stats.items.attributes.stats.PenetrationStat;
import studio.magemonkey.divinity.stats.tiers.Tier;
import studio.magemonkey.divinity.types.ItemGroup;
import studio.magemonkey.divinity.types.ItemSubType;
import java.util.*;
public class Config extends IConfigTemplate {
public Config(@NotNull Divinity plugin) {
super(plugin);
}
private static Map<String, Tier> TIERS_MAP;
private static Map<String, ItemSubType> ITEM_SUB_TYPES;
@Override
public void load() {
String path = "tiers.";
Config.TIERS_MAP = new LinkedHashMap<>();
for (String tierId : cfg.getSection("tiers")) {
String path2 = "tiers." + tierId + ".";
String tierColor = cfg.getString(path2 + "color", "&f");
String tierName = cfg.getString(path2 + "name", tierId);
Tier tier = new Tier(tierId, tierName, tierColor);
TIERS_MAP.put(tier.getId(), tier);
}
for (ItemGroup itemGroup : ItemGroup.values()) {
path = "item-groups." + itemGroup.name() + ".";
itemGroup.setName(cfg.getString(path + "name", itemGroup.name()));
itemGroup.setMaterials(cfg.getStringSet(path + "materials"));
}
ITEM_SUB_TYPES = new HashMap<>();
for (String typeId : cfg.getSection("item-sub-types")) {
path = "item-sub-types." + typeId + ".";
String name = cfg.getString(path + "name", typeId);
ItemSubType ist = new ItemSubType(typeId, name, cfg.getStringSet(path + "materials"));
ITEM_SUB_TYPES.put(ist.getId(), ist);
}
}
public void setupAttributes() {
this.setupDamages();
this.setupDefense();
this.setupStats();
this.setupDamageBuffs();
this.setupDefenseBuffs();
this.setupPenetrations();
this.setupHand();
this.setupAmmo();
this.setupSockets();
}
private void setupDamages() {
JYML cfg;
try {
cfg = JYML.loadOrExtract(plugin, "/item_stats/damage.yml");
} catch (InvalidConfigurationException e) {
this.plugin.error("Failed to load damage config (" + this.plugin.getName()
+ "/item_stats/damage.yml): Configuration error");
e.printStackTrace();
return;
}
for (String dmgId : cfg.getSection("")) {
String path = dmgId + ".";
int dmgPriority = cfg.getInt(path + "priority");
String dmgName = StringUT.color(cfg.getString(path + "name", dmgId));
String dmgFormat = StringUT.color(cfg.getString(path + "format", "%name%: &f%value%"));
ActionManipulator dmgActions = new ActionManipulator(plugin, cfg, path + "on-hit-actions");
Set<String> dmgCauses = new HashSet<>();
for (String sName : cfg.getStringList(path + "attached-damage-causes")) {
dmgCauses.add(sName.toUpperCase());
}
Map<String, Double> dmgBiomeMod = new HashMap<>();
for (String sName : cfg.getSection(path + "biome-damage-modifier")) {
double bMod = cfg.getDouble(path + "biome-damage-modifier." + sName);
dmgBiomeMod.put(sName.toUpperCase(), bMod);
}
Map<String, Double> dmgEntityMod = new HashMap<>();
for (String eType : cfg.getSection(path + "entity-type-modifier")) {
double dMod = cfg.getDouble(path + "entity-type-modifier." + eType);
dmgEntityMod.put(eType.toUpperCase(), dMod);
}
Map<String, Double> mythicFactionMod = new HashMap<>();
for (String eType : cfg.getSection(path + "mythic-mob-faction-modifier")) {
double dMod = cfg.getDouble(path + "mythic-mob-faction-modifier." + eType);
mythicFactionMod.put(eType.toLowerCase(), dMod);
}
DamageAttribute damageAttribute = new DamageAttribute(
dmgId,
dmgName,
dmgFormat,
dmgPriority,
dmgActions,
dmgCauses,
dmgBiomeMod,
dmgEntityMod,
mythicFactionMod
);
ItemStats.registerDamage(damageAttribute);
}
}
private void setupDefense() {
JYML cfg;
try {
cfg = JYML.loadOrExtract(plugin, "/item_stats/defense.yml");
} catch (InvalidConfigurationException e) {
this.plugin.error("Failed to load defense config (" + this.plugin.getName()
+ "/item_stats/defense.yml): Configuration error");
e.printStackTrace();
return;
}
for (String defId : cfg.getSection("")) {
String path = defId + ".";
cfg.addMissing(path + "protection-factor", 0.25D);
cfg.saveChanges();
int defPriority = cfg.getInt(path + "priority");
String defFormat = StringUT.color(cfg.getString(path + "format", "&6▸ %name%: &f%value%"));
String defName = StringUT.color(cfg.getString(path + "name", defId));
Set<String> defDamages = new HashSet<>();
for (String s : cfg.getStringList(path + "block-damage-types")) {
defDamages.add(s.toLowerCase());
}
double defProtFactor = cfg.getDouble(path + "protection-factor", 0.25D);
DefenseAttribute defenseAttribute = new DefenseAttribute(
defId,
defName,
defFormat,
defPriority,
defDamages,
defProtFactor);
ItemStats.registerDefense(defenseAttribute);
}
}
private void setupStats() {
JYML cfg;
try {
cfg = JYML.loadOrExtract(plugin, "/item_stats/stats/general_stats.yml");
} catch (InvalidConfigurationException e) {
this.plugin.error("Failed to load stats config (" + this.plugin.getName()
+ "/item_stats/stats/general_stats.yml): Configuration error");
e.printStackTrace();
return;
}
for (SimpleStat.Type statType : TypedStat.Type.values()) {
String path2 = statType.name() + ".";
if (!cfg.getBoolean(path2 + "enabled")) {
continue;
}
String statName = StringUT.color(cfg.getString(path2 + "name", statType.name()));
String statFormat = StringUT.color(cfg.getString(path2 + "format", "&a▸ %name%: &f%value%"));
double statCap = cfg.getDouble(path2 + "capacity", -1D);
TypedStat stat;
if (statType == TypedStat.Type.DURABILITY) {
stat = new DurabilityStat(statName, statFormat, statCap);
} else if (statType == TypedStat.Type.BLEED_RATE) {
String formula = cfg.getString(path2 + "settings.damage", "%damage% * 0.5");
boolean ofMax = cfg.getBoolean(path2 + "settings.of-max-health");
double duration = cfg.getDouble(path2 + "settings.duration", 10);
stat = new BleedStat(statName, statFormat, statCap, formula, ofMax, duration);
} else {
stat = new SimpleStat(statType, statName, statFormat, statCap);
}
ItemStats.registerStat(stat);
}
}
private void setupDamageBuffs() {
JYML cfg;
try {
cfg = JYML.loadOrExtract(plugin, "/item_stats/stats/damage_buffs_percent.yml");
} catch (InvalidConfigurationException e) {
this.plugin.error("Failed to load damage_buffs_percent config: Configuration error");
e.printStackTrace();
return;
}
for (DamageAttribute dmg : ItemStats.getDamages()) {
String id = dmg.getId();
String path = id + ".";
cfg.addMissing(path + "enabled", true);
cfg.addMissing(path + "name", dmg.getName() + " Buff %");
cfg.addMissing(path + "format", "&3▸ %name%: &f%value%%condition%");
cfg.addMissing(path + "capacity", -1.0);
cfg.addMissing(path + "hook", Collections.singletonList(id));
}
cfg.saveChanges();
for (String buffId : cfg.getSection("")) {
if (!cfg.getBoolean(buffId + ".enabled")) continue;
String name = StringUT.color(cfg.getString(buffId + ".name", buffId));
String format = StringUT.color(cfg.getString(buffId + ".format", "&3▸ %name%: &f%value%"));
double cap = cfg.getDouble(buffId + ".capacity", -1D);
Set<String> hooks = new HashSet<>(cfg.getStringList(buffId + ".hook"));
DynamicBuffStat buff = new DynamicBuffStat(
DynamicBuffStat.BuffTarget.DAMAGE, buffId, name, format, hooks, cap);
ItemStats.registerDamageBuff(buff);
}
}
private void setupDefenseBuffs() {
JYML cfg;
try {
cfg = JYML.loadOrExtract(plugin, "/item_stats/stats/defense_buffs_percent.yml");
} catch (InvalidConfigurationException e) {
this.plugin.error("Failed to load defense_buffs_percent config: Configuration error");
e.printStackTrace();
return;
}
for (DefenseAttribute def : ItemStats.getDefenses()) {
String id = def.getId();
String path = id + ".";
cfg.addMissing(path + "enabled", true);
cfg.addMissing(path + "name", def.getName() + " Buff %");
cfg.addMissing(path + "format", "&9▸ %name%: &f%value%%condition%");
cfg.addMissing(path + "capacity", -1.0);
cfg.addMissing(path + "hook", Collections.singletonList(id));
}
cfg.saveChanges();
for (String buffId : cfg.getSection("")) {
if (!cfg.getBoolean(buffId + ".enabled")) continue;
String name = StringUT.color(cfg.getString(buffId + ".name", buffId));
String format = StringUT.color(cfg.getString(buffId + ".format", "&9▸ %name%: &f%value%"));
double cap = cfg.getDouble(buffId + ".capacity", -1D);
Set<String> hooks = new HashSet<>(cfg.getStringList(buffId + ".hook"));
DynamicBuffStat buff = new DynamicBuffStat(
DynamicBuffStat.BuffTarget.DEFENSE, buffId, name, format, hooks, cap);
ItemStats.registerDefenseBuff(buff);
}
}
private void setupPenetrations() {
JYML cfg;
try {
cfg = JYML.loadOrExtract(plugin, "/item_stats/stats/penetration.yml");
} catch (InvalidConfigurationException e) {
this.plugin.error("Failed to load penetration config: Configuration error");
e.printStackTrace();
return;
}
// Auto-generate a flat-pen entry for every registered damage type (if missing)
for (DamageAttribute dmg : ItemStats.getDamages()) {
String id = dmg.getId() + "_pen";
String path = id + ".";
cfg.addMissing(path + "enabled", true);
cfg.addMissing(path + "name", dmg.getName() + " Penetration");
cfg.addMissing(path + "format", "&c▸ %name%: &f%value%%condition%");
cfg.addMissing(path + "capacity", -1.0);
cfg.addMissing(path + "percent-pen", false);
cfg.addMissing(path + "hooks", Collections.singletonList(dmg.getId()));
}
cfg.saveChanges();
for (String penId : cfg.getSection("")) {
if (!cfg.getBoolean(penId + ".enabled")) continue;
String name = StringUT.color(cfg.getString(penId + ".name", penId));
String format = StringUT.color(cfg.getString(penId + ".format", "&c▸ %name%: &f%value%"));
double cap = cfg.getDouble(penId + ".capacity", -1D);
boolean percentPen = cfg.getBoolean(penId + ".percent-pen", false);
Set<String> hooks = new HashSet<>(cfg.getStringList(penId + ".hooks"));
new PenetrationStat(penId, name, format, hooks, percentPen, cap);
}
}
private void setupHand() {
JYML cfg;
try {
cfg = JYML.loadOrExtract(plugin, "/item_stats/hand.yml");
} catch (InvalidConfigurationException e) {
this.plugin.error("Failed to load hand config (" + this.plugin.getName()
+ "/item_stats/hand.yml): Configuration error");
e.printStackTrace();
return;
}
for (HandAttribute.Type handType : HandAttribute.Type.values()) {
String path2 = handType.name() + ".";
if (!cfg.getBoolean(path2 + "enabled")) {
continue;
}
String handName = StringUT.color(cfg.getString(path2 + "name", handType.name()));
String handFormat = StringUT.color(cfg.getString(path2 + "format", "&7Hand: &f%name%"));
HandAttribute hand = new HandAttribute(handType, handName, handFormat);
ItemStats.registerHand(hand);
}
}
private void setupAmmo() {
JYML cfg;
try {
cfg = JYML.loadOrExtract(plugin, "/item_stats/ammo.yml");
} catch (InvalidConfigurationException e) {
this.plugin.error("Failed to load ammo config (" + this.plugin.getName()
+ "/item_stats/ammo.yml): Configuration error");
e.printStackTrace();
return;
}
for (AmmoAttribute.Type ammoType : AmmoAttribute.Type.values()) {
String path2 = ammoType.name() + ".";
if (!cfg.getBoolean(path2 + "enabled")) {
continue;
}
String ammoName = StringUT.color(cfg.getString(path2 + "name", ammoType.name()));
String ammoFormat = StringUT.color(cfg.getString(path2 + "format", "&7Ammo Type: &f%name%"));
AmmoAttribute ammo = new AmmoAttribute(ammoType, ammoName, ammoFormat);
ItemStats.registerAmmo(ammo);
}
}
private void setupSockets() {
JYML cfg;
try {
cfg = JYML.loadOrExtract(plugin, "/item_stats/sockets.yml");
} catch (InvalidConfigurationException e) {
this.plugin.error("Failed to load sockets config (" + this.plugin.getName()
+ "/item_stats/sockets.yml): Configuration error");
e.printStackTrace();
return;
}
for (SocketAttribute.Type type : SocketAttribute.Type.values()) {
String path = type.name() + ".";
for (String catId : cfg.getSection(path + "categories")) {
String path2 = path + "categories." + catId + ".";
String catTierId = cfg.getString(path2 + "tier", JStrings.DEFAULT);
String catName = cfg.getString(path2 + "name", catId);
String catFormatMain = cfg.getString(path2 + "format.main", "%value%");
String catFormatValEmpty = cfg.getString(path2 + "format.value.empty", "%TIER_COLOR%□ <%name%>");
String catFormatValFill = cfg.getString(path2 + "format.value.filled", "%TIER_COLOR%▣ &7%value%");
Tier catTier = Config.getTier(catTierId);
if (catTier == null) {
plugin.error("Invalid tier '" + catTierId + "' for Socket Attribute '" + catId + "' !");
continue;
}
SocketAttribute socket = new SocketAttribute(
type,
catId,
catName,
catFormatMain,
catTier,
catFormatValEmpty,
catFormatValFill);
ItemStats.registerSocket(socket);
}
}
}
@Nullable
public static Tier getTier(@NotNull String id) {
return TIERS_MAP.get(id.toLowerCase());
}
@NotNull
public static Collection<Tier> getTiers() {
return TIERS_MAP.values();
}
@NotNull
public static Set<String> getSubTypeIds() {
return new HashSet<>(ITEM_SUB_TYPES.keySet());
}
@Nullable
public static ItemSubType getSubTypeById(@NotNull String id) {
return ITEM_SUB_TYPES.get(id.toLowerCase());
}
@Nullable
public static ItemSubType getItemSubType(@NotNull ItemStack item) {
return ITEM_SUB_TYPES.values().stream().filter(itemSubType -> itemSubType.isItemOfThis(item))
.findFirst().orElse(null);
}
@Deprecated
@Nullable
public static ItemSubType getItemSubType(@NotNull Material material) {
return getItemSubType(material.name());
}
@Nullable
public static ItemSubType getItemSubType(@NotNull String mat) {
return ITEM_SUB_TYPES.values().stream().filter(type -> type.isItemOfThis(mat)).findFirst().orElse(null);
}
@NotNull
public static Set<ItemType> getAllRegisteredMaterials() {
Set<ItemType> set = new HashSet<>();
for (ItemGroup group : ItemGroup.values()) {
set.addAll(group.getMaterials());
}
return set;
}
}