.
This commit is contained in:
FantasyPvP
2024-05-01 00:25:09 +01:00
parent 8993d000a9
commit 13458a0520
7 changed files with 108 additions and 7 deletions
@@ -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!");
}
@@ -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;
}
}
@@ -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;
}
}
@@ -1,5 +0,0 @@
package fantasypvp.kand_smp.commands;
public class Commands {
}
@@ -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());
}
}
}
}
@@ -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<String> 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);
+7
View File
@@ -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