Skip to content

Commit

Permalink
fix: don't override null custom messages to the event
Browse files Browse the repository at this point in the history
  • Loading branch information
rexlManu committed Jul 2, 2024
1 parent 64e992a commit 7b954f5
Showing 1 changed file with 16 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import org.bukkit.event.player.PlayerQuitEvent;
import org.bukkit.inventory.ItemStack;

@SuppressWarnings("deprecation")
@UtilityClass
public class EventMessageUtils {
public static Supplier<Component> quitMessage(PlayerQuitEvent event) {
Expand All @@ -28,11 +29,14 @@ public static Supplier<Component> quitMessage(PlayerQuitEvent event) {

public static Consumer<Component> quitMessageSetter(PlayerQuitEvent event) {
if (Environment.ENVIRONMENT.isPaper()) {
return event::quitMessage;
return component -> {
if (component != null) {
event.quitMessage(component);
}
};
}
return component -> {
if (component == null) {
event.setQuitMessage(null);
return;
}
event.setQuitMessage(LegacyComponentSerializer.legacySection().serialize(component));
Expand All @@ -52,11 +56,14 @@ public static Supplier<Component> joinMessage(PlayerJoinEvent event) {

public static Consumer<Component> joinMessageSetter(PlayerJoinEvent event) {
if (Environment.ENVIRONMENT.isPaper()) {
return event::joinMessage;
return component -> {
if (component != null) {
event.joinMessage(component);
}
};
}
return component -> {
if (component == null) {
event.setJoinMessage(null);
return;
}
event.setJoinMessage(LegacyComponentSerializer.legacySection().serialize(component));
Expand All @@ -76,11 +83,14 @@ public static Supplier<Component> deathMessage(PlayerDeathEvent event) {

public static Consumer<Component> deathMessageSetter(PlayerDeathEvent event) {
if (Environment.ENVIRONMENT.isPaper()) {
return event::deathMessage;
return component -> {
if (component != null) {
event.deathMessage(component);
}
};
}
return component -> {
if (component == null) {
event.setDeathMessage(null);
return;
}
event.setDeathMessage(LegacyComponentSerializer.legacySection().serialize(component));
Expand Down

0 comments on commit 7b954f5

Please sign in to comment.