Guest User

Untitled

a guest
Aug 15th, 2020
152
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.47 KB | None | 0 0
  1.  
  2. from classes.commands.Command import Command, Path
  3. from classes.commands.Exception import NoPermission
  4.  
  5. # Teleport command
  6. class TeleportCommand(Command):
  7. _command = 'teleport'
  8. _aliases = ['tp']
  9.  
  10. @Command.execute([
  11. '{string:target}',
  12. '{string:player_from} {string:target}'
  13. ])
  14. def executePlayer(self, target=None, player_from=None, args=None):
  15. if not self.player:
  16. self.sendMessage("You must be a player to execute this command")
  17. return
  18. # Check if player has permission to teleport
  19. if not self.player.hasPermission('mcpy.teleport') or not self.player.hasPermission('mcpy.teleport.player'):
  20. raise NoPermission(permission='mcpy.teleport')
  21.  
  22. # If player_from is different from player that execute this command and player doesn't have permission
  23. if player_from and self.player.name != player_from and not self.player.hasPermission('mcpy.teleport.other'):
  24. raise NoPermission(permission='mcpy.teleport.other')
  25. # Check if given target is connected
  26. targetPlayer = self.players.getPlayer(target)
  27. if targetPlayer:
  28. self.player.teleport(targetPlayer)
  29. self.player.sendMessage("Teleported")
  30. else:
  31. self.player.sendMessage("Player not found")
  32.  
  33. @Command.execute([
  34. '{int:x} {int:y} {int:z}',
  35. '{string:target} {int:x} {int:y} {int:z}'
  36. ])
  37. def executeLocation(self, x=0, y=0, z=0, target=None, args=None):
  38. if not self.player:
  39. self.sendMessage("You must be a player to execute this command")
  40. return
  41. # Check if player has permission to teleport
  42. if not self.player.hasPermission('mcpy.teleport'):
  43. raise NoPermission(permission='mcpy.teleport')
  44. if target:
  45. # Check if given target is connected
  46. targetPlayer = self.players.getPlayer(target)
  47. if targetPlayer:
  48. targetPlayer.teleport(targetPlayer.world.name, x, y, z)
  49. self.player.sendMessage("Player %s teleported to %d, %d, %d" % (target, x, y, z))
  50. targetPlayer.sendMessage("Player %s has teleported you to %d, %d, %d" % (self.player.name, x, y, z))
  51. else:
  52. self.player.sendMessage("Player not found")
  53. else:
  54. self.player.teleport(self.player.world.name, x, y, z)
  55. self.player.sendMessage("Teleported to %d, %d, %d" % (x, y, z))
  56.  
Advertisement
Add Comment
Please, Sign In to add comment