Skip to content

Commit

Permalink
display entity support (#2469)
Browse files Browse the repository at this point in the history
* `billboard` -> `EntityPivot`

* `brightness_*` -> `EntityBrightness`

* `EntityPivot` - minor fixes

* `glow_color` -> `EntityGlowColor`

* `width`/`height` -> `EntityCullingWidth/Height`

* `interpolation_delay` > `EntityInterpolationDelay`

* `EntityInterpolationDuration`

* `shadow_radius` -> `EntityShadowRadius`

* `shadow_strength` -> `EntityShadowStrength`

* `transformation_scale` -> `EntityScale`

* `transformation_translation` > `EntityTranslation`

* Better `DisplayEntityData` transformation handling

* `view_range` -> `EntityViewRange`

* `item_transform` -> `EntityDisplay`

* `text_alignment` -> `EntityDisplay`

* `text_line_width` -> `EntityLineWidth`

* `text` -> `EntityText`

* `text_opacity` -> `EntityOpacity`

* `EntityDefaultBackground`

* `text_is_see_through` -> `EntitySeeThrough`

* `text_is_shadowed` -> `EntityTextShadowed`

* Cleanup `EntityDisplayEntityData`

* Fix `EntityGlowColor` typo

* `interpolation_delay` -> `interpolation_start`

* `interpolation_duration` meta fix

* Properly handle signed->unsigned in `EntityOpacity`

* Improve `EntityViewRange` meta

* `EntityCullingWidth/Height` > `EntityWidth/Height`

* Document what values can be interpolated

* Minor `PropertyRegistry` ordering fix

* Minor meta fix

* `DisplayEntityData` - comment out background color

* Meta fixes

* `PaperAPITools#getText` (Spigot): `null` -> `""`

* Minor meta fixes & code cleanup

* `synonyms` and typo fix

* Add interpolation language doc

* Reference interpolation lang in mechs

* Document `opacity` edge-case

* Copypasta fix

* `EntityLeft/RightRotation`

* `left/right_rotation` -> `primary/secondary`

* Revert "`left/right_rotation` -> `primary/secondary`"

This reverts commit bcaafa5.

* Document `left/right_rotation`
  • Loading branch information
tal5 committed May 11, 2023
1 parent 4d1eb44 commit 3bbe017
Show file tree
Hide file tree
Showing 25 changed files with 1,132 additions and 207 deletions.
Expand Up @@ -20,6 +20,7 @@
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Entity;
import org.bukkit.entity.Player;
import org.bukkit.entity.TextDisplay;
import org.bukkit.event.entity.CreatureSpawnEvent;
import org.bukkit.event.entity.PlayerDeathEvent;
import org.bukkit.event.inventory.InventoryType;
Expand Down Expand Up @@ -316,4 +317,14 @@ public String convertTextToMiniMessage(String text, boolean splitNewlines) {
public Merchant createMerchant(String title) {
return Bukkit.createMerchant(PaperModule.parseFormattedText(title, ChatColor.BLACK));
}

@Override
public String getText(TextDisplay textDisplay) {
return PaperModule.stringifyComponent(textDisplay.text());
}

@Override
public void setText(TextDisplay textDisplay, String text) {
textDisplay.text(PaperModule.parseFormattedText(text, ChatColor.WHITE));
}
}
Expand Up @@ -46,6 +46,9 @@ public static void registerMainProperties() {
PropertyParser.registerProperty(EntityBoatType.class, EntityTag.class);
PropertyParser.registerProperty(EntityBodyArrows.class, EntityTag.class);
PropertyParser.registerProperty(EntityBoundingBox.class, EntityTag.class);
if (NMSHandler.getVersion().isAtLeast(NMSVersion.v1_19)) {
PropertyParser.registerProperty(EntityBrightness.class, EntityTag.class);
}
PropertyParser.registerProperty(EntityCanJoinRaid.class, EntityTag.class);
PropertyParser.registerProperty(EntityCharged.class, EntityTag.class);
PropertyParser.registerProperty(EntityChestCarrier.class, EntityTag.class);
Expand All @@ -56,31 +59,42 @@ public static void registerMainProperties() {
PropertyParser.registerProperty(EntityCustomName.class, EntityTag.class);
PropertyParser.registerProperty(EntityCustomNameVisible.class, EntityTag.class);
PropertyParser.registerProperty(EntityDarkDuration.class, EntityTag.class);
if (NMSHandler.getVersion().isAtLeast(NMSVersion.v1_19)) {
PropertyParser.registerProperty(EntityDefaultBackground.class, EntityTag.class);
}
PropertyParser.registerProperty(EntityDirection.class, EntityTag.class);
PropertyParser.registerProperty(EntityDisabledSlots.class, EntityTag.class);
if (NMSHandler.getVersion().isAtLeast(NMSVersion.v1_19)) {
PropertyParser.registerProperty(EntityDisplayEntityData.class, EntityTag.class);
PropertyParser.registerProperty(EntityDisplay.class, EntityTag.class);
}
PropertyParser.registerProperty(EntityPotionEffects.class, EntityTag.class);
PropertyParser.registerProperty(EntityEquipment.class, EntityTag.class);
PropertyParser.registerProperty(EntityExplosionFire.class, EntityTag.class);
PropertyParser.registerProperty(EntityExplosionRadius.class, EntityTag.class);
PropertyParser.registerProperty(EntityEyeTargetLocation.class, EntityTag.class);
PropertyParser.registerProperty(EntityFirework.class, EntityTag.class);
PropertyParser.registerProperty(EntityFireworkLifetime.class, EntityTag.class);
PropertyParser.registerProperty(EntityFixed.class, EntityTag.class);
PropertyParser.registerProperty(EntityFlags.class, EntityTag.class);
PropertyParser.registerProperty(EntityFlower.class, EntityTag.class);
PropertyParser.registerProperty(EntityFreezeDuration.class, EntityTag.class);
PropertyParser.registerProperty(EntityFramed.class, EntityTag.class);
if (NMSHandler.getVersion().isAtLeast(NMSVersion.v1_19)) {
PropertyParser.registerProperty(EntityGlowColor.class, EntityTag.class);
}
PropertyParser.registerProperty(EntityGravity.class, EntityTag.class);
PropertyParser.registerProperty(EntityHasNectar.class, EntityTag.class);
PropertyParser.registerProperty(EntityHasStung.class, EntityTag.class);
PropertyParser.registerProperty(EntityHealth.class, EntityTag.class);
if (NMSHandler.getVersion().isAtLeast(NMSVersion.v1_19)) {
PropertyParser.registerProperty(EntityHeight.class, EntityTag.class);
PropertyParser.registerProperty(EntityHorns.class, EntityTag.class);
}
PropertyParser.registerProperty(EntityHive.class, EntityTag.class);
PropertyParser.registerProperty(EntityImmune.class, EntityTag.class);
if (NMSHandler.getVersion().isAtLeast(NMSVersion.v1_19)) {
PropertyParser.registerProperty(EntityInterpolationDuration.class, EntityTag.class);
PropertyParser.registerProperty(EntityInterpolationStart.class, EntityTag.class);
}
PropertyParser.registerProperty(EntityInventory.class, EntityTag.class);
PropertyParser.registerProperty(EntityInvulnerable.class, EntityTag.class);
PropertyParser.registerProperty(EntityInWaterTime.class, EntityTag.class);
Expand All @@ -90,45 +104,79 @@ public static void registerMainProperties() {
PropertyParser.registerProperty(EntityItemInOffHand.class, EntityTag.class);
PropertyParser.registerProperty(EntityJumpStrength.class, EntityTag.class);
PropertyParser.registerProperty(EntityKnockback.class, EntityTag.class);
if (NMSHandler.getVersion().isAtLeast(NMSVersion.v1_19)) {
PropertyParser.registerProperty(EntityLeftRotation.class, EntityTag.class);
PropertyParser.registerProperty(EntityLineWidth.class, EntityTag.class);
}
PropertyParser.registerProperty(EntityMarker.class, EntityTag.class);
PropertyParser.registerProperty(EntityMaterial.class, EntityTag.class);
PropertyParser.registerProperty(EntityMaxFuseTicks.class, EntityTag.class);
if (NMSHandler.getVersion().isAtLeast(NMSVersion.v1_19)) {
PropertyParser.registerProperty(EntityOpacity.class, EntityTag.class);
}
PropertyParser.registerProperty(EntityPainting.class, EntityTag.class);
PropertyParser.registerProperty(EntityPatrolLeader.class, EntityTag.class);
PropertyParser.registerProperty(EntityPatrolTarget.class, EntityTag.class);
PropertyParser.registerProperty(EntityPickupStatus.class, EntityTag.class);
if (NMSHandler.getVersion().isAtLeast(NMSVersion.v1_19)) {
PropertyParser.registerProperty(EntityPivot.class, EntityTag.class);
}
PropertyParser.registerProperty(EntityPlayerCreated.class, EntityTag.class);
PropertyParser.registerProperty(EntityPlayingDead.class, EntityTag.class);
PropertyParser.registerProperty(EntityPotion.class, EntityTag.class);
PropertyParser.registerProperty(EntityPotionEffects.class, EntityTag.class);
PropertyParser.registerProperty(EntityPowered.class, EntityTag.class);
PropertyParser.registerProperty(EntityProfession.class, EntityTag.class);
PropertyParser.registerProperty(EntityPumpkinHead.class, EntityTag.class);
PropertyParser.registerProperty(EntityRiptide.class, EntityTag.class);
if (NMSHandler.getVersion().isAtLeast(NMSVersion.v1_19)) {
PropertyParser.registerProperty(EntityRightRotation.class, EntityTag.class);
}
PropertyParser.registerProperty(EntityRotation.class, EntityTag.class);
if (NMSHandler.getVersion().isAtLeast(NMSVersion.v1_19)) {
PropertyParser.registerProperty(EntityScale.class, EntityTag.class);
}
PropertyParser.registerProperty(EntityScoreboardTags.class, EntityTag.class);
PropertyParser.registerProperty(EntitySmall.class, EntityTag.class);
if (NMSHandler.getVersion().isAtLeast(NMSVersion.v1_19)) {
PropertyParser.registerProperty(EntitySeeThrough.class, EntityTag.class);
PropertyParser.registerProperty(EntityShadowRadius.class, EntityTag.class);
PropertyParser.registerProperty(EntityShadowStrength.class, EntityTag.class);
}
PropertyParser.registerProperty(EntityShivering.class, EntityTag.class);
PropertyParser.registerProperty(EntityShotAtAngle.class, EntityTag.class);
PropertyParser.registerProperty(EntityShulkerPeek.class, EntityTag.class);
PropertyParser.registerProperty(EntitySilent.class, EntityTag.class);
PropertyParser.registerProperty(EntitySitting.class, EntityTag.class);
PropertyParser.registerProperty(EntitySize.class, EntityTag.class);
PropertyParser.registerProperty(EntitySmall.class, EntityTag.class);
PropertyParser.registerProperty(EntitySpeed.class, EntityTag.class);
PropertyParser.registerProperty(EntitySpell.class, EntityTag.class);
if (NMSHandler.getVersion().isAtLeast(NMSVersion.v1_19)) {
PropertyParser.registerProperty(EntityStepHeight.class, EntityTag.class);
}
PropertyParser.registerProperty(EntityStrength.class, EntityTag.class);
PropertyParser.registerProperty(EntityTame.class, EntityTag.class);
PropertyParser.registerProperty(EntityEyeTargetLocation.class, EntityTag.class);
if (NMSHandler.getVersion().isAtLeast(NMSVersion.v1_19)) {
PropertyParser.registerProperty(EntityText.class, EntityTag.class);
PropertyParser.registerProperty(EntityTextShadowed.class, EntityTag.class);
}
PropertyParser.registerProperty(EntityTrades.class, EntityTag.class);
if (NMSHandler.getVersion().isAtLeast(NMSVersion.v1_19)) {
PropertyParser.registerProperty(EntityTranslation.class, EntityTag.class);
}
if (NMSHandler.getVersion().isAtLeast(NMSVersion.v1_18)) {
PropertyParser.registerProperty(EntityTrapped.class, EntityTag.class);
PropertyParser.registerProperty(EntityTrapTime.class, EntityTag.class);
}
if (NMSHandler.getVersion().isAtLeast(NMSVersion.v1_19)) {
PropertyParser.registerProperty(EntityViewRange.class, EntityTag.class);
}
PropertyParser.registerProperty(EntityVillagerExperience.class, EntityTag.class);
PropertyParser.registerProperty(EntityVillagerLevel.class, EntityTag.class);
PropertyParser.registerProperty(EntityVisible.class, EntityTag.class);
if (NMSHandler.getVersion().isAtLeast(NMSVersion.v1_19)) {
PropertyParser.registerProperty(EntityWidth.class, EntityTag.class);
}

// register core InventoryTag properties
PropertyParser.registerProperty(InventoryContents.class, InventoryTag.class);
Expand Down
@@ -0,0 +1,70 @@
package com.denizenscript.denizen.objects.properties.entity;

import com.denizenscript.denizen.objects.EntityTag;
import com.denizenscript.denizencore.objects.Mechanism;
import com.denizenscript.denizencore.objects.core.ElementTag;
import com.denizenscript.denizencore.objects.core.MapTag;
import org.bukkit.entity.Display;

public class EntityBrightness extends EntityProperty<MapTag> {

// <--[property]
// @object EntityTag
// @name brightness
// @input MapTag
// @description
// A map of the display entity's brightness override (if any), containing "block" and "sky" keys, each with a brightness level between 0 and 15.
// For the mechanism: provide no input to remove the brightness override.
// -->

public static boolean describes(EntityTag entity) {
return entity.getBukkitEntity() instanceof Display;
}

@Override
public MapTag getPropertyValue() {
Display.Brightness brightness = as(Display.class).getBrightness();
if (brightness == null) {
return null;
}
MapTag brightnessMap = new MapTag();
brightnessMap.putObject("block", new ElementTag(brightness.getBlockLight()));
brightnessMap.putObject("sky", new ElementTag(brightness.getSkyLight()));
return brightnessMap;
}

@Override
public void setPropertyValue(MapTag value, Mechanism mechanism) {
if (value == null) {
as(Display.class).setBrightness(null);
return;
}
Display.Brightness brightness = as(Display.class).getBrightness();
ElementTag blockLightInput = value.getElement("block");
int blockLight = blockLightInput != null ?
blockLightInput.isInt() ? blockLightInput.asInt() : -1
: brightness != null ? brightness.getBlockLight() : 0;
if (blockLight < 0 || blockLight > 15) {
mechanism.echoError("Invalid 'block' brightness, must be a number between 0 and 15.");
return;
}
ElementTag skyLightInput = value.getElement("sky");
int skyLight = skyLightInput != null ?
skyLightInput.isInt() ? skyLightInput.asInt() : -1
: brightness != null ? brightness.getSkyLight() : 0;
if (skyLight < 0 || skyLight > 15) {
mechanism.echoError("Invalid 'sky' brightness, must be a number between 0 and 15.");
return;
}
as(Display.class).setBrightness(new Display.Brightness(blockLight, skyLight));
}

@Override
public String getPropertyId() {
return "brightness";
}

public static void register() {
autoRegisterNullable("brightness", EntityBrightness.class, MapTag.class, false);
}
}
@@ -0,0 +1,48 @@
package com.denizenscript.denizen.objects.properties.entity;

import com.denizenscript.denizen.objects.EntityTag;
import com.denizenscript.denizencore.objects.Mechanism;
import com.denizenscript.denizencore.objects.core.ElementTag;
import org.bukkit.entity.TextDisplay;

public class EntityDefaultBackground extends EntityProperty<ElementTag> {

// TODO: reference the background color property here, once that's created.
// <--[property]
// @object EntityTag
// @name default_background
// @input ElementTag(Boolean)
// @description
// Whether a text display entity's background is default (same as the chat window), or custom set.
// -->

public static boolean describes(EntityTag entity) {
return entity.getBukkitEntity() instanceof TextDisplay;
}

@Override
public ElementTag getPropertyValue() {
return new ElementTag(as(TextDisplay.class).isDefaultBackground());
}

@Override
public boolean isDefaultValue(ElementTag value) {
return !value.asBoolean();
}

@Override
public void setPropertyValue(ElementTag value, Mechanism mechanism) {
if (mechanism.requireBoolean()) {
as(TextDisplay.class).setDefaultBackground(value.asBoolean());
}
}

@Override
public String getPropertyId() {
return "default_background";
}

public static void register() {
autoRegister("default_background", EntityDefaultBackground.class, ElementTag.class, false);
}
}
@@ -0,0 +1,61 @@
package com.denizenscript.denizen.objects.properties.entity;

import com.denizenscript.denizen.objects.EntityTag;
import com.denizenscript.denizencore.objects.Mechanism;
import com.denizenscript.denizencore.objects.core.ElementTag;
import org.bukkit.entity.ItemDisplay;
import org.bukkit.entity.TextDisplay;

public class EntityDisplay extends EntityProperty<ElementTag> {

// <--[property]
// @object EntityTag
// @name display
// @input ElementTag
// @synonyms EntityTag.display_transform, EntityTag.text_alignment
// @description
// For an item display entity this is the model transform it will display, can be any of <@link url https://hub.spigotmc.org/javadocs/spigot/org/bukkit/entity/ItemDisplay.ItemDisplayTransform.html>.
// For a text display entity this is its text alignment, can be any of <@link url https://hub.spigotmc.org/javadocs/spigot/org/bukkit/entity/TextDisplay.html>.
// -->

public static boolean describes(EntityTag entity) {
return entity.getBukkitEntity() instanceof ItemDisplay || entity.getBukkitEntity() instanceof TextDisplay;
}

@Override
public ElementTag getPropertyValue() {
if (getEntity() instanceof ItemDisplay itemDisplay) {
return new ElementTag(itemDisplay.getItemDisplayTransform());
}
return new ElementTag(as(TextDisplay.class).getAlignment());
}

@Override
public boolean isDefaultValue(ElementTag value) {
if (getEntity() instanceof ItemDisplay) {
return value.asEnum(ItemDisplay.ItemDisplayTransform.class) == ItemDisplay.ItemDisplayTransform.NONE;
}
return value.asEnum(TextDisplay.TextAlignment.class) == TextDisplay.TextAlignment.CENTER;
}

@Override
public void setPropertyValue(ElementTag value, Mechanism mechanism) {
if (getEntity() instanceof ItemDisplay itemDisplay) {
if (mechanism.requireEnum(ItemDisplay.ItemDisplayTransform.class)) {
itemDisplay.setItemDisplayTransform(value.asEnum(ItemDisplay.ItemDisplayTransform.class));
}
}
else if (mechanism.requireEnum(TextDisplay.TextAlignment.class)) {
as(TextDisplay.class).setAlignment(value.asEnum(TextDisplay.TextAlignment.class));
}
}

@Override
public String getPropertyId() {
return "display";
}

public static void register() {
autoRegister("display", EntityDisplay.class, ElementTag.class, false);
}
}

0 comments on commit 3bbe017

Please sign in to comment.