Skip to content

Commit

Permalink
Merge pull request #2579 from BentoBoxWorld/develop
Browse files Browse the repository at this point in the history
Version 3.2.0
  • Loading branch information
tastybento authored Dec 29, 2024
2 parents e811f90 + da8ad2f commit cf51aec
Show file tree
Hide file tree
Showing 40 changed files with 1,245 additions and 357 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/modrinth-publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ jobs:
cache: maven

# This step will take the version tag from the release and replace it in `pom.xml` before building.
- name: Set version from release tag
run: mvn -B versions:set -DnewVersion=${{ github.event.release.tag_name }} -DgenerateBackupPoms=false
#- name: Set version from release tag
# run: mvn -B versions:set -DnewVersion=${{ github.event.release.tag_name }} -DgenerateBackupPoms=false

- name: Build and package with Maven
run: mvn -B clean package --file pom.xml
Expand Down
48 changes: 31 additions & 17 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java.version>17</java.version>
<java.version>21</java.version>
<!-- Non-minecraft related dependencies -->
<powermock.version>2.0.9</powermock.version>
<!-- Database related dependencies -->
Expand All @@ -84,7 +84,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.1.1</build.version>
<build.version>3.2.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 Expand Up @@ -161,12 +161,6 @@
<id>papermc</id>
<url>https://repo.papermc.io/repository/maven-public/</url>
</repository>
<repository>
<!-- This is a temporary reference as the Maven Shade plugin
that supports Java 16 is not released yet -->
<id>maven-snapshots</id>
<url>https://repository.apache.org/content/repositories/snapshots/</url>
</repository>
<repository>
<id>minecraft-repo</id>
<url>https://libraries.minecraft.net/</url>
Expand Down Expand Up @@ -198,6 +192,12 @@
<name>FancyPlugins Repository</name>
<url>https://repo.fancyplugins.de/releases</url>
</repository>
<!-- ZNPCsPlus-->
<repository>
<id>pyr-snapshots</id>
<name>Pyr's Repo</name>
<url>https://repo.pyr.lol/snapshots</url>
</repository>
</repositories>

<dependencies>
Expand Down Expand Up @@ -233,6 +233,13 @@
<version>4.2.2</version>
<scope>test</scope>
</dependency>
<!-- Paper API -->
<dependency>
<groupId>io.papermc.paper</groupId>
<artifactId>paper-api</artifactId>
<version>${paper.version}</version>
<scope>provided</scope>
</dependency>
<!-- Spigot API -->
<dependency>
<groupId>org.spigotmc</groupId>
Expand Down Expand Up @@ -357,13 +364,6 @@
<artifactId>org.eclipse.jdt.annotation</artifactId>
<version>2.2.600</version>
</dependency>
<!-- PaperLib -->
<dependency>
<groupId>io.papermc</groupId>
<artifactId>paperlib</artifactId>
<version>1.0.6</version>
<scope>compile</scope>
</dependency>
<!-- LangUtils -->
<dependency>
<groupId>com.github.apachezy</groupId>
Expand Down Expand Up @@ -406,6 +406,20 @@
<version>2.4.0</version>
<scope>provided</scope>
</dependency>
<!-- ZNPCs Plus -->
<dependency>
<groupId>lol.pyr</groupId>
<artifactId>znpcsplus-api</artifactId>
<version>2.0.0-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
<!-- FancyHolograms -->
<dependency>
<groupId>de.oliver</groupId>
<artifactId>FancyHolograms</artifactId>
<version>2.4.1</version>
<scope>provided</scope>
</dependency>
</dependencies>

<build>
Expand Down Expand Up @@ -454,7 +468,7 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.0.0-M5</version>
<version>3.5.2</version>
<!--suppress MavenModelInspection -->
<configuration>
<argLine>
Expand Down Expand Up @@ -528,7 +542,7 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>3.4.0</version>
<version>3.6.0</version>
<configuration>
<minimizeJar>true</minimizeJar>
<dependencyReducedPomLocation>${project.build.directory}/dependency-reduced-pom.xml</dependencyReducedPomLocation>
Expand Down
4 changes: 3 additions & 1 deletion src/main/java/world/bentobox/bentobox/BentoBox.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@

