mirror of
https://github.com/nulli0n/ExcellentEnchants-spigot.git
synced 2024-11-22 11:35:18 +01:00
3.3.0.4
This commit is contained in:
parent
a419c9e147
commit
390f7d0149
12
Core/pom.xml
12
Core/pom.xml
@ -5,7 +5,7 @@
|
||||
<parent>
|
||||
<artifactId>ExcellentEnchants</artifactId>
|
||||
<groupId>su.nightexpress.excellentenchants</groupId>
|
||||
<version>3.3.0.3</version>
|
||||
<version>3.3.0.4</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
@ -45,27 +45,27 @@
|
||||
<dependency>
|
||||
<groupId>su.nightexpress.excellentenchants</groupId>
|
||||
<artifactId>NMS</artifactId>
|
||||
<version>3.3.0.3</version>
|
||||
<version>3.3.0.4</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>su.nightexpress.excellentenchants</groupId>
|
||||
<artifactId>V1_17_R1</artifactId>
|
||||
<version>3.3.0.3</version>
|
||||
<version>3.3.0.4</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>su.nightexpress.excellentenchants</groupId>
|
||||
<artifactId>V1_18_R2</artifactId>
|
||||
<version>3.3.0.3</version>
|
||||
<version>3.3.0.4</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>su.nightexpress.excellentenchants</groupId>
|
||||
<artifactId>V1_19_R1</artifactId>
|
||||
<version>3.3.0.3</version>
|
||||
<version>3.3.0.4</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>su.nightexpress.excellentenchants</groupId>
|
||||
<artifactId>V1_19_R2</artifactId>
|
||||
<version>3.3.0.3</version>
|
||||
<version>3.3.0.4</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>fr.neatmonster</groupId>
|
||||
|
@ -420,6 +420,11 @@ public abstract class ExcellentEnchant extends Enchantment implements IEnchantme
|
||||
return EnchantManager.isEnchantmentFullOfCharges(item, this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getCharges(@NotNull ItemStack item) {
|
||||
return EnchantManager.getEnchantmentCharges(item, this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void consumeCharges(@NotNull ItemStack item) {
|
||||
EnchantManager.consumeEnchantmentCharges(item, this);
|
||||
|
@ -70,6 +70,8 @@ public interface IEnchantment {
|
||||
|
||||
boolean isChargesFuel(@NotNull ItemStack item);
|
||||
|
||||
int getCharges(@NotNull ItemStack item);
|
||||
|
||||
boolean isFullOfCharges(@NotNull ItemStack item);
|
||||
|
||||
boolean isOutOfCharges(@NotNull ItemStack item);
|
||||
|
@ -131,7 +131,11 @@ public class EnchantRegrowth extends ExcellentEnchant implements PassiveEnchant,
|
||||
public void action() {
|
||||
for (LivingEntity entity : this.getEntities()) {
|
||||
EnchantManager.getEquippedEnchants(entity, EnchantRegrowth.class).forEach((item, enchants) -> {
|
||||
enchants.forEach((enchant, level) -> enchant.onTrigger(entity, item, level));
|
||||
enchants.forEach((enchant, level) -> {
|
||||
if (enchant.onTrigger(entity, item, level)) {
|
||||
enchant.consumeCharges(item);
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
|
@ -19,6 +19,7 @@ import su.nightexpress.excellentenchants.ExcellentEnchantsAPI;
|
||||
import su.nightexpress.excellentenchants.api.enchantment.ExcellentEnchant;
|
||||
import su.nightexpress.excellentenchants.enchantment.EnchantManager;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
@ -56,7 +57,7 @@ public class EnchantAnvilListener extends AbstractListener<ExcellentEnchants> {
|
||||
private boolean handleRename(@NotNull PrepareAnvilEvent e,
|
||||
@NotNull ItemStack first, @NotNull ItemStack second, @NotNull ItemStack result) {
|
||||
|
||||
if (!second.getType().isAir()) return false;
|
||||
if (!second.getType().isAir() && (second.getType() == first.getType() || second.getType() == Material.ENCHANTED_BOOK)) return false;
|
||||
if (result.getType() != first.getType()) return false;
|
||||
|
||||
ItemStack result2 = new ItemStack(result);
|
||||
@ -71,16 +72,22 @@ public class EnchantAnvilListener extends AbstractListener<ExcellentEnchants> {
|
||||
@NotNull ItemStack first, @NotNull ItemStack second, @NotNull ItemStack result) {
|
||||
if (second.getType().isAir()) return false;
|
||||
|
||||
Set<ExcellentEnchant> chargeable = EnchantManager.getExcellentEnchantments(first).keySet().stream()
|
||||
Set<ExcellentEnchant> chargeables = EnchantManager.getExcellentEnchantments(first).keySet().stream()
|
||||
.filter(en -> en.isChargesEnabled() && en.isChargesFuel(second) && !en.isFullOfCharges(first))
|
||||
.collect(Collectors.toSet());
|
||||
if (chargeable.isEmpty()) return false;
|
||||
if (chargeables.isEmpty()) return false;
|
||||
|
||||
ItemStack result2 = new ItemStack(first);
|
||||
chargeable.forEach(enchant -> EnchantManager.rechargeEnchantmentCharges(result2, enchant));
|
||||
PDCUtil.setData(result2, RECHARGED, true);
|
||||
|
||||
int count = 0;
|
||||
while (count < second.getAmount() && !chargeables.stream().allMatch(en -> en.isFullOfCharges(result2))) {
|
||||
chargeables.forEach(enchant -> EnchantManager.rechargeEnchantmentCharges(result2, enchant));
|
||||
count++;
|
||||
}
|
||||
|
||||
PDCUtil.setData(result2, RECHARGED, count);
|
||||
e.setResult(result2);
|
||||
this.plugin.runTask(c -> e.getInventory().setRepairCost(chargeable.size()), false);
|
||||
this.plugin.runTask(c -> e.getInventory().setRepairCost(chargeables.size()), false);
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -92,12 +99,14 @@ public class EnchantAnvilListener extends AbstractListener<ExcellentEnchants> {
|
||||
|
||||
ItemStack result2 = new ItemStack(result.getType().isAir() ? first : result);
|
||||
Map<ExcellentEnchant, Integer> enchantments = EnchantManager.getExcellentEnchantments(first);
|
||||
Map<ExcellentEnchant, Integer> charges = new HashMap<>(enchantments.keySet().stream().collect(Collectors.toMap(k -> k, v -> v.getCharges(first))));
|
||||
AtomicInteger repairCost = new AtomicInteger(e.getInventory().getRepairCost());
|
||||
|
||||
// Merge only if it's Item + Item, Item + Enchanted book or Enchanted Book + Enchanted Book
|
||||
if (second.getType() == Material.ENCHANTED_BOOK || second.getType() == first.getType()) {
|
||||
EnchantManager.getExcellentEnchantments(second).forEach((enchant, level) -> {
|
||||
enchantments.merge(enchant, level, (oldLvl, newLvl) -> (oldLvl.equals(newLvl)) ? (Math.min(enchant.getMaxLevel(), oldLvl + 1)) : (Math.max(oldLvl, newLvl)));
|
||||
charges.merge(enchant, enchant.getCharges(second), Integer::sum);
|
||||
});
|
||||
}
|
||||
|
||||
@ -105,6 +114,7 @@ public class EnchantAnvilListener extends AbstractListener<ExcellentEnchants> {
|
||||
enchantments.forEach((enchant, level) -> {
|
||||
if (EnchantManager.addEnchantment(result2, enchant, level, false)) {
|
||||
repairCost.addAndGet(enchant.getAnvilMergeCost(level));
|
||||
EnchantManager.setEnchantmentCharges(result2, enchant, charges.getOrDefault(enchant, 0));
|
||||
}
|
||||
});
|
||||
|
||||
@ -123,7 +133,10 @@ public class EnchantAnvilListener extends AbstractListener<ExcellentEnchants> {
|
||||
if (e.getRawSlot() != 2) return;
|
||||
|
||||
ItemStack item = e.getCurrentItem();
|
||||
if (item == null || !PDCUtil.getBooleanData(item, RECHARGED)) return;
|
||||
if (item == null) return;
|
||||
|
||||
int count = PDCUtil.getIntData(item, RECHARGED);
|
||||
if (count == 0) return;
|
||||
|
||||
Player player = (Player) e.getWhoClicked();
|
||||
if (player.getLevel() < inventory.getRepairCost()) return;
|
||||
@ -137,7 +150,7 @@ public class EnchantAnvilListener extends AbstractListener<ExcellentEnchants> {
|
||||
|
||||
ItemStack second = inventory.getItem(1);
|
||||
if (second != null && !second.getType().isAir()) {
|
||||
second.setAmount(second.getAmount() - 1);
|
||||
second.setAmount(second.getAmount() - count);
|
||||
}
|
||||
inventory.setItem(0, null);
|
||||
//inventory.setItem(1, null);
|
||||
|
@ -84,9 +84,10 @@ public class ProtocolHook {
|
||||
ItemMeta meta = copy.getItemMeta();
|
||||
if (meta == null) return item;
|
||||
|
||||
List<String> lore = meta.getLore() == null ? new ArrayList<>() : meta.getLore();
|
||||
Map<ExcellentEnchant, Integer> enchants = EnchantManager.getExcellentEnchantments(item);
|
||||
if (enchants.isEmpty()) return item;
|
||||
|
||||
List<String> lore = meta.getLore() == null ? new ArrayList<>() : meta.getLore();
|
||||
enchants.keySet().forEach(enchant -> lore.removeIf(line -> line.contains(enchant.getDisplayName())));
|
||||
if (isCreative) {
|
||||
enchants.forEach((enchant, level) -> {
|
||||
|
@ -5,7 +5,7 @@
|
||||
<parent>
|
||||
<artifactId>ExcellentEnchants</artifactId>
|
||||
<groupId>su.nightexpress.excellentenchants</groupId>
|
||||
<version>3.3.0.3</version>
|
||||
<version>3.3.0.4</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
|
@ -5,7 +5,7 @@
|
||||
<parent>
|
||||
<artifactId>ExcellentEnchants</artifactId>
|
||||
<groupId>su.nightexpress.excellentenchants</groupId>
|
||||
<version>3.3.0.3</version>
|
||||
<version>3.3.0.4</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
@ -26,7 +26,7 @@
|
||||
<dependency>
|
||||
<groupId>su.nightexpress.excellentenchants</groupId>
|
||||
<artifactId>NMS</artifactId>
|
||||
<version>3.3.0.3</version>
|
||||
<version>3.3.0.4</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
|
@ -5,7 +5,7 @@
|
||||
<parent>
|
||||
<artifactId>ExcellentEnchants</artifactId>
|
||||
<groupId>su.nightexpress.excellentenchants</groupId>
|
||||
<version>3.3.0.3</version>
|
||||
<version>3.3.0.4</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
@ -26,7 +26,7 @@
|
||||
<dependency>
|
||||
<groupId>su.nightexpress.excellentenchants</groupId>
|
||||
<artifactId>NMS</artifactId>
|
||||
<version>3.3.0.3</version>
|
||||
<version>3.3.0.4</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
|
@ -5,7 +5,7 @@
|
||||
<parent>
|
||||
<artifactId>ExcellentEnchants</artifactId>
|
||||
<groupId>su.nightexpress.excellentenchants</groupId>
|
||||
<version>3.3.0.3</version>
|
||||
<version>3.3.0.4</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
@ -26,7 +26,7 @@
|
||||
<dependency>
|
||||
<groupId>su.nightexpress.excellentenchants</groupId>
|
||||
<artifactId>NMS</artifactId>
|
||||
<version>3.3.0.3</version>
|
||||
<version>3.3.0.4</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
|
@ -5,7 +5,7 @@
|
||||
<parent>
|
||||
<artifactId>ExcellentEnchants</artifactId>
|
||||
<groupId>su.nightexpress.excellentenchants</groupId>
|
||||
<version>3.3.0.3</version>
|
||||
<version>3.3.0.4</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
@ -26,7 +26,7 @@
|
||||
<dependency>
|
||||
<groupId>su.nightexpress.excellentenchants</groupId>
|
||||
<artifactId>NMS</artifactId>
|
||||
<version>3.3.0.3</version>
|
||||
<version>3.3.0.4</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user