Skip to content

Commit

Permalink
Merge pull request #2633 from BentoBoxWorld/develop
Browse files Browse the repository at this point in the history
Version 3.3.0
  • Loading branch information
tastybento authored Mar 9, 2025
2 parents dc907e4 + 5298a47 commit 29156ab
Show file tree
Hide file tree
Showing 6 changed files with 108 additions and 43 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@
<!-- Do not change unless you want different name for local builds. -->
<build.number>-LOCAL</build.number>
<!-- This allows to change between versions. -->
<build.version>3.2.5</build.version>
<build.version>3.3.0</build.version>
<sonar.organization>bentobox-world</sonar.organization>
<sonar.host.url>https://sonarcloud.io</sonar.host.url>
<server.jars>${project.basedir}/lib</server.jars>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import org.bukkit.block.data.Attachable;
import org.bukkit.block.sign.Side;
import org.bukkit.entity.Entity;
import org.bukkit.entity.ItemFrame;
import org.bukkit.entity.Player;
import org.bukkit.inventory.InventoryHolder;
import org.bukkit.inventory.ItemStack;
Expand Down Expand Up @@ -270,6 +271,13 @@ private BlueprintBlock bluePrintBlock(Vector pos, Block block, boolean copyBiome
if (blockState.getBlockData() instanceof Attachable) {
// Placeholder for attachment
bpBlocks.put(pos, new BlueprintBlock("minecraft:air"));
// Check for ItemsAdder block
plugin.getHooks().getHook("ItemsAdder").ifPresent(hook -> {
String iab = ItemsAdderHook.getInCustomRegion(block.getLocation());
if (iab != null) {
b.setItemsAdderBlock(iab);
}
});
bpAttachable.put(pos, b);
return null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import org.bukkit.DyeColor;
import org.bukkit.Location;
import org.bukkit.NamespacedKey;
import org.bukkit.Rotation;
import org.bukkit.World;
import org.bukkit.block.BlockFace;
import org.bukkit.block.data.BlockData;
Expand All @@ -25,6 +26,7 @@
import org.bukkit.entity.Horse.Style;
import org.bukkit.entity.ItemDisplay;
import org.bukkit.entity.ItemDisplay.ItemDisplayTransform;
import org.bukkit.entity.ItemFrame;
import org.bukkit.entity.Tameable;
import org.bukkit.entity.TextDisplay;
import org.bukkit.entity.TextDisplay.TextAlignment;
Expand Down Expand Up @@ -143,7 +145,29 @@ public record TextDisplayRec(@Expose String text, @Expose TextAlignment alignmen
private Boolean invulnerable;
@Expose
private int fireTicks;

/**
* Item in ItemFrames
* @since 3.2.6
*/
public record ItemFrameRec(
@Expose
ItemStack item,
@Expose
Rotation rotation,
@Expose
boolean isFixed,
@Expose
boolean isVisible,
@Expose
float dropChance
) {}
/**
* Item in ItemFrames
* @since 3.2.6
*/
@Expose
private ItemFrameRec itemFrame;

/**
* Serializes an entity to a Blueprint Entity
* @param entity entity to serialize
Expand Down Expand Up @@ -195,6 +219,10 @@ public BlueprintEntity(Entity entity) {
if (entity instanceof Display disp) {
this.storeDisplay(disp);
}
// ItemFrames
if (entity instanceof ItemFrame frame) {
this.setItemFrame(new ItemFrameRec(frame.getItem(), frame.getRotation(), frame.isFixed(), frame.isVisible(), frame.getItemDropChance()));
}

}

Expand Down Expand Up @@ -229,6 +257,10 @@ public void configureEntity(Entity e) {
e.setSilent(isSilent());
e.setInvulnerable(isInvulnerable());
e.setFireTicks(getFireTicks());

if (e instanceof ItemFrame frame) {
setFrame(frame);
}

if (e instanceof Villager villager) {
setVillager(villager);
Expand Down Expand Up @@ -262,6 +294,17 @@ public void configureEntity(Entity e) {
// 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));
}
private void setFrame(ItemFrame frame) {
if (this.itemFrame == null) {
return;
}
frame.setItem(itemFrame.item());
frame.setVisible(itemFrame.isVisible);
frame.setFixed(frame.isFixed());
frame.setRotation(itemFrame.rotation());
frame.setItemDropChance((float)itemFrame.dropChance());
}

/**
* @return the adult
*/
Expand Down Expand Up @@ -663,4 +706,20 @@ public int getFireTicks() {
public void setFireTicks(int fireTicks) {
this.fireTicks = fireTicks;
}

/**
* @return the itemFrame
*/
public ItemFrameRec getItemFrame() {
return itemFrame;
}

/**
* @param itemFrame the itemFrame to set
*/
public void setItemFrame(ItemFrameRec itemFrame) {
this.itemFrame = itemFrame;
}


}
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ public void clearBlockInfo(Location location) {
*/
public static Optional<String> getNamespacedId(ItemStack myItemStack) {
CustomStack stack = CustomStack.byItemStack(myItemStack);
return Optional.of(stack == null ? null : stack.getNamespacedID());
return Optional.ofNullable(stack == null ? null : stack.getNamespacedID());
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,18 +29,6 @@ public CompletableFuture<Void> pasteBlocks(Island island, World world, Map<Locat
);
}

@Override
public CompletableFuture<Void> pasteEntities(Island island, World world, Map<Location, List<BlueprintEntity>> entityMap) {
return entityMap.entrySet().stream()
.map(entry -> DefaultPasteUtil.setEntity(island, entry.getKey(), entry.getValue()))
.collect(
Collectors.collectingAndThen(
Collectors.toList(),
list -> CompletableFuture.allOf(list.toArray(new CompletableFuture[0]))
)
);
}

@Override
public CompletableFuture<Void> setBlock(Island island, Location location, BlueprintBlock bpBlock) {
return DefaultPasteUtil.setBlock(island, location, bpBlock);
Expand Down
66 changes: 38 additions & 28 deletions src/main/java/world/bentobox/bentobox/util/DefaultPasteUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,14 @@
import org.bukkit.block.sign.Side;
import org.bukkit.block.sign.SignSide;
import org.bukkit.configuration.InvalidConfigurationException;
import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Entity;
import org.bukkit.entity.ItemFrame;
import org.bukkit.entity.Player;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.InventoryHolder;
import org.bukkit.spawner.TrialSpawnerConfiguration;

import net.kyori.adventure.text.Component;
import world.bentobox.bentobox.BentoBox;
import world.bentobox.bentobox.api.localization.TextVariables;
import world.bentobox.bentobox.api.user.User;
Expand Down Expand Up @@ -119,7 +121,7 @@ public static BlockData convertBlockData(BlueprintBlock block) {
}

/**
* Handles signs, chests and mob spawner blocks
* Handles signs, chests, frames, and mob spawner blocks
*
* @param island - island
* @param block - block
Expand All @@ -128,40 +130,47 @@ public static BlockData convertBlockData(BlueprintBlock block) {
public static void setBlockState(Island island, Block block, BlueprintBlock bpBlock) {
// Get the block state
BlockState bs = block.getState();
// Signs
if (bs instanceof Sign) {
for (Side side : Side.values()) {
writeSign(island, block, bpBlock, side);
// ItemFrames
if (bs instanceof ItemFrame frame ) {
if (!bpBlock.getInventory().isEmpty()) {
frame.setItem(bpBlock.getInventory().get(0));
bs.update();
}
} else
// Signs
if (bs instanceof Sign) {
for (Side side : Side.values()) {
writeSign(island, block, bpBlock, side);
}
}
}
// Chests, in general
else if (bs instanceof InventoryHolder holder) {
Inventory ih = holder.getInventory();
// Double chests are pasted as two blocks so inventory is filled twice.
// This code stops over-filling for the first block.
bpBlock.getInventory().forEach((slot, item) -> ih.setItem(slot, item));
}
else if (bs instanceof InventoryHolder holder) {
Inventory ih = holder.getInventory();
// Double chests are pasted as two blocks so inventory is filled twice.
// This code stops over-filling for the first block.
bpBlock.getInventory().forEach((slot, item) -> ih.setItem(slot, item));
}
// Mob spawners
else if (bs instanceof CreatureSpawner spawner) {
setSpawner(spawner, bpBlock.getCreatureSpawner());
}
else if (bs instanceof TrialSpawner ts) {
else if (bs instanceof CreatureSpawner spawner) {
setSpawner(spawner, bpBlock.getCreatureSpawner());
}
else if (bs instanceof TrialSpawner ts) {
TrialSpawnerConfiguration config = ts.getNormalConfiguration();
ts.setOminous(bpBlock.getTrialSpawner().configTrialSpawner(config));
if (!bs.update(true, false)) {
BentoBox.getInstance().logError("Trial Spawner update failed!");
}
}
}
// Banners
else if (bs instanceof Banner banner && bpBlock.getBannerPatterns() != null) {
bpBlock.getBannerPatterns().removeIf(Objects::isNull);
banner.setPatterns(bpBlock.getBannerPatterns());
banner.update(true, false);
} else // Check ItemsAdder
if (bpBlock.getItemsAdderBlock() != null && !bpBlock.getItemsAdderBlock().isEmpty()) {
BentoBox.getInstance().getHooks().getHook("ItemsAdder")
else if (bs instanceof Banner banner && bpBlock.getBannerPatterns() != null) {
bpBlock.getBannerPatterns().removeIf(Objects::isNull);
banner.setPatterns(bpBlock.getBannerPatterns());
banner.update(true, false);
} else // Check ItemsAdder
if (bpBlock.getItemsAdderBlock() != null && !bpBlock.getItemsAdderBlock().isEmpty()) {
BentoBox.getInstance().getHooks().getHook("ItemsAdder")
.ifPresent(h -> ItemsAdderHook.place(bpBlock.getItemsAdderBlock(), block.getLocation()));
}
}

}

Expand Down Expand Up @@ -247,7 +256,7 @@ static boolean spawnBlueprintEntity(BlueprintEntity k, Location location, Island
// Nothing
return false;
}
LivingEntity e = (LivingEntity) location.getWorld().spawnEntity(location, k.getType());
Entity e = location.getWorld().spawnEntity(location, k.getType());
if (k.getCustomName() != null) {
String customName = k.getCustomName();

Expand All @@ -264,9 +273,10 @@ static boolean spawnBlueprintEntity(BlueprintEntity k, Location location, Island
}

// Actually set the custom name
e.setCustomName(customName);
e.customName(Component.text(customName));
}
k.configureEntity(e);

return true;
}

Expand Down

0 comments on commit 29156ab

Please sign in to comment.