-
-
Notifications
You must be signed in to change notification settings - Fork 42
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add quests stage change event, for #266
stages don't have IDs for some painful reason
- Loading branch information
1 parent
0ea9f04
commit e409964
Showing
1 changed file
with
79 additions
and
0 deletions.
There are no files selected for viewing
79 changes: 79 additions & 0 deletions
79
...a/com/denizenscript/depenizen/bukkit/events/quests/PlayerQuestStageChangeScriptEvent.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
package com.denizenscript.depenizen.bukkit.events.quests; | ||
|
||
import com.denizenscript.denizen.events.BukkitScriptEvent; | ||
import com.denizenscript.denizen.objects.PlayerTag; | ||
import com.denizenscript.denizen.utilities.implementation.BukkitScriptEntryData; | ||
import com.denizenscript.denizencore.objects.ObjectTag; | ||
import com.denizenscript.denizencore.objects.core.ElementTag; | ||
import com.denizenscript.denizencore.scripts.ScriptEntryData; | ||
import com.denizenscript.denizencore.utilities.CoreUtilities; | ||
import me.blackvein.quests.events.quester.QuesterPostChangeStageEvent; | ||
import org.bukkit.event.EventHandler; | ||
import org.bukkit.event.Listener; | ||
|
||
public class PlayerQuestStageChangeScriptEvent extends BukkitScriptEvent implements Listener { | ||
|
||
// <--[event] | ||
// @Events | ||
// quests player changes quest stage | ||
// quests player changes <quest> stage | ||
// | ||
// @Regex ^on quests player changes [^\s]+ stage$ | ||
// | ||
// @Cancellable true | ||
// | ||
// @Triggers when a player changes stage in a quest from the Quests plugin. Note that stages don't have unique IDs. | ||
// | ||
// @Context | ||
// <context.quest> returns the ID of the quest. | ||
// | ||
// @Plugin Depenizen, Quests | ||
// | ||
// --> | ||
|
||
public PlayerQuestStageChangeScriptEvent() { | ||
instance = this; | ||
} | ||
|
||
public static PlayerQuestStageChangeScriptEvent instance; | ||
public QuesterPostChangeStageEvent event; | ||
|
||
@Override | ||
public boolean couldMatch(ScriptPath path) { | ||
return path.eventLower.startsWith("quests player changes"); | ||
} | ||
|
||
@Override | ||
public boolean matches(ScriptPath path) { | ||
String questName = path.eventArgLowerAt(3); | ||
if (!questName.equals("quest") && !questName.equals(CoreUtilities.toLowerCase(event.getQuest().getId()))) { | ||
return false; | ||
} | ||
|
||
return true; | ||
} | ||
|
||
@Override | ||
public String getName() { | ||
return "QuestsPlayerQuestStageChange"; | ||
} | ||
|
||
@Override | ||
public ScriptEntryData getScriptEntryData() { | ||
return new BukkitScriptEntryData(new PlayerTag(event.getQuester().getOfflinePlayer()), null); | ||
} | ||
|
||
@Override | ||
public ObjectTag getContext(String name) { | ||
if (name.equals("quest")) { | ||
return new ElementTag(event.getQuest().getId()); | ||
} | ||
return super.getContext(name); | ||
} | ||
|
||
@EventHandler | ||
public void onQuestEvent(QuesterPostChangeStageEvent event) { | ||
this.event = event; | ||
fire(event); | ||
} | ||
} |