Paste #121315: I spawn the npc with the command and then I try to move it to the clicked log (it does not move)

Date: 2024/03/27 12:15:11 UTC-07:00
Type: Java

View Raw Paste Download This Paste
Copy Link


------------------------CITIZENS LISTENER---------------------------
public class CitizensCostumersListener implements Listener {
    private final RestaurantTycoon plugin;

    public CitizensCostumersListener() {
        this.plugin = RestaurantTycoon.getInstance();
    }

    @EventHandler
    public void onPlayerInteract(PlayerInteractEvent event) {
        Player player = event.getPlayer();

        if (event.getAction() == Action.RIGHT_CLICK_BLOCK && event.getClickedBlock().getType() == Material.OAK_LOG) {
            Block oakLog = event.getClickedBlock();

            NPCCommand npcCommand = new NPCCommand();
            npcCommand.spawnNPC(player);

            if (npcCommand.npc != null) {
                Navigator navigator = npcCommand.npc.getNavigator();
                navigator.setTarget(oakLog.getLocation());
                player.sendMessage("test");
            }
        }
    }
}


----------------COMMAND CLASS---------------
@CommandAlias("testnpc")
@CommandPermission("restauranttycoon.command.npc")
@Description("Voeg customer npc toe.")
public class NPCCommand extends BaseCommand {
    public NPC npc;

    @Default
    public void spawnNPC(Player player) {
        String randomName = generateRandomPlayerName();

        npc = CitizensAPI.getNPCRegistry().createNPC(EntityType.PLAYER, randomName);
        npc.spawn(player.getLocation());
    }

    private String generateRandomPlayerName() {
        String[] names = {"Johan", "Daniel", "Pieter"};
        Random random = new Random();

        return names[random.nextInt(names.length)];
    }
}


Highlighting for 'Other' types handled by Highlight.JS, which was released under the BSD 3-Clause License.