Update NPC effect thread (breaking)

This commit is contained in:
PikaMug 2024-02-08 00:51:13 -05:00
parent 5ebeb77cd7
commit a85c2d4b81
2 changed files with 50 additions and 103 deletions

View File

@ -10,55 +10,49 @@
package me.pikamug.quests.events.quester;
import lol.pyr.znpcsplus.api.npc.Npc;
import me.pikamug.quests.player.BukkitQuester;
import org.bukkit.entity.Entity;
import org.bukkit.Location;
import org.bukkit.event.HandlerList;
import org.jetbrains.annotations.NotNull;
import java.util.UUID;
public class BukkitQuesterPostViewEffectEvent extends BukkitQuesterEvent {
private static final HandlerList HANDLERS = new HandlerList();
private final Entity entity;
private final Npc npc;
private final UUID targetUuid;
private final Location targetLocation;
private final String effect;
private final boolean redoable;
public BukkitQuesterPostViewEffectEvent(final BukkitQuester quester, Entity entity, String effect, boolean redoable) {
public BukkitQuesterPostViewEffectEvent(final BukkitQuester quester, UUID targetUuid, Location targetLocation,
String effect, boolean redoable) {
super(quester);
this.entity = entity;
this.targetUuid = targetUuid;
this.targetLocation = targetLocation;
this.effect = effect;
this.redoable = redoable;
this.npc=null;
}
public BukkitQuesterPostViewEffectEvent(final BukkitQuester quester, Npc npc, String effect, boolean redoable) {
super(quester);
this.npc = npc;
this.effect = effect;
this.redoable = redoable;
this.entity = null;
}
/**
* Returns the entity involved in this event
* Get the target of this event, usually an NPC
*
* @return entity who is involved in this event
* @return UUID of target
*/
public Entity getEntity() {
return entity;
public UUID getTargetUuid() {
return targetUuid;
}
/**
* Returns the npc involved in this event (only if using ZNPCsPlus 2.0.0 or higher)
* Get the target location for this event
*
* @return npc who is involved in this event
* @return Location of target
*/
public Npc getNpc() {
return npc;
public Location getTargetLocation() {
return targetLocation;
}
/**
* Returns the effect involved in this event
* Get the effect involved in this event
*
* @return Effect which is involved in this event
*/

View File

@ -10,14 +10,12 @@
package me.pikamug.quests.tasks;
import lol.pyr.znpcsplus.api.npc.Npc;
import lol.pyr.znpcsplus.api.npc.NpcEntry;
import me.pikamug.quests.enums.BukkitPreBuiltParticle;
import me.pikamug.quests.player.BukkitQuester;
import me.pikamug.quests.BukkitQuestsPlugin;
import me.pikamug.quests.enums.BukkitPreBuiltParticle;
import me.pikamug.quests.events.quester.BukkitQuesterPostViewEffectEvent;
import me.pikamug.quests.nms.BukkitParticleProvider;
import net.citizensnpcs.api.npc.NPC;
import me.pikamug.quests.player.BukkitQuester;
import org.bukkit.Location;
import org.bukkit.entity.Entity;
import org.bukkit.entity.Player;
@ -41,24 +39,33 @@ public class BukkitNpcEffectThread implements Runnable {
final List<Entity> nearby = player.getNearbyEntities(32.0, 16.0, 32.0);
if (!nearby.isEmpty()) {
for (final Entity entity : nearby) {
showConfigEffect(plugin.getQuester(player.getUniqueId()), entity);
final UUID uuid = plugin.getDependencies().getUuidFromNpc(entity);
if (uuid != null) {
showConfigEffect(plugin.getQuester(player.getUniqueId()), entity.getUniqueId(),
entity.getLocation());
}
}
}
}
if (plugin.getDependencies().getZnpcsPlus() != null) {
for (io.github.znetworkw.znpcservers.npc.NPC npc : io.github.znetworkw.znpcservers.npc.NPC.all()) {
if (npc.getLocation().getWorld() == null || player.getLocation().getWorld() == null) {
final Location location = npc.getLocation();
if (location.getWorld() == null || player.getLocation().getWorld() == null) {
return;
}
if (npc.getLocation().getWorld().getName().equals(player.getLocation().getWorld().getName())) {
if (npc.getLocation().distanceSquared(player.getLocation()) < 24) {
showConfigEffect(plugin.getQuester(player.getUniqueId()), (Entity) npc.getBukkitEntity());
if (location.getWorld().getName().equals(player.getLocation().getWorld().getName())) {
if (location.distanceSquared(player.getLocation()) < 24) {
final UUID uuid = plugin.getDependencies().getUuidFromNpc((Entity) npc.getBukkitEntity());
if (uuid != null) {
showConfigEffect(plugin.getQuester(player.getUniqueId()), uuid, location);
}
}
}
}
}
if (plugin.getDependencies().getZnpcsPlusApi() != null) {
Collection<? extends NpcEntry> znpcs = plugin.getDependencies().getZnpcsPlusApi().getNpcRegistry().getAllPlayerMade();
Collection<? extends NpcEntry> znpcs = plugin.getDependencies().getZnpcsPlusApi().getNpcRegistry()
.getAllPlayerMade();
for (NpcEntry npc : znpcs) {
if (npc.getNpc().getWorld() == null || player.getLocation().getWorld() == null) {
return;
@ -66,7 +73,8 @@ public class BukkitNpcEffectThread implements Runnable {
if (npc.getNpc().getWorld().equals(player.getLocation().getWorld())) {
if (npc.getNpc().getLocation().toBukkitLocation(npc.getNpc().getWorld())
.distanceSquared(player.getLocation()) < 24) {
showConfigEffect(plugin.getQuester(player.getUniqueId()), npc.getNpc());
showConfigEffect(plugin.getQuester(player.getUniqueId()), npc.getNpc().getUuid(),
npc.getNpc().getLocation().toBukkitLocation(npc.getNpc().getWorld()).add(0, 2, 0));
}
}
}
@ -75,89 +83,34 @@ public class BukkitNpcEffectThread implements Runnable {
}
/**
* Display config setting particle effect above an entity one time
* Display config setting particle effect above an acceptable NPC one time
*
* @param quester Target quester to let view the effect
* @param entity Target entity to place the effect above
* @param targetUuid Target NPC UUID to place the effect above
* @param targetLocation Target NPC location to place the effect above
*/
public void showConfigEffect(final BukkitQuester quester, final Entity entity) {
UUID uuid = plugin.getDependencies().getUuidFromNpc(entity);
if (uuid != null) {
public void showConfigEffect(final BukkitQuester quester, final UUID targetUuid, final Location targetLocation) {
if (targetUuid != null) {
final BukkitQuesterPostViewEffectEvent event;
if (quester.canAcceptQuest(uuid)) {
showEffect(quester.getPlayer(), entity, plugin.getConfigSettings().getEffect());
if (quester.canAcceptQuest(targetUuid)) {
showEffect(quester.getPlayer(), targetLocation, plugin.getConfigSettings().getEffect());
event = new BukkitQuesterPostViewEffectEvent(quester, entity,
event = new BukkitQuesterPostViewEffectEvent(quester, targetUuid, targetLocation,
plugin.getConfigSettings().getEffect(), false);
plugin.getServer().getPluginManager().callEvent(event);
} else if (quester.canAcceptCompletedRedoableQuest(uuid)) {
showEffect(quester.getPlayer(), entity, plugin.getConfigSettings().getRedoEffect());
} else if (quester.canAcceptCompletedRedoableQuest(targetUuid)) {
showEffect(quester.getPlayer(), targetLocation, plugin.getConfigSettings().getRedoEffect());
event = new BukkitQuesterPostViewEffectEvent(quester, entity,
event = new BukkitQuesterPostViewEffectEvent(quester, targetUuid, targetLocation,
plugin.getConfigSettings().getRedoEffect(), true);
plugin.getServer().getPluginManager().callEvent(event);
}
}
}
/**
* Display config setting particle effect above an {@link Npc} one time
* @param quester Target quester to let view the effect
* @param npc Target NPC to place the effect above
*/
public void showConfigEffect(final BukkitQuester quester, final Npc npc) {
if (npc == null) return;
final BukkitQuesterPostViewEffectEvent event;
if (quester.canAcceptQuest(npc.getUuid())) {
if (npc.getWorld() == null) return;
showEffect(quester.getPlayer(), npc.getLocation().toBukkitLocation(npc.getWorld()).add(0, 2, 0), plugin.getConfigSettings().getEffect());
event = new BukkitQuesterPostViewEffectEvent(quester, npc,
plugin.getConfigSettings().getEffect(), false);
plugin.getServer().getPluginManager().callEvent(event);
} else if (quester.canAcceptCompletedRedoableQuest(npc.getUuid())) {
if (npc.getWorld() == null) return;
showEffect(quester.getPlayer(), npc.getLocation().toBukkitLocation(npc.getWorld()).add(0, 2, 0), plugin.getConfigSettings().getRedoEffect());
event = new BukkitQuesterPostViewEffectEvent(quester, npc,
plugin.getConfigSettings().getRedoEffect(), true);
plugin.getServer().getPluginManager().callEvent(event);
}
}
/**
* Display specified particle effect above a Citizens NPC one time
* @param player Target player to let view the effect
* @param npc Target NPC to place the effect above
* @param effectType Value of EnumParticle such as NOTE or SMOKE
* @deprecated Use {@link #showEffect(Player, Entity, String)}
*/
public void showEffect(final Player player, final NPC npc, final String effectType) {
if (player == null || npc == null || npc.getEntity() == null) {
return;
}
if (plugin.getDependencies().getCitizens() != null) {
final Location eyeLoc = npc.getEntity().getLocation();
eyeLoc.setY(eyeLoc.getY() + 2);
try {
BukkitParticleProvider.sendToPlayer(player, eyeLoc, effectType.toUpperCase());
} catch (final NoClassDefFoundError e) {
// Unsupported Minecraft version
}
}
}
/**
* Display specified particle effect above an entity one time
* @param player Target player to let view the effect
* @param entity Target entity to place the effect above
* @param effectType Value of {@link org.bukkit.Particle} or {@link BukkitPreBuiltParticle}
*/
public void showEffect(final Player player, final Entity entity, final String effectType) {
showEffect(player, entity.getLocation().add(0, 2, 0), effectType);
}
/**
* Display specified particle effect at a location one time
*
* @param player Target player to let view the effect
* @param location Target location to place the effect at
* @param effectType Value of {@link org.bukkit.Particle} or {@link BukkitPreBuiltParticle}