diff --git a/src/main/java/fantasypvp/kand_smp/Kand_smp.java b/src/main/java/fantasypvp/kand_smp/Kand_smp.java index e61dff6..05901d9 100644 --- a/src/main/java/fantasypvp/kand_smp/Kand_smp.java +++ b/src/main/java/fantasypvp/kand_smp/Kand_smp.java @@ -1,5 +1,7 @@ package fantasypvp.kand_smp; +import fantasypvp.kand_smp.commands.CmdLightningSword; +import fantasypvp.kand_smp.commands.CmdTeleportSpawn; import fantasypvp.kand_smp.events.Events; import fantasypvp.kand_smp.items.Items; import org.bukkit.plugin.java.JavaPlugin; @@ -13,6 +15,9 @@ public final class Kand_smp extends JavaPlugin { // register listeners getServer().getPluginManager().registerEvents(new Events(), this); + getCommand("lightning_sword").setExecutor(new CmdLightningSword()); + getCommand("spawn").setExecutor(new CmdTeleportSpawn()); + getServer().broadcastMessage("§aKand SMP has been enabled!"); } diff --git a/src/main/java/fantasypvp/kand_smp/commands/CmdLightningSword.java b/src/main/java/fantasypvp/kand_smp/commands/CmdLightningSword.java new file mode 100644 index 0000000..a9a3d57 --- /dev/null +++ b/src/main/java/fantasypvp/kand_smp/commands/CmdLightningSword.java @@ -0,0 +1,24 @@ +package fantasypvp.kand_smp.commands; + +import fantasypvp.kand_smp.items.Items; +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 (command.getName().equalsIgnoreCase("lightning_sword")) { + player.getInventory().addItem(Items.lightning_sword); + } + + return true; + } +} + diff --git a/src/main/java/fantasypvp/kand_smp/commands/CmdTeleportSpawn.java b/src/main/java/fantasypvp/kand_smp/commands/CmdTeleportSpawn.java new file mode 100644 index 0000000..9a8dee5 --- /dev/null +++ b/src/main/java/fantasypvp/kand_smp/commands/CmdTeleportSpawn.java @@ -0,0 +1,22 @@ +package fantasypvp.kand_smp.commands; + +import org.bukkit.Location; +import org.bukkit.command.CommandExecutor; +import org.bukkit.entity.Player; + + +public class CmdTeleportSpawn implements CommandExecutor { + public boolean onCommand(org.bukkit.command.CommandSender sender, org.bukkit.command.Command command, String label, String[] args) { + if (command.getName().equalsIgnoreCase("spawn")) { + if (!(sender instanceof Player)) { + sender.sendMessage("Only players can use this command"); + return true; + } + } + Player player = (Player) sender; + Location location = player.getWorld().getSpawnLocation(); + + player.teleport(location); + return true; + } +} diff --git a/src/main/java/fantasypvp/kand_smp/commands/Commands.java b/src/main/java/fantasypvp/kand_smp/commands/Commands.java deleted file mode 100644 index 0f770fb..0000000 --- a/src/main/java/fantasypvp/kand_smp/commands/Commands.java +++ /dev/null @@ -1,5 +0,0 @@ -package fantasypvp.kand_smp.commands; - -public class Commands { - -} diff --git a/src/main/java/fantasypvp/kand_smp/events/Events.java b/src/main/java/fantasypvp/kand_smp/events/Events.java index 096a6d3..e07a226 100644 --- a/src/main/java/fantasypvp/kand_smp/events/Events.java +++ b/src/main/java/fantasypvp/kand_smp/events/Events.java @@ -1,11 +1,25 @@ package fantasypvp.kand_smp.events; import org.bukkit.event.Listener; - +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; import static org.bukkit.Bukkit.getServer; public class Events implements Listener { + @EventHandler public static void onPlayerJoin(org.bukkit.event.player.PlayerJoinEvent event) { getServer().broadcastMessage("§a" + event.getPlayer().getName() + " has joined the server!"); } + + @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 + if (player.getInventory().getItemInMainHand().getType() == org.bukkit.Material.NETHERITE_SWORD && player.getInventory().getItemInMainHand().getItemMeta().getDisplayName().equals("Lightning Sword")) { + player.getWorld().strikeLightning(event.getEntity().getLocation()); + } + } + } } diff --git a/src/main/java/fantasypvp/kand_smp/items/Items.java b/src/main/java/fantasypvp/kand_smp/items/Items.java index 565ea63..feee1f3 100644 --- a/src/main/java/fantasypvp/kand_smp/items/Items.java +++ b/src/main/java/fantasypvp/kand_smp/items/Items.java @@ -18,7 +18,7 @@ public class Items { public static ItemStack true_netherite_chestplate; public static ItemStack true_netherite_leggings; public static ItemStack true_netherite_boots; - + public static ItemStack lightning_sword; public static void init() { trueNetheriteSword(); @@ -26,8 +26,42 @@ public class Items { trueNetheriteChestplate(); trueNetheriteLeggings(); trueNetheriteBoots(); + lightningSword(); } + private static void 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"); + meta.setLore(lore); + // set damage to 12 when in main hand + meta.addAttributeModifier( + Attribute.GENERIC_ATTACK_DAMAGE, + new AttributeModifier( + "generic.attackDamage", + 12, + AttributeModifier.Operation.ADD_NUMBER + ) + ); + item.setItemMeta(meta); + lightning_sword = item; + + meta.addItemFlags(ItemFlag.HIDE_ATTRIBUTES); + + // shaped recipe + ShapedRecipe recipe = new ShapedRecipe(NamespacedKey.minecraft("lightning_sword"), item); + recipe.shape( + " X", + " X ", + "H " + ); + recipe.setIngredient('X', Material.NETHER_STAR); + recipe.setIngredient('H', Material.LIGHTNING_ROD); + + getServer().addRecipe(recipe); + } private static void trueNetheriteSword() { ItemStack item = new ItemStack(Material.NETHERITE_SWORD, 1); diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml index 5ee8599..7416bdc 100644 --- a/src/main/resources/plugin.yml +++ b/src/main/resources/plugin.yml @@ -2,3 +2,10 @@ name: kand_smp version: '${project.version}' main: fantasypvp.kand_smp.Kand_smp api-version: '1.20' +commands: + lightning_sword: + description: Give player a lightning sword + usage: /lightning_sword + spawn: + description: Spawn player + usage: /spawn \ No newline at end of file