[plugin]Whereis Player

    • [plugin]Whereis Player

      Hello everybody,

      I present a plugin that shows in which cardinal direction a designated player is.

      Usage: Type "/whereis playername" in the chat. It shows in which direction the said player is, as long as he/she is online.

      WhereisPlayer.zip

      Screenshot

      Source code:


      Java-Quellcode: WhereisPlayer.java

      1. /*
      2. * To change this license header, choose License Headers in Project Properties.
      3. * To change this template file, choose Tools | Templates
      4. * and open the template in the editor.
      5. */
      6. package world.yokohama.whereisplayer;
      7. /**
      8. *
      9. * @author Usiemon
      10. */
      11. import net.risingworld.api.Plugin;
      12. import net.risingworld.api.events.EventMethod;
      13. import net.risingworld.api.events.Listener;
      14. import net.risingworld.api.events.player.PlayerCommandEvent;
      15. import net.risingworld.api.objects.Player;
      16. import net.risingworld.api.utils.Vector3f;
      17. public class WhereisPlayer extends Plugin implements Listener{
      18. @Override
      19. public void onEnable(){
      20. //Register event listener
      21. registerEventListener(this);
      22. }
      23. @Override
      24. public void onDisable(){
      25. //...
      26. }
      27. @EventMethod
      28. public void onCommand(PlayerCommandEvent event){
      29. boolean playerfound = false;
      30. Player player = event.getPlayer();
      31. String command = event.getCommand();
      32. String[] directions= {"North", "North East", "East", "South East", "South", "South West", "West", "North West", "North"};
      33. String targetdir;
      34. //split the command
      35. String[] cmd = command.split(" ");
      36. //check the command and if player provided player name
      37. if((cmd[0].equals("/whereis")) && (cmd[1] != null)){
      38. //check if provided player name is online
      39. for(Player p : getServer().getAllPlayers()){
      40. //Check if a player with provided name is online
      41. if(p.getName().equals(cmd[1])){
      42. //get the target's position
      43. Vector3f targetpos = p.getPosition();
      44. playerfound = true;
      45. //calculate direction if target found
      46. //get player position
      47. Vector3f playerpos = player.getPosition();
      48. //decide direction on X-Z plane by degree
      49. double gapX = targetpos.getX() - playerpos.getX();
      50. double gapZ = targetpos.getZ() - playerpos.getZ();
      51. double targetangle = Math.toDegrees(Math.atan2(gapX,gapZ));
      52. //convert degree into direction
      53. targetdir = directions[ (int)Math.round( (targetangle % 360) / 45) ];
      54. //send message to player
      55. player.sendTextMessage("[#FFFF00] " + cmd[1] + " is to " + targetdir);
      56. }
      57. //notifies player that the target is not found
      58. if(playerfound==false){
      59. player.sendTextMessage("[#FFFF00]Player: " + cmd[1] + " not found");
      60. }
      61. }
      62. }
      63. }
      64. }
      Alles anzeigen
      Edit by yahgiggle, because some users could not see the screenshot
      Rising World Server: Yokohama
      Server discord: discord.gg/BQ7J7EM

      Dieser Beitrag wurde bereits 2 mal editiert, zuletzt von yahgiggle ()