From 0573b95b9309b8068f004b911fd729467b655caf Mon Sep 17 00:00:00 2001 From: FantasyPvP <80643031+FantasyPvP@users.noreply.github.com> Date: Sat, 26 Oct 2024 00:48:33 +0100 Subject: [PATCH] - refactored a bit - added a steven sword --- pom.xml | 32 ++- .../kand/commands/CmdLightningSword.java | 31 --- .../kand/commands/GiveDashItemCmd.java | 35 --- .../kand/commands/SetAntiGriefCmd.java | 80 ++++++ .../kand/commands/SetSpawnCommand.java | 1 + .../fantasypvp/kand/database/Database.java | 47 ++++ .../kand/events/DashItemListener.java | 56 ---- .../fantasypvp/kand/events/DragonGlide.java | 13 - .../java/fantasypvp/kand/events/Events.java | 65 ----- .../kand/events/FireDamageListener.java | 2 +- .../kand/events/PlayerJumpEvent.java | 78 ------ .../fantasypvp/kand/items/BlazingHalo.java | 2 +- .../fantasypvp/kand/items/BlazingSet.java | 10 +- .../fantasypvp/kand/items/BlessedSet.java | 118 ++++++++ .../java/fantasypvp/kand/items/DashItem.java | 74 ++++- .../java/fantasypvp/kand/items/DragonSet.java | 261 ++++++++++++++++++ .../fantasypvp/kand/items/GearTemplate.java | 2 +- .../fantasypvp/kand/items/LightningGear.java | 59 +++- .../fantasypvp/kand/items/TrueNetherite.java | 2 +- .../java/fantasypvp/kand/items/Witherite.java | 211 ++++++++------ src/main/java/fantasypvp/kand/kandMain.java | 41 ++- src/main/java/fantasypvp/kand/teams/Team.java | 117 ++++++++ .../TierBase.java | 2 +- .../TierIII.java | 2 +- .../TierIV.java | 2 +- .../TierV.java | 2 +- .../TierVI.java | 2 +- .../fantasypvp/kand/util/playerCoords.java | 16 ++ src/main/resources/plugin.yml | 10 + 29 files changed, 959 insertions(+), 414 deletions(-) delete mode 100644 src/main/java/fantasypvp/kand/commands/CmdLightningSword.java delete mode 100644 src/main/java/fantasypvp/kand/commands/GiveDashItemCmd.java create mode 100644 src/main/java/fantasypvp/kand/commands/SetAntiGriefCmd.java create mode 100644 src/main/java/fantasypvp/kand/database/Database.java delete mode 100644 src/main/java/fantasypvp/kand/events/DashItemListener.java delete mode 100644 src/main/java/fantasypvp/kand/events/DragonGlide.java delete mode 100644 src/main/java/fantasypvp/kand/events/Events.java delete mode 100644 src/main/java/fantasypvp/kand/events/PlayerJumpEvent.java create mode 100644 src/main/java/fantasypvp/kand/items/BlessedSet.java create mode 100644 src/main/java/fantasypvp/kand/items/DragonSet.java create mode 100644 src/main/java/fantasypvp/kand/teams/Team.java rename src/main/java/fantasypvp/kand/util/{attribute_gear => gear_templates}/TierBase.java (93%) rename src/main/java/fantasypvp/kand/util/{attribute_gear => gear_templates}/TierIII.java (98%) rename src/main/java/fantasypvp/kand/util/{attribute_gear => gear_templates}/TierIV.java (98%) rename src/main/java/fantasypvp/kand/util/{attribute_gear => gear_templates}/TierV.java (99%) rename src/main/java/fantasypvp/kand/util/{attribute_gear => gear_templates}/TierVI.java (99%) create mode 100644 src/main/java/fantasypvp/kand/util/playerCoords.java diff --git a/pom.xml b/pom.xml index b28798a..a99c5b2 100644 --- a/pom.xml +++ b/pom.xml @@ -12,7 +12,7 @@ kand - 1.8 + 20 UTF-8 @@ -23,8 +23,8 @@ maven-compiler-plugin 3.8.1 - 14 - 14 + 20 + 20 @@ -58,6 +58,10 @@ sonatype https://oss.sonatype.org/content/groups/public/ + + jitpack.io + https://jitpack.io + @@ -67,5 +71,27 @@ 1.20.1-R0.1-SNAPSHOT provided + + com.github.booksaw + BetterTeams + 4.9.4 + provided + + + org.xerial + sqlite-jdbc + 3.46.0.0 + + + org.jetbrains + annotations + 24.0.1 + compile + + + com.googlecode.json-simple + json-simple + 1.1.1 + diff --git a/src/main/java/fantasypvp/kand/commands/CmdLightningSword.java b/src/main/java/fantasypvp/kand/commands/CmdLightningSword.java deleted file mode 100644 index 5399855..0000000 --- a/src/main/java/fantasypvp/kand/commands/CmdLightningSword.java +++ /dev/null @@ -1,31 +0,0 @@ -package fantasypvp.kand.commands; - -import fantasypvp.kand.items.LightningGear; -import org.bukkit.ChatColor; -import org.bukkit.command.CommandExecutor; -import org.bukkit.entity.Player; - -public class CmdLightningSword implements CommandExecutor { - - @Override - public boolean onCommand(org.bukkit.command.CommandSender sender, org.bukkit.command.Command command, String label, String[] args) { - if (!(sender instanceof Player)) { - sender.sendMessage("Only players can use this command"); - return true; - } - - Player player = (Player) sender; - - if(player.hasPermission("kand.lightning_sword")) { - if (command.getName().equalsIgnoreCase("lightning_sword")) { - player.getInventory().addItem(LightningGear.lightning_sword); - } - - } else { - player.sendMessage(ChatColor.RED+"You don't have permission to run this command."); - } - - return true; - } -} - diff --git a/src/main/java/fantasypvp/kand/commands/GiveDashItemCmd.java b/src/main/java/fantasypvp/kand/commands/GiveDashItemCmd.java deleted file mode 100644 index 0a121c9..0000000 --- a/src/main/java/fantasypvp/kand/commands/GiveDashItemCmd.java +++ /dev/null @@ -1,35 +0,0 @@ -package fantasypvp.kand.commands; - -import fantasypvp.kand.items.DashItem; -import org.bukkit.ChatColor; -import org.bukkit.command.Command; -import org.bukkit.command.CommandExecutor; -import org.bukkit.command.CommandSender; -import org.bukkit.entity.Player; -import org.bukkit.inventory.ItemStack; - -public class GiveDashItemCmd implements CommandExecutor { - - @Override - public boolean onCommand(CommandSender sender, Command command, String s, String[] args) { - - if(!(sender instanceof Player)){ - sender.sendMessage("You must be a player to execute this command"); - return true; - } - - Player player = (Player) sender; - - if(!(player.hasPermission("giveDashItem"))){ - player.sendMessage(ChatColor.RED+"You don't have permission to run this command."); - return true; - } - - ItemStack dashItem = new DashItem().createDashItem(); - - player.getInventory().addItem(dashItem); - - - return true; - } -} diff --git a/src/main/java/fantasypvp/kand/commands/SetAntiGriefCmd.java b/src/main/java/fantasypvp/kand/commands/SetAntiGriefCmd.java new file mode 100644 index 0000000..c0113f9 --- /dev/null +++ b/src/main/java/fantasypvp/kand/commands/SetAntiGriefCmd.java @@ -0,0 +1,80 @@ +package fantasypvp.kand.commands; + +import com.booksaw.betterTeams.Team; +import com.booksaw.betterTeams.customEvents.DisbandTeamEvent; +import fantasypvp.kand.database.Database; +import org.bukkit.ChatColor; +import org.bukkit.command.Command; +import org.bukkit.command.CommandExecutor; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.Listener; +import org.bukkit.plugin.java.JavaPlugin; + +import fantasypvp.kand.util.playerCoords; + +import java.io.File; +import java.io.IOException; +import java.sql.Connection; + +public class SetAntiGriefCmd implements CommandExecutor, Listener { + + private final JavaPlugin plugin; + + public SetAntiGriefCmd(JavaPlugin plugin) { this.plugin = plugin; } + + @Override + public boolean onCommand(CommandSender sender, Command command, String s, String[] args) { + if (!(sender instanceof Player)) { + sender.sendMessage(ChatColor.RED + "Only players can execute this command!"); + return true; + } + + Player player = (Player) sender; + + String coordinates = playerCoords.get(player); + + String locationname = args[0]; + + try { + if (SetCoordinates(player, coordinates)) { + player.sendMessage(ChatColor.GREEN + "Base location" + locationname + "set at coordinates" + coordinates); + player.sendMessage("These coordinates are visible only to you."); + } else { + return false; + } + } catch (IOException e) { + player.sendMessage(ChatColor.RED + "Unable to set Anti Grief"); + } + + + return true; + } + + + private boolean SetCoordinates(Player player, String coordinates) throws IOException { + + Team team = Team.getTeam(player); + + if(team == null){ + player.sendMessage(ChatColor.RED + "You must create or join a team to set a base area!"); + return false; + } + + Connection conn = Database.SQLite.connect(); + + + + File dataFolder = plugin.getDataFolder(); + if (!dataFolder.exists()) { + dataFolder.mkdirs(); + } + return true; + } + + @EventHandler + public static void DisbandTeamEvent(DisbandTeamEvent event) { + + } +} diff --git a/src/main/java/fantasypvp/kand/commands/SetSpawnCommand.java b/src/main/java/fantasypvp/kand/commands/SetSpawnCommand.java index bd70b86..2a7789d 100644 --- a/src/main/java/fantasypvp/kand/commands/SetSpawnCommand.java +++ b/src/main/java/fantasypvp/kand/commands/SetSpawnCommand.java @@ -11,6 +11,7 @@ import java.io.File; import java.io.FileWriter; import java.io.IOException; + public class SetSpawnCommand implements CommandExecutor { private final JavaPlugin plugin; diff --git a/src/main/java/fantasypvp/kand/database/Database.java b/src/main/java/fantasypvp/kand/database/Database.java new file mode 100644 index 0000000..d34253f --- /dev/null +++ b/src/main/java/fantasypvp/kand/database/Database.java @@ -0,0 +1,47 @@ +package fantasypvp.kand.database; + +import java.sql.Connection; +import java.sql.DriverManager; +import java.sql.SQLException; + +// import sql database library and connect + + +public class Database { + + public class SQLite { + private static Connection connection; + private static SQLite instance; + + private SQLite() { + connect(); + } + + public static Connection connect() { + try { + String url = "jdbc:sqlite:database.db"; + connection = DriverManager.getConnection(url); + } catch (SQLException e) { + e.printStackTrace(); + } + return null; + } + + public void disconnect() { + try { + if (connection != null) { + connection.close(); + } + } catch (SQLException e) { + e.printStackTrace(); + } + } + + public SQLite getInstance() { + if (instance == null) { + instance = new SQLite(); + } + return instance; + } + } +} \ No newline at end of file diff --git a/src/main/java/fantasypvp/kand/events/DashItemListener.java b/src/main/java/fantasypvp/kand/events/DashItemListener.java deleted file mode 100644 index b2e731c..0000000 --- a/src/main/java/fantasypvp/kand/events/DashItemListener.java +++ /dev/null @@ -1,56 +0,0 @@ -package fantasypvp.kand.events; - -import fantasypvp.kand.items.DashItem; - -import org.bukkit.Location; - -import org.bukkit.Particle; -import org.bukkit.Sound; -import org.bukkit.World; -import org.bukkit.entity.Player; -import org.bukkit.event.EventHandler; -import org.bukkit.event.Listener; -import org.bukkit.event.block.Action; -import org.bukkit.event.entity.EntityDamageEvent; -import org.bukkit.event.player.PlayerInteractEvent; -import org.bukkit.inventory.EquipmentSlot; -import org.bukkit.inventory.ItemStack; -import org.bukkit.util.Vector; - -public class DashItemListener implements Listener { - - @EventHandler - public void onPlayerInteract(PlayerInteractEvent event) { - Player player = event.getPlayer(); - ItemStack item = event.getItem(); // Get the item the player interacted with - - // Check if the interaction was a right-click and the item is in the main hand - if (event.getAction() == Action.RIGHT_CLICK_AIR || event.getAction() == Action.RIGHT_CLICK_BLOCK) { - if (item != null && item.isSimilar(new DashItem().createDashItem()) && event.getHand() == EquipmentSlot.HAND) { - Location location = player.getLocation(); - Vector direction = location.getDirection(); - player.setVelocity(direction.multiply(5.0)); - player.playSound(location, Sound.ENTITY_DRAGON_FIREBALL_EXPLODE, 1.0f, 1.0f); - World world = player.getWorld(); - world.spawnParticle(Particle.EXPLOSION_HUGE, location, 1); - } - } - } - - @EventHandler - public void OnEntityDamage(EntityDamageEvent event){ - if(event.getEntity() instanceof Player){ - - Player player = (Player) event.getEntity(); - - ItemStack itemInMainHand = player.getInventory().getItemInMainHand(); - - if (itemInMainHand.isSimilar(new DashItem().createDashItem()) && event.getCause() == EntityDamageEvent.DamageCause.FALL) { - - event.setCancelled(true); - - } - - } - } -} diff --git a/src/main/java/fantasypvp/kand/events/DragonGlide.java b/src/main/java/fantasypvp/kand/events/DragonGlide.java deleted file mode 100644 index c4d5566..0000000 --- a/src/main/java/fantasypvp/kand/events/DragonGlide.java +++ /dev/null @@ -1,13 +0,0 @@ -package fantasypvp.kand.events; - -import org.bukkit.event.Listener; -import org.bukkit.event.EventHandler; - -import static org.bukkit.Bukkit.*; - -public class DragonGlide implements Listener { - @EventHandler - public static void onPlayerJump(PlayerJumpEvent event) { - getServer().broadcastMessage("§a" + event.getPlayer().getName() + " jumped!"); - } -} \ No newline at end of file diff --git a/src/main/java/fantasypvp/kand/events/Events.java b/src/main/java/fantasypvp/kand/events/Events.java deleted file mode 100644 index e3d7825..0000000 --- a/src/main/java/fantasypvp/kand/events/Events.java +++ /dev/null @@ -1,65 +0,0 @@ -package fantasypvp.kand.events; - -import org.bukkit.entity.LivingEntity; -import org.bukkit.event.Listener; -import org.bukkit.entity.Player; -import org.bukkit.event.EventHandler; -import org.bukkit.potion.PotionEffect; - -import static org.bukkit.Bukkit.*; - -public class Events implements Listener { - - @EventHandler - public static void onEntityDamageByEntity(org.bukkit.event.entity.EntityDamageByEntityEvent event) { - - if (event.getDamager() instanceof org.bukkit.entity.Player) { - Player player = (Player) event.getDamager(); - // check if the player is using the lightning sword - - try { - player.getInventory().getItemInMainHand().getItemMeta().getLore().toString(); - } catch (NullPointerException e) { - return; - } - - if (player.getInventory().getItemInMainHand().getItemMeta().getLore().toString().contains("§7All who oppose shall be smitten")) { - // check if hit is critical - if (player.getFallDistance() > 0.0F && !player.isInsideVehicle() && !player.isGliding() && !player.isSwimming() && !player.isClimbing() && player.getAttackCooldown() == 1.0F) { - player.getWorld().strikeLightningEffect(event.getEntity().getLocation()); - } - } - - - - - - else if (player.getInventory().getItemInMainHand().getItemMeta().getLore().toString().contains("§f[T5+] Witherite Sword")) { - // if affected entity is wearing witherite gear - if (event.getEntity() instanceof Player) { - Player entity = (Player) event.getEntity(); - if (entity.getInventory().getHelmet().getItemMeta().getLore().toString().contains("§f[T5+] Witherite Helmet") - && entity.getInventory().getChestplate().getItemMeta().getLore().toString().contains("§f[T5+] Witherite Chestplate") - && entity.getInventory().getLeggings().getItemMeta().getLore().toString().contains("§f[T5+] Witherite Leggings") - && entity.getInventory().getBoots().getItemMeta().getLore().toString().contains("§f[T5+] Witherite Boots")) { - ; - } else { - PotionEffect effect = new PotionEffect( - org.bukkit.potion.PotionEffectType.WITHER, - 20 * 5, - 2 - ); - effect.apply((LivingEntity) event.getEntity()); - } - } else { - PotionEffect effect = new PotionEffect( - org.bukkit.potion.PotionEffectType.WITHER, - 20 * 5, - 2 - ); - effect.apply((LivingEntity) event.getEntity()); - } - } - } - } -} diff --git a/src/main/java/fantasypvp/kand/events/FireDamageListener.java b/src/main/java/fantasypvp/kand/events/FireDamageListener.java index 37b1ad4..aaada1c 100644 --- a/src/main/java/fantasypvp/kand/events/FireDamageListener.java +++ b/src/main/java/fantasypvp/kand/events/FireDamageListener.java @@ -1,4 +1,4 @@ -package fantasypvp.kand_smp.events; +package fantasypvp.kand.events; import org.bukkit.ChatColor; import org.bukkit.entity.Player; diff --git a/src/main/java/fantasypvp/kand/events/PlayerJumpEvent.java b/src/main/java/fantasypvp/kand/events/PlayerJumpEvent.java deleted file mode 100644 index 2fc3ca5..0000000 --- a/src/main/java/fantasypvp/kand/events/PlayerJumpEvent.java +++ /dev/null @@ -1,78 +0,0 @@ -package fantasypvp.kand.events; - -import org.bukkit.Bukkit; -import org.bukkit.Statistic; -import org.bukkit.entity.Player; -import org.bukkit.event.*; -import org.bukkit.event.player.PlayerJoinEvent; -import org.bukkit.event.player.PlayerMoveEvent; -import org.bukkit.event.player.PlayerQuitEvent; -import org.bukkit.plugin.java.JavaPlugin; - -import java.util.HashMap; -import java.util.Map; -import java.util.UUID; - -public class PlayerJumpEvent extends Event { - - private static final HandlerList handlers = new HandlerList(); - private static final PlayerJumpEventListener listener = new PlayerJumpEventListener(); - - private Player player; - - public PlayerJumpEvent(Player player) { - this.player = player; - } - - public Player getPlayer() { - return player; - } - - @Override - public HandlerList getHandlers() { - return handlers; - } - - public static HandlerList getHandlerList() { - return handlers; - } - - private static class PlayerJumpEventListener implements Listener { - - private Map jumps = new HashMap<>(); - - @EventHandler(priority = EventPriority.MONITOR) - public void onPlayerJoin(PlayerJoinEvent e) { - jumps.put(e.getPlayer().getUniqueId(), e.getPlayer().getStatistic(Statistic.JUMP)); - } - - @EventHandler(priority = EventPriority.MONITOR) - public void onPlayerQuit(PlayerQuitEvent e) { - jumps.remove(e.getPlayer().getUniqueId()); - } - - @EventHandler(priority = EventPriority.MONITOR) - public void onPlayerMove(PlayerMoveEvent e) { - Player player = e.getPlayer(); - - if(e.getFrom().getY() < e.getTo().getY()) { - int current = player.getStatistic(Statistic.JUMP); - int last = jumps.getOrDefault(player.getUniqueId(), -1); - - if(last != current) { - jumps.put(player.getUniqueId(), current); - - double yDif = (long) ((e.getTo().getY() - e.getFrom().getY()) * 1000) / 1000d; - - if((yDif < 0.035 || yDif > 0.037) && (yDif < 0.116 || yDif > 0.118)) { - Bukkit.getPluginManager().callEvent(new PlayerJumpEvent(player)); - } - } - } - } - } - - public static void register(JavaPlugin plugin) { - Bukkit.getPluginManager().registerEvents(listener, plugin); - } -} \ No newline at end of file diff --git a/src/main/java/fantasypvp/kand/items/BlazingHalo.java b/src/main/java/fantasypvp/kand/items/BlazingHalo.java index 3abd46b..996a44b 100644 --- a/src/main/java/fantasypvp/kand/items/BlazingHalo.java +++ b/src/main/java/fantasypvp/kand/items/BlazingHalo.java @@ -1,4 +1,4 @@ -package fantasypvp.kand_smp.items; +package fantasypvp.kand.items; import org.bukkit.Bukkit; import org.bukkit.ChatColor; diff --git a/src/main/java/fantasypvp/kand/items/BlazingSet.java b/src/main/java/fantasypvp/kand/items/BlazingSet.java index 70b0ccf..ed8984e 100644 --- a/src/main/java/fantasypvp/kand/items/BlazingSet.java +++ b/src/main/java/fantasypvp/kand/items/BlazingSet.java @@ -1,6 +1,6 @@ package fantasypvp.kand.items; -import fantasypvp.kand.util.attribute_gear.TierV; +import fantasypvp.kand.util.gear_templates.TierV; import org.bukkit.Material; import org.bukkit.NamespacedKey; import org.bukkit.inventory.*; @@ -68,12 +68,12 @@ public class BlazingSet { } private static void chestplate() { - ItemStack item = TierV.chestplate(); + ItemStack item = new ItemStack(Material.NETHERITE_CHESTPLATE); ItemMeta meta = item.getItemMeta(); meta.setDisplayName("§bPLACEHOLDER"); item.setItemMeta(meta); - helmet = item; + chestplate = item; NamespacedKey key = new NamespacedKey("fantasypvp.kand_smp.items", "PLACEHOLDER_CHESTPLATE"); RecipeChoice chestplate = new RecipeChoice.MaterialChoice(Material.NETHERITE_CHESTPLATE); @@ -87,7 +87,7 @@ public class BlazingSet { ItemMeta meta = item.getItemMeta(); meta.setDisplayName("§bPLACEHOLDER"); item.setItemMeta(meta); - helmet = item; + leggings = item; NamespacedKey key = new NamespacedKey("fantasypvp.kand_smp.items", "PLACEHOLDER_LEGGINGS"); RecipeChoice leggings = new RecipeChoice.MaterialChoice(Material.NETHERITE_LEGGINGS); @@ -101,7 +101,7 @@ public class BlazingSet { ItemMeta meta = item.getItemMeta(); meta.setDisplayName("§bPLACEHOLDER"); item.setItemMeta(meta); - helmet = item; + boots = item; NamespacedKey key = new NamespacedKey("fantasypvp.kand_smp.items", "PLACEHOLDER_BOOTS"); RecipeChoice boots = new RecipeChoice.MaterialChoice(Material.NETHERITE_BOOTS); diff --git a/src/main/java/fantasypvp/kand/items/BlessedSet.java b/src/main/java/fantasypvp/kand/items/BlessedSet.java new file mode 100644 index 0000000..d4783fb --- /dev/null +++ b/src/main/java/fantasypvp/kand/items/BlessedSet.java @@ -0,0 +1,118 @@ +package fantasypvp.kand.items; + +import fantasypvp.kand.util.gear_templates.TierIV; +import fantasypvp.kand.util.gear_templates.TierV; +import org.bukkit.*; +import org.bukkit.command.CommandExecutor; +import org.bukkit.entity.Egg; +import org.bukkit.entity.Item; +import org.bukkit.entity.LivingEntity; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.Listener; +import org.bukkit.event.block.Action; +import org.bukkit.event.player.PlayerInteractEvent; +import org.bukkit.inventory.EquipmentSlot; +import org.bukkit.inventory.ItemStack; +import org.bukkit.inventory.meta.ItemMeta; +import org.bukkit.util.Vector; + +import java.util.ArrayList; +import java.util.List; +import java.util.Objects; + +import static org.bukkit.Bukkit.getServer; + +public class BlessedSet implements Listener, CommandExecutor { + private ArrayList cooldown = new ArrayList<>(); + + public static ItemStack sword() { + ItemStack item = TierV.sword(); + + ItemMeta meta = item.getItemMeta(); + List lore = new ArrayList<>(); + lore.add("§fA sword blessed by Steven"); + meta.setLore(lore); + meta.setDisplayName("§bBlessed Sword"); + item.setItemMeta(meta); + + return item; + } + + @EventHandler + public void onPlayerInteract(PlayerInteractEvent event) { + Player player = event.getPlayer(); + ItemStack item = event.getItem(); // Get the item the player interacted with + + if (!(event.getAction() == Action.RIGHT_CLICK_AIR || event.getAction() == Action.RIGHT_CLICK_BLOCK)) { + return; + } + + if (item == null || event.getHand() != EquipmentSlot.HAND) { + return; + } + + try { + ItemMeta meta = item.getItemMeta(); + List lore = meta.getLore(); + if (!lore.toString().contains("§fA sword blessed by Steven")) { + return; + } + } catch (Exception e) { + return; + } + + if (cooldown.contains(player)) { + return; + } + + Egg egg = event.getPlayer().launchProjectile(Egg.class); + // set some custom hidden data for the egg that allows us to distinguish it + egg.setCustomName("blessed egg"); + + Location location = player.getLocation(); + player.playSound(location, Sound.ENTITY_GENERIC_EXPLODE, 1.0f, 1.0f); + World world = player.getWorld(); + world.spawnParticle(Particle.EXPLOSION_NORMAL, location, 1); + + cooldown.add(player); + Bukkit.getScheduler().scheduleSyncDelayedTask( + Objects.requireNonNull(Bukkit.getPluginManager().getPlugin("kand")), + () -> cooldown.remove(player), + 5 + ); + } + + @EventHandler + public void onProjectileHit(org.bukkit.event.entity.ProjectileHitEvent event) { + if (event.getEntity() instanceof Egg && ((Egg) event.getEntity()).getCustomName().equals("blessed egg")) { + ((LivingEntity) event.getHitEntity()).damage(8); + event.getEntity().getWorld().spawnParticle(Particle.EXPLOSION_NORMAL, event.getEntity().getLocation(), 1); + } + } + + @Override + public boolean onCommand(org.bukkit.command.CommandSender sender, org.bukkit.command.Command command, String label, String[] args) { + if (!(sender instanceof Player)) { + sender.sendMessage("Only players can use this command"); + return true; + } + + Player player = (Player) sender; + + if(player.hasPermission("kand.lightning_sword")) { + if (command.getName().equalsIgnoreCase("steven_gear")) { +// player.getInventory().addItem(DragonSet.helmet); +// player.getInventory().addItem(DragonSet.chestplate); +// player.getInventory().addItem(DragonSet.leggings); +// player.getInventory().addItem(DragonSet.boots); + player.getInventory().addItem(sword()); + } + + } else { + player.sendMessage(ChatColor.RED+"You don't have permission to run this command."); + } + + return true; + } +} diff --git a/src/main/java/fantasypvp/kand/items/DashItem.java b/src/main/java/fantasypvp/kand/items/DashItem.java index e439d37..190c700 100644 --- a/src/main/java/fantasypvp/kand/items/DashItem.java +++ b/src/main/java/fantasypvp/kand/items/DashItem.java @@ -1,36 +1,80 @@ package fantasypvp.kand.items; -import org.bukkit.ChatColor; -import org.bukkit.Material; +import org.bukkit.*; +import org.bukkit.command.Command; +import org.bukkit.command.CommandExecutor; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.Listener; +import org.bukkit.event.block.Action; +import org.bukkit.event.entity.EntityDamageEvent; +import org.bukkit.event.player.PlayerInteractEvent; +import org.bukkit.inventory.EquipmentSlot; import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.meta.ItemMeta; +import org.bukkit.util.Vector; import java.util.ArrayList; import java.util.List; -public class DashItem extends ItemStack { +public class DashItem extends ItemStack implements CommandExecutor, Listener { + + @EventHandler + public void onPlayerInteract(PlayerInteractEvent event) { + Player player = event.getPlayer(); + ItemStack item = event.getItem(); // Get the item the player interacted with + + // Check if the interaction was a right-click and the item is in the main hand + if (event.getAction() == Action.RIGHT_CLICK_AIR || event.getAction() == Action.RIGHT_CLICK_BLOCK) { + if (item != null && item.isSimilar(new DashItem().createDashItem()) && event.getHand() == EquipmentSlot.HAND) { + Location location = player.getLocation(); + Vector direction = location.getDirection(); + player.setVelocity(direction.multiply(5.0)); + player.playSound(location, Sound.ENTITY_DRAGON_FIREBALL_EXPLODE, 1.0f, 1.0f); + World world = player.getWorld(); + world.spawnParticle(Particle.EXPLOSION_HUGE, location, 1); + } + } + } + + @EventHandler + public void OnEntityDamage(EntityDamageEvent event){ + if(event.getEntity() instanceof Player){ + Player player = (Player) event.getEntity(); + ItemStack itemInMainHand = player.getInventory().getItemInMainHand(); + if (itemInMainHand.isSimilar(new DashItem().createDashItem()) && event.getCause() == EntityDamageEvent.DamageCause.FALL) { + event.setCancelled(true); + } + } + } + @Override + public boolean onCommand(CommandSender sender, Command command, String s, String[] args) { + if(!(sender instanceof Player)){ + sender.sendMessage("You must be a player to execute this command"); + return true; + } + + Player player = (Player) sender; + if(!(player.hasPermission("giveDashItem"))){ + player.sendMessage(ChatColor.RED+"You don't have permission to run this command."); + return true; + } + + ItemStack dashItem = new DashItem().createDashItem(); + player.getInventory().addItem(dashItem); + return true; + } public ItemStack createDashItem(){ - ItemStack item = new ItemStack(Material.STICK,1); - ItemMeta meta = item.getItemMeta(); - ListstickLore = new ArrayList<>(); stickLore.add("Click this stick and you'll be there in a jiffy."); stickLore.add("About this, don't get sniffy."); - - meta.setLore(stickLore); - meta.setDisplayName(ChatColor.AQUA+"[Dash"+ChatColor.BLUE+" Stick]"); - item.setItemMeta(meta); - return item; - - - } - } diff --git a/src/main/java/fantasypvp/kand/items/DragonSet.java b/src/main/java/fantasypvp/kand/items/DragonSet.java new file mode 100644 index 0000000..4cee47a --- /dev/null +++ b/src/main/java/fantasypvp/kand/items/DragonSet.java @@ -0,0 +1,261 @@ +package fantasypvp.kand.items; + +import fantasypvp.kand.kandMain; +import fantasypvp.kand.util.gear_templates.TierIV; +import org.bukkit.*; +import org.bukkit.attribute.Attribute; +import org.bukkit.attribute.AttributeModifier; +import org.bukkit.command.CommandExecutor; +import org.bukkit.enchantments.Enchantment; +import org.bukkit.entity.EnderDragon; +import org.bukkit.entity.Item; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.Listener; +import org.bukkit.event.block.Action; +import org.bukkit.event.player.PlayerInteractEvent; +import org.bukkit.inventory.*; +import org.bukkit.inventory.meta.ItemMeta; +import org.bukkit.loot.LootContext; +import org.bukkit.loot.LootTable; +import org.bukkit.plugin.Plugin; +import org.bukkit.util.Vector; +import org.jetbrains.annotations.NotNull; + +import java.util.*; + +public class DragonSet implements CommandExecutor, Listener, LootTable { + private ArrayList cooldown = new ArrayList<>(); + + private Plugin plugin = kandMain.getPlugin(kandMain.class); + private NamespacedKey key = new NamespacedKey(plugin, "dragon_loot"); + private Collection items = new ArrayList(); + + + @NotNull + @Override + public Collection populateLoot(Random random, LootContext context) { + int scaleCount = 32; + ItemStack dragonScales = dragonScale(); + dragonScales.setAmount(scaleCount); + items.add(dragonScales); + + return items; + } + + @Override + public void fillInventory(@NotNull Inventory inventory, @NotNull Random random, @NotNull LootContext lootContext) { + // nothing. + } + + @NotNull + @Override + public NamespacedKey getKey() { + return key; + } + + + @EventHandler + public void onPlayerInteract(PlayerInteractEvent event) { + Player player = event.getPlayer(); + ItemStack item = event.getItem(); // Get the item the player interacted with + + if (!(event.getAction() == Action.RIGHT_CLICK_AIR || event.getAction() == Action.RIGHT_CLICK_BLOCK)) { + return; + } + + if (item == null || item.getType() != Material.DIAMOND_SWORD || event.getHand() != EquipmentSlot.HAND) { + return; + } + + try { + ItemMeta meta = item.getItemMeta(); + if (!meta.getLore().toString().contains("A Blade Crafted from the essence of dragons")) { + return; + } + } catch (Exception e) { + return; + } + + if (cooldown.contains(player)) { + return; + } + + Location location = player.getLocation(); + Vector direction = location.getDirection(); + player.setVelocity(direction.multiply(2.0)); + player.playSound(location, Sound.ENTITY_ENDERMAN_TELEPORT, 1.0f, 1.0f); + World world = player.getWorld(); + world.spawnParticle(Particle.PORTAL, location, 1); + + cooldown.add(player); + Bukkit.getScheduler().scheduleSyncDelayedTask( + Objects.requireNonNull(Bukkit.getPluginManager().getPlugin("kand")), + () -> cooldown.remove(player), + 50 + ); + + } + + @EventHandler + public void onEntityDeath(org.bukkit.event.entity.EntityDeathEvent event) { + + if (event.getEntity() instanceof EnderDragon dragon) {} else { + return; + } + + event.getDrops().clear(); + Location location = dragon.getLocation(); + Player player = dragon.getKiller(); + + int looting_mod; + try { + looting_mod = player.getInventory().getItemInMainHand().getEnchantmentLevel(Enchantment.LOOT_BONUS_MOBS); + } catch (NullPointerException e) { + looting_mod = 0; + } + double luck_mod = player.getAttribute(Attribute.GENERIC_LUCK).getValue(); + + LootContext.Builder builder = new LootContext.Builder(event.getEntity().getLocation()); + builder.lootedEntity(dragon); + builder.lootingModifier(looting_mod); + builder.luck((float)luck_mod); + builder.killer(player); + LootContext lootContext = builder.build(); + + + Collection drops = new DragonSet().populateLoot(new Random(), lootContext); + ArrayList items = (ArrayList) drops; + + location.getWorld().dropItemNaturally(location, items.get(0)); + + } + + @Override + public boolean onCommand(org.bukkit.command.CommandSender sender, org.bukkit.command.Command command, String label, String[] args) { + if (!(sender instanceof Player)) { + sender.sendMessage("Only players can use this command"); + return true; + } + + Player player = (Player) sender; + + if(player.hasPermission("kand.lightning_sword")) { + if (command.getName().equalsIgnoreCase("dragon_gear")) { + player.getInventory().addItem(DragonSet.helmet()); + player.getInventory().addItem(DragonSet.chestplate()); + player.getInventory().addItem(DragonSet.leggings()); + player.getInventory().addItem(DragonSet.boots()); + player.getInventory().addItem(DragonSet.sword()); + } + + } else { + player.sendMessage(ChatColor.RED+"You don't have permission to run this command."); + } + + return true; + } + + public static ItemStack dragonScale() { + ItemStack item = new ItemStack(Material.POPPED_CHORUS_FRUIT, 1); + ItemMeta meta = item.getItemMeta(); + meta.setDisplayName(ChatColor.DARK_PURPLE + "Dragon Scale"); + + List lore = new ArrayList<>(); + String lore_line = ChatColor.GRAY + "Used to craft powerful items..."; + lore.add(lore_line); + meta.setLore(lore); + + item.setItemMeta(meta); + return item; + } + + public static ItemStack sword() { + ItemStack item = TierIV.sword(); + + ItemMeta meta = item.getItemMeta(); + List lore = new ArrayList<>(); + lore.add(ChatColor.GRAY + "A Blade Crafted from the essence of dragons"); + meta.setLore(lore); + meta.setDisplayName(ChatColor.WHITE + "Dragon Sword"); + item.setItemMeta(meta); + return item; + } + + public static ItemStack helmet() { + ItemStack item = new ItemStack(Material.DRAGON_HEAD); + ItemMeta meta = item.getItemMeta(); + + meta.addAttributeModifier(Attribute.GENERIC_ARMOR, new AttributeModifier( + UUID.randomUUID(), + "generic.armor", + 3.0, + AttributeModifier.Operation.ADD_NUMBER, + EquipmentSlot.HEAD + )); + meta.addAttributeModifier(Attribute.GENERIC_ARMOR_TOUGHNESS, new AttributeModifier( + UUID.randomUUID(), + "generic.armorToughness", + 2.0, + AttributeModifier.Operation.ADD_NUMBER, + EquipmentSlot.HEAD + )); + + List lore = new ArrayList<>(); + lore.add(ChatColor.GRAY + "A Helm Crafted from the essence of dragons"); + meta.setLore(lore); + meta.setDisplayName(ChatColor.WHITE + "Dragon Helmet"); + item.setItemMeta(meta); + return item; + } + + public static ItemStack chestplate() { + ItemStack item = new ItemStack(Material.ELYTRA); + + ItemMeta meta = item.getItemMeta(); + meta.addAttributeModifier(Attribute.GENERIC_ARMOR, new AttributeModifier( + UUID.randomUUID(), + "generic.armor", + 8.0, + AttributeModifier.Operation.ADD_NUMBER, + EquipmentSlot.CHEST + )); + meta.addAttributeModifier(Attribute.GENERIC_ARMOR_TOUGHNESS, new AttributeModifier( + UUID.randomUUID(), + "generic.armorToughness", + 2.0, + AttributeModifier.Operation.ADD_NUMBER, + EquipmentSlot.CHEST + )); + List lore = new ArrayList<>(); + lore.add(ChatColor.GRAY + "A Chestplate Crafted from the essence of dragons"); + meta.setLore(lore); + meta.setDisplayName(ChatColor.WHITE + "Dragon Chestplate"); + item.setItemMeta(meta); + return item; + } + + public static ItemStack leggings() { + ItemStack item = TierIV.leggings(); + + ItemMeta meta = item.getItemMeta(); + List lore = new ArrayList<>(); + lore.add(ChatColor.GRAY + "Leggings Crafted from the essence of dragons"); + meta.setLore(lore); + meta.setDisplayName(ChatColor.WHITE + "Dragon Leggings"); + item.setItemMeta(meta); + return item; + } + + public static ItemStack boots() { + ItemStack item = TierIV.boots(); + + ItemMeta meta = item.getItemMeta(); + List lore = new ArrayList<>(); + lore.add(ChatColor.GRAY + "Boots Crafted from the essence of dragons"); + meta.setLore(lore); + meta.setDisplayName(ChatColor.WHITE + "Dragon Boots"); + item.setItemMeta(meta); + return item; + } +} \ No newline at end of file diff --git a/src/main/java/fantasypvp/kand/items/GearTemplate.java b/src/main/java/fantasypvp/kand/items/GearTemplate.java index 45f26b1..c643b05 100644 --- a/src/main/java/fantasypvp/kand/items/GearTemplate.java +++ b/src/main/java/fantasypvp/kand/items/GearTemplate.java @@ -1,6 +1,6 @@ package fantasypvp.kand.items; -import fantasypvp.kand.util.attribute_gear.TierV; +import fantasypvp.kand.util.gear_templates.TierV; import org.bukkit.Material; import org.bukkit.NamespacedKey; import org.bukkit.inventory.*; diff --git a/src/main/java/fantasypvp/kand/items/LightningGear.java b/src/main/java/fantasypvp/kand/items/LightningGear.java index 2855cf1..6bd8ef2 100644 --- a/src/main/java/fantasypvp/kand/items/LightningGear.java +++ b/src/main/java/fantasypvp/kand/items/LightningGear.java @@ -1,32 +1,75 @@ package fantasypvp.kand.items; -import fantasypvp.kand.util.attribute_gear.TierVI; +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.command.CommandExecutor; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.Listener; import org.bukkit.inventory.*; import org.bukkit.inventory.meta.ItemMeta; import java.util.ArrayList; +import java.util.EventListener; import java.util.List; import java.util.UUID; import static org.bukkit.Bukkit.getServer; -public class LightningGear { - public static ItemStack lightning_sword; +public class LightningGear implements Listener, CommandExecutor { - public static void init() { - lightningSword(); + @EventHandler + public static void onEntityDamageByEntity(org.bukkit.event.entity.EntityDamageByEntityEvent event) { + + if (event.getDamager() instanceof org.bukkit.entity.Player) { + Player player = (Player) event.getDamager(); + // check if the player is using the lightning sword + + try { + player.getInventory().getItemInMainHand().getItemMeta().getLore().toString(); + } catch (NullPointerException e) { + return; + } + + if (player.getInventory().getItemInMainHand().getItemMeta().getLore().toString().contains(ChatColor.YELLOW + "All Who Oppose Shall Be SMITTEN!")) { + // check if hit is critical + if (player.getFallDistance() > 0.0F && !player.isInsideVehicle() && !player.isGliding() && !player.isSwimming() && !player.isClimbing() && player.getAttackCooldown() == 1.0F) { + player.getWorld().strikeLightningEffect(event.getEntity().getLocation()); + } + } + } } - private static void lightningSword() { + @Override + public boolean onCommand(org.bukkit.command.CommandSender sender, org.bukkit.command.Command command, String label, String[] args) { + if (!(sender instanceof Player)) { + sender.sendMessage("Only players can use this command"); + return true; + } + + Player player = (Player) sender; + + if(player.hasPermission("kand.lightning_sword")) { + if (command.getName().equalsIgnoreCase("lightning_sword")) { + player.getInventory().addItem(lightningSword()); + } + + } else { + player.sendMessage(ChatColor.RED+"You don't have permission to run this command."); + } + + return true; + } + + public static ItemStack lightningSword() { ItemStack item = new ItemStack(Material.NETHERITE_SWORD, 1); ItemMeta meta = item.getItemMeta(); meta.setDisplayName("Lightning Sword"); List lore = new ArrayList<>(); - lore.add("§7All who oppose shall be smitten"); + lore.add(ChatColor.YELLOW + "All Who Oppose Shall Be SMITTEN!"); meta.setLore(lore); // set damage to 12 when in main hand UUID uuid = UUID.randomUUID(); @@ -46,7 +89,6 @@ public class LightningGear { EquipmentSlot.HAND )); item.setItemMeta(meta); - lightning_sword = item; // shaped recipe ShapedRecipe recipe = new ShapedRecipe(NamespacedKey.minecraft("lightning_sword"), item); @@ -59,6 +101,7 @@ public class LightningGear { recipe.setIngredient('H', Material.LIGHTNING_ROD); getServer().addRecipe(recipe); + return item; } } diff --git a/src/main/java/fantasypvp/kand/items/TrueNetherite.java b/src/main/java/fantasypvp/kand/items/TrueNetherite.java index 59749ff..753a637 100644 --- a/src/main/java/fantasypvp/kand/items/TrueNetherite.java +++ b/src/main/java/fantasypvp/kand/items/TrueNetherite.java @@ -1,6 +1,6 @@ package fantasypvp.kand.items; -import fantasypvp.kand.util.attribute_gear.TierVI; +import fantasypvp.kand.util.gear_templates.TierVI; import org.bukkit.Material; import org.bukkit.NamespacedKey; import org.bukkit.attribute.Attribute; diff --git a/src/main/java/fantasypvp/kand/items/Witherite.java b/src/main/java/fantasypvp/kand/items/Witherite.java index 7e7ee95..9746fac 100644 --- a/src/main/java/fantasypvp/kand/items/Witherite.java +++ b/src/main/java/fantasypvp/kand/items/Witherite.java @@ -1,123 +1,170 @@ package fantasypvp.kand.items; -import fantasypvp.kand.util.attribute_gear.TierV; +import fantasypvp.kand.util.gear_templates.TierV; +import org.bukkit.ChatColor; import org.bukkit.Material; import org.bukkit.NamespacedKey; +import org.bukkit.entity.Item; +import org.bukkit.entity.LivingEntity; +import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.bukkit.event.Listener; -import org.bukkit.event.inventory.PrepareSmithingEvent; import org.bukkit.inventory.*; import org.bukkit.inventory.meta.ItemMeta; +import org.bukkit.potion.PotionEffect; import java.util.ArrayList; import java.util.List; import static org.bukkit.Bukkit.getServer; -public class Witherite { - public static ItemStack sword; - public static ItemStack helmet; - public static ItemStack chestplate; - public static ItemStack leggings; - public static ItemStack boots; +public class Witherite implements Listener { + private static RecipeChoice netherite_upgrade = new RecipeChoice.MaterialChoice(Material.NETHERITE_UPGRADE_SMITHING_TEMPLATE); + private static RecipeChoice wither_skull = new RecipeChoice.MaterialChoice(Material.WITHER_SKELETON_SKULL); - private static RecipeChoice netherite_upgrade; - private static RecipeChoice wither_skull; - public static void init() { - netherite_upgrade = new RecipeChoice.MaterialChoice(Material.NETHERITE_UPGRADE_SMITHING_TEMPLATE); - wither_skull = new RecipeChoice.MaterialChoice(Material.WITHER_SKELETON_SKULL); + @EventHandler + public void onEntityDamageByEntity(org.bukkit.event.entity.EntityDamageByEntityEvent event) { + + // checks that it is a player that is performing the attack. + if (!(event.getDamager() instanceof org.bukkit.entity.Player player)) { + return; + } + + try { + if (!player.getInventory().getItemInMainHand().getItemMeta().getLore().toString().contains("Blade Of The Wither")) { + return; + } + } catch (Exception e) { + e.printStackTrace(); + return; + } + + PotionEffect effect = new PotionEffect( + org.bukkit.potion.PotionEffectType.WITHER, + 20 * 5, + 1 + ); + effect.apply((LivingEntity) event.getEntity()); - sword(); - helmet(); - chestplate(); - leggings(); - boots(); } - private static void sword() { + @EventHandler + public void onEntityPotionEffectEvent(org.bukkit.event.entity.EntityPotionEffectEvent event) { + if (event.getEntity() instanceof Player player) { + try { + if (player.getInventory().getHelmet().getItemMeta().getLore().toString().contains("Helm Of The Wither") + && player.getInventory().getChestplate().getItemMeta().getLore().toString().contains("Chestplate Of The Wither") + && player.getInventory().getLeggings().getItemMeta().getLore().toString().contains("Leggings Of The Wither") + && player.getInventory().getBoots().getItemMeta().getLore().toString().contains("Boots Of The Wither")) { + event.setCancelled(true); + } + } catch (Exception e) { + e.printStackTrace(); + } + } + } + + private static ItemStack sword; + private static ItemStack helmet; + private static ItemStack chestplate; + private static ItemStack leggings; + private static ItemStack boots; + + public static void init() { ItemStack item = TierV.sword(); ItemMeta meta = item.getItemMeta(); - meta.setDisplayName("§bWitherite Sword"); - List lore = new ArrayList<>(); - lore.add("§f[T5+] Witherite Sword"); + lore.add(ChatColor.GRAY + "Blade Of The Wither"); meta.setLore(lore); + meta.setDisplayName(ChatColor.WHITE + "Witherite Sword"); item.setItemMeta(meta); - sword = item; NamespacedKey key = new NamespacedKey("fantasypvp.kand_smp.items", "witherite_sword"); RecipeChoice netherite_sword = new RecipeChoice.MaterialChoice(Material.NETHERITE_SWORD); SmithingTransformRecipe recipe = new SmithingTransformRecipe(key, item, netherite_upgrade, wither_skull, netherite_sword); getServer().addRecipe(recipe); + sword = item; + + // Initialize Witherite Helmet + ItemStack helmetItem = TierV.helmet(); + ItemMeta helmetMeta = helmetItem.getItemMeta(); + List helmetLore = new ArrayList<>(); + helmetLore.add(ChatColor.GRAY + "Helm Of The Wither"); + helmetMeta.setLore(helmetLore); + helmetMeta.setDisplayName(ChatColor.WHITE + "Witherite Helmet"); + helmetItem.setItemMeta(helmetMeta); + + NamespacedKey helmetKey = new NamespacedKey("fantasypvp.kand_smp.items", "witherite_helmet"); + RecipeChoice netheriteHelmet = new RecipeChoice.MaterialChoice(Material.NETHERITE_HELMET); + SmithingTransformRecipe helmetRecipe = new SmithingTransformRecipe(helmetKey, helmetItem, netherite_upgrade, wither_skull, netheriteHelmet); + getServer().addRecipe(helmetRecipe); + helmet = helmetItem; + + // Initialize Witherite Chestplate + ItemStack chestplateItem = TierV.chestplate(); + ItemMeta chestplateMeta = chestplateItem.getItemMeta(); + List chestplateLore = new ArrayList<>(); + chestplateLore.add(ChatColor.GRAY + "Chestplate Of The Wither"); + chestplateMeta.setLore(chestplateLore); + chestplateMeta.setDisplayName(ChatColor.WHITE + "Witherite Chestplate"); + chestplateItem.setItemMeta(chestplateMeta); + + NamespacedKey chestplateKey = new NamespacedKey("fantasypvp.kand_smp.items", "witherite_chestplate"); + RecipeChoice netheriteChestplate = new RecipeChoice.MaterialChoice(Material.NETHERITE_CHESTPLATE); + SmithingTransformRecipe chestplateRecipe = new SmithingTransformRecipe(chestplateKey, chestplateItem, netherite_upgrade, wither_skull, netheriteChestplate); + getServer().addRecipe(chestplateRecipe); + chestplate = chestplateItem; + + // Initialize Witherite Leggings + ItemStack leggingsItem = TierV.leggings(); + ItemMeta leggingsMeta = leggingsItem.getItemMeta(); + List leggingsLore = new ArrayList<>(); + leggingsLore.add(ChatColor.GRAY + "Leggings Of The Wither"); + leggingsMeta.setLore(leggingsLore); + leggingsMeta.setDisplayName(ChatColor.WHITE + "Witherite Leggings"); + leggingsItem.setItemMeta(leggingsMeta); + + NamespacedKey leggingsKey = new NamespacedKey("fantasypvp.kand_smp.items", "witherite_leggings"); + RecipeChoice netheriteLeggings = new RecipeChoice.MaterialChoice(Material.NETHERITE_LEGGINGS); + SmithingTransformRecipe leggingsRecipe = new SmithingTransformRecipe(leggingsKey, leggingsItem, netherite_upgrade, wither_skull, netheriteLeggings); + getServer().addRecipe(leggingsRecipe); + leggings = leggingsItem; + + // Initialize Witherite Boots + ItemStack bootsItem = TierV.boots(); + ItemMeta bootsMeta = bootsItem.getItemMeta(); + List bootsLore = new ArrayList<>(); + bootsLore.add(ChatColor.GRAY + "Boots Of The Wither"); + bootsMeta.setLore(bootsLore); + bootsMeta.setDisplayName(ChatColor.WHITE + "Witherite Boots"); + bootsItem.setItemMeta(bootsMeta); + + NamespacedKey bootsKey = new NamespacedKey("fantasypvp.kand_smp.items", "witherite_boots"); + RecipeChoice netheriteBoots = new RecipeChoice.MaterialChoice(Material.NETHERITE_BOOTS); + SmithingTransformRecipe bootsRecipe = new SmithingTransformRecipe(bootsKey, bootsItem, netherite_upgrade, wither_skull, netheriteBoots); + getServer().addRecipe(bootsRecipe); + boots = bootsItem; } - private static void helmet() { - ItemStack item = TierV.helmet(); - - ItemMeta meta = item.getItemMeta(); - List lore = new ArrayList<>(); - lore.add("§f[T5+] Witherite Helmet"); - meta.setLore(lore); - meta.setDisplayName("§bWitherite Helmet"); - item.setItemMeta(meta); - helmet = item; - - NamespacedKey key = new NamespacedKey("fantasypvp.kand_smp.items", "witherite_helmet"); - RecipeChoice netherite_helmet = new RecipeChoice.MaterialChoice(Material.NETHERITE_HELMET); - SmithingTransformRecipe recipe = new SmithingTransformRecipe(key, item, netherite_upgrade, wither_skull, netherite_helmet); - getServer().addRecipe(recipe); + public static ItemStack sword() { + return sword; } - private static void chestplate() { - ItemStack item = TierV.chestplate(); - - ItemMeta meta = item.getItemMeta(); - List lore = new ArrayList<>(); - lore.add("§f[T5+] Witherite Chestplate"); - meta.setLore(lore); - meta.setDisplayName("§bWitherite Chestplate"); - item.setItemMeta(meta); - helmet = item; - - NamespacedKey key = new NamespacedKey("fantasypvp.kand_smp.items", "witherite_chestplate"); - RecipeChoice netherite_chestplate = new RecipeChoice.MaterialChoice(Material.NETHERITE_CHESTPLATE); - SmithingTransformRecipe recipe = new SmithingTransformRecipe(key, item, netherite_upgrade, wither_skull, netherite_chestplate); - getServer().addRecipe(recipe); + public static ItemStack helmet() { + return helmet; } - private static void leggings() { - ItemStack item = TierV.leggings(); - - ItemMeta meta = item.getItemMeta(); - List lore = new ArrayList<>(); - lore.add("§f[T5+] Witherite Leggings"); - meta.setLore(lore); - meta.setDisplayName("§bWitherite Leggings"); - item.setItemMeta(meta); - helmet = item; - - NamespacedKey key = new NamespacedKey("fantasypvp.kand_smp.items", "witherite_leggings"); - RecipeChoice netherite_leggings = new RecipeChoice.MaterialChoice(Material.NETHERITE_LEGGINGS); - SmithingTransformRecipe recipe = new SmithingTransformRecipe(key, item, netherite_upgrade, wither_skull, netherite_leggings); - getServer().addRecipe(recipe); + public static ItemStack chestplate() { + return chestplate; } - private static void boots() { - ItemStack item = TierV.boots(); + public static ItemStack leggings() { + return leggings; + } - ItemMeta meta = item.getItemMeta(); - List lore = new ArrayList<>(); - lore.add("§f[T5+] Witherite Boots"); - meta.setLore(lore); - meta.setDisplayName("§bWitherite Boots"); - item.setItemMeta(meta); - helmet = item; - - NamespacedKey key = new NamespacedKey("fantasypvp.kand_smp.items", "witherite_boots"); - RecipeChoice netherite_boots = new RecipeChoice.MaterialChoice(Material.NETHERITE_BOOTS); - SmithingTransformRecipe recipe = new SmithingTransformRecipe(key, item, netherite_upgrade, wither_skull, netherite_boots); - getServer().addRecipe(recipe); + public static ItemStack boots() { + return boots; } } \ No newline at end of file diff --git a/src/main/java/fantasypvp/kand/kandMain.java b/src/main/java/fantasypvp/kand/kandMain.java index b60443d..529de95 100644 --- a/src/main/java/fantasypvp/kand/kandMain.java +++ b/src/main/java/fantasypvp/kand/kandMain.java @@ -1,11 +1,11 @@ package fantasypvp.kand; import fantasypvp.kand.commands.*; -import fantasypvp.kand.events.DashItemListener; -import fantasypvp.kand.events.Events; -import fantasypvp.kand.events.PlayerJumpEvent; +import fantasypvp.kand.events.*; import fantasypvp.kand.items.*; +import org.bukkit.loot.LootTable; +import org.bukkit.loot.LootTables; import org.bukkit.plugin.java.JavaPlugin; public final class kandMain extends JavaPlugin { @@ -13,26 +13,39 @@ public final class kandMain extends JavaPlugin { @Override public void onEnable() { // Plugin startup logic - LightningGear.init(); TrueNetherite.init(); - Witherite.init(); CustomDrinks.init(); KandCoin.init(); - // register listeners - getServer().getPluginManager().registerEvents(new Events(), this); - getServer().getPluginManager().registerEvents(new DashItemListener(),this); - getServer().getPluginManager().registerEvents(new CustomDrinks(), this); - getServer().getPluginManager().registerEvents(new KandCoinCmd(), this); - PlayerJumpEvent.register(this); - getCommand("lightning_sword").setExecutor(new CmdLightningSword()); getCommand("spawn").setExecutor(new CmdTeleportSpawn(this)); getCommand("setglobalspawn").setExecutor(new SetSpawnCommand(this)); - getCommand("dashstick").setExecutor(new GiveDashItemCmd()); getCommand("get_currency").setExecutor(new KandCoinCmd()); + // register listeners + getServer().getPluginManager().registerEvents(new CustomDrinks(), this); + getServer().getPluginManager().registerEvents(new KandCoinCmd(), this); + getServer().getPluginManager().registerEvents(new FireDamageListener(), this); + BlessedSet steven_gear = new BlessedSet(); + getServer().getPluginManager().registerEvents(steven_gear, this); + getCommand("steven_gear").setExecutor(steven_gear); - getServer().broadcastMessage("§aKand SMP 2 has been enabled!"); + DragonSet dragon_gear = new DragonSet(); + getServer().getPluginManager().registerEvents(dragon_gear, this); + getCommand("dragon_gear").setExecutor(dragon_gear); + + DashItem dash_stick = new DashItem(); + getServer().getPluginManager().registerEvents(dash_stick, this); + getCommand("dashstick").setExecutor(dash_stick); + + LightningGear lightning_sword = new LightningGear(); + getServer().getPluginManager().registerEvents(lightning_sword, this); + getCommand("lightning_sword").setExecutor(lightning_sword); + + Witherite witherite_gear = new Witherite(); + Witherite.init(); + getServer().getPluginManager().registerEvents(witherite_gear, this); + + getServer().broadcastMessage("§aKand SMP Plugin has been enabled!"); } @Override diff --git a/src/main/java/fantasypvp/kand/teams/Team.java b/src/main/java/fantasypvp/kand/teams/Team.java new file mode 100644 index 0000000..3f5ceb4 --- /dev/null +++ b/src/main/java/fantasypvp/kand/teams/Team.java @@ -0,0 +1,117 @@ +package fantasypvp.kand.teams; +import org.bukkit.plugin.java.JavaPlugin; +import org.json.simple.JSONArray; +import org.json.simple.JSONObject; +import org.json.simple.parser.JSONParser; +import org.json.simple.parser.ParseException; + +import java.io.*; +import java.lang.reflect.Member; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.UUID; + +public class Team { + public String name; + public HashMap members; + public String tag; + + + public static void newTeam(JavaPlugin plugin, String name, UUID founder) throws Exception { + + JSONParser parser = new JSONParser(); + JSONArray teams; + + File f = plugin.getDataFolder().toPath().resolve("teams.json").toFile(); + if (f.exists()) { + Object obj; + try { + obj = parser.parse(new FileReader(f)); + teams = (JSONArray) obj; + } catch (ParseException e) { + throw new Exception("Unable to parse teams.json", e); + } + } else { + teams = new JSONArray(); + } + + JSONObject members = new JSONObject(); + members.put(founder.toString(), "founder"); + + JSONObject team = new JSONObject(); + + team.put("name", name); + team.put("members", members); + + // write the team to the json file + teams.add(team); + try (FileWriter file = new FileWriter(f)) { + file.write(teams.toJSONString()); + } + } + + public Team(JavaPlugin plugin, String name) throws Exception { + JSONParser parser = new JSONParser(); + JSONObject team; + + File f = plugin.getDataFolder().toPath().resolve("teams.json").toFile(); + if (f.exists()) { + Object obj; + try { + obj = parser.parse(new FileReader(f)); + JSONArray teams = (JSONArray) obj; + + for (int i = 0; i < teams.size(); i++) { + if (((JSONObject) teams.get(i)).get("name") == name) { + team = (JSONObject) teams.get(i); + } + } + + } catch (ParseException e) { + throw new Exception("Unable to parse teams.json", e); + } + } else { + throw new Exception("specified team does not exist"); + } + } + + private void saveState(JavaPlugin plugin) { + + } + + public void setName(String name) { + this.name = name; + + } +} + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/main/java/fantasypvp/kand/util/attribute_gear/TierBase.java b/src/main/java/fantasypvp/kand/util/gear_templates/TierBase.java similarity index 93% rename from src/main/java/fantasypvp/kand/util/attribute_gear/TierBase.java rename to src/main/java/fantasypvp/kand/util/gear_templates/TierBase.java index ca14877..f525a57 100644 --- a/src/main/java/fantasypvp/kand/util/attribute_gear/TierBase.java +++ b/src/main/java/fantasypvp/kand/util/gear_templates/TierBase.java @@ -1,4 +1,4 @@ -package fantasypvp.kand.util.attribute_gear; +package fantasypvp.kand.util.gear_templates; import org.bukkit.Material; import org.bukkit.inventory.ItemStack; diff --git a/src/main/java/fantasypvp/kand/util/attribute_gear/TierIII.java b/src/main/java/fantasypvp/kand/util/gear_templates/TierIII.java similarity index 98% rename from src/main/java/fantasypvp/kand/util/attribute_gear/TierIII.java rename to src/main/java/fantasypvp/kand/util/gear_templates/TierIII.java index 4ada176..f19f42b 100644 --- a/src/main/java/fantasypvp/kand/util/attribute_gear/TierIII.java +++ b/src/main/java/fantasypvp/kand/util/gear_templates/TierIII.java @@ -1,4 +1,4 @@ -package fantasypvp.kand.util.attribute_gear; +package fantasypvp.kand.util.gear_templates; import org.bukkit.Material; import org.bukkit.attribute.Attribute; diff --git a/src/main/java/fantasypvp/kand/util/attribute_gear/TierIV.java b/src/main/java/fantasypvp/kand/util/gear_templates/TierIV.java similarity index 98% rename from src/main/java/fantasypvp/kand/util/attribute_gear/TierIV.java rename to src/main/java/fantasypvp/kand/util/gear_templates/TierIV.java index 36c5228..09826d5 100644 --- a/src/main/java/fantasypvp/kand/util/attribute_gear/TierIV.java +++ b/src/main/java/fantasypvp/kand/util/gear_templates/TierIV.java @@ -1,4 +1,4 @@ -package fantasypvp.kand.util.attribute_gear; +package fantasypvp.kand.util.gear_templates; import org.bukkit.Material; import org.bukkit.attribute.Attribute; diff --git a/src/main/java/fantasypvp/kand/util/attribute_gear/TierV.java b/src/main/java/fantasypvp/kand/util/gear_templates/TierV.java similarity index 99% rename from src/main/java/fantasypvp/kand/util/attribute_gear/TierV.java rename to src/main/java/fantasypvp/kand/util/gear_templates/TierV.java index 2094cf9..ddb1896 100644 --- a/src/main/java/fantasypvp/kand/util/attribute_gear/TierV.java +++ b/src/main/java/fantasypvp/kand/util/gear_templates/TierV.java @@ -1,4 +1,4 @@ -package fantasypvp.kand.util.attribute_gear; +package fantasypvp.kand.util.gear_templates; import org.bukkit.Material; import org.bukkit.attribute.Attribute; diff --git a/src/main/java/fantasypvp/kand/util/attribute_gear/TierVI.java b/src/main/java/fantasypvp/kand/util/gear_templates/TierVI.java similarity index 99% rename from src/main/java/fantasypvp/kand/util/attribute_gear/TierVI.java rename to src/main/java/fantasypvp/kand/util/gear_templates/TierVI.java index f4f019c..94b03bc 100644 --- a/src/main/java/fantasypvp/kand/util/attribute_gear/TierVI.java +++ b/src/main/java/fantasypvp/kand/util/gear_templates/TierVI.java @@ -1,4 +1,4 @@ -package fantasypvp.kand.util.attribute_gear; +package fantasypvp.kand.util.gear_templates; import org.bukkit.Material; import org.bukkit.attribute.Attribute; diff --git a/src/main/java/fantasypvp/kand/util/playerCoords.java b/src/main/java/fantasypvp/kand/util/playerCoords.java new file mode 100644 index 0000000..e337b1d --- /dev/null +++ b/src/main/java/fantasypvp/kand/util/playerCoords.java @@ -0,0 +1,16 @@ +package fantasypvp.kand.util; +import org.bukkit.entity.Player; + +public class playerCoords { + + public static String get(Player player) { + + String x,y,z; + + x=String.format("%.0f",player.getLocation().getX()); + y=String.format("%.0f",player.getLocation().getY()); + z=String.format("%.0f",player.getLocation().getZ()); + + return (x +" " + y + " "+ z); + } +} diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml index d8167b7..52fe796 100644 --- a/src/main/resources/plugin.yml +++ b/src/main/resources/plugin.yml @@ -6,6 +6,9 @@ commands: lightning_sword: description: Give player a lightning sword usage: /lightning_sword + dragon_gear: + description: Give player dragon gear + usage: /dragon_gear spawn: description: Spawn player usage: /spawn @@ -18,6 +21,9 @@ commands: get_currency: description: get currency usage: /get_currency + steven_gear: + description: Give player steven gear + usage: /steven_gear @@ -26,6 +32,7 @@ permissions: description: provides access to all kand commands children: kand.lightning_sword: true + kand.dragon_gear: true kand.spawn: true kand.setglobalspawn: true kand.dashstick: true @@ -34,6 +41,9 @@ permissions: kand.lightning_sword: description: Allows player to run /lightning_sword default: op + kand.dragon_gear: + description: Allows player to run /dragon_gear + default: op kand.setglobalspawn: description: Allows player to run /setglobalspawn default: op