-
Notifications
You must be signed in to change notification settings - Fork 2
/
CookingSkill.java
737 lines (581 loc) · 22.3 KB
/
CookingSkill.java
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
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
/*
* QuestManager: An RPG plugin for the Bukkit API.
* Copyright (C) 2015-2016 Github Contributors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.skyisland.questmanager.player.skill.defaults;
import java.io.File;
import java.util.HashMap;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.Sound;
import org.bukkit.block.Furnace;
import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.entity.FoodLevelChangeEvent;
import org.bukkit.event.player.PlayerInteractEvent;
import org.bukkit.event.player.PlayerItemConsumeEvent;
import org.bukkit.inventory.EquipmentSlot;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;
import com.google.common.collect.Lists;
import com.skyisland.questmanager.QuestManagerPlugin;
import com.skyisland.questmanager.configuration.utils.YamlWriter;
import com.skyisland.questmanager.player.QuestPlayer;
import com.skyisland.questmanager.player.skill.CraftingSkill;
import com.skyisland.questmanager.player.skill.FoodItem;
import com.skyisland.questmanager.player.skill.LogSkill;
import com.skyisland.questmanager.player.skill.Skill;
import com.skyisland.questmanager.player.skill.SkillRecipe;
import com.skyisland.questmanager.player.skill.event.CraftEvent;
import com.skyisland.questmanager.ui.menu.InventoryMenu;
import com.skyisland.questmanager.ui.menu.inventory.minigames.CombiningGui;
import com.skyisland.questmanager.ui.menu.inventory.minigames.CookingGui;
public class CookingSkill extends LogSkill implements Listener, CraftingSkill {
private static final String IN_USE_MESSAGE = ChatColor.GRAY + "That oven is already in use by another player";
public static final String CONFIG_NAME = "Cooking.yml";
private static final String BLACKLIST_MESSAGE = ChatColor.GRAY + "You cannot eat food in that state!";
public static final class OvenRecipe implements SkillRecipe {
public int difficulty;
public ItemStack input;
public FoodItem output;
public OvenRecipe(int difficulty, ItemStack input, FoodItem output) {
this.difficulty = difficulty;
this.input = input;
this.output = output;
}
@Override
public ItemStack getDisplay() {
return output.getItem();
}
@Override
public String getDescription() {
String name;
name = YamlWriter.toStandardFormat(input.getType().name());
if (input.hasItemMeta() && input.getItemMeta().hasDisplayName())
name = input.getItemMeta().getDisplayName();
return "Cook a [" + name + "] in any oven";
}
@Override
public int getDifficulty() {
return this.difficulty;
}
}
public static final class CookingStats {
private double cookTime;
private double fuelSwapTime;
private int failInterval;
public CookingStats(double cookTime, double fuelSwapTime,
int failInterval) {
super();
this.cookTime = cookTime;
this.fuelSwapTime = fuelSwapTime;
this.failInterval = failInterval;
}
public double getCookTime() {
return cookTime;
}
public double getFuelSwapTime() {
return fuelSwapTime;
}
public int getFailInterval() {
return failInterval;
}
}
public static final class CombineRecipe implements SkillRecipe {
public int difficulty;
public ItemStack input1;
public ItemStack input2;
public ItemStack input3;
public FoodItem result;
public CombineRecipe(int difficulty, ItemStack input1, ItemStack input2, ItemStack input3,
FoodItem result) {
this.difficulty = difficulty;
if (input1 == null && input2 != null) {
input1 = input2;
input2 = null;
} else if (input1 == null && input3 != null) {
input1 = input3;
input3 = null;
}
this.input1 = input1;
if (input3 != null && input2 == null) {
input2 = input3;
input3 = null;
}
this.input2 = input2;
this.input3 = input3;
this.result = result;
}
@Override
public ItemStack getDisplay() {
return result.getItem();
}
@Override
public String getDescription() {
String name;
name = YamlWriter.toStandardFormat(input1.getType().name());
String builder = "In a mixing pot, stir together ";
if (input1.hasItemMeta() && input1.getItemMeta().hasDisplayName())
name = input1.getItemMeta().getDisplayName();
builder += "a [" + name + "] ";
if (input2 == null) {
return builder;
}
name = YamlWriter.toStandardFormat(input2.getType().name());
if (input2.hasItemMeta() && input2.getItemMeta().hasDisplayName())
name = input2.getItemMeta().getDisplayName();
if (input3 == null)
builder += "and ";
else
builder += ", ";
builder += "a [" + name + "] ";
if (input3 == null) {
return builder;
}
name = YamlWriter.toStandardFormat(input3.getType().name());
if (input3.hasItemMeta() && input3.getItemMeta().hasDisplayName())
name = input3.getItemMeta().getDisplayName();
builder += ", and a [" + name + "] ";
return builder;
}
@Override
public int getDifficulty() {
return this.difficulty;
}
}
public Type getType() {
return Skill.Type.TRADE;
}
public String getName() {
return "Cooking";
}
public String getDescription(QuestPlayer player) {
String ret = ChatColor.WHITE + "The Cooking Skill governs the players ability to create difficult"
+ " mixtures and complicated meals. It also how good a player's dishes are.";
int level = player.getSkillLevel(this);
ret += "\n\n" + ChatColor.GOLD + "Bonus Quality: +" + String.format("%.2f", (level * qualityRate));
ret += "\n" + ChatColor.GREEN + "Time Discount: "
+ (int) (100 * (timeDiscount * level)) + "%" + ChatColor.RESET;
return ret;
}
@Override
public int getStartingLevel() {
return startingLevel;
}
@Override
public String getConfigKey() {
return "Cooking";
}
@Override
public ItemStack getIcon() {
return new ItemStack(Material.BREAD);
}
@Override
public boolean equals(Object o) {
return (o instanceof CookingSkill);
}
private int startingLevel;
private double timeDiscount;
private double qualityRate;
private Map<Location, QuestPlayer> furnaceMap;
private double fuelSwapTime;
private double baseTime;
private double timeRate;
private double bonusQuality;
private int failInterval;
private boolean useItemQuality;
private double combineDifficultyRate;
private List<OvenRecipe> oRecipes;
private List<CombineRecipe> cRecipes;
private List<Material> foodBlacklist;
private double hungerRate;
public CookingSkill() {
File configFile = new File(QuestManagerPlugin.questManagerPlugin.getDataFolder(),
QuestManagerPlugin.questManagerPlugin.getPluginConfiguration().getSkillPath() + CONFIG_NAME);
YamlConfiguration config = createConfig(configFile);
if (!config.getBoolean("enabled", true)) {
return;
}
this.startingLevel = config.getInt("startingLevel", 0);
this.baseTime = config.getDouble("baseTime", 20.0);
this.timeRate = config.getDouble("timeRate", .2);
this.timeDiscount = config.getDouble("timeDiscount", .005);
this.fuelSwapTime = config.getDouble("fuelSwapTime", 1.0);
this.qualityRate = config.getDouble("qualityRate", .02);
this.useItemQuality = config.getBoolean("useItemQuality", true);
this.failInterval = config.getInt("failInterval", 25);
this.combineDifficultyRate = config.getDouble("combineDifficultyRate", .05);
this.bonusQuality = config.getDouble("bonusQuality", .20);
this.hungerRate = config.getDouble("hungerRate", .005);
this.oRecipes = new LinkedList<>();
if (!config.contains("oven")) {
QuestManagerPlugin.logger.warning("Didn't find any oven recipe table"
+ "for CookingSkill even though it's enabled!");
return;
} else {
ConfigurationSection sex = config.getConfigurationSection("oven");
for (String key : sex.getKeys(false)) {
if (key.startsWith("==")) {
continue;
}
try {
oRecipes.add(new OvenRecipe(
sex.getInt(key + ".difficulty"), sex.getItemStack(key + ".input"),
new FoodItem(sex.getItemStack(key + ".output"), sex.getInt(key + ".food"))
));
} catch (Exception e) {
e.printStackTrace();
QuestManagerPlugin.logger.warning("Skipping that one! ^");
}
}
}
this.cRecipes = new LinkedList<>();
if (!config.contains("mixing")) {
QuestManagerPlugin.logger.warning("Didn't find any mixing recipe table"
+ "for CookingSkill even though it's enabled!");
return;
} else {
ConfigurationSection sex = config.getConfigurationSection("mixing");
for (String key : sex.getKeys(false)) {
if (key.startsWith("==")) {
continue;
}
try {
cRecipes.add(new CombineRecipe(
sex.getInt(key + ".difficulty"), sex.getItemStack(key + ".input1"),
(sex.contains(key + ".input2") ? sex.getItemStack(key + ".input2") : null),
(sex.contains(key + ".input3") ? sex.getItemStack(key + ".input3") : null),
new FoodItem(sex.getItemStack(key + ".output"), sex.getInt(key + ".food"))
));
} catch (Exception e) {
e.printStackTrace();
QuestManagerPlugin.logger.warning("Skipping that one! ^");
}
}
}
this.foodBlacklist = new LinkedList<>();
if (config.contains("badfoods")) {
List<String> blacklist = config.getStringList("badfoods");
for (String b : blacklist) {
try {
foodBlacklist.add(Material.valueOf(b.toUpperCase()));
} catch (Exception e) {
QuestManagerPlugin.logger.warning("Could not find Material: "
+ b);
}
}
}
this.furnaceMap = new HashMap<>();
Bukkit.getPluginManager().registerEvents(this, QuestManagerPlugin.questManagerPlugin);
CookingGui.setCookingSkill(this);
CombiningGui.setCookingSkill(this);
}
private YamlConfiguration createConfig(File configFile) {
if (!configFile.exists()) {
YamlWriter writer = new YamlWriter();
writer.addLine("enabled", true, Lists.newArrayList("Whether or not this skill is allowed to be used.", "true | false"))
.addLine("startingLevel", 0, Lists.newArrayList("The level given to players who don't have this skill yet", "[int]"))
.addLine("baseTime", 20.0, Lists.newArrayList("Base time it takes to fufill a recipe", "[double] time in seconds"))
.addLine("timeRate", .2, Lists.newArrayList("How many more seconds are added per", "difficulty of the recipe", "[double] time in seconds"))
.addLine("timeDiscount", .005, Lists.newArrayList("How much of the time a player gets cut", "off per skill level", "[double] 0.01 is 1%"))
.addLine("fuelSwapTime", 1.0, Lists.newArrayList("Time between fuel swaps if the player", "doesn't pick a fuel", "low and high values are difficult", "[double] time in seconds"))
.addLine("qualityRate", .02, Lists.newArrayList("Additional quality on a crafted item given", "per skill level"))
.addLine("useItemQuality", true, Lists.newArrayList("Should ingredient quality be used to calculate", "product quality? If false, quality from", "qualityRate * this skill level is the only", "source of quality. Else, that quality is", "added to the sum of the ingredients", "[true|false]"))
.addLine("failInterval", 25, Lists.newArrayList("How far from 100 (perfect center) the player", "can be without the job stalling and", "racking up failure", "[int] between 0-100"))
.addLine("combineDifficultyRate", .05, Lists.newArrayList("Success-change penalty per level difference in", "mixing recipes and player skill", "[double] 0.05 is 5% per level"))
.addLine("bonusQuality", .20, Lists.newArrayList("Bonus quality percent added to a", "perfect cooking craft", "[double] .2 is 20%"))
.addLine("hungerRate", .005, Lists.newArrayList("How much should hunger be scaled per", "hundreth of quality?", "[double] percentage scaled"));
Map<String, Map<String, Object>> map = new HashMap<>();
Map<String, Object> sub = new HashMap<>();
sub.put("difficulty", 5);
ItemStack item = new ItemStack(Material.RAW_FISH);
ItemMeta meta = item.getItemMeta();
meta.setDisplayName("Trout");
item.setItemMeta(meta);
sub.put("input", item);
item = new ItemStack(Material.COOKED_FISH);
meta = item.getItemMeta();
meta.setDisplayName("Trout");
item.setItemMeta(meta);
sub.put("output", item);
sub.put("food", 3);
map.put("Trout", sub);
sub = new HashMap<>();
sub.put("difficulty", 15);
item = new ItemStack(Material.RAW_FISH, 1, (short) 1);
meta = item.getItemMeta();
meta.setDisplayName("Salmon");
item.setItemMeta(meta);
sub.put("input", item);
item = new ItemStack(Material.COOKED_FISH, 1, (short) 1);
meta = item.getItemMeta();
meta.setDisplayName("Salmon");
item.setItemMeta(meta);
sub.put("output", item);
sub.put("food", 4);
map.put("Salmon", sub);
sub = new HashMap<>();
sub.put("difficulty", 20);
item = new ItemStack(Material.CLAY_BALL);
meta = item.getItemMeta();
meta.setDisplayName("Dough");
item.setItemMeta(meta);
sub.put("input", item);
item = new ItemStack(Material.BREAD);
meta = item.getItemMeta();
sub.put("output", item);
sub.put("food", 3);
map.put("Bread", sub);
writer.addLine("oven", map, Lists.newArrayList("List of oven recipes. Names of", "input items must match exactly", "Plan difficulties carefully, as players that are", "at a level with no fish in range (maxDifficultyRange)", "are stuck forever!", "name: {difficulty: [int], icon: [itemstack]}"));
map = new HashMap<>();
sub = new HashMap<>();
sub.put("difficulty", 10);
item = new ItemStack(Material.WHEAT);
sub.put("input1", item);
item = new ItemStack(Material.WHEAT);
sub.put("input2", item);
item = new ItemStack(Material.CLAY_BALL);
meta = item.getItemMeta();
meta.setDisplayName("Dough");
item.setItemMeta(meta);
sub.put("output", item);
sub.put("food", 0);
map.put("Dough", sub);
writer.addLine("mixing", map, Lists.newArrayList("List of mixing recipes. Names of", "input items must match exactly", "Difficulty follows the traditional (think magery)", "spell calculations. No rounding happens.", "name: {difficulty: [int], input1: [itemstack], input 2..3: [itemstack|null] output: [itemstack]}"));
try {
writer.save(configFile);
} catch (Exception e) {
e.printStackTrace();
}
return writer.buildYaml();
}
YamlConfiguration config = YamlConfiguration.loadConfiguration(configFile);
return config;
}
private void onPlayerCombine(PlayerInteractEvent e) {
if (e.getClickedBlock().getType() != Material.CAULDRON) {
return;
}
QuestPlayer qp = QuestManagerPlugin.questManagerPlugin.getPlayerManager().getPlayer(e.getPlayer());
CombiningGui gui = new CombiningGui(e.getPlayer(), "Mixing Pot");
InventoryMenu menu = new InventoryMenu(qp, gui);
QuestManagerPlugin.questManagerPlugin.getInventoryGuiHandler().showMenu(e.getPlayer(), menu);
e.setCancelled(true);
}
@EventHandler
public void onPlayerCook(PlayerInteractEvent e) {
if (!QuestManagerPlugin.questManagerPlugin.getPluginConfiguration().getWorlds()
.contains(e.getPlayer().getWorld().getName())) {
return;
}
if (e.getHand() != EquipmentSlot.HAND)
return;
if (e.getClickedBlock() == null)
return;
if (e.getClickedBlock().getType() != Material.FURNACE &&
e.getClickedBlock().getType() != Material.BURNING_FURNACE) {
onPlayerCombine(e);
return;
}
if (furnaceMap.containsKey(e.getClickedBlock().getLocation())) {
e.getPlayer().sendMessage(IN_USE_MESSAGE);
e.setCancelled(true);
return;
}
QuestPlayer qp = QuestManagerPlugin.questManagerPlugin.getPlayerManager().getPlayer(e.getPlayer());
furnaceMap.put(e.getClickedBlock().getLocation(), qp);
CookingGui gui = new CookingGui(e.getPlayer(), (Furnace) e.getClickedBlock().getState(),
bonusQuality, useItemQuality
);
InventoryMenu menu = new InventoryMenu(qp, gui);
QuestManagerPlugin.questManagerPlugin.getInventoryGuiHandler().showMenu(e.getPlayer(), menu);
e.setCancelled(true);
return;
}
/**
* Scans the available recipes given the provided input and returns the first matching recipe.
* If multiple recipes are defined with the same input, the first registered is returned.
* @return A recipe with the same input as given, if one exists. Null otherwise
*/
public OvenRecipe getOvenRecipe(ItemStack input) {
if (oRecipes.isEmpty()) {
return null;
}
for (OvenRecipe recipe : oRecipes) {
if (isMatch(recipe.input, input)) {
return recipe;
}
}
return null;
}
/**
* With the provided inputs, looks for a combine recipe with the same constraints.
* The recipe provided must match all constraints. This included names
* @return A recipe with the same input as given, if one exists. Null otherwise
*/
public CombineRecipe getMixingRecipe(ItemStack input1, ItemStack input2, ItemStack input3) {
if (oRecipes.isEmpty()) {
return null;
}
List<ItemStack> args, inputs;
Iterator<ItemStack> it;
inputs = Lists.newArrayList(input1, input2, input3);
for (CombineRecipe recipe : cRecipes) {
int size = inputs.size();
args = Lists.newArrayList(recipe.input1, recipe.input2, recipe.input3);
for (ItemStack item : inputs) {
size--;
it = args.iterator();
while (it.hasNext()) {
if (isMatch(it.next(), item)) {
it.remove();
break;
}
}
if (size < args.size())
break;
}
if (args.isEmpty())
return recipe;
}
return null;
}
public double getCombineChance(QuestPlayer player, CombineRecipe recipe) {
int level = player.getSkillLevel(this);
return 1.0 - Math.max(0, Math.min(1, combineDifficultyRate * ((double) (recipe.difficulty - level))));
}
private boolean isMatch(ItemStack i1, ItemStack i2) {
if (i1 == null && i2 == null)
return true;
if (i1 == null || i2 == null) {
return false;
}
if (i1.getType() != i2.getType() || i1.getDurability() != i2.getDurability())
return false;
// if (!i1.hasItemMeta() && !i2.hasItemMeta())
// return true;
//
// if (!i1.hasItemMeta() || !i2.hasItemMeta())
// return false;
//
// ItemMeta m1 = i1.getItemMeta(), m2 = i2.getItemMeta();
//
// if (m1.getDisplayName() == null && m2.getDisplayName() == null)
// return true;
//
// if (m1.getDisplayName() == null || m2.getDisplayName() == null)
// return false;
String name1, name2;
name1 = name2 = null;
if (i1.hasItemMeta() && i1.getItemMeta().hasDisplayName())
name1 = i1.getItemMeta().getDisplayName();
if (i2.hasItemMeta() && i2.getItemMeta().hasDisplayName())
name2 = i2.getItemMeta().getDisplayName();
if (name1 == null && name2 == null)
return true;
if (name1 == null || name2 == null)
return false;
return ChatColor.stripColor(name1).equals(ChatColor.stripColor(name2));
}
public void unregisterOven(Location location) {
furnaceMap.remove(location);
}
@EventHandler
public void onCook(CraftEvent e) {
if (e.getType() != CraftEvent.CraftingType.COOKING) {
return;
}
double level = e.getPlayer().getSkillLevel(this);
e.setQualityModifier(e.getQualityModifier() + (level * qualityRate));
}
public CookingStats getCookingStats(OvenRecipe recipe, QuestPlayer player) {
double cookTime, fuelSwapTime;
int failInterval;
int lvl = player.getSkillLevel(this);
cookTime = baseTime + (timeRate * (double) recipe.difficulty);
cookTime *= 1.0 - ((double) lvl * timeDiscount);
fuelSwapTime = this.fuelSwapTime;
failInterval = this.failInterval;
return new CookingStats(cookTime, fuelSwapTime, failInterval);
}
@EventHandler
public void onPlayerEat(PlayerItemConsumeEvent e) {
if (!QuestManagerPlugin.questManagerPlugin.getPluginConfiguration().getWorlds()
.contains(e.getPlayer().getWorld().getName())) {
return;
}
e.setCancelled(true);
if (foodBlacklist.contains(e.getItem().getType())) {
e.getPlayer().sendMessage(BLACKLIST_MESSAGE);
return;
}
ItemStack inHand = e.getItem();
FoodItem food = FoodItem.wrapItem(inHand.clone());
//make sure not raw food
if (inHand.hasItemMeta() && inHand.getItemMeta().hasLore()) {
boolean qlevel = false, flevel = false;
for (String line : inHand.getItemMeta().getLore()) {
if (line.toLowerCase().contains("quality:"))
qlevel = true;
else if (line.toLowerCase().contains("food level:"))
flevel = true;
}
if (qlevel && !flevel)
return;
}
inHand.setAmount(inHand.getAmount() - 1);
if (inHand.getAmount() == 0)
inHand = null;
if (e.getItem().isSimilar(e.getPlayer().getInventory().getItemInMainHand()))
e.getPlayer().getInventory().setItemInMainHand(inHand);
else
e.getPlayer().getInventory().setItemInOffHand(inHand);
double qualityDifference = food.getQuality() - 1.0;
qualityDifference = qualityDifference * hungerRate;
int newLevel = Math.min(20, e.getPlayer().getFoodLevel()
// + (int) Math.round(food.getFoodLevel() * (1 + qualityDifference)));
+ (int) Math.round(food.getFoodLevel()));
FoodLevelChangeEvent event = new FoodLevelChangeEvent(e.getPlayer(), newLevel);
Bukkit.getPluginManager().callEvent(event);
if (event.isCancelled()) {
return;
}
newLevel = event.getFoodLevel();
e.getPlayer().setSaturation(e.getPlayer().getSaturation() + food.getFoodLevel());
e.getPlayer().setFoodLevel(newLevel);
e.getPlayer().getWorld().playSound(e.getPlayer().getLocation(), Sound.ENTITY_PLAYER_BURP, 1,1);
}
@Override
public List<SkillRecipe> getRecipes() {
List<SkillRecipe> list = new LinkedList<>();
list.addAll(cRecipes);
list.addAll(oRecipes);
return list;
}
public double calculateFoodLevel(int initialFoodLevel, double quality) {
double additional = Math.max(0, quality - 1);
additional *= hungerRate;
return initialFoodLevel + additional;
}
}