enchantment handler on item lore

This commit is contained in:
night0721 2022-07-12 07:53:13 +01:00
parent dd75ae0ddf
commit ccf9627b79
5 changed files with 105 additions and 46 deletions

View file

@ -7,11 +7,13 @@ import java.util.Arrays;
import java.util.stream.Collectors; import java.util.stream.Collectors;
public class EnchantmentHandler { 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() { public static void register() {
boolean registered = Arrays.stream(Enchantment.values()).collect(Collectors.toList()).contains(ThunderBolt); boolean registered = Arrays.stream(Enchantment.values()).collect(Collectors.toList()).contains(ThunderBolt);
if(!registered) { if(!registered) {
registerEnchantment(ThunderBolt); registerEnchantment(ThunderBolt);
registerEnchantment(SmeltingTouch);
} }
} }

View file

@ -9,8 +9,7 @@ import org.bukkit.entity.*;
import org.bukkit.event.EventHandler; import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener; import org.bukkit.event.Listener;
import org.bukkit.event.block.Action; import org.bukkit.event.block.Action;
import org.bukkit.event.entity.EntityDamageByEntityEvent; import org.bukkit.event.entity.*;
import org.bukkit.event.entity.EntityShootBowEvent;
import org.bukkit.event.player.PlayerFishEvent; import org.bukkit.event.player.PlayerFishEvent;
import org.bukkit.event.player.PlayerInteractEvent; import org.bukkit.event.player.PlayerInteractEvent;
@ -88,15 +87,24 @@ public class CustomItemEvents implements Listener {
s.setVelocity(player.getLocation().getDirection().multiply(10)); s.setVelocity(player.getLocation().getDirection().multiply(10));
} else if (name.equalsIgnoreCase(net.md_5.bungee.api.ChatColor.of("#ff23ff") + "Terminator")) { } else if (name.equalsIgnoreCase(net.md_5.bungee.api.ChatColor.of("#ff23ff") + "Terminator")) {
Arrow arrow = player.launchProjectile(Arrow.class, player.getEyeLocation().getDirection()); Arrow arrow = player.launchProjectile(Arrow.class, player.getEyeLocation().getDirection());
arrow.setPickupStatus(Arrow.PickupStatus.DISALLOWED);
arrow.setVelocity(arrow.getVelocity().multiply(5)); arrow.setVelocity(arrow.getVelocity().multiply(5));
arrow.setPickupStatus(Arrow.PickupStatus.DISALLOWED);
arrow.setDamage(50);
Arrow a1 = player.launchProjectile(Arrow.class, player.getEyeLocation().getDirection()); Arrow a1 = player.launchProjectile(Arrow.class, player.getEyeLocation().getDirection());
a1.setVelocity(arrow.getVelocity().rotateAroundY(Math.toRadians(5)).multiply(5)); a1.setVelocity(arrow.getVelocity().rotateAroundY(Math.toRadians(5)).multiply(5));
a1.setPickupStatus(Arrow.PickupStatus.DISALLOWED); a1.setPickupStatus(Arrow.PickupStatus.DISALLOWED);
a1.setDamage(50);
Arrow a2 = player.launchProjectile(Arrow.class, player.getEyeLocation().getDirection()); Arrow a2 = player.launchProjectile(Arrow.class, player.getEyeLocation().getDirection());
a2.setVelocity(arrow.getVelocity().rotateAroundY(Math.toRadians(-5)).multiply(5)); a2.setVelocity(arrow.getVelocity().rotateAroundY(Math.toRadians(-5)).multiply(5));
a2.setPickupStatus(Arrow.PickupStatus.DISALLOWED); a2.setPickupStatus(Arrow.PickupStatus.DISALLOWED);
a2.setDamage(50);
e.setCancelled(true); 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(); String name = player.getInventory().getItemInMainHand().getItemMeta().getDisplayName();
if (name.equalsIgnoreCase(net.md_5.bungee.api.ChatColor.of("#ff23ff") + "Terminator")) { if (name.equalsIgnoreCase(net.md_5.bungee.api.ChatColor.of("#ff23ff") + "Terminator")) {
e.setCancelled(true); 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));
}
}
}
}
} }

View file

