-
Notifications
You must be signed in to change notification settings - Fork 4
Implement SSK Sword #35
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
cpaca
wants to merge
8
commits into
TraceLTRC:master
Choose a base branch
from
cpaca:SSKSword
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
70b0b1b
SSK Sword First Creation
cpaca 5fed72d
Merge branch 'master' into SSKSword
cpaca e3bf3f0
Rewrite SSK to be a diamond sword
cpaca ef18bbd
Fix SSKSword applyEnchantment
cpaca be9bb8a
Negative damage does actually heal
cpaca 0b360ec
Merge branch 'master' into SSKSword
dlee13 8479e0d
Refactor
dlee13 7cbbfcc
Refactor
dlee13 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
98 changes: 98 additions & 0 deletions
98
src/main/java/xyz/holocons/mc/holoitemsrevamp/enchantment/SSKSword.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,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(); | ||
| } | ||
| } | ||
66 changes: 66 additions & 0 deletions
66
src/main/java/xyz/holocons/mc/holoitemsrevamp/item/SSKSwordItem.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,66 @@ | ||
| package xyz.holocons.mc.holoitemsrevamp.item; | ||
|
|
||
| import com.strangeone101.holoitemsapi.enchantment.CustomEnchantment; | ||
| import com.strangeone101.holoitemsapi.enchantment.EnchantManager; | ||
| import com.strangeone101.holoitemsapi.enchantment.Enchantable; | ||
| import com.strangeone101.holoitemsapi.item.CustomItem; | ||
| import net.kyori.adventure.text.Component; | ||
| import net.kyori.adventure.text.format.NamedTextColor; | ||
| import org.bukkit.Bukkit; | ||
| import org.bukkit.Material; | ||
| import org.bukkit.enchantments.Enchantment; | ||
| import org.bukkit.inventory.ItemStack; | ||
| import org.bukkit.inventory.Recipe; | ||
| import org.bukkit.inventory.ShapedRecipe; | ||
| import xyz.holocons.mc.holoitemsrevamp.HoloItemsRevamp; | ||
|
|
||
| import java.util.List; | ||
|
|
||
| public class SSKSwordItem extends CustomItem implements Enchantable { | ||
|
|
||
| private static final String name = "ssk_sword"; | ||
| private static final Material material = Material.DIAMOND_SWORD; | ||
| private static final Component displayName = Component.text("SSK Sword", NamedTextColor.RED); | ||
| private static final List<Component> lore = List.of( | ||
| Component.text("Heal-on-hit when at full health!", NamedTextColor.DARK_PURPLE) | ||
| ); | ||
|
|
||
| private final EnchantManager enchantManager; | ||
|
|
||
| public SSKSwordItem(HoloItemsRevamp plugin) { | ||
| super(plugin, name, material, displayName, lore); | ||
| this.enchantManager = plugin.getEnchantManager(); | ||
| this.register(); | ||
| } | ||
|
|
||
| @Override | ||
| protected Recipe getRecipe() { | ||
| final var recipe = new ShapedRecipe(getKey(), buildStack(null)); | ||
| recipe.shape("*&#","*&#","*/#"); | ||
| recipe.setIngredient('*', Material.BLAZE_POWDER); | ||
| recipe.setIngredient('&', Material.GHAST_TEAR); | ||
| recipe.setIngredient('#', Material.SUGAR); | ||
| recipe.setIngredient('/', Material.NETHER_STAR); | ||
| return recipe; | ||
| } | ||
|
|
||
| @Override | ||
| public Enchantment getEnchantment() { | ||
| return CustomEnchantment.getByKey(getKey()); | ||
| } | ||
|
|
||
| @Override | ||
| public ItemStack applyEnchantment(ItemStack itemStack) { | ||
| var enchantedStack = itemStack.clone(); | ||
| var enchantedMeta = enchantedStack.hasItemMeta() ? enchantedStack.getItemMeta() : Bukkit.getItemFactory().getItemMeta(enchantedStack.getType()); | ||
|
|
||
| if (enchantedMeta.addEnchant(getEnchantment(), 1, false)) { | ||
| enchantedStack.setItemMeta(enchantedMeta); | ||
| enchantManager.removeCustomEnchantmentLore(enchantedStack); | ||
| enchantManager.applyCustomEnchantmentLore(enchantedStack); | ||
| return enchantedStack; | ||
| } else { | ||
| return null; | ||
| } | ||
| } | ||
| } |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.