Skip to content

Commit adfee10

Browse files
committed
improve: 优化附魔上限限制
1 parent 9e9715a commit adfee10

3 files changed

Lines changed: 8 additions & 15 deletions

File tree

pom.xml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@
66
<groupId>com.github.thebusybiscuit</groupId>
77
<artifactId>Slimefun</artifactId>
88

9-
<!-- Our default version will be UNOFFICIAL, this will prevent the auto updater -->
10-
<!-- from overriding our local test file -->
119
<version>4.8-nightly</version>
1210

1311
<properties>

src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/electric/machines/AutoDisenchanter.java

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
import org.bukkit.Bukkit;
1414
import org.bukkit.Material;
1515
import org.bukkit.enchantments.Enchantment;
16-
import org.bukkit.entity.HumanEntity;
1716
import org.bukkit.inventory.ItemStack;
1817
import org.bukkit.inventory.meta.EnchantmentStorageMeta;
1918
import org.bukkit.inventory.meta.ItemMeta;
@@ -36,9 +35,13 @@
3635
*/
3736
public class AutoDisenchanter extends AContainer {
3837

38+
private final int limit;
39+
3940
@ParametersAreNonnullByDefault
4041
public AutoDisenchanter(Category category, SlimefunItemStack item, RecipeType recipeType, ItemStack[] recipe) {
4142
super(category, item, recipeType, recipe);
43+
44+
limit = SlimefunPlugin.getCfg().getInt("options.enchanter-level-limit");
4245
}
4346

4447
@Override
@@ -71,13 +74,12 @@ protected MachineRecipe findNextRecipe(BlockMenu menu) {
7174
int amount = 0;
7275

7376
for (Map.Entry<Enchantment, Integer> entry : item.getEnchantments().entrySet()) {
74-
if (entry.getValue() <= SlimefunPlugin.getCfg().getInt("options.enchanter-level-limit") || SlimefunPlugin.getCfg().getInt("options.enchanter-level-limit") == 0) {
77+
if (entry.getValue() <= limit || limit < 1) {
7578
enchantments.put(entry.getKey(), entry.getValue());
7679
amount++;
7780
} else {
7881
if (!menu.toInventory().getViewers().isEmpty()) {
79-
HumanEntity p = menu.toInventory().getViewers().get(0);
80-
SlimefunPlugin.getLocalization().sendMessage(p, "messages.above-limit-level", true);
82+
menu.toInventory().getViewers().forEach(p -> SlimefunPlugin.getLocalization().sendMessage(p, "messages.above-limit-level", true));
8183
}
8284
return null;
8385
}

src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/electric/machines/AutoEnchanter.java

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
import me.mrCookieSlime.Slimefun.api.inventory.BlockMenu;
1212
import org.bukkit.Material;
1313
import org.bukkit.enchantments.Enchantment;
14-
import org.bukkit.entity.HumanEntity;
1514
import org.bukkit.inventory.ItemStack;
1615
import org.bukkit.inventory.meta.EnchantmentStorageMeta;
1716

@@ -21,16 +20,13 @@
2120

2221
public class AutoEnchanter extends AContainer {
2322

24-
private final int emeraldEnchantsLimit;
25-
2623
private final int limit;
2724

2825
@ParametersAreNonnullByDefault
2926
public AutoEnchanter(Category category, SlimefunItemStack item, RecipeType recipeType, ItemStack[] recipe) {
3027
super(category, item, recipeType, recipe);
3128

3229
limit = SlimefunPlugin.getCfg().getInt("options.enchanter-level-limit");
33-
emeraldEnchantsLimit = SlimefunPlugin.getCfg().getInt("options.emerald-enchantment-limit");
3430
}
3531

3632
@Override
@@ -52,20 +48,17 @@ protected MachineRecipe findNextRecipe(BlockMenu menu) {
5248

5349
if (item != null && item.getType() == Material.ENCHANTED_BOOK && target != null) {
5450
Map<Enchantment, Integer> enchantments = new HashMap<>();
55-
5651
int amount = 0;
57-
5852
EnchantmentStorageMeta meta = (EnchantmentStorageMeta) item.getItemMeta();
5953

6054
for (Map.Entry<Enchantment, Integer> e : meta.getStoredEnchants().entrySet()) {
6155
if (e.getKey().canEnchantItem(target)) {
62-
if (e.getValue() <= limit || limit == 0) {
56+
if (e.getValue() <= limit || limit < 1) {
6357
amount++;
6458
enchantments.put(e.getKey(), e.getValue());
6559
} else {
6660
if (!menu.toInventory().getViewers().isEmpty()) {
67-
HumanEntity p = menu.toInventory().getViewers().get(0);
68-
SlimefunPlugin.getLocalization().sendMessage(p, "messages.above-limit-level", true);
61+
menu.toInventory().getViewers().forEach(p -> SlimefunPlugin.getLocalization().sendMessage(p, "messages.above-limit-level", true));
6962
}
7063
}
7164
}

0 commit comments

Comments
 (0)