2021-06-12 21:20:18 +02:00
|
|
|
package net.citizensnpcs.nms.v1_17_R1.entity;
|
|
|
|
|
|
|
|
import java.util.UUID;
|
2023-02-22 17:06:13 +01:00
|
|
|
|
2021-06-12 21:20:18 +02:00
|
|
|
import org.bukkit.Bukkit;
|
|
|
|
import org.bukkit.Location;
|
|
|
|
import org.bukkit.craftbukkit.v1_17_R1.CraftWorld;
|
|
|
|
import org.bukkit.entity.Entity;
|
|
|
|
import org.bukkit.entity.Player;
|
2023-02-22 17:06:13 +01:00
|
|
|
|
2021-06-12 21:20:18 +02:00
|
|
|
import com.mojang.authlib.GameProfile;
|
2023-02-22 17:06:13 +01:00
|
|
|
|
2021-06-12 21:20:18 +02: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;
|
2021-06-12 21:20:18 +02:00
|
|
|
import net.citizensnpcs.util.NMS;
|
|
|
|
import net.citizensnpcs.util.Util;
|
|
|
|
import net.minecraft.server.MinecraftServer;
|
|
|
|
import net.minecraft.server.level.ServerLevel;
|
|
|
|
|
|
|
|
public class HumanController extends AbstractEntityController {
|
|
|
|
public HumanController() {
|
|
|
|
super();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
protected Entity createEntity(final Location at, final NPC npc) {
|
|
|
|
final ServerLevel nmsWorld = ((CraftWorld) at.getWorld()).getHandle();
|
|
|
|
String coloredName = npc.getFullName();
|
|
|
|
String name = coloredName.length() > 16 ? coloredName.substring(0, 16) : coloredName;
|
|
|
|
UUID uuid = npc.getUniqueId();
|
|
|
|
String teamName = Util.getTeamName(uuid);
|
|
|
|
if (npc.requiresNameHologram()) {
|
|
|
|
name = teamName;
|
|
|
|
}
|
|
|
|
if (Setting.USE_SCOREBOARD_TEAMS.asBoolean()) {
|
2022-07-25 17:14:00 +02:00
|
|
|
npc.getOrAddTrait(ScoreboardTrait.class).createTeam(teamName);
|
2021-06-12 21:20:18 +02:00
|
|
|
}
|
|
|
|
final GameProfile profile = new GameProfile(uuid, name);
|
|
|
|
final EntityHumanNPC handle = new EntityHumanNPC(MinecraftServer.getServer(), nmsWorld, profile, npc);
|
|
|
|
Skin skin = handle.getSkinTracker().getSkin();
|
|
|
|
if (skin != null) {
|
|
|
|
skin.apply(handle);
|
|
|
|
}
|
|
|
|
Bukkit.getScheduler().scheduleSyncDelayedTask(CitizensAPI.getPlugin(), new Runnable() {
|
|
|
|
@Override
|
|
|
|
public void run() {
|
|
|
|
if (getBukkitEntity() == null || !getBukkitEntity().isValid()
|
|
|
|
|| getBukkitEntity() != handle.getBukkitEntity())
|
|
|
|
return;
|
|
|
|
boolean removeFromPlayerList = npc.data().get("removefromplayerlist",
|
|
|
|
Setting.REMOVE_PLAYERS_FROM_PLAYER_LIST.asBoolean());
|
|
|
|
NMS.addOrRemoveFromPlayerList(getBukkitEntity(), removeFromPlayerList);
|
|
|
|
}
|
|
|
|
}, 20);
|
|
|
|
handle.getBukkitEntity().setSleepingIgnored(true);
|
|
|
|
return handle.getBukkitEntity();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public Player getBukkitEntity() {
|
|
|
|
return (Player) super.getBukkitEntity();
|
|
|
|
}
|
|
|
|
}
|