PlayerDeathEvent#getDeathMessage should provide translation for legacy reasons #5227
This commit is contained in:
@@ -1319,30 +1319,30 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
|
|||||||
--- a/src/main/java/org/bukkit/event/entity/PlayerDeathEvent.java
|
--- a/src/main/java/org/bukkit/event/entity/PlayerDeathEvent.java
|
||||||
+++ b/src/main/java/org/bukkit/event/entity/PlayerDeathEvent.java
|
+++ b/src/main/java/org/bukkit/event/entity/PlayerDeathEvent.java
|
||||||
@@ -0,0 +0,0 @@ import org.jetbrains.annotations.Nullable;
|
@@ -0,0 +0,0 @@ import org.jetbrains.annotations.Nullable;
|
||||||
*/
|
|
||||||
public class PlayerDeathEvent extends EntityDeathEvent {
|
public class PlayerDeathEvent extends EntityDeathEvent {
|
||||||
private int newExp = 0;
|
private int newExp = 0;
|
||||||
- private String deathMessage = "";
|
private String deathMessage = "";
|
||||||
+ private net.kyori.adventure.text.Component deathMessage; // Paper
|
+ private net.kyori.adventure.text.Component adventure$deathMessage; // Paper
|
||||||
private int newLevel = 0;
|
private int newLevel = 0;
|
||||||
private int newTotalExp = 0;
|
private int newTotalExp = 0;
|
||||||
private boolean keepLevel = false;
|
private boolean keepLevel = false;
|
||||||
private boolean keepInventory = false;
|
private boolean keepInventory = false;
|
||||||
+ // Paper start
|
+ // Paper start
|
||||||
+ public PlayerDeathEvent(@NotNull final Player player, @NotNull final List<ItemStack> drops, final int droppedExp, @Nullable final net.kyori.adventure.text.Component deathMessage) {
|
+ public PlayerDeathEvent(@NotNull final Player player, @NotNull final List<ItemStack> drops, final int droppedExp, @Nullable final net.kyori.adventure.text.Component adventure$deathMessage) {
|
||||||
+ this(player, drops, droppedExp, 0, deathMessage);
|
+ this(player, drops, droppedExp, 0, adventure$deathMessage, null);
|
||||||
+ }
|
+ }
|
||||||
+
|
+
|
||||||
+ public PlayerDeathEvent(@NotNull final Player player, @NotNull final List<ItemStack> drops, final int droppedExp, final int newExp, @Nullable final net.kyori.adventure.text.Component deathMessage) {
|
+ public PlayerDeathEvent(@NotNull final Player player, @NotNull final List<ItemStack> drops, final int droppedExp, final int newExp, @Nullable final net.kyori.adventure.text.Component adventure$deathMessage, @Nullable String deathMessage) {
|
||||||
+ this(player, drops, droppedExp, newExp, 0, 0, deathMessage);
|
+ this(player, drops, droppedExp, newExp, 0, 0, adventure$deathMessage, deathMessage);
|
||||||
+ }
|
+ }
|
||||||
|
|
||||||
+ public PlayerDeathEvent(@NotNull final Player player, @NotNull final List<ItemStack> drops, final int droppedExp, final int newExp, final int newTotalExp, final int newLevel, @Nullable final net.kyori.adventure.text.Component deathMessage) {
|
+ public PlayerDeathEvent(@NotNull final Player player, @NotNull final List<ItemStack> drops, final int droppedExp, final int newExp, final int newTotalExp, final int newLevel, @Nullable final net.kyori.adventure.text.Component adventure$deathMessage, @Nullable String deathMessage) {
|
||||||
+ super(player, drops, droppedExp);
|
+ super(player, drops, droppedExp);
|
||||||
+ this.newExp = newExp;
|
+ this.newExp = newExp;
|
||||||
+ this.newTotalExp = newTotalExp;
|
+ this.newTotalExp = newTotalExp;
|
||||||
+ this.newLevel = newLevel;
|
+ this.newLevel = newLevel;
|
||||||
+ this.deathMessage = deathMessage;
|
+ this.deathMessage = deathMessage;
|
||||||
|
+ this.adventure$deathMessage = adventure$deathMessage;
|
||||||
+ }
|
+ }
|
||||||
+ // Paper end
|
+ // Paper end
|
||||||
+
|
+
|
||||||
@@ -1362,8 +1362,8 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
|
|||||||
this.newExp = newExp;
|
this.newExp = newExp;
|
||||||
this.newTotalExp = newTotalExp;
|
this.newTotalExp = newTotalExp;
|
||||||
this.newLevel = newLevel;
|
this.newLevel = newLevel;
|
||||||
- this.deathMessage = deathMessage;
|
this.deathMessage = deathMessage;
|
||||||
+ this.deathMessage = deathMessage != null ? net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer.legacySection().deserialize(deathMessage) : net.kyori.adventure.text.Component.empty(); // Paper
|
+ this.adventure$deathMessage = deathMessage != null ? net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer.legacySection().deserialize(deathMessage) : net.kyori.adventure.text.Component.empty(); // Paper
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
@@ -1372,50 +1372,59 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
|
|||||||
}
|
}
|
||||||
|
|
||||||
+ // Paper start
|
+ // Paper start
|
||||||
/**
|
|
||||||
* Set the death message that will appear to everyone on the server.
|
|
||||||
*
|
|
||||||
* @param deathMessage Message to appear to other players on the server.
|
|
||||||
*/
|
|
||||||
- public void setDeathMessage(@Nullable String deathMessage) {
|
|
||||||
+ public void deathMessage(@Nullable net.kyori.adventure.text.Component deathMessage) {
|
|
||||||
this.deathMessage = deathMessage;
|
|
||||||
}
|
|
||||||
|
|
||||||
@@ -0,0 +0,0 @@ public class PlayerDeathEvent extends EntityDeathEvent {
|
|
||||||
*
|
|
||||||
* @return Message to appear to other players on the server.
|
|
||||||
*/
|
|
||||||
+ public @Nullable net.kyori.adventure.text.Component deathMessage() {
|
|
||||||
+ return this.deathMessage;
|
|
||||||
+ }
|
|
||||||
+ // Paper end
|
|
||||||
+
|
|
||||||
+ /**
|
+ /**
|
||||||
+ * Set the death message that will appear to everyone on the server.
|
+ * Set the death message that will appear to everyone on the server.
|
||||||
+ *
|
+ *
|
||||||
+ * @param deathMessage Message to appear to other players on the server.
|
+ * @param deathMessage Message to appear to other players on the server.
|
||||||
+ * @deprecated in favour of {@link #deathMessage(net.kyori.adventure.text.Component)}
|
|
||||||
+ */
|
+ */
|
||||||
+ @Deprecated // Paper
|
+ public void deathMessage(@Nullable net.kyori.adventure.text.Component deathMessage) {
|
||||||
+ public void setDeathMessage(@Nullable String deathMessage) {
|
+ this.deathMessage = null;
|
||||||
+ this.deathMessage = deathMessage != null ? net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer.legacySection().deserialize(deathMessage) : net.kyori.adventure.text.Component.empty(); // Paper
|
+ this.adventure$deathMessage = deathMessage;
|
||||||
+ }
|
+ }
|
||||||
+
|
+
|
||||||
+ /**
|
+ /**
|
||||||
+ * Get the death message that will appear to everyone on the server.
|
+ * Get the death message that will appear to everyone on the server.
|
||||||
+ *
|
+ *
|
||||||
+ * @return Message to appear to other players on the server.
|
+ * @return Message to appear to other players on the server.
|
||||||
+ * @deprecated in favour of {@link #deathMessage()}
|
|
||||||
+ */
|
+ */
|
||||||
|
+ public @Nullable net.kyori.adventure.text.Component deathMessage() {
|
||||||
|
+ return this.adventure$deathMessage;
|
||||||
|
+ }
|
||||||
|
+ // Paper end
|
||||||
|
+
|
||||||
|
/**
|
||||||
|
* Set the death message that will appear to everyone on the server.
|
||||||
|
*
|
||||||
|
* @param deathMessage Message to appear to other players on the server.
|
||||||
|
+ * @deprecated in favour of {@link #deathMessage(net.kyori.adventure.text.Component)}
|
||||||
|
*/
|
||||||
|
+ @Deprecated // Paper
|
||||||
|
public void setDeathMessage(@Nullable String deathMessage) {
|
||||||
|
this.deathMessage = deathMessage;
|
||||||
|
+ this.adventure$deathMessage = deathMessage != null ? net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer.legacySection().deserialize(deathMessage) : net.kyori.adventure.text.Component.empty(); // Paper
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the death message that will appear to everyone on the server.
|
||||||
|
*
|
||||||
|
* @return Message to appear to other players on the server.
|
||||||
|
+ * @deprecated in favour of {@link #deathMessage()}
|
||||||
|
*/
|
||||||
@Nullable
|
@Nullable
|
||||||
+ @Deprecated // Paper
|
+ @Deprecated // Paper
|
||||||
public String getDeathMessage() {
|
public String getDeathMessage() {
|
||||||
- return deathMessage;
|
- return deathMessage;
|
||||||
+ return this.deathMessage == null ? null : net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer.legacySection().serialize(this.deathMessage); // Paper
|
+ return this.deathMessage != null ? this.deathMessage : (this.adventure$deathMessage != null ? getDeathMessageString(this.adventure$deathMessage) : null); // Paper
|
||||||
}
|
}
|
||||||
|
-
|
||||||
|
+ // Paper start //TODO: add translation API to drop String deathMessage in favor of just Adventure
|
||||||
|
+ private static String getDeathMessageString(net.kyori.adventure.text.Component component) {
|
||||||
|
+ return net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer.legacySection().serialize(component);
|
||||||
|
+ }
|
||||||
|
+ // Paper end
|
||||||
/**
|
/**
|
||||||
|
* Gets how much EXP the Player should have at respawn.
|
||||||
|
* <p>
|
||||||
diff --git a/src/main/java/org/bukkit/event/inventory/InventoryType.java b/src/main/java/org/bukkit/event/inventory/InventoryType.java
|
diff --git a/src/main/java/org/bukkit/event/inventory/InventoryType.java b/src/main/java/org/bukkit/event/inventory/InventoryType.java
|
||||||
index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
|
index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
|
||||||
--- a/src/main/java/org/bukkit/event/inventory/InventoryType.java
|
--- a/src/main/java/org/bukkit/event/inventory/InventoryType.java
|
||||||
|
|||||||
@@ -20,7 +20,7 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
|
|||||||
this(player, drops, droppedExp, 0, deathMessage);
|
this(player, drops, droppedExp, 0, deathMessage);
|
||||||
}
|
}
|
||||||
@@ -0,0 +0,0 @@ public class PlayerDeathEvent extends EntityDeathEvent {
|
@@ -0,0 +0,0 @@ public class PlayerDeathEvent extends EntityDeathEvent {
|
||||||
this.deathMessage = deathMessage != null ? net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer.legacySection().deserialize(deathMessage) : net.kyori.adventure.text.Component.empty(); // Paper
|
this.adventure$deathMessage = deathMessage != null ? net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer.legacySection().deserialize(deathMessage) : net.kyori.adventure.text.Component.empty(); // Paper
|
||||||
}
|
}
|
||||||
|
|
||||||
+ @Deprecated // Paper
|
+ @Deprecated // Paper
|
||||||
|
|||||||
@@ -23,22 +23,23 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
|
|||||||
// Paper start
|
// Paper start
|
||||||
+ private boolean doExpDrop;
|
+ private boolean doExpDrop;
|
||||||
+
|
+
|
||||||
public PlayerDeathEvent(@NotNull final Player player, @NotNull final List<ItemStack> drops, final int droppedExp, @Nullable final net.kyori.adventure.text.Component deathMessage) {
|
public PlayerDeathEvent(@NotNull final Player player, @NotNull final List<ItemStack> drops, final int droppedExp, @Nullable final net.kyori.adventure.text.Component adventure$deathMessage) {
|
||||||
this(player, drops, droppedExp, 0, deathMessage);
|
this(player, drops, droppedExp, 0, adventure$deathMessage, null);
|
||||||
}
|
}
|
||||||
@@ -0,0 +0,0 @@ public class PlayerDeathEvent extends EntityDeathEvent {
|
@@ -0,0 +0,0 @@ public class PlayerDeathEvent extends EntityDeathEvent {
|
||||||
}
|
}
|
||||||
|
|
||||||
public PlayerDeathEvent(@NotNull final Player player, @NotNull final List<ItemStack> drops, final int droppedExp, final int newExp, final int newTotalExp, final int newLevel, @Nullable final net.kyori.adventure.text.Component deathMessage) {
|
public PlayerDeathEvent(@NotNull final Player player, @NotNull final List<ItemStack> drops, final int droppedExp, final int newExp, final int newTotalExp, final int newLevel, @Nullable final net.kyori.adventure.text.Component adventure$deathMessage, @Nullable String deathMessage) {
|
||||||
+ this(player, drops, droppedExp, newExp, newTotalExp, newLevel, deathMessage, true);
|
+ this(player, drops, droppedExp, newExp, newTotalExp, newLevel, adventure$deathMessage, deathMessage, true);
|
||||||
+ }
|
+ }
|
||||||
+
|
+
|
||||||
+ public PlayerDeathEvent(@NotNull final Player player, @NotNull final List<ItemStack> drops, final int droppedExp, final int newExp, final int newTotalExp, final int newLevel, @Nullable final net.kyori.adventure.text.Component deathMessage, boolean doExpDrop) {
|
+ public PlayerDeathEvent(@NotNull final Player player, @NotNull final List<ItemStack> drops, final int droppedExp, final int newExp, final int newTotalExp, final int newLevel, @Nullable final net.kyori.adventure.text.Component adventure$deathMessage, @Nullable String deathMessage, boolean doExpDrop) {
|
||||||
super(player, drops, droppedExp);
|
super(player, drops, droppedExp);
|
||||||
this.newExp = newExp;
|
this.newExp = newExp;
|
||||||
this.newTotalExp = newTotalExp;
|
this.newTotalExp = newTotalExp;
|
||||||
this.newLevel = newLevel;
|
this.newLevel = newLevel;
|
||||||
this.deathMessage = deathMessage;
|
this.deathMessage = deathMessage;
|
||||||
|
this.adventure$deathMessage = adventure$deathMessage;
|
||||||
+ this.doExpDrop = doExpDrop;
|
+ this.doExpDrop = doExpDrop;
|
||||||
}
|
}
|
||||||
// Paper end
|
// Paper end
|
||||||
|
|||||||
@@ -782,7 +782,7 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
|
|||||||
|
|
||||||
- String deathmessage = defaultMessage.getString();
|
- String deathmessage = defaultMessage.getString();
|
||||||
- org.bukkit.event.entity.PlayerDeathEvent event = CraftEventFactory.callPlayerDeathEvent(this, loot, deathmessage, keepInventory);
|
- org.bukkit.event.entity.PlayerDeathEvent event = CraftEventFactory.callPlayerDeathEvent(this, loot, deathmessage, keepInventory);
|
||||||
+ org.bukkit.event.entity.PlayerDeathEvent event = CraftEventFactory.callPlayerDeathEvent(this, loot, PaperAdventure.asAdventure(defaultMessage), keepInventory); // Paper - Adventure
|
+ org.bukkit.event.entity.PlayerDeathEvent event = CraftEventFactory.callPlayerDeathEvent(this, loot, PaperAdventure.asAdventure(defaultMessage), defaultMessage.getString(), keepInventory); // Paper - Adventure
|
||||||
|
|
||||||
// SPIGOT-943 - only call if they have an inventory open
|
// SPIGOT-943 - only call if they have an inventory open
|
||||||
if (this.activeContainer != this.defaultContainer) {
|
if (this.activeContainer != this.defaultContainer) {
|
||||||
@@ -2162,10 +2162,13 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
|
|||||||
}
|
}
|
||||||
|
|
||||||
- public static PlayerDeathEvent callPlayerDeathEvent(EntityPlayer victim, List<org.bukkit.inventory.ItemStack> drops, String deathMessage, boolean keepInventory) {
|
- public static PlayerDeathEvent callPlayerDeathEvent(EntityPlayer victim, List<org.bukkit.inventory.ItemStack> drops, String deathMessage, boolean keepInventory) {
|
||||||
+ public static PlayerDeathEvent callPlayerDeathEvent(EntityPlayer victim, List<org.bukkit.inventory.ItemStack> drops, net.kyori.adventure.text.Component deathMessage, boolean keepInventory) { // Paper - Adventure
|
+ public static PlayerDeathEvent callPlayerDeathEvent(EntityPlayer victim, List<org.bukkit.inventory.ItemStack> drops, net.kyori.adventure.text.Component deathMessage, String stringDeathMessage, boolean keepInventory) { // Paper - Adventure
|
||||||
CraftPlayer entity = victim.getBukkitEntity();
|
CraftPlayer entity = victim.getBukkitEntity();
|
||||||
PlayerDeathEvent event = new PlayerDeathEvent(entity, drops, victim.getExpReward(), 0, deathMessage);
|
- PlayerDeathEvent event = new PlayerDeathEvent(entity, drops, victim.getExpReward(), 0, deathMessage);
|
||||||
|
+ PlayerDeathEvent event = new PlayerDeathEvent(entity, drops, victim.getExpReward(), 0, deathMessage, stringDeathMessage); // Paper - Adventure
|
||||||
event.setKeepInventory(keepInventory);
|
event.setKeepInventory(keepInventory);
|
||||||
|
org.bukkit.World world = entity.getWorld();
|
||||||
|
Bukkit.getServer().getPluginManager().callEvent(event);
|
||||||
@@ -0,0 +0,0 @@ public class CraftEventFactory {
|
@@ -0,0 +0,0 @@ public class CraftEventFactory {
|
||||||
* Server methods
|
* Server methods
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -291,7 +291,7 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
|
|||||||
@@ -0,0 +0,0 @@ public class EntityPlayer extends EntityHuman implements ICrafting {
|
@@ -0,0 +0,0 @@ public class EntityPlayer extends EntityHuman implements ICrafting {
|
||||||
IChatBaseComponent defaultMessage = this.getCombatTracker().getDeathMessage();
|
IChatBaseComponent defaultMessage = this.getCombatTracker().getDeathMessage();
|
||||||
|
|
||||||
org.bukkit.event.entity.PlayerDeathEvent event = CraftEventFactory.callPlayerDeathEvent(this, loot, PaperAdventure.asAdventure(defaultMessage), keepInventory); // Paper - Adventure
|
org.bukkit.event.entity.PlayerDeathEvent event = CraftEventFactory.callPlayerDeathEvent(this, loot, PaperAdventure.asAdventure(defaultMessage), defaultMessage.getString(), keepInventory); // Paper - Adventure
|
||||||
+ // Paper start - cancellable death event
|
+ // Paper start - cancellable death event
|
||||||
+ if (event.isCancelled()) {
|
+ if (event.isCancelled()) {
|
||||||
+ // make compatible with plugins that might have already set the health in an event listener
|
+ // make compatible with plugins that might have already set the health in an event listener
|
||||||
@@ -368,7 +368,7 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
|
|||||||
for (org.bukkit.inventory.ItemStack stack : event.getDrops()) {
|
for (org.bukkit.inventory.ItemStack stack : event.getDrops()) {
|
||||||
@@ -0,0 +0,0 @@ public class CraftEventFactory {
|
@@ -0,0 +0,0 @@ public class CraftEventFactory {
|
||||||
CraftPlayer entity = victim.getBukkitEntity();
|
CraftPlayer entity = victim.getBukkitEntity();
|
||||||
PlayerDeathEvent event = new PlayerDeathEvent(entity, drops, victim.getExpReward(), 0, deathMessage);
|
PlayerDeathEvent event = new PlayerDeathEvent(entity, drops, victim.getExpReward(), 0, deathMessage, stringDeathMessage); // Paper - Adventure
|
||||||
event.setKeepInventory(keepInventory);
|
event.setKeepInventory(keepInventory);
|
||||||
+ populateFields(victim, event); // Paper - make cancellable
|
+ populateFields(victim, event); // Paper - make cancellable
|
||||||
org.bukkit.World world = entity.getWorld();
|
org.bukkit.World world = entity.getWorld();
|
||||||
|
|||||||
Reference in New Issue
Block a user