Support Denizen 1.2.2+, fixes #1877. Bump version

This commit is contained in:
PikaMug 2022-02-07 02:27:08 -05:00
parent 2c92e6cd46
commit 7c05200909
11 changed files with 151 additions and 32 deletions

View File

@ -5,7 +5,7 @@
<parent> <parent>
<groupId>me.blackvein.quests</groupId> <groupId>me.blackvein.quests</groupId>
<artifactId>quests-parent</artifactId> <artifactId>quests-parent</artifactId>
<version>4.2.0</version> <version>4.2.1</version>
</parent> </parent>
<artifactId>quests-api</artifactId> <artifactId>quests-api</artifactId>
@ -66,7 +66,7 @@
<dependency> <dependency>
<groupId>com.denizenscript</groupId> <groupId>com.denizenscript</groupId>
<artifactId>denizen</artifactId> <artifactId>denizen</artifactId>
<version>1.1.3-SNAPSHOT</version> <version>1.2.3-SNAPSHOT</version>
<scope>provided</scope> <scope>provided</scope>
</dependency> </dependency>
<dependency> <dependency>

View File

@ -24,6 +24,7 @@ public class DenizenAPI {
private Class<?> denizen_1_0_9 = null; private Class<?> denizen_1_0_9 = null;
private Class<?> denizen_1_1_0 = null; private Class<?> denizen_1_1_0 = null;
private Class<?> denizen_1_1_1 = null; private Class<?> denizen_1_1_1 = null;
private Class<?> denizen_1_2_2 = null;
protected Class<?> scriptRegistry = null; protected Class<?> scriptRegistry = null;
protected Method containsScriptMethod = null; protected Method containsScriptMethod = null;
protected Method getScriptNamesMethod = null; protected Method getScriptNamesMethod = null;
@ -38,12 +39,21 @@ public class DenizenAPI {
protected Class<?> bukkitScriptEntryData = null; protected Class<?> bukkitScriptEntryData = null;
public DenizenAPI() { public DenizenAPI() {
try {
Class.forName("com.denizenscript.denizencore.utilities.ScriptUtilities");
denizen_1_2_2 = Class.forName("com.denizenscript.denizen.Denizen");
return;
} catch (final Exception e) {
// Fail silently
}
try { try {
bukkitScriptEntryData bukkitScriptEntryData
= Class.forName("com.denizenscript.denizen.utilities.implementation.BukkitScriptEntryData"); = Class.forName("com.denizenscript.denizen.utilities.implementation.BukkitScriptEntryData");
denizen_1_1_1 = Class.forName("com.denizenscript.denizen.Denizen"); denizen_1_1_1 = Class.forName("com.denizenscript.denizen.Denizen");
containsScriptMethod = scriptRegistry.getMethod("containsScript", String.class);
return; return;
} catch (final Exception e2) { } catch (final Exception e) {
// Fail silently // Fail silently
} }
try { try {
@ -57,10 +67,11 @@ public class DenizenAPI {
scriptEntryData = Class.forName("com.denizenscript.denizencore.scripts.ScriptEntryData"); scriptEntryData = Class.forName("com.denizenscript.denizencore.scripts.ScriptEntryData");
bukkitScriptEntryData = Class.forName("com.denizenscript.denizen.BukkitScriptEntryData"); bukkitScriptEntryData = Class.forName("com.denizenscript.denizen.BukkitScriptEntryData");
denizen_1_1_0 = Class.forName("com.denizenscript.denizen.Denizen"); denizen_1_1_0 = Class.forName("com.denizenscript.denizen.Denizen");
containsScriptMethod = scriptRegistry.getMethod("containsScript", String.class);
getScriptNamesMethod = scriptRegistry.getMethod("_getScriptNames"); getScriptNamesMethod = scriptRegistry.getMethod("_getScriptNames");
return; return;
} catch (final Exception e1) { } catch (final Exception e) {
// Fail silently // Fail silently
} }
try { try {
@ -86,12 +97,14 @@ public class DenizenAPI {
} }
public boolean isEnabled() { public boolean isEnabled() {
return denizen_1_1_1 != null || denizen_1_1_0 != null || denizen_1_0_9 != null; return denizen_1_2_2 != null || denizen_1_1_1 != null || denizen_1_1_0 != null || denizen_1_0_9 != null;
} }
@Nullable @Nullable
public Class<?> getDenizenClass() { public Class<?> getDenizenClass() {
if (denizen_1_1_1 != null) { if (denizen_1_2_2 != null) {
return denizen_1_2_2;
} else if (denizen_1_1_1 != null) {
return denizen_1_1_1; return denizen_1_1_1;
} else if (denizen_1_1_0 != null) { } else if (denizen_1_1_0 != null) {
return denizen_1_1_0; return denizen_1_1_0;
@ -102,7 +115,9 @@ public class DenizenAPI {
} }
public boolean containsScript(final String input) { public boolean containsScript(final String input) {
if (denizen_1_1_1 != null) { if (denizen_1_2_2 != null) {
return DenizenAPI_1_2_2.containsScript(input);
} else if (denizen_1_1_1 != null) {
return DenizenAPI_1_1_1.containsScript(input); return DenizenAPI_1_1_1.containsScript(input);
} else if (denizen_1_1_0 != null) { } else if (denizen_1_1_0 != null) {
return DenizenAPI_1_1_0.containsScript(input); return DenizenAPI_1_1_0.containsScript(input);
@ -114,7 +129,9 @@ public class DenizenAPI {
@Nullable @Nullable
public String getScriptContainerName(final String input) { public String getScriptContainerName(final String input) {
if (denizen_1_1_1 != null) { if (denizen_1_2_2 != null) {
return DenizenAPI_1_2_2.getScriptContainerName(input);
} else if (denizen_1_1_1 != null) {
return DenizenAPI_1_1_1.getScriptContainerName(input); return DenizenAPI_1_1_1.getScriptContainerName(input);
} else if (denizen_1_1_0 != null) { } else if (denizen_1_1_0 != null) {
return DenizenAPI_1_1_0.getScriptContainerName(input); return DenizenAPI_1_1_0.getScriptContainerName(input);
@ -126,7 +143,9 @@ public class DenizenAPI {
@Nullable @Nullable
public Set<String> getScriptNames() { public Set<String> getScriptNames() {
if (denizen_1_1_1 != null) { if (denizen_1_2_2 != null) {
return DenizenAPI_1_2_2.getScriptNames();
} else if (denizen_1_1_1 != null) {
return DenizenAPI_1_1_1.getScriptNames(); return DenizenAPI_1_1_1.getScriptNames();
} else if (denizen_1_1_0 != null) { } else if (denizen_1_1_0 != null) {
return DenizenAPI_1_1_0.getScriptNames(); return DenizenAPI_1_1_0.getScriptNames();
@ -138,7 +157,9 @@ public class DenizenAPI {
@Nullable @Nullable
public Object getScriptContainerAs(final String scriptName) { public Object getScriptContainerAs(final String scriptName) {
if (denizen_1_1_1 != null) { if (denizen_1_2_2 != null) {
return DenizenAPI_1_2_2.getScriptContainerAs(scriptName);
} else if (denizen_1_1_1 != null) {
return DenizenAPI_1_1_1.getScriptContainerAs(scriptName); return DenizenAPI_1_1_1.getScriptContainerAs(scriptName);
} else if (denizen_1_1_0 != null) { } else if (denizen_1_1_0 != null) {
return DenizenAPI_1_1_0.getScriptContainerAs(scriptName); return DenizenAPI_1_1_0.getScriptContainerAs(scriptName);
@ -150,7 +171,9 @@ public class DenizenAPI {
@Nullable @Nullable
public Object mirrorBukkitPlayer(final Player player) { public Object mirrorBukkitPlayer(final Player player) {
if (denizen_1_1_1 != null) { if (denizen_1_2_2 != null) {
return DenizenAPI_1_2_2.mirrorBukkitPlayer(player);
} else if (denizen_1_1_1 != null) {
return DenizenAPI_1_1_1.mirrorBukkitPlayer(player); return DenizenAPI_1_1_1.mirrorBukkitPlayer(player);
} else if (denizen_1_1_0 != null) { } else if (denizen_1_1_0 != null) {
return DenizenAPI_1_1_0.mirrorBukkitPlayer(player); return DenizenAPI_1_1_0.mirrorBukkitPlayer(player);
@ -162,7 +185,9 @@ public class DenizenAPI {
@Nullable @Nullable
public Object mirrorCitizensNPC(final NPC npc) { public Object mirrorCitizensNPC(final NPC npc) {
if (denizen_1_1_1 != null) { if (denizen_1_2_2 != null) {
return DenizenAPI_1_2_2.mirrorCitizensNPC(npc);
} else if (denizen_1_1_1 != null) {
return DenizenAPI_1_1_1.mirrorCitizensNPC(npc); return DenizenAPI_1_1_1.mirrorCitizensNPC(npc);
} else if (denizen_1_1_0 != null) { } else if (denizen_1_1_0 != null) {
return DenizenAPI_1_1_0.mirrorCitizensNPC(npc); return DenizenAPI_1_1_0.mirrorCitizensNPC(npc);
@ -173,7 +198,9 @@ public class DenizenAPI {
} }
public void runTaskScript(final String scriptName, final Player player) { public void runTaskScript(final String scriptName, final Player player) {
if (denizen_1_1_1 != null) { if (denizen_1_2_2 != null) {
DenizenAPI_1_2_2.runTaskScript(scriptName, player);
} else if (denizen_1_1_1 != null) {
DenizenAPI_1_1_1.runTaskScript(scriptName, player); DenizenAPI_1_1_1.runTaskScript(scriptName, player);
} else if (denizen_1_1_0 != null) { } else if (denizen_1_1_0 != null) {
DenizenAPI_1_1_0.runTaskScript(scriptName, player); DenizenAPI_1_1_0.runTaskScript(scriptName, player);

View File

@ -33,9 +33,16 @@ public class DenizenAPI_1_1_0 {
private static final QuestsAPI quests = (QuestsAPI) Bukkit.getPluginManager().getPlugin("Quests"); private static final QuestsAPI quests = (QuestsAPI) Bukkit.getPluginManager().getPlugin("Quests");
private static final DenizenAPI api = quests != null ? quests.getDependencies().getDenizenApi() : null; private static final DenizenAPI api = quests != null ? quests.getDependencies().getDenizenApi() : null;
public static boolean containsScript(final String input) { public static boolean containsScript(final String input) {
return ScriptRegistry.containsScript(input); if (quests == null || api.scriptRegistry == null || api.containsScriptMethod == null) return false;
boolean script = false;
try {
script = (boolean)api.containsScriptMethod.invoke(api.scriptRegistry, input);
} catch (final Exception e) {
quests.getLogger().log(Level.WARNING, "Error invoking Denizen ScriptRegistry#containsScript", e);
}
return script;
} }
@Nullable @Nullable
@ -67,7 +74,7 @@ public class DenizenAPI_1_1_0 {
} }
public static @NotNull Object mirrorCitizensNPC(final NPC npc) { public static @NotNull Object mirrorCitizensNPC(final NPC npc) {
return NPCTag.mirrorCitizensNPC(npc); 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) {

View File

@ -17,19 +17,33 @@ import com.denizenscript.denizen.objects.PlayerTag;
import com.denizenscript.denizen.utilities.implementation.BukkitScriptEntryData; import com.denizenscript.denizen.utilities.implementation.BukkitScriptEntryData;
import com.denizenscript.denizencore.scripts.ScriptRegistry; import com.denizenscript.denizencore.scripts.ScriptRegistry;
import com.denizenscript.denizencore.scripts.containers.core.TaskScriptContainer; import com.denizenscript.denizencore.scripts.containers.core.TaskScriptContainer;
import com.denizenscript.denizencore.scripts.queues.ScriptQueue;
import com.denizenscript.denizencore.scripts.queues.core.InstantQueue; import com.denizenscript.denizencore.scripts.queues.core.InstantQueue;
import me.blackvein.quests.QuestsAPI;
import net.citizensnpcs.api.npc.NPC; import net.citizensnpcs.api.npc.NPC;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable; import org.jetbrains.annotations.Nullable;
import java.lang.reflect.Method;
import java.util.List;
import java.util.Set; import java.util.Set;
import java.util.logging.Level;
public class DenizenAPI_1_1_1 { public class DenizenAPI_1_1_1 {
private static final QuestsAPI quests = (QuestsAPI) Bukkit.getPluginManager().getPlugin("Quests");
private static final DenizenAPI api = quests != null ? quests.getDependencies().getDenizenApi() : null;
public static boolean containsScript(final String input) { public static boolean containsScript(final String input) {
return ScriptRegistry.containsScript(input); if (quests == null || api.scriptRegistry == null || api.containsScriptMethod == null) return false;
boolean script = false;
try {
script = (boolean)api.containsScriptMethod.invoke(api.scriptRegistry, input);
} catch (final Exception e) {
quests.getLogger().log(Level.WARNING, "Error invoking Denizen ScriptRegistry#containsScript", e);
}
return script;
} }
@Nullable @Nullable
@ -52,14 +66,23 @@ public class DenizenAPI_1_1_1 {
} }
public static @NotNull Object mirrorCitizensNPC(final NPC npc) { public static @NotNull Object mirrorCitizensNPC(final NPC npc) {
return NPCTag.mirrorCitizensNPC(npc); 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 TaskScriptContainer taskScript = ScriptRegistry.getScriptContainerAs(scriptName, TaskScriptContainer.class); 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), null);
final ScriptQueue queue = new InstantQueue(taskScript.getName()) final InstantQueue queue = new InstantQueue(taskScript.getName());
.addEntries(taskScript.getBaseEntries(entryData.clone()));
queue.start(); if (quests == null) {
return;
}
try {
final Method addEntries = queue.getClass().getMethod("addEntries", List.class);
addEntries.invoke(queue, taskScript.getBaseEntries(entryData.clone()));
queue.start();
} catch (final Exception e) {
quests.getLogger().log(Level.WARNING, "Error invoking Denizen InstantQueue#addEntries", e);
}
} }
} }

View File

@ -0,0 +1,62 @@
/*
* 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.reflect.denizen;
import com.denizenscript.denizen.objects.NPCTag;
import com.denizenscript.denizen.objects.PlayerTag;
import com.denizenscript.denizen.utilities.implementation.BukkitScriptEntryData;
import com.denizenscript.denizencore.scripts.ScriptRegistry;
import com.denizenscript.denizencore.scripts.containers.core.TaskScriptContainer;
import com.denizenscript.denizencore.utilities.ScriptUtilities;
import net.citizensnpcs.api.npc.NPC;
import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.util.Set;
public class DenizenAPI_1_2_2 {
public static boolean containsScript(final String input) {
return ScriptRegistry.containsScript(input, TaskScriptContainer.class);
}
@Nullable
public static String getScriptContainerName(final String input) {
return ScriptRegistry.getScriptContainer(input).getName();
}
public static @NotNull Set<String> getScriptNames() {
return ScriptRegistry.scriptContainers.keySet();
}
@Nullable
public static Object getScriptContainerAs(final String scriptName) {
return ScriptRegistry.getScriptContainerAs(scriptName, TaskScriptContainer.class);
}
@Nullable
public static Object mirrorBukkitPlayer(final Player player) {
return PlayerTag.mirrorBukkitPlayer(player);
}
public static @NotNull Object mirrorCitizensNPC(final NPC npc) {
return NPCTag.fromEntity(npc.getEntity());
}
public static void runTaskScript(final String scriptName, final Player player) {
final TaskScriptContainer taskScript = ScriptRegistry.getScriptContainerAs(scriptName, TaskScriptContainer.class);
final BukkitScriptEntryData entryData = new BukkitScriptEntryData(PlayerTag.mirrorBukkitPlayer(player), null);
ScriptUtilities.createAndStartQueue(taskScript, null, entryData);
}
}

View File

@ -5,7 +5,7 @@
<parent> <parent>
<groupId>me.blackvein.quests</groupId> <groupId>me.blackvein.quests</groupId>
<artifactId>quests-parent</artifactId> <artifactId>quests-parent</artifactId>
<version>4.2.0</version> <version>4.2.1</version>
</parent> </parent>
<artifactId>quests-core</artifactId> <artifactId>quests-core</artifactId>

2
dist/pom.xml vendored
View File

@ -5,7 +5,7 @@
<parent> <parent>
<groupId>me.blackvein.quests</groupId> <groupId>me.blackvein.quests</groupId>
<artifactId>quests-parent</artifactId> <artifactId>quests-parent</artifactId>
<version>4.2.0</version> <version>4.2.1</version>
</parent> </parent>
<artifactId>quests-dist</artifactId> <artifactId>quests-dist</artifactId>
<packaging>pom</packaging> <packaging>pom</packaging>

View File

@ -6,12 +6,12 @@
<groupId>me.blackvein.quests</groupId> <groupId>me.blackvein.quests</groupId>
<artifactId>quests-parent</artifactId> <artifactId>quests-parent</artifactId>
<version>4.2.0</version> <version>4.2.1</version>
<name>quests</name> <name>quests</name>
<url>https://github.com/PikaMug/Quests/</url> <url>https://github.com/PikaMug/Quests/</url>
<properties> <properties>
<revision>4.2.0</revision> <revision>4.2.1</revision>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>1.8</maven.compiler.source> <maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target> <maven.compiler.target>1.8</maven.compiler.target>

View File

@ -6,7 +6,7 @@
<parent> <parent>
<groupId>me.blackvein.quests</groupId> <groupId>me.blackvein.quests</groupId>
<artifactId>quests-parent</artifactId> <artifactId>quests-parent</artifactId>
<version>4.2.0</version> <version>4.2.1</version>
</parent> </parent>
<properties> <properties>

View File

@ -6,7 +6,7 @@
<parent> <parent>
<groupId>me.blackvein.quests</groupId> <groupId>me.blackvein.quests</groupId>
<artifactId>quests-parent</artifactId> <artifactId>quests-parent</artifactId>
<version>4.2.0</version> <version>4.2.1</version>
</parent> </parent>
<properties> <properties>

View File

@ -6,7 +6,7 @@
<parent> <parent>
<groupId>me.blackvein.quests</groupId> <groupId>me.blackvein.quests</groupId>
<artifactId>quests-parent</artifactId> <artifactId>quests-parent</artifactId>
<version>4.2.0</version> <version>4.2.1</version>
</parent> </parent>
<properties> <properties>