From 6c1212b21fd0bbab16bf7971c2938b09717abcc5 Mon Sep 17 00:00:00 2001 From: BuildTools Date: Sun, 13 Jan 2019 00:48:20 -0500 Subject: [PATCH] Fix Denizen linkage --- .../me/blackvein/quests/DenizenTrigger.java | 20 ++++++++++++++++ .../me/blackvein/quests/Dependencies.java | 8 +++++++ src/main/java/me/blackvein/quests/Quest.java | 4 ++-- src/main/java/me/blackvein/quests/Quests.java | 24 +++++-------------- .../blackvein/quests/timers/StageTimer.java | 4 ++-- 5 files changed, 38 insertions(+), 22 deletions(-) create mode 100644 src/main/java/me/blackvein/quests/DenizenTrigger.java diff --git a/src/main/java/me/blackvein/quests/DenizenTrigger.java b/src/main/java/me/blackvein/quests/DenizenTrigger.java new file mode 100644 index 000000000..2326b4a49 --- /dev/null +++ b/src/main/java/me/blackvein/quests/DenizenTrigger.java @@ -0,0 +1,20 @@ +package me.blackvein.quests; + +import net.aufdemrand.denizen.BukkitScriptEntryData; +import net.aufdemrand.denizen.objects.dPlayer; +import net.aufdemrand.denizencore.scripts.ScriptRegistry; +import net.aufdemrand.denizencore.scripts.containers.core.TaskScriptContainer; + +public class DenizenTrigger { + protected boolean runDenizenScript(String scriptName, Quester quester) { + if (scriptName == null) { + return false; + } + if (ScriptRegistry.containsScript(scriptName)) { + TaskScriptContainer task_script = ScriptRegistry.getScriptContainerAs(scriptName, TaskScriptContainer.class); + BukkitScriptEntryData entryData = new BukkitScriptEntryData(dPlayer.mirrorBukkitPlayer(quester.getPlayer()), null); + task_script.runTaskScript(entryData, null); + } + return true; + } +} diff --git a/src/main/java/me/blackvein/quests/Dependencies.java b/src/main/java/me/blackvein/quests/Dependencies.java index 1654d4a15..9e2e8cee0 100644 --- a/src/main/java/me/blackvein/quests/Dependencies.java +++ b/src/main/java/me/blackvein/quests/Dependencies.java @@ -3,7 +3,11 @@ package me.blackvein.quests; import org.bukkit.plugin.RegisteredServiceProvider; import me.clip.placeholderapi.PlaceholderAPIPlugin; +import net.aufdemrand.denizen.BukkitScriptEntryData; import net.aufdemrand.denizen.Denizen; +import net.aufdemrand.denizen.objects.dPlayer; +import net.aufdemrand.denizencore.scripts.ScriptRegistry; +import net.aufdemrand.denizencore.scripts.containers.core.TaskScriptContainer; import net.citizensnpcs.api.CitizensPlugin; import net.milkbowl.vault.economy.Economy; import net.milkbowl.vault.permission.Permission; @@ -163,4 +167,8 @@ public class Dependencies { } return (permission != null); } + + public boolean runDenizenScript(String scriptName, Quester quester) { + return plugin.getDenizenTrigger().runDenizenScript(scriptName, quester); + } } diff --git a/src/main/java/me/blackvein/quests/Quest.java b/src/main/java/me/blackvein/quests/Quest.java index 6dcd2bbee..7d959292e 100644 --- a/src/main/java/me/blackvein/quests/Quest.java +++ b/src/main/java/me/blackvein/quests/Quest.java @@ -168,7 +168,7 @@ public class Quest { if (q.getCurrentStage(this).delay < 0) { if (q.currentQuests.get(this) == (orderedStages.size() - 1)) { if (q.getCurrentStage(this).script != null) { - plugin.runDenizenScript(q.getCurrentStage(this).script, q); + plugin.getDenizenTrigger().runDenizenScript(q.getCurrentStage(this).script, q); } if (q.getCurrentStage(this).finishEvent != null) { q.getCurrentStage(this).finishEvent.fire(q, this); @@ -222,7 +222,7 @@ public class Quest { quester.hardStagePut(this, stage); quester.addEmptiesFor(this, stage); if (currentStage.script != null) { - plugin.runDenizenScript(quester.getCurrentStage(this).script, quester); + plugin.getDenizenTrigger().runDenizenScript(quester.getCurrentStage(this).script, quester); } /* * if (quester.getCurrentStage(this).finishEvent != null) { quester.getCurrentStage(this).finishEvent.fire(quester); } diff --git a/src/main/java/me/blackvein/quests/Quests.java b/src/main/java/me/blackvein/quests/Quests.java index 15eb38ea2..55e51f691 100644 --- a/src/main/java/me/blackvein/quests/Quests.java +++ b/src/main/java/me/blackvein/quests/Quests.java @@ -90,10 +90,7 @@ import me.blackvein.quests.util.Lang; import me.blackvein.quests.util.LocaleQuery; import me.blackvein.quests.util.MiscUtil; import me.clip.placeholderapi.PlaceholderAPI; -import net.aufdemrand.denizen.BukkitScriptEntryData; -import net.aufdemrand.denizen.objects.dPlayer; import net.aufdemrand.denizencore.scripts.ScriptRegistry; -import net.aufdemrand.denizencore.scripts.containers.core.TaskScriptContainer; import net.citizensnpcs.api.CitizensAPI; import net.citizensnpcs.api.npc.NPC; @@ -119,6 +116,7 @@ public class Quests extends JavaPlugin implements ConversationAbandonedListener private NpcListener npcListener; private NpcEffectThread effThread; private PartiesListener partiesListener; + private DenizenTrigger trigger; private Lang lang; private LocaleQuery localeQuery; @@ -290,6 +288,10 @@ public class Quests extends JavaPlugin implements ConversationAbandonedListener return eventFactory; } + public DenizenTrigger getDenizenTrigger() { + return trigger; + } + public Lang getLang() { return lang; } @@ -1303,6 +1305,7 @@ public class Quests extends JavaPlugin implements ConversationAbandonedListener // Denizen script load if (config.contains("quests." + questKey + ".stages.ordered." + s2 + ".script-to-run")) { if (ScriptRegistry.containsScript(config.getString("quests." + questKey + ".stages.ordered." + s2 + ".script-to-run"))) { + trigger = new DenizenTrigger(); oStage.script = config.getString("quests." + questKey + ".stages.ordered." + s2 + ".script-to-run"); } else { stageFailed("script-to-run: in Stage " + s2 + " of Quest " + quest.getName() + " is not a Denizen script!"); @@ -2641,21 +2644,6 @@ public class Quests extends JavaPlugin implements ConversationAbandonedListener } return depends.getHeroes().getCharacterManager().getHero(p); } - - public boolean runDenizenScript(String scriptName, Quester quester) { - if (scriptName == null) { - return false; - } - if (depends.getDenizen() == null) { - return false; - } - if (ScriptRegistry.containsScript(scriptName)) { - TaskScriptContainer task_script = ScriptRegistry.getScriptContainerAs(scriptName, TaskScriptContainer.class); - BukkitScriptEntryData entryData = new BukkitScriptEntryData(dPlayer.mirrorBukkitPlayer(quester.getPlayer()), null); - task_script.runTaskScript(entryData, null); - } - return true; - } public boolean testPrimaryHeroesClass(String primaryClass, UUID uuid) { Hero hero = getHero(uuid); diff --git a/src/main/java/me/blackvein/quests/timers/StageTimer.java b/src/main/java/me/blackvein/quests/timers/StageTimer.java index 932565de1..7b915f9bf 100644 --- a/src/main/java/me/blackvein/quests/timers/StageTimer.java +++ b/src/main/java/me/blackvein/quests/timers/StageTimer.java @@ -38,7 +38,7 @@ public class StageTimer implements Runnable { if (quester.getQuestData(quest).delayOver) { if (quest.getStages().indexOf(quester.getCurrentStage(quest)) == (quest.getStages().size() - 1)) { if (quester.getCurrentStage(quest).getScript() != null) { - plugin.runDenizenScript(quester.getCurrentStage(quest).getScript(), quester); + plugin.getDependencies().runDenizenScript(quester.getCurrentStage(quest).getScript(), quester); } if (quester.getCurrentStage(quest).getFinishEvent() != null) { quester.getCurrentStage(quest).getFinishEvent().fire(quester, quest); @@ -49,7 +49,7 @@ public class StageTimer implements Runnable { int stageNum = quester.getCurrentQuests().get(quest) + 1; quester.hardQuit(quest); if (currentStage.getScript() != null) { - plugin.runDenizenScript(currentStage.getScript(), quester); + plugin.getDependencies().runDenizenScript(currentStage.getScript(), quester); } if (currentStage.getFinishEvent() != null) { currentStage.getFinishEvent().fire(quester, quest);