From 7dd18898f2e97f8509af5bf8c2f22148337f40e8 Mon Sep 17 00:00:00 2001 From: night0721 Date: Mon, 11 Jul 2022 14:08:53 +0100 Subject: [PATCH] Added shortbow and edited path for jar file to output --- pom.xml | 10 +++- .../nullvalkyrie/Events/onEntityShoot.java | 47 +++++++++++++++++ .../nullvalkyrie/Items/CustomItemManager.java | 51 ++++++++++++++++++- .../java/com/night/nullvalkyrie/Main.java | 4 +- .../nullvalkyrie/commands/MessageCommand.java | 1 - .../nullvalkyrie/commands/WeaponCommand.java | 34 +++---------- 6 files changed, 117 insertions(+), 30 deletions(-) create mode 100644 src/main/java/com/night/nullvalkyrie/Events/onEntityShoot.java diff --git a/pom.xml b/pom.xml index 64f51fd..3a1595f 100644 --- a/pom.xml +++ b/pom.xml @@ -19,6 +19,7 @@ https://github.com/night0721/nullvalkyrie + ${project.name}-${project.version} org.apache.maven.plugins @@ -45,6 +46,14 @@ + + org.apache.maven.plugins + maven-jar-plugin + 2.4 + + D:\Server\plugins + + @@ -53,7 +62,6 @@ - spigotmc-repo diff --git a/src/main/java/com/night/nullvalkyrie/Events/onEntityShoot.java b/src/main/java/com/night/nullvalkyrie/Events/onEntityShoot.java new file mode 100644 index 0000000..b8fe599 --- /dev/null +++ b/src/main/java/com/night/nullvalkyrie/Events/onEntityShoot.java @@ -0,0 +1,47 @@ +package com.night.nullvalkyrie.Events; + +import org.bukkit.ChatColor; +import org.bukkit.entity.Arrow; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.Listener; +import org.bukkit.event.block.Action; +import org.bukkit.event.entity.EntityShootBowEvent; +import org.bukkit.event.player.PlayerInteractEvent; + +public class onEntityShoot implements Listener { + @EventHandler + public void onEntityShoot(EntityShootBowEvent e) { + if(e.getProjectile() instanceof Arrow) { + if(e.getEntity() instanceof Player) { + if(e.getBow() != null && e.getBow().getItemMeta() != null && e.getBow().getItemMeta().getLore() != null && e.getBow().getItemMeta().getLore().contains(ChatColor.GOLD + "Item Ability: Triple Shot")) { + e.setCancelled(true); + } + } + } + } + @EventHandler + public void onInteract(PlayerInteractEvent e) { + Player player = e.getPlayer(); + if(e.getAction() == Action.RIGHT_CLICK_AIR || e.getAction() == Action.RIGHT_CLICK_BLOCK) { + if(e.hasItem()) { + if(player.getInventory().getItemInMainHand().getItemMeta() != null) { + String name = player.getInventory().getItemInMainHand().getItemMeta().getDisplayName(); + if (name.equalsIgnoreCase(net.md_5.bungee.api.ChatColor.of("#ff23ff") + "Terminator")) { + Arrow arrow = player.launchProjectile(Arrow.class, player.getEyeLocation().getDirection()); + arrow.setPickupStatus(Arrow.PickupStatus.DISALLOWED); + arrow.setVelocity(arrow.getVelocity().multiply(5)); + Arrow a1 = player.launchProjectile(Arrow.class, player.getEyeLocation().getDirection()); + a1.setVelocity(arrow.getVelocity().rotateAroundY(Math.toRadians(5)).multiply(5)); + a1.setPickupStatus(Arrow.PickupStatus.DISALLOWED); + Arrow a2 = player.launchProjectile(Arrow.class, player.getEyeLocation().getDirection()); + a2.setVelocity(arrow.getVelocity().rotateAroundY(Math.toRadians(-5)).multiply(5)); + a2.setPickupStatus(Arrow.PickupStatus.DISALLOWED); + e.setCancelled(true); + } + } + } + } + + } +} diff --git a/src/main/java/com/night/nullvalkyrie/Items/CustomItemManager.java b/src/main/java/com/night/nullvalkyrie/Items/CustomItemManager.java index a11c9a7..960e5cb 100644 --- a/src/main/java/com/night/nullvalkyrie/Items/CustomItemManager.java +++ b/src/main/java/com/night/nullvalkyrie/Items/CustomItemManager.java @@ -1,5 +1,7 @@ package com.night.nullvalkyrie.Items; + +import com.night.nullvalkyrie.Enchantments.EnchantmentHandler; import com.night.nullvalkyrie.Main; import org.bukkit.Bukkit; import org.bukkit.ChatColor; @@ -18,8 +20,11 @@ import org.bukkit.inventory.meta.ItemMeta; import java.io.File; import java.io.IOException; import java.util.ArrayList; +import java.util.Arrays; import java.util.UUID; +import static com.night.nullvalkyrie.Enchantments.EnchantmentHandler.ThunderBolt; + public class CustomItemManager { private static Main main; public CustomItemManager(Main main) { @@ -30,9 +35,16 @@ public class CustomItemManager { } public static ItemStack WidowSword; + public static ItemStack Terminator; + public static ItemStack ExplosiveBow; + public static ItemStack Grenade; + public static ItemStack SnowGun; public static void register() { createItemDataDirectory("ItemData"); setWidowSword(); + setTerminator(); + setGrenade(); + setSnowGun(); } public static YamlConfiguration loadConfig(String path) { @@ -77,7 +89,6 @@ public class CustomItemManager { } } private static void setWidowSword() { - YamlConfiguration config = loadConfig("ItemData\\WidowSword.yml"); config.set("zombie", 100); config.set("skeleton", 100); @@ -118,4 +129,42 @@ public class CustomItemManager { wither_sword_recipe.setIngredient('B', Material.STICK); Bukkit.addRecipe(wither_sword_recipe); } + private static void setTerminator() { + ItemStack terminator = new ItemStack(Material.BOW); + terminator.addUnsafeEnchantment(Enchantment.DAMAGE_ALL, 20); + terminator.addUnsafeEnchantment(Enchantment.LOOT_BONUS_MOBS, 10); + terminator.addUnsafeEnchantment(ThunderBolt,5); + ItemMeta terminatorMeta = terminator.getItemMeta(); + terminatorMeta.setDisplayName(net.md_5.bungee.api.ChatColor.of("#ff23ff") + "Terminator"); + terminatorMeta.setUnbreakable(true); + ArrayList lore = new ArrayList<>(); + lore.add(""); + lore.add(ChatColor.GOLD + "Item Ability: Triple Shot"); + lore.add(ChatColor.GRAY + "Shoot three arrow at one time"); + lore.add(""); + lore.add(net.md_5.bungee.api.ChatColor.of("#ff23ff").toString() + ChatColor.BOLD + "MYTHIC"); + terminatorMeta.setLore(lore); + terminator.setItemMeta(terminatorMeta); + Terminator = terminator; + } + private static void setGrenade() { + ItemStack egg = new ItemStack(Material.EGG); + ItemMeta eggdata = egg.getItemMeta(); + eggdata.setDisplayName(net.md_5.bungee.api.ChatColor.of("#ff23ff") + "Frag Grenade"); + eggdata.setUnbreakable(true); + eggdata.setLore(Arrays.asList(ChatColor.GOLD + "Boom")); + egg.setItemMeta(eggdata); + Grenade = egg; + } + private static void setSnowGun() { + ItemStack hoe = new ItemStack(Material.DIAMOND_HOE); + hoe.addUnsafeEnchantment(EnchantmentHandler.ThunderBolt, 5); + hoe.addUnsafeEnchantment(Enchantment.DAMAGE_ALL, 20); + ItemMeta hoedata = hoe.getItemMeta(); + hoedata.setDisplayName(net.md_5.bungee.api.ChatColor.of("#ff23ff") + "SnowGun"); + hoedata.setUnbreakable(true); + hoedata.setLore(Arrays.asList(ChatColor.GOLD + "Shoot Snowball!")); + hoe.setItemMeta(hoedata); + SnowGun = hoe; + } } diff --git a/src/main/java/com/night/nullvalkyrie/Main.java b/src/main/java/com/night/nullvalkyrie/Main.java index 2cdc721..bf85ae8 100644 --- a/src/main/java/com/night/nullvalkyrie/Main.java +++ b/src/main/java/com/night/nullvalkyrie/Main.java @@ -3,6 +3,7 @@ package com.night.nullvalkyrie; import com.night.nullvalkyrie.Chests.MenuListener; import com.night.nullvalkyrie.Enchantments.EnchantmentHandler; import com.night.nullvalkyrie.Events.onEntityDamageByEntity; +import com.night.nullvalkyrie.Events.onEntityShoot; import com.night.nullvalkyrie.Items.CustomItemManager; import com.night.nullvalkyrie.Rank.*; import com.night.nullvalkyrie.Util.Util; @@ -54,12 +55,13 @@ public final class Main extends JavaPlugin implements Listener { Bukkit.getPluginManager().registerEvents(new MenuListener(), this); Bukkit.getPluginManager().registerEvents(new ScoreboardListener(this), this); Bukkit.getPluginManager().registerEvents(new onEntityDamageByEntity(), this); + Bukkit.getPluginManager().registerEvents(new onEntityShoot(), this); nameTagManager = new NameTagManager(this); rankManager = new RankManager(this); sideBarManager = new SideBarManager(this); belowNameManager = new BelowNameManager(); customItemManager = new CustomItemManager(this); - customItemManager.register(); + CustomItemManager.register(); EnchantmentHandler.register(); } diff --git a/src/main/java/com/night/nullvalkyrie/commands/MessageCommand.java b/src/main/java/com/night/nullvalkyrie/commands/MessageCommand.java index a9a395c..16265fc 100644 --- a/src/main/java/com/night/nullvalkyrie/commands/MessageCommand.java +++ b/src/main/java/com/night/nullvalkyrie/commands/MessageCommand.java @@ -7,7 +7,6 @@ import org.bukkit.entity.Player; import org.bukkit.util.StringUtil; import java.util.ArrayList; -import java.util.Arrays; import java.util.List; public class MessageCommand extends Command { diff --git a/src/main/java/com/night/nullvalkyrie/commands/WeaponCommand.java b/src/main/java/com/night/nullvalkyrie/commands/WeaponCommand.java index 3f6f867..02625f8 100644 --- a/src/main/java/com/night/nullvalkyrie/commands/WeaponCommand.java +++ b/src/main/java/com/night/nullvalkyrie/commands/WeaponCommand.java @@ -1,15 +1,8 @@ package com.night.nullvalkyrie.commands; -import com.night.nullvalkyrie.Enchantments.EnchantmentHandler; import com.night.nullvalkyrie.Items.CustomItemManager; -import org.bukkit.Bukkit; -import org.bukkit.ChatColor; -import org.bukkit.Material; import org.bukkit.command.CommandSender; -import org.bukkit.enchantments.Enchantment; import org.bukkit.entity.Player; -import org.bukkit.inventory.ItemStack; -import org.bukkit.inventory.meta.ItemMeta; import org.bukkit.util.StringUtil; import java.util.ArrayList; @@ -31,36 +24,25 @@ public class WeaponCommand extends Command { @Override public void onCommand(CommandSender sender, String[] args) { - String name = String.join(" ", args); + List ar = new ArrayList<>(); + ar.addAll(Arrays.asList(args)); + String name = String.join(" ", ar.remove(0)); Player player = (Player) sender; if(name.equalsIgnoreCase("Snow Gun")) { - ItemStack hoe = new ItemStack(Material.DIAMOND_HOE); - hoe.addUnsafeEnchantment(EnchantmentHandler.ThunderBolt, 5); - hoe.addUnsafeEnchantment(Enchantment.DAMAGE_ALL, 20); - ItemMeta hoedata = hoe.getItemMeta(); - hoedata.setDisplayName(net.md_5.bungee.api.ChatColor.of("#ff23ff") + "SnowGun"); - hoedata.setUnbreakable(true); - hoedata.setLore(Arrays.asList(ChatColor.GOLD + "Shoot Snowball!")); - hoe.setItemMeta(hoedata); - - player.getInventory().addItem(hoe); + player.getInventory().addItem(CustomItemManager.SnowGun); } else if(name.equalsIgnoreCase("Grenade")) { - ItemStack egg = new ItemStack(Material.EGG); - ItemMeta eggdata = egg.getItemMeta(); - eggdata.setDisplayName(net.md_5.bungee.api.ChatColor.of("#ff23ff") + "Frag Grenade"); - eggdata.setUnbreakable(true); - eggdata.setLore(Arrays.asList(ChatColor.GOLD + "Boom")); - egg.setItemMeta(eggdata); - player.getInventory().addItem(egg); + player.getInventory().addItem(CustomItemManager.Grenade); } else if(name.equalsIgnoreCase("Widow Sword")) { player.getInventory().addItem(CustomItemManager.WidowSword); + } else if(name.equalsIgnoreCase("Terminator")) { + player.getInventory().addItem(CustomItemManager.Terminator); } } @Override public List onTabComplete(CommandSender sender, String[] args) { if(args.length == 1) { - return StringUtil.copyPartialMatches(args[0], Arrays.asList("Snow Gun", "Grenade", "Widow Sword"), new ArrayList<>()); + return StringUtil.copyPartialMatches(args[0], Arrays.asList("Snow Gun", "Grenade", "Widow Sword", "Terminator"), new ArrayList<>()); } return new ArrayList<>(); }