CommandTpPos.java 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. package me.km.commands;
  2. import me.km.permissions.Permissions;
  3. import me.km.api.Utils;
  4. import me.km.api.GlobalText;
  5. import me.km.api.Location;
  6. import me.km.api.Module;
  7. import me.km.api.ModuleCommand;
  8. import me.km.dimensions.ModDimensions;
  9. import me.km.exception.PlayerNotFoundException;
  10. import net.minecraft.command.ICommandSender;
  11. import net.minecraft.entity.player.EntityPlayer;
  12. import net.minecraft.util.math.Vec3d;
  13. import net.minecraft.world.World;
  14. public class CommandTpPos extends ModuleCommand
  15. {
  16. public CommandTpPos(Module m)
  17. {
  18. super("tppos", m);
  19. super.setDescription("Teleportiert einen Spieler zu Koordinaten");
  20. super.setUsage("/tppos <x> <y> <z> [world] [player]");
  21. super.setPermission(Permissions.TP_POS);
  22. }
  23. @Override
  24. public boolean execute(ICommandSender cs, String[] arg)
  25. {
  26. if(arg.length < 3)
  27. {
  28. return false;
  29. }
  30. EntityPlayer affectedPlayer;
  31. try
  32. {
  33. affectedPlayer = Utils.getPlayerByName(arg[4]);
  34. }
  35. catch(PlayerNotFoundException ex)
  36. {
  37. this.getModule().send(cs, GlobalText.cantFindPlayer(arg[4]));
  38. return true;
  39. }
  40. catch(IndexOutOfBoundsException ex)
  41. {
  42. if(!(cs instanceof EntityPlayer))
  43. {
  44. this.getModule().send(cs, GlobalText.missingParameter());
  45. return true;
  46. }
  47. affectedPlayer = (EntityPlayer) cs;
  48. }
  49. try
  50. {
  51. World w;
  52. if(arg.length >= 4)
  53. {
  54. w = ModDimensions.getWorldFromName(arg[3]);
  55. if(w == null)
  56. {
  57. this.getModule().send(cs, "Die Welt '" + arg[3] + "' wurde nicht gefunden.");
  58. }
  59. }
  60. else
  61. {
  62. w = affectedPlayer.getEntityWorld();
  63. }
  64. Vec3d v = new Vec3d(Double.parseDouble(arg[0]), Double.parseDouble(arg[1]), Double.parseDouble(arg[2]));
  65. Utils.teleportEntity(affectedPlayer, new Location(w, v));
  66. String s = " zu " + v.x + ", " + v.y + ", " + v.z + " teleportiert.";
  67. this.getModule().send(affectedPlayer, "Du wurdest" + s);
  68. if(!cs.equals(affectedPlayer))
  69. {
  70. this.getModule().send(cs, affectedPlayer.getName() + " wurde" + s);
  71. }
  72. return true;
  73. }
  74. catch(Exception ex)
  75. {
  76. this.getModule().send(cs, GlobalText.noIntegerNumber());
  77. return true;
  78. }
  79. }
  80. }