1.15.2 command sender cast to player unable to get unique id

Discussion in 'Spigot Plugin Development' started by catssss, Apr 16, 2020.

  1. I have a oncommand event and I need to get the senders unique id but IDK if I can do that by casting to player
  2. Mmmhhh maybe you are doing something wrong.
    Code (Java):
    if(!(sender instanceof Player)) return;
    Player player = (Player) sender;
    UUID uuid = player.getUniqueId(); // this should work
    • Like Like x 1
  3. I was a player and I ran the command and It didn't work but maybe it was some other part of my code
  4. Post your code if you want :)

    Also, I suggest you read this article: http://xyproblem.info/ <3
  5. double jump code (its messy): https://pastebin.com/6u8wjfBH
    the current thing I am trying to fix is the oncommand where I am trying to make it so if the player runs the command double jump won't work and they can fly normally it has to be per player because my server has more than just me
  6. ok so how would I get the UUID of the sender
  7. First thing, you are not checking to make sure the sender is a player. This will cause an error if sent by the console. Aren't you already doing this in your onCommand?
    Code (Text):
    Player player = (Player) sender;
  8. this is not my command
  9. is it possible to edit what the command outputs?
  10. I quoted that from your pastebin entry, so thats what was inside your command.

    I do not understand what you are asking. Commands from your plugin output what you make them output. So to answer your question, yes?
  11. My code should have worked because I was a player but it didn't and I found out why it was because with my ground detection sets it and so I just added some to say if they are on ground then you just set their flight to false
  12. Not my command I wanted to know if it was possible to edit it in oncommand and not in playercommandprepocces but I found a way around it it's gine
  13. @Override
    public boolean onCommand(CommandSender cs, Command cmd, String label, String[] args) {
    if (cs instanceof Player) return false;
    Player player = (Player) cs;
    UUID uuid = cs.getUniqueId();
    // stuff

  14. I found out why my code is not working it is because the oncommand isn't even running IDK why but I added a Bukkit.broadcastMessage("oncommand has fired"); and it didn't broadcast so some help would be appreciated
  15. drives_a_ford


    Did you register the command in plugin.yml?
    Do you have the @ Override annotation before the onCommand method?
    Are you sure your method exactly matches the signature of JavaPlugin#onCommand?
  16. its not my command does it have to be? and also does it need to be in the main class or use javaplugin at all? and what does override do?
  17. You said your onCommand method was not working, so he is showing you how you can fix the command.
    If it is in your main class, it has to extend JavaPlugin. however if you make it in another class, it doesn't have to extend JavaPlugin.
  18. the command I am trying to do something with is not in my plugin.yml because the stuff the command does is in a different plugin
  19. drives_a_ford


    And how are you linking your onCommand method to this command in another plugin exactly?