Skip to content

Commit

Permalink
ZNPCs Hook. FC but needs testing
Browse files Browse the repository at this point in the history
  • Loading branch information
tastybento committed Dec 25, 2024
2 parents 8346405 + 212166e commit ce84d66
Show file tree
Hide file tree
Showing 8 changed files with 105 additions and 143 deletions.
1 change: 1 addition & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ on:
push:
branches:
- develop
- master
pull_request:
types: [opened, synchronize, reopened]
jobs:
Expand Down
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
7 changes: 0 additions & 7 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -419,11 +419,6 @@
<version>2.0.0-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>lol.pyr</groupId>
<artifactId>ZNPCsPlus</artifactId>
<version>1.0.7</version>
</dependency>
</dependencies>

<build>
Expand Down Expand Up @@ -475,8 +470,6 @@
<version>3.5.2</version>
<!--suppress MavenModelInspection -->
<configuration>
<parallel>classes</parallel>
<threadCount>8</threadCount>
<argLine>
${argLine}
--add-opens java.base/java.lang=ALL-UNNAMED
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
4 changes: 2 additions & 2 deletions src/main/java/world/bentobox/bentobox/database/Database.java
Original file line number Diff line number Diff line change
Expand Up @@ -167,8 +167,8 @@ public static Set<Class<? extends DataObject>> getDataobjects() {
}

/**
* Load all objects async
* @return CompletableFuture<List<T>>
* Load all objects asynchronously.
* @return {@code CompletableFuture<List<T>>}
*/
public @NonNull CompletableFuture<List<T>> loadObjectsASync() {
return handler.loadObjectsASync();
Expand Down
130 changes: 0 additions & 130 deletions src/main/java/world/bentobox/bentobox/hooks/ZNPCSPlusHook.java

This file was deleted.

97 changes: 97 additions & 0 deletions src/main/java/world/bentobox/bentobox/hooks/ZNPCsPlusHook.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
package world.bentobox.bentobox.hooks;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

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

import lol.pyr.znpcsplus.api.NpcApiProvider;
import lol.pyr.znpcsplus.api.npc.NpcEntry;
import lol.pyr.znpcsplus.util.NpcLocation;
import world.bentobox.bentobox.BentoBox;
import world.bentobox.bentobox.api.hooks.Hook;
import world.bentobox.bentobox.blueprints.dataobjects.BlueprintEntity;

/**
* Provides copy and pasting of ZNPCS Plus in blueprints https://github.com/Pyrbu/ZNPCsPlus
*
* @author tastybento
* @since 3.2.0
*/
public class ZNPCsPlusHook extends Hook {

public ZNPCsPlusHook() {
super("ZNPCsPlus", Material.PLAYER_HEAD);
}

public String serializeNPC(NpcEntry entry, Vector origin) {
String result = NpcApiProvider.get().getNpcSerializerRegistry().getSerializer(YamlConfiguration.class)
.serialize(entry)
.saveToString();
BentoBox.getInstance().logDebug(result);
return result;
}

public boolean spawnNpc(String yaml, Location pos) throws InvalidConfigurationException {
YamlConfiguration yaml2 = new YamlConfiguration();
yaml2.loadFromString(yaml);
NpcEntry entry = NpcApiProvider.get().getNpcSerializerRegistry().getSerializer(YamlConfiguration.class)
.deserialize(yaml2);
NpcLocation loc = new NpcLocation(pos);
entry.getNpc().setLocation(loc);
NpcApiProvider.get().getNpcRegistry().register(entry);
return true;
}

@Override
public boolean hook() {
boolean hooked = this.isPluginAvailable();
// Check version
String version = this.getPlugin().getDescription().getVersion();
BentoBox.getInstance().logDebug("ZNPCsPlus version = " + version);
if (!hooked) {
BentoBox.getInstance().logError("Could not hook into FancyNpcs");
}
return hooked; // The hook process shouldn't fail
}

@Override
public String getFailureCause() {
return null; // The hook process shouldn't fail
}

public Map<? extends Vector, ? extends List<BlueprintEntity>> getNpcsInArea(World world, List<Vector> vectorsToCopy,
@Nullable Vector origin) {
Map<Vector, List<BlueprintEntity>> bpEntities = new HashMap<>();

for (NpcEntry npc : NpcApiProvider.get().getNpcRegistry().getAll()) {
NpcLocation npcLocation = npc.getNpc().getLocation();
Vector spot = new Vector(npcLocation.getBlockX(), npcLocation.getBlockY(), npcLocation.getBlockZ());
if (npc.getNpc().getWorld().equals(world) && vectorsToCopy.contains(spot)) {
BlueprintEntity cit = new BlueprintEntity();
//cit.setType(npc.getNpc().getType());
cit.setNpc(this.serializeNPC(npc, origin));
// Retrieve or create the list, then add the entity
List<BlueprintEntity> entities = bpEntities.getOrDefault(spot, new ArrayList<>());
entities.add(cit);
// Create position
Vector origin2 = origin == null ? new Vector(0, 0, 0) : origin;
int x = spot.getBlockX() - origin2.getBlockX();
int y = spot.getBlockY() - origin2.getBlockY();
int z = spot.getBlockZ() - origin2.getBlockZ();
Vector pos = new Vector(x, y, z);
// Store
bpEntities.put(pos, entities); // Update the map
}
}
return bpEntities;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,6 @@ public class IslandHomesPanel extends AbstractPanel
*
* @param command CompositeCommand
* @param user User who opens panel
* @param islandMap map of island names and IslandInfo
*/
private IslandHomesPanel(@NonNull CompositeCommand command, @NonNull User user)
{
Expand Down

0 comments on commit ce84d66

Please sign in to comment.