@ -1,6 +1,5 @@
package com.night.nullvalkyrie.Items; package com.night.nullvalkyrie.Items;
import com.night.nullvalkyrie.Enchantments.EnchantmentHandler; import com.night.nullvalkyrie.Enchantments.EnchantmentHandler;
import com.night.nullvalkyrie.Main; import com.night.nullvalkyrie.Main;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
@ -21,6 +20,7 @@ import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.List;
import java.util.UUID; import java.util.UUID;
import static com.night.nullvalkyrie.Enchantments.EnchantmentHandler.ThunderBolt; import static com.night.nullvalkyrie.Enchantments.EnchantmentHandler.ThunderBolt;
@ -109,12 +109,35 @@ public class CustomItemManager {
ItemStack widow_sword = new ItemStack(Material.STICK); ItemStack widow_sword = new ItemStack(Material.STICK);
widow_sword.addUnsafeEnchantment(Enchantment.DAMAGE_ALL, 20); widow_sword.addUnsafeEnchantment(Enchantment.DAMAGE_ALL, 20);
widow_sword.addUnsafeEnchantment(Enchantment.LOOT_BONUS_MOBS, 10); 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(); ItemMeta wsMeta = widow_sword.getItemMeta();
wsMeta.setDisplayName(net.md_5.bungee.api.ChatColor.of("#ff23ff") + "Fabled Widow Sword"); wsMeta.setDisplayName(net.md_5.bungee.api.ChatColor.of("#ff23ff") + "Fabled Widow Sword");
wsMeta.setUnbreakable(true); wsMeta.setUnbreakable(true);
ArrayList<String> lore = new ArrayList<>(); ArrayList<String> lore = new ArrayList<>();
lore.add(ChatColor.GRAY + "Damage: " + ChatColor.RED + "+100"); lore.add(ChatColor.GRAY + "Damage: " + ChatColor.RED + "+100");
lore.add(""); 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.GOLD + "Item Ability: Damage Multiplier");
lore.add(ChatColor.GRAY + "Damage dealt to mobs will be multiplied"); lore.add(ChatColor.GRAY + "Damage dealt to mobs will be multiplied");
lore.add(ChatColor.RED + "Zombie +" + zombiedmg + "%"); lore.add(ChatColor.RED + "Zombie +" + zombiedmg + "%");
@ -128,7 +151,7 @@ public class CustomItemManager {
wsMeta.addItemFlags(ItemFlag.HIDE_ATTRIBUTES, ItemFlag.HIDE_UNBREAKABLE, ItemFlag.HIDE_ENCHANTS); wsMeta.addItemFlags(ItemFlag.HIDE_ATTRIBUTES, ItemFlag.HIDE_UNBREAKABLE, ItemFlag.HIDE_ENCHANTS);
widow_sword.setItemMeta(wsMeta); widow_sword.setItemMeta(wsMeta);
WidowSword = widow_sword; 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.shape(" A ", " A "," B ");
wither_sword_recipe.setIngredient('A', Material.IRON_INGOT); wither_sword_recipe.setIngredient('A', Material.IRON_INGOT);
wither_sword_recipe.setIngredient('B', Material.STICK); 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.setDisplayName(net.md_5.bungee.api.ChatColor.of("#ff23ff") + "Terminator");
terminatorMeta.setUnbreakable(true); terminatorMeta.setUnbreakable(true);
ArrayList<String> lore = new ArrayList<>(); ArrayList<String> lore = new ArrayList<>();
lore.add(ChatColor.GRAY + "Damage: " + ChatColor.RED + "+50");
lore.add(""); lore.add("");
lore.add(ChatColor.GOLD + "Item Ability: Triple Shot"); lore.add(ChatColor.GOLD + "Item Ability: Triple Shot");
lore.add(ChatColor.GRAY + "Shoot three arrow at one time"); lore.add(ChatColor.GRAY + "Shoot three arrow at one time");
@ -187,7 +211,23 @@ public class CustomItemManager {
SnowGun = hoe; SnowGun = hoe;
} }
private static void setExplosiveBow() { 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() { private static void setAOTV() {
ItemStack i = new ItemStack(Material.DIAMOND_SWORD, 1); ItemStack i = new ItemStack(Material.DIAMOND_SWORD, 1);

View file

@ -55,19 +55,7 @@ public final class Main extends JavaPlugin implements Listener {
CustomItemManager.register(); CustomItemManager.register();
EnchantmentHandler.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 @EventHandler
public void onJoin(PlayerJoinEvent e) { 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 // For hologram clicks to change page
// @EventHandler // @EventHandler

View file

@ -24,7 +24,9 @@ public class WeaponCommand extends Command {
@Override @Override
public void onCommand(CommandSender sender, String[] args) { 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; Player player = (Player) sender;
if(name.equalsIgnoreCase("Snow Gun")) { if(name.equalsIgnoreCase("Snow Gun")) {
player.getInventory().addItem(CustomItemManager.SnowGun); player.getInventory().addItem(CustomItemManager.SnowGun);