CommandTpPos.java 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. package me.km.commands;
  2. import me.kt.api.Utils;
  3. import me.kt.api.GlobalText;
  4. import me.kt.api.Module;
  5. import me.kt.api.ModuleCommand;
  6. import me.kt.exceptions.PlayerNotFoundException;
  7. import org.bukkit.Bukkit;
  8. import org.bukkit.Location;
  9. import org.bukkit.World;
  10. import org.bukkit.command.CommandSender;
  11. import org.bukkit.entity.Player;
  12. public class CommandTpPos extends ModuleCommand
  13. {
  14. public CommandTpPos(Module m)
  15. {
  16. super("tppos", m);
  17. this.setDescription("Teleportiert einen Spieler zu Koordinaten");
  18. this.setUsage("/tppos <x> <y> <z> [world] [player]");
  19. this.setPermission("kt.tppos");
  20. }
  21. @Override
  22. public boolean execute(CommandSender cs, String string, String[] arg)
  23. {
  24. if(arg.length < 3)
  25. {
  26. return false;
  27. }
  28. Player affectedPlayer;
  29. try
  30. {
  31. affectedPlayer = Utils.getPlayerByName(arg[4]);
  32. }
  33. catch(PlayerNotFoundException ex)
  34. {
  35. this.getModule().send(cs, GlobalText.cantFindPlayer(arg[4]));
  36. return true;
  37. }
  38. catch(IndexOutOfBoundsException ex)
  39. {
  40. if(!(cs instanceof Player))
  41. {
  42. this.getModule().send(cs, GlobalText.missingParameter());
  43. return true;
  44. }
  45. affectedPlayer = (Player) cs;
  46. }
  47. try
  48. {
  49. World w;
  50. if(arg.length >= 4 && Bukkit.getWorld(arg[3]) != null)
  51. {
  52. w = Bukkit.getWorld(arg[3]);
  53. }
  54. else
  55. {
  56. w = affectedPlayer.getWorld();
  57. }
  58. Location l = new Location(w, Double.parseDouble(arg[0]), Double.parseDouble(arg[1]), Double.parseDouble(arg[2]));
  59. affectedPlayer.teleport(l);
  60. String s = " zu " + l.getBlockX() + ", " + l.getBlockY() + ", " + l.getBlockZ() + " teleportiert.";
  61. this.getModule().send(affectedPlayer, "Du wurdest" + s);
  62. if(!cs.equals(affectedPlayer))
  63. {
  64. this.getModule().send(cs, affectedPlayer.getName() + " wurde" + s);
  65. }
  66. return true;
  67. }
  68. catch(Exception ex)
  69. {
  70. this.getModule().send(cs, GlobalText.noIntegerNumber());
  71. return true;
  72. }
  73. }
  74. }