-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathSSKSword.java
More file actions
98 lines (79 loc) · 3.31 KB
/
Copy pathSSKSword.java
File metadata and controls
98 lines (79 loc) · 3.31 KB
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
package xyz.holocons.mc.holoitemsrevamp.enchantment;
import java.util.List;
import org.bukkit.Material;
import org.bukkit.Particle;
import org.bukkit.Sound;
import org.bukkit.attribute.Attribute;
import org.bukkit.enchantments.Enchantment;
import org.bukkit.entity.Entity;
import org.bukkit.entity.EntityCategory;
import org.bukkit.entity.LivingEntity;
import org.bukkit.event.entity.EntityDamageByEntityEvent;
import org.bukkit.inventory.ItemStack;
import org.bukkit.potion.PotionEffect;
import org.bukkit.potion.PotionEffectType;
import org.jetbrains.annotations.NotNull;
import com.strangeone101.holoitemsapi.enchantment.CustomEnchantment;
import com.strangeone101.holoitemsapi.enchantment.EnchantmentAbility;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.format.NamedTextColor;
import net.kyori.adventure.text.format.TextDecoration;
import xyz.holocons.mc.holoitemsrevamp.HoloItemsRevamp;
public class SSKSword extends CustomEnchantment implements EnchantmentAbility {
private static final int ticksPerLevel = 80;
public SSKSword(HoloItemsRevamp plugin) {
super(plugin, "ssk_sword");
}
@Override
public int getMaxLevel() {
return 1;
}
@Override
public boolean conflictsWith(@NotNull Enchantment other) {
return false;
}
@Override
public boolean canEnchantItem(@NotNull ItemStack itemStack) {
return itemStack.getType() == Material.DIAMOND_SWORD;
}
@Override
public @NotNull Component displayName(int level) {
return Component.text()
.color(NamedTextColor.GRAY)
.decoration(TextDecoration.ITALIC, false)
.append(Component.text("SSK Sword"))
.build();
}
@Override
public int getCostMultiplier() {
return 12;
}
@Override
public void onEntityDamageByEntity(EntityDamageByEntityEvent event, ItemStack itemStack) {
if (isMissingHealth(event.getDamager())) {
return;
}
final var rawDamage = event.getDamage();
if (rawDamage <= 0d || !(event.getEntity() instanceof LivingEntity target)) {
return;
}
event.setDamage(0);
final var targetIsUndead = target.getCategory() == EntityCategory.UNDEAD;
final var effectType = targetIsUndead ? PotionEffectType.HARM : PotionEffectType.HEAL;
target.addPotionEffect(new PotionEffect(effectType, 1, 1));
final var fireAspectLevel = itemStack.getEnchantmentLevel(FIRE_ASPECT);
if (fireAspectLevel > 0) {
target.addPotionEffects(List.of(
new PotionEffect(PotionEffectType.FIRE_RESISTANCE, ticksPerLevel * fireAspectLevel, 1),
new PotionEffect(PotionEffectType.SPEED, ticksPerLevel * fireAspectLevel, 1)));
}
final var location = target.getLocation().add(0, target.getHeight() / 2, 0);
final var world = location.getWorld();
world.spawnParticle(Particle.HEART, location, 3, 0.5, 0.5, 0.5);
world.playSound(location, Sound.ENTITY_EXPERIENCE_ORB_PICKUP, 0.1f, 1f);
}
private static boolean isMissingHealth(final Entity entity) {
return entity instanceof LivingEntity livingEntity
&& livingEntity.getHealth() < livingEntity.getAttribute(Attribute.GENERIC_MAX_HEALTH).getValue();
}
}