-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add Deflective Retribution enchantment
- Loading branch information
1 parent
304c4ef
commit 24fc80e
Showing
8 changed files
with
158 additions
and
6 deletions.
There are no files selected for viewing
This file contains 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 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 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 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 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
44 changes: 44 additions & 0 deletions
44
...va/com/github/PatrykCholewa/FoxKiller/listeners/DeflectiveRetributionEnchantListener.java
This file contains 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,44 @@ | ||
package com.github.PatrykCholewa.FoxKiller.listeners; | ||
|
||
import com.github.PatrykCholewa.FoxKiller.enchantments.EnchantmentDefinitions; | ||
import io.papermc.paper.registry.RegistryAccess; | ||
import io.papermc.paper.registry.RegistryKey; | ||
import org.bukkit.enchantments.Enchantment; | ||
import org.bukkit.entity.*; | ||
import org.bukkit.event.EventHandler; | ||
import org.bukkit.event.Listener; | ||
import org.bukkit.event.entity.EntityDamageByEntityEvent; | ||
import org.bukkit.event.entity.EntityDamageEvent; | ||
|
||
import static com.github.PatrykCholewa.FoxKiller.utils.EnchantmentUtils.getEnchantmentRef; | ||
|
||
public class DeflectiveRetributionEnchantListener implements Listener { | ||
|
||
private static final Enchantment ENCHANTMENT = getEnchantmentRef(EnchantmentDefinitions.DEFLECTIVE_RETRIBUTION); | ||
|
||
@EventHandler | ||
public static void onDeath(EntityDamageByEntityEvent event) { | ||
if (!(event.getEntity() instanceof Player)) { | ||
return; | ||
} | ||
|
||
Player player = (Player) event.getEntity(); | ||
|
||
if (!player.getActiveItem().containsEnchantment(ENCHANTMENT)) { | ||
return; | ||
} | ||
|
||
if (!player.isBlocking() && event.getDamage(EntityDamageEvent.DamageModifier.BLOCKING) >= 0) { | ||
return; | ||
} | ||
|
||
Entity cause = event.getDamageSource().getDirectEntity(); | ||
|
||
if (!(cause instanceof Projectile)) { | ||
return; | ||
} | ||
|
||
cause.setVelocity(cause.getVelocity().multiply(25)); | ||
} | ||
|
||
} |
50 changes: 50 additions & 0 deletions
50
src/main/java/com/github/PatrykCholewa/FoxKiller/recipes/RecipeDefinitions.java
This file contains 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,50 @@ | ||
package com.github.PatrykCholewa.FoxKiller.recipes; | ||
|
||
import com.github.PatrykCholewa.FoxKiller.enchantments.EnchantmentDefinitions; | ||
import org.bukkit.Material; | ||
import org.bukkit.NamespacedKey; | ||
import org.bukkit.inventory.ItemStack; | ||
import org.bukkit.inventory.Recipe; | ||
import org.bukkit.inventory.ShapedRecipe; | ||
import org.bukkit.inventory.ShapelessRecipe; | ||
import org.bukkit.inventory.meta.BookMeta; | ||
import org.bukkit.inventory.meta.EnchantmentStorageMeta; | ||
import org.bukkit.inventory.meta.ItemMeta; | ||
import org.bukkit.plugin.Plugin; | ||
|
||
import java.util.List; | ||
|
||
import static com.github.PatrykCholewa.FoxKiller.utils.EnchantmentUtils.getEnchantmentRef; | ||
|
||
|
||
public class RecipeDefinitions { | ||
|
||
private Plugin plugin; | ||
|
||
public RecipeDefinitions(Plugin plugin) { | ||
this.plugin = plugin; | ||
} | ||
|
||
public List<Recipe> createDefinitions() { | ||
return List.of(createDeflectiveRetributionBook()); | ||
} | ||
|
||
private Recipe createDeflectiveRetributionBook() { | ||
NamespacedKey key = new NamespacedKey(plugin, "WarriorSword"); | ||
ItemStack item = new ItemStack(Material.ENCHANTED_BOOK); | ||
EnchantmentStorageMeta itemMeta = (EnchantmentStorageMeta) item.getItemMeta(); | ||
itemMeta.addStoredEnchant(getEnchantmentRef(EnchantmentDefinitions.DEFLECTIVE_RETRIBUTION), 1, false); | ||
item.setItemMeta(itemMeta); | ||
|
||
ShapedRecipe recipe = new ShapedRecipe(key, item); | ||
recipe.shape(" A ", "BCD", "AEA"); | ||
recipe.setIngredient('A', Material.LAPIS_LAZULI); | ||
recipe.setIngredient('C', Material.BOOK); | ||
recipe.setIngredient('B', Material.SPECTRAL_ARROW); | ||
recipe.setIngredient('D', Material.TIPPED_ARROW); | ||
recipe.setIngredient('E', Material.ARROW); | ||
|
||
return recipe; | ||
} | ||
|
||
} |
20 changes: 20 additions & 0 deletions
20
src/main/java/com/github/PatrykCholewa/FoxKiller/utils/EnchantmentUtils.java
This file contains 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,20 @@ | ||
package com.github.PatrykCholewa.FoxKiller.utils; | ||
|
||
import com.github.PatrykCholewa.FoxKiller.enchantments.EnchantmentAssignment; | ||
import io.papermc.paper.registry.RegistryAccess; | ||
import io.papermc.paper.registry.RegistryKey; | ||
import org.bukkit.enchantments.Enchantment; | ||
|
||
public class EnchantmentUtils { | ||
|
||
private EnchantmentUtils() { | ||
|
||
} | ||
|
||
public static Enchantment getEnchantmentRef(EnchantmentAssignment enchantmentAssignment) { | ||
return RegistryAccess.registryAccess() | ||
.getRegistry(RegistryKey.ENCHANTMENT) | ||
.get(enchantmentAssignment.getKey()); | ||
} | ||
|
||
} |