diff --git a/src/main/java/com/night/nullvalkyrie/Events/onEntityDamageByEntity.java b/src/main/java/com/night/nullvalkyrie/Events/onEntityDamageByEntity.java new file mode 100644 index 0000000..a00d0c5 --- /dev/null +++ b/src/main/java/com/night/nullvalkyrie/Events/onEntityDamageByEntity.java @@ -0,0 +1,44 @@ +package com.night.nullvalkyrie.Events; + +import org.bukkit.ChatColor; +import org.bukkit.entity.*; +import org.bukkit.event.EventHandler; +import org.bukkit.event.Listener; +import org.bukkit.event.entity.EntityDamageByEntityEvent; + +import static com.night.nullvalkyrie.Items.CustomItemManager.loadConfig; + +public class onEntityDamageByEntity implements Listener { + @EventHandler + public void onEntityDamageByEntity(EntityDamageByEntityEvent e) { + if (e.getDamager().getType() == EntityType.SNOWBALL) { + Snowball sb = (Snowball) e.getDamager(); + 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")) { + e.setDamage(10000); + } else if (name.equalsIgnoreCase("AA-12")) { + e.setDamage(7); + } else { + e.setDamage(0); + } + } + } else if(e.getDamager() instanceof Player) { + Player player = (Player) e.getDamager(); + if(player.getInventory().getItemInMainHand().getItemMeta() != null && player.getInventory().getItemInMainHand().getItemMeta().getLore() != null && player.getInventory().getItemInMainHand().getItemMeta().getLore().contains(ChatColor.GOLD + "Item Ability: Damage Multiplier")) { + if(e.getEntity() instanceof Zombie) { + int zombie = loadConfig("ItemData\\WidowSword.yml").getInt("zombie"); + e.setDamage(e.getDamage() * (1 + zombie / 100)); + } else if(e.getEntity() instanceof Skeleton) { + int skeleton = loadConfig("ItemData\\WidowSword.yml").getInt("skeleton"); + e.setDamage(e.getDamage() * (1 + skeleton / 100)); + } else if(e.getEntity() instanceof Spider) { + int spider = loadConfig("ItemData\\WidowSword.yml").getInt("spider"); + e.setDamage(e.getDamage() * (1 + spider / 100)); + } + player.sendMessage(String.valueOf(e.getDamage())); + } + } + } +} diff --git a/src/main/java/com/night/nullvalkyrie/Items/CustomItemManager.java b/src/main/java/com/night/nullvalkyrie/Items/CustomItemManager.java new file mode 100644 index 0000000..a11c9a7 --- /dev/null +++ b/src/main/java/com/night/nullvalkyrie/Items/CustomItemManager.java @@ -0,0 +1,121 @@ +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.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.ArrayList; +import java.util.UUID; + +public class CustomItemManager { + private static Main main; + public CustomItemManager(Main main) { + this.main = main; + if(!main.getDataFolder().exists()) { + main.getDataFolder().mkdir(); + } + + } + public static ItemStack WidowSword; + public static void register() { + createItemDataDirectory("ItemData"); + setWidowSword(); + } + + 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); + ItemMeta wsMeta = widow_sword.getItemMeta(); + wsMeta.setDisplayName(net.md_5.bungee.api.ChatColor.of("#ff23ff") + "Fabled Widow Sword"); + wsMeta.setUnbreakable(true); + ArrayList lore = new ArrayList<>(); + lore.add(ChatColor.GRAY + "Damage: " + ChatColor.RED + "+100"); + 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); + widow_sword.setItemMeta(wsMeta); + WidowSword = widow_sword; + 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); + } +} diff --git a/src/main/java/com/night/nullvalkyrie/Main.java b/src/main/java/com/night/nullvalkyrie/Main.java index 651555b..2cdc721 100644 --- a/src/main/java/com/night/nullvalkyrie/Main.java +++ b/src/main/java/com/night/nullvalkyrie/Main.java @@ -2,7 +2,10 @@ package com.night.nullvalkyrie; import com.night.nullvalkyrie.Chests.MenuListener; import com.night.nullvalkyrie.Enchantments.EnchantmentHandler; -import com.night.nullvalkyrie.RankSys.*; +import com.night.nullvalkyrie.Events.onEntityDamageByEntity; +import com.night.nullvalkyrie.Items.CustomItemManager; +import com.night.nullvalkyrie.Rank.*; +import com.night.nullvalkyrie.Util.Util; import com.night.nullvalkyrie.commands.*; import net.md_5.bungee.api.ChatMessageType; import net.md_5.bungee.api.chat.TextComponent; @@ -10,22 +13,15 @@ import org.bukkit.*; import org.bukkit.boss.BarColor; import org.bukkit.boss.BarStyle; import org.bukkit.boss.BossBar; -import org.bukkit.enchantments.Enchantment; import org.bukkit.entity.*; import org.bukkit.event.EventHandler; import org.bukkit.event.Listener; -import org.bukkit.event.block.BlockBreakEvent; import org.bukkit.event.entity.CreatureSpawnEvent; -import org.bukkit.event.entity.EntityDamageByEntityEvent; import org.bukkit.event.entity.ProjectileHitEvent; import org.bukkit.event.entity.ProjectileLaunchEvent; -import org.bukkit.event.inventory.InventoryClickEvent; import org.bukkit.event.player.PlayerInteractEvent; import org.bukkit.event.player.PlayerJoinEvent; import org.bukkit.event.server.ServerListPingEvent; -import org.bukkit.inventory.ItemStack; -import org.bukkit.inventory.ShapedRecipe; -import org.bukkit.inventory.meta.ItemMeta; import org.bukkit.plugin.java.JavaPlugin; import java.io.File; @@ -36,6 +32,7 @@ public final class Main extends JavaPlugin implements Listener { private NameTagManager nameTagManager; private SideBarManager sideBarManager; private BelowNameManager belowNameManager; + private CustomItemManager customItemManager; public RankManager getRankManager() { return rankManager; @@ -56,22 +53,14 @@ public final class Main extends JavaPlugin implements Listener { Bukkit.getPluginManager().registerEvents(this, this); Bukkit.getPluginManager().registerEvents(new MenuListener(), this); Bukkit.getPluginManager().registerEvents(new ScoreboardListener(this), this); + Bukkit.getPluginManager().registerEvents(new onEntityDamageByEntity(), this); nameTagManager = new NameTagManager(this); rankManager = new RankManager(this); sideBarManager = new SideBarManager(this); belowNameManager = new BelowNameManager(); - ItemStack widow_sword = new ItemStack(Material.STICK); - widow_sword.addUnsafeEnchantment(Enchantment.DAMAGE_ALL, 20); - widow_sword.addUnsafeEnchantment(Enchantment.LOOT_BONUS_MOBS, 10); - ItemMeta wsMeta = widow_sword.getItemMeta(); - wsMeta.setDisplayName(net.md_5.bungee.api.ChatColor.of("#ff23ff") + "Fabled Widow Sword"); - wsMeta.setUnbreakable(true); - widow_sword.setItemMeta(wsMeta); - ShapedRecipe wither_sword_recipe = new ShapedRecipe(new NamespacedKey(this, "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); + customItemManager = new CustomItemManager(this); + customItemManager.register(); + EnchantmentHandler.register(); } @EventHandler @@ -109,24 +98,12 @@ public final class Main extends JavaPlugin implements Listener { 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"); } - public String centerText(String text, int lineLength) { - StringBuilder builder = new StringBuilder(); - char space = ' '; - int distance = (lineLength - text.length()) / 2; - for (int ii = 0; ii < distance; ii++) { - builder.append(space); - } - builder.append(text); - for (int i = 0; i < distance; ++i) { - builder.append(space); - } - return builder.toString(); - } + @EventHandler public void onPing(ServerListPingEvent e) { e.setMaxPlayers(8964); - String s = centerText("Matrix", 45); - String s2 = centerText("Support 1.18 & 1.8.9",45); + String s = Util.centerText("Matrix", 45); + String s2 = Util.centerText("Support 1.18 & 1.8.9",45); e.setMotd(ChatColor.AQUA.toString() + ChatColor.BOLD + s + "\n" + ChatColor.GOLD + ChatColor.BOLD + s2); try { e.setServerIcon(Bukkit.loadServerIcon(new File("nuke.png"))); @@ -135,23 +112,7 @@ public final class Main extends JavaPlugin implements Listener { } } - @EventHandler - public void onEntityDamageByEntity(EntityDamageByEntityEvent e) { - if (e.getDamager().getType() == EntityType.SNOWBALL) { - Snowball sb = (Snowball) e.getDamager(); - 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")) { - e.setDamage(10000); - } else if (name.equalsIgnoreCase("AA-12")) { - e.setDamage(7); - } else { - e.setDamage(0); - } - } - } - } + @EventHandler public void onProjectileHit(ProjectileHitEvent e) { if(e.getEntity().getShooter() instanceof Player) { diff --git a/src/main/java/com/night/nullvalkyrie/RankSys/BelowNameManager.java b/src/main/java/com/night/nullvalkyrie/Rank/BelowNameManager.java similarity index 93% rename from src/main/java/com/night/nullvalkyrie/RankSys/BelowNameManager.java rename to src/main/java/com/night/nullvalkyrie/Rank/BelowNameManager.java index 46fba52..3a6f3d4 100644 --- a/src/main/java/com/night/nullvalkyrie/RankSys/BelowNameManager.java +++ b/src/main/java/com/night/nullvalkyrie/Rank/BelowNameManager.java @@ -1,4 +1,4 @@ -package com.night.nullvalkyrie.RankSys; +package com.night.nullvalkyrie.Rank; import org.bukkit.ChatColor; import org.bukkit.entity.Player; diff --git a/src/main/java/com/night/nullvalkyrie/RankSys/NameTagManager.java b/src/main/java/com/night/nullvalkyrie/Rank/NameTagManager.java similarity index 95% rename from src/main/java/com/night/nullvalkyrie/RankSys/NameTagManager.java rename to src/main/java/com/night/nullvalkyrie/Rank/NameTagManager.java index 760a4c6..5a1d220 100644 --- a/src/main/java/com/night/nullvalkyrie/RankSys/NameTagManager.java +++ b/src/main/java/com/night/nullvalkyrie/Rank/NameTagManager.java @@ -1,7 +1,6 @@ -package com.night.nullvalkyrie.RankSys; +package com.night.nullvalkyrie.Rank; import com.night.nullvalkyrie.Main; -import com.night.nullvalkyrie.RankSys.Rank; import org.bukkit.Bukkit; import org.bukkit.entity.Player; import org.bukkit.scoreboard.DisplaySlot; diff --git a/src/main/java/com/night/nullvalkyrie/RankSys/Rank.java b/src/main/java/com/night/nullvalkyrie/Rank/Rank.java similarity index 90% rename from src/main/java/com/night/nullvalkyrie/RankSys/Rank.java rename to src/main/java/com/night/nullvalkyrie/Rank/Rank.java index efc0040..72cf26c 100644 --- a/src/main/java/com/night/nullvalkyrie/RankSys/Rank.java +++ b/src/main/java/com/night/nullvalkyrie/Rank/Rank.java @@ -1,4 +1,4 @@ -package com.night.nullvalkyrie.RankSys; +package com.night.nullvalkyrie.Rank; import org.bukkit.ChatColor; diff --git a/src/main/java/com/night/nullvalkyrie/RankSys/RankManager.java b/src/main/java/com/night/nullvalkyrie/Rank/RankManager.java similarity index 95% rename from src/main/java/com/night/nullvalkyrie/RankSys/RankManager.java rename to src/main/java/com/night/nullvalkyrie/Rank/RankManager.java index 4df440d..909ca77 100644 --- a/src/main/java/com/night/nullvalkyrie/RankSys/RankManager.java +++ b/src/main/java/com/night/nullvalkyrie/Rank/RankManager.java @@ -1,8 +1,7 @@ -package com.night.nullvalkyrie.RankSys; +package com.night.nullvalkyrie.Rank; import com.night.nullvalkyrie.Main; import org.bukkit.Bukkit; -import org.bukkit.ChatColor; import org.bukkit.configuration.file.YamlConfiguration; import org.bukkit.entity.Player; diff --git a/src/main/java/com/night/nullvalkyrie/RankSys/ScoreboardListener.java b/src/main/java/com/night/nullvalkyrie/Rank/ScoreboardListener.java similarity index 95% rename from src/main/java/com/night/nullvalkyrie/RankSys/ScoreboardListener.java rename to src/main/java/com/night/nullvalkyrie/Rank/ScoreboardListener.java index 1b369b0..bda774e 100644 --- a/src/main/java/com/night/nullvalkyrie/RankSys/ScoreboardListener.java +++ b/src/main/java/com/night/nullvalkyrie/Rank/ScoreboardListener.java @@ -1,4 +1,4 @@ -package com.night.nullvalkyrie.RankSys; +package com.night.nullvalkyrie.Rank; import com.night.nullvalkyrie.Main; import org.bukkit.Bukkit; @@ -11,9 +11,6 @@ import org.bukkit.event.player.AsyncPlayerChatEvent; import org.bukkit.event.player.PlayerJoinEvent; import org.bukkit.event.player.PlayerQuitEvent; -import java.util.HashMap; -import java.util.UUID; - public class ScoreboardListener implements Listener { private Main main; diff --git a/src/main/java/com/night/nullvalkyrie/RankSys/SideBarManager.java b/src/main/java/com/night/nullvalkyrie/Rank/SideBarManager.java similarity index 93% rename from src/main/java/com/night/nullvalkyrie/RankSys/SideBarManager.java rename to src/main/java/com/night/nullvalkyrie/Rank/SideBarManager.java index 3e03970..25c070f 100644 --- a/src/main/java/com/night/nullvalkyrie/RankSys/SideBarManager.java +++ b/src/main/java/com/night/nullvalkyrie/Rank/SideBarManager.java @@ -1,12 +1,9 @@ -package com.night.nullvalkyrie.RankSys; +package com.night.nullvalkyrie.Rank; import com.night.nullvalkyrie.Main; import org.bukkit.Bukkit; import org.bukkit.ChatColor; import org.bukkit.entity.Player; -import org.bukkit.event.EventHandler; -import org.bukkit.event.Listener; -import org.bukkit.event.entity.PlayerDeathEvent; import org.bukkit.scoreboard.*; import org.bukkit.scoreboard.Scoreboard; diff --git a/src/main/java/com/night/nullvalkyrie/Util/Util.java b/src/main/java/com/night/nullvalkyrie/Util/Util.java new file mode 100644 index 0000000..5645fc0 --- /dev/null +++ b/src/main/java/com/night/nullvalkyrie/Util/Util.java @@ -0,0 +1,17 @@ +package com.night.nullvalkyrie.Util; + +public class Util { + public static String centerText(String text, int lineLength) { + StringBuilder builder = new StringBuilder(); + char space = ' '; + int distance = (lineLength - text.length()) / 2; + for (int ii = 0; ii < distance; ii++) { + builder.append(space); + } + builder.append(text); + for (int i = 0; i < distance; ++i) { + builder.append(space); + } + return builder.toString(); + } +} diff --git a/src/main/java/com/night/nullvalkyrie/commands/RankCommand.java b/src/main/java/com/night/nullvalkyrie/commands/RankCommand.java index 7180f9b..25a93ea 100644 --- a/src/main/java/com/night/nullvalkyrie/commands/RankCommand.java +++ b/src/main/java/com/night/nullvalkyrie/commands/RankCommand.java @@ -3,7 +3,7 @@ package com.night.nullvalkyrie.commands; import com.google.common.cache.Cache; import com.google.common.cache.CacheBuilder; import com.night.nullvalkyrie.Main; -import com.night.nullvalkyrie.RankSys.Rank; +import com.night.nullvalkyrie.Rank.Rank; import org.bukkit.Bukkit; import org.bukkit.ChatColor; import org.bukkit.OfflinePlayer; diff --git a/src/main/java/com/night/nullvalkyrie/commands/WeaponCommand.java b/src/main/java/com/night/nullvalkyrie/commands/WeaponCommand.java index 40c687a..53b5288 100644 --- a/src/main/java/com/night/nullvalkyrie/commands/WeaponCommand.java +++ b/src/main/java/com/night/nullvalkyrie/commands/WeaponCommand.java @@ -1,6 +1,7 @@ package com.night.nullvalkyrie.commands; import com.night.nullvalkyrie.Enchantments.EnchantmentHandler; +import com.night.nullvalkyrie.Items.CustomItemManager; import org.bukkit.ChatColor; import org.bukkit.Material; import org.bukkit.command.CommandSender; @@ -29,8 +30,9 @@ public class WeaponCommand extends Command { @Override public void onCommand(CommandSender sender, String[] args) { + System.out.println(args[0]); Player player = (Player) sender; - if(args[0].equalsIgnoreCase("snowgun")) { + if(args[0].equalsIgnoreCase("Snow Gun")) { ItemStack hoe = new ItemStack(Material.DIAMOND_HOE); hoe.addUnsafeEnchantment(EnchantmentHandler.ThunderBolt, 5); hoe.addUnsafeEnchantment(Enchantment.DAMAGE_ALL, 20); @@ -41,7 +43,7 @@ public class WeaponCommand extends Command { hoe.setItemMeta(hoedata); player.getInventory().addItem(hoe); - } else if(args[0].equalsIgnoreCase("grenade")) { + } else if(args[0].equalsIgnoreCase("Grenade")) { ItemStack egg = new ItemStack(Material.EGG); ItemMeta eggdata = egg.getItemMeta(); eggdata.setDisplayName(net.md_5.bungee.api.ChatColor.of("#ff23ff") + "Frag Grenade"); @@ -49,13 +51,15 @@ public class WeaponCommand extends Command { eggdata.setLore(Arrays.asList(ChatColor.GOLD + "Boom")); egg.setItemMeta(eggdata); player.getInventory().addItem(egg); + } else if(args[0].equalsIgnoreCase("Widow Sword")) { + player.getInventory().addItem(CustomItemManager.WidowSword); } } @Override public List onTabComplete(CommandSender sender, String[] args) { if(args.length == 1) { - return StringUtil.copyPartialMatches(args[0], Arrays.asList("snowgun", "grenade"), new ArrayList<>()); + return StringUtil.copyPartialMatches(args[0], Arrays.asList("Snow Gun", "Grenade", "Widow Sword"), new ArrayList<>()); } return new ArrayList<>(); }