From 4560638683540a388163b2ba7088c93c4695ec0f Mon Sep 17 00:00:00 2001 From: Emi Date: Sat, 2 Aug 2025 13:26:52 +0100 Subject: [PATCH 1/3] Added config.yml and added customizable messages --- pom.xml | 27 +--- .../its/felk/instantdeath/InstantDeath.java | 103 --------------- .../my/epic/instantdeath/InstantDeath.java | 120 ++++++++++++++++++ src/main/resources/config.yml | 14 ++ src/main/resources/plugin.yml | 21 ++- 5 files changed, 152 insertions(+), 133 deletions(-) delete mode 100644 src/main/java/its/felk/instantdeath/InstantDeath.java create mode 100644 src/main/java/my/epic/instantdeath/InstantDeath.java create mode 100644 src/main/resources/config.yml 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..29beb04 --- /dev/null +++ b/src/main/java/my/epic/instantdeath/InstantDeath.java @@ -0,0 +1,120 @@ +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); + 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) { + target.setHealth(0.0); + + String key = selfKill ? "self-kill" : "killed-by-other"; + String msg = formatMessage(getMessage(key), target, killer); + target.sendMessage(msg); + } + + 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"); + } +} \ No newline at end of file diff --git a/src/main/resources/config.yml b/src/main/resources/config.yml new file mode 100644 index 0000000..8f3e352 --- /dev/null +++ b/src/main/resources/config.yml @@ -0,0 +1,14 @@ +# InstantDeath plugin configuration +settings: + self-kill-requires-permission: false + +messages: + self-kill: "&cYou have died at &eX: %x%&c, &eY: %y%&c, &eZ: %z%" + target-kill: "&cYou have killed %target% at &eX: %x%&c, &eY: %y%&c, &eZ: %z%" + killed-by-other: "&cYou were killed by %killer%!" + 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 From 2b5fbe4b595bf48bbd6206e4f345a7e21067bdb6 Mon Sep 17 00:00:00 2001 From: Emi Date: Sat, 2 Aug 2025 13:36:08 +0100 Subject: [PATCH 2/3] Made minecraft handle death message and instead of setting health to 0 it just damages you as much as it can. --- .../java/my/epic/instantdeath/InstantDeath.java | 13 ++++++++----- src/main/resources/config.yml | 1 - 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/src/main/java/my/epic/instantdeath/InstantDeath.java b/src/main/java/my/epic/instantdeath/InstantDeath.java index 29beb04..eaed584 100644 --- a/src/main/java/my/epic/instantdeath/InstantDeath.java +++ b/src/main/java/my/epic/instantdeath/InstantDeath.java @@ -98,11 +98,14 @@ private void handleConsoleCommand(CommandSender sender, String cmd, String[] arg } private void handleKill(Player target, boolean selfKill, Player killer) { - target.setHealth(0.0); - - String key = selfKill ? "self-kill" : "killed-by-other"; - String msg = formatMessage(getMessage(key), target, killer); - target.sendMessage(msg); + 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); + // No custom killed-by-other message to let vanilla handle death messages + } } private boolean hasKillPermission(Player player) { diff --git a/src/main/resources/config.yml b/src/main/resources/config.yml index 8f3e352..fb0e2ca 100644 --- a/src/main/resources/config.yml +++ b/src/main/resources/config.yml @@ -5,7 +5,6 @@ settings: messages: self-kill: "&cYou have died at &eX: %x%&c, &eY: %y%&c, &eZ: %z%" target-kill: "&cYou have killed %target% at &eX: %x%&c, &eY: %y%&c, &eZ: %z%" - killed-by-other: "&cYou were killed by %killer%!" player-not-found: "&cPlayer '%target%' not found." no-permission: "&cYou do not have permission to kill others." usage: "&cUsage: /%label% [player]" From ff7eee5525dfb60c9772819224d225b744072356 Mon Sep 17 00:00:00 2001 From: Emi Date: Sat, 2 Aug 2025 13:48:01 +0100 Subject: [PATCH 3/3] Made minecraft handle death message and instead of setting health to 0 it just damages you as much as it can. Also adds config option to show chords to victims. Fixed issue that if you logout when you died and join back your at 0 health but alive. --- .idea/dictionaries/project.xml | 1 + src/main/java/my/epic/instantdeath/InstantDeath.java | 10 ++++++++-- src/main/resources/config.yml | 6 +++++- 3 files changed, 14 insertions(+), 3 deletions(-) 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/src/main/java/my/epic/instantdeath/InstantDeath.java b/src/main/java/my/epic/instantdeath/InstantDeath.java index eaed584..2f0a312 100644 --- a/src/main/java/my/epic/instantdeath/InstantDeath.java +++ b/src/main/java/my/epic/instantdeath/InstantDeath.java @@ -66,6 +66,7 @@ public boolean onCommand(CommandSender sender, Command command, String label, St 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 { @@ -104,7 +105,12 @@ private void handleKill(Player target, boolean selfKill, Player killer) { target.sendMessage(msg); } else { target.damage(Float.MAX_VALUE, killer); - // No custom killed-by-other message to let vanilla handle death messages + 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) } } @@ -120,4 +126,4 @@ private String formatMessage(String template, Player target, Player killer) { .replace("%target%", target.getName()) .replace("%killer%", killer != null ? killer.getName() : "Console"); } -} \ No newline at end of file +} diff --git a/src/main/resources/config.yml b/src/main/resources/config.yml index fb0e2ca..50cd31e 100644 --- a/src/main/resources/config.yml +++ b/src/main/resources/config.yml @@ -1,10 +1,14 @@ # 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% 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]"