added custom item handler, when u add a yml file to ItemData folder it will automatically register for you

This commit is contained in:
night0721 2022-07-12 21:33:28 +01:00
parent 235fbcc0ce
commit ecc4990117
8 changed files with 232 additions and 354 deletions

View file

@ -7,6 +7,9 @@ import java.util.Arrays;
import java.util.stream.Collectors;
public class EnchantmentManager {
public EnchantmentManager() {
register();
}
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() {
@ -18,7 +21,6 @@ public class EnchantmentManager {
}
public static void registerEnchantment(Enchantment en) {
boolean registered = true;
try {
try {
Field f = Enchantment.class.getDeclaredField("acceptingNew");
@ -29,12 +31,8 @@ public class EnchantmentManager {
}
Enchantment.registerEnchantment(en);
} catch (Exception e) {
registered = false;
e.printStackTrace();
}
if (registered) {
}
}
}

View file

@ -1,5 +1,6 @@
package com.night.nullvalkyrie.Events;
import com.night.nullvalkyrie.Items.Rarity;
import org.bukkit.ChatColor;
import org.bukkit.Location;
import org.bukkit.Material;
@ -15,7 +16,7 @@ import org.bukkit.event.player.PlayerInteractEvent;
import java.util.Set;
import static com.night.nullvalkyrie.Items.CustomItem.loadConfig;
import static com.night.nullvalkyrie.Items.CustomItemManager.loadConfig;
public class CustomItemEvents implements Listener {
@EventHandler
@ -25,7 +26,7 @@ public class CustomItemEvents implements Listener {
Player pl = (Player) sb.getShooter();
if (pl.getInventory().getItemInMainHand().getItemMeta() != null) {
String name = pl.getInventory().getItemInMainHand().getItemMeta().getDisplayName();
if (name.equalsIgnoreCase(net.md_5.bungee.api.ChatColor.of("#ff23ff") + "SnowGun")) {
if (name.equalsIgnoreCase(Rarity.ULTRA.getColor() + "Snow Gun")) {
e.setDamage(10000);
} else if (name.equalsIgnoreCase("AA-12")) {
e.setDamage(7);
@ -37,7 +38,7 @@ public class CustomItemEvents implements Listener {
Player player = (Player) e.getDamager();
if (player.getInventory().getItemInMainHand().getItemMeta() != null) {
String name = player.getInventory().getItemInMainHand().getItemMeta().getDisplayName();
if(name.equalsIgnoreCase(net.md_5.bungee.api.ChatColor.of("#ff23ff") + "Fabled Widow Sword")) {
if(name.equalsIgnoreCase(Rarity.MYTHIC.getColor() + "Fabled Widow Sword")) {
if (e.getEntity() instanceof Zombie) {
int zombie = loadConfig("ItemData\\WidowSword.yml").getInt("zombie");
e.setDamage(e.getDamage() * (1 + zombie / 100));
@ -58,7 +59,7 @@ public class CustomItemEvents implements Listener {
Player player = e.getPlayer();
if (player.getInventory().getItemInMainHand().getItemMeta() != null) {
String name = player.getInventory().getItemInMainHand().getItemMeta().getDisplayName();
if (name.equalsIgnoreCase(ChatColor.WHITE + "Grappling Hook")) {
if (name.equalsIgnoreCase(Rarity.RARE.getColor() + "Grappling Hook")) {
if(e.getState().equals(PlayerFishEvent.State.REEL_IN)) {
Location change = e.getHook().getLocation().subtract(player.getLocation());
player.setVelocity(change.toVector().multiply(0.4));
@ -72,7 +73,7 @@ public class CustomItemEvents implements Listener {
if (player.getInventory().getItemInMainHand().getItemMeta() != null) {
String name = player.getInventory().getItemInMainHand().getItemMeta().getDisplayName();
if (e.getAction().equals(Action.RIGHT_CLICK_AIR) || e.getAction().equals(Action.RIGHT_CLICK_BLOCK)) {
if (name.equalsIgnoreCase(ChatColor.DARK_PURPLE + "Aspect of The Void")) {
if (name.equalsIgnoreCase(Rarity.GRAND.getColor() + "Teleport Door")) {
Block block = player.getTargetBlock((Set<Material>) null, 12);
Location l = block.getLocation();
l.add(0, 1, 0);
@ -82,10 +83,10 @@ public class CustomItemEvents implements Listener {
l.setPitch(pitch);
player.teleport(l);
player.playSound(player.getLocation(), Sound.ENTITY_ENDERMAN_TELEPORT, 10, 10);
} else if (name.equalsIgnoreCase(net.md_5.bungee.api.ChatColor.of("#ff23ff") + "SnowGun")) {
} else if (name.equalsIgnoreCase(Rarity.ULTRA.getColor() + "Snow Gun")) {
Snowball s = player.launchProjectile(Snowball.class, player.getLocation().getDirection());
s.setVelocity(player.getLocation().getDirection().multiply(10));
} else if (name.equalsIgnoreCase(net.md_5.bungee.api.ChatColor.of("#ff23ff") + "Terminator")) {
} else if (name.equalsIgnoreCase(Rarity.MYTHIC.getColor() + "Terminator")) {
Arrow arrow = player.launchProjectile(Arrow.class, player.getEyeLocation().getDirection());
arrow.setVelocity(arrow.getVelocity().multiply(5));
arrow.setPickupStatus(Arrow.PickupStatus.DISALLOWED);
@ -99,7 +100,7 @@ public class CustomItemEvents implements Listener {
a2.setPickupStatus(Arrow.PickupStatus.DISALLOWED);
a2.setDamage(50);
e.setCancelled(true);
} else if(name.equalsIgnoreCase(ChatColor.GOLD + "Explosive Bow")) {
} else if(name.equalsIgnoreCase(Rarity.LEGENDARY.getColor() + "Explosive Bow")) {
Arrow arrow = player.launchProjectile(Arrow.class, player.getEyeLocation().getDirection());
arrow.setVelocity(arrow.getVelocity().multiply(5));
arrow.setDamage(50);
@ -116,9 +117,9 @@ public class CustomItemEvents implements Listener {
Player player = (Player) e.getEntity();
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")) {
if (name.equalsIgnoreCase(Rarity.MYTHIC.getColor() + "Terminator")) {
e.setCancelled(true);
} else if(name.equalsIgnoreCase(ChatColor.GOLD + "Explosive Bow")) {
} else if(name.equalsIgnoreCase(Rarity.LEGENDARY.getColor() + "Explosive Bow")) {
e.setCancelled(true);
}
}
@ -131,7 +132,7 @@ public class CustomItemEvents implements Listener {
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(name.equalsIgnoreCase(Rarity.LEGENDARY.getColor() + "Frag Grenade")) {
if(e.getHitBlock() == null) {
Location l = e.getHitEntity().getLocation();
e.getHitEntity().getWorld().createExplosion(l.getX(),l.getY(),l.getZ(),100,false,false);
@ -139,7 +140,7 @@ public class CustomItemEvents implements Listener {
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")) {
} else if(name.equalsIgnoreCase(Rarity.LEGENDARY.getColor() + "Explosive Bow")) {
Arrow arrow = (Arrow) e.getEntity();
Location al = arrow.getLocation();
shooter.getWorld().createExplosion(al, 100, false, false);
@ -160,7 +161,7 @@ public class CustomItemEvents implements Listener {
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")) {
if (name.equalsIgnoreCase(Rarity.LEGENDARY.getColor() + "Frag Grenade")) {
Egg s = (Egg) e.getEntity();
s.setVelocity(player.getLocation().getDirection().multiply(10));
}

View file

@ -1,260 +0,0 @@
package com.night.nullvalkyrie.Items;
import com.night.nullvalkyrie.Enchantments.EnchantmentManager;
import com.night.nullvalkyrie.Main;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.Material;
import org.bukkit.NamespacedKey;
import org.bukkit.attribute.Attribute;
import org.bukkit.attribute.AttributeModifier;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.enchantments.Enchantment;
import org.bukkit.inventory.EquipmentSlot;
import org.bukkit.inventory.ItemFlag;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.ShapedRecipe;
import org.bukkit.inventory.meta.ItemMeta;
import java.io.File;
import java.io.IOException;
import java.util.*;
import static com.night.nullvalkyrie.Enchantments.EnchantmentManager.ThunderBolt;
public class CustomItem {
private static Main main;
public CustomItem(Main main) {
this.main = main;
if(!main.getDataFolder().exists()) {
main.getDataFolder().mkdir();
}
}
public static ItemStack WidowSword;
public static ItemStack Terminator;
public static ItemStack Grenade;
public static ItemStack SnowGun;
public static ItemStack ExplosiveBow;
public static ItemStack AOTV;
public static ItemStack GrapplingHook;
public static void register() {
createItemDataDirectory("ItemData");
setWidowSword();
setTerminator();
setGrenade();
setSnowGun();
setExplosiveBow();
setAOTV();
setGrapplingHook();
}
public static YamlConfiguration loadConfig(String path) {
File f = new File(main.getDataFolder(), path);
if(!f.exists()) {
try {
f.createNewFile();
} catch (IOException e) {
e.printStackTrace();
}
}
return YamlConfiguration.loadConfiguration(f);
}
public static File loadFile(String path) {
File f = new File(main.getDataFolder(), path);
if(!f.exists()) {
try {
f.createNewFile();
} catch (IOException e) {
e.printStackTrace();
}
}
return f;
}
private static void createItemDataDirectory(String path) {
File f = new File(main.getDataFolder(), path);
if(!f.exists()) {
try {
if(!f.mkdir()) {
try {
f.mkdir();
} catch (SecurityException e) {
e.printStackTrace();
}
}
} catch (SecurityException e) {
e.printStackTrace();
}
}
}
private static void setWidowSword() {
YamlConfiguration config = loadConfig("ItemData\\WidowSword.yml");
config.set("zombie", 100);
config.set("skeleton", 100);
config.set("spider", 100);
try {
config.save(loadFile("ItemData\\WidowSword.yml"));
} catch (IOException e) {
e.printStackTrace();
}
int skeletondmg = config.getInt("skeleton");
int zombiedmg = config.getInt("zombie");
int spiderdmg = config.getInt("spider");
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 + "%");
lore.add(ChatColor.RED + "Skeleton +" + skeletondmg + "%");
lore.add(ChatColor.RED + "Spider +" + spiderdmg + "%");
lore.add("");
lore.add(net.md_5.bungee.api.ChatColor.of("#ff23ff").toString() + ChatColor.BOLD + "MYTHIC");
wsMeta.setLore(lore);
AttributeModifier dmg = new AttributeModifier(UUID.randomUUID(), "generic.attackDamage", 100, AttributeModifier.Operation.ADD_NUMBER, EquipmentSlot.HAND);
wsMeta.addAttributeModifier(Attribute.GENERIC_ATTACK_DAMAGE, dmg);
wsMeta.addItemFlags(ItemFlag.HIDE_ATTRIBUTES, ItemFlag.HIDE_UNBREAKABLE, ItemFlag.HIDE_ENCHANTS);
widow_sword.setItemMeta(wsMeta);
WidowSword = 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);
Bukkit.addRecipe(wither_sword_recipe);
}
private static void setTerminator() {
HashMap<String, List<String>> d = new HashMap<>();
List<String> pr = new ArrayList<>();
pr.add(ChatColor.GRAY + "Damage: " + ChatColor.RED + "+50");
d.put("properties", pr);
List<String> ia = new ArrayList<>();
ia.add(ChatColor.GOLD + "Item Ability: Triple Shot");
ia.add(ChatColor.GRAY + "Shoot three arrow at one time");
d.put("ability", ia);
HashMap<Enchantment, Integer> e = new HashMap<>();
e.put(Enchantment.DAMAGE_ALL, 20);
e.put(Enchantment.LOOT_BONUS_MOBS, 10);
e.put(ThunderBolt,5);
Terminator = main.getCustomItemManager().register(Material.BOW, "Terminator",Rarity.MYTHIC, d, e,50.0,0.05);
}
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);
ArrayList<String> lore = new ArrayList<>();
lore.add(ChatColor.GOLD + "Item Ability: Throw a TNT ");
lore.add(ChatColor.GRAY + "Shoot TNT with 25x more power!");
lore.add("");
lore.add(net.md_5.bungee.api.ChatColor.of("#ff23ff").toString() + ChatColor.BOLD + "MYTHIC");
eggdata.setLore(lore);
eggdata.addItemFlags(ItemFlag.HIDE_ATTRIBUTES, ItemFlag.HIDE_UNBREAKABLE, ItemFlag.HIDE_ENCHANTS);
egg.setItemMeta(eggdata);
Grenade = egg;
}
private static void setSnowGun() {
ItemStack hoe = new ItemStack(Material.DIAMOND_HOE);
hoe.addUnsafeEnchantment(EnchantmentManager.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);
ArrayList<String> lore = new ArrayList<>();
lore.add(ChatColor.GOLD + "Item Ability: Shoot Snowball");
lore.add(ChatColor.GRAY + "Shoot snowball!");
lore.add("");
lore.add(net.md_5.bungee.api.ChatColor.of("#ff23ff").toString() + ChatColor.BOLD + "MYTHIC");
hoedata.setLore(lore);
hoedata.addItemFlags(ItemFlag.HIDE_ATTRIBUTES, ItemFlag.HIDE_UNBREAKABLE, ItemFlag.HIDE_ENCHANTS);
hoe.setItemMeta(hoedata);
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);
ItemMeta im = i.getItemMeta();
im.setDisplayName(ChatColor.DARK_PURPLE + "Aspect of The Void");
ArrayList<String> lore = new ArrayList<>();
lore.add(ChatColor.GRAY + "Damage: " + ChatColor.RED + "+100");
lore.add("");
lore.add(ChatColor.GOLD + "Item Ability: Instant Teleport");
lore.add(ChatColor.GRAY + "Teleport 12 blocks ahead");
lore.add("");
lore.add(ChatColor.DARK_PURPLE.toString() + ChatColor.BOLD + "EPIC");
im.setLore(lore);
im.setUnbreakable(true);
AttributeModifier dmg = new AttributeModifier(UUID.randomUUID(), "generic.attackDamage", 25, AttributeModifier.Operation.ADD_NUMBER, EquipmentSlot.HAND);
AttributeModifier speed = new AttributeModifier(UUID.randomUUID(), "generic.movementSpeed", 0.2, AttributeModifier.Operation.ADD_NUMBER, EquipmentSlot.HAND);
im.addAttributeModifier(Attribute.GENERIC_ATTACK_DAMAGE, dmg);
im.addAttributeModifier(Attribute.GENERIC_MOVEMENT_SPEED, speed);
im.addItemFlags(ItemFlag.HIDE_ATTRIBUTES, ItemFlag.HIDE_UNBREAKABLE, ItemFlag.HIDE_ENCHANTS);
i.setItemMeta(im);
AOTV = i;
}
private static void setGrapplingHook() {
ItemStack i = new ItemStack(Material.FISHING_ROD, 1);
ItemMeta im = i.getItemMeta();
im.setDisplayName(ChatColor.WHITE + "Grappling Hook");
ArrayList<String> lore = new ArrayList<>();
lore.add(ChatColor.GRAY + "I believe I can fly...");
lore.add("");
lore.add(ChatColor.WHITE.toString() + ChatColor.BOLD + "COMMON");
im.setLore(lore);
im.setUnbreakable(true);
im.addItemFlags(ItemFlag.HIDE_ATTRIBUTES, ItemFlag.HIDE_UNBREAKABLE, ItemFlag.HIDE_ENCHANTS);
i.setItemMeta(im);
GrapplingHook = i;
}
}

View file

@ -1,30 +1,81 @@
package com.night.nullvalkyrie.Items;
import com.night.nullvalkyrie.Main;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.Material;
import org.bukkit.NamespacedKey;
import org.bukkit.attribute.Attribute;
import org.bukkit.attribute.AttributeModifier;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.enchantments.Enchantment;
import org.bukkit.inventory.EquipmentSlot;
import org.bukkit.inventory.ItemFlag;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.ShapedRecipe;
import org.bukkit.inventory.meta.ItemMeta;
import java.io.File;
import java.io.IOException;
import java.util.*;
public class CustomItemManager {
public ItemStack register(Material item, String name, Rarity rarity, HashMap<String, List<String>> lore, HashMap<Enchantment, Integer> enchantment, double damage, double movespeed) {
ItemStack i = new ItemStack(item);
for(Enchantment e : enchantment.keySet()) {
i.addUnsafeEnchantment(e, enchantment.get(e));
private static HashMap<String, ItemStack> a = new HashMap<>();
private static Main main;
public CustomItemManager(Main main) {
this.main = main;
if(!main.getDataFolder().exists()) {
main.getDataFolder().mkdir();
}
createItemDataDirectory("ItemData");
register();
}
public void register() {
List<String> hh = getAllFilesFromDirectory("ItemData");
for(int kk = 0; kk < hh.size(); kk++) {
FileConfiguration c = loadConfig("ItemData\\" + hh.get(kk));
ItemStack i = new ItemStack(Material.matchMaterial(c.getString("material")));
HashMap<String, List<String>> d = new HashMap<>();
List<String> pr = new ArrayList<>();
List<String> ia = new ArrayList<>();
HashMap<String, Double> aa = new HashMap<>();
for (String key : c.getKeys(true)) {
if (key.startsWith("enchants.")) {
i.addUnsafeEnchantment(Enchantment.getByKey(NamespacedKey.minecraft(Arrays.asList(key.split("\\.")).get(1))), c.getInt(key));
} else if (key.startsWith("lore.properties.")) {
String property = Arrays.asList(key.split("\\.")).get(2);
if (property.equals("damage") && c.getInt(key) > 0) {
pr.add(ChatColor.GRAY + "Damage: " + ChatColor.RED + "+" + c.getInt(key));
} else if (property.equals("damage") && c.getInt(key) > 0) {
pr.add(ChatColor.GRAY + "Speed: " + ChatColor.RED + "+" + c.getInt(key));
}
} else if (key.startsWith("lore.ability.")) {
String a = Arrays.asList(key.split("\\.")).get(2);
if (a.equals("name")) {
ia.add(ChatColor.GOLD + "Item Ability: " + c.getString(key));
} else if (a.equals("details")) {
for (Object line : c.getList(key)) {
ia.add(ChatColor.GRAY.toString() + line);
}
}
} else if (key.startsWith("attributes.")) {
if (c.getDouble(key) > 0.0) {
aa.put(Arrays.asList(key.split("\\.")).get(1), c.getDouble(key));
}
} else if (key.startsWith("recipe.")) {
}
}
d.put("properties", pr);
d.put("ability", ia);
d.put("attributes", pr);
ItemMeta im = i.getItemMeta();
im.setDisplayName(rarity.getColor() + name);
im.setDisplayName(Rarity.getRarity(c.getString("rarity")).getColor() + c.getString("name"));
im.setUnbreakable(true);
ArrayList<String> l = new ArrayList<>();
for(String ll : lore.get("properties")) {
l.add(ll);
}
l.addAll(d.get("properties"));
l.add("");
ArrayList<String> e = new ArrayList<>();
for (Enchantment ee : i.getEnchantments().keySet()) {
@ -32,33 +83,99 @@ public class CustomItemManager {
StringBuilder n = new StringBuilder();
for (String ii : splitted) {
String s = ii.substring(0, 1).toUpperCase() + ii.substring(1);
if(splitted.size() > 1) {
if(ii.equals(splitted.get(splitted.size() - 1))) {
if (splitted.size() > 1) {
if (ii.equals(splitted.get(splitted.size() - 1))) {
n.append(s);
} else {
n.append(s);
n.append(" ");
}
} else n.append(s);
}
e.add(n + " " + i.getEnchantmentLevel(ee));
}
l.add(ChatColor.BLUE + String.join(", ", e));
l.add("");
for(String ll : lore.get("ability")) {
l.add(ll);
}
l.addAll(ia);
l.add("");
l.add(rarity.getDisplay());
l.add(Rarity.getRarity(c.getString("rarity")).getDisplay());
im.setLore(l);
AttributeModifier d = new AttributeModifier(UUID.randomUUID(), "generic.attackDamage", damage, AttributeModifier.Operation.ADD_NUMBER, EquipmentSlot.HAND);
im.addAttributeModifier(Attribute.GENERIC_ATTACK_DAMAGE, d);
AttributeModifier s = new AttributeModifier(UUID.randomUUID(), "generic.movementSpeed", movespeed, AttributeModifier.Operation.ADD_NUMBER, EquipmentSlot.HAND);
for (String q : aa.keySet()) {
if (q.equals("damage")) {
AttributeModifier p = new AttributeModifier(UUID.randomUUID(), "generic.attackDamage", aa.get(q), AttributeModifier.Operation.ADD_NUMBER, EquipmentSlot.HAND);
im.addAttributeModifier(Attribute.GENERIC_ATTACK_DAMAGE, p);
} else if (q.equals("moveSpeed")) {
AttributeModifier s = new AttributeModifier(UUID.randomUUID(), "generic.movementSpeed", aa.get(q), AttributeModifier.Operation.ADD_NUMBER, EquipmentSlot.HAND);
im.addAttributeModifier(Attribute.GENERIC_MOVEMENT_SPEED, s);
}
}
im.addItemFlags(ItemFlag.HIDE_ATTRIBUTES, ItemFlag.HIDE_UNBREAKABLE, ItemFlag.HIDE_ENCHANTS);
i.setItemMeta(im);
a.put(c.getString("name"), i);
}
}
public static void setItemRecipe(NamespacedKey key, ItemStack i, int ingredient, String shape1, String shape2, String shape3, List<Material> ingredients) {
// ShapedRecipe wither_sword_recipe = new ShapedRecipe(new NamespacedKey(main, "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);
// Bukkit.addRecipe(wither_sword_recipe);
}
public static YamlConfiguration loadConfig(String path) {
File f = new File(main.getDataFolder(), path);
if(!f.exists()) {
try {
f.createNewFile();
} catch (IOException e) {
e.printStackTrace();
}
return i;
}
return YamlConfiguration.loadConfiguration(f);
}
public static File loadFile(String path) {
File f = new File(main.getDataFolder(), path);
if(!f.exists()) {
try {
f.createNewFile();
} catch (IOException e) {
e.printStackTrace();
}
}
return f;
}
private static void createItemDataDirectory(String path) {
File f = new File(main.getDataFolder(), path);
if(!f.exists()) {
try {
if(!f.mkdir()) {
try {
f.mkdir();
} catch (SecurityException e) {
e.printStackTrace();
}
}
} catch (SecurityException e) {
e.printStackTrace();
}
}
}
private static List<String> getAllFilesFromDirectory(String path) {
ArrayList<String> ns = new ArrayList<>();
try {
File f = new File(main.getDataFolder(), path);
File[] files = f.listFiles();
for (int i = 0; i < files.length; i++) {
ns.add(files[i].getName());
}
} catch (Exception e) {
e.printStackTrace();
}
return ns;
}
public static ItemStack getItem(String name){
return a.get(name);
}
}

View file

@ -8,8 +8,8 @@ public enum Rarity {
EPIC(net.md_5.bungee.api.ChatColor.of("#b201b2").toString() + ChatColor.BOLD + "EPIC", net.md_5.bungee.api.ChatColor.of("#b201b2").toString()),
LEGENDARY(net.md_5.bungee.api.ChatColor.of("#ffa21b").toString() + ChatColor.BOLD + "LEGENDARY", net.md_5.bungee.api.ChatColor.of("#ffa21b").toString()),
MYTHIC(net.md_5.bungee.api.ChatColor.of("#ff23ff").toString() + ChatColor.BOLD + "MYTHIC", net.md_5.bungee.api.ChatColor.of("#ff23ff").toString()),
ULTRA(ChatColor.BLACK.toString() + ChatColor.BOLD + "ULTRA", ChatColor.BLACK.toString()),
GRAND(net.md_5.bungee.api.ChatColor.of("#ffc509").toString() + ChatColor.BOLD + "GRAND", net.md_5.bungee.api.ChatColor.of("#ffc509").toString());
ULTRA(ChatColor.RED.toString() + ChatColor.BOLD + "ULTRA", ChatColor.RED.toString()),
GRAND(net.md_5.bungee.api.ChatColor.of("#00fdff").toString() + ChatColor.BOLD + "GRAND", net.md_5.bungee.api.ChatColor.of("#00fdff").toString());
private String display;
private String color;
Rarity(String display, String color) {
@ -22,4 +22,26 @@ public enum Rarity {
public String getColor() {
return color;
}
public static Rarity getRarity(String str) {
switch(str) {
case "COMMON":
return COMMON;
case "UNCOMMON":
return UNCOMMON;
case "RARE":
return RARE;
case "EPIC":
return EPIC;
case "LEGENDARY":
return LEGENDARY;
case "MYTHIC":
return MYTHIC;
case "ULTRA":
return ULTRA;
case "GRAND":
return GRAND;
default:
return COMMON;
}
}
}

View file

@ -3,7 +3,6 @@ package com.night.nullvalkyrie;
import com.night.nullvalkyrie.Chests.MenuListener;
import com.night.nullvalkyrie.Enchantments.EnchantmentManager;
import com.night.nullvalkyrie.Events.CustomItemEvents;
import com.night.nullvalkyrie.Items.CustomItem;
import com.night.nullvalkyrie.Items.CustomItemManager;
import com.night.nullvalkyrie.Rank.*;
import com.night.nullvalkyrie.Util.Util;
@ -29,7 +28,6 @@ public final class Main extends JavaPlugin implements Listener {
private SideBarManager sideBarManager;
private BelowNameManager belowNameManager;
private CustomItemManager customItemManager;
private CustomItem customItems;
public RankManager getRankManager() {
return rankManager;
@ -50,6 +48,7 @@ public final class Main extends JavaPlugin implements Listener {
return customItemManager;
}
@Override
public void onEnable() {
new VanishCommand();
@ -57,13 +56,13 @@ public final class Main extends JavaPlugin implements Listener {
new AnvilCommand();
new ArmorCommand();
new MenuCommand();
new RankCommand(this);
new MessageCommand();
new HologramCommand();
new CraftCommand();
new EnchantingCommand();
new SpawnCommand();
new WeaponCommand();
new RankCommand(this);
new WeaponCommand(this);
bossbar = Bukkit.createBossBar(ChatColor.GOLD + "Kuudra", BarColor.RED, BarStyle.SEGMENTED_12);
Bukkit.getPluginManager().registerEvents(this, this);
Bukkit.getPluginManager().registerEvents(new MenuListener(), this);
@ -73,20 +72,15 @@ public final class Main extends JavaPlugin implements Listener {
rankManager = new RankManager(this);
sideBarManager = new SideBarManager(this);
belowNameManager = new BelowNameManager();
customItemManager = new CustomItemManager();
customItems = new CustomItem(this);
customItems.register();
EnchantmentManager.register();
new EnchantmentManager();
customItemManager = new CustomItemManager(this);
}
@EventHandler
public void onJoin(PlayerJoinEvent e) {
e.getPlayer().sendTitle(ChatColor.RED + "Welcome to Matrix!", ChatColor.GREEN + "LOL", 20, 100, 20);
e.getPlayer().spigot().sendMessage(ChatMessageType.ACTION_BAR, TextComponent.fromLegacyText("§1NOT ENOUGH MANNER"));
bossbar.addPlayer(e.getPlayer());
e.getPlayer().setPlayerListHeaderFooter(ChatColor.AQUA + "You are playing on " + ChatColor.GREEN + "127.0.0.1", ChatColor.GOLD + "Ranks, boosters, & more!" + ChatColor.AQUA + "127.0.0.1");
}
@EventHandler

View file

@ -22,8 +22,10 @@ public class ScoreboardListener implements Listener {
public void onJoin(PlayerJoinEvent e) {
Player player = e.getPlayer();
if(!player.hasPlayedBefore()) {
e.getPlayer().sendTitle(ChatColor.RED + "Welcome to Matrix!", ChatColor.GREEN + "LOL", 20, 100, 20);
main.getRankManager().setRank(player.getUniqueId(), Rank.ROOKIE);
}
e.getPlayer().setPlayerListHeaderFooter(ChatColor.AQUA + "You are playing on " + ChatColor.GREEN + "127.0.0.1", ChatColor.GOLD + "Ranks, boosters, & more!" + ChatColor.AQUA + "127.0.0.1");
main.getNameTagManager().setNametags(player);
main.getNameTagManager().newTag(player);
main.getSideBarManager().setSideBar(player);

View file

@ -1,17 +1,21 @@
package com.night.nullvalkyrie.commands;
import com.night.nullvalkyrie.Items.CustomItem;
import com.night.nullvalkyrie.Items.CustomItemManager;
import com.night.nullvalkyrie.Main;
import org.bukkit.ChatColor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import org.bukkit.util.StringUtil;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Objects;
public class WeaponCommand extends Command {
public WeaponCommand() {
private Main main;
public WeaponCommand(Main main) {
super(
"weapon",
new String[]{},
@ -19,36 +23,36 @@ public class WeaponCommand extends Command {
""
);
this.main = main;
}
@Override
public void onCommand(CommandSender sender, String[] 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(CustomItem.SnowGun);
} else if(name.equalsIgnoreCase("Grenade")) {
player.getInventory().addItem(CustomItem.Grenade);
} else if(name.equalsIgnoreCase("Widow Sword")) {
player.getInventory().addItem(CustomItem.WidowSword);
} else if(name.equalsIgnoreCase("Terminator")) {
player.getInventory().addItem(CustomItem.Terminator);
} else if(name.equalsIgnoreCase("Explosive Bow")) {
player.getInventory().addItem(CustomItem.ExplosiveBow);
} else if(name.equalsIgnoreCase("AOTV")) {
player.getInventory().addItem(CustomItem.AOTV);
} else if(name.equalsIgnoreCase("Grappling Hook")) {
player.getInventory().addItem(CustomItem.GrapplingHook);
StringBuilder s = new StringBuilder();
List<String> b = Arrays.asList(args);
for(String a: args) {
if(a.equals(b.get(b.size() - 1))) {
s.append(a);
} else {
s.append(a);
s.append(" ");
}
}
ItemStack item = main.getCustomItemManager().getItem(s.toString());
if(item.hasItemMeta()) {
player.getInventory().addItem(item);
} else {
player.sendMessage(ChatColor.RED + "This item doesn't exist");
}
}
@Override
public List<String> onTabComplete(CommandSender sender, String[] args) {
if(args.length == 1) {
return StringUtil.copyPartialMatches(args[0], Arrays.asList("Snow Gun", "Grenade", "Widow Sword", "Terminator", "Explosive Bow", "AOTV", "Grappling Hook"), new ArrayList<>());
return StringUtil.copyPartialMatches(args[0], Arrays.asList("Snow Gun", "Frag Grenade", "Widow Sword", "Terminator", "Explosive Bow", "Teleport Door", "Grappling Hook"), new ArrayList<>());
}
return new ArrayList<>();
}