import world.bentobox.bentobox.api.configuration.Config;
import world.bentobox.bentobox.api.events.BentoBoxReadyEvent;
import world.bentobox.bentobox.api.hooks.Hook;
import world.bentobox.bentobox.api.localization.TextVariables;
import world.bentobox.bentobox.api.user.Notifier;
import world.bentobox.bentobox.api.user.User;
Expand All @@ -33,6 +32,7 @@
import world.bentobox.bentobox.hooks.MythicMobsHook;
import world.bentobox.bentobox.hooks.SlimefunHook;
import world.bentobox.bentobox.hooks.VaultHook;
import world.bentobox.bentobox.hooks.ZNPCsPlusHook;
import world.bentobox.bentobox.hooks.placeholders.PlaceholderAPIHook;
import world.bentobox.bentobox.listeners.BannedCommands;
import world.bentobox.bentobox.listeners.BlockEndDragon;
Expand Down Expand Up @@ -196,6 +196,8 @@ private void completeSetup(long loadTime) {

// FancyNpcs
hooksManager.registerHook(new FancyNpcsHook());
// ZNPCsPlus
hooksManager.registerHook(new ZNPCsPlusHook());

// MythicMobs
hooksManager.registerHook(new MythicMobsHook());
Expand Down
39 changes: 39 additions & 0 deletions src/main/java/world/bentobox/bentobox/api/hooks/NPCHook.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package world.bentobox.bentobox.api.hooks;

import java.util.List;
import java.util.Map;

import org.bukkit.Chunk;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.World;
import org.bukkit.configuration.InvalidConfigurationException;
import org.bukkit.util.Vector;
import org.eclipse.jdt.annotation.NonNull;
import org.eclipse.jdt.annotation.Nullable;

import world.bentobox.bentobox.blueprints.dataobjects.BlueprintEntity;

/**
* NPC Hooks
* @author tastybento
* @since 3.2.0
*/
public abstract class NPCHook extends Hook {

protected NPCHook(@NonNull String pluginName, @NonNull Material icon) {
super(pluginName, icon);
}

public abstract boolean spawnNpc(String yaml, Location pos) throws InvalidConfigurationException;

public abstract Map<? extends Vector, ? extends List<BlueprintEntity>> getNpcsInArea(World world,
List<Vector> vectorsToCopy, @Nullable Vector origin);

/**
* Remove all NPCs in chunk
* @param chunk chunk
*/
public abstract void removeNPCsInChunk(Chunk chunk);

}
Original file line number Diff line number Diff line change
Expand Up @@ -12,25 +12,20 @@
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;
import org.bukkit.block.BlockState;
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.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.Attachable;
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;
Expand All @@ -45,6 +40,7 @@
import world.bentobox.bentobox.blueprints.dataobjects.BlueprintEntity;
import world.bentobox.bentobox.hooks.FancyNpcsHook;
import world.bentobox.bentobox.hooks.MythicMobsHook;
import world.bentobox.bentobox.hooks.ZNPCsPlusHook;

/**
* The clipboard provides the holding spot for an active blueprint that is being
Expand All @@ -56,6 +52,10 @@
*/
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;
Expand All @@ -71,6 +71,8 @@ public class BlueprintClipboard {
private final BentoBox plugin = BentoBox.getInstance();
private Optional<MythicMobsHook> mmh;
private Optional<FancyNpcsHook> npc;
private Optional<ZNPCsPlusHook> znpc;


/**
* Create a clipboard for blueprint
Expand All @@ -82,12 +84,15 @@ public BlueprintClipboard(@NonNull Blueprint blueprint) {
}

public BlueprintClipboard() {
// Citizens Hook
// Fancy NPCs Hook
npc = plugin.getHooks().getHook("FancyNpcs").filter(FancyNpcsHook.class::isInstance)
.map(FancyNpcsHook.class::cast);
// MythicMobs Hook
mmh = plugin.getHooks().getHook("MythicMobs").filter(MythicMobsHook.class::isInstance)
.map(MythicMobsHook.class::cast);
// ZNPCs Plus Hook
znpc = plugin.getHooks().getHook("ZNPCsPlus").filter(ZNPCsPlusHook.class::isInstance)
.map(ZNPCsPlusHook.class::cast);
}

/**
Expand Down Expand Up @@ -143,6 +148,10 @@ private void copyAsync(World world, User user, List<Vector> vectorsToCopy, int s
// 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));
}

// Repeating copy task
copyTask = Bukkit.getScheduler().runTaskTimer(plugin, () -> {
Expand All @@ -154,9 +163,9 @@ private void copyAsync(World world, User user, List<Vector> vectorsToCopy, int s
List<Entity> ents = world.getEntities().stream()
.filter(Objects::nonNull)
.filter(e -> !(e instanceof Player))
.filter(e -> new Vector(Math.rint(e.getLocation().getX()),
Math.rint(e.getLocation().getY()),
Math.rint(e.getLocation().getZ())).equals(v))
.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();
if (copyBlock(v.toLocation(world), copyAir, copyBiome, ents)) {
count++;
Expand Down Expand Up @@ -222,7 +231,6 @@ private boolean copyBlock(Location l, boolean copyAir, boolean copyBiome, List<E
if (!copyAir && block.getType().equals(Material.AIR) && !ents.isEmpty()) {
return true;
}

BlueprintBlock b = bluePrintBlock(pos, block, copyBiome);
if (b != null) {
this.bpBlocks.put(pos, b);
Expand All @@ -248,7 +256,7 @@ private BlueprintBlock bluePrintBlock(Vector pos, Block block, boolean copyBiome
}
}
// Set block data
if (blockState.getData() instanceof Attachable) {
if (blockState.getBlockData() instanceof Attachable) {
// Placeholder for attachment
bpBlocks.put(pos, new BlueprintBlock("minecraft:air"));
bpAttachable.put(pos, b);
Expand All @@ -265,7 +273,6 @@ private BlueprintBlock bluePrintBlock(Vector pos, Block block, boolean copyBiome
}
}
}

// Chests
if (blockState instanceof InventoryHolder ih) {
b.setInventory(new HashMap<>());
Expand All @@ -276,11 +283,9 @@ private BlueprintBlock bluePrintBlock(Vector pos, Block block, boolean copyBiome
}
}
}

if (blockState instanceof CreatureSpawner spawner) {
b.setCreatureSpawner(getSpawner(spawner));
}

// Banners
if (blockState instanceof Banner banner) {
b.setBannerPatterns(banner.getPatterns());
Expand Down Expand Up @@ -309,62 +314,15 @@ private BlueprintCreatureSpawner getSpawner(CreatureSpawner spawner) {
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);

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
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ private void pasteEntities(Bits bits, int count, Optional<User> owner, int paste
int x = location.getBlockX() + entry.getKey().getBlockX();
int y = location.getBlockY() + entry.getKey().getBlockY();
int z = location.getBlockZ() + entry.getKey().getBlockZ();
Location center = new Location(world, x, y, z).add(new Vector(0.5, 0.5, 0.5));
Location center = new Location(world, x, y, z).add(new Vector(0.5, 0D, 0.5));
List<BlueprintEntity> entities = entry.getValue();
entityMap.put(center, entities);
count++;
Expand Down
Loading

0 comments on commit cf51aec

Please sign in to comment.