Fix pasting of other display entities. Remove debug.

This commit is contained in:
tastybento 2024-12-28 10:16:59 -08:00
parent 62a4f63040
commit 30d3fad81f
4 changed files with 437 additions and 319 deletions

View File

@ -12,6 +12,7 @@ import java.util.Optional;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.NamespacedKey;
import org.bukkit.World;
import org.bukkit.block.Banner;
import org.bukkit.block.Block;
@ -20,18 +21,11 @@ import org.bukkit.block.CreatureSpawner;
import org.bukkit.block.Sign;
import org.bukkit.block.data.Attachable;
import org.bukkit.block.sign.Side;
import org.bukkit.entity.AbstractHorse;
import org.bukkit.entity.Ageable;
import org.bukkit.entity.ChestedHorse;
import org.bukkit.entity.Display;
import org.bukkit.entity.Entity;
import org.bukkit.entity.Horse;
import org.bukkit.entity.Player;
import org.bukkit.entity.Tameable;
import org.bukkit.entity.Villager;
import org.bukkit.inventory.InventoryHolder;
import org.bukkit.inventory.ItemStack;
import org.bukkit.material.Colorable;
import org.bukkit.persistence.PersistentDataType;
import org.bukkit.scheduler.BukkitTask;
import org.bukkit.util.BoundingBox;
import org.bukkit.util.Vector;
@ -58,6 +52,10 @@ import world.bentobox.bentobox.hooks.ZNPCsPlusHook;
*/
public class BlueprintClipboard {
/**
* Used to filter out hidden DisplayEntity armor stands when copying
*/
private static final NamespacedKey KEY = new NamespacedKey(BentoBox.getInstance(), "associatedDisplayEntity");
private @Nullable Blueprint blueprint;
private @Nullable Location pos1;
private @Nullable Location pos2;
@ -75,6 +73,7 @@ public class BlueprintClipboard {
private Optional<FancyNpcsHook> npc;
private Optional<ZNPCsPlusHook> znpc;
/**
* Create a clipboard for blueprint
* @param blueprint - the blueprint to load into the clipboard
@ -149,6 +148,7 @@ public class BlueprintClipboard {
// Add all the citizens for the area in one go. This is pretty fast.
bpEntities.putAll(npc.get().getNpcsInArea(world, vectorsToCopy, origin));
}
// ZNPCsPlus NPCs
if (znpc.isPresent()) {
bpEntities.putAll(znpc.get().getNpcsInArea(world, vectorsToCopy, origin));
}
@ -163,6 +163,7 @@ public class BlueprintClipboard {
List<Entity> ents = world.getEntities().stream()
.filter(Objects::nonNull)
.filter(e -> !(e instanceof Player))
.filter(e -> !e.getPersistentDataContainer().has(KEY, PersistentDataType.STRING)) // Do not copy hidden display entities
.filter(e -> new Vector(e.getLocation().getBlockX(), e.getLocation().getBlockY(),
e.getLocation().getBlockZ()).equals(v))
.toList();
@ -230,7 +231,6 @@ public class BlueprintClipboard {
if (!copyAir && block.getType().equals(Material.AIR) && !ents.isEmpty()) {
return true;
}
BentoBox.getInstance().logDebug("Saving blueprint block");
BlueprintBlock b = bluePrintBlock(pos, block, copyBiome);
if (b != null) {
this.bpBlocks.put(pos, b);
@ -241,7 +241,6 @@ public class BlueprintClipboard {
private BlueprintBlock bluePrintBlock(Vector pos, Block block, boolean copyBiome) {
// Block state
BlockState blockState = block.getState();
BentoBox.getInstance().logDebug("saving state");
BlueprintBlock b = new BlueprintBlock(block.getBlockData().getAsString());
if (copyBiome) {
@ -256,7 +255,6 @@ public class BlueprintClipboard {
b.setGlowingText(side, sign.getSide(side).isGlowingText());
}
}
BentoBox.getInstance().logDebug("Get block data");
// Set block data
if (blockState.getBlockData() instanceof Attachable) {
// Placeholder for attachment
@ -264,7 +262,6 @@ public class BlueprintClipboard {
bpAttachable.put(pos, b);
return null;
}
BentoBox.getInstance().logDebug("Check bedrock");
if (block.getType().equals(Material.BEDROCK)) {
// Find highest bedrock
@ -276,7 +273,6 @@ public class BlueprintClipboard {
}
}
}
BentoBox.getInstance().logDebug("Chests");
// Chests
if (blockState instanceof InventoryHolder ih) {
b.setInventory(new HashMap<>());
@ -287,11 +283,9 @@ public class BlueprintClipboard {
}
}
}
BentoBox.getInstance().logDebug("Spawner");
if (blockState instanceof CreatureSpawner spawner) {
b.setCreatureSpawner(getSpawner(spawner));
}
BentoBox.getInstance().logDebug("Banners");
// Banners
if (blockState instanceof Banner banner) {
b.setBannerPatterns(banner.getPatterns());
@ -320,67 +314,15 @@ public class BlueprintClipboard {
private List<BlueprintEntity> setEntities(List<Entity> ents) {
List<BlueprintEntity> bpEnts = new ArrayList<>();
for (Entity entity : ents) {
BlueprintEntity bpe = new BlueprintEntity();
bpe.setType(entity.getType());
bpe.setCustomName(entity.getCustomName());
if (entity instanceof Villager villager) {
setVillager(villager, bpe);
}
if (entity instanceof Colorable c && c.getColor() != null) {
bpe.setColor(c.getColor());
}
if (entity instanceof Tameable tameable) {
bpe.setTamed(tameable.isTamed());
}
if (entity instanceof ChestedHorse chestedHorse) {
bpe.setChest(chestedHorse.isCarryingChest());
}
// Only set if child. Most animals are adults
if (entity instanceof Ageable ageable && !ageable.isAdult()) {
bpe.setAdult(false);
}
if (entity instanceof AbstractHorse horse) {
bpe.setDomestication(horse.getDomestication());
bpe.setInventory(new HashMap<>());
for (int i = 0; i < horse.getInventory().getSize(); i++) {
ItemStack item = horse.getInventory().getItem(i);
if (item != null) {
bpe.getInventory().put(i, item);
}
}
}
if (entity instanceof Horse horse) {
bpe.setStyle(horse.getStyle());
}
BlueprintEntity bpe = new BlueprintEntity(entity);
// Mythic mob check
mmh.filter(mm -> mm.isMythicMob(entity)).map(mm -> mm.getMythicMob(entity))
.ifPresent(bpe::setMythicMobsRecord);
// Display entities
if (entity instanceof Display disp) {
BentoBox.getInstance().logDebug("Storing display: " + disp.getAsString());
bpe.storeDisplay(disp);
}
bpEnts.add(bpe);
}
return bpEnts;
}
/**
* Set the villager stats
* @param v - villager
* @param bpe - Blueprint Entity
*/
private void setVillager(Villager v, BlueprintEntity bpe) {
bpe.setExperience(v.getVillagerExperience());
bpe.setLevel(v.getVillagerLevel());
bpe.setProfession(v.getProfession());
bpe.setVillagerType(v.getVillagerType());
}
/**
* @return the origin
*/

View File

@ -13,7 +13,6 @@ import org.bukkit.event.player.PlayerInteractAtEntityEvent;
import org.bukkit.persistence.PersistentDataType;
import world.bentobox.bentobox.BentoBox;
import world.bentobox.bentobox.api.user.User;
/**
* Provides a listener for the Display Objects pasted when a hologram is interacted with
@ -23,7 +22,6 @@ public class DisplayListener implements Listener {
@EventHandler
public void onPlayerInteractEntity(PlayerInteractAtEntityEvent event) {
BentoBox.getInstance().logDebug(event.getEventName());
if (event.getRightClicked() instanceof ArmorStand) {
ArmorStand armorStand = (ArmorStand) event.getRightClicked();
NamespacedKey key = new NamespacedKey(BentoBox.getInstance(), "associatedDisplayEntity");
@ -36,15 +34,11 @@ public class DisplayListener implements Listener {
world.getEntitiesByClass(Display.class).stream()
.filter(e -> e.getUniqueId().equals(UUID.fromString(displayEntityUUID))).findFirst()
.ifPresent(e -> {
User user = User.getInstance(event.getPlayer());
user.sendRawMessage("You interacted with a DisplayEntity! ");
event.getPlayer().playSound(event.getPlayer().getLocation(), Sound.BLOCK_GLASS_BREAK, 1F,
1F);
e.remove();
});
// Perform actions related to the DisplayEntity
}
}
}

View File

@ -1,5 +1,6 @@
package world.bentobox.bentobox.blueprints.dataobjects;
import java.util.HashMap;
import java.util.Map;
import org.bukkit.Bukkit;
@ -38,8 +39,6 @@ import org.bukkit.util.Vector;
import com.google.gson.annotations.Expose;
import world.bentobox.bentobox.BentoBox;
import world.bentobox.bentobox.blueprints.dataobjects.BlueprintEntity.ItemDispRec.DisplayRec;
import world.bentobox.bentobox.blueprints.dataobjects.BlueprintEntity.ItemDispRec.TextDisplayRec;
/**
* @author tastybento
@ -47,48 +46,82 @@ import world.bentobox.bentobox.blueprints.dataobjects.BlueprintEntity.ItemDispRe
*/
public class BlueprintEntity {
// Npc storage
@Expose
private String npc;
// MythicMobs storage
public record MythicMobRecord(String type, String displayName, double level, float power, String stance) {
}
// GSON can serialize records, but the record class needs to be know in advance. So this breaks out the record entries
@Expose
String MMtype;
@Expose
Double MMLevel;
@Expose
String MMStance;
@Expose
Float MMpower;
/**
* Item Display Entity store
* @since 3.2.0
*/
public record ItemDispRec(@Expose ItemStack item, @Expose ItemDisplayTransform itemDispTrans) {}
@Expose
private DyeColor color;
@Expose
private EntityType type;
@Expose
private String customName;
@Expose
private Boolean tamed;
@Expose
private Boolean chest;
/**
* Display Entity store
* @since 3.2.0
*/
public record DisplayRec(@Expose Billboard billboard, @Expose Brightness brightness, @Expose float height,
@Expose float width, @Expose Color glowColorOverride, @Expose int interpolationDelay,
@Expose int interpolationDuration, @Expose float shadowRadius, @Expose float shadowStrength,
@Expose int teleportDuration, @Expose Transformation transformation, @Expose float range) {
}
/**
* TextDisplay entity store
* @since 3.2.0
*/
public record TextDisplayRec(@Expose String text, @Expose TextAlignment alignment, @Expose Color bgColor,
@Expose BlockFace face, @Expose int lWidth, @Expose byte opacity, @Expose boolean isShadowed,
@Expose boolean isSeeThrough, @Expose boolean isDefaultBg) {
}
@Expose
private Boolean adult;
@Expose
public BlueprintBlock blockDisp;
@Expose
private Boolean chest;
@Expose
private DyeColor color;
@Expose
private String customName;
@Expose
public DisplayRec displayRec;
@Expose
private Integer domestication;
@Expose
private Integer experience;
@Expose
private Map<Integer, ItemStack> inventory;
@Expose
private Style style;
public ItemDispRec itemDisp;
@Expose
private Integer level;
@Expose
Double MMLevel;
@Expose
Float MMpower;
@Expose
String MMStance;
// GSON can serialize records, but the record class needs to be know in advance. So this breaks out the record entries
@Expose
String MMtype;
// Npc storage
@Expose
private String npc;
@Expose
private Profession profession;
@Expose
private Integer experience;
private Style style;
@Expose
private Boolean tamed;
@Expose
public TextDisplayRec textDisp;
@Expose
private EntityType type;
@Expose
private Villager.Type villagerType;
// Position within the block
@ -98,12 +131,104 @@ public class BlueprintEntity {
private double y;
@Expose
private double z;
@Expose
private boolean glowing;
@Expose
private boolean gravity;
@Expose
private boolean visualFire;
@Expose
private boolean silent;
@Expose
private boolean invulnerable;
@Expose
private int fireTicks;
/**
* Serializes an entity to a Blueprint Entity
* @param entity entity to serialize
* @since 3.2.0
*/
public BlueprintEntity(Entity entity) {
this.setType(entity.getType());
this.setCustomName(entity.getCustomName());
this.setGlowing(entity.isGlowing());
this.setGravity(entity.hasGravity());
this.setVisualFire(entity.isVisualFire());
this.setSilent(entity.isSilent());
this.setInvulnerable(entity.isInvulnerable());
this.setFireTicks(entity.getFireTicks());
if (entity instanceof Villager villager) {
configVillager(villager);
}
if (entity instanceof Colorable c && c.getColor() != null) {
this.setColor(c.getColor());
}
if (entity instanceof Tameable tameable) {
this.setTamed(tameable.isTamed());
}
if (entity instanceof ChestedHorse chestedHorse) {
this.setChest(chestedHorse.isCarryingChest());
}
// Only set if child. Most animals are adults
if (entity instanceof Ageable ageable && !ageable.isAdult()) {
this.setAdult(false);
}
if (entity instanceof AbstractHorse horse) {
this.setDomestication(horse.getDomestication());
this.setInventory(new HashMap<>());
for (int i = 0; i < horse.getInventory().getSize(); i++) {
ItemStack item = horse.getInventory().getItem(i);
if (item != null) {
this.getInventory().put(i, item);
}
}
}
if (entity instanceof Horse horse) {
this.setStyle(horse.getStyle());
}
// Display entities
if (entity instanceof Display disp) {
this.storeDisplay(disp);
}
}
/**
* Makes a blank BlueprintEntity
*/
public BlueprintEntity() {
// Blank constructor
}
/**
* Set the villager stats
* @param v - villager
* @param bpe - Blueprint Entity
*/
private void configVillager(Villager v) {
this.setExperience(v.getVillagerExperience());
this.setLevel(v.getVillagerLevel());
this.setProfession(v.getProfession());
this.setVillagerType(v.getVillagerType());
}
/**
* Adjusts the entity according to how it was stored
* @since 1.8.0
*/
public void configureEntity(Entity e) {
// Set the general states
e.setGlowing(glowing);
e.setGravity(gravity);
e.setVisualFire(visualFire);
e.setSilent(silent);
e.setInvulnerable(invulnerable);
e.setFireTicks(fireTicks);
if (e instanceof Villager villager) {
setVillager(villager);
}
@ -133,83 +258,8 @@ public class BlueprintEntity {
if (style != null && e instanceof Horse horse) {
horse.setStyle(style);
}
// Shift to the in-block location
Vector add = new Vector(x, y, z);
BentoBox.getInstance().logDebug("entity is at " + e.getLocation().toVector() + " and adding " + add);
e.getLocation().add(add);
BentoBox.getInstance().logDebug("entity is now at " + e.getLocation().toVector());
}
/**
* @param v - villager
* @since 1.16.0
*/
private void setVillager(Villager v) {
v.setProfession(profession == null ? Profession.NONE : profession);
v.setVillagerExperience(experience == null ? 0 : experience);
v.setVillagerLevel(level == null ? 0 : level);
v.setVillagerType(villagerType == null ? Villager.Type.PLAINS : villagerType);
}
/**
* @return the color
*/
public DyeColor getColor() {
return color;
}
/**
* @param color the color to set
*/
public void setColor(DyeColor color) {
this.color = color;
}
/**
* @return the type
*/
public EntityType getType() {
return type;
}
/**
* @param type the type to set
*/
public void setType(EntityType type) {
this.type = type;
}
/**
* @return the customName
*/
public String getCustomName() {
return customName;
}
/**
* @param customName the customName to set
*/
public void setCustomName(String customName) {
this.customName = customName;
}
/**
* @return the tamed
*/
public Boolean getTamed() {
return tamed;
}
/**
* @param tamed the tamed to set
*/
public void setTamed(Boolean tamed) {
this.tamed = tamed;
}
/**
* @return the chest
*/
public Boolean getChest() {
return chest;
}
/**
* @param chest the chest to set
*/
public void setChest(Boolean chest) {
this.chest = chest;
// Shift to the in-block location (remove the 0.5 that the location serializer used)
e.getLocation().add(new Vector(x - 0.5D, y, z - 0.5D));
}
/**
* @return the adult
@ -218,10 +268,22 @@ public class BlueprintEntity {
return adult;
}
/**
* @param adult the adult to set
* @return the chest
*/
public void setAdult(Boolean adult) {
this.adult = adult;
public Boolean getChest() {
return chest;
}
/**
* @return the color
*/
public DyeColor getColor() {
return color;
}
/**
* @return the customName
*/
public String getCustomName() {
return customName;
}
/**
* @return the domestication
@ -230,10 +292,10 @@ public class BlueprintEntity {
return domestication;
}
/**
* @param domestication the domestication to set
* @return the experience
*/
public void setDomestication(int domestication) {
this.domestication = domestication;
public Integer getExperience() {
return experience;
}
/**
* @return the inventory
@ -242,10 +304,31 @@ public class BlueprintEntity {
return inventory;
}
/**
* @param inventory the inventory to set
* @return the level
*/
public void setInventory(Map<Integer, ItemStack> inventory) {
this.inventory = inventory;
public Integer getLevel() {
return level;
}
/**
* @return the mythicMobsRecord
*/
public MythicMobRecord getMythicMobsRecord() {
if (this.MMtype == null || this.MMLevel == null || this.MMpower == null || this.MMStance == null) {
return null;
}
return new MythicMobRecord(this.MMtype, this.getCustomName(), this.MMLevel, this.MMpower, this.MMStance);
}
/**
* @return the npc
*/
public String getNpc() {
return npc;
}
/**
* @return the profession
*/
public Profession getProfession() {
return profession;
}
/**
* @return the style
@ -253,53 +336,19 @@ public class BlueprintEntity {
public Style getStyle() {
return style;
}
/**
* @param style the style to set
* @return the tamed
*/
public void setStyle(Style style) {
this.style = style;
public Boolean getTamed() {
return tamed;
}
/**
* @return the level
* @return the type
*/
public Integer getLevel() {
return level;
}
/**
* @param level the level to set
*/
public void setLevel(Integer level) {
this.level = level;
}
/**
* @return the profession
*/
public Profession getProfession() {
return profession;
}
/**
* @param profession the profession to set
*/
public void setProfession(Profession profession) {
this.profession = profession;
}
/**
* @return the experience
*/
public Integer getExperience() {
return experience;
}
/**
* @param experience the experience to set
*/
public void setExperience(Integer experience) {
this.experience = experience;
public EntityType getType() {
return type;
}
/**
@ -310,10 +359,93 @@ public class BlueprintEntity {
}
/**
* @param villagerType the villagerType to set
* @param adult the adult to set
*/
public void setVillagerType(Villager.Type villagerType) {
this.villagerType = villagerType;
public void setAdult(Boolean adult) {
this.adult = adult;
}
/**
* @param chest the chest to set
*/
public void setChest(Boolean chest) {
this.chest = chest;
}
/**
* @param color the color to set
*/
public void setColor(DyeColor color) {
this.color = color;
}
/**
* @param customName the customName to set
*/
public void setCustomName(String customName) {
this.customName = customName;
}
/**
* Sets any display entity properties to the location, e.g. holograms
* @param pos location
*/
public void setDisplay(Location pos) {
World world = pos.getWorld();
Location newPos = pos.clone().add(new Vector(x - 0.5D, y, z - 0.5D));
Display d = null;
if (this.blockDisp != null) {
// Block Display
d = world.spawn(newPos, BlockDisplay.class);
BlockData bd = Bukkit.createBlockData(this.blockDisp.getBlockData());
((BlockDisplay) d).setBlock(bd);
} else if (this.itemDisp != null) {
// Item Display
d = world.spawn(newPos, ItemDisplay.class);
((ItemDisplay) d).setItemStack(itemDisp.item());
((ItemDisplay) d).setItemDisplayTransform(itemDisp.itemDispTrans());
} else if (this.textDisp != null) {
// Text Display
d = world.spawn(newPos, TextDisplay.class);
((TextDisplay) d).setText(textDisp.text());
((TextDisplay) d).setAlignment(textDisp.alignment());
((TextDisplay) d).setBackgroundColor(textDisp.bgColor());
((TextDisplay) d).setLineWidth(textDisp.lWidth());
((TextDisplay) d).setTextOpacity(textDisp.opacity());
((TextDisplay) d).setShadowed(textDisp.isShadowed());
((TextDisplay) d).setSeeThrough(textDisp.isSeeThrough());
((TextDisplay) d).setBackgroundColor(textDisp.bgColor());
}
if (d != null && this.displayRec != null) {
d.setCustomName(getCustomName());
d.setBillboard(displayRec.billboard());
d.setBrightness(displayRec.brightness());
d.setDisplayHeight(displayRec.height());
d.setDisplayWidth(displayRec.width());
d.setGlowColorOverride(displayRec.glowColorOverride());
d.setInterpolationDelay(displayRec.interpolationDelay());
d.setInterpolationDuration(displayRec.interpolationDuration());
d.setShadowRadius(displayRec.shadowRadius());
d.setShadowStrength(displayRec.shadowStrength());
d.setTeleportDuration(displayRec.teleportDuration());
d.setTransformation(displayRec.transformation());
d.setViewRange(displayRec.range());
// Spawn an armor stand here so that we have a way to detect if a player interacts with the item
ArmorStand armorStand = (ArmorStand) world.spawnEntity(newPos, EntityType.ARMOR_STAND);
armorStand.setSmall(true); // Reduces size
armorStand.setGravity(false); // Prevents falling
armorStand.setInvisible(true);
NamespacedKey key = new NamespacedKey(BentoBox.getInstance(), "associatedDisplayEntity");
armorStand.getPersistentDataContainer().set(key, PersistentDataType.STRING, d.getUniqueId().toString());
}
}
/**
* @param domestication the domestication to set
*/
public void setDomestication(int domestication) {
this.domestication = domestication;
}
/**
@ -324,13 +456,24 @@ public class BlueprintEntity {
}
/**
* @return the mythicMobsRecord
* @param experience the experience to set
*/
public MythicMobRecord getMythicMobsRecord() {
if (this.MMtype == null || this.MMLevel == null || this.MMpower == null || this.MMStance == null) {
return null;
}
return new MythicMobRecord(this.MMtype, this.getCustomName(), this.MMLevel, this.MMpower, this.MMStance);
public void setExperience(Integer experience) {
this.experience = experience;
}
/**
* @param inventory the inventory to set
*/
public void setInventory(Map<Integer, ItemStack> inventory) {
this.inventory = inventory;
}
/**
* @param level the level to set
*/
public void setLevel(Integer level) {
this.level = level;
}
/**
@ -344,41 +487,55 @@ public class BlueprintEntity {
this.MMStance = mmr.stance();
this.MMpower = mmr.power();
}
/**
* @return the npc
*/
public String getNpc() {
return npc;
}
/**
* @param npc the citizen to set
*/
public void setNpc(String npc) {
this.npc = npc;
}
@Expose
public DisplayRec displayRec;
@Expose
public TextDisplayRec textDisp;
@Expose
public BlueprintBlock blockDisp;
@Expose
public ItemDispRec itemDisp;
public record ItemDispRec(@Expose ItemStack item, @Expose ItemDisplayTransform itemDispTrans) {}
public record DisplayRec(@Expose Billboard billboard, @Expose Brightness brightness, @Expose float height,
@Expose float width, @Expose Color glowColorOverride, @Expose int interpolationDelay,
@Expose int interpolationDuration, @Expose float shadowRadius, @Expose float shadowStrength,
@Expose int teleportDuration, @Expose Transformation transformation, @Expose float range) {
/**
* @param profession the profession to set
*/
public void setProfession(Profession profession) {
this.profession = profession;
}
/**
* @param style the style to set
*/
public void setStyle(Style style) {
this.style = style;
}
public record TextDisplayRec(@Expose String text, @Expose TextAlignment alignment, @Expose Color bgColor,
@Expose BlockFace face, @Expose int lWidth, @Expose byte opacity, @Expose boolean isShadowed,
@Expose boolean isSeeThrough, @Expose boolean isDefaultBg) {
/**
* @param tamed the tamed to set
*/
public void setTamed(Boolean tamed) {
this.tamed = tamed;
}
/**
* @param type the type to set
*/
public void setType(EntityType type) {
this.type = type;
}
/**
* @param v - villager
* @since 1.16.0
*/
private void setVillager(Villager v) {
v.setProfession(profession == null ? Profession.NONE : profession);
v.setVillagerExperience(experience == null ? 0 : experience);
v.setVillagerLevel(level == null ? 0 : level);
v.setVillagerType(villagerType == null ? Villager.Type.PLAINS : villagerType);
}
/**
* @param villagerType the villagerType to set
*/
public void setVillagerType(Villager.Type villagerType) {
this.villagerType = villagerType;
}
/**
@ -408,60 +565,86 @@ public class BlueprintEntity {
}
/**
* Sets any display entity properties to the location, e.g. holograms
* @param pos location
* @return the glowing
*/
public void setDisplay(Location pos) {
World world = pos.getWorld();
Location newPos = pos.clone().add(new Vector(x - 0.5D, y, z - 0.5D));
Display d = null;
if (this.blockDisp != null) {
// Block Display
d = world.spawn(newPos, BlockDisplay.class);
BlockData bd = Bukkit.createBlockData(this.blockDisp.getBlockData());
((BlockDisplay) d).setBlock(bd);
} else if (this.itemDisp != null) {
// Item Display
d = world.spawn(newPos, ItemDisplay.class);
((ItemDisplay) d).setItemStack(itemDisp.item());
((ItemDisplay) d).setItemDisplayTransform(itemDisp.itemDispTrans());
} else if (this.textDisp != null) {
BentoBox.getInstance().logDebug("Text display - " + textDisp.text());
// Text Display
d = world.spawn(newPos, TextDisplay.class);
((TextDisplay) d).setText(textDisp.text());
((TextDisplay) d).setAlignment(textDisp.alignment());
((TextDisplay) d).setBackgroundColor(textDisp.bgColor());
((TextDisplay) d).setLineWidth(textDisp.lWidth());
((TextDisplay) d).setTextOpacity(textDisp.opacity());
((TextDisplay) d).setShadowed(textDisp.isShadowed());
((TextDisplay) d).setSeeThrough(textDisp.isSeeThrough());
((TextDisplay) d).setBackgroundColor(textDisp.bgColor());
}
if (d != null && this.displayRec != null) {
BentoBox.getInstance().logDebug("General display");
d.setCustomName(getCustomName());
d.setBillboard(displayRec.billboard());
d.setBrightness(displayRec.brightness());
d.setDisplayHeight(displayRec.height());
d.setDisplayWidth(displayRec.width());
d.setGlowColorOverride(displayRec.glowColorOverride());
d.setInterpolationDelay(displayRec.interpolationDelay());
d.setInterpolationDuration(displayRec.interpolationDuration());
d.setShadowRadius(displayRec.shadowRadius());
d.setShadowStrength(displayRec.shadowStrength());
d.setTeleportDuration(displayRec.teleportDuration());
d.setTransformation(displayRec.transformation());
d.setViewRange(displayRec.range());
}
// Spawn an armor stand here so that we have a way to detect if a player interacts with the item
ArmorStand armorStand = (ArmorStand) world.spawnEntity(newPos, EntityType.ARMOR_STAND);
armorStand.setSmall(true); // Reduces size
armorStand.setGravity(false); // Prevents falling
//armorStand.setInvisible(true);
//armorStand.setMarker(true); // No hitbox
NamespacedKey key = new NamespacedKey(BentoBox.getInstance(), "associatedDisplayEntity");
armorStand.getPersistentDataContainer().set(key, PersistentDataType.STRING, d.getUniqueId().toString());
BentoBox.getInstance().logDebug("display set done");
public boolean isGlowing() {
return glowing;
}
/**
* @param glowing the glowing to set
*/
public void setGlowing(boolean glowing) {
this.glowing = glowing;
}
/**
* @return the gravity
*/
public boolean isGravity() {
return gravity;
}
/**
* @param gravity the gravity to set
*/
public void setGravity(boolean gravity) {
this.gravity = gravity;
}
/**
* @return the visualFire
*/
public boolean isVisualFire() {
return visualFire;
}
/**
* @param visualFire the visualFire to set
*/
public void setVisualFire(boolean visualFire) {
this.visualFire = visualFire;
}
/**
* @return the silent
*/
public boolean isSilent() {
return silent;
}
/**
* @param silent the silent to set
*/
public void setSilent(boolean silent) {
this.silent = silent;
}
/**
* @return the invulnerable
*/
public boolean isInvulnerable() {
return invulnerable;
}
/**
* @param invulnerable the invulnerable to set
*/
public void setInvulnerable(boolean invulnerable) {
this.invulnerable = invulnerable;
}
/**
* @return the fireTicks
*/
public int getFireTicks() {
return fireTicks;
}
/**
* @param fireTicks the fireTicks to set
*/
public void setFireTicks(int fireTicks) {
this.fireTicks = fireTicks;
}
}

View File

@ -189,7 +189,6 @@ public class DefaultPasteUtil {
* @return true if Bukkit entity spawned, false another plugin entity spawned
*/
static boolean spawnBlueprintEntity(BlueprintEntity k, Location location, Island island) {
BentoBox.getInstance().logDebug("spawn blueprint entiy " + k + " at " + location);
// Display Entity (holograms, etc.)
k.setDisplay(location);
// FancyNpc entity