Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from classes.commands.Command import Command, Path
- from classes.commands.Exception import NoPermission
- # Teleport command
- class TeleportCommand(Command):
- _command = 'teleport'
- _aliases = ['tp']
- @Command.execute([
- '{string:target}',
- '{string:player_from} {string:target}'
- ])
- def executePlayer(self, target=None, player_from=None, args=None):
- if not self.player:
- self.sendMessage("You must be a player to execute this command")
- return
- # Check if player has permission to teleport
- if not self.player.hasPermission('mcpy.teleport') or not self.player.hasPermission('mcpy.teleport.player'):
- raise NoPermission(permission='mcpy.teleport')
- # If player_from is different from player that execute this command and player doesn't have permission
- if player_from and self.player.name != player_from and not self.player.hasPermission('mcpy.teleport.other'):
- raise NoPermission(permission='mcpy.teleport.other')
- # Check if given target is connected
- targetPlayer = self.players.getPlayer(target)
- if targetPlayer:
- self.player.teleport(targetPlayer)
- self.player.sendMessage("Teleported")
- else:
- self.player.sendMessage("Player not found")
- @Command.execute([
- '{int:x} {int:y} {int:z}',
- '{string:target} {int:x} {int:y} {int:z}'
- ])
- def executeLocation(self, x=0, y=0, z=0, target=None, args=None):
- if not self.player:
- self.sendMessage("You must be a player to execute this command")
- return
- # Check if player has permission to teleport
- if not self.player.hasPermission('mcpy.teleport'):
- raise NoPermission(permission='mcpy.teleport')
- if target:
- # Check if given target is connected
- targetPlayer = self.players.getPlayer(target)
- if targetPlayer:
- targetPlayer.teleport(targetPlayer.world.name, x, y, z)
- self.player.sendMessage("Player %s teleported to %d, %d, %d" % (target, x, y, z))
- targetPlayer.sendMessage("Player %s has teleported you to %d, %d, %d" % (self.player.name, x, y, z))
- else:
- self.player.sendMessage("Player not found")
- else:
- self.player.teleport(self.player.world.name, x, y, z)
- self.player.sendMessage("Teleported to %d, %d, %d" % (x, y, z))
Advertisement
Add Comment
Please, Sign In to add comment