mirror of
https://github.com/BentoBoxWorld/BentoBox.git
synced 2025-01-23 00:21:30 +01:00
ZNPCs Hook. FC but needs testing
This commit is contained in:
commit
ce84d66b91
1
.github/workflows/build.yml
vendored
1
.github/workflows/build.yml
vendored
@ -3,6 +3,7 @@ on:
|
|||||||
push:
|
push:
|
||||||
branches:
|
branches:
|
||||||
- develop
|
- develop
|
||||||
|
- master
|
||||||
pull_request:
|
pull_request:
|
||||||
types: [opened, synchronize, reopened]
|
types: [opened, synchronize, reopened]
|
||||||
jobs:
|
jobs:
|
||||||
|
4
.github/workflows/modrinth-publish.yml
vendored
4
.github/workflows/modrinth-publish.yml
vendored
@ -21,8 +21,8 @@ jobs:
|
|||||||
cache: maven
|
cache: maven
|
||||||
|
|
||||||
# This step will take the version tag from the release and replace it in `pom.xml` before building.
|
# This step will take the version tag from the release and replace it in `pom.xml` before building.
|
||||||
- name: Set version from release tag
|
#- name: Set version from release tag
|
||||||
run: mvn -B versions:set -DnewVersion=${{ github.event.release.tag_name }} -DgenerateBackupPoms=false
|
# run: mvn -B versions:set -DnewVersion=${{ github.event.release.tag_name }} -DgenerateBackupPoms=false
|
||||||
|
|
||||||
- name: Build and package with Maven
|
- name: Build and package with Maven
|
||||||
run: mvn -B clean package --file pom.xml
|
run: mvn -B clean package --file pom.xml
|
||||||
|
7
pom.xml
7
pom.xml
@ -419,11 +419,6 @@
|
|||||||
<version>2.0.0-SNAPSHOT</version>
|
<version>2.0.0-SNAPSHOT</version>
|
||||||
<scope>provided</scope>
|
<scope>provided</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
|
||||||
<groupId>lol.pyr</groupId>
|
|
||||||
<artifactId>ZNPCsPlus</artifactId>
|
|
||||||
<version>1.0.7</version>
|
|
||||||
</dependency>
|
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
<build>
|
<build>
|
||||||
@ -475,8 +470,6 @@
|
|||||||
<version>3.5.2</version>
|
<version>3.5.2</version>
|
||||||
<!--suppress MavenModelInspection -->
|
<!--suppress MavenModelInspection -->
|
||||||
<configuration>
|
<configuration>
|
||||||
<parallel>classes</parallel>
|
|
||||||
<threadCount>8</threadCount>
|
|
||||||
<argLine>
|
<argLine>
|
||||||
${argLine}
|
${argLine}
|
||||||
--add-opens java.base/java.lang=ALL-UNNAMED
|
--add-opens java.base/java.lang=ALL-UNNAMED
|
||||||
|
@ -19,7 +19,6 @@ import org.eclipse.jdt.annotation.Nullable;
|
|||||||
|
|
||||||
import world.bentobox.bentobox.api.configuration.Config;
|
import world.bentobox.bentobox.api.configuration.Config;
|
||||||
import world.bentobox.bentobox.api.events.BentoBoxReadyEvent;
|
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.localization.TextVariables;
|
||||||
import world.bentobox.bentobox.api.user.Notifier;
|
import world.bentobox.bentobox.api.user.Notifier;
|
||||||
import world.bentobox.bentobox.api.user.User;
|
import world.bentobox.bentobox.api.user.User;
|
||||||
@ -33,6 +32,7 @@ import world.bentobox.bentobox.hooks.MyWorldsHook;
|
|||||||
import world.bentobox.bentobox.hooks.MythicMobsHook;
|
import world.bentobox.bentobox.hooks.MythicMobsHook;
|
||||||
import world.bentobox.bentobox.hooks.SlimefunHook;
|
import world.bentobox.bentobox.hooks.SlimefunHook;
|
||||||
import world.bentobox.bentobox.hooks.VaultHook;
|
import world.bentobox.bentobox.hooks.VaultHook;
|
||||||
|
import world.bentobox.bentobox.hooks.ZNPCsPlusHook;
|
||||||
import world.bentobox.bentobox.hooks.placeholders.PlaceholderAPIHook;
|
import world.bentobox.bentobox.hooks.placeholders.PlaceholderAPIHook;
|
||||||
import world.bentobox.bentobox.listeners.BannedCommands;
|
import world.bentobox.bentobox.listeners.BannedCommands;
|
||||||
import world.bentobox.bentobox.listeners.BlockEndDragon;
|
import world.bentobox.bentobox.listeners.BlockEndDragon;
|
||||||
@ -196,6 +196,8 @@ public class BentoBox extends JavaPlugin implements Listener {
|
|||||||
|
|
||||||
// FancyNpcs
|
// FancyNpcs
|
||||||
hooksManager.registerHook(new FancyNpcsHook());
|
hooksManager.registerHook(new FancyNpcsHook());
|
||||||
|
// ZNPCsPlus
|
||||||
|
hooksManager.registerHook(new ZNPCsPlusHook());
|
||||||
|
|
||||||
// MythicMobs
|
// MythicMobs
|
||||||
hooksManager.registerHook(new MythicMobsHook());
|
hooksManager.registerHook(new MythicMobsHook());
|
||||||
|
@ -167,8 +167,8 @@ public class Database<T> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Load all objects async
|
* Load all objects asynchronously.
|
||||||
* @return CompletableFuture<List<T>>
|
* @return {@code CompletableFuture<List<T>>}
|
||||||
*/
|
*/
|
||||||
public @NonNull CompletableFuture<List<T>> loadObjectsASync() {
|
public @NonNull CompletableFuture<List<T>> loadObjectsASync() {
|
||||||
return handler.loadObjectsASync();
|
return handler.loadObjectsASync();
|
||||||
|
@ -1,130 +0,0 @@
|
|||||||
package world.bentobox.bentobox.hooks;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Map;
|
|
||||||
import java.util.Objects;
|
|
||||||
import java.util.UUID;
|
|
||||||
import java.util.stream.Collectors;
|
|
||||||
|
|
||||||
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 de.oliver.fancynpcs.api.FancyNpcsPlugin;
|
|
||||||
import lol.pyr.znpcsplus.ZNPCsPlus;
|
|
||||||
import lol.pyr.znpcsplus.api.entity.EntityProperty;
|
|
||||||
import lol.pyr.znpcsplus.api.interaction.InteractionAction;
|
|
||||||
import lol.pyr.znpcsplus.api.npc.Npc;
|
|
||||||
import lol.pyr.znpcsplus.api.npc.NpcType;
|
|
||||||
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 {
|
|
||||||
|
|
||||||
private ZNPCsPlus plugin;
|
|
||||||
|
|
||||||
public ZNPCSPlusHook() {
|
|
||||||
super("ZNPCsPlus", Material.PLAYER_HEAD);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public String serializeNPC(Npc npc, Vector origin) {
|
|
||||||
if (npc == null) {
|
|
||||||
throw new IllegalArgumentException("NPC cannot be null.");
|
|
||||||
}
|
|
||||||
YamlConfiguration config = new YamlConfiguration();
|
|
||||||
NpcType type = npc.getType();
|
|
||||||
for (EntityProperty<?> property : npc.getAppliedProperties())
|
|
||||||
try {
|
|
||||||
PropertySerializer<?> serializer = propertyRegistry
|
|
||||||
.getSerializer(((EntityPropertyImpl<?>) property).getType());
|
|
||||||
if (serializer == null) {
|
|
||||||
BentoBox.getInstance().logWarning("Unknown serializer for property '" + property.getName()
|
|
||||||
+ "' for npc '" + npc.getUuid() + "'. skipping ...");
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
config.set("properties." + property.getName(), serializer.UNSAFE_serialize(npc.getProperty(property)));
|
|
||||||
} catch (Exception exception) {
|
|
||||||
BentoBox.getInstance().logWarning(
|
|
||||||
"Failed to serialize property " + property.getName() + " for npc with id " + npc.getUuid());
|
|
||||||
exception.printStackTrace();
|
|
||||||
}
|
|
||||||
|
|
||||||
lol.pyr.znpcsplus.api.hologram.Hologram hologram = npc.getHologram();
|
|
||||||
if (hologram.getRefreshDelay() != -1)
|
|
||||||
config.set("hologram.refresh-delay", hologram.getRefreshDelay());
|
|
||||||
List<String> lines = new ArrayList<>(npc.getHologram().lineCount());
|
|
||||||
for (int i = 0; i < npc.getHologram().lineCount(); i++) {
|
|
||||||
lines.add(hologram.getLine(i));
|
|
||||||
}
|
|
||||||
config.set("hologram.lines", lines);
|
|
||||||
config.set("actions", npc.getActions().stream().map(InteractionAction::toString).filter(Objects::nonNull)
|
|
||||||
.collect(Collectors.toList()));
|
|
||||||
return config.saveToString();
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean spawnNpc(String yaml, Location pos) throws InvalidConfigurationException {
|
|
||||||
YamlConfiguration npcConfig = new YamlConfiguration();
|
|
||||||
npcConfig.loadFromString(yaml);
|
|
||||||
|
|
||||||
String name = UUID.randomUUID().toString(); // Create a unique name
|
|
||||||
|
|
||||||
UUID creator = UUID.randomUUID(); // Random creator
|
|
||||||
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean hook() {
|
|
||||||
boolean hooked = this.isPluginAvailable();
|
|
||||||
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 (Npc npc : FancyNpcsPlugin.get().getNpcManager().getAllNpcs()) {
|
|
||||||
Location npcLocation = npc.getData().getLocation();
|
|
||||||
Vector spot = new Vector(npcLocation.getBlockX(), npcLocation.getBlockY(), npcLocation.getBlockZ());
|
|
||||||
if (npcLocation.getWorld().equals(world) && vectorsToCopy.contains(spot)) {
|
|
||||||
BlueprintEntity cit = new BlueprintEntity();
|
|
||||||
cit.setType(npc.getData().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;
|
|
||||||
}
|
|
||||||
}
|
|
@ -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;
|
||||||
|
}
|
||||||
|
}
|
@ -60,7 +60,6 @@ public class IslandHomesPanel extends AbstractPanel
|
|||||||
*
|
*
|
||||||
* @param command CompositeCommand
|
* @param command CompositeCommand
|
||||||
* @param user User who opens panel
|
* @param user User who opens panel
|
||||||
* @param islandMap map of island names and IslandInfo
|
|
||||||
*/
|
*/
|
||||||
private IslandHomesPanel(@NonNull CompositeCommand command, @NonNull User user)
|
private IslandHomesPanel(@NonNull CompositeCommand command, @NonNull User user)
|
||||||
{
|
{
|
||||||
|
Loading…
Reference in New Issue
Block a user