@@ -54,10 +54,10 @@ public Rewards() {
54
54
private Map <Integer , List <String >> commandrewards = new HashMap <>();
55
55
private Map <Integer , List <ItemStack >> materialrewards = new HashMap <>();
56
56
private Map <Integer , Integer > minplayersrequired = new HashMap <>();
57
- private List <String > places = new ArrayList <>(List .of ("reward" ));
58
57
private int startingPlayers ;
59
58
private int maxplaces ;
60
59
private int index ;
60
+ private String path ;
61
61
62
62
public List <ItemStack > getMaterialReward (int place ) {
63
63
return materialrewards .get (place );
@@ -91,10 +91,10 @@ public int getMaxPlaces() {
91
91
*/
92
92
private boolean isActiveReward (int place ) {
93
93
if (Utils .debug ()) {
94
- Bukkit .getLogger ().info ("[TNTRun] place = " + place +", maxplaces = " + maxplaces +
94
+ Bukkit .getLogger ().info ("[TNTRun] place = " + place +", maxplaces = " + getMaxPlaces () +
95
95
", starters = " + startingPlayers + ", min = " + getMinPlayersRequired (place ));
96
96
}
97
- return place <= (maxplaces + 1 ) && startingPlayers >= getMinPlayersRequired (place );
97
+ return place <= (getMaxPlaces () ) && startingPlayers >= getMinPlayersRequired (place );
98
98
}
99
99
100
100
public void setMaterialReward (String item , String amount , String label , boolean isFirstItem , int place ) {
@@ -110,6 +110,7 @@ public void setMaterialReward(String item, String amount, String label, boolean
110
110
setMaterialDisplayName (reward , label );
111
111
}
112
112
materialrewards .computeIfAbsent (place , k -> new ArrayList <>()).add (reward );
113
+ maxplaces = Math .max (maxplaces , place );
113
114
114
115
if (Utils .debug ()) {
115
116
Bukkit .getLogger ().info ("[TNTRun] reward(" + place + ") = " + materialrewards .toString ());
@@ -124,6 +125,7 @@ private void setMaterialDisplayName(ItemStack is, String label) {
124
125
125
126
public void setMoneyReward (int money , int place ) {
126
127
moneyreward .put (place , money );
128
+ maxplaces = Math .max (maxplaces , place );
127
129
}
128
130
129
131
public void setCommandReward (String cmdreward , boolean isFirstCmd , int place ) {
@@ -134,6 +136,8 @@ public void setCommandReward(String cmdreward, boolean isFirstCmd, int place) {
134
136
Bukkit .getLogger ().info ("[TNTRun] reward(" + place + ") = " + commandrewards .toString ());
135
137
}
136
138
commandrewards .computeIfAbsent (place , k -> new ArrayList <>()).add (cmdreward );
139
+ maxplaces = Math .max (maxplaces , place );
140
+
137
141
if (Utils .debug ()) {
138
142
Bukkit .getLogger ().info ("[TNTRun] reward(" + place + ") = " + commandrewards .toString ());
139
143
}
@@ -145,6 +149,7 @@ public void setCommandRewards(List<String> cmdreward, int place) {
145
149
146
150
public void setXPReward (int xprwd , int place ) {
147
151
xpreward .put (place , xprwd );
152
+ maxplaces = Math .max (maxplaces , place );
148
153
}
149
154
150
155
public void deleteMaterialReward (int place ) {
@@ -218,8 +223,9 @@ public void setStartingPlayers(int starters) {
218
223
}
219
224
220
225
public void saveToConfig (FileConfiguration config ) {
221
- index = 1 ;
222
- places .stream ().forEach (path -> {
226
+ path = "reward" ;
227
+ IntStream .range (1 , getMaxPlaces () + 1 ).forEach (index -> {
228
+
223
229
config .set (path + ".minPlayers" , getMinPlayersRequired (index ));
224
230
config .set (path + ".money" , getMoneyReward (index ));
225
231
config .set (path + ".xp" , getXPReward (index ));
@@ -229,14 +235,17 @@ public void saveToConfig(FileConfiguration config) {
229
235
config .set (path + ".material." + is .getType ().toString () + ".amount" , is .getAmount ());
230
236
});
231
237
}
232
- index ++ ;
238
+ path = "places." + ( index + 1 ) ;
233
239
});
234
240
}
235
241
236
242
public void loadFromConfig (FileConfiguration config ) {
237
- maxplaces = config .isConfigurationSection ("places" ) ? config .getConfigurationSection ("places" ).getKeys (false ).size () : 0 ;
243
+ if (!config .isConfigurationSection ("reward" )) {
244
+ return ;
245
+ }
238
246
index = 1 ;
239
- getRewardPlaces (config ).stream ().forEach (path -> {
247
+ getPlacesFromFile (config ).stream ().forEach (path -> {
248
+
240
249
setMinPlayersRequired (config .getInt (path + ".minPlayers" ), index );
241
250
setMoneyReward (config .getInt (path + ".money" ), index );
242
251
setXPReward (config .getInt (path + ".xp" ), index );
@@ -252,23 +261,32 @@ public void loadFromConfig(FileConfiguration config) {
252
261
}
253
262
index ++;
254
263
});
264
+
265
+ maxplaces = index - 1 ;
255
266
}
256
267
257
- private List <String > getRewardPlaces (FileConfiguration config ) {
268
+ private List <String > getPlacesFromFile (FileConfiguration config ) {
269
+ List <String > paths = new ArrayList <>(List .of ("reward" ));
270
+ if (!config .isConfigurationSection ("places" )) {
271
+ return paths ;
272
+ }
258
273
for (String key : config .getConfigurationSection ("places" ).getKeys (false )) {
259
274
// temp code to rewrite config from v9.27
260
275
if (key .equalsIgnoreCase ("second" )) {
261
- places .add ("places.2" );
276
+ paths .add ("places." + 2 );
262
277
continue ;
263
278
} else if (key .equalsIgnoreCase ("third" )) {
264
- places .add ("places.3" );
279
+ paths .add ("places." + 3 );
265
280
continue ;
266
281
}
267
282
268
- places .add ("places." + key );
283
+ paths .add ("places." + key );
284
+ }
285
+ if (Utils .debug ()) {
286
+ Bukkit .getLogger ().info ("[TNTRun] reward paths = " + paths .toString ());
269
287
}
270
288
271
- return places ;
289
+ return paths ;
272
290
}
273
291
274
292
private boolean isValidReward (String materialreward , int materialamount ) {
@@ -281,7 +299,7 @@ private boolean isValidReward(String materialreward, int materialamount) {
281
299
public void listRewards (Player player , String arenaName ) {
282
300
Messages .sendMessage (player , Messages .rewardshead .replace ("{ARENA}" , arenaName ), false );
283
301
284
- IntStream .range (1 , maxplaces + 2 ).forEach (i -> {
302
+ IntStream .range (1 , getMaxPlaces () + 1 ).forEach (i -> {
285
303
286
304
StringBuilder sb = new StringBuilder (200 );
287
305
if (getXPReward (i ) != 0 ) {
0 commit comments