Skip to content

Commit

Permalink
Fix Totems
Browse files Browse the repository at this point in the history
Makes it so that all armor effects are re-applied after the totem takes them away.
  • Loading branch information
TrueDarkLord committed Jan 29, 2024
1 parent d4ae91f commit 163e296
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 5 deletions.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ issues = https://github.com/Crazy-Crew/CrazyEnchantments/issues

group = com.badbones69.crazyenchantments
description = Adds over 80 unique enchantments to your server and more!
version = 2.2
version = 2.2.1
apiVersion = 1.20

minecraftVersion = 1.20.4
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import com.badbones69.crazyenchantments.paper.utilities.misc.EnchantUtils;
import com.badbones69.crazyenchantments.paper.utilities.misc.EventUtils;
import com.destroystokyo.paper.event.player.PlayerArmorChangeEvent;
import org.bukkit.Material;
import org.bukkit.Particle;
import org.bukkit.attribute.Attribute;
import org.bukkit.entity.LivingEntity;
Expand All @@ -32,6 +33,7 @@
import org.bukkit.event.entity.EntityDamageByEntityEvent;
import org.bukkit.event.entity.EntityDamageEvent;
import org.bukkit.event.entity.EntityDamageEvent.DamageCause;
import org.bukkit.event.entity.EntityResurrectEvent;
import org.bukkit.event.entity.PlayerDeathEvent;
import org.bukkit.event.player.PlayerMoveEvent;
import org.bukkit.inventory.ItemStack;
Expand Down Expand Up @@ -78,6 +80,13 @@ public void stop() {
armorMoveProcessor.stop();
}

@EventHandler
public void onDeath(EntityResurrectEvent event) {
if (!(event.getEntity() instanceof Player player)) return;
ItemStack air = new ItemStack(Material.AIR);
plugin.getServer().getScheduler().runTaskLater(plugin, () -> newUpdateEffects(player, air, air), 10);
}

@EventHandler
public void onEquip(PlayerArmorChangeEvent event) {
Player player = event.getPlayer();
Expand Down Expand Up @@ -134,10 +143,12 @@ private Map<PotionEffectType, Integer> getTopPotionEffects(Map<CEnchantment, Int
private HashMap<CEnchantment, Integer> currentEnchantsOnPlayerAdded(Player player, ItemStack newItem) {
HashMap<CEnchantment, Integer> toAdd = getTopEnchantsOnPlayer(player);

enchantmentBookSettings.getEnchantments(newItem).entrySet().stream()
.filter(ench -> !toAdd.containsKey(ench.getKey()) || toAdd.get(ench.getKey()) <= ench.getValue())
.filter(ench -> EnchantUtils.isArmorEventActive(player, CEnchantments.valueOf(ench.getKey().getName().toUpperCase()), newItem))
.forEach(ench -> toAdd.put(ench.getKey(), ench.getValue()));
if (!newItem.isEmpty()) {
enchantmentBookSettings.getEnchantments(newItem).entrySet().stream()
.filter(ench -> !toAdd.containsKey(ench.getKey()) || toAdd.get(ench.getKey()) <= ench.getValue())
.filter(ench -> EnchantUtils.isArmorEventActive(player, CEnchantments.valueOf(ench.getKey().getName().toUpperCase()), newItem))
.forEach(ench -> toAdd.put(ench.getKey(), ench.getValue()));
}

return toAdd;
}
Expand Down

0 comments on commit 163e296

Please sign in to comment.