def chat_command(self, username, parameters): data = self.factory.world.serializer.load_plugin_data("warps") warps = get_locations(data) if len(parameters) == 0: yield "Usage: /warp <warpname>" return location = parameters[0] if location in warps: yield "Teleporting you to %s" % location protocol = self.factory.protocols[username] # An explanation might be necessary. # We are changing the location of the player, but we must # immediately send a new location packet in order to force the # player to appear at the new location. However, before we can do # that, we need to get the chunk loaded for them. This ends up # being the same sequence of events as the initial chunk and # location setup, so we call send_initial_chunk_and_location() # instead of update_location(). l = protocol.player.location x, y, z, yaw, pitch = warps[location] l.pos = Position.from_player(x, y, z) l.ori = Orientation.from_degs(yaw, pitch) protocol.send_initial_chunk_and_location() yield "Teleportation successful!" else: yield "No warp location %s available" % parameters
def chat_command(self, username, parameters): data = self.factory.world.serializer.load_plugin_data("homes") homes = get_locations(data) protocol = self.factory.protocols[username] l = protocol.player.location if username in homes: yield "Teleporting %s home" % username x, y, z, yaw, pitch = homes[username] else: yield "Teleporting %s to spawn" % username x, y, z = self.factory.world.level.spawn yaw, pitch = 0, 0 l.pos = Position.from_player(x, y, z) l.ori = Orientation.from_degs(yaw, pitch) protocol.send_initial_chunk_and_location() yield "Teleportation successful!"
def position(self, container): """ Hook for position packets. """ old_position = self.location.pos position = Position.from_player(container.position.x, container.position.y, container.position.z) self.location.pos = position # Stance is the current jumping position, plus a small offset of # around 0.1. In the Alpha server, it must between 0.1 and 1.65, # or the anti-grounded code kicks the client. self.location.stance = container.position.stance self.grounded(container.grounded) if old_position != position: self.position_changed()
def position(self, container): """ Hook for position packets. """ # Refuse to handle any new position information while we are # relocating. Clients mess this up frequently, and it's fairly racy, # so don't consider this to be exceptional. Just ignore this one # packet and continue. if self.state != STATE_LOCATED: return self.grounded(container.grounded) old_position = self.location.pos position = Position.from_player(container.position.x, container.position.y, container.position.z) altered = False dx, dy, dz = old_position - position if any(abs(d) >= 64 for d in (dx, dy, dz)): # Whoa, slow down there, cowboy. You're moving too fast. We're # gonna ignore this position change completely, because it's # either bogus or ignoring a recent teleport. altered = True else: self.location.pos = position self.location.stance = container.position.stance # Santitize location. This handles safety boundaries, illegal stance, # etc. altered = self.location.clamp() or altered # If, for any reason, our opinion on where the client should be # located is different than theirs, force them to conform to our point # of view. if altered: log.msg("Not updating bogus position!") self.update_location() # If our position actually changed, fire the position change hook. if old_position != position: self.position_changed()
def test_from_player(self): p = Position.from_player(2.5, 3.0, -1.0) self.assertEqual(p, (80, 96, -32))