diff --git a/src/main/java/me/night/nullvalkyrie/commands/BetaCommand.java b/src/main/java/me/night/nullvalkyrie/commands/BetaCommand.java index 0c2de96..5f2d0fb 100644 --- a/src/main/java/me/night/nullvalkyrie/commands/BetaCommand.java +++ b/src/main/java/me/night/nullvalkyrie/commands/BetaCommand.java @@ -1,26 +1,22 @@ package me.night.nullvalkyrie.commands; import me.night.nullvalkyrie.Main; -import net.md_5.bungee.api.ChatMessageType; -import net.md_5.bungee.api.chat.TextComponent; -import net.minecraft.network.protocol.game.*; +import net.minecraft.network.protocol.game.PacketPlayOutEntityHeadRotation; import net.minecraft.server.level.EntityPlayer; import org.bukkit.Bukkit; +import org.bukkit.Location; +import org.bukkit.World; import org.bukkit.command.CommandSender; import org.bukkit.craftbukkit.v1_19_R1.entity.CraftPlayer; +import org.bukkit.entity.Entity; +import org.bukkit.entity.EntityType; import org.bukkit.entity.Player; -import org.bukkit.scheduler.BukkitScheduler; -import org.apache.commons.lang3.time.StopWatch; import java.util.List; -import java.util.concurrent.TimeUnit; -import static java.lang.Thread.sleep; -import static me.night.nullvalkyrie.database.Client.getUser; public class BetaCommand extends Command { private Main main; - private BukkitScheduler scheduler; public BetaCommand(Main main) { super("beta", new String[]{"b"}, "Beta", ""); @@ -29,7 +25,6 @@ public class BetaCommand extends Command { @Override public void onCommand(CommandSender sender, String[] args) { -// getUser("Kaly15"); if (sender instanceof Player) { Player pa = (Player) sender; // CraftPlayer cp = (CraftPlayer) sender; @@ -44,42 +39,6 @@ public class BetaCommand extends Command { // TextComponent.fromLegacyText("§1NOT ENOUGH MANNER")); // } // }.runTaskTimer(main, 0L, 10); - - Bukkit.getServer().getScheduler().scheduleSyncRepeatingTask(main, new Runnable() { - int ms = 1; - @Override - public void run() { - while (true) { - try { - sleep(10); // will run every 0.1 seconds - long minutes = (ms / 1000) / 60; - long seconds = (ms / 100) % 60; - long milliseconds = (ms /10); - String secondsStr = Long.toString(seconds); - String secs; - if (secondsStr.length() >= 2) { - secs = secondsStr.substring(0, 2); - } else { - secs = "0" + secondsStr; - } - String minsStr = Long.toString(minutes); - String mins; - if (minsStr.length() >= 2) { - mins = minsStr.substring(0, 2); - } else { - mins = "0" + minsStr; - } - String sw = mins + ":" + secs + ":" + milliseconds; - System.out.println(sw); - pa.spigot().sendMessage(ChatMessageType.ACTION_BAR, TextComponent.fromLegacyText("§1"+ sw)); - ms++; - } catch (InterruptedException ex) { - throw new RuntimeException(ex); - } - - } - } - }, 0L, 1); } } diff --git a/src/main/java/me/night/nullvalkyrie/commands/SpawnCommand.java b/src/main/java/me/night/nullvalkyrie/commands/SpawnCommand.java index b26fb1f..4d97dbf 100644 --- a/src/main/java/me/night/nullvalkyrie/commands/SpawnCommand.java +++ b/src/main/java/me/night/nullvalkyrie/commands/SpawnCommand.java @@ -1,152 +1,151 @@ -package me.night.nullvalkyrie.commands; - -import me.night.nullvalkyrie.Main; -import me.night.nullvalkyrie.util.components.CustomMob; -import me.night.nullvalkyrie.util.Utils; -import org.bukkit.Bukkit; -import org.bukkit.Location; -import org.bukkit.World; -import org.bukkit.block.Block; -import org.bukkit.command.CommandSender; -import org.bukkit.entity.*; -import org.bukkit.event.EventHandler; -import org.bukkit.event.Listener; -import org.bukkit.event.entity.EntityDamageEvent; -import org.bukkit.event.entity.EntityDeathEvent; -import org.bukkit.scheduler.BukkitRunnable; - -import java.text.DecimalFormat; -import java.util.*; - -public class SpawnCommand extends Command implements Listener { - private final Main main; - public World world; - public final Map indicators = new HashMap<>(); - public final Map entities = new HashMap<>(); - private final DecimalFormat formatter = new DecimalFormat("#"); - public SpawnCommand(Main main) { - super( - "spawn", - new String[]{}, - "Spawn a custom mob", - "" - ); - this.main = main; - } - - @Override - public void onCommand(CommandSender sender, String[] args) { - world = Bukkit.getWorld("world"); - - spawnMobs(9, 10, 5 * 20); - new BukkitRunnable() { - final Set stands = indicators.keySet(); - final List removal = new ArrayList<>(); - @Override - public void run() { - for (Entity stand : stands) { - int ticksLeft = indicators.get(stand); - if (ticksLeft == 0) { - stand.remove(); - removal.add(stand); - continue; - } - ticksLeft--; - indicators.put(stand, ticksLeft); - } - stands.removeAll(removal); - } - }.runTaskTimer(main, 0L, 1L); - - } - public void spawnMobs(int size, int mobCap, int spawnTime) { - CustomMob[] mobTypes = CustomMob.values(); - new BukkitRunnable() { - final Set spawned = entities.keySet(); - final List removal = new ArrayList<>(); - @Override - public void run() { - for (Entity entity : spawned) { - if (!entity.isValid() || entity.isDead()) removal.add(entity); - } - spawned.removeAll(removal); - - // Spawning Algorithm - int diff = mobCap - entities.size(); - if (diff <= 0) return; - int spawnAmount = (int) (Math.random() * (diff + 1)), count = 0; - while (count <= spawnAmount) { - count++; - int ranX = getRandomWithNeg(size), ranZ = getRandomWithNeg(size); - Block block = world.getHighestBlockAt(ranX, ranZ); - double xOffset = getRandomOffset(), zOffset = getRandomOffset(); - Location loc = block.getLocation().clone().add(xOffset, 1, zOffset); - if (!isSpawnable(loc)) continue; - double random = Math.random() * 101, previous = 0; - CustomMob typeToSpawn = mobTypes[0]; - for (CustomMob type : mobTypes) { - previous += type.getSpawnChance(); - if (random <= previous) { - typeToSpawn = type; - break; - } - } - entities.put(typeToSpawn.spawn(loc), typeToSpawn); - } - } - }.runTaskTimer(main, 0L, spawnTime); - } - - public static boolean isSpawnable(Location loc) { - Block feetBlock = loc.getBlock(), headBlock = loc.clone().add(0, 1, 0).getBlock(), upperBlock = loc.clone().add(0, 2, 0).getBlock(); - return feetBlock.isPassable() && !feetBlock.isLiquid() && headBlock.isPassable() && !headBlock.isLiquid() && upperBlock.isPassable() && !upperBlock.isLiquid(); - } - - private static double getRandomOffset() { - double random = Math.random(); - if (Math.random() > 0.5) random *= -1; - return random; - } - - public static int getRandomWithNeg(int size) { - int random = (int) (Math.random() * (size + 1)); - if (Math.random() > 0.5) random *= -1; - return random; - } - - @EventHandler - public void onEntityDamage(EntityDamageEvent event) { - Entity rawEntity = event.getEntity(); - if (!entities.containsKey(rawEntity)) return; - CustomMob mob = entities.get(rawEntity); - LivingEntity entity = (LivingEntity) rawEntity; - double damage = event.getFinalDamage(), health = entity.getHealth() + entity.getAbsorptionAmount(); - if (health > damage) { - // If the entity survived the hit - health -= damage; - entity.setCustomName(Utils.color(mob.getName() + " &r&c" + (int) health + "/" + (int) mob.getMaxHealth() + "❤")); - } - Location loc = entity.getLocation().clone().add(getRandomOffset(), 1, getRandomOffset()); - world.spawn(loc, ArmorStand.class, armorStand -> { - armorStand.setMarker(true); - armorStand.setVisible(false); - armorStand.setGravity(false); - armorStand.setSmall(true); - armorStand.setCustomNameVisible(true); - armorStand.setCustomName(Utils.color("&c" + formatter.format(damage))); - indicators.put(armorStand, 30); - }); - } - - @EventHandler - public void onEntityDeath(EntityDeathEvent event) { - if (!entities.containsKey(event.getEntity())) return; - event.setDroppedExp(0); - event.getDrops().clear(); - entities.remove(event.getEntity()).tryDropLoot(event.getEntity().getLocation()); - } - @Override - public List onTabComplete(CommandSender sender, String[] args) { - return null; - } -} +//package me.night.nullvalkyrie.commands; +// +//import me.night.nullvalkyrie.Main; +//import me.night.nullvalkyrie.util.components.CustomMob; +//import org.bukkit.Bukkit; +//import org.bukkit.Location; +//import org.bukkit.World; +//import org.bukkit.block.Block; +//import org.bukkit.command.CommandSender; +//import org.bukkit.entity.*; +//import org.bukkit.event.EventHandler; +//import org.bukkit.event.Listener; +//import org.bukkit.event.entity.EntityDamageEvent; +//import org.bukkit.event.entity.EntityDeathEvent; +//import org.bukkit.scheduler.BukkitRunnable; +// +//import java.text.DecimalFormat; +//import java.util.*; +// +//public class SpawnCommand extends Command implements Listener { +// private final Main main; +// public World world; +// public final Map indicators = new HashMap<>(); +// public final Map entities = new HashMap<>(); +// private final DecimalFormat formatter = new DecimalFormat("#"); +// public SpawnCommand(Main main) { +// super( +// "spawn", +// new String[]{}, +// "Spawn a custom mob", +// "" +// ); +// this.main = main; +// } +// +// @Override +// public void onCommand(CommandSender sender, String[] args) { +// world = Bukkit.getWorld("world"); +// +// spawnMobs(9, 10, 5 * 20); +// new BukkitRunnable() { +// final Set stands = indicators.keySet(); +// final List removal = new ArrayList<>(); +// @Override +// public void run() { +// for (Entity stand : stands) { +// int ticksLeft = indicators.get(stand); +// if (ticksLeft == 0) { +// stand.remove(); +// removal.add(stand); +// continue; +// } +// ticksLeft--; +// indicators.put(stand, ticksLeft); +// } +// stands.removeAll(removal); +// } +// }.runTaskTimer(main, 0L, 1L); +// +// } +// public void spawnMobs(int size, int mobCap, int spawnTime) { +// CustomMob[] mobTypes = CustomMob.values(); +// new BukkitRunnable() { +// final Set spawned = entities.keySet(); +// final List removal = new ArrayList<>(); +// @Override +// public void run() { +// for (Entity entity : spawned) { +// if (!entity.isValid() || entity.isDead()) removal.add(entity); +// } +// spawned.removeAll(removal); +// +// // Spawning Algorithm +// int diff = mobCap - entities.size(); +// if (diff <= 0) return; +// int spawnAmount = (int) (Math.random() * (diff + 1)), count = 0; +// while (count <= spawnAmount) { +// count++; +// int ranX = getRandomWithNeg(size), ranZ = getRandomWithNeg(size); +// Block block = world.getHighestBlockAt(ranX, ranZ); +// double xOffset = getRandomOffset(), zOffset = getRandomOffset(); +// Location loc = block.getLocation().clone().add(xOffset, 1, zOffset); +// if (!isSpawnable(loc)) continue; +// double random = Math.random() * 101, previous = 0; +// CustomMob typeToSpawn = mobTypes[0]; +// for (CustomMob type : mobTypes) { +// previous += type.getSpawnChance(); +// if (random <= previous) { +// typeToSpawn = type; +// break; +// } +// } +// entities.put(typeToSpawn.spawn(loc), typeToSpawn); +// } +// } +// }.runTaskTimer(main, 0L, spawnTime); +// } +// +// public static boolean isSpawnable(Location loc) { +// Block feetBlock = loc.getBlock(), headBlock = loc.clone().add(0, 1, 0).getBlock(), upperBlock = loc.clone().add(0, 2, 0).getBlock(); +// return feetBlock.isPassable() && !feetBlock.isLiquid() && headBlock.isPassable() && !headBlock.isLiquid() && upperBlock.isPassable() && !upperBlock.isLiquid(); +// } +// +// private static double getRandomOffset() { +// double random = Math.random(); +// if (Math.random() > 0.5) random *= -1; +// return random; +// } +// +// public static int getRandomWithNeg(int size) { +// int random = (int) (Math.random() * (size + 1)); +// if (Math.random() > 0.5) random *= -1; +// return random; +// } +// +// @EventHandler +// public void onEntityDamage(EntityDamageEvent event) { +// Entity rawEntity = event.getEntity(); +// if (!entities.containsKey(rawEntity)) return; +// CustomMob mob = entities.get(rawEntity); +// LivingEntity entity = (LivingEntity) rawEntity; +// double damage = event.getFinalDamage(), health = entity.getHealth() + entity.getAbsorptionAmount(); +// if (health > damage) { +// // If the entity survived the hit +// health -= damage; +// entity.setCustomName(Utils.color(mob.getName() + " &r&c" + (int) health + "/" + (int) mob.getMaxHealth() + "❤")); +// } +// Location loc = entity.getLocation().clone().add(getRandomOffset(), 1, getRandomOffset()); +// world.spawn(loc, ArmorStand.class, armorStand -> { +// armorStand.setMarker(true); +// armorStand.setVisible(false); +// armorStand.setGravity(false); +// armorStand.setSmall(true); +// armorStand.setCustomNameVisible(true); +// armorStand.setCustomName(Util.color("&c" + formatter.format(damage))); +// indicators.put(armorStand, 30); +// }); +// } +// +// @EventHandler +// public void onEntityDeath(EntityDeathEvent event) { +// if (!entities.containsKey(event.getEntity())) return; +// event.setDroppedExp(0); +// event.getDrops().clear(); +// entities.remove(event.getEntity()).tryDropLoot(event.getEntity().getLocation()); +// } +// @Override +// public List onTabComplete(CommandSender sender, String[] args) { +// return null; +// } +//} diff --git a/src/main/java/me/night/nullvalkyrie/events/CustomItemEvents.java b/src/main/java/me/night/nullvalkyrie/events/CustomItemEvents.java index 3252b61..b190305 100644 --- a/src/main/java/me/night/nullvalkyrie/events/CustomItemEvents.java +++ b/src/main/java/me/night/nullvalkyrie/events/CustomItemEvents.java @@ -3,7 +3,6 @@ package me.night.nullvalkyrie.events; import me.night.nullvalkyrie.items.CustomItemManager; import me.night.nullvalkyrie.items.Rarity; import me.night.nullvalkyrie.Main; -import me.night.nullvalkyrie.commands.SpawnCommand; import net.md_5.bungee.api.ChatMessageType; import net.md_5.bungee.api.chat.TextComponent; import org.bukkit.*; @@ -20,11 +19,9 @@ import org.bukkit.inventory.MerchantRecipe; import org.bukkit.inventory.meta.ItemMeta; import org.bukkit.persistence.PersistentDataContainer; import org.bukkit.persistence.PersistentDataType; -import org.bukkit.scheduler.BukkitRunnable; import java.util.*; - public class CustomItemEvents implements Listener { private final Main main; @@ -48,23 +45,6 @@ public class CustomItemEvents implements Listener { e.setDamage(0); } } - } else if (e.getDamager() instanceof Player) { - Player player = (Player) e.getDamager(); - if (player.getInventory().getItemInMainHand().getItemMeta() != null) { - String name = player.getInventory().getItemInMainHand().getItemMeta().getDisplayName(); - if (name.equalsIgnoreCase(Rarity.MYTHIC.getColor() + "Fabled Widow Sword")) { - if (e.getEntity() instanceof Zombie) { - int zombie = CustomItemManager.loadConfig("ItemData\\WidowSword.yml").getInt("zombie"); - e.setDamage(e.getDamage() * (1 + zombie / 100)); - } else if (e.getEntity() instanceof Skeleton) { - int skeleton = CustomItemManager.loadConfig("ItemData\\WidowSword.yml").getInt("skeleton"); - e.setDamage(e.getDamage() * (1 + skeleton / 100)); - } else if (e.getEntity() instanceof Spider) { - int spider = CustomItemManager.loadConfig("ItemData\\WidowSword.yml").getInt("spider"); - e.setDamage(e.getDamage() * (1 + spider / 100)); - } - } - } } } @@ -105,7 +85,7 @@ public class CustomItemEvents implements Listener { ItemStack weapon = player.getInventory().getItemInMainHand(); ItemMeta weaponMeta = weapon.getItemMeta(); PersistentDataContainer container = weaponMeta.getPersistentDataContainer(); - if(container != null) { + if (container != null) { NamespacedKey ammocount = CustomItemManager.keys.get("Snow Gun.ammo"); int ammo = container.get(ammocount, PersistentDataType.INTEGER); container.set(ammocount, PersistentDataType.INTEGER, ammo - 1); @@ -250,62 +230,37 @@ public class CustomItemEvents implements Listener { } } - private Location l; - private boolean spawnable = false; - @EventHandler public void onDamage(EntityDamageByEntityEvent e) { if (e.getEntity() instanceof Player) { Player player = (Player) e.getEntity(); - if ((player.getHealth() - e.getDamage()) <= 0) { - e.setCancelled(true); - Location loc = player.getWorld().getBlockAt(-3, 23, -3).getLocation(); - player.teleport(loc); - for (Player p : Bukkit.getOnlinePlayers()) { - p.sendMessage(e.getDamager() instanceof Player - ? ChatColor.RED + player.getName() + " has been killed by " + e.getDamager().getName() - : ChatColor.RED + player.getName() + " died"); - p.hidePlayer(player); - } - new BukkitRunnable() { - @Override - public void run() { - for (Player p : Bukkit.getOnlinePlayers()) { - p.showPlayer(player); - } - player.setHealth(20); -// while(!spawnable) { -// l = generateRandomCoord(9, Bukkit.getWorld("world")); -// if(isSpawnable(l)) { -// spawnable = true; -// player.teleport(l); -// } -// } - player.teleport(generateRandomCoord(9, Bukkit.getWorld("world"))); - } - }.runTaskLater(main, 100L); - run(player, new int[]{5}); - } +// if ((player.getHealth() - e.getDamage()) <= 0) { +// e.setCancelled(true); +// Location loc = player.getWorld().getBlockAt(-3, 23, -3).getLocation(); +// player.teleport(loc); +// for (Player p : Bukkit.getOnlinePlayers()) { +// p.sendMessage(e.getDamager() instanceof Player +// ? ChatColor.RED + player.getName() + " has been killed by " + e.getDamager().getName() +// : ChatColor.RED + player.getName() + " died"); +// p.hidePlayer(player); +// } +// new BukkitRunnable() { +// @Override +// public void run() { +// for (Player p : Bukkit.getOnlinePlayers()) { +// p.showPlayer(player); +// } +// player.setHealth(20); +// player.teleport(generateRandomCoord(9, Bukkit.getWorld("world"))); +// } +// }.runTaskLater(main, 100L); +// countDown(player, new int[]{5}); +// } } } - - public Location generateRandomCoord(int size, World world) { - int ranX = SpawnCommand.getRandomWithNeg(size), ranZ = SpawnCommand.getRandomWithNeg(size); - Block block = world.getHighestBlockAt(ranX, ranZ); - return block.getLocation(); - } - - public boolean isSpawnable(Location loc) { - Block feetBlock = loc.getBlock(), headBlock = loc.clone().add(0, 1, 0).getBlock(), - upperBlock = loc.clone().add(0, 2, 0).getBlock(); - return feetBlock.isPassable() && !feetBlock.isLiquid() && headBlock.isPassable() && !headBlock.isLiquid() - && upperBlock.isPassable() && !upperBlock.isLiquid(); - } - private int taskID; - - public void run(Player player, int[] a) { + public void countDown(Player player, int[] a) { taskID = Bukkit.getServer().getScheduler().scheduleSyncRepeatingTask(main, () -> { player.sendTitle(ChatColor.RED + "YOU DIED!", ChatColor.GREEN + "You will revive in " + a[0] + " seconds", 0, 20, 0); @@ -337,11 +292,9 @@ public class CustomItemEvents implements Listener { MerchantRecipe tntStick = new MerchantRecipe(CustomItemManager.getItem("Terminator"), 10); tntStick.addIngredient(CustomItemManager.getItem("Widow Sword")); recipes.add(tntStick); - Merchant merchant = Bukkit.createMerchant("Yum Yum In The Tum Tum"); + Merchant merchant = Bukkit.createMerchant("Exchange here"); merchant.setRecipes(recipes); - villagerlist.put(villager.getUniqueId(), merchant); - p.spawnParticle(Particle.END_ROD, loc, 30, 0, 1, 0, 0.2); p.openMerchant(merchant, true); } @@ -353,4 +306,11 @@ public class CustomItemEvents implements Listener { p.openMerchant(merchant, true); } } + + // For hologram clicks to change page +// @EventHandler +// public void onEntityInteract(EntityInteractEvent e) { +// System.out.println(e.getEntity().getLocation()); +// e.getEntity().setCustomName(ChatColor.RED + "Changed name since you ust clicked lol"); +// } } \ No newline at end of file diff --git a/src/main/java/me/night/nullvalkyrie/mobs/ModdedZombie.yml b/src/main/java/me/night/nullvalkyrie/mobs/ModdedZombie.yml deleted file mode 100644 index b428ffb..0000000 --- a/src/main/java/me/night/nullvalkyrie/mobs/ModdedZombie.yml +++ /dev/null @@ -1,3 +0,0 @@ -name: Zombie -level: 69 -health: 1000 \ No newline at end of file diff --git a/src/main/java/me/night/nullvalkyrie/util/Util.java b/src/main/java/me/night/nullvalkyrie/util/Util.java index 5787bec..2f64105 100644 --- a/src/main/java/me/night/nullvalkyrie/util/Util.java +++ b/src/main/java/me/night/nullvalkyrie/util/Util.java @@ -1,17 +1,19 @@ package me.night.nullvalkyrie.util; +import org.bukkit.ChatColor; + 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); - } + String repeat = String.valueOf(space).repeat(Math.max(0, distance)); + builder.append(repeat); builder.append(text); - for (int i = 0; i < distance; ++i) { - builder.append(space); - } + builder.append(repeat); return builder.toString(); } + public static String color(String string) { + return ChatColor.translateAlternateColorCodes('&', string); + } } diff --git a/src/main/java/me/night/nullvalkyrie/util/Utils.java b/src/main/java/me/night/nullvalkyrie/util/Utils.java deleted file mode 100644 index a9afc3d..0000000 --- a/src/main/java/me/night/nullvalkyrie/util/Utils.java +++ /dev/null @@ -1,49 +0,0 @@ -package me.night.nullvalkyrie.util; - -import org.bukkit.ChatColor; -import org.bukkit.Material; -import org.bukkit.enchantments.Enchantment; -import org.bukkit.inventory.ItemFlag; -import org.bukkit.inventory.ItemStack; -import org.bukkit.inventory.meta.ItemMeta; - -import java.util.ArrayList; -import java.util.List; - -public class Utils { - public static String color(String string) { - return ChatColor.translateAlternateColorCodes('&', string); - } - - public static ItemStack createItem(Material type, int amount, String name, String... lines) { - ItemStack item = new ItemStack(type, amount); - ItemMeta meta = item.getItemMeta(); - meta.setUnbreakable(true); - meta.addItemFlags(ItemFlag.HIDE_UNBREAKABLE, ItemFlag.HIDE_ENCHANTS); - if (name != null) meta.setDisplayName(color(name)); - if (lines != null) { - List lore = new ArrayList<>(); - for (String line : lines) { - lore.add(color(line)); - } - meta.setLore(lore); - } - item.setItemMeta(meta); - return item; - } - - public static ItemStack enchantItem(ItemStack item, Enchantment enchant, int level) { - item.addUnsafeEnchantment(enchant, level); - return item; - } - - public static ItemStack[] makeArmorSet(ItemStack helmet, ItemStack chestplate, ItemStack leggings, ItemStack boots) { - ItemStack[] armor = new ItemStack[4]; - armor[3] = helmet; - armor[2] = chestplate; - armor[1] = leggings; - armor[0] = boots; - return armor; - } - -} diff --git a/src/main/java/me/night/nullvalkyrie/util/components/CustomMob.java b/src/main/java/me/night/nullvalkyrie/util/components/CustomMob.java deleted file mode 100644 index ff09dd5..0000000 --- a/src/main/java/me/night/nullvalkyrie/util/components/CustomMob.java +++ /dev/null @@ -1,111 +0,0 @@ -package me.night.nullvalkyrie.util.components; - -import org.bukkit.Location; -import org.bukkit.Material; -import org.bukkit.attribute.Attribute; -import org.bukkit.enchantments.Enchantment; -import org.bukkit.entity.EntityType; -import org.bukkit.entity.LivingEntity; -import org.bukkit.inventory.EntityEquipment; -import org.bukkit.inventory.ItemStack; - -import java.util.Arrays; -import java.util.List; - -import static me.night.nullvalkyrie.util.Utils.color; -import static me.night.nullvalkyrie.util.Utils.*; - -public enum CustomMob { - - DESERT_RISEN( - "&6Desert Risen", - 2048, - 60, - EntityType.HUSK, - null, - null, - new LootItem(createItem(Material.ROTTEN_FLESH, 1, "&fPreserved Flesh", "&7A preserved flesh from a rotting corpse", "&7Not sure what you'd want this for, though", "&7", "&9Foodstuff"), 1, 3, 100)), - - SKELETAL_MAGE( - "&dSkeletal Mage", - 2048, - 15, - EntityType.SKELETON, - createItem(Material.BONE, 1, null), makeArmorSet(new ItemStack(Material.IRON_HELMET), - null, - null, - null), - new LootItem(createItem(Material.BONE, 1, "&dBone Wand", "&7A wand made from skeletal bones"), 30), - new LootItem(new ItemStack(Material.BONE), 1, 3, 100)), - - ZOMBIE_SQUIRE( - "&bZombie Squire", - 2048, - 12, - EntityType.ZOMBIE, - new ItemStack(Material.IRON_SWORD), - makeArmorSet(new ItemStack(Material.CHAINMAIL_HELMET), new ItemStack(Material.CHAINMAIL_CHESTPLATE), new ItemStack(Material.CHAINMAIL_LEGGINGS), new ItemStack(Material.IRON_BOOTS)), new LootItem(new ItemStack(Material.CHAINMAIL_CHESTPLATE), 35), new LootItem(new ItemStack(Material.CHAINMAIL_LEGGINGS), 35), new LootItem(new ItemStack(Material.CHAINMAIL_HELMET), 35), new LootItem(new ItemStack(Material.IRON_BOOTS), 25), new LootItem(new ItemStack(Material.IRON_SWORD), 40)), - - CHARRED_ARCHER( - "&8Charred Archer", - 2048, - 3, - EntityType.WITHER_SKELETON, - enchantItem(new ItemStack(Material.BOW), Enchantment.ARROW_KNOCKBACK, 2), - null, new LootItem(enchantItem(enchantItem(createItem(Material.BOW, 1, "&cBurnt Bow", "&7This bow is burnt to a crisp but remains intact", "&8due to special enchantments"), Enchantment.ARROW_FIRE, 1), Enchantment.ARROW_KNOCKBACK, 2), 100), - new LootItem(new ItemStack(Material.BONE), 1, 5, 100)), - ; - - private String name; - private double maxHealth, spawnChance; - private EntityType type; - private ItemStack mainItem; - private ItemStack[] armor; - private List lootTable; - - CustomMob(String name, double maxHealth, double spawnChance, EntityType type, ItemStack mainItem, ItemStack[] armor, LootItem... lootItems) { - this.name = name; - this.maxHealth = maxHealth; - this.spawnChance = spawnChance; - this.type = type; - this.mainItem = mainItem; - this.armor = armor; - lootTable = Arrays.asList(lootItems); - } - - public LivingEntity spawn(Location location) { - LivingEntity entity = (LivingEntity) location.getWorld().spawnEntity(location, type); - entity.setCustomNameVisible(true); - entity.setCustomName(color(name + " &r&c" + (int) maxHealth + "/" + (int) maxHealth + "❤")); - entity.getAttribute(Attribute.GENERIC_MAX_HEALTH).setBaseValue(maxHealth); - entity.setHealth(maxHealth); - EntityEquipment inv = entity.getEquipment(); - if (armor != null) inv.setArmorContents(armor); - inv.setHelmetDropChance(0f); - inv.setChestplateDropChance(0f); - inv.setLeggingsDropChance(0f); - inv.setBootsDropChance(0f); - inv.setItemInMainHand(mainItem); - inv.setItemInMainHandDropChance(0f); - return entity; - } - - public void tryDropLoot(Location location) { - for (LootItem item : lootTable) { - item.tryDropItem(location); - } - } - - public String getName() { - return name; - } - - public double getMaxHealth() { - return maxHealth; - } - - public double getSpawnChance() { - return spawnChance; - } - -} diff --git a/src/main/java/me/night/nullvalkyrie/util/components/LootItem.java b/src/main/java/me/night/nullvalkyrie/util/components/LootItem.java deleted file mode 100644 index 98e50ae..0000000 --- a/src/main/java/me/night/nullvalkyrie/util/components/LootItem.java +++ /dev/null @@ -1,36 +0,0 @@ -package me.night.nullvalkyrie.util.components; - -import org.bukkit.Location; -import org.bukkit.inventory.ItemStack; - -import java.util.Random; - -public class LootItem { - - private ItemStack item; - private int min = 1, max = 1; - private double dropRate; - private static Random randomiser = new Random(); - - public LootItem(ItemStack item, double dropRate) { - this.item = item; - this.dropRate = dropRate; - } - - public LootItem(ItemStack item, int min, int max, double dropRate) { - this.item = item; - this.min = min; - this.max = max; - this.dropRate = dropRate; - } - - public void tryDropItem(Location loc) { - if (Math.random() * 101 > dropRate) return; - int amount = randomiser.nextInt(max - min + 1) + min; - if (amount == 0) return; - ItemStack item = this.item.clone(); - item.setAmount(amount); - loc.getWorld().dropItemNaturally(loc, item); - } - -}