2017-12-30 08:36:36 +01:00
|
|
|
package net.citizensnpcs.nms.v1_10_R1.entity;
|
|
|
|
|
|
|
|
import java.util.UUID;
|
2023-02-22 17:06:13 +01:00
|
|
|
|
2017-12-30 08:36:36 +01:00
|
|
|
import org.bukkit.Bukkit;
|
|
|
|
import org.bukkit.Location;
|
|
|
|
import org.bukkit.craftbukkit.v1_10_R1.CraftWorld;
|
|
|
|
import org.bukkit.entity.Entity;
|
|
|
|
import org.bukkit.entity.Player;
|
2023-02-22 17:06:13 +01:00
|
|
|
|
2017-12-30 08:36:36 +01:00
|
|
|
import com.mojang.authlib.GameProfile;
|
2023-02-22 17:06:13 +01:00
|
|
|
|
2017-12-30 08:36:36 +01:00
|
|
|
import net.citizensnpcs.Settings.Setting;
|
|
|
|
import net.citizensnpcs.api.CitizensAPI;
|
|
|
|
import net.citizensnpcs.api.npc.NPC;
|
|
|
|
import net.citizensnpcs.npc.AbstractEntityController;
|
|
|
|
import net.citizensnpcs.npc.skin.Skin;
|
2022-07-25 17:14:00 +02:00
|
|
|
import net.citizensnpcs.trait.ScoreboardTrait;
|
2017-12-30 08:36:36 +01:00
|
|
|
import net.citizensnpcs.util.NMS;
|
2020-07-06 10:37:34 +02:00
|
|
|
import net.citizensnpcs.util.Util;
|
2017-12-30 08:36:36 +01:00
|
|
|
import net.minecraft.server.v1_10_R1.PlayerInteractManager;
|
|
|
|
import net.minecraft.server.v1_10_R1.WorldServer;
|
|
|
|
|
|
|
|
public class HumanController extends AbstractEntityController {
|
|
|
|
public HumanController() {
|
|
|
|
super();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
protected Entity createEntity(final Location at, final NPC npc) {
|
|
|
|
final WorldServer nmsWorld = ((CraftWorld) at.getWorld()).getHandle();
|
2020-07-06 10:37:34 +02:00
|
|
|
String coloredName = npc.getFullName();
|
|
|
|
String name = coloredName.length() > 16 ? coloredName.substring(0, 16) : coloredName;
|
2023-06-18 11:07:08 +02:00
|
|
|
UUID uuid = npc.getMinecraftUniqueId();
|
2020-08-28 16:43:14 +02:00
|
|
|
String teamName = Util.getTeamName(uuid);
|
|
|
|
if (npc.requiresNameHologram()) {
|
|
|
|
name = teamName;
|
|
|
|
}
|
2021-05-07 20:02:17 +02:00
|
|
|
if (Setting.USE_SCOREBOARD_TEAMS.asBoolean()) {
|
2022-07-25 17:14:00 +02:00
|
|
|
npc.getOrAddTrait(ScoreboardTrait.class).createTeam(name);
|
2021-05-07 20:02:17 +02:00
|
|
|
}
|
2017-12-30 08:36:36 +01:00
|
|
|
final GameProfile profile = new GameProfile(uuid, name);
|
|
|
|
final EntityHumanNPC handle = new EntityHumanNPC(nmsWorld.getServer().getServer(), nmsWorld, profile,
|
|
|
|
new PlayerInteractManager(nmsWorld), npc);
|
|
|
|
Skin skin = handle.getSkinTracker().getSkin();
|
|
|
|
if (skin != null) {
|
|
|
|
skin.apply(handle);
|
|
|
|
}
|
|
|
|
Bukkit.getScheduler().scheduleSyncDelayedTask(CitizensAPI.getPlugin(), new Runnable() {
|
|
|
|
@Override
|
|
|
|
public void run() {
|
2020-09-13 10:16:54 +02:00
|
|
|
if (getBukkitEntity() == null || !getBukkitEntity().isValid()
|
|
|
|
|| getBukkitEntity() != handle.getBukkitEntity())
|
2017-12-30 08:36:36 +01:00
|
|
|
return;
|
|
|
|
boolean removeFromPlayerList = npc.data().get("removefromplayerlist",
|
|
|
|
Setting.REMOVE_PLAYERS_FROM_PLAYER_LIST.asBoolean());
|
2018-06-27 06:00:03 +02:00
|
|
|
NMS.addOrRemoveFromPlayerList(getBukkitEntity(), removeFromPlayerList);
|
2017-12-30 08:36:36 +01:00
|
|
|
}
|
|
|
|
}, 20);
|
|
|
|
handle.getBukkitEntity().setSleepingIgnored(true);
|
|
|
|
return handle.getBukkitEntity();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public Player getBukkitEntity() {
|
|
|
|
return (Player) super.getBukkitEntity();
|
|
|
|
}
|
|
|
|
}
|