Add view effect event

This commit is contained in:
PikaMug 2022-12-26 18:42:28 -05:00
parent f14040c7fe
commit fd40f15b8b
2 changed files with 104 additions and 5 deletions

View File

@ -0,0 +1,69 @@
/*
* Copyright (c) 2014 PikaMug and contributors. All rights reserved.
*
* THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN
* NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
* OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package me.blackvein.quests.events.quester;
import me.blackvein.quests.Quester;
import org.bukkit.event.HandlerList;
import org.jetbrains.annotations.NotNull;
import java.util.UUID;
public class QuesterPostViewEffectEvent extends QuesterEvent {
private static final HandlerList HANDLERS = new HandlerList();
private final UUID entity;
private final String effect;
private final boolean redoable;
public QuesterPostViewEffectEvent(final Quester quester, UUID entity, String effect, boolean redoable) {
super(quester);
this.entity = entity;
this.effect = effect;
this.redoable = redoable;
}
/**
* Returns the UUID of the entity involved in this event
*
* @return UUID of entity who is involved in this event
*/
public UUID getEntity() {
return entity;
}
/**
* Returns the effect involved in this event
*
* @return Effect which is involved in this event
*/
public String getEffect() {
return effect;
}
/**
* Whether the effect is for a redoable quest
*
* @return true if redoable
*/
public boolean isRedoable() {
return redoable;
}
@Override
public @NotNull HandlerList getHandlers() {
return HANDLERS;
}
public static HandlerList getHandlerList() {
return HANDLERS;
}
}

View File

@ -12,8 +12,9 @@
package me.blackvein.quests.tasks;
import me.blackvein.quests.player.IQuester;
import me.blackvein.quests.Quester;
import me.blackvein.quests.Quests;
import me.blackvein.quests.events.quester.QuesterPostViewEffectEvent;
import me.blackvein.quests.nms.ParticleProvider;
import net.citizensnpcs.api.npc.NPC;
import org.bukkit.Location;
@ -33,18 +34,27 @@ public class NpcEffectThread implements Runnable {
@Override
public void run() {
for (final Player player : plugin.getServer().getOnlinePlayers()) {
final List<Entity> nearby = player.getNearbyEntities(32.0, 32.0, 32.0);
final List<Entity> nearby = player.getNearbyEntities(32.0, 16.0, 32.0);
if (!nearby.isEmpty()) {
final IQuester quester = plugin.getQuester(player.getUniqueId());
final Quester quester = plugin.getQuester(player.getUniqueId());
for (final Entity e : nearby) {
if (plugin.getDependencies().getCitizens() != null
&& plugin.getDependencies().getCitizens().getNPCRegistry() != null) {
if (plugin.getDependencies().getCitizens().getNPCRegistry().isNPC(e)) {
final NPC npc = plugin.getDependencies().getCitizens().getNPCRegistry().getNPC(e);
final QuesterPostViewEffectEvent event;
if (plugin.hasQuest(npc, quester)) {
showEffect(player, npc, plugin.getSettings().getEffect());
showEffect(player, npc.getEntity(), plugin.getSettings().getEffect());
event = new QuesterPostViewEffectEvent(quester, npc.getUniqueId(),
plugin.getSettings().getEffect(), false);
plugin.getServer().getPluginManager().callEvent(event);
} else if (plugin.hasCompletedRedoableQuest(npc, quester)) {
showEffect(player, npc, plugin.getSettings().getRedoEffect());
showEffect(player, npc.getEntity(), plugin.getSettings().getRedoEffect());
event = new QuesterPostViewEffectEvent(quester, npc.getUniqueId(),
plugin.getSettings().getEffect(), true);
plugin.getServer().getPluginManager().callEvent(event);
}
}
}
@ -58,6 +68,7 @@ public class NpcEffectThread implements Runnable {
* @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) {
@ -73,4 +84,23 @@ public class NpcEffectThread implements Runnable {
}
}
}
/**
* Display a 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 me.blackvein.quests.nms.PreBuiltParticle}
*/
public void showEffect(final Player player, final Entity entity, final String effectType) {
if (player == null || entity == null) {
return;
}
final Location eyeLoc = entity.getLocation();
eyeLoc.setY(eyeLoc.getY() + 2);
try {
ParticleProvider.sendToPlayer(player, eyeLoc, effectType.toUpperCase());
} catch (final NoClassDefFoundError e) {
// Unsupported Minecraft version
}
}
}