mirror of
https://github.com/MinecraftForge/MinecraftForge.git
synced 2026-11-12 08:17:35 +00:00
Add an event similar to PlayerEvent.NameFormat but for the name shown in the tab list. (#7740)
This commit is contained in:
1 parent
da2594289c
commit
77d41023b5
3 files changed
+76
-3
No files matched your search
@@ -260,6 +260,13 @@ public class ForgeEventFactory
|
||||
MinecraftForge.EVENT_BUS.post(event);
|
||||
return event.getDisplayname();
|
||||
}
|
||||
|
||||
public static ITextComponent getPlayerTabListDisplayName(PlayerEntity player)
|
||||
{
|
||||
PlayerEvent.TabListNameFormat event = new PlayerEvent.TabListNameFormat(player);
|
||||
MinecraftForge.EVENT_BUS.post(event);
|
||||
return event.getDisplayName();
|
||||
}
|
||||
|
||||
public static BlockState fireFluidPlaceBlockEvent(IWorld world, BlockPos pos, BlockPos liquidPos, BlockState state)
|
||||
{
|
||||
|
||||
@@ -22,6 +22,7 @@ package net.minecraftforge.event.entity.player;
|
||||
import java.io.File;
|
||||
|
||||
import net.minecraft.entity.item.ItemEntity;
|
||||
import net.minecraft.entity.player.ServerPlayerEntity;
|
||||
import net.minecraft.inventory.IInventory;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.RegistryKey;
|
||||
@@ -39,6 +40,7 @@ import net.minecraftforge.event.entity.living.LivingEvent;
|
||||
import net.minecraftforge.eventbus.api.Event;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
/**
|
||||
* PlayerEvent is fired whenever an event involving Living entities occurs. <br>
|
||||
@@ -180,6 +182,43 @@ public class PlayerEvent extends LivingEvent
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* TabListNameFormat is fired when a player's display name for the tablist is retrieved.<br>
|
||||
* This event is fired whenever a player's display name for the tablist is retrieved in
|
||||
* {@link ServerPlayerEntity#getTabListDisplayName()} or {@link ServerPlayerEntity#refreshTabListName()}.<br>
|
||||
* <br>
|
||||
* This event is fired via the {@link ForgeEventFactory#getPlayerTabListDisplayName(PlayerEntity)}.<br>
|
||||
* <br>
|
||||
* {@link #getDisplayName()} contains the display name of the player or null if the client should determine the display name itself.
|
||||
* <br>
|
||||
* This event is not {@link net.minecraftforge.eventbus.api.Cancelable}.
|
||||
* <br>
|
||||
* This event does not have a result. {@link HasResult}
|
||||
* <br>
|
||||
* This event is fired on the {@link MinecraftForge#EVENT_BUS}.
|
||||
**/
|
||||
public static class TabListNameFormat extends PlayerEvent
|
||||
{
|
||||
@Nullable
|
||||
private ITextComponent displayName;
|
||||
|
||||
public TabListNameFormat(PlayerEntity player)
|
||||
{
|
||||
super(player);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public ITextComponent getDisplayName()
|
||||
{
|
||||
return displayName;
|
||||
}
|
||||
|
||||
public void setDisplayName(@Nullable ITextComponent displayName)
|
||||
{
|
||||
this.displayName = displayName;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Fired when the EntityPlayer is cloned, typically caused by the network sending a RESPAWN_PLAYER event.
|
||||
* Either caused by death, or by traveling from the End to the overworld.
|
||||
|
||||
Reference in new issue
Block a user