Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .idea/dictionaries/project.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

27 changes: 1 addition & 26 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>its.felk</groupId>
<artifactId>InstantDeath</artifactId>
<version>1.0.0</version>
<version>2.0.0</version>
<packaging>jar</packaging>

<name>InstantDeath</name>
Expand All @@ -27,7 +27,6 @@
</repositories>

<dependencies>
<!-- CraftBukkit dependency marked as provided -->
<dependency>
<groupId>org.bukkit</groupId>
<artifactId>craftbukkit</artifactId>
Expand Down Expand Up @@ -58,30 +57,6 @@
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>3.2.4</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<filters>
<filter>
<artifact>*:*</artifact>
<excludes>
<!-- Avoid risky dependencies -->
<exclude>org/bukkit/craftbukkit/libs/**</exclude>
<exclude>org/sqlite/**</exclude>
<exclude>org/apache/commons/io/**</exclude>
<exclude>org/fusesource/**</exclude>
<exclude>org/ibex/**</exclude>
<exclude>com/mysql/**</exclude>
</excludes>
</filter>
</filters>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
Expand Down
103 changes: 0 additions & 103 deletions src/main/java/its/felk/instantdeath/InstantDeath.java

This file was deleted.

129 changes: 129 additions & 0 deletions src/main/java/my/epic/instantdeath/InstantDeath.java
Original file line number Diff line number Diff line change
@@ -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<String, String> 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");
}
}
17 changes: 17 additions & 0 deletions src/main/resources/config.yml
Original file line number Diff line number Diff line change
@@ -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% <player>"
21 changes: 17 additions & 4 deletions src/main/resources/plugin.yml
Original file line number Diff line number Diff line change
@@ -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: /<command>
usage: /<command> [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 <player>
default: op

instantdeath.kill.self:
description: Allows player to kill themselves
default: true