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