Skip to content

Commit

Permalink
Hide killer name in PvP death message (#18)
Browse files Browse the repository at this point in the history
* Hide killer name in PvP death message

* Obfuscate killer name
  • Loading branch information
PainOchoco authored Apr 2, 2024
1 parent 47d39f6 commit d713f5d
Showing 1 changed file with 19 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import org.bukkit.event.entity.EntityDamageByEntityEvent;
import org.bukkit.event.entity.EntityDamageEvent.DamageCause;
import org.bukkit.event.entity.EntityPlaceEvent;
import org.bukkit.event.entity.PlayerDeathEvent;
import org.bukkit.event.player.PlayerJoinEvent;
import org.bukkit.event.player.PlayerPortalEvent;
import org.bukkit.event.player.PlayerResourcePackStatusEvent;
Expand All @@ -36,6 +37,8 @@
import com.comphenix.protocol.events.PacketEvent;

import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.TextReplacementConfig;
import net.kyori.adventure.text.format.TextDecoration;
import net.kyori.adventure.text.minimessage.MiniMessage;
import net.laboulangerie.laboulangeriecore.LaBoulangerieCore;
import net.laboulangerie.laboulangeriecore.core.UsersData;
Expand Down Expand Up @@ -214,4 +217,20 @@ public void onPlaceCrystal(EntityPlaceEvent event) {
crystalDelay.replace(event.getPlayer().getUniqueId(), new Date());
}
}

// Obfuscate killer name in player death message
@EventHandler
public void onPlayerDeath(PlayerDeathEvent event) {
// PvP kill only
if (!(event.getEntity().getKiller() instanceof Player))
return;

String killerName = event.getEntity().getKiller().getName();
Component obfuscatedKiller = Component.text("??????").decoration(TextDecoration.OBFUSCATED, true);
TextReplacementConfig killerReplacement = TextReplacementConfig.builder().matchLiteral(killerName)
.replacement(obfuscatedKiller).build();

Component newDeathMessage = event.deathMessage().replaceText(killerReplacement);
event.deathMessage(newDeathMessage);
}
}

0 comments on commit d713f5d

Please sign in to comment.