diff --git a/.idea/dictionaries/project.xml b/.idea/dictionaries/project.xml index 86d7394..247460f 100644 --- a/.idea/dictionaries/project.xml +++ b/.idea/dictionaries/project.xml @@ -1,6 +1,7 @@ + instantdeath temurin diff --git a/pom.xml b/pom.xml index 2f3da27..7d98d06 100644 --- a/pom.xml +++ b/pom.xml @@ -6,7 +6,7 @@ its.felk InstantDeath - 1.0.0 + 2.0.0 jar InstantDeath @@ -27,7 +27,6 @@ - org.bukkit craftbukkit @@ -58,30 +57,6 @@ org.apache.maven.plugins maven-shade-plugin 3.2.4 - - - package - - shade - - - - - *:* - - - org/bukkit/craftbukkit/libs/** - org/sqlite/** - org/apache/commons/io/** - org/fusesource/** - org/ibex/** - com/mysql/** - - - - - - diff --git a/src/main/java/its/felk/instantdeath/InstantDeath.java b/src/main/java/its/felk/instantdeath/InstantDeath.java deleted file mode 100644 index 43aa87a..0000000 --- a/src/main/java/its/felk/instantdeath/InstantDeath.java +++ /dev/null @@ -1,103 +0,0 @@ -package its.felk.instantdeath; - -import org.bukkit.ChatColor; -import org.bukkit.command.Command; -import org.bukkit.command.CommandSender; -import org.bukkit.entity.Player; -import org.bukkit.plugin.java.JavaPlugin; - -public final class InstantDeath extends JavaPlugin { - - @Override - public void onEnable() { - getLogger().info("[InstantDeath] Made with love by Emilia"); - getLogger().info("[InstantDeath] Checkout MyEpicWebsite.net"); - getLogger().info("[InstantDeath] Trans lives matter! :3"); - } - - @Override - public void onDisable() { - getLogger().info("[InstantDeath] Thanks for using Instant Death <3"); - } - - @Override - public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { - if (!(sender instanceof Player)) { - // Handle the command when executed from the console - handleConsoleCommand(sender, label, args); - return true; - } - - Player player = (Player) sender; - - // Check if the command is "kill" or its alias "suicide" and has valid arguments - if ((label.equalsIgnoreCase("kill") || label.equalsIgnoreCase("suicide")) && args.length <= 1) { - // Handle self-kill or targeted kill based on the provided arguments - if (args.length == 0) { - handleKill(player, true); // Self-kill - } else if (hasKillPermission(player)) { - Player targetPlayer = getServer().getPlayer(args[0]); - if (targetPlayer != null) { - handleKill(targetPlayer, false); // Targeted kill - } else { - player.sendMessage("Player " + args[0] + " not found."); - } - } else { - player.sendMessage(ChatColor.RED + "You do not have permission to kill others."); - } - return true; - } - - // Send usage message for invalid command or arguments - player.sendMessage(ChatColor.RED + "Usage: /" + label + " [player]"); - return true; - } - - // Handle the kill command when executed from the console - private void handleConsoleCommand(CommandSender sender, String label, String[] args) { - if ((label.equalsIgnoreCase("kill") || label.equalsIgnoreCase("suicide")) && args.length == 1) { - Player targetPlayer = getServer().getPlayer(args[0]); - - if (targetPlayer != null) { - // Kill the target player from the console - targetPlayer.setHealth(0.0); - getLogger().info("Player " + targetPlayer.getName() + " killed from console."); - } else { - getLogger().info("Player " + args[0] + " not found."); - } - } else { - getLogger().info("Usage from console: /" + label + " "); - } - } - - // Format coordinates for display - private String formatCoordinates(int x, int y, int z) { - return ChatColor.YELLOW + "X: " + ChatColor.GOLD + x + - ChatColor.RED + ", " + - ChatColor.YELLOW + "Y: " + ChatColor.GOLD + y + - ChatColor.RED + ", " + - ChatColor.YELLOW + "Z: " + ChatColor.GOLD + z; - } - - // Handle the kill command for both self-kill and targeted kill - private void handleKill(Player target, boolean selfKill) { - int x = target.getLocation().getBlockX(); - int y = target.getLocation().getBlockY(); - int z = target.getLocation().getBlockZ(); - - // Kill the target player - target.setHealth(0.0); - - // Send appropriate kill message to the executor - if (selfKill) { - target.sendMessage(ChatColor.RED + "You killed yourself at " + formatCoordinates(x, y, z)); - } else { - target.sendMessage(ChatColor.RED + "You killed " + target.getName() + "!"); - } - } - - // Check if the player has the permission to kill others - private boolean hasKillPermission(Player player) { - return player.hasPermission("minecraft.command.kill") || player.isOp(); - } -} \ No newline at end of file diff --git a/src/main/java/my/epic/instantdeath/InstantDeath.java b/src/main/java/my/epic/instantdeath/InstantDeath.java new file mode 100644 index 0000000..2f0a312 --- /dev/null +++ b/src/main/java/my/epic/instantdeath/InstantDeath.java @@ -0,0 +1,129 @@ +package my.epic.instantdeath; + +import org.bukkit.ChatColor; +import org.bukkit.command.Command; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; +import org.bukkit.plugin.java.JavaPlugin; + +import java.util.HashMap; +import java.util.Map; + +public final class InstantDeath extends JavaPlugin { + + private Map messages = new HashMap<>(); + + @Override + public void onEnable() { + saveDefaultConfig(); + loadMessages(); + getLogger().info("[InstantDeath] Made with love by Emilia"); + getLogger().info("[InstantDeath] Trans lives matter! :3"); + } + + @Override + public void onDisable() { + getLogger().info("[InstantDeath] Thanks for using Instant Death <3"); + } + + private void loadMessages() { + messages.clear(); + if (getConfig().isConfigurationSection("messages")) { + for (String key : getConfig().getConfigurationSection("messages").getKeys(false)) { + String msg = getConfig().getString("messages." + key, ""); + messages.put(key, ChatColor.translateAlternateColorCodes('&', msg)); + } + } + } + + private String getMessage(String key) { + return messages.getOrDefault(key, ChatColor.RED + "Missing message: " + key); + } + + @Override + public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { + String cmd = command.getName().toLowerCase(); + + if (!(sender instanceof Player)) { + handleConsoleCommand(sender, cmd, args); + return true; + } + + Player player = (Player) sender; + + if ((cmd.equals("kill") || cmd.equals("suicide")) && args.length <= 1) { + if (args.length == 0) { + // Self kill with optional permission requirement + boolean requirePerm = getConfig().getBoolean("settings.self-kill-requires-permission", false); + if (!requirePerm || player.hasPermission("instantdeath.kill.self") || player.isOp()) { + handleKill(player, true, player); + } else { + player.sendMessage(getMessage("no-permission")); + } + } else { + // Targeted kill requires permission + if (hasKillPermission(player)) { + Player targetPlayer = getServer().getPlayerExact(args[0]); + if (targetPlayer != null) { + handleKill(targetPlayer, false, player); + // Inform the killer with a message without coords + String msg = formatMessage(getMessage("target-kill"), targetPlayer, player); + player.sendMessage(msg); + } else { + player.sendMessage(getMessage("player-not-found").replace("%target%", args[0])); + } + } else { + player.sendMessage(getMessage("no-permission")); + } + } + return true; + } + + player.sendMessage(getMessage("usage").replace("%label%", label)); + return true; + } + + private void handleConsoleCommand(CommandSender sender, String cmd, String[] args) { + if ((cmd.equals("kill") || cmd.equals("suicide")) && args.length == 1) { + Player targetPlayer = getServer().getPlayerExact(args[0]); + + if (targetPlayer != null) { + targetPlayer.setHealth(0.0); + getLogger().info(getMessage("console-kill").replace("%target%", targetPlayer.getName())); + } else { + getLogger().info(getMessage("console-player-not-found").replace("%target%", args[0])); + } + } else { + getLogger().info(getMessage("console-usage").replace("%label%", cmd)); + } + } + + private void handleKill(Player target, boolean selfKill, Player killer) { + if (selfKill) { + target.damage(Float.MAX_VALUE); + String msg = formatMessage(getMessage("self-kill"), target, killer); + target.sendMessage(msg); + } else { + target.damage(Float.MAX_VALUE, killer); + boolean showDeathLoc = getConfig().getBoolean("settings.show-death-location-on-kill", false); + if (showDeathLoc) { + String deathLocMsg = formatMessage(getMessage("death-location"), target, killer); + target.sendMessage(deathLocMsg); + } + // killer gets target-kill message (already handled in onCommand) + } + } + + private boolean hasKillPermission(Player player) { + return player.hasPermission("instantdeath.kill.others") || player.isOp(); + } + + private String formatMessage(String template, Player target, Player killer) { + return template + .replace("%x%", String.valueOf(target.getLocation().getBlockX())) + .replace("%y%", String.valueOf(target.getLocation().getBlockY())) + .replace("%z%", String.valueOf(target.getLocation().getBlockZ())) + .replace("%target%", target.getName()) + .replace("%killer%", killer != null ? killer.getName() : "Console"); + } +} diff --git a/src/main/resources/config.yml b/src/main/resources/config.yml new file mode 100644 index 0000000..50cd31e --- /dev/null +++ b/src/main/resources/config.yml @@ -0,0 +1,17 @@ +# InstantDeath plugin configuration +settings: + # You need instantdeath.kill.self to kill yourself + self-kill-requires-permission: false + # If you die it tells you where you died in chat + show-death-location-on-kill: true + +messages: + self-kill: "&cYou have died at &eX: %x%&c, &eY: %y%&c, &eZ: %z%" + target-kill: "&cYou have killed %target%." + death-location: "&cYou died at &eX: %x%&c, &eY: %y%&c, &eZ: %z%" + player-not-found: "&cPlayer '%target%' not found." + no-permission: "&cYou do not have permission to kill others." + usage: "&cUsage: /%label% [player]" + console-kill: "Player %target% killed from console." + console-player-not-found: "Player '%target%' not found." + console-usage: "Usage from console: /%label% " \ No newline at end of file diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml index fa8cc79..33ad339 100644 --- a/src/main/resources/plugin.yml +++ b/src/main/resources/plugin.yml @@ -1,14 +1,27 @@ name: InstantDeath -version: 'v1.0.0' +version: 'v2.0.0' main: my.epic.instantdeath.InstantDeath api-version: '1.6.1' -authors: [ Emilia ] +authors: + - Emilia description: A simple plugin that lets you kill yourself with /kill without needing any special permissions website: https://MyEpicWebsite.net folia-supported: true + commands: kill: - description: Kill yourself + description: Kill yourself or another player (if permitted) aliases: - suicide - usage: / + usage: / [player] + permission: instantdeath.kill.self + permission-message: "&cYou do not have permission to use this command." + +permissions: + instantdeath.kill.others: + description: Allows player to kill others using /kill + default: op + + instantdeath.kill.self: + description: Allows player to kill themselves + default: true