Its me again -- Having issies with Vector3f, how can i retrive it from a command?

  • English

2019-04-16: A new hotfix (0.9.5.7) is now available!

  • Its me again -- Having issies with Vector3f, how can i retrive it from a command?

    I'm Trying to have vector3f save the coords to memory, then retrive it From a command
    Ive tried attributes but that resulted in errors, id post the console here, but its not writing any errors into the debug console.
    it writes fine, i can get it from the same event, but i want to get the vector3f from the other event.



    Join me In my New Server:
    The World Within
    Discord: The World Within
  • What error did you get exactly? Maybe post your code here.

    Storing the Vector as attribute is actually the right way (or more precisely, the most convenient way) to store data. Make sure to use a unique attribute key name to avoid collisions with other plugins, e.g. use your package name or something like this (for example "testplugin.captaincornball.playerdata.vector"). When retrieving the data, you have to cast it to a Vector3f (since the "getAttribute()" function returns an "Object"). Example:

    Java Source Code

    1. //STORE VECTOR
    2. //The Vector3f you want to store
    3. Vector3f vector = new Vector3f(1, 2, 3);
    4. //Store as attribute (use unique key name)
    5. player.setAttribute("testvector", vector);
    6. //RETRIEVE VECTOR
    7. //Check if attribute is set
    8. if(player.hasAttribute("testvector")){
    9. //Get attribute and cast it to Vector3f
    10. Vector3f retrievedVector = (Vector3f) player.getAttribute("testvector");
    11. }
    Display All
  • Java Source Code

    1. @EventMethod
    2. public void onDeath(PlayerDeathEvent event){
    3. Player player = event.getPlayer();
    4. Vector3f Where = event.getDeathPosition();
    5. player.sendTextMessage("died");
    6. player.setAttribute("DeathPosition", Where);
    7. }
    8. @EventMethod
    9. public void onCommand(PlayerCommandEvent event){
    10. Player player = event.getPlayer();
    11. String command = event.getCommand();
    12. //split the command
    13. String[] cmd = command.split(" ");
    14. if(cmd[0].equals("/body")){
    15. if(player.hasAttribute("DeathPosition")){
    16. //Get attribute and cast it to Vector3f
    17. Vector3f retrievedVector = (Vector3f) player.getAttribute("testvector");
    18. player.moveTo(retrievedVector, 0);
    19. }
    Display All
    I don't know why it won;t write any Error logs or anything, It won't write to the debug console, i checked the logs, nothing.



    Join me In my New Server:
    The World Within
    Discord: The World Within