def command_handle_tp(player, args, proto_inst): name = args[0] players_matched = get_players(name, proto_inst) if len(players_matched) > 1: players_list = '' for curr_player in players_matched: players_list += curr_player.username + " " info = helpers.handle_gen_chat_packets( r"More than 1 player matched: &6" + players_list, 0, 0) for packet in info: player.add_packet(packet) elif len(players_matched) == 1: dest_player = players_matched[0] is_long = helpers.get_extension_state(player, ('ExtEntityPositions', 1)) tp_packet = helpers.gen_pos_packet(-1, dest_player.xpos, dest_player.ypos, dest_player.zpos, dest_player.yaw, dest_player.pitch, is_long) player.add_packet(tp_packet) player.teleport_to(dest_player) if not (player.x_offset == dest_player.x_offset and player.z_offset == dest_player.z_offset): map_handler.get_player_tp_map_data(player, dest_player) player.teleport_to(dest_player) else: info = helpers.gen_chat_packet("No such player found.", 0) player.add_packet(info)
def handle_chat(tmp_player, proto_inst): messages = tmp_player.get_messages() # if it's a command then process it and return if messages[1] != '/' and commands.process_if_command(tmp_player, messages, proto_inst): return if messages[0] == '/': messages = messages[1:] full_msg = tmp_player.displayname + r': %f' + messages full_msg_color = proto_inst.factory.data.colors_regex.sub('&', full_msg) packets_to_send = helpers.handle_gen_chat_packets(full_msg_color, len(tmp_player.displayname), 0) for curr_packet in packets_to_send: proto_inst.factory.data.chat_broadcast_queue.put((curr_packet, tmp_player.username))
def command_handle_kick(player, args, proto_inst): name = args[0] reason = "" if (len(args) > 1): reason = " (" + " ".join(args[1:]) + ")" players_matched = get_players(name, proto_inst) if len(players_matched) > 1: players_list = '' for curr_player in players_matched: players_list += curr_player.username + " " info = helpers.handle_gen_chat_packets(r"More than 1 player matched: &6" + players_list, 0, 0) for packet in info: player.add_packet(packet) elif len(players_matched) == 1: helpers.disconnect_protocol(players_matched[0].proto_inst, "kicked by " + player.username + reason) else: info = helpers.gen_chat_packet("No such player found.", 0) player.add_packet(info)