Added a display name to Actors

Dieser Commit ist enthalten in:
Matthew Miller 2018-12-18 17:36:53 +10:00
Ursprung 700e41b706
Commit 8f236afae9
4 geänderte Dateien mit 24 neuen und 1 gelöschten Zeilen

Datei anzeigen

@ -83,6 +83,11 @@ public class BukkitPlayer extends AbstractPlayerActor {
return player.getName();
}
@Override
public String getDisplayName() {
return player.getDisplayName();
}
@Override
public void giveItem(BaseItemStack itemStack) {
player.getInventory().addItem(BukkitAdapter.adapt(itemStack));

Datei anzeigen

@ -38,6 +38,15 @@ public interface Actor extends Identifiable, SessionOwner, Subject {
*/
String getName();
/**
* Gets the display name of the actor. This can be a nickname, and is not guaranteed to be unique.
*
* @return The display name
*/
default String getDisplayName() {
return getName();
}
/**
* Print a message.
*

Datei anzeigen

@ -82,6 +82,11 @@ class PlayerProxy extends AbstractPlayerActor {
return basePlayer.getName();
}
@Override
public String getDisplayName() {
return basePlayer.getDisplayName();
}
@Override
public BaseEntity getState() {
throw new UnsupportedOperationException("Can't getState() on a player");

Datei anzeigen

@ -35,7 +35,6 @@ import com.sk89q.worldedit.world.block.BlockStateHolder;
import com.sk89q.worldedit.world.gamemode.GameMode;
import com.sk89q.worldedit.world.gamemode.GameModes;
import com.sk89q.worldedit.world.item.ItemTypes;
import org.spongepowered.api.Sponge;
import org.spongepowered.api.data.type.HandTypes;
import org.spongepowered.api.entity.living.player.Player;
@ -79,6 +78,11 @@ public class SpongePlayer extends AbstractPlayerActor {
return this.player.getName();
}
@Override
public String getDisplayName() {
return player.getDisplayNameData().displayName().getDirect().map(TextSerializers.LEGACY_FORMATTING_CODE::serialize).orElse(getName());
}
@Override
public BaseEntity getState() {
throw new UnsupportedOperationException("Cannot create a state from this object");