diff --git a/pom.xml b/pom.xml index e29d7d061..3198bfad0 100644 --- a/pom.xml +++ b/pom.xml @@ -419,6 +419,13 @@ 2.0.0-SNAPSHOT provided + + + de.oliver + FancyHolograms + 2.4.1 + provided + diff --git a/src/main/java/world/bentobox/bentobox/blueprints/BlueprintClipboard.java b/src/main/java/world/bentobox/bentobox/blueprints/BlueprintClipboard.java index 6d678bd08..a5ae6ad1b 100644 --- a/src/main/java/world/bentobox/bentobox/blueprints/BlueprintClipboard.java +++ b/src/main/java/world/bentobox/bentobox/blueprints/BlueprintClipboard.java @@ -22,6 +22,7 @@ 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; @@ -356,6 +357,11 @@ public class BlueprintClipboard { mmh.filter(mm -> mm.isMythicMob(entity)).map(mm -> mm.getMythicMob(entity)) .ifPresent(bpe::setMythicMobsRecord); + // Display entities + if (entity instanceof Display disp) { + BentoBox.getInstance().logDebug(disp.getAsString()); + bpe.storeDisplay(disp); + } bpEnts.add(bpe); } return bpEnts; diff --git a/src/main/java/world/bentobox/bentobox/blueprints/dataobjects/BlueprintEntity.java b/src/main/java/world/bentobox/bentobox/blueprints/dataobjects/BlueprintEntity.java index 2ce285fee..b37bc3fe5 100644 --- a/src/main/java/world/bentobox/bentobox/blueprints/dataobjects/BlueprintEntity.java +++ b/src/main/java/world/bentobox/bentobox/blueprints/dataobjects/BlueprintEntity.java @@ -2,19 +2,32 @@ package world.bentobox.bentobox.blueprints.dataobjects; import java.util.Map; +import org.bukkit.Color; import org.bukkit.DyeColor; +import org.bukkit.Location; +import org.bukkit.World; +import org.bukkit.block.BlockFace; +import org.bukkit.block.data.BlockData; import org.bukkit.entity.AbstractHorse; import org.bukkit.entity.Ageable; +import org.bukkit.entity.BlockDisplay; import org.bukkit.entity.ChestedHorse; +import org.bukkit.entity.Display; +import org.bukkit.entity.Display.Billboard; +import org.bukkit.entity.Display.Brightness; import org.bukkit.entity.Entity; import org.bukkit.entity.EntityType; import org.bukkit.entity.Horse; import org.bukkit.entity.Horse.Style; +import org.bukkit.entity.ItemDisplay; import org.bukkit.entity.Tameable; +import org.bukkit.entity.TextDisplay; +import org.bukkit.entity.TextDisplay.TextAlignment; import org.bukkit.entity.Villager; import org.bukkit.entity.Villager.Profession; import org.bukkit.inventory.ItemStack; import org.bukkit.material.Colorable; +import org.bukkit.util.Transformation; import com.google.gson.annotations.Expose; @@ -342,4 +355,138 @@ public class BlueprintEntity { + (villagerType != null ? "villagerType=" + villagerType : "") + "]"; } + + + + @Expose + public DisplayRec displayRec; + @Expose + public TextDisplayRec textDisp; + @Expose + public BlockData blockDisp; + @Expose + public ItemStack itemDisp; + + 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) { + } + + 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) { + } + + /** + * BlockDisplay, ItemDisplay, TextDisplay + * @param disp display entity + */ + public void storeDisplay(Display disp) { + // Generic items + displayRec = new DisplayRec(disp.getBillboard(), disp.getBrightness(), disp.getDisplayHeight(), + disp.getDisplayWidth(), disp.getGlowColorOverride(), disp.getInterpolationDelay(), + disp.getInterpolationDuration(), disp.getShadowRadius(), disp.getShadowStrength(), + disp.getTeleportDuration(), disp.getTransformation(), disp.getViewRange()); + // Class specific items + if (disp instanceof BlockDisplay bd) { + this.blockDisp = bd.getBlock(); + } else if (disp instanceof ItemDisplay id) { + itemDisp = id.getItemStack(); + } else if (disp instanceof TextDisplay td) { + textDisp = new TextDisplayRec(td.getText(), td.getAlignment(), td.getBackgroundColor(), + td.getFacing(), td.getLineWidth(), td.getTextOpacity(), td.isShadowed(), td.isSeeThrough(), + td.isDefaultBackground()); + } + + // , getBrightness, getDisplayHeight, getDisplayWidth, getGlowColorOverride, getInterpolationDelay, getInterpolationDuration, + //getShadowRadius, getShadowStrength, getTeleportDuration, getTransformation, getViewRange, setBillboard, setBrightness, + // setDisplayHeight, setDisplayWidth, setGlowColorOverride, setInterpolationDelay, setInterpolationDuration, setShadowRadius, setShadowStrength, setTeleportDuration, setTransformation, setTransformationMatrix, setViewRange + } + + /** + * Sets any display entity properties to the location, e.g. holograms + * @param pos location + */ + public void setDisplay(Location pos) { + World world = pos.getWorld(); + Display d = null; + if (this.blockDisp != null) { + // Block Display + d = world.spawn(pos, BlockDisplay.class); + ((BlockDisplay) d).setBlock(this.blockDisp); + } else if (this.itemDisp != null) { + // Item Display + d = world.spawn(pos, ItemDisplay.class); + ((ItemDisplay) d).setItemStack(itemDisp); + } else if (this.textDisp != null) { + // Block Display + d = world.spawn(pos, 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.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()); + } + } + + /** + * @return the displayRec + */ + public DisplayRec getDisplayRec() { + return displayRec; + } + + /** + * @param displayRec the displayRec to set + */ + public void setDisplayRec(DisplayRec displayRec) { + this.displayRec = displayRec; + } + + /** + * @return the blockDisp + */ + public BlockData getBlockDisp() { + return blockDisp; + } + + /** + * @param blockDisp the blockDisp to set + */ + public void setBlockDisp(BlockData blockDisp) { + this.blockDisp = blockDisp; + } + + /** + * @return the itemDisp + */ + public ItemStack getItemDisp() { + return itemDisp; + } + + /** + * @param itemDisp the itemDisp to set + */ + public void setItemDisp(ItemStack itemDisp) { + this.itemDisp = itemDisp; + } + } diff --git a/src/main/java/world/bentobox/bentobox/database/json/adapters/MaterialTypeAdapter.java b/src/main/java/world/bentobox/bentobox/database/json/adapters/MaterialTypeAdapter.java index e5efa70a9..13e5d3401 100644 --- a/src/main/java/world/bentobox/bentobox/database/json/adapters/MaterialTypeAdapter.java +++ b/src/main/java/world/bentobox/bentobox/database/json/adapters/MaterialTypeAdapter.java @@ -17,7 +17,7 @@ import com.google.gson.stream.JsonWriter; /** * Minecraft 1.20 changed GRASS to SHORT_GRASS. This class provides and backwards compatibility when loading - * databased files stored with previous versions. It can be extended in the future if further enum changes are made. + * database files stored with previous versions. It can be extended in the future if further enum changes are made. * @author tastybento * @since 2.0.0 */ diff --git a/src/main/java/world/bentobox/bentobox/hooks/FancyHologramsHook.java b/src/main/java/world/bentobox/bentobox/hooks/FancyHologramsHook.java new file mode 100644 index 000000000..650e39133 --- /dev/null +++ b/src/main/java/world/bentobox/bentobox/hooks/FancyHologramsHook.java @@ -0,0 +1,35 @@ +package world.bentobox.bentobox.hooks; + +import org.bukkit.Material; + +import world.bentobox.bentobox.BentoBox; +import world.bentobox.bentobox.api.hooks.Hook; + +/** + * Provides copy and pasting of FancyHolograms in blueprints + * + * @author tastybento + * @since 3.2.0 + */ +public class FancyHologramsHook extends Hook { + + public FancyHologramsHook() { + super("FancyHolograms", Material.END_PORTAL); + } + + + @Override + public boolean hook() { + boolean hooked = this.isPluginAvailable(); + if (!hooked) { + BentoBox.getInstance().logError("Could not hook into FancyHolograms"); + } + return hooked; // The hook process shouldn't fail + } + + @Override + public String getFailureCause() { + return null; // The hook process shouldn't fail + } + +} diff --git a/src/main/java/world/bentobox/bentobox/util/DefaultPasteUtil.java b/src/main/java/world/bentobox/bentobox/util/DefaultPasteUtil.java index 2e6083026..2de5ae600 100644 --- a/src/main/java/world/bentobox/bentobox/util/DefaultPasteUtil.java +++ b/src/main/java/world/bentobox/bentobox/util/DefaultPasteUtil.java @@ -189,6 +189,8 @@ public class DefaultPasteUtil { * @return true if Bukkit entity spawned, false another plugin entity spawned */ static boolean spawnBlueprintEntity(BlueprintEntity k, Location location, Island island) { + // Display Entity (holograms, etc.) + k.setDisplay(location); // FancyNpc entity if (k.getNpc() != null && plugin.getHooks().getHook("FancyNpcs").filter(mmh -> mmh instanceof FancyNpcsHook).map(mmh -> { diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml index 9ddec656a..d314626f3 100644 --- a/src/main/resources/plugin.yml +++ b/src/main/resources/plugin.yml @@ -25,6 +25,8 @@ softdepend: - EconomyPlus - MythicMobs - ZNPCsPlus + - FancyNpcs + - FancyHolograms libraries: - mysql:mysql-connector-java:${mysql.version}