Solved Citizens API

Discussion in 'Plugin Development' started by rhunter, Oct 25, 2016.

Thread Status:
Not open for further replies.
  1. Offline

    rhunter

    Hey im trying to use Citizens API so when a player does /clone, it spawns a clone of the player where they are standing. This is also my first time using an API. I can't figure out why it won't work. there are no errors in console.
    Code:
    public void onEnable() {
    Bukkit.getServer().getPluginManager().registerEvents(this, this);
          
             if(getServer().getPluginManager().getPlugin("Citizens") == null || getServer().getPluginManager().getPlugin("Citizens").isEnabled() == false) {
                    getLogger().log(Level.SEVERE, "Citizens 2.0 not found or not enabled");
                    getServer().getPluginManager().disablePlugin(this);
                    return;
                }
        }
    Code:
    if(cmd.getName().equalsIgnoreCase("clone")){
                Player player = (Player) sender;
                    NPCRegistry registry = CitizensAPI.getNPCRegistry();
                    NPC npc = registry.createNPC(EntityType.PLAYER, player.getName());
                    npc.spawn(Bukkit.getWorlds().get(0).getSpawnLocation());
            }
    Code:
    name: EasyRPG
    author: reecehunter
    version: 0.1
    description: Rpg plugin
    main: me.reece.EasyRPG.Main
    softdepend: [Citizens]
    commands:
      clone:
        description: Creates a clone of you.
     
    Last edited: Oct 25, 2016
  2. Offline

    Zombie_Striker

    Don't blindly cast the sender to a player. You have to make sure sender is actually a player before casting it. What if another plugin sends the command, or what if the console sends a command? Even if you think/know they will never send the message, why would you not want to check?

    Neither can we. We don't know what is wrong.
     
  3. Offline

    rhunter

    Neither do I, there is no error in console or anything. How am I supposed to know what is wrong?
     
  4. Offline

    timtower Administrator Administrator Moderator

    @rhunter You do know that you are spawning the NPC at spawn of the first world?
    Why not spawn on the location of the player as you want?
     
    rhunter likes this.
  5. Offline

    rhunter

    Thanks it worked! Haha that was dumb of me...
     
    timtower likes this.
  6. Offline

    timtower Administrator Administrator Moderator

    @rhunter Everybody makes mistakes :p
    Marked as solved
     
Thread Status:
Not open for further replies.

Share This Page