Skip to content

Commit c8f66e8

Browse files
authored
feat: Tell players where they died
Made this in the GitHub web editor (without codespace), so code isn't tested, I had no help with imports, and this might not even compile.
1 parent 3221b8f commit c8f66e8

File tree

2 files changed

+35
-0
lines changed

2 files changed

+35
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
import org.bukkit.event.Listener;
2+
import de.kiridevs.ksmpplugin.main.KiriSmpPlugin;
3+
import org.bukkit.event.EventHandler;
4+
import org.bukkit.event.player.PlayerDeathEvent;
5+
import org.bukkit.entity.Player;
6+
import org.bukkit.Location;
7+
import org.bukkit.Bukkit;
8+
9+
public class DeathMessage implements Listener {
10+
private static final String MESSAGE_FORMAT = "You died at X=%d, Y=%d, Z=%d";
11+
12+
private final KiriSmpPlugin plugin;
13+
14+
public DeathMessage(KiriSmpPlugin plugin) {
15+
this.plugin = plugin;
16+
}
17+
18+
@EventHandler
19+
public void onPlayerDeath(PlayerDeathEvent deathEvent) {
20+
Player player = deathEvent.getPlayer();
21+
Location loc = player.getLocation();
22+
23+
player.sendMessage(MESSAGE_FORMAT.formatted(
24+
(int) loc.getX(),
25+
(int) loc.getY(),
26+
(int) loc.getZ()
27+
));
28+
}
29+
30+
public void init(KiriSmpPlugin plugin) {
31+
this.plugin.log.info("features: DragonBuff: Initializing");
32+
Bukkit.getPluginManager().registerEvents(this, this.plugin);
33+
}
34+
}

src/main/java/de/kiridevs/ksmpplugin/main/KiriSmpPlugin.java

+1
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ private void registerRecipes() {
4040
public void initFeatures() {
4141
new DragonBuff(this).init();
4242
new EndCrystalBuff(this).init();
43+
new DeathMessage(this).init();
4344
}
4445

4546
@Override

0 commit comments

Comments
 (0)