enchantment handler on item lore
This commit is contained in:
parent
dd75ae0ddf
commit
ccf9627b79
5 changed files with 105 additions and 46 deletions
|
@ -7,11 +7,13 @@ import java.util.Arrays;
|
|||
import java.util.stream.Collectors;
|
||||
|
||||
public class EnchantmentHandler {
|
||||
public static final Enchantment ThunderBolt = new CustomEnchantment("enc_thunderbolt", "Thunderbolt", 5);
|
||||
public static final Enchantment ThunderBolt = new CustomEnchantment("thunderbolt", "ThunderBolt", 5);
|
||||
public static final Enchantment SmeltingTouch = new CustomEnchantment("smelting-touch", "Smelting Touch", 1);
|
||||
public static void register() {
|
||||
boolean registered = Arrays.stream(Enchantment.values()).collect(Collectors.toList()).contains(ThunderBolt);
|
||||
if(!registered) {
|
||||
registerEnchantment(ThunderBolt);
|
||||
registerEnchantment(SmeltingTouch);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -9,8 +9,7 @@ import org.bukkit.entity.*;
|
|||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.block.Action;
|
||||
import org.bukkit.event.entity.EntityDamageByEntityEvent;
|
||||
import org.bukkit.event.entity.EntityShootBowEvent;
|
||||
import org.bukkit.event.entity.*;
|
||||
import org.bukkit.event.player.PlayerFishEvent;
|
||||
import org.bukkit.event.player.PlayerInteractEvent;
|
||||
|
||||
|
@ -88,15 +87,24 @@ public class CustomItemEvents implements Listener {
|
|||
s.setVelocity(player.getLocation().getDirection().multiply(10));
|
||||
} else 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.setPickupStatus(Arrow.PickupStatus.DISALLOWED);
|
||||
arrow.setDamage(50);
|
||||
Arrow a1 = player.launchProjectile(Arrow.class, player.getEyeLocation().getDirection());
|
||||
a1.setVelocity(arrow.getVelocity().rotateAroundY(Math.toRadians(5)).multiply(5));
|
||||
a1.setPickupStatus(Arrow.PickupStatus.DISALLOWED);
|
||||
a1.setDamage(50);
|
||||
Arrow a2 = player.launchProjectile(Arrow.class, player.getEyeLocation().getDirection());
|
||||
a2.setVelocity(arrow.getVelocity().rotateAroundY(Math.toRadians(-5)).multiply(5));
|
||||
a2.setPickupStatus(Arrow.PickupStatus.DISALLOWED);
|
||||
a2.setDamage(50);
|
||||
e.setCancelled(true);
|
||||
} else if(name.equalsIgnoreCase(ChatColor.GOLD + "Explosive Bow")) {
|
||||
Arrow arrow = player.launchProjectile(Arrow.class, player.getEyeLocation().getDirection());
|
||||
arrow.setVelocity(arrow.getVelocity().multiply(5));
|
||||
arrow.setDamage(50);
|
||||
e.setCancelled(true);
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -110,9 +118,53 @@ public class CustomItemEvents implements Listener {
|
|||
String name = player.getInventory().getItemInMainHand().getItemMeta().getDisplayName();
|
||||
if (name.equalsIgnoreCase(net.md_5.bungee.api.ChatColor.of("#ff23ff") + "Terminator")) {
|
||||
e.setCancelled(true);
|
||||
} else if(name.equalsIgnoreCase(ChatColor.GOLD + "Explosive Bow")) {
|
||||
e.setCancelled(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@EventHandler
|
||||
public void onProjectileHit(ProjectileHitEvent e) {
|
||||
if(e.getEntity().getShooter() instanceof Player) {
|
||||
Player shooter = (Player) e.getEntity().getShooter();
|
||||
if(shooter.getInventory().getItemInMainHand().getItemMeta() != null) {
|
||||
String name = shooter.getInventory().getItemInMainHand().getItemMeta().getDisplayName();
|
||||
if(name.equalsIgnoreCase(net.md_5.bungee.api.ChatColor.of("#ff23ff") + "Frag Grenade")) {
|
||||
if(e.getHitBlock() == null) {
|
||||
Location l = e.getHitEntity().getLocation();
|
||||
e.getHitEntity().getWorld().createExplosion(l.getX(),l.getY(),l.getZ(),100,false,false);
|
||||
} else if(e.getHitEntity() == null) {
|
||||
Location l = e.getHitBlock().getLocation();
|
||||
e.getHitBlock().getWorld().createExplosion(l.getX(),l.getY(),l.getZ(),100,false,false);
|
||||
}
|
||||
} else if(name.equalsIgnoreCase(ChatColor.GOLD + "Explosive Bow")) {
|
||||
Arrow arrow = (Arrow) e.getEntity();
|
||||
Location al = arrow.getLocation();
|
||||
shooter.getWorld().createExplosion(al, 100, false, false);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@EventHandler
|
||||
public void onCreatureSpawn(CreatureSpawnEvent event) {
|
||||
if (event.getSpawnReason() == CreatureSpawnEvent.SpawnReason.EGG) {
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
@EventHandler
|
||||
public void Projectile(ProjectileLaunchEvent e) {
|
||||
if(e.getEntity().getShooter() instanceof Player) {
|
||||
Player player = (Player) e.getEntity().getShooter();
|
||||
if(player.getInventory().getItemInMainHand().getItemMeta() != null) {
|
||||
String name = player.getInventory().getItemInMainHand().getItemMeta().getDisplayName();
|
||||
if (name.equalsIgnoreCase(net.md_5.bungee.api.ChatColor.of("#ff23ff") + "Frag Grenade")) {
|
||||
Egg s = (Egg) e.getEntity();
|
||||
s.setVelocity(player.getLocation().getDirection().multiply(10));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,6 +1,5 @@
|
|||
package com.night.nullvalkyrie.Items;
|
||||
|
||||
|
||||
import com.night.nullvalkyrie.Enchantments.EnchantmentHandler;
|
||||
import com.night.nullvalkyrie.Main;
|
||||
import org.bukkit.Bukkit;
|
||||
|
@ -21,6 +20,7 @@ import java.io.File;
|
|||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
import static com.night.nullvalkyrie.Enchantments.EnchantmentHandler.ThunderBolt;
|
||||
|
@ -109,12 +109,35 @@ public class CustomItemManager {
|
|||
ItemStack widow_sword = new ItemStack(Material.STICK);
|
||||
widow_sword.addUnsafeEnchantment(Enchantment.DAMAGE_ALL, 20);
|
||||
widow_sword.addUnsafeEnchantment(Enchantment.LOOT_BONUS_MOBS, 10);
|
||||
widow_sword.addUnsafeEnchantment(Enchantment.FIRE_ASPECT,2);
|
||||
widow_sword.addUnsafeEnchantment(Enchantment.LUCK,5);
|
||||
widow_sword.addUnsafeEnchantment(ThunderBolt,5);
|
||||
ItemMeta wsMeta = widow_sword.getItemMeta();
|
||||
wsMeta.setDisplayName(net.md_5.bungee.api.ChatColor.of("#ff23ff") + "Fabled Widow Sword");
|
||||
wsMeta.setUnbreakable(true);
|
||||
ArrayList<String> lore = new ArrayList<>();
|
||||
lore.add(ChatColor.GRAY + "Damage: " + ChatColor.RED + "+100");
|
||||
lore.add("");
|
||||
ArrayList<String> enchants = new ArrayList<>();
|
||||
for (Enchantment enchant : widow_sword.getEnchantments().keySet()) {
|
||||
List<String> splitted = Arrays.asList(Arrays.asList(enchant.getKey().toString().split(":")).get(1).split("_"));
|
||||
StringBuilder name = new StringBuilder();
|
||||
for (String i : splitted) {
|
||||
String s = i.substring(0, 1).toUpperCase() + i.substring(1);
|
||||
if(splitted.size() > 1) {
|
||||
if(i.equals(splitted.get(splitted.size() - 1))) {
|
||||
name.append(s);
|
||||
} else {
|
||||
name.append(s);
|
||||
name.append(" ");
|
||||
}
|
||||
} else name.append(s);
|
||||
|
||||
}
|
||||
enchants.add(name + " " + widow_sword.getEnchantmentLevel(enchant));
|
||||
}
|
||||
lore.add(ChatColor.BLUE + String.join(", ", enchants));
|
||||
lore.add("");
|
||||
lore.add(ChatColor.GOLD + "Item Ability: Damage Multiplier");
|
||||
lore.add(ChatColor.GRAY + "Damage dealt to mobs will be multiplied");
|
||||
lore.add(ChatColor.RED + "Zombie +" + zombiedmg + "%");
|
||||
|
@ -128,7 +151,7 @@ public class CustomItemManager {
|
|||
wsMeta.addItemFlags(ItemFlag.HIDE_ATTRIBUTES, ItemFlag.HIDE_UNBREAKABLE, ItemFlag.HIDE_ENCHANTS);
|
||||
widow_sword.setItemMeta(wsMeta);
|
||||
WidowSword = widow_sword;
|
||||
ShapedRecipe wither_sword_recipe = new ShapedRecipe(new NamespacedKey(main, "widow_sword"), widow_sword);
|
||||
ShapedRecipe wither_sword_recipe = new ShapedRecipe(NamespacedKey.minecraft("widow_sword"), widow_sword);
|
||||
wither_sword_recipe.shape(" A ", " A "," B ");
|
||||
wither_sword_recipe.setIngredient('A', Material.IRON_INGOT);
|
||||
wither_sword_recipe.setIngredient('B', Material.STICK);
|
||||
|
@ -143,6 +166,7 @@ public class CustomItemManager {
|
|||
terminatorMeta.setDisplayName(net.md_5.bungee.api.ChatColor.of("#ff23ff") + "Terminator");
|
||||
terminatorMeta.setUnbreakable(true);
|
||||
ArrayList<String> lore = new ArrayList<>();
|
||||
lore.add(ChatColor.GRAY + "Damage: " + ChatColor.RED + "+50");
|
||||
lore.add("");
|
||||
lore.add(ChatColor.GOLD + "Item Ability: Triple Shot");
|
||||
lore.add(ChatColor.GRAY + "Shoot three arrow at one time");
|
||||
|
@ -187,7 +211,23 @@ public class CustomItemManager {
|
|||
SnowGun = hoe;
|
||||
}
|
||||
private static void setExplosiveBow() {
|
||||
|
||||
ItemStack i = new ItemStack(Material.BOW);
|
||||
i.addUnsafeEnchantment(Enchantment.DAMAGE_ALL, 20);
|
||||
i.addUnsafeEnchantment(Enchantment.LOOT_BONUS_MOBS, 10);
|
||||
i.addUnsafeEnchantment(ThunderBolt,5);
|
||||
ItemMeta im = i.getItemMeta();
|
||||
im.setDisplayName(ChatColor.GOLD + "Explosive Bow");
|
||||
im.setUnbreakable(true);
|
||||
ArrayList<String> lore = new ArrayList<>();
|
||||
lore.add("");
|
||||
lore.add(ChatColor.GOLD + "Item Ability: Explosive Shot");
|
||||
lore.add(ChatColor.GRAY + "Shoot explosive arrows");
|
||||
lore.add("");
|
||||
lore.add(ChatColor.GOLD.toString() + ChatColor.BOLD + "LEGENDARY");
|
||||
im.setLore(lore);
|
||||
im.addItemFlags(ItemFlag.HIDE_ATTRIBUTES, ItemFlag.HIDE_UNBREAKABLE, ItemFlag.HIDE_ENCHANTS);
|
||||
i.setItemMeta(im);
|
||||
ExplosiveBow = i;
|
||||
}
|
||||
private static void setAOTV() {
|
||||
ItemStack i = new ItemStack(Material.DIAMOND_SWORD, 1);
|
||||
|
|
|
@ -55,19 +55,7 @@ public final class Main extends JavaPlugin implements Listener {
|
|||
CustomItemManager.register();
|
||||
EnchantmentHandler.register();
|
||||
}
|
||||
@EventHandler
|
||||
public void Projectile(ProjectileLaunchEvent e) {
|
||||
if(e.getEntity().getShooter() instanceof Player) {
|
||||
Player player = (Player) e.getEntity().getShooter();
|
||||
if(player.getInventory().getItemInMainHand().getItemMeta() != null) {
|
||||
String name = player.getInventory().getItemInMainHand().getItemMeta().getDisplayName();
|
||||
if (name.equalsIgnoreCase(net.md_5.bungee.api.ChatColor.of("#ff23ff") + "Frag Grenade")) {
|
||||
Egg s = (Egg) e.getEntity();
|
||||
s.setVelocity(player.getLocation().getDirection().multiply(10));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@EventHandler
|
||||
public void onJoin(PlayerJoinEvent e) {
|
||||
|
@ -92,31 +80,6 @@ public final class Main extends JavaPlugin implements Listener {
|
|||
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onProjectileHit(ProjectileHitEvent e) {
|
||||
if(e.getEntity().getShooter() instanceof Player) {
|
||||
Player shooter = (Player) e.getEntity().getShooter();
|
||||
if(shooter.getInventory().getItemInMainHand().getItemMeta() != null) {
|
||||
String name = shooter.getInventory().getItemInMainHand().getItemMeta().getDisplayName();
|
||||
if(name.equalsIgnoreCase(net.md_5.bungee.api.ChatColor.of("#ff23ff") + "Frag Grenade")) {
|
||||
if(e.getHitBlock() == null) {
|
||||
Location l = e.getHitEntity().getLocation();
|
||||
e.getHitEntity().getWorld().createExplosion(l.getX(),l.getY(),l.getZ(),100,false,false);
|
||||
} else if(e.getHitEntity() == null) {
|
||||
Location l = e.getHitBlock().getLocation();
|
||||
e.getHitBlock().getWorld().createExplosion(l.getX(),l.getY(),l.getZ(),100,false,false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@EventHandler
|
||||
public void onCreatureSpawn(CreatureSpawnEvent event) {
|
||||
if (event.getSpawnReason() == CreatureSpawnEvent.SpawnReason.EGG) {
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
|
||||
// For hologram clicks to change page
|
||||
// @EventHandler
|
||||
|
|
|
@ -24,7 +24,9 @@ public class WeaponCommand extends Command {
|
|||
|
||||
@Override
|
||||
public void onCommand(CommandSender sender, String[] args) {
|
||||
String name = String.join(" ", args);
|
||||
List<String> arg = Arrays.asList(args);
|
||||
//arg.remove(0); //in case buggy bukkit make it bug again
|
||||
String name = String.join(" ", arg);
|
||||
Player player = (Player) sender;
|
||||
if(name.equalsIgnoreCase("Snow Gun")) {
|
||||
player.getInventory().addItem(CustomItemManager.SnowGun);
|
||||
|
|
Loading…
Reference in a new issue