Add event for quest update compass target, fixes #1627

This commit is contained in:
PikaMug 2021-03-02 03:43:40 -05:00
parent f7b34dcac0
commit db9d64732f
2 changed files with 68 additions and 0 deletions

View File

@ -42,6 +42,7 @@ import com.gmail.nossr50.util.player.UserManager;
import com.herocraftonline.heroes.characters.Hero;
import me.blackvein.quests.actions.Action;
import me.blackvein.quests.events.quest.QuestUpdateCompassEvent;
import me.blackvein.quests.events.quester.QuesterPostChangeStageEvent;
import me.blackvein.quests.events.quester.QuesterPostCompleteQuestEvent;
import me.blackvein.quests.events.quester.QuesterPostFailQuestEvent;
@ -391,6 +392,12 @@ public class Quest implements Comparable<Quest> {
}
if (targetLocation != null && targetLocation.getWorld() != null) {
if (targetLocation.getWorld().getName().equals(quester.getPlayer().getWorld().getName())) {
final QuestUpdateCompassEvent event = new QuestUpdateCompassEvent(this, quester, targetLocation);
plugin.getServer().getPluginManager().callEvent(event);
if (event.isCancelled()) {
return false;
}
quester.getPlayer().setCompassTarget(targetLocation);
}
}

View File

@ -0,0 +1,61 @@
package me.blackvein.quests.events.quest;
import org.bukkit.Location;
import org.bukkit.event.Cancellable;
import org.bukkit.event.HandlerList;
import me.blackvein.quests.Quest;
import me.blackvein.quests.Quester;
/**
* Called when a quest has its compass target updated for a quester
*/
public class QuestUpdateCompassEvent extends QuestEvent implements Cancellable {
private static final HandlerList HANDLERS = new HandlerList();
private final Quester quester;
private final Location target;
private boolean cancel = false;
public QuestUpdateCompassEvent(final Quest quest, final Quester who, final Location target) {
super(quest);
this.quester = who;
this.target = target;
}
/**
* Returns the quester involved in this event
*
* @return Quester who is involved in this event
*/
public Quester getQuester() {
return quester;
}
/**
* Returns the new compass target in this event
*
* @return Location which shall be the new target
*/
public Location getNewCompassTarget() {
return target;
}
@Override
public boolean isCancelled() {
return cancel;
}
@Override
public void setCancelled(final boolean cancel) {
this.cancel = cancel;
}
@Override
public HandlerList getHandlers() {
return HANDLERS;
}
public static HandlerList getHandlerList() {
return HANDLERS;
}
}