Skip to content

Commit

Permalink
Supports Folia and FancyNpcs.
Browse files Browse the repository at this point in the history
  • Loading branch information
toxicity188 committed Dec 1, 2023
1 parent e7e6a5c commit 49ec543
Show file tree
Hide file tree
Showing 70 changed files with 892 additions and 400 deletions.
3 changes: 3 additions & 0 deletions .idea/gradle.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

23 changes: 0 additions & 23 deletions api/src/main/java/kor/toxicity/questadder/api/APIManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -96,24 +96,6 @@ public interface APIManager {
*/
<T,R> void addFunction(@NotNull String name, @NotNull List<@NotNull Class<?>> args, @NotNull Class<T> argsClass, @NotNull Class<R> returnClass, @NotNull BiFunction<@NotNull T, @NotNull Object[], @NotNull R> function);

/**
* Gets NPC object from given uuid.
*
* @param uuid An entity uuid of NPC
* @return An object of NPC of null
* @since 1.0.3
*/
@Nullable
IActualNPC getNPC(@NotNull UUID uuid);
/**
* Gets NPC object from given name.
*
* @param name A yaml key of the NPC
* @return An object of NPC of null
* @since 1.0.5
*/
@Nullable
IActualNPC getNPC(@NotNull String name);

/**
* Gets all NPC in server.
Expand Down Expand Up @@ -171,11 +153,6 @@ public interface APIManager {
* @since 1.0.7
*/
@NotNull List<@NotNull String> getActionKeys();
/**
* @return A keys of all of loaded NPCs.
* @since 1.0.7
*/
@NotNull List<@NotNull String> getNPCKeys();
/**
* @return A keys of all of loaded quest NPCs.
* @since 1.0.7
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
package kor.toxicity.questadder.api;

import kor.toxicity.questadder.api.concurrent.LazyRunnable;
import kor.toxicity.questadder.api.mechanic.AbstractEvent;
import org.bukkit.event.Event;
import org.jetbrains.annotations.ApiStatus;
import org.jetbrains.annotations.NotNull;

import java.util.function.Supplier;

public interface QuestAdder {
/**
* Get an instance of QuestAdder's bukkit plugin.
Expand All @@ -26,7 +29,7 @@ public interface QuestAdder {
* @param runnable task
*/

void addLazyTask(@NotNull Runnable runnable); //This method is only available in custom action.
void addLazyTask(@NotNull LazyRunnable runnable); //This method is only available in custom action.
@ApiStatus.Internal
<T extends Event> void registerEvent(AbstractEvent<T> event, Class<T> clazz);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package kor.toxicity.questadder.api.concurrent;

import org.jetbrains.annotations.NotNull;

public interface LazyRunnable {
LazyRunnable EMPTY = new LazyRunnable() {
@Override
public long getDelay() {
return 0;
}

@Override
public void run() {

}
};
static @NotNull LazyRunnable emptyOf(@NotNull Runnable runnable) {
return new LazyRunnable() {
@Override
public long getDelay() {
return 0;
}

@Override
public void run() {
runnable.run();
}
};
}
long getDelay();
void run();
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,15 @@

import kor.toxicity.questadder.api.gui.IGui;
import kor.toxicity.questadder.api.util.SoundData;
import org.bukkit.Location;
import org.bukkit.entity.Entity;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import java.util.function.Supplier;

public interface DialogSender {
@Nullable
Entity getEntity();
@Nullable Supplier<Location> getLocationSupplier();
@NotNull
SoundData getSoundData();
@NotNull
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
package kor.toxicity.questadder.api.mechanic;

import kor.toxicity.questadder.api.npc.WrappedNPC;
import net.citizensnpcs.api.npc.NPC;
import org.jetbrains.annotations.NotNull;

public interface IActualNPC extends DialogSender {
@NotNull NPC toCitizensNPC();
@NotNull WrappedNPC toUsedNPC();
@NotNull IQuestNPC toQuestNPC();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package kor.toxicity.questadder.api.npc;

public interface CitizensNPC extends WrappedNPC {
int getId();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package kor.toxicity.questadder.api.npc;

import org.jetbrains.annotations.NotNull;

public interface FancyNpcsNPC extends WrappedNPC {
@NotNull String getId();
}
18 changes: 18 additions & 0 deletions api/src/main/java/kor/toxicity/questadder/api/npc/WrappedNPC.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package kor.toxicity.questadder.api.npc;

import org.bukkit.Location;
import org.bukkit.World;
import org.bukkit.entity.Entity;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import java.util.UUID;

public interface WrappedNPC {
@NotNull UUID getUUID();
@NotNull Object getHandle();
@Nullable Location getLocation();
@Nullable World getWorld();
float getEyeHeight();
@Nullable Entity getEntity();
}
3 changes: 2 additions & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ plugins {
}

val questAdderGroup = "kor.toxicity.questadder"
val questAdderVersion = "1.1.9"
val questAdderVersion = "1.2.0"

val adventureVersion = "4.14.0"
val platformVersion = "4.3.1"
Expand All @@ -34,6 +34,7 @@ allprojects {
maven(url = "https://repo.bg-software.com/repository/api/")
maven(url = "https://nexus.phoenixdevt.fr/repository/maven-public/")
maven(url = "https://repo.oraxen.com/releases")
maven(url = "https://repo.fancyplugins.de/releases")
}

dependencies {
Expand Down
1 change: 1 addition & 0 deletions nms/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
subprojects {
dependencies {
compileOnly(project(":platform"))
compileOnly(project(":scheduler"))
compileOnly(project(":plugin"))
compileOnly(project(":api"))
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ class NMSChannelImpl: NMSChannel {
connection.send(ClientboundOpenSignEditorPacket(blockPos))
it.signCallback = { arr ->
connection.send(ClientboundBlockUpdatePacket(blockPos, air))
QuestAdderBukkit.task {
QuestAdderBukkit.task(player.location) {
callback(arr)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import org.bukkit.command.CommandSender
import org.bukkit.command.SimpleCommandMap
import org.bukkit.craftbukkit.v1_17_R1.CraftServer
import org.bukkit.craftbukkit.v1_17_R1.CraftWorld
import org.bukkit.craftbukkit.v1_17_R1.entity.CraftEntity
import org.bukkit.craftbukkit.v1_17_R1.entity.CraftItem
import org.bukkit.craftbukkit.v1_17_R1.entity.CraftPlayer
import org.bukkit.craftbukkit.v1_17_R1.help.SimpleHelpMap
Expand Down Expand Up @@ -260,11 +261,16 @@ class NMSImpl: NMS {
t.setItemSlot(EquipmentSlot.HEAD, i)
connection.send(ClientboundSetEquipmentPacket(t.id, listOf(Pair.of(EquipmentSlot.HEAD, i))))
}

override fun setText(text: Component) {
t.customName = CraftChatMessage.fromJSON(GsonComponentSerializer.gson().serialize(text))
sendEntityDataPacket()
}

override fun setCustomNameVisible(boolean: Boolean) {
t.isCustomNameVisible = boolean
sendEntityDataPacket()
}
}
override fun getEyeHeight(entity: org.bukkit.entity.Entity): Float {
return (entity as CraftEntity).handle.eyeHeight
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ class NMSChannelImpl: NMSChannel {
connection.send(ClientboundOpenSignEditorPacket(blockPos))
it.signCallback = { arr ->
connection.send(ClientboundBlockUpdatePacket(blockPos, air))
QuestAdderBukkit.task {
QuestAdderBukkit.task(player.location) {
callback(arr)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import org.bukkit.command.CommandSender
import org.bukkit.command.SimpleCommandMap
import org.bukkit.craftbukkit.v1_18_R1.CraftServer
import org.bukkit.craftbukkit.v1_18_R1.CraftWorld
import org.bukkit.craftbukkit.v1_18_R1.entity.CraftEntity
import org.bukkit.craftbukkit.v1_18_R1.entity.CraftItem
import org.bukkit.craftbukkit.v1_18_R1.entity.CraftPlayer
import org.bukkit.craftbukkit.v1_18_R1.help.SimpleHelpMap
Expand Down Expand Up @@ -260,11 +261,16 @@ class NMSImpl: NMS {
t.setItemSlot(EquipmentSlot.HEAD, i)
connection.send(ClientboundSetEquipmentPacket(t.id, listOf(Pair.of(EquipmentSlot.HEAD, i))))
}

override fun setText(text: Component) {
t.customName = CraftChatMessage.fromJSON(GsonComponentSerializer.gson().serialize(text))
sendEntityDataPacket()
}

override fun setCustomNameVisible(boolean: Boolean) {
t.isCustomNameVisible = boolean
sendEntityDataPacket()
}
}
override fun getEyeHeight(entity: org.bukkit.entity.Entity): Float {
return (entity as CraftEntity).handle.eyeHeight
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ class NMSChannelImpl: NMSChannel {
connection.send(ClientboundOpenSignEditorPacket(blockPos))
it.signCallback = { arr ->
connection.send(ClientboundBlockUpdatePacket(blockPos, air))
QuestAdderBukkit.task {
QuestAdderBukkit.task(player.location) {
callback(arr)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import org.bukkit.command.CommandSender
import org.bukkit.command.SimpleCommandMap
import org.bukkit.craftbukkit.v1_18_R2.CraftServer
import org.bukkit.craftbukkit.v1_18_R2.CraftWorld
import org.bukkit.craftbukkit.v1_18_R2.entity.CraftEntity
import org.bukkit.craftbukkit.v1_18_R2.entity.CraftItem
import org.bukkit.craftbukkit.v1_18_R2.entity.CraftPlayer
import org.bukkit.craftbukkit.v1_18_R2.help.SimpleHelpMap
Expand Down Expand Up @@ -260,11 +261,16 @@ class NMSImpl: NMS {
t.setItemSlot(EquipmentSlot.HEAD, i)
connection.send(ClientboundSetEquipmentPacket(t.id, listOf(Pair.of(EquipmentSlot.HEAD, i))))
}

override fun setText(text: Component) {
t.customName = CraftChatMessage.fromJSON(GsonComponentSerializer.gson().serialize(text))
sendEntityDataPacket()
}

override fun setCustomNameVisible(boolean: Boolean) {
t.isCustomNameVisible = boolean
sendEntityDataPacket()
}
}
override fun getEyeHeight(entity: org.bukkit.entity.Entity): Float {
return (entity as CraftEntity).handle.eyeHeight
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ class NMSChannelImpl: NMSChannel {
connection.send(ClientboundOpenSignEditorPacket(blockPos))
it.signCallback = { arr ->
connection.send(ClientboundBlockUpdatePacket(blockPos, air))
QuestAdderBukkit.task {
QuestAdderBukkit.task(player.location) {
callback(arr)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import org.bukkit.command.CommandSender
import org.bukkit.command.SimpleCommandMap
import org.bukkit.craftbukkit.v1_19_R1.CraftServer
import org.bukkit.craftbukkit.v1_19_R1.CraftWorld
import org.bukkit.craftbukkit.v1_19_R1.entity.CraftEntity
import org.bukkit.craftbukkit.v1_19_R1.entity.CraftItem
import org.bukkit.craftbukkit.v1_19_R1.entity.CraftPlayer
import org.bukkit.craftbukkit.v1_19_R1.help.SimpleHelpMap
Expand Down Expand Up @@ -259,11 +260,16 @@ class NMSImpl: NMS {
t.setItemSlot(EquipmentSlot.HEAD, i)
connection.send(ClientboundSetEquipmentPacket(t.id, listOf(Pair.of(EquipmentSlot.HEAD, i))))
}

override fun setText(text: Component) {
t.customName = CraftChatMessage.fromJSON(GsonComponentSerializer.gson().serialize(text))
sendEntityDataPacket()
}

override fun setCustomNameVisible(boolean: Boolean) {
t.isCustomNameVisible = boolean
sendEntityDataPacket()
}
}
override fun getEyeHeight(entity: org.bukkit.entity.Entity): Float {
return (entity as CraftEntity).handle.eyeHeight
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ class NMSChannelImpl: NMSChannel {
connection.send(ClientboundOpenSignEditorPacket(blockPos))
it.signCallback = { arr ->
connection.send(ClientboundBlockUpdatePacket(blockPos, air))
QuestAdderBukkit.task {
QuestAdderBukkit.task(player.location) {
callback(arr)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ import org.bukkit.command.CommandSender
import org.bukkit.command.SimpleCommandMap
import org.bukkit.craftbukkit.v1_19_R2.CraftServer
import org.bukkit.craftbukkit.v1_19_R2.CraftWorld
import org.bukkit.craftbukkit.v1_19_R2.entity.CraftEntity
import org.bukkit.craftbukkit.v1_19_R2.entity.CraftItem
import org.bukkit.craftbukkit.v1_19_R2.entity.CraftPlayer
import org.bukkit.craftbukkit.v1_19_R2.help.SimpleHelpMap
Expand Down Expand Up @@ -273,11 +274,16 @@ class NMSImpl: NMS {
t.setItemSlot(EquipmentSlot.HEAD, i)
connection.send(ClientboundSetEquipmentPacket(t.id, listOf(Pair.of(EquipmentSlot.HEAD, i))))
}

override fun setText(text: Component) {
t.customName = CraftChatMessage.fromJSON(GsonComponentSerializer.gson().serialize(text))
sendEntityDataPacket()
}

override fun setCustomNameVisible(boolean: Boolean) {
t.isCustomNameVisible = boolean
sendEntityDataPacket()
}
}
override fun getEyeHeight(entity: org.bukkit.entity.Entity): Float {
return (entity as CraftEntity).handle.eyeHeight
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ class NMSChannelImpl: NMSChannel {
connection.send(ClientboundOpenSignEditorPacket(blockPos))
it.signCallback = { arr ->
connection.send(ClientboundBlockUpdatePacket(blockPos, air))
QuestAdderBukkit.task {
QuestAdderBukkit.task(player.location) {
callback(arr)
}
}
Expand Down
Loading

0 comments on commit 49ec543

Please sign in to comment.