Skip to content

Commit

Permalink
[FIX] Enchant that are already presents now take highest level
Browse files Browse the repository at this point in the history
  • Loading branch information
Dzious committed Nov 18, 2020
1 parent f2f4630 commit ea1e8c2
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 10 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ ___
[Arkobat]: https://github.com/Arkobat
[EnchantContol]: https://www.spigotmc.org/resources/enchantcontrol-1-8-1-14-take-back-control-over-all-enchants-on-your-server.55084

[Latest Release]: https://github.com/Dzious/EnchantControl/releases/tag/v1.2.1
[Latest Release]: https://github.com/Dzious/EnchantControl/releases/tag/v1.2.2
<!-- [Latest Pre-Release] -->

[Issue Tracker]: https://github.com/Dzious/EnchantControl/issues
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>com.dzious.bukkit.enchantcontrol</groupId>
<artifactId>EnchantControl_Reforged</artifactId>
<version>1.2.1</version>
<version>1.2.2</version>

<properties>
<java.version>1.8</java.version>
Expand Down
22 changes: 14 additions & 8 deletions src/com/dzious/bukkit/enchantcontrol/listener/AnvilListener.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
package com.dzious.bukkit.enchantcontrol.listener;

import java.util.HashMap;
import java.util.Map;

import com.dzious.bukkit.enchantcontrol.EnchantControl;

import org.bukkit.enchantments.Enchantment;
Expand All @@ -12,9 +15,6 @@

import net.md_5.bungee.api.ChatColor;

import java.util.HashMap;
import java.util.Map;

public class AnvilListener implements Listener {
private final EnchantControl plugin;
boolean bypassMinecraftMaxLevel = false;
Expand Down Expand Up @@ -116,7 +116,7 @@ private Map<Enchantment, Integer> computeFusion(ItemStack[] items) {
if (!items[0].getItemMeta().getEnchants().isEmpty()) {
lhsEnchantments = new HashMap<>(items[0].getItemMeta().getEnchants()); ;
} else if (items[0].getItemMeta() instanceof EnchantmentStorageMeta &&
!((EnchantmentStorageMeta)items[0].getItemMeta()).getStoredEnchants().isEmpty()) {
!((EnchantmentStorageMeta)items[0].getItemMeta()).getStoredEnchants().isEmpty()) {
lhsEnchantments = new HashMap<>(((EnchantmentStorageMeta)items[0].getItemMeta()).getStoredEnchants());
} else {
lhsEnchantments = new HashMap<>();
Expand All @@ -132,10 +132,16 @@ private Map<Enchantment, Integer> computeFusion(ItemStack[] items) {
}

for (Map.Entry<Enchantment, Integer> enchantment : lhsEnchantments.entrySet()) {
if (rhsEnchantments.containsKey(enchantment.getKey()) &&
enchantment.getValue() == rhsEnchantments.get(enchantment.getKey()) &&
enchantment.getValue() < plugin.getEnchantmentManager().getAffectedEnchantments().get(enchantment.getKey())) {
enchantments.put(enchantment.getKey(), enchantment.getValue() + 1);
if (rhsEnchantments.containsKey(enchantment.getKey())) {
if (enchantment.getValue() == rhsEnchantments.get(enchantment.getKey()) &&
enchantment.getValue() < plugin.getEnchantmentManager().getAffectedEnchantments().get(enchantment.getKey())) {
enchantments.put(enchantment.getKey(), enchantment.getValue() + 1);
} else if (enchantment.getValue() < rhsEnchantments.get(enchantment.getKey())) {
enchantments.put(enchantment.getKey(), rhsEnchantments.get(enchantment.getKey()));
} else {
enchantments.put(enchantment.getKey(), enchantment.getValue());

}
} else {
enchantments.put(enchantment.getKey(), enchantment.getValue());
}
Expand Down

0 comments on commit ea1e8c2

Please sign in to comment.