def add_player(self, player: str, level_name: Optional[str] = None) -> int: """ Add a new player with permission level level_name If level_name is not set use default level Then save the permission data to file :param player: the name of the player :param level_name: the permission level name :return: the permission of the player after operation done """ if level_name is None: level_name = self.get_default_permission_level() PermissionLevel.from_value(level_name) # validity check self.get_permission_group_list(level_name).append(player) self.mcdr_server.logger.debug('Added player {} with permission level {}'.format(player, level_name), option=DebugOption.PERMISSION) self.save() return PermissionLevel.from_value(level_name).level
def get_permission_group_list(self, value): """ Return the list of the player who has permission level <level> Example return value: ['Steve', 'Alex'] :param str or int value: a permission related object :rtype: list[str] """ level_name = PermissionLevel.from_value(value).name if self._data[level_name] is None: self._data[level_name] = [] return self._data[level_name]
def query_player_permission(self, source: CommandSource, player: Optional[str]): if player is None: level = source.get_permission_level() source.reply( self.tr('mcdr_command.query_player_permission.self', PermissionLevel.from_value(level))) else: if not Validator.player_name(player): source.reply(self.tr('mcdr_command.invalid_player_name')) return else: level = self.mcdr_server.permission_manager.get_player_permission_level( player, auto_add=False) if level is not None: source.reply( self.tr('mcdr_command.query_player_permission.player', player, PermissionLevel.from_value(level))) else: source.reply( self.tr( 'mcdr_command.query_player_permission.player_unknown', player))
def query_self_permission(self, source: CommandSource): source.reply( self.tr('mcdr_command.query_player_permission.self', PermissionLevel.from_value(source.get_permission_level())))