For version 1.0-dev.
This commit is contained in:
@@ -42,13 +42,14 @@ public class NPCLib {
|
|||||||
/**
|
/**
|
||||||
* Create a new non-player character (NPC).
|
* Create a new non-player character (NPC).
|
||||||
*
|
*
|
||||||
* @param skin The skin you want the NPC to have.
|
* @param skin The skin you want the NPC to have.
|
||||||
* @param lines The text you want to sendShowPackets above the NPC (null = no text).
|
* @param autoHideDistance Distance from where you want to NPC to hide from the player (50 recommended).
|
||||||
|
* @param lines The text you want to sendShowPackets above the NPC (null = no text).
|
||||||
* @return The NPC object you may use to sendShowPackets it to players.
|
* @return The NPC object you may use to sendShowPackets it to players.
|
||||||
*/
|
*/
|
||||||
public NPC createNPC(Skin skin, List<String> lines) {
|
public NPC createNPC(Skin skin, double autoHideDistance, List<String> lines) {
|
||||||
try {
|
try {
|
||||||
return version.createNPC(plugin, skin, lines);
|
return version.createNPC(plugin, skin, autoHideDistance, lines);
|
||||||
} catch (InstantiationException | IllegalAccessException | InvocationTargetException exception) {
|
} catch (InstantiationException | IllegalAccessException | InvocationTargetException exception) {
|
||||||
Bukkit.getConsoleSender().sendMessage(ChatColor.RED + "NPCLib failed to create NPC. Please report this stacktrace:");
|
Bukkit.getConsoleSender().sendMessage(ChatColor.RED + "NPCLib failed to create NPC. Please report this stacktrace:");
|
||||||
exception.printStackTrace();
|
exception.printStackTrace();
|
||||||
@@ -56,4 +57,15 @@ public class NPCLib {
|
|||||||
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create a new non-player character (NPC).
|
||||||
|
*
|
||||||
|
* @param skin The skin you want the NPC to have.
|
||||||
|
* @param lines The text you want to sendShowPackets above the NPC (null = no text).
|
||||||
|
* @return The NPC object you may use to sendShowPackets it to players.
|
||||||
|
*/
|
||||||
|
public NPC createNPC(Skin skin, List<String> lines) {
|
||||||
|
return createNPC(skin, 50, lines);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ import com.mojang.authlib.properties.Property;
|
|||||||
import net.jitse.npclib.NPCManager;
|
import net.jitse.npclib.NPCManager;
|
||||||
import net.jitse.npclib.events.NPCDestroyEvent;
|
import net.jitse.npclib.events.NPCDestroyEvent;
|
||||||
import net.jitse.npclib.events.NPCSpawnEvent;
|
import net.jitse.npclib.events.NPCSpawnEvent;
|
||||||
|
import net.jitse.npclib.events.trigger.TriggerType;
|
||||||
import net.jitse.npclib.skin.Skin;
|
import net.jitse.npclib.skin.Skin;
|
||||||
import org.bukkit.Location;
|
import org.bukkit.Location;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
@@ -41,10 +42,6 @@ public abstract class NPC {
|
|||||||
NPCManager.add(this);
|
NPCManager.add(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
public NPC(JavaPlugin plugin, Skin skin, List<String> lines) {
|
|
||||||
this(plugin, skin, 50, lines);
|
|
||||||
}
|
|
||||||
|
|
||||||
protected GameProfile generateGameProfile(UUID uuid, String name) {
|
protected GameProfile generateGameProfile(UUID uuid, String name) {
|
||||||
GameProfile gameProfile = new GameProfile(uuid, name);
|
GameProfile gameProfile = new GameProfile(uuid, name);
|
||||||
gameProfile.getProperties().removeAll("textures");
|
gameProfile.getProperties().removeAll("textures");
|
||||||
@@ -88,7 +85,7 @@ public abstract class NPC {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void show(Player player, boolean auto) {
|
public void show(Player player, boolean auto) {
|
||||||
NPCSpawnEvent event = new NPCSpawnEvent(this, player);
|
NPCSpawnEvent event = new NPCSpawnEvent(this, player, auto ? TriggerType.AUTOMATIC : TriggerType.MANUAL);
|
||||||
plugin.getServer().getPluginManager().callEvent(event);
|
plugin.getServer().getPluginManager().callEvent(event);
|
||||||
if (event.isCancelled()) {
|
if (event.isCancelled()) {
|
||||||
return;
|
return;
|
||||||
@@ -121,7 +118,7 @@ public abstract class NPC {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void hide(Player player, boolean auto) {
|
public void hide(Player player, boolean auto) {
|
||||||
NPCDestroyEvent event = new NPCDestroyEvent(this, player);
|
NPCDestroyEvent event = new NPCDestroyEvent(this, player, auto ? TriggerType.AUTOMATIC : TriggerType.MANUAL);
|
||||||
plugin.getServer().getPluginManager().callEvent(event);
|
plugin.getServer().getPluginManager().callEvent(event);
|
||||||
if (event.isCancelled()) {
|
if (event.isCancelled()) {
|
||||||
return;
|
return;
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
package net.jitse.npclib.events;
|
package net.jitse.npclib.events;
|
||||||
|
|
||||||
import net.jitse.npclib.api.NPC;
|
import net.jitse.npclib.api.NPC;
|
||||||
|
import net.jitse.npclib.events.trigger.TriggerType;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.event.Cancellable;
|
import org.bukkit.event.Cancellable;
|
||||||
import org.bukkit.event.Event;
|
import org.bukkit.event.Event;
|
||||||
@@ -14,10 +15,12 @@ public class NPCDestroyEvent extends Event implements Cancellable {
|
|||||||
|
|
||||||
private final NPC npc;
|
private final NPC npc;
|
||||||
private final Player player;
|
private final Player player;
|
||||||
|
private final TriggerType trigger;
|
||||||
|
|
||||||
public NPCDestroyEvent(NPC npc, Player player) {
|
public NPCDestroyEvent(NPC npc, Player player, TriggerType trigger) {
|
||||||
this.npc = npc;
|
this.npc = npc;
|
||||||
this.player = player;
|
this.player = player;
|
||||||
|
this.trigger = trigger;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -33,6 +36,10 @@ public class NPCDestroyEvent extends Event implements Cancellable {
|
|||||||
return player;
|
return player;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public TriggerType getTrigger() {
|
||||||
|
return trigger;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isCancelled() {
|
public boolean isCancelled() {
|
||||||
return cancelled;
|
return cancelled;
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
package net.jitse.npclib.events;
|
package net.jitse.npclib.events;
|
||||||
|
|
||||||
import net.jitse.npclib.api.NPC;
|
import net.jitse.npclib.api.NPC;
|
||||||
|
import net.jitse.npclib.events.trigger.TriggerType;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.event.Cancellable;
|
import org.bukkit.event.Cancellable;
|
||||||
import org.bukkit.event.Event;
|
import org.bukkit.event.Event;
|
||||||
@@ -14,10 +15,12 @@ public class NPCSpawnEvent extends Event implements Cancellable {
|
|||||||
|
|
||||||
private final NPC npc;
|
private final NPC npc;
|
||||||
private final Player player;
|
private final Player player;
|
||||||
|
private final TriggerType trigger;
|
||||||
|
|
||||||
public NPCSpawnEvent(NPC npc, Player player) {
|
public NPCSpawnEvent(NPC npc, Player player, TriggerType trigger) {
|
||||||
this.npc = npc;
|
this.npc = npc;
|
||||||
this.player = player;
|
this.player = player;
|
||||||
|
this.trigger = trigger;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -33,6 +36,10 @@ public class NPCSpawnEvent extends Event implements Cancellable {
|
|||||||
return player;
|
return player;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public TriggerType getTrigger() {
|
||||||
|
return trigger;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isCancelled() {
|
public boolean isCancelled() {
|
||||||
return cancelled;
|
return cancelled;
|
||||||
|
|||||||
@@ -0,0 +1,6 @@
|
|||||||
|
package net.jitse.npclib.events.trigger;
|
||||||
|
|
||||||
|
public enum TriggerType {
|
||||||
|
|
||||||
|
MANUAL, AUTOMATIC
|
||||||
|
}
|
||||||
@@ -25,8 +25,8 @@ public class NPC_V1_10_R1 extends NPC {
|
|||||||
private PacketPlayOutEntityHeadRotation packetPlayOutEntityHeadRotation;
|
private PacketPlayOutEntityHeadRotation packetPlayOutEntityHeadRotation;
|
||||||
private PacketPlayOutEntityDestroy packetPlayOutEntityDestroy;
|
private PacketPlayOutEntityDestroy packetPlayOutEntityDestroy;
|
||||||
|
|
||||||
public NPC_V1_10_R1(JavaPlugin plugin, Skin skin, List<String> lines) {
|
public NPC_V1_10_R1(JavaPlugin plugin, Skin skin, double autoHideDistance, List<String> lines) {
|
||||||
super(plugin, skin, lines);
|
super(plugin, skin, autoHideDistance, lines);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -25,8 +25,8 @@ public class NPC_V1_11_R1 extends NPC {
|
|||||||
private PacketPlayOutEntityHeadRotation packetPlayOutEntityHeadRotation;
|
private PacketPlayOutEntityHeadRotation packetPlayOutEntityHeadRotation;
|
||||||
private PacketPlayOutEntityDestroy packetPlayOutEntityDestroy;
|
private PacketPlayOutEntityDestroy packetPlayOutEntityDestroy;
|
||||||
|
|
||||||
public NPC_V1_11_R1(JavaPlugin plugin, Skin skin, List<String> lines) {
|
public NPC_V1_11_R1(JavaPlugin plugin, Skin skin, double autoHideDistance, List<String> lines) {
|
||||||
super(plugin, skin, lines);
|
super(plugin, skin, autoHideDistance, lines);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -25,8 +25,8 @@ public class NPC_V1_12_R1 extends NPC {
|
|||||||
private PacketPlayOutEntityHeadRotation packetPlayOutEntityHeadRotation;
|
private PacketPlayOutEntityHeadRotation packetPlayOutEntityHeadRotation;
|
||||||
private PacketPlayOutEntityDestroy packetPlayOutEntityDestroy;
|
private PacketPlayOutEntityDestroy packetPlayOutEntityDestroy;
|
||||||
|
|
||||||
public NPC_V1_12_R1(JavaPlugin plugin, Skin skin, List<String> lines) {
|
public NPC_V1_12_R1(JavaPlugin plugin, Skin skin, double autoHideDistance, List<String> lines) {
|
||||||
super(plugin, skin, lines);
|
super(plugin, skin, autoHideDistance, lines);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -25,8 +25,8 @@ public class NPC_V1_8_R1 extends NPC {
|
|||||||
private PacketPlayOutEntityHeadRotation packetPlayOutEntityHeadRotation;
|
private PacketPlayOutEntityHeadRotation packetPlayOutEntityHeadRotation;
|
||||||
private PacketPlayOutEntityDestroy packetPlayOutEntityDestroy;
|
private PacketPlayOutEntityDestroy packetPlayOutEntityDestroy;
|
||||||
|
|
||||||
public NPC_V1_8_R1(JavaPlugin plugin, Skin skin, List<String> lines) {
|
public NPC_V1_8_R1(JavaPlugin plugin, Skin skin, double autoHideDistance, List<String> lines) {
|
||||||
super(plugin, skin, lines);
|
super(plugin, skin, autoHideDistance, lines);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -25,8 +25,8 @@ public class NPC_V1_8_R2 extends NPC {
|
|||||||
private PacketPlayOutEntityHeadRotation packetPlayOutEntityHeadRotation;
|
private PacketPlayOutEntityHeadRotation packetPlayOutEntityHeadRotation;
|
||||||
private PacketPlayOutEntityDestroy packetPlayOutEntityDestroy;
|
private PacketPlayOutEntityDestroy packetPlayOutEntityDestroy;
|
||||||
|
|
||||||
public NPC_V1_8_R2(JavaPlugin plugin, Skin skin, List<String> lines) {
|
public NPC_V1_8_R2(JavaPlugin plugin, Skin skin, double autoHideDistance, List<String> lines) {
|
||||||
super(plugin, skin, lines);
|
super(plugin, skin, autoHideDistance, lines);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -25,8 +25,8 @@ public class NPC_V1_8_R3 extends NPC {
|
|||||||
private PacketPlayOutEntityHeadRotation packetPlayOutEntityHeadRotation;
|
private PacketPlayOutEntityHeadRotation packetPlayOutEntityHeadRotation;
|
||||||
private PacketPlayOutEntityDestroy packetPlayOutEntityDestroy;
|
private PacketPlayOutEntityDestroy packetPlayOutEntityDestroy;
|
||||||
|
|
||||||
public NPC_V1_8_R3(JavaPlugin plugin, Skin skin, List<String> lines) {
|
public NPC_V1_8_R3(JavaPlugin plugin, Skin skin, double autoHideDistance, List<String> lines) {
|
||||||
super(plugin, skin, lines);
|
super(plugin, skin, autoHideDistance, lines);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -25,8 +25,8 @@ public class NPC_V1_9_R1 extends NPC {
|
|||||||
private PacketPlayOutEntityHeadRotation packetPlayOutEntityHeadRotation;
|
private PacketPlayOutEntityHeadRotation packetPlayOutEntityHeadRotation;
|
||||||
private PacketPlayOutEntityDestroy packetPlayOutEntityDestroy;
|
private PacketPlayOutEntityDestroy packetPlayOutEntityDestroy;
|
||||||
|
|
||||||
public NPC_V1_9_R1(JavaPlugin plugin, Skin skin, List<String> lines) {
|
public NPC_V1_9_R1(JavaPlugin plugin, Skin skin, double autoHideDistance, List<String> lines) {
|
||||||
super(plugin, skin, lines);
|
super(plugin, skin, autoHideDistance, lines);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -25,8 +25,8 @@ public class NPC_V1_9_R2 extends NPC {
|
|||||||
private PacketPlayOutEntityHeadRotation packetPlayOutEntityHeadRotation;
|
private PacketPlayOutEntityHeadRotation packetPlayOutEntityHeadRotation;
|
||||||
private PacketPlayOutEntityDestroy packetPlayOutEntityDestroy;
|
private PacketPlayOutEntityDestroy packetPlayOutEntityDestroy;
|
||||||
|
|
||||||
public NPC_V1_9_R2(JavaPlugin plugin, Skin skin, List<String> lines) {
|
public NPC_V1_9_R2(JavaPlugin plugin, Skin skin, double autoHideDistance, List<String> lines) {
|
||||||
super(plugin, skin, lines);
|
super(plugin, skin, autoHideDistance, lines);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -33,7 +33,7 @@ public class NPCLibPlugin extends JavaPlugin implements Listener {
|
|||||||
}
|
}
|
||||||
|
|
||||||
MineSkinFetcher.fetchSkinFromIdAsync(168841, skin -> {
|
MineSkinFetcher.fetchSkinFromIdAsync(168841, skin -> {
|
||||||
NPC npc = npcLib.createNPC(skin, Arrays.asList(
|
NPC npc = npcLib.createNPC(skin, 5, Arrays.asList(
|
||||||
ChatColor.BOLD + "NPC Library", "",
|
ChatColor.BOLD + "NPC Library", "",
|
||||||
"Create your own", "non-player characters",
|
"Create your own", "non-player characters",
|
||||||
"with the simplistic", "API of NPCLib!"
|
"with the simplistic", "API of NPCLib!"
|
||||||
|
|||||||
Reference in New Issue
Block a user