mirror of
https://github.com/PikaMug/Quests.git
synced 2024-11-21 18:15:32 +01:00
Begin to support NPC in Denizen script, fixes #1560
This commit is contained in:
parent
a7be8e9eb6
commit
b234e097e3
@ -65,7 +65,7 @@ public interface IDependencies {
|
||||
|
||||
boolean isPluginAvailable(final String pluginName);
|
||||
|
||||
boolean runDenizenScript(final String scriptName, final IQuester quester);
|
||||
boolean runDenizenScript(final String scriptName, final IQuester quester, final UUID uuid);
|
||||
|
||||
Location getNPCLocation(final int id);
|
||||
|
||||
|
@ -185,6 +185,9 @@ public class DenizenAPI {
|
||||
|
||||
@Nullable
|
||||
public Object mirrorCitizensNPC(final NPC npc) {
|
||||
if (npc == null) {
|
||||
return null;
|
||||
}
|
||||
if (denizen_1_2_2 != null) {
|
||||
return DenizenAPI_1_2_2.mirrorCitizensNPC(npc);
|
||||
} else if (denizen_1_1_1 != null) {
|
||||
@ -197,15 +200,15 @@ public class DenizenAPI {
|
||||
return null;
|
||||
}
|
||||
|
||||
public void runTaskScript(final String scriptName, final Player player) {
|
||||
public void runTaskScript(final String scriptName, final Player player, NPC npc) {
|
||||
if (denizen_1_2_2 != null) {
|
||||
DenizenAPI_1_2_2.runTaskScript(scriptName, player);
|
||||
DenizenAPI_1_2_2.runTaskScript(scriptName, player, npc);
|
||||
} else if (denizen_1_1_1 != null) {
|
||||
DenizenAPI_1_1_1.runTaskScript(scriptName, player);
|
||||
DenizenAPI_1_1_1.runTaskScript(scriptName, player, npc);
|
||||
} else if (denizen_1_1_0 != null) {
|
||||
DenizenAPI_1_1_0.runTaskScript(scriptName, player);
|
||||
DenizenAPI_1_1_0.runTaskScript(scriptName, player, npc);
|
||||
} else if (denizen_1_0_9 != null) {
|
||||
DenizenAPI_1_0_9.runTaskScript(scriptName, player);
|
||||
DenizenAPI_1_0_9.runTaskScript(scriptName, player, npc);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -105,14 +105,14 @@ public class DenizenAPI_1_0_9 {
|
||||
return dp;
|
||||
}
|
||||
|
||||
public static void runTaskScript(final String scriptName, final Player player) {
|
||||
public static void runTaskScript(final String scriptName, final Player player, final NPC npc) {
|
||||
if (quests == null || api.scriptRegistry == null || api.bukkitScriptEntryData == null || api.scriptEntryData == null) return;
|
||||
try {
|
||||
final Constructor<?> constructor = api.bukkitScriptEntryData.getConstructors()[0];
|
||||
final Object tsc = getScriptContainerAs(scriptName);
|
||||
if (tsc != null) {
|
||||
final Method runTaskScript = tsc.getClass().getMethod("runTaskScript", api.scriptEntryData, Map.class);
|
||||
runTaskScript.invoke(tsc, constructor.newInstance(mirrorBukkitPlayer(player), null), null);
|
||||
runTaskScript.invoke(tsc, constructor.newInstance(mirrorBukkitPlayer(player), mirrorCitizensNPC(npc)), null);
|
||||
}
|
||||
} catch (final Exception e) {
|
||||
quests.getPluginLogger().log(Level.WARNING, "Error invoking Denizen TaskScriptContainer#runTaskScript", e);
|
||||
|
@ -77,7 +77,7 @@ public class DenizenAPI_1_1_0 {
|
||||
return NPCTag.fromEntity(npc.getEntity());
|
||||
}
|
||||
|
||||
public static void runTaskScript(final String scriptName, final Player player) {
|
||||
public static void runTaskScript(final String scriptName, final Player player, final NPC npc) {
|
||||
if (quests == null) {
|
||||
return;
|
||||
}
|
||||
@ -86,7 +86,7 @@ public class DenizenAPI_1_1_0 {
|
||||
final Object tsc = getScriptContainerAs(scriptName);
|
||||
if (tsc != null) {
|
||||
final Method runTaskScript = tsc.getClass().getMethod("runTaskScript", api.scriptEntryData, Map.class);
|
||||
runTaskScript.invoke(tsc, constructor.newInstance(mirrorBukkitPlayer(player), null), null);
|
||||
runTaskScript.invoke(tsc, constructor.newInstance(mirrorBukkitPlayer(player), mirrorCitizensNPC(npc)), null);
|
||||
}
|
||||
} catch (final Exception e) {
|
||||
quests.getPluginLogger().log(Level.WARNING, "Error invoking Denizen TaskScriptContainer#runTaskScript", e);
|
||||
|
@ -69,9 +69,10 @@ public class DenizenAPI_1_1_1 {
|
||||
return NPCTag.fromEntity(npc.getEntity());
|
||||
}
|
||||
|
||||
public static void runTaskScript(final String scriptName, final Player player) {
|
||||
public static void runTaskScript(final String scriptName, final Player player, final NPC npc) {
|
||||
final TaskScriptContainer taskScript = ScriptRegistry.getScriptContainerAs(scriptName, TaskScriptContainer.class);
|
||||
final BukkitScriptEntryData entryData = new BukkitScriptEntryData(PlayerTag.mirrorBukkitPlayer(player), null);
|
||||
final BukkitScriptEntryData entryData = new BukkitScriptEntryData(PlayerTag.mirrorBukkitPlayer(player),
|
||||
npc != null ? NPCTag.fromEntity(npc.getEntity()) : null);
|
||||
final InstantQueue queue = new InstantQueue(taskScript.getName());
|
||||
|
||||
if (quests == null) {
|
||||
|
@ -54,9 +54,10 @@ public class DenizenAPI_1_2_2 {
|
||||
return NPCTag.fromEntity(npc.getEntity());
|
||||
}
|
||||
|
||||
public static void runTaskScript(final String scriptName, final Player player) {
|
||||
public static void runTaskScript(final String scriptName, final Player player, final NPC npc) {
|
||||
final TaskScriptContainer taskScript = ScriptRegistry.getScriptContainerAs(scriptName, TaskScriptContainer.class);
|
||||
final BukkitScriptEntryData entryData = new BukkitScriptEntryData(PlayerTag.mirrorBukkitPlayer(player), null);
|
||||
final BukkitScriptEntryData entryData = new BukkitScriptEntryData(PlayerTag.mirrorBukkitPlayer(player),
|
||||
npc != null ? NPCTag.fromEntity(npc.getEntity()) : null);
|
||||
ScriptUtilities.createAndStartQueue(taskScript, null, entryData);
|
||||
}
|
||||
}
|
||||
|
@ -268,8 +268,8 @@ public class Dependencies implements IDependencies {
|
||||
return (partyProvider != null);
|
||||
}
|
||||
|
||||
public boolean runDenizenScript(final String scriptName, final IQuester quester) {
|
||||
return plugin.getDenizenTrigger().runDenizenScript(scriptName, quester);
|
||||
public boolean runDenizenScript(final String scriptName, final IQuester quester, final UUID uuid) {
|
||||
return plugin.getDenizenTrigger().runDenizenScript(scriptName, quester, uuid);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -270,7 +270,7 @@ public class Quest implements IQuest {
|
||||
}
|
||||
if (quester.getCurrentQuestsTemp().get(this) == (orderedStages.size() - 1)) {
|
||||
if (currentStage.getScript() != null) {
|
||||
plugin.getDenizenTrigger().runDenizenScript(currentStage.getScript(), quester);
|
||||
plugin.getDenizenTrigger().runDenizenScript(currentStage.getScript(), quester, null);
|
||||
}
|
||||
completeQuest(quester);
|
||||
} else {
|
||||
@ -327,7 +327,7 @@ public class Quest implements IQuest {
|
||||
quester.hardStagePut(this, stage);
|
||||
quester.addEmptiesFor(this, stage);
|
||||
if (currentStage.getScript() != null) {
|
||||
plugin.getDenizenTrigger().runDenizenScript(currentStage.getScript(), quester);
|
||||
plugin.getDenizenTrigger().runDenizenScript(currentStage.getScript(), quester, null);
|
||||
}
|
||||
if (nextStage.getStartAction() != null) {
|
||||
nextStage.getStartAction().fire(quester, this);
|
||||
|
@ -463,7 +463,7 @@ public class Action implements IAction {
|
||||
}
|
||||
}
|
||||
if (denizenScript != null) {
|
||||
plugin.getDenizenTrigger().runDenizenScript(denizenScript, quester);
|
||||
plugin.getDenizenTrigger().runDenizenScript(denizenScript, quester, null);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -12,8 +12,11 @@
|
||||
|
||||
package me.blackvein.quests.dependencies;
|
||||
|
||||
import me.blackvein.quests.player.IQuester;
|
||||
import me.blackvein.quests.Quests;
|
||||
import me.blackvein.quests.player.IQuester;
|
||||
import net.citizensnpcs.api.npc.NPC;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
public class DenizenTrigger {
|
||||
private final Quests plugin;
|
||||
@ -21,12 +24,18 @@ public class DenizenTrigger {
|
||||
public DenizenTrigger(final Quests plugin) {
|
||||
this.plugin = plugin;
|
||||
}
|
||||
public boolean runDenizenScript(final String scriptName, final IQuester quester) {
|
||||
|
||||
public boolean runDenizenScript(final String scriptName, final IQuester quester, final UUID uuid) {
|
||||
if (scriptName == null) {
|
||||
return false;
|
||||
}
|
||||
if (plugin.getDependencies().getDenizenApi().containsScript(scriptName)) {
|
||||
plugin.getDependencies().getDenizenApi().runTaskScript(scriptName, quester.getPlayer());
|
||||
if (plugin.getDependencies().getCitizens() != null) {
|
||||
final NPC npc = plugin.getDependencies().getCitizens().getNPCRegistry().getByUniqueId(uuid);
|
||||
plugin.getDependencies().getDenizenApi().runTaskScript(scriptName, quester.getPlayer(), npc);
|
||||
} else {
|
||||
plugin.getDependencies().getDenizenApi().runTaskScript(scriptName, quester.getPlayer(), null);
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
@ -44,7 +44,7 @@ public class StageTimer implements Runnable {
|
||||
}
|
||||
if (quest.getStages().indexOf(quester.getCurrentStage(quest)) == (quest.getStages().size() - 1)) {
|
||||
if (quester.getCurrentStage(quest).getScript() != null) {
|
||||
plugin.getDependencies().runDenizenScript(quester.getCurrentStage(quest).getScript(), quester);
|
||||
plugin.getDependencies().runDenizenScript(quester.getCurrentStage(quest).getScript(), quester, null);
|
||||
}
|
||||
quest.completeQuest(quester);
|
||||
} else if (quester.testComplete(quest)) {
|
||||
|
Loading…
Reference in New Issue
Block a user