Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: backport Paper changes on EntityDeathEvent #3417

Open
wants to merge 4 commits into
base: 1.20.1
Choose a base branch
from
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -368,7 +368,7 @@
} catch (Throwable throwable) {
CrashReport crashreport = CrashReport.m_127521_(throwable, "Ticking player");
CrashReportCategory crashreportcategory = crashreport.m_127514_("Player being ticked");
@@ -563,16 +_,53 @@
@@ -563,34 +_,79 @@
}

private void m_9104_(ObjectiveCriteria p_9105_, int p_9106_) {
Expand All @@ -384,6 +384,12 @@
boolean flag = this.m_9236_().m_46469_().m_46207_(GameRules.f_46142_);
- if (flag) {
- Component component = this.m_21231_().m_19293_();
- this.f_8906_.m_243119_(new ClientboundPlayerCombatKillPacket(this.m_19879_(), component), PacketSendListener.m_243073_(() -> {
- int i = 256;
- String s = component.m_130668_(256);
- Component component1 = Component.m_237110_("death.attack.message_too_long", Component.m_237113_(s).m_130940_(ChatFormatting.YELLOW));
- Component component2 = Component.m_237110_("death.attack.even_more_magic", this.m_5446_()).m_130938_((p_143420_) -> {
- return p_143420_.m_131144_(new HoverEvent(HoverEvent.Action.f_130831_, component1));
+ // CraftBukkit start - fire PlayerDeathEvent
+ if (this.m_213877_()) {
+ return;
Expand All @@ -406,25 +412,59 @@
+ String deathmessage = defaultMessage.getString();
+
+ keepLevel = keepInventory; // SPIGOT-2222: pre-set keepLevel
+ org.bukkit.event.entity.PlayerDeathEvent event = CraftEventFactory.callPlayerDeathEvent(this, loot, deathmessage, keepInventory);
+ org.bukkit.event.entity.PlayerDeathEvent event = CraftEventFactory.callPlayerDeathEvent(this, loot, com.mohistmc.paper.adventure.PaperAdventure.asAdventure(defaultMessage), defaultMessage.getString(), keepInventory); // Paper - Adventure // Mohist - Mohist PaperAdventure
+ // Paper start - cancellable death event
+ if (event.isCancelled()) {
+ // make compatible with plugins that might have already set the health in an event listener
+ if (this.m_21223_() <= 0) {
+ this.m_21153_((float) event.getReviveHealth());
+ }
+ return;
+ }
+ // Paper end
+
+ // SPIGOT-943 - only call if they have an inventory open
+ if (this.f_36096_ != this.f_36095_) {
+ useHandleContainerClose = true;
+ this.m_6915_();
+ }
+
+ String deathMessage = event.getDeathMessage();
+ if (deathMessage != null && deathMessage.length() > 0 && flag) { // TODO: allow plugins to override?
+ Component component;
+ if (deathMessage.equals(deathmessage)) {
+ component = this.m_21231_().m_19293_();
+ } else {
+ component = CraftChatMessage.fromStringOrNull(deathMessage);
+ }
this.f_8906_.m_243119_(new ClientboundPlayerCombatKillPacket(this.m_19879_(), component), PacketSendListener.m_243073_(() -> {
int i = 256;
String s = component.m_130668_(256);
+ net.kyori.adventure.text.Component deathMessage = event.deathMessage() != null ? event.deathMessage() : net.kyori.adventure.text.Component.empty(); // Paper - Adventure
+
+ if (deathMessage != null && deathMessage != net.kyori.adventure.text.Component.empty() && flag) { // Paper - Adventure // TODO: allow plugins to override?
+ Component ichatbasecomponent = com.mohistmc.paper.adventure.PaperAdventure.asVanilla(deathMessage); // Paper - Adventure // Mohist - Mohist PaperAdventure
+
+ this.f_8906_.m_243119_(new ClientboundPlayerCombatKillPacket(this.m_19879_(), ichatbasecomponent), PacketSendListener.m_243073_(() -> {
+ boolean flag1 = true;
+ String s = ichatbasecomponent.m_130668_(256);
+ net.minecraft.network.chat.MutableComponent ichatmutablecomponent = Component.m_237110_("death.attack.message_too_long", Component.m_237113_(s).m_130940_(ChatFormatting.YELLOW));
+ net.minecraft.network.chat.MutableComponent ichatmutablecomponent1 = Component.m_237110_("death.attack.even_more_magic", this.m_5446_()).m_130938_((chatmodifier) -> {
+ return chatmodifier.m_131144_(new HoverEvent(HoverEvent.Action.f_130831_, ichatmutablecomponent));
});
- return new ClientboundPlayerCombatKillPacket(this.m_19879_(), component2);
+
+ return new ClientboundPlayerCombatKillPacket(this.m_19879_(), ichatmutablecomponent1);
}));
- Team team = this.m_5647_();
- if (team != null && team.m_7468_() != Team.Visibility.ALWAYS) {
- if (team.m_7468_() == Team.Visibility.HIDE_FOR_OTHER_TEAMS) {
- this.f_8924_.m_6846_().m_215621_(this, component);
- } else if (team.m_7468_() == Team.Visibility.HIDE_FOR_OWN_TEAM) {
- this.f_8924_.m_6846_().m_215649_(this, component);
+ Team scoreboardteambase = this.m_5647_();
+
+ if (scoreboardteambase != null && scoreboardteambase.m_7468_() != Team.Visibility.ALWAYS) {
+ if (scoreboardteambase.m_7468_() == Team.Visibility.HIDE_FOR_OTHER_TEAMS) {
+ this.f_8924_.m_6846_().m_215621_(this, ichatbasecomponent);
+ } else if (scoreboardteambase.m_7468_() == Team.Visibility.HIDE_FOR_OWN_TEAM) {
+ this.f_8924_.m_6846_().m_215649_(this, ichatbasecomponent);
}
} else {
- this.f_8924_.m_6846_().m_240416_(component, false);
+ this.f_8924_.m_6846_().m_240416_(ichatbasecomponent, false);
}
} else {
this.f_8906_.m_9829_(new ClientboundPlayerCombatKillPacket(this.m_19879_(), CommonComponents.f_237098_));
@@ -601,11 +_,16 @@
this.m_9215_();
}
Expand Down
Loading